akanjs 2.3.9-rc.8 → 2.3.9
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 +7 -0
- package/fetch/client/fetchClient.ts +2 -2
- package/fetch/fetchType/endpointFetch.type.ts +2 -2
- package/fetch/fetchType/sliceFetch.type.ts +16 -14
- package/package.json +1 -1
- package/types/fetch/fetchType/endpointFetch.type.d.ts +2 -2
- package/types/fetch/fetchType/sliceFetch.type.d.ts +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -274,7 +274,7 @@ export class FetchClient {
|
|
|
274
274
|
const serializerMap = this.#makeArgSerializer(endpoint.args);
|
|
275
275
|
const parseReturn = this.#makeReturnParser(endpoint.returns);
|
|
276
276
|
const wrappedListeners = new WeakMap<(data: unknown) => void, (data: unknown) => void>();
|
|
277
|
-
return
|
|
277
|
+
return (...argData: unknown[]) => {
|
|
278
278
|
const args = argData.slice(0, roomArgLength);
|
|
279
279
|
const handleEvent = argData[roomArgLength] as (data: unknown) => void;
|
|
280
280
|
const fetchPolicy = argData[roomArgLength + 1] as FetchPolicy | undefined;
|
|
@@ -300,7 +300,7 @@ export class FetchClient {
|
|
|
300
300
|
const msgArgs = endpoint.args.filter((arg) => arg.type === "msg");
|
|
301
301
|
const msgArgLength = msgArgs.length;
|
|
302
302
|
const serializerMap = this.#makeArgSerializer(endpoint.args);
|
|
303
|
-
return
|
|
303
|
+
return (...argData: unknown[]) => {
|
|
304
304
|
const args = argData.slice(0, msgArgLength);
|
|
305
305
|
const data = msgArgs.map((arg, idx) => serializerMap.get(arg.name)?.(args[idx]) ?? null);
|
|
306
306
|
this.ws.emit(key, data);
|
|
@@ -40,7 +40,7 @@ type QueryOrMutationFetchFn<E, SlceCls extends SliceCls | never> = (
|
|
|
40
40
|
...args: [...EndpInfoArgs<E>, fetchPolicy?: FetchPolicy]
|
|
41
41
|
) => Promise<EndpInfoReturns<E, SlceCls>>;
|
|
42
42
|
|
|
43
|
-
type MessageEmitFn<E
|
|
43
|
+
type MessageEmitFn<E> = (...args: EndpInfoArgs<E>) => void;
|
|
44
44
|
|
|
45
45
|
type MessageListenFn<E, SlceCls extends SliceCls | never> = (
|
|
46
46
|
handleEvent: (data: EndpInfoReturns<E, SlceCls>) => PromiseOrObject<void>,
|
|
@@ -59,7 +59,7 @@ type PrimaryFetchFn<E, SlceCls extends SliceCls | never> =
|
|
|
59
59
|
EndpInfoReqType<E> extends "query" | "mutation"
|
|
60
60
|
? QueryOrMutationFetchFn<E, SlceCls>
|
|
61
61
|
: EndpInfoReqType<E> extends "message"
|
|
62
|
-
? MessageEmitFn<E
|
|
62
|
+
? MessageEmitFn<E>
|
|
63
63
|
: never;
|
|
64
64
|
|
|
65
65
|
type PrimaryFetchType<EInfoObj extends { [key: string]: EndpointInfo }, SlceCls extends SliceCls | never> = {
|
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
SliceCls,
|
|
17
17
|
SliceInfoArgs,
|
|
18
18
|
} from "akanjs/signal";
|
|
19
|
-
import type {
|
|
19
|
+
import type { EditReturn, InitReturn, ServerEdit, ServerInit, ServerView, ViewReturn } from "./appliedReturn.type";
|
|
20
20
|
|
|
21
21
|
type _SliceMap<S extends SliceCls> = S[typeof SLICE_META];
|
|
22
22
|
type _RefName<S extends SliceCls> = SlceCnstRefName<S>;
|
|
@@ -74,16 +74,18 @@ type SliceInitFetch<S extends SliceCls> = {
|
|
|
74
74
|
type SliceGetInitFetch<S extends SliceCls> = {
|
|
75
75
|
[Suffix in keyof _SliceMap<S> as Suffix extends string ? `get${_Cap<S>}Init${Capitalize<Suffix>}` : never]: (
|
|
76
76
|
...args: [...SliceInfoArgs<_SliceMap<S>[Suffix]>, option?: _SliceFetchInitOption<S>]
|
|
77
|
-
) =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
) => Promise<
|
|
78
|
+
ServerInit<
|
|
79
|
+
_RefName<S>,
|
|
80
|
+
_Light<S>,
|
|
81
|
+
_Insight<S>,
|
|
82
|
+
SliceInfoArgs<_SliceMap<S>[Suffix]>,
|
|
83
|
+
_Filter<S>,
|
|
84
|
+
_Cap<S>,
|
|
85
|
+
GetStateObject<_LightWithId<S>>,
|
|
86
|
+
GetStateObject<_Insight<S>>,
|
|
87
|
+
_Sort<S>
|
|
88
|
+
>
|
|
87
89
|
>;
|
|
88
90
|
};
|
|
89
91
|
|
|
@@ -131,7 +133,7 @@ type RawBaseSliceFetchType<
|
|
|
131
133
|
fetchPolicy?: FetchPolicy,
|
|
132
134
|
) => Promise<Full>;
|
|
133
135
|
} & {
|
|
134
|
-
[K in `remove${_CapitalizedRefName}`]: (id: string, fetchPolicy?: FetchPolicy) => Promise<
|
|
136
|
+
[K in `remove${_CapitalizedRefName}`]: (id: string, fetchPolicy?: FetchPolicy) => Promise<Full>;
|
|
135
137
|
};
|
|
136
138
|
|
|
137
139
|
type AppliedBaseSliceFetchType<
|
|
@@ -143,11 +145,11 @@ type AppliedBaseSliceFetchType<
|
|
|
143
145
|
> = {
|
|
144
146
|
[K in `view${_CapitalizedRefName}`]: (id: string, option?: FetchPolicy) => Promise<ViewReturn<RefName, Full>>;
|
|
145
147
|
} & {
|
|
146
|
-
[K in `get${_CapitalizedRefName}View`]: (id: string, option?: FetchPolicy) =>
|
|
148
|
+
[K in `get${_CapitalizedRefName}View`]: (id: string, option?: FetchPolicy) => Promise<ServerView<RefName, Full>>;
|
|
147
149
|
} & {
|
|
148
150
|
[K in `edit${_CapitalizedRefName}`]: (id: string, option?: FetchPolicy) => Promise<EditReturn<RefName, Full>>;
|
|
149
151
|
} & {
|
|
150
|
-
[K in `get${_CapitalizedRefName}Edit`]: (id: string, option?: FetchPolicy) =>
|
|
152
|
+
[K in `get${_CapitalizedRefName}Edit`]: (id: string, option?: FetchPolicy) => Promise<ServerEdit<RefName, Full>>;
|
|
151
153
|
} & {
|
|
152
154
|
[K in `add${_CapitalizedRefName}Files`]: (
|
|
153
155
|
fileList: FileList,
|
package/package.json
CHANGED
|
@@ -5,14 +5,14 @@ type ExtendedEndpointReturn<ClientReturns, Full, Light, Insight> = ClientReturns
|
|
|
5
5
|
type EndpointClientReturns<E, SlceCls extends SliceCls | never> = [SlceCls] extends [never] ? EndpInfoClientReturns<E> : ExtendedEndpointReturn<EndpInfoClientReturns<E>, SlceCnstFull<SlceCls>, SlceCnstLight<SlceCls>, SlceCnstInsight<SlceCls>>;
|
|
6
6
|
type EndpInfoReturns<E, SlceCls extends SliceCls | never> = EndpointClientReturns<E, SlceCls> | (EndpInfoNullable<E> extends true ? null : never);
|
|
7
7
|
type QueryOrMutationFetchFn<E, SlceCls extends SliceCls | never> = (...args: [...EndpInfoArgs<E>, fetchPolicy?: FetchPolicy]) => Promise<EndpInfoReturns<E, SlceCls>>;
|
|
8
|
-
type MessageEmitFn<E
|
|
8
|
+
type MessageEmitFn<E> = (...args: EndpInfoArgs<E>) => void;
|
|
9
9
|
type MessageListenFn<E, SlceCls extends SliceCls | never> = (handleEvent: (data: EndpInfoReturns<E, SlceCls>) => PromiseOrObject<void>, options?: FetchPolicy) => () => void;
|
|
10
10
|
type PubsubSubscribeFn<E, SlceCls extends SliceCls | never> = (...args: [
|
|
11
11
|
...EndpInfoArgs<E>,
|
|
12
12
|
handleEvent: (data: EndpInfoReturns<E, SlceCls>) => PromiseOrObject<void>,
|
|
13
13
|
options?: FetchPolicy
|
|
14
14
|
]) => () => void;
|
|
15
|
-
type PrimaryFetchFn<E, SlceCls extends SliceCls | never> = EndpInfoReqType<E> extends "query" | "mutation" ? QueryOrMutationFetchFn<E, SlceCls> : EndpInfoReqType<E> extends "message" ? MessageEmitFn<E
|
|
15
|
+
type PrimaryFetchFn<E, SlceCls extends SliceCls | never> = EndpInfoReqType<E> extends "query" | "mutation" ? QueryOrMutationFetchFn<E, SlceCls> : EndpInfoReqType<E> extends "message" ? MessageEmitFn<E> : never;
|
|
16
16
|
type PrimaryFetchType<EInfoObj extends {
|
|
17
17
|
[key: string]: EndpointInfo;
|
|
18
18
|
}, SlceCls extends SliceCls | never> = {
|
|
@@ -3,7 +3,7 @@ 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
5
|
import type { SlceCnstCapitalizedRefName, SlceCnstDefaultInput, SlceCnstFull, SlceCnstInput, SlceCnstInsight, SlceCnstLight, SlceCnstPurifiedInput, SlceCnstRefName, SlceDbFilter, SlceDbSort, SliceCls, SliceInfoArgs } from "akanjs/signal";
|
|
6
|
-
import type {
|
|
6
|
+
import type { EditReturn, InitReturn, ServerEdit, ServerInit, ServerView, ViewReturn } from "./appliedReturn.type";
|
|
7
7
|
type _SliceMap<S extends SliceCls> = S[typeof SLICE_META];
|
|
8
8
|
type _RefName<S extends SliceCls> = SlceCnstRefName<S>;
|
|
9
9
|
type _Cap<S extends SliceCls> = SlceCnstCapitalizedRefName<S>;
|
|
@@ -37,7 +37,7 @@ type SliceInitFetch<S extends SliceCls> = {
|
|
|
37
37
|
[Suffix in keyof _SliceMap<S> as Suffix extends string ? `init${_Cap<S>}${Capitalize<Suffix>}` : never]: (...args: [...SliceInfoArgs<_SliceMap<S>[Suffix]>, option?: _SliceFetchInitOption<S>]) => Promise<InitReturn<_RefName<S>, Suffix & string, _Light<S>, _Insight<S>, SliceInfoArgs<_SliceMap<S>[Suffix]>, _Filter<S>, _Cap<S>, Suffix extends string ? Capitalize<Suffix> : never, _LightWithId<S>, GetStateObject<_LightWithId<S>>, GetStateObject<_Insight<S>>, _Sort<S>>>;
|
|
38
38
|
};
|
|
39
39
|
type SliceGetInitFetch<S extends SliceCls> = {
|
|
40
|
-
[Suffix in keyof _SliceMap<S> as Suffix extends string ? `get${_Cap<S>}Init${Capitalize<Suffix>}` : never]: (...args: [...SliceInfoArgs<_SliceMap<S>[Suffix]>, option?: _SliceFetchInitOption<S>]) =>
|
|
40
|
+
[Suffix in keyof _SliceMap<S> as Suffix extends string ? `get${_Cap<S>}Init${Capitalize<Suffix>}` : never]: (...args: [...SliceInfoArgs<_SliceMap<S>[Suffix]>, option?: _SliceFetchInitOption<S>]) => Promise<ServerInit<_RefName<S>, _Light<S>, _Insight<S>, SliceInfoArgs<_SliceMap<S>[Suffix]>, _Filter<S>, _Cap<S>, GetStateObject<_LightWithId<S>>, GetStateObject<_Insight<S>>, _Sort<S>>>;
|
|
41
41
|
};
|
|
42
42
|
export type GetFetchTypeFromSlice<SlceCls extends SliceCls> = SlceCls["srv"]["cnst"] extends ConstantModel ? SlceCls["srv"]["db"] extends DatabaseModel ? SliceListFetch<SlceCls> & SliceInsightFetch<SlceCls> & SliceInitFetch<SlceCls> & SliceGetInitFetch<SlceCls> & RawBaseSliceFetchType<_RefName<SlceCls>, _Input<SlceCls>, _Full<SlceCls>, _Light<SlceCls>, _Cap<SlceCls>, _PurifiedInput<SlceCls>> & AppliedBaseSliceFetchType<_RefName<SlceCls>, _Input<SlceCls>, _Full<SlceCls>, _Cap<SlceCls>, _PurifiedInput<SlceCls>> : never : never;
|
|
43
43
|
type RawBaseSliceFetchType<RefName extends string, Input, Full, Light, _CapitalizedRefName extends string = Capitalize<RefName>, _PurifiedInput = PurifiedModel<Input>> = {
|
|
@@ -49,16 +49,16 @@ type RawBaseSliceFetchType<RefName extends string, Input, Full, Light, _Capitali
|
|
|
49
49
|
} & {
|
|
50
50
|
[K in `update${_CapitalizedRefName}`]: (id: string, input: _PurifiedInput, fetchPolicy?: FetchPolicy) => Promise<Full>;
|
|
51
51
|
} & {
|
|
52
|
-
[K in `remove${_CapitalizedRefName}`]: (id: string, fetchPolicy?: FetchPolicy) => Promise<
|
|
52
|
+
[K in `remove${_CapitalizedRefName}`]: (id: string, fetchPolicy?: FetchPolicy) => Promise<Full>;
|
|
53
53
|
};
|
|
54
54
|
type AppliedBaseSliceFetchType<RefName extends string, Input, Full, _CapitalizedRefName extends string = Capitalize<RefName>, _PurifiedInput = PurifiedModel<Input>> = {
|
|
55
55
|
[K in `view${_CapitalizedRefName}`]: (id: string, option?: FetchPolicy) => Promise<ViewReturn<RefName, Full>>;
|
|
56
56
|
} & {
|
|
57
|
-
[K in `get${_CapitalizedRefName}View`]: (id: string, option?: FetchPolicy) =>
|
|
57
|
+
[K in `get${_CapitalizedRefName}View`]: (id: string, option?: FetchPolicy) => Promise<ServerView<RefName, Full>>;
|
|
58
58
|
} & {
|
|
59
59
|
[K in `edit${_CapitalizedRefName}`]: (id: string, option?: FetchPolicy) => Promise<EditReturn<RefName, Full>>;
|
|
60
60
|
} & {
|
|
61
|
-
[K in `get${_CapitalizedRefName}Edit`]: (id: string, option?: FetchPolicy) =>
|
|
61
|
+
[K in `get${_CapitalizedRefName}Edit`]: (id: string, option?: FetchPolicy) => Promise<ServerEdit<RefName, Full>>;
|
|
62
62
|
} & {
|
|
63
63
|
[K in `add${_CapitalizedRefName}Files`]: (fileList: FileList, parentId?: string, option?: FetchPolicy) => Promise<ProtoFile[]>;
|
|
64
64
|
} & {
|