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 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
- - UniqueId // A UUID property
267
- - DateProperty // A property for dates. Includes the ability to "autoNow".
268
- - ArrayProperty // An array property which can be used to limit types within it.
269
- - ModelReferenceProperty // A property that references another property. (Think Foreign Key)
270
- - AdvancedModelReferenceProperty // A more fuller/advanced property for referencing other properties.
271
- - IntegerProperty // A property for integers.
272
- - TextProperty // A text or string property.
273
- - ConstantValueProperty // A property that contains a single, unchanging, static value.
274
- - NumberProperty // A property for float/number types.
275
- - ObjectProperty // A property that has a JavaScript object. (Not a foreign key references)
276
- - EmailProperty // An email property.
277
- - BooleanProperty // A true or false value property.
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
- readonly [s: string]: readonly string[];
3
- };
1
+ declare type KeysToErrors = Readonly<{
2
+ [s: string]: readonly string[];
3
+ }>;
4
4
  declare class ValidationError extends Error {
5
- modelName: String;
5
+ modelName: string;
6
6
  keysToErrors: KeysToErrors;
7
- constructor(modelName: String, keysToErrors: KeysToErrors);
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-expression */
5
- /* eslint-disable functional/no-class */
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,kDAAkD;AAClD,wCAAwC;AACxC,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"}
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
@@ -6,5 +6,4 @@ import * as utils from './utils';
6
6
  import * as interfaces from './interfaces';
7
7
  export * from './models';
8
8
  export * from './properties';
9
- export * from './methods';
10
9
  export { constants, errors, validation, serialization, utils, interfaces };
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;AAW/B,8BAAS;AAVlB,iDAAkC;AAUd,wBAAM;AAT1B,yDAA0C;AASd,gCAAU;AARtC,+DAAgD;AAQR,sCAAa;AAPrD,+CAAgC;AAOuB,sBAAK;AAN5D,yDAA0C;AAMoB,gCAAU;AAJxE,2CAAwB;AACxB,+CAA4B;AAC5B,4CAAyB"}
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 UnWrapPromises<T> = {
8
- readonly [P in keyof T]: Awaited<T[P]>;
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 NoFunctions<UnWrapPromises<T>>]: JsonAble;
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 ValueIsOfType<T, V> = {
21
- readonly [P in keyof T as T[P] extends V ? P : never]: T[P];
22
- };
23
- declare type ModelMethod<T extends FunctionalModel = FunctionalModel, TModel extends Model<T> = Model<T>> = (model: TModel, ...args: readonly any[]) => any;
24
- declare type ModelMethodClient = (...args: readonly any[]) => any;
25
- declare type ModelMethods<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = ValueIsOfType<T, ModelMethod | ModelMethod<T> | ModelMethod<T, TModel>>;
26
- declare type ModelMethodGetters<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = {
27
- readonly [P in keyof T as T[P] extends ModelMethod<T, TModel> | ModelMethod<T> | ModelMethod ? P : never]: ModelMethodClient;
28
- };
29
- declare type ModelInstanceMethod<T extends FunctionalModel = FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = (instance: TModelInstance, model: TModel, ...args: readonly any[]) => any;
30
- declare type ModelInstanceMethodClient = (...args: readonly any[]) => any;
31
- declare type RemoveType<T, TRemove> = {
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, TModel extends Model<T> = Model<T>> = {
59
- readonly [Property in keyof T as T[Property] extends ModelMethodTypes<T, TModel> ? never : Property]: readonly string[] | undefined;
60
- } & {
61
- readonly overall?: readonly string[] | undefined;
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
- readonly getConfig: () => object;
73
- readonly getChoices: () => readonly VeryPrimitivesTypes[];
74
- readonly getDefaultValue: () => TValue;
75
- readonly getConstantValue: () => TValue;
76
- readonly getPropertyType: () => string;
77
- readonly createGetter: (value: TValue) => ValueGetter<TValue, T, TModel, TModelInstance>;
78
- readonly getValidator: (valueGetter: ValueGetter<TValue, T, TModel, TModelInstance>) => PropertyValidator<TModel>;
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>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> extends PropertyInstance<TProperty> {
84
- readonly getReferencedId: (instanceValues: ModelReference<T, TModel, TModelInstance>) => Maybe<PrimaryKeyType>;
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, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = TModelInstance | ModelInstanceInputData<T> | PrimaryKeyType;
88
- declare type DefaultPropertyValidators = {
89
- readonly required?: boolean;
90
- readonly isInteger?: boolean;
91
- readonly isNumber?: boolean;
92
- readonly isString?: boolean;
93
- readonly isArray?: boolean;
94
- readonly isBoolean?: boolean;
95
- };
96
- declare type PropertyConfigContents<T extends Arrayable<FunctionalValue>> = {
97
- readonly type?: string;
98
- readonly defaultValue?: T;
99
- readonly value?: T;
100
- readonly choices?: readonly VeryPrimitivesTypes[];
101
- readonly lazyLoadMethod?: (value: T) => MaybeLazy<T>;
102
- readonly valueSelector?: (instanceValue: MaybePromise<T>) => T;
103
- readonly validators?: readonly PropertyValidatorComponent<any>[];
104
- readonly maxLength?: number;
105
- readonly minLength?: number;
106
- readonly maxValue?: number;
107
- readonly minValue?: number;
108
- readonly autoNow?: boolean;
109
- readonly fetcher?: ModelFetcher;
110
- };
111
- declare type ModelFetcher = <T extends FunctionalModel, TModel extends Model<T> = Model<T>>(model: TModel, primaryKey: PrimaryKeyType) => Promise<ModelInstance<T, TModel>> | Promise<ModelInstanceInputData<T>> | Promise<null> | Promise<undefined>;
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>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = {
116
- readonly getPrimaryKeyName?: () => string;
117
- readonly properties: PropertiesList<T> & {
118
- readonly id?: PrimaryKeyPropertyInstanceType;
119
- };
120
- readonly modelMethods?: ModelMethods<T, TModel>;
121
- readonly instanceMethods?: InstanceMethods<T, TModel, TModelInstance>;
122
- readonly modelValidators?: readonly ModelValidatorComponent<T, TModel>[];
123
- };
124
- declare type ModelFactory = <T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>>(modelName: string, modelDefinition: ModelDefinition<T, TModel, TModelInstance>, options?: OptionalModelOptions<T, TModel, TModelInstance>) => TModel;
125
- declare type CreateParams<T extends FunctionalModel> = ModelInstanceInputData<T> | (ModelInstanceInputData<T> & {
126
- readonly id?: PrimaryKeyType;
127
- });
128
- declare type Model<T extends FunctionalModel> = {
129
- readonly getName: () => string;
130
- readonly getPrimaryKeyName: () => string;
131
- readonly getModelDefinition: () => ModelDefinition<T>;
132
- readonly getPrimaryKey: (t: ModelInstanceInputData<T>) => PrimaryKeyType;
133
- readonly getOptions: () => object & ModelOptions<T>;
134
- readonly create: (data: CreateParams<T>) => ModelInstance<T>;
135
- readonly methods: ModelMethodGetters<T>;
136
- };
137
- declare type ModelReferenceFunctions = {
138
- readonly [s: string]: () => ModelReference<any>;
139
- };
140
- declare type PropertyValidators<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = {
141
- readonly [s: string]: PropertyValidator<T, TModel>;
142
- };
143
- declare type ModelInstance<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = {
144
- readonly get: PropertyGetters<T, TModel> & {
145
- readonly id: () => MaybePromise<PrimaryKeyType>;
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
- readonly methods: InstanceMethodGetters<T, TModel>;
148
- readonly references: ModelReferenceFunctions;
149
- readonly toObj: toObj<T>;
150
- readonly getPrimaryKeyName: () => string;
151
- readonly getPrimaryKey: () => PrimaryKeyType;
152
- readonly validators: PropertyValidators<T, TModel>;
153
- readonly validate: (options?: {}) => Promise<ModelErrors<T, TModel>>;
154
- readonly getModel: () => TModel;
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
- readonly instanceCreatedCallback: Nullable<Arrayable<(instance: TModelInstance) => void>>;
164
- readonly [s: string]: any;
165
- };
166
- declare type OptionalModelOptions<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = {
167
- readonly instanceCreatedCallback?: Nullable<Arrayable<(instance: TModelInstance) => void>>;
168
- readonly [s: string]: any;
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, ModelMethod, OptionalModelOptions, ModelReferencePropertyInstance, PropertyGetters, PropertyValidators, PropertyValidatorComponentTypeAdvanced, ModelInstanceMethod, FunctionalModel, ModelInstanceInputData, ModelMethodGetters, InstanceMethodGetters, ModelReferenceFunctions, ModelErrors, PrimaryKeyType, ModelFactory, ModelFetcher, CreateParams, ValidatorConfiguration, ValuePropertyValidatorComponent, ValueRequired, ValueOptional, ValueOptionalR, ValueRequiredR, PropertyModifier, ValidationErrors, ModelError, IsAsync, ModelInstanceMethodClient, ModelMethodClient, TypedJsonObj, JsonObj, };
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":";;AAyeA,kCAAkC"}
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: Function) => (...args: readonly any[]) => Promise<any>;
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,MAAgB,EAAE,EAAE;IACrC,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"}
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"}