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.
Files changed (81) hide show
  1. package/base/base.ts +6 -2
  2. package/base/primitiveRegistry.ts +50 -46
  3. package/base/symbols.ts +16 -11
  4. package/base/types.ts +12 -0
  5. package/constant/constantRegistry.ts +10 -9
  6. package/constant/deserialize.ts +7 -7
  7. package/constant/fieldInfo.ts +173 -31
  8. package/constant/getDefault.ts +2 -2
  9. package/constant/immerify.ts +2 -2
  10. package/constant/purify.ts +19 -4
  11. package/constant/serialize.ts +6 -5
  12. package/constant/types.ts +9 -1
  13. package/constant/via.ts +312 -57
  14. package/dictionary/dictInfo.ts +28 -38
  15. package/dictionary/locale.ts +36 -38
  16. package/document/by.ts +84 -21
  17. package/document/database.ts +53 -18
  18. package/document/databaseRegistry.ts +7 -3
  19. package/document/filterMeta.ts +26 -14
  20. package/document/into.ts +71 -76
  21. package/document/types.ts +4 -2
  22. package/fetch/fetchType/endpointFetch.type.ts +6 -3
  23. package/fetch/fetchType/sliceFetch.type.ts +24 -13
  24. package/package.json +1 -1
  25. package/service/predefinedAdaptor/compress.adaptor.ts +9 -9
  26. package/service/predefinedAdaptor/database.adaptor.ts +3 -7
  27. package/service/serve.ts +17 -52
  28. package/service/types.ts +61 -21
  29. package/signal/endpoint.ts +2 -1
  30. package/signal/endpointInfo.ts +53 -23
  31. package/signal/internal.ts +2 -1
  32. package/signal/internalInfo.ts +71 -23
  33. package/signal/serverSignal.ts +23 -57
  34. package/signal/slice.ts +35 -35
  35. package/signal/sliceInfo.ts +63 -47
  36. package/signal/types.ts +23 -17
  37. package/store/action.ts +57 -44
  38. package/store/state.ts +47 -36
  39. package/store/stateBuilder.ts +3 -3
  40. package/store/store.ts +61 -15
  41. package/store/types.ts +16 -6
  42. package/types/base/base.d.ts +5 -1
  43. package/types/base/primitiveRegistry.d.ts +43 -38
  44. package/types/base/symbols.d.ts +5 -0
  45. package/types/base/types.d.ts +1 -0
  46. package/types/constant/constantRegistry.d.ts +3 -8
  47. package/types/constant/deserialize.d.ts +2 -2
  48. package/types/constant/fieldInfo.d.ts +41 -20
  49. package/types/constant/immerify.d.ts +2 -2
  50. package/types/constant/purify.d.ts +3 -2
  51. package/types/constant/serialize.d.ts +2 -2
  52. package/types/constant/types.d.ts +6 -1
  53. package/types/constant/via.d.ts +143 -22
  54. package/types/dictionary/dictInfo.d.ts +18 -11
  55. package/types/dictionary/locale.d.ts +23 -16
  56. package/types/document/by.d.ts +44 -7
  57. package/types/document/database.d.ts +9 -7
  58. package/types/document/databaseRegistry.d.ts +5 -4
  59. package/types/document/filterMeta.d.ts +18 -11
  60. package/types/document/into.d.ts +46 -19
  61. package/types/document/types.d.ts +3 -2
  62. package/types/fetch/fetchType/endpointFetch.type.d.ts +2 -2
  63. package/types/fetch/fetchType/sliceFetch.type.d.ts +11 -11
  64. package/types/service/serve.d.ts +4 -5
  65. package/types/service/serviceModule.d.ts +5 -5
  66. package/types/service/types.d.ts +23 -5
  67. package/types/signal/endpoint.d.ts +2 -1
  68. package/types/signal/endpointInfo.d.ts +40 -15
  69. package/types/signal/internal.d.ts +2 -1
  70. package/types/signal/internalInfo.d.ts +46 -12
  71. package/types/signal/serverSignal.d.ts +15 -12
  72. package/types/signal/slice.d.ts +8 -6
  73. package/types/signal/sliceInfo.d.ts +41 -20
  74. package/types/signal/types.d.ts +23 -17
  75. package/types/store/action.d.ts +25 -22
  76. package/types/store/baseSt.d.ts +42 -13
  77. package/types/store/state.d.ts +23 -26
  78. package/types/store/stateBuilder.d.ts +2 -2
  79. package/types/store/store.d.ts +17 -5
  80. package/types/store/types.d.ts +9 -3
  81. package/ui/Signal/makeExample.ts +3 -3
@@ -1,8 +1,8 @@
1
1
  import { FIELD_META } from "akanjs/base";
2
2
  import { immerable } from "immer";
3
- import type { ConstantCls } from ".";
3
+ import type { ConstantModelRef } from ".";
4
4
 
5
- export const immerify = <T extends object>(modelRef: ConstantCls, objOrArr: T): T => {
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,
@@ -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 { type BaseObject, type ConstantCls, ConstantRegistry, type DefaultOf, type FieldProps } from ".";
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 ConstantCls)(value as object);
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: ConstantCls<I>): PurifyFunc<I> => {
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)) {
@@ -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: ConstantCls<Input> | PrimitiveScalar,
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: ConstantCls | PrimitiveScalar,
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> = keyof T extends (...args: never[]) => unknown ? never : keyof 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;