@trapi/metadata
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -1,2 +0,2 @@ | ||
import { Cache } from "./type"; | ||
import { Cache } from './type'; | ||
export declare class CacheDriver { | ||
@@ -3,0 +3,0 @@ private readonly config; |
@@ -32,6 +32,6 @@ "use strict"; | ||
exports.CacheDriver = void 0; | ||
const utils_1 = require("./utils"); | ||
const fs_1 = __importDefault(require("fs")); | ||
const glob = __importStar(require("glob")); | ||
const path_1 = __importDefault(require("path")); | ||
const utils_1 = require("./utils"); | ||
class CacheDriver { | ||
@@ -85,3 +85,3 @@ constructor(config) { | ||
const files = glob.sync(this.buildFilePath('**')); | ||
files.map(file => fs_1.default.unlinkSync(file)); | ||
files.map((file) => fs_1.default.unlinkSync(file)); | ||
} | ||
@@ -96,5 +96,3 @@ // ------------------------------------------------------------------------- | ||
} | ||
else { | ||
return `.swagger-${hash !== null && hash !== void 0 ? hash : (0, utils_1.buildFileHash)(sourceFilesSize)}.json`; | ||
} | ||
return `.swagger-${hash !== null && hash !== void 0 ? hash : (0, utils_1.buildFileHash)(sourceFilesSize)}.json`; | ||
} | ||
@@ -101,0 +99,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { GeneratorOutput } from "../type"; | ||
import { GeneratorOutput } from '../type'; | ||
export declare namespace Cache { | ||
@@ -3,0 +3,0 @@ interface Config { |
@@ -1,4 +0,4 @@ | ||
import { Cache } from "./type"; | ||
import { Cache } from './type'; | ||
export declare function buildCacheConfig(config?: string | boolean | Partial<Cache.Config>): Cache.Config; | ||
export declare function buildFileHash(sourceFilesSize?: number): string; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
enabled: true, | ||
directoryPath: config | ||
directoryPath: config, | ||
}; | ||
@@ -26,3 +26,3 @@ } | ||
config = { | ||
enabled: config | ||
enabled: config, | ||
}; | ||
@@ -39,3 +39,3 @@ } | ||
enabled: (_a = config.enabled) !== null && _a !== void 0 ? _a : false, | ||
clearAtRandom: (_b = config.clearAtRandom) !== null && _b !== void 0 ? _b : !isTestEnvironment | ||
clearAtRandom: (_b = config.clearAtRandom) !== null && _b !== void 0 ? _b : !isTestEnvironment, | ||
}; | ||
@@ -42,0 +42,0 @@ } |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/* | ||
@@ -7,3 +8,2 @@ * Copyright (c) 2021. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,3 +15,3 @@ exports.IsDouble = exports.IsFloat = exports.IsLong = exports.IsInt = exports.SwaggerDeprecated = exports.SwaggerHidden = exports.SwaggerTags = exports.ResponseProduces = exports.ResponseExample = exports.ResponseDescription = exports.RequestFileParam = exports.RequestConsumes = void 0; | ||
function RequestConsumes(...values) { | ||
return () => { return; }; | ||
return () => { }; | ||
} | ||
@@ -27,3 +27,3 @@ exports.RequestConsumes = RequestConsumes; | ||
function RequestFileParam(key) { | ||
return () => { return; }; | ||
return () => { }; | ||
} | ||
@@ -55,3 +55,3 @@ exports.RequestFileParam = RequestFileParam; | ||
function ResponseDescription(name, description, example) { | ||
return () => { return; }; | ||
return () => { }; | ||
} | ||
@@ -77,3 +77,3 @@ exports.ResponseDescription = ResponseDescription; | ||
function ResponseExample(example) { | ||
return () => { return; }; | ||
return () => { }; | ||
} | ||
@@ -85,3 +85,3 @@ exports.ResponseExample = ResponseExample; | ||
function ResponseProduces(...values) { | ||
return () => { return; }; | ||
return () => { }; | ||
} | ||
@@ -104,3 +104,3 @@ exports.ResponseProduces = ResponseProduces; | ||
function SwaggerTags(...values) { | ||
return () => { return; }; | ||
return () => { }; | ||
} | ||
@@ -112,3 +112,3 @@ exports.SwaggerTags = SwaggerTags; | ||
function SwaggerHidden() { | ||
return () => { return; }; | ||
return () => { }; | ||
} | ||
@@ -120,3 +120,3 @@ exports.SwaggerHidden = SwaggerHidden; | ||
function SwaggerDeprecated() { | ||
return () => { return; }; | ||
return () => { }; | ||
} | ||
@@ -128,3 +128,2 @@ exports.SwaggerDeprecated = SwaggerDeprecated; | ||
function IsInt(target, propertyKey, parameterIndex) { | ||
return; | ||
} | ||
@@ -136,3 +135,2 @@ exports.IsInt = IsInt; | ||
function IsLong(target, propertyKey, parameterIndex) { | ||
return; | ||
} | ||
@@ -144,3 +142,2 @@ exports.IsLong = IsLong; | ||
function IsFloat(target, propertyKey, parameterIndex) { | ||
return; | ||
} | ||
@@ -153,5 +150,4 @@ exports.IsFloat = IsFloat; | ||
function IsDouble(target, propertyKey, parameterIndex) { | ||
return; | ||
} | ||
exports.IsDouble = IsDouble; | ||
//# sourceMappingURL=functions.js.map |
@@ -6,3 +6,3 @@ export * from './mapper'; | ||
export * from './type'; | ||
export * from "./utils"; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,4 +0,4 @@ | ||
import { Node } from "typescript"; | ||
import { RepresentationManager } from "../representation"; | ||
import { Decorator } from "../type"; | ||
import { Node } from 'typescript'; | ||
import { RepresentationManager } from '../representation'; | ||
import { Decorator } from '../type'; | ||
export declare class DecoratorMapper { | ||
@@ -5,0 +5,0 @@ protected config?: Decorator.Config; |
@@ -37,3 +37,3 @@ "use strict"; | ||
for (let i = 0; i < representations.length; i++) { | ||
const items = decorators.filter(decorator => decorator.text === representations[i].id); | ||
const items = decorators.filter((decorator) => decorator.text === representations[i].id); | ||
if (items.length > 0) { | ||
@@ -56,5 +56,3 @@ return new representation_1.RepresentationManager(representations[i], items); | ||
internalMap : | ||
(0, utils_1.reduceTypeRepresentationMapping)(internalMap, (type) => { | ||
return (0, utils_1.isMappingTypeIncluded)(type, this.config.internal); | ||
})); | ||
(0, utils_1.reduceTypeRepresentationMapping)(internalMap, (type) => (0, utils_1.isMappingTypeIncluded)(type, this.config.internal))); | ||
// mapping - extension | ||
@@ -72,3 +70,3 @@ if (typeof this.config.map !== 'undefined') { | ||
[this.config.library]; | ||
items.push(...libraries.map(library => (0, utils_1.getDecoratorMap)(library))); | ||
items.push(...libraries.map((library) => (0, utils_1.getDecoratorMap)(library))); | ||
} | ||
@@ -78,5 +76,3 @@ else { | ||
for (const key in this.config.library) { | ||
items.push((0, utils_1.reduceTypeRepresentationMapping)((0, utils_1.getDecoratorMap)(key), (type) => { | ||
return (0, utils_1.isMappingTypeIncluded)(type, this.config.library[key]); | ||
})); | ||
items.push((0, utils_1.reduceTypeRepresentationMapping)((0, utils_1.getDecoratorMap)(key), (type) => (0, utils_1.isMappingTypeIncluded)(type, this.config.library[key]))); | ||
} | ||
@@ -97,3 +93,3 @@ } | ||
let keys = mappings | ||
.map(mapping => Object.keys(mapping)) | ||
.map((mapping) => Object.keys(mapping)) | ||
.reduce(((previousValue, currentValue) => [...previousValue, ...currentValue])); | ||
@@ -100,0 +96,0 @@ keys = Array.from(new Set(keys)); |
@@ -1,4 +0,4 @@ | ||
import { Decorator } from "../../type"; | ||
import { Decorator } from '../../type'; | ||
declare const _default: Partial<Decorator.TypeRepresentationMap>; | ||
export default _default; | ||
//# sourceMappingURL=decorators-express.d.ts.map |
@@ -14,4 +14,4 @@ "use strict"; | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -23,4 +23,4 @@ // Method | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -30,4 +30,4 @@ { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -37,4 +37,4 @@ { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -44,4 +44,4 @@ { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -51,4 +51,4 @@ { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -58,4 +58,4 @@ { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -65,4 +65,4 @@ { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -72,5 +72,5 @@ { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
], | ||
@@ -81,11 +81,11 @@ // Parameter | ||
id: 'Request', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
{ | ||
id: 'Response', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
{ | ||
id: 'Next', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
@@ -96,4 +96,4 @@ ], | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -104,4 +104,4 @@ SERVER_FORM: undefined, | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -111,4 +111,4 @@ SERVER_HEADERS: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -118,4 +118,4 @@ SERVER_COOKIES: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -125,6 +125,6 @@ SERVER_PATH_PARAMS: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
}; | ||
//# sourceMappingURL=decorators-express.js.map |
@@ -1,4 +0,4 @@ | ||
import { Decorator } from "../../type"; | ||
import { Decorator } from '../../type'; | ||
declare const _default: Partial<Decorator.TypeRepresentationMap>; | ||
export default _default; | ||
//# sourceMappingURL=internal.d.ts.map |
@@ -13,5 +13,5 @@ "use strict"; | ||
properties: { | ||
KEY: { type: "element", srcArgumentType: "argument", srcPosition: 0 }, | ||
VALUE: { type: "element", srcArgumentType: "argument", srcPosition: 1 } | ||
} | ||
KEY: { type: 'element', srcArgumentType: 'argument', srcPosition: 0 }, | ||
VALUE: { type: 'element', srcArgumentType: 'argument', srcPosition: 1 }, | ||
}, | ||
}, | ||
@@ -22,4 +22,4 @@ // Class | ||
properties: { | ||
DEFAULT: { type: 'array', srcArgumentType: "argument" } | ||
} | ||
DEFAULT: { type: 'array', srcArgumentType: 'argument' }, | ||
}, | ||
}, | ||
@@ -30,5 +30,5 @@ // Class + Method | ||
properties: { | ||
TYPE: { isType: true, srcArgumentType: "typeArgument" }, | ||
PAYLOAD: { type: "element", srcArgumentType: "argument", srcPosition: 0 } | ||
} | ||
TYPE: { isType: true, srcArgumentType: 'typeArgument' }, | ||
PAYLOAD: { type: 'element', srcArgumentType: 'argument', srcPosition: 0 }, | ||
}, | ||
}, | ||
@@ -38,7 +38,7 @@ RESPONSE_DESCRIPTION: { | ||
properties: { | ||
TYPE: { isType: true, srcArgumentType: "typeArgument" }, | ||
STATUS_CODE: { type: "element", srcArgumentType: "argument", srcPosition: 0 }, | ||
DESCRIPTION: { type: "element", srcArgumentType: "argument", srcPosition: 1 }, | ||
PAYLOAD: { type: "element", srcArgumentType: "argument", srcPosition: 2 } | ||
} | ||
TYPE: { isType: true, srcArgumentType: 'typeArgument' }, | ||
STATUS_CODE: { type: 'element', srcArgumentType: 'argument', srcPosition: 0 }, | ||
DESCRIPTION: { type: 'element', srcArgumentType: 'argument', srcPosition: 1 }, | ||
PAYLOAD: { type: 'element', srcArgumentType: 'argument', srcPosition: 2 }, | ||
}, | ||
}, | ||
@@ -48,4 +48,6 @@ REQUEST_CONSUMES: { | ||
properties: { | ||
DEFAULT: { type: 'array', srcArgumentType: "argument", srcAmount: -1, srcStrategy: "merge" } | ||
} | ||
DEFAULT: { | ||
type: 'array', srcArgumentType: 'argument', srcAmount: -1, srcStrategy: 'merge', | ||
}, | ||
}, | ||
}, | ||
@@ -55,28 +57,30 @@ RESPONSE_PRODUCES: { | ||
properties: { | ||
DEFAULT: { type: 'array', srcArgumentType: "argument", srcAmount: -1, srcStrategy: "merge" } | ||
} | ||
DEFAULT: { | ||
type: 'array', srcArgumentType: 'argument', srcAmount: -1, srcStrategy: 'merge', | ||
}, | ||
}, | ||
}, | ||
HIDDEN: { | ||
id: 'SwaggerHidden', | ||
properties: [] | ||
properties: [], | ||
}, | ||
DEPRECATED: { | ||
id: 'SwaggerDeprecated', | ||
properties: undefined | ||
properties: undefined, | ||
}, | ||
IS_INT: { | ||
id: 'IsInt', | ||
properties: undefined | ||
properties: undefined, | ||
}, | ||
IS_LONG: { | ||
id: 'IsLong', | ||
properties: undefined | ||
properties: undefined, | ||
}, | ||
IS_FlOAT: { | ||
id: 'IsFloat', | ||
properties: undefined | ||
properties: undefined, | ||
}, | ||
IS_DOUBLE: { | ||
id: 'IsDouble', | ||
properties: undefined | ||
properties: undefined, | ||
}, | ||
@@ -86,4 +90,4 @@ SERVER_FILES_PARAM: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -93,6 +97,6 @@ SERVER_FILE_PARAM: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
}; | ||
//# sourceMappingURL=internal.js.map |
@@ -1,4 +0,4 @@ | ||
import { Decorator } from "../../type"; | ||
import { Decorator } from '../../type'; | ||
declare const _default: Partial<Decorator.TypeRepresentationMap>; | ||
export default _default; | ||
//# sourceMappingURL=typescript-rest.d.ts.map |
@@ -14,4 +14,4 @@ "use strict"; | ||
properties: { | ||
DEFAULT: { type: 'element', srcArgumentType: "argument" } | ||
} | ||
DEFAULT: { type: 'element', srcArgumentType: 'argument' }, | ||
}, | ||
}, | ||
@@ -23,5 +23,5 @@ // Class + Method | ||
properties: { | ||
TYPE: { isType: true, srcArgumentType: "typeArgument" }, | ||
PAYLOAD: { type: "element", srcArgumentType: "argument" } | ||
} | ||
TYPE: { isType: true, srcArgumentType: 'typeArgument' }, | ||
PAYLOAD: { type: 'element', srcArgumentType: 'argument' }, | ||
}, | ||
}, | ||
@@ -31,7 +31,7 @@ RESPONSE_DESCRIPTION: { | ||
properties: { | ||
TYPE: { type: "element", srcArgumentType: "typeArgument" }, | ||
STATUS_CODE: { type: "element", srcArgumentType: "argument", srcPosition: 0 }, | ||
DESCRIPTION: { type: "element", srcArgumentType: "argument", srcPosition: 1 }, | ||
PAYLOAD: { type: "element", srcArgumentType: "argument", srcPosition: 2 } | ||
} | ||
TYPE: { type: 'element', srcArgumentType: 'typeArgument' }, | ||
STATUS_CODE: { type: 'element', srcArgumentType: 'argument', srcPosition: 0 }, | ||
DESCRIPTION: { type: 'element', srcArgumentType: 'argument', srcPosition: 1 }, | ||
PAYLOAD: { type: 'element', srcArgumentType: 'argument', srcPosition: 2 }, | ||
}, | ||
}, | ||
@@ -41,31 +41,31 @@ // Method | ||
id: 'ALL', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
GET: { | ||
id: 'GET', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
POST: { | ||
id: 'POST', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
PUT: { | ||
id: 'PUT', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
DELETE: { | ||
id: 'DELETE', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
PATCH: { | ||
id: 'PATCH', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
OPTIONS: { | ||
id: 'OPTIONS', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
HEAD: { | ||
id: 'HEAD', | ||
properties: {} | ||
properties: {}, | ||
}, | ||
@@ -75,4 +75,4 @@ METHOD_PATH: { | ||
properties: { | ||
DEFAULT: { type: 'element', srcArgumentType: "argument" } | ||
} | ||
DEFAULT: { type: 'element', srcArgumentType: 'argument' }, | ||
}, | ||
}, | ||
@@ -98,3 +98,3 @@ // Parameter | ||
id: 'ContextAccept', | ||
} | ||
}, | ||
], | ||
@@ -104,4 +104,4 @@ SERVER_PARAMS: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -111,4 +111,4 @@ SERVER_QUERY: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -118,4 +118,4 @@ SERVER_FORM: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -126,4 +126,4 @@ SERVER_BODY: undefined, | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -133,4 +133,4 @@ SERVER_COOKIES: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -140,4 +140,4 @@ SERVER_PATH_PARAMS: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -147,4 +147,4 @@ SERVER_FILES_PARAM: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
@@ -154,6 +154,6 @@ SERVER_FILE_PARAM: { | ||
properties: { | ||
DEFAULT: {} | ||
} | ||
} | ||
DEFAULT: {}, | ||
}, | ||
}, | ||
}; | ||
//# sourceMappingURL=typescript-rest.js.map |
@@ -1,2 +0,2 @@ | ||
import { Decorator } from "../type"; | ||
import { Decorator } from '../type'; | ||
/** | ||
@@ -3,0 +3,0 @@ * |
@@ -54,3 +54,3 @@ "use strict"; | ||
exports.isMappingTypeIncluded = isMappingTypeIncluded; | ||
let decoratorMap = {}; | ||
const decoratorMap = {}; | ||
function getDecoratorMap(name) { | ||
@@ -57,0 +57,0 @@ if ((0, metadata_utils_1.hasOwnProperty)(decoratorMap, name)) { |
@@ -1,2 +0,2 @@ | ||
import { Decorator } from "../type"; | ||
import { Decorator } from '../type'; | ||
import TypePropertyMaps = Decorator.TypePropertyMap; | ||
@@ -3,0 +3,0 @@ export declare class RepresentationManager<T extends Decorator.Type> { |
@@ -1,2 +0,2 @@ | ||
import { Decorator } from "../../type"; | ||
import { Decorator } from '../../type'; | ||
export declare function extendRepresentationPropertyConfig(property: Decorator.Property): Decorator.Property; | ||
@@ -3,0 +3,0 @@ export declare function extractRepresentationPropertyValue<T extends Decorator.Type, P extends keyof Decorator.TypePropertyMap[T]>(decorator: Decorator.Data, config: Decorator.Property): Decorator.TypePropertyMap[T][P] | undefined; |
@@ -36,3 +36,3 @@ "use strict"; | ||
break; | ||
case "argument": | ||
case 'argument': | ||
items = decorator.arguments; | ||
@@ -60,3 +60,3 @@ break; | ||
switch (srcStrategy) { | ||
case "merge": | ||
case 'merge': | ||
switch (config.type) { | ||
@@ -69,3 +69,3 @@ case 'array': | ||
} | ||
case "none": | ||
case 'none': | ||
// if we dont have any merge strategy, we just return the first argument. | ||
@@ -72,0 +72,0 @@ switch (config.type) { |
import { Node } from 'typescript'; | ||
import { Decorator } from "../type"; | ||
import { Decorator } from '../type'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Get Decorators for a specific node. |
@@ -18,3 +18,3 @@ "use strict"; | ||
function getNodeDecorators(node, isMatching) { | ||
const decorators = node.decorators; | ||
const { decorators } = node; | ||
if (!decorators || !decorators.length) { | ||
@@ -24,6 +24,6 @@ return []; | ||
const items = decorators | ||
.map(d => { | ||
.map((d) => { | ||
const result = { | ||
arguments: [], | ||
typeArguments: [] | ||
typeArguments: [], | ||
}; | ||
@@ -37,5 +37,3 @@ let x = d.expression; | ||
} | ||
else { | ||
return argument; | ||
} | ||
return argument; | ||
}); | ||
@@ -42,0 +40,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import { SchemaOf } from "yup"; | ||
import { Decorator } from "../type"; | ||
import { SchemaOf } from 'yup'; | ||
import { Decorator } from '../type'; | ||
export declare function useDecoratorConfigValidator(): SchemaOf<Decorator.Config>; | ||
//# sourceMappingURL=validator.d.ts.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
} | ||
const configMappingOptionValidator = (0, yup_1.lazy)(value => { | ||
const configMappingOptionValidator = (0, yup_1.lazy)((value) => { | ||
if (typeof value === 'boolean') { | ||
@@ -34,3 +34,3 @@ return (0, yup_1.boolean)(); | ||
}); | ||
const useLibraryValidator = (0, yup_1.lazy)(value => { | ||
const useLibraryValidator = (0, yup_1.lazy)((value) => { | ||
if (typeof value === 'string') { | ||
@@ -59,3 +59,3 @@ return (0, yup_1.string)(); | ||
id: (0, yup_1.string)().required(), | ||
properties: (0, yup_1.lazy)(value => { | ||
properties: (0, yup_1.lazy)((value) => { | ||
if (Object.prototype.toString.call(value) === '[object Object]') { | ||
@@ -65,7 +65,7 @@ return (0, yup_1.object)((0, metadata_utils_1.mapYupRuleForDictionary)(value, representationPropertyValidator)).optional().default({}); | ||
return (0, yup_1.mixed)().optional().default(undefined); | ||
}) | ||
}), | ||
}); | ||
const overrideValidator = (0, yup_1.lazy)(value => { | ||
const overrideValidator = (0, yup_1.lazy)((value) => { | ||
if (Object.prototype.toString.call(value) === '[object Object]') { | ||
return (0, yup_1.object)((0, metadata_utils_1.mapYupRuleForDictionary)(value, (0, yup_1.lazy)(val => { | ||
return (0, yup_1.object)((0, metadata_utils_1.mapYupRuleForDictionary)(value, (0, yup_1.lazy)((val) => { | ||
if (Array.isArray(val)) { | ||
@@ -82,6 +82,6 @@ return (0, yup_1.array)().of(representationValidator); | ||
internal: configMappingOptionValidator, | ||
map: overrideValidator | ||
map: overrideValidator, | ||
}).optional().default({ | ||
library: ['typescript-rest', '@decorators/express'], | ||
internal: true | ||
internal: true, | ||
}); | ||
@@ -88,0 +88,0 @@ return validatorInstance; |
import { ClassDeclaration } from 'typescript'; | ||
import { EndpointGenerator } from './endpoint'; | ||
import { MetadataGenerator } from './index'; | ||
import { Controller } from "../type"; | ||
import { Controller } from '../type'; | ||
export declare class ControllerGenerator extends EndpointGenerator<ClassDeclaration> { | ||
@@ -6,0 +6,0 @@ private genMethods; |
import { ArrayLiteralExpression, Node } from 'typescript'; | ||
import { Decorator } from "../decorator"; | ||
import { Decorator } from '../decorator'; | ||
import { MetadataGenerator } from './index'; | ||
import { Response } from "../type"; | ||
import { Response } from '../type'; | ||
export declare abstract class EndpointGenerator<T extends Node> { | ||
@@ -6,0 +6,0 @@ protected current: MetadataGenerator; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/* | ||
@@ -7,3 +8,2 @@ * Copyright (c) 2021. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -13,5 +13,5 @@ exports.EndpointGenerator = void 0; | ||
const metadata_utils_1 = require("@trapi/metadata-utils"); | ||
const decorator_1 = require("../decorator"); | ||
const resolver_1 = require("../resolver"); | ||
const utils_1 = require("../utils"); | ||
const decorator_1 = require("../decorator"); | ||
class EndpointGenerator { | ||
@@ -37,3 +37,3 @@ // ------------------------------------------- | ||
getDecoratorValues(decoratorName, acceptMultiple = false) { | ||
const decorators = (0, decorator_1.getNodeDecorators)(this.node, decorator => decorator.text === decoratorName); | ||
const decorators = (0, decorator_1.getNodeDecorators)(this.node, (decorator) => decorator.text === decoratorName); | ||
if (!decorators || !decorators.length) { | ||
@@ -47,3 +47,3 @@ return []; | ||
if (acceptMultiple) { | ||
result = decorators.map(d => d.arguments); | ||
result = decorators.map((d) => d.arguments); | ||
} | ||
@@ -62,7 +62,7 @@ else { | ||
} | ||
return securities.map(security => { | ||
return securities.map((security) => { | ||
const rolesArray = security[0] ? this.handleRolesArray(security[0]) : []; | ||
return { | ||
name: security[1] ? security[1] : 'default', | ||
scopes: rolesArray | ||
scopes: rolesArray, | ||
}; | ||
@@ -73,8 +73,6 @@ }); | ||
if ((0, typescript_1.isArrayLiteralExpression)(argument)) { | ||
return argument.elements.map(value => value.getText()) | ||
.map(val => (val && val.startsWith('\'') && val.endsWith('\'')) ? val.slice(1, -1) : val); | ||
return argument.elements.map((value) => value.getText()) | ||
.map((val) => ((val && val.startsWith('\'') && val.endsWith('\'')) ? val.slice(1, -1) : val)); | ||
} | ||
else { | ||
return argument; | ||
} | ||
return argument; | ||
} | ||
@@ -107,10 +105,10 @@ // ------------------------------------------- | ||
const status = representation.getPropertyValue('STATUS_CODE', i) || '200'; | ||
let examples = representation.getPropertyValue('PAYLOAD', i); | ||
const examples = representation.getPropertyValue('PAYLOAD', i); | ||
const type = representation.getPropertyValue('TYPE'); | ||
const response = { | ||
description: description, | ||
examples: examples, | ||
description, | ||
examples, | ||
schema: type ? new resolver_1.TypeNodeResolver(type, this.current).resolve() : undefined, | ||
status: status, | ||
name: status | ||
name: status, | ||
}; | ||
@@ -162,3 +160,3 @@ responses.push(response); | ||
isDeprecated(node) { | ||
if ((0, utils_1.isExistJSDocTag)(node, tag => tag.tagName.text === 'deprecated')) { | ||
if ((0, utils_1.isExistJSDocTag)(node, (tag) => tag.tagName.text === 'deprecated')) { | ||
return true; | ||
@@ -165,0 +163,0 @@ } |
import * as ts from 'typescript'; | ||
import { EndpointGenerator } from './endpoint'; | ||
import { MetadataGenerator } from './index'; | ||
import { Method } from "../type"; | ||
import { Method } from '../type'; | ||
export declare class MethodGenerator extends EndpointGenerator<ts.MethodDeclaration> { | ||
@@ -6,0 +6,0 @@ private readonly controllerPath; |
@@ -31,8 +31,8 @@ "use strict"; | ||
const ts = __importStar(require("typescript")); | ||
const metadata_utils_1 = require("@trapi/metadata-utils"); | ||
const decorator_1 = require("../decorator"); | ||
const endpoint_1 = require("./endpoint"); | ||
const parameter_1 = require("./parameter"); | ||
const resolver_1 = require("../resolver"); | ||
const metadata_utils_1 = require("@trapi/metadata-utils"); | ||
const utils_1 = require("../utils"); | ||
const decorator_1 = require("../decorator"); | ||
class MethodGenerator extends endpoint_1.EndpointGenerator { | ||
@@ -59,3 +59,3 @@ // -------------------------------------------------------------------- | ||
if (!nodeType) { | ||
const typeChecker = this.current.typeChecker; | ||
const { typeChecker } = this.current; | ||
const signature = typeChecker.getSignatureFromDeclaration(this.node); | ||
@@ -79,7 +79,7 @@ const implicitType = typeChecker.getReturnTypeOfSignature(signature); | ||
produces: this.getProduces(), | ||
responses: responses, | ||
responses, | ||
security: this.getSecurity(), | ||
summary: (0, utils_1.getJSDocTagComment)(this.node, 'summary'), | ||
tags: this.getTags(), | ||
type: type | ||
type, | ||
}; | ||
@@ -116,3 +116,3 @@ } | ||
processMethodDecorators() { | ||
const httpMethodDecorators = (0, decorator_1.getNodeDecorators)(this.node, decorator => this.supportsPathMethod(decorator.text)); | ||
const httpMethodDecorators = (0, decorator_1.getNodeDecorators)(this.node, (decorator) => this.supportsPathMethod(decorator.text)); | ||
if (!httpMethodDecorators || !httpMethodDecorators.length) { | ||
@@ -122,3 +122,3 @@ return; | ||
if (httpMethodDecorators.length > 1) { | ||
throw new Error(`Only one HTTP Method decorator in '${this.getCurrentLocation}' method is acceptable, Found: ${httpMethodDecorators.map(d => d.text).join(', ')}`); | ||
throw new Error(`Only one HTTP Method decorator in '${this.getCurrentLocation}' method is acceptable, Found: ${httpMethodDecorators.map((d) => d.text).join(', ')}`); | ||
} | ||
@@ -136,3 +136,3 @@ const methodDecorator = httpMethodDecorators[0]; | ||
status: resolver_1.Resolver.isVoidType(type) ? '204' : '200', | ||
name: resolver_1.Resolver.isVoidType(type) ? '204' : '200' | ||
name: resolver_1.Resolver.isVoidType(type) ? '204' : '200', | ||
}; | ||
@@ -161,3 +161,3 @@ } | ||
} | ||
let value = representation.getPropertyValue('PAYLOAD'); | ||
const value = representation.getPropertyValue('PAYLOAD'); | ||
if (typeof value === 'undefined') { | ||
@@ -184,3 +184,3 @@ return []; | ||
supportsPathMethod(method) { | ||
return ['ALL', 'GET', 'POST', 'PATCH', 'DELETE', 'PUT', 'OPTIONS', 'HEAD'].some(m => m.toLowerCase() === method.toLowerCase()); | ||
return ['ALL', 'GET', 'POST', 'PATCH', 'DELETE', 'PUT', 'OPTIONS', 'HEAD'].some((m) => m.toLowerCase() === method.toLowerCase()); | ||
} | ||
@@ -187,0 +187,0 @@ } |
import { CompilerOptions, Node, TypeChecker } from 'typescript'; | ||
import { Config, GeneratorOutput } from "../type"; | ||
import { DecoratorMapper } from "../decorator"; | ||
import { Resolver } from "../resolver"; | ||
import { Config, GeneratorOutput } from '../type'; | ||
import { DecoratorMapper } from '../decorator'; | ||
import { Resolver } from '../resolver'; | ||
export declare class MetadataGenerator { | ||
@@ -6,0 +6,0 @@ readonly nodes: Node[]; |
@@ -16,3 +16,3 @@ "use strict"; | ||
const cache_1 = require("../cache"); | ||
const minimatch = require("minimatch"); | ||
const minimatch = require('minimatch'); | ||
class MetadataGenerator { | ||
@@ -38,7 +38,7 @@ // ------------------------------------------------------------------------- | ||
this.buildControllers(); | ||
this.circularDependencyResolvers.forEach(resolve => resolve(this.referenceTypes)); | ||
this.circularDependencyResolvers.forEach((resolve) => resolve(this.referenceTypes)); | ||
cache = { | ||
controllers: this.controllers, | ||
referenceTypes: this.referenceTypes, | ||
sourceFilesSize: sourceFileSize | ||
sourceFilesSize: sourceFileSize, | ||
}; | ||
@@ -49,3 +49,3 @@ this.cache.save(cache); | ||
controllers: cache.controllers, | ||
referenceTypes: cache.referenceTypes | ||
referenceTypes: cache.referenceTypes, | ||
}; | ||
@@ -70,3 +70,3 @@ } | ||
if ((node.flags & typescript_1.NodeFlags.Namespace) === 0 && node.body && (0, typescript_1.isModuleBlock)(node.body)) { | ||
node.body.statements.forEach(statement => { | ||
node.body.statements.forEach((statement) => { | ||
this.nodes.push(statement); | ||
@@ -93,3 +93,3 @@ }); | ||
} | ||
return this.config.ignore.some(item => minimatch(filePath, item)); | ||
return this.config.ignore.some((item) => minimatch(filePath, item)); | ||
} | ||
@@ -106,3 +106,3 @@ /** | ||
} | ||
return this.config.allow.some(item => minimatch(filePath, item)); | ||
return this.config.allow.some((item) => minimatch(filePath, item)); | ||
} | ||
@@ -128,3 +128,3 @@ // ------------------------------------------------------------------------- | ||
const found = this.nodes | ||
.filter(node => { | ||
.filter((node) => { | ||
const classDeclaration = node; | ||
@@ -140,3 +140,3 @@ return (node.kind === typescript_1.SyntaxKind.ClassDeclaration && classDeclaration.name && classDeclaration.name.text === className); | ||
const found = this.nodes | ||
.filter(node => { | ||
.filter((node) => { | ||
const interfaceDeclaration = node; | ||
@@ -154,5 +154,5 @@ return (node.kind === typescript_1.SyntaxKind.InterfaceDeclaration && interfaceDeclaration.name && interfaceDeclaration.name.text === className); | ||
const options = { cwd: process.cwd() }; | ||
sourceFilesExpressions.forEach(pattern => { | ||
sourceFilesExpressions.forEach((pattern) => { | ||
const matches = (0, glob_1.sync)(pattern, options); | ||
matches.forEach(file => { result.add(file); }); | ||
matches.forEach((file) => { result.add(file); }); | ||
}); | ||
@@ -163,11 +163,11 @@ return Array.from(result); | ||
this.controllers = this.nodes | ||
.filter(node => node.kind === typescript_1.SyntaxKind.ClassDeclaration) | ||
.filter(node => { | ||
.filter((node) => node.kind === typescript_1.SyntaxKind.ClassDeclaration) | ||
.filter((node) => { | ||
const isHidden = this.decoratorMapper.match('HIDDEN', node); | ||
return typeof isHidden === 'undefined'; | ||
}) | ||
.filter(node => typeof this.decoratorMapper.match('CLASS_PATH', node) !== 'undefined') | ||
.filter((node) => typeof this.decoratorMapper.match('CLASS_PATH', node) !== 'undefined') | ||
.map((classDeclaration) => new controller_1.ControllerGenerator(classDeclaration, this)) | ||
.filter(generator => generator.isValid()) | ||
.map(generator => generator.generate()); | ||
.filter((generator) => generator.isValid()) | ||
.map((generator) => generator.generate()); | ||
} | ||
@@ -174,0 +174,0 @@ } |
import * as ts from 'typescript'; | ||
import { MetadataGenerator } from './index'; | ||
import { Parameter } from "../type"; | ||
import { Parameter } from '../type'; | ||
export declare class ParameterGenerator { | ||
@@ -5,0 +5,0 @@ private readonly parameter; |
@@ -31,3 +31,2 @@ "use strict"; | ||
const resolver_1 = require("../resolver"); | ||
const resolver_2 = require("../resolver"); | ||
const node_1 = require("../decorator/utils/node"); | ||
@@ -43,3 +42,3 @@ const supportedParameterKeys = [ | ||
'SERVER_PATH_PARAMS', | ||
'SERVER_FILES_PARAM' | ||
'SERVER_FILES_PARAM', | ||
]; | ||
@@ -105,5 +104,5 @@ class ParameterGenerator { | ||
name: name || parameterName, | ||
parameterName: parameterName, | ||
parameterName, | ||
required: !this.parameter.questionToken, | ||
type: type | ||
type, | ||
}; | ||
@@ -117,5 +116,5 @@ } | ||
name: parameterName, | ||
parameterName: parameterName, | ||
parameterName, | ||
required: !this.parameter.questionToken, | ||
type: null | ||
type: null, | ||
}; | ||
@@ -154,3 +153,3 @@ } | ||
if (isArray) { | ||
type = { typeName: 'array', elementType: elementType }; | ||
type = { typeName: 'array', elementType }; | ||
} | ||
@@ -164,5 +163,5 @@ else { | ||
name: name || parameterName, | ||
parameterName: parameterName, | ||
parameterName, | ||
required: !this.parameter.questionToken && !this.parameter.initializer, | ||
type: type | ||
type, | ||
}; | ||
@@ -185,5 +184,5 @@ } | ||
name: name || parameterName, | ||
parameterName: parameterName, | ||
parameterName, | ||
required: !this.parameter.questionToken && !this.parameter.initializer, | ||
type: type | ||
type, | ||
}; | ||
@@ -206,5 +205,5 @@ } | ||
name: name || parameterName, | ||
parameterName: parameterName, | ||
parameterName, | ||
required: !this.parameter.questionToken && !this.parameter.initializer, | ||
type: type | ||
type, | ||
}; | ||
@@ -229,5 +228,5 @@ } | ||
name: name || parameterName, | ||
parameterName: parameterName, | ||
parameterName, | ||
required: !this.parameter.questionToken && !this.parameter.initializer, | ||
type: type | ||
type, | ||
}; | ||
@@ -250,5 +249,5 @@ } | ||
name: name || parameterName, | ||
parameterName: parameterName, | ||
parameterName, | ||
required: !this.parameter.questionToken && !this.parameter.initializer, | ||
type: type | ||
type, | ||
}; | ||
@@ -283,3 +282,3 @@ } | ||
collectionFormat: options.collectionFormat, | ||
default: (0, resolver_2.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type), | ||
default: (0, resolver_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type), | ||
description: this.getParameterDescription(this.parameter), | ||
@@ -289,9 +288,9 @@ in: 'query', | ||
minItems: options.minItems, | ||
name: name, | ||
parameterName: parameterName, | ||
name, | ||
parameterName, | ||
required: !this.parameter.questionToken && !this.parameter.initializer, | ||
type: type | ||
type, | ||
}; | ||
if (type.typeName === 'array') { | ||
return Object.assign(Object.assign({}, properties), { collectionFormat: 'multi', type: type }); | ||
return Object.assign(Object.assign({}, properties), { collectionFormat: 'multi', type }); | ||
} | ||
@@ -318,5 +317,5 @@ return properties; | ||
name: pathName, | ||
parameterName: parameterName, | ||
parameterName, | ||
required: true, | ||
type: type | ||
type, | ||
}; | ||
@@ -335,6 +334,6 @@ } | ||
supportsBodyParameters(method) { | ||
return ['delete', 'post', 'put', 'patch', 'get'].some(m => m === method); | ||
return ['delete', 'post', 'put', 'patch', 'get'].some((m) => m === method); | ||
} | ||
supportPathDataType(parameterType) { | ||
return ['string', 'integer', 'long', 'float', 'double', 'date', 'datetime', 'buffer', 'boolean', 'enum'].find(t => t === parameterType.typeName); | ||
return ['string', 'integer', 'long', 'float', 'double', 'date', 'datetime', 'buffer', 'boolean', 'enum'].find((t) => t === parameterType.typeName); | ||
} | ||
@@ -344,3 +343,3 @@ supportQueryDataType(parameterType) { | ||
return ['string', 'integer', 'long', 'float', 'double', 'date', | ||
'datetime', 'buffer', 'boolean', 'enum', 'array', 'object'].find(t => t === parameterType.typeName); | ||
'datetime', 'buffer', 'boolean', 'enum', 'array', 'object'].find((t) => t === parameterType.typeName); | ||
} | ||
@@ -347,0 +346,0 @@ getValidatedType(parameter) { |
import * as ts from 'typescript'; | ||
import { MetadataGenerator } from '../generator'; | ||
import { Resolver } from "./type"; | ||
import { Resolver } from './type'; | ||
interface TypeNodeResolverContext { | ||
@@ -5,0 +5,0 @@ [name: string]: ts.TypeReferenceNode | ts.TypeNode; |
@@ -31,6 +31,6 @@ "use strict"; | ||
const metadata_utils_1 = require("@trapi/metadata-utils"); | ||
const decorator_1 = require("../decorator"); | ||
const utils_1 = require("../utils"); | ||
const error_1 = require("./error"); | ||
const utils_2 = require("./utils"); | ||
const decorator_1 = require("../decorator"); | ||
const localReferenceTypeCache = {}; | ||
@@ -52,21 +52,19 @@ const inProgressTypes = {}; | ||
} | ||
else if (syntaxKind === ts.SyntaxKind.StringKeyword) { | ||
if (syntaxKind === ts.SyntaxKind.StringKeyword) { | ||
return 'string'; | ||
} | ||
else if (syntaxKind === ts.SyntaxKind.BooleanKeyword) { | ||
if (syntaxKind === ts.SyntaxKind.BooleanKeyword) { | ||
return 'boolean'; | ||
} | ||
else if (syntaxKind === ts.SyntaxKind.VoidKeyword) { | ||
if (syntaxKind === ts.SyntaxKind.VoidKeyword) { | ||
return 'void'; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
return undefined; | ||
}; | ||
} | ||
static clearCache() { | ||
Object.keys(localReferenceTypeCache).forEach(key => { | ||
Object.keys(localReferenceTypeCache).forEach((key) => { | ||
delete localReferenceTypeCache[key]; | ||
}); | ||
Object.keys(inProgressTypes).forEach(key => { | ||
Object.keys(inProgressTypes).forEach((key) => { | ||
delete inProgressTypes[key]; | ||
@@ -93,5 +91,3 @@ }); | ||
if (ts.isUnionTypeNode(this.typeNode)) { | ||
const types = this.typeNode.types.map(type => { | ||
return new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve(); | ||
}); | ||
const types = this.typeNode.types.map((type) => new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve()); | ||
return { | ||
@@ -103,5 +99,3 @@ typeName: 'union', | ||
if (ts.isIntersectionTypeNode(this.typeNode)) { | ||
const types = this.typeNode.types.map(type => { | ||
return new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve(); | ||
}); | ||
const types = this.typeNode.types.map((type) => new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve()); | ||
return { | ||
@@ -125,7 +119,7 @@ typeName: 'intersection', | ||
const properties = this.typeNode.members | ||
.filter(member => ts.isPropertySignature(member)) | ||
.filter((member) => ts.isPropertySignature(member)) | ||
.reduce((res, propertySignature) => { | ||
const type = new TypeNodeResolver(propertySignature.type, this.current, propertySignature, this.context).resolve(); | ||
const property = { | ||
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, tag => tag.tagName.text === 'deprecated'), | ||
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, (tag) => tag.tagName.text === 'deprecated'), | ||
example: TypeNodeResolver.getNodeExample(propertySignature), | ||
@@ -137,8 +131,8 @@ default: (0, utils_1.getJSDocTagComment)(propertySignature, 'default'), | ||
required: !propertySignature.questionToken, | ||
type: type, | ||
validators: getPropertyValidators(propertySignature) || {} | ||
type, | ||
validators: getPropertyValidators(propertySignature) || {}, | ||
}; | ||
return [property, ...res]; | ||
}, []); | ||
const indexMember = this.typeNode.members.find(member => ts.isIndexSignatureDeclaration(member)); | ||
const indexMember = this.typeNode.members.find((member) => ts.isIndexSignatureDeclaration(member)); | ||
let additionalType; | ||
@@ -149,3 +143,3 @@ if (indexMember) { | ||
if (indexType.typeName !== 'string') { | ||
throw new error_1.ResolverError(`Only string indexes are supported.`, this.typeNode); | ||
throw new error_1.ResolverError('Only string indexes are supported.', this.typeNode); | ||
} | ||
@@ -157,3 +151,3 @@ additionalType = new TypeNodeResolver(indexSignatureDeclaration.type, this.current, this.parentNode, this.context).resolve(); | ||
typeName: 'nestedObjectLiteral', | ||
properties: properties, | ||
properties, | ||
}; | ||
@@ -167,7 +161,7 @@ } | ||
const mappedTypeNode = this.typeNode; | ||
const typeChecker = this.current.typeChecker; | ||
const { typeChecker } = this.current; | ||
const getDeclaration = (prop) => prop.declarations && prop.declarations[0]; | ||
const isIgnored = (prop) => { | ||
const declaration = getDeclaration(prop); | ||
return (prop.getJsDocTags().find(tag => tag.name === 'ignore') !== undefined || | ||
return (prop.getJsDocTags().find((tag) => tag.name === 'ignore') !== undefined || | ||
(declaration !== undefined && !ts.isPropertyDeclaration(declaration) && !ts.isPropertySignature(declaration) && !ts.isParameter(declaration))); | ||
@@ -178,5 +172,5 @@ }; | ||
// Ignore methods, getter, setter and @ignored props | ||
.filter(property => isIgnored(property) === false) | ||
.filter((property) => isIgnored(property) === false) | ||
// Transform to property | ||
.map(property => { | ||
.map((property) => { | ||
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, this.typeNode); | ||
@@ -187,3 +181,3 @@ const declaration = getDeclaration(property); | ||
} | ||
else if (declaration && (ts.isPropertyDeclaration(declaration) || ts.isParameter(declaration))) { | ||
if (declaration && (ts.isPropertyDeclaration(declaration) || ts.isParameter(declaration))) { | ||
return Object.assign(Object.assign({}, this.propertyFromDeclaration(declaration, mappedTypeNode.questionToken)), { name: property.getName() }); | ||
@@ -203,3 +197,3 @@ } | ||
name: property.getName(), | ||
required: required, | ||
required, | ||
deprecated: false, | ||
@@ -212,3 +206,3 @@ type: new TypeNodeResolver(typeNode, this.current, this.typeNode, this.context, this.referencer).resolve(), | ||
typeName: 'nestedObjectLiteral', | ||
properties: properties, | ||
properties, | ||
}; | ||
@@ -229,11 +223,9 @@ } | ||
} | ||
else if (ts.isEnumDeclaration(declaration)) { | ||
if (ts.isEnumDeclaration(declaration)) { | ||
return this.getEnumerateType(declaration.name); | ||
} | ||
else { | ||
throw new error_1.ResolverError(`Couldn't resolve Conditional to TypeNode. If you think this should be resolvable, please file an Issue. We found an aliasSymbol and it's declaration was of kind ${declaration.kind}`, this.typeNode); | ||
} | ||
throw new error_1.ResolverError(`Couldn't resolve Conditional to TypeNode. If you think this should be resolvable, please file an Issue. We found an aliasSymbol and it's declaration was of kind ${declaration.kind}`, this.typeNode); | ||
}); | ||
} | ||
else if (type.isClassOrInterface()) { | ||
if (type.isClassOrInterface()) { | ||
let declaration = type.symbol.declarations[0]; | ||
@@ -246,10 +238,8 @@ if (declaration.name) { | ||
} | ||
else { | ||
try { | ||
return new TypeNodeResolver(this.current.typeChecker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation), this.current, this.typeNode, this.context, this.referencer).resolve(); | ||
} | ||
catch (_a) { | ||
throw new error_1.ResolverError(`Couldn't resolve Conditional to TypeNode. If you think this should be resolvable, please file an Issue. The flags on the result of the ConditionalType was ${type.flags}`, this.typeNode); | ||
} | ||
try { | ||
return new TypeNodeResolver(this.current.typeChecker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation), this.current, this.typeNode, this.context, this.referencer).resolve(); | ||
} | ||
catch (_a) { | ||
throw new error_1.ResolverError(`Couldn't resolve Conditional to TypeNode. If you think this should be resolvable, please file an Issue. The flags on the result of the ConditionalType was ${type.flags}`, this.typeNode); | ||
} | ||
} | ||
@@ -297,3 +287,3 @@ if (ts.isTypeOperatorNode(this.typeNode) && this.typeNode.operator === ts.SyntaxKind.KeyOfKeyword) { | ||
const type = this.current.typeChecker.getTypeFromTypeNode(this.referencer || this.typeNode); | ||
if (type.isUnion() && type.types.every(unionElementType => unionElementType.isStringLiteral())) { | ||
if (type.isUnion() && type.types.every((unionElementType) => unionElementType.isStringLiteral())) { | ||
return { | ||
@@ -304,5 +294,3 @@ typeName: 'enum', | ||
} | ||
else { | ||
throw new error_1.ResolverError(`Could not the type of ${this.current.typeChecker.typeToString(this.current.typeChecker.getTypeFromTypeNode(this.typeNode), this.typeNode)}`, this.typeNode); | ||
} | ||
throw new error_1.ResolverError(`Could not the type of ${this.current.typeChecker.typeToString(this.current.typeChecker.getTypeFromTypeNode(this.typeNode), this.typeNode)}`, this.typeNode); | ||
} | ||
@@ -366,3 +354,3 @@ if (ts.isParenthesizedTypeNode(this.typeNode)) { | ||
const utilityOptions = { | ||
keys: [] | ||
keys: [], | ||
}; | ||
@@ -374,3 +362,3 @@ if (typeArguments.length >= 2) { | ||
if (ts.isLiteralTypeNode(args[i])) { | ||
utilityOptions['keys'].push(TypeNodeResolver.getLiteralValue(args[i])); | ||
utilityOptions.keys.push(TypeNodeResolver.getLiteralValue(args[i])); | ||
} | ||
@@ -380,3 +368,3 @@ } | ||
if (ts.isLiteralTypeNode(typeArguments[1])) { | ||
utilityOptions['keys'].push(TypeNodeResolver.getLiteralValue(typeArguments[1])); | ||
utilityOptions.keys.push(TypeNodeResolver.getLiteralValue(typeArguments[1])); | ||
} | ||
@@ -391,3 +379,3 @@ } | ||
return properties | ||
.filter(property => { | ||
.filter((property) => { | ||
const name = typeof property.name !== 'string' ? property.name.text : property.name; | ||
@@ -402,3 +390,3 @@ switch (utilityType) { | ||
}) | ||
.map(property => { | ||
.map((property) => { | ||
if ((0, metadata_utils_1.hasOwnProperty)(property, 'required')) { | ||
@@ -471,17 +459,15 @@ switch (utilityType) { | ||
const tags = (0, utils_1.getJSDocTagNames)(parentNode) | ||
.filter(name => { | ||
return [ | ||
'isInt', | ||
'isLong', | ||
'isFloat', | ||
'isDouble' | ||
].some(m => m.toLowerCase() === name.toLowerCase()); | ||
}) | ||
.map(name => name.toLowerCase()); | ||
const data = (0, decorator_1.getNodeDecorators)(parentNode, identifier => [ | ||
.filter((name) => [ | ||
'isInt', | ||
'isLong', | ||
'isFloat', | ||
'isDouble' | ||
].some(m => m.toLowerCase() === identifier.text.toLowerCase())); | ||
'isDouble', | ||
].some((m) => m.toLowerCase() === name.toLowerCase())) | ||
.map((name) => name.toLowerCase()); | ||
const data = (0, decorator_1.getNodeDecorators)(parentNode, (identifier) => [ | ||
'isInt', | ||
'isLong', | ||
'isFloat', | ||
'isDouble', | ||
].some((m) => m.toLowerCase() === identifier.text.toLowerCase())); | ||
let decorator = data.length > 0 ? data[0].text : undefined; | ||
@@ -531,5 +517,3 @@ if (typeof decorator !== 'undefined') { | ||
} | ||
const tags = (0, utils_1.getJSDocTagNames)(parentNode).filter(name => { | ||
return ['isDate', 'isDateTime'].some(m => m === name); | ||
}); | ||
const tags = (0, utils_1.getJSDocTagNames)(parentNode).filter((name) => ['isDate', 'isDateTime'].some((m) => m === name)); | ||
if (tags.length === 0) { | ||
@@ -552,3 +536,3 @@ return { typeName: 'datetime' }; | ||
const enumName = typeName.text; | ||
let enumNodes = this.current.nodes.filter(node => node.kind === ts.SyntaxKind.EnumDeclaration).filter(node => node.name.text === enumName); | ||
let enumNodes = this.current.nodes.filter((node) => node.kind === ts.SyntaxKind.EnumDeclaration).filter((node) => node.name.text === enumName); | ||
if (!enumNodes.length) { | ||
@@ -562,7 +546,5 @@ return undefined; | ||
const enumDeclaration = enumNodes[0]; | ||
const isNotUndefined = (item) => { | ||
return item !== undefined; | ||
}; | ||
const isNotUndefined = (item) => item !== undefined; | ||
const enums = enumDeclaration.members.map(this.current.typeChecker.getConstantValue.bind(this.current.typeChecker)).filter(isNotUndefined); | ||
const enumNames = enumDeclaration.members.map(e => e.name.getText()).filter(isNotUndefined); | ||
const enumNames = enumDeclaration.members.map((e) => e.name.getText()).filter(isNotUndefined); | ||
return { | ||
@@ -574,3 +556,3 @@ typeName: 'refEnum', | ||
refName: enumName, | ||
deprecated: (0, utils_1.isExistJSDocTag)(enumDeclaration, tag => tag.tagName.text === 'deprecated') | ||
deprecated: (0, utils_1.isExistJSDocTag)(enumDeclaration, (tag) => tag.tagName.text === 'deprecated'), | ||
}; | ||
@@ -587,3 +569,3 @@ } | ||
else { | ||
throw new error_1.ResolverError(`Can't resolve Reference type.`); | ||
throw new error_1.ResolverError('Can\'t resolve Reference type.'); | ||
} | ||
@@ -595,3 +577,3 @@ // Can't invoke getText on Synthetic Nodes | ||
const argumentsString = node.typeArguments | ||
.map(arg => { | ||
.map((arg) => { | ||
if (ts.isLiteralTypeNode(arg)) { | ||
@@ -614,6 +596,6 @@ return `'${String(TypeNodeResolver.getLiteralValue(arg))}'`; | ||
let utilityOptions = { | ||
keys: [] | ||
keys: [], | ||
}; | ||
if (utilityTypeSupported) { | ||
const typeArguments = type.parent.typeArguments; | ||
const { typeArguments } = type.parent; | ||
if (ts.isTypeReferenceNode(typeArguments[0])) { | ||
@@ -626,3 +608,3 @@ type = typeArguments[0].typeName; | ||
else { | ||
throw new error_1.ResolverError(`Can't resolve Reference type.`); | ||
throw new error_1.ResolverError('Can\'t resolve Reference type.'); | ||
} | ||
@@ -660,3 +642,3 @@ utilityOptions = TypeNodeResolver.getUtilityTypeOptions(typeArguments); | ||
memberNames: [declaration.name.getText()], | ||
deprecated: (0, utils_1.isExistJSDocTag)(declaration, tag => tag.tagName.text === 'deprecated') | ||
deprecated: (0, utils_1.isExistJSDocTag)(declaration, (tag) => tag.tagName.text === 'deprecated'), | ||
}; | ||
@@ -689,3 +671,3 @@ } | ||
const example = TypeNodeResolver.getNodeExample(declaration); | ||
return Object.assign({ typeName: 'refAlias', default: (0, utils_1.getJSDocTagComment)(declaration, 'default'), description: this.getNodeDescription(declaration), refName: refName, format: TypeNodeResolver.getNodeFormat(declaration), type: type, validators: getPropertyValidators(declaration) || {}, deprecated: (0, utils_1.isExistJSDocTag)(declaration, tag => tag.tagName.text === 'deprecated') }, (example && { example: example })); | ||
return Object.assign({ typeName: 'refAlias', default: (0, utils_1.getJSDocTagComment)(declaration, 'default'), description: this.getNodeDescription(declaration), refName, format: TypeNodeResolver.getNodeFormat(declaration), type, validators: getPropertyValidators(declaration) || {}, deprecated: (0, utils_1.isExistJSDocTag)(declaration, (tag) => tag.tagName.text === 'deprecated') }, (example && { example })); | ||
} | ||
@@ -695,6 +677,6 @@ getModelReference(modelType, name, utilityType, utilityOptions) { | ||
const description = this.getNodeDescription(modelType); | ||
const deprecated = (0, utils_1.isExistJSDocTag)(modelType, tag => tag.tagName.text === 'deprecated') || typeof this.current.decoratorMapper.match('DEPRECATED', modelType) !== 'undefined'; | ||
const deprecated = (0, utils_1.isExistJSDocTag)(modelType, (tag) => tag.tagName.text === 'deprecated') || typeof this.current.decoratorMapper.match('DEPRECATED', modelType) !== 'undefined'; | ||
// Handle toJSON methods | ||
if (!modelType.name) { | ||
throw new error_1.ResolverError("Can't get Symbol from anonymous class", modelType); | ||
throw new error_1.ResolverError('Can\'t get Symbol from anonymous class', modelType); | ||
} | ||
@@ -710,3 +692,3 @@ const type = this.current.typeChecker.getTypeAtLocation(modelType.name); | ||
} | ||
return Object.assign({ refName: TypeNodeResolver.getRefTypeName(name, utilityType) + 'Alias', typeName: 'refAlias', description: description, type: new TypeNodeResolver(nodeType, this.current).resolve(), deprecated: deprecated, validators: {} }, (example && { example: example })); | ||
return Object.assign({ refName: `${TypeNodeResolver.getRefTypeName(name, utilityType)}Alias`, typeName: 'refAlias', description, type: new TypeNodeResolver(nodeType, this.current).resolve(), deprecated, validators: {} }, (example && { example })); | ||
} | ||
@@ -716,3 +698,3 @@ const properties = this.getModelProperties(modelType, undefined, utilityType, utilityOptions); | ||
const inheritedProperties = this.getModelInheritedProperties(modelType) || []; | ||
const referenceType = Object.assign({ additionalProperties: additionalProperties, typeName: 'refObject', description: description, properties: this.filterUtilityProperties(inheritedProperties, utilityType, utilityOptions), refName: TypeNodeResolver.getRefTypeName(name, utilityType), deprecated: deprecated }, (example && { example: example })); | ||
const referenceType = Object.assign({ additionalProperties, typeName: 'refObject', description, properties: this.filterUtilityProperties(inheritedProperties, utilityType, utilityOptions), refName: TypeNodeResolver.getRefTypeName(name, utilityType), deprecated }, (example && { example })); | ||
referenceType.properties = referenceType.properties.concat(properties); | ||
@@ -739,9 +721,7 @@ return referenceType; | ||
contextualizedName(name) { | ||
return Object.entries(this.context).reduce((acc, [key, entry]) => { | ||
return acc | ||
.replace(new RegExp(`<\\s*([^>]*\\s)*\\s*(${key})(\\s[^>]*)*\\s*>`, 'g'), `<$1${entry.getText()}$3>`) | ||
.replace(new RegExp(`<\\s*([^,]*\\s)*\\s*(${key})(\\s[^,]*)*\\s*,`, 'g'), `<$1${entry.getText()}$3,`) | ||
.replace(new RegExp(`,\\s*([^>]*\\s)*\\s*(${key})(\\s[^>]*)*\\s*>`, 'g'), `,$1${entry.getText()}$3>`) | ||
.replace(new RegExp(`<\\s*([^<]*\\s)*\\s*(${key})(\\s[^<]*)*\\s*<`, 'g'), `<$1${entry.getText()}$3<`); | ||
}, name); | ||
return Object.entries(this.context).reduce((acc, [key, entry]) => acc | ||
.replace(new RegExp(`<\\s*([^>]*\\s)*\\s*(${key})(\\s[^>]*)*\\s*>`, 'g'), `<$1${entry.getText()}$3>`) | ||
.replace(new RegExp(`<\\s*([^,]*\\s)*\\s*(${key})(\\s[^,]*)*\\s*,`, 'g'), `<$1${entry.getText()}$3,`) | ||
.replace(new RegExp(`,\\s*([^>]*\\s)*\\s*(${key})(\\s[^>]*)*\\s*>`, 'g'), `,$1${entry.getText()}$3>`) | ||
.replace(new RegExp(`<\\s*([^<]*\\s)*\\s*(${key})(\\s[^<]*)*\\s*<`, 'g'), `<$1${entry.getText()}$3<`), name); | ||
} | ||
@@ -772,5 +752,5 @@ handleCachingAndCircularReferences(name, declarationResolver) { | ||
typeName: 'refObject', | ||
refName: refName, | ||
refName, | ||
}; | ||
this.current.registerDependencyResolver(referenceTypes => { | ||
this.current.registerDependencyResolver((referenceTypes) => { | ||
const realReferenceType = referenceTypes[refName]; | ||
@@ -829,12 +809,10 @@ if (!realReferenceType) { | ||
if (moduleDeclarations.length > 0) { | ||
statements = Array.prototype.concat(...moduleDeclarations.map(declaration => { | ||
statements = Array.prototype.concat(...moduleDeclarations.map((declaration) => { | ||
if (ts.isEnumDeclaration(declaration)) { | ||
return declaration.members; | ||
} | ||
else { | ||
if (!declaration.body || !ts.isModuleBlock(declaration.body)) { | ||
throw new error_1.ResolverError(`Module declaration found for ${leftmostName} has no body.`); | ||
} | ||
return declaration.body.statements; | ||
if (!declaration.body || !ts.isModuleBlock(declaration.body)) { | ||
throw new error_1.ResolverError(`Module declaration found for ${leftmostName} has no body.`); | ||
} | ||
return declaration.body.statements; | ||
})); | ||
@@ -850,3 +828,3 @@ } | ||
const typeName = type.kind === ts.SyntaxKind.Identifier ? type.text : type.right.text; | ||
let modelTypes = statements.filter(node => { | ||
let modelTypes = statements.filter((node) => { | ||
var _a; | ||
@@ -864,9 +842,7 @@ if (!TypeNodeResolver.nodeIsUsable(node) || !this.current.isExportedNode(node)) { | ||
// remove types that are from typescript e.g. 'Account' | ||
modelTypes = modelTypes.filter(modelType => { | ||
return modelType.getSourceFile().fileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules') <= -1; | ||
}); | ||
modelTypes = modelTypes.filter((modelType) => modelType.getSourceFile().fileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules') <= -1); | ||
modelTypes = TypeNodeResolver.getDesignatedModels(modelTypes, typeName); | ||
} | ||
if (modelTypes.length > 1) { | ||
const conflicts = modelTypes.map(modelType => modelType.getSourceFile().fileName).join('"; "'); | ||
const conflicts = modelTypes.map((modelType) => modelType.getSourceFile().fileName).join('"; "'); | ||
throw new error_1.ResolverError(`Multiple matching models found for referenced type ${typeName}; please make model names unique. Conflicts found: "${conflicts}".`); | ||
@@ -877,22 +853,20 @@ } | ||
getModelProperties(node, overrideToken, utilityType, utilityOptions) { | ||
const isIgnored = (e) => { | ||
return (0, utils_1.isExistJSDocTag)(e, tag => tag.tagName.text === 'ignore'); | ||
}; | ||
const isIgnored = (e) => (0, utils_1.isExistJSDocTag)(e, (tag) => tag.tagName.text === 'ignore'); | ||
// Interface model | ||
if (ts.isInterfaceDeclaration(node)) { | ||
return node.members.filter(member => !isIgnored(member) && ts.isPropertySignature(member)).map((member) => this.propertyFromSignature(member, overrideToken)); | ||
return node.members.filter((member) => !isIgnored(member) && ts.isPropertySignature(member)).map((member) => this.propertyFromSignature(member, overrideToken)); | ||
} | ||
// Class model | ||
let properties = node.members | ||
.filter(member => !isIgnored(member)) | ||
.filter(member => member.kind === ts.SyntaxKind.PropertyDeclaration) | ||
.filter(member => !this.hasStaticModifier(member)) | ||
.filter(member => this.hasPublicModifier(member)); | ||
const classConstructor = node.members.find(member => ts.isConstructorDeclaration(member)); | ||
.filter((member) => !isIgnored(member)) | ||
.filter((member) => member.kind === ts.SyntaxKind.PropertyDeclaration) | ||
.filter((member) => !this.hasStaticModifier(member)) | ||
.filter((member) => this.hasPublicModifier(member)); | ||
const classConstructor = node.members.find((member) => ts.isConstructorDeclaration(member)); | ||
if (classConstructor && classConstructor.parameters) { | ||
const constructorProperties = classConstructor.parameters.filter(parameter => this.isAccessibleParameter(parameter)); | ||
const constructorProperties = classConstructor.parameters.filter((parameter) => this.isAccessibleParameter(parameter)); | ||
properties.push(...constructorProperties); | ||
} | ||
properties = this.filterUtilityProperties(properties, utilityType, utilityOptions); | ||
return properties.map(property => this.propertyFromDeclaration(property, overrideToken, utilityType)); | ||
return properties.map((property) => this.propertyFromDeclaration(property, overrideToken, utilityType)); | ||
} | ||
@@ -902,3 +876,3 @@ propertyFromSignature(propertySignature, overrideToken) { | ||
if (!propertySignature.type) { | ||
throw new error_1.ResolverError(`No valid type found for property declaration.`); | ||
throw new error_1.ResolverError('No valid type found for property declaration.'); | ||
} | ||
@@ -913,3 +887,3 @@ let required = !propertySignature.questionToken; | ||
const property = { | ||
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, tag => tag.tagName.text === 'deprecated'), | ||
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, (tag) => tag.tagName.text === 'deprecated'), | ||
default: (0, utils_1.getJSDocTagComment)(propertySignature, 'default'), | ||
@@ -920,5 +894,5 @@ description: this.getNodeDescription(propertySignature), | ||
name: identifier.text, | ||
required: required, | ||
required, | ||
type: new TypeNodeResolver(propertySignature.type, this.current, propertySignature.type.parent, this.context, propertySignature.type).resolve(), | ||
validators: getPropertyValidators(propertySignature) || {} | ||
validators: getPropertyValidators(propertySignature) || {}, | ||
}; | ||
@@ -935,3 +909,3 @@ return property; | ||
if (!typeNode) { | ||
throw new error_1.ResolverError(`No valid type found for property declaration.`); | ||
throw new error_1.ResolverError('No valid type found for property declaration.'); | ||
} | ||
@@ -955,3 +929,3 @@ const type = new TypeNodeResolver(typeNode, this.current, propertyDeclaration, this.context, typeNode).resolve(); | ||
const property = { | ||
deprecated: (0, utils_1.isExistJSDocTag)(propertyDeclaration, tag => tag.tagName.text === 'deprecated'), | ||
deprecated: (0, utils_1.isExistJSDocTag)(propertyDeclaration, (tag) => tag.tagName.text === 'deprecated'), | ||
default: (0, utils_2.getInitializerValue)(propertyDeclaration.initializer, this.current.typeChecker), | ||
@@ -962,4 +936,4 @@ description: this.getNodeDescription(propertyDeclaration), | ||
name: identifier.text, | ||
required: required, | ||
type: type, | ||
required, | ||
type, | ||
validators: getPropertyValidators(propertyDeclaration) || {}, | ||
@@ -971,3 +945,3 @@ }; | ||
if (node.kind === ts.SyntaxKind.InterfaceDeclaration) { | ||
const indexMember = node.members.find(member => member.kind === ts.SyntaxKind.IndexSignature); | ||
const indexMember = node.members.find((member) => member.kind === ts.SyntaxKind.IndexSignature); | ||
if (!indexMember) { | ||
@@ -979,3 +953,3 @@ return undefined; | ||
if (indexType.typeName !== 'string') { | ||
throw new error_1.ResolverError(`Only string indexers are supported.`, this.typeNode); | ||
throw new error_1.ResolverError('Only string indexers are supported.', this.typeNode); | ||
} | ||
@@ -1015,11 +989,11 @@ return new TypeNodeResolver(indexSignatureDeclaration.type, this.current, this.parentNode, this.context).resolve(); | ||
let properties = []; | ||
const heritageClauses = modelTypeDeclaration.heritageClauses; | ||
const { heritageClauses } = modelTypeDeclaration; | ||
if (!heritageClauses) { | ||
return properties; | ||
} | ||
heritageClauses.forEach(clause => { | ||
heritageClauses.forEach((clause) => { | ||
if (!clause.types) { | ||
return; | ||
} | ||
clause.types.forEach(t => { | ||
clause.types.forEach((t) => { | ||
const baseEntityName = t.expression; | ||
@@ -1046,3 +1020,3 @@ // create subContext | ||
else if (referenceType.typeName === 'refObject') { | ||
referenceType.properties.forEach(property => properties.push(property)); | ||
referenceType.properties.forEach((property) => properties.push(property)); | ||
} | ||
@@ -1061,11 +1035,7 @@ else { | ||
return (!node.modifiers || | ||
node.modifiers.every(modifier => { | ||
return modifier.kind !== ts.SyntaxKind.ProtectedKeyword && modifier.kind !== ts.SyntaxKind.PrivateKeyword; | ||
})); | ||
node.modifiers.every((modifier) => modifier.kind !== ts.SyntaxKind.ProtectedKeyword && modifier.kind !== ts.SyntaxKind.PrivateKeyword)); | ||
} | ||
hasStaticModifier(node) { | ||
return (node.modifiers && | ||
node.modifiers.some(modifier => { | ||
return modifier.kind === ts.SyntaxKind.StaticKeyword; | ||
})); | ||
node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword)); | ||
} | ||
@@ -1078,10 +1048,8 @@ isAccessibleParameter(node) { | ||
// public || public readonly | ||
if (node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.PublicKeyword)) { | ||
if (node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.PublicKeyword)) { | ||
return true; | ||
} | ||
// readonly, not private readonly, not public readonly | ||
const isReadonly = node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.ReadonlyKeyword); | ||
const isProtectedOrPrivate = node.modifiers.some(modifier => { | ||
return modifier.kind === ts.SyntaxKind.ProtectedKeyword || modifier.kind === ts.SyntaxKind.PrivateKeyword; | ||
}); | ||
const isReadonly = node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword); | ||
const isProtectedOrPrivate = node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ProtectedKeyword || modifier.kind === ts.SyntaxKind.PrivateKeyword); | ||
return isReadonly && !isProtectedOrPrivate; | ||
@@ -1088,0 +1056,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Property } from "../type"; | ||
import { Property } from '../type'; | ||
export declare namespace Resolver { | ||
@@ -3,0 +3,0 @@ type TypeStringLiteral = 'string' | 'boolean' | 'double' | 'float' | 'file' | 'integer' | 'long' | 'enum' | 'array' | 'datetime' | 'date' | 'binary' | 'buffer' | 'byte' | 'void' | 'object' | 'any' | 'refEnum' | 'refObject' | 'refAlias' | 'nestedObjectLiteral' | 'union' | 'intersection'; |
import * as ts from 'typescript'; | ||
import { Resolver } from "../type"; | ||
import { Resolver } from '../type'; | ||
export declare function getInitializerValue(initializer?: ts.Expression, typeChecker?: ts.TypeChecker, type?: Resolver.Type): unknown; | ||
export declare const hasInitializer: (node: ts.Node) => node is ts.HasInitializer; | ||
//# sourceMappingURL=initializer.d.ts.map |
@@ -38,3 +38,3 @@ "use strict"; | ||
const arrayLiteral = initializer; | ||
return arrayLiteral.elements.map(element => getInitializerValue(element, typeChecker)); | ||
return arrayLiteral.elements.map((element) => getInitializerValue(element, typeChecker)); | ||
case ts.SyntaxKind.StringLiteral: | ||
@@ -55,4 +55,4 @@ return initializer.text; | ||
if (newExpression.arguments) { | ||
const newArguments = newExpression.arguments.filter(args => args.kind !== undefined); | ||
const argsValue = newArguments.map(args => getInitializerValue(args, typeChecker)); | ||
const newArguments = newExpression.arguments.filter((args) => args.kind !== undefined); | ||
const argsValue = newArguments.map((args) => getInitializerValue(args, typeChecker)); | ||
if (argsValue.length > 0) { | ||
@@ -80,14 +80,12 @@ date = new Date(argsValue); | ||
} | ||
else { | ||
if (typeof initializer.parent === 'undefined' || | ||
typeof typeChecker === 'undefined') { | ||
if ((0, metadata_utils_1.hasOwnProperty)(initializer, 'text')) { | ||
return initializer.text; | ||
} | ||
return undefined; | ||
if (typeof initializer.parent === 'undefined' || | ||
typeof typeChecker === 'undefined') { | ||
if ((0, metadata_utils_1.hasOwnProperty)(initializer, 'text')) { | ||
return initializer.text; | ||
} | ||
const symbol = typeChecker.getSymbolAtLocation(initializer); | ||
const extractedInitializer = symbol && symbol.valueDeclaration && (0, exports.hasInitializer)(symbol.valueDeclaration) && symbol.valueDeclaration.initializer; | ||
return extractedInitializer ? getInitializerValue(extractedInitializer, typeChecker) : undefined; | ||
return undefined; | ||
} | ||
const symbol = typeChecker.getSymbolAtLocation(initializer); | ||
const extractedInitializer = symbol && symbol.valueDeclaration && (0, exports.hasInitializer)(symbol.valueDeclaration) && symbol.valueDeclaration.initializer; | ||
return extractedInitializer ? getInitializerValue(extractedInitializer, typeChecker) : undefined; | ||
} | ||
@@ -94,0 +92,0 @@ } |
import { ParameterDeclaration } from 'typescript'; | ||
import { Validator } from "../../type"; | ||
import { Validator } from '../../type'; | ||
export declare function getParameterValidators(parameter: ParameterDeclaration, name: string): Record<string, Validator>; | ||
//# sourceMappingURL=validator.d.ts.map |
@@ -16,6 +16,6 @@ "use strict"; | ||
const getCommentValue = (comment) => comment && comment.split(' ')[0]; | ||
const tags = (0, utils_1.getJSDocTags)(parameter.parent, tag => { | ||
let { comment } = tag; | ||
const tags = (0, utils_1.getJSDocTags)(parameter.parent, (tag) => { | ||
const { comment } = tag; | ||
const text = Array.isArray(comment) ? (comment.length > 0 ? comment[0].text : undefined) : comment; | ||
return getSupportedParameterTags().some(value => !!comment && value === tag.tagName.text && getCommentValue(text) === name); | ||
return getSupportedParameterTags().some((value) => !!comment && value === tag.tagName.text && getCommentValue(text) === name); | ||
}); | ||
@@ -31,12 +31,8 @@ function getErrorMsg(comment, isValue = true) { | ||
} | ||
else { | ||
return undefined; | ||
} | ||
return undefined; | ||
} | ||
else { | ||
return comment; | ||
} | ||
return comment; | ||
} | ||
const validators = {}; | ||
tags.map(tag => { | ||
tags.map((tag) => { | ||
var _a; | ||
@@ -43,0 +39,0 @@ if (!tag.comment) { |
@@ -1,4 +0,4 @@ | ||
import { Resolver } from "./resolver"; | ||
import { Decorator } from "./decorator"; | ||
import { Cache } from "./cache"; | ||
import { Resolver } from './resolver'; | ||
import { Decorator } from './decorator'; | ||
import { Cache } from './cache'; | ||
export interface Config { | ||
@@ -5,0 +5,0 @@ /** |
import { CompilerOptions } from 'typescript'; | ||
import { Config, GeneratorOutput } from "../type"; | ||
import { MetadataGenerator } from "../generator"; | ||
import { Config, GeneratorOutput } from '../type'; | ||
import { MetadataGenerator } from '../generator'; | ||
export declare function createMetadataGenerator(config: Config, compilerOptions?: CompilerOptions | boolean): MetadataGenerator; | ||
export declare function generateMetadata(config: Config, compilerOptions?: CompilerOptions | boolean): GeneratorOutput; | ||
//# sourceMappingURL=generator.d.ts.map |
@@ -10,4 +10,4 @@ "use strict"; | ||
exports.generateMetadata = exports.createMetadataGenerator = void 0; | ||
const metadata_utils_1 = require("@trapi/metadata-utils"); | ||
const generator_1 = require("../generator"); | ||
const metadata_utils_1 = require("@trapi/metadata-utils"); | ||
function createMetadataGenerator(config, compilerOptions) { | ||
@@ -14,0 +14,0 @@ const skipLoad = (typeof compilerOptions === 'boolean' && !compilerOptions) || |
@@ -21,3 +21,3 @@ "use strict"; | ||
const jsDocs = node.jsDoc | ||
.filter(jsDoc => typeof jsDoc.comment === 'string'); | ||
.filter((jsDoc) => typeof jsDoc.comment === 'string'); | ||
if (jsDocs.length === 0) { | ||
@@ -60,3 +60,3 @@ return undefined; | ||
const tagNames = Array.isArray(isMatching) ? isMatching : [isMatching]; | ||
return jsDocTags.filter(tag => tagNames.indexOf(tag.tagName.text) !== -1); | ||
return jsDocTags.filter((tag) => tagNames.indexOf(tag.tagName.text) !== -1); | ||
} | ||
@@ -88,7 +88,7 @@ exports.getJSDocTags = getJSDocTags; | ||
const parameterName = node.name.text; | ||
tags = getJSDocTags(node.parent, tag => { | ||
tags = getJSDocTags(node.parent, (tag) => { | ||
if ((0, typescript_1.isJSDocParameterTag)(tag)) { | ||
return false; | ||
} | ||
else if (tag.comment === undefined) { | ||
if (tag.comment === undefined) { | ||
throw new resolver_1.ResolverError(`Orphan tag: @${String(tag.tagName.text || tag.tagName.escapedText)} should have a parameter name follows with.`); | ||
@@ -100,11 +100,7 @@ } | ||
else { | ||
tags = getJSDocTags(node, tag => { | ||
return requireTagName ? tag.comment !== undefined : true; | ||
}); | ||
tags = getJSDocTags(node, (tag) => (requireTagName ? tag.comment !== undefined : true)); | ||
} | ||
return tags.map(tag => { | ||
return tag.tagName.text; | ||
}); | ||
return tags.map((tag) => tag.tagName.text); | ||
} | ||
exports.getJSDocTagNames = getJSDocTagNames; | ||
//# sourceMappingURL=js-doc.js.map |
@@ -1,4 +0,4 @@ | ||
import { SchemaOf } from "yup"; | ||
import { Config } from "../type"; | ||
import { SchemaOf } from 'yup'; | ||
import { Config } from '../type'; | ||
export declare function useConfigValidator(): SchemaOf<Config>; | ||
//# sourceMappingURL=validator.d.ts.map |
@@ -18,3 +18,3 @@ "use strict"; | ||
validatorInstance = (0, yup_1.object)({ | ||
entryFile: (0, yup_1.lazy)(value => { | ||
entryFile: (0, yup_1.lazy)((value) => { | ||
if (typeof value === 'string') { | ||
@@ -25,3 +25,3 @@ return (0, yup_1.string)().required(); | ||
}), | ||
cache: (0, yup_1.lazy)(value => { | ||
cache: (0, yup_1.lazy)((value) => { | ||
if (typeof value === 'string') { | ||
@@ -28,0 +28,0 @@ return (0, yup_1.string)(); |
{ | ||
"name": "@trapi/metadata", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Generate REST-API metadata scheme from TypeScript Decorators.", | ||
@@ -15,3 +15,3 @@ "main": "./dist/index.js", | ||
"test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js", | ||
"test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage", | ||
"test:coverage": "npm run test -- --coverage", | ||
"preblushOnly": "npm run build" | ||
@@ -37,3 +37,3 @@ }, | ||
"@types/minimatch": "^3.0.5", | ||
"@types/node": "^16.11.12", | ||
"@types/node": "^17.0.14", | ||
"@types/yup": "^0.29.13", | ||
@@ -45,6 +45,6 @@ "jest": "^27.4.7", | ||
"dependencies": { | ||
"@trapi/metadata-utils": "^0.0.4", | ||
"@trapi/metadata-utils": "^0.0.5", | ||
"glob": "^7.2.0", | ||
"minimatch": "^3.0.4", | ||
"typescript": "^4.5.4", | ||
"typescript": "^4.5.5", | ||
"yup": "^0.32.11" | ||
@@ -55,3 +55,3 @@ }, | ||
}, | ||
"gitHead": "62b194d06e2fe4bcce24df6306cfcdfa7c1479a6" | ||
"gitHead": "f8ebabe5794093769ba5bf9fa4542544c06a0179" | ||
} |
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
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
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
341594
4738
+ Added@trapi/metadata-utils@0.0.5(transitive)
- Removed@trapi/metadata-utils@0.0.4(transitive)
Updated@trapi/metadata-utils@^0.0.5
Updatedtypescript@^4.5.5