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