Skip to content

Commit

Permalink
Merge pull request #175 from frouriojs/develop
Browse files Browse the repository at this point in the history
chore(release): 0.25.1
  • Loading branch information
solufa authored Jul 4, 2021
2 parents c9fe414 + baf33a5 commit 52368ee
Show file tree
Hide file tree
Showing 8 changed files with 1,486 additions and 1,987 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [10, 12, 14]
node-version: [12, 14, 16]
os: [ubuntu-latest]
include:
- os: windows-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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.

### [0.25.1](https://github.com/frouriojs/frourio/compare/v0.25.0...v0.25.1) (2021-07-04)

## [0.25.0](https://github.com/frouriojs/frourio/compare/v0.24.1...v0.25.0) (2021-04-22)


Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { compilerOptions } from './tsconfig.json'
const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: { Blob: {} },
globals: { Blob: {}, 'ts-jest': {} },
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
coveragePathIgnorePatterns: ['\\$api.ts', 'dist']
}
Expand Down
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frourio",
"version": "0.25.0",
"version": "0.25.1",
"description": "Fast and type-safe full stack framework, for TypeScript",
"author": "Solufa <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -32,7 +32,7 @@
"release:minor": "npm run release -- --release-as minor",
"release:patch": "npm run release -- --release-as patch",
"lint": "eslint --ext .js,.ts --ignore-path .gitignore . && prettier --check \"./**/*.ts\"",
"lint:fix": "npm run lint -- --fix",
"lint:fix": "eslint --ext .js,.ts --ignore-path .gitignore . --fix && prettier --write \"./**/*.ts\"",
"test": "jest",
"typecheck": "tsc --noEmit"
},
Expand Down Expand Up @@ -82,37 +82,37 @@
]
},
"dependencies": {
"aspida": "^1.7.0",
"aspida": "^1.7.1",
"velona": "^0.7.0"
},
"devDependencies": {
"@aspida/axios": "^1.7.0",
"@aspida/node-fetch": "^1.7.0",
"@aspida/axios": "^1.7.1",
"@aspida/node-fetch": "^1.7.1",
"@types/busboy": "^0.2.3",
"@types/jest": "^26.0.22",
"@types/jest": "^26.0.23",
"@types/node-fetch": "^2.5.10",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"axios": "^0.21.1",
"class-validator": "^0.13.1",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.2.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.5",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"fastify": "^3.15.0",
"fastify-multipart": "^4.0.5",
"jest": "^26.6.3",
"fastify": "^3.18.1",
"fastify-multipart": "^4.0.7",
"jest": "^27.0.6",
"node-fetch": "^2.6.1",
"prettier": "^2.2.1",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"standard-version": "^9.2.0",
"ts-jest": "^26.5.5",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
"standard-version": "^9.3.0",
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"typescript": "^4.3.5"
}
}
2 changes: 1 addition & 1 deletion servers/all/$server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const parseBooleanTypeQueryParams = (booleanTypeParams: [string, boolean, boolea
}

// prettier-ignore
const callParserIfExistsQuery = (parser: preValidationHookHandler): preValidationHookHandler => (req, reply, done) =>
const callParserIfExistsQuery = (parser: OmitThisParameter<preValidationHookHandler>): preValidationHookHandler => (req, reply, done) =>
Object.keys(req.query as any).length ? parser(req, reply, done) : done()

// prettier-ignore
Expand Down
2 changes: 1 addition & 1 deletion src/buildServerFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const parseBooleanTypeQueryParams = (booleanTypeParams: [string, boolean, boolea
}${
hasOptionalQuery
? `
const callParserIfExistsQuery = (parser: preValidationHookHandler): preValidationHookHandler => (req, reply, done) =>
const callParserIfExistsQuery = (parser: OmitThisParameter<preValidationHookHandler>): preValidationHookHandler => (req, reply, done) =>
Object.keys(req.query as any).length ? parser(req, reply, done) : done()
`
: ''
Expand Down
102 changes: 56 additions & 46 deletions src/createControllersText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,13 @@ export default (appDir: string, project: string) => {
.getTypeAtLocation(node.body)
.getProperties()
.map(p => {
const typeNode = checker.typeToTypeNode(
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
undefined,
undefined
)
const typeNode =
p.valueDeclaration &&
checker.typeToTypeNode(
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
undefined,
undefined
)

return {
type: p.name as HooksEvent,
Expand Down Expand Up @@ -271,14 +273,16 @@ export default (appDir: string, project: string) => {
.getProperties()
.map(
t =>
t.valueDeclaration &&
checker
.getSignaturesOfType(
checker.getTypeOfSymbolAtLocation(t, t.valueDeclaration),
ts.SignatureKind.Call
)[0]
.getReturnType()
.getSymbol()
?.getEscapedName() === 'Promise' && t.name
?.getEscapedName() === 'Promise' &&
t.name
)
.filter((n): n is string => !!n)
)
Expand Down Expand Up @@ -330,11 +334,13 @@ export default (appDir: string, project: string) => {
?.getReturnType()
.getProperties()
.map(p => {
const typeNode = checker.typeToTypeNode(
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
undefined,
undefined
)
const typeNode =
p.valueDeclaration &&
checker.typeToTypeNode(
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
undefined,
undefined
)

return {
type: p.name as HooksEvent,
Expand Down Expand Up @@ -364,15 +370,16 @@ export default (appDir: string, project: string) => {
const genResSchemaText = (method: LowerHttpMethod) =>
`schema: { response: responseSchema${controllers.filter(c => c[2]).length}.${method} }`
const getSomeTypeQueryParams = (typeName: string, query: ts.Symbol) =>
query.valueDeclaration &&
checker
.getTypeOfSymbolAtLocation(query, query.valueDeclaration)
.getProperties()
.map(p => {
const typeString = checker.typeToString(
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration)
)
const typeString =
p.valueDeclaration &&
checker.typeToString(checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration))
return typeString === typeName || typeString === `${typeName}[]`
? `['${p.name}', ${p.declarations.some(d =>
? `['${p.name}', ${!!p.declarations?.some(d =>
d.getChildren().some(c => c.kind === ts.SyntaxKind.QuestionToken)
)}, ${typeString === `${typeName}[]`}]`
: null
Expand All @@ -382,7 +389,9 @@ export default (appDir: string, project: string) => {
results.push(
methods
.map(m => {
const props = checker.getTypeOfSymbolAtLocation(m, m.valueDeclaration).getProperties()
const props = m.valueDeclaration
? checker.getTypeOfSymbolAtLocation(m, m.valueDeclaration).getProperties()
: []
const query = props.find(p => p.name === 'query')
const numberTypeQueryParams = query && getSomeTypeQueryParams('number', query)
const booleanTypeQueryParams = query && getSomeTypeQueryParams('boolean', query)
Expand All @@ -394,31 +403,30 @@ export default (appDir: string, project: string) => {
.filter((prop): prop is { name: string; val: ts.Symbol } => !!prop.val)
.map(({ name, val }) => ({
name,
type: checker.getTypeOfSymbolAtLocation(val, val.valueDeclaration),
hasQuestion: val.declarations.some(
type:
val.valueDeclaration &&
checker.getTypeOfSymbolAtLocation(val, val.valueDeclaration),
hasQuestion: !!val.declarations?.some(
d => d.getChildAt(1).kind === ts.SyntaxKind.QuestionToken
)
}))
.filter(({ type }) => type.isClass())
.filter(({ type }) => type?.isClass())

const reqFormat = props.find(p => p.name === 'reqFormat')
const isFormData =
(reqFormat &&
(reqFormat?.valueDeclaration &&
checker.typeToString(
checker.getTypeOfSymbolAtLocation(reqFormat, reqFormat.valueDeclaration)
)) === 'FormData'
const reqBody = props.find(p => p.name === 'reqBody')
const hooksTexts = ([
'onRequest',
'preParsing',
'preValidation',
'preHandler'
] as const)
const hooksTexts = (
['onRequest', 'preParsing', 'preValidation', 'preHandler'] as const
)
.map(key => {
if (key === 'preValidation') {
const texts = [
numberTypeQueryParams?.length
? query?.declarations.some(
? query?.declarations?.some(
d => d.getChildAt(1).kind === ts.SyntaxKind.QuestionToken
)
? `callParserIfExistsQuery(parseNumberTypeQueryParams([${numberTypeQueryParams.join(
Expand All @@ -427,27 +435,29 @@ export default (appDir: string, project: string) => {
: `parseNumberTypeQueryParams([${numberTypeQueryParams.join(', ')}])`
: '',
booleanTypeQueryParams?.length
? query?.declarations.some(
? query?.declarations?.some(
d => d.getChildAt(1).kind === ts.SyntaxKind.QuestionToken
)
? `callParserIfExistsQuery(parseBooleanTypeQueryParams([${booleanTypeQueryParams.join(
', '
)}]))`
: `parseBooleanTypeQueryParams([${booleanTypeQueryParams.join(', ')}])`
: '',
isFormData && reqBody
isFormData && reqBody?.valueDeclaration
? `formatMultipartData([${checker
.getTypeOfSymbolAtLocation(reqBody, reqBody.valueDeclaration)
.getProperties()
.map(p => {
const node = checker.typeToTypeNode(
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
undefined,
undefined
)
const node =
p.valueDeclaration &&
checker.typeToTypeNode(
checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration),
undefined,
undefined
)
return node && (ts.isArrayTypeNode(node) || ts.isTupleTypeNode(node))
? `['${p.name}', ${p.declarations.some(d =>
? `['${p.name}', ${!!p.declarations?.some(d =>
d
.getChildren()
.some(c => c.kind === ts.SyntaxKind.QuestionToken)
Expand All @@ -459,23 +469,23 @@ export default (appDir: string, project: string) => {
: '',
...genHookTexts('preValidation'),
...(query &&
[
...(numberTypeQueryParams ?? []),
...(booleanTypeQueryParams ?? [])
].some(t => t?.endsWith('true]')) &&
[...(numberTypeQueryParams ?? []), ...(booleanTypeQueryParams ?? [])].some(
t => t?.endsWith('true]')
) &&
validateInfo.length
? ['normalizeQuery']
: []),
validateInfo.length
? `createValidateHandler(req => [
${validateInfo
.map(
v =>
` ${
v.hasQuestion ? `Object.keys(req.${v.name} as any).length ? ` : ''
}validateOrReject(Object.assign(new Validators.${checker.typeToString(v.type)}(), req.${
v.name
} as any), validatorOptions)${v.hasQuestion ? ' : null' : ''}`
.map(v =>
v.type
? ` ${
v.hasQuestion ? `Object.keys(req.${v.name} as any).length ? ` : ''
}validateOrReject(Object.assign(new Validators.${checker.typeToString(v.type)}(), req.${
v.name
} as any), validatorOptions)${v.hasQuestion ? ' : null' : ''}`
: ''
)
.join(',\n')}\n ])`
: '',
Expand Down
Loading

0 comments on commit 52368ee

Please sign in to comment.