akanjs 2.3.5-rc.2 → 2.3.5-rc.4

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.
@@ -273,26 +273,15 @@ export class ConstantRegistry {
273
273
  }
274
274
  }
275
275
 
276
- export interface ConstantModel<
276
+ export interface ConstantCore<
277
277
  T extends string = string,
278
- Input = any,
279
- Obj = any,
280
- Full = any,
281
- Light = any,
282
- Insight = any,
278
+ Input = unknown,
279
+ Obj = unknown,
280
+ Full = unknown,
281
+ Light = unknown,
282
+ Insight = unknown,
283
283
  FullFieldObj extends FieldObject = FieldObject,
284
284
  _CapitalizedRefName extends string = Capitalize<T>,
285
- _Default = DefaultOf<Full>,
286
- _DefaultInput = DefaultOf<Input>,
287
- _DefaultState = GetStateObject<Full>,
288
- _DefaultStateInput = GetStateObject<Input>,
289
- _DefaultInsight = DefaultOf<Insight>,
290
- _PurifiedInput = PurifiedModel<Input>,
291
- _Doc = DocumentModel<Full>,
292
- _DocInput = DocumentModel<Input>,
293
- _QueryOfDoc = QueryOf<_Doc>,
294
- _StateLight = GetStateObject<Light>,
295
- _StateInsight = GetStateObject<Insight>,
296
285
  > {
297
286
  refName: T;
298
287
  input: ConstantCls<Input>;
@@ -306,6 +295,25 @@ export interface ConstantModel<
306
295
  _Full: Full;
307
296
  _Light: Light;
308
297
  _Insight: Insight;
298
+ }
299
+
300
+ export interface ConstantDerived<
301
+ Input = unknown,
302
+ Full = unknown,
303
+ Light = unknown,
304
+ Insight = unknown,
305
+ _Default = DefaultOf<Full>,
306
+ _DefaultInput = DefaultOf<Input>,
307
+ _DefaultState = GetStateObject<Full>,
308
+ _DefaultStateInput = GetStateObject<Input>,
309
+ _DefaultInsight = DefaultOf<Insight>,
310
+ _PurifiedInput = PurifiedModel<Input>,
311
+ _Doc = DocumentModel<Full>,
312
+ _DocInput = DocumentModel<Input>,
313
+ _QueryOfDoc = QueryOf<_Doc>,
314
+ _StateLight = GetStateObject<Light>,
315
+ _StateInsight = GetStateObject<Insight>,
316
+ > {
309
317
  _Default: _Default;
310
318
  _DefaultInput: _DefaultInput;
311
319
  _DefaultState: _DefaultState;
@@ -319,6 +327,98 @@ export interface ConstantModel<
319
327
  _StateInsight: _StateInsight;
320
328
  }
321
329
 
330
+ export interface ConstantModel<
331
+ T extends string = string,
332
+ Input = any,
333
+ Obj = any,
334
+ Full = any,
335
+ Light = any,
336
+ Insight = any,
337
+ FullFieldObj extends FieldObject = FieldObject,
338
+ _CapitalizedRefName extends string = Capitalize<T>,
339
+ _Default = DefaultOf<Full>,
340
+ _DefaultInput = DefaultOf<Input>,
341
+ _DefaultState = GetStateObject<Full>,
342
+ _DefaultStateInput = GetStateObject<Input>,
343
+ _DefaultInsight = DefaultOf<Insight>,
344
+ _PurifiedInput = PurifiedModel<Input>,
345
+ _Doc = DocumentModel<Full>,
346
+ _DocInput = DocumentModel<Input>,
347
+ _QueryOfDoc = QueryOf<_Doc>,
348
+ _StateLight = GetStateObject<Light>,
349
+ _StateInsight = GetStateObject<Insight>,
350
+ > extends ConstantCore<T, Input, Obj, Full, Light, Insight, FullFieldObj, _CapitalizedRefName>,
351
+ ConstantDerived<
352
+ Input,
353
+ Full,
354
+ Light,
355
+ Insight,
356
+ _Default,
357
+ _DefaultInput,
358
+ _DefaultState,
359
+ _DefaultStateInput,
360
+ _DefaultInsight,
361
+ _PurifiedInput,
362
+ _Doc,
363
+ _DocInput,
364
+ _QueryOfDoc,
365
+ _StateLight,
366
+ _StateInsight
367
+ > {}
368
+
369
+ export type ConstantReturnView<Full = unknown, Light = unknown, Insight = unknown> = {
370
+ full: Full;
371
+ light: Light;
372
+ insight: Insight;
373
+ };
374
+
375
+ export type ConstantReturnViewOf<Cnst> = Cnst extends {
376
+ _Full: infer Full;
377
+ _Light: infer Light;
378
+ _Insight: infer Insight;
379
+ }
380
+ ? ConstantReturnView<Full, Light, Insight>
381
+ : never;
382
+
383
+ export type ConstantFetchView<
384
+ RefName extends string = string,
385
+ CapRefName extends string = Capitalize<RefName>,
386
+ Input = unknown,
387
+ Full = unknown,
388
+ Light = unknown,
389
+ Insight = unknown,
390
+ PurifiedInput = unknown,
391
+ DefaultInput = unknown,
392
+ StateLight = unknown,
393
+ StateInsight = unknown,
394
+ > = {
395
+ refName: RefName;
396
+ capRefName: CapRefName;
397
+ input: Input;
398
+ full: Full;
399
+ light: Light;
400
+ insight: Insight;
401
+ purifiedInput: PurifiedInput;
402
+ defaultInput: DefaultInput;
403
+ stateLight: StateLight;
404
+ stateInsight: StateInsight;
405
+ };
406
+
407
+ export type ConstantFetchViewOf<Cnst> = Cnst extends {
408
+ refName: infer RefName extends string;
409
+ _CapitalizedRefName: infer CapRefName extends string;
410
+ _Input: infer Input;
411
+ _Full: infer Full;
412
+ _Light: infer Light;
413
+ _Insight: infer Insight;
414
+ _PurifiedInput: infer PurifiedInput;
415
+ _DefaultInput: infer DefaultInput;
416
+ _StateLight: infer StateLight;
417
+ _StateInsight: infer StateInsight;
418
+ }
419
+ ? ConstantFetchView<RefName, CapRefName, Input, Full, Light, Insight, PurifiedInput, DefaultInput, StateLight, StateInsight>
420
+ : never;
421
+
322
422
  export interface ScalarConstantModel<
323
423
  T extends string = string,
324
424
  Model = any,
@@ -1,5 +1,6 @@
1
1
  import type { ENDPOINT_META, PromiseOrObject } from "akanjs/base";
2
2
  import type { FetchPolicy } from "akanjs/common";
3
+ import type { ConstantReturnViewOf } from "akanjs/constant";
3
4
  import type {
4
5
  EndpInfoArgs,
5
6
  EndpInfoClientReturns,
@@ -19,11 +20,7 @@ export type EndpointReturnContext<Full = unknown, Light = unknown, Insight = unk
19
20
  type EndpointReturnContextOf<SlceCls extends SliceCls | never> = [SlceCls] extends [never]
20
21
  ? never
21
22
  : SlceCls extends SliceCls
22
- ? EndpointReturnContext<
23
- SlceCls["srv"]["cnst"]["_Full"],
24
- SlceCls["srv"]["cnst"]["_Light"],
25
- SlceCls["srv"]["cnst"]["_Insight"]
26
- >
23
+ ? ConstantReturnViewOf<SlceCls["srv"]["cnst"]>
27
24
  : never;
28
25
 
29
26
  type ExtendedEndpointReturn<ClientReturns, Context> = ClientReturns extends (infer R)[]
@@ -1,6 +1,6 @@
1
- import type { GetStateObject, SLICE_META } from "akanjs/base";
1
+ import type { SLICE_META } from "akanjs/base";
2
2
  import type { FetchPolicy } from "akanjs/common";
3
- import type { DefaultOf, ProtoFile, PurifiedModel } from "akanjs/constant";
3
+ import type { ConstantFetchViewOf, DefaultOf, ProtoFile, PurifiedModel } from "akanjs/constant";
4
4
  import type { ExtractSort, FilterInstance } from "akanjs/document";
5
5
  import type { SliceCls, SliceInfo, SliceInfoArgs } from "akanjs/signal";
6
6
  import type { ClientEdit, ClientInit, ClientView, EditReturn, InitReturn, ViewReturn } from "./appliedReturn.type";
@@ -11,7 +11,7 @@ type LightWithId<Light> = Light extends { id: string } ? Light : { id: string };
11
11
  export type SliceFetchDescriptor<
12
12
  SliceMap extends SliceInfoMap = SliceInfoMap,
13
13
  RefName extends string = string,
14
- CapRefName extends string = Capitalize<RefName>,
14
+ CapRefName extends string = string,
15
15
  Input = unknown,
16
16
  Full = unknown,
17
17
  Light = unknown,
@@ -38,21 +38,37 @@ export type SliceFetchDescriptor<
38
38
  sort: Sort;
39
39
  };
40
40
 
41
- export type SliceFetchDescriptorOf<SlceCls extends SliceCls> = SliceFetchDescriptor<
42
- SlceCls[typeof SLICE_META],
43
- SlceCls["baseName"],
44
- SlceCls["srv"]["cnst"]["_CapitalizedRefName"],
45
- SlceCls["srv"]["cnst"]["_Input"],
46
- SlceCls["srv"]["cnst"]["_Full"],
47
- SlceCls["srv"]["cnst"]["_Light"],
48
- SlceCls["srv"]["cnst"]["_Insight"],
49
- SlceCls["srv"]["cnst"]["_PurifiedInput"],
50
- SlceCls["srv"]["cnst"]["_DefaultInput"],
51
- GetStateObject<LightWithId<SlceCls["srv"]["cnst"]["_Light"]>>,
52
- GetStateObject<SlceCls["srv"]["cnst"]["_Insight"]>,
53
- SlceCls["srv"]["db"]["_Filter"],
54
- SlceCls["srv"]["db"]["_Sort"]
55
- >;
41
+ type SliceConstantFetchViewOf<SlceCls extends SliceCls> = ConstantFetchViewOf<SlceCls["srv"]["cnst"]>;
42
+
43
+ export type SliceFetchDescriptorOf<SlceCls extends SliceCls> =
44
+ SliceConstantFetchViewOf<SlceCls> extends infer View extends {
45
+ refName: string;
46
+ capRefName: string;
47
+ input: unknown;
48
+ full: unknown;
49
+ light: unknown;
50
+ insight: unknown;
51
+ purifiedInput: unknown;
52
+ defaultInput: unknown;
53
+ stateLight: unknown;
54
+ stateInsight: unknown;
55
+ }
56
+ ? SliceFetchDescriptor<
57
+ SlceCls[typeof SLICE_META],
58
+ View["refName"],
59
+ View["capRefName"],
60
+ View["input"],
61
+ View["full"],
62
+ View["light"],
63
+ View["insight"],
64
+ View["purifiedInput"],
65
+ View["defaultInput"],
66
+ View["stateLight"],
67
+ View["stateInsight"],
68
+ SlceCls["srv"]["db"]["_Filter"],
69
+ SlceCls["srv"]["db"]["_Sort"]
70
+ >
71
+ : never;
56
72
 
57
73
  type _SliceMap<D extends SliceFetchDescriptor> = D["sliceMap"];
58
74
  type _RefName<D extends SliceFetchDescriptor> = D["refName"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "2.3.5-rc.2",
3
+ "version": "2.3.5-rc.4",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/signal/slice.ts CHANGED
@@ -4,7 +4,7 @@ import type { DocumentModel, QueryOf } from "akanjs/constant";
4
4
  import type { FilterInstance } from "akanjs/document";
5
5
  import { type Adaptor, type AdaptorCls, dangerouslyAdapt, type ServiceModel } from "akanjs/service";
6
6
  import type { Guard, GuardCls } from "./guard";
7
- import { buildSlice, type SliceBuilder, type SliceInfo } from "./sliceInfo";
7
+ import { buildSlice, type SliceBuilder, type SliceInfo, type SlicePayloadOf } from "./sliceInfo";
8
8
 
9
9
  export interface Slice extends Adaptor {}
10
10
 
@@ -31,11 +31,12 @@ interface RootSliceOption {
31
31
  type ExtendSliceInfoObj<
32
32
  SrvModule extends ServiceModel,
33
33
  LibSlices extends SliceCls[],
34
- _Input = NonNullable<SrvModule["cnst"]>["_Input"],
35
- _Full = NonNullable<SrvModule["cnst"]>["_Full"],
36
- _Light = NonNullable<SrvModule["cnst"]>["_Light"],
37
- _Insight = NonNullable<SrvModule["cnst"]>["_Insight"],
38
- _Filter extends FilterInstance = any,
34
+ _Payload extends SlicePayloadOf<SrvModule> = SlicePayloadOf<SrvModule>,
35
+ _Input = _Payload["input"],
36
+ _Full = _Payload["full"],
37
+ _Light = _Payload["light"],
38
+ _Insight = _Payload["insight"],
39
+ _Filter extends FilterInstance = _Payload["filter"],
39
40
  _Merged = MergeAllKeyOfObjects<LibSlices, typeof SLICE_META>,
40
41
  > = {
41
42
  [K in keyof _Merged]: _Merged[K] extends SliceInfo<
@@ -72,11 +73,12 @@ export function slice<
72
73
  SrvModule extends ServiceModel,
73
74
  BuildSlice extends SliceBuilder<SrvModule>,
74
75
  LibSlices extends SliceCls[],
75
- _Input = NonNullable<SrvModule["cnst"]>["_Input"],
76
- _Full = NonNullable<SrvModule["cnst"]>["_Full"],
77
- _Light = NonNullable<SrvModule["cnst"]>["_Light"],
78
- _Insight = NonNullable<SrvModule["cnst"]>["_Insight"],
79
- _Filter extends FilterInstance = NonNullable<SrvModule["db"]>["_Filter"],
76
+ _Payload extends SlicePayloadOf<SrvModule> = SlicePayloadOf<SrvModule>,
77
+ _Input = _Payload["input"],
78
+ _Full = _Payload["full"],
79
+ _Light = _Payload["light"],
80
+ _Insight = _Payload["insight"],
81
+ _Filter extends FilterInstance = _Payload["filter"],
80
82
  _Query = QueryOf<DocumentModel<_Full>>,
81
83
  >(
82
84
  srv: SrvModule,
@@ -90,13 +92,13 @@ export function slice<
90
92
  LibSlices extends []
91
93
  ? {
92
94
  [""]: SliceInfo<
93
- SrvModule["srv"]["refName"],
95
+ _Payload["refName"],
94
96
  _Input,
95
97
  _Full,
96
98
  _Light,
97
99
  _Insight,
98
100
  _Filter,
99
- SrvModule["srvMap"],
101
+ _Payload["srvs"],
100
102
  ["query"],
101
103
  [_Query],
102
104
  [],
@@ -2,6 +2,7 @@ import type { Cls, PromiseOrObject } from "akanjs/base";
2
2
  import type {
3
3
  BaseInsight,
4
4
  BaseObject,
5
+ ConstantFetchViewOf,
5
6
  ConstantFieldTypeInput,
6
7
  DocumentModel,
7
8
  FieldToValue,
@@ -225,30 +226,68 @@ export type SliceInfoInternalArgs<S> =
225
226
  export type SliceInfoServerArgs<S> =
226
227
  S extends SliceInfo<any, any, any, any, any, any, any, any, any, any, infer S2> ? S2 : never;
227
228
 
229
+ export type SlicePayload<
230
+ RefName extends string = string,
231
+ Input = unknown,
232
+ Full = unknown,
233
+ Light = unknown,
234
+ Insight = unknown,
235
+ Filter extends FilterInstance = FilterInstance,
236
+ Srvs extends Record<string, unknown> = Record<string, unknown>,
237
+ > = {
238
+ refName: RefName;
239
+ input: Input;
240
+ full: Full;
241
+ light: Light;
242
+ insight: Insight;
243
+ filter: Filter;
244
+ srvs: Srvs;
245
+ };
246
+
247
+ export type SlicePayloadOf<SrvModule extends ServiceModel> =
248
+ ConstantFetchViewOf<NonNullable<SrvModule["cnst"]>> extends infer CnstView extends {
249
+ refName: string;
250
+ input: unknown;
251
+ full: unknown;
252
+ light: unknown;
253
+ insight: unknown;
254
+ }
255
+ ? SlicePayload<
256
+ SrvModule["srv"]["refName"],
257
+ CnstView["input"],
258
+ CnstView["full"],
259
+ CnstView["light"],
260
+ CnstView["insight"],
261
+ NonNullable<SrvModule["db"]>["_Filter"],
262
+ SrvModule["srvMap"]
263
+ >
264
+ : never;
265
+
228
266
  export type SliceBuilder<
229
267
  SrvModule extends ServiceModel,
230
- _Input = NonNullable<SrvModule["cnst"]>["_Input"],
231
- _Full = NonNullable<SrvModule["cnst"]>["_Full"],
232
- _Light = NonNullable<SrvModule["cnst"]>["_Light"],
233
- _Insight = NonNullable<SrvModule["cnst"]>["_Insight"],
234
- _Filter extends FilterInstance = NonNullable<SrvModule["db"]>["_Filter"],
268
+ _Payload extends SlicePayload = SlicePayloadOf<SrvModule>,
269
+ _Input = _Payload["input"],
270
+ _Full = _Payload["full"],
271
+ _Light = _Payload["light"],
272
+ _Insight = _Payload["insight"],
273
+ _Filter extends FilterInstance = _Payload["filter"],
235
274
  _Sort = ExtractSort<_Filter>,
236
275
  > = (
237
276
  init: (
238
277
  signalOption?: SignalOption,
239
278
  ) => SliceInfo<
240
- SrvModule["srv"]["refName"],
279
+ _Payload["refName"],
241
280
  _Input,
242
281
  _Full,
243
282
  _Light,
244
283
  _Insight,
245
284
  _Filter,
246
- SrvModule["srvMap"],
285
+ _Payload["srvs"],
247
286
  [],
248
287
  [],
249
288
  [],
250
289
  []
251
290
  >,
252
291
  ) => {
253
- [key: string]: SliceInfo<SrvModule["srv"]["refName"], _Input, _Full, _Light, _Insight, _Filter, SrvModule["srvMap"]>;
292
+ [key: string]: SliceInfo<_Payload["refName"], _Input, _Full, _Light, _Insight, _Filter, _Payload["srvs"]>;
254
293
  };
@@ -54,7 +54,7 @@ export declare class ConstantRegistry {
54
54
  static serialize<Value>(modelRef: Cls | Cls[], value: Value, nullable?: boolean): Value;
55
55
  static deserialize<Value>(modelRef: Cls | Cls[], value: Value, nullable?: boolean): Value;
56
56
  }
57
- export interface ConstantModel<T extends string = string, Input = any, Obj = any, Full = any, Light = any, Insight = any, FullFieldObj extends FieldObject = FieldObject, _CapitalizedRefName extends string = Capitalize<T>, _Default = DefaultOf<Full>, _DefaultInput = DefaultOf<Input>, _DefaultState = GetStateObject<Full>, _DefaultStateInput = GetStateObject<Input>, _DefaultInsight = DefaultOf<Insight>, _PurifiedInput = PurifiedModel<Input>, _Doc = DocumentModel<Full>, _DocInput = DocumentModel<Input>, _QueryOfDoc = QueryOf<_Doc>, _StateLight = GetStateObject<Light>, _StateInsight = GetStateObject<Insight>> {
57
+ export interface ConstantCore<T extends string = string, Input = unknown, Obj = unknown, Full = unknown, Light = unknown, Insight = unknown, FullFieldObj extends FieldObject = FieldObject, _CapitalizedRefName extends string = Capitalize<T>> {
58
58
  refName: T;
59
59
  input: ConstantCls<Input>;
60
60
  object: ConstantCls<Obj>;
@@ -67,6 +67,8 @@ export interface ConstantModel<T extends string = string, Input = any, Obj = any
67
67
  _Full: Full;
68
68
  _Light: Light;
69
69
  _Insight: Insight;
70
+ }
71
+ export interface ConstantDerived<Input = unknown, Full = unknown, Light = unknown, Insight = unknown, _Default = DefaultOf<Full>, _DefaultInput = DefaultOf<Input>, _DefaultState = GetStateObject<Full>, _DefaultStateInput = GetStateObject<Input>, _DefaultInsight = DefaultOf<Insight>, _PurifiedInput = PurifiedModel<Input>, _Doc = DocumentModel<Full>, _DocInput = DocumentModel<Input>, _QueryOfDoc = QueryOf<_Doc>, _StateLight = GetStateObject<Light>, _StateInsight = GetStateObject<Insight>> {
70
72
  _Default: _Default;
71
73
  _DefaultInput: _DefaultInput;
72
74
  _DefaultState: _DefaultState;
@@ -79,6 +81,42 @@ export interface ConstantModel<T extends string = string, Input = any, Obj = any
79
81
  _StateLight: _StateLight;
80
82
  _StateInsight: _StateInsight;
81
83
  }
84
+ export interface ConstantModel<T extends string = string, Input = any, Obj = any, Full = any, Light = any, Insight = any, FullFieldObj extends FieldObject = FieldObject, _CapitalizedRefName extends string = Capitalize<T>, _Default = DefaultOf<Full>, _DefaultInput = DefaultOf<Input>, _DefaultState = GetStateObject<Full>, _DefaultStateInput = GetStateObject<Input>, _DefaultInsight = DefaultOf<Insight>, _PurifiedInput = PurifiedModel<Input>, _Doc = DocumentModel<Full>, _DocInput = DocumentModel<Input>, _QueryOfDoc = QueryOf<_Doc>, _StateLight = GetStateObject<Light>, _StateInsight = GetStateObject<Insight>> extends ConstantCore<T, Input, Obj, Full, Light, Insight, FullFieldObj, _CapitalizedRefName>, ConstantDerived<Input, Full, Light, Insight, _Default, _DefaultInput, _DefaultState, _DefaultStateInput, _DefaultInsight, _PurifiedInput, _Doc, _DocInput, _QueryOfDoc, _StateLight, _StateInsight> {
85
+ }
86
+ export type ConstantReturnView<Full = unknown, Light = unknown, Insight = unknown> = {
87
+ full: Full;
88
+ light: Light;
89
+ insight: Insight;
90
+ };
91
+ export type ConstantReturnViewOf<Cnst> = Cnst extends {
92
+ _Full: infer Full;
93
+ _Light: infer Light;
94
+ _Insight: infer Insight;
95
+ } ? ConstantReturnView<Full, Light, Insight> : never;
96
+ export type ConstantFetchView<RefName extends string = string, CapRefName extends string = Capitalize<RefName>, Input = unknown, Full = unknown, Light = unknown, Insight = unknown, PurifiedInput = unknown, DefaultInput = unknown, StateLight = unknown, StateInsight = unknown> = {
97
+ refName: RefName;
98
+ capRefName: CapRefName;
99
+ input: Input;
100
+ full: Full;
101
+ light: Light;
102
+ insight: Insight;
103
+ purifiedInput: PurifiedInput;
104
+ defaultInput: DefaultInput;
105
+ stateLight: StateLight;
106
+ stateInsight: StateInsight;
107
+ };
108
+ export type ConstantFetchViewOf<Cnst> = Cnst extends {
109
+ refName: infer RefName extends string;
110
+ _CapitalizedRefName: infer CapRefName extends string;
111
+ _Input: infer Input;
112
+ _Full: infer Full;
113
+ _Light: infer Light;
114
+ _Insight: infer Insight;
115
+ _PurifiedInput: infer PurifiedInput;
116
+ _DefaultInput: infer DefaultInput;
117
+ _StateLight: infer StateLight;
118
+ _StateInsight: infer StateInsight;
119
+ } ? ConstantFetchView<RefName, CapRefName, Input, Full, Light, Insight, PurifiedInput, DefaultInput, StateLight, StateInsight> : never;
82
120
  export interface ScalarConstantModel<T extends string = string, Model = any, _Default = DefaultOf<Model>, _Doc = DocumentModel<Model>, _PurifiedInput = PurifiedModel<Model>> {
83
121
  refName: T;
84
122
  model: ConstantCls<Model>;
@@ -1,12 +1,13 @@
1
1
  import type { ENDPOINT_META, PromiseOrObject } from "akanjs/base";
2
2
  import type { FetchPolicy } from "akanjs/common";
3
+ import type { ConstantReturnViewOf } from "akanjs/constant";
3
4
  import type { EndpInfoArgs, EndpInfoClientReturns, EndpInfoNullable, EndpInfoReqType, EndpointCls, EndpointInfo, SliceCls } from "akanjs/signal";
4
5
  export type EndpointReturnContext<Full = unknown, Light = unknown, Insight = unknown> = {
5
6
  full: Full;
6
7
  light: Light;
7
8
  insight: Insight;
8
9
  };
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 EndpointReturnContextOf<SlceCls extends SliceCls | never> = [SlceCls] extends [never] ? never : SlceCls extends SliceCls ? ConstantReturnViewOf<SlceCls["srv"]["cnst"]> : never;
10
11
  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
12
  type EndpointClientReturns<E, Context> = [Context] extends [never] ? EndpInfoClientReturns<E> : ExtendedEndpointReturn<EndpInfoClientReturns<E>, Context>;
12
13
  type EndpInfoReturns<E, Context> = EndpointClientReturns<E, Context> | (EndpInfoNullable<E> extends true ? null : never);
@@ -1,6 +1,6 @@
1
- import type { GetStateObject, SLICE_META } from "akanjs/base";
1
+ import type { SLICE_META } from "akanjs/base";
2
2
  import type { FetchPolicy } from "akanjs/common";
3
- import type { DefaultOf, ProtoFile, PurifiedModel } from "akanjs/constant";
3
+ import type { ConstantFetchViewOf, DefaultOf, ProtoFile, PurifiedModel } from "akanjs/constant";
4
4
  import type { ExtractSort, FilterInstance } from "akanjs/document";
5
5
  import type { SliceCls, SliceInfo, SliceInfoArgs } from "akanjs/signal";
6
6
  import type { ClientEdit, ClientInit, ClientView, EditReturn, InitReturn, ViewReturn } from "./appliedReturn.type";
@@ -12,7 +12,7 @@ type LightWithId<Light> = Light extends {
12
12
  } ? Light : {
13
13
  id: string;
14
14
  };
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 = unknown, DefaultInput = unknown, StateLight = unknown, StateInsight = unknown, Filter extends FilterInstance = FilterInstance, Sort = unknown> = {
15
+ export type SliceFetchDescriptor<SliceMap extends SliceInfoMap = SliceInfoMap, RefName extends string = string, CapRefName extends string = string, Input = unknown, Full = unknown, Light = unknown, Insight = unknown, PurifiedInput = unknown, DefaultInput = unknown, StateLight = unknown, StateInsight = unknown, Filter extends FilterInstance = FilterInstance, Sort = unknown> = {
16
16
  sliceMap: SliceMap;
17
17
  refName: RefName;
18
18
  capRefName: CapRefName;
@@ -27,7 +27,19 @@ export type SliceFetchDescriptor<SliceMap extends SliceInfoMap = SliceInfoMap, R
27
27
  filter: Filter;
28
28
  sort: Sort;
29
29
  };
30
- export type SliceFetchDescriptorOf<SlceCls extends SliceCls> = SliceFetchDescriptor<SlceCls[typeof SLICE_META], SlceCls["baseName"], 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"]>;
30
+ type SliceConstantFetchViewOf<SlceCls extends SliceCls> = ConstantFetchViewOf<SlceCls["srv"]["cnst"]>;
31
+ export type SliceFetchDescriptorOf<SlceCls extends SliceCls> = SliceConstantFetchViewOf<SlceCls> extends infer View extends {
32
+ refName: string;
33
+ capRefName: string;
34
+ input: unknown;
35
+ full: unknown;
36
+ light: unknown;
37
+ insight: unknown;
38
+ purifiedInput: unknown;
39
+ defaultInput: unknown;
40
+ stateLight: unknown;
41
+ stateInsight: unknown;
42
+ } ? SliceFetchDescriptor<SlceCls[typeof SLICE_META], View["refName"], View["capRefName"], View["input"], View["full"], View["light"], View["insight"], View["purifiedInput"], View["defaultInput"], View["stateLight"], View["stateInsight"], SlceCls["srv"]["db"]["_Filter"], SlceCls["srv"]["db"]["_Sort"]> : never;
31
43
  type _SliceMap<D extends SliceFetchDescriptor> = D["sliceMap"];
32
44
  type _RefName<D extends SliceFetchDescriptor> = D["refName"];
33
45
  type _Cap<D extends SliceFetchDescriptor> = D["capRefName"];
@@ -3,7 +3,7 @@ import type { DocumentModel, QueryOf } from "akanjs/constant";
3
3
  import type { FilterInstance } from "akanjs/document";
4
4
  import { type Adaptor, type AdaptorCls, type ServiceModel } from "akanjs/service";
5
5
  import type { Guard, GuardCls } from "./guard.d.ts";
6
- import { type SliceBuilder, type SliceInfo } from "./sliceInfo.d.ts";
6
+ import { type SliceBuilder, type SliceInfo, type SlicePayloadOf } from "./sliceInfo.d.ts";
7
7
  export interface Slice extends Adaptor {
8
8
  }
9
9
  export type SliceCls<SrvModule extends ServiceModel = ServiceModel, SliceInfoObj extends {
@@ -25,12 +25,12 @@ interface RootSliceOption {
25
25
  };
26
26
  prefix?: string;
27
27
  }
28
- type ExtendSliceInfoObj<SrvModule extends ServiceModel, LibSlices extends SliceCls[], _Input = NonNullable<SrvModule["cnst"]>["_Input"], _Full = NonNullable<SrvModule["cnst"]>["_Full"], _Light = NonNullable<SrvModule["cnst"]>["_Light"], _Insight = NonNullable<SrvModule["cnst"]>["_Insight"], _Filter extends FilterInstance = any, _Merged = MergeAllKeyOfObjects<LibSlices, typeof SLICE_META>> = {
28
+ type ExtendSliceInfoObj<SrvModule extends ServiceModel, LibSlices extends SliceCls[], _Payload extends SlicePayloadOf<SrvModule> = SlicePayloadOf<SrvModule>, _Input = _Payload["input"], _Full = _Payload["full"], _Light = _Payload["light"], _Insight = _Payload["insight"], _Filter extends FilterInstance = _Payload["filter"], _Merged = MergeAllKeyOfObjects<LibSlices, typeof SLICE_META>> = {
29
29
  [K in keyof _Merged]: _Merged[K] extends SliceInfo<any, any, any, any, any, any, infer Srvs, infer ArgNames, infer Args, infer InternalArgs, infer ServerArgs> ? SliceInfo<SrvModule["srv"]["refName"], _Input, _Full, _Light, _Insight, _Filter, Srvs, ArgNames, Args, InternalArgs, ServerArgs> : never;
30
30
  };
31
31
  /** Builds database-backed slice APIs for list, insight, init, view, edit, create, update, and remove flows. */
32
- export declare function slice<SrvModule extends ServiceModel, BuildSlice extends SliceBuilder<SrvModule>, LibSlices extends SliceCls[], _Input = NonNullable<SrvModule["cnst"]>["_Input"], _Full = NonNullable<SrvModule["cnst"]>["_Full"], _Light = NonNullable<SrvModule["cnst"]>["_Light"], _Insight = NonNullable<SrvModule["cnst"]>["_Insight"], _Filter extends FilterInstance = NonNullable<SrvModule["db"]>["_Filter"], _Query = QueryOf<DocumentModel<_Full>>>(srv: SrvModule, option: RootSliceOption, sliceBuilder: BuildSlice, ...libSlices: LibSlices): SliceCls<SrvModule, Assign<ReturnType<BuildSlice>, LibSlices extends [] ? {
33
- [""]: SliceInfo<SrvModule["srv"]["refName"], _Input, _Full, _Light, _Insight, _Filter, SrvModule["srvMap"], [
32
+ export declare function slice<SrvModule extends ServiceModel, BuildSlice extends SliceBuilder<SrvModule>, LibSlices extends SliceCls[], _Payload extends SlicePayloadOf<SrvModule> = SlicePayloadOf<SrvModule>, _Input = _Payload["input"], _Full = _Payload["full"], _Light = _Payload["light"], _Insight = _Payload["insight"], _Filter extends FilterInstance = _Payload["filter"], _Query = QueryOf<DocumentModel<_Full>>>(srv: SrvModule, option: RootSliceOption, sliceBuilder: BuildSlice, ...libSlices: LibSlices): SliceCls<SrvModule, Assign<ReturnType<BuildSlice>, LibSlices extends [] ? {
33
+ [""]: SliceInfo<_Payload["refName"], _Input, _Full, _Light, _Insight, _Filter, _Payload["srvs"], [
34
34
  "query"
35
35
  ], [
36
36
  _Query
@@ -1,5 +1,5 @@
1
1
  import type { Cls, PromiseOrObject } from "akanjs/base";
2
- import type { BaseInsight, BaseObject, ConstantFieldTypeInput, DocumentModel, FieldToValue, ParamFieldType, PlainTypeToFieldType, PurifiedModel, QueryOf } from "akanjs/constant";
2
+ import type { BaseInsight, BaseObject, ConstantFetchViewOf, ConstantFieldTypeInput, DocumentModel, FieldToValue, ParamFieldType, PlainTypeToFieldType, PurifiedModel, QueryOf } from "akanjs/constant";
3
3
  import type { ExtractSort, FilterCls, FilterInstance } from "akanjs/document";
4
4
  import type { ServiceModel } from "akanjs/service";
5
5
  import { type ArgInfo, type EndpointArgProps, type InternalArgInfo, type InternalArgProps } from "./endpointInfo.d.ts";
@@ -42,10 +42,26 @@ export type SliceInfoArgNames<S> = S extends SliceInfo<any, any, any, any, any,
42
42
  export type SliceInfoArgs<S> = S extends SliceInfo<any, any, any, any, any, any, any, any, infer A, any, any> ? A : never;
43
43
  export type SliceInfoInternalArgs<S> = S extends SliceInfo<any, any, any, any, any, any, any, any, any, infer I, any> ? I : never;
44
44
  export type SliceInfoServerArgs<S> = S extends SliceInfo<any, any, any, any, any, any, any, any, any, any, infer S2> ? S2 : never;
45
- export type SliceBuilder<SrvModule extends ServiceModel, _Input = NonNullable<SrvModule["cnst"]>["_Input"], _Full = NonNullable<SrvModule["cnst"]>["_Full"], _Light = NonNullable<SrvModule["cnst"]>["_Light"], _Insight = NonNullable<SrvModule["cnst"]>["_Insight"], _Filter extends FilterInstance = NonNullable<SrvModule["db"]>["_Filter"], _Sort = ExtractSort<_Filter>> = (init: (signalOption?: SignalOption) => SliceInfo<SrvModule["srv"]["refName"], _Input, _Full, _Light, _Insight, _Filter, SrvModule["srvMap"], [
45
+ export type SlicePayload<RefName extends string = string, Input = unknown, Full = unknown, Light = unknown, Insight = unknown, Filter extends FilterInstance = FilterInstance, Srvs extends Record<string, unknown> = Record<string, unknown>> = {
46
+ refName: RefName;
47
+ input: Input;
48
+ full: Full;
49
+ light: Light;
50
+ insight: Insight;
51
+ filter: Filter;
52
+ srvs: Srvs;
53
+ };
54
+ export type SlicePayloadOf<SrvModule extends ServiceModel> = ConstantFetchViewOf<NonNullable<SrvModule["cnst"]>> extends infer CnstView extends {
55
+ refName: string;
56
+ input: unknown;
57
+ full: unknown;
58
+ light: unknown;
59
+ insight: unknown;
60
+ } ? SlicePayload<SrvModule["srv"]["refName"], CnstView["input"], CnstView["full"], CnstView["light"], CnstView["insight"], NonNullable<SrvModule["db"]>["_Filter"], SrvModule["srvMap"]> : never;
61
+ export type SliceBuilder<SrvModule extends ServiceModel, _Payload extends SlicePayload = SlicePayloadOf<SrvModule>, _Input = _Payload["input"], _Full = _Payload["full"], _Light = _Payload["light"], _Insight = _Payload["insight"], _Filter extends FilterInstance = _Payload["filter"], _Sort = ExtractSort<_Filter>> = (init: (signalOption?: SignalOption) => SliceInfo<_Payload["refName"], _Input, _Full, _Light, _Insight, _Filter, _Payload["srvs"], [
46
62
  ], [
47
63
  ], [
48
64
  ], [
49
65
  ]>) => {
50
- [key: string]: SliceInfo<SrvModule["srv"]["refName"], _Input, _Full, _Light, _Insight, _Filter, SrvModule["srvMap"]>;
66
+ [key: string]: SliceInfo<_Payload["refName"], _Input, _Full, _Light, _Insight, _Filter, _Payload["srvs"]>;
51
67
  };
@@ -22,6 +22,7 @@ export const InfiniteScroll = ({
22
22
  reverse,
23
23
  }: InfiniteScrollProps) => {
24
24
  const [isFetching, setIsFetching] = useState(false);
25
+ const isFetchingRef = useRef(false);
25
26
  const target = useRef<HTMLDivElement>(null);
26
27
  const page = useRef<number>(currentPage);
27
28
  const totalPages = Math.ceil(total / (itemsPerPage || 1));
@@ -38,14 +39,39 @@ export const InfiniteScroll = ({
38
39
  }, []);
39
40
 
40
41
  const fetchMoreItems = async () => {
41
- if (isFetching) return;
42
+ if (isFetchingRef.current) return;
42
43
  const nextPage = page.current + 1;
43
44
  if (nextPage > totalPages) return;
45
+
46
+ const scroller = reverse ? document.scrollingElement : null;
47
+ const prevScrollHeight = scroller?.scrollHeight ?? 0;
48
+ const prevScrollTop = scroller?.scrollTop ?? 0;
49
+
50
+ isFetchingRef.current = true;
44
51
  setIsFetching(true);
45
- await onAddPage(nextPage);
46
- onPageSelect(nextPage);
47
- setIsFetching(false);
48
- page.current = nextPage;
52
+ try {
53
+ await onAddPage(nextPage);
54
+ onPageSelect(nextPage);
55
+ page.current = nextPage;
56
+
57
+ const restoreScroll = () => {
58
+ if (scroller) {
59
+ scroller.scrollTop = prevScrollTop + (scroller.scrollHeight - prevScrollHeight);
60
+ }
61
+ isFetchingRef.current = false;
62
+ setIsFetching(false);
63
+ };
64
+
65
+ if (typeof requestAnimationFrame === "function") {
66
+ requestAnimationFrame(restoreScroll);
67
+ } else {
68
+ restoreScroll();
69
+ }
70
+ } catch (error) {
71
+ isFetchingRef.current = false;
72
+ setIsFetching(false);
73
+ throw error;
74
+ }
49
75
  };
50
76
 
51
77
  return (
package/webkit/lazy.tsx CHANGED
@@ -8,6 +8,12 @@ const isServer = typeof window === "undefined";
8
8
  type LazyOption = { ssr?: boolean; loading?: () => ReactNode };
9
9
  type LazyProps = Record<string, unknown>;
10
10
  type LoadedOf<Loaded> = Loaded extends { default: infer T } ? T : Loaded;
11
+ type LazyModule = { default: ComponentType<LazyProps> };
12
+
13
+ const normalizeLazyModule = <Loaded,>(loaded: Loaded): LazyModule => {
14
+ if (loaded && typeof loaded === "object" && "default" in loaded) return loaded as LazyModule;
15
+ return { default: loaded as ComponentType<LazyProps> };
16
+ };
11
17
 
12
18
  /** React lazy wrapper with Akan's `ssr: false` server stub and client mount gate. */
13
19
  export const lazy = <Loaded,>(loader: () => Promise<Loaded>, option?: LazyOption): LoadedOf<Loaded> => {
@@ -18,7 +24,7 @@ export const lazy = <Loaded,>(loader: () => Promise<Loaded>, option?: LazyOption
18
24
  Stub.displayName = "LazySsrFalseStub";
19
25
  return Stub as unknown as LoadedOf<Loaded>;
20
26
  }
21
- const LazyInner = reactLazy(loader as () => Promise<{ default: ComponentType<LazyProps> }>);
27
+ const LazyInner = reactLazy(async () => normalizeLazyModule(await loader()));
22
28
 
23
29
  if (!ssrFalse) {
24
30
  const Wrapper = forwardRef<unknown, LazyProps>((props, ref) => <LazyInner {...props} ref={ref as never} />);