functional-models 2.0.14 → 2.1.1
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/README.md +58 -12
- package/errors.d.ts +5 -5
- package/errors.js +2 -2
- package/errors.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/interfaces.d.ts +109 -134
- package/interfaces.js.map +1 -1
- package/lazy.d.ts +1 -1
- package/lazy.js.map +1 -1
- package/lib.d.ts +4039 -0
- package/lib.js +67 -0
- package/lib.js.map +1 -0
- package/methods.d.ts +2 -2
- package/models.js +18 -30
- package/models.js.map +1 -1
- package/package.json +28 -10
- package/properties.d.ts +12680 -1073
- package/properties.js +49 -53
- package/properties.js.map +1 -1
- package/serialization.d.ts +2 -26
- package/serialization.js.map +1 -1
- package/utils.d.ts +4 -2
- package/utils.js +25 -3
- package/utils.js.map +1 -1
- package/validation.d.ts +10112 -180
- package/validation.js +14 -26
- package/validation.js.map +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ Functional Models was born out of the enjoyment and power of working with Django
|
|
|
21
21
|
- Many common properties out of the box.
|
|
22
22
|
- Supports foreign keys, 1 to 1 as well as 1 to many (via an Array).
|
|
23
23
|
- Supports custom primary key name. (id is used by default)
|
|
24
|
+
- Supports different model namings, (plural, singular, display), and the ability to customize them.
|
|
24
25
|
|
|
25
26
|
## Simple JavaScript Example Usage
|
|
26
27
|
|
|
@@ -263,15 +264,60 @@ validation requirements, etc.
|
|
|
263
264
|
|
|
264
265
|
### List of Properties Out-Of-The-Box
|
|
265
266
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
267
|
+
#### UniqueId
|
|
268
|
+
|
|
269
|
+
A UUID Property.
|
|
270
|
+
|
|
271
|
+
#### NaturalIdProperty
|
|
272
|
+
|
|
273
|
+
An id that is composed of other properties on an object. It is "natural" in the sense that it is
|
|
274
|
+
not an arbitrary id, but rather a mixture of properties that make up a unique instance. This is often
|
|
275
|
+
useful for when creating a "key" property.
|
|
276
|
+
|
|
277
|
+
NOTE: This property is never automatically updated if the properties changed. It is recommended that
|
|
278
|
+
any model that has a NaturalIdProperty should be deleted and then re-created rather than "updated" if
|
|
279
|
+
any property changes that make up the key composition.
|
|
280
|
+
|
|
281
|
+
#### DateProperty
|
|
282
|
+
|
|
283
|
+
A property for dates. Includes the ability to "autoNow".
|
|
284
|
+
|
|
285
|
+
#### ArrayProperty
|
|
286
|
+
|
|
287
|
+
An array property which can be used to limit types within it.
|
|
288
|
+
|
|
289
|
+
#### IntegerProperty
|
|
290
|
+
|
|
291
|
+
A property for integers.
|
|
292
|
+
|
|
293
|
+
#### TextProperty
|
|
294
|
+
|
|
295
|
+
A text or string property.
|
|
296
|
+
|
|
297
|
+
#### ConstantValueProperty
|
|
298
|
+
|
|
299
|
+
A property that contains a single, unchanging, static value.
|
|
300
|
+
|
|
301
|
+
#### NumberProperty
|
|
302
|
+
|
|
303
|
+
A property for float/number types.
|
|
304
|
+
|
|
305
|
+
#### ObjectProperty
|
|
306
|
+
|
|
307
|
+
A property that has a JavaScript object. (Not a foreign key references)
|
|
308
|
+
|
|
309
|
+
#### EmailProperty
|
|
310
|
+
|
|
311
|
+
An email property.
|
|
312
|
+
|
|
313
|
+
#### BooleanProperty
|
|
314
|
+
|
|
315
|
+
A true or false value property.
|
|
316
|
+
|
|
317
|
+
#### ModelReferenceProperty
|
|
318
|
+
|
|
319
|
+
A property that references another property. (Think Foreign Key)
|
|
320
|
+
|
|
321
|
+
#### AdvancedModelReferenceProperty
|
|
322
|
+
|
|
323
|
+
A more fuller/advanced property for referencing other properties. Useful for typescripting.
|
package/errors.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
declare type KeysToErrors = {
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
declare type KeysToErrors = Readonly<{
|
|
2
|
+
[s: string]: readonly string[];
|
|
3
|
+
}>;
|
|
4
4
|
declare class ValidationError extends Error {
|
|
5
|
-
modelName:
|
|
5
|
+
modelName: string;
|
|
6
6
|
keysToErrors: KeysToErrors;
|
|
7
|
-
constructor(modelName:
|
|
7
|
+
constructor(modelName: string, keysToErrors: KeysToErrors);
|
|
8
8
|
}
|
|
9
9
|
export { ValidationError };
|
package/errors.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValidationError = void 0;
|
|
4
|
-
/* eslint-disable functional/no-this-
|
|
5
|
-
/* eslint-disable functional/no-
|
|
4
|
+
/* eslint-disable functional/no-this-expressions */
|
|
5
|
+
/* eslint-disable functional/no-classes */
|
|
6
6
|
class ValidationError extends Error {
|
|
7
7
|
constructor(modelName, keysToErrors) {
|
|
8
8
|
super(`${modelName} did not pass validation`);
|
package/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEA,mDAAmD;AACnD,0CAA0C;AAC1C,MAAM,eAAgB,SAAQ,KAAK;IAGjC,YAAY,SAAiB,EAAE,YAA0B;QACvD,KAAK,CAAC,GAAG,SAAS,0BAA0B,CAAC,CAAA;QAC7C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;CACF;AAIQ,0CAAe"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -37,5 +37,4 @@ const interfaces = __importStar(require("./interfaces"));
|
|
|
37
37
|
exports.interfaces = interfaces;
|
|
38
38
|
__exportStar(require("./models"), exports);
|
|
39
39
|
__exportStar(require("./properties"), exports);
|
|
40
|
-
__exportStar(require("./methods"), exports);
|
|
41
40
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAwC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAwC;AAU/B,8BAAS;AATlB,iDAAkC;AASd,wBAAM;AAR1B,yDAA0C;AAQd,gCAAU;AAPtC,+DAAgD;AAOR,sCAAa;AANrD,+CAAgC;AAMuB,sBAAK;AAL5D,yDAA0C;AAKoB,gCAAU;AAHxE,2CAAwB;AACxB,+CAA4B"}
|
package/interfaces.d.ts
CHANGED
|
@@ -4,62 +4,35 @@ declare type Nullable<T> = T | null;
|
|
|
4
4
|
declare type Maybe<T> = T | undefined | null;
|
|
5
5
|
declare type Arrayable<T> = T | readonly T[];
|
|
6
6
|
declare type MaybeLazy<T> = Maybe<Promise<T>>;
|
|
7
|
-
declare type
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
declare type JsonObj = {
|
|
11
|
-
readonly [s: string]: JsonAble | null;
|
|
12
|
-
};
|
|
13
|
-
declare type NoFunctions<T> = RemoveType<T, (...args: readonly any[]) => any>;
|
|
7
|
+
declare type JsonObj = Readonly<{
|
|
8
|
+
[s: string]: JsonAble | null;
|
|
9
|
+
}>;
|
|
14
10
|
declare type TypedJsonObj<T extends FunctionalModel> = {
|
|
15
|
-
readonly [P in keyof
|
|
11
|
+
readonly [P in keyof T]: JsonAble;
|
|
16
12
|
};
|
|
17
13
|
declare type JsonAble = Arrayable<JsonObj> | readonly (number | string | boolean)[] | number | string | boolean | null;
|
|
18
14
|
declare type VeryPrimitivesTypes = null | string | number | boolean;
|
|
19
15
|
declare type toObj<T extends FunctionalModel> = () => Promise<TypedJsonObj<T>>;
|
|
20
|
-
declare type
|
|
21
|
-
readonly [
|
|
22
|
-
};
|
|
23
|
-
declare type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
declare type
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
readonly [P in keyof T as T[P] extends TRemove ? never : P]: T[P];
|
|
33
|
-
};
|
|
34
|
-
declare type NotModelMethods<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = RemoveType<T, ModelMethod | ModelMethod<T> | ModelMethod<T, TModel>>;
|
|
35
|
-
declare type InstanceMethodGetters<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = {
|
|
36
|
-
readonly [P in keyof NotModelMethods<T, TModel> as NotModelMethods<T, TModel>[P] extends ModelInstanceMethod | ModelInstanceMethod<T, TModel> | ModelInstanceMethod<T, TModel, TModelInstance> | ModelInstanceMethod<T, TModel, any> ? P : never]: ModelInstanceMethodClient;
|
|
37
|
-
};
|
|
38
|
-
declare type ModelMethodTypes<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = ModelMethod | ModelMethod<T> | ModelMethod<T, TModel> | ModelInstanceMethod | ModelInstanceMethod<T> | ModelInstanceMethod<T, TModel> | ModelInstanceMethod<T, TModel, any>;
|
|
39
|
-
declare type InstanceMethods<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = ValueIsOfType<T, ModelInstanceMethod | ModelInstanceMethod<T> | ModelInstanceMethod<T, TModel> | ModelInstanceMethod<T, TModel, TModelInstance>>;
|
|
40
|
-
declare type PropertyGetters<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = {
|
|
41
|
-
readonly [Property in keyof T as T[Property] extends ModelMethodTypes<T, TModel> ? never : Property]: () => T[Property];
|
|
42
|
-
};
|
|
43
|
-
declare type FunctionalModel = ({
|
|
44
|
-
readonly [s: string]: Arrayable<number> | Promise<number> | Arrayable<string> | Arrayable<boolean> | Arrayable<null> | Arrayable<FunctionalModel> | Arrayable<Date> | Arrayable<undefined> | ModelReference<any> | ModelInstanceMethod | ModelMethod;
|
|
45
|
-
} & {
|
|
46
|
-
readonly id?: PrimaryKeyType;
|
|
47
|
-
});
|
|
48
|
-
declare type FunctionalValue = MaybePromise<JsonAble | (() => FunctionalValue) | Arrayable<null> | Arrayable<undefined> | Arrayable<Date> | Arrayable<FunctionalModel> | Arrayable<{
|
|
49
|
-
readonly [s: string]: JsonAble;
|
|
50
|
-
}>>;
|
|
51
|
-
declare type ModelInstanceInputData<T extends FunctionalModel> = RemoveType<T, (...args: readonly any[]) => any> | UnWrapPromises<T> | TypedJsonObj<T>;
|
|
52
|
-
declare type ValidatorConfiguration = {
|
|
53
|
-
readonly [s: string]: any;
|
|
54
|
-
};
|
|
16
|
+
declare type PropertyGetters<T extends FunctionalModel> = {
|
|
17
|
+
readonly [Property in keyof T]: () => T[Property];
|
|
18
|
+
};
|
|
19
|
+
declare type FunctionalModel = Readonly<{
|
|
20
|
+
[s: string]: Arrayable<number> | Promise<number> | Arrayable<string> | Arrayable<boolean> | Arrayable<null> | Arrayable<FunctionalModel> | Arrayable<Date> | Arrayable<undefined> | ModelReference<any> | Arrayable<JsonAble>;
|
|
21
|
+
}> & Readonly<{
|
|
22
|
+
id?: PrimaryKeyType;
|
|
23
|
+
}>;
|
|
24
|
+
declare type FunctionalValue = MaybePromise<Arrayable<JsonAble> | (() => FunctionalValue) | Arrayable<null> | Arrayable<undefined> | Arrayable<Date> | Arrayable<FunctionalModel>>;
|
|
25
|
+
declare type ValidatorConfiguration = Readonly<{
|
|
26
|
+
[s: string]: any;
|
|
27
|
+
}>;
|
|
55
28
|
declare type ValidationErrorResponse = string | undefined;
|
|
56
29
|
declare type ValidationErrors = readonly string[];
|
|
57
30
|
declare type ModelError = string | undefined;
|
|
58
|
-
declare type ModelErrors<T extends FunctionalModel
|
|
59
|
-
readonly [Property in keyof T
|
|
60
|
-
} & {
|
|
61
|
-
|
|
62
|
-
}
|
|
31
|
+
declare type ModelErrors<T extends FunctionalModel> = {
|
|
32
|
+
readonly [Property in keyof T]: readonly string[] | undefined;
|
|
33
|
+
} & Readonly<{
|
|
34
|
+
overall?: readonly string[] | undefined;
|
|
35
|
+
}>;
|
|
63
36
|
declare type PropertyValidatorComponentTypeAdvanced<TValue, T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = (value: TValue, instance: TModelInstance, instanceData: T | JsonAble, configurations: ValidatorConfiguration) => ValidationErrorResponse;
|
|
64
37
|
declare type PropertyValidatorComponentSync<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = PropertyValidatorComponentTypeAdvanced<any, T, TModel, TModelInstance>;
|
|
65
38
|
declare type ValuePropertyValidatorComponent<T extends Arrayable<FunctionalValue>> = (value: T) => ValidationErrorResponse;
|
|
@@ -68,103 +41,105 @@ declare type PropertyValidatorComponent<T extends FunctionalModel, TModel extend
|
|
|
68
41
|
declare type PropertyValidator<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = (instance: TModelInstance, instanceData: T | JsonAble, configurations: ValidatorConfiguration) => Promise<ValidationErrors>;
|
|
69
42
|
declare type ModelValidatorComponent<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = (instance: TModelInstance, instanceData: T | JsonAble, configurations: ValidatorConfiguration) => Promise<ModelError>;
|
|
70
43
|
declare type ValueGetter<TValue extends Arrayable<FunctionalValue>, T extends FunctionalModel = FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = () => MaybePromise<TValue | TModelInstance>;
|
|
71
|
-
declare type PropertyInstance<TValue extends Arrayable<FunctionalValue>, T extends FunctionalModel = FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
44
|
+
declare type PropertyInstance<TValue extends Arrayable<FunctionalValue>, T extends FunctionalModel = FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = Readonly<{
|
|
45
|
+
getConfig: () => object;
|
|
46
|
+
getChoices: () => readonly VeryPrimitivesTypes[];
|
|
47
|
+
getDefaultValue: () => TValue;
|
|
48
|
+
getConstantValue: () => TValue;
|
|
49
|
+
getPropertyType: () => string;
|
|
50
|
+
createGetter: (value: TValue, modelData: T, modelInstance: TModelInstance) => ValueGetter<TValue, T, TModel, TModelInstance>;
|
|
51
|
+
getValidator: (valueGetter: ValueGetter<TValue, T, TModel, TModelInstance>) => PropertyValidator<T, TModel, TModelInstance>;
|
|
52
|
+
}>;
|
|
80
53
|
declare type PropertiesList<T extends FunctionalModel> = {
|
|
81
54
|
readonly [P in keyof T as T[P] extends Arrayable<FunctionalValue> ? P : never]: PropertyInstance<any>;
|
|
82
55
|
};
|
|
83
|
-
interface ModelReferencePropertyInstance<T extends FunctionalModel, TProperty extends Arrayable<FunctionalValue>, TModel extends Model<T> = Model<T
|
|
84
|
-
readonly getReferencedId: (instanceValues: ModelReference<T
|
|
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>;
|
|
85
58
|
readonly getReferencedModel: () => TModel;
|
|
86
59
|
}
|
|
87
|
-
declare type ModelReference<T extends FunctionalModel
|
|
88
|
-
declare type DefaultPropertyValidators = {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
declare type PropertyConfigContents<T extends Arrayable<FunctionalValue>> = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
declare type ModelFetcher = <T extends FunctionalModel, TModel extends Model<T> = Model<T>>(model: TModel, primaryKey: PrimaryKeyType) => Promise<
|
|
60
|
+
declare type ModelReference<T extends FunctionalModel> = T | TypedJsonObj<T> | PrimaryKeyType;
|
|
61
|
+
declare type DefaultPropertyValidators = Readonly<{
|
|
62
|
+
required?: boolean;
|
|
63
|
+
isInteger?: boolean;
|
|
64
|
+
isNumber?: boolean;
|
|
65
|
+
isString?: boolean;
|
|
66
|
+
isArray?: boolean;
|
|
67
|
+
isBoolean?: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
declare type PropertyConfigContents<T extends Arrayable<FunctionalValue>> = Readonly<{
|
|
70
|
+
type?: string;
|
|
71
|
+
defaultValue?: T;
|
|
72
|
+
value?: T;
|
|
73
|
+
choices?: readonly VeryPrimitivesTypes[];
|
|
74
|
+
lazyLoadMethod?: <TData extends FunctionalModel>(value: T, modelData: TData) => MaybeLazy<T>;
|
|
75
|
+
valueSelector?: (instanceValue: MaybePromise<T>) => T;
|
|
76
|
+
validators?: readonly PropertyValidatorComponent<any>[];
|
|
77
|
+
maxLength?: number;
|
|
78
|
+
minLength?: number;
|
|
79
|
+
maxValue?: number;
|
|
80
|
+
minValue?: number;
|
|
81
|
+
autoNow?: boolean;
|
|
82
|
+
fetcher?: ModelFetcher;
|
|
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>;
|
|
112
85
|
declare type PropertyConfig<T extends Arrayable<FunctionalValue>> = (PropertyConfigContents<T> & DefaultPropertyValidators) | undefined;
|
|
113
86
|
declare type PrimaryKeyPropertyInstanceType = PropertyInstance<string> | PropertyInstance<number>;
|
|
114
87
|
declare type PrimaryKeyType = string | number;
|
|
115
|
-
declare type ModelDefinition<T extends FunctionalModel, TModel extends Model<T> = Model<T
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
readonly
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
declare type ModelFactory = <T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>>(
|
|
125
|
-
declare type CreateParams<T extends FunctionalModel> =
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
declare type Model<T extends FunctionalModel> = {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
88
|
+
declare type ModelDefinition<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = Readonly<{
|
|
89
|
+
getPrimaryKeyName?: () => string;
|
|
90
|
+
properties: {
|
|
91
|
+
id?: PrimaryKeyPropertyInstanceType;
|
|
92
|
+
} & PropertiesList<T>;
|
|
93
|
+
modelValidators?: readonly ModelValidatorComponent<T, TModel>[];
|
|
94
|
+
singularName?: string;
|
|
95
|
+
displayName?: string;
|
|
96
|
+
}>;
|
|
97
|
+
declare type ModelFactory = <T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>>(pluralName: string, modelDefinition: ModelDefinition<T, TModel>, options?: OptionalModelOptions<T, TModel, TModelInstance>) => TModel;
|
|
98
|
+
declare type CreateParams<T extends FunctionalModel> = T | TypedJsonObj<T> | (TypedJsonObj<T> & Readonly<{
|
|
99
|
+
id?: PrimaryKeyType;
|
|
100
|
+
}>);
|
|
101
|
+
declare type Model<T extends FunctionalModel> = Readonly<{
|
|
102
|
+
getName: () => string;
|
|
103
|
+
getSingularName: () => string;
|
|
104
|
+
getDisplayName: () => string;
|
|
105
|
+
getPrimaryKeyName: () => string;
|
|
106
|
+
getModelDefinition: () => ModelDefinition<T>;
|
|
107
|
+
getPrimaryKey: (t: T | TypedJsonObj<T>) => PrimaryKeyType;
|
|
108
|
+
getOptions: () => object & ModelOptions<T>;
|
|
109
|
+
create: (data: CreateParams<T>) => ModelInstance<T>;
|
|
110
|
+
}>;
|
|
111
|
+
declare type ModelReferenceFunctions = Readonly<{
|
|
112
|
+
[s: string]: () => Maybe<PrimaryKeyType>;
|
|
113
|
+
}>;
|
|
114
|
+
declare type PropertyValidators<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = Readonly<{
|
|
115
|
+
id?: PropertyValidator<T, TModel>;
|
|
116
|
+
}> & Readonly<{
|
|
117
|
+
[s: string]: PropertyValidator<T, TModel>;
|
|
118
|
+
}>;
|
|
119
|
+
declare type ModelInstance<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = Readonly<{
|
|
120
|
+
get: PropertyGetters<T> & {
|
|
121
|
+
id?: () => MaybePromise<PrimaryKeyType>;
|
|
146
122
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
};
|
|
123
|
+
references: ModelReferenceFunctions;
|
|
124
|
+
toObj: toObj<T>;
|
|
125
|
+
getPrimaryKeyName: () => string;
|
|
126
|
+
getPrimaryKey: () => PrimaryKeyType;
|
|
127
|
+
validators: PropertyValidators<T, TModel>;
|
|
128
|
+
validate: (options?: object) => Promise<ModelErrors<T>>;
|
|
129
|
+
getModel: () => TModel;
|
|
130
|
+
}>;
|
|
156
131
|
declare type ValueRequired<T extends Arrayable<FunctionalValue>> = NonNullable<T>;
|
|
157
132
|
declare type ValueOptional<T extends Arrayable<FunctionalValue>> = Maybe<T>;
|
|
158
|
-
declare type ValueOptionalR<T extends FunctionalModel> = ValueOptional<ModelReference<T>>;
|
|
159
133
|
declare type ValueRequiredR<T extends FunctionalModel> = ValueRequired<ModelReference<T>>;
|
|
134
|
+
declare type ValueOptionalR<T extends FunctionalModel> = ValueOptional<ModelReference<T>>;
|
|
160
135
|
declare type IsAsync<T extends Arrayable<FunctionalValue>> = Promise<T>;
|
|
161
136
|
declare type PropertyModifier<T extends Arrayable<FunctionalValue>> = ValueRequired<T> | ValueOptional<T> | T;
|
|
162
|
-
declare type ModelOptions<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
declare type OptionalModelOptions<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
} | undefined;
|
|
170
|
-
export { MaybeFunction, Maybe, MaybePromise, Nullable, Arrayable, MaybeLazy, JsonAble, toObj, ModelInstance, Model, PropertyValidatorComponent, PropertyValidatorComponentSync, PropertyValidatorComponentAsync, PropertyValidator, ModelValidatorComponent, PropertyInstance, PropertyConfig, FunctionalValue, ValueGetter, ModelReference, ModelDefinition, ModelOptions,
|
|
137
|
+
declare type ModelOptions<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = Readonly<{
|
|
138
|
+
instanceCreatedCallback: Nullable<Arrayable<(instance: TModelInstance) => void>>;
|
|
139
|
+
[s: string]: any;
|
|
140
|
+
}>;
|
|
141
|
+
declare type OptionalModelOptions<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = Readonly<{
|
|
142
|
+
instanceCreatedCallback?: Nullable<Arrayable<(instance: TModelInstance) => void>>;
|
|
143
|
+
[s: string]: any;
|
|
144
|
+
}> | undefined;
|
|
145
|
+
export { MaybeFunction, Maybe, MaybePromise, Nullable, Arrayable, MaybeLazy, JsonAble, toObj, ModelInstance, Model, PropertyValidatorComponent, PropertyValidatorComponentSync, PropertyValidatorComponentAsync, PropertyValidator, ModelValidatorComponent, PropertyInstance, PropertyConfig, FunctionalValue, ValueGetter, ModelReference, ModelDefinition, ModelOptions, OptionalModelOptions, ModelReferencePropertyInstance, PropertyGetters, PropertyValidators, PropertyValidatorComponentTypeAdvanced, FunctionalModel, ModelReferenceFunctions, ModelErrors, PrimaryKeyType, ModelFactory, ModelFetcher, CreateParams, ValidatorConfiguration, ValuePropertyValidatorComponent, ValueRequired, ValueOptional, PropertyModifier, ValidationErrors, ModelError, IsAsync, TypedJsonObj, JsonObj, ValueRequiredR, ValueOptionalR, };
|
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":";;AA0XA,kCAAkC"}
|
package/lazy.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const lazyValue: (method:
|
|
1
|
+
declare const lazyValue: (method: (...args: any[]) => any) => (...args: readonly any[]) => Promise<any>;
|
|
2
2
|
export { lazyValue };
|
package/lazy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4DAAkC;AAClC,mCAAoC;AAEpC,MAAM,SAAS,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4DAAkC;AAClC,mCAAoC;AAEpC,MAAM,SAAS,GAAG,CAAC,MAA+B,EAAE,EAAE;IACpD,MAAM,GAAG,GAAG,IAAA,kBAAU,GAAE,CAAA;IACxB,MAAM,IAAI,GAAG,IAAI,oBAAS,EAAE,CAAA;IAC5B,sCAAsC;IACtC,IAAI,KAAK,GAAQ,SAAS,CAAA;IAC1B,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,OAAO,CAAO,GAAG,IAAoB,EAAE,EAAE;QACvC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAS,EAAE;YAClC,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,GAAG,IAAI,CAAA;gBACb,KAAK,GAAG,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;gBAC7B,kDAAkD;aACnD;YAED,OAAO,KAAK,CAAA;QACd,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC,CAAA,CAAA;IACD,qCAAqC;AACvC,CAAC,CAAA;AAEQ,8BAAS"}
|