@akanjs/store 0.0.44 → 0.0.46

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.
Files changed (2) hide show
  1. package/index.js +1016 -2100
  2. package/package.json +1 -8
package/index.js CHANGED
@@ -1,1710 +1,975 @@
1
- (() => {
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
- }) : x)(function(x) {
11
- if (typeof require !== "undefined")
12
- return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
-
32
- // pkgs/@akanjs/base/src/base.ts
33
- var DataList = class _DataList {
34
- // [immerable] = true;
35
- #idMap;
36
- length;
37
- values;
38
- constructor(data = []) {
39
- this.values = Array.isArray(data) ? [...data] : [...data.values];
40
- this.#idMap = new Map(this.values.map((value, idx) => [value.id, idx]));
41
- this.length = this.values.length;
42
- }
43
- indexOf(id) {
44
- const idx = this.#idMap.get(id);
45
- if (idx === void 0)
46
- throw new Error(`Value ${id} is not in list`);
47
- return idx;
48
- }
49
- set(value) {
50
- const idx = this.#idMap.get(value.id);
51
- if (idx !== void 0)
52
- this.values = [...this.values.slice(0, idx), value, ...this.values.slice(idx + 1)];
53
- else {
54
- this.#idMap.set(value.id, this.length);
55
- this.values = [...this.values, value];
56
- this.length++;
57
- }
58
- return this;
59
- }
60
- delete(id) {
61
- const idx = this.#idMap.get(id);
62
- if (idx === void 0)
63
- return this;
64
- this.#idMap.delete(id);
65
- this.values.splice(idx, 1);
66
- this.values.slice(idx).forEach((value, i) => this.#idMap.set(value.id, i + idx));
67
- this.length--;
68
- return this;
69
- }
70
- get(id) {
71
- const idx = this.#idMap.get(id);
72
- if (idx === void 0)
73
- return void 0;
74
- return this.values[idx];
75
- }
76
- at(idx) {
77
- return this.values.at(idx);
78
- }
79
- pickAt(idx) {
80
- const value = this.values.at(idx);
81
- if (value === void 0)
82
- throw new Error(`Value at ${idx} is undefined`);
83
- return value;
84
- }
85
- pick(id) {
86
- return this.values[this.indexOf(id)];
87
- }
88
- has(id) {
89
- return this.#idMap.has(id);
90
- }
91
- find(fn) {
92
- const val = this.values.find(fn);
93
- return val;
94
- }
95
- findIndex(fn) {
96
- const val = this.values.findIndex(fn);
97
- return val;
98
- }
99
- some(fn) {
100
- return this.values.some(fn);
101
- }
102
- every(fn) {
103
- return this.values.every(fn);
104
- }
105
- forEach(fn) {
106
- this.values.forEach(fn);
107
- }
108
- map(fn) {
109
- return this.values.map(fn);
110
- }
111
- flatMap(fn) {
112
- return this.values.flatMap(fn);
113
- }
114
- sort(fn) {
115
- return new _DataList(this.values.sort(fn));
116
- }
117
- filter(fn) {
118
- return new _DataList(this.values.filter(fn));
119
- }
120
- reduce(fn, initialValue) {
121
- return this.values.reduce(fn, initialValue);
122
- }
123
- slice(start, end = this.length) {
124
- return new _DataList(this.values.slice(start, end));
125
- }
126
- save() {
127
- return new _DataList(this);
128
- }
129
- [Symbol.iterator]() {
130
- return this.values[Symbol.iterator]();
131
- }
132
- };
133
- var version = "0.9.0";
134
- var logo = `
135
- _ _ _
136
- / \\ | | ____ _ _ __ (_)___
137
- / _ \\ | |/ / _' | '_ \\ | / __|
138
- / ___ \\| < (_| | | | |_ | \\__ \\
139
- /_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
140
- |__/ ver ${version}
141
- ? See more details on docs https://www.akanjs.com/docs
142
- \u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
143
-
144
- `;
145
-
146
- // pkgs/@akanjs/base/src/baseEnv.ts
147
- var appName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
148
- var repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
149
- var serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
150
- if (appName === "unknown")
151
- throw new Error("environment variable NEXT_PUBLIC_APP_NAME is required");
152
- if (repoName === "unknown")
153
- throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
154
- if (serveDomain === "unknown")
155
- throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
156
- var environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
157
- var operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
158
- var operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
159
- var networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
160
- var tunnelUsername = process.env.SSU_TUNNEL_USERNAME ?? "root";
161
- var tunnelPassword = process.env.SSU_TUNNEL_PASSWORD ?? repoName;
162
- var baseEnv = {
163
- repoName,
164
- serveDomain,
165
- appName,
166
- environment,
167
- operationType,
168
- operationMode,
169
- networkType,
170
- tunnelUsername,
171
- tunnelPassword
172
- };
173
- var side = typeof window === "undefined" ? "server" : "client";
174
- var renderMode = process.env.RENDER_ENV ?? "ssr";
175
- var clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
176
- var clientPort = parseInt(
177
- process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
178
- );
179
- var clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
180
- var clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
181
- var serverHost = process.env.SERVER_HOST ?? (operationMode === "local" ? typeof window === "undefined" ? "localhost" : window.location.host.split(":")[0] : renderMode === "csr" ? `${appName}-${environment}.${serveDomain}` : side === "client" ? window.location.host.split(":")[0] : operationMode === "cloud" ? `backend-svc.${appName}-${environment}.svc.cluster.local` : "localhost");
182
- var serverPort = parseInt(
183
- process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
184
- );
185
- var serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
186
- var serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
187
- var serverGraphqlUri = `${serverHttpUri}/graphql`;
188
- var serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
189
- var serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
190
- var baseClientEnv = {
191
- ...baseEnv,
192
- side,
193
- renderMode,
194
- websocket: true,
195
- clientHost,
196
- clientPort,
197
- clientHttpProtocol,
198
- clientHttpUri,
199
- serverHost,
200
- serverPort,
201
- serverHttpProtocol,
202
- serverHttpUri,
203
- serverGraphqlUri,
204
- serverWsProtocol,
205
- serverWsUri
206
- };
207
-
208
- // pkgs/@akanjs/base/src/scalar.ts
209
- var import_dayjs = __toESM(__require("dayjs"));
210
- var dayjs = import_dayjs.default;
211
- var Int = class {
212
- __Scalar__;
213
- };
214
- var Upload = class {
215
- __Scalar__;
216
- filename;
217
- mimetype;
218
- encoding;
219
- createReadStream;
220
- };
221
- var Float = class {
222
- __Scalar__;
223
- };
224
- var ID = class {
225
- __Scalar__;
226
- };
227
- var JSON2 = class {
228
- __Scalar__;
229
- };
230
- var getNonArrayModel = (arraiedModel2) => {
231
- let arrDepth = 0;
232
- let target = arraiedModel2;
233
- while (Array.isArray(target)) {
234
- target = target[0];
235
- arrDepth++;
236
- }
237
- return [target, arrDepth];
238
- };
239
- var scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON2, Map]);
240
- var scalarNameMap = /* @__PURE__ */ new Map([
241
- [ID, "ID"],
242
- [Int, "Int"],
243
- [Float, "Float"],
244
- [String, "String"],
245
- [Boolean, "Boolean"],
246
- [Date, "Date"],
247
- [Upload, "Upload"],
248
- [JSON2, "JSON"],
249
- [Map, "Map"]
250
- ]);
251
- var scalarArgMap = /* @__PURE__ */ new Map([
252
- [ID, null],
253
- [String, ""],
254
- [Boolean, false],
255
- [Date, dayjs(/* @__PURE__ */ new Date(-1))],
256
- [Int, 0],
257
- [Float, 0],
258
- [JSON2, {}],
259
- [Map, {}]
260
- ]);
261
- var scalarDefaultMap = /* @__PURE__ */ new Map([
262
- [ID, null],
263
- [String, ""],
264
- [Boolean, false],
265
- [Date, dayjs(/* @__PURE__ */ new Date(-1))],
266
- [Int, 0],
267
- [Float, 0],
268
- [JSON2, {}]
269
- ]);
270
- var isGqlScalar = (modelRef) => scalarSet.has(modelRef);
271
- var isGqlMap = (modelRef) => modelRef === Map;
272
-
273
- // pkgs/@akanjs/common/src/isDayjs.ts
274
- var import_dayjs2 = __require("dayjs");
275
-
276
- // pkgs/@akanjs/common/src/deepObjectify.ts
277
- var deepObjectify = (obj, option = {}) => {
278
- if ((0, import_dayjs2.isDayjs)(obj) || obj?.constructor === Date) {
279
- if (!option.serializable && !option.convertDate)
280
- return obj;
281
- if (option.convertDate === "string")
282
- return obj.toISOString();
283
- else if (option.convertDate === "number")
284
- return (0, import_dayjs2.isDayjs)(obj) ? obj.toDate().getTime() : obj.getTime();
285
- else
286
- return (0, import_dayjs2.isDayjs)(obj) ? obj.toDate() : obj;
287
- } else if (Array.isArray(obj)) {
288
- return obj.map((o) => deepObjectify(o, option));
289
- } else if (obj && typeof obj === "object") {
290
- const val = {};
291
- Object.keys(obj).forEach((key) => {
292
- const fieldValue = obj[key];
293
- if (fieldValue?.__ModelType__ && !option.serializable)
294
- val[key] = fieldValue;
295
- else if (typeof obj[key] !== "function")
296
- val[key] = deepObjectify(fieldValue, option);
297
- });
298
- return val;
299
- } else {
300
- return obj;
301
- }
302
- };
303
-
304
- // pkgs/@akanjs/common/src/isQueryEqual.ts
305
- var import_dayjs3 = __toESM(__require("dayjs"));
306
- var isQueryEqual = (value1, value2) => {
307
- if (value1 === value2)
308
- return true;
309
- if (Array.isArray(value1) && Array.isArray(value2)) {
310
- if (value1.length !== value2.length)
311
- return false;
312
- for (let i = 0; i < value1.length; i++)
313
- if (!isQueryEqual(value1[i], value2[i]))
314
- return false;
315
- return true;
316
- }
317
- if ([value1, value2].some((val) => val instanceof Date || (0, import_dayjs2.isDayjs)(val)))
318
- return (0, import_dayjs3.default)(value1).isSame((0, import_dayjs3.default)(value2));
319
- if (typeof value1 === "object" && typeof value2 === "object") {
320
- if (value1 === null || value2 === null)
321
- return value1 === value2;
322
- if (Object.keys(value1).length !== Object.keys(value2).length)
323
- return false;
324
- for (const key of Object.keys(value1))
325
- if (!isQueryEqual(value1[key], value2[key]))
326
- return false;
327
- return true;
328
- }
329
- return false;
330
- };
331
-
332
- // pkgs/@akanjs/common/src/isValidDate.ts
333
- var import_dayjs4 = __toESM(__require("dayjs"));
334
- var import_customParseFormat = __toESM(__require("dayjs/plugin/customParseFormat"));
335
- import_dayjs4.default.extend(import_customParseFormat.default);
336
-
337
- // pkgs/@akanjs/common/src/pathSet.ts
338
- var pathSet = (obj, path, value) => {
339
- if (Object(obj) !== obj)
340
- return obj;
341
- if (!Array.isArray(path))
342
- path = path.toString().match(/[^.[\]]+/g) || [];
343
- path.slice(0, -1).reduce(
344
- (a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {},
345
- obj
346
- )[path[path.length - 1]] = value;
347
- return obj;
348
- };
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
349
18
 
350
- // pkgs/@akanjs/common/src/pluralize.ts
351
- var import_pluralize = __toESM(__require("pluralize"));
19
+ // pkgs/@akanjs/store/index.ts
20
+ var store_exports = {};
21
+ __export(store_exports, {
22
+ MixStore: () => MixStore,
23
+ Store: () => Store,
24
+ Toast: () => Toast,
25
+ createActions: () => createActions,
26
+ createState: () => createState,
27
+ makeStore: () => makeStore,
28
+ rootStoreOf: () => rootStoreOf,
29
+ scalarStateOf: () => scalarStateOf,
30
+ st: () => st,
31
+ stateOf: () => stateOf
32
+ });
33
+ module.exports = __toCommonJS(store_exports);
352
34
 
353
- // pkgs/@akanjs/common/src/applyMixins.ts
354
- var getAllPropertyDescriptors = (objRef) => {
355
- const descriptors = {};
356
- let current = objRef.prototype;
357
- while (current) {
358
- Object.getOwnPropertyNames(current).forEach((name) => {
359
- descriptors[name] ??= Object.getOwnPropertyDescriptor(current, name);
360
- });
361
- current = Object.getPrototypeOf(current);
362
- }
363
- return descriptors;
364
- };
365
- var applyMixins = (derivedCtor, constructors, avoidKeys) => {
366
- constructors.forEach((baseCtor) => {
367
- Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
368
- if (name === "constructor" || avoidKeys?.has(name))
369
- return;
370
- Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
371
- });
372
- });
373
- };
374
-
375
- // pkgs/@akanjs/common/src/capitalize.ts
376
- var capitalize = (str) => {
377
- return str.charAt(0).toUpperCase() + str.slice(1);
378
- };
379
-
380
- // pkgs/@akanjs/common/src/Logger.ts
381
- var import_dayjs5 = __toESM(__require("dayjs"));
382
- var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
383
- var clc = {
384
- bold: (text) => `\x1B[1m${text}\x1B[0m`,
385
- green: (text) => `\x1B[32m${text}\x1B[39m`,
386
- yellow: (text) => `\x1B[33m${text}\x1B[39m`,
387
- red: (text) => `\x1B[31m${text}\x1B[39m`,
388
- magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
389
- cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
390
- };
391
- var colorizeMap = {
392
- trace: clc.bold,
393
- verbose: clc.cyanBright,
394
- debug: clc.magentaBright,
395
- log: clc.green,
396
- info: clc.green,
397
- warn: clc.yellow,
398
- error: clc.red
399
- };
400
- var Logger = class _Logger {
401
- static #ignoreCtxSet = /* @__PURE__ */ new Set([
402
- "InstanceLoader",
403
- "RoutesResolver",
404
- "RouterExplorer",
405
- "NestFactory",
406
- "WebSocketsController",
407
- "GraphQLModule",
408
- "NestApplication"
409
- ]);
410
- static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
411
- static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
412
- static #startAt = (0, import_dayjs5.default)();
413
- static setLevel(level) {
414
- this.level = level;
415
- this.#levelIdx = logLevels.findIndex((l) => l === level);
416
- }
417
- name;
418
- constructor(name) {
419
- this.name = name;
420
- }
421
- trace(msg2, context = "") {
422
- if (_Logger.#levelIdx <= 0)
423
- _Logger.#printMessages(this.name ?? "App", msg2, context, "trace");
424
- }
425
- verbose(msg2, context = "") {
426
- if (_Logger.#levelIdx <= 1)
427
- _Logger.#printMessages(this.name ?? "App", msg2, context, "verbose");
428
- }
429
- debug(msg2, context = "") {
430
- if (_Logger.#levelIdx <= 2)
431
- _Logger.#printMessages(this.name ?? "App", msg2, context, "debug");
432
- }
433
- log(msg2, context = "") {
434
- if (_Logger.#levelIdx <= 3)
435
- _Logger.#printMessages(this.name ?? "App", msg2, context, "log");
436
- }
437
- info(msg2, context = "") {
438
- if (_Logger.#levelIdx <= 4)
439
- _Logger.#printMessages(this.name ?? "App", msg2, context, "info");
440
- }
441
- warn(msg2, context = "") {
442
- if (_Logger.#levelIdx <= 5)
443
- _Logger.#printMessages(this.name ?? "App", msg2, context, "warn");
444
- }
445
- error(msg2, context = "") {
446
- if (_Logger.#levelIdx <= 6)
447
- _Logger.#printMessages(this.name ?? "App", msg2, context, "error");
448
- }
449
- raw(msg2, method) {
450
- _Logger.rawLog(msg2, method);
451
- }
452
- rawLog(msg2, method) {
453
- _Logger.rawLog(msg2, method);
454
- }
455
- static trace(msg2, context = "") {
456
- if (_Logger.#levelIdx <= 0)
457
- _Logger.#printMessages("App", msg2, context, "trace");
458
- }
459
- static verbose(msg2, context = "") {
460
- if (_Logger.#levelIdx <= 1)
461
- _Logger.#printMessages("App", msg2, context, "verbose");
462
- }
463
- static debug(msg2, context = "") {
464
- if (_Logger.#levelIdx <= 2)
465
- _Logger.#printMessages("App", msg2, context, "debug");
466
- }
467
- static log(msg2, context = "") {
468
- if (_Logger.#levelIdx <= 3)
469
- _Logger.#printMessages("App", msg2, context, "log");
470
- }
471
- static info(msg2, context = "") {
472
- if (_Logger.#levelIdx <= 4)
473
- _Logger.#printMessages("App", msg2, context, "info");
474
- }
475
- static warn(msg2, context = "") {
476
- if (_Logger.#levelIdx <= 5)
477
- _Logger.#printMessages("App", msg2, context, "warn");
478
- }
479
- static error(msg2, context = "") {
480
- if (_Logger.#levelIdx <= 6)
481
- _Logger.#printMessages("App", msg2, context, "error");
482
- }
483
- static #colorize(msg2, logLevel) {
484
- return colorizeMap[logLevel](msg2);
485
- }
486
- static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
487
- if (this.#ignoreCtxSet.has(context))
488
- return;
489
- const now = (0, import_dayjs5.default)();
490
- const processMsg = this.#colorize(
491
- `[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
492
- logLevel
493
- );
494
- const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
495
- const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
496
- const contextMsg = context ? clc.yellow(`[${context}] `) : "";
497
- const contentMsg = this.#colorize(content, logLevel);
498
- const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
499
- if (typeof window === "undefined")
500
- process[writeStreamType].write(
501
- `${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
502
- `
503
- );
504
- else
505
- console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
506
- `);
507
- }
508
- static rawLog(msg2, method) {
509
- this.raw(`${msg2}
510
- `, method);
511
- }
512
- static raw(msg2, method) {
513
- if (typeof window === "undefined" && method !== "console" && global.process)
514
- global.process.stdout.write(msg2);
515
- else
516
- console.log(msg2);
517
- }
518
- };
519
-
520
- // pkgs/@akanjs/common/src/lowerlize.ts
521
- var lowerlize = (str) => {
522
- return str.charAt(0).toLowerCase() + str.slice(1);
523
- };
524
-
525
- // pkgs/@akanjs/common/src/sleep.ts
526
- var sleep = async (ms) => {
527
- return new Promise((resolve) => {
528
- setTimeout(() => {
529
- resolve(true);
530
- }, ms);
531
- });
532
- };
533
-
534
- // pkgs/@akanjs/constant/src/scalar.ts
535
- var import_reflect_metadata = __require("reflect-metadata");
536
- var scalarExampleMap = /* @__PURE__ */ new Map([
537
- [ID, "1234567890abcdef12345678"],
538
- [Int, 0],
539
- [Float, 0],
540
- [String, "String"],
541
- [Boolean, true],
542
- [Date, (/* @__PURE__ */ new Date()).toISOString()],
543
- [Upload, "FileUpload"],
544
- [JSON2, {}],
545
- [Map, {}]
546
- ]);
547
- var getClassMeta = (modelRef) => {
548
- const [target] = getNonArrayModel(modelRef);
549
- const classMeta = Reflect.getMetadata("class", target.prototype);
550
- if (!classMeta)
551
- throw new Error(`No ClassMeta for this target ${target.name}`);
552
- return classMeta;
553
- };
554
- var getFieldMetas = (modelRef) => {
555
- const [target] = getNonArrayModel(modelRef);
556
- const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
557
- const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
558
- return [...metadataMap.values()].sort((a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0));
559
- };
560
- var getFieldMetaMapOnPrototype = (prototype) => {
561
- const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
562
- return new Map(metadataMap);
563
- };
564
- var setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
565
- Reflect.defineMetadata("fields", new Map(metadataMap), prototype);
566
- };
567
-
568
- // pkgs/@akanjs/constant/src/fieldMeta.ts
569
- var applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
570
- const isArray = arrDepth > 0;
571
- const isClass = !isGqlScalar(modelRef);
572
- const isMap = isGqlMap(modelRef);
573
- const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
574
- const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
575
- if (isMap && !option.of)
576
- throw new Error("Map type must have 'of' option");
577
- return (prototype, key) => {
578
- const metadata = {
579
- nullable: option.nullable ?? false,
580
- ref: option.ref,
581
- refPath: option.refPath,
582
- refType: option.refType,
583
- default: option.default ?? (isArray ? [] : null),
584
- type: option.type,
585
- fieldType: option.fieldType ?? "property",
586
- immutable: option.immutable ?? false,
587
- min: option.min,
588
- max: option.max,
589
- enum: option.enum,
590
- select: option.select ?? true,
591
- minlength: option.minlength,
592
- maxlength: option.maxlength,
593
- query: option.query,
594
- accumulate: option.accumulate,
595
- example: option.example,
596
- validate: option.validate,
597
- key,
598
- name,
599
- isClass,
600
- isScalar: type === "scalar",
601
- modelRef,
602
- arrDepth,
603
- isArray,
604
- optArrDepth: optionArrDepth,
605
- isMap,
606
- of: option.of,
607
- text: option.text
608
- };
609
- const metadataMap = getFieldMetaMapOnPrototype(prototype);
610
- metadataMap.set(key, metadata);
611
- setFieldMetaMapOnPrototype(prototype, metadataMap);
35
+ // pkgs/@akanjs/store/src/storeDecorators.ts
36
+ var import_base = require("@akanjs/base");
37
+ var import_common = require("@akanjs/common");
38
+ var import_constant = require("@akanjs/constant");
39
+ var import_dictionary = require("@akanjs/dictionary");
40
+ var import_signal = require("@akanjs/signal");
41
+ var import_react = require("react");
42
+ var import_zustand = require("zustand");
43
+ var import_middleware = require("zustand/middleware");
44
+ var import_immer = require("zustand/middleware/immer");
45
+ var st = {};
46
+ var StoreStorage = class {
47
+ };
48
+ var getStoreMeta = (storeName) => {
49
+ const storeMeta = Reflect.getMetadata(storeName, StoreStorage.prototype);
50
+ if (!storeMeta)
51
+ throw new Error(`storeMeta is not defined: ${storeName}`);
52
+ return storeMeta;
53
+ };
54
+ var setStoreMeta = (storeName, storeMeta) => {
55
+ Reflect.defineMetadata(storeName, storeMeta, StoreStorage.prototype);
56
+ };
57
+ var getStoreNames = () => {
58
+ const storeNames = Reflect.getMetadataKeys(StoreStorage.prototype);
59
+ if (!storeNames)
60
+ throw new Error(`storeNames is not defined`);
61
+ return storeNames;
62
+ };
63
+ var createState = (gql) => {
64
+ const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
65
+ const names = {
66
+ model: fieldName,
67
+ Model: className,
68
+ modelLoading: `${fieldName}Loading`,
69
+ modelForm: `${fieldName}Form`,
70
+ modelFormLoading: `${fieldName}FormLoading`,
71
+ modelSubmit: `${fieldName}Submit`,
72
+ modelViewAt: `${fieldName}ViewAt`,
73
+ modelModal: `${fieldName}Modal`,
74
+ modelOperation: `${fieldName}Operation`,
75
+ defaultModel: `default${className}`,
76
+ defaultModelInsight: `default${className}Insight`,
77
+ modelList: `${fieldName}List`,
78
+ modelListLoading: `${fieldName}ListLoading`,
79
+ modelInitList: `${fieldName}InitList`,
80
+ modelInitAt: `${fieldName}InitAt`,
81
+ modelSelection: `${fieldName}Selection`,
82
+ modelInsight: `${fieldName}Insight`,
83
+ lastPageOfModel: `lastPageOf${className}`,
84
+ pageOfModel: `pageOf${className}`,
85
+ limitOfModel: `limitOf${className}`,
86
+ queryArgsOfModel: `queryArgsOf${className}`,
87
+ sortOfModel: `sortOf${className}`
88
+ };
89
+ const baseState = {
90
+ [names.model]: null,
91
+ [names.modelLoading]: true,
92
+ [names.modelForm]: { ...gql[names.defaultModel] },
93
+ [names.modelFormLoading]: true,
94
+ [names.modelSubmit]: { disabled: true, loading: false, times: 0 },
95
+ [names.modelViewAt]: /* @__PURE__ */ new Date(0),
96
+ [names.modelModal]: null,
97
+ [names.modelOperation]: "sleep"
98
+ };
99
+ const sliceState = gql.slices.reduce((acc, { sliceName, defaultArgs }) => {
100
+ const SliceName = (0, import_common.capitalize)(sliceName);
101
+ const namesOfSlice = {
102
+ defaultModel: SliceName.replace(names.Model, names.defaultModel),
103
+ //clusterInSelf Cluster
104
+ modelList: sliceName.replace(names.model, names.modelList),
105
+ modelListLoading: sliceName.replace(names.model, names.modelListLoading),
106
+ modelInitList: sliceName.replace(names.model, names.modelInitList),
107
+ modelInitAt: sliceName.replace(names.model, names.modelInitAt),
108
+ modelSelection: sliceName.replace(names.model, names.modelSelection),
109
+ modelInsight: sliceName.replace(names.model, names.modelInsight),
110
+ lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
111
+ pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
112
+ limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
113
+ queryArgsOfModel: SliceName.replace(names.Model, names.queryArgsOfModel),
114
+ sortOfModel: SliceName.replace(names.Model, names.sortOfModel)
612
115
  };
613
- };
614
- var makeField = (customOption) => (returns, fieldOption) => {
615
- const [modelRef, arrDepth] = getNonArrayModel(returns());
616
- if (!fieldOption)
617
- return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
618
- const [opt, optArrDepth] = getNonArrayModel(fieldOption);
619
- return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
620
- };
621
- var Field = {
622
- Prop: makeField({ fieldType: "property" }),
623
- Hidden: makeField({ fieldType: "hidden", nullable: true }),
624
- Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
625
- Resolve: makeField({ fieldType: "resolve" })
626
- };
627
-
628
- // pkgs/@akanjs/constant/src/constantDecorator.ts
629
- var import_reflect_metadata2 = __require("reflect-metadata");
630
-
631
- // pkgs/@akanjs/constant/src/filterMeta.ts
632
- var setFilterMeta = (filterRef, filterMeta) => {
633
- const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
634
- if (existingFilterMeta)
635
- Object.assign(filterMeta.sort, existingFilterMeta.sort);
636
- Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
637
- };
638
- var getFilterKeyMetaMapOnPrototype = (prototype) => {
639
- const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
640
- return new Map(metadataMap);
641
- };
642
- var setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
643
- Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
644
- };
645
- var applyFilterKeyMeta = (option) => {
646
- return (prototype, key, descriptor) => {
647
- const metadata = { key, ...option, descriptor };
648
- const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
649
- metadataMap.set(key, metadata);
650
- setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
651
- };
652
- };
653
- var makeFilter = (customOption) => (fieldOption) => {
654
- return applyFilterKeyMeta({ ...customOption, ...fieldOption });
655
- };
656
- var getFilterArgMetasOnPrototype = (prototype, key) => {
657
- const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
658
- return filterArgMetas;
659
- };
660
- var setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
661
- Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
662
- };
663
- var applyFilterArgMeta = (name, returns, argOption) => {
664
- return (prototype, key, idx) => {
665
- const [modelRef, arrDepth] = getNonArrayModel(returns());
666
- const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
667
- const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
668
- const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
669
- filterArgMetas[idx] = filterArgMeta;
670
- setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
671
- };
672
- };
673
- var Filter = {
674
- Mongo: makeFilter({ type: "mongo" }),
675
- // Meili: makeFilter({ fieldType: "hidden", nullable: true }),
676
- Arg: applyFilterArgMeta
677
- };
678
-
679
- // pkgs/@akanjs/constant/src/baseGql.ts
680
- var import_reflect_metadata3 = __require("reflect-metadata");
681
- var defaultFieldMeta = {
682
- fieldType: "property",
683
- immutable: false,
684
- select: true,
685
- isClass: false,
686
- isScalar: true,
687
- nullable: false,
688
- isArray: false,
689
- arrDepth: 0,
690
- optArrDepth: 0,
691
- default: null,
692
- isMap: false
693
- };
694
- var idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
695
- var createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
696
- var updatedAtFieldMeta = { ...defaultFieldMeta, key: "updatedAt", name: "Date", modelRef: Date };
697
- var removedAtFieldMeta = {
698
- ...defaultFieldMeta,
699
- key: "removedAt",
700
- name: "Date",
701
- modelRef: Date,
702
- nullable: true,
703
- default: null
704
- };
705
-
706
- // pkgs/@akanjs/constant/src/classMeta.ts
707
- var import_reflect_metadata4 = __require("reflect-metadata");
708
- var InputModelStorage = class {
709
- };
710
- var LightModelStorage = class {
711
- };
712
- var FullModelStorage = class {
713
- };
714
- var ScalarModelStorage = class {
715
- };
716
- var FilterModelStorage = class {
717
- };
718
- var getFullModelRef = (refName) => {
719
- const modelRef = Reflect.getMetadata(capitalize(refName), FullModelStorage.prototype);
720
- if (!modelRef)
721
- throw new Error(`FullModel not found - ${refName}`);
722
- return modelRef;
723
- };
724
- var hasTextField = (modelRef) => {
725
- const fieldMetas = getFieldMetas(modelRef);
726
- return fieldMetas.some(
727
- (fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
728
- );
729
- };
730
- var applyClassMeta = (type, modelType, storage) => {
731
- return function(refName) {
732
- return function(target) {
733
- const modelRef = target;
734
- const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
735
- Reflect.defineMetadata("class", classMeta, modelRef.prototype);
736
- Reflect.defineMetadata(refName, modelRef, storage.prototype);
737
- };
738
- };
739
- };
740
- var applyFilterMeta = (storage) => {
741
- return function(refName) {
742
- return function(target) {
743
- const modelRef = target;
744
- setFilterMeta(modelRef, { refName, sort: {} });
745
- Reflect.defineMetadata(refName, modelRef, storage.prototype);
746
- };
116
+ const singleSliceState = {
117
+ [namesOfSlice.defaultModel]: { ...gql[names.defaultModel] },
118
+ [namesOfSlice.modelList]: new import_base.DataList(),
119
+ [namesOfSlice.modelListLoading]: true,
120
+ [namesOfSlice.modelInitList]: new import_base.DataList(),
121
+ [namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(0),
122
+ [namesOfSlice.modelSelection]: new import_base.DataList(),
123
+ [namesOfSlice.modelInsight]: gql[names.defaultModelInsight],
124
+ [namesOfSlice.lastPageOfModel]: 1,
125
+ [namesOfSlice.pageOfModel]: 1,
126
+ [namesOfSlice.limitOfModel]: 20,
127
+ [namesOfSlice.queryArgsOfModel]: defaultArgs,
128
+ [namesOfSlice.sortOfModel]: "latest"
747
129
  };
748
- };
749
- var Model = {
750
- Light: applyClassMeta("light", "data", LightModelStorage),
751
- Object: applyClassMeta("full", "ephemeral", FullModelStorage),
752
- Full: applyClassMeta("full", "data", FullModelStorage),
753
- Input: applyClassMeta("input", "data", InputModelStorage),
754
- Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
755
- Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
756
- Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
757
- Filter: applyFilterMeta(FilterModelStorage)
758
- };
759
- var getLightModelRef = (modelRef) => {
760
- const classMeta = getClassMeta(modelRef);
761
- if (classMeta.type !== "full")
762
- return modelRef;
763
- const lightModelRef = Reflect.getMetadata(`Light${classMeta.refName}`, LightModelStorage.prototype);
764
- if (!lightModelRef)
765
- throw new Error(`LightModel not found - ${classMeta.refName}`);
766
- return lightModelRef;
767
- };
768
-
769
- // pkgs/@akanjs/signal/src/client.ts
770
- var import_core = __require("@urql/core");
771
- var import_socket = __require("socket.io-client");
772
- var SocketIo = class {
773
- socket;
774
- roomSubscribeMap = /* @__PURE__ */ new Map();
775
- constructor(uri) {
776
- this.socket = (0, import_socket.io)(uri, { transports: ["websocket"] });
777
- this.socket.on("connect", () => {
778
- this.roomSubscribeMap.forEach((option) => {
779
- this.socket.emit(option.key, { ...option.message, __subscribe__: true });
780
- });
130
+ return Object.assign(acc, singleSliceState);
131
+ }, {});
132
+ return { ...baseState, ...sliceState };
133
+ };
134
+ var createActions = (gql) => {
135
+ const formSetterActions = makeFormSetter(gql);
136
+ const baseActions = makeActions(gql);
137
+ return { ...formSetterActions, ...baseActions };
138
+ };
139
+ var 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);
143
+ const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
144
+ const names = {
145
+ model: fieldName,
146
+ Model: className,
147
+ modelForm: `${fieldName}Form`,
148
+ writeOnModel: `writeOn${className}`,
149
+ addModelFiles: `add${className}Files`
150
+ };
151
+ const baseSetAction = {
152
+ [names.writeOnModel]: function(path, value) {
153
+ this.set((state) => {
154
+ (0, import_common.pathSet)(state[names.modelForm], path, value);
781
155
  });
782
156
  }
783
- on(event, callback) {
784
- this.socket.on(event, callback);
785
- }
786
- removeListener(event, callback) {
787
- this.socket.removeListener(event, callback);
788
- }
789
- removeAllListeners() {
790
- this.socket.removeAllListeners();
791
- }
792
- hasListeners(event) {
793
- return this.socket.hasListeners(event);
794
- }
795
- emit(key, data) {
796
- this.socket.emit(key, data);
797
- }
798
- subscribe(option) {
799
- if (!this.roomSubscribeMap.has(option.roomId)) {
800
- this.roomSubscribeMap.set(option.roomId, option);
801
- this.socket.emit(option.key, { ...option.message, __subscribe__: true });
802
- }
803
- this.socket.on(option.roomId, option.handleEvent);
804
- }
805
- unsubscribe(roomId, handleEvent) {
806
- this.socket.removeListener(roomId, handleEvent);
807
- const option = this.roomSubscribeMap.get(roomId);
808
- if (this.hasListeners(roomId) || !option)
809
- return;
810
- this.roomSubscribeMap.delete(roomId);
811
- this.socket.emit(option.key, { ...option.message, __subscribe__: false });
812
- }
813
- disconnect() {
814
- this.socket.disconnect();
815
- return this;
816
- }
817
- };
818
- var Client = class _Client {
819
- static globalIoMap = /* @__PURE__ */ new Map();
820
- static tokenStore = /* @__PURE__ */ new Map();
821
- async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
822
- if (baseClientEnv.side === "server")
823
- return true;
824
- while (!this.getIo(ws).socket.connected) {
825
- Logger.verbose("waiting for websocket to initialize...");
826
- await sleep(300);
827
- }
828
- }
829
- isInitialized = false;
830
- uri = baseClientEnv.serverGraphqlUri;
831
- ws = baseClientEnv.serverWsUri;
832
- udp = null;
833
- gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
834
- jwt = null;
835
- async getJwt() {
836
- const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
837
- if (isNextServer) {
838
- const nextHeaders = __require("next/headers");
839
- return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
840
- } else
841
- return _Client.tokenStore.get(this) ?? null;
842
- }
843
- io = null;
844
- init(data = {}) {
845
- Object.assign(this, data);
846
- this.setLink(data.uri);
847
- this.setIo(data.ws);
848
- this.isInitialized = true;
849
- }
850
- setIo(ws = baseClientEnv.serverWsUri) {
851
- this.ws = ws;
852
- const existingIo = _Client.globalIoMap.get(ws);
853
- if (existingIo) {
854
- this.io = existingIo;
855
- return;
856
- }
857
- this.io = new SocketIo(ws);
858
- _Client.globalIoMap.set(ws, this.io);
859
- }
860
- getIo(ws = baseClientEnv.serverWsUri) {
861
- const existingIo = _Client.globalIoMap.get(ws);
862
- if (existingIo)
863
- return existingIo;
864
- const io2 = new SocketIo(ws);
865
- _Client.globalIoMap.set(ws, io2);
866
- return io2;
867
- }
868
- setLink(uri = baseClientEnv.serverGraphqlUri) {
869
- this.uri = uri;
870
- this.gql = (0, import_core.createClient)({
871
- url: this.uri,
872
- fetch,
873
- exchanges: [import_core.cacheExchange, import_core.fetchExchange],
874
- // requestPolicy: "network-only",
875
- fetchOptions: () => {
876
- return {
877
- headers: {
878
- "apollo-require-preflight": "true",
879
- ...this.jwt ? { authorization: `Bearer ${this.jwt}` } : {}
880
- }
881
- };
882
- }
883
- });
884
- }
885
- setJwt(jwt) {
886
- _Client.tokenStore.set(this, jwt);
887
- }
888
- reset() {
889
- this.io?.disconnect();
890
- this.io = null;
891
- this.jwt = null;
892
- }
893
- clone(data = {}) {
894
- const newClient = new _Client();
895
- newClient.init({ ...this, ...data });
896
- if (data.jwt)
897
- _Client.tokenStore.set(newClient, data.jwt);
898
- return newClient;
899
- }
900
- terminate() {
901
- this.reset();
902
- _Client.globalIoMap.forEach((io2) => io2.disconnect());
903
- this.isInitialized = false;
904
- }
905
- setUdp(udp) {
906
- this.udp = udp;
907
- }
908
- };
909
- var client = new Client();
910
-
911
- // pkgs/@akanjs/signal/src/immerify.ts
912
- var import_immer = __require("immer");
913
- var immerify = (modelRef, objOrArr) => {
914
- if (Array.isArray(objOrArr))
915
- return objOrArr.map((val) => immerify(modelRef, val));
916
- const fieldMetas = getFieldMetas(modelRef);
917
- const immeredObj = Object.assign({}, objOrArr, { [import_immer.immerable]: true });
918
- fieldMetas.forEach((fieldMeta) => {
919
- if (fieldMeta.isScalar && fieldMeta.isClass && !!objOrArr[fieldMeta.key])
920
- immeredObj[fieldMeta.key] = immerify(fieldMeta.modelRef, objOrArr[fieldMeta.key]);
921
- });
922
- return immeredObj;
923
- };
924
-
925
- // pkgs/@akanjs/signal/src/signalDecorators.ts
926
- var import_reflect_metadata5 = __require("reflect-metadata");
927
- var createArgMetaDecorator = (type) => {
928
- return function(option = {}) {
929
- return function(prototype, key, idx) {
930
- const argMetas = getArgMetasOnPrototype(prototype, key);
931
- argMetas[idx] = { key, idx, type, option };
932
- setArgMetasOnPrototype(prototype, key, argMetas);
933
- };
934
- };
935
- };
936
- var Account = createArgMetaDecorator("Account");
937
- var defaultAccount = {
938
- __InternalArg__: "Account",
939
- appName: baseEnv.appName,
940
- environment: baseEnv.environment
941
- };
942
- var Self = createArgMetaDecorator("Self");
943
- var Me = createArgMetaDecorator("Me");
944
- var UserIp = createArgMetaDecorator("UserIp");
945
- var Access = createArgMetaDecorator("Access");
946
- var Req = createArgMetaDecorator("Req");
947
- var Res = createArgMetaDecorator("Res");
948
- var Ws = createArgMetaDecorator("Ws");
949
- var Job = createArgMetaDecorator("Job");
950
- var getQuery = (allow) => function(returns, signalOption = {}, guards = []) {
951
- return (prototype, key, descriptor) => {
952
- const metadataMap = getGqlMetaMapOnPrototype(prototype);
953
- metadataMap.set(key, {
954
- returns,
955
- signalOption,
956
- key,
957
- descriptor,
958
- guards: [allow, ...guards],
959
- type: "Query"
960
- });
961
- setGqlMetaMapOnPrototype(prototype, metadataMap);
962
- };
963
- };
964
- var getMutation = (allow) => function(returns, signalOption = {}, guards = []) {
965
- return (prototype, key, descriptor) => {
966
- const metadataMap = getGqlMetaMapOnPrototype(prototype);
967
- metadataMap.set(key, {
968
- returns,
969
- signalOption,
970
- key,
971
- descriptor,
972
- guards: [allow, ...guards],
973
- type: "Mutation"
974
- });
975
- setGqlMetaMapOnPrototype(prototype, metadataMap);
976
- };
977
- };
978
- var getMessage = (allow) => function(returns, signalOption = {}, guards = []) {
979
- return (prototype, key, descriptor) => {
980
- const metadataMap = getGqlMetaMapOnPrototype(prototype);
981
- metadataMap.set(key, {
982
- returns,
983
- signalOption,
984
- key,
985
- descriptor,
986
- guards: [allow, ...guards],
987
- type: "Message"
988
- });
989
- setGqlMetaMapOnPrototype(prototype, metadataMap);
990
- };
991
- };
992
- var getPubsub = (allow) => function(returns, signalOption = {}, guards = []) {
993
- return (prototype, key, descriptor) => {
994
- const metadataMap = getGqlMetaMapOnPrototype(prototype);
995
- metadataMap.set(key, {
996
- returns,
997
- signalOption,
998
- key,
999
- descriptor,
1000
- guards: [allow, ...guards],
1001
- type: "Pubsub"
1002
- });
1003
- setGqlMetaMapOnPrototype(prototype, metadataMap);
1004
- };
1005
- };
1006
- var getProcess = (serverType) => function(returns, signalOption = {}) {
1007
- return (prototype, key, descriptor) => {
1008
- const metadataMap = getGqlMetaMapOnPrototype(prototype);
1009
- metadataMap.set(key, {
1010
- returns,
1011
- signalOption: { ...signalOption, serverType: lowerlize(serverType) },
1012
- key,
1013
- descriptor,
1014
- guards: ["None"],
1015
- type: "Process"
1016
- });
1017
- setGqlMetaMapOnPrototype(prototype, metadataMap);
1018
- };
1019
- };
1020
- var Query = {
1021
- Public: getQuery("Public"),
1022
- Every: getQuery("Every"),
1023
- Admin: getQuery("Admin"),
1024
- User: getQuery("User"),
1025
- SuperAdmin: getQuery("SuperAdmin"),
1026
- None: getQuery("None"),
1027
- Owner: getQuery("Owner")
1028
- };
1029
- var Mutation = {
1030
- Public: getMutation("Public"),
1031
- Every: getMutation("Every"),
1032
- Admin: getMutation("Admin"),
1033
- User: getMutation("User"),
1034
- SuperAdmin: getMutation("SuperAdmin"),
1035
- None: getMutation("None"),
1036
- Owner: getMutation("Owner")
1037
- };
1038
- var Message = {
1039
- Public: getMessage("Public"),
1040
- Every: getMessage("Every"),
1041
- Admin: getMessage("Admin"),
1042
- User: getMessage("User"),
1043
- SuperAdmin: getMessage("SuperAdmin"),
1044
- None: getMessage("None"),
1045
- Owner: getMessage("Owner")
1046
- };
1047
- var Pubsub = {
1048
- Public: getPubsub("Public"),
1049
- Every: getPubsub("Every"),
1050
- Admin: getPubsub("Admin"),
1051
- User: getPubsub("User"),
1052
- SuperAdmin: getPubsub("SuperAdmin"),
1053
- None: getPubsub("None"),
1054
- Owner: getPubsub("Owner")
1055
- };
1056
- var Process = {
1057
- Federation: getProcess("Federation"),
1058
- Batch: getProcess("Batch"),
1059
- All: getProcess("All")
1060
- };
1061
- var getArg = (type) => function(name, returns, argsOption = {}) {
1062
- return function(prototype, key, idx) {
1063
- const argMetas = getArgMetasOnPrototype(prototype, key);
1064
- argMetas[idx] = { name, returns, argsOption, key, idx, type };
1065
- setArgMetasOnPrototype(prototype, key, argMetas);
1066
- };
1067
- };
1068
- var Arg = {
1069
- Body: getArg("Body"),
1070
- Param: getArg("Param"),
1071
- Query: getArg("Query"),
1072
- Upload: getArg("Upload"),
1073
- Msg: getArg("Msg"),
1074
- Room: getArg("Room")
1075
- };
1076
- var getGqlMetaMapOnPrototype = (prototype) => {
1077
- const gqlMetaMap = Reflect.getMetadata("gql", prototype);
1078
- return gqlMetaMap ?? /* @__PURE__ */ new Map();
1079
- };
1080
- var setGqlMetaMapOnPrototype = (prototype, gqlMetaMap) => {
1081
- Reflect.defineMetadata("gql", gqlMetaMap, prototype);
1082
- };
1083
- var getArgMetasOnPrototype = (prototype, key) => {
1084
- return Reflect.getMetadata("args", prototype, key) ?? [];
1085
- };
1086
- var setArgMetasOnPrototype = (prototype, key, argMetas) => {
1087
- Reflect.defineMetadata("args", argMetas, prototype, key);
1088
- };
1089
-
1090
- // pkgs/@akanjs/signal/src/gql.ts
1091
- var GqlStorage = class {
1092
- };
1093
- var getGqlOnStorage = (refName) => {
1094
- const modelGql = Reflect.getMetadata(refName, GqlStorage.prototype);
1095
- if (!modelGql)
1096
- throw new Error("Gql is not defined");
1097
- return modelGql;
1098
- };
1099
-
1100
- // pkgs/@akanjs/signal/src/baseFetch.ts
1101
- var nativeFetch = fetch;
1102
- var baseFetch = Object.assign(nativeFetch, {
1103
- client,
1104
- clone: function(option = {}) {
1105
- return {
1106
- ...this,
1107
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
1108
- client: this.client.clone(option)
1109
- };
1110
- }
1111
- });
1112
-
1113
- // pkgs/@akanjs/dictionary/src/trans.ts
1114
- var msg = {
1115
- info: () => null,
1116
- success: () => null,
1117
- error: () => null,
1118
- warning: () => null,
1119
- loading: () => null
1120
- };
1121
-
1122
- // pkgs/@akanjs/store/src/storeDecorators.ts
1123
- var import_react = __require("react");
1124
- var import_zustand = __require("zustand");
1125
- var import_middleware = __require("zustand/middleware");
1126
- var import_immer2 = __require("zustand/middleware/immer");
1127
- var st = {};
1128
- var StoreStorage = class {
1129
- };
1130
- var getStoreMeta = (storeName) => {
1131
- const storeMeta = Reflect.getMetadata(storeName, StoreStorage.prototype);
1132
- if (!storeMeta)
1133
- throw new Error(`storeMeta is not defined: ${storeName}`);
1134
- return storeMeta;
1135
- };
1136
- var setStoreMeta = (storeName, storeMeta) => {
1137
- Reflect.defineMetadata(storeName, storeMeta, StoreStorage.prototype);
1138
- };
1139
- var getStoreNames = () => {
1140
- const storeNames = Reflect.getMetadataKeys(StoreStorage.prototype);
1141
- if (!storeNames)
1142
- throw new Error(`storeNames is not defined`);
1143
- return storeNames;
1144
157
  };
1145
- var createState = (gql) => {
1146
- const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
1147
- const names = {
1148
- model: fieldName,
1149
- Model: className,
1150
- modelLoading: `${fieldName}Loading`,
1151
- modelForm: `${fieldName}Form`,
1152
- modelFormLoading: `${fieldName}FormLoading`,
1153
- modelSubmit: `${fieldName}Submit`,
1154
- modelViewAt: `${fieldName}ViewAt`,
1155
- modelModal: `${fieldName}Modal`,
1156
- modelOperation: `${fieldName}Operation`,
1157
- defaultModel: `default${className}`,
1158
- defaultModelInsight: `default${className}Insight`,
1159
- modelList: `${fieldName}List`,
1160
- modelListLoading: `${fieldName}ListLoading`,
1161
- modelInitList: `${fieldName}InitList`,
1162
- modelInitAt: `${fieldName}InitAt`,
1163
- modelSelection: `${fieldName}Selection`,
1164
- modelInsight: `${fieldName}Insight`,
1165
- lastPageOfModel: `lastPageOf${className}`,
1166
- pageOfModel: `pageOf${className}`,
1167
- limitOfModel: `limitOf${className}`,
1168
- queryArgsOfModel: `queryArgsOf${className}`,
1169
- sortOfModel: `sortOf${className}`
158
+ const fieldSetAction = fieldMetas.reduce((acc, fieldMeta) => {
159
+ const [fieldKeyName, classKeyName] = [(0, import_common.lowerlize)(fieldMeta.key), (0, import_common.capitalize)(fieldMeta.key)];
160
+ const namesOfField = {
161
+ field: fieldKeyName,
162
+ Field: classKeyName,
163
+ setFieldOnModel: `set${classKeyName}On${className}`,
164
+ addFieldOnModel: `add${classKeyName}On${className}`,
165
+ subFieldOnModel: `sub${classKeyName}On${className}`,
166
+ addOrSubFieldOnModel: `addOrSub${classKeyName}On${className}`,
167
+ uploadFieldOnModel: `upload${classKeyName}On${className}`
1170
168
  };
1171
- const baseState = {
1172
- [names.model]: null,
1173
- [names.modelLoading]: true,
1174
- [names.modelForm]: { ...gql[names.defaultModel] },
1175
- [names.modelFormLoading]: true,
1176
- [names.modelSubmit]: { disabled: true, loading: false, times: 0 },
1177
- [names.modelViewAt]: /* @__PURE__ */ new Date(0),
1178
- [names.modelModal]: null,
1179
- [names.modelOperation]: "sleep"
1180
- };
1181
- const sliceState = gql.slices.reduce((acc, { sliceName, defaultArgs }) => {
1182
- const SliceName = capitalize(sliceName);
1183
- const namesOfSlice = {
1184
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
1185
- //clusterInSelf Cluster
1186
- modelList: sliceName.replace(names.model, names.modelList),
1187
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
1188
- modelInitList: sliceName.replace(names.model, names.modelInitList),
1189
- modelInitAt: sliceName.replace(names.model, names.modelInitAt),
1190
- modelSelection: sliceName.replace(names.model, names.modelSelection),
1191
- modelInsight: sliceName.replace(names.model, names.modelInsight),
1192
- lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
1193
- pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
1194
- limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
1195
- queryArgsOfModel: SliceName.replace(names.Model, names.queryArgsOfModel),
1196
- sortOfModel: SliceName.replace(names.Model, names.sortOfModel)
1197
- };
1198
- const singleSliceState = {
1199
- [namesOfSlice.defaultModel]: { ...gql[names.defaultModel] },
1200
- [namesOfSlice.modelList]: new DataList(),
1201
- [namesOfSlice.modelListLoading]: true,
1202
- [namesOfSlice.modelInitList]: new DataList(),
1203
- [namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(0),
1204
- [namesOfSlice.modelSelection]: new DataList(),
1205
- [namesOfSlice.modelInsight]: gql[names.defaultModelInsight],
1206
- [namesOfSlice.lastPageOfModel]: 1,
1207
- [namesOfSlice.pageOfModel]: 1,
1208
- [namesOfSlice.limitOfModel]: 20,
1209
- [namesOfSlice.queryArgsOfModel]: defaultArgs,
1210
- [namesOfSlice.sortOfModel]: "latest"
1211
- };
1212
- return Object.assign(acc, singleSliceState);
1213
- }, {});
1214
- return { ...baseState, ...sliceState };
1215
- };
1216
- var createActions = (gql) => {
1217
- const formSetterActions = makeFormSetter(gql);
1218
- const baseActions = makeActions(gql);
1219
- return { ...formSetterActions, ...baseActions };
1220
- };
1221
- var makeFormSetter = (gql) => {
1222
- const fileGql = getGqlOnStorage("file");
1223
- const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
1224
- const modelRef = getFullModelRef(gql.refName);
1225
- const fieldMetas = getFieldMetas(modelRef);
1226
- const names = {
1227
- model: fieldName,
1228
- Model: className,
1229
- modelForm: `${fieldName}Form`,
1230
- writeOnModel: `writeOn${className}`,
1231
- addModelFiles: `add${className}Files`
1232
- };
1233
- const baseSetAction = {
1234
- [names.writeOnModel]: function(path, value) {
169
+ const singleFieldSetAction = {
170
+ [namesOfField.setFieldOnModel]: function(value) {
1235
171
  this.set((state) => {
1236
- pathSet(state[names.modelForm], path, value);
172
+ const setValue = fieldMeta.isClass ? (0, import_signal.immerify)(fieldMeta.modelRef, value) : value;
173
+ state[names.modelForm][namesOfField.field] = setValue;
1237
174
  });
1238
- }
1239
- };
1240
- const fieldSetAction = fieldMetas.reduce((acc, fieldMeta) => {
1241
- const [fieldKeyName, classKeyName] = [lowerlize(fieldMeta.key), capitalize(fieldMeta.key)];
1242
- const namesOfField = {
1243
- field: fieldKeyName,
1244
- Field: classKeyName,
1245
- setFieldOnModel: `set${classKeyName}On${className}`,
1246
- addFieldOnModel: `add${classKeyName}On${className}`,
1247
- subFieldOnModel: `sub${classKeyName}On${className}`,
1248
- addOrSubFieldOnModel: `addOrSub${classKeyName}On${className}`,
1249
- uploadFieldOnModel: `upload${classKeyName}On${className}`
1250
- };
1251
- const singleFieldSetAction = {
1252
- [namesOfField.setFieldOnModel]: function(value) {
175
+ },
176
+ ...fieldMeta.isArray ? {
177
+ [namesOfField.addFieldOnModel]: function(value, options = {}) {
178
+ const form = this.get()[names.modelForm];
179
+ const length = form[namesOfField.field].length;
180
+ if (options.limit && options.limit <= length)
181
+ return;
182
+ const idx = options.idx ?? length;
183
+ const setValue = fieldMeta.isClass ? (0, import_signal.immerify)(fieldMeta.modelRef, value) : value;
1253
184
  this.set((state) => {
1254
- const setValue = fieldMeta.isClass ? immerify(fieldMeta.modelRef, value) : value;
1255
- state[names.modelForm][namesOfField.field] = setValue;
185
+ state[names.modelForm][namesOfField.field] = [
186
+ ...form[namesOfField.field].slice(0, idx),
187
+ ...Array.isArray(setValue) ? setValue : [setValue],
188
+ ...form[namesOfField.field].slice(idx)
189
+ ];
1256
190
  });
1257
191
  },
1258
- ...fieldMeta.isArray ? {
1259
- [namesOfField.addFieldOnModel]: function(value, options = {}) {
1260
- const form = this.get()[names.modelForm];
1261
- const length = form[namesOfField.field].length;
1262
- if (options.limit && options.limit <= length)
1263
- return;
1264
- const idx = options.idx ?? length;
1265
- const setValue = fieldMeta.isClass ? immerify(fieldMeta.modelRef, value) : value;
192
+ [namesOfField.subFieldOnModel]: function(idx) {
193
+ const form = this.get()[names.modelForm];
194
+ this.set((state) => {
195
+ state[names.modelForm][namesOfField.field] = typeof idx === "number" ? form[namesOfField.field].filter((_, i) => i !== idx) : form[namesOfField.field].filter((_, i) => !idx.includes(i));
196
+ });
197
+ },
198
+ [namesOfField.addOrSubFieldOnModel]: function(value, options = {}) {
199
+ const { [names.modelForm]: form } = this.get();
200
+ const index = form[namesOfField.field].findIndex((v) => v === value);
201
+ if (index === -1)
202
+ this[namesOfField.addFieldOnModel](value, options);
203
+ else
204
+ this[namesOfField.subFieldOnModel](index);
205
+ }
206
+ } : {},
207
+ ...fieldMeta.name === "File" ? {
208
+ [namesOfField.uploadFieldOnModel]: async function(fileList, index) {
209
+ const form = this.get()[names.modelForm];
210
+ if (!fileList.length)
211
+ return;
212
+ const files = await gql[names.addModelFiles](
213
+ fileList,
214
+ form.id
215
+ );
216
+ if (fieldMeta.isArray) {
217
+ const idx = index ?? form[namesOfField.field].length;
1266
218
  this.set((state) => {
1267
219
  state[names.modelForm][namesOfField.field] = [
1268
220
  ...form[namesOfField.field].slice(0, idx),
1269
- ...Array.isArray(setValue) ? setValue : [setValue],
221
+ ...files,
1270
222
  ...form[namesOfField.field].slice(idx)
1271
223
  ];
1272
224
  });
1273
- },
1274
- [namesOfField.subFieldOnModel]: function(idx) {
1275
- const form = this.get()[names.modelForm];
225
+ } else {
1276
226
  this.set((state) => {
1277
- state[names.modelForm][namesOfField.field] = typeof idx === "number" ? form[namesOfField.field].filter((_, i) => i !== idx) : form[namesOfField.field].filter((_, i) => !idx.includes(i));
1278
- });
1279
- },
1280
- [namesOfField.addOrSubFieldOnModel]: function(value, options = {}) {
1281
- const { [names.modelForm]: form } = this.get();
1282
- const index = form[namesOfField.field].findIndex((v) => v === value);
1283
- if (index === -1)
1284
- this[namesOfField.addFieldOnModel](value, options);
1285
- else
1286
- this[namesOfField.subFieldOnModel](index);
1287
- }
1288
- } : {},
1289
- ...fieldMeta.name === "File" ? {
1290
- [namesOfField.uploadFieldOnModel]: async function(fileList, index) {
1291
- const form = this.get()[names.modelForm];
1292
- if (!fileList.length)
1293
- return;
1294
- const files = await gql[names.addModelFiles](
1295
- fileList,
1296
- form.id
1297
- );
1298
- if (fieldMeta.isArray) {
1299
- const idx = index ?? form[namesOfField.field].length;
1300
- this.set((state) => {
1301
- state[names.modelForm][namesOfField.field] = [
1302
- ...form[namesOfField.field].slice(0, idx),
1303
- ...files,
1304
- ...form[namesOfField.field].slice(idx)
1305
- ];
1306
- });
1307
- } else {
1308
- this.set((state) => {
1309
- state[names.modelForm][namesOfField.field] = files[0];
1310
- });
1311
- }
1312
- files.map((file) => {
1313
- const intervalKey = setInterval(() => {
1314
- void (async () => {
1315
- const currentFile = await fileGql.file(file.id);
1316
- if (fieldMeta.isArray)
1317
- this.set((state) => {
1318
- state[names.modelForm][namesOfField.field] = state[names.modelForm][namesOfField.field].map(
1319
- (file2) => file2.id === currentFile.id ? currentFile : file2
1320
- );
1321
- });
1322
- else
1323
- this.set((state) => {
1324
- state[names.modelForm][namesOfField.field] = currentFile;
1325
- });
1326
- if (currentFile.status !== "uploading")
1327
- clearInterval(intervalKey);
1328
- })();
1329
- }, 3e3);
227
+ state[names.modelForm][namesOfField.field] = files[0];
1330
228
  });
1331
229
  }
1332
- } : {}
1333
- };
1334
- return Object.assign(acc, singleFieldSetAction);
1335
- }, {});
1336
- return Object.assign(fieldSetAction, baseSetAction);
1337
- };
1338
- var makeActions = (gql) => {
1339
- const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
1340
- const modelRef = getFullModelRef(className);
1341
- const lightModelRef = getLightModelRef(modelRef);
1342
- const names = {
1343
- model: fieldName,
1344
- _model: `_${fieldName}`,
1345
- Model: className,
1346
- purifyModel: `purify${className}`,
1347
- crystalizeModel: `crystalize${className}`,
1348
- lightCrystalizeModel: `lightCrystalize${className}`,
1349
- crystalizeInsight: `crystalize${className}Insight`,
1350
- modelOperation: `${fieldName}Operation`,
1351
- defaultModel: `default${className}`,
1352
- modelInsight: `${fieldName}Insight`,
1353
- modelForm: `${fieldName}Form`,
1354
- modelSubmit: `${fieldName}Submit`,
1355
- modelLoading: `${fieldName}Loading`,
1356
- modelFormLoading: `${fieldName}FormLoading`,
1357
- modelList: `${fieldName}List`,
1358
- modelListLoading: `${fieldName}ListLoading`,
1359
- modelSelection: `${fieldName}Selection`,
1360
- createModelInForm: `create${className}InForm`,
1361
- updateModelInForm: `modify${className}InForm`,
1362
- createModel: `create${className}`,
1363
- updateModel: `update${className}`,
1364
- removeModel: `remove${className}`,
1365
- checkModelSubmitable: `check${className}Submitable`,
1366
- submitModel: `submit${className}`,
1367
- newModel: `new${className}`,
1368
- editModel: `edit${className}`,
1369
- mergeModel: `merge${className}`,
1370
- viewModel: `view${className}`,
1371
- setModel: `set${className}`,
1372
- resetModel: `reset${className}`,
1373
- modelViewAt: `${fieldName}ViewAt`,
1374
- modelModal: `${fieldName}Modal`,
1375
- initModel: `init${className}`,
1376
- modelInitList: `${fieldName}InitList`,
1377
- modelInitAt: `${fieldName}InitAt`,
1378
- refreshModel: `refresh${className}`,
1379
- selectModel: `select${className}`,
1380
- setPageOfModel: `setPageOf${className}`,
1381
- addPageOfModel: `addPageOf${className}`,
1382
- setLimitOfModel: `setLimitOf${className}`,
1383
- setQueryArgsOfModel: `setQueryArgsOf${className}`,
1384
- setSortOfModel: `setSortOf${className}`,
1385
- lastPageOfModel: `lastPageOf${className}`,
1386
- pageOfModel: `pageOf${className}`,
1387
- limitOfModel: `limitOf${className}`,
1388
- queryArgsOfModel: `queryArgsOf${className}`,
1389
- sortOfModel: `sortOf${className}`
230
+ files.map((file) => {
231
+ const intervalKey = setInterval(() => {
232
+ void (async () => {
233
+ const currentFile = await fileGql.file(file.id);
234
+ if (fieldMeta.isArray)
235
+ this.set((state) => {
236
+ state[names.modelForm][namesOfField.field] = state[names.modelForm][namesOfField.field].map(
237
+ (file2) => file2.id === currentFile.id ? currentFile : file2
238
+ );
239
+ });
240
+ else
241
+ this.set((state) => {
242
+ state[names.modelForm][namesOfField.field] = currentFile;
243
+ });
244
+ if (currentFile.status !== "uploading")
245
+ clearInterval(intervalKey);
246
+ })();
247
+ }, 3e3);
248
+ });
249
+ }
250
+ } : {}
1390
251
  };
1391
- const baseAction = {
1392
- [names.createModelInForm]: async function({ idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
1393
- const SliceName = capitalize(sliceName);
252
+ return Object.assign(acc, singleFieldSetAction);
253
+ }, {});
254
+ return Object.assign(fieldSetAction, baseSetAction);
255
+ };
256
+ var makeActions = (gql) => {
257
+ const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
258
+ const modelRef = (0, import_constant.getFullModelRef)(className);
259
+ const lightModelRef = (0, import_constant.getLightModelRef)(modelRef);
260
+ const names = {
261
+ model: fieldName,
262
+ _model: `_${fieldName}`,
263
+ Model: className,
264
+ purifyModel: `purify${className}`,
265
+ crystalizeModel: `crystalize${className}`,
266
+ lightCrystalizeModel: `lightCrystalize${className}`,
267
+ crystalizeInsight: `crystalize${className}Insight`,
268
+ modelOperation: `${fieldName}Operation`,
269
+ defaultModel: `default${className}`,
270
+ modelInsight: `${fieldName}Insight`,
271
+ modelForm: `${fieldName}Form`,
272
+ modelSubmit: `${fieldName}Submit`,
273
+ modelLoading: `${fieldName}Loading`,
274
+ modelFormLoading: `${fieldName}FormLoading`,
275
+ modelList: `${fieldName}List`,
276
+ modelListLoading: `${fieldName}ListLoading`,
277
+ modelSelection: `${fieldName}Selection`,
278
+ createModelInForm: `create${className}InForm`,
279
+ updateModelInForm: `modify${className}InForm`,
280
+ createModel: `create${className}`,
281
+ updateModel: `update${className}`,
282
+ removeModel: `remove${className}`,
283
+ checkModelSubmitable: `check${className}Submitable`,
284
+ submitModel: `submit${className}`,
285
+ newModel: `new${className}`,
286
+ editModel: `edit${className}`,
287
+ mergeModel: `merge${className}`,
288
+ viewModel: `view${className}`,
289
+ setModel: `set${className}`,
290
+ resetModel: `reset${className}`,
291
+ modelViewAt: `${fieldName}ViewAt`,
292
+ modelModal: `${fieldName}Modal`,
293
+ initModel: `init${className}`,
294
+ modelInitList: `${fieldName}InitList`,
295
+ modelInitAt: `${fieldName}InitAt`,
296
+ refreshModel: `refresh${className}`,
297
+ selectModel: `select${className}`,
298
+ setPageOfModel: `setPageOf${className}`,
299
+ addPageOfModel: `addPageOf${className}`,
300
+ setLimitOfModel: `setLimitOf${className}`,
301
+ setQueryArgsOfModel: `setQueryArgsOf${className}`,
302
+ setSortOfModel: `setSortOf${className}`,
303
+ lastPageOfModel: `lastPageOf${className}`,
304
+ pageOfModel: `pageOf${className}`,
305
+ limitOfModel: `limitOf${className}`,
306
+ queryArgsOfModel: `queryArgsOf${className}`,
307
+ sortOfModel: `sortOf${className}`
308
+ };
309
+ const baseAction = {
310
+ [names.createModelInForm]: async function({ idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
311
+ const SliceName = (0, import_common.capitalize)(sliceName);
312
+ const namesOfSlice = {
313
+ defaultModel: SliceName.replace(names.Model, names.defaultModel),
314
+ modelList: sliceName.replace(names.model, names.modelList),
315
+ modelListLoading: sliceName.replace(names.model, names.modelListLoading),
316
+ modelInsight: sliceName.replace(names.model, names.modelInsight)
317
+ };
318
+ const currentState = this.get();
319
+ const modelForm = currentState[names.modelForm];
320
+ const modelList = currentState[namesOfSlice.modelList];
321
+ const modelListLoading = currentState[namesOfSlice.modelListLoading];
322
+ const modelInsight = currentState[namesOfSlice.modelInsight];
323
+ const defaultModel = currentState[namesOfSlice.defaultModel];
324
+ const modelInput = gql[names.purifyModel](modelForm);
325
+ if (!modelInput)
326
+ return;
327
+ this.set({ [names.modelLoading]: true });
328
+ const model = await gql[names.createModel](modelInput, { onError });
329
+ const newModelList = modelListLoading ? modelList : new import_base.DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
330
+ const newModelInsight = gql[names.crystalizeInsight]({
331
+ ...modelInsight,
332
+ count: modelInsight.count + 1
333
+ });
334
+ this.set({
335
+ [names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
336
+ [names.model]: model,
337
+ [names.modelLoading]: false,
338
+ [namesOfSlice.modelList]: newModelList,
339
+ [namesOfSlice.modelInsight]: newModelInsight,
340
+ [names.modelViewAt]: /* @__PURE__ */ new Date(),
341
+ [names.modelModal]: modal ?? null,
342
+ ...typeof path === "string" && path ? { [path]: model } : {}
343
+ });
344
+ await onSuccess?.(model);
345
+ },
346
+ [names.updateModelInForm]: async function({ path, modal, sliceName = names.model, onError, onSuccess } = {}) {
347
+ const SliceName = (0, import_common.capitalize)(sliceName);
348
+ const namesOfSlice = {
349
+ defaultModel: SliceName.replace(names.Model, names.defaultModel)
350
+ };
351
+ const currentState = this.get();
352
+ const model = currentState[names.model];
353
+ const modelForm = currentState[names.modelForm];
354
+ const defaultModel = currentState[namesOfSlice.defaultModel];
355
+ const modelInput = gql[names.purifyModel](modelForm);
356
+ if (!modelInput)
357
+ return;
358
+ if (model?.id === modelForm.id)
359
+ this.set({ [names.modelLoading]: modelForm.id });
360
+ const updatedModel = await gql[names.updateModel](modelForm.id, modelInput, {
361
+ onError
362
+ });
363
+ this.set({
364
+ ...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
365
+ [names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
366
+ [names.modelModal]: modal ?? null,
367
+ ...typeof path === "string" && path ? { [path]: updatedModel } : {}
368
+ });
369
+ const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
370
+ gql.slices.forEach(({ sliceName: sliceName2 }) => {
371
+ const namesOfSlice2 = {
372
+ modelList: sliceName2.replace(names.model, names.modelList),
373
+ modelListLoading: sliceName2.replace(names.model, names.modelListLoading)
374
+ };
375
+ const currentState2 = this.get();
376
+ const modelList = currentState2[namesOfSlice2.modelList];
377
+ const modelListLoading = currentState2[namesOfSlice2.modelListLoading];
378
+ if (modelListLoading || !modelList.has(updatedModel.id))
379
+ return;
380
+ const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
381
+ this.set({ [namesOfSlice2.modelList]: newModelList });
382
+ });
383
+ await onSuccess?.(updatedModel);
384
+ },
385
+ [names.createModel]: async function(data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
386
+ const SliceName = (0, import_common.capitalize)(sliceName);
387
+ const namesOfSlice = {
388
+ defaultModel: SliceName.replace(names.Model, names.defaultModel),
389
+ modelList: sliceName.replace(names.model, names.modelList),
390
+ modelListLoading: sliceName.replace(names.model, names.modelListLoading),
391
+ modelInsight: sliceName.replace(names.model, names.modelInsight)
392
+ };
393
+ const currentState = this.get();
394
+ const modelList = currentState[namesOfSlice.modelList];
395
+ const modelListLoading = currentState[namesOfSlice.modelListLoading];
396
+ const modelInsight = currentState[namesOfSlice.modelInsight];
397
+ const modelInput = gql[names.purifyModel](data);
398
+ if (!modelInput)
399
+ return;
400
+ this.set({ [names.modelLoading]: true });
401
+ const model = await gql[names.createModel](modelInput, { onError });
402
+ const newModelList = modelListLoading ? modelList : new import_base.DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
403
+ const newModelInsight = gql[names.crystalizeInsight]({
404
+ ...modelInsight,
405
+ count: modelInsight.count + 1
406
+ });
407
+ this.set({
408
+ [names.model]: model,
409
+ [names.modelLoading]: false,
410
+ [namesOfSlice.modelList]: newModelList,
411
+ [namesOfSlice.modelInsight]: newModelInsight,
412
+ [names.modelViewAt]: /* @__PURE__ */ new Date(),
413
+ [names.modelModal]: modal ?? null,
414
+ ...typeof path === "string" && path ? { [path]: model } : {}
415
+ });
416
+ await onSuccess?.(model);
417
+ },
418
+ [names.updateModel]: async function(id, data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
419
+ const currentState = this.get();
420
+ const model = currentState[names.model];
421
+ const modelInput = gql[names.purifyModel](data);
422
+ if (!modelInput)
423
+ return;
424
+ if (model?.id === id)
425
+ this.set({ [names.modelLoading]: id });
426
+ const updatedModel = await gql[names.updateModel](id, modelInput, { onError });
427
+ this.set({
428
+ ...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
429
+ [names.modelModal]: modal ?? null,
430
+ ...typeof path === "string" && path ? { [path]: updatedModel } : {}
431
+ });
432
+ const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
433
+ gql.slices.forEach(({ sliceName: sliceName2 }) => {
434
+ const namesOfSlice = {
435
+ modelList: sliceName2.replace(names.model, names.modelList),
436
+ modelListLoading: sliceName2.replace(names.model, names.modelListLoading)
437
+ };
438
+ const currentState2 = this.get();
439
+ const modelList = currentState2[namesOfSlice.modelList];
440
+ const modelListLoading = currentState2[namesOfSlice.modelListLoading];
441
+ if (modelListLoading || !modelList.has(updatedModel.id))
442
+ return;
443
+ const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
444
+ this.set({ [namesOfSlice.modelList]: newModelList });
445
+ });
446
+ await onSuccess?.(updatedModel);
447
+ },
448
+ [names.removeModel]: async function(id, options) {
449
+ const { modal, ...fetchPolicyOptions } = options ?? {};
450
+ const model = await gql[names.removeModel](
451
+ id,
452
+ fetchPolicyOptions
453
+ );
454
+ const lightModel = gql[names.lightCrystalizeModel](model);
455
+ gql.slices.forEach(({ sliceName }) => {
1394
456
  const namesOfSlice = {
1395
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
1396
457
  modelList: sliceName.replace(names.model, names.modelList),
1397
458
  modelListLoading: sliceName.replace(names.model, names.modelListLoading),
459
+ modelSelection: sliceName.replace(names.model, names.modelSelection),
1398
460
  modelInsight: sliceName.replace(names.model, names.modelInsight)
1399
461
  };
1400
462
  const currentState = this.get();
1401
- const modelForm = currentState[names.modelForm];
1402
463
  const modelList = currentState[namesOfSlice.modelList];
1403
464
  const modelListLoading = currentState[namesOfSlice.modelListLoading];
465
+ const modelSelection = currentState[namesOfSlice.modelSelection];
1404
466
  const modelInsight = currentState[namesOfSlice.modelInsight];
1405
- const defaultModel = currentState[namesOfSlice.defaultModel];
1406
- const modelInput = gql[names.purifyModel](modelForm);
1407
- if (!modelInput)
467
+ if (modelListLoading || !modelList.has(model.id))
1408
468
  return;
1409
- this.set({ [names.modelLoading]: true });
1410
- const model = await gql[names.createModel](modelInput, { onError });
1411
- const newModelList = modelListLoading ? modelList : new DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
1412
- const newModelInsight = gql[names.crystalizeInsight]({
1413
- ...modelInsight,
1414
- count: modelInsight.count + 1
1415
- });
1416
- this.set({
1417
- [names.modelForm]: immerify(modelRef, defaultModel),
1418
- [names.model]: model,
1419
- [names.modelLoading]: false,
1420
- [namesOfSlice.modelList]: newModelList,
1421
- [namesOfSlice.modelInsight]: newModelInsight,
1422
- [names.modelViewAt]: /* @__PURE__ */ new Date(),
1423
- [names.modelModal]: modal ?? null,
1424
- ...typeof path === "string" && path ? { [path]: model } : {}
1425
- });
1426
- await onSuccess?.(model);
1427
- },
1428
- [names.updateModelInForm]: async function({ path, modal, sliceName = names.model, onError, onSuccess } = {}) {
1429
- const SliceName = capitalize(sliceName);
469
+ const newModelList = new import_base.DataList(modelList);
470
+ if (model.removedAt) {
471
+ newModelList.delete(id);
472
+ const newModelInsight = gql[names.crystalizeInsight]({
473
+ ...modelInsight,
474
+ count: modelInsight.count - 1
475
+ });
476
+ const newModelSelection = new import_base.DataList(modelSelection);
477
+ newModelSelection.delete(id);
478
+ this.set({
479
+ [namesOfSlice.modelList]: newModelList,
480
+ [namesOfSlice.modelInsight]: newModelInsight,
481
+ ...modelSelection.has(model.id) ? { [namesOfSlice.modelSelection]: newModelSelection } : {},
482
+ ...modal !== void 0 ? { [names.modelModal]: modal } : {}
483
+ });
484
+ } else {
485
+ newModelList.set(lightModel);
486
+ this.set({
487
+ [namesOfSlice.modelList]: newModelList,
488
+ ...modal !== void 0 ? { [names.modelModal]: modal } : {}
489
+ });
490
+ }
491
+ });
492
+ },
493
+ [names.checkModelSubmitable]: function(disabled) {
494
+ const currentState = this.get();
495
+ const modelForm = currentState[names.modelForm];
496
+ const modelSubmit = currentState[names.modelSubmit];
497
+ const modelInput = gql[names.purifyModel](modelForm);
498
+ this.set({ [names.modelSubmit]: { ...modelSubmit, disabled: !modelInput || disabled } });
499
+ },
500
+ [names.submitModel]: async function(option) {
501
+ const currentState = this.get();
502
+ const modelForm = currentState[names.modelForm];
503
+ const modelSubmit = currentState[names.modelSubmit];
504
+ this.set({ [names.modelSubmit]: { ...modelSubmit, loading: true } });
505
+ if (modelForm.id)
506
+ await this[names.updateModelInForm](option);
507
+ else
508
+ await this[names.createModelInForm](option);
509
+ this.set({ [names.modelSubmit]: { ...modelSubmit, loading: false, times: modelSubmit.times + 1 } });
510
+ },
511
+ [names.newModel]: function(partial = {}, { modal, setDefault, sliceName = names.model } = {}) {
512
+ const SliceName = (0, import_common.capitalize)(sliceName);
513
+ const namesOfSlice = {
514
+ defaultModel: SliceName.replace(names.Model, names.defaultModel)
515
+ };
516
+ const currentState = this.get();
517
+ const defaultModel = currentState[namesOfSlice.defaultModel];
518
+ this.set({
519
+ [names.modelForm]: (0, import_signal.immerify)(modelRef, { ...defaultModel, ...partial }),
520
+ [namesOfSlice.defaultModel]: setDefault ? (0, import_signal.immerify)(modelRef, { ...defaultModel, ...partial }) : defaultModel,
521
+ [names.model]: null,
522
+ [names.modelModal]: modal ?? "edit",
523
+ [names.modelFormLoading]: false
524
+ });
525
+ },
526
+ [names.editModel]: async function(modelOrId, { modal, onError } = {}) {
527
+ const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
528
+ this.set({ [names.modelFormLoading]: id, [names.modelModal]: modal ?? "edit" });
529
+ this.set((state) => {
530
+ state[names.modelForm].id = id;
531
+ });
532
+ const model = await gql[names.model](id, { onError });
533
+ const modelForm = (0, import_common.deepObjectify)(model);
534
+ this.set({
535
+ [names.model]: model,
536
+ [names.modelFormLoading]: false,
537
+ [names.modelViewAt]: /* @__PURE__ */ new Date(),
538
+ [names.modelForm]: modelForm
539
+ });
540
+ },
541
+ [names.mergeModel]: async function(modelOrId, data, options) {
542
+ const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
543
+ const currentState = this.get();
544
+ const model = currentState[names.model];
545
+ if (id === model?.id)
546
+ this.set({ modelLoading: id });
547
+ const updatedModel = await gql[names.mergeModel](modelOrId, data, options);
548
+ this.set({
549
+ [names.model]: id === model?.id ? updatedModel : model,
550
+ [names.modelLoading]: false
551
+ });
552
+ const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
553
+ gql.slices.forEach(({ sliceName }) => {
1430
554
  const namesOfSlice = {
1431
- defaultModel: SliceName.replace(names.Model, names.defaultModel)
555
+ modelList: sliceName.replace(names.model, names.modelList),
556
+ modelListLoading: sliceName.replace(names.model, names.modelListLoading)
1432
557
  };
1433
- const currentState = this.get();
1434
- const model = currentState[names.model];
1435
- const modelForm = currentState[names.modelForm];
1436
- const defaultModel = currentState[namesOfSlice.defaultModel];
1437
- const modelInput = gql[names.purifyModel](modelForm);
1438
- if (!modelInput)
558
+ const currentState2 = this.get();
559
+ const modelList = currentState2[namesOfSlice.modelList];
560
+ const modelListLoading = currentState2[namesOfSlice.modelListLoading];
561
+ if (modelListLoading || !modelList.has(updatedModel.id))
1439
562
  return;
1440
- if (model?.id === modelForm.id)
1441
- this.set({ [names.modelLoading]: modelForm.id });
1442
- const updatedModel = await gql[names.updateModel](modelForm.id, modelInput, {
1443
- onError
1444
- });
1445
- this.set({
1446
- ...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
1447
- [names.modelForm]: immerify(modelRef, defaultModel),
1448
- [names.modelModal]: modal ?? null,
1449
- ...typeof path === "string" && path ? { [path]: updatedModel } : {}
1450
- });
1451
- const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
1452
- gql.slices.forEach(({ sliceName: sliceName2 }) => {
1453
- const namesOfSlice2 = {
1454
- modelList: sliceName2.replace(names.model, names.modelList),
1455
- modelListLoading: sliceName2.replace(names.model, names.modelListLoading)
1456
- };
1457
- const currentState2 = this.get();
1458
- const modelList = currentState2[namesOfSlice2.modelList];
1459
- const modelListLoading = currentState2[namesOfSlice2.modelListLoading];
1460
- if (modelListLoading || !modelList.has(updatedModel.id))
1461
- return;
1462
- const newModelList = new DataList(modelList).set(updatedLightModel);
1463
- this.set({ [namesOfSlice2.modelList]: newModelList });
1464
- });
1465
- await onSuccess?.(updatedModel);
1466
- },
1467
- [names.createModel]: async function(data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
1468
- const SliceName = capitalize(sliceName);
563
+ const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
564
+ this.set({ [namesOfSlice.modelList]: newModelList });
565
+ });
566
+ },
567
+ [names.viewModel]: async function(modelOrId, { modal, onError } = {}) {
568
+ const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
569
+ this.set({ [names.modelModal]: modal ?? "view", [names.modelLoading]: id });
570
+ const model = await gql[names.model](id, { onError });
571
+ this.set({ [names.model]: model, [names.modelViewAt]: /* @__PURE__ */ new Date(), [names.modelLoading]: false });
572
+ },
573
+ [names.setModel]: function(fullOrLightModel) {
574
+ const currentState = this.get();
575
+ const model = currentState[names.model];
576
+ const isFull = fullOrLightModel instanceof modelRef;
577
+ if (isFull) {
578
+ const crystalizedModel = gql[names.crystalizeModel](fullOrLightModel);
579
+ this.set({ [names.model]: crystalizedModel });
580
+ } else if (model?.id === fullOrLightModel.id) {
581
+ const crystalizedModel = gql[names.crystalizeModel]({ ...model, ...fullOrLightModel });
582
+ this.set({ [names.model]: crystalizedModel });
583
+ }
584
+ const lightModel = gql[names.lightCrystalizeModel](fullOrLightModel);
585
+ gql.slices.forEach(({ sliceName }) => {
1469
586
  const namesOfSlice = {
1470
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
1471
587
  modelList: sliceName.replace(names.model, names.modelList),
1472
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
1473
- modelInsight: sliceName.replace(names.model, names.modelInsight)
588
+ modelListLoading: sliceName.replace(names.model, names.modelListLoading)
1474
589
  };
1475
- const currentState = this.get();
1476
590
  const modelList = currentState[namesOfSlice.modelList];
1477
591
  const modelListLoading = currentState[namesOfSlice.modelListLoading];
1478
- const modelInsight = currentState[namesOfSlice.modelInsight];
1479
- const modelInput = gql[names.purifyModel](data);
1480
- if (!modelInput)
592
+ if (modelListLoading || !modelList.has(lightModel.id))
1481
593
  return;
1482
- this.set({ [names.modelLoading]: true });
1483
- const model = await gql[names.createModel](modelInput, { onError });
1484
- const newModelList = modelListLoading ? modelList : new DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
1485
- const newModelInsight = gql[names.crystalizeInsight]({
1486
- ...modelInsight,
1487
- count: modelInsight.count + 1
1488
- });
1489
- this.set({
1490
- [names.model]: model,
1491
- [names.modelLoading]: false,
1492
- [namesOfSlice.modelList]: newModelList,
1493
- [namesOfSlice.modelInsight]: newModelInsight,
1494
- [names.modelViewAt]: /* @__PURE__ */ new Date(),
1495
- [names.modelModal]: modal ?? null,
1496
- ...typeof path === "string" && path ? { [path]: model } : {}
1497
- });
1498
- await onSuccess?.(model);
594
+ this.set({ [namesOfSlice.modelList]: modelList.set(lightModel).save() });
595
+ });
596
+ },
597
+ [names.resetModel]: function(model) {
598
+ const currentState = this.get();
599
+ const defaultModel = currentState[names.defaultModel];
600
+ this.set({
601
+ [names.model]: model ?? null,
602
+ [names.modelViewAt]: /* @__PURE__ */ new Date(0),
603
+ [names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
604
+ [names.modelModal]: null
605
+ });
606
+ return model ?? null;
607
+ }
608
+ };
609
+ const sliceAction = gql.slices.reduce((acc, { sliceName, argLength }) => {
610
+ const SliceName = (0, import_common.capitalize)(sliceName);
611
+ const namesOfSlice = {
612
+ defaultModel: SliceName.replace(names.Model, names.defaultModel),
613
+ modelInsight: sliceName.replace(names.model, names.modelInsight),
614
+ modelList: sliceName.replace(names.model, names.modelList),
615
+ modelListLoading: sliceName.replace(names.model, names.modelListLoading),
616
+ initModel: SliceName.replace(names.Model, names.initModel),
617
+ modelInitList: SliceName.replace(names.Model, names.modelInitList),
618
+ modelInitAt: SliceName.replace(names.Model, names.modelInitAt),
619
+ refreshModel: SliceName.replace(names.Model, names.refreshModel),
620
+ selectModel: SliceName.replace(names.Model, names.selectModel),
621
+ setPageOfModel: SliceName.replace(names.Model, names.setPageOfModel),
622
+ addPageOfModel: SliceName.replace(names.Model, names.addPageOfModel),
623
+ setLimitOfModel: SliceName.replace(names.Model, names.setLimitOfModel),
624
+ setQueryArgsOfModel: SliceName.replace(names.Model, names.setQueryArgsOfModel),
625
+ setSortOfModel: SliceName.replace(names.Model, names.setSortOfModel),
626
+ lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
627
+ pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
628
+ limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
629
+ queryArgsOfModel: SliceName.replace(names.Model, names.queryArgsOfModel),
630
+ sortOfModel: SliceName.replace(names.Model, names.sortOfModel),
631
+ modelSelection: SliceName.replace(names.Model, names.modelSelection)
632
+ };
633
+ const singleSliceAction = {
634
+ [namesOfSlice.initModel]: async function(...args) {
635
+ const initArgLength = Math.min(args.length, argLength);
636
+ const initForm = { invalidate: false, ...args[argLength] ?? {} };
637
+ const queryArgs = new Array(initArgLength).fill(null).map((_, i) => args[i]);
638
+ const defaultModel = (0, import_signal.immerify)(modelRef, { ...gql[names.defaultModel], ...initForm.default ?? {} });
639
+ this.set({ [names.defaultModel]: defaultModel });
640
+ await this[namesOfSlice.refreshModel](
641
+ ...initArgLength === argLength ? [...queryArgs, initForm] : queryArgs
642
+ );
1499
643
  },
1500
- [names.updateModel]: async function(id, data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
644
+ [namesOfSlice.refreshModel]: async function(...args) {
645
+ const refreshArgLength = Math.min(args.length, argLength);
1501
646
  const currentState = this.get();
1502
- const model = currentState[names.model];
1503
- const modelInput = gql[names.purifyModel](data);
1504
- if (!modelInput)
647
+ const existingQueryArgs = currentState[namesOfSlice.queryArgsOfModel];
648
+ const queryArgs = [
649
+ ...new Array(refreshArgLength).fill(null).map((_, i) => args[i]),
650
+ ...existingQueryArgs.slice(refreshArgLength, argLength)
651
+ ];
652
+ const initForm = args[argLength] ?? {};
653
+ const {
654
+ page = currentState[namesOfSlice.pageOfModel],
655
+ limit = currentState[namesOfSlice.limitOfModel],
656
+ sort = currentState[namesOfSlice.sortOfModel],
657
+ invalidate = true
658
+ } = initForm;
659
+ const modelOperation = currentState[names.modelOperation];
660
+ const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
661
+ const pageOfModel = currentState[namesOfSlice.pageOfModel];
662
+ const limitOfModel = currentState[namesOfSlice.limitOfModel];
663
+ const sortOfModel = currentState[namesOfSlice.sortOfModel];
664
+ if (!invalidate && !["sleep", "reset"].includes(modelOperation) && (0, import_common.isQueryEqual)(queryArgs, queryArgsOfModel) && page === pageOfModel && limit === limitOfModel && (0, import_common.isQueryEqual)(sort, sortOfModel))
1505
665
  return;
1506
- if (model?.id === id)
1507
- this.set({ [names.modelLoading]: id });
1508
- const updatedModel = await gql[names.updateModel](id, modelInput, { onError });
666
+ else
667
+ this.set({ [namesOfSlice.modelListLoading]: true });
668
+ const [modelDataList, modelInsight] = await Promise.all([
669
+ gql[namesOfSlice.modelList](
670
+ ...queryArgs,
671
+ (page - 1) * limit,
672
+ limit,
673
+ sort,
674
+ { onError: initForm.onError }
675
+ ),
676
+ gql[namesOfSlice.modelInsight](...queryArgs, {
677
+ onError: initForm.onError
678
+ })
679
+ ]);
680
+ const modelList = new import_base.DataList(modelDataList);
1509
681
  this.set({
1510
- ...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
1511
- [names.modelModal]: modal ?? null,
1512
- ...typeof path === "string" && path ? { [path]: updatedModel } : {}
1513
- });
1514
- const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
1515
- gql.slices.forEach(({ sliceName: sliceName2 }) => {
1516
- const namesOfSlice = {
1517
- modelList: sliceName2.replace(names.model, names.modelList),
1518
- modelListLoading: sliceName2.replace(names.model, names.modelListLoading)
1519
- };
1520
- const currentState2 = this.get();
1521
- const modelList = currentState2[namesOfSlice.modelList];
1522
- const modelListLoading = currentState2[namesOfSlice.modelListLoading];
1523
- if (modelListLoading || !modelList.has(updatedModel.id))
1524
- return;
1525
- const newModelList = new DataList(modelList).set(updatedLightModel);
1526
- this.set({ [namesOfSlice.modelList]: newModelList });
1527
- });
1528
- await onSuccess?.(updatedModel);
1529
- },
1530
- [names.removeModel]: async function(id, options) {
1531
- const { modal, ...fetchPolicyOptions } = options ?? {};
1532
- const model = await gql[names.removeModel](
1533
- id,
1534
- fetchPolicyOptions
1535
- );
1536
- const lightModel = gql[names.lightCrystalizeModel](model);
1537
- gql.slices.forEach(({ sliceName }) => {
1538
- const namesOfSlice = {
1539
- modelList: sliceName.replace(names.model, names.modelList),
1540
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
1541
- modelSelection: sliceName.replace(names.model, names.modelSelection),
1542
- modelInsight: sliceName.replace(names.model, names.modelInsight)
1543
- };
1544
- const currentState = this.get();
1545
- const modelList = currentState[namesOfSlice.modelList];
1546
- const modelListLoading = currentState[namesOfSlice.modelListLoading];
1547
- const modelSelection = currentState[namesOfSlice.modelSelection];
1548
- const modelInsight = currentState[namesOfSlice.modelInsight];
1549
- if (modelListLoading || !modelList.has(model.id))
1550
- return;
1551
- const newModelList = new DataList(modelList);
1552
- if (model.removedAt) {
1553
- newModelList.delete(id);
1554
- const newModelInsight = gql[names.crystalizeInsight]({
1555
- ...modelInsight,
1556
- count: modelInsight.count - 1
1557
- });
1558
- const newModelSelection = new DataList(modelSelection);
1559
- newModelSelection.delete(id);
1560
- this.set({
1561
- [namesOfSlice.modelList]: newModelList,
1562
- [namesOfSlice.modelInsight]: newModelInsight,
1563
- ...modelSelection.has(model.id) ? { [namesOfSlice.modelSelection]: newModelSelection } : {},
1564
- ...modal !== void 0 ? { [names.modelModal]: modal } : {}
1565
- });
1566
- } else {
1567
- newModelList.set(lightModel);
1568
- this.set({
1569
- [namesOfSlice.modelList]: newModelList,
1570
- ...modal !== void 0 ? { [names.modelModal]: modal } : {}
1571
- });
1572
- }
682
+ [namesOfSlice.modelList]: modelList,
683
+ [namesOfSlice.modelListLoading]: false,
684
+ [namesOfSlice.modelInsight]: modelInsight,
685
+ [namesOfSlice.modelInitList]: modelList,
686
+ [namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(),
687
+ [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limit) + 1, 1),
688
+ [namesOfSlice.limitOfModel]: limit,
689
+ [namesOfSlice.queryArgsOfModel]: queryArgs,
690
+ [namesOfSlice.sortOfModel]: sort,
691
+ [namesOfSlice.pageOfModel]: page,
692
+ [names.modelOperation]: "idle"
1573
693
  });
1574
694
  },
1575
- [names.checkModelSubmitable]: function(disabled) {
1576
- const currentState = this.get();
1577
- const modelForm = currentState[names.modelForm];
1578
- const modelSubmit = currentState[names.modelSubmit];
1579
- const modelInput = gql[names.purifyModel](modelForm);
1580
- this.set({ [names.modelSubmit]: { ...modelSubmit, disabled: !modelInput || disabled } });
1581
- },
1582
- [names.submitModel]: async function(option) {
695
+ [namesOfSlice.selectModel]: function(model, { refresh, remove } = {}) {
696
+ const models = Array.isArray(model) ? model : [model];
1583
697
  const currentState = this.get();
1584
- const modelForm = currentState[names.modelForm];
1585
- const modelSubmit = currentState[names.modelSubmit];
1586
- this.set({ [names.modelSubmit]: { ...modelSubmit, loading: true } });
1587
- if (modelForm.id)
1588
- await this[names.updateModelInForm](option);
1589
- else
1590
- await this[names.createModelInForm](option);
1591
- this.set({ [names.modelSubmit]: { ...modelSubmit, loading: false, times: modelSubmit.times + 1 } });
698
+ const modelSelection = currentState[namesOfSlice.modelSelection];
699
+ if (refresh)
700
+ this.set({ [namesOfSlice.modelSelection]: new import_base.DataList(models) });
701
+ else if (remove) {
702
+ const newModelSelection = new import_base.DataList(modelSelection);
703
+ models.map((model2) => newModelSelection.delete(model2.id));
704
+ this.set({ [namesOfSlice.modelSelection]: newModelSelection });
705
+ } else {
706
+ this.set({ [namesOfSlice.modelSelection]: new import_base.DataList([...modelSelection.values, ...models]) });
707
+ }
1592
708
  },
1593
- [names.newModel]: function(partial = {}, { modal, setDefault, sliceName = names.model } = {}) {
1594
- const SliceName = capitalize(sliceName);
1595
- const namesOfSlice = {
1596
- defaultModel: SliceName.replace(names.Model, names.defaultModel)
1597
- };
709
+ [namesOfSlice.setPageOfModel]: async function(page, options) {
1598
710
  const currentState = this.get();
1599
- const defaultModel = currentState[namesOfSlice.defaultModel];
711
+ const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
712
+ const pageOfModel = currentState[namesOfSlice.pageOfModel];
713
+ const limitOfModel = currentState[namesOfSlice.limitOfModel];
714
+ const sortOfModel = currentState[namesOfSlice.sortOfModel];
715
+ if (pageOfModel === page)
716
+ return;
717
+ this.set({ [namesOfSlice.modelListLoading]: true });
718
+ const modelDataList = await gql[namesOfSlice.modelList](
719
+ ...queryArgsOfModel,
720
+ (page - 1) * limitOfModel,
721
+ limitOfModel,
722
+ sortOfModel,
723
+ options
724
+ );
725
+ const modelList = new import_base.DataList(modelDataList);
1600
726
  this.set({
1601
- [names.modelForm]: immerify(modelRef, { ...defaultModel, ...partial }),
1602
- [namesOfSlice.defaultModel]: setDefault ? immerify(modelRef, { ...defaultModel, ...partial }) : defaultModel,
1603
- [names.model]: null,
1604
- [names.modelModal]: modal ?? "edit",
1605
- [names.modelFormLoading]: false
727
+ [namesOfSlice.modelList]: modelList,
728
+ [namesOfSlice.pageOfModel]: page,
729
+ [namesOfSlice.modelListLoading]: false
1606
730
  });
1607
731
  },
1608
- [names.editModel]: async function(modelOrId, { modal, onError } = {}) {
1609
- const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
1610
- this.set({ [names.modelFormLoading]: id, [names.modelModal]: modal ?? "edit" });
1611
- this.set((state) => {
1612
- state[names.modelForm].id = id;
1613
- });
1614
- const model = await gql[names.model](id, { onError });
1615
- const modelForm = deepObjectify(model);
1616
- this.set({
1617
- [names.model]: model,
1618
- [names.modelFormLoading]: false,
1619
- [names.modelViewAt]: /* @__PURE__ */ new Date(),
1620
- [names.modelForm]: modelForm
1621
- });
732
+ [namesOfSlice.addPageOfModel]: async function(page, options) {
733
+ const currentState = this.get();
734
+ const modelList = currentState[namesOfSlice.modelList];
735
+ const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
736
+ const pageOfModel = currentState[namesOfSlice.pageOfModel];
737
+ const limitOfModel = currentState[namesOfSlice.limitOfModel];
738
+ const sortOfModel = currentState[namesOfSlice.sortOfModel];
739
+ if (pageOfModel === page)
740
+ return;
741
+ const addFront = page < pageOfModel;
742
+ const modelDataList = await gql[namesOfSlice.modelList](
743
+ ...queryArgsOfModel,
744
+ (page - 1) * limitOfModel,
745
+ limitOfModel,
746
+ sortOfModel,
747
+ options
748
+ );
749
+ const newModelList = new import_base.DataList(
750
+ addFront ? [...modelDataList, ...modelList] : [...modelList, ...modelDataList]
751
+ );
752
+ this.set({ [namesOfSlice.modelList]: newModelList, [namesOfSlice.pageOfModel]: page });
1622
753
  },
1623
- [names.mergeModel]: async function(modelOrId, data, options) {
1624
- const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
754
+ [namesOfSlice.setLimitOfModel]: async function(limit, options) {
1625
755
  const currentState = this.get();
1626
- const model = currentState[names.model];
1627
- if (id === model?.id)
1628
- this.set({ modelLoading: id });
1629
- const updatedModel = await gql[names.mergeModel](modelOrId, data, options);
756
+ const modelInsight = currentState[namesOfSlice.modelInsight];
757
+ const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
758
+ const pageOfModel = currentState[namesOfSlice.pageOfModel];
759
+ const limitOfModel = currentState[namesOfSlice.limitOfModel];
760
+ const sortOfModel = currentState[namesOfSlice.sortOfModel];
761
+ if (limitOfModel === limit)
762
+ return;
763
+ const skip = (pageOfModel - 1) * limitOfModel;
764
+ const page = Math.max(Math.floor((skip - 1) / limit) + 1, 1);
765
+ const modelDataList = await gql[namesOfSlice.modelList](
766
+ ...queryArgsOfModel,
767
+ (page - 1) * limit,
768
+ limit,
769
+ sortOfModel,
770
+ options
771
+ );
772
+ const modelList = new import_base.DataList(modelDataList);
1630
773
  this.set({
1631
- [names.model]: id === model?.id ? updatedModel : model,
1632
- [names.modelLoading]: false
1633
- });
1634
- const updatedLightModel = gql[names.lightCrystalizeModel](updatedModel);
1635
- gql.slices.forEach(({ sliceName }) => {
1636
- const namesOfSlice = {
1637
- modelList: sliceName.replace(names.model, names.modelList),
1638
- modelListLoading: sliceName.replace(names.model, names.modelListLoading)
1639
- };
1640
- const currentState2 = this.get();
1641
- const modelList = currentState2[namesOfSlice.modelList];
1642
- const modelListLoading = currentState2[namesOfSlice.modelListLoading];
1643
- if (modelListLoading || !modelList.has(updatedModel.id))
1644
- return;
1645
- const newModelList = new DataList(modelList).set(updatedLightModel);
1646
- this.set({ [namesOfSlice.modelList]: newModelList });
774
+ [namesOfSlice.modelList]: modelList,
775
+ [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limit) + 1, 1),
776
+ [namesOfSlice.limitOfModel]: limit,
777
+ [namesOfSlice.pageOfModel]: page
1647
778
  });
1648
779
  },
1649
- [names.viewModel]: async function(modelOrId, { modal, onError } = {}) {
1650
- const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
1651
- this.set({ [names.modelModal]: modal ?? "view", [names.modelLoading]: id });
1652
- const model = await gql[names.model](id, { onError });
1653
- this.set({ [names.model]: model, [names.modelViewAt]: /* @__PURE__ */ new Date(), [names.modelLoading]: false });
1654
- },
1655
- [names.setModel]: function(fullOrLightModel) {
780
+ [namesOfSlice.setQueryArgsOfModel]: async function(...args) {
781
+ const queryArgs = new Array(argLength).fill(null).map((_, i) => args[i]);
782
+ const options = args[argLength];
1656
783
  const currentState = this.get();
1657
- const model = currentState[names.model];
1658
- const isFull = fullOrLightModel instanceof modelRef;
1659
- if (isFull) {
1660
- const crystalizedModel = gql[names.crystalizeModel](fullOrLightModel);
1661
- this.set({ [names.model]: crystalizedModel });
1662
- } else if (model?.id === fullOrLightModel.id) {
1663
- const crystalizedModel = gql[names.crystalizeModel]({ ...model, ...fullOrLightModel });
1664
- this.set({ [names.model]: crystalizedModel });
784
+ const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
785
+ const limitOfModel = currentState[namesOfSlice.limitOfModel];
786
+ const sortOfModel = currentState[namesOfSlice.sortOfModel];
787
+ if ((0, import_common.isQueryEqual)(queryArgsOfModel, queryArgs)) {
788
+ import_common.Logger.trace(`${namesOfSlice.queryArgsOfModel} store-level cache hit`);
789
+ return;
1665
790
  }
1666
- const lightModel = gql[names.lightCrystalizeModel](fullOrLightModel);
1667
- gql.slices.forEach(({ sliceName }) => {
1668
- const namesOfSlice = {
1669
- modelList: sliceName.replace(names.model, names.modelList),
1670
- modelListLoading: sliceName.replace(names.model, names.modelListLoading)
1671
- };
1672
- const modelList = currentState[namesOfSlice.modelList];
1673
- const modelListLoading = currentState[namesOfSlice.modelListLoading];
1674
- if (modelListLoading || !modelList.has(lightModel.id))
1675
- return;
1676
- this.set({ [namesOfSlice.modelList]: modelList.set(lightModel).save() });
791
+ this.set({ [namesOfSlice.modelListLoading]: true });
792
+ const [modelDataList, modelInsight] = await Promise.all([
793
+ gql[namesOfSlice.modelList](
794
+ ...queryArgs,
795
+ 0,
796
+ limitOfModel,
797
+ sortOfModel,
798
+ options
799
+ ),
800
+ gql[namesOfSlice.modelInsight](...queryArgs, options)
801
+ ]);
802
+ const modelList = new import_base.DataList(modelDataList);
803
+ this.set({
804
+ [namesOfSlice.queryArgsOfModel]: queryArgs,
805
+ [namesOfSlice.modelList]: modelList,
806
+ [namesOfSlice.modelInsight]: modelInsight,
807
+ [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limitOfModel) + 1, 1),
808
+ [namesOfSlice.pageOfModel]: 1,
809
+ [namesOfSlice.modelSelection]: /* @__PURE__ */ new Map(),
810
+ [namesOfSlice.modelListLoading]: false
1677
811
  });
1678
812
  },
1679
- [names.resetModel]: function(model) {
813
+ [namesOfSlice.setSortOfModel]: async function(sort, options) {
1680
814
  const currentState = this.get();
1681
- const defaultModel = currentState[names.defaultModel];
815
+ const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
816
+ const limitOfModel = currentState[namesOfSlice.limitOfModel];
817
+ const sortOfModel = currentState[namesOfSlice.sortOfModel];
818
+ if (sortOfModel === sort)
819
+ return;
820
+ this.set({ [namesOfSlice.modelListLoading]: true });
821
+ const modelDataList = await gql[namesOfSlice.modelList](
822
+ ...queryArgsOfModel,
823
+ 0,
824
+ limitOfModel,
825
+ sort,
826
+ options
827
+ );
828
+ const modelList = new import_base.DataList(modelDataList);
1682
829
  this.set({
1683
- [names.model]: model ?? null,
1684
- [names.modelViewAt]: /* @__PURE__ */ new Date(0),
1685
- [names.modelForm]: immerify(modelRef, defaultModel),
1686
- [names.modelModal]: null
830
+ [namesOfSlice.modelList]: modelList,
831
+ [namesOfSlice.sortOfModel]: sort,
832
+ [namesOfSlice.pageOfModel]: 1,
833
+ [namesOfSlice.modelListLoading]: false
1687
834
  });
1688
- return model ?? null;
1689
835
  }
1690
836
  };
1691
- const sliceAction = gql.slices.reduce((acc, { sliceName, argLength }) => {
1692
- const SliceName = capitalize(sliceName);
1693
- const namesOfSlice = {
837
+ return Object.assign(acc, singleSliceAction);
838
+ }, {});
839
+ return { ...baseAction, ...sliceAction };
840
+ };
841
+ var stateOf = (gql, state) => {
842
+ const applyState = Object.assign(createState(gql), state);
843
+ const applyAction = createActions(gql);
844
+ setStoreMeta(gql.refName, {
845
+ refName: gql.refName,
846
+ useKeys: Object.keys(applyState),
847
+ doKeys: Object.keys(applyAction),
848
+ slices: gql.slices
849
+ });
850
+ const applyStore = { ...applyState, ...applyAction };
851
+ class StateStore {
852
+ get;
853
+ set;
854
+ pick;
855
+ }
856
+ Object.keys(applyStore).forEach(
857
+ (key) => Object.defineProperty(StateStore.prototype, key, { value: applyStore[key] })
858
+ );
859
+ return StateStore;
860
+ };
861
+ var scalarStateOf = (refName, state) => {
862
+ const applyState = state;
863
+ setStoreMeta(refName, { refName, useKeys: Object.keys(applyState), doKeys: [], slices: [] });
864
+ class StateStore {
865
+ get;
866
+ set;
867
+ pick;
868
+ }
869
+ Object.keys(applyState).forEach(
870
+ (key) => Object.defineProperty(StateStore.prototype, key, { value: applyState[key] })
871
+ );
872
+ return StateStore;
873
+ };
874
+ var Store = (returnsOrObj) => {
875
+ const refName = typeof returnsOrObj === "object" ? returnsOrObj.name : (0, import_common.lowerlize)((0, import_constant.getClassMeta)(returnsOrObj()).refName);
876
+ const storeMeta = getStoreMeta(refName);
877
+ return function(target) {
878
+ const customDoKeys = Object.getOwnPropertyNames(target.prototype).filter((key) => key !== "constructor");
879
+ setStoreMeta(refName, { ...storeMeta, doKeys: [...storeMeta.doKeys, ...customDoKeys] });
880
+ };
881
+ };
882
+ var createSelectors = (_store, store = {}) => {
883
+ store.get = _store.getState;
884
+ store.set = (s) => {
885
+ if (typeof s === "function")
886
+ _store.setState((st2) => {
887
+ s(st2);
888
+ });
889
+ else
890
+ _store.setState(s);
891
+ };
892
+ store.sel = (selectFn, equals) => _store(selectFn, equals);
893
+ const state = store.get();
894
+ store.sub = _store.subscribe;
895
+ const useReference = (selectFn) => {
896
+ const ref = (0, import_react.useRef)(selectFn(store.get()));
897
+ (0, import_react.useEffect)(() => {
898
+ return store.sub(selectFn, (val) => ref.current = val);
899
+ }, []);
900
+ return ref;
901
+ };
902
+ store.ref = useReference;
903
+ const existingUse = store.use;
904
+ const existingDo = store.do;
905
+ const existingSlice = store.slice;
906
+ if (!existingUse)
907
+ Object.assign(store, { use: {} });
908
+ if (!existingDo)
909
+ Object.assign(store, { do: {} });
910
+ if (!existingSlice)
911
+ Object.assign(store, { slice: {} });
912
+ for (const k of Object.keys(state)) {
913
+ if (typeof state[k] !== "function") {
914
+ store.use[k] = () => store.sel((s) => s[k]);
915
+ const setKey = `set${(0, import_common.capitalize)(k)}`;
916
+ if (!state[setKey])
917
+ store.do[setKey] = (value) => {
918
+ store.set({ [k]: value });
919
+ };
920
+ } else {
921
+ store.do[k] = async (...args) => {
922
+ try {
923
+ import_common.Logger.verbose(`${k} action loading...`);
924
+ const start = Date.now();
925
+ await state[k](...args);
926
+ const end = Date.now();
927
+ import_common.Logger.verbose(`=> ${k} action dispatched (${end - start}ms)`);
928
+ } catch (e) {
929
+ const errKey = typeof e === "string" ? e : e.message;
930
+ import_dictionary.msg.error(errKey, { key: k });
931
+ throw e;
932
+ }
933
+ };
934
+ }
935
+ }
936
+ const storeNames = getStoreNames();
937
+ for (const storeName of storeNames) {
938
+ const [fieldName, className] = [(0, import_common.lowerlize)(storeName), (0, import_common.capitalize)(storeName)];
939
+ const names = {
940
+ model: fieldName,
941
+ Model: className,
942
+ defaultModel: `default${className}`,
943
+ modelInsight: `${fieldName}Insight`,
944
+ modelList: `${fieldName}List`,
945
+ modelListLoading: `${fieldName}ListLoading`,
946
+ modelInitList: `${fieldName}InitList`,
947
+ modelInitAt: `${fieldName}InitAt`,
948
+ pageOfModel: `pageOf${className}`,
949
+ limitOfModel: `limitOf${className}`,
950
+ queryArgsOfModel: `queryArgsOf${className}`,
951
+ sortOfModel: `sortOf${className}`,
952
+ modelSelection: `${fieldName}Selection`,
953
+ initModel: `init${className}`,
954
+ refreshModel: `refresh${className}`,
955
+ selectModel: `select${className}`,
956
+ setPageOfModel: `setPageOf${className}`,
957
+ addPageOfModel: `addPageOf${className}`,
958
+ setLimitOfModel: `setLimitOf${className}`,
959
+ setQueryArgsOfModel: `setQueryArgsOf${className}`,
960
+ setSortOfModel: `setSortOf${className}`,
961
+ lastPageOfModel: `lastPageOf${className}`
962
+ };
963
+ const storeMeta = getStoreMeta(storeName);
964
+ storeMeta.slices.forEach(({ sliceName, argLength, refName }) => {
965
+ const SliceName = (0, import_common.capitalize)(sliceName);
966
+ const namesOfSliceState = {
1694
967
  defaultModel: SliceName.replace(names.Model, names.defaultModel),
968
+ modelInitList: SliceName.replace(names.Model, names.modelInitList),
1695
969
  modelInsight: sliceName.replace(names.model, names.modelInsight),
1696
970
  modelList: sliceName.replace(names.model, names.modelList),
1697
971
  modelListLoading: sliceName.replace(names.model, names.modelListLoading),
1698
- initModel: SliceName.replace(names.Model, names.initModel),
1699
- modelInitList: SliceName.replace(names.Model, names.modelInitList),
1700
972
  modelInitAt: SliceName.replace(names.Model, names.modelInitAt),
1701
- refreshModel: SliceName.replace(names.Model, names.refreshModel),
1702
- selectModel: SliceName.replace(names.Model, names.selectModel),
1703
- setPageOfModel: SliceName.replace(names.Model, names.setPageOfModel),
1704
- addPageOfModel: SliceName.replace(names.Model, names.addPageOfModel),
1705
- setLimitOfModel: SliceName.replace(names.Model, names.setLimitOfModel),
1706
- setQueryArgsOfModel: SliceName.replace(names.Model, names.setQueryArgsOfModel),
1707
- setSortOfModel: SliceName.replace(names.Model, names.setSortOfModel),
1708
973
  lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
1709
974
  pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
1710
975
  limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
@@ -1712,474 +977,125 @@
1712
977
  sortOfModel: SliceName.replace(names.Model, names.sortOfModel),
1713
978
  modelSelection: SliceName.replace(names.Model, names.modelSelection)
1714
979
  };
1715
- const singleSliceAction = {
1716
- [namesOfSlice.initModel]: async function(...args) {
1717
- const initArgLength = Math.min(args.length, argLength);
1718
- const initForm = { invalidate: false, ...args[argLength] ?? {} };
1719
- const queryArgs = new Array(initArgLength).fill(null).map((_, i) => args[i]);
1720
- const defaultModel = immerify(modelRef, { ...gql[names.defaultModel], ...initForm.default ?? {} });
1721
- this.set({ [names.defaultModel]: defaultModel });
1722
- await this[namesOfSlice.refreshModel](
1723
- ...initArgLength === argLength ? [...queryArgs, initForm] : queryArgs
1724
- );
1725
- },
1726
- [namesOfSlice.refreshModel]: async function(...args) {
1727
- const refreshArgLength = Math.min(args.length, argLength);
1728
- const currentState = this.get();
1729
- const existingQueryArgs = currentState[namesOfSlice.queryArgsOfModel];
1730
- const queryArgs = [
1731
- ...new Array(refreshArgLength).fill(null).map((_, i) => args[i]),
1732
- ...existingQueryArgs.slice(refreshArgLength, argLength)
1733
- ];
1734
- const initForm = args[argLength] ?? {};
1735
- const {
1736
- page = currentState[namesOfSlice.pageOfModel],
1737
- limit = currentState[namesOfSlice.limitOfModel],
1738
- sort = currentState[namesOfSlice.sortOfModel],
1739
- invalidate = true
1740
- } = initForm;
1741
- const modelOperation = currentState[names.modelOperation];
1742
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
1743
- const pageOfModel = currentState[namesOfSlice.pageOfModel];
1744
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
1745
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
1746
- if (!invalidate && !["sleep", "reset"].includes(modelOperation) && isQueryEqual(queryArgs, queryArgsOfModel) && page === pageOfModel && limit === limitOfModel && isQueryEqual(sort, sortOfModel))
1747
- return;
1748
- else
1749
- this.set({ [namesOfSlice.modelListLoading]: true });
1750
- const [modelDataList, modelInsight] = await Promise.all([
1751
- gql[namesOfSlice.modelList](
1752
- ...queryArgs,
1753
- (page - 1) * limit,
1754
- limit,
1755
- sort,
1756
- { onError: initForm.onError }
1757
- ),
1758
- gql[namesOfSlice.modelInsight](...queryArgs, {
1759
- onError: initForm.onError
1760
- })
1761
- ]);
1762
- const modelList = new DataList(modelDataList);
1763
- this.set({
1764
- [namesOfSlice.modelList]: modelList,
1765
- [namesOfSlice.modelListLoading]: false,
1766
- [namesOfSlice.modelInsight]: modelInsight,
1767
- [namesOfSlice.modelInitList]: modelList,
1768
- [namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(),
1769
- [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limit) + 1, 1),
1770
- [namesOfSlice.limitOfModel]: limit,
1771
- [namesOfSlice.queryArgsOfModel]: queryArgs,
1772
- [namesOfSlice.sortOfModel]: sort,
1773
- [namesOfSlice.pageOfModel]: page,
1774
- [names.modelOperation]: "idle"
1775
- });
1776
- },
1777
- [namesOfSlice.selectModel]: function(model, { refresh, remove } = {}) {
1778
- const models = Array.isArray(model) ? model : [model];
1779
- const currentState = this.get();
1780
- const modelSelection = currentState[namesOfSlice.modelSelection];
1781
- if (refresh)
1782
- this.set({ [namesOfSlice.modelSelection]: new DataList(models) });
1783
- else if (remove) {
1784
- const newModelSelection = new DataList(modelSelection);
1785
- models.map((model2) => newModelSelection.delete(model2.id));
1786
- this.set({ [namesOfSlice.modelSelection]: newModelSelection });
1787
- } else {
1788
- this.set({ [namesOfSlice.modelSelection]: new DataList([...modelSelection.values, ...models]) });
1789
- }
1790
- },
1791
- [namesOfSlice.setPageOfModel]: async function(page, options) {
1792
- const currentState = this.get();
1793
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
1794
- const pageOfModel = currentState[namesOfSlice.pageOfModel];
1795
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
1796
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
1797
- if (pageOfModel === page)
1798
- return;
1799
- this.set({ [namesOfSlice.modelListLoading]: true });
1800
- const modelDataList = await gql[namesOfSlice.modelList](
1801
- ...queryArgsOfModel,
1802
- (page - 1) * limitOfModel,
1803
- limitOfModel,
1804
- sortOfModel,
1805
- options
1806
- );
1807
- const modelList = new DataList(modelDataList);
1808
- this.set({
1809
- [namesOfSlice.modelList]: modelList,
1810
- [namesOfSlice.pageOfModel]: page,
1811
- [namesOfSlice.modelListLoading]: false
1812
- });
1813
- },
1814
- [namesOfSlice.addPageOfModel]: async function(page, options) {
1815
- const currentState = this.get();
1816
- const modelList = currentState[namesOfSlice.modelList];
1817
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
1818
- const pageOfModel = currentState[namesOfSlice.pageOfModel];
1819
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
1820
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
1821
- if (pageOfModel === page)
1822
- return;
1823
- const addFront = page < pageOfModel;
1824
- const modelDataList = await gql[namesOfSlice.modelList](
1825
- ...queryArgsOfModel,
1826
- (page - 1) * limitOfModel,
1827
- limitOfModel,
1828
- sortOfModel,
1829
- options
1830
- );
1831
- const newModelList = new DataList(
1832
- addFront ? [...modelDataList, ...modelList] : [...modelList, ...modelDataList]
1833
- );
1834
- this.set({ [namesOfSlice.modelList]: newModelList, [namesOfSlice.pageOfModel]: page });
1835
- },
1836
- [namesOfSlice.setLimitOfModel]: async function(limit, options) {
1837
- const currentState = this.get();
1838
- const modelInsight = currentState[namesOfSlice.modelInsight];
1839
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
1840
- const pageOfModel = currentState[namesOfSlice.pageOfModel];
1841
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
1842
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
1843
- if (limitOfModel === limit)
1844
- return;
1845
- const skip = (pageOfModel - 1) * limitOfModel;
1846
- const page = Math.max(Math.floor((skip - 1) / limit) + 1, 1);
1847
- const modelDataList = await gql[namesOfSlice.modelList](
1848
- ...queryArgsOfModel,
1849
- (page - 1) * limit,
1850
- limit,
1851
- sortOfModel,
1852
- options
1853
- );
1854
- const modelList = new DataList(modelDataList);
1855
- this.set({
1856
- [namesOfSlice.modelList]: modelList,
1857
- [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limit) + 1, 1),
1858
- [namesOfSlice.limitOfModel]: limit,
1859
- [namesOfSlice.pageOfModel]: page
1860
- });
1861
- },
1862
- [namesOfSlice.setQueryArgsOfModel]: async function(...args) {
1863
- const queryArgs = new Array(argLength).fill(null).map((_, i) => args[i]);
1864
- const options = args[argLength];
1865
- const currentState = this.get();
1866
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
1867
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
1868
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
1869
- if (isQueryEqual(queryArgsOfModel, queryArgs)) {
1870
- Logger.trace(`${namesOfSlice.queryArgsOfModel} store-level cache hit`);
1871
- return;
1872
- }
1873
- this.set({ [namesOfSlice.modelListLoading]: true });
1874
- const [modelDataList, modelInsight] = await Promise.all([
1875
- gql[namesOfSlice.modelList](
1876
- ...queryArgs,
1877
- 0,
1878
- limitOfModel,
1879
- sortOfModel,
1880
- options
1881
- ),
1882
- gql[namesOfSlice.modelInsight](...queryArgs, options)
1883
- ]);
1884
- const modelList = new DataList(modelDataList);
1885
- this.set({
1886
- [namesOfSlice.queryArgsOfModel]: queryArgs,
1887
- [namesOfSlice.modelList]: modelList,
1888
- [namesOfSlice.modelInsight]: modelInsight,
1889
- [namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limitOfModel) + 1, 1),
1890
- [namesOfSlice.pageOfModel]: 1,
1891
- [namesOfSlice.modelSelection]: /* @__PURE__ */ new Map(),
1892
- [namesOfSlice.modelListLoading]: false
1893
- });
1894
- },
1895
- [namesOfSlice.setSortOfModel]: async function(sort, options) {
1896
- const currentState = this.get();
1897
- const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
1898
- const limitOfModel = currentState[namesOfSlice.limitOfModel];
1899
- const sortOfModel = currentState[namesOfSlice.sortOfModel];
1900
- if (sortOfModel === sort)
1901
- return;
1902
- this.set({ [namesOfSlice.modelListLoading]: true });
1903
- const modelDataList = await gql[namesOfSlice.modelList](
1904
- ...queryArgsOfModel,
1905
- 0,
1906
- limitOfModel,
1907
- sort,
1908
- options
1909
- );
1910
- const modelList = new DataList(modelDataList);
1911
- this.set({
1912
- [namesOfSlice.modelList]: modelList,
1913
- [namesOfSlice.sortOfModel]: sort,
1914
- [namesOfSlice.pageOfModel]: 1,
1915
- [namesOfSlice.modelListLoading]: false
1916
- });
1917
- }
980
+ const namesOfSliceAction = {
981
+ initModel: SliceName.replace(names.Model, names.initModel),
982
+ refreshModel: SliceName.replace(names.Model, names.refreshModel),
983
+ selectModel: SliceName.replace(names.Model, names.selectModel),
984
+ setPageOfModel: SliceName.replace(names.Model, names.setPageOfModel),
985
+ addPageOfModel: SliceName.replace(names.Model, names.addPageOfModel),
986
+ setLimitOfModel: SliceName.replace(names.Model, names.setLimitOfModel),
987
+ setQueryArgsOfModel: SliceName.replace(names.Model, names.setQueryArgsOfModel),
988
+ setSortOfModel: SliceName.replace(names.Model, names.setSortOfModel)
1918
989
  };
1919
- return Object.assign(acc, singleSliceAction);
1920
- }, {});
1921
- return { ...baseAction, ...sliceAction };
1922
- };
1923
- var stateOf = (gql, state) => {
1924
- const applyState = Object.assign(createState(gql), state);
1925
- const applyAction = createActions(gql);
1926
- setStoreMeta(gql.refName, {
1927
- refName: gql.refName,
1928
- useKeys: Object.keys(applyState),
1929
- doKeys: Object.keys(applyAction),
1930
- slices: gql.slices
990
+ store.slice[sliceName] = { do: {}, use: {} };
991
+ const targetSlice = store.slice[sliceName];
992
+ Object.keys(namesOfSliceAction).forEach((key) => {
993
+ targetSlice.do[names[key]] = store.do[namesOfSliceAction[key]];
994
+ });
995
+ Object.keys(namesOfSliceState).map((key) => {
996
+ targetSlice.use[names[key]] = store.use[namesOfSliceState[key]];
997
+ targetSlice.do[`set${(0, import_common.capitalize)(names[key])}`] = store.do[`set${(0, import_common.capitalize)(namesOfSliceState[key])}`];
998
+ });
999
+ targetSlice.sliceName = sliceName;
1000
+ targetSlice.refName = refName;
1001
+ targetSlice.argLength = argLength;
1931
1002
  });
1932
- const applyStore = { ...applyState, ...applyAction };
1933
- class StateStore {
1934
- get;
1935
- set;
1936
- pick;
1937
- }
1938
- Object.keys(applyStore).forEach(
1939
- (key) => Object.defineProperty(StateStore.prototype, key, { value: applyStore[key] })
1940
- );
1941
- return StateStore;
1942
- };
1943
- var scalarStateOf = (refName, state) => {
1944
- const applyState = state;
1945
- setStoreMeta(refName, { refName, useKeys: Object.keys(applyState), doKeys: [], slices: [] });
1946
- class StateStore {
1947
- get;
1948
- set;
1949
- pick;
1950
- }
1951
- Object.keys(applyState).forEach(
1952
- (key) => Object.defineProperty(StateStore.prototype, key, { value: applyState[key] })
1953
- );
1954
- return StateStore;
1955
- };
1956
- var Store = (returnsOrObj) => {
1957
- const refName = typeof returnsOrObj === "object" ? returnsOrObj.name : lowerlize(getClassMeta(returnsOrObj()).refName);
1958
- const storeMeta = getStoreMeta(refName);
1959
- return function(target) {
1960
- const customDoKeys = Object.getOwnPropertyNames(target.prototype).filter((key) => key !== "constructor");
1961
- setStoreMeta(refName, { ...storeMeta, doKeys: [...storeMeta.doKeys, ...customDoKeys] });
1962
- };
1963
- };
1964
- var createSelectors = (_store, store = {}) => {
1965
- store.get = _store.getState;
1966
- store.set = (s) => {
1967
- if (typeof s === "function")
1968
- _store.setState((st2) => {
1969
- s(st2);
1970
- });
1971
- else
1972
- _store.setState(s);
1973
- };
1974
- store.sel = (selectFn, equals) => _store(selectFn, equals);
1975
- const state = store.get();
1976
- store.sub = _store.subscribe;
1977
- const useReference = (selectFn) => {
1978
- const ref = (0, import_react.useRef)(selectFn(store.get()));
1979
- (0, import_react.useEffect)(() => {
1980
- return store.sub(selectFn, (val) => ref.current = val);
1981
- }, []);
1982
- return ref;
1983
- };
1984
- store.ref = useReference;
1985
- const existingUse = store.use;
1986
- const existingDo = store.do;
1987
- const existingSlice = store.slice;
1988
- if (!existingUse)
1989
- Object.assign(store, { use: {} });
1990
- if (!existingDo)
1991
- Object.assign(store, { do: {} });
1992
- if (!existingSlice)
1993
- Object.assign(store, { slice: {} });
1994
- for (const k of Object.keys(state)) {
1995
- if (typeof state[k] !== "function") {
1996
- store.use[k] = () => store.sel((s) => s[k]);
1997
- const setKey = `set${capitalize(k)}`;
1998
- if (!state[setKey])
1999
- store.do[setKey] = (value) => {
2000
- store.set({ [k]: value });
2001
- };
2002
- } else {
2003
- store.do[k] = async (...args) => {
2004
- try {
2005
- Logger.verbose(`${k} action loading...`);
2006
- const start = Date.now();
2007
- await state[k](...args);
2008
- const end = Date.now();
2009
- Logger.verbose(`=> ${k} action dispatched (${end - start}ms)`);
2010
- } catch (e) {
2011
- const errKey = typeof e === "string" ? e : e.message;
2012
- msg.error(errKey, { key: k });
2013
- throw e;
2014
- }
2015
- };
1003
+ }
1004
+ return store;
1005
+ };
1006
+ var makePicker = (set, get) => (...fields) => {
1007
+ const state = get();
1008
+ const ret = {};
1009
+ for (const field of fields) {
1010
+ const val = state[field];
1011
+ if (!val)
1012
+ throw new Error(`Field ${field} is not ready`);
1013
+ if (typeof val === "string" && val.length === 0)
1014
+ throw new Error(`Field is empty string (${field})`);
1015
+ else if (["self", "me"].includes(field) && !state[field].id?.length)
1016
+ throw new Error("Self or Me Id is not defined");
1017
+ ret[field] = val;
1018
+ }
1019
+ return ret;
1020
+ };
1021
+ var makeStore = (st2, storeRef, { library } = {}) => {
1022
+ if (library)
1023
+ return st2;
1024
+ const zustandStore = (0, import_zustand.create)(
1025
+ (0, import_middleware.devtools)(
1026
+ (0, import_middleware.subscribeWithSelector)(
1027
+ (0, import_immer.immer)((set, get) => {
1028
+ const store = {};
1029
+ const pick = makePicker(set, get);
1030
+ Object.getOwnPropertyNames(storeRef.prototype).forEach((key) => {
1031
+ const descriptor = Object.getOwnPropertyDescriptor(storeRef.prototype, key);
1032
+ if (descriptor)
1033
+ store[key] = descriptor.value;
1034
+ });
1035
+ Object.assign(store, { set, get, pick });
1036
+ return store;
1037
+ })
1038
+ ),
1039
+ { name: "root", anonymousActionType: "root", type: "root" }
1040
+ )
1041
+ );
1042
+ return createSelectors(zustandStore, st2);
1043
+ };
1044
+ var 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) => {
1045
+ const stores = [
1046
+ s1,
1047
+ s2,
1048
+ s3,
1049
+ s4,
1050
+ s5,
1051
+ s6,
1052
+ s7,
1053
+ s8,
1054
+ s9,
1055
+ s10,
1056
+ s11,
1057
+ s12,
1058
+ s13,
1059
+ s14,
1060
+ s15,
1061
+ s16,
1062
+ s17,
1063
+ s18,
1064
+ s19,
1065
+ s20,
1066
+ s21,
1067
+ s22,
1068
+ s23,
1069
+ s24,
1070
+ s25,
1071
+ s26,
1072
+ s27,
1073
+ s28,
1074
+ s29,
1075
+ s30
1076
+ ].filter((s) => !!s);
1077
+ class Mix {
1078
+ }
1079
+ (0, import_common.applyMixins)(Mix, stores);
1080
+ return Mix;
1081
+ };
1082
+ var rootStoreOf = (store) => {
1083
+ return Object.getPrototypeOf(store);
1084
+ };
1085
+ var Toast = ({ root, duration = 3 } = {}) => {
1086
+ return function(target, key, descriptor) {
1087
+ const originMethod = descriptor.value;
1088
+ descriptor.value = async function(...args) {
1089
+ try {
1090
+ import_dictionary.msg.loading(`${root ? `${root}.` : ""}${key}-loading`, { key, duration });
1091
+ const result = await originMethod.apply(this, args);
1092
+ import_dictionary.msg.success(`${root ? `${root}.` : ""}${key}-success`, { key, duration });
1093
+ return result;
1094
+ } catch (err) {
1095
+ const errKey = typeof err === "string" ? err : err.message;
1096
+ import_dictionary.msg.error(errKey, { key, duration });
1097
+ import_common.Logger.error(`${key} action error return: ${err}`);
2016
1098
  }
2017
- }
2018
- const storeNames = getStoreNames();
2019
- for (const storeName of storeNames) {
2020
- const [fieldName, className] = [lowerlize(storeName), capitalize(storeName)];
2021
- const names = {
2022
- model: fieldName,
2023
- Model: className,
2024
- defaultModel: `default${className}`,
2025
- modelInsight: `${fieldName}Insight`,
2026
- modelList: `${fieldName}List`,
2027
- modelListLoading: `${fieldName}ListLoading`,
2028
- modelInitList: `${fieldName}InitList`,
2029
- modelInitAt: `${fieldName}InitAt`,
2030
- pageOfModel: `pageOf${className}`,
2031
- limitOfModel: `limitOf${className}`,
2032
- queryArgsOfModel: `queryArgsOf${className}`,
2033
- sortOfModel: `sortOf${className}`,
2034
- modelSelection: `${fieldName}Selection`,
2035
- initModel: `init${className}`,
2036
- refreshModel: `refresh${className}`,
2037
- selectModel: `select${className}`,
2038
- setPageOfModel: `setPageOf${className}`,
2039
- addPageOfModel: `addPageOf${className}`,
2040
- setLimitOfModel: `setLimitOf${className}`,
2041
- setQueryArgsOfModel: `setQueryArgsOf${className}`,
2042
- setSortOfModel: `setSortOf${className}`,
2043
- lastPageOfModel: `lastPageOf${className}`
2044
- };
2045
- const storeMeta = getStoreMeta(storeName);
2046
- storeMeta.slices.forEach(({ sliceName, argLength, refName }) => {
2047
- const SliceName = capitalize(sliceName);
2048
- const namesOfSliceState = {
2049
- defaultModel: SliceName.replace(names.Model, names.defaultModel),
2050
- modelInitList: SliceName.replace(names.Model, names.modelInitList),
2051
- modelInsight: sliceName.replace(names.model, names.modelInsight),
2052
- modelList: sliceName.replace(names.model, names.modelList),
2053
- modelListLoading: sliceName.replace(names.model, names.modelListLoading),
2054
- modelInitAt: SliceName.replace(names.Model, names.modelInitAt),
2055
- lastPageOfModel: SliceName.replace(names.Model, names.lastPageOfModel),
2056
- pageOfModel: SliceName.replace(names.Model, names.pageOfModel),
2057
- limitOfModel: SliceName.replace(names.Model, names.limitOfModel),
2058
- queryArgsOfModel: SliceName.replace(names.Model, names.queryArgsOfModel),
2059
- sortOfModel: SliceName.replace(names.Model, names.sortOfModel),
2060
- modelSelection: SliceName.replace(names.Model, names.modelSelection)
2061
- };
2062
- const namesOfSliceAction = {
2063
- initModel: SliceName.replace(names.Model, names.initModel),
2064
- refreshModel: SliceName.replace(names.Model, names.refreshModel),
2065
- selectModel: SliceName.replace(names.Model, names.selectModel),
2066
- setPageOfModel: SliceName.replace(names.Model, names.setPageOfModel),
2067
- addPageOfModel: SliceName.replace(names.Model, names.addPageOfModel),
2068
- setLimitOfModel: SliceName.replace(names.Model, names.setLimitOfModel),
2069
- setQueryArgsOfModel: SliceName.replace(names.Model, names.setQueryArgsOfModel),
2070
- setSortOfModel: SliceName.replace(names.Model, names.setSortOfModel)
2071
- };
2072
- store.slice[sliceName] = { do: {}, use: {} };
2073
- const targetSlice = store.slice[sliceName];
2074
- Object.keys(namesOfSliceAction).forEach((key) => {
2075
- targetSlice.do[names[key]] = store.do[namesOfSliceAction[key]];
2076
- });
2077
- Object.keys(namesOfSliceState).map((key) => {
2078
- targetSlice.use[names[key]] = store.use[namesOfSliceState[key]];
2079
- targetSlice.do[`set${capitalize(names[key])}`] = store.do[`set${capitalize(namesOfSliceState[key])}`];
2080
- });
2081
- targetSlice.sliceName = sliceName;
2082
- targetSlice.refName = refName;
2083
- targetSlice.argLength = argLength;
2084
- });
2085
- }
2086
- return store;
2087
- };
2088
- var makePicker = (set, get) => (...fields) => {
2089
- const state = get();
2090
- const ret = {};
2091
- for (const field of fields) {
2092
- const val = state[field];
2093
- if (!val)
2094
- throw new Error(`Field ${field} is not ready`);
2095
- if (typeof val === "string" && val.length === 0)
2096
- throw new Error(`Field is empty string (${field})`);
2097
- else if (["self", "me"].includes(field) && !state[field].id?.length)
2098
- throw new Error("Self or Me Id is not defined");
2099
- ret[field] = val;
2100
- }
2101
- return ret;
2102
- };
2103
- var makeStore = (st2, storeRef, { library } = {}) => {
2104
- if (library)
2105
- return st2;
2106
- const zustandStore = (0, import_zustand.create)(
2107
- (0, import_middleware.devtools)(
2108
- (0, import_middleware.subscribeWithSelector)(
2109
- (0, import_immer2.immer)((set, get) => {
2110
- const store = {};
2111
- const pick = makePicker(set, get);
2112
- Object.getOwnPropertyNames(storeRef.prototype).forEach((key) => {
2113
- const descriptor = Object.getOwnPropertyDescriptor(storeRef.prototype, key);
2114
- if (descriptor)
2115
- store[key] = descriptor.value;
2116
- });
2117
- Object.assign(store, { set, get, pick });
2118
- return store;
2119
- })
2120
- ),
2121
- { name: "root", anonymousActionType: "root", type: "root" }
2122
- )
2123
- );
2124
- return createSelectors(zustandStore, st2);
2125
- };
2126
- var 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) => {
2127
- const stores = [
2128
- s1,
2129
- s2,
2130
- s3,
2131
- s4,
2132
- s5,
2133
- s6,
2134
- s7,
2135
- s8,
2136
- s9,
2137
- s10,
2138
- s11,
2139
- s12,
2140
- s13,
2141
- s14,
2142
- s15,
2143
- s16,
2144
- s17,
2145
- s18,
2146
- s19,
2147
- s20,
2148
- s21,
2149
- s22,
2150
- s23,
2151
- s24,
2152
- s25,
2153
- s26,
2154
- s27,
2155
- s28,
2156
- s29,
2157
- s30
2158
- ].filter((s) => !!s);
2159
- class Mix {
2160
- }
2161
- applyMixins(Mix, stores);
2162
- return Mix;
2163
- };
2164
- var rootStoreOf = (store) => {
2165
- return Object.getPrototypeOf(store);
2166
- };
2167
- var Toast = ({ root, duration = 3 } = {}) => {
2168
- return function(target, key, descriptor) {
2169
- const originMethod = descriptor.value;
2170
- descriptor.value = async function(...args) {
2171
- try {
2172
- msg.loading(`${root ? `${root}.` : ""}${key}-loading`, { key, duration });
2173
- const result = await originMethod.apply(this, args);
2174
- msg.success(`${root ? `${root}.` : ""}${key}-success`, { key, duration });
2175
- return result;
2176
- } catch (err) {
2177
- const errKey = typeof err === "string" ? err : err.message;
2178
- msg.error(errKey, { key, duration });
2179
- Logger.error(`${key} action error return: ${err}`);
2180
- }
2181
- };
2182
1099
  };
2183
1100
  };
2184
- })();
2185
- //! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
1101
+ };