@akanjs/client 0.0.28 → 0.0.29

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.
@@ -1,1111 +0,0 @@
1
- "use client";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var storeDecorators_exports = {};
20
- __export(storeDecorators_exports, {
21
- MixStore: () => MixStore,
22
- Store: () => Store,
23
- Toast: () => Toast,
24
- createActions: () => createActions,
25
- createState: () => createState,
26
- makeStore: () => makeStore,
27
- rootStoreOf: () => rootStoreOf,
28
- scalarStateOf: () => scalarStateOf,
29
- st: () => st,
30
- stateOf: () => stateOf
31
- });
32
- module.exports = __toCommonJS(storeDecorators_exports);
33
- var import_base = require("@akanjs/base");
34
- var import_common = require("@akanjs/common");
35
- var import_constant = require("@akanjs/constant");
36
- var import_dictionary = require("@akanjs/dictionary");
37
- var import_signal = require("@akanjs/signal");
38
- var import_react = require("react");
39
- var import_zustand = require("zustand");
40
- var import_middleware = require("zustand/middleware");
41
- var import_immer = require("zustand/middleware/immer");
42
- const st = {};
43
- class StoreStorage {
44
- }
45
- const getStoreMeta = (storeName) => {
46
- const storeMeta = Reflect.getMetadata(storeName, StoreStorage.prototype);
47
- if (!storeMeta)
48
- throw new Error(`storeMeta is not defined: ${storeName}`);
49
- return storeMeta;
50
- };
51
- const setStoreMeta = (storeName, storeMeta) => {
52
- Reflect.defineMetadata(storeName, storeMeta, StoreStorage.prototype);
53
- };
54
- const getStoreNames = () => {
55
- const storeNames = Reflect.getMetadataKeys(StoreStorage.prototype);
56
- if (!storeNames)
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)];
62
- const names = {
63
- model: fieldName,
64
- Model: className,
65
- modelLoading: `${fieldName}Loading`,
66
- modelForm: `${fieldName}Form`,
67
- modelFormLoading: `${fieldName}FormLoading`,
68
- modelSubmit: `${fieldName}Submit`,
69
- modelViewAt: `${fieldName}ViewAt`,
70
- modelModal: `${fieldName}Modal`,
71
- modelOperation: `${fieldName}Operation`,
72
- defaultModel: `default${className}`,
73
- defaultModelInsight: `default${className}Insight`,
74
- modelList: `${fieldName}List`,
75
- modelListLoading: `${fieldName}ListLoading`,
76
- modelInitList: `${fieldName}InitList`,
77
- modelInitAt: `${fieldName}InitAt`,
78
- modelSelection: `${fieldName}Selection`,
79
- modelInsight: `${fieldName}Insight`,
80
- lastPageOfModel: `lastPageOf${className}`,
81
- pageOfModel: `pageOf${className}`,
82
- limitOfModel: `limitOf${className}`,
83
- queryArgsOfModel: `queryArgsOf${className}`,
84
- sortOfModel: `sortOf${className}`
85
- };
86
- const baseState = {
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 }) => {
97
- const SliceName = (0, import_common.capitalize)(sliceName);
98
- const namesOfSlice = {
99
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
100
- //clusterInSelf Cluster
101
- modelList: sliceName.replace(names.model, names.modelList),
102
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
103
- modelInitList: sliceName.replace(names.model, names.modelInitList),
104
- modelInitAt: sliceName.replace(names.model, names.modelInitAt),
105
- modelSelection: sliceName.replace(names.model, names.modelSelection),
106
- modelInsight: sliceName.replace(names.model, names.modelInsight),
107
- lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
108
- pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
109
- limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
110
- queryArgsOfModel: SliceName.replace(names.Model, names.queryArgsOfModel),
111
- sortOfModel: SliceName.replace(names.Model, names.sortOfModel)
112
- };
113
- const singleSliceState = {
114
- [namesOfSlice.defaultModel]: { ...gql[names.defaultModel] },
115
- [namesOfSlice.modelList]: new import_base.DataList(),
116
- [namesOfSlice.modelListLoading]: true,
117
- [namesOfSlice.modelInitList]: new import_base.DataList(),
118
- [namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(0),
119
- [namesOfSlice.modelSelection]: new import_base.DataList(),
120
- [namesOfSlice.modelInsight]: gql[names.defaultModelInsight],
121
- [namesOfSlice.lastPageOfModel]: 1,
122
- [namesOfSlice.pageOfModel]: 1,
123
- [namesOfSlice.limitOfModel]: 20,
124
- [namesOfSlice.queryArgsOfModel]: defaultArgs,
125
- [namesOfSlice.sortOfModel]: "latest"
126
- };
127
- return Object.assign(acc, singleSliceState);
128
- }, {});
129
- return { ...baseState, ...sliceState };
130
- };
131
- const createActions = (gql) => {
132
- const formSetterActions = makeFormSetter(gql);
133
- const baseActions = makeActions(gql);
134
- return { ...formSetterActions, ...baseActions };
135
- };
136
- const makeFormSetter = (gql) => {
137
- const fileGql = (0, import_signal.getGqlOnStorage)("file");
138
- const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
139
- const modelRef = (0, import_constant.getFullModelRef)(gql.refName);
140
- const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
141
- const names = {
142
- model: fieldName,
143
- Model: className,
144
- modelForm: `${fieldName}Form`,
145
- writeOnModel: `writeOn${className}`,
146
- addModelFiles: `add${className}Files`
147
- };
148
- const baseSetAction = {
149
- [names.writeOnModel]: function(path, value) {
150
- this.set((state) => {
151
- (0, import_common.pathSet)(state[names.modelForm], path, value);
152
- });
153
- }
154
- };
155
- const fieldSetAction = fieldMetas.reduce((acc, fieldMeta) => {
156
- const [fieldKeyName, classKeyName] = [(0, import_common.lowerlize)(fieldMeta.key), (0, import_common.capitalize)(fieldMeta.key)];
157
- const namesOfField = {
158
- field: fieldKeyName,
159
- Field: classKeyName,
160
- setFieldOnModel: `set${classKeyName}On${className}`,
161
- addFieldOnModel: `add${classKeyName}On${className}`,
162
- subFieldOnModel: `sub${classKeyName}On${className}`,
163
- addOrSubFieldOnModel: `addOrSub${classKeyName}On${className}`,
164
- uploadFieldOnModel: `upload${classKeyName}On${className}`
165
- };
166
- const singleFieldSetAction = {
167
- [namesOfField.setFieldOnModel]: function(value) {
168
- this.set((state) => {
169
- const setValue = fieldMeta.isClass ? (0, import_signal.immerify)(fieldMeta.modelRef, value) : value;
170
- state[names.modelForm][namesOfField.field] = setValue;
171
- });
172
- },
173
- ...fieldMeta.isArray ? {
174
- [namesOfField.addFieldOnModel]: function(value, options = {}) {
175
- const form = this.get()[names.modelForm];
176
- const length = form[namesOfField.field].length;
177
- if (options.limit && options.limit <= length)
178
- return;
179
- const idx = options.idx ?? length;
180
- const setValue = fieldMeta.isClass ? (0, import_signal.immerify)(fieldMeta.modelRef, value) : value;
181
- this.set((state) => {
182
- state[names.modelForm][namesOfField.field] = [
183
- ...form[namesOfField.field].slice(0, idx),
184
- ...Array.isArray(setValue) ? setValue : [setValue],
185
- ...form[namesOfField.field].slice(idx)
186
- ];
187
- });
188
- },
189
- [namesOfField.subFieldOnModel]: function(idx) {
190
- const form = this.get()[names.modelForm];
191
- this.set((state) => {
192
- state[names.modelForm][namesOfField.field] = typeof idx === "number" ? form[namesOfField.field].filter((_, i) => i !== idx) : form[namesOfField.field].filter((_, i) => !idx.includes(i));
193
- });
194
- },
195
- [namesOfField.addOrSubFieldOnModel]: function(value, options = {}) {
196
- const { [names.modelForm]: form } = this.get();
197
- const index = form[namesOfField.field].findIndex((v) => v === value);
198
- if (index === -1)
199
- this[namesOfField.addFieldOnModel](value, options);
200
- else
201
- this[namesOfField.subFieldOnModel](index);
202
- }
203
- } : {},
204
- ...fieldMeta.name === "File" ? {
205
- [namesOfField.uploadFieldOnModel]: async function(fileList, index) {
206
- const form = this.get()[names.modelForm];
207
- if (!fileList.length)
208
- return;
209
- const files = await gql[names.addModelFiles](
210
- fileList,
211
- form.id
212
- );
213
- if (fieldMeta.isArray) {
214
- const idx = index ?? form[namesOfField.field].length;
215
- this.set((state) => {
216
- state[names.modelForm][namesOfField.field] = [
217
- ...form[namesOfField.field].slice(0, idx),
218
- ...files,
219
- ...form[namesOfField.field].slice(idx)
220
- ];
221
- });
222
- } else {
223
- this.set((state) => {
224
- state[names.modelForm][namesOfField.field] = files[0];
225
- });
226
- }
227
- files.map((file) => {
228
- const intervalKey = setInterval(() => {
229
- void (async () => {
230
- const currentFile = await fileGql.file(file.id);
231
- if (fieldMeta.isArray)
232
- this.set((state) => {
233
- state[names.modelForm][namesOfField.field] = state[names.modelForm][namesOfField.field].map(
234
- (file2) => file2.id === currentFile.id ? currentFile : file2
235
- );
236
- });
237
- else
238
- this.set((state) => {
239
- state[names.modelForm][namesOfField.field] = currentFile;
240
- });
241
- if (currentFile.status !== "uploading")
242
- clearInterval(intervalKey);
243
- })();
244
- }, 3e3);
245
- });
246
- }
247
- } : {}
248
- };
249
- return Object.assign(acc, singleFieldSetAction);
250
- }, {});
251
- return Object.assign(fieldSetAction, baseSetAction);
252
- };
253
- const makeActions = (gql) => {
254
- const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
255
- const modelRef = (0, import_constant.getFullModelRef)(className);
256
- const lightModelRef = (0, import_constant.getLightModelRef)(modelRef);
257
- const names = {
258
- model: fieldName,
259
- _model: `_${fieldName}`,
260
- Model: className,
261
- purifyModel: `purify${className}`,
262
- crystalizeModel: `crystalize${className}`,
263
- lightCrystalizeModel: `lightCrystalize${className}`,
264
- crystalizeInsight: `crystalize${className}Insight`,
265
- modelOperation: `${fieldName}Operation`,
266
- defaultModel: `default${className}`,
267
- modelInsight: `${fieldName}Insight`,
268
- modelForm: `${fieldName}Form`,
269
- modelSubmit: `${fieldName}Submit`,
270
- modelLoading: `${fieldName}Loading`,
271
- modelFormLoading: `${fieldName}FormLoading`,
272
- modelList: `${fieldName}List`,
273
- modelListLoading: `${fieldName}ListLoading`,
274
- modelSelection: `${fieldName}Selection`,
275
- createModelInForm: `create${className}InForm`,
276
- updateModelInForm: `modify${className}InForm`,
277
- createModel: `create${className}`,
278
- updateModel: `update${className}`,
279
- removeModel: `remove${className}`,
280
- checkModelSubmitable: `check${className}Submitable`,
281
- submitModel: `submit${className}`,
282
- newModel: `new${className}`,
283
- editModel: `edit${className}`,
284
- mergeModel: `merge${className}`,
285
- viewModel: `view${className}`,
286
- setModel: `set${className}`,
287
- resetModel: `reset${className}`,
288
- modelViewAt: `${fieldName}ViewAt`,
289
- modelModal: `${fieldName}Modal`,
290
- initModel: `init${className}`,
291
- modelInitList: `${fieldName}InitList`,
292
- modelInitAt: `${fieldName}InitAt`,
293
- refreshModel: `refresh${className}`,
294
- selectModel: `select${className}`,
295
- setPageOfModel: `setPageOf${className}`,
296
- addPageOfModel: `addPageOf${className}`,
297
- setLimitOfModel: `setLimitOf${className}`,
298
- setQueryArgsOfModel: `setQueryArgsOf${className}`,
299
- setSortOfModel: `setSortOf${className}`,
300
- lastPageOfModel: `lastPageOf${className}`,
301
- pageOfModel: `pageOf${className}`,
302
- limitOfModel: `limitOf${className}`,
303
- queryArgsOfModel: `queryArgsOf${className}`,
304
- sortOfModel: `sortOf${className}`
305
- };
306
- const baseAction = {
307
- [names.createModelInForm]: async function({ idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
308
- const SliceName = (0, import_common.capitalize)(sliceName);
309
- const namesOfSlice = {
310
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
311
- modelList: sliceName.replace(names.model, names.modelList),
312
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
313
- modelInsight: sliceName.replace(names.model, names.modelInsight)
314
- };
315
- const currentState = this.get();
316
- const modelForm = currentState[names.modelForm];
317
- const modelList = currentState[namesOfSlice.modelList];
318
- const modelListLoading = currentState[namesOfSlice.modelListLoading];
319
- const modelInsight = currentState[namesOfSlice.modelInsight];
320
- const defaultModel = currentState[namesOfSlice.defaultModel];
321
- const modelInput = gql[names.purifyModel](modelForm);
322
- if (!modelInput)
323
- return;
324
- this.set({ [names.modelLoading]: true });
325
- const model = await gql[names.createModel](modelInput, { onError });
326
- const newModelList = modelListLoading ? modelList : new import_base.DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
327
- const newModelInsight = gql[names.crystalizeInsight]({
328
- ...modelInsight,
329
- count: modelInsight.count + 1
330
- });
331
- this.set({
332
- [names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
333
- [names.model]: model,
334
- [names.modelLoading]: false,
335
- [namesOfSlice.modelList]: newModelList,
336
- [namesOfSlice.modelInsight]: newModelInsight,
337
- [names.modelViewAt]: /* @__PURE__ */ new Date(),
338
- [names.modelModal]: modal ?? null,
339
- ...typeof path === "string" && path ? { [path]: model } : {}
340
- });
341
- await onSuccess?.(model);
342
- },
343
- [names.updateModelInForm]: async function({ path, modal, sliceName = names.model, onError, onSuccess } = {}) {
344
- const SliceName = (0, import_common.capitalize)(sliceName);
345
- const namesOfSlice = {
346
- defaultModel: SliceName.replace(names.Model, names.defaultModel)
347
- };
348
- const currentState = this.get();
349
- const model = currentState[names.model];
350
- const modelForm = currentState[names.modelForm];
351
- const defaultModel = currentState[namesOfSlice.defaultModel];
352
- const modelInput = gql[names.purifyModel](modelForm);
353
- if (!modelInput)
354
- return;
355
- if (model?.id === modelForm.id)
356
- this.set({ [names.modelLoading]: modelForm.id });
357
- const updatedModel = await gql[names.updateModel](modelForm.id, modelInput, {
358
- onError
359
- });
360
- this.set({
361
- ...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
362
- [names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
363
- [names.modelModal]: modal ?? null,
364
- ...typeof path === "string" && path ? { [path]: updatedModel } : {}
365
- });
366
- const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
367
- gql.slices.forEach(({ sliceName: sliceName2 }) => {
368
- const namesOfSlice2 = {
369
- modelList: sliceName2.replace(names.model, names.modelList),
370
- modelListLoading: sliceName2.replace(names.model, names.modelListLoading)
371
- };
372
- const currentState2 = this.get();
373
- const modelList = currentState2[namesOfSlice2.modelList];
374
- const modelListLoading = currentState2[namesOfSlice2.modelListLoading];
375
- if (modelListLoading || !modelList.has(updatedModel.id))
376
- return;
377
- const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
378
- this.set({ [namesOfSlice2.modelList]: newModelList });
379
- });
380
- await onSuccess?.(updatedModel);
381
- },
382
- [names.createModel]: async function(data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
383
- const SliceName = (0, import_common.capitalize)(sliceName);
384
- const namesOfSlice = {
385
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
386
- modelList: sliceName.replace(names.model, names.modelList),
387
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
388
- modelInsight: sliceName.replace(names.model, names.modelInsight)
389
- };
390
- const currentState = this.get();
391
- const modelList = currentState[namesOfSlice.modelList];
392
- const modelListLoading = currentState[namesOfSlice.modelListLoading];
393
- const modelInsight = currentState[namesOfSlice.modelInsight];
394
- const modelInput = gql[names.purifyModel](data);
395
- if (!modelInput)
396
- return;
397
- this.set({ [names.modelLoading]: true });
398
- const model = await gql[names.createModel](modelInput, { onError });
399
- const newModelList = modelListLoading ? modelList : new import_base.DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
400
- const newModelInsight = gql[names.crystalizeInsight]({
401
- ...modelInsight,
402
- count: modelInsight.count + 1
403
- });
404
- this.set({
405
- [names.model]: model,
406
- [names.modelLoading]: false,
407
- [namesOfSlice.modelList]: newModelList,
408
- [namesOfSlice.modelInsight]: newModelInsight,
409
- [names.modelViewAt]: /* @__PURE__ */ new Date(),
410
- [names.modelModal]: modal ?? null,
411
- ...typeof path === "string" && path ? { [path]: model } : {}
412
- });
413
- await onSuccess?.(model);
414
- },
415
- [names.updateModel]: async function(id, data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
416
- const currentState = this.get();
417
- const model = currentState[names.model];
418
- const modelInput = gql[names.purifyModel](data);
419
- if (!modelInput)
420
- return;
421
- if (model?.id === id)
422
- this.set({ [names.modelLoading]: id });
423
- const updatedModel = await gql[names.updateModel](id, modelInput, { onError });
424
- this.set({
425
- ...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
426
- [names.modelModal]: modal ?? null,
427
- ...typeof path === "string" && path ? { [path]: updatedModel } : {}
428
- });
429
- const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
430
- gql.slices.forEach(({ sliceName: sliceName2 }) => {
431
- const namesOfSlice = {
432
- modelList: sliceName2.replace(names.model, names.modelList),
433
- modelListLoading: sliceName2.replace(names.model, names.modelListLoading)
434
- };
435
- const currentState2 = this.get();
436
- const modelList = currentState2[namesOfSlice.modelList];
437
- const modelListLoading = currentState2[namesOfSlice.modelListLoading];
438
- if (modelListLoading || !modelList.has(updatedModel.id))
439
- return;
440
- const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
441
- this.set({ [namesOfSlice.modelList]: newModelList });
442
- });
443
- await onSuccess?.(updatedModel);
444
- },
445
- [names.removeModel]: async function(id, options) {
446
- const { modal, ...fetchPolicyOptions } = options ?? {};
447
- const model = await gql[names.removeModel](
448
- id,
449
- fetchPolicyOptions
450
- );
451
- const lightModel = gql[names.lightCrystalizeModel](model);
452
- gql.slices.forEach(({ sliceName }) => {
453
- const namesOfSlice = {
454
- modelList: sliceName.replace(names.model, names.modelList),
455
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
456
- modelSelection: sliceName.replace(names.model, names.modelSelection),
457
- modelInsight: sliceName.replace(names.model, names.modelInsight)
458
- };
459
- const currentState = this.get();
460
- const modelList = currentState[namesOfSlice.modelList];
461
- const modelListLoading = currentState[namesOfSlice.modelListLoading];
462
- const modelSelection = currentState[namesOfSlice.modelSelection];
463
- const modelInsight = currentState[namesOfSlice.modelInsight];
464
- if (modelListLoading || !modelList.has(model.id))
465
- return;
466
- const newModelList = new import_base.DataList(modelList);
467
- if (model.removedAt) {
468
- newModelList.delete(id);
469
- const newModelInsight = gql[names.crystalizeInsight]({
470
- ...modelInsight,
471
- count: modelInsight.count - 1
472
- });
473
- const newModelSelection = new import_base.DataList(modelSelection);
474
- newModelSelection.delete(id);
475
- this.set({
476
- [namesOfSlice.modelList]: newModelList,
477
- [namesOfSlice.modelInsight]: newModelInsight,
478
- ...modelSelection.has(model.id) ? { [namesOfSlice.modelSelection]: newModelSelection } : {},
479
- ...modal !== void 0 ? { [names.modelModal]: modal } : {}
480
- });
481
- } else {
482
- newModelList.set(lightModel);
483
- this.set({
484
- [namesOfSlice.modelList]: newModelList,
485
- ...modal !== void 0 ? { [names.modelModal]: modal } : {}
486
- });
487
- }
488
- });
489
- },
490
- [names.checkModelSubmitable]: function(disabled) {
491
- const currentState = this.get();
492
- const modelForm = currentState[names.modelForm];
493
- const modelSubmit = currentState[names.modelSubmit];
494
- const modelInput = gql[names.purifyModel](modelForm);
495
- this.set({ [names.modelSubmit]: { ...modelSubmit, disabled: !modelInput || disabled } });
496
- },
497
- [names.submitModel]: async function(option) {
498
- const currentState = this.get();
499
- const modelForm = currentState[names.modelForm];
500
- const modelSubmit = currentState[names.modelSubmit];
501
- this.set({ [names.modelSubmit]: { ...modelSubmit, loading: true } });
502
- if (modelForm.id)
503
- await this[names.updateModelInForm](option);
504
- else
505
- await this[names.createModelInForm](option);
506
- this.set({ [names.modelSubmit]: { ...modelSubmit, loading: false, times: modelSubmit.times + 1 } });
507
- },
508
- [names.newModel]: function(partial = {}, { modal, setDefault, sliceName = names.model } = {}) {
509
- const SliceName = (0, import_common.capitalize)(sliceName);
510
- const namesOfSlice = {
511
- defaultModel: SliceName.replace(names.Model, names.defaultModel)
512
- };
513
- const currentState = this.get();
514
- const defaultModel = currentState[namesOfSlice.defaultModel];
515
- this.set({
516
- [names.modelForm]: (0, import_signal.immerify)(modelRef, { ...defaultModel, ...partial }),
517
- [namesOfSlice.defaultModel]: setDefault ? (0, import_signal.immerify)(modelRef, { ...defaultModel, ...partial }) : defaultModel,
518
- [names.model]: null,
519
- [names.modelModal]: modal ?? "edit",
520
- [names.modelFormLoading]: false
521
- });
522
- },
523
- [names.editModel]: async function(modelOrId, { modal, onError } = {}) {
524
- const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
525
- this.set({ [names.modelFormLoading]: id, [names.modelModal]: modal ?? "edit" });
526
- this.set((state) => {
527
- state[names.modelForm].id = id;
528
- });
529
- const model = await gql[names.model](id, { onError });
530
- const modelForm = (0, import_common.deepObjectify)(model);
531
- this.set({
532
- [names.model]: model,
533
- [names.modelFormLoading]: false,
534
- [names.modelViewAt]: /* @__PURE__ */ new Date(),
535
- [names.modelForm]: modelForm
536
- });
537
- },
538
- [names.mergeModel]: async function(modelOrId, data, options) {
539
- const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
540
- const currentState = this.get();
541
- const model = currentState[names.model];
542
- if (id === model?.id)
543
- this.set({ modelLoading: id });
544
- const updatedModel = await gql[names.mergeModel](modelOrId, data, options);
545
- this.set({
546
- [names.model]: id === model?.id ? updatedModel : model,
547
- [names.modelLoading]: false
548
- });
549
- const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
550
- gql.slices.forEach(({ sliceName }) => {
551
- const namesOfSlice = {
552
- modelList: sliceName.replace(names.model, names.modelList),
553
- modelListLoading: sliceName.replace(names.model, names.modelListLoading)
554
- };
555
- const currentState2 = this.get();
556
- const modelList = currentState2[namesOfSlice.modelList];
557
- const modelListLoading = currentState2[namesOfSlice.modelListLoading];
558
- if (modelListLoading || !modelList.has(updatedModel.id))
559
- return;
560
- const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
561
- this.set({ [namesOfSlice.modelList]: newModelList });
562
- });
563
- },
564
- [names.viewModel]: async function(modelOrId, { modal, onError } = {}) {
565
- const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
566
- this.set({ [names.modelModal]: modal ?? "view", [names.modelLoading]: id });
567
- const model = await gql[names.model](id, { onError });
568
- this.set({ [names.model]: model, [names.modelViewAt]: /* @__PURE__ */ new Date(), [names.modelLoading]: false });
569
- },
570
- [names.setModel]: function(fullOrLightModel) {
571
- const currentState = this.get();
572
- const model = currentState[names.model];
573
- const isFull = fullOrLightModel instanceof modelRef;
574
- if (isFull) {
575
- const crystalizedModel = gql[names.crystalizeModel](fullOrLightModel);
576
- this.set({ [names.model]: crystalizedModel });
577
- } else if (model?.id === fullOrLightModel.id) {
578
- const crystalizedModel = gql[names.crystalizeModel]({ ...model, ...fullOrLightModel });
579
- this.set({ [names.model]: crystalizedModel });
580
- }
581
- const lightModel = gql[names.lightCrystalizeModel](fullOrLightModel);
582
- gql.slices.forEach(({ sliceName }) => {
583
- const namesOfSlice = {
584
- modelList: sliceName.replace(names.model, names.modelList),
585
- modelListLoading: sliceName.replace(names.model, names.modelListLoading)
586
- };
587
- const modelList = currentState[namesOfSlice.modelList];
588
- const modelListLoading = currentState[namesOfSlice.modelListLoading];
589
- if (modelListLoading || !modelList.has(lightModel.id))
590
- return;
591
- this.set({ [namesOfSlice.modelList]: modelList.set(lightModel).save() });
592
- });
593
- },
594
- [names.resetModel]: function(model) {
595
- const currentState = this.get();
596
- const defaultModel = currentState[names.defaultModel];
597
- this.set({
598
- [names.model]: model ?? null,
599
- [names.modelViewAt]: /* @__PURE__ */ new Date(0),
600
- [names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
601
- [names.modelModal]: null
602
- });
603
- return model ?? null;
604
- }
605
- };
606
- const sliceAction = gql.slices.reduce((acc, { sliceName, argLength }) => {
607
- const SliceName = (0, import_common.capitalize)(sliceName);
608
- const namesOfSlice = {
609
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
610
- modelInsight: sliceName.replace(names.model, names.modelInsight),
611
- modelList: sliceName.replace(names.model, names.modelList),
612
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
613
- initModel: SliceName.replace(names.Model, names.initModel),
614
- modelInitList: SliceName.replace(names.Model, names.modelInitList),
615
- modelInitAt: SliceName.replace(names.Model, names.modelInitAt),
616
- refreshModel: SliceName.replace(names.Model, names.refreshModel),
617
- selectModel: SliceName.replace(names.Model, names.selectModel),
618
- setPageOfModel: SliceName.replace(names.Model, names.setPageOfModel),
619
- addPageOfModel: SliceName.replace(names.Model, names.addPageOfModel),
620
- setLimitOfModel: SliceName.replace(names.Model, names.setLimitOfModel),
621
- setQueryArgsOfModel: SliceName.replace(names.Model, names.setQueryArgsOfModel),
622
- setSortOfModel: SliceName.replace(names.Model, names.setSortOfModel),
623
- lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
624
- pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
625
- limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
626
- queryArgsOfModel: SliceName.replace(names.Model, names.queryArgsOfModel),
627
- sortOfModel: SliceName.replace(names.Model, names.sortOfModel),
628
- modelSelection: SliceName.replace(names.Model, names.modelSelection)
629
- };
630
- const singleSliceAction = {
631
- [namesOfSlice.initModel]: async function(...args) {
632
- const initArgLength = Math.min(args.length, argLength);
633
- const initForm = { invalidate: false, ...args[argLength] ?? {} };
634
- const queryArgs = new Array(initArgLength).fill(null).map((_, i) => args[i]);
635
- const defaultModel = (0, import_signal.immerify)(modelRef, { ...gql[names.defaultModel], ...initForm.default ?? {} });
636
- this.set({ [names.defaultModel]: defaultModel });
637
- await this[namesOfSlice.refreshModel](
638
- ...initArgLength === argLength ? [...queryArgs, initForm] : queryArgs
639
- );
640
- },
641
- [namesOfSlice.refreshModel]: async function(...args) {
642
- const refreshArgLength = Math.min(args.length, argLength);
643
- const currentState = this.get();
644
- const existingQueryArgs = currentState[namesOfSlice.queryArgsOfModel];
645
- const queryArgs = [
646
- ...new Array(refreshArgLength).fill(null).map((_, i) => args[i]),
647
- ...existingQueryArgs.slice(refreshArgLength, argLength)
648
- ];
649
- const initForm = args[argLength] ?? {};
650
- const {
651
- page = currentState[namesOfSlice.pageOfModel],
652
- limit = currentState[namesOfSlice.limitOfModel],
653
- sort = currentState[namesOfSlice.sortOfModel],
654
- invalidate = true
655
- } = initForm;
656
- const modelOperation = currentState[names.modelOperation];
657
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
658
- const pageOfModel = currentState[namesOfSlice.pageOfModel];
659
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
660
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
661
- if (!invalidate && !["sleep", "reset"].includes(modelOperation) && (0, import_common.isQueryEqual)(queryArgs, queryArgsOfModel) && page === pageOfModel && limit === limitOfModel && (0, import_common.isQueryEqual)(sort, sortOfModel))
662
- return;
663
- else
664
- this.set({ [namesOfSlice.modelListLoading]: true });
665
- const [modelDataList, modelInsight] = await Promise.all([
666
- gql[namesOfSlice.modelList](
667
- ...queryArgs,
668
- (page - 1) * limit,
669
- limit,
670
- sort,
671
- { onError: initForm.onError }
672
- ),
673
- gql[namesOfSlice.modelInsight](...queryArgs, {
674
- onError: initForm.onError
675
- })
676
- ]);
677
- const modelList = new import_base.DataList(modelDataList);
678
- this.set({
679
- [namesOfSlice.modelList]: modelList,
680
- [namesOfSlice.modelListLoading]: false,
681
- [namesOfSlice.modelInsight]: modelInsight,
682
- [namesOfSlice.modelInitList]: modelList,
683
- [namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(),
684
- [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limit) + 1, 1),
685
- [namesOfSlice.limitOfModel]: limit,
686
- [namesOfSlice.queryArgsOfModel]: queryArgs,
687
- [namesOfSlice.sortOfModel]: sort,
688
- [namesOfSlice.pageOfModel]: page,
689
- [names.modelOperation]: "idle"
690
- });
691
- },
692
- [namesOfSlice.selectModel]: function(model, { refresh, remove } = {}) {
693
- const models = Array.isArray(model) ? model : [model];
694
- const currentState = this.get();
695
- const modelSelection = currentState[namesOfSlice.modelSelection];
696
- if (refresh)
697
- this.set({ [namesOfSlice.modelSelection]: new import_base.DataList(models) });
698
- else if (remove) {
699
- const newModelSelection = new import_base.DataList(modelSelection);
700
- models.map((model2) => newModelSelection.delete(model2.id));
701
- this.set({ [namesOfSlice.modelSelection]: newModelSelection });
702
- } else {
703
- this.set({ [namesOfSlice.modelSelection]: new import_base.DataList([...modelSelection.values, ...models]) });
704
- }
705
- },
706
- [namesOfSlice.setPageOfModel]: async function(page, options) {
707
- const currentState = this.get();
708
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
709
- const pageOfModel = currentState[namesOfSlice.pageOfModel];
710
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
711
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
712
- if (pageOfModel === page)
713
- return;
714
- this.set({ [namesOfSlice.modelListLoading]: true });
715
- const modelDataList = await gql[namesOfSlice.modelList](
716
- ...queryArgsOfModel,
717
- (page - 1) * limitOfModel,
718
- limitOfModel,
719
- sortOfModel,
720
- options
721
- );
722
- const modelList = new import_base.DataList(modelDataList);
723
- this.set({
724
- [namesOfSlice.modelList]: modelList,
725
- [namesOfSlice.pageOfModel]: page,
726
- [namesOfSlice.modelListLoading]: false
727
- });
728
- },
729
- [namesOfSlice.addPageOfModel]: async function(page, options) {
730
- const currentState = this.get();
731
- const modelList = currentState[namesOfSlice.modelList];
732
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
733
- const pageOfModel = currentState[namesOfSlice.pageOfModel];
734
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
735
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
736
- if (pageOfModel === page)
737
- return;
738
- const addFront = page < pageOfModel;
739
- const modelDataList = await gql[namesOfSlice.modelList](
740
- ...queryArgsOfModel,
741
- (page - 1) * limitOfModel,
742
- limitOfModel,
743
- sortOfModel,
744
- options
745
- );
746
- const newModelList = new import_base.DataList(
747
- addFront ? [...modelDataList, ...modelList] : [...modelList, ...modelDataList]
748
- );
749
- this.set({ [namesOfSlice.modelList]: newModelList, [namesOfSlice.pageOfModel]: page });
750
- },
751
- [namesOfSlice.setLimitOfModel]: async function(limit, options) {
752
- const currentState = this.get();
753
- const modelInsight = currentState[namesOfSlice.modelInsight];
754
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
755
- const pageOfModel = currentState[namesOfSlice.pageOfModel];
756
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
757
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
758
- if (limitOfModel === limit)
759
- return;
760
- const skip = (pageOfModel - 1) * limitOfModel;
761
- const page = Math.max(Math.floor((skip - 1) / limit) + 1, 1);
762
- const modelDataList = await gql[namesOfSlice.modelList](
763
- ...queryArgsOfModel,
764
- (page - 1) * limit,
765
- limit,
766
- sortOfModel,
767
- options
768
- );
769
- const modelList = new import_base.DataList(modelDataList);
770
- this.set({
771
- [namesOfSlice.modelList]: modelList,
772
- [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limit) + 1, 1),
773
- [namesOfSlice.limitOfModel]: limit,
774
- [namesOfSlice.pageOfModel]: page
775
- });
776
- },
777
- [namesOfSlice.setQueryArgsOfModel]: async function(...args) {
778
- const queryArgs = new Array(argLength).fill(null).map((_, i) => args[i]);
779
- const options = args[argLength];
780
- const currentState = this.get();
781
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
782
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
783
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
784
- if ((0, import_common.isQueryEqual)(queryArgsOfModel, queryArgs)) {
785
- import_common.Logger.trace(`${namesOfSlice.queryArgsOfModel} store-level cache hit`);
786
- return;
787
- }
788
- this.set({ [namesOfSlice.modelListLoading]: true });
789
- const [modelDataList, modelInsight] = await Promise.all([
790
- gql[namesOfSlice.modelList](
791
- ...queryArgs,
792
- 0,
793
- limitOfModel,
794
- sortOfModel,
795
- options
796
- ),
797
- gql[namesOfSlice.modelInsight](...queryArgs, options)
798
- ]);
799
- const modelList = new import_base.DataList(modelDataList);
800
- this.set({
801
- [namesOfSlice.queryArgsOfModel]: queryArgs,
802
- [namesOfSlice.modelList]: modelList,
803
- [namesOfSlice.modelInsight]: modelInsight,
804
- [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limitOfModel) + 1, 1),
805
- [namesOfSlice.pageOfModel]: 1,
806
- [namesOfSlice.modelSelection]: /* @__PURE__ */ new Map(),
807
- [namesOfSlice.modelListLoading]: false
808
- });
809
- },
810
- [namesOfSlice.setSortOfModel]: async function(sort, options) {
811
- const currentState = this.get();
812
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
813
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
814
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
815
- if (sortOfModel === sort)
816
- return;
817
- this.set({ [namesOfSlice.modelListLoading]: true });
818
- const modelDataList = await gql[namesOfSlice.modelList](
819
- ...queryArgsOfModel,
820
- 0,
821
- limitOfModel,
822
- sort,
823
- options
824
- );
825
- const modelList = new import_base.DataList(modelDataList);
826
- this.set({
827
- [namesOfSlice.modelList]: modelList,
828
- [namesOfSlice.sortOfModel]: sort,
829
- [namesOfSlice.pageOfModel]: 1,
830
- [namesOfSlice.modelListLoading]: false
831
- });
832
- }
833
- };
834
- return Object.assign(acc, singleSliceAction);
835
- }, {});
836
- return { ...baseAction, ...sliceAction };
837
- };
838
- const stateOf = (gql, state) => {
839
- const applyState = Object.assign(createState(gql), state);
840
- const applyAction = createActions(gql);
841
- setStoreMeta(gql.refName, {
842
- refName: gql.refName,
843
- useKeys: Object.keys(applyState),
844
- doKeys: Object.keys(applyAction),
845
- slices: gql.slices
846
- });
847
- const applyStore = { ...applyState, ...applyAction };
848
- class StateStore {
849
- get;
850
- set;
851
- pick;
852
- }
853
- Object.keys(applyStore).forEach(
854
- (key) => Object.defineProperty(StateStore.prototype, key, { value: applyStore[key] })
855
- );
856
- return StateStore;
857
- };
858
- const scalarStateOf = (refName, state) => {
859
- const applyState = state;
860
- setStoreMeta(refName, { refName, useKeys: Object.keys(applyState), doKeys: [], slices: [] });
861
- class StateStore {
862
- get;
863
- set;
864
- pick;
865
- }
866
- Object.keys(applyState).forEach(
867
- (key) => Object.defineProperty(StateStore.prototype, key, { value: applyState[key] })
868
- );
869
- return StateStore;
870
- };
871
- const Store = (returnsOrObj) => {
872
- const refName = typeof returnsOrObj === "object" ? returnsOrObj.name : (0, import_common.lowerlize)((0, import_constant.getClassMeta)(returnsOrObj()).refName);
873
- const storeMeta = getStoreMeta(refName);
874
- return function(target) {
875
- const customDoKeys = Object.getOwnPropertyNames(target.prototype).filter((key) => key !== "constructor");
876
- setStoreMeta(refName, { ...storeMeta, doKeys: [...storeMeta.doKeys, ...customDoKeys] });
877
- };
878
- };
879
- const createSelectors = (_store, store = {}) => {
880
- store.get = _store.getState;
881
- store.set = (s) => {
882
- if (typeof s === "function")
883
- _store.setState((st2) => {
884
- s(st2);
885
- });
886
- else
887
- _store.setState(s);
888
- };
889
- store.sel = (selectFn, equals) => _store(selectFn, equals);
890
- const state = store.get();
891
- store.sub = _store.subscribe;
892
- const useReference = (selectFn) => {
893
- const ref = (0, import_react.useRef)(selectFn(store.get()));
894
- (0, import_react.useEffect)(() => {
895
- return store.sub(selectFn, (val) => ref.current = val);
896
- }, []);
897
- return ref;
898
- };
899
- store.ref = useReference;
900
- const existingUse = store.use;
901
- const existingDo = store.do;
902
- const existingSlice = store.slice;
903
- if (!existingUse)
904
- Object.assign(store, { use: {} });
905
- if (!existingDo)
906
- Object.assign(store, { do: {} });
907
- if (!existingSlice)
908
- Object.assign(store, { slice: {} });
909
- for (const k of Object.keys(state)) {
910
- if (typeof state[k] !== "function") {
911
- store.use[k] = () => store.sel((s) => s[k]);
912
- const setKey = `set${(0, import_common.capitalize)(k)}`;
913
- if (!state[setKey])
914
- store.do[setKey] = (value) => {
915
- store.set({ [k]: value });
916
- };
917
- } else {
918
- store.do[k] = async (...args) => {
919
- try {
920
- import_common.Logger.verbose(`${k} action loading...`);
921
- const start = Date.now();
922
- await state[k](...args);
923
- const end = Date.now();
924
- import_common.Logger.verbose(`=> ${k} action dispatched (${end - start}ms)`);
925
- } catch (e) {
926
- const errKey = typeof e === "string" ? e : e.message;
927
- import_dictionary.msg.error(errKey, { key: k });
928
- throw e;
929
- }
930
- };
931
- }
932
- }
933
- const storeNames = getStoreNames();
934
- for (const storeName of storeNames) {
935
- const [fieldName, className] = [(0, import_common.lowerlize)(storeName), (0, import_common.capitalize)(storeName)];
936
- const names = {
937
- model: fieldName,
938
- Model: className,
939
- defaultModel: `default${className}`,
940
- modelInsight: `${fieldName}Insight`,
941
- modelList: `${fieldName}List`,
942
- modelListLoading: `${fieldName}ListLoading`,
943
- modelInitList: `${fieldName}InitList`,
944
- modelInitAt: `${fieldName}InitAt`,
945
- pageOfModel: `pageOf${className}`,
946
- limitOfModel: `limitOf${className}`,
947
- queryArgsOfModel: `queryArgsOf${className}`,
948
- sortOfModel: `sortOf${className}`,
949
- modelSelection: `${fieldName}Selection`,
950
- initModel: `init${className}`,
951
- refreshModel: `refresh${className}`,
952
- selectModel: `select${className}`,
953
- setPageOfModel: `setPageOf${className}`,
954
- addPageOfModel: `addPageOf${className}`,
955
- setLimitOfModel: `setLimitOf${className}`,
956
- setQueryArgsOfModel: `setQueryArgsOf${className}`,
957
- setSortOfModel: `setSortOf${className}`,
958
- lastPageOfModel: `lastPageOf${className}`
959
- };
960
- const storeMeta = getStoreMeta(storeName);
961
- storeMeta.slices.forEach(({ sliceName, argLength, refName }) => {
962
- const SliceName = (0, import_common.capitalize)(sliceName);
963
- const namesOfSliceState = {
964
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
965
- modelInitList: SliceName.replace(names.Model, names.modelInitList),
966
- modelInsight: sliceName.replace(names.model, names.modelInsight),
967
- modelList: sliceName.replace(names.model, names.modelList),
968
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
969
- modelInitAt: SliceName.replace(names.Model, names.modelInitAt),
970
- lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
971
- pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
972
- limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
973
- queryArgsOfModel: SliceName.replace(names.Model, names.queryArgsOfModel),
974
- sortOfModel: SliceName.replace(names.Model, names.sortOfModel),
975
- modelSelection: SliceName.replace(names.Model, names.modelSelection)
976
- };
977
- const namesOfSliceAction = {
978
- initModel: SliceName.replace(names.Model, names.initModel),
979
- refreshModel: SliceName.replace(names.Model, names.refreshModel),
980
- selectModel: SliceName.replace(names.Model, names.selectModel),
981
- setPageOfModel: SliceName.replace(names.Model, names.setPageOfModel),
982
- addPageOfModel: SliceName.replace(names.Model, names.addPageOfModel),
983
- setLimitOfModel: SliceName.replace(names.Model, names.setLimitOfModel),
984
- setQueryArgsOfModel: SliceName.replace(names.Model, names.setQueryArgsOfModel),
985
- setSortOfModel: SliceName.replace(names.Model, names.setSortOfModel)
986
- };
987
- store.slice[sliceName] = { do: {}, use: {} };
988
- const targetSlice = store.slice[sliceName];
989
- Object.keys(namesOfSliceAction).forEach((key) => {
990
- targetSlice.do[names[key]] = store.do[namesOfSliceAction[key]];
991
- });
992
- Object.keys(namesOfSliceState).map((key) => {
993
- targetSlice.use[names[key]] = store.use[namesOfSliceState[key]];
994
- targetSlice.do[`set${(0, import_common.capitalize)(names[key])}`] = store.do[`set${(0, import_common.capitalize)(namesOfSliceState[key])}`];
995
- });
996
- targetSlice.sliceName = sliceName;
997
- targetSlice.refName = refName;
998
- targetSlice.argLength = argLength;
999
- });
1000
- }
1001
- return store;
1002
- };
1003
- const makePicker = (set, get) => (...fields) => {
1004
- const state = get();
1005
- const ret = {};
1006
- for (const field of fields) {
1007
- const val = state[field];
1008
- if (!val)
1009
- throw new Error(`Field ${field} is not ready`);
1010
- if (typeof val === "string" && val.length === 0)
1011
- throw new Error(`Field is empty string (${field})`);
1012
- else if (["self", "me"].includes(field) && !state[field].id?.length)
1013
- throw new Error("Self or Me Id is not defined");
1014
- ret[field] = val;
1015
- }
1016
- return ret;
1017
- };
1018
- const makeStore = (st2, storeRef, { library } = {}) => {
1019
- if (library)
1020
- return st2;
1021
- const zustandStore = (0, import_zustand.create)(
1022
- (0, import_middleware.devtools)(
1023
- (0, import_middleware.subscribeWithSelector)(
1024
- (0, import_immer.immer)((set, get) => {
1025
- const store = {};
1026
- const pick = makePicker(set, get);
1027
- Object.getOwnPropertyNames(storeRef.prototype).forEach((key) => {
1028
- const descriptor = Object.getOwnPropertyDescriptor(storeRef.prototype, key);
1029
- if (descriptor)
1030
- store[key] = descriptor.value;
1031
- });
1032
- Object.assign(store, { set, get, pick });
1033
- return store;
1034
- })
1035
- ),
1036
- { name: "root", anonymousActionType: "root", type: "root" }
1037
- )
1038
- );
1039
- return createSelectors(zustandStore, st2);
1040
- };
1041
- const MixStore = (s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30) => {
1042
- const stores = [
1043
- s1,
1044
- s2,
1045
- s3,
1046
- s4,
1047
- s5,
1048
- s6,
1049
- s7,
1050
- s8,
1051
- s9,
1052
- s10,
1053
- s11,
1054
- s12,
1055
- s13,
1056
- s14,
1057
- s15,
1058
- s16,
1059
- s17,
1060
- s18,
1061
- s19,
1062
- s20,
1063
- s21,
1064
- s22,
1065
- s23,
1066
- s24,
1067
- s25,
1068
- s26,
1069
- s27,
1070
- s28,
1071
- s29,
1072
- s30
1073
- ].filter((s) => !!s);
1074
- class Mix {
1075
- }
1076
- (0, import_common.applyMixins)(Mix, stores);
1077
- return Mix;
1078
- };
1079
- const rootStoreOf = (store) => {
1080
- return Object.getPrototypeOf(store);
1081
- };
1082
- const Toast = ({ root, duration = 3 } = {}) => {
1083
- return function(target, key, descriptor) {
1084
- const originMethod = descriptor.value;
1085
- descriptor.value = async function(...args) {
1086
- try {
1087
- import_dictionary.msg.loading(`${root ? `${root}.` : ""}${key}-loading`, { key, duration });
1088
- const result = await originMethod.apply(this, args);
1089
- import_dictionary.msg.success(`${root ? `${root}.` : ""}${key}-success`, { key, duration });
1090
- return result;
1091
- } catch (err) {
1092
- const errKey = typeof err === "string" ? err : err.message;
1093
- import_dictionary.msg.error(errKey, { key, duration });
1094
- import_common.Logger.error(`${key} action error return: ${err}`);
1095
- }
1096
- };
1097
- };
1098
- };
1099
- // Annotate the CommonJS export names for ESM import in node:
1100
- 0 && (module.exports = {
1101
- MixStore,
1102
- Store,
1103
- Toast,
1104
- createActions,
1105
- createState,
1106
- makeStore,
1107
- rootStoreOf,
1108
- scalarStateOf,
1109
- st,
1110
- stateOf
1111
- });