functional-models 3.10.0 → 3.11.0
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/cjs/errors.cjs +38 -0
- package/cjs/errors.cjs.map +7 -0
- package/cjs/index.cjs +2426 -0
- package/cjs/index.cjs.map +7 -0
- package/cjs/lib.cjs +431 -0
- package/cjs/lib.cjs.map +7 -0
- package/cjs/models.cjs +571 -0
- package/cjs/models.cjs.map +7 -0
- package/cjs/orm/index.cjs +1765 -0
- package/cjs/orm/index.cjs.map +7 -0
- package/cjs/orm/internal-libs.cjs +136 -0
- package/cjs/orm/internal-libs.cjs.map +7 -0
- package/cjs/orm/libs.cjs +88 -0
- package/cjs/orm/libs.cjs.map +7 -0
- package/cjs/orm/models.cjs +1027 -0
- package/cjs/orm/models.cjs.map +7 -0
- package/cjs/orm/properties.cjs +989 -0
- package/cjs/orm/properties.cjs.map +7 -0
- package/cjs/orm/query.cjs +376 -0
- package/cjs/orm/query.cjs.map +7 -0
- package/cjs/orm/types.cjs +59 -0
- package/cjs/orm/types.cjs.map +7 -0
- package/cjs/orm/validation.cjs +301 -0
- package/cjs/orm/validation.cjs.map +7 -0
- package/cjs/properties.cjs +998 -0
- package/cjs/properties.cjs.map +7 -0
- package/cjs/serialization.cjs +75 -0
- package/cjs/serialization.cjs.map +7 -0
- package/cjs/types.cjs +65 -0
- package/cjs/types.cjs.map +7 -0
- package/cjs/utils.cjs +187 -0
- package/cjs/utils.cjs.map +7 -0
- package/cjs/validation.cjs +431 -0
- package/cjs/validation.cjs.map +7 -0
- package/errors.js +3 -4
- package/errors.js.map +1 -1
- package/index.d.ts +13 -13
- package/index.js +13 -52
- package/index.js.map +1 -1
- package/lib.d.ts +2 -2
- package/lib.js +45 -65
- package/lib.js.map +1 -1
- package/models.d.ts +1 -1
- package/models.js +22 -30
- package/models.js.map +1 -1
- package/orm/index.d.ts +9 -9
- package/orm/index.js +9 -48
- package/orm/index.js.map +1 -1
- package/orm/internal-libs.js +7 -11
- package/orm/internal-libs.js.map +1 -1
- package/orm/libs.d.ts +1 -1
- package/orm/libs.js +8 -16
- package/orm/libs.js.map +1 -1
- package/orm/models.d.ts +2 -2
- package/orm/models.js +20 -26
- package/orm/models.js.map +1 -1
- package/orm/properties.d.ts +22 -22
- package/orm/properties.js +26 -36
- package/orm/properties.js.map +1 -1
- package/orm/query.d.ts +1 -1
- package/orm/query.js +31 -52
- package/orm/query.js.map +1 -1
- package/orm/types.d.ts +1 -1
- package/orm/types.js +7 -10
- package/orm/types.js.map +1 -1
- package/orm/validation.d.ts +2 -2
- package/orm/validation.js +5 -13
- package/orm/validation.js.map +1 -1
- package/package.json +50 -65
- package/properties.d.ts +21 -21
- package/properties.js +65 -94
- package/properties.js.map +1 -1
- package/serialization.d.ts +1 -1
- package/serialization.js +3 -9
- package/serialization.js.map +1 -1
- package/types.js +4 -6
- package/types.js.map +1 -1
- package/utils.d.ts +2 -1
- package/utils.js +8 -23
- package/utils.js.map +1 -1
- package/validation.d.ts +1 -1
- package/validation.js +19 -50
- package/validation.js.map +1 -1
package/properties.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
|
-
import { ModelReferenceType, ModelInstance, ModelType, PropertyInstance, DataValue, PropertyConfig, ValueGetter, MaybeFunction, Arrayable, PropertyValidator, ModelReferencePropertyInstance, DataDescription, JsonAble, CalculateDenormalization, PropertyType, DateValueType, PrimitiveValueType, CanBeNullableType } from './types';
|
|
2
|
+
import { ModelReferenceType, ModelInstance, ModelType, PropertyInstance, DataValue, PropertyConfig, ValueGetter, MaybeFunction, Arrayable, PropertyValidator, ModelReferencePropertyInstance, DataDescription, JsonAble, CalculateDenormalization, PropertyType, DateValueType, PrimitiveValueType, CanBeNullableType } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* The base function that creates a fully loaded instance of a property. All standard issue properties use this function.
|
|
5
5
|
* @param propertyType - The property's value type.
|
|
@@ -38,7 +38,7 @@ type DatePropertyConfig<T extends Arrayable<DataValue>> = {
|
|
|
38
38
|
*/
|
|
39
39
|
export declare const DateProperty: <T extends CanBeNullableType<DateValueType> = DateValueType>(config?: DatePropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
40
40
|
getConfig: () => object;
|
|
41
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
41
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
42
42
|
getDefaultValue: () => T | undefined;
|
|
43
43
|
getConstantValue: () => T | undefined;
|
|
44
44
|
getPropertyType: () => PropertyType | string;
|
|
@@ -63,7 +63,7 @@ export declare const DateProperty: <T extends CanBeNullableType<DateValueType> =
|
|
|
63
63
|
*/
|
|
64
64
|
export declare const DatetimeProperty: <T extends CanBeNullableType<DateValueType> = DateValueType>(config?: DatePropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
65
65
|
getConfig: () => object;
|
|
66
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
66
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
67
67
|
getDefaultValue: () => T | undefined;
|
|
68
68
|
getConstantValue: () => T | undefined;
|
|
69
69
|
getPropertyType: () => PropertyType | string;
|
|
@@ -88,7 +88,7 @@ export declare const DatetimeProperty: <T extends CanBeNullableType<DateValueTyp
|
|
|
88
88
|
*/
|
|
89
89
|
export declare const ArrayProperty: <T extends CanBeNullableType<DataValue> = DataValue>(config?: {}, additionalMetadata?: {}) => Readonly<{
|
|
90
90
|
getConfig: () => object;
|
|
91
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
91
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
92
92
|
getDefaultValue: () => readonly T[] | undefined;
|
|
93
93
|
getConstantValue: () => readonly T[] | undefined;
|
|
94
94
|
getPropertyType: () => PropertyType | string;
|
|
@@ -114,7 +114,7 @@ export declare const ArrayProperty: <T extends CanBeNullableType<DataValue> = Da
|
|
|
114
114
|
*/
|
|
115
115
|
export declare const SingleTypeArrayProperty: <TValue extends Omit<PrimitiveValueType, "object">>(valueType: TValue, config?: {}, additionalMetadata?: {}) => Readonly<{
|
|
116
116
|
getConfig: () => object;
|
|
117
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
117
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
118
118
|
getDefaultValue: () => readonly TValue[] | undefined;
|
|
119
119
|
getConstantValue: () => readonly TValue[] | undefined;
|
|
120
120
|
getPropertyType: () => PropertyType | string;
|
|
@@ -139,7 +139,7 @@ export declare const SingleTypeArrayProperty: <TValue extends Omit<PrimitiveValu
|
|
|
139
139
|
*/
|
|
140
140
|
export declare const ObjectProperty: <TObject extends CanBeNullableType<Readonly<Record<string, JsonAble>>> = Readonly<Record<string, JsonAble>>>(config?: {}, additionalMetadata?: {}) => Readonly<{
|
|
141
141
|
getConfig: () => object;
|
|
142
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
142
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
143
143
|
getDefaultValue: () => TObject | undefined;
|
|
144
144
|
getConstantValue: () => TObject | undefined;
|
|
145
145
|
getPropertyType: () => PropertyType | string;
|
|
@@ -164,7 +164,7 @@ export declare const ObjectProperty: <TObject extends CanBeNullableType<Readonly
|
|
|
164
164
|
*/
|
|
165
165
|
export declare const TextProperty: <T extends CanBeNullableType<string> = string>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
166
166
|
getConfig: () => object;
|
|
167
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
167
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
168
168
|
getDefaultValue: () => T | undefined;
|
|
169
169
|
getConstantValue: () => T | undefined;
|
|
170
170
|
getPropertyType: () => PropertyType | string;
|
|
@@ -189,7 +189,7 @@ export declare const TextProperty: <T extends CanBeNullableType<string> = string
|
|
|
189
189
|
*/
|
|
190
190
|
export declare const BigTextProperty: <T extends CanBeNullableType<string> = string>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
191
191
|
getConfig: () => object;
|
|
192
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
192
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
193
193
|
getDefaultValue: () => T | undefined;
|
|
194
194
|
getConstantValue: () => T | undefined;
|
|
195
195
|
getPropertyType: () => PropertyType | string;
|
|
@@ -214,7 +214,7 @@ export declare const BigTextProperty: <T extends CanBeNullableType<string> = str
|
|
|
214
214
|
*/
|
|
215
215
|
export declare const IntegerProperty: <T extends CanBeNullableType<number> = number>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
216
216
|
getConfig: () => object;
|
|
217
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
217
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
218
218
|
getDefaultValue: () => T | undefined;
|
|
219
219
|
getConstantValue: () => T | undefined;
|
|
220
220
|
getPropertyType: () => PropertyType | string;
|
|
@@ -240,7 +240,7 @@ export declare const IntegerProperty: <T extends CanBeNullableType<number> = num
|
|
|
240
240
|
*/
|
|
241
241
|
export declare const YearProperty: <T extends CanBeNullableType<number> = number>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
242
242
|
getConfig: () => object;
|
|
243
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
243
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
244
244
|
getDefaultValue: () => T | undefined;
|
|
245
245
|
getConstantValue: () => T | undefined;
|
|
246
246
|
getPropertyType: () => PropertyType | string;
|
|
@@ -265,7 +265,7 @@ export declare const YearProperty: <T extends CanBeNullableType<number> = number
|
|
|
265
265
|
*/
|
|
266
266
|
export declare const NumberProperty: <T extends CanBeNullableType<number> = number>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
267
267
|
getConfig: () => object;
|
|
268
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
268
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
269
269
|
getDefaultValue: () => T | undefined;
|
|
270
270
|
getConstantValue: () => T | undefined;
|
|
271
271
|
getPropertyType: () => PropertyType | string;
|
|
@@ -292,7 +292,7 @@ export declare const NumberProperty: <T extends CanBeNullableType<number> = numb
|
|
|
292
292
|
*/
|
|
293
293
|
export declare const ConstantValueProperty: <TDataValue extends CanBeNullableType<Arrayable<DataValue>> = Arrayable<DataValue>>(valueType: PropertyType | string, value: TDataValue, config?: PropertyConfig<TDataValue>, additionalMetadata?: {}) => Readonly<{
|
|
294
294
|
getConfig: () => object;
|
|
295
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
295
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
296
296
|
getDefaultValue: () => TDataValue | undefined;
|
|
297
297
|
getConstantValue: () => TDataValue | undefined;
|
|
298
298
|
getPropertyType: () => PropertyType | string;
|
|
@@ -317,7 +317,7 @@ export declare const ConstantValueProperty: <TDataValue extends CanBeNullableTyp
|
|
|
317
317
|
*/
|
|
318
318
|
export declare const EmailProperty: <T extends CanBeNullableType<string> = string>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
319
319
|
getConfig: () => object;
|
|
320
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
320
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
321
321
|
getDefaultValue: () => T | undefined;
|
|
322
322
|
getConstantValue: () => T | undefined;
|
|
323
323
|
getPropertyType: () => PropertyType | string;
|
|
@@ -342,7 +342,7 @@ export declare const EmailProperty: <T extends CanBeNullableType<string> = strin
|
|
|
342
342
|
*/
|
|
343
343
|
export declare const BooleanProperty: <T extends CanBeNullableType<boolean> = boolean>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
344
344
|
getConfig: () => object;
|
|
345
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
345
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
346
346
|
getDefaultValue: () => T | undefined;
|
|
347
347
|
getConstantValue: () => T | undefined;
|
|
348
348
|
getPropertyType: () => PropertyType | string;
|
|
@@ -368,7 +368,7 @@ export declare const BooleanProperty: <T extends CanBeNullableType<boolean> = bo
|
|
|
368
368
|
*/
|
|
369
369
|
export declare const PrimaryKeyUuidProperty: <T extends CanBeNullableType<string> = string>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
370
370
|
getConfig: () => object;
|
|
371
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
371
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
372
372
|
getDefaultValue: () => T | undefined;
|
|
373
373
|
getConstantValue: () => T | undefined;
|
|
374
374
|
getPropertyType: () => PropertyType | string;
|
|
@@ -395,7 +395,7 @@ export declare const PrimaryKeyUuidProperty: <T extends CanBeNullableType<string
|
|
|
395
395
|
*/
|
|
396
396
|
export declare const UuidProperty: <T extends CanBeNullableType<string> = string>(config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
397
397
|
getConfig: () => object;
|
|
398
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
398
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
399
399
|
getDefaultValue: () => T | undefined;
|
|
400
400
|
getConstantValue: () => T | undefined;
|
|
401
401
|
getPropertyType: () => PropertyType | string;
|
|
@@ -454,7 +454,7 @@ export declare const AdvancedModelReferenceProperty: <T extends DataDescription,
|
|
|
454
454
|
*/
|
|
455
455
|
export declare const DenormalizedProperty: <TValue extends CanBeNullableType<DataValue>, T extends DataDescription>(propertyType: string, calculate: CalculateDenormalization<TValue, T>, config?: PropertyConfig<TValue>, additionalMetadata?: {}) => Readonly<{
|
|
456
456
|
getConfig: () => object;
|
|
457
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
457
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
458
458
|
getDefaultValue: () => TValue | undefined;
|
|
459
459
|
getConstantValue: () => TValue | undefined;
|
|
460
460
|
getPropertyType: () => PropertyType | string;
|
|
@@ -482,7 +482,7 @@ export declare const DenormalizedProperty: <TValue extends CanBeNullableType<Dat
|
|
|
482
482
|
*/
|
|
483
483
|
export declare const DenormalizedTextProperty: <T extends DataDescription, TData extends CanBeNullableType<string> = string>(calculate: CalculateDenormalization<TData, T>, config?: PropertyConfig<TData>, additionalMetadata?: {}) => Readonly<{
|
|
484
484
|
getConfig: () => object;
|
|
485
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
485
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
486
486
|
getDefaultValue: () => TData | undefined;
|
|
487
487
|
getConstantValue: () => TData | undefined;
|
|
488
488
|
getPropertyType: () => PropertyType | string;
|
|
@@ -510,7 +510,7 @@ export declare const DenormalizedTextProperty: <T extends DataDescription, TData
|
|
|
510
510
|
*/
|
|
511
511
|
export declare const DenormalizedNumberProperty: <T extends DataDescription, TData extends CanBeNullableType<number> = number>(calculate: CalculateDenormalization<TData, T>, config?: PropertyConfig<TData>, additionalMetadata?: {}) => Readonly<{
|
|
512
512
|
getConfig: () => object;
|
|
513
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
513
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
514
514
|
getDefaultValue: () => TData | undefined;
|
|
515
515
|
getConstantValue: () => TData | undefined;
|
|
516
516
|
getPropertyType: () => PropertyType | string;
|
|
@@ -538,7 +538,7 @@ export declare const DenormalizedNumberProperty: <T extends DataDescription, TDa
|
|
|
538
538
|
*/
|
|
539
539
|
export declare const DenormalizedIntegerProperty: <T extends DataDescription, TData extends CanBeNullableType<number> = number>(calculate: CalculateDenormalization<TData, T>, config?: PropertyConfig<TData>, additionalMetadata?: {}) => Readonly<{
|
|
540
540
|
getConfig: () => object;
|
|
541
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
541
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
542
542
|
getDefaultValue: () => TData | undefined;
|
|
543
543
|
getConstantValue: () => TData | undefined;
|
|
544
544
|
getPropertyType: () => PropertyType | string;
|
|
@@ -574,7 +574,7 @@ export declare const DenormalizedIntegerProperty: <T extends DataDescription, TD
|
|
|
574
574
|
*/
|
|
575
575
|
export declare const NaturalIdProperty: <T extends CanBeNullableType<string> = string>(propertyKeys: readonly string[], joiner: string, config?: PropertyConfig<T>, additionalMetadata?: {}) => Readonly<{
|
|
576
576
|
getConfig: () => object;
|
|
577
|
-
getChoices: () => readonly import("./types").ChoiceTypes[];
|
|
577
|
+
getChoices: () => readonly import("./types.js").ChoiceTypes[];
|
|
578
578
|
getDefaultValue: () => T | undefined;
|
|
579
579
|
getConstantValue: () => T | undefined;
|
|
580
580
|
getPropertyType: () => PropertyType | string;
|
package/properties.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,18 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const uuid_1 = require("uuid");
|
|
19
|
-
const validation_1 = require("./validation");
|
|
20
|
-
const utils_1 = require("./utils");
|
|
21
|
-
const types_1 = require("./types");
|
|
22
|
-
const lib_1 = require("./lib");
|
|
10
|
+
import merge from 'lodash/merge.js';
|
|
11
|
+
import get from 'lodash/get.js';
|
|
12
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
13
|
+
import { arrayType, createPropertyValidator, isType, isValidUuid, maxNumber, meetsRegex, minNumber, optionalValidator, referenceTypeMatch, } from './validation.js';
|
|
14
|
+
import { createHeadAndTail, memoizeAsync, memoizeSync } from './utils.js';
|
|
15
|
+
import { PropertyType, } from './types.js';
|
|
16
|
+
import { getValueForModelInstance, getValueForReferencedModel, isReferencedProperty, getCommonTextValidators, getCommonNumberValidators, mergeValidators, isModelInstance, createZodForProperty, } from './lib.js';
|
|
23
17
|
const MAX_YEAR = 3000;
|
|
24
18
|
const EMAIL_REGEX = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/u;
|
|
25
19
|
/**
|
|
@@ -32,7 +26,7 @@ const EMAIL_REGEX = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-
|
|
|
32
26
|
* @typeParam TModelExtensions - Any additional model extensions
|
|
33
27
|
* @typeParam TModelInstanceExtensions - Any additional model instance extensions
|
|
34
28
|
*/
|
|
35
|
-
const Property = (propertyType, config = {}, additionalMetadata = {}) => {
|
|
29
|
+
export const Property = (propertyType, config = {}, additionalMetadata = {}) => {
|
|
36
30
|
if (!propertyType && !(config === null || config === void 0 ? void 0 : config.typeOverride)) {
|
|
37
31
|
throw new Error(`Property type must be provided.`);
|
|
38
32
|
}
|
|
@@ -62,11 +56,11 @@ const Property = (propertyType, config = {}, additionalMetadata = {}) => {
|
|
|
62
56
|
const method = lazyLoadMethod
|
|
63
57
|
? lazyLoadMethod
|
|
64
58
|
: config.lazyLoadMethodAtomic
|
|
65
|
-
?
|
|
59
|
+
? memoizeAsync(config.lazyLoadMethodAtomic)
|
|
66
60
|
: typeof instanceValue === 'function'
|
|
67
61
|
? instanceValue
|
|
68
62
|
: () => instanceValue;
|
|
69
|
-
const valueGetter =
|
|
63
|
+
const valueGetter = memoizeSync(() => {
|
|
70
64
|
// @ts-ignore
|
|
71
65
|
const result = method(instanceValue, modelData,
|
|
72
66
|
// @ts-ignore
|
|
@@ -76,7 +70,7 @@ const Property = (propertyType, config = {}, additionalMetadata = {}) => {
|
|
|
76
70
|
return valueGetter;
|
|
77
71
|
};
|
|
78
72
|
const getValidator = (valueGetter) => {
|
|
79
|
-
const validator =
|
|
73
|
+
const validator = createPropertyValidator(valueGetter, config);
|
|
80
74
|
const _propertyValidatorWrapper = (model, instanceData, propertyConfiguration) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
75
|
return validator(model, instanceData, propertyConfiguration);
|
|
82
76
|
});
|
|
@@ -89,7 +83,7 @@ const Property = (propertyType, config = {}, additionalMetadata = {}) => {
|
|
|
89
83
|
if (provided) {
|
|
90
84
|
return provided;
|
|
91
85
|
}
|
|
92
|
-
return
|
|
86
|
+
return createZodForProperty(propertyType, config)();
|
|
93
87
|
};
|
|
94
88
|
const propertyInstance = Object.assign(Object.assign({}, additionalMetadata), { getConfig: () => config || {}, getChoices,
|
|
95
89
|
getDefaultValue,
|
|
@@ -98,7 +92,6 @@ const Property = (propertyType, config = {}, additionalMetadata = {}) => {
|
|
|
98
92
|
getValidator });
|
|
99
93
|
return propertyInstance;
|
|
100
94
|
};
|
|
101
|
-
exports.Property = Property;
|
|
102
95
|
/**
|
|
103
96
|
* Determines if the value is a Date object.
|
|
104
97
|
* @param value Any value
|
|
@@ -115,7 +108,7 @@ const isDate = (value) => {
|
|
|
115
108
|
* @param config - A configuration that enables overriding of date formatting
|
|
116
109
|
* @param additionalMetadata
|
|
117
110
|
*/
|
|
118
|
-
const DateProperty = (config = {}, additionalMetadata = {}) =>
|
|
111
|
+
export const DateProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Date, merge({
|
|
119
112
|
lazyLoadMethod: (value) => {
|
|
120
113
|
if (isDate(value)) {
|
|
121
114
|
if (config.formatFunction) {
|
|
@@ -133,13 +126,12 @@ const DateProperty = (config = {}, additionalMetadata = {}) => (0, exports.Prope
|
|
|
133
126
|
return value;
|
|
134
127
|
},
|
|
135
128
|
}, config), additionalMetadata);
|
|
136
|
-
exports.DateProperty = DateProperty;
|
|
137
129
|
/**
|
|
138
130
|
* A property for Date AND Times. Supports both strings and Date Objects.
|
|
139
131
|
* @param config - A configuration that enables overriding of date and time formatting
|
|
140
132
|
* @param additionalMetadata
|
|
141
133
|
*/
|
|
142
|
-
const DatetimeProperty = (config = {}, additionalMetadata = {}) =>
|
|
134
|
+
export const DatetimeProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Datetime, merge({
|
|
143
135
|
lazyLoadMethod: (value) => {
|
|
144
136
|
if (isDate(value)) {
|
|
145
137
|
if (config.formatFunction) {
|
|
@@ -157,85 +149,76 @@ const DatetimeProperty = (config = {}, additionalMetadata = {}) => (0, exports.P
|
|
|
157
149
|
return value;
|
|
158
150
|
},
|
|
159
151
|
}, config), additionalMetadata);
|
|
160
|
-
exports.DatetimeProperty = DatetimeProperty;
|
|
161
152
|
/**
|
|
162
153
|
* A property that has an array of sub values.
|
|
163
154
|
* @param config
|
|
164
155
|
* @param additionalMetadata
|
|
165
156
|
*/
|
|
166
|
-
const ArrayProperty = (config = {}, additionalMetadata = {}) =>
|
|
167
|
-
exports.ArrayProperty = ArrayProperty;
|
|
157
|
+
export const ArrayProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Array, Object.assign(Object.assign({ defaultValue: [] }, config), { isArray: true }), additionalMetadata);
|
|
168
158
|
/**
|
|
169
159
|
* A property that is an array, but only of a single value type. This is an {@link ArrayProperty} but with a validator for the type.
|
|
170
160
|
* @param valueType - The type. (Only supports primitive data types, no objects)
|
|
171
161
|
* @param config
|
|
172
162
|
* @param additionalMetadata
|
|
173
163
|
*/
|
|
174
|
-
const SingleTypeArrayProperty = (valueType, config = {}, additionalMetadata = {}) =>
|
|
164
|
+
export const SingleTypeArrayProperty = (valueType, config = {}, additionalMetadata = {}) => Property(PropertyType.Array, Object.assign(Object.assign({ defaultValue: [] }, config), { isArray: true, validators: mergeValidators(config,
|
|
175
165
|
// @ts-ignore
|
|
176
|
-
|
|
177
|
-
exports.SingleTypeArrayProperty = SingleTypeArrayProperty;
|
|
166
|
+
arrayType(valueType)) }), additionalMetadata);
|
|
178
167
|
/**
|
|
179
168
|
* A property that has simple objects. These must be JSON compliant. These are validated.
|
|
180
169
|
* @param config
|
|
181
170
|
* @param additionalMetadata
|
|
182
171
|
*/
|
|
183
|
-
const ObjectProperty = (config = {}, additionalMetadata = {}) =>
|
|
184
|
-
validators:
|
|
172
|
+
export const ObjectProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Object, merge(config, {
|
|
173
|
+
validators: mergeValidators(config, isType('object')),
|
|
185
174
|
}), additionalMetadata);
|
|
186
|
-
exports.ObjectProperty = ObjectProperty;
|
|
187
175
|
/**
|
|
188
176
|
* A simple text property. If it's possible to put ALOT of text in this field consider using the {@link BigTextProperty}
|
|
189
177
|
* @param config - Additional Configurations
|
|
190
178
|
* @param additionalMetadata - Additional Metadata
|
|
191
179
|
*/
|
|
192
|
-
const TextProperty = (config = {}, additionalMetadata = {}) =>
|
|
180
|
+
export const TextProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Text, merge(config, {
|
|
193
181
|
isString: true,
|
|
194
182
|
// @ts-ignore
|
|
195
|
-
validators:
|
|
183
|
+
validators: mergeValidators(config, ...getCommonTextValidators(config)),
|
|
196
184
|
}), additionalMetadata);
|
|
197
|
-
exports.TextProperty = TextProperty;
|
|
198
185
|
/**
|
|
199
186
|
* A property for large blocks of strings.
|
|
200
187
|
* @param config - Additional configurations
|
|
201
188
|
* @param additionalMetadata - Additional metadata
|
|
202
189
|
*/
|
|
203
|
-
const BigTextProperty = (config = {}, additionalMetadata = {}) =>
|
|
190
|
+
export const BigTextProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.BigText, merge(config, {
|
|
204
191
|
isString: true,
|
|
205
|
-
validators:
|
|
192
|
+
validators: mergeValidators(config, ...getCommonTextValidators(config)),
|
|
206
193
|
}), additionalMetadata);
|
|
207
|
-
exports.BigTextProperty = BigTextProperty;
|
|
208
194
|
/**
|
|
209
195
|
* A property that houses integers. No floats allowed.
|
|
210
196
|
* @param config
|
|
211
197
|
* @param additionalMetadata
|
|
212
198
|
*/
|
|
213
|
-
const IntegerProperty = (config = {}, additionalMetadata = {}) =>
|
|
199
|
+
export const IntegerProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Integer, merge(config, {
|
|
214
200
|
isInteger: true,
|
|
215
|
-
validators:
|
|
201
|
+
validators: mergeValidators(config, ...getCommonNumberValidators(config)),
|
|
216
202
|
}), additionalMetadata);
|
|
217
|
-
exports.IntegerProperty = IntegerProperty;
|
|
218
203
|
/**
|
|
219
204
|
* An integer property that represents a year. NOTE: This is exclusively focused on a year in a modern context.
|
|
220
205
|
* Validates from 0 to 3000
|
|
221
206
|
* @param config
|
|
222
207
|
* @param additionalMetadata
|
|
223
208
|
*/
|
|
224
|
-
const YearProperty = (config = {}, additionalMetadata = {}) =>
|
|
209
|
+
export const YearProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Integer, merge(config, {
|
|
225
210
|
isInteger: true,
|
|
226
|
-
validators:
|
|
211
|
+
validators: mergeValidators(config, ...getCommonNumberValidators(config), minNumber(0), maxNumber(MAX_YEAR)),
|
|
227
212
|
}), additionalMetadata);
|
|
228
|
-
exports.YearProperty = YearProperty;
|
|
229
213
|
/**
|
|
230
214
|
* A property for numbers. This could be integers or float values.
|
|
231
215
|
* @param config
|
|
232
216
|
* @param additionalMetadata
|
|
233
217
|
*/
|
|
234
|
-
const NumberProperty = (config = {}, additionalMetadata = {}) =>
|
|
218
|
+
export const NumberProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Number, merge(config, {
|
|
235
219
|
isNumber: true,
|
|
236
|
-
validators:
|
|
220
|
+
validators: mergeValidators(config, ...getCommonNumberValidators(config)),
|
|
237
221
|
}), additionalMetadata);
|
|
238
|
-
exports.NumberProperty = NumberProperty;
|
|
239
222
|
/**
|
|
240
223
|
* A property that has a fixed value that can never be changed. Can be useful for things like embedding the name of a model into JSONified objects.
|
|
241
224
|
* @param valueType - The value type for this property.
|
|
@@ -243,47 +226,43 @@ exports.NumberProperty = NumberProperty;
|
|
|
243
226
|
* @param config
|
|
244
227
|
* @param additionalMetadata
|
|
245
228
|
*/
|
|
246
|
-
const ConstantValueProperty = (valueType, value, config = {}, additionalMetadata = {}) =>
|
|
229
|
+
export const ConstantValueProperty = (valueType, value, config = {}, additionalMetadata = {}) => Property(valueType, merge(config, {
|
|
247
230
|
value,
|
|
248
231
|
}), additionalMetadata);
|
|
249
|
-
exports.ConstantValueProperty = ConstantValueProperty;
|
|
250
232
|
/**
|
|
251
233
|
* A property that encapsulates email addresses. Provides validation for making sure an email is valid.
|
|
252
234
|
* @param config
|
|
253
235
|
* @param additionalMetadata
|
|
254
236
|
*/
|
|
255
|
-
const EmailProperty = (config = {}, additionalMetadata = {}) =>
|
|
256
|
-
type:
|
|
257
|
-
validators:
|
|
237
|
+
export const EmailProperty = (config = {}, additionalMetadata = {}) => TextProperty(merge(config, {
|
|
238
|
+
type: PropertyType.Email,
|
|
239
|
+
validators: mergeValidators(config, meetsRegex(EMAIL_REGEX)),
|
|
258
240
|
}), additionalMetadata);
|
|
259
|
-
exports.EmailProperty = EmailProperty;
|
|
260
241
|
/**
|
|
261
242
|
* A property that has a true or false value.
|
|
262
243
|
* @param config
|
|
263
244
|
* @param additionalMetadata
|
|
264
245
|
*/
|
|
265
|
-
const BooleanProperty = (config = {}, additionalMetadata = {}) =>
|
|
246
|
+
export const BooleanProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.Boolean, merge(config, {
|
|
266
247
|
isBoolean: true,
|
|
267
248
|
}), additionalMetadata);
|
|
268
|
-
exports.BooleanProperty = BooleanProperty;
|
|
269
249
|
/**
|
|
270
250
|
* A property that is used for Primary Keys. If no value is provided a UUID is automatically created.
|
|
271
251
|
* This property has required on it.
|
|
272
252
|
* @param config - Additional configurations. NOTE: required is ALWAYS true.
|
|
273
253
|
* @param additionalMetadata - Any additional metadata.
|
|
274
254
|
*/
|
|
275
|
-
const PrimaryKeyUuidProperty = (config = {}, additionalMetadata = {}) =>
|
|
255
|
+
export const PrimaryKeyUuidProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.UniqueId, merge(config, {
|
|
276
256
|
required: true,
|
|
277
257
|
isString: true,
|
|
278
|
-
validators:
|
|
258
|
+
validators: mergeValidators(config, isValidUuid),
|
|
279
259
|
lazyLoadMethod: (value) => {
|
|
280
260
|
if (!value) {
|
|
281
|
-
return (
|
|
261
|
+
return uuidv4();
|
|
282
262
|
}
|
|
283
263
|
return value;
|
|
284
264
|
},
|
|
285
265
|
}), additionalMetadata);
|
|
286
|
-
exports.PrimaryKeyUuidProperty = PrimaryKeyUuidProperty;
|
|
287
266
|
/**
|
|
288
267
|
* A property that has a uuid.
|
|
289
268
|
* This property has required on it.
|
|
@@ -291,19 +270,18 @@ exports.PrimaryKeyUuidProperty = PrimaryKeyUuidProperty;
|
|
|
291
270
|
* @param config - Additional configurations.
|
|
292
271
|
* @param additionalMetadata - Any additional metadata.
|
|
293
272
|
*/
|
|
294
|
-
const UuidProperty = (config = {}, additionalMetadata = {}) =>
|
|
273
|
+
export const UuidProperty = (config = {}, additionalMetadata = {}) => Property(PropertyType.UniqueId, merge(config, {
|
|
295
274
|
isString: true,
|
|
296
|
-
validators:
|
|
275
|
+
validators: mergeValidators(config, config.required ? isValidUuid : optionalValidator(isValidUuid)),
|
|
297
276
|
lazyLoadMethod: (value) => {
|
|
298
277
|
if (!value) {
|
|
299
278
|
if (config.autoNow) {
|
|
300
|
-
return (
|
|
279
|
+
return uuidv4();
|
|
301
280
|
}
|
|
302
281
|
}
|
|
303
282
|
return value;
|
|
304
283
|
},
|
|
305
284
|
}), additionalMetadata);
|
|
306
|
-
exports.UuidProperty = UuidProperty;
|
|
307
285
|
/**
|
|
308
286
|
* A property that has a reference to another model instance. A "Foreign Key" if you will.
|
|
309
287
|
* For full functionality a {@link ModelInstanceFetcher} must be provided in the config.
|
|
@@ -321,8 +299,7 @@ exports.UuidProperty = UuidProperty;
|
|
|
321
299
|
* @param config
|
|
322
300
|
* @param additionalMetadata
|
|
323
301
|
*/
|
|
324
|
-
const ModelReferenceProperty = (model, config = {}, additionalMetadata = {}) =>
|
|
325
|
-
exports.ModelReferenceProperty = ModelReferenceProperty;
|
|
302
|
+
export const ModelReferenceProperty = (model, config = {}, additionalMetadata = {}) => AdvancedModelReferenceProperty(model, config, additionalMetadata);
|
|
326
303
|
/**
|
|
327
304
|
* The full implementation of a ModelReference, useful for typing certain extended functionalities.
|
|
328
305
|
* For a full description see {@link ModelReferenceProperty}
|
|
@@ -330,7 +307,7 @@ exports.ModelReferenceProperty = ModelReferenceProperty;
|
|
|
330
307
|
* @param config
|
|
331
308
|
* @param additionalMetadata
|
|
332
309
|
*/
|
|
333
|
-
const AdvancedModelReferenceProperty = (model, config = {}, additionalMetadata = {}) => {
|
|
310
|
+
export const AdvancedModelReferenceProperty = (model, config = {}, additionalMetadata = {}) => {
|
|
334
311
|
if (!model) {
|
|
335
312
|
throw new Error('Must include the referenced model');
|
|
336
313
|
}
|
|
@@ -341,8 +318,8 @@ const AdvancedModelReferenceProperty = (model, config = {}, additionalMetadata =
|
|
|
341
318
|
return model;
|
|
342
319
|
};
|
|
343
320
|
// @ts-ignore
|
|
344
|
-
const validator =
|
|
345
|
-
const validators =
|
|
321
|
+
const validator = referenceTypeMatch(model);
|
|
322
|
+
const validators = mergeValidators(config, validator);
|
|
346
323
|
const _getId = (instanceValues) => () => {
|
|
347
324
|
if (!instanceValues) {
|
|
348
325
|
return undefined;
|
|
@@ -362,17 +339,17 @@ const AdvancedModelReferenceProperty = (model, config = {}, additionalMetadata =
|
|
|
362
339
|
return instanceValues[primaryKey];
|
|
363
340
|
};
|
|
364
341
|
const lazyLoadMethodAtomic = (instanceValues) => __awaiter(void 0, void 0, void 0, function* () {
|
|
365
|
-
const valueIsModelInstance =
|
|
342
|
+
const valueIsModelInstance = isModelInstance(instanceValues);
|
|
366
343
|
const _getInstanceReturn = (objToUse) => {
|
|
367
344
|
// We need to determine if the object we just got is an actual model instance to determine if we need to make one.
|
|
368
|
-
const objIsModelInstance =
|
|
345
|
+
const objIsModelInstance = isModelInstance(objToUse);
|
|
369
346
|
const instance = objIsModelInstance
|
|
370
347
|
? objToUse
|
|
371
348
|
: // @ts-ignore
|
|
372
349
|
_getModel().create(objToUse);
|
|
373
350
|
// We are replacing the toObj function, because the reference type in the end should be the primary key when serialized.
|
|
374
|
-
return (
|
|
375
|
-
toObj:
|
|
351
|
+
return merge({}, instance, {
|
|
352
|
+
toObj: memoizeAsync(_getId(instanceValues)),
|
|
376
353
|
});
|
|
377
354
|
};
|
|
378
355
|
// @ts-ignore
|
|
@@ -382,7 +359,7 @@ const AdvancedModelReferenceProperty = (model, config = {}, additionalMetadata =
|
|
|
382
359
|
// TypedJson?
|
|
383
360
|
const theModel = _getModel();
|
|
384
361
|
const primaryKey = theModel.getModelDefinition().primaryKeyName;
|
|
385
|
-
if ((
|
|
362
|
+
if (get(instanceValues, primaryKey)) {
|
|
386
363
|
return _getInstanceReturn(instanceValues);
|
|
387
364
|
}
|
|
388
365
|
if (config === null || config === void 0 ? void 0 : config.fetcher) {
|
|
@@ -396,7 +373,7 @@ const AdvancedModelReferenceProperty = (model, config = {}, additionalMetadata =
|
|
|
396
373
|
}
|
|
397
374
|
return _getId(instanceValues)();
|
|
398
375
|
});
|
|
399
|
-
const p = (
|
|
376
|
+
const p = merge(Property(PropertyType.ModelReference, merge({}, config, {
|
|
400
377
|
validators,
|
|
401
378
|
lazyLoadMethodAtomic,
|
|
402
379
|
}), additionalMetadata), {
|
|
@@ -405,7 +382,6 @@ const AdvancedModelReferenceProperty = (model, config = {}, additionalMetadata =
|
|
|
405
382
|
});
|
|
406
383
|
return p;
|
|
407
384
|
};
|
|
408
|
-
exports.AdvancedModelReferenceProperty = AdvancedModelReferenceProperty;
|
|
409
385
|
/**
|
|
410
386
|
* A property for Denormalizing. This represents a complex value that has been simplified for ease of use.
|
|
411
387
|
* One common use is for creating "Display Values" in a GUI. This process can be extremely expensive, such as having to
|
|
@@ -419,8 +395,8 @@ exports.AdvancedModelReferenceProperty = AdvancedModelReferenceProperty;
|
|
|
419
395
|
* @param config - A Config
|
|
420
396
|
* @param additionalMetadata _ Any additional metadata.
|
|
421
397
|
*/
|
|
422
|
-
const DenormalizedProperty = (propertyType, calculate, config = {}, additionalMetadata = {}) => {
|
|
423
|
-
const property =
|
|
398
|
+
export const DenormalizedProperty = (propertyType, calculate, config = {}, additionalMetadata = {}) => {
|
|
399
|
+
const property = Property(propertyType, merge(config, {
|
|
424
400
|
isDenormalized: true,
|
|
425
401
|
lazyLoadMethodAtomic: (value, modelData, modelInstance) => __awaiter(void 0, void 0, void 0, function* () {
|
|
426
402
|
if (value !== undefined) {
|
|
@@ -429,44 +405,40 @@ const DenormalizedProperty = (propertyType, calculate, config = {}, additionalMe
|
|
|
429
405
|
return calculate(modelData, modelInstance);
|
|
430
406
|
}),
|
|
431
407
|
}), additionalMetadata);
|
|
432
|
-
return (
|
|
408
|
+
return merge(property, {
|
|
433
409
|
calculate,
|
|
434
410
|
});
|
|
435
411
|
};
|
|
436
|
-
exports.DenormalizedProperty = DenormalizedProperty;
|
|
437
412
|
/**
|
|
438
413
|
* A Denormalized Property that is for text.
|
|
439
414
|
* @param calculate - A function that can get a string
|
|
440
415
|
* @param config - Any configs
|
|
441
416
|
* @param additionalMetadata - Optional Metadata
|
|
442
417
|
*/
|
|
443
|
-
const DenormalizedTextProperty = (calculate, config = {}, additionalMetadata = {}) =>
|
|
418
|
+
export const DenormalizedTextProperty = (calculate, config = {}, additionalMetadata = {}) => DenormalizedProperty(PropertyType.Text, calculate, merge(config, {
|
|
444
419
|
isString: true,
|
|
445
|
-
validators:
|
|
420
|
+
validators: mergeValidators(config, ...getCommonTextValidators(config)),
|
|
446
421
|
}), additionalMetadata);
|
|
447
|
-
exports.DenormalizedTextProperty = DenormalizedTextProperty;
|
|
448
422
|
/**
|
|
449
423
|
* A Denormalized Property that is for numbers.
|
|
450
424
|
* @param calculate - A function that can get a string
|
|
451
425
|
* @param config - Any configs
|
|
452
426
|
* @param additionalMetadata - Optional Metadata
|
|
453
427
|
*/
|
|
454
|
-
const DenormalizedNumberProperty = (calculate, config = {}, additionalMetadata = {}) =>
|
|
428
|
+
export const DenormalizedNumberProperty = (calculate, config = {}, additionalMetadata = {}) => DenormalizedProperty(PropertyType.Number, calculate, merge(config, {
|
|
455
429
|
isNumber: true,
|
|
456
|
-
validators:
|
|
430
|
+
validators: mergeValidators(config, ...getCommonNumberValidators(config)),
|
|
457
431
|
}), additionalMetadata);
|
|
458
|
-
exports.DenormalizedNumberProperty = DenormalizedNumberProperty;
|
|
459
432
|
/**
|
|
460
433
|
* A Denormalized Property that is for integers.
|
|
461
434
|
* @param calculate - A function that can get a string
|
|
462
435
|
* @param config - Any configs
|
|
463
436
|
* @param additionalMetadata - Optional Metadata
|
|
464
437
|
*/
|
|
465
|
-
const DenormalizedIntegerProperty = (calculate, config = {}, additionalMetadata = {}) =>
|
|
438
|
+
export const DenormalizedIntegerProperty = (calculate, config = {}, additionalMetadata = {}) => DenormalizedProperty(PropertyType.Integer, calculate, merge(config, {
|
|
466
439
|
isInteger: true,
|
|
467
|
-
validators:
|
|
440
|
+
validators: mergeValidators(config, ...getCommonNumberValidators(config)),
|
|
468
441
|
}), additionalMetadata);
|
|
469
|
-
exports.DenormalizedIntegerProperty = DenormalizedIntegerProperty;
|
|
470
442
|
/**
|
|
471
443
|
* An id that is naturally formed by other properties within a model.
|
|
472
444
|
* Instead of having a "globally unique" id the model is unique because the composition of values of properties.
|
|
@@ -481,16 +453,16 @@ exports.DenormalizedIntegerProperty = DenormalizedIntegerProperty;
|
|
|
481
453
|
* @param config
|
|
482
454
|
* @param additionalMetadata
|
|
483
455
|
*/
|
|
484
|
-
const NaturalIdProperty = (propertyKeys, joiner, config = {}, additionalMetadata = {}) =>
|
|
456
|
+
export const NaturalIdProperty = (propertyKeys, joiner, config = {}, additionalMetadata = {}) => Property(PropertyType.Text, merge(config, {
|
|
485
457
|
isString: true,
|
|
486
|
-
validators:
|
|
458
|
+
validators: mergeValidators(config, ...getCommonTextValidators(config)),
|
|
487
459
|
lazyLoadMethodAtomic: (value, model, modelInstance) => __awaiter(void 0, void 0, void 0, function* () {
|
|
488
460
|
const data = yield propertyKeys.reduce((accP, key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
489
461
|
const acc = yield accP;
|
|
490
|
-
const [head] =
|
|
491
|
-
const value = yield (
|
|
492
|
-
?
|
|
493
|
-
:
|
|
462
|
+
const [head] = createHeadAndTail(key.split('.'), '.');
|
|
463
|
+
const value = yield (isReferencedProperty(modelInstance, head)
|
|
464
|
+
? getValueForReferencedModel(modelInstance, key)
|
|
465
|
+
: getValueForModelInstance(modelInstance, key));
|
|
494
466
|
return acc.concat(value);
|
|
495
467
|
}), Promise.resolve([]));
|
|
496
468
|
// If any of these values are not set, we do not want to have a value at all.
|
|
@@ -500,5 +472,4 @@ const NaturalIdProperty = (propertyKeys, joiner, config = {}, additionalMetadata
|
|
|
500
472
|
return data.join(joiner);
|
|
501
473
|
}),
|
|
502
474
|
}), additionalMetadata);
|
|
503
|
-
exports.NaturalIdProperty = NaturalIdProperty;
|
|
504
475
|
//# sourceMappingURL=properties.js.map
|