functional-models 2.0.2 → 2.0.3

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 CHANGED
@@ -32,11 +32,11 @@ declare type RemoveType<T, TRemove> = {
32
32
  readonly [P in keyof T as T[P] extends TRemove ? never : P]: T[P];
33
33
  };
34
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>> = {
36
- readonly [P in keyof NotModelMethods<T, TModel> as NotModelMethods<T, TModel>[P] extends ModelInstanceMethod | ModelInstanceMethod<T, TModel> | ModelInstanceMethod<T, TModel, any> ? P : never]: ModelInstanceMethodClient;
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
37
  };
38
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>> = ValueIsOfType<T, ModelInstanceMethod | ModelInstanceMethod<T> | ModelInstanceMethod<T, TModel>>;
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
40
  declare type PropertyGetters<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = {
41
41
  readonly [Property in keyof T as T[Property] extends ModelMethodTypes<T, TModel> ? never : Property]: () => T[Property];
42
42
  };
@@ -60,23 +60,22 @@ declare type ModelErrors<T extends FunctionalModel, TModel extends Model<T> = Mo
60
60
  } & {
61
61
  readonly overall?: readonly string[] | undefined;
62
62
  };
63
- declare type PropertyValidatorComponentTypeAdvanced<TValue, TModel extends FunctionalModel> = (value: TValue, instance: ModelInstance<TModel, any>, instanceData: TModel | JsonAble, configurations: ValidatorConfiguration) => ValidationErrorResponse;
64
- declare type PropertyValidatorComponentType<TValue> = (value: TValue, instance: ModelInstance<any, any>, instanceData: FunctionalModel | JsonAble, configurations: ValidatorConfiguration) => ValidationErrorResponse;
65
- declare type PropertyValidatorComponentSync<T extends FunctionalModel> = PropertyValidatorComponentTypeAdvanced<any, T>;
63
+ 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
+ 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>;
66
65
  declare type ValuePropertyValidatorComponent<T extends Arrayable<FunctionalValue>> = (value: T) => ValidationErrorResponse;
67
- declare type PropertyValidatorComponentAsync<T extends FunctionalModel> = (value: Arrayable<FunctionalValue>, instance: ModelInstance<T, any>, instanceData: T | JsonAble, configurations: ValidatorConfiguration) => Promise<ValidationErrorResponse>;
68
- declare type PropertyValidatorComponent<T extends FunctionalModel> = PropertyValidatorComponentSync<T> | PropertyValidatorComponentAsync<T>;
69
- declare type PropertyValidator<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = (instance: ModelInstance<T, TModel>, instanceData: T | JsonAble, configurations: ValidatorConfiguration) => Promise<ValidationErrors>;
70
- declare type ModelValidatorComponent<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = (instance: ModelInstance<T, TModel>, instanceData: T | JsonAble, configurations: ValidatorConfiguration) => Promise<ModelError>;
66
+ declare type PropertyValidatorComponentAsync<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = (value: Arrayable<FunctionalValue>, instance: TModelInstance, instanceData: T | JsonAble, configurations: ValidatorConfiguration) => Promise<ValidationErrorResponse>;
67
+ declare type PropertyValidatorComponent<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = PropertyValidatorComponentSync<T, TModel, TModelInstance> | PropertyValidatorComponentAsync<T, TModel, TModelInstance>;
68
+ 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
+ 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>;
71
70
  declare type ValueGetter<T extends Arrayable<FunctionalValue>> = () => MaybePromise<T | ModelInstance<any, any>>;
72
- declare type PropertyInstance<T extends Arrayable<FunctionalValue>> = {
71
+ declare type PropertyInstance<TValue extends Arrayable<FunctionalValue>> = {
73
72
  readonly getConfig: () => object;
74
73
  readonly getChoices: () => readonly VeryPrimitivesTypes[];
75
- readonly getDefaultValue: () => T;
76
- readonly getConstantValue: () => T;
74
+ readonly getDefaultValue: () => TValue;
75
+ readonly getConstantValue: () => TValue;
77
76
  readonly getPropertyType: () => string;
78
- readonly createGetter: (value: T) => ValueGetter<T>;
79
- readonly getValidator: <TModel extends FunctionalModel>(valueGetter: ValueGetter<T>) => PropertyValidator<TModel>;
77
+ readonly createGetter: (value: TValue) => ValueGetter<TValue>;
78
+ readonly getValidator: <TModel extends FunctionalModel>(valueGetter: ValueGetter<TValue>) => PropertyValidator<TModel>;
80
79
  };
81
80
  declare type PropertiesList<T extends FunctionalModel> = {
82
81
  readonly [P in keyof T as T[P] extends Arrayable<FunctionalValue> ? P : never]: PropertyInstance<any>;
@@ -85,7 +84,7 @@ interface ReferencePropertyInstance<T extends FunctionalModel, TProperty extends
85
84
  readonly getReferencedId: (instanceValues: ReferenceValueType<T>) => Maybe<PrimaryKeyType>;
86
85
  readonly getReferencedModel: () => Model<T>;
87
86
  }
88
- declare type ReferenceValueType<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = ModelInstance<T, TModel> | ModelInstanceInputData<T> | PrimaryKeyType;
87
+ declare type ReferenceValueType<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = TModelInstance | ModelInstanceInputData<T> | PrimaryKeyType;
89
88
  declare type DefaultPropertyValidators = {
90
89
  readonly required?: boolean;
91
90
  readonly isInteger?: boolean;
@@ -109,17 +108,17 @@ declare type PropertyConfigContents<T extends Arrayable<FunctionalValue>> = {
109
108
  readonly autoNow?: boolean;
110
109
  readonly fetcher?: ModelFetcher;
111
110
  };
112
- declare type ModelFetcher = <T extends FunctionalModel>(model: Model<T>, primaryKey: PrimaryKeyType) => Promise<ModelInstance<T, Model<T>> | ModelInstanceInputData<T> | null | undefined>;
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>;
113
112
  declare type PropertyConfig<T extends Arrayable<FunctionalValue>> = (PropertyConfigContents<T> & DefaultPropertyValidators) | undefined;
114
113
  declare type PrimaryKeyPropertyInstanceType = PropertyInstance<string> | PropertyInstance<number>;
115
114
  declare type PrimaryKeyType = string | number;
116
- declare type ModelDefinition<T extends FunctionalModel, TModel extends Model<T> = Model<T>> = {
115
+ declare type ModelDefinition<T extends FunctionalModel, TModel extends Model<T> = Model<T>, TModelInstance extends ModelInstance<T, TModel> = ModelInstance<T, TModel>> = {
117
116
  readonly getPrimaryKeyName?: () => string;
118
117
  readonly properties: PropertiesList<T> & {
119
118
  readonly id?: PrimaryKeyPropertyInstanceType;
120
119
  };
121
120
  readonly modelMethods?: ModelMethods<T, TModel>;
122
- readonly instanceMethods?: InstanceMethods<T, TModel>;
121
+ readonly instanceMethods?: InstanceMethods<T, TModel, TModelInstance>;
123
122
  readonly modelValidators?: readonly ModelValidatorComponent<T, TModel>[];
124
123
  };
125
124
  declare type ModelFactory = <T extends FunctionalModel, TModel extends Model<T> = Model<T>>(modelName: string, modelDefinition: ModelDefinition<T, TModel>, options?: OptionalModelOptions<T, TModel>) => TModel;
@@ -168,4 +167,4 @@ declare type OptionalModelOptions<T extends FunctionalModel, TModel extends Mode
168
167
  readonly instanceCreatedCallback?: Nullable<Arrayable<(instance: ModelInstance<T, TModel>) => void>>;
169
168
  readonly [s: string]: any;
170
169
  } | undefined;
171
- export { MaybeFunction, Maybe, MaybePromise, Nullable, Arrayable, MaybeLazy, JsonAble, toObj, ModelInstance, Model, PropertyValidatorComponent, PropertyValidatorComponentSync, PropertyValidatorComponentAsync, PropertyValidatorComponentType, PropertyValidator, ModelValidatorComponent, PropertyInstance, PropertyConfig, FunctionalValue, ValueGetter, ReferenceValueType, ModelDefinition, ModelOptions, ModelMethod, OptionalModelOptions, ReferencePropertyInstance, PropertyGetters, PropertyValidators, PropertyValidatorComponentTypeAdvanced, ModelInstanceMethod, FunctionalModel, ModelInstanceInputData, ModelMethodGetters, InstanceMethodGetters, ReferenceFunctions, ModelErrors, PrimaryKeyType, ModelFactory, ModelFetcher, CreateParams, ValidatorConfiguration, ValuePropertyValidatorComponent, ValueRequired, ValueOptional, ValueOptionalR, ValueRequiredR, PropertyModifier, ValidationErrors, ModelError, IsAsync, ModelInstanceMethodClient, ModelMethodClient, TypedJsonObj, };
170
+ export { MaybeFunction, Maybe, MaybePromise, Nullable, Arrayable, MaybeLazy, JsonAble, toObj, ModelInstance, Model, PropertyValidatorComponent, PropertyValidatorComponentSync, PropertyValidatorComponentAsync, PropertyValidator, ModelValidatorComponent, PropertyInstance, PropertyConfig, FunctionalValue, ValueGetter, ReferenceValueType, ModelDefinition, ModelOptions, ModelMethod, OptionalModelOptions, ReferencePropertyInstance, PropertyGetters, PropertyValidators, PropertyValidatorComponentTypeAdvanced, ModelInstanceMethod, FunctionalModel, ModelInstanceInputData, ModelMethodGetters, InstanceMethodGetters, ReferenceFunctions, ModelErrors, PrimaryKeyType, ModelFactory, ModelFetcher, CreateParams, ValidatorConfiguration, ValuePropertyValidatorComponent, ValueRequired, ValueOptional, ValueOptionalR, ValueRequiredR, PropertyModifier, ValidationErrors, ModelError, IsAsync, ModelInstanceMethodClient, ModelMethodClient, TypedJsonObj, };
package/interfaces.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;AAscA,kCAAkC"}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;AAydA,kCAAkC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functional-models",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "A library for creating JavaScript function based models.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/properties.d.ts CHANGED
@@ -36,5 +36,5 @@ declare const ReferenceProperty: <T extends {
36
36
  }>> | null | undefined;
37
37
  } & {
38
38
  readonly id?: PrimaryKeyType | undefined;
39
- }, TModifier extends PropertyModifier<ReferenceValueType<T, Model<T>>>>(model: MaybeFunction<Model<T>>, config?: PropertyConfig<TModifier>, additionalMetadata?: {}) => ReferencePropertyInstance<T, TModifier>;
39
+ }, TModifier extends PropertyModifier<ReferenceValueType<T, Model<T>, ModelInstance<T, Model<T>>>>>(model: MaybeFunction<Model<T>>, config?: PropertyConfig<TModifier>, additionalMetadata?: {}) => ReferencePropertyInstance<T, TModifier>;
40
40
  export { Property, UniqueId, DateProperty, ArrayProperty, ReferenceProperty, IntegerProperty, TextProperty, ConstantValueProperty, NumberProperty, ObjectProperty, EmailProperty, BooleanProperty, };
package/validation.d.ts CHANGED
@@ -45,7 +45,7 @@ declare const referenceTypeMatch: <TModel extends {
45
45
  }>> | null | undefined;
46
46
  } & {
47
47
  readonly id?: import("./interfaces").PrimaryKeyType | undefined;
48
- }>(referencedModel: MaybeFunction<Model<TModel>>) => PropertyValidatorComponentTypeAdvanced<ModelInstance<TModel, any>, TModel>;
48
+ }>(referencedModel: MaybeFunction<Model<TModel>>) => PropertyValidatorComponentTypeAdvanced<ModelInstance<TModel, any>, TModel, Model<TModel>, ModelInstance<TModel, Model<TModel>>>;
49
49
  declare const aggregateValidator: <T extends {
50
50
  readonly [s: string]: string | number | boolean | readonly string[] | (any & {
51
51
  readonly id?: import("./interfaces").PrimaryKeyType | undefined;
@@ -70,7 +70,7 @@ declare const aggregateValidator: <T extends {
70
70
  }>> | null | undefined;
71
71
  } & {
72
72
  readonly id?: import("./interfaces").PrimaryKeyType | undefined;
73
- }>(value: any, methodOrMethods: PropertyValidatorComponent<T> | readonly PropertyValidatorComponent<T>[]) => PropertyValidator<T, Model<T>>;
73
+ }>(value: any, methodOrMethods: PropertyValidatorComponent<T, Model<T>, ModelInstance<T, Model<T>>> | readonly PropertyValidatorComponent<T, Model<T>, ModelInstance<T, Model<T>>>[]) => PropertyValidator<T, Model<T>, ModelInstance<T, Model<T>>>;
74
74
  declare const emptyValidator: PropertyValidatorComponentSync<any>;
75
75
  declare const createPropertyValidator: <T extends Arrayable<FunctionalValue>>(valueGetter: ValueGetter<T>, config: PropertyConfig<T>) => <TModel extends {
76
76
  readonly [s: string]: string | number | boolean | readonly string[] | (any & {
@@ -121,5 +121,5 @@ declare const createModelValidator: <T extends {
121
121
  }>> | null | undefined;
122
122
  } & {
123
123
  readonly id?: import("./interfaces").PrimaryKeyType | undefined;
124
- }, TModel extends Model<T> = Model<T>>(validators: PropertyValidators<T, TModel>, modelValidators?: readonly ModelValidatorComponent<T, TModel>[] | undefined) => (instance: ModelInstance<T, TModel>, propertyConfiguration: ValidatorConfiguration) => Promise<ModelErrors<T, TModel>>;
124
+ }, TModel extends Model<T> = Model<T>>(validators: PropertyValidators<T, TModel>, modelValidators?: readonly ModelValidatorComponent<T, TModel, ModelInstance<T, TModel>>[] | undefined) => (instance: ModelInstance<T, TModel>, propertyConfiguration: ValidatorConfiguration) => Promise<ModelErrors<T, TModel>>;
125
125
  export { isNumber, isBoolean, isString, isInteger, isType, isDate, isArray, isRequired, maxNumber, minNumber, choices, maxTextLength, minTextLength, meetsRegex, aggregateValidator, emptyValidator, createPropertyValidator, createModelValidator, arrayType, referenceTypeMatch, TYPE_PRIMITIVES, };