@akanjs/store 0.9.48 → 0.9.50
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/cjs/src/baseSt.js +7 -18
- package/cjs/src/index.js +1 -0
- package/cjs/src/storeDecorators.js +180 -192
- package/cjs/src/storeInfo.js +65 -0
- package/esm/src/baseSt.js +8 -21
- package/esm/src/index.js +1 -0
- package/esm/src/storeDecorators.js +182 -196
- package/esm/src/storeInfo.js +46 -0
- package/package.json +1 -1
- package/src/baseSt.d.ts +5 -77
- package/src/index.d.ts +1 -0
- package/src/storeDecorators.d.ts +36 -26
- package/src/storeInfo.d.ts +20 -0
|
@@ -19,15 +19,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var storeDecorators_exports = {};
|
|
20
20
|
__export(storeDecorators_exports, {
|
|
21
21
|
MixStore: () => MixStore,
|
|
22
|
-
Store: () => Store,
|
|
23
22
|
Toast: () => Toast,
|
|
24
23
|
baseSt: () => baseSt,
|
|
25
|
-
|
|
26
|
-
createState: () => createState,
|
|
24
|
+
getStoreMeta: () => getStoreMeta,
|
|
27
25
|
makeStore: () => makeStore,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
stateOf: () => stateOf
|
|
26
|
+
setStoreMeta: () => setStoreMeta,
|
|
27
|
+
store: () => store
|
|
31
28
|
});
|
|
32
29
|
module.exports = __toCommonJS(storeDecorators_exports);
|
|
33
30
|
var import_base = require("@akanjs/base");
|
|
@@ -39,6 +36,7 @@ var import_react = require("react");
|
|
|
39
36
|
var import_zustand = require("zustand");
|
|
40
37
|
var import_middleware = require("zustand/middleware");
|
|
41
38
|
var import_immer = require("zustand/middleware/immer");
|
|
39
|
+
var import_storeInfo = require("./storeInfo");
|
|
42
40
|
const baseSt = {};
|
|
43
41
|
class StoreStorage {
|
|
44
42
|
}
|
|
@@ -51,14 +49,9 @@ const getStoreMeta = (storeName) => {
|
|
|
51
49
|
const setStoreMeta = (storeName, storeMeta) => {
|
|
52
50
|
Reflect.defineMetadata(storeName, storeMeta, StoreStorage.prototype);
|
|
53
51
|
};
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
throw new Error(`storeNames is not defined`);
|
|
58
|
-
return storeNames;
|
|
59
|
-
};
|
|
60
|
-
const createState = (gql) => {
|
|
61
|
-
const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
|
|
52
|
+
const createDatabaseState = (refName) => {
|
|
53
|
+
const cnst = import_constant.constantInfo.getDatabase(refName);
|
|
54
|
+
const [fieldName, className] = [refName, (0, import_common.capitalize)(refName)];
|
|
62
55
|
const names = {
|
|
63
56
|
model: fieldName,
|
|
64
57
|
Model: className,
|
|
@@ -68,7 +61,26 @@ const createState = (gql) => {
|
|
|
68
61
|
modelSubmit: `${fieldName}Submit`,
|
|
69
62
|
modelViewAt: `${fieldName}ViewAt`,
|
|
70
63
|
modelModal: `${fieldName}Modal`,
|
|
71
|
-
modelOperation: `${fieldName}Operation
|
|
64
|
+
modelOperation: `${fieldName}Operation`
|
|
65
|
+
};
|
|
66
|
+
const baseState = {
|
|
67
|
+
[names.model]: null,
|
|
68
|
+
[names.modelLoading]: true,
|
|
69
|
+
[names.modelForm]: cnst.getDefault(),
|
|
70
|
+
[names.modelFormLoading]: true,
|
|
71
|
+
[names.modelSubmit]: { disabled: true, loading: false, times: 0 },
|
|
72
|
+
[names.modelViewAt]: /* @__PURE__ */ new Date(0),
|
|
73
|
+
[names.modelModal]: null,
|
|
74
|
+
[names.modelOperation]: "sleep"
|
|
75
|
+
};
|
|
76
|
+
return baseState;
|
|
77
|
+
};
|
|
78
|
+
const createSliceState = (refName, slices) => {
|
|
79
|
+
const cnst = import_constant.constantInfo.getDatabase(refName);
|
|
80
|
+
const [fieldName, className] = [refName, (0, import_common.capitalize)(refName)];
|
|
81
|
+
const names = {
|
|
82
|
+
model: fieldName,
|
|
83
|
+
Model: className,
|
|
72
84
|
defaultModel: `default${className}`,
|
|
73
85
|
defaultModelInsight: `default${className}Insight`,
|
|
74
86
|
modelList: `${fieldName}List`,
|
|
@@ -83,17 +95,7 @@ const createState = (gql) => {
|
|
|
83
95
|
queryArgsOfModel: `queryArgsOf${className}`,
|
|
84
96
|
sortOfModel: `sortOf${className}`
|
|
85
97
|
};
|
|
86
|
-
const
|
|
87
|
-
[names.model]: null,
|
|
88
|
-
[names.modelLoading]: true,
|
|
89
|
-
[names.modelForm]: { ...gql[names.defaultModel] },
|
|
90
|
-
[names.modelFormLoading]: true,
|
|
91
|
-
[names.modelSubmit]: { disabled: true, loading: false, times: 0 },
|
|
92
|
-
[names.modelViewAt]: /* @__PURE__ */ new Date(0),
|
|
93
|
-
[names.modelModal]: null,
|
|
94
|
-
[names.modelOperation]: "sleep"
|
|
95
|
-
};
|
|
96
|
-
const sliceState = gql.slices.reduce((acc, { sliceName, defaultArgs }) => {
|
|
98
|
+
const sliceState = slices.reduce((acc, { sliceName, defaultArgs }) => {
|
|
97
99
|
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
98
100
|
const namesOfSlice = {
|
|
99
101
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
@@ -111,13 +113,13 @@ const createState = (gql) => {
|
|
|
111
113
|
sortOfModel: SliceName.replace(names.Model, names.sortOfModel)
|
|
112
114
|
};
|
|
113
115
|
const singleSliceState = {
|
|
114
|
-
[namesOfSlice.defaultModel]:
|
|
116
|
+
[namesOfSlice.defaultModel]: cnst.getDefault(),
|
|
115
117
|
[namesOfSlice.modelList]: new import_base.DataList(),
|
|
116
118
|
[namesOfSlice.modelListLoading]: true,
|
|
117
119
|
[namesOfSlice.modelInitList]: new import_base.DataList(),
|
|
118
120
|
[namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(0),
|
|
119
121
|
[namesOfSlice.modelSelection]: new import_base.DataList(),
|
|
120
|
-
[namesOfSlice.modelInsight]:
|
|
122
|
+
[namesOfSlice.modelInsight]: cnst.getDefaultInsight(),
|
|
121
123
|
[namesOfSlice.lastPageOfModel]: 1,
|
|
122
124
|
[namesOfSlice.pageOfModel]: 1,
|
|
123
125
|
[namesOfSlice.limitOfModel]: 20,
|
|
@@ -126,20 +128,11 @@ const createState = (gql) => {
|
|
|
126
128
|
};
|
|
127
129
|
return Object.assign(acc, singleSliceState);
|
|
128
130
|
}, {});
|
|
129
|
-
return
|
|
130
|
-
...baseState,
|
|
131
|
-
...sliceState
|
|
132
|
-
};
|
|
131
|
+
return sliceState;
|
|
133
132
|
};
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
return { ...formSetterActions, ...baseActions };
|
|
138
|
-
};
|
|
139
|
-
const makeFormSetter = (gql) => {
|
|
140
|
-
const fileGql = (0, import_signal.getGqlOnStorage)("file");
|
|
141
|
-
const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
|
|
142
|
-
const modelRef = (0, import_constant.getFullModelRef)(gql.refName);
|
|
133
|
+
const makeFormSetter = (refName) => {
|
|
134
|
+
const [fieldName, className] = [refName, (0, import_common.capitalize)(refName)];
|
|
135
|
+
const modelRef = import_constant.constantInfo.getDatabase(refName).full;
|
|
143
136
|
const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
|
|
144
137
|
const names = {
|
|
145
138
|
model: fieldName,
|
|
@@ -204,12 +197,12 @@ const makeFormSetter = (gql) => {
|
|
|
204
197
|
this[namesOfField.subFieldOnModel](index);
|
|
205
198
|
}
|
|
206
199
|
} : {},
|
|
207
|
-
...fieldMeta.
|
|
200
|
+
...fieldMeta.isClass && import_constant.constantInfo.getRefName(fieldMeta.modelRef) === "file" ? {
|
|
208
201
|
[namesOfField.uploadFieldOnModel]: async function(fileList, index) {
|
|
209
202
|
const form = this.get()[names.modelForm];
|
|
210
203
|
if (!fileList.length)
|
|
211
204
|
return;
|
|
212
|
-
const files = await
|
|
205
|
+
const files = await fetch[names.addModelFiles](
|
|
213
206
|
fileList,
|
|
214
207
|
form.id
|
|
215
208
|
);
|
|
@@ -230,7 +223,7 @@ const makeFormSetter = (gql) => {
|
|
|
230
223
|
files.map((file) => {
|
|
231
224
|
const intervalKey = setInterval(() => {
|
|
232
225
|
void (async () => {
|
|
233
|
-
const currentFile = await
|
|
226
|
+
const currentFile = await fetch.file(file.id);
|
|
234
227
|
if (fieldMeta.isArray)
|
|
235
228
|
this.set((state) => {
|
|
236
229
|
state[names.modelForm][namesOfField.field] = state[names.modelForm][namesOfField.field].map(
|
|
@@ -253,17 +246,14 @@ const makeFormSetter = (gql) => {
|
|
|
253
246
|
}, {});
|
|
254
247
|
return Object.assign(fieldSetAction, baseSetAction);
|
|
255
248
|
};
|
|
256
|
-
const makeActions = (
|
|
257
|
-
const [fieldName, className] = [
|
|
258
|
-
const
|
|
249
|
+
const makeActions = (refName, slices) => {
|
|
250
|
+
const [fieldName, className] = [refName, (0, import_common.capitalize)(refName)];
|
|
251
|
+
const cnst = import_constant.constantInfo.getDatabase(refName);
|
|
252
|
+
const modelRef = cnst.full;
|
|
259
253
|
const names = {
|
|
260
254
|
model: fieldName,
|
|
261
255
|
_model: `_${fieldName}`,
|
|
262
256
|
Model: className,
|
|
263
|
-
purifyModel: `purify${className}`,
|
|
264
|
-
crystalizeModel: `crystalize${className}`,
|
|
265
|
-
lightCrystalizeModel: `lightCrystalize${className}`,
|
|
266
|
-
crystalizeInsight: `crystalize${className}Insight`,
|
|
267
257
|
modelOperation: `${fieldName}Operation`,
|
|
268
258
|
defaultModel: `default${className}`,
|
|
269
259
|
modelInsight: `${fieldName}Insight`,
|
|
@@ -320,13 +310,13 @@ const makeActions = (gql) => {
|
|
|
320
310
|
const modelListLoading = currentState[namesOfSlice.modelListLoading];
|
|
321
311
|
const modelInsight = currentState[namesOfSlice.modelInsight];
|
|
322
312
|
const defaultModel = currentState[namesOfSlice.defaultModel];
|
|
323
|
-
const modelInput =
|
|
313
|
+
const modelInput = cnst.purify(modelForm);
|
|
324
314
|
if (!modelInput)
|
|
325
315
|
return;
|
|
326
316
|
this.set({ [names.modelLoading]: true });
|
|
327
|
-
const model = await
|
|
317
|
+
const model = await fetch[names.createModel](modelInput, { onError });
|
|
328
318
|
const newModelList = modelListLoading ? modelList : new import_base.DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
|
|
329
|
-
const newModelInsight =
|
|
319
|
+
const newModelInsight = cnst.crystalizeInsight({
|
|
330
320
|
...modelInsight,
|
|
331
321
|
count: modelInsight.count + 1
|
|
332
322
|
});
|
|
@@ -351,12 +341,12 @@ const makeActions = (gql) => {
|
|
|
351
341
|
const model = currentState[names.model];
|
|
352
342
|
const modelForm = currentState[names.modelForm];
|
|
353
343
|
const defaultModel = currentState[namesOfSlice.defaultModel];
|
|
354
|
-
const modelInput =
|
|
344
|
+
const modelInput = cnst.purify(modelForm);
|
|
355
345
|
if (!modelInput)
|
|
356
346
|
return;
|
|
357
347
|
if (model?.id === modelForm.id)
|
|
358
348
|
this.set({ [names.modelLoading]: modelForm.id });
|
|
359
|
-
const updatedModel = await
|
|
349
|
+
const updatedModel = await fetch[names.updateModel](modelForm.id, modelInput, {
|
|
360
350
|
onError
|
|
361
351
|
});
|
|
362
352
|
this.set({
|
|
@@ -365,8 +355,8 @@ const makeActions = (gql) => {
|
|
|
365
355
|
[names.modelModal]: modal ?? null,
|
|
366
356
|
...typeof path === "string" && path ? { [path]: updatedModel } : {}
|
|
367
357
|
});
|
|
368
|
-
const updatedLightModel =
|
|
369
|
-
|
|
358
|
+
const updatedLightModel = cnst.lightCrystalize(updatedModel);
|
|
359
|
+
slices.forEach(({ sliceName: sliceName2 }) => {
|
|
370
360
|
const namesOfSlice2 = {
|
|
371
361
|
modelList: sliceName2.replace(names.model, names.modelList),
|
|
372
362
|
modelListLoading: sliceName2.replace(names.model, names.modelListLoading)
|
|
@@ -393,13 +383,13 @@ const makeActions = (gql) => {
|
|
|
393
383
|
const modelList = currentState[namesOfSlice.modelList];
|
|
394
384
|
const modelListLoading = currentState[namesOfSlice.modelListLoading];
|
|
395
385
|
const modelInsight = currentState[namesOfSlice.modelInsight];
|
|
396
|
-
const modelInput =
|
|
386
|
+
const modelInput = cnst.purify(data);
|
|
397
387
|
if (!modelInput)
|
|
398
388
|
return;
|
|
399
389
|
this.set({ [names.modelLoading]: true });
|
|
400
|
-
const model = await
|
|
390
|
+
const model = await fetch[names.createModel](modelInput, { onError });
|
|
401
391
|
const newModelList = modelListLoading ? modelList : new import_base.DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
|
|
402
|
-
const newModelInsight =
|
|
392
|
+
const newModelInsight = cnst.crystalizeInsight({
|
|
403
393
|
...modelInsight,
|
|
404
394
|
count: modelInsight.count + 1
|
|
405
395
|
});
|
|
@@ -417,19 +407,19 @@ const makeActions = (gql) => {
|
|
|
417
407
|
[names.updateModel]: async function(id, data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
|
|
418
408
|
const currentState = this.get();
|
|
419
409
|
const model = currentState[names.model];
|
|
420
|
-
const modelInput =
|
|
410
|
+
const modelInput = cnst.purify(data);
|
|
421
411
|
if (!modelInput)
|
|
422
412
|
return;
|
|
423
413
|
if (model?.id === id)
|
|
424
414
|
this.set({ [names.modelLoading]: id });
|
|
425
|
-
const updatedModel = await
|
|
415
|
+
const updatedModel = await fetch[names.updateModel](id, modelInput, { onError });
|
|
426
416
|
this.set({
|
|
427
417
|
...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
|
|
428
418
|
[names.modelModal]: modal ?? null,
|
|
429
419
|
...typeof path === "string" && path ? { [path]: updatedModel } : {}
|
|
430
420
|
});
|
|
431
|
-
const updatedLightModel =
|
|
432
|
-
|
|
421
|
+
const updatedLightModel = cnst.lightCrystalize(updatedModel);
|
|
422
|
+
slices.forEach(({ sliceName: sliceName2 }) => {
|
|
433
423
|
const namesOfSlice = {
|
|
434
424
|
modelList: sliceName2.replace(names.model, names.modelList),
|
|
435
425
|
modelListLoading: sliceName2.replace(names.model, names.modelListLoading)
|
|
@@ -446,12 +436,12 @@ const makeActions = (gql) => {
|
|
|
446
436
|
},
|
|
447
437
|
[names.removeModel]: async function(id, options) {
|
|
448
438
|
const { modal, ...fetchPolicyOptions } = options ?? {};
|
|
449
|
-
const model = await
|
|
439
|
+
const model = await fetch[names.removeModel](
|
|
450
440
|
id,
|
|
451
441
|
fetchPolicyOptions
|
|
452
442
|
);
|
|
453
|
-
const lightModel =
|
|
454
|
-
|
|
443
|
+
const lightModel = cnst.lightCrystalize(model);
|
|
444
|
+
slices.forEach(({ sliceName }) => {
|
|
455
445
|
const namesOfSlice = {
|
|
456
446
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
457
447
|
modelListLoading: sliceName.replace(names.model, names.modelListLoading),
|
|
@@ -468,7 +458,7 @@ const makeActions = (gql) => {
|
|
|
468
458
|
const newModelList = new import_base.DataList(modelList);
|
|
469
459
|
if (model.removedAt) {
|
|
470
460
|
newModelList.delete(id);
|
|
471
|
-
const newModelInsight =
|
|
461
|
+
const newModelInsight = cnst.crystalizeInsight({
|
|
472
462
|
...modelInsight,
|
|
473
463
|
count: modelInsight.count - 1
|
|
474
464
|
});
|
|
@@ -493,7 +483,7 @@ const makeActions = (gql) => {
|
|
|
493
483
|
const currentState = this.get();
|
|
494
484
|
const modelForm = currentState[names.modelForm];
|
|
495
485
|
const modelSubmit = currentState[names.modelSubmit];
|
|
496
|
-
const modelInput =
|
|
486
|
+
const modelInput = cnst.purify(modelForm);
|
|
497
487
|
this.set({ [names.modelSubmit]: { ...modelSubmit, disabled: !modelInput || disabled } });
|
|
498
488
|
},
|
|
499
489
|
[names.submitModel]: async function(option) {
|
|
@@ -525,7 +515,7 @@ const makeActions = (gql) => {
|
|
|
525
515
|
[names.editModel]: async function(modelOrId, { modal, onError } = {}) {
|
|
526
516
|
const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
|
|
527
517
|
this.set({ [names.modelFormLoading]: id, [names.modelModal]: modal ?? "edit" });
|
|
528
|
-
const model = await
|
|
518
|
+
const model = await fetch[names.model](id, { onError });
|
|
529
519
|
const modelForm = (0, import_common.deepObjectify)(model);
|
|
530
520
|
this.set({
|
|
531
521
|
[names.model]: model,
|
|
@@ -540,13 +530,13 @@ const makeActions = (gql) => {
|
|
|
540
530
|
const model = currentState[names.model];
|
|
541
531
|
if (id === model?.id)
|
|
542
532
|
this.set({ modelLoading: id });
|
|
543
|
-
const updatedModel = await
|
|
533
|
+
const updatedModel = await fetch[names.mergeModel](modelOrId, data, options);
|
|
544
534
|
this.set({
|
|
545
535
|
[names.model]: id === model?.id ? updatedModel : model,
|
|
546
536
|
[names.modelLoading]: false
|
|
547
537
|
});
|
|
548
|
-
const updatedLightModel =
|
|
549
|
-
|
|
538
|
+
const updatedLightModel = cnst.lightCrystalize(updatedModel);
|
|
539
|
+
slices.forEach(({ sliceName }) => {
|
|
550
540
|
const namesOfSlice = {
|
|
551
541
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
552
542
|
modelListLoading: sliceName.replace(names.model, names.modelListLoading)
|
|
@@ -563,7 +553,7 @@ const makeActions = (gql) => {
|
|
|
563
553
|
[names.viewModel]: async function(modelOrId, { modal, onError } = {}) {
|
|
564
554
|
const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
|
|
565
555
|
this.set({ [names.modelModal]: modal ?? "view", [names.modelLoading]: id });
|
|
566
|
-
const model = await
|
|
556
|
+
const model = await fetch[names.model](id, { onError });
|
|
567
557
|
this.set({ [names.model]: model, [names.modelViewAt]: /* @__PURE__ */ new Date(), [names.modelLoading]: false });
|
|
568
558
|
},
|
|
569
559
|
[names.setModel]: function(fullOrLightModel) {
|
|
@@ -571,14 +561,14 @@ const makeActions = (gql) => {
|
|
|
571
561
|
const model = currentState[names.model];
|
|
572
562
|
const isFull = fullOrLightModel instanceof modelRef;
|
|
573
563
|
if (isFull) {
|
|
574
|
-
const crystalizedModel =
|
|
564
|
+
const crystalizedModel = cnst.crystalize(fullOrLightModel);
|
|
575
565
|
this.set({ [names.model]: crystalizedModel });
|
|
576
566
|
} else if (model?.id === fullOrLightModel.id) {
|
|
577
|
-
const crystalizedModel =
|
|
567
|
+
const crystalizedModel = cnst.crystalize({ ...model, ...fullOrLightModel });
|
|
578
568
|
this.set({ [names.model]: crystalizedModel });
|
|
579
569
|
}
|
|
580
|
-
const lightModel =
|
|
581
|
-
|
|
570
|
+
const lightModel = cnst.lightCrystalize(fullOrLightModel);
|
|
571
|
+
slices.forEach(({ sliceName }) => {
|
|
582
572
|
const namesOfSlice = {
|
|
583
573
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
584
574
|
modelListLoading: sliceName.replace(names.model, names.modelListLoading)
|
|
@@ -602,7 +592,7 @@ const makeActions = (gql) => {
|
|
|
602
592
|
return model ?? null;
|
|
603
593
|
}
|
|
604
594
|
};
|
|
605
|
-
const sliceAction =
|
|
595
|
+
const sliceAction = slices.reduce((acc, { sliceName, argLength }) => {
|
|
606
596
|
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
607
597
|
const namesOfSlice = {
|
|
608
598
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
@@ -631,7 +621,7 @@ const makeActions = (gql) => {
|
|
|
631
621
|
const initArgLength = Math.min(args.length, argLength);
|
|
632
622
|
const initForm = { invalidate: false, ...args[argLength] ?? {} };
|
|
633
623
|
const queryArgs = new Array(initArgLength).fill(null).map((_, i) => args[i]);
|
|
634
|
-
const defaultModel = (0, import_signal.immerify)(modelRef, { ...
|
|
624
|
+
const defaultModel = (0, import_signal.immerify)(modelRef, { ...cnst.getDefault(), ...initForm.default ?? {} });
|
|
635
625
|
this.set({ [names.defaultModel]: defaultModel });
|
|
636
626
|
await this[namesOfSlice.refreshModel](
|
|
637
627
|
...initArgLength === argLength ? [...queryArgs, initForm] : queryArgs
|
|
@@ -662,14 +652,14 @@ const makeActions = (gql) => {
|
|
|
662
652
|
else
|
|
663
653
|
this.set({ [namesOfSlice.modelListLoading]: true });
|
|
664
654
|
const [modelDataList, modelInsight] = await Promise.all([
|
|
665
|
-
|
|
655
|
+
fetch[namesOfSlice.modelList](
|
|
666
656
|
...queryArgs,
|
|
667
657
|
(page - 1) * limit,
|
|
668
658
|
limit,
|
|
669
659
|
sort,
|
|
670
660
|
{ onError: initForm.onError }
|
|
671
661
|
),
|
|
672
|
-
|
|
662
|
+
fetch[namesOfSlice.modelInsight](...queryArgs, {
|
|
673
663
|
onError: initForm.onError
|
|
674
664
|
})
|
|
675
665
|
]);
|
|
@@ -711,7 +701,7 @@ const makeActions = (gql) => {
|
|
|
711
701
|
if (pageOfModel === page)
|
|
712
702
|
return;
|
|
713
703
|
this.set({ [namesOfSlice.modelListLoading]: true });
|
|
714
|
-
const modelDataList = await
|
|
704
|
+
const modelDataList = await fetch[namesOfSlice.modelList](
|
|
715
705
|
...queryArgsOfModel,
|
|
716
706
|
(page - 1) * limitOfModel,
|
|
717
707
|
limitOfModel,
|
|
@@ -735,7 +725,7 @@ const makeActions = (gql) => {
|
|
|
735
725
|
if (pageOfModel === page)
|
|
736
726
|
return;
|
|
737
727
|
const addFront = page < pageOfModel;
|
|
738
|
-
const modelDataList = await
|
|
728
|
+
const modelDataList = await fetch[namesOfSlice.modelList](
|
|
739
729
|
...queryArgsOfModel,
|
|
740
730
|
(page - 1) * limitOfModel,
|
|
741
731
|
limitOfModel,
|
|
@@ -758,7 +748,7 @@ const makeActions = (gql) => {
|
|
|
758
748
|
return;
|
|
759
749
|
const skip = (pageOfModel - 1) * limitOfModel;
|
|
760
750
|
const page = Math.max(Math.floor((skip - 1) / limit) + 1, 1);
|
|
761
|
-
const modelDataList = await
|
|
751
|
+
const modelDataList = await fetch[namesOfSlice.modelList](
|
|
762
752
|
...queryArgsOfModel,
|
|
763
753
|
(page - 1) * limit,
|
|
764
754
|
limit,
|
|
@@ -786,14 +776,17 @@ const makeActions = (gql) => {
|
|
|
786
776
|
}
|
|
787
777
|
this.set({ [namesOfSlice.modelListLoading]: true });
|
|
788
778
|
const [modelDataList, modelInsight] = await Promise.all([
|
|
789
|
-
|
|
779
|
+
fetch[namesOfSlice.modelList](
|
|
790
780
|
...queryArgs,
|
|
791
781
|
0,
|
|
792
782
|
limitOfModel,
|
|
793
783
|
sortOfModel,
|
|
794
784
|
options
|
|
795
785
|
),
|
|
796
|
-
|
|
786
|
+
fetch[namesOfSlice.modelInsight](
|
|
787
|
+
...queryArgs,
|
|
788
|
+
options
|
|
789
|
+
)
|
|
797
790
|
]);
|
|
798
791
|
const modelList = new import_base.DataList(modelDataList);
|
|
799
792
|
this.set({
|
|
@@ -814,7 +807,7 @@ const makeActions = (gql) => {
|
|
|
814
807
|
if (sortOfModel === sort)
|
|
815
808
|
return;
|
|
816
809
|
this.set({ [namesOfSlice.modelListLoading]: true });
|
|
817
|
-
const modelDataList = await
|
|
810
|
+
const modelDataList = await fetch[namesOfSlice.modelList](
|
|
818
811
|
...queryArgsOfModel,
|
|
819
812
|
0,
|
|
820
813
|
limitOfModel,
|
|
@@ -834,27 +827,25 @@ const makeActions = (gql) => {
|
|
|
834
827
|
}, {});
|
|
835
828
|
return { ...baseAction, ...sliceAction };
|
|
836
829
|
};
|
|
830
|
+
function store(refNameOrGql, state, ...libStores) {
|
|
831
|
+
const storeRef = libStores.at(0) ?? class StateStore {
|
|
832
|
+
};
|
|
833
|
+
import_storeInfo.storeInfo.setState(storeRef, state);
|
|
834
|
+
return storeRef;
|
|
835
|
+
}
|
|
837
836
|
const stateOf = (gql, state) => {
|
|
838
|
-
const applyState =
|
|
839
|
-
const applyAction =
|
|
840
|
-
setStoreMeta(gql.refName, {
|
|
841
|
-
refName: gql.refName,
|
|
842
|
-
useKeys: Object.keys(applyState),
|
|
843
|
-
doKeys: Object.keys(applyAction),
|
|
844
|
-
slices: gql.slices
|
|
845
|
-
});
|
|
837
|
+
const applyState = state;
|
|
838
|
+
const applyAction = {};
|
|
846
839
|
const applyStore = { ...applyState, ...applyAction };
|
|
847
840
|
class StateStore {
|
|
848
841
|
get;
|
|
849
842
|
set;
|
|
850
843
|
pick;
|
|
851
844
|
}
|
|
852
|
-
Object.
|
|
853
|
-
(key) => Object.defineProperty(StateStore.prototype, key, { value: applyStore[key] })
|
|
854
|
-
);
|
|
845
|
+
Object.assign(StateStore.prototype, applyStore);
|
|
855
846
|
return StateStore;
|
|
856
847
|
};
|
|
857
|
-
const
|
|
848
|
+
const serviceStateOf = (refName, state) => {
|
|
858
849
|
const applyState = state;
|
|
859
850
|
setStoreMeta(refName, { refName, useKeys: Object.keys(applyState), doKeys: [], slices: [] });
|
|
860
851
|
class StateStore {
|
|
@@ -862,19 +853,12 @@ const scalarStateOf = (refName, state) => {
|
|
|
862
853
|
Object.keys(applyState).forEach(
|
|
863
854
|
(key) => Object.defineProperty(StateStore.prototype, key, { value: applyState[key] })
|
|
864
855
|
);
|
|
856
|
+
import_storeInfo.storeInfo.setRefNameTemp(refName, StateStore);
|
|
865
857
|
return StateStore;
|
|
866
858
|
};
|
|
867
|
-
const
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
return function(target) {
|
|
871
|
-
const customDoKeys = Object.getOwnPropertyNames(target.prototype).filter((key) => key !== "constructor");
|
|
872
|
-
setStoreMeta(refName, { ...storeMeta, doKeys: [...storeMeta.doKeys, ...customDoKeys] });
|
|
873
|
-
};
|
|
874
|
-
};
|
|
875
|
-
const createSelectors = (_store, store = {}) => {
|
|
876
|
-
store.get = _store.getState;
|
|
877
|
-
store.set = (s) => {
|
|
859
|
+
const createSelectors = (_store, store2 = {}, slices) => {
|
|
860
|
+
store2.get = _store.getState;
|
|
861
|
+
store2.set = (s) => {
|
|
878
862
|
if (typeof s === "function")
|
|
879
863
|
_store.setState((st) => {
|
|
880
864
|
s(st);
|
|
@@ -882,36 +866,36 @@ const createSelectors = (_store, store = {}) => {
|
|
|
882
866
|
else
|
|
883
867
|
_store.setState(s);
|
|
884
868
|
};
|
|
885
|
-
|
|
886
|
-
const state =
|
|
887
|
-
|
|
869
|
+
store2.sel = (selectFn, equals) => _store(selectFn, equals);
|
|
870
|
+
const state = store2.get();
|
|
871
|
+
store2.sub = _store.subscribe;
|
|
888
872
|
const useReference = (selectFn) => {
|
|
889
|
-
const ref = (0, import_react.useRef)(selectFn(
|
|
873
|
+
const ref = (0, import_react.useRef)(selectFn(store2.get()));
|
|
890
874
|
(0, import_react.useEffect)(() => {
|
|
891
|
-
return
|
|
875
|
+
return store2.sub(selectFn, (val) => ref.current = val);
|
|
892
876
|
}, []);
|
|
893
877
|
return ref;
|
|
894
878
|
};
|
|
895
|
-
|
|
896
|
-
const existingUse =
|
|
897
|
-
const existingDo =
|
|
898
|
-
const existingSlice =
|
|
879
|
+
store2.ref = useReference;
|
|
880
|
+
const existingUse = store2.use;
|
|
881
|
+
const existingDo = store2.do;
|
|
882
|
+
const existingSlice = store2.slice;
|
|
899
883
|
if (!existingUse)
|
|
900
|
-
Object.assign(
|
|
884
|
+
Object.assign(store2, { use: {} });
|
|
901
885
|
if (!existingDo)
|
|
902
|
-
Object.assign(
|
|
886
|
+
Object.assign(store2, { do: {} });
|
|
903
887
|
if (!existingSlice)
|
|
904
|
-
Object.assign(
|
|
888
|
+
Object.assign(store2, { slice: {} });
|
|
905
889
|
for (const k of Object.keys(state)) {
|
|
906
890
|
if (typeof state[k] !== "function") {
|
|
907
|
-
|
|
891
|
+
store2.use[k] = () => store2.sel((s) => s[k]);
|
|
908
892
|
const setKey = `set${(0, import_common.capitalize)(k)}`;
|
|
909
893
|
if (!state[setKey])
|
|
910
|
-
|
|
911
|
-
|
|
894
|
+
store2.do[setKey] = (value) => {
|
|
895
|
+
store2.set({ [k]: value });
|
|
912
896
|
};
|
|
913
897
|
} else {
|
|
914
|
-
|
|
898
|
+
store2.do[k] = async (...args) => {
|
|
915
899
|
try {
|
|
916
900
|
import_common.Logger.verbose(`${k} action loading...`);
|
|
917
901
|
const start = Date.now();
|
|
@@ -926,9 +910,8 @@ const createSelectors = (_store, store = {}) => {
|
|
|
926
910
|
};
|
|
927
911
|
}
|
|
928
912
|
}
|
|
929
|
-
const
|
|
930
|
-
|
|
931
|
-
const [fieldName, className] = [(0, import_common.lowerlize)(storeName), (0, import_common.capitalize)(storeName)];
|
|
913
|
+
for (const slice of slices) {
|
|
914
|
+
const [fieldName, className] = [slice.refName, (0, import_common.capitalize)(slice.refName)];
|
|
932
915
|
const names = {
|
|
933
916
|
model: fieldName,
|
|
934
917
|
Model: className,
|
|
@@ -953,55 +936,52 @@ const createSelectors = (_store, store = {}) => {
|
|
|
953
936
|
setSortOfModel: `setSortOf${className}`,
|
|
954
937
|
lastPageOfModel: `lastPageOf${className}`
|
|
955
938
|
};
|
|
956
|
-
const
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
Object.keys(namesOfSliceAction).forEach((key) => {
|
|
986
|
-
targetSlice.do[names[key]] = store.do[namesOfSliceAction[key]];
|
|
987
|
-
});
|
|
988
|
-
Object.keys(namesOfSliceState).map((key) => {
|
|
989
|
-
targetSlice.use[names[key]] = store.use[namesOfSliceState[key]];
|
|
990
|
-
targetSlice.do[`set${(0, import_common.capitalize)(names[key])}`] = store.do[`set${(0, import_common.capitalize)(namesOfSliceState[key])}`];
|
|
991
|
-
});
|
|
992
|
-
targetSlice.get = () => {
|
|
993
|
-
const state2 = store.get();
|
|
994
|
-
const stateOfSlice = Object.fromEntries(
|
|
995
|
-
Object.entries(namesOfSliceState).map(([key, value]) => [names[key], state2[value]])
|
|
996
|
-
);
|
|
997
|
-
return stateOfSlice;
|
|
998
|
-
};
|
|
999
|
-
targetSlice.sliceName = sliceName;
|
|
1000
|
-
targetSlice.refName = refName;
|
|
1001
|
-
targetSlice.argLength = argLength;
|
|
939
|
+
const SliceName = (0, import_common.capitalize)(slice.sliceName);
|
|
940
|
+
const namesOfSliceState = {
|
|
941
|
+
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
942
|
+
modelInitList: SliceName.replace(names.Model, names.modelInitList),
|
|
943
|
+
modelInsight: slice.sliceName.replace(names.model, names.modelInsight),
|
|
944
|
+
modelList: slice.sliceName.replace(names.model, names.modelList),
|
|
945
|
+
modelListLoading: slice.sliceName.replace(names.model, names.modelListLoading),
|
|
946
|
+
modelInitAt: SliceName.replace(names.Model, names.modelInitAt),
|
|
947
|
+
lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
|
|
948
|
+
pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
|
|
949
|
+
limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
|
|
950
|
+
queryArgsOfModel: SliceName.replace(names.Model, names.queryArgsOfModel),
|
|
951
|
+
sortOfModel: SliceName.replace(names.Model, names.sortOfModel),
|
|
952
|
+
modelSelection: SliceName.replace(names.Model, names.modelSelection)
|
|
953
|
+
};
|
|
954
|
+
const namesOfSliceAction = {
|
|
955
|
+
initModel: SliceName.replace(names.Model, names.initModel),
|
|
956
|
+
refreshModel: SliceName.replace(names.Model, names.refreshModel),
|
|
957
|
+
selectModel: SliceName.replace(names.Model, names.selectModel),
|
|
958
|
+
setPageOfModel: SliceName.replace(names.Model, names.setPageOfModel),
|
|
959
|
+
addPageOfModel: SliceName.replace(names.Model, names.addPageOfModel),
|
|
960
|
+
setLimitOfModel: SliceName.replace(names.Model, names.setLimitOfModel),
|
|
961
|
+
setQueryArgsOfModel: SliceName.replace(names.Model, names.setQueryArgsOfModel),
|
|
962
|
+
setSortOfModel: SliceName.replace(names.Model, names.setSortOfModel)
|
|
963
|
+
};
|
|
964
|
+
store2.slice[slice.sliceName] = { do: {}, use: {} };
|
|
965
|
+
const targetSlice = store2.slice[slice.sliceName];
|
|
966
|
+
Object.keys(namesOfSliceAction).forEach((key) => {
|
|
967
|
+
targetSlice.do[names[key]] = store2.do[namesOfSliceAction[key]];
|
|
1002
968
|
});
|
|
969
|
+
Object.keys(namesOfSliceState).map((key) => {
|
|
970
|
+
targetSlice.use[names[key]] = store2.use[namesOfSliceState[key]];
|
|
971
|
+
targetSlice.do[`set${(0, import_common.capitalize)(names[key])}`] = store2.do[`set${(0, import_common.capitalize)(namesOfSliceState[key])}`];
|
|
972
|
+
});
|
|
973
|
+
targetSlice.get = () => {
|
|
974
|
+
const state2 = store2.get();
|
|
975
|
+
const stateOfSlice = Object.fromEntries(
|
|
976
|
+
Object.entries(namesOfSliceState).map(([key, value]) => [names[key], state2[value]])
|
|
977
|
+
);
|
|
978
|
+
return stateOfSlice;
|
|
979
|
+
};
|
|
980
|
+
targetSlice.sliceName = slice.sliceName;
|
|
981
|
+
targetSlice.refName = slice.refName;
|
|
982
|
+
targetSlice.argLength = slice.argLength;
|
|
1003
983
|
}
|
|
1004
|
-
return
|
|
984
|
+
return store2;
|
|
1005
985
|
};
|
|
1006
986
|
const makePicker = (set, get) => (...fields) => {
|
|
1007
987
|
const state = get();
|
|
@@ -1018,28 +998,39 @@ const makePicker = (set, get) => (...fields) => {
|
|
|
1018
998
|
}
|
|
1019
999
|
return ret;
|
|
1020
1000
|
};
|
|
1021
|
-
const makeStore = (st,
|
|
1022
|
-
if (library)
|
|
1023
|
-
return st;
|
|
1001
|
+
const makeStore = (st, signals) => {
|
|
1024
1002
|
const zustandStore = (0, import_zustand.create)(
|
|
1025
1003
|
(0, import_middleware.devtools)(
|
|
1026
1004
|
(0, import_middleware.subscribeWithSelector)(
|
|
1027
1005
|
(0, import_immer.immer)((set, get) => {
|
|
1028
|
-
const
|
|
1006
|
+
const store2 = {};
|
|
1029
1007
|
const pick = makePicker(set, get);
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1008
|
+
const sliceSet = new Map(signals.map((signal) => [signal.refName, signal.slices]));
|
|
1009
|
+
import_storeInfo.storeInfo.store.forEach((storeRef, refName) => {
|
|
1010
|
+
const state = import_storeInfo.storeInfo.getState(storeRef);
|
|
1011
|
+
const action = import_storeInfo.storeInfo.getAction(storeRef);
|
|
1012
|
+
const isDatabase = import_constant.constantInfo.database.has(refName);
|
|
1013
|
+
const slices = sliceSet.get(refName) ?? [];
|
|
1014
|
+
Object.assign(
|
|
1015
|
+
store2,
|
|
1016
|
+
state,
|
|
1017
|
+
action,
|
|
1018
|
+
...isDatabase ? [
|
|
1019
|
+
createDatabaseState(refName),
|
|
1020
|
+
createSliceState(refName, slices),
|
|
1021
|
+
makeFormSetter(refName),
|
|
1022
|
+
makeActions(refName, slices)
|
|
1023
|
+
] : []
|
|
1024
|
+
);
|
|
1034
1025
|
});
|
|
1035
|
-
Object.assign(
|
|
1036
|
-
return
|
|
1026
|
+
Object.assign(store2, { set, get, pick });
|
|
1027
|
+
return store2;
|
|
1037
1028
|
})
|
|
1038
1029
|
),
|
|
1039
1030
|
{ name: "root", anonymousActionType: "root", type: "root" }
|
|
1040
1031
|
)
|
|
1041
1032
|
);
|
|
1042
|
-
return createSelectors(zustandStore, st);
|
|
1033
|
+
return createSelectors(zustandStore, st, signals.map((signal) => signal.slices).flat());
|
|
1043
1034
|
};
|
|
1044
1035
|
const MixStore = (...stores) => {
|
|
1045
1036
|
if (stores.length === 0)
|
|
@@ -1049,9 +1040,6 @@ const MixStore = (...stores) => {
|
|
|
1049
1040
|
(0, import_common.applyMixins)(Mix, stores);
|
|
1050
1041
|
return Mix;
|
|
1051
1042
|
};
|
|
1052
|
-
const rootStoreOf = (store) => {
|
|
1053
|
-
return Object.getPrototypeOf(store);
|
|
1054
|
-
};
|
|
1055
1043
|
const Toast = ({ root, duration = 3 } = {}) => {
|
|
1056
1044
|
return function(target, key, descriptor) {
|
|
1057
1045
|
const originMethod = descriptor.value;
|