akanjs 2.3.5-rc.9 → 2.3.5
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/base/base.ts +6 -2
- package/base/primitiveRegistry.ts +50 -46
- package/base/symbols.ts +16 -11
- package/base/types.ts +12 -0
- package/constant/constantRegistry.ts +10 -9
- package/constant/deserialize.ts +7 -7
- package/constant/fieldInfo.ts +173 -31
- package/constant/getDefault.ts +2 -2
- package/constant/immerify.ts +2 -2
- package/constant/purify.ts +19 -4
- package/constant/serialize.ts +6 -5
- package/constant/types.ts +9 -1
- package/constant/via.ts +312 -57
- package/dictionary/dictInfo.ts +28 -38
- package/dictionary/locale.ts +36 -38
- package/document/by.ts +84 -21
- package/document/database.ts +53 -18
- package/document/databaseRegistry.ts +7 -3
- package/document/filterMeta.ts +26 -14
- package/document/into.ts +71 -76
- package/document/types.ts +4 -2
- package/fetch/fetchType/endpointFetch.type.ts +6 -3
- package/fetch/fetchType/sliceFetch.type.ts +24 -13
- package/package.json +1 -1
- package/service/predefinedAdaptor/compress.adaptor.ts +9 -9
- package/service/predefinedAdaptor/database.adaptor.ts +3 -7
- package/service/serve.ts +17 -52
- package/service/types.ts +61 -21
- package/signal/endpoint.ts +2 -1
- package/signal/endpointInfo.ts +53 -23
- package/signal/internal.ts +2 -1
- package/signal/internalInfo.ts +71 -23
- package/signal/serverSignal.ts +23 -57
- package/signal/slice.ts +35 -35
- package/signal/sliceInfo.ts +63 -47
- package/signal/types.ts +23 -17
- package/store/action.ts +57 -44
- package/store/state.ts +47 -36
- package/store/stateBuilder.ts +3 -3
- package/store/store.ts +61 -15
- package/store/types.ts +16 -6
- package/types/base/base.d.ts +5 -1
- package/types/base/primitiveRegistry.d.ts +43 -38
- package/types/base/symbols.d.ts +5 -0
- package/types/base/types.d.ts +1 -0
- package/types/constant/constantRegistry.d.ts +3 -8
- package/types/constant/deserialize.d.ts +2 -2
- package/types/constant/fieldInfo.d.ts +41 -20
- package/types/constant/immerify.d.ts +2 -2
- package/types/constant/purify.d.ts +3 -2
- package/types/constant/serialize.d.ts +2 -2
- package/types/constant/types.d.ts +6 -1
- package/types/constant/via.d.ts +143 -22
- package/types/dictionary/dictInfo.d.ts +18 -11
- package/types/dictionary/locale.d.ts +23 -16
- package/types/document/by.d.ts +44 -7
- package/types/document/database.d.ts +9 -7
- package/types/document/databaseRegistry.d.ts +5 -4
- package/types/document/filterMeta.d.ts +18 -11
- package/types/document/into.d.ts +46 -19
- package/types/document/types.d.ts +3 -2
- package/types/fetch/fetchType/endpointFetch.type.d.ts +2 -2
- package/types/fetch/fetchType/sliceFetch.type.d.ts +11 -11
- package/types/service/serve.d.ts +4 -5
- package/types/service/serviceModule.d.ts +5 -5
- package/types/service/types.d.ts +23 -5
- package/types/signal/endpoint.d.ts +2 -1
- package/types/signal/endpointInfo.d.ts +40 -15
- package/types/signal/internal.d.ts +2 -1
- package/types/signal/internalInfo.d.ts +46 -12
- package/types/signal/serverSignal.d.ts +15 -12
- package/types/signal/slice.d.ts +8 -6
- package/types/signal/sliceInfo.d.ts +41 -20
- package/types/signal/types.d.ts +23 -17
- package/types/store/action.d.ts +25 -22
- package/types/store/baseSt.d.ts +42 -13
- package/types/store/state.d.ts +23 -26
- package/types/store/stateBuilder.d.ts +2 -2
- package/types/store/store.d.ts +17 -5
- package/types/store/types.d.ts +9 -3
- package/ui/Signal/makeExample.ts +3 -3
package/constant/immerify.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FIELD_META } from "akanjs/base";
|
|
2
2
|
import { immerable } from "immer";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ConstantModelRef } from ".";
|
|
4
4
|
|
|
5
|
-
export const immerify = <T extends object>(modelRef:
|
|
5
|
+
export const immerify = <T extends object>(modelRef: ConstantModelRef, objOrArr: T): T => {
|
|
6
6
|
if (Array.isArray(objOrArr)) return objOrArr.map((val) => immerify(modelRef, val as object)) as T;
|
|
7
7
|
const immeredObj = Object.assign({}, objOrArr, {
|
|
8
8
|
[immerable]: true,
|
package/constant/purify.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Any,
|
|
2
3
|
applyFnToArrayObjects,
|
|
3
4
|
type Cls,
|
|
4
5
|
type Dayjs,
|
|
@@ -13,7 +14,14 @@ import {
|
|
|
13
14
|
} from "akanjs/base";
|
|
14
15
|
import { Logger } from "akanjs/common";
|
|
15
16
|
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
type BaseObject,
|
|
19
|
+
type ConstantModelRef,
|
|
20
|
+
ConstantRegistry,
|
|
21
|
+
type DefaultOf,
|
|
22
|
+
type DefaultOfSchema,
|
|
23
|
+
type FieldProps,
|
|
24
|
+
} from ".";
|
|
17
25
|
|
|
18
26
|
type Purified<O> = O extends BaseObject
|
|
19
27
|
? string
|
|
@@ -44,6 +52,13 @@ export type PurifyFunc<Input, _DefaultInput = DefaultOf<Input>, _PurifiedInput =
|
|
|
44
52
|
isChild?: boolean,
|
|
45
53
|
) => _PurifiedInput | null;
|
|
46
54
|
|
|
55
|
+
export type PurifyFuncV2<
|
|
56
|
+
Input,
|
|
57
|
+
RelationKey extends string = never,
|
|
58
|
+
_DefaultInput = DefaultOfSchema<Input, RelationKey>,
|
|
59
|
+
_PurifiedInput = PurifiedModel<Input>,
|
|
60
|
+
> = (self: _DefaultInput, isChild?: boolean) => _PurifiedInput | null;
|
|
61
|
+
|
|
47
62
|
const getPurifyFn = (modelRef: Cls): ((value: unknown) => unknown) => {
|
|
48
63
|
const [valueRef] = getNonArrayModel(modelRef);
|
|
49
64
|
const purifyFn = PrimitiveRegistry.has(valueRef)
|
|
@@ -75,7 +90,7 @@ const purify = (field: FieldProps, key: string, value: unknown, self: Record<str
|
|
|
75
90
|
if (field.isMap && field.of) {
|
|
76
91
|
const purifyFn = PrimitiveRegistry.has(field.of as Cls)
|
|
77
92
|
? getPurifyFn(field.of as Cls)
|
|
78
|
-
: (value: unknown) => makePurify(field.of as
|
|
93
|
+
: (value: unknown) => makePurify(field.of as ConstantModelRef)(value as object);
|
|
79
94
|
return Object.fromEntries(
|
|
80
95
|
[...(value as Map<string, unknown>).entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, purifyFn)]),
|
|
81
96
|
);
|
|
@@ -87,14 +102,14 @@ const purify = (field: FieldProps, key: string, value: unknown, self: Record<str
|
|
|
87
102
|
throw new Error(`Invalid String Value (Default) in ${key} for value ${value}`);
|
|
88
103
|
if (field.validate && !field.validate(value, self))
|
|
89
104
|
throw new Error(`Invalid Value (Failed to pass validation) / ${value} in ${key}`);
|
|
90
|
-
if (!field.nullable && !value && value !== 0 && value !== false)
|
|
105
|
+
if (!field.nullable && !value && value !== 0 && value !== false && (field.modelRef as Cls) !== Any)
|
|
91
106
|
throw new Error(`Invalid Value (Nullable) in ${key} for value ${value}`);
|
|
92
107
|
|
|
93
108
|
const purifyFn = getPurifyFn(field.modelRef);
|
|
94
109
|
return purifyFn(value);
|
|
95
110
|
};
|
|
96
111
|
|
|
97
|
-
export const makePurify = <I>(modelRef:
|
|
112
|
+
export const makePurify = <I>(modelRef: ConstantModelRef<I>): PurifyFunc<I> => {
|
|
98
113
|
const fn = ((self: Record<string, unknown>, isChild?: boolean): unknown => {
|
|
99
114
|
try {
|
|
100
115
|
if (isChild && !ConstantRegistry.isScalar(modelRef)) {
|
package/constant/serialize.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Any,
|
|
2
3
|
applyFnToArrayObjects,
|
|
3
4
|
type Cls,
|
|
4
5
|
type Dayjs,
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
type PrimitiveScalar,
|
|
10
11
|
} from "akanjs/base";
|
|
11
12
|
|
|
12
|
-
import type { ConstantCls } from ".";
|
|
13
|
+
import type { ConstantCls, ConstantModelRef } from ".";
|
|
13
14
|
|
|
14
15
|
export type Serialized<O> = O extends (infer V)[]
|
|
15
16
|
? Serialized<V>[]
|
|
@@ -29,13 +30,13 @@ const getSerializeFn = (inputRef: Cls, { optional = false }: { optional?: boolea
|
|
|
29
30
|
};
|
|
30
31
|
const serializeInput = <Input = unknown>(
|
|
31
32
|
value: Input | Input[],
|
|
32
|
-
inputRef:
|
|
33
|
+
inputRef: ConstantModelRef<Input> | PrimitiveScalar,
|
|
33
34
|
arrDepth: number,
|
|
34
35
|
serializeType: "input" | "object" = "object",
|
|
35
36
|
{ optional = false }: { optional?: boolean } = {},
|
|
36
37
|
): Input | Input[] => {
|
|
37
38
|
if (arrDepth && Array.isArray(value))
|
|
38
|
-
return value.map((v) => serializeInput(v, inputRef, arrDepth - 1) as Input) as unknown as Input[];
|
|
39
|
+
return value.map((v) => serializeInput(v, inputRef, arrDepth - 1, serializeType) as Input) as unknown as Input[];
|
|
39
40
|
else if ((inputRef as MapConstructor).prototype === Map.prototype) {
|
|
40
41
|
const [valueRef] = getNonArrayModel(inputRef as Cls);
|
|
41
42
|
const serializeFn = getSerializeFn(valueRef, { optional });
|
|
@@ -74,14 +75,14 @@ const getRelationId = (value: unknown): unknown => {
|
|
|
74
75
|
};
|
|
75
76
|
|
|
76
77
|
export const serialize = (
|
|
77
|
-
argRef:
|
|
78
|
+
argRef: ConstantModelRef | PrimitiveScalar,
|
|
78
79
|
arrDepth: number,
|
|
79
80
|
value: unknown,
|
|
80
81
|
serializeType: "input" | "object" = "object",
|
|
81
82
|
{ nullable = false, key }: { nullable?: boolean; key?: string },
|
|
82
83
|
) => {
|
|
83
84
|
if (nullable && (value === null || value === undefined)) return null;
|
|
84
|
-
else if (!nullable && (value === null || value === undefined))
|
|
85
|
+
else if (!nullable && (value === null || value === undefined) && argRef !== Any)
|
|
85
86
|
throw new Error(`Invalid Value (Nullable) in ${argRef} for value ${value}${key ? ` in ${key}` : ""}`);
|
|
86
87
|
return serializeInput(value, argRef, arrDepth, serializeType, { optional: nullable }) as object[];
|
|
87
88
|
};
|
package/constant/types.ts
CHANGED
|
@@ -30,6 +30,12 @@ export type DocumentModel<T> = T extends (infer S)[]
|
|
|
30
30
|
export type FieldState<T> = T extends { id: string } ? T | null : T;
|
|
31
31
|
export type DefaultOf<S> = GetStateObject<{ [K in keyof S]: FieldState<S[K]> }>;
|
|
32
32
|
|
|
33
|
+
export type DefaultOfSchema<Schema, RelationKey = never> = [RelationKey] extends [never]
|
|
34
|
+
? Schema
|
|
35
|
+
: {
|
|
36
|
+
[K in keyof Schema]: Schema[K] | (K extends RelationKey ? null : never);
|
|
37
|
+
};
|
|
38
|
+
|
|
33
39
|
export type GetPlainObject<T, O extends string> = Omit<
|
|
34
40
|
{
|
|
35
41
|
[K in keyof T as T[K] extends (...args: never[]) => unknown
|
|
@@ -96,7 +102,9 @@ export interface TextDoc {
|
|
|
96
102
|
[key: string]: string | TextDoc;
|
|
97
103
|
}
|
|
98
104
|
|
|
99
|
-
export type NonFunctionalKeys<T> =
|
|
105
|
+
export type NonFunctionalKeys<T> = {
|
|
106
|
+
[K in keyof T]: T[K] extends (...args: never[]) => unknown ? never : K;
|
|
107
|
+
}[keyof T];
|
|
100
108
|
|
|
101
109
|
export const unsetDate = dayjs(new Date("0000"));
|
|
102
110
|
export const MAX_INT = 2147483647;
|