New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@trapi/metadata

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trapi/metadata - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

dist/errors/index.d.ts

2

dist/generator/controller.d.ts

@@ -1,2 +0,2 @@

import { MetadataGeneratorInterface } from '@trapi/decorator';
import { MetadataGeneratorInterface } from '@trapi/decorators';
import { ClassDeclaration } from 'typescript';

@@ -3,0 +3,0 @@ import { EndpointGenerator } from './endpoint';

@@ -1,2 +0,2 @@

import { MapperIDProperties, MetadataGeneratorInterface } from '@trapi/decorator';
import { MapperIDProperties, MetadataGeneratorInterface } from '@trapi/decorators';
import { ArrayLiteralExpression, Node } from 'typescript';

@@ -3,0 +3,0 @@ import { Response } from '../type';

@@ -10,3 +10,3 @@ "use strict";

exports.EndpointGenerator = void 0;
const decorator_1 = require("@trapi/decorator");
const decorators_1 = require("@trapi/decorators");
const typescript_1 = require("typescript");

@@ -34,3 +34,3 @@ const utils_1 = require("../utils");

getDecoratorValues(decoratorName, acceptMultiple = false) {
const decorators = (0, decorator_1.getNodeDecorators)(this.node, (decorator) => decorator.text === decoratorName);
const decorators = (0, decorators_1.getNodeDecorators)(this.node, (decorator) => decorator.text === decoratorName);
if (!decorators || !decorators.length) {

@@ -81,7 +81,7 @@ return [];

argument.properties.forEach((p) => {
example[p.name.text] = (0, decorator_1.getInitializerValue)(p.initializer, this.current.typeChecker);
example[p.name.text] = (0, decorators_1.getInitializerValue)(p.initializer, this.current.typeChecker);
});
}
else {
example = (0, decorator_1.getInitializerValue)(argument, this.current.typeChecker);
example = (0, decorators_1.getInitializerValue)(argument, this.current.typeChecker);
}

@@ -105,3 +105,3 @@ return example;

examples,
schema: type ? new decorator_1.TypeNodeResolver(type, this.current).resolve() : undefined,
schema: type ? new decorators_1.TypeNodeResolver(type, this.current).resolve() : undefined,
status: status,

@@ -155,3 +155,3 @@ name: status,

isDeprecated(node) {
if ((0, decorator_1.isExistJSDocTag)(node, (tag) => tag.tagName.text === 'deprecated')) {
if ((0, decorators_1.isExistJSDocTag)(node, (tag) => tag.tagName.text === 'deprecated')) {
return true;

@@ -158,0 +158,0 @@ }

@@ -1,2 +0,2 @@

import { MetadataGeneratorInterface } from '@trapi/decorator';
import { MetadataGeneratorInterface } from '@trapi/decorators';
import * as ts from 'typescript';

@@ -3,0 +3,0 @@ import { EndpointGenerator } from './endpoint';

@@ -33,3 +33,3 @@ "use strict";

exports.MethodGenerator = void 0;
const decorator_1 = require("@trapi/decorator");
const decorators_1 = require("@trapi/decorators");
const pathUtil = __importStar(require("path"));

@@ -66,3 +66,3 @@ const ts = __importStar(require("typescript"));

}
const type = new decorator_1.TypeNodeResolver(nodeType, this.current).resolve();
const type = new decorators_1.TypeNodeResolver(nodeType, this.current).resolve();
const responses = this.mergeResponses(this.getResponses(), this.getMethodSuccessResponse(type));

@@ -73,3 +73,3 @@ return {

deprecated: this.isDeprecated(this.node),
description: (0, decorator_1.getJSDocDescription)(this.node),
description: (0, decorators_1.getJSDocDescription)(this.node),
extensions: [],

@@ -84,3 +84,3 @@ hidden: this.isHidden(this.node),

security: this.getSecurity(),
summary: (0, decorator_1.getJSDocTagComment)(this.node, 'summary'),
summary: (0, decorators_1.getJSDocTagComment)(this.node, 'summary'),
tags: this.getTags(),

@@ -119,3 +119,3 @@ type,

processMethodDecorators() {
const httpMethodDecorators = (0, decorator_1.getNodeDecorators)(this.node, (decorator) => this.supportsPathMethod(decorator.text));
const httpMethodDecorators = (0, decorators_1.getNodeDecorators)(this.node, (decorator) => this.supportsPathMethod(decorator.text));
if (!httpMethodDecorators || !httpMethodDecorators.length) {

@@ -134,11 +134,11 @@ return;

return {
description: (0, decorator_1.isVoidType)(type) ? 'No content' : 'Ok',
description: (0, decorators_1.isVoidType)(type) ? 'No content' : 'Ok',
examples: this.getMethodSuccessExamples(),
schema: type,
status: (0, decorator_1.isVoidType)(type) ? '204' : '200',
name: (0, decorator_1.isVoidType)(type) ? '204' : '200',
status: (0, decorators_1.isVoidType)(type) ? '204' : '200',
name: (0, decorators_1.isVoidType)(type) ? '204' : '200',
};
}
getMethodSuccessResponseType(type) {
if (!(0, decorator_1.isVoidType)(type)) {
if (!(0, decorators_1.isVoidType)(type)) {
return type;

@@ -154,3 +154,3 @@ }

ts.isTypeNode(value)) {
type = new decorator_1.TypeNodeResolver(value, this.current).resolve();
type = new decorators_1.TypeNodeResolver(value, this.current).resolve();
}

@@ -157,0 +157,0 @@ return type;

@@ -1,2 +0,2 @@

import { DependencyResolver, Mapper, MetadataGeneratorInterface, ReferenceType } from '@trapi/decorator';
import { DependencyResolver, Mapper, MetadataGeneratorInterface, ReferenceType } from '@trapi/decorators';
import { CompilerOptions, Node, TypeChecker } from 'typescript';

@@ -3,0 +3,0 @@ import { Config, GeneratorOutput } from '../type';

@@ -13,3 +13,3 @@ "use strict";

exports.MetadataGenerator = void 0;
const decorator_1 = require("@trapi/decorator");
const decorators_1 = require("@trapi/decorators");
const minimatch_1 = __importDefault(require("minimatch"));

@@ -28,4 +28,4 @@ const glob_1 = require("glob");

this.cache = new cache_1.CacheDriver(config.cache);
this.decoratorMapper = new decorator_1.Mapper(config.decorator);
decorator_1.TypeNodeResolver.clearCache();
this.decoratorMapper = new decorators_1.Mapper(config.decorator);
decorators_1.TypeNodeResolver.clearCache();
const sourceFiles = this.scanSourceFiles(config.entryPoint);

@@ -32,0 +32,0 @@ this.program = (0, typescript_1.createProgram)(sourceFiles, compilerOptions);

@@ -1,2 +0,2 @@

import { MetadataGeneratorInterface } from '@trapi/decorator';
import { MetadataGeneratorInterface } from '@trapi/decorators';
import * as ts from 'typescript';

@@ -22,2 +22,3 @@ import { Parameter } from '../type';

private getParameterDescription;
private getParameterDeprecation;
private supportsBodyParameters;

@@ -24,0 +25,0 @@ private supportPathDataType;

@@ -33,6 +33,8 @@ "use strict";

exports.ParameterGenerator = void 0;
const decorator_1 = require("@trapi/decorator");
const decorators_1 = require("@trapi/decorators");
const ts = __importStar(require("typescript"));
const supportedParameterKeys = [
const errors_1 = require("../errors");
const parameterKeys = [
'SERVER_CONTEXT',
'SERVER_PARAM',
'SERVER_PARAMS',

@@ -42,4 +44,7 @@ 'SERVER_QUERY',

'SERVER_BODY',
'SERVER_HEADER',
'SERVER_HEADERS',
'SERVER_COOKIE',
'SERVER_COOKIES',
'SERVER_PATH_PARAM',
'SERVER_PATH_PARAMS',

@@ -56,11 +61,12 @@ 'SERVER_FILES_PARAM',

generate() {
const decorators = (0, decorator_1.getNodeDecorators)(this.parameter);
for (let i = 0; i < supportedParameterKeys.length; i++) {
const representation = this.current.decoratorMapper.match(supportedParameterKeys[i], decorators);
const decorators = (0, decorators_1.getNodeDecorators)(this.parameter);
for (let i = 0; i < parameterKeys.length; i++) {
const representation = this.current.decoratorMapper.match(parameterKeys[i], decorators);
if (typeof representation === 'undefined') {
continue;
}
switch (supportedParameterKeys[i]) {
switch (parameterKeys[i]) {
case 'SERVER_CONTEXT':
return this.getContextParameter();
case 'SERVER_PARAM':
case 'SERVER_PARAMS':

@@ -74,6 +80,9 @@ return this.getRequestParameter(representation);

return this.getBodyParameter(representation);
case 'SERVER_HEADER':
case 'SERVER_HEADERS':
return this.getHeaderParameter(representation);
case 'SERVER_COOKIE':
case 'SERVER_COOKIES':
return this.getCookieParameter(representation);
case 'SERVER_PATH_PARAM':
case 'SERVER_PATH_PARAMS':

@@ -106,3 +115,4 @@ return this.getPathParameter(representation);

return {
description: this.getParameterDescription(this.parameter),
default: (0, decorators_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(),
in: 'param',

@@ -113,2 +123,3 @@ name: name || parameterName,

type,
deprecated: this.getParameterDeprecation(),
};

@@ -119,3 +130,3 @@ }

return {
description: this.getParameterDescription(this.parameter),
description: this.getParameterDescription(),
in: 'context',

@@ -165,3 +176,4 @@ name: parameterName,

return {
description: this.getParameterDescription(this.parameter),
default: (0, decorators_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(),
in: 'formData',

@@ -172,2 +184,3 @@ name: name || parameterName,

type,
deprecated: this.getParameterDeprecation(),
};

@@ -187,3 +200,4 @@ }

return {
description: this.getParameterDescription(this.parameter),
default: (0, decorators_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(),
in: 'formData',

@@ -194,2 +208,3 @@ name: name || parameterName,

type,
deprecated: this.getParameterDeprecation(),
};

@@ -209,3 +224,4 @@ }

return {
description: this.getParameterDescription(this.parameter),
default: (0, decorators_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(),
in: 'cookie',

@@ -216,2 +232,3 @@ name: name || parameterName,

type,
deprecated: this.getParameterDeprecation(),
};

@@ -233,3 +250,4 @@ }

return {
description: this.getParameterDescription(this.parameter),
default: (0, decorators_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(),
in: 'body',

@@ -240,2 +258,3 @@ name: name || parameterName,

type,
deprecated: this.getParameterDeprecation(),
};

@@ -248,3 +267,3 @@ }

if (!this.supportPathDataType(type)) {
throw new InvalidParameterException(`Parameter '${parameterName}' can't be passed as a header parameter in '${this.getCurrentLocation()}'.`);
throw new errors_1.InvalidParameterException(`Parameter '${parameterName}' can't be passed as a header parameter in '${this.getCurrentLocation()}'.`);
}

@@ -256,3 +275,4 @@ const value = representationManager.getPropertyValue('DEFAULT');

return {
description: this.getParameterDescription(this.parameter),
default: (0, decorators_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(),
in: 'header',

@@ -263,2 +283,3 @@ name: name || parameterName,

type,
deprecated: this.getParameterDeprecation(),
};

@@ -297,4 +318,4 @@ }

collectionFormat: options.collectionFormat,
default: (0, decorator_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(this.parameter),
default: (0, decorators_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(),
in: 'query',

@@ -307,2 +328,3 @@ maxItems: options.maxItems,

type,
deprecated: this.getParameterDeprecation(),
};

@@ -323,3 +345,3 @@ if (type.typeName === 'array') {

if (!this.supportPathDataType(type)) {
throw new InvalidParameterException(`Parameter '${parameterName}:${type}' can't be passed as a path parameter in '${this.getCurrentLocation()}'.`);
throw new errors_1.InvalidParameterException(`Parameter '${parameterName}:${type}' can't be passed as a path parameter in '${this.getCurrentLocation()}'.`);
}

@@ -330,3 +352,4 @@ if ((!this.path.includes(`{${pathName}}`)) && (!this.path.includes(`:${pathName}`))) {

return {
description: this.getParameterDescription(this.parameter),
default: (0, decorators_1.getInitializerValue)(this.parameter.initializer, this.current.typeChecker, type),
description: this.getParameterDescription(),
in: 'path',

@@ -337,6 +360,7 @@ name: pathName,

type,
deprecated: this.getParameterDeprecation(),
};
}
getParameterDescription(node) {
const symbol = this.current.typeChecker.getSymbolAtLocation(node.name);
getParameterDescription() {
const symbol = this.current.typeChecker.getSymbolAtLocation(this.parameter.name);
if (symbol) {

@@ -350,2 +374,9 @@ const comments = symbol.getDocumentationComment(this.current.typeChecker);

}
getParameterDeprecation() {
if ((0, decorators_1.isExistJSDocTag)(this.parameter, (tag) => tag.tagName.text === 'deprecated')) {
return true;
}
const decorators = (0, decorators_1.getNodeDecorators)(this.parameter, (identifier) => identifier.text === 'Deprecated');
return decorators.length > 0;
}
supportsBodyParameters(method) {

@@ -368,8 +399,6 @@ return ['delete', 'post', 'put', 'patch', 'get'].some((m) => m === method);

}
return new decorator_1.TypeNodeResolver(typeNode, this.current, parameter).resolve();
return new decorators_1.TypeNodeResolver(typeNode, this.current, parameter).resolve();
}
}
exports.ParameterGenerator = ParameterGenerator;
class InvalidParameterException extends Error {
}
//# sourceMappingURL=parameter.js.map
export * from './cache';
export * from './errors';
export * from './generator';

@@ -3,0 +4,0 @@ export * from './module';

@@ -24,2 +24,3 @@ "use strict";

__exportStar(require("./cache"), exports);
__exportStar(require("./errors"), exports);
__exportStar(require("./generator"), exports);

@@ -26,0 +27,0 @@ __exportStar(require("./module"), exports);

@@ -1,2 +0,2 @@

import { ArrayType, BaseType, Config as DecoratorConfig, NestedObjectLiteralType, RefObjectType, ReferenceTypes } from '@trapi/decorator';
import { ArrayType, BaseType, Config as DecoratorConfig, NestedObjectLiteralType, RefObjectType, ReferenceTypes } from '@trapi/decorators';
import { CompilerOptions } from 'typescript';

@@ -3,0 +3,0 @@ import { Cache } from './cache';

{
"name": "@trapi/metadata",
"version": "0.3.1",
"version": "0.4.0",
"description": "Generate REST-API metadata scheme from TypeScript Decorators.",

@@ -42,3 +42,3 @@ "main": "./dist/index.js",

"devDependencies": {
"@trapi/decorator": "^0.0.3",
"@trapi/decorators": "^0.1.0",
"@types/glob": "^8.0.0",

@@ -54,3 +54,3 @@ "@types/minimatch": "^5.1.2",

"peerDependencies": {
"@trapi/decorator": ">=0.0.2 <1.0.0"
"@trapi/decorators": ">=0.0.0 <1.0.0"
},

@@ -60,3 +60,3 @@ "publishConfig": {

},
"gitHead": "3a79951e732e4b724e699f138a61b9374cb3e16f"
"gitHead": "cf4d5975d8057cae096f2f2d3ddd6fe062ebcf01"
}

@@ -34,3 +34,3 @@ # @trapi/metadata 📚

```typescript
import { Config } from '@trapi/decorator';
import { Config as DecoratorConfig } from '@trapi/decorator';
import { Cache } from '@trapi/metadata';

@@ -71,3 +71,3 @@

*/
decorator?: Config;
decorator?: DecoratorConfig;
}

@@ -147,3 +147,3 @@ ```

// we can use them both :)
library: ['decorators-express', 'typescript-rest']
preset: ['decorators-express', 'typescript-rest']
}

@@ -150,0 +150,0 @@ });

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc