akanjs 2.3.5-rc.9 → 2.3.6-rc.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/CHANGELOG.md +6 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- 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/server/akanApp.ts +11 -5
- package/server/akanServer.ts +74 -3
- package/server/artifact/builderRpc.ts +6 -0
- package/server/artifact/ipcTypes.ts +38 -2
- package/server/hmr/clientScript.ts +145 -6
- package/server/hmr/devHmrController.ts +45 -1
- package/server/hmr/wsHub.ts +10 -0
- package/server/routing/apiRouter.ts +5 -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/index.ts +1 -0
- package/signal/internal.ts +2 -1
- package/signal/internalInfo.ts +71 -23
- package/signal/openapi/index.ts +1 -0
- package/signal/openapi/openapi.ts +359 -0
- 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/server/akanApp.d.ts +1 -0
- package/types/server/akanServer.d.ts +7 -1
- package/types/server/artifact/builderRpc.d.ts +3 -1
- package/types/server/artifact/ipcTypes.d.ts +22 -0
- package/types/server/hmr/clientScript.d.ts +1 -1
- package/types/server/hmr/devHmrController.d.ts +5 -2
- package/types/server/hmr/wsHub.d.ts +11 -0
- package/types/server/routing/apiRouter.d.ts +2 -1
- 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/index.d.ts +1 -0
- package/types/signal/internal.d.ts +2 -1
- package/types/signal/internalInfo.d.ts +46 -12
- package/types/signal/openapi/index.d.ts +1 -0
- package/types/signal/openapi/openapi.d.ts +35 -0
- package/types/signal/openapi.d.ts +1 -0
- 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/CHANGELOG.md
CHANGED
package/README.ko.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Akan.js
|
|
2
2
|
|
|
3
|
-
[English](
|
|
3
|
+
[English](./README.md) | [Docs](https://akanjs.com/docs) | [npm](https://www.npmjs.com/package/akanjs)
|
|
4
4
|
|
|
5
5
|
**한 줄의 비즈니스 코드로 웹·iOS·Android·서버·DB를 한 번에.**
|
|
6
6
|
**One line of business code ships web, iOS, Android, server, and database together.**
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Akan.js
|
|
2
2
|
|
|
3
|
-
[한국어](
|
|
3
|
+
[한국어](./README.ko.md) | [Docs](https://akanjs.com/docs) | [npm](https://www.npmjs.com/package/akanjs)
|
|
4
4
|
|
|
5
5
|
**One line of business code ships web, iOS, Android, server, and database together.**
|
|
6
6
|
|
package/base/base.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
3
3
|
|
|
4
4
|
class EnumPrototype {}
|
|
@@ -6,6 +6,10 @@ export type EnumInstance<RefName extends string = string, T = string | number> =
|
|
|
6
6
|
{ refName: RefName; value: T },
|
|
7
7
|
{
|
|
8
8
|
refName: RefName;
|
|
9
|
+
[SERVER_VALUE]: T;
|
|
10
|
+
[CLIENT_VALUE]: T;
|
|
11
|
+
[DEFAULT_VALUE]: T;
|
|
12
|
+
[PURIFIED_VALUE]: T;
|
|
9
13
|
type: StringConstructor | typeof Int | typeof Float;
|
|
10
14
|
values: readonly T[];
|
|
11
15
|
valueMap: Map<T, number>;
|
|
@@ -71,7 +75,7 @@ export const enumOf = <RefName extends string, T = string | number>(
|
|
|
71
75
|
readonly refName = refName;
|
|
72
76
|
declare readonly value: T;
|
|
73
77
|
}
|
|
74
|
-
return Enum
|
|
78
|
+
return Enum as unknown as EnumInstance<RefName, T>;
|
|
75
79
|
};
|
|
76
80
|
|
|
77
81
|
/** Id-keyed list helper used for light model collections and immutable-style list updates. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dayjsLib, { type Dayjs } from "dayjs";
|
|
2
|
-
|
|
2
|
+
import { CLIENT_VALUE, DEFAULT_VALUE, EXAMPLE_VALUE, PURIFIED_VALUE, SERVER_VALUE } from "./symbols";
|
|
3
3
|
import type { Cls } from "./types";
|
|
4
4
|
|
|
5
5
|
export type { Dayjs };
|
|
@@ -44,17 +44,14 @@ export class PrimitiveRegistry {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export const PRIMITIVE_SERVER_VALUE = Symbol.for("PRIMITIVE_SERVER_VALUE");
|
|
48
|
-
export const PRIMITIVE_CLIENT_VALUE = Symbol.for("PRIMITIVE_CLIENT_VALUE");
|
|
49
|
-
export const PRIMITIVE_DEFAULT_VALUE = Symbol.for("PRIMITIVE_DEFAULT_VALUE");
|
|
50
|
-
export const PRIMITIVE_EXAMPLE_VALUE = Symbol.for("PRIMITIVE_EXAMPLE_VALUE");
|
|
51
47
|
export type PrimitiveValue = string | number | boolean | Dayjs | Date | null | undefined;
|
|
52
48
|
export class PrimitiveScalar {
|
|
53
49
|
static refName: string;
|
|
54
|
-
static [
|
|
55
|
-
static [
|
|
56
|
-
static [
|
|
57
|
-
static [
|
|
50
|
+
static [SERVER_VALUE]: unknown;
|
|
51
|
+
static [CLIENT_VALUE]: unknown;
|
|
52
|
+
static [DEFAULT_VALUE]: unknown = null;
|
|
53
|
+
static [PURIFIED_VALUE]: unknown = null;
|
|
54
|
+
static [EXAMPLE_VALUE]: unknown = null;
|
|
58
55
|
|
|
59
56
|
static validate(value: PrimitiveValue): boolean {
|
|
60
57
|
return true;
|
|
@@ -105,10 +102,11 @@ export class PrimitiveScalar {
|
|
|
105
102
|
/** Integer primitive scalar. Accepts safe integer numbers after parsing. */
|
|
106
103
|
export class Int extends PrimitiveScalar {
|
|
107
104
|
static override refName: "Int" = "Int";
|
|
108
|
-
static override [
|
|
109
|
-
static override [
|
|
110
|
-
static override [
|
|
111
|
-
static override [
|
|
105
|
+
static override [SERVER_VALUE]: number;
|
|
106
|
+
static override [CLIENT_VALUE]: number;
|
|
107
|
+
static override [DEFAULT_VALUE]: number = 0;
|
|
108
|
+
static override [PURIFIED_VALUE]: number = 0;
|
|
109
|
+
static override [EXAMPLE_VALUE]: number = 0;
|
|
112
110
|
|
|
113
111
|
static override validate(value: string | number): boolean {
|
|
114
112
|
return typeof value === "number" && Number.isSafeInteger(value);
|
|
@@ -125,10 +123,11 @@ PrimitiveRegistry.register(Int);
|
|
|
125
123
|
/** Floating point primitive scalar. Accepts finite numbers after parsing. */
|
|
126
124
|
export class Float extends PrimitiveScalar {
|
|
127
125
|
static override refName: "Float" = "Float";
|
|
128
|
-
static override [
|
|
129
|
-
static override [
|
|
130
|
-
static override [
|
|
131
|
-
static override [
|
|
126
|
+
static override [SERVER_VALUE]: number;
|
|
127
|
+
static override [CLIENT_VALUE]: number;
|
|
128
|
+
static override [DEFAULT_VALUE]: number = 0;
|
|
129
|
+
static override [PURIFIED_VALUE]: number = 0;
|
|
130
|
+
static override [EXAMPLE_VALUE]: number = 0;
|
|
132
131
|
|
|
133
132
|
static override validate(value: string | number): boolean {
|
|
134
133
|
return typeof value === "number" && Number.isFinite(value);
|
|
@@ -145,10 +144,11 @@ PrimitiveRegistry.register(Float);
|
|
|
145
144
|
/** 24-character hexadecimal id primitive used by Akan document and signal models. */
|
|
146
145
|
export class ID extends PrimitiveScalar {
|
|
147
146
|
static override refName: "ID" = "ID";
|
|
148
|
-
static override [
|
|
149
|
-
static override [
|
|
150
|
-
static override [
|
|
151
|
-
static override [
|
|
147
|
+
static override [SERVER_VALUE]: string;
|
|
148
|
+
static override [CLIENT_VALUE]: string;
|
|
149
|
+
static override [DEFAULT_VALUE]: string = "";
|
|
150
|
+
static override [PURIFIED_VALUE]: string = "";
|
|
151
|
+
static override [EXAMPLE_VALUE]: string = "1234567890abcdef12345678";
|
|
152
152
|
|
|
153
153
|
static override validate(value: string): boolean {
|
|
154
154
|
if (typeof value !== "string") return false;
|
|
@@ -161,7 +161,7 @@ export class ID extends PrimitiveScalar {
|
|
|
161
161
|
return String(value);
|
|
162
162
|
}
|
|
163
163
|
static override _checkValue(value: PrimitiveValue, options: { optional?: boolean } = {}): void {
|
|
164
|
-
if (value === ID[
|
|
164
|
+
if (value === ID[DEFAULT_VALUE]) return;
|
|
165
165
|
|
|
166
166
|
super._checkValue(value, options);
|
|
167
167
|
}
|
|
@@ -171,17 +171,18 @@ PrimitiveRegistry.register(ID);
|
|
|
171
171
|
/** Open object primitive for intentionally flexible payloads or metadata blobs. */
|
|
172
172
|
export class Any extends PrimitiveScalar {
|
|
173
173
|
static override refName: "Any" = "Any";
|
|
174
|
-
static override [
|
|
175
|
-
static override [
|
|
174
|
+
static override [DEFAULT_VALUE]: object | null = null;
|
|
175
|
+
static override [EXAMPLE_VALUE]: object = {};
|
|
176
176
|
}
|
|
177
177
|
PrimitiveRegistry.register(Any);
|
|
178
178
|
|
|
179
179
|
export class Upload extends PrimitiveScalar {
|
|
180
180
|
static override refName: "Upload" = "Upload";
|
|
181
|
-
static override [
|
|
182
|
-
static override [
|
|
183
|
-
static override [
|
|
184
|
-
static override [
|
|
181
|
+
static override [SERVER_VALUE]: File;
|
|
182
|
+
static override [CLIENT_VALUE]: File;
|
|
183
|
+
static override [DEFAULT_VALUE]: File | null = null;
|
|
184
|
+
static override [PURIFIED_VALUE]: File;
|
|
185
|
+
static override [EXAMPLE_VALUE] = "FileUpload";
|
|
185
186
|
__TEMP_TYPE__: "Upload" = "Upload";
|
|
186
187
|
}
|
|
187
188
|
PrimitiveRegistry.register(Upload);
|
|
@@ -189,10 +190,11 @@ PrimitiveRegistry.register(Upload);
|
|
|
189
190
|
declare global {
|
|
190
191
|
interface StringConstructor {
|
|
191
192
|
refName: "String";
|
|
192
|
-
[
|
|
193
|
-
[
|
|
194
|
-
[
|
|
195
|
-
[
|
|
193
|
+
[SERVER_VALUE]: string;
|
|
194
|
+
[CLIENT_VALUE]: string;
|
|
195
|
+
[DEFAULT_VALUE]: string;
|
|
196
|
+
[PURIFIED_VALUE]: string;
|
|
197
|
+
[EXAMPLE_VALUE]: string;
|
|
196
198
|
validate(value: string): boolean;
|
|
197
199
|
parseValue(input: string): string;
|
|
198
200
|
serializeValue(value: string): string;
|
|
@@ -202,10 +204,11 @@ declare global {
|
|
|
202
204
|
}
|
|
203
205
|
interface BooleanConstructor {
|
|
204
206
|
refName: "Boolean";
|
|
205
|
-
[
|
|
206
|
-
[
|
|
207
|
-
[
|
|
208
|
-
[
|
|
207
|
+
[SERVER_VALUE]: boolean;
|
|
208
|
+
[CLIENT_VALUE]: boolean;
|
|
209
|
+
[DEFAULT_VALUE]: boolean;
|
|
210
|
+
[PURIFIED_VALUE]: boolean;
|
|
211
|
+
[EXAMPLE_VALUE]: boolean;
|
|
209
212
|
validate(value: boolean | number): boolean;
|
|
210
213
|
parseValue(input: boolean | number): boolean | number;
|
|
211
214
|
serializeValue(value: boolean | number): boolean | number;
|
|
@@ -215,10 +218,11 @@ declare global {
|
|
|
215
218
|
}
|
|
216
219
|
interface DateConstructor {
|
|
217
220
|
refName: "Date";
|
|
218
|
-
[
|
|
219
|
-
[
|
|
220
|
-
[
|
|
221
|
-
[
|
|
221
|
+
[SERVER_VALUE]: Dayjs;
|
|
222
|
+
[CLIENT_VALUE]: Dayjs;
|
|
223
|
+
[DEFAULT_VALUE]: Dayjs;
|
|
224
|
+
[PURIFIED_VALUE]: Dayjs;
|
|
225
|
+
[EXAMPLE_VALUE]: string;
|
|
222
226
|
validate(value: Date): boolean;
|
|
223
227
|
parseValue(input: Date): Dayjs;
|
|
224
228
|
serializeValue(value: Dayjs | Date): Date;
|
|
@@ -287,8 +291,8 @@ const scalarPrimitiveStatics = {
|
|
|
287
291
|
|
|
288
292
|
Object.assign(String, scalarPrimitiveStatics, {
|
|
289
293
|
refName: "String",
|
|
290
|
-
[
|
|
291
|
-
[
|
|
294
|
+
[DEFAULT_VALUE]: "",
|
|
295
|
+
[EXAMPLE_VALUE]: "String",
|
|
292
296
|
validate(value: string) {
|
|
293
297
|
return typeof value === "string";
|
|
294
298
|
},
|
|
@@ -311,8 +315,8 @@ const normalizeBooleanPrimitiveValue = (value: boolean | number): boolean | null
|
|
|
311
315
|
Object.assign(Boolean, {
|
|
312
316
|
...scalarPrimitiveStatics,
|
|
313
317
|
refName: "Boolean",
|
|
314
|
-
[
|
|
315
|
-
[
|
|
318
|
+
[DEFAULT_VALUE]: false,
|
|
319
|
+
[EXAMPLE_VALUE]: true,
|
|
316
320
|
validate(value: boolean | number) {
|
|
317
321
|
return normalizeBooleanPrimitiveValue(value) !== null;
|
|
318
322
|
},
|
|
@@ -328,8 +332,8 @@ PrimitiveRegistry.register(Boolean);
|
|
|
328
332
|
Object.assign(Date, {
|
|
329
333
|
...scalarPrimitiveStatics,
|
|
330
334
|
refName: "Date",
|
|
331
|
-
[
|
|
332
|
-
[
|
|
335
|
+
[DEFAULT_VALUE]: dayjs(new Date(-1)),
|
|
336
|
+
[EXAMPLE_VALUE]: dayjs(new Date().toISOString()),
|
|
333
337
|
validate(value: Date | string | number) {
|
|
334
338
|
const date = new Date(value);
|
|
335
339
|
if (Number.isNaN(date.getTime())) return false;
|
package/base/symbols.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
export const FIELD_META = Symbol.for("
|
|
2
|
-
export const SLICE_META = Symbol.for("
|
|
3
|
-
export const FILTER_META = Symbol.for("
|
|
4
|
-
export const LOADER_META = Symbol.for("
|
|
5
|
-
export const INJECT_META = Symbol.for("
|
|
6
|
-
export const ENDPOINT_META = Symbol.for("
|
|
7
|
-
export const INTERNAL_META = Symbol.for("
|
|
8
|
-
export const STATE_META = Symbol.for("
|
|
9
|
-
export const STATE_INIT_META = Symbol.for("
|
|
10
|
-
export const STATE_DERIVED_META = Symbol.for("
|
|
11
|
-
export const ACTION_META = Symbol.for("
|
|
1
|
+
export const FIELD_META = Symbol.for("akan.field");
|
|
2
|
+
export const SLICE_META = Symbol.for("akan.slice");
|
|
3
|
+
export const FILTER_META = Symbol.for("akan.filter");
|
|
4
|
+
export const LOADER_META = Symbol.for("akan.loader");
|
|
5
|
+
export const INJECT_META = Symbol.for("akan.inject");
|
|
6
|
+
export const ENDPOINT_META = Symbol.for("akan.endpoint");
|
|
7
|
+
export const INTERNAL_META = Symbol.for("akan.internal");
|
|
8
|
+
export const STATE_META = Symbol.for("akan.state");
|
|
9
|
+
export const STATE_INIT_META = Symbol.for("akan.state.init");
|
|
10
|
+
export const STATE_DERIVED_META = Symbol.for("akan.state.derived");
|
|
11
|
+
export const ACTION_META = Symbol.for("akan.action");
|
|
12
|
+
export const SERVER_VALUE = Symbol.for("akan.value.server");
|
|
13
|
+
export const CLIENT_VALUE = Symbol.for("akan.value.client");
|
|
14
|
+
export const DEFAULT_VALUE = Symbol.for("akan.value.default");
|
|
15
|
+
export const EXAMPLE_VALUE = Symbol.for("akan.value.example");
|
|
16
|
+
export const PURIFIED_VALUE = Symbol.for("akan.value.purified");
|
package/base/types.ts
CHANGED
|
@@ -48,6 +48,18 @@ export type ObjectAssign<Objects extends object[], Acc = unknown> = Objects exte
|
|
|
48
48
|
? ObjectAssign<Rest, Assign<Acc, First>>
|
|
49
49
|
: Acc;
|
|
50
50
|
|
|
51
|
+
export type ObjectAssignKeyOfObjects<
|
|
52
|
+
T extends object[],
|
|
53
|
+
Key extends PropertyKey,
|
|
54
|
+
Acc = Record<never, never>,
|
|
55
|
+
> = T extends [infer First extends object, ...infer Rest extends object[]]
|
|
56
|
+
? Key extends keyof First
|
|
57
|
+
? First[Key] extends object
|
|
58
|
+
? ObjectAssignKeyOfObjects<Rest, Key, Assign<Acc, First[Key]>>
|
|
59
|
+
: ObjectAssignKeyOfObjects<Rest, Key, Acc>
|
|
60
|
+
: ObjectAssignKeyOfObjects<Rest, Key, Acc>
|
|
61
|
+
: Acc;
|
|
62
|
+
|
|
51
63
|
export type MergeAll<T extends object[], Acc = unknown> = T extends [
|
|
52
64
|
infer First extends object,
|
|
53
65
|
...infer Rest extends object[],
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Cls,
|
|
3
3
|
type EnumInstance,
|
|
4
|
-
FIELD_META,
|
|
5
4
|
type GetStateObject,
|
|
6
5
|
isEnum,
|
|
7
6
|
PrimitiveRegistry,
|
|
@@ -9,14 +8,16 @@ import {
|
|
|
9
8
|
type PrimitiveValue,
|
|
10
9
|
} from "akanjs/base";
|
|
11
10
|
import { capitalize, lowerlize } from "akanjs/common";
|
|
12
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type ConstantCls,
|
|
13
|
+
type ConstantModelRef,
|
|
14
|
+
deserialize,
|
|
15
|
+
type FieldObject,
|
|
16
|
+
type PurifiedModel,
|
|
17
|
+
serialize,
|
|
18
|
+
} from ".";
|
|
13
19
|
import type { ConstantType, DefaultOf, DocumentModel, QueryOf } from "./types";
|
|
14
20
|
|
|
15
|
-
type ConstantModelRef<FieldObj extends FieldObject = FieldObject> = Cls<
|
|
16
|
-
unknown,
|
|
17
|
-
{ [FIELD_META]: FieldObj; modelType: ConstantType }
|
|
18
|
-
>;
|
|
19
|
-
|
|
20
21
|
/** Runtime registry for Akan constant model metadata, refs, enums, and generated model contracts. */
|
|
21
22
|
export class ConstantRegistry {
|
|
22
23
|
static database = new Map<string, ConstantModel>();
|
|
@@ -107,7 +108,7 @@ export class ConstantRegistry {
|
|
|
107
108
|
InputRef extends ConstantModelRef,
|
|
108
109
|
ObjectRef extends ConstantModelRef,
|
|
109
110
|
FullFieldObj extends FieldObject,
|
|
110
|
-
FullRef extends ConstantModelRef<FullFieldObj>,
|
|
111
|
+
FullRef extends ConstantModelRef<any, FullFieldObj>,
|
|
111
112
|
LightRef extends ConstantModelRef,
|
|
112
113
|
InsightRef extends ConstantModelRef,
|
|
113
114
|
Input = InstanceType<InputRef>,
|
|
@@ -200,7 +201,7 @@ export class ConstantRegistry {
|
|
|
200
201
|
_StateLight: null as unknown as GetStateObject<Light>,
|
|
201
202
|
_StateInsight: null as unknown as GetStateObject<Insight>,
|
|
202
203
|
};
|
|
203
|
-
ConstantRegistry.setDatabase(refName, cnst as ConstantModel);
|
|
204
|
+
ConstantRegistry.setDatabase(refName, cnst as unknown as ConstantModel);
|
|
204
205
|
Object.entries(constExports).forEach(([key, value]) => {
|
|
205
206
|
if ((modelRefSet as Set<unknown>).has(value)) return;
|
|
206
207
|
else if (typeof value === "function" && isEnum(value as Cls))
|
package/constant/deserialize.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { applyFnToArrayObjects, type Cls, FIELD_META, PrimitiveRegistry, type PrimitiveScalar } from "akanjs/base";
|
|
1
|
+
import { Any, applyFnToArrayObjects, type Cls, FIELD_META, PrimitiveRegistry, type PrimitiveScalar } from "akanjs/base";
|
|
2
2
|
|
|
3
|
-
import { type ConstantCls, ConstantRegistry, type FieldProps } from ".";
|
|
3
|
+
import { type ConstantCls, type ConstantModelRef, ConstantRegistry, type FieldProps } from ".";
|
|
4
4
|
|
|
5
|
-
const getDeserializeFn = (inputRef:
|
|
5
|
+
const getDeserializeFn = (inputRef: ConstantModelRef | PrimitiveScalar) => {
|
|
6
6
|
const deserializeFn = PrimitiveRegistry.has(inputRef as Cls)
|
|
7
7
|
? (value: unknown) => (inputRef as unknown as typeof PrimitiveScalar)._parse(value as never)
|
|
8
8
|
: (value: unknown) => value as object;
|
|
@@ -13,14 +13,14 @@ const deserializeMap = (value: unknown, field: Pick<FieldProps, "of">) => {
|
|
|
13
13
|
return Object.fromEntries(
|
|
14
14
|
Object.entries(value as Record<string, unknown>).map(([key, val]) => [
|
|
15
15
|
key,
|
|
16
|
-
applyFnToArrayObjects(val, (v: never) => deserializeInput(v, field.of as
|
|
16
|
+
applyFnToArrayObjects(val, (v: never) => deserializeInput(v, field.of as ConstantModelRef, 0)),
|
|
17
17
|
]),
|
|
18
18
|
);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const deserializeInput = <Input = unknown>(
|
|
22
22
|
value: Input | Input[],
|
|
23
|
-
inputRef:
|
|
23
|
+
inputRef: ConstantModelRef<Input> | PrimitiveScalar,
|
|
24
24
|
arrDepth: number,
|
|
25
25
|
convertFn: (value: unknown) => unknown = (value: unknown) => value,
|
|
26
26
|
): Input | Input[] => {
|
|
@@ -58,13 +58,13 @@ const deserializeInput = <Input = unknown>(
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
export const deserialize = (
|
|
61
|
-
argRef:
|
|
61
|
+
argRef: ConstantModelRef | PrimitiveScalar,
|
|
62
62
|
arrDepth: number,
|
|
63
63
|
value: unknown,
|
|
64
64
|
{ key, nullable = false, convertFn }: { key?: string; nullable?: boolean; convertFn?: (value: unknown) => unknown },
|
|
65
65
|
) => {
|
|
66
66
|
if (nullable && (value === null || value === undefined)) return null;
|
|
67
|
-
else if (!nullable && (value === null || value === undefined))
|
|
67
|
+
else if (!nullable && (value === null || value === undefined) && argRef !== Any)
|
|
68
68
|
throw new Error(`Invalid Value (Nullable) in ${key} ${argRef} for value ${value}`);
|
|
69
69
|
return deserializeInput(value, argRef, arrDepth, convertFn) as object[];
|
|
70
70
|
};
|