akanjs 2.3.5-rc.8 → 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/signal/types.ts
CHANGED
|
@@ -6,12 +6,15 @@ import type { SliceCls } from "./slice";
|
|
|
6
6
|
|
|
7
7
|
export type CnstOf<S extends ServiceModel> = NonNullable<S["cnst"]>;
|
|
8
8
|
export type DbOf<S extends ServiceModel> = NonNullable<S["db"]>;
|
|
9
|
+
export type SrvOf<S extends ServiceModel> = S["srv"];
|
|
10
|
+
export type SrvRefName<S extends ServiceModel> = SrvOf<S>["refName"];
|
|
11
|
+
export type SrvMap<S extends ServiceModel> = S["srvMap"];
|
|
9
12
|
|
|
10
13
|
export type CnstRefName<S extends ServiceModel> = CnstOf<S>["refName"];
|
|
11
14
|
export type CnstInput<S extends ServiceModel> = CnstOf<S>["_Input"];
|
|
12
|
-
export type CnstFull<S extends ServiceModel> = CnstOf<S>["_Full"];
|
|
13
|
-
export type CnstLight<S extends ServiceModel> = CnstOf<S>["_Light"];
|
|
14
|
-
export type CnstInsight<S extends ServiceModel> = CnstOf<S>["_Insight"];
|
|
15
|
+
export type CnstFull<S extends ServiceModel> = UnCls<CnstOf<S>["full"]> & CnstOf<S>["_Full"];
|
|
16
|
+
export type CnstLight<S extends ServiceModel> = UnCls<CnstOf<S>["light"]> & CnstOf<S>["_Light"];
|
|
17
|
+
export type CnstInsight<S extends ServiceModel> = UnCls<CnstOf<S>["insight"]> & CnstOf<S>["_Insight"];
|
|
15
18
|
export type CnstDefault<S extends ServiceModel> = CnstOf<S>["_Default"];
|
|
16
19
|
export type CnstDefaultInput<S extends ServiceModel> = CnstOf<S>["_DefaultInput"];
|
|
17
20
|
export type CnstDefaultState<S extends ServiceModel> = CnstOf<S>["_DefaultState"];
|
|
@@ -21,23 +24,26 @@ export type CnstPurifiedInput<S extends ServiceModel> = CnstOf<S>["_PurifiedInpu
|
|
|
21
24
|
export type CnstCapitalizedRefName<S extends ServiceModel> = CnstOf<S>["_CapitalizedRefName"];
|
|
22
25
|
|
|
23
26
|
export type DbFilter<S extends ServiceModel> = DbOf<S>["_Filter"];
|
|
27
|
+
export type DbDoc<S extends ServiceModel> = DbOf<S>["_Doc"];
|
|
28
|
+
export type DbQuery<S extends ServiceModel> = DbOf<S>["_Query"];
|
|
24
29
|
export type DbSort<S extends ServiceModel> = DbOf<S>["_Sort"];
|
|
25
30
|
|
|
26
31
|
export type SlceSrv<S extends SliceCls> = S["srv"];
|
|
27
|
-
export type SlceCnstRefName<S extends SliceCls> = S
|
|
28
|
-
export type SlceCnstInput<S extends SliceCls> = S
|
|
29
|
-
export type SlceCnstFull<S extends SliceCls> = S
|
|
30
|
-
export type SlceCnstLight<S extends SliceCls> = S
|
|
31
|
-
export type SlceCnstInsight<S extends SliceCls> = S
|
|
32
|
-
export type SlceCnstDefault<S extends SliceCls> = S
|
|
33
|
-
export type SlceCnstDefaultInput<S extends SliceCls> = S
|
|
34
|
-
export type SlceCnstDefaultState<S extends SliceCls> = S
|
|
35
|
-
export type SlceCnstPurifiedInput<S extends SliceCls> = S
|
|
36
|
-
export type SlceCnstCapitalizedRefName<S extends SliceCls> = S
|
|
37
|
-
export type SlceCnstStateLight<S extends SliceCls> = S
|
|
38
|
-
export type SlceCnstStateInsight<S extends SliceCls> = S
|
|
39
|
-
export type SlceDbFilter<S extends SliceCls> = S
|
|
40
|
-
export type
|
|
32
|
+
export type SlceCnstRefName<S extends SliceCls> = CnstRefName<SlceSrv<S>>;
|
|
33
|
+
export type SlceCnstInput<S extends SliceCls> = CnstInput<SlceSrv<S>>;
|
|
34
|
+
export type SlceCnstFull<S extends SliceCls> = CnstFull<SlceSrv<S>>;
|
|
35
|
+
export type SlceCnstLight<S extends SliceCls> = CnstLight<SlceSrv<S>>;
|
|
36
|
+
export type SlceCnstInsight<S extends SliceCls> = CnstInsight<SlceSrv<S>>;
|
|
37
|
+
export type SlceCnstDefault<S extends SliceCls> = CnstDefault<SlceSrv<S>>;
|
|
38
|
+
export type SlceCnstDefaultInput<S extends SliceCls> = CnstDefaultInput<SlceSrv<S>>;
|
|
39
|
+
export type SlceCnstDefaultState<S extends SliceCls> = CnstDefaultState<SlceSrv<S>>;
|
|
40
|
+
export type SlceCnstPurifiedInput<S extends SliceCls> = CnstPurifiedInput<SlceSrv<S>>;
|
|
41
|
+
export type SlceCnstCapitalizedRefName<S extends SliceCls> = CnstCapitalizedRefName<SlceSrv<S>>;
|
|
42
|
+
export type SlceCnstStateLight<S extends SliceCls> = CnstStateLight<SlceSrv<S>>;
|
|
43
|
+
export type SlceCnstStateInsight<S extends SliceCls> = CnstStateInsight<SlceSrv<S>>;
|
|
44
|
+
export type SlceDbFilter<S extends SliceCls> = DbFilter<SlceSrv<S>>;
|
|
45
|
+
export type SlceDbQuery<S extends SliceCls> = DbQuery<SlceSrv<S>>;
|
|
46
|
+
export type SlceDbSort<S extends SliceCls> = DbSort<SlceSrv<S>>;
|
|
41
47
|
|
|
42
48
|
export const argTypes = ["body", "param", "search", "upload", "msg", "room"] as const;
|
|
43
49
|
export type ArgType = (typeof argTypes)[number];
|
package/store/action.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataList, type Dayjs, FIELD_META, type GetStateObject
|
|
1
|
+
import { DataList, type Dayjs, FIELD_META, type GetStateObject } from "akanjs/base";
|
|
2
2
|
import {
|
|
3
3
|
capitalize,
|
|
4
4
|
deepObjectify,
|
|
@@ -20,9 +20,21 @@ import {
|
|
|
20
20
|
} from "akanjs/constant";
|
|
21
21
|
import type { BaseFilterSortKey, ExtractSort, FilterInstance } from "akanjs/document";
|
|
22
22
|
import type { FetchInitForm, FetchProxy } from "akanjs/fetch";
|
|
23
|
-
import type {
|
|
23
|
+
import type {
|
|
24
|
+
SerializedSlice,
|
|
25
|
+
SlceCnstCapitalizedRefName,
|
|
26
|
+
SlceCnstDefault,
|
|
27
|
+
SlceCnstDefaultInput,
|
|
28
|
+
SlceCnstFull,
|
|
29
|
+
SlceCnstInput,
|
|
30
|
+
SlceCnstLight,
|
|
31
|
+
SlceCnstRefName,
|
|
32
|
+
SlceDbFilter,
|
|
33
|
+
SlceDbSort,
|
|
34
|
+
SliceCls,
|
|
35
|
+
} from "akanjs/signal";
|
|
24
36
|
import type { SliceStateKey } from "./state";
|
|
25
|
-
import type { SetGet } from "./types";
|
|
37
|
+
import type { SetGet, StoreSliceArgs, StoreSliceMap, StoreSliceSuffixCap } from "./types";
|
|
26
38
|
|
|
27
39
|
type SliceActionKey =
|
|
28
40
|
| "initModel"
|
|
@@ -33,6 +45,16 @@ type SliceActionKey =
|
|
|
33
45
|
| "setLimitOfModel"
|
|
34
46
|
| "setQueryArgsOfModel"
|
|
35
47
|
| "setSortOfModel";
|
|
48
|
+
type _SliceMap<S extends SliceCls> = StoreSliceMap<S>;
|
|
49
|
+
type _ActionRefName<S extends SliceCls> = SlceCnstRefName<S>;
|
|
50
|
+
type _ActionCap<S extends SliceCls> = SlceCnstCapitalizedRefName<S>;
|
|
51
|
+
type _ActionInput<S extends SliceCls> = SlceCnstInput<S>;
|
|
52
|
+
type _ActionFull<S extends SliceCls> = SlceCnstFull<S>;
|
|
53
|
+
type _ActionLight<S extends SliceCls> = SlceCnstLight<S>;
|
|
54
|
+
type _ActionDefault<S extends SliceCls> = SlceCnstDefault<S>;
|
|
55
|
+
type _ActionDefaultInput<S extends SliceCls> = SlceCnstDefaultInput<S>;
|
|
56
|
+
type _ActionFilter<S extends SliceCls> = SlceDbFilter<S>;
|
|
57
|
+
type _ActionSort<S extends SliceCls> = SlceDbSort<S>;
|
|
36
58
|
|
|
37
59
|
const isNullableSliceArg = (arg: SerializedSlice["args"][number]) => arg.nullable ?? arg.type === "search";
|
|
38
60
|
|
|
@@ -207,59 +229,45 @@ type FormSetter<
|
|
|
207
229
|
[K in `writeOn${_CapitalizedRefName}`]: (path: string | (string | number)[], value: any) => void;
|
|
208
230
|
};
|
|
209
231
|
|
|
210
|
-
type _SliceActionMap<SlceCls extends SliceCls> = SlceCls[typeof SLICE_META];
|
|
211
|
-
type _ActSuffixCap<SlceCls extends SliceCls, Suffix extends keyof _SliceActionMap<SlceCls>> = Capitalize<
|
|
212
|
-
Suffix & string
|
|
213
|
-
>;
|
|
214
|
-
type _ActArgs<SlceCls extends SliceCls, Suffix extends keyof _SliceActionMap<SlceCls>> = SliceInfoArgs<
|
|
215
|
-
_SliceActionMap<SlceCls>[Suffix]
|
|
216
|
-
>;
|
|
217
|
-
|
|
218
232
|
type DefaultSliceActionFields<
|
|
219
233
|
SlceCls extends SliceCls,
|
|
220
234
|
_CapRef extends string,
|
|
221
235
|
_FetchInitFormWithFetchPolicy,
|
|
222
236
|
_Light,
|
|
223
237
|
_Sort,
|
|
238
|
+
_Suffixes extends keyof _SliceMap<SlceCls> = keyof _SliceMap<SlceCls>,
|
|
224
239
|
> = {
|
|
225
|
-
[Suffix in
|
|
226
|
-
...args: [...args:
|
|
240
|
+
[Suffix in _Suffixes as `init${_CapRef}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: (
|
|
241
|
+
...args: [...args: StoreSliceArgs<SlceCls, Suffix>, initForm?: _FetchInitFormWithFetchPolicy]
|
|
227
242
|
) => Promise<void>;
|
|
228
243
|
} & {
|
|
229
|
-
[Suffix in
|
|
230
|
-
initForm?: _FetchInitFormWithFetchPolicy & { queryArgs?:
|
|
244
|
+
[Suffix in _Suffixes as `refresh${_CapRef}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: (
|
|
245
|
+
initForm?: _FetchInitFormWithFetchPolicy & { queryArgs?: StoreSliceArgs<SlceCls, Suffix> },
|
|
231
246
|
) => Promise<void>;
|
|
232
247
|
} & {
|
|
233
|
-
[Suffix in
|
|
248
|
+
[Suffix in _Suffixes as `select${_CapRef}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: (
|
|
234
249
|
model: _Light | _Light[],
|
|
235
250
|
options?: { refresh?: boolean; remove?: boolean },
|
|
236
251
|
) => void;
|
|
237
252
|
} & {
|
|
238
|
-
[Suffix in
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
[Suffix in keyof _SliceActionMap<SlceCls> as `addPageOf${_CapRef}${_ActSuffixCap<SlceCls, Suffix>}`]: (
|
|
244
|
-
page: number,
|
|
245
|
-
options?: FetchPolicy,
|
|
246
|
-
) => Promise<void>;
|
|
247
|
-
} & {
|
|
248
|
-
[Suffix in keyof _SliceActionMap<SlceCls> as `setLimitOf${_CapRef}${_ActSuffixCap<SlceCls, Suffix>}`]: (
|
|
249
|
-
limit: number,
|
|
253
|
+
[Suffix in _Suffixes as
|
|
254
|
+
| `setPageOf${_CapRef}${StoreSliceSuffixCap<SlceCls, Suffix>}`
|
|
255
|
+
| `addPageOf${_CapRef}${StoreSliceSuffixCap<SlceCls, Suffix>}`
|
|
256
|
+
| `setLimitOf${_CapRef}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: (
|
|
257
|
+
value: number,
|
|
250
258
|
options?: FetchPolicy,
|
|
251
259
|
) => Promise<void>;
|
|
252
260
|
} & {
|
|
253
|
-
[Suffix in
|
|
261
|
+
[Suffix in _Suffixes as `setQueryArgsOf${_CapRef}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: (
|
|
254
262
|
...args:
|
|
255
|
-
| [...args:
|
|
263
|
+
| [...args: StoreSliceArgs<SlceCls, Suffix>, options?: FetchPolicy]
|
|
256
264
|
| [
|
|
257
|
-
setQueryArgs: (...prevQueryArgs:
|
|
265
|
+
setQueryArgs: (...prevQueryArgs: StoreSliceArgs<SlceCls, Suffix>) => StoreSliceArgs<SlceCls, Suffix>,
|
|
258
266
|
options?: FetchPolicy,
|
|
259
267
|
]
|
|
260
268
|
) => Promise<void>;
|
|
261
269
|
} & {
|
|
262
|
-
[Suffix in
|
|
270
|
+
[Suffix in _Suffixes as `setSortOf${_CapRef}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: (
|
|
263
271
|
sort: _Sort,
|
|
264
272
|
options?: FetchPolicy,
|
|
265
273
|
) => Promise<void>;
|
|
@@ -267,15 +275,15 @@ type DefaultSliceActionFields<
|
|
|
267
275
|
|
|
268
276
|
export type DefaultAction<
|
|
269
277
|
SlceCls extends SliceCls,
|
|
270
|
-
_RefName extends string = SlceCls
|
|
271
|
-
_Input = SlceCls
|
|
272
|
-
_Full extends { id: string } = SlceCls
|
|
273
|
-
_Light = SlceCls
|
|
274
|
-
_Filter extends FilterInstance = SlceCls
|
|
275
|
-
_CapitalizedRefName extends string =
|
|
276
|
-
_Default = SlceCls
|
|
277
|
-
_DefaultInput = SlceCls
|
|
278
|
-
_Sort = SlceCls
|
|
278
|
+
_RefName extends string = _ActionRefName<SlceCls>,
|
|
279
|
+
_Input = _ActionInput<SlceCls>,
|
|
280
|
+
_Full extends { id: string } = _ActionFull<SlceCls>,
|
|
281
|
+
_Light = _ActionLight<SlceCls>,
|
|
282
|
+
_Filter extends FilterInstance = _ActionFilter<SlceCls>,
|
|
283
|
+
_CapitalizedRefName extends string = _ActionCap<SlceCls>,
|
|
284
|
+
_Default = _ActionDefault<SlceCls>,
|
|
285
|
+
_DefaultInput = _ActionDefaultInput<SlceCls>,
|
|
286
|
+
_Sort = _ActionSort<SlceCls>,
|
|
279
287
|
_CreateOption = CreateOption<_Full>,
|
|
280
288
|
_FetchInitFormWithFetchPolicy = FetchInitForm<_Input, _Filter, _DefaultInput, _Sort> & FetchPolicy,
|
|
281
289
|
> = BaseAction<_RefName, _Input, _Full, _Light, _CapitalizedRefName, _CreateOption> &
|
|
@@ -854,10 +862,15 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
854
862
|
const singleSliceAction = {
|
|
855
863
|
[namesOfSlice.initModel]: async function (
|
|
856
864
|
this: SetGet,
|
|
857
|
-
...args: [...args: any[], initForm: FetchInitForm<Input, Filter> & FetchPolicy]
|
|
865
|
+
...args: [...args: any[], initForm: FetchInitForm<Input, Filter, DefaultOf<Input>, Sort> & FetchPolicy]
|
|
858
866
|
) {
|
|
859
867
|
const initArgLength = Math.min(args.length, slice.args.length);
|
|
860
|
-
const initForm = { invalidate: false, ...(args[slice.args.length] ?? {}) } as FetchInitForm<
|
|
868
|
+
const initForm = { invalidate: false, ...(args[slice.args.length] ?? {}) } as FetchInitForm<
|
|
869
|
+
Input,
|
|
870
|
+
Filter,
|
|
871
|
+
DefaultOf<Input>,
|
|
872
|
+
Sort
|
|
873
|
+
> &
|
|
861
874
|
FetchPolicy;
|
|
862
875
|
const queryArgs = new Array(initArgLength).fill(null).map((_, i) => args[i] as object);
|
|
863
876
|
const defaultModel = new cnst.full().set(initForm.default ?? {}) as unknown as Full;
|
|
@@ -869,7 +882,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
869
882
|
},
|
|
870
883
|
[namesOfSlice.refreshModel]: async function (
|
|
871
884
|
this: SetGet,
|
|
872
|
-
initForm: FetchInitForm<Input, Filter> & FetchPolicy & { queryArgs?: any[] } = {},
|
|
885
|
+
initForm: FetchInitForm<Input, Filter, DefaultOf<Input>, Sort> & FetchPolicy & { queryArgs?: any[] } = {},
|
|
873
886
|
) {
|
|
874
887
|
const args = initForm.queryArgs ?? [];
|
|
875
888
|
const refreshArgLength = Math.min(args.length, slice.args.length);
|
package/store/state.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { DataList
|
|
1
|
+
import { DataList } from "akanjs/base";
|
|
2
2
|
import { capitalize } from "akanjs/common";
|
|
3
3
|
import { ConstantRegistry, type DefaultOf } from "akanjs/constant";
|
|
4
4
|
import type { ExtractSort, FilterInstance } from "akanjs/document";
|
|
5
|
-
import type {
|
|
6
|
-
|
|
5
|
+
import type {
|
|
6
|
+
SerializedSlice,
|
|
7
|
+
SlceCnstCapitalizedRefName,
|
|
8
|
+
SlceCnstDefault,
|
|
9
|
+
SlceCnstFull,
|
|
10
|
+
SlceCnstInsight,
|
|
11
|
+
SlceCnstLight,
|
|
12
|
+
SlceCnstRefName,
|
|
13
|
+
SlceDbFilter,
|
|
14
|
+
SlceDbSort,
|
|
15
|
+
SliceCls,
|
|
16
|
+
} from "akanjs/signal";
|
|
17
|
+
import type { StoreSliceArgs, StoreSliceMap, StoreSliceSuffixCap, Submit } from "./types";
|
|
7
18
|
|
|
8
19
|
export type SliceStateKey =
|
|
9
20
|
| "defaultModel"
|
|
@@ -18,6 +29,16 @@ export type SliceStateKey =
|
|
|
18
29
|
| "limitOfModel"
|
|
19
30
|
| "queryArgsOfModel"
|
|
20
31
|
| "sortOfModel";
|
|
32
|
+
type _SliceMap<S extends SliceCls> = StoreSliceMap<S>;
|
|
33
|
+
type _StateRefName<S extends SliceCls> = SlceCnstRefName<S>;
|
|
34
|
+
type _StateCap<S extends SliceCls> = SlceCnstCapitalizedRefName<S>;
|
|
35
|
+
type _StateFull<S extends SliceCls> = SlceCnstFull<S>;
|
|
36
|
+
type _StateLight<S extends SliceCls> = SlceCnstLight<S>;
|
|
37
|
+
type _StateInsight<S extends SliceCls> = SlceCnstInsight<S>;
|
|
38
|
+
type _StateDefault<S extends SliceCls> = SlceCnstDefault<S>;
|
|
39
|
+
type _StateFilter<S extends SliceCls> = SlceDbFilter<S>;
|
|
40
|
+
type _StateSort<S extends SliceCls> = SlceDbSort<S>;
|
|
41
|
+
|
|
21
42
|
type BaseState<RefName extends string, Full, _Default = DefaultOf<Full>> = {
|
|
22
43
|
[K in RefName]: Full | null;
|
|
23
44
|
} & {
|
|
@@ -73,15 +94,6 @@ export type SliceState<
|
|
|
73
94
|
[K in `sortOf${_CapitalizedRefName}${_CapitalizedSuffix}`]: _Sort;
|
|
74
95
|
};
|
|
75
96
|
|
|
76
|
-
type _SliceMap<SlceCls extends SliceCls> = SlceCls[typeof SLICE_META];
|
|
77
|
-
type _SuffixStr<SlceCls extends SliceCls, Suffix extends keyof _SliceMap<SlceCls>> = Suffix & string;
|
|
78
|
-
type _SuffixCap<SlceCls extends SliceCls, Suffix extends keyof _SliceMap<SlceCls>> = Capitalize<
|
|
79
|
-
_SuffixStr<SlceCls, Suffix>
|
|
80
|
-
>;
|
|
81
|
-
type _ArgsOf<SlceCls extends SliceCls, Suffix extends keyof _SliceMap<SlceCls>> = SliceInfoArgs<
|
|
82
|
-
_SliceMap<SlceCls>[Suffix]
|
|
83
|
-
>;
|
|
84
|
-
|
|
85
97
|
type DefaultSliceStateFields<
|
|
86
98
|
SlceCls extends SliceCls,
|
|
87
99
|
_RefName extends string,
|
|
@@ -91,45 +103,44 @@ type DefaultSliceStateFields<
|
|
|
91
103
|
_Insight,
|
|
92
104
|
_Default,
|
|
93
105
|
_Sort,
|
|
106
|
+
_Suffixes extends keyof _SliceMap<SlceCls> = keyof _SliceMap<SlceCls>,
|
|
94
107
|
> = {
|
|
95
|
-
[Suffix in
|
|
96
|
-
} & {
|
|
97
|
-
[Suffix in keyof _SliceMap<SlceCls> as `${_RefName}List${_SuffixCap<SlceCls, Suffix>}`]: DataList<_Light>;
|
|
98
|
-
} & {
|
|
99
|
-
[Suffix in keyof _SliceMap<SlceCls> as `${_RefName}ListLoading${_SuffixCap<SlceCls, Suffix>}`]: boolean;
|
|
100
|
-
} & {
|
|
101
|
-
[Suffix in keyof _SliceMap<SlceCls> as `${_RefName}InitList${_SuffixCap<SlceCls, Suffix>}`]: DataList<_Light>;
|
|
102
|
-
} & {
|
|
103
|
-
[Suffix in keyof _SliceMap<SlceCls> as `${_RefName}InitAt${_SuffixCap<SlceCls, Suffix>}`]: Date;
|
|
108
|
+
[Suffix in _Suffixes as `default${_CapRefName}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: _Default;
|
|
104
109
|
} & {
|
|
105
|
-
[Suffix in
|
|
110
|
+
[Suffix in _Suffixes as
|
|
111
|
+
| `${_RefName}List${StoreSliceSuffixCap<SlceCls, Suffix>}`
|
|
112
|
+
| `${_RefName}InitList${StoreSliceSuffixCap<SlceCls, Suffix>}`
|
|
113
|
+
| `${_RefName}Selection${StoreSliceSuffixCap<SlceCls, Suffix>}`]: DataList<_Light>;
|
|
106
114
|
} & {
|
|
107
|
-
[Suffix in
|
|
115
|
+
[Suffix in _Suffixes as `${_RefName}InitAt${StoreSliceSuffixCap<SlceCls, Suffix>}`]: Date;
|
|
108
116
|
} & {
|
|
109
|
-
[Suffix in
|
|
117
|
+
[Suffix in _Suffixes as `${_RefName}ListLoading${StoreSliceSuffixCap<SlceCls, Suffix>}`]: boolean;
|
|
110
118
|
} & {
|
|
111
|
-
[Suffix in
|
|
119
|
+
[Suffix in _Suffixes as `${_RefName}Insight${StoreSliceSuffixCap<SlceCls, Suffix>}`]: _Insight;
|
|
112
120
|
} & {
|
|
113
|
-
[Suffix in
|
|
121
|
+
[Suffix in _Suffixes as
|
|
122
|
+
| `lastPageOf${_CapRefName}${StoreSliceSuffixCap<SlceCls, Suffix>}`
|
|
123
|
+
| `pageOf${_CapRefName}${StoreSliceSuffixCap<SlceCls, Suffix>}`
|
|
124
|
+
| `limitOf${_CapRefName}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: number;
|
|
114
125
|
} & {
|
|
115
|
-
[Suffix in
|
|
126
|
+
[Suffix in _Suffixes as `queryArgsOf${_CapRefName}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: StoreSliceArgs<
|
|
116
127
|
SlceCls,
|
|
117
128
|
Suffix
|
|
118
129
|
>;
|
|
119
130
|
} & {
|
|
120
|
-
[Suffix in
|
|
131
|
+
[Suffix in _Suffixes as `sortOf${_CapRefName}${StoreSliceSuffixCap<SlceCls, Suffix>}`]: _Sort;
|
|
121
132
|
};
|
|
122
133
|
|
|
123
134
|
export type DefaultState<
|
|
124
135
|
SlceCls extends SliceCls,
|
|
125
|
-
_RefName extends SlceCls
|
|
126
|
-
_Full =
|
|
127
|
-
_Light extends { id: string } = SlceCls
|
|
128
|
-
_Insight = SlceCls
|
|
129
|
-
_Filter extends FilterInstance = SlceCls
|
|
130
|
-
_CapitalizedRefName extends string =
|
|
131
|
-
_Default = SlceCls
|
|
132
|
-
_Sort = SlceCls
|
|
136
|
+
_RefName extends _StateRefName<SlceCls> = _StateRefName<SlceCls>,
|
|
137
|
+
_Full = _StateFull<SlceCls>,
|
|
138
|
+
_Light extends { id: string } = _StateLight<SlceCls>,
|
|
139
|
+
_Insight = _StateInsight<SlceCls>,
|
|
140
|
+
_Filter extends FilterInstance = _StateFilter<SlceCls>,
|
|
141
|
+
_CapitalizedRefName extends string = _StateCap<SlceCls>,
|
|
142
|
+
_Default = _StateDefault<SlceCls>,
|
|
143
|
+
_Sort = _StateSort<SlceCls>,
|
|
133
144
|
> = BaseState<_RefName, _Full, _Default> &
|
|
134
145
|
DefaultSliceStateFields<SlceCls, _RefName, _CapitalizedRefName, _Full, _Light, _Insight, _Default, _Sort>;
|
|
135
146
|
|
package/store/stateBuilder.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Cls,
|
|
3
3
|
DataList,
|
|
4
|
+
DEFAULT_VALUE,
|
|
4
5
|
type EnumInstance,
|
|
5
6
|
getEnv,
|
|
6
7
|
getNonArrayModel,
|
|
7
8
|
isEnum,
|
|
8
|
-
PRIMITIVE_DEFAULT_VALUE,
|
|
9
9
|
PrimitiveRegistry,
|
|
10
10
|
type PrimitiveScalar,
|
|
11
11
|
} from "akanjs/base";
|
|
@@ -80,7 +80,7 @@ type FieldTypeInput = PrimitiveInput | Cls | EnumInstance | FieldTypeInput[];
|
|
|
80
80
|
|
|
81
81
|
type ValueOfType<T> = T extends readonly (infer V)[]
|
|
82
82
|
? ValueOfType<V>[]
|
|
83
|
-
: T extends { [
|
|
83
|
+
: T extends { [DEFAULT_VALUE]: infer V }
|
|
84
84
|
? V
|
|
85
85
|
: T extends EnumInstance<any, infer V>
|
|
86
86
|
? V
|
|
@@ -300,7 +300,7 @@ const createTypedDefaultFactory = (type: any, options: { default?: any; nullable
|
|
|
300
300
|
if (arrDepth > 0) return () => [];
|
|
301
301
|
if (isEnum(modelRef)) return () => (modelRef as EnumInstance).values[0];
|
|
302
302
|
if (PrimitiveRegistry.has(modelRef as Cls)) {
|
|
303
|
-
const defaultValue = (modelRef as typeof PrimitiveScalar)[
|
|
303
|
+
const defaultValue = (modelRef as typeof PrimitiveScalar)[DEFAULT_VALUE];
|
|
304
304
|
return makeDefaultFactory(defaultValue);
|
|
305
305
|
}
|
|
306
306
|
if (ConstantRegistry.has(modelRef as Cls)) return () => new (modelRef as Cls)();
|
package/store/store.ts
CHANGED
|
@@ -11,7 +11,18 @@ import {
|
|
|
11
11
|
import { applyMixins } from "akanjs/common";
|
|
12
12
|
import type { FilterInstance } from "akanjs/document";
|
|
13
13
|
import type { ClientSignal } from "akanjs/fetch";
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
SerializedSlice,
|
|
16
|
+
SlceCnstCapitalizedRefName,
|
|
17
|
+
SlceCnstDefault,
|
|
18
|
+
SlceCnstFull,
|
|
19
|
+
SlceCnstInput,
|
|
20
|
+
SlceCnstInsight,
|
|
21
|
+
SlceCnstLight,
|
|
22
|
+
SlceDbFilter,
|
|
23
|
+
SlceDbSort,
|
|
24
|
+
SliceCls,
|
|
25
|
+
} from "akanjs/signal";
|
|
15
26
|
import { type DefaultAction, makeActions, makeFormSetter } from "./action";
|
|
16
27
|
import { createDatabaseState, createSliceState, type DefaultState } from "./state";
|
|
17
28
|
import {
|
|
@@ -29,7 +40,42 @@ import {
|
|
|
29
40
|
type WritableStateBuilder,
|
|
30
41
|
type WritableStateOf,
|
|
31
42
|
} from "./stateBuilder";
|
|
32
|
-
import type { InternalSlice, SetGet, SetGetWritable } from "./types";
|
|
43
|
+
import type { InternalSlice, SetGet, SetGetWritable, StoreSliceMap, StoreSliceName, StoreSliceSuffix } from "./types";
|
|
44
|
+
|
|
45
|
+
type _SliceMap<S extends SliceCls> = StoreSliceMap<S>;
|
|
46
|
+
type _StoreInput<S extends SliceCls> = SlceCnstInput<S>;
|
|
47
|
+
type _StoreFull<S extends SliceCls> = SlceCnstFull<S>;
|
|
48
|
+
type _StoreLight<S extends SliceCls> = SlceCnstLight<S>;
|
|
49
|
+
type _StoreInsight<S extends SliceCls> = SlceCnstInsight<S>;
|
|
50
|
+
type _StoreFilter<S extends SliceCls> = SlceDbFilter<S>;
|
|
51
|
+
type _StoreCap<S extends SliceCls> = SlceCnstCapitalizedRefName<S>;
|
|
52
|
+
type _StoreDefault<S extends SliceCls> = SlceCnstDefault<S>;
|
|
53
|
+
type _StoreSort<S extends SliceCls> = SlceDbSort<S>;
|
|
54
|
+
type StoreSliceOf<
|
|
55
|
+
SlceCls extends SliceCls,
|
|
56
|
+
RefName extends string,
|
|
57
|
+
Suffix extends keyof _SliceMap<SlceCls>,
|
|
58
|
+
Input,
|
|
59
|
+
Full,
|
|
60
|
+
Light extends { id: string },
|
|
61
|
+
Insight,
|
|
62
|
+
Filter extends FilterInstance,
|
|
63
|
+
CapitalizedRefName extends string,
|
|
64
|
+
Default,
|
|
65
|
+
Sort,
|
|
66
|
+
> = InternalSlice<
|
|
67
|
+
_SliceMap<SlceCls>[Suffix],
|
|
68
|
+
RefName,
|
|
69
|
+
StoreSliceSuffix<SlceCls, Suffix>,
|
|
70
|
+
Input,
|
|
71
|
+
Full,
|
|
72
|
+
Light,
|
|
73
|
+
Insight,
|
|
74
|
+
Filter,
|
|
75
|
+
CapitalizedRefName,
|
|
76
|
+
Default,
|
|
77
|
+
Sort
|
|
78
|
+
>;
|
|
33
79
|
|
|
34
80
|
export type StoreCls<
|
|
35
81
|
RefName extends string = string,
|
|
@@ -38,24 +84,24 @@ export type StoreCls<
|
|
|
38
84
|
SlceCls extends SliceCls = any,
|
|
39
85
|
DerivedState = unknown,
|
|
40
86
|
State = WritableState & DerivedState,
|
|
41
|
-
_Input = SlceCls
|
|
42
|
-
_Full = SlceCls
|
|
43
|
-
_Light extends { id: string } = SlceCls
|
|
44
|
-
_Insight = SlceCls
|
|
45
|
-
_Filter extends FilterInstance = SlceCls
|
|
46
|
-
_CapitalizedRefName extends string =
|
|
47
|
-
_Default = SlceCls
|
|
48
|
-
_Sort = SlceCls
|
|
87
|
+
_Input = _StoreInput<SlceCls>,
|
|
88
|
+
_Full = _StoreFull<SlceCls>,
|
|
89
|
+
_Light extends { id: string } = _StoreLight<SlceCls>,
|
|
90
|
+
_Insight = _StoreInsight<SlceCls>,
|
|
91
|
+
_Filter extends FilterInstance = _StoreFilter<SlceCls>,
|
|
92
|
+
_CapitalizedRefName extends string = _StoreCap<SlceCls>,
|
|
93
|
+
_Default = _StoreDefault<SlceCls>,
|
|
94
|
+
_Sort = _StoreSort<SlceCls>,
|
|
49
95
|
> = Cls<
|
|
50
96
|
SetGetWritable<WritableState, State> &
|
|
51
97
|
Action & {
|
|
52
98
|
slice: {
|
|
53
|
-
[Suffix in keyof SlceCls
|
|
54
|
-
?
|
|
55
|
-
: never]:
|
|
56
|
-
SlceCls
|
|
99
|
+
[Suffix in keyof _SliceMap<SlceCls> as Suffix extends string
|
|
100
|
+
? StoreSliceName<RefName, Suffix>
|
|
101
|
+
: never]: StoreSliceOf<
|
|
102
|
+
SlceCls,
|
|
57
103
|
RefName,
|
|
58
|
-
Suffix
|
|
104
|
+
Suffix,
|
|
59
105
|
_Input,
|
|
60
106
|
_Full,
|
|
61
107
|
_Light,
|
package/store/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { SLICE_META } from "akanjs/base";
|
|
1
2
|
import type { DefaultOf } from "akanjs/constant";
|
|
2
3
|
import type { ExtractSort, FilterInstance } from "akanjs/document";
|
|
3
|
-
import type { SliceInfo } from "akanjs/signal";
|
|
4
|
+
import type { SliceCls, SliceInfo, SliceInfoArgs } from "akanjs/signal";
|
|
4
5
|
import type { SliceAction } from "./action";
|
|
5
6
|
import type { SliceState } from "./state";
|
|
6
7
|
|
|
@@ -35,10 +36,20 @@ export type Get<State, Actions> = {
|
|
|
35
36
|
get: () => State & Actions;
|
|
36
37
|
};
|
|
37
38
|
|
|
39
|
+
export type StoreSliceMap<SlceCls extends SliceCls> = SlceCls[typeof SLICE_META];
|
|
40
|
+
export type StoreSliceSuffix<SlceCls extends SliceCls, Suffix extends keyof StoreSliceMap<SlceCls>> = Suffix & string;
|
|
41
|
+
export type StoreSliceSuffixCap<SlceCls extends SliceCls, Suffix extends keyof StoreSliceMap<SlceCls>> = Capitalize<
|
|
42
|
+
StoreSliceSuffix<SlceCls, Suffix>
|
|
43
|
+
>;
|
|
44
|
+
export type StoreSliceArgs<SlceCls extends SliceCls, Suffix extends keyof StoreSliceMap<SlceCls>> = SliceInfoArgs<
|
|
45
|
+
StoreSliceMap<SlceCls>[Suffix]
|
|
46
|
+
>;
|
|
47
|
+
export type StoreSliceName<RefName extends string, Suffix extends string> = `${RefName}${Capitalize<Suffix>}`;
|
|
48
|
+
|
|
38
49
|
export type SliceStateAction<
|
|
39
50
|
RefName extends string = string,
|
|
40
51
|
Suffix extends string = "",
|
|
41
|
-
SliceName extends string =
|
|
52
|
+
SliceName extends string = StoreSliceName<RefName, Suffix>,
|
|
42
53
|
State = any,
|
|
43
54
|
Action = any,
|
|
44
55
|
> = Action & {
|
|
@@ -61,9 +72,8 @@ export type InternalSlice<
|
|
|
61
72
|
_CapitalizedRefName extends string = Capitalize<RefName>,
|
|
62
73
|
_Default = DefaultOf<Full>,
|
|
63
74
|
_Sort = ExtractSort<Filter>,
|
|
64
|
-
_Args extends any[] = SlceInfo
|
|
65
|
-
? Args
|
|
66
|
-
: never,
|
|
75
|
+
_Args extends any[] = SliceInfoArgs<SlceInfo>,
|
|
67
76
|
_SliceState = SliceState<RefName, "", Full, Light, _Args, Insight, Filter, _CapitalizedRefName, "", _Default, _Sort>,
|
|
68
77
|
_SliceAction = SliceAction<RefName, "", Input, Light, _Args, Filter, _CapitalizedRefName, "", _Sort>,
|
|
69
|
-
|
|
78
|
+
_SliceName extends string = StoreSliceName<RefName, Suffix>,
|
|
79
|
+
> = SliceStateAction<RefName, Suffix, _SliceName, _SliceState, _SliceAction>;
|
package/types/base/base.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { Cls } from ".";
|
|
1
|
+
import type { CLIENT_VALUE, Cls, DEFAULT_VALUE, PURIFIED_VALUE, SERVER_VALUE } from ".";
|
|
2
2
|
import { Float, Int } from "./primitiveRegistry.d.ts";
|
|
3
3
|
export type EnumInstance<RefName extends string = string, T = string | number> = Cls<{
|
|
4
4
|
refName: RefName;
|
|
5
5
|
value: T;
|
|
6
6
|
}, {
|
|
7
7
|
refName: RefName;
|
|
8
|
+
[SERVER_VALUE]: T;
|
|
9
|
+
[CLIENT_VALUE]: T;
|
|
10
|
+
[DEFAULT_VALUE]: T;
|
|
11
|
+
[PURIFIED_VALUE]: T;
|
|
8
12
|
type: StringConstructor | typeof Int | typeof Float;
|
|
9
13
|
values: readonly T[];
|
|
10
14
|
valueMap: Map<T, number>;
|