akanjs 2.3.2-rc.2 → 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/purify.ts +23 -80
- 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/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
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
|
|
|
@@ -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
|
@@ -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
|
};
|