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