functional-models 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/interfaces.d.ts +4 -4
- package/interfaces.js.map +1 -1
- package/lib.d.ts +15 -1
- package/lib.js +14 -1
- package/lib.js.map +1 -1
- package/package.json +2 -1
- package/properties.d.ts +9029 -930
- package/properties.js +34 -4
- package/properties.js.map +1 -1
- package/serialization.js +5 -3
- package/serialization.js.map +1 -1
- package/validation.d.ts +2044 -2
- package/validation.js +21 -1
- package/validation.js.map +1 -1
package/interfaces.d.ts
CHANGED
|
@@ -53,11 +53,11 @@ declare type PropertyInstance<TValue extends Arrayable<FunctionalValue>, T exten
|
|
|
53
53
|
declare type PropertiesList<T extends FunctionalModel> = {
|
|
54
54
|
readonly [P in keyof T as T[P] extends Arrayable<FunctionalValue> ? P : never]: PropertyInstance<any>;
|
|
55
55
|
};
|
|
56
|
-
interface ModelReferencePropertyInstance<T extends FunctionalModel, TProperty extends Arrayable<FunctionalValue>, TModel extends Model<T> = Model<T>> extends PropertyInstance<TProperty> {
|
|
57
|
-
readonly getReferencedId: (instanceValues: ModelReference<T>) => Maybe<PrimaryKeyType>;
|
|
56
|
+
interface ModelReferencePropertyInstance<T extends FunctionalModel, TProperty extends Arrayable<FunctionalValue>, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> extends PropertyInstance<TProperty> {
|
|
57
|
+
readonly getReferencedId: (instanceValues: ModelReference<T, TModel, TModelInstance>) => Maybe<PrimaryKeyType>;
|
|
58
58
|
readonly getReferencedModel: () => TModel;
|
|
59
59
|
}
|
|
60
|
-
declare type ModelReference<T extends FunctionalModel> = T | TypedJsonObj<T> | PrimaryKeyType;
|
|
60
|
+
declare type ModelReference<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = T | TModelInstance | TypedJsonObj<T> | PrimaryKeyType;
|
|
61
61
|
declare type DefaultPropertyValidators = Readonly<{
|
|
62
62
|
required?: boolean;
|
|
63
63
|
isInteger?: boolean;
|
|
@@ -81,7 +81,7 @@ declare type PropertyConfigContents<T extends Arrayable<FunctionalValue>> = Read
|
|
|
81
81
|
autoNow?: boolean;
|
|
82
82
|
fetcher?: ModelFetcher;
|
|
83
83
|
}>;
|
|
84
|
-
declare type ModelFetcher = <T extends FunctionalModel, TModel extends Model<T> = Model<T>>(model: TModel, primaryKey: PrimaryKeyType) => Promise<T | TypedJsonObj<T>> | Promise<null> | Promise<undefined>;
|
|
84
|
+
declare type ModelFetcher = <T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>>(model: TModel, primaryKey: PrimaryKeyType) => Promise<T | TModelInstance | TypedJsonObj<T>> | Promise<null> | Promise<undefined>;
|
|
85
85
|
declare type PropertyConfig<T extends Arrayable<FunctionalValue>> = (PropertyConfigContents<T> & DefaultPropertyValidators) | undefined;
|
|
86
86
|
declare type PrimaryKeyPropertyInstanceType = PropertyInstance<string> | PropertyInstance<number>;
|
|
87
87
|
declare type PrimaryKeyType = string | number;
|
package/interfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;AAgYA,kCAAkC"}
|
package/lib.d.ts
CHANGED
|
@@ -4036,4 +4036,18 @@ declare const getValidatorFromConfigElseEmpty: <T extends FunctionalModel, TValu
|
|
|
4036
4036
|
}>>;
|
|
4037
4037
|
declare const getCommonNumberValidators: <TModifier extends PropertyModifier<number>>(config: PropertyConfig<TModifier>) => readonly PropertyValidatorComponent<any>[];
|
|
4038
4038
|
declare const mergeValidators: <T extends Arrayable<FunctionalValue>>(config: PropertyConfig<T>, validators: readonly (PropertyValidatorComponent<any> | PropertyValidatorComponentTypeAdvanced<any, any>)[]) => PropertyValidatorComponent<any>[];
|
|
4039
|
-
|
|
4039
|
+
declare const isModelInstance: (obj: any) => obj is Readonly<{
|
|
4040
|
+
get: import("./interfaces").PropertyGetters<any> & {
|
|
4041
|
+
id?: (() => import("./interfaces").MaybePromise<PrimaryKeyType>) | undefined;
|
|
4042
|
+
};
|
|
4043
|
+
references: Readonly<{
|
|
4044
|
+
[s: string]: () => import("./interfaces").Maybe<PrimaryKeyType>;
|
|
4045
|
+
}>;
|
|
4046
|
+
toObj: import("./interfaces").toObj<any>;
|
|
4047
|
+
getPrimaryKeyName: () => string;
|
|
4048
|
+
getPrimaryKey: () => PrimaryKeyType;
|
|
4049
|
+
validators: import("./interfaces").PropertyValidators<any, any>;
|
|
4050
|
+
validate: (options?: object | undefined) => Promise<import("./interfaces").ModelErrors<any>>;
|
|
4051
|
+
getModel: () => any;
|
|
4052
|
+
}>;
|
|
4053
|
+
export { isReferencedProperty, getValueForModelInstance, getValueForReferencedModel, getCommonTextValidators, getValidatorFromConfigElseEmpty, getCommonNumberValidators, mergeValidators, isModelInstance, };
|
package/lib.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.mergeValidators = exports.getCommonNumberValidators = exports.getValidatorFromConfigElseEmpty = exports.getCommonTextValidators = exports.getValueForReferencedModel = exports.getValueForModelInstance = exports.isReferencedProperty = void 0;
|
|
15
|
+
exports.isModelInstance = exports.mergeValidators = exports.getCommonNumberValidators = exports.getValidatorFromConfigElseEmpty = exports.getCommonTextValidators = exports.getValueForReferencedModel = exports.getValueForModelInstance = exports.isReferencedProperty = void 0;
|
|
16
16
|
const get_1 = __importDefault(require("lodash/get"));
|
|
17
17
|
const utils_1 = require("./utils");
|
|
18
18
|
const validation_1 = require("./validation");
|
|
@@ -23,6 +23,14 @@ const getValueForReferencedModel = (modelInstance, path) => __awaiter(void 0, vo
|
|
|
23
23
|
return modelInstance.references[head]();
|
|
24
24
|
}
|
|
25
25
|
const modelReference = yield modelInstance.get[head]();
|
|
26
|
+
if (modelReference.toObj) {
|
|
27
|
+
const [nestedHead, nestedTail] = (0, utils_1.createHeadAndTail)(tail.split('.'), '.');
|
|
28
|
+
const value = yield modelReference.get[nestedHead]();
|
|
29
|
+
if (nestedTail) {
|
|
30
|
+
return (0, get_1.default)(value, nestedTail);
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
26
34
|
return (0, get_1.default)(modelReference, tail);
|
|
27
35
|
});
|
|
28
36
|
exports.getValueForReferencedModel = getValueForReferencedModel;
|
|
@@ -64,4 +72,9 @@ const mergeValidators = (config, validators) => {
|
|
|
64
72
|
return [...validators, ...((config === null || config === void 0 ? void 0 : config.validators) ? config.validators : [])];
|
|
65
73
|
};
|
|
66
74
|
exports.mergeValidators = mergeValidators;
|
|
75
|
+
const isModelInstance = (obj) => {
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
return Boolean(obj && obj.getPrimaryKeyName);
|
|
78
|
+
};
|
|
79
|
+
exports.isModelInstance = isModelInstance;
|
|
67
80
|
//# sourceMappingURL=lib.js.map
|
package/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qDAA4B;AAY5B,mCAA2C;AAC3C,6CAMqB;AAErB,MAAM,0BAA0B,GAAG,CACjC,aAAiC,EACjC,IAAY,EACmB,EAAE;IACjC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAA,yBAAiB,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;IAC5D,6DAA6D;IAC7D,IA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AAQ,EAAE,sBAAS,CAAC;QAC5D,+BAA+B,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,EAAE,sBAAS,CAAC;KAC7D,CAAA;AACH,CAAC,CAAA;AAuBC,8DAAyB;AArB3B,MAAM,eAAe,GAAG,CACtB,MAAqC,EACrC,UAGG,EACgC,EAAE;IACrC,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,EAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAC1E,CAAC,CAAA;AAcC,0CAAe;AAZjB,MAAM,eAAe,GAAG,CAAC,GAAQ,EAAkC,EAAE;IACnE,aAAa;IACb,OAAO,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAC9C,CAAC,CAAA;AAUC,0CAAe"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functional-models",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "A library for creating JavaScript function based models.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "mocha -r ts-node/register test/**/*.test.ts",
|
|
9
9
|
"test:coverage": "nyc npm run test",
|
|
10
|
+
"test:watch": "nodemon -e '*' --watch test --watch src --exec npm run test:coverage",
|
|
10
11
|
"commit": "cz",
|
|
11
12
|
"feature-tests": "./node_modules/.bin/cucumber-js -p default",
|
|
12
13
|
"coverage": "nyc --all --reporter=lcov npm test",
|