akanjs 2.3.2-rc.1 → 2.3.2-rc.3
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/constant/constantRegistry.ts +1 -1
- package/constant/purify.ts +23 -80
- package/constant/via.ts +9 -0
- package/document/by.ts +4 -12
- package/fetch/client/fetchClient.ts +2 -4
- package/fetch/fetchType/buildFetch.type.ts +21 -14
- package/fetch/fetchType/endpointFetch.type.ts +21 -16
- package/fetch/types.ts +7 -12
- package/package.json +1 -1
- package/types/constant/via.d.ts +4 -1
- package/types/document/by.d.ts +4 -2
- package/types/fetch/client/fetchClient.d.ts +3 -4
- package/types/fetch/fetchType/buildFetch.type.d.ts +12 -7
- package/types/fetch/fetchType/endpointFetch.type.d.ts +6 -7
- package/types/fetch/types.d.ts +3 -3
- package/types/signal/base.signal.d.ts +1 -1
|
@@ -200,7 +200,7 @@ export class ConstantRegistry {
|
|
|
200
200
|
_StateLight: null as unknown as GetStateObject<Light>,
|
|
201
201
|
_StateInsight: null as unknown as GetStateObject<Insight>,
|
|
202
202
|
};
|
|
203
|
-
ConstantRegistry.setDatabase(refName, cnst);
|
|
203
|
+
ConstantRegistry.setDatabase(refName, cnst as ConstantModel);
|
|
204
204
|
Object.entries(constExports).forEach(([key, value]) => {
|
|
205
205
|
if ((modelRefSet as Set<unknown>).has(value)) return;
|
|
206
206
|
else if (typeof value === "function" && isEnum(value as Cls))
|
package/constant/purify.ts
CHANGED
|
@@ -13,13 +13,7 @@ import {
|
|
|
13
13
|
} from "akanjs/base";
|
|
14
14
|
import { Logger } from "akanjs/common";
|
|
15
15
|
|
|
16
|
-
import {
|
|
17
|
-
type BaseObject,
|
|
18
|
-
type ConstantCls,
|
|
19
|
-
ConstantRegistry,
|
|
20
|
-
type DefaultOf,
|
|
21
|
-
type FieldProps,
|
|
22
|
-
} from ".";
|
|
16
|
+
import { type BaseObject, type ConstantCls, ConstantRegistry, type DefaultOf, type FieldProps } from ".";
|
|
23
17
|
|
|
24
18
|
type Purified<O> = O extends BaseObject
|
|
25
19
|
? string
|
|
@@ -30,15 +24,10 @@ type Purified<O> = O extends BaseObject
|
|
|
30
24
|
: O extends object
|
|
31
25
|
? PurifiedModel<O>
|
|
32
26
|
: O;
|
|
33
|
-
type PurifiedWithObjectToId<
|
|
34
|
-
T,
|
|
35
|
-
StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>,
|
|
36
|
-
> = {
|
|
27
|
+
type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
|
|
37
28
|
[K in StateKeys as null extends T[K] ? never : K]: Purified<T[K]>;
|
|
38
29
|
} & {
|
|
39
|
-
[K in StateKeys as null extends T[K] ? K : never]?:
|
|
40
|
-
| Purified<T[K]>
|
|
41
|
-
| undefined;
|
|
30
|
+
[K in StateKeys as null extends T[K] ? K : never]?: Purified<T[K]> | undefined;
|
|
42
31
|
};
|
|
43
32
|
export type PurifiedModel<T> = T extends Upload[]
|
|
44
33
|
? FileList
|
|
@@ -50,29 +39,20 @@ export type PurifiedModel<T> = T extends Upload[]
|
|
|
50
39
|
? Map<K, PurifiedModel<V>>
|
|
51
40
|
: PurifiedWithObjectToId<T>;
|
|
52
41
|
|
|
53
|
-
export type PurifyFunc<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
> = (self: _DefaultInput, isChild?: boolean) => _PurifiedInput | null;
|
|
42
|
+
export type PurifyFunc<Input, _DefaultInput = DefaultOf<Input>, _PurifiedInput = PurifiedModel<Input>> = (
|
|
43
|
+
self: _DefaultInput,
|
|
44
|
+
isChild?: boolean,
|
|
45
|
+
) => _PurifiedInput | null;
|
|
58
46
|
|
|
59
47
|
const getPurifyFn = (modelRef: Cls): ((value: unknown) => unknown) => {
|
|
60
48
|
const [valueRef] = getNonArrayModel(modelRef);
|
|
61
49
|
const purifyFn = PrimitiveRegistry.has(valueRef)
|
|
62
|
-
? (value: unknown) =>
|
|
63
|
-
(valueRef as unknown as typeof PrimitiveScalar)._serialize(
|
|
64
|
-
value as never,
|
|
65
|
-
)
|
|
50
|
+
? (value: unknown) => (valueRef as unknown as typeof PrimitiveScalar)._serialize(value as never)
|
|
66
51
|
: (value: unknown) => value as object;
|
|
67
52
|
return purifyFn;
|
|
68
53
|
};
|
|
69
54
|
|
|
70
|
-
const purify = (
|
|
71
|
-
field: FieldProps,
|
|
72
|
-
key: string,
|
|
73
|
-
value: unknown,
|
|
74
|
-
self: Record<string, unknown>,
|
|
75
|
-
): unknown => {
|
|
55
|
+
const purify = (field: FieldProps, key: string, value: unknown, self: Record<string, unknown>): unknown => {
|
|
76
56
|
|
|
77
57
|
if (
|
|
78
58
|
field.nullable &&
|
|
@@ -83,67 +63,30 @@ const purify = (
|
|
|
83
63
|
)
|
|
84
64
|
return null;
|
|
85
65
|
if (field.isArray) {
|
|
86
|
-
if (!Array.isArray(value))
|
|
87
|
-
throw new Error(`Invalid Array Value in ${key} for value ${value}`);
|
|
66
|
+
if (!Array.isArray(value)) throw new Error(`Invalid Array Value in ${key} for value ${value}`);
|
|
88
67
|
if (field.minlength && value.length < field.minlength)
|
|
89
|
-
throw new Error(
|
|
90
|
-
`Invalid Array Length (Min) in ${key} for value ${value}`,
|
|
91
|
-
);
|
|
68
|
+
throw new Error(`Invalid Array Length (Min) in ${key} for value ${value}`);
|
|
92
69
|
else if (field.maxlength && value.length > field.maxlength)
|
|
93
|
-
throw new Error(
|
|
94
|
-
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
field.optArrDepth === 0 &&
|
|
98
|
-
field.validate &&
|
|
99
|
-
!field.validate(value, self)
|
|
100
|
-
)
|
|
101
|
-
throw new Error(
|
|
102
|
-
`Invalid Array Value (Failed to pass validation) in ${key} for value ${value}`,
|
|
103
|
-
);
|
|
104
|
-
return value.map((v) =>
|
|
105
|
-
purify(
|
|
106
|
-
{ ...field, isArray: field.arrDepth > 1, arrDepth: field.arrDepth - 1 },
|
|
107
|
-
key,
|
|
108
|
-
v,
|
|
109
|
-
v,
|
|
110
|
-
),
|
|
111
|
-
);
|
|
70
|
+
throw new Error(`Invalid Array Length (Max) in ${key} for value ${value}`);
|
|
71
|
+
else if (field.optArrDepth === 0 && field.validate && !field.validate(value, self))
|
|
72
|
+
throw new Error(`Invalid Array Value (Failed to pass validation) in ${key} for value ${value}`);
|
|
73
|
+
return value.map((v) => purify({ ...field, isArray: field.arrDepth > 1, arrDepth: field.arrDepth - 1 }, key, v, v));
|
|
112
74
|
}
|
|
113
75
|
if (field.isMap && field.of) {
|
|
114
76
|
const purifyFn = PrimitiveRegistry.has(field.of as Cls)
|
|
115
77
|
? getPurifyFn(field.of as Cls)
|
|
116
|
-
: (value: unknown) =>
|
|
117
|
-
makePurify(field.of as ConstantCls)(value as object);
|
|
78
|
+
: (value: unknown) => makePurify(field.of as ConstantCls)(value as object);
|
|
118
79
|
return Object.fromEntries(
|
|
119
|
-
[...(value as Map<string, unknown>).entries()].map(([key, val]) => [
|
|
120
|
-
key,
|
|
121
|
-
applyFnToArrayObjects(val, purifyFn),
|
|
122
|
-
]),
|
|
80
|
+
[...(value as Map<string, unknown>).entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, purifyFn)]),
|
|
123
81
|
);
|
|
124
82
|
}
|
|
125
|
-
if (field.isClass)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
)
|
|
131
|
-
throw new Error(
|
|
132
|
-
`Invalid Date Value (Default) in ${key} for value ${value}`,
|
|
133
|
-
);
|
|
134
|
-
if (
|
|
135
|
-
[String, ID].includes(
|
|
136
|
-
field.modelRef as unknown as StringConstructor | typeof ID,
|
|
137
|
-
) &&
|
|
138
|
-
(value === "" || !value)
|
|
139
|
-
)
|
|
140
|
-
throw new Error(
|
|
141
|
-
`Invalid String Value (Default) in ${key} for value ${value}`,
|
|
142
|
-
);
|
|
83
|
+
if (field.isClass) return makePurify(field.modelRef)(value as object, true) as object;
|
|
84
|
+
if (field.modelRef === Date && dayjs(value as Date).isBefore(dayjs(new Date("0000"))))
|
|
85
|
+
throw new Error(`Invalid Date Value (Default) in ${key} for value ${value}`);
|
|
86
|
+
if ([String, ID].includes(field.modelRef as unknown as StringConstructor | typeof ID) && (value === "" || !value))
|
|
87
|
+
throw new Error(`Invalid String Value (Default) in ${key} for value ${value}`);
|
|
143
88
|
if (field.validate && !field.validate(value, self))
|
|
144
|
-
throw new Error(
|
|
145
|
-
`Invalid Value (Failed to pass validation) / ${value} in ${key}`,
|
|
146
|
-
);
|
|
89
|
+
throw new Error(`Invalid Value (Failed to pass validation) / ${value} in ${key}`);
|
|
147
90
|
if (!field.nullable && !value && value !== 0 && value !== false)
|
|
148
91
|
throw new Error(`Invalid Value (Nullable) in ${key} for value ${value}`);
|
|
149
92
|
|
package/constant/via.ts
CHANGED
|
@@ -172,6 +172,15 @@ export interface ConstantStatics<Schema = any, FieldObj extends FieldObject = Fi
|
|
|
172
172
|
relations: Set<ConstantCls>;
|
|
173
173
|
enums: Set<EnumInstance>;
|
|
174
174
|
text: { search: Set<string>; filter: Set<string>; children: { search: Set<string>; filter: Set<string> } };
|
|
175
|
+
_DatabaseSchema: {
|
|
176
|
+
[K in keyof Schema]: K extends keyof FieldObj
|
|
177
|
+
? FieldObj[K] extends ConstantField<infer FieldType, any, any, any, any, any>
|
|
178
|
+
? FieldType extends "hidden"
|
|
179
|
+
? NonNullable<Schema[K]>
|
|
180
|
+
: Schema[K]
|
|
181
|
+
: Schema[K]
|
|
182
|
+
: Schema[K];
|
|
183
|
+
};
|
|
175
184
|
}
|
|
176
185
|
export type ConstantCls<Schema = any, FieldObj extends FieldObject = FieldObject> = (new (
|
|
177
186
|
obj?: Partial<Schema>,
|
package/document/by.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { applyMixins } from "akanjs/common";
|
|
|
3
3
|
import {
|
|
4
4
|
type BaseObject,
|
|
5
5
|
type ConstantCls,
|
|
6
|
-
type ConstantField,
|
|
7
6
|
ConstantRegistry,
|
|
8
7
|
type DocumentModel,
|
|
9
8
|
type FieldObject,
|
|
@@ -23,19 +22,12 @@ type HydratedDocumentWithId<TDocument> = TDocument & { id: string } & DefaultDoc
|
|
|
23
22
|
export type Doc<M = any> = HydratedDocumentWithId<DocumentModel<M>>;
|
|
24
23
|
|
|
25
24
|
export const by = <
|
|
26
|
-
|
|
27
|
-
FieldObj extends FieldObject,
|
|
25
|
+
ModelCls,
|
|
28
26
|
AddDbModels extends DatabaseCls[],
|
|
29
|
-
_DatabaseSchema = Schema
|
|
30
|
-
|
|
31
|
-
? FieldType extends "hidden"
|
|
32
|
-
? K
|
|
33
|
-
: never
|
|
34
|
-
: never]: NonNullable<Schema[K]>;
|
|
35
|
-
},
|
|
36
|
-
_DocModel = Schema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>,
|
|
27
|
+
_DatabaseSchema = ModelCls extends { _DatabaseSchema: infer Schema } ? Schema : never,
|
|
28
|
+
_DocModel = _DatabaseSchema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>,
|
|
37
29
|
>(
|
|
38
|
-
modelRef:
|
|
30
|
+
modelRef: ModelCls,
|
|
39
31
|
...addRefs: AddDbModels
|
|
40
32
|
): DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel> => {
|
|
41
33
|
const refName = ConstantRegistry.getRefName(modelRef as Cls);
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
SerializedSlice,
|
|
11
11
|
ServiceSignal,
|
|
12
12
|
} from "akanjs/signal";
|
|
13
|
-
import type { ClientSignal, MergeAllFetchTypes, SliceMeta } from "../fetchType";
|
|
13
|
+
import type { ClientSignal, FetchClientType, FetchSignalInput, MergeAllFetchTypes, SliceMeta } from "../fetchType";
|
|
14
14
|
import { memoizeRequestQuery, cookies as requestCookies, headers as requestHeaders } from "../requestStorage";
|
|
15
15
|
import type { GetSliceMetaObjFromDatabaseSignals } from "../types";
|
|
16
16
|
import { type ErrorConstructor, HttpClient } from "./httpClient";
|
|
@@ -650,9 +650,7 @@ export class FetchClient {
|
|
|
650
650
|
if (typeof structuredClone === "function") return structuredClone(value);
|
|
651
651
|
return JSON.parse(JSON.stringify(value)) as T;
|
|
652
652
|
}
|
|
653
|
-
static from<
|
|
654
|
-
Signals extends (FetchProxy<any, any> | DatabaseSignal<any, any, any, any> | ServiceSignal<any, any, any>)[],
|
|
655
|
-
>(...signals: Signals): FetchProxy<MergeAllFetchTypes<Signals>, GetSliceMetaObjFromDatabaseSignals<Signals>> {
|
|
653
|
+
static from<Signals extends readonly FetchSignalInput[]>(...signals: Signals): FetchClientType<Signals> {
|
|
656
654
|
const serializedSignal: { [key: string]: SerializedSignal } = {};
|
|
657
655
|
const handler: Record<string, FetchHandler> = {};
|
|
658
656
|
signals.forEach((signal) => {
|
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DatabaseSignal, ServiceSignal } from "akanjs/signal";
|
|
1
|
+
import type { DatabaseSignal, EndpointCls, ServiceSignal, SliceCls } from "akanjs/signal";
|
|
3
2
|
import type { FetchProxy } from "../client";
|
|
3
|
+
import type { GetSliceMetaObjFromDatabaseSignals } from "../types";
|
|
4
4
|
import type { GetFetchTypeFromEndpoint } from "./endpointFetch.type";
|
|
5
5
|
import type { GetFetchTypeFromSlice } from "./sliceFetch.type";
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
export type FetchSignalInput = FetchProxy | DatabaseSignal | ServiceSignal;
|
|
8
|
+
|
|
9
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (
|
|
10
|
+
value: infer Intersection,
|
|
11
|
+
) => void
|
|
12
|
+
? Intersection
|
|
13
|
+
: never;
|
|
14
|
+
|
|
15
|
+
export type FetchTypeOfSignal<Signal extends FetchSignalInput> =
|
|
8
16
|
Signal extends FetchProxy<infer FetchType>
|
|
9
17
|
? FetchType
|
|
10
|
-
: Signal extends
|
|
18
|
+
: Signal extends { endpoint: infer EndpCls extends EndpointCls; slice: infer SlceCls extends SliceCls }
|
|
11
19
|
? GetFetchTypeFromEndpoint<EndpCls> & GetFetchTypeFromSlice<SlceCls>
|
|
12
|
-
: Signal extends
|
|
20
|
+
: Signal extends { endpoint: infer EndpCls extends EndpointCls }
|
|
13
21
|
? GetFetchTypeFromEndpoint<EndpCls>
|
|
14
22
|
: unknown;
|
|
15
23
|
|
|
16
|
-
export type MergeAllFetchTypes<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
: Acc;
|
|
24
|
+
export type MergeAllFetchTypes<Signals extends readonly FetchSignalInput[]> = [Signals[number]] extends [never]
|
|
25
|
+
? unknown
|
|
26
|
+
: UnionToIntersection<FetchTypeOfSignal<Signals[number]>>;
|
|
27
|
+
|
|
28
|
+
export type FetchClientType<Signals extends readonly FetchSignalInput[]> = FetchProxy<
|
|
29
|
+
MergeAllFetchTypes<Signals>,
|
|
30
|
+
GetSliceMetaObjFromDatabaseSignals<Signals>
|
|
31
|
+
>;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ENDPOINT_META, PromiseOrObject } from "akanjs/base";
|
|
2
2
|
import type { FetchPolicy } from "akanjs/common";
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
EndpInfoArgs,
|
|
5
|
+
EndpInfoClientReturns,
|
|
6
|
+
EndpInfoNullable,
|
|
7
|
+
EndpInfoReqType,
|
|
8
|
+
EndpointCls,
|
|
9
|
+
EndpointInfo,
|
|
10
|
+
} from "akanjs/signal";
|
|
4
11
|
|
|
5
|
-
type
|
|
6
|
-
type EndpInfoArgs<E> = E extends EndpointInfo<any, any, any, infer A, any, any, any, any, any, any> ? A : never;
|
|
7
|
-
type EndpInfoReturns<E> =
|
|
8
|
-
E extends EndpointInfo<any, any, any, any, any, any, any, infer R, any, infer N>
|
|
9
|
-
? R | (N extends true ? null : never)
|
|
10
|
-
: never;
|
|
12
|
+
type EndpInfoReturns<E> = EndpInfoClientReturns<E> | (EndpInfoNullable<E> extends true ? null : never);
|
|
11
13
|
|
|
12
14
|
type QueryOrMutationFetchFn<E> = (
|
|
13
15
|
...args: [...EndpInfoArgs<E>, fetchPolicy?: FetchPolicy]
|
|
@@ -24,18 +26,21 @@ type PubsubSubscribeFn<E> = (
|
|
|
24
26
|
...args: [...EndpInfoArgs<E>, handleEvent: (data: EndpInfoReturns<E>) => PromiseOrObject<void>, options?: FetchPolicy]
|
|
25
27
|
) => () => void;
|
|
26
28
|
|
|
27
|
-
type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
: EndpInfoType<EInfoObj[K]> extends "message"
|
|
33
|
-
? MessageEmitFn<EInfoObj[K]>
|
|
29
|
+
type PrimaryFetchFn<E> =
|
|
30
|
+
EndpInfoReqType<E> extends "query" | "mutation"
|
|
31
|
+
? QueryOrMutationFetchFn<E>
|
|
32
|
+
: EndpInfoReqType<E> extends "message"
|
|
33
|
+
? MessageEmitFn<E>
|
|
34
34
|
: never;
|
|
35
|
+
|
|
36
|
+
type PrimaryFetchType<EInfoObj extends { [key: string]: EndpointInfo }> = {
|
|
37
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "query" | "mutation" | "message"
|
|
38
|
+
? K
|
|
39
|
+
: never]: PrimaryFetchFn<EInfoObj[K]>;
|
|
35
40
|
};
|
|
36
41
|
|
|
37
42
|
type PubsubFetchType<EInfoObj extends { [key: string]: EndpointInfo }> = {
|
|
38
|
-
[K in keyof EInfoObj as
|
|
43
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "pubsub"
|
|
39
44
|
? K extends string
|
|
40
45
|
? `subscribe${Capitalize<K>}`
|
|
41
46
|
: never
|
|
@@ -43,7 +48,7 @@ type PubsubFetchType<EInfoObj extends { [key: string]: EndpointInfo }> = {
|
|
|
43
48
|
};
|
|
44
49
|
|
|
45
50
|
type MessageListenFetchType<EInfoObj extends { [key: string]: EndpointInfo }> = {
|
|
46
|
-
[K in keyof EInfoObj as
|
|
51
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "message"
|
|
47
52
|
? K extends string
|
|
48
53
|
? `listen${Capitalize<K>}`
|
|
49
54
|
: never
|
package/fetch/types.ts
CHANGED
|
@@ -12,17 +12,12 @@ export const getDefaultAccount = (): Account => {
|
|
|
12
12
|
return { appName: env.appName, environment: env.environment };
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
type GetSliceNameFromSignal<Signal> =
|
|
16
|
-
Signal
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
? Rest extends []
|
|
23
|
-
? GetSliceNameFromSignal<First>
|
|
24
|
-
: GetSliceNamesFromSignals<Rest> | GetSliceNameFromSignal<First>
|
|
25
|
-
: never;
|
|
26
|
-
export type GetSliceMetaObjFromDatabaseSignals<Signals extends unknown[]> = {
|
|
15
|
+
type GetSliceNameFromSignal<Signal> = Signal extends DatabaseSignal
|
|
16
|
+
? `${Signal["slice"]["baseName"]}${Capitalize<keyof Signal["slice"][typeof SLICE_META] & string>}`
|
|
17
|
+
: Signal extends { slice: { [K in infer Key]: SliceMeta } }
|
|
18
|
+
? Key
|
|
19
|
+
: never;
|
|
20
|
+
type GetSliceNamesFromSignals<Signals extends readonly unknown[]> = GetSliceNameFromSignal<Signals[number]>;
|
|
21
|
+
export type GetSliceMetaObjFromDatabaseSignals<Signals extends readonly unknown[]> = {
|
|
27
22
|
[K in GetSliceNamesFromSignals<Signals>]: SliceMeta;
|
|
28
23
|
};
|
package/package.json
CHANGED
package/types/constant/via.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Cls, type EnumInstance, FIELD_META, type MergeAllKeyOfObjects, type MergeAllTypes } from "akanjs/base";
|
|
2
|
-
import { type ExtractFieldInfoObject, type FieldBuilder, type FieldInfoObject, type FieldInfoObjectToFieldObject, type FieldObject, type FieldResolver } from "./fieldInfo.d.ts";
|
|
2
|
+
import { ConstantField, type ExtractFieldInfoObject, type FieldBuilder, type FieldInfoObject, type FieldInfoObjectToFieldObject, type FieldObject, type FieldResolver } from "./fieldInfo.d.ts";
|
|
3
3
|
import { type PurifyFunc } from "./purify.d.ts";
|
|
4
4
|
import type { BaseInsight, BaseObject, ConstantType, DefaultOf, NonFunctionalKeys } from "./types.d.ts";
|
|
5
5
|
type BaseFields = "id" | "createdAt" | "updatedAt" | "removedAt";
|
|
@@ -23,6 +23,9 @@ export interface ConstantStatics<Schema = any, FieldObj extends FieldObject = Fi
|
|
|
23
23
|
filter: Set<string>;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
+
_DatabaseSchema: {
|
|
27
|
+
[K in keyof Schema]: K extends keyof FieldObj ? FieldObj[K] extends ConstantField<infer FieldType, any, any, any, any, any> ? FieldType extends "hidden" ? NonNullable<Schema[K]> : Schema[K] : Schema[K] : Schema[K];
|
|
28
|
+
};
|
|
26
29
|
}
|
|
27
30
|
export type ConstantCls<Schema = any, FieldObj extends FieldObject = FieldObject> = (new (obj?: Partial<Schema>) => Schema & ConstantMethods<Schema>) & ConstantStatics<Schema, FieldObj>;
|
|
28
31
|
declare global {
|
package/types/document/by.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Cls, FIELD_META, type MergeAllActionTypes } from "akanjs/base";
|
|
2
|
-
import { type BaseObject, type
|
|
2
|
+
import { type BaseObject, type DocumentModel, type FieldObject } from "akanjs/constant";
|
|
3
3
|
export type DatabaseCls<Schema = any> = Cls<Schema, {
|
|
4
4
|
refName: string;
|
|
5
5
|
[FIELD_META]: FieldObject;
|
|
@@ -16,5 +16,7 @@ type HydratedDocumentWithId<TDocument> = TDocument & {
|
|
|
16
16
|
id: string;
|
|
17
17
|
} & DefaultDocMtds<TDocument>;
|
|
18
18
|
export type Doc<M = any> = HydratedDocumentWithId<DocumentModel<M>>;
|
|
19
|
-
export declare const by: <
|
|
19
|
+
export declare const by: <ModelCls, AddDbModels extends DatabaseCls[], _DatabaseSchema = ModelCls extends {
|
|
20
|
+
_DatabaseSchema: infer Schema;
|
|
21
|
+
} ? Schema : never, _DocModel = _DatabaseSchema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>>(modelRef: ModelCls, ...addRefs: AddDbModels) => DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel>;
|
|
20
22
|
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type PromiseOrObject } from "akanjs/base";
|
|
2
2
|
import { Logger } from "akanjs/common";
|
|
3
|
-
import type { DatabaseSignal, SerializedArg, SerializedEndpoint, SerializedSignal, SerializedSlice
|
|
4
|
-
import type { ClientSignal,
|
|
5
|
-
import type { GetSliceMetaObjFromDatabaseSignals } from "../types.d.ts";
|
|
3
|
+
import type { DatabaseSignal, SerializedArg, SerializedEndpoint, SerializedSignal, SerializedSlice } from "akanjs/signal";
|
|
4
|
+
import type { ClientSignal, FetchClientType, FetchSignalInput, SliceMeta } from "../fetchType.d.ts";
|
|
6
5
|
import { type ErrorConstructor, HttpClient } from "./httpClient.d.ts";
|
|
7
6
|
import { WsClient } from "./wsClient.d.ts";
|
|
8
7
|
type FetchHandler = (...args: unknown[]) => PromiseOrObject<unknown>;
|
|
@@ -63,7 +62,7 @@ export declare class FetchClient {
|
|
|
63
62
|
bodyArgs: SerializedArg[];
|
|
64
63
|
uploadArgs: SerializedArg[];
|
|
65
64
|
};
|
|
66
|
-
static from<Signals extends
|
|
65
|
+
static from<Signals extends readonly FetchSignalInput[]>(...signals: Signals): FetchClientType<Signals>;
|
|
67
66
|
static build<SigType extends {
|
|
68
67
|
fetch: any;
|
|
69
68
|
}>(constant: object, serializedSignal: {
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DatabaseSignal, ServiceSignal } from "akanjs/signal";
|
|
1
|
+
import type { DatabaseSignal, EndpointCls, ServiceSignal, SliceCls } from "akanjs/signal";
|
|
3
2
|
import type { FetchProxy } from "../client.d.ts";
|
|
3
|
+
import type { GetSliceMetaObjFromDatabaseSignals } from "../types.d.ts";
|
|
4
4
|
import type { GetFetchTypeFromEndpoint } from "./endpointFetch.type";
|
|
5
5
|
import type { GetFetchTypeFromSlice } from "./sliceFetch.type";
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export type FetchSignalInput = FetchProxy | DatabaseSignal | ServiceSignal;
|
|
7
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (value: infer Intersection) => void ? Intersection : never;
|
|
8
|
+
export type FetchTypeOfSignal<Signal extends FetchSignalInput> = Signal extends FetchProxy<infer FetchType> ? FetchType : Signal extends {
|
|
9
|
+
endpoint: infer EndpCls extends EndpointCls;
|
|
10
|
+
slice: infer SlceCls extends SliceCls;
|
|
11
|
+
} ? GetFetchTypeFromEndpoint<EndpCls> & GetFetchTypeFromSlice<SlceCls> : Signal extends {
|
|
12
|
+
endpoint: infer EndpCls extends EndpointCls;
|
|
13
|
+
} ? GetFetchTypeFromEndpoint<EndpCls> : unknown;
|
|
14
|
+
export type MergeAllFetchTypes<Signals extends readonly FetchSignalInput[]> = [Signals[number]] extends [never] ? unknown : UnionToIntersection<FetchTypeOfSignal<Signals[number]>>;
|
|
15
|
+
export type FetchClientType<Signals extends readonly FetchSignalInput[]> = FetchProxy<MergeAllFetchTypes<Signals>, GetSliceMetaObjFromDatabaseSignals<Signals>>;
|
|
11
16
|
export {};
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import type { ENDPOINT_META, PromiseOrObject } from "akanjs/base";
|
|
2
2
|
import type { FetchPolicy } from "akanjs/common";
|
|
3
|
-
import type { EndpointCls, EndpointInfo } from "akanjs/signal";
|
|
4
|
-
type
|
|
5
|
-
type EndpInfoArgs<E> = E extends EndpointInfo<any, any, any, infer A, any, any, any, any, any, any> ? A : never;
|
|
6
|
-
type EndpInfoReturns<E> = E extends EndpointInfo<any, any, any, any, any, any, any, infer R, any, infer N> ? R | (N extends true ? null : never) : never;
|
|
3
|
+
import type { EndpInfoArgs, EndpInfoClientReturns, EndpInfoNullable, EndpInfoReqType, EndpointCls, EndpointInfo } from "akanjs/signal";
|
|
4
|
+
type EndpInfoReturns<E> = EndpInfoClientReturns<E> | (EndpInfoNullable<E> extends true ? null : never);
|
|
7
5
|
type QueryOrMutationFetchFn<E> = (...args: [...EndpInfoArgs<E>, fetchPolicy?: FetchPolicy]) => Promise<EndpInfoReturns<E>>;
|
|
8
6
|
type MessageEmitFn<E> = (...args: EndpInfoArgs<E>) => EndpInfoReturns<E>;
|
|
9
7
|
type MessageListenFn<E> = (handleEvent: (data: EndpInfoReturns<E>) => PromiseOrObject<void>, options?: FetchPolicy) => () => void;
|
|
10
8
|
type PubsubSubscribeFn<E> = (...args: [...EndpInfoArgs<E>, handleEvent: (data: EndpInfoReturns<E>) => PromiseOrObject<void>, options?: FetchPolicy]) => () => void;
|
|
9
|
+
type PrimaryFetchFn<E> = EndpInfoReqType<E> extends "query" | "mutation" ? QueryOrMutationFetchFn<E> : EndpInfoReqType<E> extends "message" ? MessageEmitFn<E> : never;
|
|
11
10
|
type PrimaryFetchType<EInfoObj extends {
|
|
12
11
|
[key: string]: EndpointInfo;
|
|
13
12
|
}> = {
|
|
14
|
-
[K in keyof EInfoObj as
|
|
13
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "query" | "mutation" | "message" ? K : never]: PrimaryFetchFn<EInfoObj[K]>;
|
|
15
14
|
};
|
|
16
15
|
type PubsubFetchType<EInfoObj extends {
|
|
17
16
|
[key: string]: EndpointInfo;
|
|
18
17
|
}> = {
|
|
19
|
-
[K in keyof EInfoObj as
|
|
18
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "pubsub" ? K extends string ? `subscribe${Capitalize<K>}` : never : never]: PubsubSubscribeFn<EInfoObj[K]>;
|
|
20
19
|
};
|
|
21
20
|
type MessageListenFetchType<EInfoObj extends {
|
|
22
21
|
[key: string]: EndpointInfo;
|
|
23
22
|
}> = {
|
|
24
|
-
[K in keyof EInfoObj as
|
|
23
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "message" ? K extends string ? `listen${Capitalize<K>}` : never : never]: MessageListenFn<EInfoObj[K]>;
|
|
25
24
|
};
|
|
26
25
|
export type GetFetchTypeFromEndpoint<EndpCls extends EndpointCls, _EndpointInfoObj extends {
|
|
27
26
|
[key: string]: EndpointInfo;
|
package/types/fetch/types.d.ts
CHANGED
|
@@ -7,13 +7,13 @@ export type Account<AddData = unknown> = {
|
|
|
7
7
|
environment: Environment;
|
|
8
8
|
} & AddData;
|
|
9
9
|
export declare const getDefaultAccount: () => Account;
|
|
10
|
-
type GetSliceNameFromSignal<Signal> = Signal extends DatabaseSignal
|
|
10
|
+
type GetSliceNameFromSignal<Signal> = Signal extends DatabaseSignal ? `${Signal["slice"]["baseName"]}${Capitalize<keyof Signal["slice"][typeof SLICE_META] & string>}` : Signal extends {
|
|
11
11
|
slice: {
|
|
12
12
|
[K in infer Key]: SliceMeta;
|
|
13
13
|
};
|
|
14
14
|
} ? Key : never;
|
|
15
|
-
type GetSliceNamesFromSignals<Signals
|
|
16
|
-
export type GetSliceMetaObjFromDatabaseSignals<Signals extends unknown[]> = {
|
|
15
|
+
type GetSliceNamesFromSignals<Signals extends readonly unknown[]> = GetSliceNameFromSignal<Signals[number]>;
|
|
16
|
+
export type GetSliceMetaObjFromDatabaseSignals<Signals extends readonly unknown[]> = {
|
|
17
17
|
[K in GetSliceNamesFromSignals<Signals>]: SliceMeta;
|
|
18
18
|
};
|
|
19
19
|
export {};
|
|
@@ -31,7 +31,7 @@ declare const Base_base: import("./serverSignal.d.ts").ServerSignalCls<typeof Ba
|
|
|
31
31
|
export declare class Base extends Base_base {
|
|
32
32
|
}
|
|
33
33
|
export declare const base: import("./signalRegistry.d.ts").ServiceSignal<typeof BaseInternal, typeof BaseEndpoint, typeof Base>;
|
|
34
|
-
export declare const fetch: import("akanjs/fetch").
|
|
34
|
+
export declare const fetch: import("akanjs/fetch").FetchClientType<[import("./signalRegistry.d.ts").ServiceSignal<typeof BaseInternal, typeof BaseEndpoint, typeof Base>]>;
|
|
35
35
|
export declare const getSerializedSignal: () => {
|
|
36
36
|
[key: string]: import("./types.d.ts").SerializedSignal;
|
|
37
37
|
};
|