Skip to content

Commit

Permalink
Merge branch 'master' into feat/reflect-static-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ktutnik committed Dec 5, 2022
2 parents 9ba6f7b + 793f5dc commit 7667cc7
Show file tree
Hide file tree
Showing 28 changed files with 153 additions and 156 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/conventional-commit.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
node-version: [14.x, 16.x]
steps:
- name: Checkout
uses: actions/checkout@v2.3.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
node-version: [14.x]
node-version: [16.x]

steps:
- name: Checkout
Expand Down
6 changes: 3 additions & 3 deletions docs/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"serve": "docusaurus serve"
},
"dependencies": {
"@docusaurus/core": "^2.0.0-beta.ff31de0ff",
"@docusaurus/preset-classic": "^2.0.0-beta.ff31de0ff",
"@docusaurus/core": "^2.2.0",
"@docusaurus/preset-classic": "^2.2.0",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.1.1",
"clsx": "^1.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
Expand Down
3 changes: 2 additions & 1 deletion jest.config.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
rootDir: ".",
moduleNameMapper: {
"@plumier/(.*)": "<rootDir>packages/$1/src",
"^plumier$": "<rootDir>packages/plumier/src/index.ts"
"^plumier$": "<rootDir>packages/plumier/src/index.ts",
'axios': 'axios/dist/node/axios.cjs'
},
globals: {
'ts-jest': {
Expand Down
12 changes: 7 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ module.exports = {
rootDir: ".",
moduleNameMapper: {
"@plumier/(.*)": "<rootDir>packages/$1/src",
"^plumier$": "<rootDir>packages/plumier/src/index.ts"
"^plumier$": "<rootDir>packages/plumier/src/index.ts",
'axios': 'axios/dist/node/axios.cjs'
},
snapshotSerializers: [
"<rootDir>script/function-snapshot-serializer.js",
"<rootDir>script/mongodb-id-snapshot-serializer.js",
"<rootDir>script/date-snapshot-serializer.js"
],
globals: {
'ts-jest': {
tsconfig: '<rootDir>tests/tsconfig.json'
}
}
'ts-jest': {
tsconfig: '<rootDir>tests/tsconfig.json'
}
},
testTimeout: 30000
};
49 changes: 25 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,49 @@
"author": "Ketut Sandiarsa",
"devDependencies": {
"@hapi/joi": "^17.1.1",
"@types/body-parser": "^1.19.1",
"@types/body-parser": "^1.19.2",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/express-jwt": "^6.0.2",
"@types/faker": "^5.5.8",
"@types/express": "^4.17.14",
"@types/express-jwt": "^6.0.4",
"@types/faker": "^5.5.9",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.0.2",
"@types/hapi__joi": "^17.1.7",
"@types/jsonwebtoken": "^8.5.5",
"@types/jest": "^27.5.2",
"@types/hapi__joi": "^17.1.8",
"@types/jsonwebtoken": "^8.5.9",
"@types/koa-router": "^7.4.4",
"@types/rimraf": "^3.0.2",
"@types/supertest": "^2.0.11",
"autocannon": "^7.4.0",
"@types/supertest": "^2.0.12",
"@types/express-unless": "^2.0.1",
"autocannon": "^7.10.0",
"babel-core": "^6.26.3",
"benalu": "^2.0.0-beta-1",
"body-parser": "^1.19.0",
"body-parser": "^1.20.1",
"cors": "^2.8.5",
"coveralls": "^3.1.1",
"del": "^6.0.0",
"edit-json-file": "^1.6.0",
"del": "^6.1.1",
"edit-json-file": "^1.7.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-jwt": "^6.1.0",
"express": "^4.18.2",
"express-jwt": "^6.1.2",
"faker": "^5.5.3",
"fs-extra": "^10.0.0",
"fs-extra": "^10.1.0",
"get-port": "5.1.1",
"jest": "^27.2.4",
"jest": "^27.5.1",
"jsonwebtoken": "^8.5.1",
"koa-better-body": "^3.3.9",
"koa-router": "^10.1.1",
"lerna": "4.0.0",
"mongodb-memory-server-global": "6.9.6",
"pre-push": "^0.1.1",
"mongodb-memory-server-global": "7.6.3",
"pre-push": "^0.1.4",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"supertest": "^6.1.6",
"sqlite3": "5.0.2",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"tsconfig-paths": "^3.11.0",
"supertest": "^6.3.2",
"sqlite3": "5.1.2",
"ts-jest": "^27.1.5",
"ts-node": "^10.9.1",
"tsconfig-paths": "^3.14.1",
"tslint": "^6.1.3",
"typescript": "4.4.3"
"typescript": "4.8.4"
},
"workspaces": {
"packages": [
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"@plumier/reflect": "^1.0.6",
"@plumier/validator": "^1.0.6",
"@types/debug": "^4.1.7",
"@types/glob": "^7.1.4",
"@types/glob": "^7.2.0",
"chalk": "^4.1.2",
"debug": "^4.3.2",
"glob": "^7.2.0",
"path-to-regexp": "^6.2.0",
"tslib": "^2.3.1"
"debug": "^4.3.4",
"glob": "^7.2.3",
"path-to-regexp": "^6.2.1",
"tslib": "^2.4.1"
},
"peerDependencies": {
"@types/koa": "*"
Expand Down
2 changes: 1 addition & 1 deletion packages/mongoose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@plumier/generic-controller": "^1.0.6",
"@types/pluralize": "^0.0.29",
"chalk": "^4.1.2",
"mongoose": "^5.13.2",
"mongoose": "^5.13.15",
"pluralize": "^8.0.0"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions packages/plumier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"author": "Ketut Sandiarsa",
"license": "MIT",
"dependencies": {
"@koa/cors": "^3.1.0",
"@koa/cors": "^3.4.3",
"@plumier/core": "^1.0.6",
"@plumier/generic-controller": "^1.0.6",
"@types/bytes": "^3.1.1",
"@types/koa": "^2.13.4",
"@types/koa__cors": "^3.0.3",
"@types/koa": "^2.13.5",
"@types/koa__cors": "^3.3.0",
"@types/qs": "^6.9.7",
"bytes": "^3.1.0",
"koa": "^2.13.3",
"bytes": "^3.1.2",
"koa": "^2.13.4",
"koa-body": "^4.2.0",
"qs": "^6.10.1"
"qs": "^6.11.0"
},
"devDependencies": {
"cpy-cli": "^3.1.1"
Expand Down
14 changes: 7 additions & 7 deletions packages/reflect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"license": "MIT",
"dependencies": {
"@types/acorn": "4.0.6",
"acorn": "8.5.0",
"acorn": "8.8.1",
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/node": "^16.10.2",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.4",
"coveralls": "^3.1.1",
"jest": "^27.2.4",
"ts-jest": "^27.0.5",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
"jest": "^27.5.1",
"ts-jest": "^27.1.5",
"tslib": "^2.4.1",
"typescript": "4.8.4"
},
"bugs": {
"url": "https://github.com/plumier/plumier/issues"
Expand Down
2 changes: 1 addition & 1 deletion packages/serve-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/koa-send": "^4.1.3",
"@types/mime-types": "2.1.1",
"koa-send": "^5.0.1",
"mime-types": "2.1.33"
"mime-types": "2.1.35"
},
"bugs": {
"url": "https://github.com/plumier/plumier/issues"
Expand Down
4 changes: 2 additions & 2 deletions packages/social-login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"@plumier/core": "^1.0.6",
"@types/csrf": "^3.1.0",
"@types/debug": "^4.1.7",
"axios": "0.22.0",
"axios": "1.2.0",
"csrf": "^3.1.0",
"debug": "^4.3.2",
"debug": "^4.3.4",
"oauth-1.0a": "^2.2.6"
},
"bugs": {
Expand Down
6 changes: 3 additions & 3 deletions packages/social-login/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ class OAuthRedirectUriMiddleware implements CustomMiddleware {
if (e.response) {
const error = (e as AxiosError)
const response = error.response!;
log.error("Request URL: %s %s", error.config.method, error.config.url)
log.error("Request Data: %o", error.config.data)
log.error("Request Headers: %o", error.config.headers)
log.error("Request URL: %s %s", error.config!.method, error.config!.url)
log.error("Request Data: %o", error.config!.data)
log.error("Request Headers: %o", error.config!.headers)
log.error("Error: %o", { status: response.status, message: response.statusText, data: response.data })
throw new HttpStatusError(response.status, response.statusText)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/swagger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"@plumier/core": "^1.0.6",
"@plumier/generic-controller": "^1.0.6",
"@plumier/serve-static": "^1.0.6",
"@types/ejs": "^3.1.0",
"@types/ejs": "^3.1.1",
"@types/swagger-ui-dist": "^3.30.1",
"ejs": "^3.1.6",
"openapi3-ts": "^2.0.1",
"swagger-ui-dist": "3.52.3"
"ejs": "^3.1.8",
"openapi3-ts": "^2.0.2",
"swagger-ui-dist": "3.52.5"
},
"devDependencies": {
"cpy-cli": "^3.1.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"author": "Ketut Sandiarsa",
"license": "MIT",
"dependencies": {
"@types/jest": "^27.0.2",
"jest": "^27.2.4"
"@types/jest": "^27.5.2",
"jest": "^27.5.1"
},
"devDependencies": {
"cpy-cli": "^3.1.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/typeorm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@plumier/generic-controller": "^1.0.6",
"@types/pluralize": "^0.0.29",
"pluralize": "^8.0.0",
"typeorm": "^0.2.38"
"typeorm": "0.2.40"
},
"devDependencies": {
"cpy-cli": "^3.1.1"
Expand Down
5 changes: 3 additions & 2 deletions packages/typeorm/src/generic-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "@plumier/generic-controller"
import reflect, { generic } from "@plumier/reflect"
import pluralize from "pluralize"
import { ObjectLiteral } from "typeorm"

import { normalizeEntity } from "./helper"
import { TypeORMNestedRepository, TypeORMRepository } from "./repository"
Expand All @@ -20,7 +21,7 @@ import { TypeORMNestedRepository, TypeORMRepository } from "./repository"

@generic.parameter("T", "TID")
@generic.argument("T", "TID")
class TypeORMControllerGeneric<T = any, TID = any> extends RepoBaseControllerGeneric<T, TID>{
class TypeORMControllerGeneric<T extends ObjectLiteral = any, TID = any> extends RepoBaseControllerGeneric<T, TID>{
constructor(fac?: ((x: Class<T>) => Repository<T>)) {
super(fac ?? (x => new TypeORMRepository(x)))
}
Expand Down Expand Up @@ -64,7 +65,7 @@ function createGenericControllerTypeORM(controllers?: GenericControllers) {
* @param type entity used as the generic controller parameter
* @param config configuration to authorize/enable/disable some actions
*/
function GenericController<T>(type: Class, config?: GenericControllerConfiguration): Class<TypeORMControllerGeneric<T>>
function GenericController<T extends ObjectLiteral>(type: Class, config?: GenericControllerConfiguration): Class<TypeORMControllerGeneric<T>>
/**
* Create a nested generic controller with CRUD functionality based on Entity's One-To-Many on Many-To-One relation property
* @param relation Tuple of [Entity, relationName] used to specify entity relation as a reference of the nested generic controller
Expand Down
16 changes: 8 additions & 8 deletions packages/typeorm/src/repository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Class, NestedRepository, Repository, SelectQuery, EntityRelationInfo, entityHelper } from "@plumier/core"
import { EntityWithRelation } from "@plumier/generic-controller"
import { getManager, getRepository, Repository as NativeRepository } from "typeorm"
import { getManager, getRepository, ObjectLiteral, Repository as NativeRepository } from "typeorm"

class TypeORMRepository<T> implements Repository<T> {
class TypeORMRepository<T extends ObjectLiteral> implements Repository<T> {
readonly nativeRepository: NativeRepository<T>
constructor(protected type: Class<T>) {
this.nativeRepository = getManager().getRepository(type)
Expand Down Expand Up @@ -46,7 +46,7 @@ class TypeORMRepository<T> implements Repository<T> {
}
}

class TypeORMNestedRepository<P, T> implements NestedRepository<P, T> {
class TypeORMNestedRepository<P extends ObjectLiteral, T extends ObjectLiteral> implements NestedRepository<P, T> {
readonly nativeRepository: NativeRepository<T>
readonly nativeParentRepository: NativeRepository<P>
readonly relation: EntityRelationInfo
Expand All @@ -56,13 +56,12 @@ class TypeORMNestedRepository<P, T> implements NestedRepository<P, T> {
this.nativeParentRepository = getManager().getRepository(this.relation.parent)
}
count(pid: any, query?: any): Promise<number> {
return this.nativeRepository.count({
where: { [this.relation.childProperty!]: pid, ...query },
})
const where = { [this.relation.childProperty!]: pid, ...query }
return this.nativeRepository.count({ where })
}

async find(pid: any, offset: number, limit: number, query: any, selection: SelectQuery, order: any): Promise<T[]> {
if(!this.relation.childProperty)
if (!this.relation.childProperty)
throw new Error(`Relation without inverse property is not supported by Nested Generic Controller`)
return this.nativeRepository.find({
where:
Expand All @@ -86,7 +85,8 @@ class TypeORMNestedRepository<P, T> implements NestedRepository<P, T> {
return result
}
else {
return this.nativeRepository.save({ [this.relation.childProperty!]: pid, ...data })
const entity = { [this.relation.childProperty!]: pid, ...data }
return this.nativeRepository.save(entity)
}
}

Expand Down

0 comments on commit 7667cc7

Please sign in to comment.