Skip to content

Commit e2b3c34

Browse files
authored
Merge pull request #67 from frouriojs/develop
chore(release): 0.25.1
2 parents 6e16911 + 4bed771 commit e2b3c34

File tree

6 files changed

+1458
-1970
lines changed

6 files changed

+1458
-1970
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ${{ matrix.os }}
99
strategy:
1010
matrix:
11-
node-version: [10, 12, 14]
11+
node-version: [12, 14, 16]
1212
os: [ubuntu-latest]
1313
include:
1414
- os: windows-latest

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [0.25.1](https://github.com/frouriojs/frourio-express/compare/v0.25.0...v0.25.1) (2021-07-04)
6+
7+
8+
### Bug Fixes
9+
10+
* update createControllersText ([f0b83bf](https://github.com/frouriojs/frourio-express/commit/f0b83bfceed34d74a8898bdcad09257948b070b5))
11+
512
## [0.25.0](https://github.com/frouriojs/frourio-express/compare/v0.24.1...v0.25.0) (2021-04-22)
613

714

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { compilerOptions } from './tsconfig.json'
55
const config: Config.InitialOptions = {
66
preset: 'ts-jest',
77
testEnvironment: 'node',
8-
globals: { Blob: {} },
8+
globals: { Blob: {}, 'ts-jest': {} },
99
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
1010
coveragePathIgnorePatterns: ['\\$api.ts', 'dist']
1111
}

package.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frourio-express",
3-
"version": "0.25.0",
3+
"version": "0.25.1",
44
"description": "Fast and type-safe full stack framework, for TypeScript",
55
"author": "Solufa <[email protected]>",
66
"license": "MIT",
@@ -32,7 +32,7 @@
3232
"release:minor": "npm run release -- --release-as minor",
3333
"release:patch": "npm run release -- --release-as patch",
3434
"lint": "eslint --ext .js,.ts --ignore-path .gitignore . && prettier --check \"./**/*.ts\"",
35-
"lint:fix": "npm run lint -- --fix",
35+
"lint:fix": "eslint --ext .js,.ts --ignore-path .gitignore . --fix && prettier --write \"./**/*.ts\"",
3636
"test": "jest",
3737
"typecheck": "tsc --noEmit"
3838
},
@@ -82,39 +82,39 @@
8282
]
8383
},
8484
"dependencies": {
85-
"aspida": "^1.7.0",
86-
"fast-json-stringify": "^2.6.0",
85+
"aspida": "^1.7.1",
86+
"fast-json-stringify": "^2.7.7",
8787
"velona": "^0.7.0"
8888
},
8989
"devDependencies": {
90-
"@aspida/axios": "^1.7.0",
91-
"@aspida/node-fetch": "^1.7.0",
90+
"@aspida/axios": "^1.7.1",
91+
"@aspida/node-fetch": "^1.7.1",
9292
"@types/express": "^4.17.7",
93-
"@types/jest": "^26.0.22",
94-
"@types/multer": "^1.4.5",
93+
"@types/jest": "^26.0.23",
94+
"@types/multer": "^1.4.6",
9595
"@types/node-fetch": "^2.5.10",
9696
"@types/rimraf": "^3.0.0",
97-
"@typescript-eslint/eslint-plugin": "^4.22.0",
98-
"@typescript-eslint/parser": "^4.22.0",
97+
"@typescript-eslint/eslint-plugin": "^4.28.1",
98+
"@typescript-eslint/parser": "^4.28.1",
9999
"axios": "^0.21.1",
100100
"class-validator": "^0.13.1",
101-
"eslint": "^7.24.0",
102-
"eslint-config-prettier": "^8.2.0",
103-
"eslint-config-standard": "^16.0.2",
104-
"eslint-plugin-import": "^2.22.1",
105-
"eslint-plugin-jest": "^24.3.5",
101+
"eslint": "^7.30.0",
102+
"eslint-config-prettier": "^8.3.0",
103+
"eslint-config-standard": "^16.0.3",
104+
"eslint-plugin-import": "^2.23.4",
105+
"eslint-plugin-jest": "^24.3.6",
106106
"eslint-plugin-node": "^11.1.0",
107107
"eslint-plugin-promise": "^5.1.0",
108108
"eslint-plugin-standard": "^5.0.0",
109109
"express": "^4.17.1",
110-
"jest": "^26.6.3",
110+
"jest": "^27.0.6",
111111
"multer": "^1.4.2",
112112
"node-fetch": "^2.6.1",
113-
"prettier": "^2.2.1",
113+
"prettier": "^2.3.2",
114114
"rimraf": "^3.0.2",
115-
"standard-version": "^9.2.0",
116-
"ts-jest": "^26.5.5",
117-
"ts-node": "^9.1.1",
118-
"typescript": "^4.2.4"
115+
"standard-version": "^9.3.0",
116+
"ts-jest": "^27.0.3",
117+
"ts-node": "^10.0.0",
118+
"typescript": "^4.3.5"
119119
}
120120
}

src/createControllersText.ts

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ export default (appDir: string, project: string) => {
216216
.getTypeAtLocation(node.body)
217217
.getProperties()
218218
.map(p => {
219-
const typeNode = checker.typeToTypeNode(
220-
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
221-
undefined,
222-
undefined
223-
)
219+
const typeNode =
220+
p.valueDeclaration &&
221+
checker.typeToTypeNode(
222+
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
223+
undefined,
224+
undefined
225+
)
224226

225227
return {
226228
type: p.name as HooksEvent,
@@ -266,14 +268,16 @@ export default (appDir: string, project: string) => {
266268
.getProperties()
267269
.map(
268270
t =>
271+
t.valueDeclaration &&
269272
checker
270273
.getSignaturesOfType(
271274
checker.getTypeOfSymbolAtLocation(t, t.valueDeclaration),
272275
ts.SignatureKind.Call
273276
)[0]
274277
.getReturnType()
275278
.getSymbol()
276-
?.getEscapedName() === 'Promise' && t.name
279+
?.getEscapedName() === 'Promise' &&
280+
t.name
277281
)
278282
.filter((n): n is string => !!n)
279283
)
@@ -325,11 +329,13 @@ export default (appDir: string, project: string) => {
325329
?.getReturnType()
326330
.getProperties()
327331
.map(p => {
328-
const typeNode = checker.typeToTypeNode(
329-
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
330-
undefined,
331-
undefined
332-
)
332+
const typeNode =
333+
p.valueDeclaration &&
334+
checker.typeToTypeNode(
335+
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
336+
undefined,
337+
undefined
338+
)
333339

334340
return {
335341
type: p.name as HooksEvent,
@@ -359,15 +365,16 @@ export default (appDir: string, project: string) => {
359365
const genResSchemaText = (method: LowerHttpMethod) =>
360366
`responseSchema${controllers.filter(c => c[2]).length}.${method}`
361367
const getSomeTypeQueryParams = (typeName: string, query: ts.Symbol) =>
368+
query.valueDeclaration &&
362369
checker
363370
.getTypeOfSymbolAtLocation(query, query.valueDeclaration)
364371
.getProperties()
365372
.map(p => {
366-
const typeString = checker.typeToString(
367-
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration)
368-
)
373+
const typeString =
374+
p.valueDeclaration &&
375+
checker.typeToString(checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration))
369376
return typeString === typeName || typeString === `${typeName}[]`
370-
? `['${p.name}', ${p.declarations.some(d =>
377+
? `['${p.name}', ${!!p.declarations?.some(d =>
371378
d.getChildren().some(c => c.kind === ts.SyntaxKind.QuestionToken)
372379
)}, ${typeString === `${typeName}[]`}]`
373380
: null
@@ -377,7 +384,9 @@ export default (appDir: string, project: string) => {
377384
results.push(
378385
methods
379386
.map(m => {
380-
const props = checker.getTypeOfSymbolAtLocation(m, m.valueDeclaration).getProperties()
387+
const props = m.valueDeclaration
388+
? checker.getTypeOfSymbolAtLocation(m, m.valueDeclaration).getProperties()
389+
: []
381390
const query = props.find(p => p.name === 'query')
382391
const numberTypeQueryParams = query && getSomeTypeQueryParams('number', query)
383392
const booleanTypeQueryParams = query && getSomeTypeQueryParams('boolean', query)
@@ -389,16 +398,18 @@ export default (appDir: string, project: string) => {
389398
.filter((prop): prop is { name: string; val: ts.Symbol } => !!prop.val)
390399
.map(({ name, val }) => ({
391400
name,
392-
type: checker.getTypeOfSymbolAtLocation(val, val.valueDeclaration),
393-
hasQuestion: val.declarations.some(
401+
type:
402+
val.valueDeclaration &&
403+
checker.getTypeOfSymbolAtLocation(val, val.valueDeclaration),
404+
hasQuestion: !!val.declarations?.some(
394405
d => d.getChildAt(1).kind === ts.SyntaxKind.QuestionToken
395406
)
396407
}))
397-
.filter(({ type }) => type.isClass())
408+
.filter(({ type }) => type?.isClass())
398409

399410
const reqFormat = props.find(p => p.name === 'reqFormat')
400411
const isFormData =
401-
(reqFormat &&
412+
(reqFormat?.valueDeclaration &&
402413
checker.typeToString(
403414
checker.getTypeOfSymbolAtLocation(reqFormat, reqFormat.valueDeclaration)
404415
)) === 'FormData'
@@ -408,7 +419,7 @@ export default (appDir: string, project: string) => {
408419
...genHookTexts('onRequest'),
409420
...genHookTexts('preParsing'),
410421
numberTypeQueryParams?.length
411-
? query?.declarations.some(
422+
? query?.declarations?.some(
412423
d => d.getChildAt(1).kind === ts.SyntaxKind.QuestionToken
413424
)
414425
? `callParserIfExistsQuery(parseNumberTypeQueryParams([${numberTypeQueryParams.join(
@@ -417,29 +428,31 @@ export default (appDir: string, project: string) => {
417428
: `parseNumberTypeQueryParams([${numberTypeQueryParams.join(', ')}])`
418429
: '',
419430
booleanTypeQueryParams?.length
420-
? query?.declarations.some(
431+
? query?.declarations?.some(
421432
d => d.getChildAt(1).kind === ts.SyntaxKind.QuestionToken
422433
)
423434
? `callParserIfExistsQuery(parseBooleanTypeQueryParams([${booleanTypeQueryParams.join(
424435
', '
425436
)}]))`
426437
: `parseBooleanTypeQueryParams([${booleanTypeQueryParams.join(', ')}])`
427438
: '',
428-
...(isFormData && reqBody
439+
...(isFormData && reqBody?.valueDeclaration
429440
? [
430441
'uploader',
431442
`formatMulterData([${checker
432443
.getTypeOfSymbolAtLocation(reqBody, reqBody.valueDeclaration)
433444
.getProperties()
434445
.map(p => {
435-
const node = checker.typeToTypeNode(
436-
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
437-
undefined,
438-
undefined
439-
)
446+
const node =
447+
p.valueDeclaration &&
448+
checker.typeToTypeNode(
449+
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
450+
undefined,
451+
undefined
452+
)
440453
441454
return node && (ts.isArrayTypeNode(node) || ts.isTupleTypeNode(node))
442-
? `['${p.name}', ${p.declarations.some(d =>
455+
? `['${p.name}', ${!!p.declarations?.some(d =>
443456
d.getChildren().some(c => c.kind === ts.SyntaxKind.QuestionToken)
444457
)}]`
445458
: undefined
@@ -453,13 +466,14 @@ export default (appDir: string, project: string) => {
453466
validateInfo.length
454467
? `createValidateHandler(req => [
455468
${validateInfo
456-
.map(
457-
v =>
458-
` ${
459-
v.hasQuestion ? `Object.keys(req.${v.name}).length ? ` : ''
460-
}validateOrReject(Object.assign(new Validators.${checker.typeToString(v.type)}(), req.${
461-
v.name
462-
}), validatorOptions)${v.hasQuestion ? ' : null' : ''}`
469+
.map(v =>
470+
v.type
471+
? ` ${
472+
v.hasQuestion ? `Object.keys(req.${v.name}).length ? ` : ''
473+
}validateOrReject(Object.assign(new Validators.${checker.typeToString(v.type)}(), req.${
474+
v.name
475+
}), validatorOptions)${v.hasQuestion ? ' : null' : ''}`
476+
: ''
463477
)
464478
.join(',\n')}\n ])`
465479
: '',

0 commit comments

Comments
 (0)