@trapi/metadata
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -0,8 +1,8 @@ | ||
import { MetadataGeneratorInterface } from '@trapi/decorator'; | ||
import { ClassDeclaration } from 'typescript'; | ||
import { EndpointGenerator } from './endpoint'; | ||
import { MetadataGenerator } from './index'; | ||
import { Controller } from '../type'; | ||
export declare class ControllerGenerator extends EndpointGenerator<ClassDeclaration> { | ||
private genMethods; | ||
constructor(node: ClassDeclaration, current: MetadataGenerator); | ||
constructor(node: ClassDeclaration, current: MetadataGeneratorInterface); | ||
isValid(): boolean; | ||
@@ -9,0 +9,0 @@ generate(): Controller; |
@@ -0,11 +1,10 @@ | ||
import { MapperIDProperties, MetadataGeneratorInterface } from '@trapi/decorator'; | ||
import { ArrayLiteralExpression, Node } from 'typescript'; | ||
import { Decorator } from '../decorator'; | ||
import { MetadataGenerator } from './index'; | ||
import { Response } from '../type'; | ||
export declare abstract class EndpointGenerator<T extends Node> { | ||
protected current: MetadataGenerator; | ||
protected current: MetadataGeneratorInterface; | ||
protected path: string | undefined; | ||
protected node: T; | ||
protected constructor(node: T, current: MetadataGenerator); | ||
protected generatePath(key: Extract<Decorator.Type, 'CLASS_PATH' | 'METHOD_PATH'>): void; | ||
protected constructor(node: T, current: MetadataGeneratorInterface); | ||
protected generatePath(key: Extract<keyof MapperIDProperties, 'CLASS_PATH' | 'METHOD_PATH'>): void; | ||
protected getDecoratorValues(decoratorName: string, acceptMultiple?: boolean): any[]; | ||
@@ -12,0 +11,0 @@ protected getSecurity(): { |
@@ -10,6 +10,4 @@ "use strict"; | ||
exports.EndpointGenerator = void 0; | ||
const decorator_1 = require("@trapi/decorator"); | ||
const typescript_1 = require("typescript"); | ||
const metadata_utils_1 = require("@trapi/metadata-utils"); | ||
const decorator_1 = require("../decorator"); | ||
const resolver_1 = require("../resolver"); | ||
const utils_1 = require("../utils"); | ||
@@ -32,3 +30,3 @@ class EndpointGenerator { | ||
} | ||
this.path = (0, metadata_utils_1.normalizePath)(values.join('/')); | ||
this.path = (0, utils_1.normalizePath)(values.join('/')); | ||
} | ||
@@ -83,7 +81,7 @@ // -------------------------------------------------------------------- | ||
argument.properties.forEach((p) => { | ||
example[p.name.text] = (0, resolver_1.getInitializerValue)(p.initializer, this.current.typeChecker); | ||
example[p.name.text] = (0, decorator_1.getInitializerValue)(p.initializer, this.current.typeChecker); | ||
}); | ||
} | ||
else { | ||
example = (0, resolver_1.getInitializerValue)(argument, this.current.typeChecker); | ||
example = (0, decorator_1.getInitializerValue)(argument, this.current.typeChecker); | ||
} | ||
@@ -107,3 +105,3 @@ return example; | ||
examples, | ||
schema: type ? new resolver_1.TypeNodeResolver(type, this.current).resolve() : undefined, | ||
schema: type ? new decorator_1.TypeNodeResolver(type, this.current).resolve() : undefined, | ||
status: status, | ||
@@ -157,3 +155,3 @@ name: status, | ||
isDeprecated(node) { | ||
if ((0, utils_1.isExistJSDocTag)(node, (tag) => tag.tagName.text === 'deprecated')) { | ||
if ((0, decorator_1.isExistJSDocTag)(node, (tag) => tag.tagName.text === 'deprecated')) { | ||
return true; | ||
@@ -160,0 +158,0 @@ } |
@@ -6,2 +6,3 @@ export * from './controller'; | ||
export * from './parameter'; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -28,2 +28,3 @@ "use strict"; | ||
__exportStar(require("./parameter"), exports); | ||
__exportStar(require("./utils"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,4 +1,4 @@ | ||
import { MetadataGeneratorInterface } from '@trapi/decorator'; | ||
import * as ts from 'typescript'; | ||
import { EndpointGenerator } from './endpoint'; | ||
import { MetadataGenerator } from './index'; | ||
import { Method } from '../type'; | ||
@@ -8,3 +8,3 @@ export declare class MethodGenerator extends EndpointGenerator<ts.MethodDeclaration> { | ||
private method; | ||
constructor(node: ts.MethodDeclaration, current: MetadataGenerator, controllerPath: string); | ||
constructor(node: ts.MethodDeclaration, current: MetadataGeneratorInterface, controllerPath: string); | ||
isValid(): boolean; | ||
@@ -11,0 +11,0 @@ getMethodName(): string; |
@@ -33,10 +33,8 @@ "use strict"; | ||
exports.MethodGenerator = void 0; | ||
const decorator_1 = require("@trapi/decorator"); | ||
const pathUtil = __importStar(require("path")); | ||
const ts = __importStar(require("typescript")); | ||
const metadata_utils_1 = require("@trapi/metadata-utils"); | ||
const decorator_1 = require("../decorator"); | ||
const utils_1 = require("../utils"); | ||
const endpoint_1 = require("./endpoint"); | ||
const parameter_1 = require("./parameter"); | ||
const resolver_1 = require("../resolver"); | ||
const utils_1 = require("../utils"); | ||
class MethodGenerator extends endpoint_1.EndpointGenerator { | ||
@@ -68,3 +66,3 @@ // -------------------------------------------------------------------- | ||
} | ||
const type = new resolver_1.TypeNodeResolver(nodeType, this.current).resolve(); | ||
const type = new decorator_1.TypeNodeResolver(nodeType, this.current).resolve(); | ||
const responses = this.mergeResponses(this.getResponses(), this.getMethodSuccessResponse(type)); | ||
@@ -75,3 +73,3 @@ return { | ||
deprecated: this.isDeprecated(this.node), | ||
description: (0, utils_1.getJSDocDescription)(this.node), | ||
description: (0, decorator_1.getJSDocDescription)(this.node), | ||
extensions: [], | ||
@@ -86,3 +84,3 @@ hidden: this.isHidden(this.node), | ||
security: this.getSecurity(), | ||
summary: (0, utils_1.getJSDocTagComment)(this.node, 'summary'), | ||
summary: (0, decorator_1.getJSDocTagComment)(this.node, 'summary'), | ||
tags: this.getTags(), | ||
@@ -135,11 +133,11 @@ type, | ||
return { | ||
description: resolver_1.Resolver.isVoidType(type) ? 'No content' : 'Ok', | ||
description: (0, decorator_1.isVoidType)(type) ? 'No content' : 'Ok', | ||
examples: this.getMethodSuccessExamples(), | ||
schema: type, | ||
status: resolver_1.Resolver.isVoidType(type) ? '204' : '200', | ||
name: resolver_1.Resolver.isVoidType(type) ? '204' : '200', | ||
status: (0, decorator_1.isVoidType)(type) ? '204' : '200', | ||
name: (0, decorator_1.isVoidType)(type) ? '204' : '200', | ||
}; | ||
} | ||
getMethodSuccessResponseType(type) { | ||
if (!resolver_1.Resolver.isVoidType(type)) { | ||
if (!(0, decorator_1.isVoidType)(type)) { | ||
return type; | ||
@@ -153,5 +151,5 @@ } | ||
if (typeof value !== 'undefined' && | ||
(0, metadata_utils_1.hasOwnProperty)(value, 'kind') && | ||
(0, utils_1.hasOwnProperty)(value, 'kind') && | ||
ts.isTypeNode(value)) { | ||
type = new resolver_1.TypeNodeResolver(value, this.current).resolve(); | ||
type = new decorator_1.TypeNodeResolver(value, this.current).resolve(); | ||
} | ||
@@ -158,0 +156,0 @@ return type; |
@@ -0,9 +1,8 @@ | ||
import { DependencyResolver, Mapper, MetadataGeneratorInterface, ReferenceType } from '@trapi/decorator'; | ||
import { CompilerOptions, Node, TypeChecker } from 'typescript'; | ||
import { Config, GeneratorOutput } from '../type'; | ||
import { DecoratorMapper } from '../decorator'; | ||
import { Resolver } from '../resolver'; | ||
export declare class MetadataGenerator { | ||
export declare class MetadataGenerator implements MetadataGeneratorInterface { | ||
readonly nodes: Node[]; | ||
readonly typeChecker: TypeChecker; | ||
readonly decoratorMapper: DecoratorMapper; | ||
readonly decoratorMapper: Mapper; | ||
readonly config: Config; | ||
@@ -33,5 +32,5 @@ private readonly program; | ||
isExportedNode(node: Node): boolean; | ||
addReferenceType(referenceType: Resolver.ReferenceType): void; | ||
getReferenceType(refName: string): Resolver.ReferenceType; | ||
registerDependencyResolver(callback: Resolver.DependencyResolver): void; | ||
addReferenceType(referenceType: ReferenceType): void; | ||
getReferenceType(refName: string): ReferenceType; | ||
registerDependencyResolver(callback: DependencyResolver): void; | ||
getClassDeclaration(className: string): Node; | ||
@@ -38,0 +37,0 @@ getInterfaceDeclaration(className: string): Node; |
@@ -8,21 +8,23 @@ "use strict"; | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MetadataGenerator = void 0; | ||
const decorator_1 = require("@trapi/decorator"); | ||
const minimatch_1 = __importDefault(require("minimatch")); | ||
const glob_1 = require("glob"); | ||
const typescript_1 = require("typescript"); | ||
const decorator_1 = require("../decorator"); | ||
const controller_1 = require("./controller"); | ||
const resolver_1 = require("../resolver"); | ||
const cache_1 = require("../cache"); | ||
const minimatch = require('minimatch'); | ||
class MetadataGenerator { | ||
// ------------------------------------------------------------------------- | ||
constructor(config, compilerOptions) { | ||
this.nodes = new Array(); | ||
this.referenceTypes = {}; | ||
this.circularDependencyResolvers = new Array(); | ||
this.nodes = []; | ||
this.config = config; | ||
this.cache = new cache_1.CacheDriver(config.cache); | ||
this.decoratorMapper = new decorator_1.DecoratorMapper(config.decorator); | ||
resolver_1.TypeNodeResolver.clearCache(); | ||
this.decoratorMapper = new decorator_1.Mapper(config.decorator); | ||
decorator_1.TypeNodeResolver.clearCache(); | ||
const sourceFiles = this.scanSourceFiles(config.entryFile); | ||
@@ -90,3 +92,3 @@ this.program = (0, typescript_1.createProgram)(sourceFiles, compilerOptions); | ||
} | ||
return this.config.ignore.some((item) => minimatch(filePath, item)); | ||
return this.config.ignore.some((item) => (0, minimatch_1.default)(filePath, item)); | ||
} | ||
@@ -103,3 +105,3 @@ /** | ||
} | ||
return this.config.allow.some((item) => minimatch(filePath, item)); | ||
return this.config.allow.some((item) => (0, minimatch_1.default)(filePath, item)); | ||
} | ||
@@ -106,0 +108,0 @@ // ------------------------------------------------------------------------- |
@@ -0,3 +1,3 @@ | ||
import { MetadataGeneratorInterface } from '@trapi/decorator'; | ||
import * as ts from 'typescript'; | ||
import { MetadataGenerator } from './index'; | ||
import { Parameter } from '../type'; | ||
@@ -9,3 +9,3 @@ export declare class ParameterGenerator { | ||
private readonly current; | ||
constructor(parameter: ts.ParameterDeclaration, method: string, path: string, current: MetadataGenerator); | ||
constructor(parameter: ts.ParameterDeclaration, method: string, path: string, current: MetadataGeneratorInterface); | ||
generate(): Parameter; | ||
@@ -12,0 +12,0 @@ private getCurrentLocation; |
@@ -33,5 +33,4 @@ "use strict"; | ||
exports.ParameterGenerator = void 0; | ||
const decorator_1 = require("@trapi/decorator"); | ||
const ts = __importStar(require("typescript")); | ||
const resolver_1 = require("../resolver"); | ||
const node_1 = require("../decorator/utils/node"); | ||
const supportedParameterKeys = [ | ||
@@ -56,3 +55,3 @@ 'SERVER_CONTEXT', | ||
generate() { | ||
const decorators = (0, node_1.getNodeDecorators)(this.parameter); | ||
const decorators = (0, decorator_1.getNodeDecorators)(this.parameter); | ||
for (let i = 0; i < supportedParameterKeys.length; i++) { | ||
@@ -260,6 +259,10 @@ const representation = this.current.decoratorMapper.match(supportedParameterKeys[i], decorators); | ||
} else { | ||
throw new InvalidParameterException(`Parameter '${parameterName}' can't be passed as a query parameter in '${this.getCurrentLocation()}'.`); | ||
throw new InvalidParameterException( | ||
`Parameter '${parameterName}' can't be passed as a query parameter in '${this.getCurrentLocation()}'.` | ||
); | ||
} | ||
*/ | ||
// throw new InvalidParameterException(`Parameter '${parameterName}' can't be passed as a query parameter in '${this.getCurrentLocation()}'.`); | ||
// throw new InvalidParameterException( | ||
// `Parameter '${parameterName}' can't be passed as a query parameter in '${this.getCurrentLocation()}'.` | ||
// ); | ||
} | ||
@@ -279,3 +282,3 @@ let name = parameterName; | ||
collectionFormat: options.collectionFormat, | ||
default: (0, resolver_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type), | ||
default: (0, decorator_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type), | ||
description: this.getParameterDescription(this.parameter), | ||
@@ -345,3 +348,3 @@ in: 'query', | ||
} | ||
return new resolver_1.TypeNodeResolver(typeNode, this.current, parameter).resolve(); | ||
return new decorator_1.TypeNodeResolver(typeNode, this.current, parameter).resolve(); | ||
} | ||
@@ -348,0 +351,0 @@ } |
export * from './cache'; | ||
export * from './decorator'; | ||
export * from './generator'; | ||
export * from './resolver'; | ||
export * from './module'; | ||
export * from './utils'; | ||
export * from './type'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -24,7 +24,6 @@ "use strict"; | ||
__exportStar(require("./cache"), exports); | ||
__exportStar(require("./decorator"), exports); | ||
__exportStar(require("./generator"), exports); | ||
__exportStar(require("./resolver"), exports); | ||
__exportStar(require("./module"), exports); | ||
__exportStar(require("./utils"), exports); | ||
__exportStar(require("./type"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,4 +1,3 @@ | ||
import { ArrayType, BaseType, Config as DecoratorConfig, NestedObjectLiteralType, RefObjectType, ReferenceTypes } from '@trapi/decorator'; | ||
import { CompilerOptions } from 'typescript'; | ||
import { Resolver } from './resolver'; | ||
import { Decorator } from './decorator'; | ||
import { Cache } from './cache'; | ||
@@ -33,3 +32,3 @@ export { CompilerOptions, }; | ||
*/ | ||
decorator?: Decorator.Config; | ||
decorator?: DecoratorConfig; | ||
} | ||
@@ -49,3 +48,3 @@ /** | ||
*/ | ||
referenceTypes: Resolver.ReferenceTypes; | ||
referenceTypes: ReferenceTypes; | ||
} | ||
@@ -104,3 +103,3 @@ export interface Controller { | ||
path: string; | ||
type: Resolver.BaseType; | ||
type: BaseType; | ||
tags: string[]; | ||
@@ -128,3 +127,3 @@ responses: Response[]; | ||
required: boolean; | ||
type: Resolver.BaseType; | ||
type: BaseType; | ||
collectionFormat?: 'csv' | 'multi' | 'pipes' | 'ssv' | 'tsv'; | ||
@@ -140,3 +139,3 @@ allowEmptyValue?: boolean; | ||
export interface ArrayParameter extends Parameter { | ||
type: Resolver.ArrayType; | ||
type: ArrayType; | ||
} | ||
@@ -147,24 +146,10 @@ export interface Validator { | ||
} | ||
export interface Property { | ||
default?: any; | ||
format?: string; | ||
example?: unknown; | ||
validators?: Record<string, { | ||
value?: any; | ||
message?: string; | ||
}>; | ||
description?: string; | ||
name: string; | ||
type: Resolver.Type; | ||
required: boolean; | ||
deprecated: boolean; | ||
} | ||
export interface Response { | ||
description: string; | ||
examples?: unknown[] | unknown; | ||
headers?: Resolver.NestedObjectLiteralType | Resolver.RefObjectType; | ||
headers?: NestedObjectLiteralType | RefObjectType; | ||
name: string; | ||
status: string; | ||
schema?: Resolver.BaseType; | ||
schema?: BaseType; | ||
} | ||
//# sourceMappingURL=type.d.ts.map |
@@ -1,4 +0,5 @@ | ||
export * from './generator'; | ||
export * from './js-doc'; | ||
export * from './object'; | ||
export * from './path'; | ||
export * from './typescript'; | ||
export * from './validator'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -23,5 +23,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./generator"), exports); | ||
__exportStar(require("./js-doc"), exports); | ||
__exportStar(require("./object"), exports); | ||
__exportStar(require("./path"), exports); | ||
__exportStar(require("./typescript"), exports); | ||
__exportStar(require("./validator"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
const yup_1 = require("yup"); | ||
const validator_1 = require("../decorator/utils/validator"); | ||
const decorator_1 = require("@trapi/decorator"); | ||
let validatorInstance; | ||
@@ -35,3 +35,3 @@ function useConfigValidator() { | ||
ignore: (0, yup_1.array)((0, yup_1.string)()).optional().default(undefined), | ||
decorator: (0, validator_1.useDecoratorConfigValidator)(), | ||
decorator: (0, decorator_1.useConfigValidator)(), | ||
}); | ||
@@ -38,0 +38,0 @@ return validatorInstance; |
{ | ||
"name": "@trapi/metadata", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Generate REST-API metadata scheme from TypeScript Decorators.", | ||
@@ -34,3 +34,4 @@ "main": "./dist/index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/Tada5hi/trapi.git" | ||
"url": "git+https://github.com/Tada5hi/trapi.git", | ||
"directory": "packagesA/metadata" | ||
}, | ||
@@ -42,12 +43,12 @@ "bugs": { | ||
"devDependencies": { | ||
"@types/glob": "^7.2.0", | ||
"@types/minimatch": "^3.0.5", | ||
"@types/yup": "^0.29.14", | ||
"@types/glob": "^8.0.0", | ||
"@types/minimatch": "^5.1.2", | ||
"@types/yup": "^0.32.0", | ||
"jsonata": "^1.8.6" | ||
}, | ||
"dependencies": { | ||
"@trapi/metadata-utils": "^0.1.0", | ||
"@trapi/decorator": "^0.0.2", | ||
"glob": "^8.0.3", | ||
"minimatch": "^5.1.0", | ||
"typescript": "^4.7.4", | ||
"typescript": "^4.8.4", | ||
"yup": "^0.32.11" | ||
@@ -58,3 +59,3 @@ }, | ||
}, | ||
"gitHead": "d59081f635380a76aabe902ddb5a6f8ac102eb26" | ||
"gitHead": "769f19ac38122c322327fe2ab7633306115cdf5f" | ||
} |
@@ -20,2 +20,3 @@ # @trapi/metadata 📚 | ||
- [Structure](#structure) | ||
- [License](#license) | ||
@@ -34,3 +35,4 @@ ## Installation | ||
```typescript | ||
import {Decorator, Cache} from '@trapi/metadata'; | ||
import { Config } from '@trapi/decorator'; | ||
import { Cache } from '@trapi/metadata'; | ||
@@ -60,3 +62,3 @@ export interface Config { | ||
*/ | ||
decorator?: Decorator.Config; | ||
decorator?: Config; | ||
} | ||
@@ -104,34 +106,2 @@ ``` | ||
### Decorator | ||
The decorator configuration is relative complex and is not described in detail here yet. | ||
Please read the `source code` and the according `tests` for better understanding. | ||
- Tests: | ||
- `test/unit/decorator/mapper/index.spec.ts` | ||
- `test/unit/decorator/representation/index.spec.ts` | ||
- Code: | ||
- `src/decorator/**/*.ts` | ||
If you are the author (or contributor) of a TypeScript Decorator API library and need help to set things up, feel free to open an Issue and ask for help. | ||
```typescript | ||
export interface Config { | ||
/** | ||
* Use a pre defined third party TypeRepresentationMap in full scope or | ||
* only use a partial amount of defined type representations. | ||
* | ||
* Default: [] | ||
*/ | ||
library?: ConfigLibrary; | ||
/** | ||
* Use all internal defined type representations or only use a subset. | ||
* Default: true | ||
*/ | ||
internal?: TypeRepresentationConfig; | ||
/** | ||
* Set up self defined type representations. | ||
*/ | ||
map?: Partial<TypeRepresentationMap>; | ||
} | ||
``` | ||
## Limitations | ||
@@ -178,1 +148,7 @@ At the moment only the following TypeScript UtilityTypes are supported: | ||
**coming soon** | ||
## License | ||
Made with 💚 | ||
Published under [MIT License](./LICENSE). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
125000
87
1735
150
1
+ Added@trapi/decorator@^0.0.2
+ Added@trapi/decorator@0.0.2(transitive)
- Removed@trapi/metadata-utils@^0.1.0
- Removed@trapi/metadata-utils@0.1.0(transitive)
Updatedtypescript@^4.8.4