akanjs 2.3.5-rc.0 → 2.3.5-rc.1
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.
|
@@ -10,81 +10,95 @@ import type {
|
|
|
10
10
|
SliceCls,
|
|
11
11
|
} from "akanjs/signal";
|
|
12
12
|
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
export type EndpointReturnContext<Full = unknown, Light = unknown, Insight = unknown> = {
|
|
14
|
+
full: Full;
|
|
15
|
+
light: Light;
|
|
16
|
+
insight: Insight;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type EndpointReturnContextOf<SlceCls extends SliceCls | never> = [SlceCls] extends [never]
|
|
20
|
+
? never
|
|
21
|
+
: SlceCls extends SliceCls
|
|
22
|
+
? EndpointReturnContext<
|
|
23
|
+
SlceCls["srv"]["cnst"]["_Full"],
|
|
24
|
+
SlceCls["srv"]["cnst"]["_Light"],
|
|
25
|
+
SlceCls["srv"]["cnst"]["_Insight"]
|
|
26
|
+
>
|
|
27
|
+
: never;
|
|
28
|
+
|
|
29
|
+
type ExtendedEndpointReturn<ClientReturns, Context> = ClientReturns extends (infer R)[]
|
|
30
|
+
? ExtendedEndpointReturn<R, Context>[]
|
|
31
|
+
: Context extends EndpointReturnContext<infer Full, infer Light, infer Insight>
|
|
32
|
+
? Full extends ClientReturns
|
|
33
|
+
? Full
|
|
34
|
+
: Light extends ClientReturns
|
|
35
|
+
? Light
|
|
36
|
+
: Insight extends ClientReturns
|
|
37
|
+
? Insight
|
|
38
|
+
: ClientReturns
|
|
39
|
+
: ClientReturns;
|
|
22
40
|
|
|
23
|
-
type EndpointClientReturns<E,
|
|
41
|
+
type EndpointClientReturns<E, Context> = [Context] extends [never]
|
|
24
42
|
? EndpInfoClientReturns<E>
|
|
25
|
-
: ExtendedEndpointReturn<
|
|
26
|
-
EndpInfoClientReturns<E>,
|
|
27
|
-
SlceCls["srv"]["cnst"]["_Full"],
|
|
28
|
-
SlceCls["srv"]["cnst"]["_Light"],
|
|
29
|
-
SlceCls["srv"]["cnst"]["_Insight"]
|
|
30
|
-
>;
|
|
43
|
+
: ExtendedEndpointReturn<EndpInfoClientReturns<E>, Context>;
|
|
31
44
|
|
|
32
|
-
type EndpInfoReturns<E,
|
|
33
|
-
| EndpointClientReturns<E,
|
|
45
|
+
type EndpInfoReturns<E, Context> =
|
|
46
|
+
| EndpointClientReturns<E, Context>
|
|
34
47
|
| (EndpInfoNullable<E> extends true ? null : never);
|
|
35
48
|
|
|
36
|
-
type QueryOrMutationFetchFn<E,
|
|
49
|
+
type QueryOrMutationFetchFn<E, Context> = (
|
|
37
50
|
...args: [...EndpInfoArgs<E>, fetchPolicy?: FetchPolicy]
|
|
38
|
-
) => Promise<EndpInfoReturns<E,
|
|
51
|
+
) => Promise<EndpInfoReturns<E, Context>>;
|
|
39
52
|
|
|
40
|
-
type MessageEmitFn<E,
|
|
53
|
+
type MessageEmitFn<E, Context> = (...args: EndpInfoArgs<E>) => EndpInfoReturns<E, Context>;
|
|
41
54
|
|
|
42
|
-
type MessageListenFn<E,
|
|
43
|
-
handleEvent: (data: EndpInfoReturns<E,
|
|
55
|
+
type MessageListenFn<E, Context> = (
|
|
56
|
+
handleEvent: (data: EndpInfoReturns<E, Context>) => PromiseOrObject<void>,
|
|
44
57
|
options?: FetchPolicy,
|
|
45
58
|
) => () => void;
|
|
46
59
|
|
|
47
|
-
type PubsubSubscribeFn<E,
|
|
60
|
+
type PubsubSubscribeFn<E, Context> = (
|
|
48
61
|
...args: [
|
|
49
62
|
...EndpInfoArgs<E>,
|
|
50
|
-
handleEvent: (data: EndpInfoReturns<E,
|
|
63
|
+
handleEvent: (data: EndpInfoReturns<E, Context>) => PromiseOrObject<void>,
|
|
51
64
|
options?: FetchPolicy,
|
|
52
65
|
]
|
|
53
66
|
) => () => void;
|
|
54
67
|
|
|
55
|
-
type PrimaryFetchFn<E,
|
|
68
|
+
type PrimaryFetchFn<E, Context> =
|
|
56
69
|
EndpInfoReqType<E> extends "query" | "mutation"
|
|
57
|
-
? QueryOrMutationFetchFn<E,
|
|
70
|
+
? QueryOrMutationFetchFn<E, Context>
|
|
58
71
|
: EndpInfoReqType<E> extends "message"
|
|
59
|
-
? MessageEmitFn<E,
|
|
72
|
+
? MessageEmitFn<E, Context>
|
|
60
73
|
: never;
|
|
61
74
|
|
|
62
|
-
type PrimaryFetchType<EInfoObj extends { [key: string]: EndpointInfo },
|
|
75
|
+
type PrimaryFetchType<EInfoObj extends { [key: string]: EndpointInfo }, Context> = {
|
|
63
76
|
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "query" | "mutation" | "message"
|
|
64
77
|
? K
|
|
65
|
-
: never]: PrimaryFetchFn<EInfoObj[K],
|
|
78
|
+
: never]: PrimaryFetchFn<EInfoObj[K], Context>;
|
|
66
79
|
};
|
|
67
80
|
|
|
68
|
-
type PubsubFetchType<EInfoObj extends { [key: string]: EndpointInfo },
|
|
81
|
+
type PubsubFetchType<EInfoObj extends { [key: string]: EndpointInfo }, Context> = {
|
|
69
82
|
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "pubsub"
|
|
70
83
|
? K extends string
|
|
71
84
|
? `subscribe${Capitalize<K>}`
|
|
72
85
|
: never
|
|
73
|
-
: never]: PubsubSubscribeFn<EInfoObj[K],
|
|
86
|
+
: never]: PubsubSubscribeFn<EInfoObj[K], Context>;
|
|
74
87
|
};
|
|
75
88
|
|
|
76
|
-
type MessageListenFetchType<EInfoObj extends { [key: string]: EndpointInfo },
|
|
89
|
+
type MessageListenFetchType<EInfoObj extends { [key: string]: EndpointInfo }, Context> = {
|
|
77
90
|
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "message"
|
|
78
91
|
? K extends string
|
|
79
92
|
? `listen${Capitalize<K>}`
|
|
80
93
|
: never
|
|
81
|
-
: never]: MessageListenFn<EInfoObj[K],
|
|
94
|
+
: never]: MessageListenFn<EInfoObj[K], Context>;
|
|
82
95
|
};
|
|
83
96
|
|
|
84
97
|
export type GetFetchTypeFromEndpoint<
|
|
85
98
|
EndpCls extends EndpointCls,
|
|
86
99
|
SlceCls extends SliceCls | never = never,
|
|
87
100
|
_EndpointInfoObj extends { [key: string]: EndpointInfo } = EndpCls[typeof ENDPOINT_META],
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
_ReturnContext = EndpointReturnContextOf<SlceCls>,
|
|
102
|
+
> = PrimaryFetchType<_EndpointInfoObj, _ReturnContext> &
|
|
103
|
+
PubsubFetchType<_EndpointInfoObj, _ReturnContext> &
|
|
104
|
+
MessageListenFetchType<_EndpointInfoObj, _ReturnContext>;
|
|
@@ -2,104 +2,164 @@ import type { GetStateObject, SLICE_META } from "akanjs/base";
|
|
|
2
2
|
import type { FetchPolicy } from "akanjs/common";
|
|
3
3
|
import type { ConstantModel, DefaultOf, ProtoFile, PurifiedModel } from "akanjs/constant";
|
|
4
4
|
import type { DatabaseModel, ExtractSort, FilterInstance } from "akanjs/document";
|
|
5
|
-
import type { SliceCls, SliceInfoArgs } from "akanjs/signal";
|
|
5
|
+
import type { SliceCls, SliceInfo, SliceInfoArgs } from "akanjs/signal";
|
|
6
6
|
import type { ClientEdit, ClientInit, ClientView, EditReturn, InitReturn, ViewReturn } from "./appliedReturn.type";
|
|
7
7
|
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
type _Cap<S extends SliceCls> = S["srv"]["cnst"]["_CapitalizedRefName"];
|
|
11
|
-
type _Input<S extends SliceCls> = S["srv"]["cnst"]["_Input"];
|
|
12
|
-
type _Full<S extends SliceCls> = S["srv"]["cnst"]["_Full"];
|
|
13
|
-
type _Light<S extends SliceCls> = S["srv"]["cnst"]["_Light"];
|
|
14
|
-
type _Insight<S extends SliceCls> = S["srv"]["cnst"]["_Insight"];
|
|
15
|
-
type _PurifiedInput<S extends SliceCls> = S["srv"]["cnst"]["_PurifiedInput"];
|
|
16
|
-
type _DefaultInput<S extends SliceCls> = S["srv"]["cnst"]["_DefaultInput"];
|
|
17
|
-
type _StateLight<S extends SliceCls> = S["srv"]["cnst"]["_StateLight"];
|
|
18
|
-
type _StateInsight<S extends SliceCls> = S["srv"]["cnst"]["_StateInsight"];
|
|
19
|
-
type _Filter<S extends SliceCls> = S["srv"]["db"]["_Filter"];
|
|
20
|
-
type _Sort<S extends SliceCls> = S["srv"]["db"]["_Sort"];
|
|
21
|
-
type _LightWithId<S extends SliceCls> = _Light<S> extends { id: string } ? _Light<S> : { id: string };
|
|
22
|
-
type _SliceFetchInitOption<S extends SliceCls> = FetchInitOption<_Input<S>, _Filter<S>, _DefaultInput<S>, _Sort<S>>;
|
|
8
|
+
type SliceInfoMap = { [key: string]: SliceInfo };
|
|
9
|
+
type LightWithId<Light> = Light extends { id: string } ? Light : { id: string };
|
|
23
10
|
|
|
24
|
-
type
|
|
25
|
-
|
|
11
|
+
export type SliceFetchDescriptor<
|
|
12
|
+
SliceMap extends SliceInfoMap = SliceInfoMap,
|
|
13
|
+
RefName extends string = string,
|
|
14
|
+
CapRefName extends string = Capitalize<RefName>,
|
|
15
|
+
Input = unknown,
|
|
16
|
+
Full = unknown,
|
|
17
|
+
Light = unknown,
|
|
18
|
+
Insight = unknown,
|
|
19
|
+
PurifiedInput = PurifiedModel<Input>,
|
|
20
|
+
DefaultInput = DefaultOf<Input>,
|
|
21
|
+
StateLight = GetStateObject<LightWithId<Light>>,
|
|
22
|
+
StateInsight = GetStateObject<Insight>,
|
|
23
|
+
Filter extends FilterInstance = FilterInstance,
|
|
24
|
+
Sort = ExtractSort<Filter>,
|
|
25
|
+
> = {
|
|
26
|
+
sliceMap: SliceMap;
|
|
27
|
+
refName: RefName;
|
|
28
|
+
capRefName: CapRefName;
|
|
29
|
+
input: Input;
|
|
30
|
+
full: Full;
|
|
31
|
+
light: Light;
|
|
32
|
+
insight: Insight;
|
|
33
|
+
purifiedInput: PurifiedInput;
|
|
34
|
+
defaultInput: DefaultInput;
|
|
35
|
+
stateLight: StateLight;
|
|
36
|
+
stateInsight: StateInsight;
|
|
37
|
+
filter: Filter;
|
|
38
|
+
sort: Sort;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type SliceFetchDescriptorOf<SlceCls extends SliceCls> = SlceCls["srv"]["cnst"] extends ConstantModel
|
|
42
|
+
? SlceCls["srv"]["db"] extends DatabaseModel
|
|
43
|
+
? SliceFetchDescriptor<
|
|
44
|
+
SlceCls[typeof SLICE_META],
|
|
45
|
+
SlceCls["srv"]["cnst"]["refName"],
|
|
46
|
+
SlceCls["srv"]["cnst"]["_CapitalizedRefName"],
|
|
47
|
+
SlceCls["srv"]["cnst"]["_Input"],
|
|
48
|
+
SlceCls["srv"]["cnst"]["_Full"],
|
|
49
|
+
SlceCls["srv"]["cnst"]["_Light"],
|
|
50
|
+
SlceCls["srv"]["cnst"]["_Insight"],
|
|
51
|
+
SlceCls["srv"]["cnst"]["_PurifiedInput"],
|
|
52
|
+
SlceCls["srv"]["cnst"]["_DefaultInput"],
|
|
53
|
+
GetStateObject<LightWithId<SlceCls["srv"]["cnst"]["_Light"]>>,
|
|
54
|
+
GetStateObject<SlceCls["srv"]["cnst"]["_Insight"]>,
|
|
55
|
+
SlceCls["srv"]["db"]["_Filter"],
|
|
56
|
+
SlceCls["srv"]["db"]["_Sort"]
|
|
57
|
+
>
|
|
58
|
+
: never
|
|
59
|
+
: never;
|
|
60
|
+
|
|
61
|
+
type _SliceMap<D extends SliceFetchDescriptor> = D["sliceMap"];
|
|
62
|
+
type _RefName<D extends SliceFetchDescriptor> = D["refName"];
|
|
63
|
+
type _Cap<D extends SliceFetchDescriptor> = D["capRefName"];
|
|
64
|
+
type _Input<D extends SliceFetchDescriptor> = D["input"];
|
|
65
|
+
type _Full<D extends SliceFetchDescriptor> = D["full"];
|
|
66
|
+
type _Light<D extends SliceFetchDescriptor> = D["light"];
|
|
67
|
+
type _Insight<D extends SliceFetchDescriptor> = D["insight"];
|
|
68
|
+
type _PurifiedInput<D extends SliceFetchDescriptor> = D["purifiedInput"];
|
|
69
|
+
type _DefaultInput<D extends SliceFetchDescriptor> = D["defaultInput"];
|
|
70
|
+
type _StateLight<D extends SliceFetchDescriptor> = D["stateLight"];
|
|
71
|
+
type _StateInsight<D extends SliceFetchDescriptor> = D["stateInsight"];
|
|
72
|
+
type _Filter<D extends SliceFetchDescriptor> = D["filter"];
|
|
73
|
+
type _Sort<D extends SliceFetchDescriptor> = D["sort"];
|
|
74
|
+
type _LightWithId<D extends SliceFetchDescriptor> = LightWithId<_Light<D>>;
|
|
75
|
+
type _SliceFetchInitOption<D extends SliceFetchDescriptor> = FetchInitOption<
|
|
76
|
+
_Input<D>,
|
|
77
|
+
_Filter<D>,
|
|
78
|
+
_DefaultInput<D>,
|
|
79
|
+
_Sort<D>
|
|
80
|
+
>;
|
|
81
|
+
|
|
82
|
+
type SliceListFetch<D extends SliceFetchDescriptor> = {
|
|
83
|
+
[Suffix in keyof _SliceMap<D> as Suffix extends string ? `${_RefName<D>}List${Capitalize<Suffix>}` : never]: (
|
|
26
84
|
...args: [
|
|
27
|
-
...SliceInfoArgs<_SliceMap<
|
|
85
|
+
...SliceInfoArgs<_SliceMap<D>[Suffix]>,
|
|
28
86
|
skip?: number | null,
|
|
29
87
|
limit?: number | null,
|
|
30
|
-
sort?: _Sort<
|
|
88
|
+
sort?: _Sort<D> | null,
|
|
31
89
|
fetchPolicy?: FetchPolicy,
|
|
32
90
|
]
|
|
33
|
-
) => Promise<_Light<
|
|
91
|
+
) => Promise<_Light<D>[]>;
|
|
34
92
|
};
|
|
35
93
|
|
|
36
|
-
type SliceInsightFetch<
|
|
37
|
-
[Suffix in keyof _SliceMap<
|
|
38
|
-
...args: [...SliceInfoArgs<_SliceMap<
|
|
39
|
-
) => Promise<_Insight<
|
|
94
|
+
type SliceInsightFetch<D extends SliceFetchDescriptor> = {
|
|
95
|
+
[Suffix in keyof _SliceMap<D> as Suffix extends string ? `${_RefName<D>}Insight${Capitalize<Suffix>}` : never]: (
|
|
96
|
+
...args: [...SliceInfoArgs<_SliceMap<D>[Suffix]>, fetchPolicy?: FetchPolicy]
|
|
97
|
+
) => Promise<_Insight<D>>;
|
|
40
98
|
};
|
|
41
99
|
|
|
42
|
-
type SliceInitFetch<
|
|
43
|
-
[Suffix in keyof _SliceMap<
|
|
44
|
-
...args: [...SliceInfoArgs<_SliceMap<
|
|
100
|
+
type SliceInitFetch<D extends SliceFetchDescriptor> = {
|
|
101
|
+
[Suffix in keyof _SliceMap<D> as Suffix extends string ? `init${_Cap<D>}${Capitalize<Suffix>}` : never]: (
|
|
102
|
+
...args: [...SliceInfoArgs<_SliceMap<D>[Suffix]>, option?: _SliceFetchInitOption<D>]
|
|
45
103
|
) => Promise<
|
|
46
104
|
InitReturn<
|
|
47
|
-
_RefName<
|
|
105
|
+
_RefName<D>,
|
|
48
106
|
Suffix & string,
|
|
49
|
-
_Light<
|
|
50
|
-
_Insight<
|
|
51
|
-
SliceInfoArgs<_SliceMap<
|
|
52
|
-
_Filter<
|
|
53
|
-
_Cap<
|
|
107
|
+
_Light<D>,
|
|
108
|
+
_Insight<D>,
|
|
109
|
+
SliceInfoArgs<_SliceMap<D>[Suffix]>,
|
|
110
|
+
_Filter<D>,
|
|
111
|
+
_Cap<D>,
|
|
54
112
|
Suffix extends string ? Capitalize<Suffix> : never,
|
|
55
|
-
_LightWithId<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
_Sort<
|
|
113
|
+
_LightWithId<D>,
|
|
114
|
+
_StateLight<D>,
|
|
115
|
+
_StateInsight<D>,
|
|
116
|
+
_Sort<D>
|
|
59
117
|
>
|
|
60
118
|
>;
|
|
61
119
|
};
|
|
62
120
|
|
|
63
|
-
type SliceGetInitFetch<
|
|
64
|
-
[Suffix in keyof _SliceMap<
|
|
65
|
-
...args: [...SliceInfoArgs<_SliceMap<
|
|
121
|
+
type SliceGetInitFetch<D extends SliceFetchDescriptor> = {
|
|
122
|
+
[Suffix in keyof _SliceMap<D> as Suffix extends string ? `get${_Cap<D>}Init${Capitalize<Suffix>}` : never]: (
|
|
123
|
+
...args: [...SliceInfoArgs<_SliceMap<D>[Suffix]>, option?: _SliceFetchInitOption<D>]
|
|
66
124
|
) => ClientInit<
|
|
67
|
-
_RefName<
|
|
68
|
-
_Light<
|
|
69
|
-
_Insight<
|
|
70
|
-
SliceInfoArgs<_SliceMap<
|
|
71
|
-
_Filter<
|
|
72
|
-
_Cap<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
_Sort<
|
|
125
|
+
_RefName<D>,
|
|
126
|
+
_Light<D>,
|
|
127
|
+
_Insight<D>,
|
|
128
|
+
SliceInfoArgs<_SliceMap<D>[Suffix]>,
|
|
129
|
+
_Filter<D>,
|
|
130
|
+
_Cap<D>,
|
|
131
|
+
_StateLight<D>,
|
|
132
|
+
_StateInsight<D>,
|
|
133
|
+
_Sort<D>
|
|
76
134
|
>;
|
|
77
135
|
};
|
|
78
136
|
|
|
79
|
-
export type
|
|
80
|
-
?
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
>
|
|
100
|
-
: never
|
|
137
|
+
export type GetFetchTypeFromSliceDescriptor<Descriptor> = [Descriptor] extends [SliceFetchDescriptor]
|
|
138
|
+
? SliceListFetch<Descriptor> &
|
|
139
|
+
SliceInsightFetch<Descriptor> &
|
|
140
|
+
SliceInitFetch<Descriptor> &
|
|
141
|
+
SliceGetInitFetch<Descriptor> &
|
|
142
|
+
RawBaseSliceFetchType<
|
|
143
|
+
_RefName<Descriptor>,
|
|
144
|
+
_Input<Descriptor>,
|
|
145
|
+
_Full<Descriptor>,
|
|
146
|
+
_Light<Descriptor>,
|
|
147
|
+
_Cap<Descriptor>,
|
|
148
|
+
_PurifiedInput<Descriptor>
|
|
149
|
+
> &
|
|
150
|
+
AppliedBaseSliceFetchType<
|
|
151
|
+
_RefName<Descriptor>,
|
|
152
|
+
_Input<Descriptor>,
|
|
153
|
+
_Full<Descriptor>,
|
|
154
|
+
_Cap<Descriptor>,
|
|
155
|
+
_PurifiedInput<Descriptor>
|
|
156
|
+
>
|
|
101
157
|
: never;
|
|
102
158
|
|
|
159
|
+
export type GetFetchTypeFromSlice<SlceCls extends SliceCls> = GetFetchTypeFromSliceDescriptor<
|
|
160
|
+
SliceFetchDescriptorOf<SlceCls>
|
|
161
|
+
>;
|
|
162
|
+
|
|
103
163
|
type RawBaseSliceFetchType<
|
|
104
164
|
RefName extends string,
|
|
105
165
|
Input,
|
package/package.json
CHANGED
|
@@ -1,34 +1,40 @@
|
|
|
1
1
|
import type { ENDPOINT_META, PromiseOrObject } from "akanjs/base";
|
|
2
2
|
import type { FetchPolicy } from "akanjs/common";
|
|
3
3
|
import type { EndpInfoArgs, EndpInfoClientReturns, EndpInfoNullable, EndpInfoReqType, EndpointCls, EndpointInfo, SliceCls } from "akanjs/signal";
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
type
|
|
4
|
+
export type EndpointReturnContext<Full = unknown, Light = unknown, Insight = unknown> = {
|
|
5
|
+
full: Full;
|
|
6
|
+
light: Light;
|
|
7
|
+
insight: Insight;
|
|
8
|
+
};
|
|
9
|
+
type EndpointReturnContextOf<SlceCls extends SliceCls | never> = [SlceCls] extends [never] ? never : SlceCls extends SliceCls ? EndpointReturnContext<SlceCls["srv"]["cnst"]["_Full"], SlceCls["srv"]["cnst"]["_Light"], SlceCls["srv"]["cnst"]["_Insight"]> : never;
|
|
10
|
+
type ExtendedEndpointReturn<ClientReturns, Context> = ClientReturns extends (infer R)[] ? ExtendedEndpointReturn<R, Context>[] : Context extends EndpointReturnContext<infer Full, infer Light, infer Insight> ? Full extends ClientReturns ? Full : Light extends ClientReturns ? Light : Insight extends ClientReturns ? Insight : ClientReturns : ClientReturns;
|
|
11
|
+
type EndpointClientReturns<E, Context> = [Context] extends [never] ? EndpInfoClientReturns<E> : ExtendedEndpointReturn<EndpInfoClientReturns<E>, Context>;
|
|
12
|
+
type EndpInfoReturns<E, Context> = EndpointClientReturns<E, Context> | (EndpInfoNullable<E> extends true ? null : never);
|
|
13
|
+
type QueryOrMutationFetchFn<E, Context> = (...args: [...EndpInfoArgs<E>, fetchPolicy?: FetchPolicy]) => Promise<EndpInfoReturns<E, Context>>;
|
|
14
|
+
type MessageEmitFn<E, Context> = (...args: EndpInfoArgs<E>) => EndpInfoReturns<E, Context>;
|
|
15
|
+
type MessageListenFn<E, Context> = (handleEvent: (data: EndpInfoReturns<E, Context>) => PromiseOrObject<void>, options?: FetchPolicy) => () => void;
|
|
16
|
+
type PubsubSubscribeFn<E, Context> = (...args: [
|
|
11
17
|
...EndpInfoArgs<E>,
|
|
12
|
-
handleEvent: (data: EndpInfoReturns<E,
|
|
18
|
+
handleEvent: (data: EndpInfoReturns<E, Context>) => PromiseOrObject<void>,
|
|
13
19
|
options?: FetchPolicy
|
|
14
20
|
]) => () => void;
|
|
15
|
-
type PrimaryFetchFn<E,
|
|
21
|
+
type PrimaryFetchFn<E, Context> = EndpInfoReqType<E> extends "query" | "mutation" ? QueryOrMutationFetchFn<E, Context> : EndpInfoReqType<E> extends "message" ? MessageEmitFn<E, Context> : never;
|
|
16
22
|
type PrimaryFetchType<EInfoObj extends {
|
|
17
23
|
[key: string]: EndpointInfo;
|
|
18
|
-
},
|
|
19
|
-
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "query" | "mutation" | "message" ? K : never]: PrimaryFetchFn<EInfoObj[K],
|
|
24
|
+
}, Context> = {
|
|
25
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "query" | "mutation" | "message" ? K : never]: PrimaryFetchFn<EInfoObj[K], Context>;
|
|
20
26
|
};
|
|
21
27
|
type PubsubFetchType<EInfoObj extends {
|
|
22
28
|
[key: string]: EndpointInfo;
|
|
23
|
-
},
|
|
24
|
-
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "pubsub" ? K extends string ? `subscribe${Capitalize<K>}` : never : never]: PubsubSubscribeFn<EInfoObj[K],
|
|
29
|
+
}, Context> = {
|
|
30
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "pubsub" ? K extends string ? `subscribe${Capitalize<K>}` : never : never]: PubsubSubscribeFn<EInfoObj[K], Context>;
|
|
25
31
|
};
|
|
26
32
|
type MessageListenFetchType<EInfoObj extends {
|
|
27
33
|
[key: string]: EndpointInfo;
|
|
28
|
-
},
|
|
29
|
-
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "message" ? K extends string ? `listen${Capitalize<K>}` : never : never]: MessageListenFn<EInfoObj[K],
|
|
34
|
+
}, Context> = {
|
|
35
|
+
[K in keyof EInfoObj as EndpInfoReqType<EInfoObj[K]> extends "message" ? K extends string ? `listen${Capitalize<K>}` : never : never]: MessageListenFn<EInfoObj[K], Context>;
|
|
30
36
|
};
|
|
31
37
|
export type GetFetchTypeFromEndpoint<EndpCls extends EndpointCls, SlceCls extends SliceCls | never = never, _EndpointInfoObj extends {
|
|
32
38
|
[key: string]: EndpointInfo;
|
|
33
|
-
} = EndpCls[typeof ENDPOINT_META]
|
|
39
|
+
} = EndpCls[typeof ENDPOINT_META], _ReturnContext = EndpointReturnContextOf<SlceCls>> = PrimaryFetchType<_EndpointInfoObj, _ReturnContext> & PubsubFetchType<_EndpointInfoObj, _ReturnContext> & MessageListenFetchType<_EndpointInfoObj, _ReturnContext>;
|
|
34
40
|
export {};
|
|
@@ -2,44 +2,67 @@ import type { GetStateObject, SLICE_META } from "akanjs/base";
|
|
|
2
2
|
import type { FetchPolicy } from "akanjs/common";
|
|
3
3
|
import type { ConstantModel, DefaultOf, ProtoFile, PurifiedModel } from "akanjs/constant";
|
|
4
4
|
import type { DatabaseModel, ExtractSort, FilterInstance } from "akanjs/document";
|
|
5
|
-
import type { SliceCls, SliceInfoArgs } from "akanjs/signal";
|
|
5
|
+
import type { SliceCls, SliceInfo, SliceInfoArgs } from "akanjs/signal";
|
|
6
6
|
import type { ClientEdit, ClientInit, ClientView, EditReturn, InitReturn, ViewReturn } from "./appliedReturn.type";
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
type _Full<S extends SliceCls> = S["srv"]["cnst"]["_Full"];
|
|
12
|
-
type _Light<S extends SliceCls> = S["srv"]["cnst"]["_Light"];
|
|
13
|
-
type _Insight<S extends SliceCls> = S["srv"]["cnst"]["_Insight"];
|
|
14
|
-
type _PurifiedInput<S extends SliceCls> = S["srv"]["cnst"]["_PurifiedInput"];
|
|
15
|
-
type _DefaultInput<S extends SliceCls> = S["srv"]["cnst"]["_DefaultInput"];
|
|
16
|
-
type _Filter<S extends SliceCls> = S["srv"]["db"]["_Filter"];
|
|
17
|
-
type _Sort<S extends SliceCls> = S["srv"]["db"]["_Sort"];
|
|
18
|
-
type _LightWithId<S extends SliceCls> = _Light<S> extends {
|
|
7
|
+
type SliceInfoMap = {
|
|
8
|
+
[key: string]: SliceInfo;
|
|
9
|
+
};
|
|
10
|
+
type LightWithId<Light> = Light extends {
|
|
19
11
|
id: string;
|
|
20
|
-
} ?
|
|
12
|
+
} ? Light : {
|
|
21
13
|
id: string;
|
|
22
14
|
};
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
export type SliceFetchDescriptor<SliceMap extends SliceInfoMap = SliceInfoMap, RefName extends string = string, CapRefName extends string = Capitalize<RefName>, Input = unknown, Full = unknown, Light = unknown, Insight = unknown, PurifiedInput = PurifiedModel<Input>, DefaultInput = DefaultOf<Input>, StateLight = GetStateObject<LightWithId<Light>>, StateInsight = GetStateObject<Insight>, Filter extends FilterInstance = FilterInstance, Sort = ExtractSort<Filter>> = {
|
|
16
|
+
sliceMap: SliceMap;
|
|
17
|
+
refName: RefName;
|
|
18
|
+
capRefName: CapRefName;
|
|
19
|
+
input: Input;
|
|
20
|
+
full: Full;
|
|
21
|
+
light: Light;
|
|
22
|
+
insight: Insight;
|
|
23
|
+
purifiedInput: PurifiedInput;
|
|
24
|
+
defaultInput: DefaultInput;
|
|
25
|
+
stateLight: StateLight;
|
|
26
|
+
stateInsight: StateInsight;
|
|
27
|
+
filter: Filter;
|
|
28
|
+
sort: Sort;
|
|
29
|
+
};
|
|
30
|
+
export type SliceFetchDescriptorOf<SlceCls extends SliceCls> = SlceCls["srv"]["cnst"] extends ConstantModel ? SlceCls["srv"]["db"] extends DatabaseModel ? SliceFetchDescriptor<SlceCls[typeof SLICE_META], SlceCls["srv"]["cnst"]["refName"], SlceCls["srv"]["cnst"]["_CapitalizedRefName"], SlceCls["srv"]["cnst"]["_Input"], SlceCls["srv"]["cnst"]["_Full"], SlceCls["srv"]["cnst"]["_Light"], SlceCls["srv"]["cnst"]["_Insight"], SlceCls["srv"]["cnst"]["_PurifiedInput"], SlceCls["srv"]["cnst"]["_DefaultInput"], GetStateObject<LightWithId<SlceCls["srv"]["cnst"]["_Light"]>>, GetStateObject<SlceCls["srv"]["cnst"]["_Insight"]>, SlceCls["srv"]["db"]["_Filter"], SlceCls["srv"]["db"]["_Sort"]> : never : never;
|
|
31
|
+
type _SliceMap<D extends SliceFetchDescriptor> = D["sliceMap"];
|
|
32
|
+
type _RefName<D extends SliceFetchDescriptor> = D["refName"];
|
|
33
|
+
type _Cap<D extends SliceFetchDescriptor> = D["capRefName"];
|
|
34
|
+
type _Input<D extends SliceFetchDescriptor> = D["input"];
|
|
35
|
+
type _Full<D extends SliceFetchDescriptor> = D["full"];
|
|
36
|
+
type _Light<D extends SliceFetchDescriptor> = D["light"];
|
|
37
|
+
type _Insight<D extends SliceFetchDescriptor> = D["insight"];
|
|
38
|
+
type _PurifiedInput<D extends SliceFetchDescriptor> = D["purifiedInput"];
|
|
39
|
+
type _DefaultInput<D extends SliceFetchDescriptor> = D["defaultInput"];
|
|
40
|
+
type _StateLight<D extends SliceFetchDescriptor> = D["stateLight"];
|
|
41
|
+
type _StateInsight<D extends SliceFetchDescriptor> = D["stateInsight"];
|
|
42
|
+
type _Filter<D extends SliceFetchDescriptor> = D["filter"];
|
|
43
|
+
type _Sort<D extends SliceFetchDescriptor> = D["sort"];
|
|
44
|
+
type _LightWithId<D extends SliceFetchDescriptor> = LightWithId<_Light<D>>;
|
|
45
|
+
type _SliceFetchInitOption<D extends SliceFetchDescriptor> = FetchInitOption<_Input<D>, _Filter<D>, _DefaultInput<D>, _Sort<D>>;
|
|
46
|
+
type SliceListFetch<D extends SliceFetchDescriptor> = {
|
|
47
|
+
[Suffix in keyof _SliceMap<D> as Suffix extends string ? `${_RefName<D>}List${Capitalize<Suffix>}` : never]: (...args: [
|
|
48
|
+
...SliceInfoArgs<_SliceMap<D>[Suffix]>,
|
|
27
49
|
skip?: number | null,
|
|
28
50
|
limit?: number | null,
|
|
29
|
-
sort?: _Sort<
|
|
51
|
+
sort?: _Sort<D> | null,
|
|
30
52
|
fetchPolicy?: FetchPolicy
|
|
31
|
-
]) => Promise<_Light<
|
|
53
|
+
]) => Promise<_Light<D>[]>;
|
|
32
54
|
};
|
|
33
|
-
type SliceInsightFetch<
|
|
34
|
-
[Suffix in keyof _SliceMap<
|
|
55
|
+
type SliceInsightFetch<D extends SliceFetchDescriptor> = {
|
|
56
|
+
[Suffix in keyof _SliceMap<D> as Suffix extends string ? `${_RefName<D>}Insight${Capitalize<Suffix>}` : never]: (...args: [...SliceInfoArgs<_SliceMap<D>[Suffix]>, fetchPolicy?: FetchPolicy]) => Promise<_Insight<D>>;
|
|
35
57
|
};
|
|
36
|
-
type SliceInitFetch<
|
|
37
|
-
[Suffix in keyof _SliceMap<
|
|
58
|
+
type SliceInitFetch<D extends SliceFetchDescriptor> = {
|
|
59
|
+
[Suffix in keyof _SliceMap<D> as Suffix extends string ? `init${_Cap<D>}${Capitalize<Suffix>}` : never]: (...args: [...SliceInfoArgs<_SliceMap<D>[Suffix]>, option?: _SliceFetchInitOption<D>]) => Promise<InitReturn<_RefName<D>, Suffix & string, _Light<D>, _Insight<D>, SliceInfoArgs<_SliceMap<D>[Suffix]>, _Filter<D>, _Cap<D>, Suffix extends string ? Capitalize<Suffix> : never, _LightWithId<D>, _StateLight<D>, _StateInsight<D>, _Sort<D>>>;
|
|
38
60
|
};
|
|
39
|
-
type SliceGetInitFetch<
|
|
40
|
-
[Suffix in keyof _SliceMap<
|
|
61
|
+
type SliceGetInitFetch<D extends SliceFetchDescriptor> = {
|
|
62
|
+
[Suffix in keyof _SliceMap<D> as Suffix extends string ? `get${_Cap<D>}Init${Capitalize<Suffix>}` : never]: (...args: [...SliceInfoArgs<_SliceMap<D>[Suffix]>, option?: _SliceFetchInitOption<D>]) => ClientInit<_RefName<D>, _Light<D>, _Insight<D>, SliceInfoArgs<_SliceMap<D>[Suffix]>, _Filter<D>, _Cap<D>, _StateLight<D>, _StateInsight<D>, _Sort<D>>;
|
|
41
63
|
};
|
|
42
|
-
export type
|
|
64
|
+
export type GetFetchTypeFromSliceDescriptor<Descriptor> = [Descriptor] extends [SliceFetchDescriptor] ? SliceListFetch<Descriptor> & SliceInsightFetch<Descriptor> & SliceInitFetch<Descriptor> & SliceGetInitFetch<Descriptor> & RawBaseSliceFetchType<_RefName<Descriptor>, _Input<Descriptor>, _Full<Descriptor>, _Light<Descriptor>, _Cap<Descriptor>, _PurifiedInput<Descriptor>> & AppliedBaseSliceFetchType<_RefName<Descriptor>, _Input<Descriptor>, _Full<Descriptor>, _Cap<Descriptor>, _PurifiedInput<Descriptor>> : never;
|
|
65
|
+
export type GetFetchTypeFromSlice<SlceCls extends SliceCls> = GetFetchTypeFromSliceDescriptor<SliceFetchDescriptorOf<SlceCls>>;
|
|
43
66
|
type RawBaseSliceFetchType<RefName extends string, Input, Full, Light, _CapitalizedRefName extends string = Capitalize<RefName>, _PurifiedInput = PurifiedModel<Input>> = {
|
|
44
67
|
[K in RefName]: (id: string, fetchPolicy?: FetchPolicy) => Promise<Full>;
|
|
45
68
|
} & {
|