Socket
Socket
Sign inDemoInstall

@tsed/schema

Package Overview
Dependencies
Maintainers
5
Versions
789
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsed/schema - npm Package Compare versions

Comparing version 5.60.7 to 5.61.0

lib/utils/getComputedType.d.ts

7

lib/decorators/collections/collectionOf.js

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

const store = JsonEntityStore_1.JsonEntityStore.from(...args);
const itemSchema = store.itemSchema.toJSON();
// const itemSchema = store.itemSchema.toJSON();
if (collectionType) {

@@ -45,3 +45,6 @@ store.collectionType = collectionType;

store.type = type;
store.itemSchema.assign({ ...itemSchema, type });
// console.log(type);
store.itemSchema.type(type);
// console.log(store.itemSchema.getComputedType(), schema);
// store.itemSchema.assign({...itemSchema, type});
store.schema.assign(schema);

@@ -48,0 +51,0 @@ if (store.isArray && contains) {

@@ -37,2 +37,2 @@ /**

*/
export declare function MaxItems(maxItems: number): any;
export declare function MaxItems(maxItems: number): (...args: any[]) => any;

@@ -44,2 +44,2 @@ /**

*/
export declare function MinItems(minItems: number): any;
export declare function MinItems(minItems: number): (...args: any[]) => any;

@@ -45,2 +45,2 @@ /**

*/
export declare function UniqueItems(uniqueItems?: boolean): any;
export declare function UniqueItems(uniqueItems?: boolean): (...args: any[]) => any;

@@ -6,2 +6,2 @@ /**

*/
export declare function AdditionalProperties(bool: boolean): any;
export declare function AdditionalProperties(bool: boolean): (...args: any[]) => any;

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

const jsonEntityFn_1 = require("./jsonEntityFn");
const property_1 = require("./property");
function applyStringRule(store, values) {

@@ -63,6 +62,8 @@ if (store.type === String) {

function Allow(...values) {
return core_1.applyDecorators(property_1.Property(), jsonEntityFn_1.JsonEntityFn((store, args) => {
return core_1.applyDecorators(jsonEntityFn_1.JsonEntityFn((store, args) => {
switch (store.decoratorType) {
case core_1.DecoratorTypes.PARAM:
store.parameter.required(true);
applyStringRule(store, values);
applyNullRule(store, values);
break;

@@ -69,0 +70,0 @@ case core_1.DecoratorTypes.PROP:

@@ -36,2 +36,2 @@ import { Type } from "@tsed/core";

*/
export declare function Any(...types: (JSONSchema6TypeName | Type<any> | any)[]): any;
export declare function Any(...types: (JSONSchema6TypeName | Type<any> | any)[]): (...args: any[]) => any;

@@ -59,2 +59,2 @@ import { JSONSchema6Type } from "json-schema";

*/
export declare function Const(constValue: JSONSchema6Type | any): any;
export declare function Const(constValue: JSONSchema6Type | any): (...args: any[]) => any;

@@ -37,2 +37,2 @@ /**

*/
export declare function Default(defaultValue: string | number | boolean | {}): any;
export declare function Default(defaultValue: string | number | boolean | {}): (...args: any[]) => any;

@@ -49,2 +49,2 @@ /**

*/
export declare function Description(description: any): any;
export declare function Description(description: any): (...args: any[]) => any;

@@ -95,2 +95,2 @@ import { JSONSchema6Type } from "json-schema";

*/
export declare function Enum(enumValue: JSONSchema6Type | any, ...enumValues: JSONSchema6Type[]): any;
export declare function Enum(enumValue: JSONSchema6Type | any, ...enumValues: JSONSchema6Type[]): (...args: any[]) => any;

@@ -12,2 +12,5 @@ "use strict";

example = name;
if (typeof name === "string") {
example = [].concat(example);
}
}

@@ -14,0 +17,0 @@ return jsonEntityFn_1.JsonEntityFn((store, args) => {

@@ -66,2 +66,2 @@ /**

*/
export declare function ExclusiveMaximum(maximum: number, exclusiveMaximum?: boolean): any;
export declare function ExclusiveMaximum(maximum: number, exclusiveMaximum?: boolean): (...args: any[]) => any;

@@ -66,2 +66,2 @@ /**

*/
export declare function ExclusiveMinimum(minimum: number, exclusiveMinimum?: boolean): any;
export declare function ExclusiveMinimum(minimum: number, exclusiveMinimum?: boolean): (...args: any[]) => any;

@@ -76,3 +76,3 @@ import { ValueOf } from "@tsed/core";

*/
export declare function Format(format: JsonFormatTypes | ValueOf<JsonFormatTypes>): any;
export declare function Format(format: JsonFormatTypes | ValueOf<JsonFormatTypes>): (...args: any[]) => any;
/**

@@ -140,3 +140,3 @@ * Apply an email validation on property.

*/
export declare function Email(): any;
export declare function Email(): (...args: any[]) => any;
/**

@@ -205,3 +205,3 @@ * Apply a date-time validation on property.

*/
export declare function DateTime(): any;
export declare function DateTime(): (...args: any[]) => any;
/**

@@ -270,3 +270,3 @@ * Apply a time validation on property.

*/
export declare function DateFormat(): any;
export declare function DateFormat(): (...args: any[]) => any;
/**

@@ -335,3 +335,3 @@ * Apply a time validation on property.

*/
export declare function TimeFormat(): any;
export declare function TimeFormat(): (...args: any[]) => any;
/**

@@ -400,2 +400,2 @@ * Apply a uri validation on property.

*/
export declare function Uri(): any;
export declare function Uri(): (...args: any[]) => any;

@@ -62,2 +62,2 @@ import { IgnoreCallback } from "../../interfaces";

*/
export declare function Ignore(cb?: boolean | IgnoreCallback): any;
export declare function Ignore(cb?: boolean | IgnoreCallback): (...args: any[]) => any;

@@ -8,2 +8,2 @@ import { DecoratorParameters } from "@tsed/core";

*/
export declare function JsonEntityFn<T extends JsonEntityStore>(fn: (entity: T, parameters: DecoratorParameters) => void): any;
export declare function JsonEntityFn<T extends JsonEntityStore>(fn: (entity: T, parameters: DecoratorParameters) => void): (...args: any[]) => any;

@@ -66,3 +66,3 @@ /**

*/
export declare function Maximum(maximum: number, exclusive?: boolean): any;
export declare function Max(maximum: number, exclusive?: boolean): any;
export declare function Maximum(maximum: number, exclusive?: boolean): (...args: any[]) => any;
export declare function Max(maximum: number, exclusive?: boolean): (...args: any[]) => any;

@@ -73,2 +73,2 @@ /**

*/
export declare function MaxLength(maxLength: number): any;
export declare function MaxLength(maxLength: number): (...args: any[]) => any;

@@ -62,2 +62,2 @@ /**

*/
export declare function MaxProperties(maxProperties: number): any;
export declare function MaxProperties(maxProperties: number): (...args: any[]) => any;

@@ -66,3 +66,3 @@ /**

*/
export declare function Minimum(minimum: number, exclusive?: boolean): any;
export declare function Minimum(minimum: number, exclusive?: boolean): (...args: any[]) => any;
/**

@@ -129,2 +129,2 @@ * The value of `minimum` MUST be a number, representing an inclusive upper limit for a numeric instance.

*/
export declare function Min(minimum: number, exclusive?: boolean): any;
export declare function Min(minimum: number, exclusive?: boolean): (...args: any[]) => any;

@@ -73,2 +73,2 @@ /**

*/
export declare function MinLength(minLength: number): any;
export declare function MinLength(minLength: number): (...args: any[]) => any;

@@ -62,2 +62,2 @@ /**

*/
export declare function MinProperties(minProperties: number): any;
export declare function MinProperties(minProperties: number): (...args: any[]) => any;

@@ -64,2 +64,2 @@ /**

*/
export declare function MultipleOf(multipleOf: number): any;
export declare function MultipleOf(multipleOf: number): (...args: any[]) => any;

@@ -31,2 +31,2 @@ /**

*/
export declare function Name(name: any): any;
export declare function Name(name: any): (...args: any[]) => any;

@@ -88,2 +88,2 @@ /**

*/
export declare function Pattern(pattern: string | RegExp): any;
export declare function Pattern(pattern: string | RegExp): (...args: any[]) => any;

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

export declare function Property(type?: any): any;
export declare function Property(type?: any): (...args: any[]) => any;

@@ -37,2 +37,2 @@ import { JSONSchema6 } from "json-schema";

*/
export declare function Schema(partialSchema: Partial<JSONSchema6>): any;
export declare function Schema(partialSchema: Partial<JSONSchema6>): (...args: any[]) => any;

@@ -31,2 +31,2 @@ /**

*/
export declare function Title(title: string): any;
export declare function Title(title: string): (...args: any[]) => any;

@@ -18,2 +18,2 @@ /**

*/
export declare function Consumes(...consumes: string[]): any;
export declare function Consumes(...consumes: string[]): (...args: any[]) => any;

@@ -18,2 +18,2 @@ /**

*/
export declare function Deprecated(deprecated?: boolean): any;
export declare function Deprecated(deprecated?: boolean): (...args: any[]) => any;

@@ -7,2 +7,2 @@ import { JsonParameterTypes } from "../../domain/JsonParameterTypes";

*/
export declare function In(inType: JsonParameterTypes | string): any;
export declare function In(inType: JsonParameterTypes | string): (...args: any[]) => any;

@@ -6,2 +6,2 @@ /**

*/
export declare function OperationId(operationId: string): any;
export declare function OperationId(operationId: string): (...args: any[]) => any;

@@ -19,2 +19,2 @@ export declare enum OperationMethods {

*/
export declare function OperationPath(method: OperationMethods | string, path?: string | RegExp): any;
export declare function OperationPath(method: OperationMethods | string, path?: string | RegExp): (...args: any[]) => any;

@@ -8,2 +8,2 @@ /**

*/
export declare function Path(path: string): any;
export declare function Path(path: string): (...args: any[]) => any;

@@ -23,2 +23,2 @@ /**

*/
export declare function Produces(...produces: string[]): any;
export declare function Produces(...produces: string[]): (...args: any[]) => any;

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

decorator.Examples = (examples) => {
response.set("examples", examples);
response.set("examples", core_1.isString(examples) ? [examples] : examples);
return decorator;

@@ -216,0 +216,0 @@ };

@@ -21,2 +21,2 @@ /**

*/
export declare function Security(name: string, ...scopes: string[]): any;
export declare function Security(name: string, ...scopes: string[]): (...args: any[]) => any;

@@ -18,2 +18,2 @@ /**

*/
export declare function Summary(summary: string): any;
export declare function Summary(summary: string): (...args: any[]) => any;

@@ -21,2 +21,2 @@ import { JsonTag } from "../../interfaces/JsonOpenSpec";

*/
export declare function Tags(...tags: (string | JsonTag)[]): any;
export declare function Tags(...tags: (string | JsonTag)[]): (...args: any[]) => any;

@@ -10,1 +10,2 @@ export * from "./JsonMap";

export * from "./JsonEntityStore";
export * from "./JsonParameterTypes";

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

tslib_1.__exportStar(require("./JsonEntityStore"), exports);
tslib_1.__exportStar(require("./JsonParameterTypes"), exports);
//# sourceMappingURL=index.js.map

@@ -72,6 +72,2 @@ import { DecoratorTypes, Entity, EntityOptions, Store, Type } from "@tsed/core";

static fromMethod(target: any, propertyKey: string | symbol): JsonEntityStore;
/**
* Return a child store
* @param key
*/
protected build(): void;

@@ -78,0 +74,0 @@ protected createProperty(): any;

@@ -131,9 +131,2 @@ "use strict";

}
/**
* Return a child store
* @param key
*/
// get(key: string | number) {
// return this.children.get(key);
// }
build() {

@@ -154,2 +147,3 @@ if (!this._type) {

type = core_1.Store.getReturnType(this.target, this.propertyKey);
type = core_1.isPromise(type) ? undefined : type;
break;

@@ -229,8 +223,9 @@ }

parentStore.children.set(this.index, this);
this._schema = getSchema(this.collectionType || this.type);
parameter.schema(this._schema);
if (this.collectionType) {
this._schema.itemSchema(getSchema(this.type));
}
(_a = parentStore.operation) === null || _a === void 0 ? void 0 : _a.addParameter(this.index, parameter);
}
parameter.schema((this._schema = getSchema(this.collectionType || this.type)));
if (this.collectionType) {
this._schema.itemSchema(getSchema(this.type));
}
(_a = parentStore.operation) === null || _a === void 0 ? void 0 : _a.addParameter(this.index, parameter);
return parameter;

@@ -237,0 +232,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@tsed/core");
const httpStatusMessages_1 = require("../constants/httpStatusMessages");
const isSuccessStatus_1 = require("../utils/isSuccessStatus");
const httpStatusMessages_1 = require("../constants/httpStatusMessages");
const JsonMap_1 = require("./JsonMap");

@@ -130,12 +130,14 @@ const JsonParameter_1 = require("./JsonParameter");

this.get("parameters").forEach((parameter) => {
if (parameter.get("in")) {
if (parameter.get("in") === JsonParameterTypes_1.JsonParameterTypes.BODY) {
bodyParameters.push(parameter);
if (!JsonParameterTypes_1.isParameterType(this.get("in"))) {
if (parameter.get("in")) {
if (parameter.get("in") === JsonParameterTypes_1.JsonParameterTypes.BODY) {
bodyParameters.push(parameter);
}
else {
parameters.push(...[].concat(parameter.toJSON(options)));
}
}
else {
parameters.push(parameter.toJSON(options));
}
}
});
operation.parameters = parameters;
operation.parameters = parameters.filter(Boolean);
if (this.get("responses").size === 0) {

@@ -142,0 +144,0 @@ operation.responses = {

@@ -23,2 +23,3 @@ import { Type } from "@tsed/core";

toJSON(options?: JsonSerializerOptions): any;
private refToParameters;
}

@@ -6,2 +6,4 @@ "use strict";

const JsonMap_1 = require("./JsonMap");
const JsonParameterTypes_1 = require("./JsonParameterTypes");
const SpecTypes_1 = require("./SpecTypes");
class JsonParameterOptions {

@@ -24,3 +26,3 @@ }

in(inType, expression = "") {
this.set("in", inType);
this.set("in", inType.toLowerCase());
this.expression = expression;

@@ -38,2 +40,6 @@ return this;

toJSON(options = {}) {
if (!JsonParameterTypes_1.isParameterType(this.get("in"))) {
return null;
}
const schemas = { ...options.schemas };
const { type, schema, ...parameter } = super.toJSON(options);

@@ -44,13 +50,49 @@ const jsonSchema = serializeJsonSchema_1.serializeItem(this.$schema, {

});
parameter.required = parameter.required || this.get("in") === "path";
if (!jsonSchema.$ref && (this.get("in") === "path" || Object.keys(jsonSchema).length === 1)) {
parameter.type = jsonSchema.type;
}
else if (options.spec === SpecTypes_1.SpecTypes.SWAGGER && this.get("in") === "query") {
if (jsonSchema.$ref) {
return this.refToParameters(parameter, options, schemas);
}
if (jsonSchema.type === "array") {
return {
...parameter,
type: "array",
collectionFormat: "multi",
items: {
type: "string"
}
};
}
return {
...parameter,
...jsonSchema
};
}
else {
parameter.schema = jsonSchema;
}
parameter.required = parameter.required || this.get("in") === "path";
return parameter;
}
refToParameters(parameter, options, schemas) {
const schema = options.schemas[this.$schema.getName()];
if (options.schemas[this.$schema.getName()] && !schemas[this.$schema.getName()]) {
delete options.schemas[this.$schema.getName()];
}
return Object.entries(schema.properties || {}).reduce((params, [key, prop]) => {
return [
...params,
{
...parameter,
name: key,
required: (schema.required || []).includes(key),
...prop
}
];
}, []);
}
}
exports.JsonParameter = JsonParameter;
//# sourceMappingURL=JsonParameter.js.map

@@ -8,1 +8,2 @@ export declare enum JsonParameterTypes {

}
export declare function isParameterType(type: string): boolean;

@@ -11,2 +11,6 @@ "use strict";

})(JsonParameterTypes = exports.JsonParameterTypes || (exports.JsonParameterTypes = {}));
function isParameterType(type) {
return Object.values(JsonParameterTypes).includes(String(type).toLowerCase());
}
exports.isParameterType = isParameterType;
//# sourceMappingURL=JsonParameterTypes.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@tsed/core");
const getComputedType_1 = require("../utils/getComputedType");
const getJsonType_1 = require("../utils/getJsonType");

@@ -570,9 +571,3 @@ const serializeJsonSchema_1 = require("../utils/serializeJsonSchema");

getComputedType() {
if (core_1.isPromise(this._target)) {
return Object;
}
if (core_1.isClass(this._target)) {
return core_1.classOf(this._target);
}
return !this._target ? this._target : this._target();
return getComputedType_1.getComputedType(this._target);
}

@@ -579,0 +574,0 @@ /**

import { Type } from "@tsed/core";
import { JsonEntityStore } from "../domain/JsonEntityStore";
import { JsonSerializerOptions } from "../interfaces";
export declare function getJsonSchema(model: Type<any>, options?: JsonSerializerOptions): any;
export declare function getJsonSchema(model: Type<any> | JsonEntityStore, options?: JsonSerializerOptions): any;

@@ -6,12 +6,17 @@ "use strict";

const serializeJsonSchema_1 = require("./serializeJsonSchema");
const caches = new Map();
function get(model, options, cb) {
if (!caches.has(model)) {
caches.set(model, new Map());
}
const cache = caches.get(model);
const key = JSON.stringify(options);
const CACHE_KEY = "$cache:schemes";
function getKey(options) {
return JSON.stringify(options);
}
function get(entity, options) {
const cache = entity.store.get(CACHE_KEY) || new Map();
const key = getKey(options);
if (!cache.has(key)) {
cache.set(key, cb());
const schema = serializeJsonSchema_1.serializeJsonSchema(entity.schema, { ...options, root: false });
if (Object.keys(options.schemas).length) {
schema.definitions = options.schemas;
}
cache.set(key, schema);
}
entity.store.set(CACHE_KEY, cache);
return cache.get(key);

@@ -22,12 +27,10 @@ }

...options,
root: true,
spec: options.spec || SpecTypes_1.SpecTypes.JSON,
root: true,
schemas: {}
};
const storedJson = JsonEntityStore_1.JsonEntityStore.from(model);
return get(model, options, () => {
return serializeJsonSchema_1.serializeJsonSchema(storedJson.schema, options);
});
const entity = model instanceof JsonEntityStore_1.JsonEntityStore ? model : JsonEntityStore_1.JsonEntityStore.from(model);
return get(entity, options);
}
exports.getJsonSchema = getJsonSchema;
//# sourceMappingURL=getJsonSchema.js.map

@@ -16,3 +16,5 @@ "use strict";

currentStore.children.forEach(propStore => {
store.$properties.set(propStore.propertyKey, propStore);
if (!store.$properties.has(propStore.propertyKey)) {
store.$properties.set(propStore.propertyKey, propStore);
}
});

@@ -19,0 +21,0 @@ });

@@ -129,5 +129,5 @@ "use strict";

const { useAlias = true, schemas = {}, root = true, genericTypes } = options;
let obj = Array.from(schema.entries()).reduce((obj, [key, value]) => {
let obj = Array.from(schema.entries()).reduce((item, [key, value]) => {
if (IGNORES.includes(key)) {
return obj;
return item;
}

@@ -156,3 +156,3 @@ if (key === "type") {

if (isEmptyProperties(key, value)) {
return obj;
return item;
}

@@ -162,4 +162,4 @@ if (shouldMapAlias(key, value, useAlias)) {

}
obj[key] = value;
return obj;
item[key] = value;
return item;
}, {});

@@ -173,5 +173,2 @@ if (schema.isClass) {

}
if (root && Object.keys(schemas).length) {
obj.definitions = schemas;
}
return obj;

@@ -178,0 +175,0 @@ }

{
"name": "@tsed/schema",
"version": "5.60.7",
"version": "5.61.0",
"description": "JsonSchema module for Ts.ED Framework",

@@ -8,3 +8,3 @@ "main": "./lib/index.js",

"dependencies": {
"@tsed/core": "5.60.7",
"@tsed/core": "5.61.0",
"change-case": "4.1.1",

@@ -11,0 +11,0 @@ "tslib": "1.11.1"

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

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