akanjs 2.4.2-rc.2 → 2.4.2-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.
- package/common/fileUpload.ts +1 -1
- package/constant/purify.ts +9 -10
- package/fetch/client/fetchClient.ts +1 -1
- package/fetch/client/httpClient.ts +9 -5
- package/fetch/fetchType/sliceFetch.type.ts +1 -1
- package/local/apps/serverLifecycle/serverLifecycle-local.db +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local.db-shm +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local.db-wal +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local_solid.db +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local_solid.db-shm +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local_solid.db-wal +0 -0
- package/package.json +1 -1
- package/server/akanApp.ts +15 -2
- package/signal/endpointInfo.ts +2 -1
- package/signal/slice.ts +1 -1
- package/signal/sliceInfo.ts +2 -1
- package/store/action.ts +18 -2
- package/store/state.ts +9 -1
- package/store/storeInstance.ts +2 -0
- package/test/sampleOf.ts +3 -3
- package/types/common/fileUpload.d.ts +1 -1
- package/types/constant/purify.d.ts +3 -2
- package/types/fetch/fetchType/sliceFetch.type.d.ts +1 -1
- package/types/signal/endpointInfo.d.ts +2 -2
- package/types/signal/slice.d.ts +1 -1
- package/types/signal/sliceInfo.d.ts +2 -2
- package/types/store/action.d.ts +1 -1
- package/types/store/state.d.ts +4 -2
- package/types/test/sampleOf.d.ts +2 -2
- package/types/ui/Load/Units.d.ts +3 -1
- package/ui/Load/Units.tsx +17 -0
- package/ui/Signal/Arg.tsx +1 -1
package/common/fileUpload.ts
CHANGED
|
@@ -10,7 +10,7 @@ interface FileUploadSerializedSignal {
|
|
|
10
10
|
/** Framework-owned file-upload contract shared by client-safe packages. */
|
|
11
11
|
export const fileUploadContract = {
|
|
12
12
|
fields: { files: "files", metas: "metas", type: "type", parentId: "parentId" },
|
|
13
|
-
buildMetas: (fileList: FileList) =>
|
|
13
|
+
buildMetas: (fileList: FileList | File[]) =>
|
|
14
14
|
Array.from(fileList).map((f) => ({ lastModifiedAt: new Date(f.lastModified).toISOString(), size: f.size })),
|
|
15
15
|
} as const;
|
|
16
16
|
|
package/constant/purify.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
ID,
|
|
11
11
|
PrimitiveRegistry,
|
|
12
12
|
type PrimitiveScalar,
|
|
13
|
-
type Upload,
|
|
14
13
|
} from "akanjs/base";
|
|
15
14
|
import { Logger } from "akanjs/common";
|
|
16
15
|
|
|
@@ -37,15 +36,15 @@ type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof
|
|
|
37
36
|
} & {
|
|
38
37
|
[K in StateKeys as null extends T[K] ? K : never]?: Purified<T[K]> | undefined;
|
|
39
38
|
};
|
|
40
|
-
export type PurifiedModel<T> = T extends
|
|
41
|
-
?
|
|
42
|
-
: T extends
|
|
43
|
-
?
|
|
44
|
-
: T extends
|
|
45
|
-
?
|
|
46
|
-
: T
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
export type PurifiedModel<T> = T extends (infer S)[]
|
|
40
|
+
? PurifiedModel<S>[]
|
|
41
|
+
: T extends string | number | boolean | Dayjs | File
|
|
42
|
+
? T
|
|
43
|
+
: T extends Map<infer K, infer V>
|
|
44
|
+
? Map<K, PurifiedModel<V>>
|
|
45
|
+
: PurifiedWithObjectToId<T>;
|
|
46
|
+
|
|
47
|
+
export type UploadableClientArg<T> = [T] extends [File[]] ? File[] | FileList : T;
|
|
49
48
|
|
|
50
49
|
export type PurifyFunc<Input, _DefaultInput = DefaultOf<Input>, _PurifiedInput = PurifiedModel<Input>> = (
|
|
51
50
|
self: _DefaultInput,
|
|
@@ -491,7 +491,7 @@ export class FetchClient {
|
|
|
491
491
|
this.#setHandlerFactory(
|
|
492
492
|
names.addModelFiles,
|
|
493
493
|
() =>
|
|
494
|
-
(async (fileList: FileList, parentId?: string, option?: FetchPolicy) => {
|
|
494
|
+
(async (fileList: FileList | File[], parentId?: string, option?: FetchPolicy) => {
|
|
495
495
|
const cap = resolveFileUploadCapability(this.serializedSignal);
|
|
496
496
|
const endpoint = cap ? this.serializedSignal[cap.refName]?.endpoint[cap.endpointKey] : undefined;
|
|
497
497
|
if (!cap || !endpoint)
|
|
@@ -125,6 +125,12 @@ export class HttpClient {
|
|
|
125
125
|
});
|
|
126
126
|
return `${paramedPath}${searchPath}`;
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
static #toUploadValues(argValue: unknown): (Blob | string)[] {
|
|
130
|
+
if (Array.isArray(argValue)) return argValue as (Blob | string)[];
|
|
131
|
+
if (typeof FileList !== "undefined" && argValue instanceof FileList) return Array.from(argValue);
|
|
132
|
+
return [argValue as Blob | string];
|
|
133
|
+
}
|
|
128
134
|
static makeBody(bodyArgs: SerializedArg[], uploadArgs: SerializedArg[], argMap: Map<string, unknown>) {
|
|
129
135
|
if (uploadArgs.length > 0) {
|
|
130
136
|
const formData = new FormData();
|
|
@@ -133,11 +139,9 @@ export class HttpClient {
|
|
|
133
139
|
if (arg.nullable && (argValue === null || argValue === undefined)) return;
|
|
134
140
|
if (!arg.nullable && (argValue === null || argValue === undefined))
|
|
135
141
|
throw new Error(`Argument ${arg.name} is required`);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
-
} else formData.append(arg.name, argValue as Blob | string);
|
|
142
|
+
HttpClient.#toUploadValues(argValue).forEach((value) => {
|
|
143
|
+
formData.append(arg.name, value);
|
|
144
|
+
});
|
|
141
145
|
});
|
|
142
146
|
bodyArgs.forEach((arg) => {
|
|
143
147
|
const argValue = argMap.get(arg.name);
|
|
@@ -152,7 +152,7 @@ type AppliedBaseSliceFetchType<
|
|
|
152
152
|
[K in `get${_CapitalizedRefName}Edit`]: (id: string, option?: FetchPolicy) => Promise<ServerEdit<RefName, Full>>;
|
|
153
153
|
} & {
|
|
154
154
|
[K in `add${_CapitalizedRefName}Files`]: (
|
|
155
|
-
fileList: FileList,
|
|
155
|
+
fileList: FileList | File[],
|
|
156
156
|
parentId?: string,
|
|
157
157
|
option?: FetchPolicy,
|
|
158
158
|
) => Promise<ProtoFile[]>;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/server/akanApp.ts
CHANGED
|
@@ -43,6 +43,19 @@ type GatewayUpstream = {
|
|
|
43
43
|
ws?: Extract<AkanUpstream, { type: "tcp" }>;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Received-only close codes cannot be sent in a close frame. The gateway deliberately normalizes
|
|
48
|
+
* every unsendable code, including semantically distinct 1005 and 1006 events, to 1001 in both
|
|
49
|
+
* relay directions. In particular, Bun's global client `WebSocket.close()` throws an
|
|
50
|
+
* InvalidAccessError for these codes at the client-to-upstream relay; normalization at the
|
|
51
|
+
* upstream-to-client `Bun.ServerWebSocket.close()` relay is defensive and keeps behavior symmetric.
|
|
52
|
+
*/
|
|
53
|
+
const relayableCloseCode = (code: number): number => {
|
|
54
|
+
if (code >= 3000 && code <= 4999) return code;
|
|
55
|
+
if (code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006) return code;
|
|
56
|
+
return 1001;
|
|
57
|
+
};
|
|
58
|
+
|
|
46
59
|
/** Options for the Akan gateway that launches child server replicas and listens for traffic. */
|
|
47
60
|
export interface AkanAppOptions {
|
|
48
61
|
replica?: number | string;
|
|
@@ -583,7 +596,7 @@ export class AkanApp {
|
|
|
583
596
|
const result = ws.send(event.data as string | ArrayBuffer);
|
|
584
597
|
if (result === 0) upstream.close();
|
|
585
598
|
});
|
|
586
|
-
upstream.addEventListener("close", (event) => ws.close(event.code, event.reason));
|
|
599
|
+
upstream.addEventListener("close", (event) => ws.close(relayableCloseCode(event.code), event.reason));
|
|
587
600
|
upstream.addEventListener("error", () => ws.close(1011, "upstream websocket error"));
|
|
588
601
|
Object.assign(ws.data, { pending });
|
|
589
602
|
}
|
|
@@ -604,7 +617,7 @@ export class AkanApp {
|
|
|
604
617
|
}
|
|
605
618
|
|
|
606
619
|
#handleWsClose(ws: Bun.ServerWebSocket<GatewayWsData>, code: number, reason: string) {
|
|
607
|
-
ws.data.upstream.close(code, reason);
|
|
620
|
+
ws.data.upstream.close(relayableCloseCode(code), reason);
|
|
608
621
|
const child = this.#children.get(ws.data.childIdx);
|
|
609
622
|
if (child) child.metrics.activeWebSockets = Math.max(0, (child.metrics.activeWebSockets ?? 1) - 1);
|
|
610
623
|
}
|
package/signal/endpointInfo.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
ParamFieldType,
|
|
16
16
|
PlainTypeToFieldType,
|
|
17
17
|
PurifiedModel,
|
|
18
|
+
UploadableClientArg,
|
|
18
19
|
} from "akanjs/constant";
|
|
19
20
|
import type { ServiceModel } from "akanjs/service";
|
|
20
21
|
import type { InternalArgCls } from "./internalArg";
|
|
@@ -135,7 +136,7 @@ export class EndpointInfo<
|
|
|
135
136
|
Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>,
|
|
136
137
|
Optional extends boolean = false,
|
|
137
138
|
_ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType,
|
|
138
|
-
_ClientArg = PurifiedModel<_ArgType
|
|
139
|
+
_ClientArg = UploadableClientArg<PurifiedModel<_ArgType>>,
|
|
139
140
|
_ServerArg = DocumentModel<_ArgType>,
|
|
140
141
|
>(name: ArgName, arg: Arg, option?: EndpointArgProps<Optional>) {
|
|
141
142
|
if (this.execFn) throw new Error("Query function is already set");
|
package/signal/slice.ts
CHANGED
package/signal/sliceInfo.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
PlainTypeToFieldType,
|
|
10
10
|
PurifiedModel,
|
|
11
11
|
QueryOf,
|
|
12
|
+
UploadableClientArg,
|
|
12
13
|
} from "akanjs/constant";
|
|
13
14
|
import type { FilterCls, FilterInstance } from "akanjs/document";
|
|
14
15
|
import type { ServiceModel } from "akanjs/service";
|
|
@@ -94,7 +95,7 @@ export class SliceInfo<
|
|
|
94
95
|
Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>,
|
|
95
96
|
Optional extends boolean = false,
|
|
96
97
|
_ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType,
|
|
97
|
-
_ClientArg = PurifiedModel<_ArgType
|
|
98
|
+
_ClientArg = UploadableClientArg<PurifiedModel<_ArgType>>,
|
|
98
99
|
_ServerArg = DocumentModel<_ArgType>,
|
|
99
100
|
>(name: ArgName, arg: Arg, option?: EndpointArgProps<Optional>) {
|
|
100
101
|
if (this.execFn) throw new Error("Query function is already set");
|
package/store/action.ts
CHANGED
|
@@ -224,7 +224,7 @@ type FormSetter<
|
|
|
224
224
|
? K extends string
|
|
225
225
|
? SetterKey<"upload", K, RefName, _CapitalizedRefName>
|
|
226
226
|
: never
|
|
227
|
-
: never]: (fileList: FileList, idx?: number) => Promise<void>;
|
|
227
|
+
: never]: (fileList: FileList | File[], idx?: number) => Promise<void>;
|
|
228
228
|
} & {
|
|
229
229
|
[K in `writeOn${_CapitalizedRefName}`]: (path: string | (string | number)[], value: any) => void;
|
|
230
230
|
};
|
|
@@ -376,7 +376,11 @@ export const makeFormSetter = (refName: string, fetch: FetchProxy<any>) => {
|
|
|
376
376
|
: {}),
|
|
377
377
|
...(field.isClass && !!fileUploadRefName && ConstantRegistry.getRefName(field.modelRef) === fileUploadRefName
|
|
378
378
|
? {
|
|
379
|
-
[namesOfField.uploadFieldOnModel]: async function (
|
|
379
|
+
[namesOfField.uploadFieldOnModel]: async function (
|
|
380
|
+
this: SetGet,
|
|
381
|
+
fileList: FileList | File[],
|
|
382
|
+
index?: number,
|
|
383
|
+
) {
|
|
380
384
|
const form = (this.get() as { [key: string]: any })[names.modelForm] as { [key: string]: any };
|
|
381
385
|
if (!fileList.length) return;
|
|
382
386
|
const files = await (fetch[names.addModelFiles] as (...args: any) => Promise<ProtoFile[]>)(
|
|
@@ -476,6 +480,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
476
480
|
initModel: `init${className}`,
|
|
477
481
|
modelInitList: `${fieldName}InitList`,
|
|
478
482
|
modelInitAt: `${fieldName}InitAt`,
|
|
483
|
+
modelStaleAt: `${fieldName}StaleAt`,
|
|
479
484
|
refreshModel: `refresh${className}`,
|
|
480
485
|
selectModel: `select${className}`,
|
|
481
486
|
setPageOfModel: `setPageOf${className}`,
|
|
@@ -489,6 +494,14 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
489
494
|
queryArgsOfModel: `queryArgsOf${className}`,
|
|
490
495
|
sortOfModel: `sortOf${className}`,
|
|
491
496
|
};
|
|
497
|
+
const staleAtOfOtherSlices = (createdSliceName: string) => {
|
|
498
|
+
const staleAt = new Date();
|
|
499
|
+
return Object.fromEntries(
|
|
500
|
+
slices
|
|
501
|
+
.filter(({ sliceName }) => sliceName !== createdSliceName)
|
|
502
|
+
.map(({ sliceName }) => [sliceName.replace(names.model, names.modelStaleAt), staleAt]),
|
|
503
|
+
);
|
|
504
|
+
};
|
|
492
505
|
const baseAction = {
|
|
493
506
|
[names.createModelInForm]: async function (
|
|
494
507
|
this: SetGet,
|
|
@@ -527,6 +540,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
527
540
|
[namesOfSlice.modelInsight]: newModelInsight,
|
|
528
541
|
[names.modelViewAt]: new Date(),
|
|
529
542
|
[names.modelModal]: modal ?? null,
|
|
543
|
+
...staleAtOfOtherSlices(sliceName),
|
|
530
544
|
...(typeof path === "string" && path ? { [path]: model } : {}),
|
|
531
545
|
});
|
|
532
546
|
await onSuccess?.(model);
|
|
@@ -609,6 +623,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
609
623
|
[namesOfSlice.modelInsight]: newModelInsight,
|
|
610
624
|
[names.modelViewAt]: new Date(),
|
|
611
625
|
[names.modelModal]: modal ?? null,
|
|
626
|
+
...staleAtOfOtherSlices(sliceName),
|
|
612
627
|
...(typeof path === "string" && path ? { [path]: model } : {}),
|
|
613
628
|
});
|
|
614
629
|
await onSuccess?.(model);
|
|
@@ -845,6 +860,7 @@ export const makeActions = (refName: string, slice: { [key: string]: SerializedS
|
|
|
845
860
|
initModel: SliceName.replace(names.Model, names.initModel),
|
|
846
861
|
modelInitList: SliceName.replace(names.Model, names.modelInitList),
|
|
847
862
|
modelInitAt: SliceName.replace(names.Model, names.modelInitAt),
|
|
863
|
+
modelStaleAt: SliceName.replace(names.Model, names.modelStaleAt),
|
|
848
864
|
refreshModel: SliceName.replace(names.Model, names.refreshModel),
|
|
849
865
|
selectModel: SliceName.replace(names.Model, names.selectModel),
|
|
850
866
|
setPageOfModel: SliceName.replace(names.Model, names.setPageOfModel),
|
package/store/state.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type SliceStateKey =
|
|
|
23
23
|
| "modelListLoading"
|
|
24
24
|
| "modelInitList"
|
|
25
25
|
| "modelInitAt"
|
|
26
|
+
| "modelStaleAt"
|
|
26
27
|
| "modelSelection"
|
|
27
28
|
| "lastPageOfModel"
|
|
28
29
|
| "pageOfModel"
|
|
@@ -78,6 +79,8 @@ export type SliceState<
|
|
|
78
79
|
[K in `${RefName}InitList${_CapitalizedSuffix}`]: DataList<Light>;
|
|
79
80
|
} & {
|
|
80
81
|
[K in `${RefName}InitAt${_CapitalizedSuffix}`]: Date;
|
|
82
|
+
} & {
|
|
83
|
+
[K in `${RefName}StaleAt${_CapitalizedSuffix}`]: Date;
|
|
81
84
|
} & {
|
|
82
85
|
[K in `${RefName}Selection${_CapitalizedSuffix}`]: DataList<Light>;
|
|
83
86
|
} & {
|
|
@@ -112,7 +115,9 @@ type DefaultSliceStateFields<
|
|
|
112
115
|
| `${_RefName}InitList${StoreSliceSuffixCap<SlceCls, Suffix>}`
|
|
113
116
|
| `${_RefName}Selection${StoreSliceSuffixCap<SlceCls, Suffix>}`]: DataList<_Light>;
|
|
114
117
|
} & {
|
|
115
|
-
[Suffix in _Suffixes as
|
|
118
|
+
[Suffix in _Suffixes as
|
|
119
|
+
| `${_RefName}InitAt${StoreSliceSuffixCap<SlceCls, Suffix>}`
|
|
120
|
+
| `${_RefName}StaleAt${StoreSliceSuffixCap<SlceCls, Suffix>}`]: Date;
|
|
116
121
|
} & {
|
|
117
122
|
[Suffix in _Suffixes as `${_RefName}ListLoading${StoreSliceSuffixCap<SlceCls, Suffix>}`]: boolean;
|
|
118
123
|
} & {
|
|
@@ -182,6 +187,7 @@ export const createSliceState = (refName: string, slice: { [key: string]: Serial
|
|
|
182
187
|
modelListLoading: `${fieldName}ListLoading`,
|
|
183
188
|
modelInitList: `${fieldName}InitList`,
|
|
184
189
|
modelInitAt: `${fieldName}InitAt`,
|
|
190
|
+
modelStaleAt: `${fieldName}StaleAt`,
|
|
185
191
|
modelSelection: `${fieldName}Selection`,
|
|
186
192
|
modelInsight: `${fieldName}Insight`,
|
|
187
193
|
lastPageOfModel: `lastPageOf${className}`,
|
|
@@ -200,6 +206,7 @@ export const createSliceState = (refName: string, slice: { [key: string]: Serial
|
|
|
200
206
|
modelListLoading: sliceName.replace(names.model, names.modelListLoading),
|
|
201
207
|
modelInitList: sliceName.replace(names.model, names.modelInitList),
|
|
202
208
|
modelInitAt: sliceName.replace(names.model, names.modelInitAt),
|
|
209
|
+
modelStaleAt: sliceName.replace(names.model, names.modelStaleAt),
|
|
203
210
|
modelSelection: sliceName.replace(names.model, names.modelSelection),
|
|
204
211
|
modelInsight: sliceName.replace(names.model, names.modelInsight),
|
|
205
212
|
lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
|
|
@@ -214,6 +221,7 @@ export const createSliceState = (refName: string, slice: { [key: string]: Serial
|
|
|
214
221
|
[namesOfSlice.modelListLoading]: true,
|
|
215
222
|
[namesOfSlice.modelInitList]: new DataList(),
|
|
216
223
|
[namesOfSlice.modelInitAt]: new Date(0),
|
|
224
|
+
[namesOfSlice.modelStaleAt]: new Date(0),
|
|
217
225
|
[namesOfSlice.modelSelection]: new DataList(),
|
|
218
226
|
[namesOfSlice.modelInsight]: new cnst.insight(),
|
|
219
227
|
[namesOfSlice.lastPageOfModel]: 1,
|
package/store/storeInstance.ts
CHANGED
|
@@ -263,6 +263,7 @@ export class StoreInstance {
|
|
|
263
263
|
modelListLoading: `${fieldName}ListLoading`,
|
|
264
264
|
modelInitList: `${fieldName}InitList`,
|
|
265
265
|
modelInitAt: `${fieldName}InitAt`,
|
|
266
|
+
modelStaleAt: `${fieldName}StaleAt`,
|
|
266
267
|
pageOfModel: `pageOf${className}`,
|
|
267
268
|
limitOfModel: `limitOf${className}`,
|
|
268
269
|
queryArgsOfModel: `queryArgsOf${className}`,
|
|
@@ -286,6 +287,7 @@ export class StoreInstance {
|
|
|
286
287
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
287
288
|
modelListLoading: sliceName.replace(names.model, names.modelListLoading),
|
|
288
289
|
modelInitAt: SliceName.replace(names.Model, names.modelInitAt),
|
|
290
|
+
modelStaleAt: SliceName.replace(names.Model, names.modelStaleAt),
|
|
289
291
|
lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
|
|
290
292
|
pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
|
|
291
293
|
limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
|
package/test/sampleOf.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
Upload,
|
|
11
11
|
} from "akanjs/base";
|
|
12
12
|
import { randomPick } from "akanjs/common";
|
|
13
|
-
import type { BaseObject, ConstantCls, ConstantField, DocumentModel, FieldPreset } from "akanjs/constant";
|
|
13
|
+
import type { BaseObject, ConstantCls, ConstantField, DocumentModel, FieldObject, FieldPreset } from "akanjs/constant";
|
|
14
14
|
|
|
15
15
|
import { sample } from "./sample";
|
|
16
16
|
|
|
@@ -57,8 +57,8 @@ const makeSample = (field: ConstantField): any => {
|
|
|
57
57
|
export type SampleOf<Model> = DocumentModel<{
|
|
58
58
|
[K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]>;
|
|
59
59
|
}>;
|
|
60
|
-
export const sampleOf = <Model>(
|
|
61
|
-
modelRef: ConstantCls<Model>,
|
|
60
|
+
export const sampleOf = <Model, FieldObj extends FieldObject>(
|
|
61
|
+
modelRef: ConstantCls<Model, FieldObj>,
|
|
62
62
|
): DocumentModel<{ [K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]> }> => {
|
|
63
63
|
|
|
64
64
|
return Object.fromEntries(
|
|
@@ -13,7 +13,7 @@ export declare const fileUploadContract: {
|
|
|
13
13
|
readonly type: "type";
|
|
14
14
|
readonly parentId: "parentId";
|
|
15
15
|
};
|
|
16
|
-
readonly buildMetas: (fileList: FileList) => {
|
|
16
|
+
readonly buildMetas: (fileList: FileList | File[]) => {
|
|
17
17
|
lastModifiedAt: string;
|
|
18
18
|
size: number;
|
|
19
19
|
}[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Dayjs, type GetStateObject
|
|
1
|
+
import { type Dayjs, type GetStateObject } from "akanjs/base";
|
|
2
2
|
import { type BaseObject, type ConstantModelRef, type DefaultOf, type DefaultOfSchema } from ".";
|
|
3
3
|
type Purified<O> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? Dayjs : O extends object ? PurifiedModel<O> : O;
|
|
4
4
|
type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
|
|
@@ -6,7 +6,8 @@ type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof
|
|
|
6
6
|
} & {
|
|
7
7
|
[K in StateKeys as null extends T[K] ? K : never]?: Purified<T[K]> | undefined;
|
|
8
8
|
};
|
|
9
|
-
export type PurifiedModel<T> = T extends
|
|
9
|
+
export type PurifiedModel<T> = T extends (infer S)[] ? PurifiedModel<S>[] : T extends string | number | boolean | Dayjs | File ? T : T extends Map<infer K, infer V> ? Map<K, PurifiedModel<V>> : PurifiedWithObjectToId<T>;
|
|
10
|
+
export type UploadableClientArg<T> = [T] extends [File[]] ? File[] | FileList : T;
|
|
10
11
|
export type PurifyFunc<Input, _DefaultInput = DefaultOf<Input>, _PurifiedInput = PurifiedModel<Input>> = (self: _DefaultInput, isChild?: boolean) => _PurifiedInput | null;
|
|
11
12
|
export type PurifyFuncV2<Input, RelationKey extends string = never, _DefaultInput = DefaultOfSchema<Input, RelationKey>, _PurifiedInput = PurifiedModel<Input>> = (self: _DefaultInput, isChild?: boolean) => _PurifiedInput | null;
|
|
12
13
|
export declare const makePurify: <I>(modelRef: ConstantModelRef<I>) => PurifyFunc<I>;
|
|
@@ -60,7 +60,7 @@ type AppliedBaseSliceFetchType<RefName extends string, Input, Full, _Capitalized
|
|
|
60
60
|
} & {
|
|
61
61
|
[K in `get${_CapitalizedRefName}Edit`]: (id: string, option?: FetchPolicy) => Promise<ServerEdit<RefName, Full>>;
|
|
62
62
|
} & {
|
|
63
|
-
[K in `add${_CapitalizedRefName}Files`]: (fileList: FileList, parentId?: string, option?: FetchPolicy) => Promise<ProtoFile[]>;
|
|
63
|
+
[K in `add${_CapitalizedRefName}Files`]: (fileList: FileList | File[], parentId?: string, option?: FetchPolicy) => Promise<ProtoFile[]>;
|
|
64
64
|
} & {
|
|
65
65
|
[K in `merge${_CapitalizedRefName}`]: (modelOrId: Full | string, data: Partial<_PurifiedInput>, option?: FetchPolicy) => Promise<Full>;
|
|
66
66
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Dayjs, type EnumInstance, type PromiseOrObject } from "akanjs/base";
|
|
2
|
-
import type { ConstantFieldType, ConstantFieldTypeInput, DocumentModel, FieldToValue, ParamFieldType, PlainTypeToFieldType, PurifiedModel } from "akanjs/constant";
|
|
2
|
+
import type { ConstantFieldType, ConstantFieldTypeInput, DocumentModel, FieldToValue, ParamFieldType, PlainTypeToFieldType, PurifiedModel, UploadableClientArg } from "akanjs/constant";
|
|
3
3
|
import type { ServiceModel } from "akanjs/service";
|
|
4
4
|
import type { InternalArgCls } from "./internalArg.d.ts";
|
|
5
5
|
import type { ArgType, SignalOption, SrvMap } from "./types.d.ts";
|
|
@@ -45,7 +45,7 @@ export declare class EndpointInfo<ReqType extends EndpointType = EndpointType, S
|
|
|
45
45
|
static getReturnInfo<Returns extends ConstantFieldTypeInput = ConstantFieldTypeInput, Nullable extends boolean = false>(modelRef: Returns, signalOption?: SignalOption<Returns, Nullable>): ReturnInfo<Returns, Nullable>;
|
|
46
46
|
constructor(type: ReqType, returnRef: Returns, signalOption?: SignalOption<Returns, Nullable>);
|
|
47
47
|
param<ArgName extends string, Arg extends ParamFieldType, _ClientArg = FieldToValue<Arg>, _ServerArg = DocumentModel<_ClientArg>>(name: string, arg: Arg, option?: Omit<EndpointArgProps, "nullable">): EndpointInfo<ReqType, Srvs, [...ArgNames, ArgName], [...Args, arg: _ClientArg], InternalArgs, [...ServerArgs, arg: _ServerArg], Returns, ClientReturns, ServerReturns, Nullable>;
|
|
48
|
-
body<ArgName extends string, ExplicitType = unknown, Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, Optional extends boolean = false, _ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType, _ClientArg = PurifiedModel<_ArgType
|
|
48
|
+
body<ArgName extends string, ExplicitType = unknown, Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, Optional extends boolean = false, _ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType, _ClientArg = UploadableClientArg<PurifiedModel<_ArgType>>, _ServerArg = DocumentModel<_ArgType>>(name: ArgName, arg: Arg, option?: EndpointArgProps<Optional>): EndpointInfo<ReqType, Srvs, [...ArgNames, ArgName], Optional extends true ? [...Args, arg?: _ClientArg | null] : [...Args, arg: _ClientArg], InternalArgs, [...ServerArgs, arg: _ServerArg | (Optional extends true ? undefined : never)], Returns, ClientReturns, ServerReturns, Nullable>;
|
|
49
49
|
room<ArgName extends string, ExplicitType = unknown, Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, _ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType, _ClientArg = PurifiedModel<_ArgType>, _ServerArg = DocumentModel<_ArgType>>(name: string, arg: Arg, option?: Omit<EndpointArgProps, "nullable">): EndpointInfo<ReqType, Srvs, [...ArgNames, ArgName], [...Args, arg: _ClientArg], InternalArgs, [...ServerArgs, arg: _ServerArg], Returns, ClientReturns, ServerReturns, Nullable>;
|
|
50
50
|
msg<ArgName extends string, ExplicitType = unknown, Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, Optional extends boolean = false, _ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType, _ClientArg = PurifiedModel<_ArgType>, _ServerArg = DocumentModel<_ArgType>>(name: string, arg: Arg, option?: EndpointArgProps<Optional>): EndpointInfo<ReqType, Srvs, [...ArgNames, ArgName], Optional extends true ? [...Args, arg?: _ClientArg | null] : [...Args, arg: _ClientArg], InternalArgs, [...ServerArgs, arg: _ServerArg | (Optional extends true ? undefined : never)], Returns, ClientReturns, ServerReturns, Nullable>;
|
|
51
51
|
search<ArgName extends string, ExplicitType = unknown, Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, _ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType, _ClientArg = PurifiedModel<_ArgType>, _ServerArg = DocumentModel<_ArgType>>(name: string, arg: Arg, option?: Omit<EndpointArgProps, "nullable">): EndpointInfo<ReqType, Srvs, [...ArgNames, ArgName], [...Args, arg?: _ClientArg | null], InternalArgs, [...ServerArgs, arg: _ServerArg | undefined], Returns, ClientReturns, ServerReturns, Nullable>;
|
package/types/signal/slice.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function slice<SrvModule extends ServiceModel, BuildSlice extends
|
|
|
51
51
|
[""]: SliceInfo<SrvRefName<SrvModule>, _Input, _Full, _Light, _Insight, _Filter, SrvMap<SrvModule>, [
|
|
52
52
|
"query"
|
|
53
53
|
], [
|
|
54
|
-
_Query
|
|
54
|
+
query?: _Query | null
|
|
55
55
|
], [
|
|
56
56
|
], [
|
|
57
57
|
_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, ConstantFieldTypeInput, DocumentModel, FieldToValue, ParamFieldType, PlainTypeToFieldType, PurifiedModel, QueryOf, UploadableClientArg } from "akanjs/constant";
|
|
3
3
|
import type { 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";
|
|
@@ -23,7 +23,7 @@ export declare class SliceInfo<RefName extends string = string, Input = any, Ful
|
|
|
23
23
|
execFn: ((...args: [...ServerArgs, ...InternalArgs]) => QueryOf<DocumentModel<Full>>) | null;
|
|
24
24
|
constructor(refName: RefName, input: Cls<Input>, full: Cls<Full>, light: Cls<Light>, insight: Cls<Insight>, filter: FilterCls<Filter>, signalOption?: SignalOption);
|
|
25
25
|
param<ArgName extends string, Arg extends ParamFieldType, _ClientArg = FieldToValue<Arg>, _ServerArg = DocumentModel<_ClientArg>>(name: ArgName, arg: Arg, option?: Omit<EndpointArgProps, "nullable">): SliceInfo<RefName, Input, Full, Light, Insight, Filter, Srvs, [...ArgNames, ArgName], [...Args, arg: _ClientArg], InternalArgs, [...ServerArgs, arg: _ServerArg]>;
|
|
26
|
-
body<ArgName extends string, ExplicitType = unknown, Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, Optional extends boolean = false, _ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType, _ClientArg = PurifiedModel<_ArgType
|
|
26
|
+
body<ArgName extends string, ExplicitType = unknown, Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, Optional extends boolean = false, _ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType, _ClientArg = UploadableClientArg<PurifiedModel<_ArgType>>, _ServerArg = DocumentModel<_ArgType>>(name: ArgName, arg: Arg, option?: EndpointArgProps<Optional>): SliceInfo<RefName, Input, Full, Light, Insight, Filter, Srvs, [...ArgNames, ArgName], Optional extends true ? [...Args, arg?: _ClientArg | null] : [...Args, arg: _ClientArg], InternalArgs, [...ServerArgs, arg: _ServerArg | (Optional extends true ? undefined : never)]>;
|
|
27
27
|
search<ArgName extends string, ExplicitType = unknown, Arg extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, _ArgType = unknown extends ExplicitType ? FieldToValue<Arg> : ExplicitType, _ClientArg = PurifiedModel<_ArgType>, _ServerArg = DocumentModel<_ArgType>>(name: ArgName, arg: Arg, option?: Omit<EndpointArgProps, "nullable">): SliceInfo<RefName, Input, Full, Light, Insight, Filter, Srvs, [...ArgNames, ArgName], [...Args, arg?: _ClientArg | null], InternalArgs, [...ServerArgs, arg: _ServerArg | undefined]>;
|
|
28
28
|
with<ArgType, Optional extends boolean = false>(argRef: InternalArgCls<ArgType>, option?: InternalArgProps<Optional>): SliceInfo<RefName, Input, Full, Light, Insight, Filter, Srvs, ArgNames, Args, [...InternalArgs, arg: NonNullable<ArgType> | (Optional extends true ? null : never)], ServerArgs>;
|
|
29
29
|
exec(query: (this: {
|
package/types/store/action.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ type ArrayFieldAddOrSubSetters<RefName extends string, _CapRef extends string, _
|
|
|
111
111
|
}) => void;
|
|
112
112
|
};
|
|
113
113
|
type FormSetter<Full, RefName extends string, _CapitalizedRefName extends string = Capitalize<RefName>, _DefaultState = DefaultOf<Full>> = FieldFormSetter<_DefaultState, RefName, _CapitalizedRefName> & ArrayFieldAddSetters<RefName, _CapitalizedRefName, _DefaultState> & ArrayFieldSubSetters<RefName, _CapitalizedRefName, _DefaultState> & ArrayFieldAddOrSubSetters<RefName, _CapitalizedRefName, _DefaultState> & {
|
|
114
|
-
[K in keyof _DefaultState as _DefaultState[K] extends (ProtoFile | null) | ProtoFile[] ? K extends string ? SetterKey<"upload", K, RefName, _CapitalizedRefName> : never : never]: (fileList: FileList, idx?: number) => Promise<void>;
|
|
114
|
+
[K in keyof _DefaultState as _DefaultState[K] extends (ProtoFile | null) | ProtoFile[] ? K extends string ? SetterKey<"upload", K, RefName, _CapitalizedRefName> : never : never]: (fileList: FileList | File[], idx?: number) => Promise<void>;
|
|
115
115
|
} & {
|
|
116
116
|
[K in `writeOn${_CapitalizedRefName}`]: (path: string | (string | number)[], value: any) => void;
|
|
117
117
|
};
|
package/types/store/state.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type DefaultOf } from "akanjs/constant";
|
|
|
3
3
|
import type { ExtractSort, FilterInstance } from "akanjs/document";
|
|
4
4
|
import type { SerializedSlice, SlceCnstCapitalizedRefName, SlceCnstDefault, SlceCnstFull, SlceCnstInsight, SlceCnstLight, SlceCnstRefName, SlceDbFilter, SlceDbSort, SliceCls } from "akanjs/signal";
|
|
5
5
|
import type { StoreSliceArgs, StoreSliceMap, StoreSliceSuffixCap, Submit } from "./types.d.ts";
|
|
6
|
-
export type SliceStateKey = "defaultModel" | "modelInsight" | "modelList" | "modelListLoading" | "modelInitList" | "modelInitAt" | "modelSelection" | "lastPageOfModel" | "pageOfModel" | "limitOfModel" | "queryArgsOfModel" | "sortOfModel";
|
|
6
|
+
export type SliceStateKey = "defaultModel" | "modelInsight" | "modelList" | "modelListLoading" | "modelInitList" | "modelInitAt" | "modelStaleAt" | "modelSelection" | "lastPageOfModel" | "pageOfModel" | "limitOfModel" | "queryArgsOfModel" | "sortOfModel";
|
|
7
7
|
type _SliceMap<S extends SliceCls> = StoreSliceMap<S>;
|
|
8
8
|
type _StateRefName<S extends SliceCls> = SlceCnstRefName<S>;
|
|
9
9
|
type _StateCap<S extends SliceCls> = SlceCnstCapitalizedRefName<S>;
|
|
@@ -42,6 +42,8 @@ export type SliceState<RefName extends string, Suffix extends string, Full, Ligh
|
|
|
42
42
|
[K in `${RefName}InitList${_CapitalizedSuffix}`]: DataList<Light>;
|
|
43
43
|
} & {
|
|
44
44
|
[K in `${RefName}InitAt${_CapitalizedSuffix}`]: Date;
|
|
45
|
+
} & {
|
|
46
|
+
[K in `${RefName}StaleAt${_CapitalizedSuffix}`]: Date;
|
|
45
47
|
} & {
|
|
46
48
|
[K in `${RefName}Selection${_CapitalizedSuffix}`]: DataList<Light>;
|
|
47
49
|
} & {
|
|
@@ -64,7 +66,7 @@ type DefaultSliceStateFields<SlceCls extends SliceCls, _RefName extends string,
|
|
|
64
66
|
} & {
|
|
65
67
|
[Suffix in _Suffixes as `${_RefName}List${StoreSliceSuffixCap<SlceCls, Suffix>}` | `${_RefName}InitList${StoreSliceSuffixCap<SlceCls, Suffix>}` | `${_RefName}Selection${StoreSliceSuffixCap<SlceCls, Suffix>}`]: DataList<_Light>;
|
|
66
68
|
} & {
|
|
67
|
-
[Suffix in _Suffixes as `${_RefName}InitAt${StoreSliceSuffixCap<SlceCls, Suffix>}`]: Date;
|
|
69
|
+
[Suffix in _Suffixes as `${_RefName}InitAt${StoreSliceSuffixCap<SlceCls, Suffix>}` | `${_RefName}StaleAt${StoreSliceSuffixCap<SlceCls, Suffix>}`]: Date;
|
|
68
70
|
} & {
|
|
69
71
|
[Suffix in _Suffixes as `${_RefName}ListLoading${StoreSliceSuffixCap<SlceCls, Suffix>}`]: boolean;
|
|
70
72
|
} & {
|
package/types/test/sampleOf.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BaseObject, ConstantCls, DocumentModel } from "akanjs/constant";
|
|
1
|
+
import type { BaseObject, ConstantCls, DocumentModel, FieldObject } from "akanjs/constant";
|
|
2
2
|
export type SampleOf<Model> = DocumentModel<{
|
|
3
3
|
[K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]>;
|
|
4
4
|
}>;
|
|
5
|
-
export declare const sampleOf: <Model>(modelRef: ConstantCls<Model>) => DocumentModel<{ [K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]>; }>;
|
|
5
|
+
export declare const sampleOf: <Model, FieldObj extends FieldObject>(modelRef: ConstantCls<Model, FieldObj>) => DocumentModel<{ [K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]>; }>;
|
package/types/ui/Load/Units.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ interface DefaultProps<L extends {
|
|
|
18
18
|
renderList?: (list: DataList<L>) => ReactNode;
|
|
19
19
|
reverse?: boolean;
|
|
20
20
|
pagination?: boolean;
|
|
21
|
+
/** Max age in ms of the cached slice data before the client refetches on mount; `0` always refetches. */
|
|
22
|
+
staleTime?: number;
|
|
21
23
|
}
|
|
22
24
|
interface UnitsProps<RefName extends string, Light extends {
|
|
23
25
|
id: string;
|
|
@@ -26,5 +28,5 @@ interface UnitsProps<RefName extends string, Light extends {
|
|
|
26
28
|
}
|
|
27
29
|
export default function Units<RefName extends string, Light extends {
|
|
28
30
|
id: string;
|
|
29
|
-
}>({ containerRef, className, init, noDiv, from, to, loading, renderItem, renderList, renderEmpty, filter, sort, reverse, style, pagination, }: UnitsProps<RefName, Light>): import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
}>({ containerRef, className, init, noDiv, from, to, loading, renderItem, renderList, renderEmpty, filter, sort, reverse, style, pagination, staleTime, }: UnitsProps<RefName, Light>): import("react/jsx-runtime").JSX.Element;
|
|
30
32
|
export {};
|
package/ui/Load/Units.tsx
CHANGED
|
@@ -28,6 +28,8 @@ interface DefaultProps<L extends { id: string }> {
|
|
|
28
28
|
renderList?: (list: DataList<L>) => ReactNode;
|
|
29
29
|
reverse?: boolean;
|
|
30
30
|
pagination?: boolean;
|
|
31
|
+
/** Max age in ms of the cached slice data before the client refetches on mount; `0` always refetches. */
|
|
32
|
+
staleTime?: number;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
interface UnitsProps<RefName extends string, Light extends { id: string }> extends DefaultProps<Light> {
|
|
@@ -60,6 +62,7 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
60
62
|
sort = (a, b) => 1,
|
|
61
63
|
reverse,
|
|
62
64
|
pagination,
|
|
65
|
+
staleTime,
|
|
63
66
|
}: RenderProps<RefName, Light>) {
|
|
64
67
|
const loaded = useRef(false);
|
|
65
68
|
const storeUse = st.use as { [key: string]: () => unknown };
|
|
@@ -75,6 +78,7 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
75
78
|
modelInsight: `${modelName}Insight`,
|
|
76
79
|
modelInitList: `${modelName}InitList`,
|
|
77
80
|
modelInitAt: `${modelName}InitAt`,
|
|
81
|
+
modelStaleAt: `${modelName}StaleAt`,
|
|
78
82
|
modelObjList: `${modelName}ObjList`,
|
|
79
83
|
modelObjInsight: `${modelName}ObjInsight`,
|
|
80
84
|
pageOfModel: `pageOf${ModelName}`,
|
|
@@ -84,12 +88,14 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
84
88
|
sortOfModel: `sortOf${ModelName}`,
|
|
85
89
|
setPageOfModel: `setPageOf${ModelName}`,
|
|
86
90
|
addPageOfModel: `addPageOf${ModelName}`,
|
|
91
|
+
refreshModel: `refresh${ModelName}`,
|
|
87
92
|
};
|
|
88
93
|
const namesOfSlice = {
|
|
89
94
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
90
95
|
modelListLoading: sliceName.replace(names.model, names.modelListLoading),
|
|
91
96
|
modelInitList: sliceName.replace(names.model, names.modelInitList),
|
|
92
97
|
modelInitAt: sliceName.replace(names.model, names.modelInitAt),
|
|
98
|
+
modelStaleAt: sliceName.replace(names.model, names.modelStaleAt),
|
|
93
99
|
modelInsight: sliceName.replace(names.model, names.modelInsight),
|
|
94
100
|
pageOfModel: sliceName.replace(names.model, names.pageOfModel),
|
|
95
101
|
lastPageOfModel: sliceName.replace(names.model, names.lastPageOfModel),
|
|
@@ -98,6 +104,7 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
98
104
|
sortOfModel: sliceName.replace(names.model, names.sortOfModel),
|
|
99
105
|
setPageOfModel: sliceName.replace(names.model, names.setPageOfModel),
|
|
100
106
|
addPageOfModel: sliceName.replace(names.model, names.addPageOfModel),
|
|
107
|
+
refreshModel: sliceName.replace(names.model, names.refreshModel),
|
|
101
108
|
};
|
|
102
109
|
const modelList = storeUse[namesOfSlice.modelList]() as DataList<Light>;
|
|
103
110
|
const modelListLoading = storeUse[namesOfSlice.modelListLoading]() as string | boolean;
|
|
@@ -106,6 +113,7 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
106
113
|
const initModelObjInsight = (init as any)[names.modelObjInsight] as BaseInsight;
|
|
107
114
|
const initLimitOfModel = (init as any)[names.limitOfModel] as number;
|
|
108
115
|
const initPageOfModel = (init as any)[names.pageOfModel] as number;
|
|
116
|
+
const modelStaleAt = storeUse[namesOfSlice.modelStaleAt]() as Date;
|
|
109
117
|
|
|
110
118
|
const useCache =
|
|
111
119
|
!modelListLoading &&
|
|
@@ -143,6 +151,13 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
143
151
|
loaded.current = true;
|
|
144
152
|
}, []);
|
|
145
153
|
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
const staleThreshold = Math.max(modelStaleAt.getTime(), staleTime === undefined ? 0 : Date.now() - staleTime);
|
|
156
|
+
if (storeGet<Date>()[namesOfSlice.modelInitAt].getTime() >= staleThreshold) return;
|
|
157
|
+
if (storeGet<boolean>()[namesOfSlice.modelListLoading]) return;
|
|
158
|
+
void storeDo[namesOfSlice.refreshModel]({ invalidate: true });
|
|
159
|
+
}, [modelStaleAt]);
|
|
160
|
+
|
|
146
161
|
const modelInsight = storeUse[namesOfSlice.modelInsight]() as BaseInsight;
|
|
147
162
|
const limitOfModel = storeUse[namesOfSlice.limitOfModel]() as number;
|
|
148
163
|
const pageOfModel = storeUse[namesOfSlice.pageOfModel]() as number;
|
|
@@ -237,6 +252,7 @@ export default function Units<RefName extends string, Light extends { id: string
|
|
|
237
252
|
reverse,
|
|
238
253
|
style,
|
|
239
254
|
pagination = true,
|
|
255
|
+
staleTime,
|
|
240
256
|
}: UnitsProps<RefName, Light>) {
|
|
241
257
|
const props: UnitsProps<RefName, Light> = {
|
|
242
258
|
containerRef,
|
|
@@ -254,6 +270,7 @@ export default function Units<RefName extends string, Light extends { id: string
|
|
|
254
270
|
sort,
|
|
255
271
|
reverse,
|
|
256
272
|
pagination,
|
|
273
|
+
staleTime,
|
|
257
274
|
};
|
|
258
275
|
|
|
259
276
|
const { fulfilled, value: promiseInit } = useFetch(init);
|
package/ui/Signal/Arg.tsx
CHANGED
|
@@ -351,7 +351,7 @@ const ArgUpload = ({ value, onChange }: ArgUploadProps) => {
|
|
|
351
351
|
multiple
|
|
352
352
|
className="file-input file-input-bordered w-full max-w-xs"
|
|
353
353
|
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
354
|
-
onChange(
|
|
354
|
+
onChange(e.target.files);
|
|
355
355
|
}}
|
|
356
356
|
/>
|
|
357
357
|
);
|