@worldsibu/convector-core-model
Advanced tools
Comparing version 1.2.1-0-alpha.cf9e512a to 1.2.1-0-alpha.d00d4639
import * as yup from 'yup'; | ||
export declare type RequiredKeys<T> = { | ||
[K in keyof T]-?: string extends K ? never : number extends K ? never : {} extends Pick<T, K> ? never : K; | ||
} extends { | ||
[_ in keyof T]-?: infer U; | ||
} ? U extends keyof T ? U : never : never; | ||
export declare type OptionalKeys<T> = { | ||
[K in keyof T]-?: string extends K ? never : number extends K ? never : {} extends Pick<T, K> ? K : never; | ||
} extends { | ||
[_ in keyof T]-?: infer U; | ||
} ? U extends keyof T ? U : never : never; | ||
export declare type FlatConvectorModel<T> = { | ||
[L in Exclude<keyof T, keyof ConvectorModel<any>>]: T[L]; | ||
[L in Exclude<OptionalKeys<T>, keyof ConvectorModel<any>>]?: T[L]; | ||
} & { | ||
[L in Exclude<RequiredKeys<T>, keyof ConvectorModel<any>>]: T[L]; | ||
}; | ||
@@ -11,2 +23,3 @@ export interface History<T> { | ||
export declare abstract class ConvectorModel<T extends ConvectorModel<any>> { | ||
private static type; | ||
static schema<T extends ConvectorModel<any>>(this: Function & { | ||
@@ -13,0 +26,0 @@ prototype: T; |
@@ -23,8 +23,7 @@ "use strict"; | ||
ConvectorModel.schema = function () { | ||
var instance = new this(); | ||
return yup.object().shape(tslib_1.__assign({ id: yup.string().required(), type: 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))); | ||
}; | ||
ConvectorModel.getOne = function (id, type) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var content; | ||
var content, model; | ||
return tslib_1.__generator(this, function (_a) { | ||
@@ -37,3 +36,7 @@ switch (_a.label) { | ||
content = _a.sent(); | ||
return [2, new type(content)]; | ||
model = new type(content); | ||
if ((content && model) && content.type !== model.type) { | ||
throw new Error("Possible ID collision, element " + id + " of type " + content.type + " is not " + model.type); | ||
} | ||
return [2, model]; | ||
} | ||
@@ -54,3 +57,3 @@ }); | ||
type = this; | ||
if (args[0] && args[0].prototype.__proto__.constructor === ConvectorModel) { | ||
if (args[0] && 'type' in args[0] && args[0].type === ConvectorModel.type) { | ||
type = args.shift(); | ||
@@ -166,3 +169,3 @@ } | ||
.filter(function (k) { return !k.startsWith('_'); }) | ||
.filter(function (k) { return !skipEmpty || _this[k] !== undefined || _this[k] !== null; }) | ||
.filter(function (k) { return !skipEmpty || !(_this[k] === undefined || _this[k] === null); }) | ||
.reduce(function (result, key) { | ||
@@ -182,2 +185,5 @@ return (tslib_1.__assign({}, result, (_a = {}, _a[key] = _this[key], _a))); | ||
} | ||
if (result[key] instanceof ConvectorModel) { | ||
result[key] = result[key].toJSON(true); | ||
} | ||
return result; | ||
@@ -211,2 +217,3 @@ }, base); | ||
}; | ||
ConvectorModel.type = 'io.convector.model'; | ||
tslib_1.__decorate([ | ||
@@ -213,0 +220,0 @@ required_decorator_1.Required(), |
{ | ||
"name": "@worldsibu/convector-core-model", | ||
"version": "1.2.1-0-alpha.cf9e512a", | ||
"version": "1.2.1-0-alpha.d00d4639", | ||
"description": "Convector Model base class", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/hyperledger-labs/convector/tree/develop/%40worldsibu/convector-core-model" | ||
}, | ||
"homepage": "https://worldsibu.tech/convector/convector-smart-contracts/", | ||
"main": "./dist/src/index.js", | ||
@@ -35,4 +40,4 @@ "typings": "./dist/src/index.d.ts", | ||
"dependencies": { | ||
"@worldsibu/convector-core-errors": "1.2.1-0-alpha.cf9e512a", | ||
"@worldsibu/convector-core-storage": "1.2.1-0-alpha.cf9e512a", | ||
"@worldsibu/convector-core-errors": "1.2.1-0-alpha.d00d4639", | ||
"@worldsibu/convector-core-storage": "1.2.1-0-alpha.d00d4639", | ||
"tslib": "^1.9.0", | ||
@@ -39,0 +44,0 @@ "yup": "^0.26.10" |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
42138
418
1
0
+ Added@worldsibu/convector-core-errors@1.2.1-0-alpha.d00d4639(transitive)
+ Added@worldsibu/convector-core-storage@1.2.1-0-alpha.d00d4639(transitive)
- Removed@worldsibu/convector-core-errors@1.2.1-0-alpha.cf9e512a(transitive)
- Removed@worldsibu/convector-core-storage@1.2.1-0-alpha.cf9e512a(transitive)
Updated@worldsibu/convector-core-errors@1.2.1-0-alpha.d00d4639
Updated@worldsibu/convector-core-storage@1.2.1-0-alpha.d00d4639