Skip to content

Commit

Permalink
Merge 68e5026 into 5487bb9
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenader committed Nov 14, 2020
2 parents 5487bb9 + 68e5026 commit e4f6685
Show file tree
Hide file tree
Showing 35 changed files with 2,842 additions and 2,295 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ max_line_length = 140
[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[*.json]
indent_size = 2
31 changes: 31 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name-template: 'Version $RESOLVED_VERSION 🌈'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
labels:
- 'chore'
- 'dependencies'
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Changes
$CHANGES
14 changes: 14 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release Drafter

on:
push:
branches:
- master

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests

on:
- push
- pull_request

jobs:
test:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master')
strategy:
matrix:
node: [10, 12, 14]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ matrix.node }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install deps
run: |
yarn
yarn bootstrap
- name: Build package
run: yarn build
- name: Run tests
run: yarn test:coverage
- name: Check examples
run: yarn run-examples
- name: Coveralls
if: matrix.node == '10'
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# tg-resources

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Build Status][ci-image]][ci-url]
[![Dependency Status][depstat-image]][depstat-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![Downloads][download-badge]][npm-url]
[![Greenkeeper badge][greenkeeper-badge]][greenkeeper-url]

> Abstractions on-top of `superagent` and `fetch` (or other Ajax libaries) for communication with REST.
> Targeted mostly against `Django Rest Framework (DRF)` running on `Django` so some logic might not be applicable for
Expand Down Expand Up @@ -260,15 +259,15 @@ Do a `method` request to the resource endpoint with optional kwargs and query pa

### ``Resource.patch``

Alias for `Resource.post(kwargs, data, query, requestConfig)` with `options` method.
Alias for `Resource.post(kwargs, data, query, attachments, requestConfig)` with `patch` method.

### ``Resource.put``

Alias for `Resource.post(kwargs, data, query, requestConfig)` with `put` method.
Alias for `Resource.post(kwargs, data, query, attachments, requestConfig)` with `put` method.

### ``Resource.del``

Alias for `Resource.post(kwargs, data, query, requestConfig)` with `del` method.
Alias for `Resource.post(kwargs, data, query, attachments, requestConfig)` with `del` method.

### ``ResourceErrorInterface``

Expand Down Expand Up @@ -395,8 +394,8 @@ MIT © [Thorgate](http://github.com/thorgate)
[npm-url]: https://npmjs.org/package/tg-resources
[npm-image]: https://img.shields.io/npm/v/tg-resources.svg?style=flat-square

[travis-url]: https://travis-ci.com/thorgate/tg-resources
[travis-image]: https://img.shields.io/travis/thorgate/tg-resources.svg?style=flat-square
[ci-url]: https://github.com/thorgate/tg-resources/actions
[ci-image]: https://github.com/thorgate/tg-resources/workflows/.github/workflows/run-tests.yml/badge.svg?branch=master

[depstat-url]: https://david-dm.org/thorgate/tg-resources
[depstat-image]: https://david-dm.org/thorgate/tg-resources.svg?style=flat-square
Expand All @@ -405,6 +404,3 @@ MIT © [Thorgate](http://github.com/thorgate)
[coveralls-image]: https://coveralls.io/repos/github/thorgate/tg-resources/badge.svg?branch=master

[download-badge]: http://img.shields.io/npm/dm/tg-resources.svg?style=flat-square

[greenkeeper-badge]: https://badges.greenkeeper.io/thorgate/tg-resources.svg
[greenkeeper-url]: https://badges.greenkeeper.io/thorgate/tg-resources.svg
1 change: 1 addition & 0 deletions examples/example-usage/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const presets = [
node: 'current',
},
useBuiltIns: 'usage',
corejs: '3',
},
],
];
Expand Down
11 changes: 7 additions & 4 deletions examples/example-usage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"main": "lib/index.js",
"license": "MIT",
"dependencies": {
"@tg-resources/fetch": "^3.1.4",
"@tg-resources/fetch-runtime": "^3.1.4",
"@tg-resources/superagent": "^3.1.4",
"@tg-resources/test-server": "^3.1.4",
"tg-resources": "^3.1.4"
Expand All @@ -21,9 +23,10 @@
"start": "node ./lib/index.js"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.6",
"@babel/polyfill": "^7.8.3",
"@babel/preset-env": "^7.8.6"
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"core-js": "^3.7.0"
}
}
3 changes: 2 additions & 1 deletion examples/example-usage/src/router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-unused-vars, no-console */
import '@tg-resources/fetch-runtime';
import { listen, getHostUrl } from '@tg-resources/test-server';
import { Router, parseErrors, prepareError } from 'tg-resources';
import { SuperAgentResource as Resource } from '@tg-resources/superagent';
import { FetchResource as Resource } from '@tg-resources/fetch';

const server = listen(3005);

Expand Down
6 changes: 5 additions & 1 deletion jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
const { defaults } = require('jest-config');

const config = {
verbose: true,
cache: false,

collectCoverageFrom: ['src/**/*.{ts,tsx}', '!**/node_modules/**'],

transform: { '.(ts|tsx)': 'ts-jest' },
transform: {
'\.tsx?$': 'ts-jest',
'\.jsx?$': 'babel-jest',
},

moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],

Expand Down
40 changes: 18 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "tg-resources",
"name": "tg-resources-root",
"private": true,
"workspaces": [
"examples/*",
Expand All @@ -19,8 +19,6 @@
"lint": "yarn check-formatting && lerna --ignore=examples/* exec yarn lint",
"test": "jest",
"test:coverage": "yarn test --coverage",
"precoveralls": "yarn test:coverage --no-cache",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"check-packages": "yarn clean && yarn build && yarn test && yarn lint",
"bump-version": "lerna --ignore=examples/* version --no-push --exact",
"prerun-publish": "yarn build",
Expand Down Expand Up @@ -54,61 +52,59 @@
},
"homepage": "https://github.com/thorgate/tg-resources#readme",
"dependencies": {
"@babel/core": "7.8.6",
"@babel/plugin-transform-async-to-generator": "7.8.3",
"@babel/preset-env": "^7.8.6",
"@babel/core": "7.12.3",
"@babel/plugin-transform-async-to-generator": "7.12.1",
"@babel/preset-env": "^7.12.1",
"@rollup/plugin-commonjs": "11.1.0",
"@rollup/plugin-json": "4.0.3",
"@rollup/plugin-node-resolve": "7.1.2",
"@rollup/plugin-replace": "2.3.2",
"@types/body-parser": "^1.17.0",
"@types/cookie": "^0.3.1",
"@types/cookie-parser": "^1.4.1",
"@types/express": "^4.16.0",
"@types/express": "^4.17.9",
"@types/jest": "25.1.3",
"@types/lodash.template": "^4.4.4",
"@types/multiparty": "^0.0.32",
"@types/node": "^13.1.0",
"@types/qs": "^6.9.1",
"@types/qs": "^6.9.5",
"@types/superagent": "^4.1.6",
"@types/uuid": "^7.0.0",
"@typescript-eslint/eslint-plugin": "2.19.1",
"@typescript-eslint/parser": "2.19.1",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "25.1.0",
"body-parser": "^1.17.2",
"babel-jest": "26.6.3",
"check-engines": "1.5.0",
"cookie-parser": "^1.4.3",
"coveralls": "^3.0.7",
"debug": "*",
"eslint": "6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^3.0.0",
"express": "^4.15.3",
"express": "^4.17.1",
"form-data": "^3.0.0",
"fs-extra": "*",
"isparta": "*",
"jest": "25.1.0",
"jest-cli": "25.1.0",
"jest": "26.6.3",
"jest-cli": "26.6.3",
"jest-extended": "0.11.5",
"lerna": "3.20.2",
"lodash": "^4.17.19",
"lodash.template": "*",
"multiparty": "*",
"prettier": "1.19.0",
"qs": "^6.9.1",
"prettier": "2.1.2",
"qs": "^6.9.4",
"redux": "^4.0.4",
"redux-saga": "^1.1.1",
"regenerator-runtime": "0.13.5",
"redux-saga": "^1.1.3",
"regenerator-runtime": "0.13.7",
"rimraf": "^3.0.2",
"rollup": "^2.0.0",
"rollup-plugin-typescript2": "0.26.0",
"superagent": "^5.2.1",
"temp-dir": "2.0.0",
"ts-jest": "25.2.1",
"tslib": "1.11.0",
"typescript": "3.7.5",
"ts-jest": "26.4.4",
"tslib": "2.0.3",
"typescript": "3.9.7",
"uuid": "^7.0.0",
"watch": "*"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/ValidationError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class SingleValidationError extends ValidationErrorInterface {
if (process.env.NODE_ENV !== 'production') {
if (
!isArray(errors) ||
errors.filter(x => !isString(x)).length > 0
errors.filter((x) => !isString(x)).length > 0
) {
// eslint-disable-next-line no-console
console.error(
Expand Down Expand Up @@ -204,7 +204,7 @@ export class ValidationError extends ParentValidationErrorInterface {
// MAP: falsy to null, bind all errors w/ their fieldName
const mutErrors: ValidationErrorObject = {};
if (errors) {
Object.keys(errors).forEach(fieldName => {
Object.keys(errors).forEach((fieldName) => {
mutErrors[fieldName] = bindAndCoerce(
errors[fieldName],
fieldName
Expand Down Expand Up @@ -242,13 +242,13 @@ export class ValidationError extends ParentValidationErrorInterface {
return (
prefix +
this._errKeys
.map(k => `${k}: ${this._errors[k].asString()}`)
.map((k) => `${k}: ${this._errors[k].asString()}`)
.join(glue)
);
}

public _iter() {
return Object.keys(this._errors).map(x => this.errors[x]);
return Object.keys(this._errors).map((x) => this.errors[x]);
}

public errorByIndex(index: number) {
Expand Down Expand Up @@ -346,7 +346,7 @@ export function prepareError(err: any, parentConfig: ConfigType) {
let resNonField = null;
const resErrors: ObjectMap = {};

Object.keys(errors).forEach(key => {
Object.keys(errors).forEach((key) => {
const error = parentConfig.prepareError(errors[key], parentConfig);

if (key === 'non_field_errors') {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/createRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function createRouter<Klass extends Resource, T extends ObjectMap = {}>(
[key: string]: Router | Resource;
} = {};

Object.keys(routes).forEach(key => {
Object.keys(routes).forEach((key) => {
if (routes[key] instanceof Router) {
routeMap[key] = routes[key];
} else if (isString(routes[key])) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ export abstract class Resource extends Route implements ResourceInterface {
requestConfig: RequestConfig
): Promise<R> {
return this.ensureStatusAndJson<R>(
new Promise(resolve => {
new Promise((resolve) => {
const headers = this.getHeaders(requestConfig);

if (headers && isObject(headers)) {
Object.keys(headers).forEach(key => {
Object.keys(headers).forEach((key) => {
if (hasValue(headers[key])) {
req = this.setHeader(req, key, headers[key]);
}
Expand Down

0 comments on commit e4f6685

Please sign in to comment.