@akanjs/signal 0.0.44 → 0.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1535 -2183
- package/package.json +1 -3
package/index.js
CHANGED
|
@@ -1,2052 +1,1370 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
));
|
|
31
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
32
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
33
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
34
|
-
if (decorator = decorators[i])
|
|
35
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
36
|
-
if (kind && result)
|
|
37
|
-
__defProp(target, key, result);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
41
|
-
|
|
42
|
-
// pkgs/@akanjs/base/src/base.ts
|
|
43
|
-
var Enum = class {
|
|
44
|
-
constructor(values) {
|
|
45
|
-
this.values = values;
|
|
46
|
-
this.valueMap = new Map(values.map((value, idx) => [value, idx]));
|
|
47
|
-
}
|
|
48
|
-
value;
|
|
49
|
-
// for type
|
|
50
|
-
valueMap;
|
|
51
|
-
has(value) {
|
|
52
|
-
return this.valueMap.has(value);
|
|
53
|
-
}
|
|
54
|
-
indexOf(value) {
|
|
55
|
-
const idx = this.valueMap.get(value);
|
|
56
|
-
if (idx === void 0)
|
|
57
|
-
throw new Error(`Value ${value} is not in enum`);
|
|
58
|
-
return idx;
|
|
59
|
-
}
|
|
60
|
-
find(callback) {
|
|
61
|
-
const val = this.values.find(callback);
|
|
62
|
-
if (val === void 0)
|
|
63
|
-
throw new Error(`Value not found in enum`);
|
|
64
|
-
return val;
|
|
65
|
-
}
|
|
66
|
-
findIndex(callback) {
|
|
67
|
-
const idx = this.values.findIndex(callback);
|
|
68
|
-
if (idx === -1)
|
|
69
|
-
throw new Error(`Value not found in enum`);
|
|
70
|
-
return idx;
|
|
71
|
-
}
|
|
72
|
-
filter(callback) {
|
|
73
|
-
return this.values.filter(callback);
|
|
74
|
-
}
|
|
75
|
-
map(callback) {
|
|
76
|
-
return this.values.map(callback);
|
|
77
|
-
}
|
|
78
|
-
forEach(callback) {
|
|
79
|
-
this.values.forEach(callback);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
var DataList = class _DataList {
|
|
83
|
-
// [immerable] = true;
|
|
84
|
-
#idMap;
|
|
85
|
-
length;
|
|
86
|
-
values;
|
|
87
|
-
constructor(data = []) {
|
|
88
|
-
this.values = Array.isArray(data) ? [...data] : [...data.values];
|
|
89
|
-
this.#idMap = new Map(this.values.map((value, idx) => [value.id, idx]));
|
|
90
|
-
this.length = this.values.length;
|
|
91
|
-
}
|
|
92
|
-
indexOf(id) {
|
|
93
|
-
const idx = this.#idMap.get(id);
|
|
94
|
-
if (idx === void 0)
|
|
95
|
-
throw new Error(`Value ${id} is not in list`);
|
|
96
|
-
return idx;
|
|
97
|
-
}
|
|
98
|
-
set(value) {
|
|
99
|
-
const idx = this.#idMap.get(value.id);
|
|
100
|
-
if (idx !== void 0)
|
|
101
|
-
this.values = [...this.values.slice(0, idx), value, ...this.values.slice(idx + 1)];
|
|
102
|
-
else {
|
|
103
|
-
this.#idMap.set(value.id, this.length);
|
|
104
|
-
this.values = [...this.values, value];
|
|
105
|
-
this.length++;
|
|
106
|
-
}
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
delete(id) {
|
|
110
|
-
const idx = this.#idMap.get(id);
|
|
111
|
-
if (idx === void 0)
|
|
112
|
-
return this;
|
|
113
|
-
this.#idMap.delete(id);
|
|
114
|
-
this.values.splice(idx, 1);
|
|
115
|
-
this.values.slice(idx).forEach((value, i) => this.#idMap.set(value.id, i + idx));
|
|
116
|
-
this.length--;
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
get(id) {
|
|
120
|
-
const idx = this.#idMap.get(id);
|
|
121
|
-
if (idx === void 0)
|
|
122
|
-
return void 0;
|
|
123
|
-
return this.values[idx];
|
|
124
|
-
}
|
|
125
|
-
at(idx) {
|
|
126
|
-
return this.values.at(idx);
|
|
127
|
-
}
|
|
128
|
-
pickAt(idx) {
|
|
129
|
-
const value = this.values.at(idx);
|
|
130
|
-
if (value === void 0)
|
|
131
|
-
throw new Error(`Value at ${idx} is undefined`);
|
|
132
|
-
return value;
|
|
133
|
-
}
|
|
134
|
-
pick(id) {
|
|
135
|
-
return this.values[this.indexOf(id)];
|
|
136
|
-
}
|
|
137
|
-
has(id) {
|
|
138
|
-
return this.#idMap.has(id);
|
|
139
|
-
}
|
|
140
|
-
find(fn) {
|
|
141
|
-
const val = this.values.find(fn);
|
|
142
|
-
return val;
|
|
143
|
-
}
|
|
144
|
-
findIndex(fn) {
|
|
145
|
-
const val = this.values.findIndex(fn);
|
|
146
|
-
return val;
|
|
147
|
-
}
|
|
148
|
-
some(fn) {
|
|
149
|
-
return this.values.some(fn);
|
|
150
|
-
}
|
|
151
|
-
every(fn) {
|
|
152
|
-
return this.values.every(fn);
|
|
153
|
-
}
|
|
154
|
-
forEach(fn) {
|
|
155
|
-
this.values.forEach(fn);
|
|
156
|
-
}
|
|
157
|
-
map(fn) {
|
|
158
|
-
return this.values.map(fn);
|
|
159
|
-
}
|
|
160
|
-
flatMap(fn) {
|
|
161
|
-
return this.values.flatMap(fn);
|
|
162
|
-
}
|
|
163
|
-
sort(fn) {
|
|
164
|
-
return new _DataList(this.values.sort(fn));
|
|
165
|
-
}
|
|
166
|
-
filter(fn) {
|
|
167
|
-
return new _DataList(this.values.filter(fn));
|
|
168
|
-
}
|
|
169
|
-
reduce(fn, initialValue) {
|
|
170
|
-
return this.values.reduce(fn, initialValue);
|
|
171
|
-
}
|
|
172
|
-
slice(start, end = this.length) {
|
|
173
|
-
return new _DataList(this.values.slice(start, end));
|
|
174
|
-
}
|
|
175
|
-
save() {
|
|
176
|
-
return new _DataList(this);
|
|
177
|
-
}
|
|
178
|
-
[Symbol.iterator]() {
|
|
179
|
-
return this.values[Symbol.iterator]();
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
var version = "0.9.0";
|
|
183
|
-
var logo = `
|
|
184
|
-
_ _ _
|
|
185
|
-
/ \\ | | ____ _ _ __ (_)___
|
|
186
|
-
/ _ \\ | |/ / _' | '_ \\ | / __|
|
|
187
|
-
/ ___ \\| < (_| | | | |_ | \\__ \\
|
|
188
|
-
/_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
|
|
189
|
-
|__/ ver ${version}
|
|
190
|
-
? See more details on docs https://www.akanjs.com/docs
|
|
191
|
-
\u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
|
|
192
|
-
|
|
193
|
-
`;
|
|
194
|
-
|
|
195
|
-
// pkgs/@akanjs/base/src/baseEnv.ts
|
|
196
|
-
var appName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
|
|
197
|
-
var repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
|
|
198
|
-
var serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
|
|
199
|
-
if (appName === "unknown")
|
|
200
|
-
throw new Error("environment variable NEXT_PUBLIC_APP_NAME is required");
|
|
201
|
-
if (repoName === "unknown")
|
|
202
|
-
throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
|
|
203
|
-
if (serveDomain === "unknown")
|
|
204
|
-
throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
|
|
205
|
-
var environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
206
|
-
var operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
|
|
207
|
-
var operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
|
|
208
|
-
var networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
|
|
209
|
-
var tunnelUsername = process.env.SSU_TUNNEL_USERNAME ?? "root";
|
|
210
|
-
var tunnelPassword = process.env.SSU_TUNNEL_PASSWORD ?? repoName;
|
|
211
|
-
var baseEnv = {
|
|
212
|
-
repoName,
|
|
213
|
-
serveDomain,
|
|
214
|
-
appName,
|
|
215
|
-
environment,
|
|
216
|
-
operationType,
|
|
217
|
-
operationMode,
|
|
218
|
-
networkType,
|
|
219
|
-
tunnelUsername,
|
|
220
|
-
tunnelPassword
|
|
221
|
-
};
|
|
222
|
-
var side = typeof window === "undefined" ? "server" : "client";
|
|
223
|
-
var renderMode = process.env.RENDER_ENV ?? "ssr";
|
|
224
|
-
var clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
|
|
225
|
-
var clientPort = parseInt(
|
|
226
|
-
process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
|
|
227
|
-
);
|
|
228
|
-
var clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
|
|
229
|
-
var clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
|
|
230
|
-
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");
|
|
231
|
-
var serverPort = parseInt(
|
|
232
|
-
process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
|
|
233
|
-
);
|
|
234
|
-
var serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
|
|
235
|
-
var serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
|
|
236
|
-
var serverGraphqlUri = `${serverHttpUri}/graphql`;
|
|
237
|
-
var serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
|
|
238
|
-
var serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
|
|
239
|
-
var baseClientEnv = {
|
|
240
|
-
...baseEnv,
|
|
241
|
-
side,
|
|
242
|
-
renderMode,
|
|
243
|
-
websocket: true,
|
|
244
|
-
clientHost,
|
|
245
|
-
clientPort,
|
|
246
|
-
clientHttpProtocol,
|
|
247
|
-
clientHttpUri,
|
|
248
|
-
serverHost,
|
|
249
|
-
serverPort,
|
|
250
|
-
serverHttpProtocol,
|
|
251
|
-
serverHttpUri,
|
|
252
|
-
serverGraphqlUri,
|
|
253
|
-
serverWsProtocol,
|
|
254
|
-
serverWsUri
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
// pkgs/@akanjs/base/src/scalar.ts
|
|
258
|
-
var import_dayjs = __toESM(__require("dayjs"));
|
|
259
|
-
var dayjs = import_dayjs.default;
|
|
260
|
-
var Int = class {
|
|
261
|
-
__Scalar__;
|
|
262
|
-
};
|
|
263
|
-
var Upload = class {
|
|
264
|
-
__Scalar__;
|
|
265
|
-
filename;
|
|
266
|
-
mimetype;
|
|
267
|
-
encoding;
|
|
268
|
-
createReadStream;
|
|
269
|
-
};
|
|
270
|
-
var Float = class {
|
|
271
|
-
__Scalar__;
|
|
272
|
-
};
|
|
273
|
-
var ID = class {
|
|
274
|
-
__Scalar__;
|
|
275
|
-
};
|
|
276
|
-
var JSON2 = class {
|
|
277
|
-
__Scalar__;
|
|
278
|
-
};
|
|
279
|
-
var getNonArrayModel = (arraiedModel2) => {
|
|
280
|
-
let arrDepth = 0;
|
|
281
|
-
let target = arraiedModel2;
|
|
282
|
-
while (Array.isArray(target)) {
|
|
283
|
-
target = target[0];
|
|
284
|
-
arrDepth++;
|
|
285
|
-
}
|
|
286
|
-
return [target, arrDepth];
|
|
287
|
-
};
|
|
288
|
-
var arraiedModel = (modelRef, arrDepth = 0) => {
|
|
289
|
-
let target = modelRef;
|
|
290
|
-
for (let i = 0; i < arrDepth; i++)
|
|
291
|
-
target = [target];
|
|
292
|
-
return target;
|
|
293
|
-
};
|
|
294
|
-
var applyFnToArrayObjects = (arraiedData, fn) => {
|
|
295
|
-
if (Array.isArray(arraiedData))
|
|
296
|
-
return arraiedData.map((data) => applyFnToArrayObjects(data, fn));
|
|
297
|
-
return fn(arraiedData);
|
|
298
|
-
};
|
|
299
|
-
var scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON2, Map]);
|
|
300
|
-
var scalarNameMap = /* @__PURE__ */ new Map([
|
|
301
|
-
[ID, "ID"],
|
|
302
|
-
[Int, "Int"],
|
|
303
|
-
[Float, "Float"],
|
|
304
|
-
[String, "String"],
|
|
305
|
-
[Boolean, "Boolean"],
|
|
306
|
-
[Date, "Date"],
|
|
307
|
-
[Upload, "Upload"],
|
|
308
|
-
[JSON2, "JSON"],
|
|
309
|
-
[Map, "Map"]
|
|
310
|
-
]);
|
|
311
|
-
var scalarArgMap = /* @__PURE__ */ new Map([
|
|
312
|
-
[ID, null],
|
|
313
|
-
[String, ""],
|
|
314
|
-
[Boolean, false],
|
|
315
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
316
|
-
[Int, 0],
|
|
317
|
-
[Float, 0],
|
|
318
|
-
[JSON2, {}],
|
|
319
|
-
[Map, {}]
|
|
320
|
-
]);
|
|
321
|
-
var scalarDefaultMap = /* @__PURE__ */ new Map([
|
|
322
|
-
[ID, null],
|
|
323
|
-
[String, ""],
|
|
324
|
-
[Boolean, false],
|
|
325
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
326
|
-
[Int, 0],
|
|
327
|
-
[Float, 0],
|
|
328
|
-
[JSON2, {}]
|
|
329
|
-
]);
|
|
330
|
-
var isGqlScalar = (modelRef) => scalarSet.has(modelRef);
|
|
331
|
-
var isGqlMap = (modelRef) => modelRef === Map;
|
|
332
|
-
|
|
333
|
-
// pkgs/@akanjs/common/src/isDayjs.ts
|
|
334
|
-
var import_dayjs2 = __require("dayjs");
|
|
335
|
-
|
|
336
|
-
// pkgs/@akanjs/common/src/isQueryEqual.ts
|
|
337
|
-
var import_dayjs3 = __toESM(__require("dayjs"));
|
|
338
|
-
|
|
339
|
-
// pkgs/@akanjs/common/src/isValidDate.ts
|
|
340
|
-
var import_dayjs4 = __toESM(__require("dayjs"));
|
|
341
|
-
var import_customParseFormat = __toESM(__require("dayjs/plugin/customParseFormat"));
|
|
342
|
-
import_dayjs4.default.extend(import_customParseFormat.default);
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
19
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
21
|
+
if (decorator = decorators[i])
|
|
22
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
23
|
+
if (kind && result)
|
|
24
|
+
__defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
343
28
|
|
|
344
|
-
|
|
345
|
-
|
|
29
|
+
// pkgs/@akanjs/signal/index.ts
|
|
30
|
+
var signal_exports = {};
|
|
31
|
+
__export(signal_exports, {
|
|
32
|
+
Access: () => Access,
|
|
33
|
+
Account: () => Account,
|
|
34
|
+
Arg: () => Arg,
|
|
35
|
+
CrystalizeStorage: () => CrystalizeStorage,
|
|
36
|
+
DbSignal: () => DbSignal,
|
|
37
|
+
DefaultStorage: () => DefaultStorage,
|
|
38
|
+
FragmentStorage: () => FragmentStorage,
|
|
39
|
+
GqlStorage: () => GqlStorage,
|
|
40
|
+
Job: () => Job,
|
|
41
|
+
LogSignal: () => LogSignal,
|
|
42
|
+
Me: () => Me,
|
|
43
|
+
Message: () => Message,
|
|
44
|
+
Mutation: () => Mutation,
|
|
45
|
+
Parent: () => Parent,
|
|
46
|
+
Process: () => Process,
|
|
47
|
+
Pubsub: () => Pubsub,
|
|
48
|
+
PurifyStorage: () => PurifyStorage,
|
|
49
|
+
Query: () => Query,
|
|
50
|
+
Req: () => Req,
|
|
51
|
+
Res: () => Res,
|
|
52
|
+
ResolveField: () => ResolveField,
|
|
53
|
+
Self: () => Self,
|
|
54
|
+
Signal: () => Signal,
|
|
55
|
+
SignalStorage: () => SignalStorage,
|
|
56
|
+
UserIp: () => UserIp,
|
|
57
|
+
Ws: () => Ws,
|
|
58
|
+
argTypes: () => argTypes,
|
|
59
|
+
baseFetch: () => baseFetch,
|
|
60
|
+
client: () => client,
|
|
61
|
+
copySignal: () => copySignal,
|
|
62
|
+
createArgMetaDecorator: () => createArgMetaDecorator,
|
|
63
|
+
defaultAccount: () => defaultAccount,
|
|
64
|
+
deserializeArg: () => deserializeArg,
|
|
65
|
+
done: () => done,
|
|
66
|
+
emit: () => emit,
|
|
67
|
+
endpointTypes: () => endpointTypes,
|
|
68
|
+
fetchOf: () => fetchOf,
|
|
69
|
+
getAllSignalRefs: () => getAllSignalRefs,
|
|
70
|
+
getArgMetas: () => getArgMetas,
|
|
71
|
+
getControllerPath: () => getControllerPath,
|
|
72
|
+
getControllerPrefix: () => getControllerPrefix,
|
|
73
|
+
getExampleData: () => getExampleData,
|
|
74
|
+
getGqlMeta: () => getGqlMeta,
|
|
75
|
+
getGqlMetaMapOnPrototype: () => getGqlMetaMapOnPrototype,
|
|
76
|
+
getGqlMetas: () => getGqlMetas,
|
|
77
|
+
getGqlOnStorage: () => getGqlOnStorage,
|
|
78
|
+
getGqlStr: () => getGqlStr,
|
|
79
|
+
getResolveFieldMetas: () => getResolveFieldMetas,
|
|
80
|
+
getSigMeta: () => getSigMeta,
|
|
81
|
+
getSignalRefsOnStorage: () => getSignalRefsOnStorage,
|
|
82
|
+
gqlOf: () => gqlOf,
|
|
83
|
+
guardTypes: () => guardTypes,
|
|
84
|
+
immerify: () => immerify,
|
|
85
|
+
internalArgTypes: () => internalArgTypes,
|
|
86
|
+
makeCrystalize: () => makeCrystalize,
|
|
87
|
+
makeDefault: () => makeDefault,
|
|
88
|
+
makeFetch: () => makeFetch,
|
|
89
|
+
makeFragment: () => makeFragment,
|
|
90
|
+
makePurify: () => makePurify,
|
|
91
|
+
makeRequestExample: () => makeRequestExample,
|
|
92
|
+
makeResponseExample: () => makeResponseExample,
|
|
93
|
+
resolve: () => resolve,
|
|
94
|
+
roleTypes: () => roleTypes,
|
|
95
|
+
scalarUtilOf: () => scalarUtilOf,
|
|
96
|
+
serializeArg: () => serializeArg,
|
|
97
|
+
setArgMetas: () => setArgMetas,
|
|
98
|
+
setGqlMetaMapOnPrototype: () => setGqlMetaMapOnPrototype,
|
|
99
|
+
signalTypes: () => signalTypes,
|
|
100
|
+
ssoTypes: () => ssoTypes,
|
|
101
|
+
subscribe: () => subscribe
|
|
102
|
+
});
|
|
103
|
+
module.exports = __toCommonJS(signal_exports);
|
|
346
104
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
constructors.forEach((baseCtor) => {
|
|
361
|
-
Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
|
|
362
|
-
if (name === "constructor" || avoidKeys?.has(name))
|
|
363
|
-
return;
|
|
364
|
-
Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
|
|
105
|
+
// pkgs/@akanjs/signal/src/client.ts
|
|
106
|
+
var import_base = require("@akanjs/base");
|
|
107
|
+
var import_common = require("@akanjs/common");
|
|
108
|
+
var import_core = require("@urql/core");
|
|
109
|
+
var import_socket = require("socket.io-client");
|
|
110
|
+
var SocketIo = class {
|
|
111
|
+
socket;
|
|
112
|
+
roomSubscribeMap = /* @__PURE__ */ new Map();
|
|
113
|
+
constructor(uri) {
|
|
114
|
+
this.socket = (0, import_socket.io)(uri, { transports: ["websocket"] });
|
|
115
|
+
this.socket.on("connect", () => {
|
|
116
|
+
this.roomSubscribeMap.forEach((option) => {
|
|
117
|
+
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
365
118
|
});
|
|
366
119
|
});
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
verbose: clc.cyanBright,
|
|
388
|
-
debug: clc.magentaBright,
|
|
389
|
-
log: clc.green,
|
|
390
|
-
info: clc.green,
|
|
391
|
-
warn: clc.yellow,
|
|
392
|
-
error: clc.red
|
|
393
|
-
};
|
|
394
|
-
var Logger = class _Logger {
|
|
395
|
-
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
396
|
-
"InstanceLoader",
|
|
397
|
-
"RoutesResolver",
|
|
398
|
-
"RouterExplorer",
|
|
399
|
-
"NestFactory",
|
|
400
|
-
"WebSocketsController",
|
|
401
|
-
"GraphQLModule",
|
|
402
|
-
"NestApplication"
|
|
403
|
-
]);
|
|
404
|
-
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
405
|
-
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
406
|
-
static #startAt = (0, import_dayjs5.default)();
|
|
407
|
-
static setLevel(level) {
|
|
408
|
-
this.level = level;
|
|
409
|
-
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
410
|
-
}
|
|
411
|
-
name;
|
|
412
|
-
constructor(name) {
|
|
413
|
-
this.name = name;
|
|
414
|
-
}
|
|
415
|
-
trace(msg, context = "") {
|
|
416
|
-
if (_Logger.#levelIdx <= 0)
|
|
417
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
418
|
-
}
|
|
419
|
-
verbose(msg, context = "") {
|
|
420
|
-
if (_Logger.#levelIdx <= 1)
|
|
421
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
422
|
-
}
|
|
423
|
-
debug(msg, context = "") {
|
|
424
|
-
if (_Logger.#levelIdx <= 2)
|
|
425
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
426
|
-
}
|
|
427
|
-
log(msg, context = "") {
|
|
428
|
-
if (_Logger.#levelIdx <= 3)
|
|
429
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
430
|
-
}
|
|
431
|
-
info(msg, context = "") {
|
|
432
|
-
if (_Logger.#levelIdx <= 4)
|
|
433
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
434
|
-
}
|
|
435
|
-
warn(msg, context = "") {
|
|
436
|
-
if (_Logger.#levelIdx <= 5)
|
|
437
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
438
|
-
}
|
|
439
|
-
error(msg, context = "") {
|
|
440
|
-
if (_Logger.#levelIdx <= 6)
|
|
441
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
442
|
-
}
|
|
443
|
-
raw(msg, method) {
|
|
444
|
-
_Logger.rawLog(msg, method);
|
|
445
|
-
}
|
|
446
|
-
rawLog(msg, method) {
|
|
447
|
-
_Logger.rawLog(msg, method);
|
|
448
|
-
}
|
|
449
|
-
static trace(msg, context = "") {
|
|
450
|
-
if (_Logger.#levelIdx <= 0)
|
|
451
|
-
_Logger.#printMessages("App", msg, context, "trace");
|
|
452
|
-
}
|
|
453
|
-
static verbose(msg, context = "") {
|
|
454
|
-
if (_Logger.#levelIdx <= 1)
|
|
455
|
-
_Logger.#printMessages("App", msg, context, "verbose");
|
|
456
|
-
}
|
|
457
|
-
static debug(msg, context = "") {
|
|
458
|
-
if (_Logger.#levelIdx <= 2)
|
|
459
|
-
_Logger.#printMessages("App", msg, context, "debug");
|
|
460
|
-
}
|
|
461
|
-
static log(msg, context = "") {
|
|
462
|
-
if (_Logger.#levelIdx <= 3)
|
|
463
|
-
_Logger.#printMessages("App", msg, context, "log");
|
|
464
|
-
}
|
|
465
|
-
static info(msg, context = "") {
|
|
466
|
-
if (_Logger.#levelIdx <= 4)
|
|
467
|
-
_Logger.#printMessages("App", msg, context, "info");
|
|
468
|
-
}
|
|
469
|
-
static warn(msg, context = "") {
|
|
470
|
-
if (_Logger.#levelIdx <= 5)
|
|
471
|
-
_Logger.#printMessages("App", msg, context, "warn");
|
|
472
|
-
}
|
|
473
|
-
static error(msg, context = "") {
|
|
474
|
-
if (_Logger.#levelIdx <= 6)
|
|
475
|
-
_Logger.#printMessages("App", msg, context, "error");
|
|
476
|
-
}
|
|
477
|
-
static #colorize(msg, logLevel) {
|
|
478
|
-
return colorizeMap[logLevel](msg);
|
|
479
|
-
}
|
|
480
|
-
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
481
|
-
if (this.#ignoreCtxSet.has(context))
|
|
482
|
-
return;
|
|
483
|
-
const now = (0, import_dayjs5.default)();
|
|
484
|
-
const processMsg = this.#colorize(
|
|
485
|
-
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
486
|
-
logLevel
|
|
487
|
-
);
|
|
488
|
-
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
489
|
-
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
490
|
-
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
491
|
-
const contentMsg = this.#colorize(content, logLevel);
|
|
492
|
-
const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
|
|
493
|
-
if (typeof window === "undefined")
|
|
494
|
-
process[writeStreamType].write(
|
|
495
|
-
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
496
|
-
`
|
|
497
|
-
);
|
|
498
|
-
else
|
|
499
|
-
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
500
|
-
`);
|
|
501
|
-
}
|
|
502
|
-
static rawLog(msg, method) {
|
|
503
|
-
this.raw(`${msg}
|
|
504
|
-
`, method);
|
|
505
|
-
}
|
|
506
|
-
static raw(msg, method) {
|
|
507
|
-
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
508
|
-
global.process.stdout.write(msg);
|
|
509
|
-
else
|
|
510
|
-
console.log(msg);
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
// pkgs/@akanjs/common/src/lowerlize.ts
|
|
515
|
-
var lowerlize = (str) => {
|
|
516
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
// pkgs/@akanjs/common/src/sleep.ts
|
|
520
|
-
var sleep = async (ms) => {
|
|
521
|
-
return new Promise((resolve2) => {
|
|
522
|
-
setTimeout(() => {
|
|
523
|
-
resolve2(true);
|
|
524
|
-
}, ms);
|
|
525
|
-
});
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
// pkgs/@akanjs/signal/src/client.ts
|
|
529
|
-
var import_core = __require("@urql/core");
|
|
530
|
-
var import_socket = __require("socket.io-client");
|
|
531
|
-
var SocketIo = class {
|
|
532
|
-
socket;
|
|
533
|
-
roomSubscribeMap = /* @__PURE__ */ new Map();
|
|
534
|
-
constructor(uri) {
|
|
535
|
-
this.socket = (0, import_socket.io)(uri, { transports: ["websocket"] });
|
|
536
|
-
this.socket.on("connect", () => {
|
|
537
|
-
this.roomSubscribeMap.forEach((option) => {
|
|
538
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
539
|
-
});
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
on(event, callback) {
|
|
543
|
-
this.socket.on(event, callback);
|
|
544
|
-
}
|
|
545
|
-
removeListener(event, callback) {
|
|
546
|
-
this.socket.removeListener(event, callback);
|
|
547
|
-
}
|
|
548
|
-
removeAllListeners() {
|
|
549
|
-
this.socket.removeAllListeners();
|
|
550
|
-
}
|
|
551
|
-
hasListeners(event) {
|
|
552
|
-
return this.socket.hasListeners(event);
|
|
553
|
-
}
|
|
554
|
-
emit(key, data) {
|
|
555
|
-
this.socket.emit(key, data);
|
|
556
|
-
}
|
|
557
|
-
subscribe(option) {
|
|
558
|
-
if (!this.roomSubscribeMap.has(option.roomId)) {
|
|
559
|
-
this.roomSubscribeMap.set(option.roomId, option);
|
|
560
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
561
|
-
}
|
|
562
|
-
this.socket.on(option.roomId, option.handleEvent);
|
|
563
|
-
}
|
|
564
|
-
unsubscribe(roomId, handleEvent) {
|
|
565
|
-
this.socket.removeListener(roomId, handleEvent);
|
|
566
|
-
const option = this.roomSubscribeMap.get(roomId);
|
|
567
|
-
if (this.hasListeners(roomId) || !option)
|
|
568
|
-
return;
|
|
569
|
-
this.roomSubscribeMap.delete(roomId);
|
|
570
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: false });
|
|
571
|
-
}
|
|
572
|
-
disconnect() {
|
|
573
|
-
this.socket.disconnect();
|
|
574
|
-
return this;
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
var Client = class _Client {
|
|
578
|
-
static globalIoMap = /* @__PURE__ */ new Map();
|
|
579
|
-
static tokenStore = /* @__PURE__ */ new Map();
|
|
580
|
-
async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
|
|
581
|
-
if (baseClientEnv.side === "server")
|
|
582
|
-
return true;
|
|
583
|
-
while (!this.getIo(ws).socket.connected) {
|
|
584
|
-
Logger.verbose("waiting for websocket to initialize...");
|
|
585
|
-
await sleep(300);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
isInitialized = false;
|
|
589
|
-
uri = baseClientEnv.serverGraphqlUri;
|
|
590
|
-
ws = baseClientEnv.serverWsUri;
|
|
591
|
-
udp = null;
|
|
592
|
-
gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
|
|
593
|
-
jwt = null;
|
|
594
|
-
async getJwt() {
|
|
595
|
-
const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
|
|
596
|
-
if (isNextServer) {
|
|
597
|
-
const nextHeaders = __require("next/headers");
|
|
598
|
-
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
599
|
-
} else
|
|
600
|
-
return _Client.tokenStore.get(this) ?? null;
|
|
120
|
+
}
|
|
121
|
+
on(event, callback) {
|
|
122
|
+
this.socket.on(event, callback);
|
|
123
|
+
}
|
|
124
|
+
removeListener(event, callback) {
|
|
125
|
+
this.socket.removeListener(event, callback);
|
|
126
|
+
}
|
|
127
|
+
removeAllListeners() {
|
|
128
|
+
this.socket.removeAllListeners();
|
|
129
|
+
}
|
|
130
|
+
hasListeners(event) {
|
|
131
|
+
return this.socket.hasListeners(event);
|
|
132
|
+
}
|
|
133
|
+
emit(key, data) {
|
|
134
|
+
this.socket.emit(key, data);
|
|
135
|
+
}
|
|
136
|
+
subscribe(option) {
|
|
137
|
+
if (!this.roomSubscribeMap.has(option.roomId)) {
|
|
138
|
+
this.roomSubscribeMap.set(option.roomId, option);
|
|
139
|
+
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
601
140
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
141
|
+
this.socket.on(option.roomId, option.handleEvent);
|
|
142
|
+
}
|
|
143
|
+
unsubscribe(roomId, handleEvent) {
|
|
144
|
+
this.socket.removeListener(roomId, handleEvent);
|
|
145
|
+
const option = this.roomSubscribeMap.get(roomId);
|
|
146
|
+
if (this.hasListeners(roomId) || !option)
|
|
147
|
+
return;
|
|
148
|
+
this.roomSubscribeMap.delete(roomId);
|
|
149
|
+
this.socket.emit(option.key, { ...option.message, __subscribe__: false });
|
|
150
|
+
}
|
|
151
|
+
disconnect() {
|
|
152
|
+
this.socket.disconnect();
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var Client = class _Client {
|
|
157
|
+
static globalIoMap = /* @__PURE__ */ new Map();
|
|
158
|
+
static tokenStore = /* @__PURE__ */ new Map();
|
|
159
|
+
async waitUntilWebSocketConnected(ws = import_base.baseClientEnv.serverWsUri) {
|
|
160
|
+
if (import_base.baseClientEnv.side === "server")
|
|
161
|
+
return true;
|
|
162
|
+
while (!this.getIo(ws).socket.connected) {
|
|
163
|
+
import_common.Logger.verbose("waiting for websocket to initialize...");
|
|
164
|
+
await (0, import_common.sleep)(300);
|
|
608
165
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
166
|
+
}
|
|
167
|
+
isInitialized = false;
|
|
168
|
+
uri = import_base.baseClientEnv.serverGraphqlUri;
|
|
169
|
+
ws = import_base.baseClientEnv.serverWsUri;
|
|
170
|
+
udp = null;
|
|
171
|
+
gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
|
|
172
|
+
jwt = null;
|
|
173
|
+
async getJwt() {
|
|
174
|
+
const isNextServer = import_base.baseClientEnv.side === "server" && import_base.baseEnv.operationType === "client";
|
|
175
|
+
if (isNextServer) {
|
|
176
|
+
const nextHeaders = require("next/headers");
|
|
177
|
+
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
178
|
+
} else
|
|
179
|
+
return _Client.tokenStore.get(this) ?? null;
|
|
180
|
+
}
|
|
181
|
+
io = null;
|
|
182
|
+
init(data = {}) {
|
|
183
|
+
Object.assign(this, data);
|
|
184
|
+
this.setLink(data.uri);
|
|
185
|
+
this.setIo(data.ws);
|
|
186
|
+
this.isInitialized = true;
|
|
187
|
+
}
|
|
188
|
+
setIo(ws = import_base.baseClientEnv.serverWsUri) {
|
|
189
|
+
this.ws = ws;
|
|
190
|
+
const existingIo = _Client.globalIoMap.get(ws);
|
|
191
|
+
if (existingIo) {
|
|
192
|
+
this.io = existingIo;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
this.io = new SocketIo(ws);
|
|
196
|
+
_Client.globalIoMap.set(ws, this.io);
|
|
197
|
+
}
|
|
198
|
+
getIo(ws = import_base.baseClientEnv.serverWsUri) {
|
|
199
|
+
const existingIo = _Client.globalIoMap.get(ws);
|
|
200
|
+
if (existingIo)
|
|
201
|
+
return existingIo;
|
|
202
|
+
const io2 = new SocketIo(ws);
|
|
203
|
+
_Client.globalIoMap.set(ws, io2);
|
|
204
|
+
return io2;
|
|
205
|
+
}
|
|
206
|
+
setLink(uri = import_base.baseClientEnv.serverGraphqlUri) {
|
|
207
|
+
this.uri = uri;
|
|
208
|
+
this.gql = (0, import_core.createClient)({
|
|
209
|
+
url: this.uri,
|
|
210
|
+
fetch,
|
|
211
|
+
exchanges: [import_core.cacheExchange, import_core.fetchExchange],
|
|
212
|
+
// requestPolicy: "network-only",
|
|
213
|
+
fetchOptions: () => {
|
|
214
|
+
return {
|
|
215
|
+
headers: {
|
|
216
|
+
"apollo-require-preflight": "true",
|
|
217
|
+
...this.jwt ? { authorization: `Bearer ${this.jwt}` } : {}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
615
220
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
setJwt(jwt) {
|
|
645
|
-
_Client.tokenStore.set(this, jwt);
|
|
646
|
-
}
|
|
647
|
-
reset() {
|
|
648
|
-
this.io?.disconnect();
|
|
649
|
-
this.io = null;
|
|
650
|
-
this.jwt = null;
|
|
651
|
-
}
|
|
652
|
-
clone(data = {}) {
|
|
653
|
-
const newClient = new _Client();
|
|
654
|
-
newClient.init({ ...this, ...data });
|
|
655
|
-
if (data.jwt)
|
|
656
|
-
_Client.tokenStore.set(newClient, data.jwt);
|
|
657
|
-
return newClient;
|
|
658
|
-
}
|
|
659
|
-
terminate() {
|
|
660
|
-
this.reset();
|
|
661
|
-
_Client.globalIoMap.forEach((io2) => io2.disconnect());
|
|
662
|
-
this.isInitialized = false;
|
|
663
|
-
}
|
|
664
|
-
setUdp(udp) {
|
|
665
|
-
this.udp = udp;
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
var client = new Client();
|
|
669
|
-
|
|
670
|
-
// pkgs/@akanjs/constant/src/scalar.ts
|
|
671
|
-
var import_reflect_metadata = __require("reflect-metadata");
|
|
672
|
-
var scalarExampleMap = /* @__PURE__ */ new Map([
|
|
673
|
-
[ID, "1234567890abcdef12345678"],
|
|
674
|
-
[Int, 0],
|
|
675
|
-
[Float, 0],
|
|
676
|
-
[String, "String"],
|
|
677
|
-
[Boolean, true],
|
|
678
|
-
[Date, (/* @__PURE__ */ new Date()).toISOString()],
|
|
679
|
-
[Upload, "FileUpload"],
|
|
680
|
-
[JSON2, {}],
|
|
681
|
-
[Map, {}]
|
|
682
|
-
]);
|
|
683
|
-
var getScalarExample = (ref) => scalarExampleMap.get(ref) ?? null;
|
|
684
|
-
var getGqlTypeStr = (ref) => scalarNameMap.get(ref) ?? getClassMeta(ref).refName;
|
|
685
|
-
var getClassMeta = (modelRef) => {
|
|
686
|
-
const [target] = getNonArrayModel(modelRef);
|
|
687
|
-
const classMeta = Reflect.getMetadata("class", target.prototype);
|
|
688
|
-
if (!classMeta)
|
|
689
|
-
throw new Error(`No ClassMeta for this target ${target.name}`);
|
|
690
|
-
return classMeta;
|
|
691
|
-
};
|
|
692
|
-
var getFieldMetas = (modelRef) => {
|
|
693
|
-
const [target] = getNonArrayModel(modelRef);
|
|
694
|
-
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
695
|
-
const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
|
|
696
|
-
return [...metadataMap.values()].sort((a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0));
|
|
697
|
-
};
|
|
698
|
-
var getFieldMetaMap = (modelRef) => {
|
|
699
|
-
const [target] = getNonArrayModel(modelRef);
|
|
700
|
-
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
701
|
-
return new Map(metadataMap);
|
|
702
|
-
};
|
|
703
|
-
var getFieldMetaMapOnPrototype = (prototype) => {
|
|
704
|
-
const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
|
|
705
|
-
return new Map(metadataMap);
|
|
706
|
-
};
|
|
707
|
-
var setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
708
|
-
Reflect.defineMetadata("fields", new Map(metadataMap), prototype);
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
// pkgs/@akanjs/constant/src/fieldMeta.ts
|
|
712
|
-
var applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
713
|
-
const isArray = arrDepth > 0;
|
|
714
|
-
const isClass = !isGqlScalar(modelRef);
|
|
715
|
-
const isMap = isGqlMap(modelRef);
|
|
716
|
-
const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
|
|
717
|
-
const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
|
|
718
|
-
if (isMap && !option.of)
|
|
719
|
-
throw new Error("Map type must have 'of' option");
|
|
720
|
-
return (prototype, key) => {
|
|
721
|
-
const metadata = {
|
|
722
|
-
nullable: option.nullable ?? false,
|
|
723
|
-
ref: option.ref,
|
|
724
|
-
refPath: option.refPath,
|
|
725
|
-
refType: option.refType,
|
|
726
|
-
default: option.default ?? (isArray ? [] : null),
|
|
727
|
-
type: option.type,
|
|
728
|
-
fieldType: option.fieldType ?? "property",
|
|
729
|
-
immutable: option.immutable ?? false,
|
|
730
|
-
min: option.min,
|
|
731
|
-
max: option.max,
|
|
732
|
-
enum: option.enum,
|
|
733
|
-
select: option.select ?? true,
|
|
734
|
-
minlength: option.minlength,
|
|
735
|
-
maxlength: option.maxlength,
|
|
736
|
-
query: option.query,
|
|
737
|
-
accumulate: option.accumulate,
|
|
738
|
-
example: option.example,
|
|
739
|
-
validate: option.validate,
|
|
740
|
-
key,
|
|
741
|
-
name,
|
|
742
|
-
isClass,
|
|
743
|
-
isScalar: type === "scalar",
|
|
744
|
-
modelRef,
|
|
745
|
-
arrDepth,
|
|
746
|
-
isArray,
|
|
747
|
-
optArrDepth: optionArrDepth,
|
|
748
|
-
isMap,
|
|
749
|
-
of: option.of,
|
|
750
|
-
text: option.text
|
|
751
|
-
};
|
|
752
|
-
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
753
|
-
metadataMap.set(key, metadata);
|
|
754
|
-
setFieldMetaMapOnPrototype(prototype, metadataMap);
|
|
755
|
-
};
|
|
756
|
-
};
|
|
757
|
-
var makeField = (customOption) => (returns, fieldOption) => {
|
|
758
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
759
|
-
if (!fieldOption)
|
|
760
|
-
return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
|
|
761
|
-
const [opt, optArrDepth] = getNonArrayModel(fieldOption);
|
|
762
|
-
return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
|
|
763
|
-
};
|
|
764
|
-
var Field = {
|
|
765
|
-
Prop: makeField({ fieldType: "property" }),
|
|
766
|
-
Hidden: makeField({ fieldType: "hidden", nullable: true }),
|
|
767
|
-
Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
|
|
768
|
-
Resolve: makeField({ fieldType: "resolve" })
|
|
769
|
-
};
|
|
770
|
-
|
|
771
|
-
// pkgs/@akanjs/constant/src/constantDecorator.ts
|
|
772
|
-
var import_reflect_metadata2 = __require("reflect-metadata");
|
|
773
|
-
|
|
774
|
-
// pkgs/@akanjs/constant/src/filterMeta.ts
|
|
775
|
-
var setFilterMeta = (filterRef, filterMeta) => {
|
|
776
|
-
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
777
|
-
if (existingFilterMeta)
|
|
778
|
-
Object.assign(filterMeta.sort, existingFilterMeta.sort);
|
|
779
|
-
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
780
|
-
};
|
|
781
|
-
var getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
782
|
-
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
783
|
-
return new Map(metadataMap);
|
|
784
|
-
};
|
|
785
|
-
var setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
786
|
-
Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
|
|
787
|
-
};
|
|
788
|
-
var applyFilterKeyMeta = (option) => {
|
|
789
|
-
return (prototype, key, descriptor) => {
|
|
790
|
-
const metadata = { key, ...option, descriptor };
|
|
791
|
-
const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
|
|
792
|
-
metadataMap.set(key, metadata);
|
|
793
|
-
setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
|
|
794
|
-
};
|
|
795
|
-
};
|
|
796
|
-
var makeFilter = (customOption) => (fieldOption) => {
|
|
797
|
-
return applyFilterKeyMeta({ ...customOption, ...fieldOption });
|
|
798
|
-
};
|
|
799
|
-
var getFilterArgMetasOnPrototype = (prototype, key) => {
|
|
800
|
-
const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
|
|
801
|
-
return filterArgMetas;
|
|
802
|
-
};
|
|
803
|
-
var setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
|
|
804
|
-
Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
|
|
805
|
-
};
|
|
806
|
-
var applyFilterArgMeta = (name, returns, argOption) => {
|
|
807
|
-
return (prototype, key, idx) => {
|
|
808
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
809
|
-
const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
|
|
810
|
-
const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
|
|
811
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
|
|
812
|
-
filterArgMetas[idx] = filterArgMeta;
|
|
813
|
-
setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
|
|
814
|
-
};
|
|
815
|
-
};
|
|
816
|
-
var Filter = {
|
|
817
|
-
Mongo: makeFilter({ type: "mongo" }),
|
|
818
|
-
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
819
|
-
Arg: applyFilterArgMeta
|
|
820
|
-
};
|
|
821
|
-
|
|
822
|
-
// pkgs/@akanjs/constant/src/baseGql.ts
|
|
823
|
-
var import_reflect_metadata3 = __require("reflect-metadata");
|
|
824
|
-
var defaultFieldMeta = {
|
|
825
|
-
fieldType: "property",
|
|
826
|
-
immutable: false,
|
|
827
|
-
select: true,
|
|
828
|
-
isClass: false,
|
|
829
|
-
isScalar: true,
|
|
830
|
-
nullable: false,
|
|
831
|
-
isArray: false,
|
|
832
|
-
arrDepth: 0,
|
|
833
|
-
optArrDepth: 0,
|
|
834
|
-
default: null,
|
|
835
|
-
isMap: false
|
|
836
|
-
};
|
|
837
|
-
var idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
|
|
838
|
-
var createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
|
|
839
|
-
var updatedAtFieldMeta = { ...defaultFieldMeta, key: "updatedAt", name: "Date", modelRef: Date };
|
|
840
|
-
var removedAtFieldMeta = {
|
|
841
|
-
...defaultFieldMeta,
|
|
842
|
-
key: "removedAt",
|
|
843
|
-
name: "Date",
|
|
844
|
-
modelRef: Date,
|
|
845
|
-
nullable: true,
|
|
846
|
-
default: null
|
|
847
|
-
};
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
setJwt(jwt) {
|
|
224
|
+
_Client.tokenStore.set(this, jwt);
|
|
225
|
+
}
|
|
226
|
+
reset() {
|
|
227
|
+
this.io?.disconnect();
|
|
228
|
+
this.io = null;
|
|
229
|
+
this.jwt = null;
|
|
230
|
+
}
|
|
231
|
+
clone(data = {}) {
|
|
232
|
+
const newClient = new _Client();
|
|
233
|
+
newClient.init({ ...this, ...data });
|
|
234
|
+
if (data.jwt)
|
|
235
|
+
_Client.tokenStore.set(newClient, data.jwt);
|
|
236
|
+
return newClient;
|
|
237
|
+
}
|
|
238
|
+
terminate() {
|
|
239
|
+
this.reset();
|
|
240
|
+
_Client.globalIoMap.forEach((io2) => io2.disconnect());
|
|
241
|
+
this.isInitialized = false;
|
|
242
|
+
}
|
|
243
|
+
setUdp(udp) {
|
|
244
|
+
this.udp = udp;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var client = new Client();
|
|
848
248
|
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
};
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
return fieldMetas.some(
|
|
864
|
-
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
865
|
-
);
|
|
866
|
-
};
|
|
867
|
-
var applyClassMeta = (type, modelType, storage) => {
|
|
868
|
-
return function(refName) {
|
|
869
|
-
return function(target) {
|
|
870
|
-
const modelRef = target;
|
|
871
|
-
const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
|
|
872
|
-
Reflect.defineMetadata("class", classMeta, modelRef.prototype);
|
|
873
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
874
|
-
};
|
|
875
|
-
};
|
|
876
|
-
};
|
|
877
|
-
var applyFilterMeta = (storage) => {
|
|
878
|
-
return function(refName) {
|
|
879
|
-
return function(target) {
|
|
880
|
-
const modelRef = target;
|
|
881
|
-
setFilterMeta(modelRef, { refName, sort: {} });
|
|
882
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
883
|
-
};
|
|
884
|
-
};
|
|
885
|
-
};
|
|
886
|
-
var Model = {
|
|
887
|
-
Light: applyClassMeta("light", "data", LightModelStorage),
|
|
888
|
-
Object: applyClassMeta("full", "ephemeral", FullModelStorage),
|
|
889
|
-
Full: applyClassMeta("full", "data", FullModelStorage),
|
|
890
|
-
Input: applyClassMeta("input", "data", InputModelStorage),
|
|
891
|
-
Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
|
|
892
|
-
Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
|
|
893
|
-
Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
|
|
894
|
-
Filter: applyFilterMeta(FilterModelStorage)
|
|
895
|
-
};
|
|
896
|
-
var getLightModelRef = (modelRef) => {
|
|
897
|
-
const classMeta = getClassMeta(modelRef);
|
|
898
|
-
if (classMeta.type !== "full")
|
|
899
|
-
return modelRef;
|
|
900
|
-
const lightModelRef = Reflect.getMetadata(`Light${classMeta.refName}`, LightModelStorage.prototype);
|
|
901
|
-
if (!lightModelRef)
|
|
902
|
-
throw new Error(`LightModel not found - ${classMeta.refName}`);
|
|
903
|
-
return lightModelRef;
|
|
904
|
-
};
|
|
249
|
+
// pkgs/@akanjs/signal/src/immerify.ts
|
|
250
|
+
var import_constant = require("@akanjs/constant");
|
|
251
|
+
var import_immer = require("immer");
|
|
252
|
+
var immerify = (modelRef, objOrArr) => {
|
|
253
|
+
if (Array.isArray(objOrArr))
|
|
254
|
+
return objOrArr.map((val) => immerify(modelRef, val));
|
|
255
|
+
const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
|
|
256
|
+
const immeredObj = Object.assign({}, objOrArr, { [import_immer.immerable]: true });
|
|
257
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
258
|
+
if (fieldMeta.isScalar && fieldMeta.isClass && !!objOrArr[fieldMeta.key])
|
|
259
|
+
immeredObj[fieldMeta.key] = immerify(fieldMeta.modelRef, objOrArr[fieldMeta.key]);
|
|
260
|
+
});
|
|
261
|
+
return immeredObj;
|
|
262
|
+
};
|
|
905
263
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
return objOrArr.map((val) => immerify(modelRef, val));
|
|
911
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
912
|
-
const immeredObj = Object.assign({}, objOrArr, { [import_immer.immerable]: true });
|
|
913
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
914
|
-
if (fieldMeta.isScalar && fieldMeta.isClass && !!objOrArr[fieldMeta.key])
|
|
915
|
-
immeredObj[fieldMeta.key] = immerify(fieldMeta.modelRef, objOrArr[fieldMeta.key]);
|
|
916
|
-
});
|
|
917
|
-
return immeredObj;
|
|
918
|
-
};
|
|
264
|
+
// pkgs/@akanjs/signal/src/gql.ts
|
|
265
|
+
var import_base3 = require("@akanjs/base");
|
|
266
|
+
var import_common3 = require("@akanjs/common");
|
|
267
|
+
var import_constant3 = require("@akanjs/constant");
|
|
919
268
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
return function(option = {}) {
|
|
1014
|
-
return function(prototype, key, idx) {
|
|
1015
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1016
|
-
argMetas[idx] = { key, idx, type, option };
|
|
1017
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1018
|
-
};
|
|
1019
|
-
};
|
|
1020
|
-
};
|
|
1021
|
-
var Account = createArgMetaDecorator("Account");
|
|
1022
|
-
var defaultAccount = {
|
|
1023
|
-
__InternalArg__: "Account",
|
|
1024
|
-
appName: baseEnv.appName,
|
|
1025
|
-
environment: baseEnv.environment
|
|
1026
|
-
};
|
|
1027
|
-
var Self = createArgMetaDecorator("Self");
|
|
1028
|
-
var Me = createArgMetaDecorator("Me");
|
|
1029
|
-
var UserIp = createArgMetaDecorator("UserIp");
|
|
1030
|
-
var Access = createArgMetaDecorator("Access");
|
|
1031
|
-
var Req = createArgMetaDecorator("Req");
|
|
1032
|
-
var Res = createArgMetaDecorator("Res");
|
|
1033
|
-
var Ws = createArgMetaDecorator("Ws");
|
|
1034
|
-
var Job = createArgMetaDecorator("Job");
|
|
1035
|
-
var getQuery = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1036
|
-
return (prototype, key, descriptor) => {
|
|
1037
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1038
|
-
metadataMap.set(key, {
|
|
1039
|
-
returns,
|
|
1040
|
-
signalOption,
|
|
1041
|
-
key,
|
|
1042
|
-
descriptor,
|
|
1043
|
-
guards: [allow, ...guards],
|
|
1044
|
-
type: "Query"
|
|
1045
|
-
});
|
|
1046
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1047
|
-
};
|
|
1048
|
-
};
|
|
1049
|
-
var getMutation = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1050
|
-
return (prototype, key, descriptor) => {
|
|
1051
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1052
|
-
metadataMap.set(key, {
|
|
1053
|
-
returns,
|
|
1054
|
-
signalOption,
|
|
1055
|
-
key,
|
|
1056
|
-
descriptor,
|
|
1057
|
-
guards: [allow, ...guards],
|
|
1058
|
-
type: "Mutation"
|
|
1059
|
-
});
|
|
1060
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1061
|
-
};
|
|
1062
|
-
};
|
|
1063
|
-
var getMessage = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1064
|
-
return (prototype, key, descriptor) => {
|
|
1065
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1066
|
-
metadataMap.set(key, {
|
|
1067
|
-
returns,
|
|
1068
|
-
signalOption,
|
|
1069
|
-
key,
|
|
1070
|
-
descriptor,
|
|
1071
|
-
guards: [allow, ...guards],
|
|
1072
|
-
type: "Message"
|
|
1073
|
-
});
|
|
1074
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1075
|
-
};
|
|
1076
|
-
};
|
|
1077
|
-
var getPubsub = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1078
|
-
return (prototype, key, descriptor) => {
|
|
1079
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1080
|
-
metadataMap.set(key, {
|
|
1081
|
-
returns,
|
|
1082
|
-
signalOption,
|
|
1083
|
-
key,
|
|
1084
|
-
descriptor,
|
|
1085
|
-
guards: [allow, ...guards],
|
|
1086
|
-
type: "Pubsub"
|
|
1087
|
-
});
|
|
1088
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1089
|
-
};
|
|
1090
|
-
};
|
|
1091
|
-
var getProcess = (serverType) => function(returns, signalOption = {}) {
|
|
1092
|
-
return (prototype, key, descriptor) => {
|
|
1093
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1094
|
-
metadataMap.set(key, {
|
|
1095
|
-
returns,
|
|
1096
|
-
signalOption: { ...signalOption, serverType: lowerlize(serverType) },
|
|
1097
|
-
key,
|
|
1098
|
-
descriptor,
|
|
1099
|
-
guards: ["None"],
|
|
1100
|
-
type: "Process"
|
|
1101
|
-
});
|
|
1102
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1103
|
-
};
|
|
1104
|
-
};
|
|
1105
|
-
var Query = {
|
|
1106
|
-
Public: getQuery("Public"),
|
|
1107
|
-
Every: getQuery("Every"),
|
|
1108
|
-
Admin: getQuery("Admin"),
|
|
1109
|
-
User: getQuery("User"),
|
|
1110
|
-
SuperAdmin: getQuery("SuperAdmin"),
|
|
1111
|
-
None: getQuery("None"),
|
|
1112
|
-
Owner: getQuery("Owner")
|
|
1113
|
-
};
|
|
1114
|
-
var Mutation = {
|
|
1115
|
-
Public: getMutation("Public"),
|
|
1116
|
-
Every: getMutation("Every"),
|
|
1117
|
-
Admin: getMutation("Admin"),
|
|
1118
|
-
User: getMutation("User"),
|
|
1119
|
-
SuperAdmin: getMutation("SuperAdmin"),
|
|
1120
|
-
None: getMutation("None"),
|
|
1121
|
-
Owner: getMutation("Owner")
|
|
1122
|
-
};
|
|
1123
|
-
var Message = {
|
|
1124
|
-
Public: getMessage("Public"),
|
|
1125
|
-
Every: getMessage("Every"),
|
|
1126
|
-
Admin: getMessage("Admin"),
|
|
1127
|
-
User: getMessage("User"),
|
|
1128
|
-
SuperAdmin: getMessage("SuperAdmin"),
|
|
1129
|
-
None: getMessage("None"),
|
|
1130
|
-
Owner: getMessage("Owner")
|
|
1131
|
-
};
|
|
1132
|
-
var Pubsub = {
|
|
1133
|
-
Public: getPubsub("Public"),
|
|
1134
|
-
Every: getPubsub("Every"),
|
|
1135
|
-
Admin: getPubsub("Admin"),
|
|
1136
|
-
User: getPubsub("User"),
|
|
1137
|
-
SuperAdmin: getPubsub("SuperAdmin"),
|
|
1138
|
-
None: getPubsub("None"),
|
|
1139
|
-
Owner: getPubsub("Owner")
|
|
1140
|
-
};
|
|
1141
|
-
var Process = {
|
|
1142
|
-
Federation: getProcess("Federation"),
|
|
1143
|
-
Batch: getProcess("Batch"),
|
|
1144
|
-
All: getProcess("All")
|
|
269
|
+
// pkgs/@akanjs/signal/src/signalDecorators.ts
|
|
270
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
271
|
+
var import_base2 = require("@akanjs/base");
|
|
272
|
+
var import_common2 = require("@akanjs/common");
|
|
273
|
+
var import_constant2 = require("@akanjs/constant");
|
|
274
|
+
var ssoTypes = ["github", "google", "facebook", "apple", "naver", "kakao"];
|
|
275
|
+
var SignalStorage = class {
|
|
276
|
+
};
|
|
277
|
+
var getAllSignalRefs = () => {
|
|
278
|
+
const signalNames = Reflect.getOwnMetadataKeys(SignalStorage.prototype);
|
|
279
|
+
const sigRefs = signalNames?.reduce((acc, signalName) => [...acc, ...getSignalRefsOnStorage(signalName)], []) ?? [];
|
|
280
|
+
return sigRefs;
|
|
281
|
+
};
|
|
282
|
+
var getSignalRefsOnStorage = (refName) => {
|
|
283
|
+
const sigRefs = Reflect.getMetadata(refName, SignalStorage.prototype);
|
|
284
|
+
return sigRefs ?? [];
|
|
285
|
+
};
|
|
286
|
+
var setSignalRefOnStorage = (refName, signalRef) => {
|
|
287
|
+
Reflect.defineMetadata(refName, [...getSignalRefsOnStorage(refName), signalRef], SignalStorage.prototype);
|
|
288
|
+
};
|
|
289
|
+
var resolve = (data) => data;
|
|
290
|
+
var emit = (data) => data;
|
|
291
|
+
var done = (data) => data;
|
|
292
|
+
var subscribe = () => void 0;
|
|
293
|
+
var signalTypes = ["graphql", "restapi"];
|
|
294
|
+
var endpointTypes = ["Query", "Mutation", "Message", "Pubsub", "Process"];
|
|
295
|
+
var guardTypes = ["Public", "None", "User", "Admin", "SuperAdmin", "Every", "Owner"];
|
|
296
|
+
var roleTypes = ["Public", "User", "Admin", "SuperAdmin"];
|
|
297
|
+
var argTypes = ["Body", "Param", "Query", "Upload", "Msg", "Room"];
|
|
298
|
+
var internalArgTypes = [
|
|
299
|
+
"Account",
|
|
300
|
+
"Me",
|
|
301
|
+
"Self",
|
|
302
|
+
"UserIp",
|
|
303
|
+
"Access",
|
|
304
|
+
"Parent",
|
|
305
|
+
"Req",
|
|
306
|
+
"Res",
|
|
307
|
+
"Ws",
|
|
308
|
+
"Job"
|
|
309
|
+
];
|
|
310
|
+
var getDefaultArg = (argRef) => {
|
|
311
|
+
const [modelRef, arrDepth] = (0, import_base2.getNonArrayModel)(argRef);
|
|
312
|
+
if (arrDepth)
|
|
313
|
+
return [];
|
|
314
|
+
const scalarArg = import_base2.scalarArgMap.get(modelRef);
|
|
315
|
+
if (scalarArg)
|
|
316
|
+
return scalarArg;
|
|
317
|
+
else
|
|
318
|
+
return {};
|
|
319
|
+
};
|
|
320
|
+
function Signal(returnsOrObj) {
|
|
321
|
+
const returns = typeof returnsOrObj === "function" ? returnsOrObj : void 0;
|
|
322
|
+
const prefix = typeof returnsOrObj === "object" ? returnsOrObj.prefix : void 0;
|
|
323
|
+
return function(target) {
|
|
324
|
+
if (returns) {
|
|
325
|
+
const modelRef = returns();
|
|
326
|
+
const classMeta = (0, import_constant2.getClassMeta)(modelRef);
|
|
327
|
+
const gqlMetas = getGqlMetas(target);
|
|
328
|
+
const modelName = (0, import_common2.lowerlize)(classMeta.refName);
|
|
329
|
+
const listName = `${modelName}ListIn`;
|
|
330
|
+
const slices = [
|
|
331
|
+
{ refName: modelName, sliceName: modelName, argLength: 1, defaultArgs: [{}] },
|
|
332
|
+
...gqlMetas.filter((gqlMeta) => {
|
|
333
|
+
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
334
|
+
if (!name.includes(listName))
|
|
335
|
+
return false;
|
|
336
|
+
const [retRef, arrDepth] = (0, import_base2.getNonArrayModel)(gqlMeta.returns());
|
|
337
|
+
return retRef.prototype === modelRef.prototype && arrDepth === 1;
|
|
338
|
+
}).map((gqlMeta) => {
|
|
339
|
+
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
340
|
+
const sliceName = name.replace(listName, `${modelName}In`);
|
|
341
|
+
const [argMetas] = getArgMetas(target, gqlMeta.key);
|
|
342
|
+
const skipIdx = argMetas.findIndex((argMeta) => argMeta.name === "skip");
|
|
343
|
+
if (skipIdx === -1)
|
|
344
|
+
throw new Error(`Invalid Args for ${sliceName}`);
|
|
345
|
+
const argLength = skipIdx;
|
|
346
|
+
const queryArgRefs = argMetas.slice(0, skipIdx).map((argMeta) => argMeta.returns());
|
|
347
|
+
const defaultArgs = queryArgRefs.map(
|
|
348
|
+
(queryArgRef, idx) => argMetas[idx].argsOption.nullable ? null : getDefaultArg(queryArgRef)
|
|
349
|
+
);
|
|
350
|
+
return { refName: modelName, sliceName, argLength, defaultArgs };
|
|
351
|
+
})
|
|
352
|
+
];
|
|
353
|
+
setSigMeta(target, { returns, prefix, slices, refName: modelName });
|
|
354
|
+
setSignalRefOnStorage(modelName, target);
|
|
355
|
+
} else {
|
|
356
|
+
const refName = typeof returnsOrObj === "object" ? (0, import_common2.lowerlize)(returnsOrObj.name) : void 0;
|
|
357
|
+
if (!refName)
|
|
358
|
+
throw new Error("Signal name is required");
|
|
359
|
+
setSigMeta(target, { returns, prefix, slices: [], refName });
|
|
360
|
+
setSignalRefOnStorage(refName, target);
|
|
361
|
+
}
|
|
1145
362
|
};
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
metadataMap.set(key, { returns, argsOption, key, descriptor });
|
|
1150
|
-
Reflect.defineMetadata("resolveField", metadataMap, target);
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
var getArg = (type) => function(name, returns, argsOption = {}) {
|
|
363
|
+
}
|
|
364
|
+
var createArgMetaDecorator = (type) => {
|
|
365
|
+
return function(option = {}) {
|
|
1154
366
|
return function(prototype, key, idx) {
|
|
1155
367
|
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1156
|
-
argMetas[idx] = {
|
|
368
|
+
argMetas[idx] = { key, idx, type, option };
|
|
1157
369
|
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1158
370
|
};
|
|
1159
371
|
};
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
372
|
+
};
|
|
373
|
+
var Account = createArgMetaDecorator("Account");
|
|
374
|
+
var defaultAccount = {
|
|
375
|
+
__InternalArg__: "Account",
|
|
376
|
+
appName: import_base2.baseEnv.appName,
|
|
377
|
+
environment: import_base2.baseEnv.environment
|
|
378
|
+
};
|
|
379
|
+
var Self = createArgMetaDecorator("Self");
|
|
380
|
+
var Me = createArgMetaDecorator("Me");
|
|
381
|
+
var UserIp = createArgMetaDecorator("UserIp");
|
|
382
|
+
var Access = createArgMetaDecorator("Access");
|
|
383
|
+
var Req = createArgMetaDecorator("Req");
|
|
384
|
+
var Res = createArgMetaDecorator("Res");
|
|
385
|
+
var Ws = createArgMetaDecorator("Ws");
|
|
386
|
+
var Job = createArgMetaDecorator("Job");
|
|
387
|
+
var getQuery = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
388
|
+
return (prototype, key, descriptor) => {
|
|
389
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
390
|
+
metadataMap.set(key, {
|
|
391
|
+
returns,
|
|
392
|
+
signalOption,
|
|
393
|
+
key,
|
|
394
|
+
descriptor,
|
|
395
|
+
guards: [allow, ...guards],
|
|
396
|
+
type: "Query"
|
|
397
|
+
});
|
|
398
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
var getMutation = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
402
|
+
return (prototype, key, descriptor) => {
|
|
403
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
404
|
+
metadataMap.set(key, {
|
|
405
|
+
returns,
|
|
406
|
+
signalOption,
|
|
407
|
+
key,
|
|
408
|
+
descriptor,
|
|
409
|
+
guards: [allow, ...guards],
|
|
410
|
+
type: "Mutation"
|
|
411
|
+
});
|
|
412
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
413
|
+
};
|
|
414
|
+
};
|
|
415
|
+
var getMessage = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
416
|
+
return (prototype, key, descriptor) => {
|
|
417
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
418
|
+
metadataMap.set(key, {
|
|
419
|
+
returns,
|
|
420
|
+
signalOption,
|
|
421
|
+
key,
|
|
422
|
+
descriptor,
|
|
423
|
+
guards: [allow, ...guards],
|
|
424
|
+
type: "Message"
|
|
425
|
+
});
|
|
426
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
var getPubsub = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
430
|
+
return (prototype, key, descriptor) => {
|
|
431
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
432
|
+
metadataMap.set(key, {
|
|
433
|
+
returns,
|
|
434
|
+
signalOption,
|
|
435
|
+
key,
|
|
436
|
+
descriptor,
|
|
437
|
+
guards: [allow, ...guards],
|
|
438
|
+
type: "Pubsub"
|
|
439
|
+
});
|
|
440
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
var getProcess = (serverType) => function(returns, signalOption = {}) {
|
|
444
|
+
return (prototype, key, descriptor) => {
|
|
445
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
446
|
+
metadataMap.set(key, {
|
|
447
|
+
returns,
|
|
448
|
+
signalOption: { ...signalOption, serverType: (0, import_common2.lowerlize)(serverType) },
|
|
449
|
+
key,
|
|
450
|
+
descriptor,
|
|
451
|
+
guards: ["None"],
|
|
452
|
+
type: "Process"
|
|
453
|
+
});
|
|
454
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
455
|
+
};
|
|
456
|
+
};
|
|
457
|
+
var Query = {
|
|
458
|
+
Public: getQuery("Public"),
|
|
459
|
+
Every: getQuery("Every"),
|
|
460
|
+
Admin: getQuery("Admin"),
|
|
461
|
+
User: getQuery("User"),
|
|
462
|
+
SuperAdmin: getQuery("SuperAdmin"),
|
|
463
|
+
None: getQuery("None"),
|
|
464
|
+
Owner: getQuery("Owner")
|
|
465
|
+
};
|
|
466
|
+
var Mutation = {
|
|
467
|
+
Public: getMutation("Public"),
|
|
468
|
+
Every: getMutation("Every"),
|
|
469
|
+
Admin: getMutation("Admin"),
|
|
470
|
+
User: getMutation("User"),
|
|
471
|
+
SuperAdmin: getMutation("SuperAdmin"),
|
|
472
|
+
None: getMutation("None"),
|
|
473
|
+
Owner: getMutation("Owner")
|
|
474
|
+
};
|
|
475
|
+
var Message = {
|
|
476
|
+
Public: getMessage("Public"),
|
|
477
|
+
Every: getMessage("Every"),
|
|
478
|
+
Admin: getMessage("Admin"),
|
|
479
|
+
User: getMessage("User"),
|
|
480
|
+
SuperAdmin: getMessage("SuperAdmin"),
|
|
481
|
+
None: getMessage("None"),
|
|
482
|
+
Owner: getMessage("Owner")
|
|
483
|
+
};
|
|
484
|
+
var Pubsub = {
|
|
485
|
+
Public: getPubsub("Public"),
|
|
486
|
+
Every: getPubsub("Every"),
|
|
487
|
+
Admin: getPubsub("Admin"),
|
|
488
|
+
User: getPubsub("User"),
|
|
489
|
+
SuperAdmin: getPubsub("SuperAdmin"),
|
|
490
|
+
None: getPubsub("None"),
|
|
491
|
+
Owner: getPubsub("Owner")
|
|
492
|
+
};
|
|
493
|
+
var Process = {
|
|
494
|
+
Federation: getProcess("Federation"),
|
|
495
|
+
Batch: getProcess("Batch"),
|
|
496
|
+
All: getProcess("All")
|
|
497
|
+
};
|
|
498
|
+
function ResolveField(returns, argsOption = {}) {
|
|
499
|
+
return function(target, key, descriptor) {
|
|
500
|
+
const metadataMap = getResolveFieldMetaMapOnPrototype(target);
|
|
501
|
+
metadataMap.set(key, { returns, argsOption, key, descriptor });
|
|
502
|
+
Reflect.defineMetadata("resolveField", metadataMap, target);
|
|
1167
503
|
};
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
504
|
+
}
|
|
505
|
+
var getArg = (type) => function(name, returns, argsOption = {}) {
|
|
506
|
+
return function(prototype, key, idx) {
|
|
507
|
+
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
508
|
+
argMetas[idx] = { name, returns, argsOption, key, idx, type };
|
|
509
|
+
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
var Arg = {
|
|
513
|
+
Body: getArg("Body"),
|
|
514
|
+
Param: getArg("Param"),
|
|
515
|
+
Query: getArg("Query"),
|
|
516
|
+
Upload: getArg("Upload"),
|
|
517
|
+
Msg: getArg("Msg"),
|
|
518
|
+
Room: getArg("Room")
|
|
519
|
+
};
|
|
520
|
+
function Parent() {
|
|
521
|
+
return function(prototype, key, idx) {
|
|
522
|
+
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
523
|
+
argMetas[idx] = { key, idx, type: "Parent" };
|
|
524
|
+
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function LogSignal(srv) {
|
|
528
|
+
class BaseSignal {
|
|
1174
529
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
530
|
+
return BaseSignal;
|
|
531
|
+
}
|
|
532
|
+
function DbSignal(constant, srv, option) {
|
|
533
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
534
|
+
const meta = (0, import_constant2.getClassMeta)(constant.Full);
|
|
535
|
+
const serviceName = `${(0, import_common2.lowerlize)(meta.refName)}Service`;
|
|
536
|
+
const [modelName, className] = [(0, import_common2.lowerlize)(meta.refName), (0, import_common2.capitalize)(meta.refName)];
|
|
537
|
+
const names = {
|
|
538
|
+
modelId: `${modelName}Id`,
|
|
539
|
+
model: modelName,
|
|
540
|
+
lightModel: `light${className}`,
|
|
541
|
+
modelList: `${modelName}List`,
|
|
542
|
+
modelInsight: `${modelName}Insight`,
|
|
543
|
+
modelExists: `${modelName}Exists`,
|
|
544
|
+
getModel: `get${className}`,
|
|
545
|
+
createModel: `create${className}`,
|
|
546
|
+
updateModel: `update${className}`,
|
|
547
|
+
removeModel: `remove${className}`
|
|
548
|
+
};
|
|
549
|
+
class BaseSignal {
|
|
550
|
+
async [_a = names.lightModel](id) {
|
|
551
|
+
const service = this[serviceName];
|
|
552
|
+
const model = await service[names.getModel](id);
|
|
553
|
+
return resolve(model);
|
|
554
|
+
}
|
|
555
|
+
async [_b = names.model](id) {
|
|
556
|
+
const service = this[serviceName];
|
|
557
|
+
const model = await service[names.getModel](id);
|
|
558
|
+
return resolve(model);
|
|
559
|
+
}
|
|
560
|
+
async [_c = names.modelList](query2, skip, limit, sort) {
|
|
561
|
+
const service = this[serviceName];
|
|
562
|
+
const models = query2?.$search ? await service.__searchDocs(query2.$search, { skip, limit, sort }) : await service.__list(query2, { skip, limit, sort });
|
|
563
|
+
return resolve(models);
|
|
564
|
+
}
|
|
565
|
+
async [_d = names.modelInsight](query2) {
|
|
566
|
+
const service = this[serviceName];
|
|
567
|
+
const insight = query2.$search ? { ...makeDefault(constant.Insight), count: await service.__searchCount(query2.$search) } : await service.__insight(query2);
|
|
568
|
+
return resolve(insight);
|
|
569
|
+
}
|
|
570
|
+
async [_e = names.modelExists](query2) {
|
|
571
|
+
const service = this[serviceName];
|
|
572
|
+
const exists = await service.__exists(query2);
|
|
573
|
+
return resolve(exists);
|
|
574
|
+
}
|
|
575
|
+
async [_f = names.createModel](data) {
|
|
576
|
+
const service = this[serviceName];
|
|
577
|
+
const model = await service[names.createModel](data);
|
|
578
|
+
return resolve(model);
|
|
579
|
+
}
|
|
580
|
+
async [_g = names.updateModel](id, data) {
|
|
581
|
+
const service = this[serviceName];
|
|
582
|
+
const model = await service[names.updateModel](id, data);
|
|
583
|
+
return resolve(model);
|
|
584
|
+
}
|
|
585
|
+
async [_h = names.removeModel](id) {
|
|
586
|
+
const service = this[serviceName];
|
|
587
|
+
const model = await service[names.removeModel](id);
|
|
588
|
+
return resolve(model);
|
|
1177
589
|
}
|
|
1178
|
-
return BaseSignal;
|
|
1179
590
|
}
|
|
1180
|
-
|
|
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
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
591
|
+
__decorateClass([
|
|
592
|
+
option.guards.get(() => constant.Light),
|
|
593
|
+
__decorateParam(0, Arg.Param(names.modelId, () => import_base2.ID))
|
|
594
|
+
], BaseSignal.prototype, _a, 1);
|
|
595
|
+
__decorateClass([
|
|
596
|
+
option.guards.get(() => constant.Full),
|
|
597
|
+
__decorateParam(0, Arg.Param(names.modelId, () => import_base2.ID))
|
|
598
|
+
], BaseSignal.prototype, _b, 1);
|
|
599
|
+
__decorateClass([
|
|
600
|
+
Query.Admin(() => [constant.Full]),
|
|
601
|
+
__decorateParam(0, Arg.Query("query", () => import_base2.JSON)),
|
|
602
|
+
__decorateParam(1, Arg.Query("skip", () => import_base2.Int, { nullable: true, example: 0 })),
|
|
603
|
+
__decorateParam(2, Arg.Query("limit", () => import_base2.Int, { nullable: true, example: 20 })),
|
|
604
|
+
__decorateParam(3, Arg.Query("sort", () => String, { nullable: true, example: "latest" }))
|
|
605
|
+
], BaseSignal.prototype, _c, 1);
|
|
606
|
+
__decorateClass([
|
|
607
|
+
Query.Admin(() => constant.Insight),
|
|
608
|
+
__decorateParam(0, Arg.Query("query", () => import_base2.JSON))
|
|
609
|
+
], BaseSignal.prototype, _d, 1);
|
|
610
|
+
__decorateClass([
|
|
611
|
+
Query.Admin(() => Boolean),
|
|
612
|
+
__decorateParam(0, Arg.Query("query", () => import_base2.JSON))
|
|
613
|
+
], BaseSignal.prototype, _e, 1);
|
|
614
|
+
__decorateClass([
|
|
615
|
+
option.guards.cru(() => constant.Full),
|
|
616
|
+
__decorateParam(0, Arg.Body(`data`, () => constant.Input))
|
|
617
|
+
], BaseSignal.prototype, _f, 1);
|
|
618
|
+
__decorateClass([
|
|
619
|
+
option.guards.cru(() => constant.Full),
|
|
620
|
+
__decorateParam(0, Arg.Param(names.modelId, () => import_base2.ID)),
|
|
621
|
+
__decorateParam(1, Arg.Body("data", () => constant.Input))
|
|
622
|
+
], BaseSignal.prototype, _g, 1);
|
|
623
|
+
__decorateClass([
|
|
624
|
+
option.guards.cru(() => constant.Full, { partial: ["status", "removedAt"] }),
|
|
625
|
+
__decorateParam(0, Arg.Param(names.modelId, () => import_base2.ID))
|
|
626
|
+
], BaseSignal.prototype, _h, 1);
|
|
627
|
+
return BaseSignal;
|
|
628
|
+
}
|
|
629
|
+
var getSigMeta = (sigRef) => {
|
|
630
|
+
const sigMeta = Reflect.getMetadata("signal", sigRef.prototype);
|
|
631
|
+
if (!sigMeta)
|
|
632
|
+
throw new Error(`No SignalMeta found for ${sigRef.name}`);
|
|
633
|
+
return sigMeta;
|
|
634
|
+
};
|
|
635
|
+
var setSigMeta = (sigRef, sigMeta) => {
|
|
636
|
+
Reflect.defineMetadata("signal", sigMeta, sigRef.prototype);
|
|
637
|
+
};
|
|
638
|
+
var getGqlMeta = (sigRef, key) => {
|
|
639
|
+
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
640
|
+
if (!gqlMetaMap)
|
|
641
|
+
throw new Error(`No GqlMeta found for ${sigRef.name}`);
|
|
642
|
+
const gqlMeta = gqlMetaMap.get(key);
|
|
643
|
+
if (!gqlMeta)
|
|
644
|
+
throw new Error(`No GqlMeta found for ${key}`);
|
|
645
|
+
return gqlMeta;
|
|
646
|
+
};
|
|
647
|
+
var getGqlMetaMapOnPrototype = (prototype) => {
|
|
648
|
+
const gqlMetaMap = Reflect.getMetadata("gql", prototype);
|
|
649
|
+
return gqlMetaMap ?? /* @__PURE__ */ new Map();
|
|
650
|
+
};
|
|
651
|
+
var getGqlMetas = (sigRef) => {
|
|
652
|
+
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
653
|
+
return gqlMetaMap ? [...gqlMetaMap.values()] : [];
|
|
654
|
+
};
|
|
655
|
+
var setGqlMetaMapOnPrototype = (prototype, gqlMetaMap) => {
|
|
656
|
+
Reflect.defineMetadata("gql", gqlMetaMap, prototype);
|
|
657
|
+
};
|
|
658
|
+
var getArgMetas = (sigRef, key) => {
|
|
659
|
+
const metas = Reflect.getMetadata("args", sigRef.prototype, key) ?? [];
|
|
660
|
+
const argMetas = metas.filter((meta) => !!meta.returns);
|
|
661
|
+
const internalArgMetas = metas.filter((meta) => !meta.returns);
|
|
662
|
+
return [argMetas, internalArgMetas];
|
|
663
|
+
};
|
|
664
|
+
var getArgMetasOnPrototype = (prototype, key) => {
|
|
665
|
+
return Reflect.getMetadata("args", prototype, key) ?? [];
|
|
666
|
+
};
|
|
667
|
+
var setArgMetas = (sigRef, key, argMetas, internalArgMetas) => {
|
|
668
|
+
Reflect.defineMetadata("args", [...argMetas, ...internalArgMetas], sigRef.prototype, key);
|
|
669
|
+
};
|
|
670
|
+
var setArgMetasOnPrototype = (prototype, key, argMetas) => {
|
|
671
|
+
Reflect.defineMetadata("args", argMetas, prototype, key);
|
|
672
|
+
};
|
|
673
|
+
var getResolveFieldMetaMapOnPrototype = (prototype) => {
|
|
674
|
+
const resolveFieldMetaMap = Reflect.getMetadata("resolveField", prototype);
|
|
675
|
+
return resolveFieldMetaMap ?? /* @__PURE__ */ new Map();
|
|
676
|
+
};
|
|
677
|
+
var getResolveFieldMetas = (sigRef) => {
|
|
678
|
+
const resolveFieldMetaMap = Reflect.getMetadata("resolveField", sigRef.prototype);
|
|
679
|
+
return resolveFieldMetaMap ? [...resolveFieldMetaMap.values()] : [];
|
|
680
|
+
};
|
|
681
|
+
var setResolveFieldMetaMapOnPrototype = (prototype, resolveFieldMetaMap) => {
|
|
682
|
+
Reflect.defineMetadata("resolveField", resolveFieldMetaMap, prototype);
|
|
683
|
+
};
|
|
684
|
+
var getControllerPrefix = (sigMeta) => {
|
|
685
|
+
return sigMeta.returns ? (0, import_common2.lowerlize)((0, import_constant2.getClassMeta)(sigMeta.returns()).refName) : sigMeta.prefix;
|
|
686
|
+
};
|
|
687
|
+
var getControllerPath = (gqlMeta, paramArgMetas) => {
|
|
688
|
+
return gqlMeta.signalOption.path ?? [gqlMeta.signalOption.name ?? gqlMeta.key, ...paramArgMetas.map((argMeta) => `:${argMeta.name}`)].join("/");
|
|
689
|
+
};
|
|
690
|
+
var copySignal = (sigRef) => {
|
|
691
|
+
class CopiedSignal {
|
|
1276
692
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
if (!gqlMeta)
|
|
1292
|
-
throw new Error(`No GqlMeta found for ${key}`);
|
|
1293
|
-
return gqlMeta;
|
|
1294
|
-
};
|
|
1295
|
-
var getGqlMetaMapOnPrototype = (prototype) => {
|
|
1296
|
-
const gqlMetaMap = Reflect.getMetadata("gql", prototype);
|
|
1297
|
-
return gqlMetaMap ?? /* @__PURE__ */ new Map();
|
|
1298
|
-
};
|
|
1299
|
-
var getGqlMetas = (sigRef) => {
|
|
1300
|
-
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
1301
|
-
return gqlMetaMap ? [...gqlMetaMap.values()] : [];
|
|
1302
|
-
};
|
|
1303
|
-
var setGqlMetaMapOnPrototype = (prototype, gqlMetaMap) => {
|
|
1304
|
-
Reflect.defineMetadata("gql", gqlMetaMap, prototype);
|
|
1305
|
-
};
|
|
1306
|
-
var getArgMetas = (sigRef, key) => {
|
|
1307
|
-
const metas = Reflect.getMetadata("args", sigRef.prototype, key) ?? [];
|
|
1308
|
-
const argMetas = metas.filter((meta) => !!meta.returns);
|
|
1309
|
-
const internalArgMetas = metas.filter((meta) => !meta.returns);
|
|
1310
|
-
return [argMetas, internalArgMetas];
|
|
1311
|
-
};
|
|
1312
|
-
var getArgMetasOnPrototype = (prototype, key) => {
|
|
1313
|
-
return Reflect.getMetadata("args", prototype, key) ?? [];
|
|
1314
|
-
};
|
|
1315
|
-
var setArgMetas = (sigRef, key, argMetas, internalArgMetas) => {
|
|
1316
|
-
Reflect.defineMetadata("args", [...argMetas, ...internalArgMetas], sigRef.prototype, key);
|
|
1317
|
-
};
|
|
1318
|
-
var setArgMetasOnPrototype = (prototype, key, argMetas) => {
|
|
1319
|
-
Reflect.defineMetadata("args", argMetas, prototype, key);
|
|
1320
|
-
};
|
|
1321
|
-
var getResolveFieldMetaMapOnPrototype = (prototype) => {
|
|
1322
|
-
const resolveFieldMetaMap = Reflect.getMetadata("resolveField", prototype);
|
|
1323
|
-
return resolveFieldMetaMap ?? /* @__PURE__ */ new Map();
|
|
1324
|
-
};
|
|
1325
|
-
var getResolveFieldMetas = (sigRef) => {
|
|
1326
|
-
const resolveFieldMetaMap = Reflect.getMetadata("resolveField", sigRef.prototype);
|
|
1327
|
-
return resolveFieldMetaMap ? [...resolveFieldMetaMap.values()] : [];
|
|
1328
|
-
};
|
|
1329
|
-
var setResolveFieldMetaMapOnPrototype = (prototype, resolveFieldMetaMap) => {
|
|
1330
|
-
Reflect.defineMetadata("resolveField", resolveFieldMetaMap, prototype);
|
|
1331
|
-
};
|
|
1332
|
-
var getControllerPrefix = (sigMeta) => {
|
|
1333
|
-
return sigMeta.returns ? lowerlize(getClassMeta(sigMeta.returns()).refName) : sigMeta.prefix;
|
|
1334
|
-
};
|
|
1335
|
-
var getControllerPath = (gqlMeta, paramArgMetas) => {
|
|
1336
|
-
return gqlMeta.signalOption.path ?? [gqlMeta.signalOption.name ?? gqlMeta.key, ...paramArgMetas.map((argMeta) => `:${argMeta.name}`)].join("/");
|
|
1337
|
-
};
|
|
1338
|
-
var copySignal = (sigRef) => {
|
|
1339
|
-
class CopiedSignal {
|
|
1340
|
-
}
|
|
1341
|
-
applyMixins(CopiedSignal, [sigRef]);
|
|
1342
|
-
const sigMeta = getSigMeta(sigRef);
|
|
1343
|
-
setSigMeta(CopiedSignal, sigMeta);
|
|
1344
|
-
const gqlMetaMap = getGqlMetaMapOnPrototype(sigRef.prototype);
|
|
1345
|
-
setGqlMetaMapOnPrototype(CopiedSignal.prototype, new Map(gqlMetaMap));
|
|
1346
|
-
const resolveFieldMetaMap = getResolveFieldMetaMapOnPrototype(sigRef.prototype);
|
|
1347
|
-
setResolveFieldMetaMapOnPrototype(CopiedSignal.prototype, new Map(resolveFieldMetaMap));
|
|
1348
|
-
for (const endpointMeta of [...gqlMetaMap.values(), ...resolveFieldMetaMap.values()]) {
|
|
1349
|
-
const argMetas = getArgMetasOnPrototype(sigRef.prototype, endpointMeta.key);
|
|
1350
|
-
setArgMetasOnPrototype(CopiedSignal.prototype, endpointMeta.key, [...argMetas]);
|
|
1351
|
-
const paramtypes = Reflect.getMetadata("design:paramtypes", sigRef.prototype, endpointMeta.key);
|
|
1352
|
-
const argParamtypes = argMetas.filter((argMeta) => !!argMeta.returns).map((argMeta) => Object);
|
|
1353
|
-
Reflect.defineMetadata("design:paramtypes", paramtypes ?? argParamtypes, CopiedSignal.prototype, endpointMeta.key);
|
|
1354
|
-
Reflect.defineMetadata("design:paramtypes", paramtypes ?? argParamtypes, CopiedSignal.prototype, endpointMeta.key);
|
|
1355
|
-
}
|
|
1356
|
-
return CopiedSignal;
|
|
1357
|
-
};
|
|
1358
|
-
|
|
1359
|
-
// pkgs/@akanjs/signal/src/gql.ts
|
|
1360
|
-
function graphql(literals, ...args) {
|
|
1361
|
-
if (typeof literals === "string")
|
|
1362
|
-
literals = [literals];
|
|
1363
|
-
let result = literals[0];
|
|
1364
|
-
args.forEach((arg, i) => {
|
|
1365
|
-
if (arg && arg.kind === "Document")
|
|
1366
|
-
result += arg.loc.source.body;
|
|
1367
|
-
else
|
|
1368
|
-
result += arg;
|
|
1369
|
-
result += literals[i + 1];
|
|
1370
|
-
});
|
|
1371
|
-
return result;
|
|
693
|
+
(0, import_common2.applyMixins)(CopiedSignal, [sigRef]);
|
|
694
|
+
const sigMeta = getSigMeta(sigRef);
|
|
695
|
+
setSigMeta(CopiedSignal, sigMeta);
|
|
696
|
+
const gqlMetaMap = getGqlMetaMapOnPrototype(sigRef.prototype);
|
|
697
|
+
setGqlMetaMapOnPrototype(CopiedSignal.prototype, new Map(gqlMetaMap));
|
|
698
|
+
const resolveFieldMetaMap = getResolveFieldMetaMapOnPrototype(sigRef.prototype);
|
|
699
|
+
setResolveFieldMetaMapOnPrototype(CopiedSignal.prototype, new Map(resolveFieldMetaMap));
|
|
700
|
+
for (const endpointMeta of [...gqlMetaMap.values(), ...resolveFieldMetaMap.values()]) {
|
|
701
|
+
const argMetas = getArgMetasOnPrototype(sigRef.prototype, endpointMeta.key);
|
|
702
|
+
setArgMetasOnPrototype(CopiedSignal.prototype, endpointMeta.key, [...argMetas]);
|
|
703
|
+
const paramtypes = Reflect.getMetadata("design:paramtypes", sigRef.prototype, endpointMeta.key);
|
|
704
|
+
const argParamtypes = argMetas.filter((argMeta) => !!argMeta.returns).map((argMeta) => Object);
|
|
705
|
+
Reflect.defineMetadata("design:paramtypes", paramtypes ?? argParamtypes, CopiedSignal.prototype, endpointMeta.key);
|
|
706
|
+
Reflect.defineMetadata("design:paramtypes", paramtypes ?? argParamtypes, CopiedSignal.prototype, endpointMeta.key);
|
|
1372
707
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
[names.
|
|
1496
|
-
|
|
1497
|
-
|
|
708
|
+
return CopiedSignal;
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
// pkgs/@akanjs/signal/src/gql.ts
|
|
712
|
+
function graphql(literals, ...args) {
|
|
713
|
+
if (typeof literals === "string")
|
|
714
|
+
literals = [literals];
|
|
715
|
+
let result = literals[0];
|
|
716
|
+
args.forEach((arg, i) => {
|
|
717
|
+
if (arg && arg.kind === "Document")
|
|
718
|
+
result += arg.loc.source.body;
|
|
719
|
+
else
|
|
720
|
+
result += arg;
|
|
721
|
+
result += literals[i + 1];
|
|
722
|
+
});
|
|
723
|
+
return result;
|
|
724
|
+
}
|
|
725
|
+
var GqlStorage = class {
|
|
726
|
+
};
|
|
727
|
+
var FragmentStorage = class {
|
|
728
|
+
};
|
|
729
|
+
var PurifyStorage = class {
|
|
730
|
+
};
|
|
731
|
+
var DefaultStorage = class {
|
|
732
|
+
};
|
|
733
|
+
var CrystalizeStorage = class {
|
|
734
|
+
};
|
|
735
|
+
var scalarUtilOf = (name, target) => {
|
|
736
|
+
const refName = (0, import_constant3.getClassMeta)(target).refName;
|
|
737
|
+
const [fieldName, className] = [(0, import_common3.lowerlize)(refName), (0, import_common3.capitalize)(refName)];
|
|
738
|
+
const graphQL = {
|
|
739
|
+
refName,
|
|
740
|
+
[className]: target,
|
|
741
|
+
[`default${className}`]: immerify(target, Object.assign(new target(), makeDefault(target))),
|
|
742
|
+
[`purify${className}`]: makePurify(target),
|
|
743
|
+
[`crystalize${className}`]: makeCrystalize(target),
|
|
744
|
+
[`${fieldName}Fragment`]: makeFragment(target)
|
|
745
|
+
};
|
|
746
|
+
return graphQL;
|
|
747
|
+
};
|
|
748
|
+
var getGqlOnStorage = (refName) => {
|
|
749
|
+
const modelGql = Reflect.getMetadata(refName, GqlStorage.prototype);
|
|
750
|
+
if (!modelGql)
|
|
751
|
+
throw new Error("Gql is not defined");
|
|
752
|
+
return modelGql;
|
|
753
|
+
};
|
|
754
|
+
var setGqlOnStorage = (refName, modelGql) => {
|
|
755
|
+
Reflect.defineMetadata(refName, modelGql, GqlStorage.prototype);
|
|
756
|
+
};
|
|
757
|
+
var gqlOf = (constant, sigRef, option = {}) => {
|
|
758
|
+
const refName = constant.refName;
|
|
759
|
+
const [fieldName, className] = [(0, import_common3.lowerlize)(refName), (0, import_common3.capitalize)(refName)];
|
|
760
|
+
const sigMeta = getSigMeta(sigRef);
|
|
761
|
+
const names = {
|
|
762
|
+
refName,
|
|
763
|
+
model: fieldName,
|
|
764
|
+
Model: className,
|
|
765
|
+
_model: `_${fieldName}`,
|
|
766
|
+
lightModel: `light${className}`,
|
|
767
|
+
_lightModel: `_light${className}`,
|
|
768
|
+
purifyModel: `purify${className}`,
|
|
769
|
+
crystalizeModel: `crystalize${className}`,
|
|
770
|
+
lightCrystalizeModel: `lightCrystalize${className}`,
|
|
771
|
+
crystalizeModelInsight: `crystalize${className}Insight`,
|
|
772
|
+
defaultModel: `default${className}`,
|
|
773
|
+
defaultModelInsight: `default${className}Insight`,
|
|
774
|
+
mergeModel: `merge${className}`,
|
|
775
|
+
viewModel: `view${className}`,
|
|
776
|
+
getModelView: `get${className}View`,
|
|
777
|
+
modelView: `${fieldName}View`,
|
|
778
|
+
modelViewAt: `${fieldName}ViewAt`,
|
|
779
|
+
editModel: `edit${className}`,
|
|
780
|
+
getModelEdit: `get${className}Edit`,
|
|
781
|
+
modelEdit: `${fieldName}Edit`,
|
|
782
|
+
listModel: `list${className}`,
|
|
783
|
+
modelList: `${fieldName}List`,
|
|
784
|
+
modelObjList: `${fieldName}ObjList`,
|
|
785
|
+
modelInsight: `${fieldName}Insight`,
|
|
786
|
+
modelObjInsight: `${fieldName}ObjInsight`,
|
|
787
|
+
updateModel: `update${className}`,
|
|
788
|
+
modelObj: `${fieldName}Obj`,
|
|
789
|
+
_modelList: `_${fieldName}List`,
|
|
790
|
+
modelInit: `${fieldName}Init`,
|
|
791
|
+
pageOfModel: `pageOf${className}`,
|
|
792
|
+
lastPageOfModel: `lastPageOf${className}`,
|
|
793
|
+
limitOfModel: `limitOf${className}`,
|
|
794
|
+
queryArgsOfModel: `queryArgsOf${className}`,
|
|
795
|
+
sortOfModel: `sortOf${className}`,
|
|
796
|
+
modelInitAt: `${fieldName}InitAt`,
|
|
797
|
+
initModel: `init${className}`,
|
|
798
|
+
getModelInit: `get${className}Init`,
|
|
799
|
+
addModelFiles: `add${className}Files`
|
|
800
|
+
};
|
|
801
|
+
const base = {
|
|
802
|
+
refName,
|
|
803
|
+
[names.purifyModel]: makePurify(constant.Input, option),
|
|
804
|
+
[names.crystalizeModel]: makeCrystalize(constant.Full, option),
|
|
805
|
+
[names.lightCrystalizeModel]: makeCrystalize(constant.Light, option),
|
|
806
|
+
[names.crystalizeModelInsight]: makeCrystalize(constant.Insight, option),
|
|
807
|
+
[names.defaultModel]: immerify(
|
|
808
|
+
constant.Full,
|
|
809
|
+
Object.assign(new constant.Full(), makeDefault(constant.Full, option))
|
|
810
|
+
),
|
|
811
|
+
[names.defaultModelInsight]: Object.assign(
|
|
812
|
+
new constant.Insight(),
|
|
813
|
+
makeDefault(constant.Insight, option)
|
|
814
|
+
)
|
|
815
|
+
};
|
|
816
|
+
const gql = Object.assign(option.overwrite ?? { client }, fetchOf(sigRef));
|
|
817
|
+
const util = {
|
|
818
|
+
[names.addModelFiles]: async (files, id, option2) => {
|
|
819
|
+
const fileGql = getGqlOnStorage("file");
|
|
820
|
+
const metas = Array.from(files).map((file) => ({ lastModifiedAt: new Date(file.lastModified), size: file.size }));
|
|
821
|
+
return await fileGql.addFiles(
|
|
822
|
+
files,
|
|
823
|
+
metas,
|
|
824
|
+
names.model,
|
|
825
|
+
id,
|
|
826
|
+
option2
|
|
827
|
+
);
|
|
828
|
+
},
|
|
829
|
+
[names.mergeModel]: async (modelOrId, data, option2) => {
|
|
830
|
+
const model = typeof modelOrId === "string" ? await gql[names._model](modelOrId) : modelOrId;
|
|
831
|
+
const input = base[names.purifyModel]({ ...model, ...data });
|
|
832
|
+
if (!input)
|
|
833
|
+
throw new Error("Error");
|
|
834
|
+
return await gql[names.updateModel](model.id, input, option2);
|
|
835
|
+
},
|
|
836
|
+
[names.viewModel]: async (id, option2) => {
|
|
837
|
+
const modelObj = await gql[names._model](id, option2);
|
|
838
|
+
return {
|
|
839
|
+
[names.model]: base[names.crystalizeModel](modelObj),
|
|
840
|
+
[names.modelView]: {
|
|
1498
841
|
refName: names.model,
|
|
1499
|
-
[names.modelObj]:
|
|
842
|
+
[names.modelObj]: modelObj,
|
|
1500
843
|
[names.modelViewAt]: /* @__PURE__ */ new Date()
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
},
|
|
847
|
+
[names.getModelView]: async (id, option2) => {
|
|
848
|
+
const modelView = await gql[names._model](id, option2);
|
|
849
|
+
return {
|
|
850
|
+
refName: names.model,
|
|
851
|
+
[names.modelObj]: modelView,
|
|
852
|
+
[names.modelViewAt]: /* @__PURE__ */ new Date()
|
|
853
|
+
};
|
|
854
|
+
},
|
|
855
|
+
[names.editModel]: async (id, option2) => {
|
|
856
|
+
const modelObj = await gql[names._model](id, option2);
|
|
857
|
+
return {
|
|
858
|
+
[names.model]: base[names.crystalizeModel](modelObj),
|
|
859
|
+
[names.modelEdit]: {
|
|
860
|
+
refName: names.model,
|
|
861
|
+
[names.modelObj]: modelObj,
|
|
862
|
+
[names.modelViewAt]: /* @__PURE__ */ new Date()
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
},
|
|
866
|
+
[names.getModelEdit]: async (id, option2) => {
|
|
867
|
+
const modelEdit = await gql[names.editModel](id, option2);
|
|
868
|
+
return modelEdit[names.modelEdit];
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
const sliceUtil = Object.fromEntries(
|
|
872
|
+
sigMeta.slices.reduce((acc, { sliceName, argLength, defaultArgs }) => {
|
|
873
|
+
const namesOfSlice = {
|
|
874
|
+
modelList: sliceName.replace(names.model, names.modelList),
|
|
875
|
+
// modelListInSelf
|
|
876
|
+
modelInsight: sliceName.replace(names.model, names.modelInsight),
|
|
877
|
+
// modelInsightInSelf
|
|
878
|
+
modelInit: sliceName.replace(names.model, names.modelInit),
|
|
879
|
+
// modelInitInSelf
|
|
880
|
+
initModel: sliceName.replace(names.model, names.initModel),
|
|
881
|
+
// initModelInSelf
|
|
882
|
+
getModelInit: sliceName.replace(names.model, names.getModelInit)
|
|
883
|
+
// getModelInitInSelf
|
|
884
|
+
};
|
|
885
|
+
const getInitFn = async (...args) => {
|
|
886
|
+
const queryArgLength = Math.min(args.length, argLength);
|
|
887
|
+
const queryArgs = [
|
|
888
|
+
...new Array(queryArgLength).fill(null).map((_, i) => args[i]),
|
|
889
|
+
...queryArgLength < argLength ? new Array(argLength - queryArgLength).fill(null).map((_, i) => defaultArgs[i + queryArgLength] ?? null) : []
|
|
890
|
+
];
|
|
891
|
+
const fetchInitOption = args[argLength] ?? {};
|
|
892
|
+
const { page = 1, limit = 20, sort = "latest", insight } = fetchInitOption;
|
|
893
|
+
const skip = (page - 1) * limit;
|
|
894
|
+
const [modelObjList, modelObjInsight] = await Promise.all([
|
|
895
|
+
gql[`_${namesOfSlice.modelList}`](
|
|
896
|
+
...queryArgs,
|
|
897
|
+
skip,
|
|
898
|
+
limit,
|
|
899
|
+
sort,
|
|
900
|
+
fetchInitOption
|
|
901
|
+
),
|
|
902
|
+
gql[`_${namesOfSlice.modelInsight}`](...queryArgs, fetchInitOption)
|
|
903
|
+
]);
|
|
904
|
+
const count = modelObjInsight.count;
|
|
1505
905
|
return {
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
};
|
|
1519
|
-
const sliceUtil = Object.fromEntries(
|
|
1520
|
-
sigMeta.slices.reduce((acc, { sliceName, argLength, defaultArgs }) => {
|
|
1521
|
-
const namesOfSlice = {
|
|
1522
|
-
modelList: sliceName.replace(names.model, names.modelList),
|
|
1523
|
-
// modelListInSelf
|
|
1524
|
-
modelInsight: sliceName.replace(names.model, names.modelInsight),
|
|
1525
|
-
// modelInsightInSelf
|
|
1526
|
-
modelInit: sliceName.replace(names.model, names.modelInit),
|
|
1527
|
-
// modelInitInSelf
|
|
1528
|
-
initModel: sliceName.replace(names.model, names.initModel),
|
|
1529
|
-
// initModelInSelf
|
|
1530
|
-
getModelInit: sliceName.replace(names.model, names.getModelInit)
|
|
1531
|
-
// getModelInitInSelf
|
|
1532
|
-
};
|
|
1533
|
-
const getInitFn = async (...args) => {
|
|
1534
|
-
const queryArgLength = Math.min(args.length, argLength);
|
|
1535
|
-
const queryArgs = [
|
|
1536
|
-
...new Array(queryArgLength).fill(null).map((_, i) => args[i]),
|
|
1537
|
-
...queryArgLength < argLength ? new Array(argLength - queryArgLength).fill(null).map((_, i) => defaultArgs[i + queryArgLength] ?? null) : []
|
|
1538
|
-
];
|
|
1539
|
-
const fetchInitOption = args[argLength] ?? {};
|
|
1540
|
-
const { page = 1, limit = 20, sort = "latest", insight } = fetchInitOption;
|
|
1541
|
-
const skip = (page - 1) * limit;
|
|
1542
|
-
const [modelObjList, modelObjInsight] = await Promise.all([
|
|
1543
|
-
gql[`_${namesOfSlice.modelList}`](
|
|
1544
|
-
...queryArgs,
|
|
1545
|
-
skip,
|
|
1546
|
-
limit,
|
|
1547
|
-
sort,
|
|
1548
|
-
fetchInitOption
|
|
1549
|
-
),
|
|
1550
|
-
gql[`_${namesOfSlice.modelInsight}`](...queryArgs, fetchInitOption)
|
|
1551
|
-
]);
|
|
1552
|
-
const count = modelObjInsight.count;
|
|
1553
|
-
return {
|
|
1554
|
-
// Client Component용
|
|
1555
|
-
refName: names.model,
|
|
1556
|
-
sliceName,
|
|
1557
|
-
argLength,
|
|
1558
|
-
[names.modelObjList]: modelObjList,
|
|
1559
|
-
[names.modelObjInsight]: modelObjInsight,
|
|
1560
|
-
[names.pageOfModel]: page,
|
|
1561
|
-
[names.lastPageOfModel]: Math.max(Math.floor((count - 1) / limit) + 1, 1),
|
|
1562
|
-
[names.limitOfModel]: limit,
|
|
1563
|
-
[names.queryArgsOfModel]: JSON.parse(JSON.stringify(queryArgs)),
|
|
1564
|
-
[names.sortOfModel]: sort,
|
|
1565
|
-
[names.modelInitAt]: /* @__PURE__ */ new Date()
|
|
1566
|
-
};
|
|
906
|
+
// Client Component용
|
|
907
|
+
refName: names.model,
|
|
908
|
+
sliceName,
|
|
909
|
+
argLength,
|
|
910
|
+
[names.modelObjList]: modelObjList,
|
|
911
|
+
[names.modelObjInsight]: modelObjInsight,
|
|
912
|
+
[names.pageOfModel]: page,
|
|
913
|
+
[names.lastPageOfModel]: Math.max(Math.floor((count - 1) / limit) + 1, 1),
|
|
914
|
+
[names.limitOfModel]: limit,
|
|
915
|
+
[names.queryArgsOfModel]: JSON.parse(JSON.stringify(queryArgs)),
|
|
916
|
+
[names.sortOfModel]: sort,
|
|
917
|
+
[names.modelInitAt]: /* @__PURE__ */ new Date()
|
|
1567
918
|
};
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
)
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
919
|
+
};
|
|
920
|
+
const initFn = async (...args) => {
|
|
921
|
+
const modelInit = await getInitFn(...args);
|
|
922
|
+
const modelObjList = modelInit[names.modelObjList];
|
|
923
|
+
const modelObjInsight = modelInit[names.modelObjInsight];
|
|
924
|
+
const modelList = new import_base3.DataList(
|
|
925
|
+
modelObjList.map((modelObj) => base[names.lightCrystalizeModel](modelObj))
|
|
926
|
+
);
|
|
927
|
+
const modelInsight = base[names.crystalizeModelInsight](modelObjInsight);
|
|
928
|
+
return {
|
|
929
|
+
[namesOfSlice.modelList]: modelList,
|
|
930
|
+
// Server Component용
|
|
931
|
+
[namesOfSlice.modelInsight]: modelInsight,
|
|
932
|
+
// Server Component용
|
|
933
|
+
[namesOfSlice.modelInit]: modelInit
|
|
1583
934
|
};
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
)
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
)
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
result[metadata.key] = metadata.default;
|
|
1626
|
-
} else if (metadata.isArray)
|
|
1627
|
-
result[metadata.key] = [];
|
|
1628
|
-
else if (metadata.nullable)
|
|
1629
|
-
result[metadata.key] = null;
|
|
1630
|
-
else if (metadata.isClass)
|
|
1631
|
-
result[metadata.key] = metadata.isScalar ? makeDefault(metadata.modelRef) : null;
|
|
935
|
+
};
|
|
936
|
+
return [...acc, [namesOfSlice.getModelInit, getInitFn], [namesOfSlice.initModel, initFn]];
|
|
937
|
+
}, [])
|
|
938
|
+
);
|
|
939
|
+
const overwriteSlices = option.overwrite ? option.overwrite.slices.filter(
|
|
940
|
+
(slice) => !sigMeta.slices.some((s) => s.sliceName === slice.sliceName)
|
|
941
|
+
) : [];
|
|
942
|
+
const modelGql = Object.assign(option.overwrite ?? {}, {
|
|
943
|
+
...gql,
|
|
944
|
+
...base,
|
|
945
|
+
...util,
|
|
946
|
+
...sliceUtil,
|
|
947
|
+
slices: [...overwriteSlices, ...sigMeta.slices]
|
|
948
|
+
});
|
|
949
|
+
setGqlOnStorage(refName, modelGql);
|
|
950
|
+
return modelGql;
|
|
951
|
+
};
|
|
952
|
+
var getPredefinedDefault = (refName) => {
|
|
953
|
+
const defaultData = Reflect.getMetadata(refName, DefaultStorage.prototype);
|
|
954
|
+
return defaultData;
|
|
955
|
+
};
|
|
956
|
+
var setPredefinedDefault = (refName, defaultData) => {
|
|
957
|
+
Reflect.defineMetadata(refName, defaultData, DefaultStorage.prototype);
|
|
958
|
+
};
|
|
959
|
+
var makeDefault = (target, option = {}) => {
|
|
960
|
+
const classMeta = (0, import_constant3.getClassMeta)(target);
|
|
961
|
+
const predefinedDefault = getPredefinedDefault(classMeta.refName);
|
|
962
|
+
if (predefinedDefault && !option.overwrite)
|
|
963
|
+
return predefinedDefault;
|
|
964
|
+
if (option.isChild && classMeta.type !== "scalar")
|
|
965
|
+
return null;
|
|
966
|
+
const metadatas = (0, import_constant3.getFieldMetas)(target);
|
|
967
|
+
const result = {};
|
|
968
|
+
for (const metadata of metadatas) {
|
|
969
|
+
if (metadata.fieldType === "hidden")
|
|
970
|
+
result[metadata.key] = null;
|
|
971
|
+
else if (metadata.default) {
|
|
972
|
+
if (typeof metadata.default === "function")
|
|
973
|
+
result[metadata.key] = metadata.default();
|
|
974
|
+
else if (metadata.default instanceof import_base3.Enum)
|
|
975
|
+
result[metadata.key] = [...metadata.default.values];
|
|
1632
976
|
else
|
|
1633
|
-
result[metadata.key] =
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
977
|
+
result[metadata.key] = metadata.default;
|
|
978
|
+
} else if (metadata.isArray)
|
|
979
|
+
result[metadata.key] = [];
|
|
980
|
+
else if (metadata.nullable)
|
|
981
|
+
result[metadata.key] = null;
|
|
982
|
+
else if (metadata.isClass)
|
|
983
|
+
result[metadata.key] = metadata.isScalar ? makeDefault(metadata.modelRef) : null;
|
|
984
|
+
else
|
|
985
|
+
result[metadata.key] = import_base3.scalarDefaultMap.get(metadata.modelRef);
|
|
986
|
+
}
|
|
987
|
+
setPredefinedDefault(classMeta.refName, result);
|
|
988
|
+
return result;
|
|
989
|
+
};
|
|
990
|
+
var query = async (fetchClient, query2, variables = {}, option = {}) => {
|
|
991
|
+
const jwt = option.url ? null : await fetchClient.getJwt();
|
|
992
|
+
const { data, error } = await fetchClient.gql.query(query2, variables, {
|
|
993
|
+
fetch,
|
|
994
|
+
url: option.url ?? fetchClient.uri,
|
|
995
|
+
requestPolicy: typeof option.cache === "string" ? option.cache : option.cache === true ? "cache-first" : "network-only",
|
|
996
|
+
fetchOptions: {
|
|
997
|
+
...typeof option.cache === "number" ? { next: { revalidate: option.cache } } : option.cache === true ? { cache: "force-cache" } : { cache: "no-store" },
|
|
998
|
+
headers: {
|
|
999
|
+
"apollo-require-preflight": "true",
|
|
1000
|
+
...jwt ? { authorization: `Bearer ${jwt}` } : {},
|
|
1001
|
+
...option.token ? { authorization: `Bearer ${option.token}` } : {}
|
|
1651
1002
|
}
|
|
1652
|
-
}).toPromise();
|
|
1653
|
-
if (!data) {
|
|
1654
|
-
const content = error?.graphQLErrors[0]?.message ?? "Unknown Error";
|
|
1655
|
-
if (option.onError) {
|
|
1656
|
-
option.onError(content);
|
|
1657
|
-
return;
|
|
1658
|
-
} else
|
|
1659
|
-
throw new Error(content);
|
|
1660
1003
|
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1004
|
+
}).toPromise();
|
|
1005
|
+
if (!data) {
|
|
1006
|
+
const content = error?.graphQLErrors[0]?.message ?? "Unknown Error";
|
|
1007
|
+
if (option.onError) {
|
|
1008
|
+
option.onError(content);
|
|
1009
|
+
return;
|
|
1010
|
+
} else
|
|
1011
|
+
throw new Error(content);
|
|
1012
|
+
}
|
|
1013
|
+
return data;
|
|
1014
|
+
};
|
|
1015
|
+
var mutate = async (fetchClient, mutation, variables = {}, option = {}) => {
|
|
1016
|
+
const jwt = option.url ? null : await fetchClient.getJwt();
|
|
1017
|
+
const { data, error } = await fetchClient.gql.mutation(mutation, variables, {
|
|
1018
|
+
fetch,
|
|
1019
|
+
url: option.url ?? fetchClient.uri,
|
|
1020
|
+
requestPolicy: "network-only",
|
|
1021
|
+
fetchOptions: {
|
|
1022
|
+
cache: "no-store",
|
|
1023
|
+
headers: {
|
|
1024
|
+
"apollo-require-preflight": "true",
|
|
1025
|
+
...jwt ? { authorization: `Bearer ${jwt}` } : {},
|
|
1026
|
+
...option.token ? { authorization: `Bearer ${option.token}` } : {}
|
|
1676
1027
|
}
|
|
1677
|
-
}).toPromise();
|
|
1678
|
-
if (!data) {
|
|
1679
|
-
const content = error?.graphQLErrors[0]?.message ?? "Unknown Error";
|
|
1680
|
-
if (option.onError) {
|
|
1681
|
-
option.onError(content);
|
|
1682
|
-
return;
|
|
1683
|
-
} else
|
|
1684
|
-
throw new Error(content);
|
|
1685
1028
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1029
|
+
}).toPromise();
|
|
1030
|
+
if (!data) {
|
|
1031
|
+
const content = error?.graphQLErrors[0]?.message ?? "Unknown Error";
|
|
1032
|
+
if (option.onError) {
|
|
1033
|
+
option.onError(content);
|
|
1034
|
+
return;
|
|
1035
|
+
} else
|
|
1036
|
+
throw new Error(content);
|
|
1037
|
+
}
|
|
1038
|
+
return data;
|
|
1039
|
+
};
|
|
1040
|
+
var scalarPurifyMap = /* @__PURE__ */ new Map([
|
|
1041
|
+
[Date, (value) => (0, import_base3.dayjs)(value).toDate()],
|
|
1042
|
+
[String, (value) => value],
|
|
1043
|
+
[import_base3.ID, (value) => value],
|
|
1044
|
+
[Boolean, (value) => value],
|
|
1045
|
+
[import_base3.Int, (value) => value],
|
|
1046
|
+
[import_base3.Float, (value) => value],
|
|
1047
|
+
[import_base3.JSON, (value) => value]
|
|
1048
|
+
]);
|
|
1049
|
+
var getPurifyFn = (modelRef) => {
|
|
1050
|
+
const [valueRef] = (0, import_base3.getNonArrayModel)(modelRef);
|
|
1051
|
+
return scalarPurifyMap.get(valueRef) ?? ((value) => value);
|
|
1052
|
+
};
|
|
1053
|
+
var purify = (metadata, value, self) => {
|
|
1054
|
+
if (metadata.nullable && (value === null || value === void 0 || typeof value === "number" && isNaN(value) || typeof value === "string" && !value.length))
|
|
1055
|
+
return null;
|
|
1056
|
+
if (metadata.isArray) {
|
|
1057
|
+
if (!Array.isArray(value))
|
|
1058
|
+
throw new Error(`Invalid Array Value in ${metadata.key} for value ${value}`);
|
|
1059
|
+
if (metadata.minlength && value.length < metadata.minlength)
|
|
1060
|
+
throw new Error(`Invalid Array Length (Min) in ${metadata.key} for value ${value}`);
|
|
1061
|
+
else if (metadata.maxlength && value.length > metadata.maxlength)
|
|
1062
|
+
throw new Error(`Invalid Array Length (Max) in ${metadata.key} for value ${value}`);
|
|
1063
|
+
else if (metadata.optArrDepth === 0 && metadata.validate && !metadata.validate(value, self))
|
|
1064
|
+
throw new Error(`Invalid Array Value (Failed to pass validation) in ${metadata.key} for value ${value}`);
|
|
1065
|
+
return value.map((v) => purify({ ...metadata, isArray: false }, v, v));
|
|
1066
|
+
}
|
|
1067
|
+
if (metadata.isMap && metadata.of) {
|
|
1068
|
+
const purifyFn2 = getPurifyFn(metadata.of);
|
|
1069
|
+
return Object.fromEntries(
|
|
1070
|
+
[...value.entries()].map(([key, val]) => [key, (0, import_base3.applyFnToArrayObjects)(val, purifyFn2)])
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
if (metadata.isClass)
|
|
1074
|
+
return makePurify(metadata.modelRef)(value, true);
|
|
1075
|
+
if (metadata.name === "Date" && (0, import_base3.dayjs)(value).isBefore((0, import_base3.dayjs)(/* @__PURE__ */ new Date("0000"))))
|
|
1076
|
+
throw new Error(`Invalid Date Value (Default) in ${metadata.key} for value ${value}`);
|
|
1077
|
+
if (["String", "ID"].includes(metadata.name) && (value === "" || !value))
|
|
1078
|
+
throw new Error(`Invalid String Value (Default) in ${metadata.key} for value ${value}`);
|
|
1079
|
+
if (metadata.validate && !metadata.validate(value, self))
|
|
1080
|
+
throw new Error(`Invalid Value (Failed to pass validation) / ${value} in ${metadata.key}`);
|
|
1081
|
+
if (!metadata.nullable && !value && value !== 0 && value !== false)
|
|
1082
|
+
throw new Error(`Invalid Value (Nullable) in ${metadata.key} for value ${value}`);
|
|
1083
|
+
const purifyFn = getPurifyFn(metadata.modelRef);
|
|
1084
|
+
return purifyFn(value);
|
|
1085
|
+
};
|
|
1086
|
+
var getPredefinedPurifyFn = (refName) => {
|
|
1087
|
+
const purify2 = Reflect.getMetadata(refName, PurifyStorage.prototype);
|
|
1088
|
+
return purify2;
|
|
1089
|
+
};
|
|
1090
|
+
var setPredefinedPurifyFn = (refName, purify2) => {
|
|
1091
|
+
Reflect.defineMetadata(refName, purify2, PurifyStorage.prototype);
|
|
1092
|
+
};
|
|
1093
|
+
var makePurify = (target, option = {}) => {
|
|
1094
|
+
const classMeta = (0, import_constant3.getClassMeta)(target);
|
|
1095
|
+
const purifyFn = getPredefinedPurifyFn(classMeta.refName);
|
|
1096
|
+
if (purifyFn && !option.overwrite)
|
|
1097
|
+
return purifyFn;
|
|
1098
|
+
const metadatas = (0, import_constant3.getFieldMetas)(target);
|
|
1099
|
+
const fn = (self, isChild) => {
|
|
1100
|
+
try {
|
|
1101
|
+
if (isChild && classMeta.type !== "scalar") {
|
|
1102
|
+
const id = self.id;
|
|
1103
|
+
if (!id)
|
|
1104
|
+
throw new Error(`Invalid Value (No ID) for id ${classMeta.refName}`);
|
|
1105
|
+
return id;
|
|
1106
|
+
}
|
|
1107
|
+
const result = {};
|
|
1108
|
+
for (const metadata of metadatas) {
|
|
1109
|
+
const value = self[metadata.key];
|
|
1110
|
+
result[metadata.key] = purify(metadata, value, self);
|
|
1111
|
+
}
|
|
1112
|
+
return result;
|
|
1113
|
+
} catch (err) {
|
|
1114
|
+
if (isChild)
|
|
1115
|
+
throw new Error(err);
|
|
1116
|
+
import_common3.Logger.debug(err);
|
|
1703
1117
|
return null;
|
|
1704
|
-
if (metadata.isArray) {
|
|
1705
|
-
if (!Array.isArray(value))
|
|
1706
|
-
throw new Error(`Invalid Array Value in ${metadata.key} for value ${value}`);
|
|
1707
|
-
if (metadata.minlength && value.length < metadata.minlength)
|
|
1708
|
-
throw new Error(`Invalid Array Length (Min) in ${metadata.key} for value ${value}`);
|
|
1709
|
-
else if (metadata.maxlength && value.length > metadata.maxlength)
|
|
1710
|
-
throw new Error(`Invalid Array Length (Max) in ${metadata.key} for value ${value}`);
|
|
1711
|
-
else if (metadata.optArrDepth === 0 && metadata.validate && !metadata.validate(value, self))
|
|
1712
|
-
throw new Error(`Invalid Array Value (Failed to pass validation) in ${metadata.key} for value ${value}`);
|
|
1713
|
-
return value.map((v) => purify({ ...metadata, isArray: false }, v, v));
|
|
1714
|
-
}
|
|
1715
|
-
if (metadata.isMap && metadata.of) {
|
|
1716
|
-
const purifyFn2 = getPurifyFn(metadata.of);
|
|
1717
|
-
return Object.fromEntries(
|
|
1718
|
-
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, purifyFn2)])
|
|
1719
|
-
);
|
|
1720
1118
|
}
|
|
1721
|
-
if (metadata.isClass)
|
|
1722
|
-
return makePurify(metadata.modelRef)(value, true);
|
|
1723
|
-
if (metadata.name === "Date" && dayjs(value).isBefore(dayjs(/* @__PURE__ */ new Date("0000"))))
|
|
1724
|
-
throw new Error(`Invalid Date Value (Default) in ${metadata.key} for value ${value}`);
|
|
1725
|
-
if (["String", "ID"].includes(metadata.name) && (value === "" || !value))
|
|
1726
|
-
throw new Error(`Invalid String Value (Default) in ${metadata.key} for value ${value}`);
|
|
1727
|
-
if (metadata.validate && !metadata.validate(value, self))
|
|
1728
|
-
throw new Error(`Invalid Value (Failed to pass validation) / ${value} in ${metadata.key}`);
|
|
1729
|
-
if (!metadata.nullable && !value && value !== 0 && value !== false)
|
|
1730
|
-
throw new Error(`Invalid Value (Nullable) in ${metadata.key} for value ${value}`);
|
|
1731
|
-
const purifyFn = getPurifyFn(metadata.modelRef);
|
|
1732
|
-
return purifyFn(value);
|
|
1733
1119
|
};
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1120
|
+
setPredefinedPurifyFn(classMeta.refName, fn);
|
|
1121
|
+
return fn;
|
|
1122
|
+
};
|
|
1123
|
+
var scalarCrystalizeMap = /* @__PURE__ */ new Map([
|
|
1124
|
+
[Date, (value) => (0, import_base3.dayjs)(value)],
|
|
1125
|
+
[String, (value) => value],
|
|
1126
|
+
[import_base3.ID, (value) => value],
|
|
1127
|
+
[Boolean, (value) => value],
|
|
1128
|
+
[import_base3.Int, (value) => value],
|
|
1129
|
+
[import_base3.Float, (value) => value],
|
|
1130
|
+
[import_base3.JSON, (value) => value]
|
|
1131
|
+
]);
|
|
1132
|
+
var crystalize = (metadata, value) => {
|
|
1133
|
+
if (value === void 0 || value === null)
|
|
1134
|
+
return value;
|
|
1135
|
+
if (metadata.isArray && Array.isArray(value))
|
|
1136
|
+
return value.map((v) => crystalize({ ...metadata, isArray: false }, v));
|
|
1137
|
+
if (metadata.isMap) {
|
|
1138
|
+
const [valueRef] = (0, import_base3.getNonArrayModel)(metadata.of);
|
|
1139
|
+
const crystalizeValue = scalarCrystalizeMap.get(valueRef) ?? ((value2) => value2);
|
|
1140
|
+
return new Map(
|
|
1141
|
+
Object.entries(value).map(([key, val]) => [key, (0, import_base3.applyFnToArrayObjects)(val, crystalizeValue)])
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
if (metadata.isClass)
|
|
1145
|
+
return makeCrystalize(metadata.modelRef)(value, true);
|
|
1146
|
+
if (metadata.name === "Date")
|
|
1147
|
+
return (0, import_base3.dayjs)(value);
|
|
1148
|
+
return (scalarCrystalizeMap.get(metadata.modelRef) ?? ((value2) => value2))(value);
|
|
1149
|
+
};
|
|
1150
|
+
var getPredefinedCrystalizeFn = (refName) => {
|
|
1151
|
+
const crystalize2 = Reflect.getMetadata(refName, CrystalizeStorage.prototype);
|
|
1152
|
+
return crystalize2;
|
|
1153
|
+
};
|
|
1154
|
+
var setPredefinedCrystalizeFn = (refName, crystalize2) => {
|
|
1155
|
+
Reflect.defineMetadata(refName, crystalize2, CrystalizeStorage.prototype);
|
|
1156
|
+
};
|
|
1157
|
+
var makeCrystalize = (target, option = {}) => {
|
|
1158
|
+
const classMeta = (0, import_constant3.getClassMeta)(target);
|
|
1159
|
+
const crystalizeFn = getPredefinedCrystalizeFn(classMeta.refName);
|
|
1160
|
+
if (crystalizeFn && !option.overwrite && !option.partial?.length)
|
|
1161
|
+
return crystalizeFn;
|
|
1162
|
+
const fieldMetaMap = (0, import_constant3.getFieldMetaMap)(target);
|
|
1163
|
+
const fieldKeys = option.partial?.length ? classMeta.type === "scalar" ? option.partial : ["id", ...option.partial, "updatedAt"] : [...fieldMetaMap.keys()];
|
|
1164
|
+
const metadatas = fieldKeys.map((key) => fieldMetaMap.get(key));
|
|
1165
|
+
const fn = (self, isChild) => {
|
|
1166
|
+
try {
|
|
1167
|
+
const result = Object.assign(new target(), self);
|
|
1168
|
+
for (const metadata of metadatas.filter((m) => !!self[m.key])) {
|
|
1169
|
+
if (metadata.fieldType === "hidden")
|
|
1170
|
+
continue;
|
|
1171
|
+
result[metadata.key] = crystalize(metadata, self[metadata.key]);
|
|
1766
1172
|
}
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
[Date, (value) => dayjs(value)],
|
|
1773
|
-
[String, (value) => value],
|
|
1774
|
-
[ID, (value) => value],
|
|
1775
|
-
[Boolean, (value) => value],
|
|
1776
|
-
[Int, (value) => value],
|
|
1777
|
-
[Float, (value) => value],
|
|
1778
|
-
[JSON2, (value) => value]
|
|
1779
|
-
]);
|
|
1780
|
-
var crystalize = (metadata, value) => {
|
|
1781
|
-
if (value === void 0 || value === null)
|
|
1782
|
-
return value;
|
|
1783
|
-
if (metadata.isArray && Array.isArray(value))
|
|
1784
|
-
return value.map((v) => crystalize({ ...metadata, isArray: false }, v));
|
|
1785
|
-
if (metadata.isMap) {
|
|
1786
|
-
const [valueRef] = getNonArrayModel(metadata.of);
|
|
1787
|
-
const crystalizeValue = scalarCrystalizeMap.get(valueRef) ?? ((value2) => value2);
|
|
1788
|
-
return new Map(
|
|
1789
|
-
Object.entries(value).map(([key, val]) => [key, applyFnToArrayObjects(val, crystalizeValue)])
|
|
1790
|
-
);
|
|
1173
|
+
return result;
|
|
1174
|
+
} catch (err) {
|
|
1175
|
+
if (isChild)
|
|
1176
|
+
throw new Error(err);
|
|
1177
|
+
return null;
|
|
1791
1178
|
}
|
|
1792
|
-
if (metadata.isClass)
|
|
1793
|
-
return makeCrystalize(metadata.modelRef)(value, true);
|
|
1794
|
-
if (metadata.name === "Date")
|
|
1795
|
-
return dayjs(value);
|
|
1796
|
-
return (scalarCrystalizeMap.get(metadata.modelRef) ?? ((value2) => value2))(value);
|
|
1797
|
-
};
|
|
1798
|
-
var getPredefinedCrystalizeFn = (refName) => {
|
|
1799
|
-
const crystalize2 = Reflect.getMetadata(refName, CrystalizeStorage.prototype);
|
|
1800
|
-
return crystalize2;
|
|
1801
|
-
};
|
|
1802
|
-
var setPredefinedCrystalizeFn = (refName, crystalize2) => {
|
|
1803
|
-
Reflect.defineMetadata(refName, crystalize2, CrystalizeStorage.prototype);
|
|
1804
|
-
};
|
|
1805
|
-
var makeCrystalize = (target, option = {}) => {
|
|
1806
|
-
const classMeta = getClassMeta(target);
|
|
1807
|
-
const crystalizeFn = getPredefinedCrystalizeFn(classMeta.refName);
|
|
1808
|
-
if (crystalizeFn && !option.overwrite && !option.partial?.length)
|
|
1809
|
-
return crystalizeFn;
|
|
1810
|
-
const fieldMetaMap = getFieldMetaMap(target);
|
|
1811
|
-
const fieldKeys = option.partial?.length ? classMeta.type === "scalar" ? option.partial : ["id", ...option.partial, "updatedAt"] : [...fieldMetaMap.keys()];
|
|
1812
|
-
const metadatas = fieldKeys.map((key) => fieldMetaMap.get(key));
|
|
1813
|
-
const fn = (self, isChild) => {
|
|
1814
|
-
try {
|
|
1815
|
-
const result = Object.assign(new target(), self);
|
|
1816
|
-
for (const metadata of metadatas.filter((m) => !!self[m.key])) {
|
|
1817
|
-
if (metadata.fieldType === "hidden")
|
|
1818
|
-
continue;
|
|
1819
|
-
result[metadata.key] = crystalize(metadata, self[metadata.key]);
|
|
1820
|
-
}
|
|
1821
|
-
return result;
|
|
1822
|
-
} catch (err) {
|
|
1823
|
-
if (isChild)
|
|
1824
|
-
throw new Error(err);
|
|
1825
|
-
return null;
|
|
1826
|
-
}
|
|
1827
|
-
};
|
|
1828
|
-
if (!option.partial?.length)
|
|
1829
|
-
setPredefinedCrystalizeFn(classMeta.refName, fn);
|
|
1830
|
-
return fn;
|
|
1831
1179
|
};
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1180
|
+
if (!option.partial?.length)
|
|
1181
|
+
setPredefinedCrystalizeFn(classMeta.refName, fn);
|
|
1182
|
+
return fn;
|
|
1183
|
+
};
|
|
1184
|
+
var fragmentize = (target, fragMap = /* @__PURE__ */ new Map(), partial) => {
|
|
1185
|
+
const classMeta = (0, import_constant3.getClassMeta)(target);
|
|
1186
|
+
const metadatas = (0, import_constant3.getFieldMetas)(target);
|
|
1187
|
+
const selectKeys = partial ? ["id", ...partial, "updatedAt"] : metadatas.map((metadata) => metadata.key);
|
|
1188
|
+
const selectKeySet = new Set(selectKeys);
|
|
1189
|
+
const fragment = `fragment ${(0, import_common3.lowerlize)(classMeta.refName)}Fragment on ${(0, import_common3.capitalize)(
|
|
1190
|
+
classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName
|
|
1191
|
+
)} {
|
|
1840
1192
|
` + metadatas.filter((metadata) => metadata.fieldType !== "hidden" && selectKeySet.has(metadata.key)).map((metadata) => {
|
|
1841
|
-
|
|
1842
|
-
...${lowerlize(metadata.name)}Fragment
|
|
1193
|
+
return metadata.isClass ? ` ${metadata.key} {
|
|
1194
|
+
...${(0, import_common3.lowerlize)(metadata.name)}Fragment
|
|
1843
1195
|
}` : ` ${metadata.key}`;
|
|
1844
|
-
|
|
1196
|
+
}).join(`
|
|
1845
1197
|
`) + `
|
|
1846
1198
|
}`;
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1199
|
+
fragMap.set(classMeta.refName, fragment);
|
|
1200
|
+
metadatas.filter((metadata) => metadata.fieldType !== "hidden" && selectKeySet.has(metadata.key) && metadata.isClass).forEach((metadata) => fragmentize(metadata.modelRef, fragMap));
|
|
1201
|
+
return fragMap;
|
|
1202
|
+
};
|
|
1203
|
+
var getPredefinedFragment = (refName) => {
|
|
1204
|
+
const fragment = Reflect.getMetadata(refName, FragmentStorage.prototype);
|
|
1205
|
+
return fragment;
|
|
1206
|
+
};
|
|
1207
|
+
var setPredefinedFragment = (refName, fragment) => {
|
|
1208
|
+
Reflect.defineMetadata(refName, fragment, FragmentStorage.prototype);
|
|
1209
|
+
};
|
|
1210
|
+
var makeFragment = (target, option = {}) => {
|
|
1211
|
+
const classMeta = (0, import_constant3.getClassMeta)(target);
|
|
1212
|
+
const fragment = getPredefinedFragment(classMeta.refName);
|
|
1213
|
+
if (fragment && !option.overwrite && !option.excludeSelf && !option.partial?.length)
|
|
1853
1214
|
return fragment;
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
return gqlStr;
|
|
1870
|
-
};
|
|
1871
|
-
var getGqlStr = (modelRef, gqlMeta, argMetas, returnRef, partial) => {
|
|
1872
|
-
const isScalar = isGqlScalar(modelRef);
|
|
1873
|
-
const argStr = makeArgStr(argMetas);
|
|
1874
|
-
const argAssignStr = makeArgAssignStr(argMetas);
|
|
1875
|
-
const returnStr = makeReturnStr(returnRef, partial);
|
|
1876
|
-
const gqlStr = `${isScalar ? "" : makeFragment(returnRef, { excludeSelf: !!partial?.length, partial })}
|
|
1877
|
-
${lowerlize(gqlMeta.type) + " " + gqlMeta.key + argStr}{
|
|
1215
|
+
const fragMap = new Map(fragmentize(target, /* @__PURE__ */ new Map(), option.partial));
|
|
1216
|
+
if (option.excludeSelf)
|
|
1217
|
+
fragMap.delete(classMeta.refName);
|
|
1218
|
+
const gqlStr = [...fragMap.values()].join("\n");
|
|
1219
|
+
if (!option.excludeSelf)
|
|
1220
|
+
setPredefinedFragment(classMeta.refName, gqlStr);
|
|
1221
|
+
return gqlStr;
|
|
1222
|
+
};
|
|
1223
|
+
var getGqlStr = (modelRef, gqlMeta, argMetas, returnRef, partial) => {
|
|
1224
|
+
const isScalar = (0, import_base3.isGqlScalar)(modelRef);
|
|
1225
|
+
const argStr = makeArgStr(argMetas);
|
|
1226
|
+
const argAssignStr = makeArgAssignStr(argMetas);
|
|
1227
|
+
const returnStr = makeReturnStr(returnRef, partial);
|
|
1228
|
+
const gqlStr = `${isScalar ? "" : makeFragment(returnRef, { excludeSelf: !!partial?.length, partial })}
|
|
1229
|
+
${(0, import_common3.lowerlize)(gqlMeta.type) + " " + gqlMeta.key + argStr}{
|
|
1878
1230
|
${gqlMeta.key}${argAssignStr}${returnStr}
|
|
1879
1231
|
}
|
|
1880
1232
|
`;
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
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
|
-
const io2 = this.client.getIo(fetchPolicy.url);
|
|
2005
|
-
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2006
|
-
io2.emit(gqlMeta.key, message);
|
|
2007
|
-
Logger.debug(`socket emit: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2008
|
-
});
|
|
2009
|
-
}
|
|
2010
|
-
};
|
|
2011
|
-
const listenEvent = function(handleEvent, fetchPolicy = {}) {
|
|
2012
|
-
const crystalize2 = (data) => {
|
|
2013
|
-
if (isScalar) {
|
|
2014
|
-
if (returnRef.prototype === Date.prototype)
|
|
2015
|
-
return dayjs(data);
|
|
2016
|
-
else
|
|
2017
|
-
return data;
|
|
2018
|
-
} else if (Array.isArray(data))
|
|
2019
|
-
return data.map((d) => crystalize2(d));
|
|
2020
|
-
else
|
|
2021
|
-
return makeCrystalize(returnRef)(data);
|
|
2022
|
-
};
|
|
2023
|
-
const handle = (data) => {
|
|
2024
|
-
Logger.debug(`socket listened: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2025
|
-
handleEvent(crystalize2(data));
|
|
2026
|
-
};
|
|
1233
|
+
return gqlStr;
|
|
1234
|
+
};
|
|
1235
|
+
var scalarSerializeMap = /* @__PURE__ */ new Map([
|
|
1236
|
+
[Date, (value) => (0, import_base3.dayjs)(value).toDate()],
|
|
1237
|
+
[String, (value) => value],
|
|
1238
|
+
[import_base3.ID, (value) => value],
|
|
1239
|
+
[Boolean, (value) => value],
|
|
1240
|
+
[import_base3.Int, (value) => value],
|
|
1241
|
+
[import_base3.Float, (value) => value],
|
|
1242
|
+
[import_base3.JSON, (value) => value]
|
|
1243
|
+
]);
|
|
1244
|
+
var getSerializeFn = (inputRef) => {
|
|
1245
|
+
const serializeFn = scalarSerializeMap.get(inputRef);
|
|
1246
|
+
if (!serializeFn)
|
|
1247
|
+
return (value) => value;
|
|
1248
|
+
else
|
|
1249
|
+
return serializeFn;
|
|
1250
|
+
};
|
|
1251
|
+
var serializeInput = (value, inputRef, arrDepth) => {
|
|
1252
|
+
if (arrDepth && Array.isArray(value))
|
|
1253
|
+
return value.map((v) => serializeInput(v, inputRef, arrDepth - 1));
|
|
1254
|
+
else if (inputRef.prototype === Map.prototype) {
|
|
1255
|
+
const [valueRef] = (0, import_base3.getNonArrayModel)(inputRef);
|
|
1256
|
+
const serializeFn = getSerializeFn(valueRef);
|
|
1257
|
+
return Object.fromEntries(
|
|
1258
|
+
[...value.entries()].map(([key, val]) => [key, (0, import_base3.applyFnToArrayObjects)(val, serializeFn)])
|
|
1259
|
+
);
|
|
1260
|
+
} else if ((0, import_base3.isGqlScalar)(inputRef)) {
|
|
1261
|
+
const serializeFn = getSerializeFn(inputRef);
|
|
1262
|
+
return serializeFn(value);
|
|
1263
|
+
}
|
|
1264
|
+
const classMeta = (0, import_constant3.getClassMeta)(inputRef);
|
|
1265
|
+
if (classMeta.type !== "scalar")
|
|
1266
|
+
return value;
|
|
1267
|
+
else
|
|
1268
|
+
return Object.fromEntries(
|
|
1269
|
+
(0, import_constant3.getFieldMetas)(inputRef).map((fieldMeta) => [
|
|
1270
|
+
fieldMeta.key,
|
|
1271
|
+
serializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
|
|
1272
|
+
])
|
|
1273
|
+
);
|
|
1274
|
+
};
|
|
1275
|
+
var serializeArg = (argMeta, value) => {
|
|
1276
|
+
const [returnRef, arrDepth] = (0, import_base3.getNonArrayModel)(argMeta.returns());
|
|
1277
|
+
if (argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
1278
|
+
return null;
|
|
1279
|
+
else if (!argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
1280
|
+
throw new Error(`Invalid Value (Nullable) in ${argMeta.name} for value ${value}`);
|
|
1281
|
+
return serializeInput(value, returnRef, arrDepth);
|
|
1282
|
+
};
|
|
1283
|
+
var scalarDeserializeMap = /* @__PURE__ */ new Map([
|
|
1284
|
+
[Date, (value) => (0, import_base3.dayjs)(value)],
|
|
1285
|
+
[String, (value) => value],
|
|
1286
|
+
[import_base3.ID, (value) => value],
|
|
1287
|
+
[Boolean, (value) => value],
|
|
1288
|
+
[import_base3.Int, (value) => value],
|
|
1289
|
+
[import_base3.Float, (value) => value],
|
|
1290
|
+
[import_base3.JSON, (value) => value]
|
|
1291
|
+
]);
|
|
1292
|
+
var getDeserializeFn = (inputRef) => {
|
|
1293
|
+
const deserializeFn = scalarDeserializeMap.get(inputRef);
|
|
1294
|
+
if (!deserializeFn)
|
|
1295
|
+
return (value) => value;
|
|
1296
|
+
return deserializeFn;
|
|
1297
|
+
};
|
|
1298
|
+
var deserializeInput = (value, inputRef, arrDepth) => {
|
|
1299
|
+
if (arrDepth && Array.isArray(value))
|
|
1300
|
+
return value.map((v) => deserializeInput(v, inputRef, arrDepth - 1));
|
|
1301
|
+
else if (inputRef.prototype === Map.prototype) {
|
|
1302
|
+
const [valueRef] = (0, import_base3.getNonArrayModel)(inputRef);
|
|
1303
|
+
const deserializeFn = getDeserializeFn(valueRef);
|
|
1304
|
+
return Object.fromEntries(
|
|
1305
|
+
[...value.entries()].map(([key, val]) => [key, (0, import_base3.applyFnToArrayObjects)(val, deserializeFn)])
|
|
1306
|
+
);
|
|
1307
|
+
} else if ((0, import_base3.isGqlScalar)(inputRef)) {
|
|
1308
|
+
const deserializeFn = getDeserializeFn(inputRef);
|
|
1309
|
+
return deserializeFn(value);
|
|
1310
|
+
}
|
|
1311
|
+
const classMeta = (0, import_constant3.getClassMeta)(inputRef);
|
|
1312
|
+
if (classMeta.type !== "scalar")
|
|
1313
|
+
return value;
|
|
1314
|
+
else
|
|
1315
|
+
return Object.fromEntries(
|
|
1316
|
+
(0, import_constant3.getFieldMetas)(inputRef).map((fieldMeta) => [
|
|
1317
|
+
fieldMeta.key,
|
|
1318
|
+
deserializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
|
|
1319
|
+
])
|
|
1320
|
+
);
|
|
1321
|
+
};
|
|
1322
|
+
var deserializeArg = (argMeta, value) => {
|
|
1323
|
+
const [returnRef, arrDepth] = (0, import_base3.getNonArrayModel)(argMeta.returns());
|
|
1324
|
+
if (argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
1325
|
+
return null;
|
|
1326
|
+
else if (!argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
1327
|
+
throw new Error(`Invalid Value (Nullable) in ${argMeta.name} for value ${value}`);
|
|
1328
|
+
return deserializeInput(value, returnRef, arrDepth);
|
|
1329
|
+
};
|
|
1330
|
+
var fetchOf = (sigRef) => {
|
|
1331
|
+
const gqls = {};
|
|
1332
|
+
const gqlMetas = getGqlMetas(sigRef);
|
|
1333
|
+
gqlMetas.filter((gqlMeta) => !gqlMeta.signalOption.default).forEach((gqlMeta) => {
|
|
1334
|
+
if (gqlMeta.type === "Message") {
|
|
1335
|
+
const [returnRef, arrDepth] = (0, import_base3.getNonArrayModel)(gqlMeta.returns());
|
|
1336
|
+
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
1337
|
+
const isScalar = (0, import_base3.isGqlScalar)(returnRef);
|
|
1338
|
+
const emitEvent = function(...args) {
|
|
1339
|
+
const fetchPolicy = args[argMetas.length] ?? { crystalize: true };
|
|
1340
|
+
if (!this.client.io && !fetchPolicy.url) {
|
|
1341
|
+
import_common3.Logger.warn(`${gqlMeta.key} emit suppressed - socket is not connected`);
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
const message = Object.fromEntries(
|
|
1345
|
+
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
1346
|
+
);
|
|
1347
|
+
if (fetchPolicy.transport === "udp") {
|
|
1348
|
+
if (!this.client.udp)
|
|
1349
|
+
throw new Error("UDP is not set");
|
|
1350
|
+
const uri = fetchPolicy.url ?? "udpout:localhost:4000";
|
|
1351
|
+
const [host, port] = uri.split(":").slice(1);
|
|
1352
|
+
this.client.udp.send(JSON.stringify(message), parseInt(port), host);
|
|
1353
|
+
import_common3.Logger.debug(`udp emit: ${gqlMeta.key}: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
1354
|
+
return;
|
|
1355
|
+
} else {
|
|
2027
1356
|
const io2 = this.client.getIo(fetchPolicy.url);
|
|
2028
|
-
this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2029
|
-
io2.
|
|
2030
|
-
|
|
2031
|
-
Logger.debug(`socket listen start: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
1357
|
+
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
1358
|
+
io2.emit(gqlMeta.key, message);
|
|
1359
|
+
import_common3.Logger.debug(`socket emit: ${gqlMeta.key}: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2032
1360
|
});
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
io2.removeListener(gqlMeta.key, handle);
|
|
2037
|
-
};
|
|
2038
|
-
};
|
|
2039
|
-
gqls[gqlMeta.key] = emitEvent;
|
|
2040
|
-
gqls[`listen${capitalize(gqlMeta.key)}`] = listenEvent;
|
|
2041
|
-
} else if (gqlMeta.type === "Pubsub") {
|
|
2042
|
-
const [returnRef] = getNonArrayModel(gqlMeta.returns());
|
|
2043
|
-
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
2044
|
-
const isScalar = isGqlScalar(returnRef);
|
|
2045
|
-
const makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
const listenEvent = function(handleEvent, fetchPolicy = {}) {
|
|
2046
1364
|
const crystalize2 = (data) => {
|
|
2047
1365
|
if (isScalar) {
|
|
2048
1366
|
if (returnRef.prototype === Date.prototype)
|
|
2049
|
-
return dayjs(data);
|
|
1367
|
+
return (0, import_base3.dayjs)(data);
|
|
2050
1368
|
else
|
|
2051
1369
|
return data;
|
|
2052
1370
|
} else if (Array.isArray(data))
|
|
@@ -2054,202 +1372,236 @@ ${lowerlize(gqlMeta.type) + " " + gqlMeta.key + argStr}{
|
|
|
2054
1372
|
else
|
|
2055
1373
|
return makeCrystalize(returnRef)(data);
|
|
2056
1374
|
};
|
|
2057
|
-
const
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
const message = Object.fromEntries(
|
|
2061
|
-
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
2062
|
-
);
|
|
2063
|
-
const handleEvent = (data) => {
|
|
2064
|
-
if (data.__subscribe__)
|
|
2065
|
-
return;
|
|
2066
|
-
onData(crystalize2(data));
|
|
2067
|
-
};
|
|
2068
|
-
const roomId = makeRoomId(
|
|
2069
|
-
gqlMeta.key,
|
|
2070
|
-
argMetas.map((argMeta) => message[argMeta.name])
|
|
2071
|
-
);
|
|
2072
|
-
const io2 = this.client.getIo(fetchPolicy.url);
|
|
2073
|
-
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2074
|
-
Logger.debug(`socket subscribe start: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2075
|
-
io2.subscribe({ key: gqlMeta.key, roomId, message, handleEvent });
|
|
2076
|
-
});
|
|
2077
|
-
return async () => {
|
|
2078
|
-
await this.client.waitUntilWebSocketConnected(fetchPolicy.url);
|
|
2079
|
-
Logger.debug(`socket unsubscribe: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2080
|
-
io2.unsubscribe(roomId, handleEvent);
|
|
2081
|
-
};
|
|
1375
|
+
const handle = (data) => {
|
|
1376
|
+
import_common3.Logger.debug(`socket listened: ${gqlMeta.key}: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
1377
|
+
handleEvent(crystalize2(data));
|
|
2082
1378
|
};
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
Logger.debug(`
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
};
|
|
2108
|
-
try {
|
|
2109
|
-
const res = (await (gqlMeta.type === "Query" ? query : mutate)(
|
|
2110
|
-
this.client,
|
|
2111
|
-
graphql(getGqlStr(modelRef, gqlMeta, argMetas, returnRef, partial)),
|
|
2112
|
-
Object.fromEntries(
|
|
2113
|
-
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
2114
|
-
),
|
|
2115
|
-
fetchPolicy
|
|
2116
|
-
))[name];
|
|
2117
|
-
const data = resolve2 ? crystalize2(res) : res;
|
|
2118
|
-
Logger.debug(
|
|
2119
|
-
`fetch: ${gqlMeta.key} end: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")} ${Date.now() - now}ms`
|
|
2120
|
-
);
|
|
1379
|
+
const io2 = this.client.getIo(fetchPolicy.url);
|
|
1380
|
+
this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
1381
|
+
io2.removeListener(gqlMeta.key, handle);
|
|
1382
|
+
io2.on(gqlMeta.key, handle);
|
|
1383
|
+
import_common3.Logger.debug(`socket listen start: ${gqlMeta.key}: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
1384
|
+
});
|
|
1385
|
+
return async () => {
|
|
1386
|
+
await this.client.waitUntilWebSocketConnected(fetchPolicy.url);
|
|
1387
|
+
import_common3.Logger.debug(`socket listen end: ${gqlMeta.key}: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
1388
|
+
io2.removeListener(gqlMeta.key, handle);
|
|
1389
|
+
};
|
|
1390
|
+
};
|
|
1391
|
+
gqls[gqlMeta.key] = emitEvent;
|
|
1392
|
+
gqls[`listen${(0, import_common3.capitalize)(gqlMeta.key)}`] = listenEvent;
|
|
1393
|
+
} else if (gqlMeta.type === "Pubsub") {
|
|
1394
|
+
const [returnRef] = (0, import_base3.getNonArrayModel)(gqlMeta.returns());
|
|
1395
|
+
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
1396
|
+
const isScalar = (0, import_base3.isGqlScalar)(returnRef);
|
|
1397
|
+
const makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
1398
|
+
const crystalize2 = (data) => {
|
|
1399
|
+
if (isScalar) {
|
|
1400
|
+
if (returnRef.prototype === Date.prototype)
|
|
1401
|
+
return (0, import_base3.dayjs)(data);
|
|
1402
|
+
else
|
|
2121
1403
|
return data;
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
1404
|
+
} else if (Array.isArray(data))
|
|
1405
|
+
return data.map((d) => crystalize2(d));
|
|
1406
|
+
else
|
|
1407
|
+
return makeCrystalize(returnRef)(data);
|
|
1408
|
+
};
|
|
1409
|
+
const subscribeEvent = function(...args) {
|
|
1410
|
+
const onData = args[argMetas.length];
|
|
1411
|
+
const fetchPolicy = args[argMetas.length + 1] ?? { crystalize: true };
|
|
1412
|
+
const message = Object.fromEntries(
|
|
1413
|
+
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
1414
|
+
);
|
|
1415
|
+
const handleEvent = (data) => {
|
|
1416
|
+
if (data.__subscribe__)
|
|
1417
|
+
return;
|
|
1418
|
+
onData(crystalize2(data));
|
|
2126
1419
|
};
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
1420
|
+
const roomId = makeRoomId(
|
|
1421
|
+
gqlMeta.key,
|
|
1422
|
+
argMetas.map((argMeta) => message[argMeta.name])
|
|
1423
|
+
);
|
|
1424
|
+
const io2 = this.client.getIo(fetchPolicy.url);
|
|
1425
|
+
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
1426
|
+
import_common3.Logger.debug(`socket subscribe start: ${gqlMeta.key}: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
1427
|
+
io2.subscribe({ key: gqlMeta.key, roomId, message, handleEvent });
|
|
1428
|
+
});
|
|
1429
|
+
return async () => {
|
|
1430
|
+
await this.client.waitUntilWebSocketConnected(fetchPolicy.url);
|
|
1431
|
+
import_common3.Logger.debug(`socket unsubscribe: ${gqlMeta.key}: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
1432
|
+
io2.unsubscribe(roomId, handleEvent);
|
|
1433
|
+
};
|
|
1434
|
+
};
|
|
1435
|
+
gqls[`subscribe${(0, import_common3.capitalize)(gqlMeta.key)}`] = subscribeEvent;
|
|
1436
|
+
} else if (gqlMeta.type === "Query" || gqlMeta.type === "Mutation") {
|
|
1437
|
+
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
1438
|
+
const makeReq = ({ resolve: resolve2 }) => async function(...args) {
|
|
1439
|
+
import_common3.Logger.debug(`fetch: ${gqlMeta.key} start: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
1440
|
+
const now = Date.now();
|
|
1441
|
+
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
1442
|
+
const [modelRef, arrDepth] = (0, import_base3.getNonArrayModel)(gqlMeta.returns());
|
|
1443
|
+
const isScalar = (0, import_base3.isGqlScalar)(modelRef);
|
|
1444
|
+
const returnRef = isScalar || !arrDepth ? modelRef : (0, import_constant3.getLightModelRef)(modelRef);
|
|
1445
|
+
const fetchPolicy = args[argMetas.length] ?? { crystalize: true };
|
|
1446
|
+
const partial = fetchPolicy.partial ?? gqlMeta.signalOption.partial;
|
|
1447
|
+
const crystalize2 = (data) => {
|
|
1448
|
+
if (fetchPolicy.crystalize === false)
|
|
1449
|
+
return data;
|
|
1450
|
+
if (isScalar) {
|
|
1451
|
+
if (returnRef.prototype === Date.prototype)
|
|
1452
|
+
return (0, import_base3.dayjs)(data);
|
|
1453
|
+
else
|
|
1454
|
+
return data;
|
|
1455
|
+
} else if (Array.isArray(data))
|
|
1456
|
+
return data.map((d) => crystalize2(d));
|
|
1457
|
+
else
|
|
1458
|
+
return makeCrystalize(returnRef, { partial })(data);
|
|
1459
|
+
};
|
|
1460
|
+
try {
|
|
1461
|
+
const res = (await (gqlMeta.type === "Query" ? query : mutate)(
|
|
1462
|
+
this.client,
|
|
1463
|
+
graphql(getGqlStr(modelRef, gqlMeta, argMetas, returnRef, partial)),
|
|
1464
|
+
Object.fromEntries(
|
|
1465
|
+
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
1466
|
+
),
|
|
1467
|
+
fetchPolicy
|
|
1468
|
+
))[name];
|
|
1469
|
+
const data = resolve2 ? crystalize2(res) : res;
|
|
1470
|
+
import_common3.Logger.debug(
|
|
1471
|
+
`fetch: ${gqlMeta.key} end: ${(0, import_base3.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")} ${Date.now() - now}ms`
|
|
1472
|
+
);
|
|
1473
|
+
return data;
|
|
1474
|
+
} catch (e) {
|
|
1475
|
+
import_common3.Logger.error(`fetch: ${gqlMeta.key} error: ${e}`);
|
|
1476
|
+
throw e;
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
gqls[name] = makeReq({ resolve: true });
|
|
1480
|
+
gqls[`_${name}`] = makeReq({ resolve: false });
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1483
|
+
return gqls;
|
|
1484
|
+
};
|
|
1485
|
+
var makeFetch = (fetch1, fetch2, fetch3, fetch4, fetch5, fetch6, fetch7, fetch8, fetch9, fetch10) => {
|
|
1486
|
+
return Object.assign(fetch1, fetch2, fetch3, fetch4, fetch5, fetch6, fetch7, fetch8, fetch9, fetch10);
|
|
1487
|
+
};
|
|
1488
|
+
var makeArgStr = (argMetas) => {
|
|
1489
|
+
return argMetas.length ? `(${argMetas.map((argMeta) => {
|
|
1490
|
+
const [argRef, arrDepth] = (0, import_base3.getNonArrayModel)(argMeta.returns());
|
|
1491
|
+
const argRefType = (0, import_base3.isGqlScalar)(argRef) ? "gqlScalar" : (0, import_constant3.getClassMeta)(argRef).type === "scalar" ? "scalar" : "model";
|
|
1492
|
+
const gqlTypeStr = "[".repeat(arrDepth) + ((0, import_constant3.getGqlTypeStr)(argRef) + (argRefType === "scalar" ? "Input" : "")) + "!]".repeat(arrDepth);
|
|
1493
|
+
return `$${argMeta.name}: ` + gqlTypeStr + (argMeta.argsOption.nullable ? "" : "!");
|
|
1494
|
+
}).join(", ")})` : "";
|
|
1495
|
+
};
|
|
1496
|
+
var makeArgAssignStr = (argMetas) => {
|
|
1497
|
+
return argMetas.length ? `(${argMetas.map((argMeta) => `${argMeta.name}: $${argMeta.name}`).join(", ")})` : "";
|
|
1498
|
+
};
|
|
1499
|
+
var makeReturnStr = (returnRef, partial) => {
|
|
1500
|
+
const isScalar = (0, import_base3.isGqlScalar)(returnRef);
|
|
1501
|
+
if (isScalar)
|
|
1502
|
+
return "";
|
|
1503
|
+
const classMeta = (0, import_constant3.getClassMeta)(returnRef);
|
|
1504
|
+
if (!partial?.length)
|
|
2158
1505
|
return ` {
|
|
1506
|
+
...${(0, import_common3.lowerlize)(classMeta.refName)}Fragment
|
|
1507
|
+
}`;
|
|
1508
|
+
const targetKeys = classMeta.type === "scalar" ? partial : [.../* @__PURE__ */ new Set(["id", ...partial, "updatedAt"])];
|
|
1509
|
+
const fieldMetaMap = (0, import_constant3.getFieldMetaMap)(returnRef);
|
|
1510
|
+
return ` {
|
|
2159
1511
|
${targetKeys.map((key) => fieldMetaMap.get(key)).filter((metadata) => metadata && metadata.fieldType !== "hidden").map(
|
|
2160
|
-
|
|
2161
|
-
...${lowerlize(fieldMeta.name)}Fragment
|
|
1512
|
+
(fieldMeta) => fieldMeta.isClass ? ` ${fieldMeta.key} {
|
|
1513
|
+
...${(0, import_common3.lowerlize)(fieldMeta.name)}Fragment
|
|
2162
1514
|
}` : ` ${fieldMeta.key}`
|
|
2163
|
-
|
|
1515
|
+
).join("\n")}
|
|
2164
1516
|
}`;
|
|
2165
|
-
|
|
1517
|
+
};
|
|
2166
1518
|
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
1519
|
+
// pkgs/@akanjs/signal/src/doc.ts
|
|
1520
|
+
var import_base4 = require("@akanjs/base");
|
|
1521
|
+
var import_constant4 = require("@akanjs/constant");
|
|
1522
|
+
var ResponseExampleStorage = class {
|
|
1523
|
+
};
|
|
1524
|
+
var getPredefinedRequestExample = (modelRef) => {
|
|
1525
|
+
return Reflect.getMetadata(modelRef, ResponseExampleStorage.prototype);
|
|
1526
|
+
};
|
|
1527
|
+
var getResponseExample = (ref) => {
|
|
1528
|
+
const [modelRef, arrDepth] = (0, import_base4.getNonArrayModel)(ref);
|
|
1529
|
+
const existing = getPredefinedRequestExample(modelRef);
|
|
1530
|
+
if (existing)
|
|
1531
|
+
return existing;
|
|
1532
|
+
const isScalar = (0, import_base4.isGqlScalar)(modelRef);
|
|
1533
|
+
if (isScalar)
|
|
1534
|
+
return (0, import_base4.arraiedModel)((0, import_constant4.getScalarExample)(modelRef), arrDepth);
|
|
1535
|
+
const fieldMetas = (0, import_constant4.getFieldMetas)(modelRef);
|
|
1536
|
+
const example = {};
|
|
1537
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
1538
|
+
if (fieldMeta.example)
|
|
1539
|
+
example[fieldMeta.key] = fieldMeta.example;
|
|
1540
|
+
else if (fieldMeta.enum)
|
|
1541
|
+
example[fieldMeta.key] = (0, import_base4.arraiedModel)(fieldMeta.enum.values[0], fieldMeta.arrDepth);
|
|
1542
|
+
else
|
|
1543
|
+
example[fieldMeta.key] = getResponseExample(fieldMeta.modelRef);
|
|
1544
|
+
});
|
|
1545
|
+
const result = (0, import_base4.arraiedModel)(example, arrDepth);
|
|
1546
|
+
Reflect.defineMetadata(ref, result, ResponseExampleStorage.prototype);
|
|
1547
|
+
return result;
|
|
1548
|
+
};
|
|
1549
|
+
var RequestExampleStorage = class {
|
|
1550
|
+
};
|
|
1551
|
+
var getRequestExample = (ref) => {
|
|
1552
|
+
const existing = getPredefinedRequestExample(ref);
|
|
1553
|
+
if (existing)
|
|
1554
|
+
return existing;
|
|
1555
|
+
const fieldMetas = (0, import_constant4.getFieldMetas)(ref);
|
|
1556
|
+
const example = {};
|
|
1557
|
+
const isScalar = (0, import_base4.isGqlScalar)(ref);
|
|
1558
|
+
if (isScalar)
|
|
1559
|
+
return (0, import_constant4.getScalarExample)(ref);
|
|
1560
|
+
else {
|
|
2183
1561
|
fieldMetas.forEach((fieldMeta) => {
|
|
2184
|
-
if (fieldMeta.
|
|
2185
|
-
example[fieldMeta.key] =
|
|
2186
|
-
else if (fieldMeta.enum)
|
|
2187
|
-
example[fieldMeta.key] = arraiedModel(fieldMeta.enum.values[0], fieldMeta.arrDepth);
|
|
1562
|
+
if (!fieldMeta.isScalar && fieldMeta.isClass)
|
|
1563
|
+
example[fieldMeta.key] = "ObjectID";
|
|
2188
1564
|
else
|
|
2189
|
-
example[fieldMeta.key] =
|
|
1565
|
+
example[fieldMeta.key] = fieldMeta.example ?? fieldMeta.enum ? (0, import_base4.arraiedModel)(fieldMeta.example ?? (fieldMeta.enum?.values)[0], fieldMeta.optArrDepth) : (0, import_base4.arraiedModel)(getRequestExample(fieldMeta.modelRef), fieldMeta.arrDepth);
|
|
2190
1566
|
});
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
const
|
|
2202
|
-
const example =
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
var makeRequestExample = (sigRef, key) => {
|
|
2218
|
-
const [argMetas] = getArgMetas(sigRef, key);
|
|
2219
|
-
return getExampleData(argMetas);
|
|
2220
|
-
};
|
|
2221
|
-
var getExampleData = (argMetas, signalType = "graphql") => Object.fromEntries(
|
|
2222
|
-
argMetas.filter((argMeta) => argMeta.type !== "Upload").map((argMeta) => {
|
|
2223
|
-
const [argRef, argArrDepth] = getNonArrayModel(argMeta.returns());
|
|
2224
|
-
const example = argMeta.argsOption.example ?? getRequestExample(argRef);
|
|
2225
|
-
return [
|
|
2226
|
-
argMeta.name,
|
|
2227
|
-
arraiedModel(
|
|
2228
|
-
signalType === "restapi" && argRef.prototype === JSON2.prototype ? JSON.stringify(example, null, 2) : example,
|
|
2229
|
-
argArrDepth
|
|
2230
|
-
)
|
|
2231
|
-
];
|
|
2232
|
-
})
|
|
2233
|
-
);
|
|
2234
|
-
var makeResponseExample = (sigRef, key) => {
|
|
2235
|
-
const gqlMeta = getGqlMeta(sigRef, key);
|
|
2236
|
-
const example = getResponseExample(gqlMeta.returns());
|
|
2237
|
-
return example;
|
|
2238
|
-
};
|
|
1567
|
+
}
|
|
1568
|
+
Reflect.defineMetadata(ref, example, RequestExampleStorage.prototype);
|
|
1569
|
+
return example;
|
|
1570
|
+
};
|
|
1571
|
+
var makeRequestExample = (sigRef, key) => {
|
|
1572
|
+
const [argMetas] = getArgMetas(sigRef, key);
|
|
1573
|
+
return getExampleData(argMetas);
|
|
1574
|
+
};
|
|
1575
|
+
var getExampleData = (argMetas, signalType = "graphql") => Object.fromEntries(
|
|
1576
|
+
argMetas.filter((argMeta) => argMeta.type !== "Upload").map((argMeta) => {
|
|
1577
|
+
const [argRef, argArrDepth] = (0, import_base4.getNonArrayModel)(argMeta.returns());
|
|
1578
|
+
const example = argMeta.argsOption.example ?? getRequestExample(argRef);
|
|
1579
|
+
return [
|
|
1580
|
+
argMeta.name,
|
|
1581
|
+
(0, import_base4.arraiedModel)(
|
|
1582
|
+
signalType === "restapi" && argRef.prototype === import_base4.JSON.prototype ? JSON.stringify(example, null, 2) : example,
|
|
1583
|
+
argArrDepth
|
|
1584
|
+
)
|
|
1585
|
+
];
|
|
1586
|
+
})
|
|
1587
|
+
);
|
|
1588
|
+
var makeResponseExample = (sigRef, key) => {
|
|
1589
|
+
const gqlMeta = getGqlMeta(sigRef, key);
|
|
1590
|
+
const example = getResponseExample(gqlMeta.returns());
|
|
1591
|
+
return example;
|
|
1592
|
+
};
|
|
2239
1593
|
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
})();
|
|
2253
|
-
//! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
|
|
1594
|
+
// pkgs/@akanjs/signal/src/baseFetch.ts
|
|
1595
|
+
var nativeFetch = fetch;
|
|
1596
|
+
var baseFetch = Object.assign(nativeFetch, {
|
|
1597
|
+
client,
|
|
1598
|
+
clone: function(option = {}) {
|
|
1599
|
+
return {
|
|
1600
|
+
...this,
|
|
1601
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
1602
|
+
client: this.client.clone(option)
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
2254
1606
|
//! 임시 적용 테스트
|
|
2255
1607
|
//! 앱에서 다른 앱 넘어갈 때 언마운트 되버리면서 subscribe가 끊기는 일이 있음.
|