-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use metadata-booster #616
Use metadata-booster #616
Changes from all commits
f1b6caa
1d5679f
1d0b366
ac31188
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ | |
"mock-jwks": "^0.3.1", | ||
"nock": "^13.0.4", | ||
"sinon": "9.2.3", | ||
"sinon-chai": "3.5.0" | ||
"sinon-chai": "3.5.0", | ||
"metadata-booster": "0.3.1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this package should live together with the framework? Also it should have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer it not to live in the framework repository, as this can be used by anyone in any project (I mean the transformer code) However, I agree with you that we can add the @boostercloud namespace. Let's see if I can change that |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
import { PropertyMetadata, Class, AnyClass } from '@boostercloud/framework-types' | ||
import { Class } from '@boostercloud/framework-types' | ||
import { ClassMetadata, PropertyMetadata } from 'metadata-booster' | ||
import 'reflect-metadata' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function getPropertiesMetadata(classType: Class<any>): Array<PropertyMetadata> { | ||
const propertyNames = Object.getOwnPropertyNames(new classType()) | ||
const propertyTypes = Reflect.getMetadata('design:paramtypes', classType) | ||
if (propertyNames.length != propertyTypes.length) { | ||
const meta: ClassMetadata = Reflect.getMetadata('booster:typeinfo', classType) | ||
if (!meta) { | ||
// eslint-disable-next-line prettier/prettier | ||
throw new Error(`Could not get proper metadata information of ${classType.name}. While inspecting the class, the following properties were found: | ||
> ${propertyNames.join(', ')} | ||
But its constructor parameters have the following types: | ||
> ${propertyTypes.map((type: AnyClass) => type.name).join(', ')} | ||
They mismatch. Make sure you define all properties as "constructor parameter properties" (see https://www.typescriptlang.org/docs/handbook/classes.html#parameter-properties) | ||
`) | ||
throw new Error(`Could not get proper metadata information of ${classType.name}`) | ||
} | ||
|
||
return propertyNames.map((propertyName, index) => ({ | ||
name: propertyName, | ||
type: propertyTypes[index], | ||
})) | ||
return meta.fields | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"emitDecoratorMetadata": true, | ||
"outDir": "./dist", | ||
"rootDir": "./src" | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
], | ||
"ts-node": { | ||
"compiler": "ttypescript", | ||
"compilerOptions": { | ||
"plugins": [ | ||
{ | ||
"transform": "metadata-booster" | ||
} | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,9 @@ | |
"faker": "5.1.0", | ||
"graphql-tag": "^2.10.3", | ||
"subscriptions-transport-ws": "^0.9.16", | ||
"ws": "^7.3.0" | ||
"ws": "^7.3.0", | ||
"ttypescript": "1.5.12", | ||
"metadata-booster": "0.3.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
|
@@ -46,7 +48,7 @@ | |
"watch:local": "nodemon --watch ../framework-provider-local/dist --watch ../framework-provider-local-infrastructure --watch dist --exec \"../cli/bin/run start -e local\"", | ||
"lint:check": "eslint --ext '.js,.ts' **/*.ts", | ||
"lint:fix": "eslint --quiet --fix --ext '.js,.ts' **/*.ts", | ||
"compile": "tsc -b tsconfig.json", | ||
"compile": "npx ttsc -b tsconfig.json", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, better use |
||
"clean": "npx rimraf ./dist tsconfig.tsbuildinfo", | ||
"integration": "npm run integration/cli && npm run integration/local && npm run integration/aws-deploy && npm run integration/aws-func && npm run integration/end-to-end && npm run integration/aws-nuke", | ||
"integration/aws-deploy": "AWS_SDK_LOAD_CONFIG=true mocha --forbid-only --exit --config \"integration/providers/aws/deployment/.mocharc.yml\" \"integration/providers/aws/deployment/**/*.integration.ts\"", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using
ttypescript
and having to use the explicit wrapperttsc
it's better to usets-patch
as it patches your current typescript with support for transformers, so the rest stays the same. Oh, and supports pre-typecheck transformers!