@dereekb/model 13.0.7 → 13.2.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/index.cjs.js +745 -421
- package/index.cjs.js.map +1 -1
- package/index.esm.js +730 -402
- package/index.esm.js.map +1 -1
- package/package.json +3 -6
- package/src/lib/data/address/address.d.ts +36 -15
- package/src/lib/data/website/link.d.ts +38 -9
- package/src/lib/data/website/link.file.d.ts +97 -18
- package/src/lib/data/website/link.website.d.ts +254 -3
- package/src/lib/index.d.ts +1 -0
- package/src/lib/service/permission/permission.d.ts +37 -1
- package/src/lib/service/permission/role.d.ts +71 -9
- package/src/lib/service/sync/sync.entity.d.ts +32 -3
- package/src/lib/service/sync/sync.entity.synchronizer.basic.d.ts +15 -0
- package/src/lib/service/sync/sync.entity.synchronizer.d.ts +20 -0
- package/src/lib/transform/index.d.ts +0 -2
- package/src/lib/transform/transform.d.ts +54 -25
- package/src/lib/transform/transform.function.d.ts +22 -2
- package/src/lib/transform/transform.result.d.ts +10 -2
- package/src/lib/type/index.d.ts +2 -0
- package/src/lib/type/model.d.ts +20 -0
- package/src/lib/type/type.d.ts +21 -0
- package/src/lib/validator/date.d.ts +2 -4
- package/src/lib/validator/number.d.ts +2 -4
- package/src/lib/validator/phone.d.ts +6 -14
- package/src/lib/validator/unique.d.ts +11 -4
- package/src/lib/validator/url.d.ts +4 -6
- package/src/lib/transform/type.annotation.d.ts +0 -5
- package/src/lib/transform/type.d.ts +0 -6
|
@@ -1,64 +1,93 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type ClassTransformOptions } from 'class-transformer';
|
|
3
|
-
import { type ValidationError, type ValidatorOptions } from 'class-validator';
|
|
1
|
+
import { type Type, type ArkErrors } from 'arktype';
|
|
4
2
|
export interface TransformAndValidateObjectOutput<T, O> {
|
|
5
3
|
readonly object: T;
|
|
6
4
|
readonly result: O;
|
|
7
5
|
}
|
|
8
6
|
export type TransformAndValidateObjectFunction<T, O, I extends object = object, C = unknown> = (input: I, context?: C) => Promise<TransformAndValidateObjectOutput<T, O>>;
|
|
9
|
-
export type TransformAndValidateObjectHandleValidate<O = unknown> = (validationErrors:
|
|
7
|
+
export type TransformAndValidateObjectHandleValidate<O = unknown> = (validationErrors: ArkErrors) => Promise<O>;
|
|
10
8
|
/**
|
|
11
9
|
* transformAndValidateObject() configuration that also provides error handling.
|
|
12
10
|
*/
|
|
13
11
|
export interface TransformAndValidateObject<T extends object, O, C = unknown> extends TransformAndValidateObjectResultFunctionConfig<T, O, C> {
|
|
14
12
|
readonly handleValidationError: TransformAndValidateObjectHandleValidate<O>;
|
|
15
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a function that validates input against an ArkType schema and then processes it.
|
|
16
|
+
*
|
|
17
|
+
* On validation success, calls the configured handler function. On validation failure, delegates to the error handler.
|
|
18
|
+
*
|
|
19
|
+
* @param config - schema, handler function, and validation error handler
|
|
20
|
+
* @returns a function that validates and processes input objects
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const processUser = transformAndValidateObject({
|
|
25
|
+
* schema: userType,
|
|
26
|
+
* fn: async (user) => ({ id: user.id }),
|
|
27
|
+
* handleValidationError: async (errors) => { throw new Error(errors.summary); }
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const result = await processUser({ id: '123', name: 'John' });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
16
33
|
export declare function transformAndValidateObject<T extends object, O, I extends object = object, C = unknown>(config: TransformAndValidateObject<T, O, C>): TransformAndValidateObjectFunction<T, O, I, C>;
|
|
17
34
|
/**
|
|
18
35
|
* Configuration for the transformAndValidateObject function from transformAndValidateObjectFactory().
|
|
19
36
|
*/
|
|
20
|
-
export interface TransformAndValidateObjectFactoryDefaults<C>
|
|
37
|
+
export interface TransformAndValidateObjectFactoryDefaults<C> {
|
|
21
38
|
readonly handleValidationError: TransformAndValidateObjectHandleValidate<unknown>;
|
|
22
39
|
}
|
|
23
40
|
/**
|
|
24
41
|
* Factory for generating TransformAndValidateObjectFunction functions.
|
|
25
42
|
*/
|
|
26
|
-
export type TransformAndValidateObjectFactory<C = unknown> = <T extends object, O, I extends object = object>(
|
|
43
|
+
export type TransformAndValidateObjectFactory<C = unknown> = <T extends object, O, I extends object = object>(schema: Type<T>, fn: (parsed: T) => Promise<O>, handleValidationError?: TransformAndValidateObjectHandleValidate<O>) => TransformAndValidateObjectFunction<T, O, I, C>;
|
|
27
44
|
/**
|
|
28
|
-
* Creates a
|
|
45
|
+
* Creates a reusable factory for generating transform-and-validate functions with shared defaults.
|
|
29
46
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
47
|
+
* The factory pre-configures error handling so individual function calls
|
|
48
|
+
* only need to specify the schema and handler.
|
|
49
|
+
*
|
|
50
|
+
* @param defaults - default error handler
|
|
51
|
+
* @returns a factory function that creates TransformAndValidateObjectFunction instances
|
|
32
52
|
*/
|
|
33
53
|
export declare function transformAndValidateObjectFactory<C = unknown>(defaults: TransformAndValidateObjectFactoryDefaults<C>): TransformAndValidateObjectFactory<C>;
|
|
34
54
|
export type TransformAndValidateObjectResultFunction<T, O, I extends object = object, C = unknown> = (input: I, context?: C) => Promise<TransformAndValidateObjectResultOutput<T, O>>;
|
|
35
|
-
export
|
|
36
|
-
readonly transform?: ClassTransformOptions;
|
|
37
|
-
readonly validate?: ValidatorOptions;
|
|
38
|
-
}
|
|
39
|
-
export type TransformAndValidateObjectResultContextOptionsFunction<C> = (context?: C) => TransformAndValidateObjectResultTransformContextOptions;
|
|
40
|
-
export type TransformAndValidateObjectResultOutput<T, O> = TransformAndValidateObjectSuccessResultOutput<T, O> | TransformAndValidateObjectErrorResultOutput<T>;
|
|
55
|
+
export type TransformAndValidateObjectResultOutput<T, O> = TransformAndValidateObjectSuccessResultOutput<T, O> | TransformAndValidateObjectErrorResultOutput;
|
|
41
56
|
export interface TransformAndValidateObjectSuccessResultOutput<T, O> {
|
|
42
57
|
readonly success: true;
|
|
43
58
|
readonly object: T;
|
|
44
59
|
readonly result: O;
|
|
45
60
|
}
|
|
46
|
-
export interface TransformAndValidateObjectErrorResultOutput
|
|
61
|
+
export interface TransformAndValidateObjectErrorResultOutput {
|
|
47
62
|
readonly success: false;
|
|
48
|
-
readonly
|
|
49
|
-
readonly validationErrors: ValidationError[];
|
|
63
|
+
readonly validationErrors: ArkErrors;
|
|
50
64
|
}
|
|
51
65
|
export interface TransformAndValidateObjectResultFunctionConfig<T extends object, O, C = unknown, I extends object = object> {
|
|
52
|
-
readonly
|
|
53
|
-
readonly classType: ClassType<T>;
|
|
66
|
+
readonly schema: Type<T>;
|
|
54
67
|
readonly fn: (parsed: T) => Promise<O>;
|
|
55
|
-
readonly optionsForContext?: TransformAndValidateObjectResultContextOptionsFunction<C>;
|
|
56
68
|
}
|
|
57
69
|
/**
|
|
58
|
-
*
|
|
70
|
+
* Creates a function that validates input against an ArkType schema and returns a discriminated result.
|
|
71
|
+
*
|
|
72
|
+
* Returns `{ success: true, object, result }` on valid input, or `{ success: false, validationErrors }` on failure.
|
|
73
|
+
* The caller is responsible for handling the error case.
|
|
74
|
+
*
|
|
75
|
+
* @param config - schema and handler function
|
|
76
|
+
* @returns a function that returns a success/error discriminated result
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const validateUser = transformAndValidateObjectResult({
|
|
81
|
+
* schema: userType,
|
|
82
|
+
* fn: async (user) => ({ saved: true })
|
|
83
|
+
* });
|
|
59
84
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
85
|
+
* const result = await validateUser({ name: 'John' });
|
|
86
|
+
* if (result.success) {
|
|
87
|
+
* console.log(result.result);
|
|
88
|
+
* } else {
|
|
89
|
+
* console.log(result.validationErrors.summary);
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
63
92
|
*/
|
|
64
93
|
export declare function transformAndValidateObjectResult<T extends object, O, I extends object = object, C = unknown>(config: TransformAndValidateObjectResultFunctionConfig<T, O, C, I>): TransformAndValidateObjectResultFunction<T, O, I, C>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Type } from 'arktype';
|
|
2
2
|
import { type TransformAndValidateObjectFactory, type TransformAndValidateObjectFactoryDefaults, type TransformAndValidateObjectHandleValidate, type TransformAndValidateObjectOutput } from './transform';
|
|
3
3
|
import { type TransformAndValidateResultFunction } from './transform.result';
|
|
4
4
|
/**
|
|
@@ -8,8 +8,28 @@ export type TransformAndValidateFunctionResult<T extends object, O> = O & {
|
|
|
8
8
|
params: T;
|
|
9
9
|
};
|
|
10
10
|
export type TransformAndValidateFunctionResultFunction<T extends object, O, I extends object = object, C = unknown> = TransformAndValidateResultFunction<TransformAndValidateFunctionResult<T, O>, I, C>;
|
|
11
|
-
export type TransformAndValidateFunctionResultFactory<C = unknown> = <T extends object, O, I extends object = object>(
|
|
11
|
+
export type TransformAndValidateFunctionResultFactory<C = unknown> = <T extends object, O, I extends object = object>(schema: Type<T>, fn: (parsed: T) => Promise<O>, handleValidationError?: TransformAndValidateObjectHandleValidate<O>) => TransformAndValidateFunctionResultFunction<T, O, I, C>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a factory for transform-and-validate functions that return the result with the parsed object attached as `params`.
|
|
14
|
+
*
|
|
15
|
+
* @param defaults - shared error handler defaults
|
|
16
|
+
* @returns a factory that produces functions returning {@link TransformAndValidateFunctionResult}
|
|
17
|
+
*/
|
|
12
18
|
export declare function transformAndValidateFunctionResultFactory<C = unknown>(defaults: TransformAndValidateObjectFactoryDefaults<C>): TransformAndValidateFunctionResultFactory<C>;
|
|
19
|
+
/**
|
|
20
|
+
* Wraps an existing {@link TransformAndValidateObjectFactory} to produce functions that attach the parsed object
|
|
21
|
+
* as `params` on the result.
|
|
22
|
+
*
|
|
23
|
+
* @param transformAndValidateObjectFactory - the base factory to wrap
|
|
24
|
+
* @returns a factory that produces functions returning results with `params` attached
|
|
25
|
+
*/
|
|
13
26
|
export declare function toTransformAndValidateFunctionResultFactory<C = unknown>(transformAndValidateObjectFactory: TransformAndValidateObjectFactory<C>): TransformAndValidateFunctionResultFactory<C>;
|
|
27
|
+
/**
|
|
28
|
+
* Transforms a {@link TransformAndValidateObjectOutput} into a {@link TransformAndValidateFunctionResult}
|
|
29
|
+
* by attaching the parsed object as `params` on the result.
|
|
30
|
+
*
|
|
31
|
+
* @param objectOutput - the transform-and-validate output (sync or async)
|
|
32
|
+
* @returns the result with `params` attached
|
|
33
|
+
*/
|
|
14
34
|
export declare function toTransformAndValidateFunctionResult<T extends object, O>(objectOutput: Promise<TransformAndValidateObjectOutput<T, O>>): Promise<TransformAndValidateFunctionResult<T, O>>;
|
|
15
35
|
export declare function toTransformAndValidateFunctionResult<T extends object, O>(objectOutput: TransformAndValidateObjectOutput<T, O>): TransformAndValidateFunctionResult<T, O>;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Type } from 'arktype';
|
|
2
2
|
import { type TransformAndValidateObjectFactoryDefaults, type TransformAndValidateObjectHandleValidate } from './transform';
|
|
3
3
|
/**
|
|
4
4
|
* A TransformAndValidate function that returns only the result.
|
|
5
5
|
*/
|
|
6
6
|
export type TransformAndValidateResultFunction<O, I extends object = object, C = unknown> = (input: I, context?: C) => Promise<O>;
|
|
7
|
-
export type TransformAndValidateResultFactory<C = unknown> = <T extends object, O, I extends object = object>(
|
|
7
|
+
export type TransformAndValidateResultFactory<C = unknown> = <T extends object, O, I extends object = object>(schema: Type<T>, fn: (parsed: T) => Promise<O>, handleValidationError?: TransformAndValidateObjectHandleValidate<O>) => TransformAndValidateResultFunction<O, I, C>;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a factory for transform-and-validate functions that return only the result (discarding the parsed object).
|
|
10
|
+
*
|
|
11
|
+
* Useful when you only need the processed output and don't need access to the validated input.
|
|
12
|
+
*
|
|
13
|
+
* @param defaults - shared error handler defaults
|
|
14
|
+
* @returns a factory that produces functions returning only the handler's result
|
|
15
|
+
*/
|
|
8
16
|
export declare function transformAndValidateResultFactory<C = unknown>(defaults: TransformAndValidateObjectFactoryDefaults<C>): TransformAndValidateResultFactory<C>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArkType schema for a model key (non-empty string).
|
|
3
|
+
*/
|
|
4
|
+
export declare const modelKeyType: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
5
|
+
/**
|
|
6
|
+
* ArkType schema for a model id (non-empty string).
|
|
7
|
+
*/
|
|
8
|
+
export declare const modelIdType: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
9
|
+
/**
|
|
10
|
+
* ArkType schema for target model params with a required `key` field.
|
|
11
|
+
*/
|
|
12
|
+
export declare const targetModelParamsType: import("arktype/internal/variants/object.ts").ObjectType<{
|
|
13
|
+
key: string;
|
|
14
|
+
}, {}>;
|
|
15
|
+
/**
|
|
16
|
+
* ArkType schema for target model id params with a required `id` field.
|
|
17
|
+
*/
|
|
18
|
+
export declare const targetModelIdParamsType: import("arktype/internal/variants/object.ts").ObjectType<{
|
|
19
|
+
id: string;
|
|
20
|
+
}, {}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type type, type Type } from 'arktype';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an ArkType schema that accepts the given ArkType definition OR null/undefined.
|
|
4
|
+
* Used for fields where null acts as a "clear/reset" signal for the model.
|
|
5
|
+
*
|
|
6
|
+
* The dbx-components library uses null in API calls to signal that something can be deleted entirely,
|
|
7
|
+
* whereas undefined is simply treated as an ignore.
|
|
8
|
+
*
|
|
9
|
+
* Accepts either a string definition or a Type instance.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const schema = type({
|
|
14
|
+
* "sdat?": clearable("string.date.parse"), // string definition
|
|
15
|
+
* "phone?": clearable(e164PhoneNumberType), // Type instance
|
|
16
|
+
* "items?": clearable(mySchemaType.array()), // .array() result
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function clearable<const def extends string>(definition: def): Type<type.infer<def> | null | undefined>;
|
|
21
|
+
export declare function clearable<T>(definition: Type<T>): Type<T | null | undefined>;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { type ObjectWithConstructor } from '@dereekb/util';
|
|
2
|
-
import { type ValidationOptions } from 'class-validator';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* ArkType schema for a valid ISO 8601 day string (e.g., "2024-01-15").
|
|
5
3
|
*/
|
|
6
|
-
export declare
|
|
4
|
+
export declare const iso8601DayStringType: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { type ObjectWithConstructor } from '@dereekb/util';
|
|
2
|
-
import { type ValidationOptions } from 'class-validator';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* ArkType schema for a valid minute of the day (0-1439).
|
|
5
3
|
*/
|
|
6
|
-
export declare
|
|
4
|
+
export declare const minuteOfDayType: import("arktype/internal/variants/number.ts").NumberType<number, {}>;
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import { type ObjectWithConstructor } from '@dereekb/util';
|
|
2
|
-
import { type ValidationOptions } from 'class-validator';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* ArkType schema for a valid E.164 phone number without an extension.
|
|
5
3
|
*/
|
|
6
|
-
export declare
|
|
4
|
+
export declare const e164PhoneNumberType: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @param validationOptions
|
|
11
|
-
* @returns
|
|
6
|
+
* ArkType schema for a valid E.164 phone number, optionally with an extension.
|
|
12
7
|
*/
|
|
13
|
-
export declare
|
|
8
|
+
export declare const e164PhoneNumberWithOptionalExtensionType: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
14
9
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @param validationOptions
|
|
18
|
-
* @returns
|
|
10
|
+
* ArkType schema for a valid E.164 phone number that includes an extension.
|
|
19
11
|
*/
|
|
20
|
-
export declare
|
|
12
|
+
export declare const e164PhoneNumberWithExtensionType: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type ValidationOptions } from 'class-validator';
|
|
1
|
+
import { type ReadKeyFunction } from '@dereekb/util';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* Creates an ArkType schema that validates an array has no duplicate keys.
|
|
4
|
+
*
|
|
5
|
+
* @param readKey - function that extracts the key from each array element
|
|
6
|
+
* @returns an ArkType schema that narrows `T[]` to ensure uniqueness
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const uniqueItemsType = uniqueKeyedType((item: Item) => item.id);
|
|
11
|
+
* ```
|
|
5
12
|
*/
|
|
6
|
-
export declare function
|
|
13
|
+
export declare function uniqueKeyedType<T>(readKey: ReadKeyFunction<T>): import("arktype/internal/variants/array.ts").ArrayType<unknown[], {}>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { type ObjectWithConstructor } from '@dereekb/util';
|
|
2
|
-
import { type ValidationOptions } from 'class-validator';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* ArkType schema for a valid website URL (with or without protocol prefix).
|
|
5
3
|
*/
|
|
6
|
-
export declare
|
|
4
|
+
export declare const websiteUrlType: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
6
|
+
* ArkType schema for a valid website URL that starts with `http://` or `https://`.
|
|
9
7
|
*/
|
|
10
|
-
export declare
|
|
8
|
+
export declare const websiteUrlWithPrefixType: import("arktype/internal/variants/string.ts").StringType<string, {}>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type MapStringFunction } from '@dereekb/util';
|
|
2
|
-
export declare function TransformCommaSeparatedValueToArray<T>(mapFn: MapStringFunction<T>): PropertyDecorator;
|
|
3
|
-
export declare const TransformCommaSeparatedStringValueToArray: () => PropertyDecorator;
|
|
4
|
-
export declare const TransformCommaSeparatedNumberValueToArray: () => PropertyDecorator;
|
|
5
|
-
export declare const TransformStringValueToBoolean: () => PropertyDecorator;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type MapStringFunction, type Maybe } from '@dereekb/util';
|
|
2
|
-
import { type TransformFnParams } from 'class-transformer';
|
|
3
|
-
export declare function transformStringToBoolean(defaultValue?: boolean | undefined): (params: TransformFnParams) => Maybe<boolean>;
|
|
4
|
-
export declare function transformCommaSeparatedValueToArray<T>(mapFn: MapStringFunction<T>): (params: TransformFnParams) => Maybe<T[]>;
|
|
5
|
-
export declare const transformCommaSeparatedNumberValueToArray: (params: TransformFnParams) => Maybe<number[]>;
|
|
6
|
-
export declare const transformCommaSeparatedStringValueToArray: (params: TransformFnParams) => Maybe<string[]>;
|