@akanjs/signal 0.0.46 → 0.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -1592
- package/package.json +1 -1
- package/src/baseFetch.js +34 -0
- package/src/client.js +164 -0
- package/src/doc.js +101 -0
- package/src/gql.js +850 -0
- package/src/immerify.js +35 -0
- package/src/index.js +30 -0
- package/src/signalDecorators.js +520 -0
package/index.js
CHANGED
|
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
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
5
|
var __copyProps = (to, from, except, desc) => {
|
|
10
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,1594 +10,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
10
|
}
|
|
15
11
|
return to;
|
|
16
12
|
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
14
|
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);
|
|
28
|
-
|
|
29
|
-
// pkgs/@akanjs/signal/index.ts
|
|
30
15
|
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
16
|
module.exports = __toCommonJS(signal_exports);
|
|
104
|
-
|
|
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 });
|
|
118
|
-
});
|
|
119
|
-
});
|
|
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 });
|
|
140
|
-
}
|
|
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);
|
|
165
|
-
}
|
|
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
|
-
};
|
|
220
|
-
}
|
|
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();
|
|
248
|
-
|
|
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
|
-
};
|
|
263
|
-
|
|
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");
|
|
268
|
-
|
|
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
|
-
}
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
var createArgMetaDecorator = (type) => {
|
|
365
|
-
return function(option = {}) {
|
|
366
|
-
return function(prototype, key, idx) {
|
|
367
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
368
|
-
argMetas[idx] = { key, idx, type, option };
|
|
369
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
370
|
-
};
|
|
371
|
-
};
|
|
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);
|
|
503
|
-
};
|
|
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 {
|
|
529
|
-
}
|
|
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);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
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 {
|
|
692
|
-
}
|
|
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);
|
|
707
|
-
}
|
|
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]: {
|
|
841
|
-
refName: names.model,
|
|
842
|
-
[names.modelObj]: modelObj,
|
|
843
|
-
[names.modelViewAt]: /* @__PURE__ */ new Date()
|
|
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;
|
|
905
|
-
return {
|
|
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()
|
|
918
|
-
};
|
|
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
|
|
934
|
-
};
|
|
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];
|
|
976
|
-
else
|
|
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}` } : {}
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
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}` } : {}
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
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);
|
|
1117
|
-
return null;
|
|
1118
|
-
}
|
|
1119
|
-
};
|
|
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]);
|
|
1172
|
-
}
|
|
1173
|
-
return result;
|
|
1174
|
-
} catch (err) {
|
|
1175
|
-
if (isChild)
|
|
1176
|
-
throw new Error(err);
|
|
1177
|
-
return null;
|
|
1178
|
-
}
|
|
1179
|
-
};
|
|
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
|
-
)} {
|
|
1192
|
-
` + metadatas.filter((metadata) => metadata.fieldType !== "hidden" && selectKeySet.has(metadata.key)).map((metadata) => {
|
|
1193
|
-
return metadata.isClass ? ` ${metadata.key} {
|
|
1194
|
-
...${(0, import_common3.lowerlize)(metadata.name)}Fragment
|
|
1195
|
-
}` : ` ${metadata.key}`;
|
|
1196
|
-
}).join(`
|
|
1197
|
-
`) + `
|
|
1198
|
-
}`;
|
|
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)
|
|
1214
|
-
return fragment;
|
|
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}{
|
|
1230
|
-
${gqlMeta.key}${argAssignStr}${returnStr}
|
|
1231
|
-
}
|
|
1232
|
-
`;
|
|
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 {
|
|
1356
|
-
const io2 = this.client.getIo(fetchPolicy.url);
|
|
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")}`);
|
|
1360
|
-
});
|
|
1361
|
-
}
|
|
1362
|
-
};
|
|
1363
|
-
const listenEvent = function(handleEvent, fetchPolicy = {}) {
|
|
1364
|
-
const crystalize2 = (data) => {
|
|
1365
|
-
if (isScalar) {
|
|
1366
|
-
if (returnRef.prototype === Date.prototype)
|
|
1367
|
-
return (0, import_base3.dayjs)(data);
|
|
1368
|
-
else
|
|
1369
|
-
return data;
|
|
1370
|
-
} else if (Array.isArray(data))
|
|
1371
|
-
return data.map((d) => crystalize2(d));
|
|
1372
|
-
else
|
|
1373
|
-
return makeCrystalize(returnRef)(data);
|
|
1374
|
-
};
|
|
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));
|
|
1378
|
-
};
|
|
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
|
|
1403
|
-
return data;
|
|
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));
|
|
1419
|
-
};
|
|
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)
|
|
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 ` {
|
|
1511
|
-
${targetKeys.map((key) => fieldMetaMap.get(key)).filter((metadata) => metadata && metadata.fieldType !== "hidden").map(
|
|
1512
|
-
(fieldMeta) => fieldMeta.isClass ? ` ${fieldMeta.key} {
|
|
1513
|
-
...${(0, import_common3.lowerlize)(fieldMeta.name)}Fragment
|
|
1514
|
-
}` : ` ${fieldMeta.key}`
|
|
1515
|
-
).join("\n")}
|
|
1516
|
-
}`;
|
|
1517
|
-
};
|
|
1518
|
-
|
|
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 {
|
|
1561
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
1562
|
-
if (!fieldMeta.isScalar && fieldMeta.isClass)
|
|
1563
|
-
example[fieldMeta.key] = "ObjectID";
|
|
1564
|
-
else
|
|
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);
|
|
1566
|
-
});
|
|
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
|
-
};
|
|
1593
|
-
|
|
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
|
-
});
|
|
1606
|
-
//! 임시 적용 테스트
|
|
1607
|
-
//! 앱에서 다른 앱 넘어갈 때 언마운트 되버리면서 subscribe가 끊기는 일이 있음.
|
|
17
|
+
__reExport(signal_exports, require("./src"), module.exports);
|