@worldsibu/convector-core-model
Advanced tools
Comparing version 1.2.1-0-alpha.16483a5b to 1.2.1-0-alpha.7c22f03f
@@ -11,4 +11,7 @@ import * as yup from 'yup'; | ||
export declare abstract class ConvectorModel<T extends ConvectorModel<any>> { | ||
static schema<T extends ConvectorModel<any>>(this: new (...args: any[]) => T): yup.ObjectSchema<FlatConvectorModel<T> & { | ||
static schema<T extends ConvectorModel<any>>(this: Function & { | ||
prototype: T; | ||
}): yup.ObjectSchema<FlatConvectorModel<T> & { | ||
id: string; | ||
type: string; | ||
}>; | ||
@@ -15,0 +18,0 @@ static getOne<T extends ConvectorModel<any>>(this: new (content: any) => T, id: string, type?: new (content: any) => T): Promise<T>; |
@@ -23,4 +23,3 @@ "use strict"; | ||
ConvectorModel.schema = function () { | ||
var instance = new this(); | ||
return yup.object().shape(tslib_1.__assign({ id: yup.string().required(), key: yup.string() }, validate_decorator_2.getPropertiesValidation(instance))); | ||
return yup.object().shape(tslib_1.__assign({ id: yup.string().required(), type: yup.string() }, validate_decorator_2.getPropertiesValidation(this.prototype))); | ||
}; | ||
@@ -136,3 +135,3 @@ ConvectorModel.getOne = function (id, type) { | ||
else { | ||
throw new Error("Model " + this.type + " is not complete\n" + JSON.stringify(this)); | ||
throw new Error("Model " + this.type + " is not complete\n" + JSON.stringify(this) + ".\n Check your model definition for more details."); | ||
} | ||
@@ -155,3 +154,10 @@ } | ||
if (skipEmpty === void 0) { skipEmpty = false; } | ||
var proto = Object.getPrototypeOf(this); | ||
var protos = []; | ||
var children = this; | ||
do { | ||
children = Object.getPrototypeOf(children); | ||
protos.push(children); | ||
} while (children['__proto__'].constructor.name !== ConvectorModel.name); | ||
var descriptors = protos.reduce(function (result, proto) { return result.concat(Object.keys(proto) | ||
.map(function (key) { return [key, Object.getOwnPropertyDescriptor(proto, key)]; })); }, []); | ||
var base = Object.keys(this).concat('id') | ||
@@ -164,5 +170,5 @@ .filter(function (k) { return !k.startsWith('_'); }) | ||
}, {}); | ||
return Object.keys(proto) | ||
.reduce(function (result, key) { | ||
var desc = Object.getOwnPropertyDescriptor(proto, key); | ||
return descriptors | ||
.reduce(function (result, _a) { | ||
var key = _a[0], desc = _a[1]; | ||
var hasGetter = desc && typeof desc.get === 'function'; | ||
@@ -169,0 +175,0 @@ if (hasGetter) { |
@@ -0,3 +1,4 @@ | ||
export declare const defaultMetadataKey: any; | ||
import 'reflect-metadata'; | ||
export declare function Default<T>(defaultValue: T): (target: any, key: string) => void; | ||
export declare function getDefaults(obj: any): {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var defaultMetadataKey = Symbol('default'); | ||
var g = global; | ||
exports.defaultMetadataKey = g.ConvectorDefaultMetadataKey || Symbol('default'); | ||
g.ConvectorDefaultMetadataKey = exports.defaultMetadataKey; | ||
require("reflect-metadata"); | ||
function Default(defaultValue) { | ||
return function (target, key) { | ||
var defaults = Reflect.getMetadata(defaultMetadataKey, target) || {}; | ||
Reflect.defineMetadata(defaultMetadataKey, tslib_1.__assign({}, defaults, (_a = {}, _a[key] = defaultValue, _a)), target); | ||
var defaults = Reflect.getMetadata(exports.defaultMetadataKey, target) || {}; | ||
Reflect.defineMetadata(exports.defaultMetadataKey, tslib_1.__assign({}, defaults, (_a = {}, _a[key] = defaultValue, _a)), target); | ||
var _a; | ||
@@ -15,3 +17,3 @@ }; | ||
function getDefaults(obj) { | ||
var defaults = Reflect.getMetadata(defaultMetadataKey, obj); | ||
var defaults = Reflect.getMetadata(exports.defaultMetadataKey, obj); | ||
return !defaults ? {} : Object.keys(defaults) | ||
@@ -18,0 +20,0 @@ .reduce(function (result, k) { |
@@ -0,3 +1,4 @@ | ||
export declare const requiredMetadataKey: any; | ||
import 'reflect-metadata'; | ||
export declare function Required(): (target: any, key: string) => void; | ||
export declare function ensureRequired(obj: any): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var requiredMetadataKey = Symbol('required'); | ||
var g = global; | ||
exports.requiredMetadataKey = g.ConvectorRequiredMetadataKey || Symbol('required'); | ||
g.ConvectorRequiredMetadataKey = exports.requiredMetadataKey; | ||
require("reflect-metadata"); | ||
function Required() { | ||
return function (target, key) { | ||
var required = Reflect.getMetadata(requiredMetadataKey, target); | ||
Reflect.defineMetadata(requiredMetadataKey, tslib_1.__assign({}, required, (_a = {}, _a[key] = true, _a)), target); | ||
var required = Reflect.getMetadata(exports.requiredMetadataKey, target); | ||
Reflect.defineMetadata(exports.requiredMetadataKey, tslib_1.__assign({}, required, (_a = {}, _a[key] = true, _a)), target); | ||
var _a; | ||
@@ -17,3 +19,3 @@ }; | ||
try { | ||
required = Reflect.getMetadata(requiredMetadataKey, obj) || {}; | ||
required = Reflect.getMetadata(exports.requiredMetadataKey, obj) || {}; | ||
} | ||
@@ -20,0 +22,0 @@ catch (e) { |
import { Schema } from 'yup'; | ||
import 'reflect-metadata'; | ||
export declare const validateMetadataKey: any; | ||
export declare function Validate<T>(input: Schema<T> | { | ||
@@ -4,0 +5,0 @@ schema: () => Schema<T>; |
@@ -5,7 +5,9 @@ "use strict"; | ||
require("reflect-metadata"); | ||
var validateMetadataKey = Symbol('validate'); | ||
var g = global; | ||
exports.validateMetadataKey = g.ConvectorValidateMetadataKey || Symbol('validate'); | ||
g.ConvectorValidateMetadataKey = exports.validateMetadataKey; | ||
function Validate(input) { | ||
var schema = input; | ||
if ('schema' in input) { | ||
schema = input.schema; | ||
schema = input.schema(); | ||
} | ||
@@ -26,4 +28,4 @@ return function (target, key) { | ||
Object.defineProperty(target, key, getSet); | ||
var validated = Reflect.getMetadata(validateMetadataKey, target); | ||
Reflect.defineMetadata(validateMetadataKey, tslib_1.__assign({}, validated, (_a = {}, _a[key] = schema, _a)), target); | ||
var validated = Reflect.getMetadata(exports.validateMetadataKey, target); | ||
Reflect.defineMetadata(exports.validateMetadataKey, tslib_1.__assign({}, validated, (_a = {}, _a[key] = schema, _a)), target); | ||
var _a; | ||
@@ -36,3 +38,3 @@ }; | ||
try { | ||
validated = Reflect.getMetadata(validateMetadataKey, obj) || {}; | ||
validated = Reflect.getMetadata(exports.validateMetadataKey, obj) || {}; | ||
} | ||
@@ -39,0 +41,0 @@ catch (e) { |
{ | ||
"name": "@worldsibu/convector-core-model", | ||
"version": "1.2.1-0-alpha.16483a5b", | ||
"version": "1.2.1-0-alpha.7c22f03f", | ||
"description": "Convector Model base class", | ||
@@ -35,6 +35,6 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@worldsibu/convector-core-errors": "1.2.1-0-alpha.16483a5b", | ||
"@worldsibu/convector-core-storage": "1.2.1-0-alpha.16483a5b", | ||
"@worldsibu/convector-core-errors": "1.2.1-0-alpha.7c22f03f", | ||
"@worldsibu/convector-core-storage": "1.2.1-0-alpha.7c22f03f", | ||
"tslib": "^1.9.0", | ||
"yup": "^0.24.1" | ||
"yup": "^0.26.10" | ||
}, | ||
@@ -41,0 +41,0 @@ "devDependencies": { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40452
397
+ Added@babel/runtime@7.0.0(transitive)
+ Added@worldsibu/convector-core-errors@1.2.1-0-alpha.7c22f03f(transitive)
+ Added@worldsibu/convector-core-storage@1.2.1-0-alpha.7c22f03f(transitive)
+ Addedfn-name@2.0.1(transitive)
+ Addedregenerator-runtime@0.12.1(transitive)
+ Addedsynchronous-promise@2.0.17(transitive)
+ Addedtoposort@2.0.2(transitive)
+ Addedyup@0.26.10(transitive)
- Removed@worldsibu/convector-core-errors@1.2.1-0-alpha.16483a5b(transitive)
- Removed@worldsibu/convector-core-storage@1.2.1-0-alpha.16483a5b(transitive)
- Removedcase@1.6.3(transitive)
- Removedfn-name@1.0.1(transitive)
- Removedsynchronous-promise@1.0.18(transitive)
- Removedtoposort@0.2.12(transitive)
- Removedtype-name@2.0.2(transitive)
- Removedyup@0.24.1(transitive)
Updated@worldsibu/convector-core-errors@1.2.1-0-alpha.7c22f03f
Updated@worldsibu/convector-core-storage@1.2.1-0-alpha.7c22f03f
Updatedyup@^0.26.10