@akanjs/server 0.0.45 → 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 +390 -2884
- package/package.json +2 -23
package/index.js
CHANGED
|
@@ -35,2264 +35,189 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
35
35
|
return result;
|
|
36
36
|
};
|
|
37
37
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
38
|
-
var __accessCheck = (obj, member, msg) => {
|
|
39
|
-
if (!member.has(obj))
|
|
40
|
-
throw TypeError("Cannot " + msg);
|
|
41
|
-
};
|
|
42
|
-
var __privateGet = (obj, member, getter) => {
|
|
43
|
-
__accessCheck(obj, member, "read from private field");
|
|
44
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
45
|
-
};
|
|
46
|
-
var __privateAdd = (obj, member, value) => {
|
|
47
|
-
if (member.has(obj))
|
|
48
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
49
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
50
|
-
};
|
|
51
|
-
var __privateMethod = (obj, member, method) => {
|
|
52
|
-
__accessCheck(obj, member, "access private method");
|
|
53
|
-
return method;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// pkgs/@akanjs/server/index.ts
|
|
57
|
-
var server_exports = {};
|
|
58
|
-
__export(server_exports, {
|
|
59
|
-
DateScalar: () => DateScalar,
|
|
60
|
-
SearchDaemonModule: () => SearchDaemonModule,
|
|
61
|
-
addSchema: () => addSchema,
|
|
62
|
-
applyNestField: () => applyNestField,
|
|
63
|
-
batchModuleOf: () => batchModuleOf,
|
|
64
|
-
controllerOf: () => controllerOf,
|
|
65
|
-
createNestApp: () => createNestApp,
|
|
66
|
-
databaseModuleOf: () => databaseModuleOf,
|
|
67
|
-
generateGql: () => generateGql,
|
|
68
|
-
generateGqlInput: () => generateGqlInput,
|
|
69
|
-
makeTextFilter: () => makeTextFilter,
|
|
70
|
-
processorOf: () => processorOf,
|
|
71
|
-
queueOf: () => queueOf,
|
|
72
|
-
resolverOf: () => resolverOf,
|
|
73
|
-
scalarModuleOf: () => scalarModuleOf,
|
|
74
|
-
scalarModulesOf: () => scalarModulesOf,
|
|
75
|
-
schemaOf: () => schemaOf,
|
|
76
|
-
serviceModuleOf: () => serviceModuleOf,
|
|
77
|
-
useGlobals: () => useGlobals,
|
|
78
|
-
websocketOf: () => websocketOf,
|
|
79
|
-
websocketServerOf: () => websocketServerOf
|
|
80
|
-
});
|
|
81
|
-
module.exports = __toCommonJS(server_exports);
|
|
82
|
-
|
|
83
|
-
// pkgs/@akanjs/base/src/base.ts
|
|
84
|
-
var Enum = class {
|
|
85
|
-
constructor(values) {
|
|
86
|
-
this.values = values;
|
|
87
|
-
this.valueMap = new Map(values.map((value, idx) => [value, idx]));
|
|
88
|
-
}
|
|
89
|
-
value;
|
|
90
|
-
// for type
|
|
91
|
-
valueMap;
|
|
92
|
-
has(value) {
|
|
93
|
-
return this.valueMap.has(value);
|
|
94
|
-
}
|
|
95
|
-
indexOf(value) {
|
|
96
|
-
const idx = this.valueMap.get(value);
|
|
97
|
-
if (idx === void 0)
|
|
98
|
-
throw new Error(`Value ${value} is not in enum`);
|
|
99
|
-
return idx;
|
|
100
|
-
}
|
|
101
|
-
find(callback) {
|
|
102
|
-
const val = this.values.find(callback);
|
|
103
|
-
if (val === void 0)
|
|
104
|
-
throw new Error(`Value not found in enum`);
|
|
105
|
-
return val;
|
|
106
|
-
}
|
|
107
|
-
findIndex(callback) {
|
|
108
|
-
const idx = this.values.findIndex(callback);
|
|
109
|
-
if (idx === -1)
|
|
110
|
-
throw new Error(`Value not found in enum`);
|
|
111
|
-
return idx;
|
|
112
|
-
}
|
|
113
|
-
filter(callback) {
|
|
114
|
-
return this.values.filter(callback);
|
|
115
|
-
}
|
|
116
|
-
map(callback) {
|
|
117
|
-
return this.values.map(callback);
|
|
118
|
-
}
|
|
119
|
-
forEach(callback) {
|
|
120
|
-
this.values.forEach(callback);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var version = "0.9.0";
|
|
124
|
-
var logo = `
|
|
125
|
-
_ _ _
|
|
126
|
-
/ \\ | | ____ _ _ __ (_)___
|
|
127
|
-
/ _ \\ | |/ / _' | '_ \\ | / __|
|
|
128
|
-
/ ___ \\| < (_| | | | |_ | \\__ \\
|
|
129
|
-
/_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
|
|
130
|
-
|__/ ver ${version}
|
|
131
|
-
? See more details on docs https://www.akanjs.com/docs
|
|
132
|
-
\u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
|
|
133
|
-
|
|
134
|
-
`;
|
|
135
|
-
|
|
136
|
-
// pkgs/@akanjs/base/src/baseEnv.ts
|
|
137
|
-
var appName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
|
|
138
|
-
var repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
|
|
139
|
-
var serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
|
|
140
|
-
if (appName === "unknown")
|
|
141
|
-
throw new Error("environment variable NEXT_PUBLIC_APP_NAME is required");
|
|
142
|
-
if (repoName === "unknown")
|
|
143
|
-
throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
|
|
144
|
-
if (serveDomain === "unknown")
|
|
145
|
-
throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
|
|
146
|
-
var environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
147
|
-
var operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
|
|
148
|
-
var operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
|
|
149
|
-
var networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
|
|
150
|
-
var tunnelUsername = process.env.SSU_TUNNEL_USERNAME ?? "root";
|
|
151
|
-
var tunnelPassword = process.env.SSU_TUNNEL_PASSWORD ?? repoName;
|
|
152
|
-
var baseEnv = {
|
|
153
|
-
repoName,
|
|
154
|
-
serveDomain,
|
|
155
|
-
appName,
|
|
156
|
-
environment,
|
|
157
|
-
operationType,
|
|
158
|
-
operationMode,
|
|
159
|
-
networkType,
|
|
160
|
-
tunnelUsername,
|
|
161
|
-
tunnelPassword
|
|
162
|
-
};
|
|
163
|
-
var side = typeof window === "undefined" ? "server" : "client";
|
|
164
|
-
var renderMode = process.env.RENDER_ENV ?? "ssr";
|
|
165
|
-
var clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
|
|
166
|
-
var clientPort = parseInt(
|
|
167
|
-
process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
|
|
168
|
-
);
|
|
169
|
-
var clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
|
|
170
|
-
var clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
|
|
171
|
-
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");
|
|
172
|
-
var serverPort = parseInt(
|
|
173
|
-
process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
|
|
174
|
-
);
|
|
175
|
-
var serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
|
|
176
|
-
var serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
|
|
177
|
-
var serverGraphqlUri = `${serverHttpUri}/graphql`;
|
|
178
|
-
var serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
|
|
179
|
-
var serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
|
|
180
|
-
var baseClientEnv = {
|
|
181
|
-
...baseEnv,
|
|
182
|
-
side,
|
|
183
|
-
renderMode,
|
|
184
|
-
websocket: true,
|
|
185
|
-
clientHost,
|
|
186
|
-
clientPort,
|
|
187
|
-
clientHttpProtocol,
|
|
188
|
-
clientHttpUri,
|
|
189
|
-
serverHost,
|
|
190
|
-
serverPort,
|
|
191
|
-
serverHttpProtocol,
|
|
192
|
-
serverHttpUri,
|
|
193
|
-
serverGraphqlUri,
|
|
194
|
-
serverWsProtocol,
|
|
195
|
-
serverWsUri
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
// pkgs/@akanjs/base/src/scalar.ts
|
|
199
|
-
var import_dayjs = __toESM(require("dayjs"));
|
|
200
|
-
var dayjs = import_dayjs.default;
|
|
201
|
-
var Int = class {
|
|
202
|
-
__Scalar__;
|
|
203
|
-
};
|
|
204
|
-
var Upload = class {
|
|
205
|
-
__Scalar__;
|
|
206
|
-
filename;
|
|
207
|
-
mimetype;
|
|
208
|
-
encoding;
|
|
209
|
-
createReadStream;
|
|
210
|
-
};
|
|
211
|
-
var Float = class {
|
|
212
|
-
__Scalar__;
|
|
213
|
-
};
|
|
214
|
-
var ID = class {
|
|
215
|
-
__Scalar__;
|
|
216
|
-
};
|
|
217
|
-
var JSON2 = class {
|
|
218
|
-
__Scalar__;
|
|
219
|
-
};
|
|
220
|
-
var getNonArrayModel = (arraiedModel2) => {
|
|
221
|
-
let arrDepth = 0;
|
|
222
|
-
let target = arraiedModel2;
|
|
223
|
-
while (Array.isArray(target)) {
|
|
224
|
-
target = target[0];
|
|
225
|
-
arrDepth++;
|
|
226
|
-
}
|
|
227
|
-
return [target, arrDepth];
|
|
228
|
-
};
|
|
229
|
-
var arraiedModel = (modelRef, arrDepth = 0) => {
|
|
230
|
-
let target = modelRef;
|
|
231
|
-
for (let i = 0; i < arrDepth; i++)
|
|
232
|
-
target = [target];
|
|
233
|
-
return target;
|
|
234
|
-
};
|
|
235
|
-
var applyFnToArrayObjects = (arraiedData, fn) => {
|
|
236
|
-
if (Array.isArray(arraiedData))
|
|
237
|
-
return arraiedData.map((data) => applyFnToArrayObjects(data, fn));
|
|
238
|
-
return fn(arraiedData);
|
|
239
|
-
};
|
|
240
|
-
var scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON2, Map]);
|
|
241
|
-
var scalarNameMap = /* @__PURE__ */ new Map([
|
|
242
|
-
[ID, "ID"],
|
|
243
|
-
[Int, "Int"],
|
|
244
|
-
[Float, "Float"],
|
|
245
|
-
[String, "String"],
|
|
246
|
-
[Boolean, "Boolean"],
|
|
247
|
-
[Date, "Date"],
|
|
248
|
-
[Upload, "Upload"],
|
|
249
|
-
[JSON2, "JSON"],
|
|
250
|
-
[Map, "Map"]
|
|
251
|
-
]);
|
|
252
|
-
var scalarArgMap = /* @__PURE__ */ new Map([
|
|
253
|
-
[ID, null],
|
|
254
|
-
[String, ""],
|
|
255
|
-
[Boolean, false],
|
|
256
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
257
|
-
[Int, 0],
|
|
258
|
-
[Float, 0],
|
|
259
|
-
[JSON2, {}],
|
|
260
|
-
[Map, {}]
|
|
261
|
-
]);
|
|
262
|
-
var scalarDefaultMap = /* @__PURE__ */ new Map([
|
|
263
|
-
[ID, null],
|
|
264
|
-
[String, ""],
|
|
265
|
-
[Boolean, false],
|
|
266
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
267
|
-
[Int, 0],
|
|
268
|
-
[Float, 0],
|
|
269
|
-
[JSON2, {}]
|
|
270
|
-
]);
|
|
271
|
-
var isGqlScalar = (modelRef) => scalarSet.has(modelRef);
|
|
272
|
-
var isGqlMap = (modelRef) => modelRef === Map;
|
|
273
|
-
|
|
274
|
-
// pkgs/@akanjs/constant/src/types.ts
|
|
275
|
-
var DEFAULT_PAGE_SIZE = 20;
|
|
276
|
-
|
|
277
|
-
// pkgs/@akanjs/constant/src/scalar.ts
|
|
278
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
279
|
-
var scalarExampleMap = /* @__PURE__ */ new Map([
|
|
280
|
-
[ID, "1234567890abcdef12345678"],
|
|
281
|
-
[Int, 0],
|
|
282
|
-
[Float, 0],
|
|
283
|
-
[String, "String"],
|
|
284
|
-
[Boolean, true],
|
|
285
|
-
[Date, (/* @__PURE__ */ new Date()).toISOString()],
|
|
286
|
-
[Upload, "FileUpload"],
|
|
287
|
-
[JSON2, {}],
|
|
288
|
-
[Map, {}]
|
|
289
|
-
]);
|
|
290
|
-
var getClassMeta = (modelRef) => {
|
|
291
|
-
const [target] = getNonArrayModel(modelRef);
|
|
292
|
-
const classMeta = Reflect.getMetadata("class", target.prototype);
|
|
293
|
-
if (!classMeta)
|
|
294
|
-
throw new Error(`No ClassMeta for this target ${target.name}`);
|
|
295
|
-
return classMeta;
|
|
296
|
-
};
|
|
297
|
-
var getFieldMetas = (modelRef) => {
|
|
298
|
-
const [target] = getNonArrayModel(modelRef);
|
|
299
|
-
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
300
|
-
const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
|
|
301
|
-
return [...metadataMap.values()].sort((a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0));
|
|
302
|
-
};
|
|
303
|
-
var getFieldMetaMap = (modelRef) => {
|
|
304
|
-
const [target] = getNonArrayModel(modelRef);
|
|
305
|
-
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
306
|
-
return new Map(metadataMap);
|
|
307
|
-
};
|
|
308
|
-
var getFieldMetaMapOnPrototype = (prototype) => {
|
|
309
|
-
const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
|
|
310
|
-
return new Map(metadataMap);
|
|
311
|
-
};
|
|
312
|
-
var setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
313
|
-
Reflect.defineMetadata("fields", new Map(metadataMap), prototype);
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// pkgs/@akanjs/constant/src/fieldMeta.ts
|
|
317
|
-
var applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
318
|
-
const isArray = arrDepth > 0;
|
|
319
|
-
const isClass = !isGqlScalar(modelRef);
|
|
320
|
-
const isMap = isGqlMap(modelRef);
|
|
321
|
-
const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
|
|
322
|
-
const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
|
|
323
|
-
if (isMap && !option.of)
|
|
324
|
-
throw new Error("Map type must have 'of' option");
|
|
325
|
-
return (prototype, key) => {
|
|
326
|
-
const metadata = {
|
|
327
|
-
nullable: option.nullable ?? false,
|
|
328
|
-
ref: option.ref,
|
|
329
|
-
refPath: option.refPath,
|
|
330
|
-
refType: option.refType,
|
|
331
|
-
default: option.default ?? (isArray ? [] : null),
|
|
332
|
-
type: option.type,
|
|
333
|
-
fieldType: option.fieldType ?? "property",
|
|
334
|
-
immutable: option.immutable ?? false,
|
|
335
|
-
min: option.min,
|
|
336
|
-
max: option.max,
|
|
337
|
-
enum: option.enum,
|
|
338
|
-
select: option.select ?? true,
|
|
339
|
-
minlength: option.minlength,
|
|
340
|
-
maxlength: option.maxlength,
|
|
341
|
-
query: option.query,
|
|
342
|
-
accumulate: option.accumulate,
|
|
343
|
-
example: option.example,
|
|
344
|
-
validate: option.validate,
|
|
345
|
-
key,
|
|
346
|
-
name,
|
|
347
|
-
isClass,
|
|
348
|
-
isScalar: type === "scalar",
|
|
349
|
-
modelRef,
|
|
350
|
-
arrDepth,
|
|
351
|
-
isArray,
|
|
352
|
-
optArrDepth: optionArrDepth,
|
|
353
|
-
isMap,
|
|
354
|
-
of: option.of,
|
|
355
|
-
text: option.text
|
|
356
|
-
};
|
|
357
|
-
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
358
|
-
metadataMap.set(key, metadata);
|
|
359
|
-
setFieldMetaMapOnPrototype(prototype, metadataMap);
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
var makeField = (customOption) => (returns, fieldOption) => {
|
|
363
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
364
|
-
if (!fieldOption)
|
|
365
|
-
return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
|
|
366
|
-
const [opt, optArrDepth] = getNonArrayModel(fieldOption);
|
|
367
|
-
return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
|
|
368
|
-
};
|
|
369
|
-
var Field = {
|
|
370
|
-
Prop: makeField({ fieldType: "property" }),
|
|
371
|
-
Hidden: makeField({ fieldType: "hidden", nullable: true }),
|
|
372
|
-
Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
|
|
373
|
-
Resolve: makeField({ fieldType: "resolve" })
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
// pkgs/@akanjs/constant/src/constantDecorator.ts
|
|
377
|
-
var import_reflect_metadata2 = require("reflect-metadata");
|
|
378
|
-
var CnstStorage = class {
|
|
379
|
-
};
|
|
380
|
-
var getCnstMeta = (refName) => {
|
|
381
|
-
const cnst = Reflect.getMetadata(refName, CnstStorage.prototype);
|
|
382
|
-
if (!cnst)
|
|
383
|
-
throw new Error(`No cnst meta for ${refName}`);
|
|
384
|
-
return cnst;
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
// pkgs/@akanjs/constant/src/filterMeta.ts
|
|
388
|
-
var getFilterMeta = (filterRef) => {
|
|
389
|
-
const filterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
390
|
-
if (!filterMeta)
|
|
391
|
-
throw new Error("filterMeta is not defined");
|
|
392
|
-
return filterMeta;
|
|
393
|
-
};
|
|
394
|
-
var setFilterMeta = (filterRef, filterMeta) => {
|
|
395
|
-
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
396
|
-
if (existingFilterMeta)
|
|
397
|
-
Object.assign(filterMeta.sort, existingFilterMeta.sort);
|
|
398
|
-
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
399
|
-
};
|
|
400
|
-
var getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
401
|
-
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
402
|
-
return new Map(metadataMap);
|
|
403
|
-
};
|
|
404
|
-
var setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
405
|
-
Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
|
|
406
|
-
};
|
|
407
|
-
var applyFilterKeyMeta = (option) => {
|
|
408
|
-
return (prototype, key, descriptor) => {
|
|
409
|
-
const metadata = { key, ...option, descriptor };
|
|
410
|
-
const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
|
|
411
|
-
metadataMap.set(key, metadata);
|
|
412
|
-
setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
|
|
413
|
-
};
|
|
414
|
-
};
|
|
415
|
-
var makeFilter = (customOption) => (fieldOption) => {
|
|
416
|
-
return applyFilterKeyMeta({ ...customOption, ...fieldOption });
|
|
417
|
-
};
|
|
418
|
-
var getFilterArgMetasOnPrototype = (prototype, key) => {
|
|
419
|
-
const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
|
|
420
|
-
return filterArgMetas;
|
|
421
|
-
};
|
|
422
|
-
var setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
|
|
423
|
-
Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
|
|
424
|
-
};
|
|
425
|
-
var applyFilterArgMeta = (name, returns, argOption) => {
|
|
426
|
-
return (prototype, key, idx) => {
|
|
427
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
428
|
-
const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
|
|
429
|
-
const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
|
|
430
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
|
|
431
|
-
filterArgMetas[idx] = filterArgMeta;
|
|
432
|
-
setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
|
|
433
|
-
};
|
|
434
|
-
};
|
|
435
|
-
var getFilterQuery = (filterRef, key) => {
|
|
436
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(filterRef.prototype);
|
|
437
|
-
const filterKeyMeta = filterKeyMetaMap.get(key);
|
|
438
|
-
if (!filterKeyMeta?.descriptor.value)
|
|
439
|
-
throw new Error(`filterKeyMeta is not defined for key: ${key}`);
|
|
440
|
-
return filterKeyMeta.descriptor.value;
|
|
441
|
-
};
|
|
442
|
-
var getFilterSort = (filterRef, key) => {
|
|
443
|
-
const filterMeta = getFilterMeta(filterRef);
|
|
444
|
-
const sort = filterMeta.sort[key];
|
|
445
|
-
return sort;
|
|
446
|
-
};
|
|
447
|
-
var getFilterSortMap = (filterRef) => {
|
|
448
|
-
const filterMeta = getFilterMeta(filterRef);
|
|
449
|
-
return filterMeta.sort;
|
|
450
|
-
};
|
|
451
|
-
var Filter = {
|
|
452
|
-
Mongo: makeFilter({ type: "mongo" }),
|
|
453
|
-
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
454
|
-
Arg: applyFilterArgMeta
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
// pkgs/@akanjs/constant/src/baseGql.ts
|
|
458
|
-
var import_reflect_metadata3 = require("reflect-metadata");
|
|
459
|
-
|
|
460
|
-
// pkgs/@akanjs/common/src/isDayjs.ts
|
|
461
|
-
var import_dayjs2 = require("dayjs");
|
|
462
|
-
|
|
463
|
-
// pkgs/@akanjs/common/src/isQueryEqual.ts
|
|
464
|
-
var import_dayjs3 = __toESM(require("dayjs"));
|
|
465
|
-
|
|
466
|
-
// pkgs/@akanjs/common/src/isValidDate.ts
|
|
467
|
-
var import_dayjs4 = __toESM(require("dayjs"));
|
|
468
|
-
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
469
|
-
import_dayjs4.default.extend(import_customParseFormat.default);
|
|
470
|
-
var isValidDate = (d) => {
|
|
471
|
-
const format = "YYYY-MM-DD";
|
|
472
|
-
if (typeof d === "string") {
|
|
473
|
-
return (0, import_dayjs4.default)(d, format).isValid();
|
|
474
|
-
} else if ((0, import_dayjs2.isDayjs)(d))
|
|
475
|
-
return d.isValid();
|
|
476
|
-
else
|
|
477
|
-
return d instanceof Date && !isNaN(d.getTime());
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
// pkgs/@akanjs/common/src/pluralize.ts
|
|
481
|
-
var import_pluralize = __toESM(require("pluralize"));
|
|
482
|
-
|
|
483
|
-
// pkgs/@akanjs/common/src/applyMixins.ts
|
|
484
|
-
var getAllPropertyDescriptors = (objRef) => {
|
|
485
|
-
const descriptors = {};
|
|
486
|
-
let current = objRef.prototype;
|
|
487
|
-
while (current) {
|
|
488
|
-
Object.getOwnPropertyNames(current).forEach((name) => {
|
|
489
|
-
descriptors[name] ??= Object.getOwnPropertyDescriptor(current, name);
|
|
490
|
-
});
|
|
491
|
-
current = Object.getPrototypeOf(current);
|
|
492
|
-
}
|
|
493
|
-
return descriptors;
|
|
494
|
-
};
|
|
495
|
-
var applyMixins = (derivedCtor, constructors, avoidKeys) => {
|
|
496
|
-
constructors.forEach((baseCtor) => {
|
|
497
|
-
Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
|
|
498
|
-
if (name === "constructor" || avoidKeys?.has(name))
|
|
499
|
-
return;
|
|
500
|
-
Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
|
|
501
|
-
});
|
|
502
|
-
});
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
// pkgs/@akanjs/common/src/capitalize.ts
|
|
506
|
-
var capitalize = (str) => {
|
|
507
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
// pkgs/@akanjs/common/src/Logger.ts
|
|
511
|
-
var import_dayjs5 = __toESM(require("dayjs"));
|
|
512
|
-
var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
513
|
-
var clc = {
|
|
514
|
-
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
515
|
-
green: (text) => `\x1B[32m${text}\x1B[39m`,
|
|
516
|
-
yellow: (text) => `\x1B[33m${text}\x1B[39m`,
|
|
517
|
-
red: (text) => `\x1B[31m${text}\x1B[39m`,
|
|
518
|
-
magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
|
|
519
|
-
cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
|
|
520
|
-
};
|
|
521
|
-
var colorizeMap = {
|
|
522
|
-
trace: clc.bold,
|
|
523
|
-
verbose: clc.cyanBright,
|
|
524
|
-
debug: clc.magentaBright,
|
|
525
|
-
log: clc.green,
|
|
526
|
-
info: clc.green,
|
|
527
|
-
warn: clc.yellow,
|
|
528
|
-
error: clc.red
|
|
529
|
-
};
|
|
530
|
-
var Logger = class _Logger {
|
|
531
|
-
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
532
|
-
"InstanceLoader",
|
|
533
|
-
"RoutesResolver",
|
|
534
|
-
"RouterExplorer",
|
|
535
|
-
"NestFactory",
|
|
536
|
-
"WebSocketsController",
|
|
537
|
-
"GraphQLModule",
|
|
538
|
-
"NestApplication"
|
|
539
|
-
]);
|
|
540
|
-
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
541
|
-
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
542
|
-
static #startAt = (0, import_dayjs5.default)();
|
|
543
|
-
static setLevel(level) {
|
|
544
|
-
this.level = level;
|
|
545
|
-
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
546
|
-
}
|
|
547
|
-
name;
|
|
548
|
-
constructor(name) {
|
|
549
|
-
this.name = name;
|
|
550
|
-
}
|
|
551
|
-
trace(msg, context = "") {
|
|
552
|
-
if (_Logger.#levelIdx <= 0)
|
|
553
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
554
|
-
}
|
|
555
|
-
verbose(msg, context = "") {
|
|
556
|
-
if (_Logger.#levelIdx <= 1)
|
|
557
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
558
|
-
}
|
|
559
|
-
debug(msg, context = "") {
|
|
560
|
-
if (_Logger.#levelIdx <= 2)
|
|
561
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
562
|
-
}
|
|
563
|
-
log(msg, context = "") {
|
|
564
|
-
if (_Logger.#levelIdx <= 3)
|
|
565
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
566
|
-
}
|
|
567
|
-
info(msg, context = "") {
|
|
568
|
-
if (_Logger.#levelIdx <= 4)
|
|
569
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
570
|
-
}
|
|
571
|
-
warn(msg, context = "") {
|
|
572
|
-
if (_Logger.#levelIdx <= 5)
|
|
573
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
574
|
-
}
|
|
575
|
-
error(msg, context = "") {
|
|
576
|
-
if (_Logger.#levelIdx <= 6)
|
|
577
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
578
|
-
}
|
|
579
|
-
raw(msg, method) {
|
|
580
|
-
_Logger.rawLog(msg, method);
|
|
581
|
-
}
|
|
582
|
-
rawLog(msg, method) {
|
|
583
|
-
_Logger.rawLog(msg, method);
|
|
584
|
-
}
|
|
585
|
-
static trace(msg, context = "") {
|
|
586
|
-
if (_Logger.#levelIdx <= 0)
|
|
587
|
-
_Logger.#printMessages("App", msg, context, "trace");
|
|
588
|
-
}
|
|
589
|
-
static verbose(msg, context = "") {
|
|
590
|
-
if (_Logger.#levelIdx <= 1)
|
|
591
|
-
_Logger.#printMessages("App", msg, context, "verbose");
|
|
592
|
-
}
|
|
593
|
-
static debug(msg, context = "") {
|
|
594
|
-
if (_Logger.#levelIdx <= 2)
|
|
595
|
-
_Logger.#printMessages("App", msg, context, "debug");
|
|
596
|
-
}
|
|
597
|
-
static log(msg, context = "") {
|
|
598
|
-
if (_Logger.#levelIdx <= 3)
|
|
599
|
-
_Logger.#printMessages("App", msg, context, "log");
|
|
600
|
-
}
|
|
601
|
-
static info(msg, context = "") {
|
|
602
|
-
if (_Logger.#levelIdx <= 4)
|
|
603
|
-
_Logger.#printMessages("App", msg, context, "info");
|
|
604
|
-
}
|
|
605
|
-
static warn(msg, context = "") {
|
|
606
|
-
if (_Logger.#levelIdx <= 5)
|
|
607
|
-
_Logger.#printMessages("App", msg, context, "warn");
|
|
608
|
-
}
|
|
609
|
-
static error(msg, context = "") {
|
|
610
|
-
if (_Logger.#levelIdx <= 6)
|
|
611
|
-
_Logger.#printMessages("App", msg, context, "error");
|
|
612
|
-
}
|
|
613
|
-
static #colorize(msg, logLevel) {
|
|
614
|
-
return colorizeMap[logLevel](msg);
|
|
615
|
-
}
|
|
616
|
-
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
617
|
-
if (this.#ignoreCtxSet.has(context))
|
|
618
|
-
return;
|
|
619
|
-
const now = (0, import_dayjs5.default)();
|
|
620
|
-
const processMsg = this.#colorize(
|
|
621
|
-
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
622
|
-
logLevel
|
|
623
|
-
);
|
|
624
|
-
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
625
|
-
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
626
|
-
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
627
|
-
const contentMsg = this.#colorize(content, logLevel);
|
|
628
|
-
const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
|
|
629
|
-
if (typeof window === "undefined")
|
|
630
|
-
process[writeStreamType].write(
|
|
631
|
-
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
632
|
-
`
|
|
633
|
-
);
|
|
634
|
-
else
|
|
635
|
-
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
636
|
-
`);
|
|
637
|
-
}
|
|
638
|
-
static rawLog(msg, method) {
|
|
639
|
-
this.raw(`${msg}
|
|
640
|
-
`, method);
|
|
641
|
-
}
|
|
642
|
-
static raw(msg, method) {
|
|
643
|
-
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
644
|
-
global.process.stdout.write(msg);
|
|
645
|
-
else
|
|
646
|
-
console.log(msg);
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
// pkgs/@akanjs/common/src/lowerlize.ts
|
|
651
|
-
var lowerlize = (str) => {
|
|
652
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
// pkgs/@akanjs/common/src/sleep.ts
|
|
656
|
-
var sleep = async (ms) => {
|
|
657
|
-
return new Promise((resolve) => {
|
|
658
|
-
setTimeout(() => {
|
|
659
|
-
resolve(true);
|
|
660
|
-
}, ms);
|
|
661
|
-
});
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
// pkgs/@akanjs/constant/src/baseGql.ts
|
|
665
|
-
var defaultFieldMeta = {
|
|
666
|
-
fieldType: "property",
|
|
667
|
-
immutable: false,
|
|
668
|
-
select: true,
|
|
669
|
-
isClass: false,
|
|
670
|
-
isScalar: true,
|
|
671
|
-
nullable: false,
|
|
672
|
-
isArray: false,
|
|
673
|
-
arrDepth: 0,
|
|
674
|
-
optArrDepth: 0,
|
|
675
|
-
default: null,
|
|
676
|
-
isMap: false
|
|
677
|
-
};
|
|
678
|
-
var idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
|
|
679
|
-
var createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
|
|
680
|
-
var updatedAtFieldMeta = { ...defaultFieldMeta, key: "updatedAt", name: "Date", modelRef: Date };
|
|
681
|
-
var removedAtFieldMeta = {
|
|
682
|
-
...defaultFieldMeta,
|
|
683
|
-
key: "removedAt",
|
|
684
|
-
name: "Date",
|
|
685
|
-
modelRef: Date,
|
|
686
|
-
nullable: true,
|
|
687
|
-
default: null
|
|
688
|
-
};
|
|
689
|
-
|
|
690
|
-
// pkgs/@akanjs/constant/src/classMeta.ts
|
|
691
|
-
var import_reflect_metadata4 = require("reflect-metadata");
|
|
692
|
-
var InputModelStorage = class {
|
|
693
|
-
};
|
|
694
|
-
var LightModelStorage = class {
|
|
695
|
-
};
|
|
696
|
-
var FullModelStorage = class {
|
|
697
|
-
};
|
|
698
|
-
var ScalarModelStorage = class {
|
|
699
|
-
};
|
|
700
|
-
var FilterModelStorage = class {
|
|
701
|
-
};
|
|
702
|
-
var getFullModelRef = (refName) => {
|
|
703
|
-
const modelRef = Reflect.getMetadata(capitalize(refName), FullModelStorage.prototype);
|
|
704
|
-
if (!modelRef)
|
|
705
|
-
throw new Error(`FullModel not found - ${refName}`);
|
|
706
|
-
return modelRef;
|
|
707
|
-
};
|
|
708
|
-
var getInputModelRef = (refName) => {
|
|
709
|
-
const modelRef = Reflect.getMetadata(capitalize(refName), InputModelStorage.prototype);
|
|
710
|
-
if (!modelRef)
|
|
711
|
-
throw new Error(`InputModel not found - ${refName}`);
|
|
712
|
-
return modelRef;
|
|
713
|
-
};
|
|
714
|
-
var getChildClassRefs = (target) => {
|
|
715
|
-
const metadatas = getFieldMetas(target);
|
|
716
|
-
const refMap = /* @__PURE__ */ new Map();
|
|
717
|
-
const childRefs = metadatas.filter((metadata) => metadata.isClass).reduce((acc, metadata) => {
|
|
718
|
-
return [...acc, metadata.modelRef, ...getChildClassRefs(metadata.modelRef)];
|
|
719
|
-
}, []);
|
|
720
|
-
childRefs.filter((modelRef, idx) => childRefs.findIndex((ref) => ref.prototype === modelRef.prototype) === idx).map((modelRef) => refMap.set(getClassMeta(modelRef).refName, modelRef));
|
|
721
|
-
return [...refMap.values()];
|
|
722
|
-
};
|
|
723
|
-
var hasTextField = (modelRef) => {
|
|
724
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
725
|
-
return fieldMetas.some(
|
|
726
|
-
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
727
|
-
);
|
|
728
|
-
};
|
|
729
|
-
var applyClassMeta = (type, modelType, storage) => {
|
|
730
|
-
return function(refName) {
|
|
731
|
-
return function(target) {
|
|
732
|
-
const modelRef = target;
|
|
733
|
-
const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
|
|
734
|
-
Reflect.defineMetadata("class", classMeta, modelRef.prototype);
|
|
735
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
736
|
-
};
|
|
737
|
-
};
|
|
738
|
-
};
|
|
739
|
-
var applyFilterMeta = (storage) => {
|
|
740
|
-
return function(refName) {
|
|
741
|
-
return function(target) {
|
|
742
|
-
const modelRef = target;
|
|
743
|
-
setFilterMeta(modelRef, { refName, sort: {} });
|
|
744
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
745
|
-
};
|
|
746
|
-
};
|
|
747
|
-
};
|
|
748
|
-
var Model = {
|
|
749
|
-
Light: applyClassMeta("light", "data", LightModelStorage),
|
|
750
|
-
Object: applyClassMeta("full", "ephemeral", FullModelStorage),
|
|
751
|
-
Full: applyClassMeta("full", "data", FullModelStorage),
|
|
752
|
-
Input: applyClassMeta("input", "data", InputModelStorage),
|
|
753
|
-
Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
|
|
754
|
-
Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
|
|
755
|
-
Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
|
|
756
|
-
Filter: applyFilterMeta(FilterModelStorage)
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
// pkgs/@akanjs/server/src/gql.ts
|
|
760
|
-
var Nest = __toESM(require("@nestjs/graphql"));
|
|
761
|
-
var import_graphql = require("@nestjs/graphql");
|
|
762
|
-
var import_dayjs6 = require("dayjs");
|
|
763
|
-
var import_graphql2 = require("graphql");
|
|
764
|
-
var import_graphql_type_json = __toESM(require("graphql-type-json"));
|
|
765
|
-
var DateScalar = class {
|
|
766
|
-
description = "Date custom scalar type";
|
|
767
|
-
parseValue(value) {
|
|
768
|
-
return dayjs(value);
|
|
769
|
-
}
|
|
770
|
-
serialize(value) {
|
|
771
|
-
if ((0, import_dayjs6.isDayjs)(value))
|
|
772
|
-
return value.toDate();
|
|
773
|
-
else
|
|
774
|
-
return new Date(value);
|
|
775
|
-
}
|
|
776
|
-
parseLiteral(ast) {
|
|
777
|
-
if (ast.kind === import_graphql2.Kind.INT)
|
|
778
|
-
return dayjs(ast.value);
|
|
779
|
-
else if (ast.kind === import_graphql2.Kind.STRING)
|
|
780
|
-
return dayjs(ast.value);
|
|
781
|
-
else
|
|
782
|
-
return null;
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
DateScalar = __decorateClass([
|
|
786
|
-
Nest.Scalar("Date", () => Date)
|
|
787
|
-
], DateScalar);
|
|
788
|
-
var ObjectGqlStorage = class {
|
|
789
|
-
};
|
|
790
|
-
var InputGqlStorage = class {
|
|
791
|
-
};
|
|
792
|
-
var getPredefinedInqutGql = (refName) => {
|
|
793
|
-
const inputGql = Reflect.getMetadata(refName, InputGqlStorage.prototype);
|
|
794
|
-
return inputGql;
|
|
795
|
-
};
|
|
796
|
-
var setPredefinedInqutGql = (refName, inputGql) => {
|
|
797
|
-
Reflect.defineMetadata(refName, inputGql, InputGqlStorage.prototype);
|
|
798
|
-
};
|
|
799
|
-
var getPredefinedObjectGql = (refName) => {
|
|
800
|
-
const objectGql = Reflect.getMetadata(refName, ObjectGqlStorage.prototype);
|
|
801
|
-
return objectGql;
|
|
802
|
-
};
|
|
803
|
-
var setPredefinedObjectGql = (refName, objectGql) => {
|
|
804
|
-
Reflect.defineMetadata(refName, objectGql, ObjectGqlStorage.prototype);
|
|
805
|
-
};
|
|
806
|
-
var gqlNestFieldMap = /* @__PURE__ */ new Map([
|
|
807
|
-
[ID, Nest.ID],
|
|
808
|
-
[Int, Nest.Int],
|
|
809
|
-
[Float, Nest.Float],
|
|
810
|
-
[JSON2, import_graphql_type_json.default],
|
|
811
|
-
[Map, import_graphql_type_json.default]
|
|
812
|
-
]);
|
|
813
|
-
var applyNestField = (model, fieldMeta, type = "object") => {
|
|
814
|
-
if (fieldMeta.fieldType === "hidden" && type === "object")
|
|
815
|
-
return;
|
|
816
|
-
const modelRef = fieldMeta.isClass ? type === "object" ? generateGql(fieldMeta.modelRef) : fieldMeta.isScalar ? generateGqlInput(fieldMeta.modelRef) : Nest.ID : gqlNestFieldMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
|
|
817
|
-
(0, import_graphql.Field)(() => arraiedModel(modelRef, fieldMeta.arrDepth), { nullable: fieldMeta.nullable })(
|
|
818
|
-
model.prototype,
|
|
819
|
-
fieldMeta.key
|
|
820
|
-
);
|
|
821
|
-
};
|
|
822
|
-
var generateGqlInput = (inputRef) => {
|
|
823
|
-
const classMeta = getClassMeta(inputRef);
|
|
824
|
-
const predefinedInputGql = getPredefinedInqutGql(classMeta.refName);
|
|
825
|
-
if (predefinedInputGql)
|
|
826
|
-
return predefinedInputGql;
|
|
827
|
-
const fieldMetas = getFieldMetas(inputRef);
|
|
828
|
-
class InputGql {
|
|
829
|
-
}
|
|
830
|
-
const inputGql = classMeta.type === "scalar" ? InputGql : getInputModelRef(classMeta.refName);
|
|
831
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
832
|
-
applyNestField(inputGql, fieldMeta, "input");
|
|
833
|
-
});
|
|
834
|
-
(0, import_graphql.InputType)(classMeta.refName + (classMeta.type === "scalar" ? "Input" : ""))(inputGql);
|
|
835
|
-
setPredefinedInqutGql(classMeta.refName, inputGql);
|
|
836
|
-
return inputGql;
|
|
837
|
-
};
|
|
838
|
-
var generateGql = (objectRef) => {
|
|
839
|
-
const classMeta = getClassMeta(objectRef);
|
|
840
|
-
if (classMeta.type === "light") {
|
|
841
|
-
const fullModelRefName = classMeta.refName.slice(5);
|
|
842
|
-
const fullModelRef = getFullModelRef(fullModelRefName);
|
|
843
|
-
return generateGql(fullModelRef);
|
|
844
|
-
}
|
|
845
|
-
const predefinedObjectGql = getPredefinedObjectGql(classMeta.refName);
|
|
846
|
-
if (predefinedObjectGql)
|
|
847
|
-
return predefinedObjectGql;
|
|
848
|
-
const fieldMetas = getFieldMetas(objectRef);
|
|
849
|
-
class ObjectGql {
|
|
850
|
-
}
|
|
851
|
-
const objectGql = classMeta.type === "scalar" ? ObjectGql : getFullModelRef(classMeta.refName);
|
|
852
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
853
|
-
applyNestField(objectGql, fieldMeta);
|
|
854
|
-
});
|
|
855
|
-
(0, import_graphql.ObjectType)(classMeta.refName)(objectGql);
|
|
856
|
-
setPredefinedObjectGql(classMeta.refName, objectGql);
|
|
857
|
-
return objectGql;
|
|
858
|
-
};
|
|
859
|
-
|
|
860
|
-
// pkgs/@akanjs/signal/src/client.ts
|
|
861
|
-
var import_core = require("@urql/core");
|
|
862
|
-
var import_socket = require("socket.io-client");
|
|
863
|
-
var SocketIo = class {
|
|
864
|
-
socket;
|
|
865
|
-
roomSubscribeMap = /* @__PURE__ */ new Map();
|
|
866
|
-
constructor(uri) {
|
|
867
|
-
this.socket = (0, import_socket.io)(uri, { transports: ["websocket"] });
|
|
868
|
-
this.socket.on("connect", () => {
|
|
869
|
-
this.roomSubscribeMap.forEach((option) => {
|
|
870
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
871
|
-
});
|
|
872
|
-
});
|
|
873
|
-
}
|
|
874
|
-
on(event, callback) {
|
|
875
|
-
this.socket.on(event, callback);
|
|
876
|
-
}
|
|
877
|
-
removeListener(event, callback) {
|
|
878
|
-
this.socket.removeListener(event, callback);
|
|
879
|
-
}
|
|
880
|
-
removeAllListeners() {
|
|
881
|
-
this.socket.removeAllListeners();
|
|
882
|
-
}
|
|
883
|
-
hasListeners(event) {
|
|
884
|
-
return this.socket.hasListeners(event);
|
|
885
|
-
}
|
|
886
|
-
emit(key, data) {
|
|
887
|
-
this.socket.emit(key, data);
|
|
888
|
-
}
|
|
889
|
-
subscribe(option) {
|
|
890
|
-
if (!this.roomSubscribeMap.has(option.roomId)) {
|
|
891
|
-
this.roomSubscribeMap.set(option.roomId, option);
|
|
892
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
893
|
-
}
|
|
894
|
-
this.socket.on(option.roomId, option.handleEvent);
|
|
895
|
-
}
|
|
896
|
-
unsubscribe(roomId, handleEvent) {
|
|
897
|
-
this.socket.removeListener(roomId, handleEvent);
|
|
898
|
-
const option = this.roomSubscribeMap.get(roomId);
|
|
899
|
-
if (this.hasListeners(roomId) || !option)
|
|
900
|
-
return;
|
|
901
|
-
this.roomSubscribeMap.delete(roomId);
|
|
902
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: false });
|
|
903
|
-
}
|
|
904
|
-
disconnect() {
|
|
905
|
-
this.socket.disconnect();
|
|
906
|
-
return this;
|
|
907
|
-
}
|
|
908
|
-
};
|
|
909
|
-
var Client = class _Client {
|
|
910
|
-
static globalIoMap = /* @__PURE__ */ new Map();
|
|
911
|
-
static tokenStore = /* @__PURE__ */ new Map();
|
|
912
|
-
async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
|
|
913
|
-
if (baseClientEnv.side === "server")
|
|
914
|
-
return true;
|
|
915
|
-
while (!this.getIo(ws).socket.connected) {
|
|
916
|
-
Logger.verbose("waiting for websocket to initialize...");
|
|
917
|
-
await sleep(300);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
isInitialized = false;
|
|
921
|
-
uri = baseClientEnv.serverGraphqlUri;
|
|
922
|
-
ws = baseClientEnv.serverWsUri;
|
|
923
|
-
udp = null;
|
|
924
|
-
gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
|
|
925
|
-
jwt = null;
|
|
926
|
-
async getJwt() {
|
|
927
|
-
const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
|
|
928
|
-
if (isNextServer) {
|
|
929
|
-
const nextHeaders = require("next/headers");
|
|
930
|
-
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
931
|
-
} else
|
|
932
|
-
return _Client.tokenStore.get(this) ?? null;
|
|
933
|
-
}
|
|
934
|
-
io = null;
|
|
935
|
-
init(data = {}) {
|
|
936
|
-
Object.assign(this, data);
|
|
937
|
-
this.setLink(data.uri);
|
|
938
|
-
this.setIo(data.ws);
|
|
939
|
-
this.isInitialized = true;
|
|
940
|
-
}
|
|
941
|
-
setIo(ws = baseClientEnv.serverWsUri) {
|
|
942
|
-
this.ws = ws;
|
|
943
|
-
const existingIo = _Client.globalIoMap.get(ws);
|
|
944
|
-
if (existingIo) {
|
|
945
|
-
this.io = existingIo;
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
this.io = new SocketIo(ws);
|
|
949
|
-
_Client.globalIoMap.set(ws, this.io);
|
|
950
|
-
}
|
|
951
|
-
getIo(ws = baseClientEnv.serverWsUri) {
|
|
952
|
-
const existingIo = _Client.globalIoMap.get(ws);
|
|
953
|
-
if (existingIo)
|
|
954
|
-
return existingIo;
|
|
955
|
-
const io2 = new SocketIo(ws);
|
|
956
|
-
_Client.globalIoMap.set(ws, io2);
|
|
957
|
-
return io2;
|
|
958
|
-
}
|
|
959
|
-
setLink(uri = baseClientEnv.serverGraphqlUri) {
|
|
960
|
-
this.uri = uri;
|
|
961
|
-
this.gql = (0, import_core.createClient)({
|
|
962
|
-
url: this.uri,
|
|
963
|
-
fetch,
|
|
964
|
-
exchanges: [import_core.cacheExchange, import_core.fetchExchange],
|
|
965
|
-
// requestPolicy: "network-only",
|
|
966
|
-
fetchOptions: () => {
|
|
967
|
-
return {
|
|
968
|
-
headers: {
|
|
969
|
-
"apollo-require-preflight": "true",
|
|
970
|
-
...this.jwt ? { authorization: `Bearer ${this.jwt}` } : {}
|
|
971
|
-
}
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
});
|
|
975
|
-
}
|
|
976
|
-
setJwt(jwt3) {
|
|
977
|
-
_Client.tokenStore.set(this, jwt3);
|
|
978
|
-
}
|
|
979
|
-
reset() {
|
|
980
|
-
this.io?.disconnect();
|
|
981
|
-
this.io = null;
|
|
982
|
-
this.jwt = null;
|
|
983
|
-
}
|
|
984
|
-
clone(data = {}) {
|
|
985
|
-
const newClient = new _Client();
|
|
986
|
-
newClient.init({ ...this, ...data });
|
|
987
|
-
if (data.jwt)
|
|
988
|
-
_Client.tokenStore.set(newClient, data.jwt);
|
|
989
|
-
return newClient;
|
|
990
|
-
}
|
|
991
|
-
terminate() {
|
|
992
|
-
this.reset();
|
|
993
|
-
_Client.globalIoMap.forEach((io2) => io2.disconnect());
|
|
994
|
-
this.isInitialized = false;
|
|
995
|
-
}
|
|
996
|
-
setUdp(udp) {
|
|
997
|
-
this.udp = udp;
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
var client = new Client();
|
|
1001
|
-
|
|
1002
|
-
// pkgs/@akanjs/signal/src/immerify.ts
|
|
1003
|
-
var import_immer = require("immer");
|
|
1004
|
-
|
|
1005
|
-
// pkgs/@akanjs/signal/src/signalDecorators.ts
|
|
1006
|
-
var import_reflect_metadata5 = require("reflect-metadata");
|
|
1007
|
-
var SignalStorage = class {
|
|
1008
|
-
};
|
|
1009
|
-
var getSignalRefsOnStorage = (refName) => {
|
|
1010
|
-
const sigRefs = Reflect.getMetadata(refName, SignalStorage.prototype);
|
|
1011
|
-
return sigRefs ?? [];
|
|
1012
|
-
};
|
|
1013
|
-
var setSignalRefOnStorage = (refName, signalRef) => {
|
|
1014
|
-
Reflect.defineMetadata(refName, [...getSignalRefsOnStorage(refName), signalRef], SignalStorage.prototype);
|
|
1015
|
-
};
|
|
1016
|
-
var getDefaultArg = (argRef) => {
|
|
1017
|
-
const [modelRef, arrDepth] = getNonArrayModel(argRef);
|
|
1018
|
-
if (arrDepth)
|
|
1019
|
-
return [];
|
|
1020
|
-
const scalarArg = scalarArgMap.get(modelRef);
|
|
1021
|
-
if (scalarArg)
|
|
1022
|
-
return scalarArg;
|
|
1023
|
-
else
|
|
1024
|
-
return {};
|
|
1025
|
-
};
|
|
1026
|
-
function Signal(returnsOrObj) {
|
|
1027
|
-
const returns = typeof returnsOrObj === "function" ? returnsOrObj : void 0;
|
|
1028
|
-
const prefix = typeof returnsOrObj === "object" ? returnsOrObj.prefix : void 0;
|
|
1029
|
-
return function(target) {
|
|
1030
|
-
if (returns) {
|
|
1031
|
-
const modelRef = returns();
|
|
1032
|
-
const classMeta = getClassMeta(modelRef);
|
|
1033
|
-
const gqlMetas = getGqlMetas(target);
|
|
1034
|
-
const modelName = lowerlize(classMeta.refName);
|
|
1035
|
-
const listName = `${modelName}ListIn`;
|
|
1036
|
-
const slices = [
|
|
1037
|
-
{ refName: modelName, sliceName: modelName, argLength: 1, defaultArgs: [{}] },
|
|
1038
|
-
...gqlMetas.filter((gqlMeta) => {
|
|
1039
|
-
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
1040
|
-
if (!name.includes(listName))
|
|
1041
|
-
return false;
|
|
1042
|
-
const [retRef, arrDepth] = getNonArrayModel(gqlMeta.returns());
|
|
1043
|
-
return retRef.prototype === modelRef.prototype && arrDepth === 1;
|
|
1044
|
-
}).map((gqlMeta) => {
|
|
1045
|
-
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
1046
|
-
const sliceName = name.replace(listName, `${modelName}In`);
|
|
1047
|
-
const [argMetas] = getArgMetas(target, gqlMeta.key);
|
|
1048
|
-
const skipIdx = argMetas.findIndex((argMeta) => argMeta.name === "skip");
|
|
1049
|
-
if (skipIdx === -1)
|
|
1050
|
-
throw new Error(`Invalid Args for ${sliceName}`);
|
|
1051
|
-
const argLength = skipIdx;
|
|
1052
|
-
const queryArgRefs = argMetas.slice(0, skipIdx).map((argMeta) => argMeta.returns());
|
|
1053
|
-
const defaultArgs = queryArgRefs.map(
|
|
1054
|
-
(queryArgRef, idx) => argMetas[idx].argsOption.nullable ? null : getDefaultArg(queryArgRef)
|
|
1055
|
-
);
|
|
1056
|
-
return { refName: modelName, sliceName, argLength, defaultArgs };
|
|
1057
|
-
})
|
|
1058
|
-
];
|
|
1059
|
-
setSigMeta(target, { returns, prefix, slices, refName: modelName });
|
|
1060
|
-
setSignalRefOnStorage(modelName, target);
|
|
1061
|
-
} else {
|
|
1062
|
-
const refName = typeof returnsOrObj === "object" ? lowerlize(returnsOrObj.name) : void 0;
|
|
1063
|
-
if (!refName)
|
|
1064
|
-
throw new Error("Signal name is required");
|
|
1065
|
-
setSigMeta(target, { returns, prefix, slices: [], refName });
|
|
1066
|
-
setSignalRefOnStorage(refName, target);
|
|
1067
|
-
}
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
var createArgMetaDecorator = (type) => {
|
|
1071
|
-
return function(option = {}) {
|
|
1072
|
-
return function(prototype, key, idx) {
|
|
1073
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1074
|
-
argMetas[idx] = { key, idx, type, option };
|
|
1075
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1076
|
-
};
|
|
1077
|
-
};
|
|
1078
|
-
};
|
|
1079
|
-
var Account = createArgMetaDecorator("Account");
|
|
1080
|
-
var defaultAccount = {
|
|
1081
|
-
__InternalArg__: "Account",
|
|
1082
|
-
appName: baseEnv.appName,
|
|
1083
|
-
environment: baseEnv.environment
|
|
1084
|
-
};
|
|
1085
|
-
var Self = createArgMetaDecorator("Self");
|
|
1086
|
-
var Me = createArgMetaDecorator("Me");
|
|
1087
|
-
var UserIp = createArgMetaDecorator("UserIp");
|
|
1088
|
-
var Access = createArgMetaDecorator("Access");
|
|
1089
|
-
var Req = createArgMetaDecorator("Req");
|
|
1090
|
-
var Res = createArgMetaDecorator("Res");
|
|
1091
|
-
var Ws = createArgMetaDecorator("Ws");
|
|
1092
|
-
var Job = createArgMetaDecorator("Job");
|
|
1093
|
-
var getQuery = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
1094
|
-
return (prototype, key, descriptor) => {
|
|
1095
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1096
|
-
metadataMap.set(key, {
|
|
1097
|
-
returns,
|
|
1098
|
-
signalOption,
|
|
1099
|
-
key,
|
|
1100
|
-
descriptor,
|
|
1101
|
-
guards: [allow2, ...guards],
|
|
1102
|
-
type: "Query"
|
|
1103
|
-
});
|
|
1104
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1105
|
-
};
|
|
1106
|
-
};
|
|
1107
|
-
var getMutation = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
1108
|
-
return (prototype, key, descriptor) => {
|
|
1109
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1110
|
-
metadataMap.set(key, {
|
|
1111
|
-
returns,
|
|
1112
|
-
signalOption,
|
|
1113
|
-
key,
|
|
1114
|
-
descriptor,
|
|
1115
|
-
guards: [allow2, ...guards],
|
|
1116
|
-
type: "Mutation"
|
|
1117
|
-
});
|
|
1118
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1119
|
-
};
|
|
1120
|
-
};
|
|
1121
|
-
var getMessage = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
1122
|
-
return (prototype, key, descriptor) => {
|
|
1123
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1124
|
-
metadataMap.set(key, {
|
|
1125
|
-
returns,
|
|
1126
|
-
signalOption,
|
|
1127
|
-
key,
|
|
1128
|
-
descriptor,
|
|
1129
|
-
guards: [allow2, ...guards],
|
|
1130
|
-
type: "Message"
|
|
1131
|
-
});
|
|
1132
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1133
|
-
};
|
|
1134
|
-
};
|
|
1135
|
-
var getPubsub = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
1136
|
-
return (prototype, key, descriptor) => {
|
|
1137
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1138
|
-
metadataMap.set(key, {
|
|
1139
|
-
returns,
|
|
1140
|
-
signalOption,
|
|
1141
|
-
key,
|
|
1142
|
-
descriptor,
|
|
1143
|
-
guards: [allow2, ...guards],
|
|
1144
|
-
type: "Pubsub"
|
|
1145
|
-
});
|
|
1146
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1147
|
-
};
|
|
1148
|
-
};
|
|
1149
|
-
var getProcess = (serverType) => function(returns, signalOption = {}) {
|
|
1150
|
-
return (prototype, key, descriptor) => {
|
|
1151
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1152
|
-
metadataMap.set(key, {
|
|
1153
|
-
returns,
|
|
1154
|
-
signalOption: { ...signalOption, serverType: lowerlize(serverType) },
|
|
1155
|
-
key,
|
|
1156
|
-
descriptor,
|
|
1157
|
-
guards: ["None"],
|
|
1158
|
-
type: "Process"
|
|
1159
|
-
});
|
|
1160
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1161
|
-
};
|
|
1162
|
-
};
|
|
1163
|
-
var Query = {
|
|
1164
|
-
Public: getQuery("Public"),
|
|
1165
|
-
Every: getQuery("Every"),
|
|
1166
|
-
Admin: getQuery("Admin"),
|
|
1167
|
-
User: getQuery("User"),
|
|
1168
|
-
SuperAdmin: getQuery("SuperAdmin"),
|
|
1169
|
-
None: getQuery("None"),
|
|
1170
|
-
Owner: getQuery("Owner")
|
|
1171
|
-
};
|
|
1172
|
-
var Mutation = {
|
|
1173
|
-
Public: getMutation("Public"),
|
|
1174
|
-
Every: getMutation("Every"),
|
|
1175
|
-
Admin: getMutation("Admin"),
|
|
1176
|
-
User: getMutation("User"),
|
|
1177
|
-
SuperAdmin: getMutation("SuperAdmin"),
|
|
1178
|
-
None: getMutation("None"),
|
|
1179
|
-
Owner: getMutation("Owner")
|
|
1180
|
-
};
|
|
1181
|
-
var Message = {
|
|
1182
|
-
Public: getMessage("Public"),
|
|
1183
|
-
Every: getMessage("Every"),
|
|
1184
|
-
Admin: getMessage("Admin"),
|
|
1185
|
-
User: getMessage("User"),
|
|
1186
|
-
SuperAdmin: getMessage("SuperAdmin"),
|
|
1187
|
-
None: getMessage("None"),
|
|
1188
|
-
Owner: getMessage("Owner")
|
|
1189
|
-
};
|
|
1190
|
-
var Pubsub = {
|
|
1191
|
-
Public: getPubsub("Public"),
|
|
1192
|
-
Every: getPubsub("Every"),
|
|
1193
|
-
Admin: getPubsub("Admin"),
|
|
1194
|
-
User: getPubsub("User"),
|
|
1195
|
-
SuperAdmin: getPubsub("SuperAdmin"),
|
|
1196
|
-
None: getPubsub("None"),
|
|
1197
|
-
Owner: getPubsub("Owner")
|
|
1198
|
-
};
|
|
1199
|
-
var Process = {
|
|
1200
|
-
Federation: getProcess("Federation"),
|
|
1201
|
-
Batch: getProcess("Batch"),
|
|
1202
|
-
All: getProcess("All")
|
|
1203
|
-
};
|
|
1204
|
-
var getArg = (type) => function(name, returns, argsOption = {}) {
|
|
1205
|
-
return function(prototype, key, idx) {
|
|
1206
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1207
|
-
argMetas[idx] = { name, returns, argsOption, key, idx, type };
|
|
1208
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1209
|
-
};
|
|
1210
|
-
};
|
|
1211
|
-
var Arg = {
|
|
1212
|
-
Body: getArg("Body"),
|
|
1213
|
-
Param: getArg("Param"),
|
|
1214
|
-
Query: getArg("Query"),
|
|
1215
|
-
Upload: getArg("Upload"),
|
|
1216
|
-
Msg: getArg("Msg"),
|
|
1217
|
-
Room: getArg("Room")
|
|
1218
|
-
};
|
|
1219
|
-
function LogSignal(srv) {
|
|
1220
|
-
class BaseSignal {
|
|
1221
|
-
}
|
|
1222
|
-
return BaseSignal;
|
|
1223
|
-
}
|
|
1224
|
-
var getSigMeta = (sigRef) => {
|
|
1225
|
-
const sigMeta = Reflect.getMetadata("signal", sigRef.prototype);
|
|
1226
|
-
if (!sigMeta)
|
|
1227
|
-
throw new Error(`No SignalMeta found for ${sigRef.name}`);
|
|
1228
|
-
return sigMeta;
|
|
1229
|
-
};
|
|
1230
|
-
var setSigMeta = (sigRef, sigMeta) => {
|
|
1231
|
-
Reflect.defineMetadata("signal", sigMeta, sigRef.prototype);
|
|
1232
|
-
};
|
|
1233
|
-
var getGqlMeta = (sigRef, key) => {
|
|
1234
|
-
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
1235
|
-
if (!gqlMetaMap)
|
|
1236
|
-
throw new Error(`No GqlMeta found for ${sigRef.name}`);
|
|
1237
|
-
const gqlMeta = gqlMetaMap.get(key);
|
|
1238
|
-
if (!gqlMeta)
|
|
1239
|
-
throw new Error(`No GqlMeta found for ${key}`);
|
|
1240
|
-
return gqlMeta;
|
|
1241
|
-
};
|
|
1242
|
-
var getGqlMetaMapOnPrototype = (prototype) => {
|
|
1243
|
-
const gqlMetaMap = Reflect.getMetadata("gql", prototype);
|
|
1244
|
-
return gqlMetaMap ?? /* @__PURE__ */ new Map();
|
|
1245
|
-
};
|
|
1246
|
-
var getGqlMetas = (sigRef) => {
|
|
1247
|
-
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
1248
|
-
return gqlMetaMap ? [...gqlMetaMap.values()] : [];
|
|
1249
|
-
};
|
|
1250
|
-
var setGqlMetaMapOnPrototype = (prototype, gqlMetaMap) => {
|
|
1251
|
-
Reflect.defineMetadata("gql", gqlMetaMap, prototype);
|
|
1252
|
-
};
|
|
1253
|
-
var getArgMetas = (sigRef, key) => {
|
|
1254
|
-
const metas = Reflect.getMetadata("args", sigRef.prototype, key) ?? [];
|
|
1255
|
-
const argMetas = metas.filter((meta) => !!meta.returns);
|
|
1256
|
-
const internalArgMetas = metas.filter((meta) => !meta.returns);
|
|
1257
|
-
return [argMetas, internalArgMetas];
|
|
1258
|
-
};
|
|
1259
|
-
var getArgMetasOnPrototype = (prototype, key) => {
|
|
1260
|
-
return Reflect.getMetadata("args", prototype, key) ?? [];
|
|
1261
|
-
};
|
|
1262
|
-
var setArgMetasOnPrototype = (prototype, key, argMetas) => {
|
|
1263
|
-
Reflect.defineMetadata("args", argMetas, prototype, key);
|
|
1264
|
-
};
|
|
1265
|
-
var getResolveFieldMetaMapOnPrototype = (prototype) => {
|
|
1266
|
-
const resolveFieldMetaMap = Reflect.getMetadata("resolveField", prototype);
|
|
1267
|
-
return resolveFieldMetaMap ?? /* @__PURE__ */ new Map();
|
|
1268
|
-
};
|
|
1269
|
-
var getResolveFieldMetas = (sigRef) => {
|
|
1270
|
-
const resolveFieldMetaMap = Reflect.getMetadata("resolveField", sigRef.prototype);
|
|
1271
|
-
return resolveFieldMetaMap ? [...resolveFieldMetaMap.values()] : [];
|
|
1272
|
-
};
|
|
1273
|
-
var setResolveFieldMetaMapOnPrototype = (prototype, resolveFieldMetaMap) => {
|
|
1274
|
-
Reflect.defineMetadata("resolveField", resolveFieldMetaMap, prototype);
|
|
1275
|
-
};
|
|
1276
|
-
var getControllerPrefix = (sigMeta) => {
|
|
1277
|
-
return sigMeta.returns ? lowerlize(getClassMeta(sigMeta.returns()).refName) : sigMeta.prefix;
|
|
1278
|
-
};
|
|
1279
|
-
var getControllerPath = (gqlMeta, paramArgMetas) => {
|
|
1280
|
-
return gqlMeta.signalOption.path ?? [gqlMeta.signalOption.name ?? gqlMeta.key, ...paramArgMetas.map((argMeta) => `:${argMeta.name}`)].join("/");
|
|
1281
|
-
};
|
|
1282
|
-
var copySignal = (sigRef) => {
|
|
1283
|
-
class CopiedSignal {
|
|
1284
|
-
}
|
|
1285
|
-
applyMixins(CopiedSignal, [sigRef]);
|
|
1286
|
-
const sigMeta = getSigMeta(sigRef);
|
|
1287
|
-
setSigMeta(CopiedSignal, sigMeta);
|
|
1288
|
-
const gqlMetaMap = getGqlMetaMapOnPrototype(sigRef.prototype);
|
|
1289
|
-
setGqlMetaMapOnPrototype(CopiedSignal.prototype, new Map(gqlMetaMap));
|
|
1290
|
-
const resolveFieldMetaMap = getResolveFieldMetaMapOnPrototype(sigRef.prototype);
|
|
1291
|
-
setResolveFieldMetaMapOnPrototype(CopiedSignal.prototype, new Map(resolveFieldMetaMap));
|
|
1292
|
-
for (const endpointMeta of [...gqlMetaMap.values(), ...resolveFieldMetaMap.values()]) {
|
|
1293
|
-
const argMetas = getArgMetasOnPrototype(sigRef.prototype, endpointMeta.key);
|
|
1294
|
-
setArgMetasOnPrototype(CopiedSignal.prototype, endpointMeta.key, [...argMetas]);
|
|
1295
|
-
const paramtypes = Reflect.getMetadata("design:paramtypes", sigRef.prototype, endpointMeta.key);
|
|
1296
|
-
const argParamtypes = argMetas.filter((argMeta) => !!argMeta.returns).map((argMeta) => Object);
|
|
1297
|
-
Reflect.defineMetadata("design:paramtypes", paramtypes ?? argParamtypes, CopiedSignal.prototype, endpointMeta.key);
|
|
1298
|
-
Reflect.defineMetadata("design:paramtypes", paramtypes ?? argParamtypes, CopiedSignal.prototype, endpointMeta.key);
|
|
1299
|
-
}
|
|
1300
|
-
return CopiedSignal;
|
|
1301
|
-
};
|
|
1302
|
-
|
|
1303
|
-
// pkgs/@akanjs/signal/src/gql.ts
|
|
1304
|
-
var DefaultStorage = class {
|
|
1305
|
-
};
|
|
1306
|
-
var getPredefinedDefault = (refName) => {
|
|
1307
|
-
const defaultData = Reflect.getMetadata(refName, DefaultStorage.prototype);
|
|
1308
|
-
return defaultData;
|
|
1309
|
-
};
|
|
1310
|
-
var setPredefinedDefault = (refName, defaultData) => {
|
|
1311
|
-
Reflect.defineMetadata(refName, defaultData, DefaultStorage.prototype);
|
|
1312
|
-
};
|
|
1313
|
-
var makeDefault = (target, option = {}) => {
|
|
1314
|
-
const classMeta = getClassMeta(target);
|
|
1315
|
-
const predefinedDefault = getPredefinedDefault(classMeta.refName);
|
|
1316
|
-
if (predefinedDefault && !option.overwrite)
|
|
1317
|
-
return predefinedDefault;
|
|
1318
|
-
if (option.isChild && classMeta.type !== "scalar")
|
|
1319
|
-
return null;
|
|
1320
|
-
const metadatas = getFieldMetas(target);
|
|
1321
|
-
const result = {};
|
|
1322
|
-
for (const metadata of metadatas) {
|
|
1323
|
-
if (metadata.fieldType === "hidden")
|
|
1324
|
-
result[metadata.key] = null;
|
|
1325
|
-
else if (metadata.default) {
|
|
1326
|
-
if (typeof metadata.default === "function")
|
|
1327
|
-
result[metadata.key] = metadata.default();
|
|
1328
|
-
else if (metadata.default instanceof Enum)
|
|
1329
|
-
result[metadata.key] = [...metadata.default.values];
|
|
1330
|
-
else
|
|
1331
|
-
result[metadata.key] = metadata.default;
|
|
1332
|
-
} else if (metadata.isArray)
|
|
1333
|
-
result[metadata.key] = [];
|
|
1334
|
-
else if (metadata.nullable)
|
|
1335
|
-
result[metadata.key] = null;
|
|
1336
|
-
else if (metadata.isClass)
|
|
1337
|
-
result[metadata.key] = metadata.isScalar ? makeDefault(metadata.modelRef) : null;
|
|
1338
|
-
else
|
|
1339
|
-
result[metadata.key] = scalarDefaultMap.get(metadata.modelRef);
|
|
1340
|
-
}
|
|
1341
|
-
setPredefinedDefault(classMeta.refName, result);
|
|
1342
|
-
return result;
|
|
1343
|
-
};
|
|
1344
|
-
var scalarDeserializeMap = /* @__PURE__ */ new Map([
|
|
1345
|
-
[Date, (value) => dayjs(value)],
|
|
1346
|
-
[String, (value) => value],
|
|
1347
|
-
[ID, (value) => value],
|
|
1348
|
-
[Boolean, (value) => value],
|
|
1349
|
-
[Int, (value) => value],
|
|
1350
|
-
[Float, (value) => value],
|
|
1351
|
-
[JSON2, (value) => value]
|
|
1352
|
-
]);
|
|
1353
|
-
var getDeserializeFn = (inputRef) => {
|
|
1354
|
-
const deserializeFn = scalarDeserializeMap.get(inputRef);
|
|
1355
|
-
if (!deserializeFn)
|
|
1356
|
-
return (value) => value;
|
|
1357
|
-
return deserializeFn;
|
|
1358
|
-
};
|
|
1359
|
-
var deserializeInput = (value, inputRef, arrDepth) => {
|
|
1360
|
-
if (arrDepth && Array.isArray(value))
|
|
1361
|
-
return value.map((v) => deserializeInput(v, inputRef, arrDepth - 1));
|
|
1362
|
-
else if (inputRef.prototype === Map.prototype) {
|
|
1363
|
-
const [valueRef] = getNonArrayModel(inputRef);
|
|
1364
|
-
const deserializeFn = getDeserializeFn(valueRef);
|
|
1365
|
-
return Object.fromEntries(
|
|
1366
|
-
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, deserializeFn)])
|
|
1367
|
-
);
|
|
1368
|
-
} else if (isGqlScalar(inputRef)) {
|
|
1369
|
-
const deserializeFn = getDeserializeFn(inputRef);
|
|
1370
|
-
return deserializeFn(value);
|
|
1371
|
-
}
|
|
1372
|
-
const classMeta = getClassMeta(inputRef);
|
|
1373
|
-
if (classMeta.type !== "scalar")
|
|
1374
|
-
return value;
|
|
1375
|
-
else
|
|
1376
|
-
return Object.fromEntries(
|
|
1377
|
-
getFieldMetas(inputRef).map((fieldMeta) => [
|
|
1378
|
-
fieldMeta.key,
|
|
1379
|
-
deserializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
|
|
1380
|
-
])
|
|
1381
|
-
);
|
|
1382
|
-
};
|
|
1383
|
-
var deserializeArg = (argMeta, value) => {
|
|
1384
|
-
const [returnRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
1385
|
-
if (argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
1386
|
-
return null;
|
|
1387
|
-
else if (!argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
1388
|
-
throw new Error(`Invalid Value (Nullable) in ${argMeta.name} for value ${value}`);
|
|
1389
|
-
return deserializeInput(value, returnRef, arrDepth);
|
|
1390
|
-
};
|
|
1391
|
-
|
|
1392
|
-
// pkgs/@akanjs/signal/src/baseFetch.ts
|
|
1393
|
-
var nativeFetch = fetch;
|
|
1394
|
-
var baseFetch = Object.assign(nativeFetch, {
|
|
1395
|
-
client,
|
|
1396
|
-
clone: function(option = {}) {
|
|
1397
|
-
return {
|
|
1398
|
-
...this,
|
|
1399
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
1400
|
-
client: this.client.clone(option)
|
|
1401
|
-
};
|
|
1402
|
-
}
|
|
1403
|
-
});
|
|
1404
|
-
|
|
1405
|
-
// pkgs/@akanjs/nest/src/authorization.ts
|
|
1406
|
-
var import_apollo = require("@nestjs/apollo");
|
|
1407
|
-
var jwt = __toESM(require("jsonwebtoken"));
|
|
1408
|
-
var verifyToken = (secret, authorization) => {
|
|
1409
|
-
const [type, token] = authorization?.split(" ") ?? [void 0, void 0];
|
|
1410
|
-
if (!token || type !== "Bearer")
|
|
1411
|
-
return defaultAccount;
|
|
1412
|
-
try {
|
|
1413
|
-
const account = jwt.verify(token, secret);
|
|
1414
|
-
if (account.appName !== baseEnv.appName || account.environment !== baseEnv.environment)
|
|
1415
|
-
return defaultAccount;
|
|
1416
|
-
return {
|
|
1417
|
-
__InternalArg__: "Account",
|
|
1418
|
-
self: account.self && !account.self.removedAt ? account.self : void 0,
|
|
1419
|
-
me: account.me && !account.me.removedAt ? account.me : void 0,
|
|
1420
|
-
appName: account.appName,
|
|
1421
|
-
environment: account.environment
|
|
1422
|
-
};
|
|
1423
|
-
} catch (e) {
|
|
1424
|
-
return defaultAccount;
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
var allow = (account, roles, userId) => {
|
|
1428
|
-
if (!account)
|
|
1429
|
-
throw new import_apollo.AuthenticationError("No Authentication Account");
|
|
1430
|
-
for (const role of roles) {
|
|
1431
|
-
if (role === "user" && account.self?.roles.includes("user"))
|
|
1432
|
-
return true;
|
|
1433
|
-
else if (role === "admin" && account.me?.roles.includes("admin"))
|
|
1434
|
-
return true;
|
|
1435
|
-
else if (role === "superAdmin" && account.me?.roles.includes("superAdmin"))
|
|
1436
|
-
return true;
|
|
1437
|
-
}
|
|
1438
|
-
throw new import_apollo.AuthenticationError(
|
|
1439
|
-
`No Authentication With Roles: ${roles.join(", ")}, Your roles are ${[
|
|
1440
|
-
...account.self?.roles ?? [],
|
|
1441
|
-
...account.me?.roles ?? []
|
|
1442
|
-
].join(", ")}${!account.self?.roles.length && !account.me?.roles.length ? " (No Roles)" : ""}`
|
|
1443
|
-
);
|
|
1444
|
-
};
|
|
1445
|
-
|
|
1446
|
-
// pkgs/@akanjs/nest/src/authGuards.ts
|
|
1447
|
-
var authGuards_exports = {};
|
|
1448
|
-
__export(authGuards_exports, {
|
|
1449
|
-
Admin: () => Admin,
|
|
1450
|
-
Every: () => Every,
|
|
1451
|
-
None: () => None,
|
|
1452
|
-
Owner: () => Owner,
|
|
1453
|
-
Public: () => Public,
|
|
1454
|
-
SuperAdmin: () => SuperAdmin,
|
|
1455
|
-
User: () => User,
|
|
1456
|
-
getArgs: () => getArgs,
|
|
1457
|
-
getRequest: () => getRequest,
|
|
1458
|
-
getResponse: () => getResponse,
|
|
1459
|
-
getSocket: () => getSocket
|
|
1460
|
-
});
|
|
1461
|
-
var import_common6 = require("@nestjs/common");
|
|
1462
|
-
var import_graphql3 = require("@nestjs/graphql");
|
|
1463
|
-
var getRequest = (context) => {
|
|
1464
|
-
const type = context.getType();
|
|
1465
|
-
if (type === "ws")
|
|
1466
|
-
throw new Error("Getting Request in Websocket is not allowed");
|
|
1467
|
-
return type === "http" ? context.switchToHttp().getRequest() : import_graphql3.GqlExecutionContext.create(context).getContext().req;
|
|
1468
|
-
};
|
|
1469
|
-
var getResponse = (context) => {
|
|
1470
|
-
const type = context.getType();
|
|
1471
|
-
if (type === "ws")
|
|
1472
|
-
throw new Error("Getting Response in Websocket is not allowed");
|
|
1473
|
-
return type === "http" ? context.switchToHttp().getResponse() : import_graphql3.GqlExecutionContext.create(context).getContext().req.res;
|
|
1474
|
-
};
|
|
1475
|
-
var getArgs = (context) => {
|
|
1476
|
-
const type = context.getType();
|
|
1477
|
-
if (type === "ws")
|
|
1478
|
-
throw new Error("Getting Args in Websocket is not allowed");
|
|
1479
|
-
if (type === "graphql")
|
|
1480
|
-
return import_graphql3.GqlExecutionContext.create(context).getArgs();
|
|
1481
|
-
else if (type === "http") {
|
|
1482
|
-
const { params, query, body } = context.switchToHttp().getRequest();
|
|
1483
|
-
return { ...params, ...query, ...body };
|
|
1484
|
-
} else
|
|
1485
|
-
throw new Error("Getting Args in Unknown context is not allowed");
|
|
1486
|
-
};
|
|
1487
|
-
var getSocket = (context) => {
|
|
1488
|
-
const type = context.getType();
|
|
1489
|
-
if (type !== "ws")
|
|
1490
|
-
throw new Error("Getting Socket in Http or GraphQL is not allowed");
|
|
1491
|
-
const socket = context.getArgByIndex(0);
|
|
1492
|
-
return socket;
|
|
1493
|
-
};
|
|
1494
|
-
var Public = class {
|
|
1495
|
-
canActivate(context) {
|
|
1496
|
-
return true;
|
|
1497
|
-
}
|
|
1498
|
-
};
|
|
1499
|
-
Public = __decorateClass([
|
|
1500
|
-
(0, import_common6.Injectable)()
|
|
1501
|
-
], Public);
|
|
1502
|
-
var None = class {
|
|
1503
|
-
canActivate() {
|
|
1504
|
-
return false;
|
|
1505
|
-
}
|
|
1506
|
-
};
|
|
1507
|
-
None = __decorateClass([
|
|
1508
|
-
(0, import_common6.Injectable)()
|
|
1509
|
-
], None);
|
|
1510
|
-
var Every = class {
|
|
1511
|
-
canActivate(context) {
|
|
1512
|
-
const { account } = getRequest(context);
|
|
1513
|
-
return allow(account, ["user", "admin", "superAdmin"]);
|
|
1514
|
-
}
|
|
1515
|
-
};
|
|
1516
|
-
Every = __decorateClass([
|
|
1517
|
-
(0, import_common6.Injectable)()
|
|
1518
|
-
], Every);
|
|
1519
|
-
var Owner = class {
|
|
1520
|
-
canActivate(context) {
|
|
1521
|
-
const { account } = getRequest(context);
|
|
1522
|
-
return allow(account, ["user", "admin", "superAdmin"]);
|
|
1523
|
-
}
|
|
1524
|
-
};
|
|
1525
|
-
Owner = __decorateClass([
|
|
1526
|
-
(0, import_common6.Injectable)()
|
|
1527
|
-
], Owner);
|
|
1528
|
-
var Admin = class {
|
|
1529
|
-
canActivate(context) {
|
|
1530
|
-
const { account } = getRequest(context);
|
|
1531
|
-
return allow(account, ["admin", "superAdmin"]);
|
|
1532
|
-
}
|
|
1533
|
-
};
|
|
1534
|
-
Admin = __decorateClass([
|
|
1535
|
-
(0, import_common6.Injectable)()
|
|
1536
|
-
], Admin);
|
|
1537
|
-
var SuperAdmin = class {
|
|
1538
|
-
canActivate(context) {
|
|
1539
|
-
const { account } = getRequest(context);
|
|
1540
|
-
return allow(account, ["superAdmin"]);
|
|
1541
|
-
}
|
|
1542
|
-
};
|
|
1543
|
-
SuperAdmin = __decorateClass([
|
|
1544
|
-
(0, import_common6.Injectable)()
|
|
1545
|
-
], SuperAdmin);
|
|
1546
|
-
var User = class {
|
|
1547
|
-
canActivate(context) {
|
|
1548
|
-
const { account } = getRequest(context);
|
|
1549
|
-
return allow(account, ["user"]);
|
|
1550
|
-
}
|
|
1551
|
-
};
|
|
1552
|
-
User = __decorateClass([
|
|
1553
|
-
(0, import_common6.Injectable)()
|
|
1554
|
-
], User);
|
|
1555
|
-
|
|
1556
|
-
// pkgs/@akanjs/nest/src/authentication.ts
|
|
1557
|
-
var import_common7 = require("@nestjs/common");
|
|
1558
|
-
var import_ua_parser_js = __toESM(require("ua-parser-js"));
|
|
1559
|
-
var Account3 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1560
|
-
const { account } = getRequest(context);
|
|
1561
|
-
return account;
|
|
1562
|
-
});
|
|
1563
|
-
var Self2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1564
|
-
const { account } = getRequest(context);
|
|
1565
|
-
const self = account.self;
|
|
1566
|
-
if (!self && !option.nullable)
|
|
1567
|
-
throw new import_common7.UnauthorizedException("No or Invalid Account in Self (User)");
|
|
1568
|
-
return self;
|
|
1569
|
-
});
|
|
1570
|
-
var Me2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1571
|
-
const { account } = getRequest(context);
|
|
1572
|
-
const me = account.me;
|
|
1573
|
-
if (!me && !option.nullable)
|
|
1574
|
-
throw new import_common7.UnauthorizedException("No or Invalid Account in Me (Admin)");
|
|
1575
|
-
return me;
|
|
1576
|
-
});
|
|
1577
|
-
var UserIp2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1578
|
-
const req = getRequest(context);
|
|
1579
|
-
const ip = req.ip;
|
|
1580
|
-
if (!ip && !option.nullable)
|
|
1581
|
-
throw new import_common7.UnauthorizedException("Invalid IP");
|
|
1582
|
-
return { ip };
|
|
1583
|
-
});
|
|
1584
|
-
var Access2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1585
|
-
const req = getRequest(context);
|
|
1586
|
-
const res = new import_ua_parser_js.default(req.userAgent).getResult();
|
|
1587
|
-
if (!req.userAgent && !option.nullable)
|
|
1588
|
-
throw new import_common7.UnauthorizedException("Invalid UserAgent");
|
|
1589
|
-
return {
|
|
1590
|
-
...req.geolocation ? JSON.parse(req.geolocation) : {},
|
|
1591
|
-
osName: res.os.name,
|
|
1592
|
-
osVersion: res.os.version,
|
|
1593
|
-
browserName: res.browser.name,
|
|
1594
|
-
browserVersion: res.browser.version,
|
|
1595
|
-
mobileModel: res.device.model,
|
|
1596
|
-
mobileVendor: res.device.vendor,
|
|
1597
|
-
deviceType: res.device.type ?? "desktop",
|
|
1598
|
-
at: dayjs(),
|
|
1599
|
-
period: 0
|
|
1600
|
-
};
|
|
1601
|
-
});
|
|
1602
|
-
var Req2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1603
|
-
return getRequest(context);
|
|
1604
|
-
});
|
|
1605
|
-
var Res2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1606
|
-
return getResponse(context);
|
|
1607
|
-
});
|
|
1608
|
-
var Ws2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1609
|
-
const socket = context.getArgByIndex(0);
|
|
1610
|
-
const { __subscribe__ } = context.getArgByIndex(1);
|
|
1611
|
-
return {
|
|
1612
|
-
socket,
|
|
1613
|
-
subscribe: __subscribe__,
|
|
1614
|
-
onDisconnect: (handler) => {
|
|
1615
|
-
socket.on("disconnect", handler);
|
|
1616
|
-
},
|
|
1617
|
-
onSubscribe: (handler) => {
|
|
1618
|
-
if (__subscribe__)
|
|
1619
|
-
handler();
|
|
1620
|
-
},
|
|
1621
|
-
onUnsubscribe: (handler) => {
|
|
1622
|
-
if (!__subscribe__)
|
|
1623
|
-
handler();
|
|
1624
|
-
}
|
|
1625
|
-
};
|
|
1626
|
-
});
|
|
1627
|
-
|
|
1628
|
-
// pkgs/@akanjs/nest/src/interceptors.ts
|
|
1629
|
-
var import_common9 = require("@nestjs/common");
|
|
1630
|
-
var import_graphql4 = require("@nestjs/graphql");
|
|
1631
|
-
var import_rxjs = require("rxjs");
|
|
1632
|
-
var import_operators = require("rxjs/operators");
|
|
1633
|
-
var _logger, _CACHE_PREFIX, _generateCacheKey, generateCacheKey_fn, _getCache, getCache_fn, _setCache, setCache_fn;
|
|
1634
|
-
var CacheInterceptor = class {
|
|
1635
|
-
constructor(redis) {
|
|
1636
|
-
this.redis = redis;
|
|
1637
|
-
__privateAdd(this, _generateCacheKey);
|
|
1638
|
-
__privateAdd(this, _getCache);
|
|
1639
|
-
__privateAdd(this, _setCache);
|
|
1640
|
-
__privateAdd(this, _logger, new Logger("CacheInterceptor"));
|
|
1641
|
-
__privateAdd(this, _CACHE_PREFIX, "signal:");
|
|
1642
|
-
}
|
|
1643
|
-
async intercept(context, next) {
|
|
1644
|
-
const handler = context.getHandler();
|
|
1645
|
-
const signalKey = handler.name;
|
|
1646
|
-
const gqlMeta = getGqlMeta(context.getClass(), signalKey);
|
|
1647
|
-
if (gqlMeta.type !== "Query" || !gqlMeta.signalOption.cache) {
|
|
1648
|
-
if (gqlMeta.signalOption.cache)
|
|
1649
|
-
__privateGet(this, _logger).warn(`CacheInterceptor: ${signalKey} is not Query endpoint or cache is not set`);
|
|
1650
|
-
return next.handle();
|
|
1651
|
-
}
|
|
1652
|
-
const args = getArgs(context);
|
|
1653
|
-
const cacheKey = __privateMethod(this, _generateCacheKey, generateCacheKey_fn).call(this, signalKey, args);
|
|
1654
|
-
const cachedData = await __privateMethod(this, _getCache, getCache_fn).call(this, cacheKey);
|
|
1655
|
-
if (cachedData) {
|
|
1656
|
-
__privateGet(this, _logger).debug(`Cache hit for key: ${cacheKey}`);
|
|
1657
|
-
return next.handle().pipe(
|
|
1658
|
-
(0, import_operators.map)(() => cachedData),
|
|
1659
|
-
(0, import_operators.catchError)((error) => {
|
|
1660
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1661
|
-
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
1662
|
-
return (0, import_rxjs.throwError)(() => error);
|
|
1663
|
-
})
|
|
1664
|
-
);
|
|
1665
|
-
}
|
|
1666
|
-
return next.handle().pipe(
|
|
1667
|
-
(0, import_operators.map)((data) => {
|
|
1668
|
-
const cacheDuration = gqlMeta.signalOption.cache;
|
|
1669
|
-
if (typeof cacheDuration === "number") {
|
|
1670
|
-
void __privateMethod(this, _setCache, setCache_fn).call(this, cacheKey, data, cacheDuration);
|
|
1671
|
-
__privateGet(this, _logger).debug(`Cache set for key: ${cacheKey}`);
|
|
1672
|
-
}
|
|
1673
|
-
return data;
|
|
1674
|
-
}),
|
|
1675
|
-
(0, import_operators.catchError)((error) => {
|
|
1676
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1677
|
-
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
1678
|
-
return (0, import_rxjs.throwError)(() => error);
|
|
1679
|
-
})
|
|
1680
|
-
);
|
|
1681
|
-
}
|
|
1682
|
-
};
|
|
1683
|
-
_logger = new WeakMap();
|
|
1684
|
-
_CACHE_PREFIX = new WeakMap();
|
|
1685
|
-
_generateCacheKey = new WeakSet();
|
|
1686
|
-
generateCacheKey_fn = function(signalKey, args) {
|
|
1687
|
-
return `${__privateGet(this, _CACHE_PREFIX)}${signalKey}:${JSON.stringify(args)}`;
|
|
1688
|
-
};
|
|
1689
|
-
_getCache = new WeakSet();
|
|
1690
|
-
getCache_fn = async function(key) {
|
|
1691
|
-
try {
|
|
1692
|
-
const cached = await this.redis.get(key);
|
|
1693
|
-
if (!cached)
|
|
1694
|
-
return null;
|
|
1695
|
-
const { data } = JSON.parse(cached);
|
|
1696
|
-
return data;
|
|
1697
|
-
} catch (error) {
|
|
1698
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1699
|
-
__privateGet(this, _logger).error(`Error retrieving cache for key ${key}: ${errorMessage}`);
|
|
1700
|
-
return null;
|
|
1701
|
-
}
|
|
1702
|
-
};
|
|
1703
|
-
_setCache = new WeakSet();
|
|
1704
|
-
setCache_fn = async function(key, data, ttlMs) {
|
|
1705
|
-
try {
|
|
1706
|
-
const cacheData = { data, timestamp: Date.now() };
|
|
1707
|
-
await this.redis.set(key, JSON.stringify(cacheData), { PX: ttlMs });
|
|
1708
|
-
} catch (error) {
|
|
1709
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1710
|
-
__privateGet(this, _logger).error(`Error setting cache for key ${key}: ${errorMessage}`);
|
|
1711
|
-
}
|
|
1712
|
-
};
|
|
1713
|
-
CacheInterceptor = __decorateClass([
|
|
1714
|
-
(0, import_common9.Injectable)(),
|
|
1715
|
-
__decorateParam(0, (0, import_common9.Inject)("REDIS_CLIENT"))
|
|
1716
|
-
], CacheInterceptor);
|
|
1717
|
-
var TimeoutInterceptor = class {
|
|
1718
|
-
intercept(context, next) {
|
|
1719
|
-
const gqlMeta = getGqlMeta(context.getClass(), context.getHandler().name);
|
|
1720
|
-
const timeoutMs = gqlMeta.signalOption.timeout ?? 3e4;
|
|
1721
|
-
if (timeoutMs === 0)
|
|
1722
|
-
return next.handle();
|
|
1723
|
-
return next.handle().pipe(
|
|
1724
|
-
(0, import_operators.timeout)(timeoutMs),
|
|
1725
|
-
(0, import_operators.catchError)((err) => {
|
|
1726
|
-
if (err instanceof import_rxjs.TimeoutError)
|
|
1727
|
-
return (0, import_rxjs.throwError)(() => new import_common9.RequestTimeoutException());
|
|
1728
|
-
return (0, import_rxjs.throwError)(() => err);
|
|
1729
|
-
})
|
|
1730
|
-
);
|
|
1731
|
-
}
|
|
1732
|
-
};
|
|
1733
|
-
TimeoutInterceptor = __decorateClass([
|
|
1734
|
-
(0, import_common9.Injectable)()
|
|
1735
|
-
], TimeoutInterceptor);
|
|
1736
|
-
var LoggingInterceptor = class {
|
|
1737
|
-
logger = new Logger("IO");
|
|
1738
|
-
intercept(context, next) {
|
|
1739
|
-
const gqlReq = context.getArgByIndex(3);
|
|
1740
|
-
const req = getRequest(context);
|
|
1741
|
-
const reqType = gqlReq?.parentType?.name ?? req.method;
|
|
1742
|
-
const reqName = gqlReq?.fieldName ?? req.url;
|
|
1743
|
-
const before = Date.now();
|
|
1744
|
-
const ip = import_graphql4.GqlExecutionContext.create(context).getContext().req.ip;
|
|
1745
|
-
this.logger.debug(`Before ${reqType}-${reqName} / ${ip} / ${before}`);
|
|
1746
|
-
return next.handle().pipe(
|
|
1747
|
-
(0, import_operators.tap)(() => {
|
|
1748
|
-
const after = Date.now();
|
|
1749
|
-
this.logger.debug(`After ${reqType}-${reqName} / ${ip} / ${after} (${after - before}ms)`);
|
|
1750
|
-
})
|
|
1751
|
-
);
|
|
1752
|
-
}
|
|
1753
|
-
};
|
|
1754
|
-
LoggingInterceptor = __decorateClass([
|
|
1755
|
-
(0, import_common9.Injectable)()
|
|
1756
|
-
], LoggingInterceptor);
|
|
1757
|
-
|
|
1758
|
-
// pkgs/@akanjs/nest/src/redis-io.adapter.ts
|
|
1759
|
-
var import_platform_socket = require("@nestjs/platform-socket.io");
|
|
1760
|
-
var import_redis_adapter = require("@socket.io/redis-adapter");
|
|
1761
|
-
var import_redis = require("redis");
|
|
1762
|
-
var RedisIoAdapter = class extends import_platform_socket.IoAdapter {
|
|
1763
|
-
adapterConstructor;
|
|
1764
|
-
logger = new Logger("RedisIoAdapter");
|
|
1765
|
-
server;
|
|
1766
|
-
pubClient;
|
|
1767
|
-
subClient;
|
|
1768
|
-
option;
|
|
1769
|
-
constructor(appOrHttpServer, option) {
|
|
1770
|
-
super(appOrHttpServer);
|
|
1771
|
-
this.option = option;
|
|
1772
|
-
}
|
|
1773
|
-
async connectToRedis(url) {
|
|
1774
|
-
this.pubClient = (0, import_redis.createClient)({ url });
|
|
1775
|
-
this.subClient = this.pubClient.duplicate();
|
|
1776
|
-
this.pubClient.on("disconnect", (err) => {
|
|
1777
|
-
this.logger.error(`Redis pub database is disconnected. Error: ${err}`);
|
|
1778
|
-
void this.pubClient.connect();
|
|
1779
|
-
});
|
|
1780
|
-
this.subClient.on("disconnect", (err) => {
|
|
1781
|
-
this.logger.error(`Redis sub database is disconnected. Error: ${err}`);
|
|
1782
|
-
void this.subClient.connect();
|
|
1783
|
-
});
|
|
1784
|
-
this.pubClient.on("error", (err) => {
|
|
1785
|
-
this.logger.error(`Redis pub database is errored. Error: ${err}`);
|
|
1786
|
-
const reconnect = async () => {
|
|
1787
|
-
await this.pubClient.quit();
|
|
1788
|
-
await sleep(1e3);
|
|
1789
|
-
await this.pubClient.connect();
|
|
1790
|
-
};
|
|
1791
|
-
void reconnect();
|
|
1792
|
-
});
|
|
1793
|
-
this.subClient.on("error", (err) => {
|
|
1794
|
-
this.logger.error(`Redis sub database is errored. Error: ${err}`);
|
|
1795
|
-
const reconnect = async () => {
|
|
1796
|
-
await this.subClient.quit();
|
|
1797
|
-
await sleep(1e3);
|
|
1798
|
-
await this.subClient.connect();
|
|
1799
|
-
};
|
|
1800
|
-
void reconnect();
|
|
1801
|
-
});
|
|
1802
|
-
await Promise.all([this.pubClient.connect(), this.subClient.connect()]);
|
|
1803
|
-
this.adapterConstructor = (0, import_redis_adapter.createAdapter)(this.pubClient, this.subClient);
|
|
1804
|
-
}
|
|
1805
|
-
createIOServer(port, options) {
|
|
1806
|
-
this.server = super.createIOServer(port, options);
|
|
1807
|
-
this.server.adapter(this.adapterConstructor);
|
|
1808
|
-
return this.server;
|
|
1809
|
-
}
|
|
1810
|
-
async destroy() {
|
|
1811
|
-
await Promise.all([this.pubClient.quit(), this.subClient.quit()]);
|
|
1812
|
-
await this.close(this.server);
|
|
1813
|
-
this.logger.log("RedisIoAdapter is closed");
|
|
1814
|
-
}
|
|
1815
|
-
};
|
|
1816
|
-
|
|
1817
|
-
// pkgs/@akanjs/nest/src/pipes.ts
|
|
1818
|
-
var import_common11 = require("@nestjs/common");
|
|
1819
|
-
var import_stream = require("stream");
|
|
1820
|
-
var ArrayifyPipe = class {
|
|
1821
|
-
transform(value, metadata) {
|
|
1822
|
-
return Array.isArray(value) ? value : value.split(",");
|
|
1823
|
-
}
|
|
1824
|
-
};
|
|
1825
|
-
ArrayifyPipe = __decorateClass([
|
|
1826
|
-
(0, import_common11.Injectable)()
|
|
1827
|
-
], ArrayifyPipe);
|
|
1828
|
-
var IntPipe = class {
|
|
1829
|
-
transform(value, metadata) {
|
|
1830
|
-
return Array.isArray(value) ? value.map(parseInt) : [parseInt(value)];
|
|
1831
|
-
}
|
|
1832
|
-
};
|
|
1833
|
-
IntPipe = __decorateClass([
|
|
1834
|
-
(0, import_common11.Injectable)()
|
|
1835
|
-
], IntPipe);
|
|
1836
|
-
var FloatPipe = class {
|
|
1837
|
-
transform(value, metadata) {
|
|
1838
|
-
return Array.isArray(value) ? value.map(parseFloat) : [parseFloat(value)];
|
|
1839
|
-
}
|
|
1840
|
-
};
|
|
1841
|
-
FloatPipe = __decorateClass([
|
|
1842
|
-
(0, import_common11.Injectable)()
|
|
1843
|
-
], FloatPipe);
|
|
1844
|
-
var BooleanPipe = class {
|
|
1845
|
-
transform(value, metadata) {
|
|
1846
|
-
return Array.isArray(value) ? value.map((v) => Boolean(v)) : [Boolean(value)];
|
|
1847
|
-
}
|
|
1848
|
-
};
|
|
1849
|
-
BooleanPipe = __decorateClass([
|
|
1850
|
-
(0, import_common11.Injectable)()
|
|
1851
|
-
], BooleanPipe);
|
|
1852
|
-
var DayjsPipe = class {
|
|
1853
|
-
transform(value, metadata) {
|
|
1854
|
-
return Array.isArray(value) ? value.map(dayjs) : [dayjs(value)];
|
|
1855
|
-
}
|
|
1856
|
-
};
|
|
1857
|
-
DayjsPipe = __decorateClass([
|
|
1858
|
-
(0, import_common11.Injectable)()
|
|
1859
|
-
], DayjsPipe);
|
|
1860
|
-
var JSONPipe = class {
|
|
1861
|
-
transform(value, metadata) {
|
|
1862
|
-
const transformable = typeof value === "string" && value.length;
|
|
1863
|
-
const obj = transformable ? JSON.parse(atob(value)) : value;
|
|
1864
|
-
return obj;
|
|
1865
|
-
}
|
|
1866
|
-
};
|
|
1867
|
-
JSONPipe = __decorateClass([
|
|
1868
|
-
(0, import_common11.Injectable)()
|
|
1869
|
-
], JSONPipe);
|
|
1870
|
-
var convertToFileStream = (value) => ({
|
|
1871
|
-
filename: value.originalname,
|
|
1872
|
-
mimetype: value.mimetype,
|
|
1873
|
-
encoding: value.encoding,
|
|
1874
|
-
createReadStream: () => import_stream.Readable.from(value.buffer)
|
|
1875
|
-
});
|
|
1876
|
-
var MulterToUploadPipe = class {
|
|
1877
|
-
transform(value, metadata) {
|
|
1878
|
-
return Array.isArray(value) ? value.map(convertToFileStream) : convertToFileStream(value);
|
|
1879
|
-
}
|
|
1880
|
-
};
|
|
1881
|
-
MulterToUploadPipe = __decorateClass([
|
|
1882
|
-
(0, import_common11.Injectable)()
|
|
1883
|
-
], MulterToUploadPipe);
|
|
1884
|
-
var gqlScalarPipeMap = /* @__PURE__ */ new Map([
|
|
1885
|
-
[Int, IntPipe],
|
|
1886
|
-
[Float, FloatPipe],
|
|
1887
|
-
[Boolean, BooleanPipe],
|
|
1888
|
-
[Date, DayjsPipe],
|
|
1889
|
-
[JSON2, JSONPipe]
|
|
1890
|
-
]);
|
|
1891
|
-
var getQueryPipes = (modelRef, arrDepth) => {
|
|
1892
|
-
const pipes = arrDepth ? [ArrayifyPipe] : [];
|
|
1893
|
-
const scalarPipe = gqlScalarPipeMap.get(modelRef);
|
|
1894
|
-
if (scalarPipe)
|
|
1895
|
-
pipes.push(scalarPipe);
|
|
1896
|
-
return pipes;
|
|
1897
|
-
};
|
|
1898
|
-
var getBodyPipes = (argMeta) => {
|
|
1899
|
-
const [returnRef] = getNonArrayModel(argMeta.returns());
|
|
1900
|
-
if (returnRef.prototype !== Date.prototype && !isGqlScalar(returnRef))
|
|
1901
|
-
return [];
|
|
1902
|
-
let BodyPipe = class {
|
|
1903
|
-
transform(value, metadata) {
|
|
1904
|
-
return deserializeArg(argMeta, value);
|
|
1905
|
-
}
|
|
1906
|
-
};
|
|
1907
|
-
BodyPipe = __decorateClass([
|
|
1908
|
-
(0, import_common11.Injectable)()
|
|
1909
|
-
], BodyPipe);
|
|
1910
|
-
return [BodyPipe];
|
|
1911
|
-
};
|
|
1912
|
-
|
|
1913
|
-
// pkgs/@akanjs/nest/src/exporter.ts
|
|
1914
|
-
var fs = __toESM(require("fs"));
|
|
1915
38
|
|
|
1916
|
-
// pkgs/@akanjs/
|
|
1917
|
-
var
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
39
|
+
// pkgs/@akanjs/server/index.ts
|
|
40
|
+
var server_exports = {};
|
|
41
|
+
__export(server_exports, {
|
|
42
|
+
DateScalar: () => DateScalar,
|
|
43
|
+
SearchDaemonModule: () => SearchDaemonModule,
|
|
44
|
+
addSchema: () => addSchema,
|
|
45
|
+
applyNestField: () => applyNestField,
|
|
46
|
+
batchModuleOf: () => batchModuleOf,
|
|
47
|
+
controllerOf: () => controllerOf,
|
|
48
|
+
createNestApp: () => createNestApp,
|
|
49
|
+
databaseModuleOf: () => databaseModuleOf,
|
|
50
|
+
generateGql: () => generateGql,
|
|
51
|
+
generateGqlInput: () => generateGqlInput,
|
|
52
|
+
makeTextFilter: () => makeTextFilter,
|
|
53
|
+
processorOf: () => processorOf,
|
|
54
|
+
queueOf: () => queueOf,
|
|
55
|
+
resolverOf: () => resolverOf,
|
|
56
|
+
scalarModuleOf: () => scalarModuleOf,
|
|
57
|
+
scalarModulesOf: () => scalarModulesOf,
|
|
58
|
+
schemaOf: () => schemaOf,
|
|
59
|
+
serviceModuleOf: () => serviceModuleOf,
|
|
60
|
+
useGlobals: () => useGlobals,
|
|
61
|
+
websocketOf: () => websocketOf,
|
|
62
|
+
websocketServerOf: () => websocketServerOf
|
|
63
|
+
});
|
|
64
|
+
module.exports = __toCommonJS(server_exports);
|
|
1930
65
|
|
|
1931
|
-
// pkgs/@akanjs/
|
|
1932
|
-
var
|
|
1933
|
-
var
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
Request: ${reqType2}-${reqName2}
|
|
1944
|
-
Args: ${JSON.stringify(gqlArgs, null, 2)}
|
|
1945
|
-
${exception.stack}`
|
|
1946
|
-
);
|
|
1947
|
-
throw exception;
|
|
1948
|
-
}
|
|
1949
|
-
const ctx = host.switchToHttp();
|
|
1950
|
-
const res = ctx.getResponse();
|
|
1951
|
-
const req = ctx.getRequest();
|
|
1952
|
-
const reqType = req.method;
|
|
1953
|
-
const reqName = req.url;
|
|
1954
|
-
const status = exception instanceof import_common14.HttpException ? exception.getStatus() : null;
|
|
1955
|
-
if (status) {
|
|
1956
|
-
res.status(status).json({
|
|
1957
|
-
statusCode: status,
|
|
1958
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1959
|
-
path: req.url,
|
|
1960
|
-
message: exception instanceof import_common14.HttpException ? exception.getResponse() : exception.message
|
|
1961
|
-
});
|
|
1962
|
-
this.logger.error(
|
|
1963
|
-
`Http Error: ${status}
|
|
1964
|
-
Request: ${reqType}-${reqName}
|
|
1965
|
-
Body: ${JSON.stringify(req.body, null, 2)}
|
|
1966
|
-
${exception.stack}`
|
|
1967
|
-
);
|
|
1968
|
-
}
|
|
66
|
+
// pkgs/@akanjs/server/src/gql.ts
|
|
67
|
+
var import_base = require("@akanjs/base");
|
|
68
|
+
var import_constant = require("@akanjs/constant");
|
|
69
|
+
var Nest = __toESM(require("@nestjs/graphql"));
|
|
70
|
+
var import_graphql = require("@nestjs/graphql");
|
|
71
|
+
var import_dayjs = require("dayjs");
|
|
72
|
+
var import_graphql2 = require("graphql");
|
|
73
|
+
var import_graphql_type_json = __toESM(require("graphql-type-json"));
|
|
74
|
+
var DateScalar = class {
|
|
75
|
+
description = "Date custom scalar type";
|
|
76
|
+
parseValue(value) {
|
|
77
|
+
return (0, import_base.dayjs)(value);
|
|
1969
78
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
// pkgs/@akanjs/nest/src/generateSecrets.ts
|
|
1976
|
-
var import_crypto = require("crypto");
|
|
1977
|
-
var import_tunnel_ssh = require("tunnel-ssh");
|
|
1978
|
-
var generateHexStringFromSeed = (seed, length = 256) => {
|
|
1979
|
-
let hexString = "";
|
|
1980
|
-
let currentSeed = seed;
|
|
1981
|
-
while (hexString.length < length * 2) {
|
|
1982
|
-
const hash = (0, import_crypto.createHash)("sha256").update(currentSeed).digest("hex");
|
|
1983
|
-
hexString += hash;
|
|
1984
|
-
currentSeed = hash;
|
|
79
|
+
serialize(value) {
|
|
80
|
+
if ((0, import_dayjs.isDayjs)(value))
|
|
81
|
+
return value.toDate();
|
|
82
|
+
else
|
|
83
|
+
return new Date(value);
|
|
1985
84
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
var getEnvironmentPort = (environment2) => environment2 === "main" ? 2e3 : environment2 === "develop" ? 1e3 : environment2 === "debug" ? 0 : 0;
|
|
1994
|
-
var getServicePort = (appCode, service) => (service === "redis" ? 300 : service === "mongo" ? 400 : 500) + appCode % 10 * 10 + (appCode >= 10 ? 5 : 0);
|
|
1995
|
-
var createDatabaseTunnel = async ({
|
|
1996
|
-
appName: appName2,
|
|
1997
|
-
environment: environment2,
|
|
1998
|
-
type,
|
|
1999
|
-
port,
|
|
2000
|
-
sshOptions = {
|
|
2001
|
-
host: `${appName2}-${environment2}.${baseEnv.serveDomain}`,
|
|
2002
|
-
port: 32767,
|
|
2003
|
-
username: baseEnv.tunnelUsername,
|
|
2004
|
-
password: baseEnv.tunnelPassword
|
|
85
|
+
parseLiteral(ast) {
|
|
86
|
+
if (ast.kind === import_graphql2.Kind.INT)
|
|
87
|
+
return (0, import_base.dayjs)(ast.value);
|
|
88
|
+
else if (ast.kind === import_graphql2.Kind.STRING)
|
|
89
|
+
return (0, import_base.dayjs)(ast.value);
|
|
90
|
+
else
|
|
91
|
+
return null;
|
|
2005
92
|
}
|
|
2006
|
-
}) => {
|
|
2007
|
-
const tunnelOptions = { autoClose: true, reconnectOnError: false };
|
|
2008
|
-
const serverOptions = { port };
|
|
2009
|
-
const forwardOptions = {
|
|
2010
|
-
srcAddr: "0.0.0.0",
|
|
2011
|
-
srcPort: port,
|
|
2012
|
-
dstAddr: `${type}-0.${type}-svc.${appName2}-${environment2}`,
|
|
2013
|
-
dstPort: type === "mongo" ? 27017 : type === "redis" ? 6379 : 7700
|
|
2014
|
-
};
|
|
2015
|
-
const [server, client2] = await (0, import_tunnel_ssh.createTunnel)(tunnelOptions, serverOptions, sshOptions, forwardOptions);
|
|
2016
|
-
return `localhost:${port}`;
|
|
2017
93
|
};
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
const url = operationMode2 === "cloud" ? `redis-svc.${appName2}-${environment2}.svc.cluster.local` : operationMode2 === "local" ? await createDatabaseTunnel({ appName: appName2, environment: environment2, type: "redis", port, sshOptions }) : "localhost:6379";
|
|
2023
|
-
const uri = `redis://${url}`;
|
|
2024
|
-
return uri;
|
|
94
|
+
DateScalar = __decorateClass([
|
|
95
|
+
Nest.Scalar("Date", () => Date)
|
|
96
|
+
], DateScalar);
|
|
97
|
+
var ObjectGqlStorage = class {
|
|
2025
98
|
};
|
|
2026
|
-
var
|
|
2027
|
-
appName: appName2,
|
|
2028
|
-
appCode,
|
|
2029
|
-
environment: environment2,
|
|
2030
|
-
operationMode: operationMode2,
|
|
2031
|
-
username = `${appName2}-${environment2}-mongo-user`,
|
|
2032
|
-
password,
|
|
2033
|
-
sshOptions
|
|
2034
|
-
}) => {
|
|
2035
|
-
if (process.env.MONGO_URI)
|
|
2036
|
-
return process.env.MONGO_URI;
|
|
2037
|
-
const record = operationMode2 === "cloud" ? "mongodb+srv" : "mongodb";
|
|
2038
|
-
const port = operationMode2 === "local" ? DEFAULT_CLOUD_PORT + getEnvironmentPort(environment2) + getServicePort(appCode, "mongo") : 27017;
|
|
2039
|
-
const url = operationMode2 === "cloud" ? `mongo-svc.${appName2}-${environment2}.svc.cluster.local` : operationMode2 === "local" ? await createDatabaseTunnel({ appName: appName2, environment: environment2, type: "mongo", port, sshOptions }) : "localhost:27017";
|
|
2040
|
-
const usernameEncoded = password ? encodeURIComponent(username) : null;
|
|
2041
|
-
const passwordEncoded = password ? encodeURIComponent(password) : null;
|
|
2042
|
-
const dbName = `${appName2}-${environment2}`;
|
|
2043
|
-
const directConnection = operationMode2 === "cloud" ? false : true;
|
|
2044
|
-
const authInfo = usernameEncoded ? `${usernameEncoded}:${passwordEncoded}@` : "";
|
|
2045
|
-
const uri = `${record}://${authInfo}${url}/${dbName}?authSource=${dbName}&readPreference=primary&ssl=false&retryWrites=true&directConnection=${directConnection}`;
|
|
2046
|
-
return uri;
|
|
99
|
+
var InputGqlStorage = class {
|
|
2047
100
|
};
|
|
2048
|
-
var
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
const protocol = operationMode2 === "local" ? "https" : "http";
|
|
2052
|
-
const url = operationMode2 === "cloud" ? `meili-0.meili-svc.${appName2}-${environment2}.svc.cluster.local:7700` : operationMode2 === "local" ? `${appName2}-${environment2}.${baseEnv.serveDomain}/search` : "localhost:7700";
|
|
2053
|
-
const uri = `${protocol}://${url}`;
|
|
2054
|
-
return uri;
|
|
101
|
+
var getPredefinedInqutGql = (refName) => {
|
|
102
|
+
const inputGql = Reflect.getMetadata(refName, InputGqlStorage.prototype);
|
|
103
|
+
return inputGql;
|
|
2055
104
|
};
|
|
2056
|
-
var
|
|
2057
|
-
|
|
105
|
+
var setPredefinedInqutGql = (refName, inputGql) => {
|
|
106
|
+
Reflect.defineMetadata(refName, inputGql, InputGqlStorage.prototype);
|
|
2058
107
|
};
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
var initMongoDB = ({
|
|
2063
|
-
logging,
|
|
2064
|
-
threshold = 5e3,
|
|
2065
|
-
sendReport = false
|
|
2066
|
-
}) => {
|
|
2067
|
-
const mongoDBLogger = new Logger("MongoDB");
|
|
2068
|
-
if (logging)
|
|
2069
|
-
import_mongoose.default.set("debug", function(collection, method, ...methodArgs) {
|
|
2070
|
-
mongoDBLogger.verbose(
|
|
2071
|
-
`${collection}.${method}(${methodArgs.slice(0, -1).map((arg) => JSON.stringify(arg)).join(", ")})`
|
|
2072
|
-
);
|
|
2073
|
-
});
|
|
2074
|
-
const originalExec = import_mongoose.default.Query.prototype.exec;
|
|
2075
|
-
const getQueryInfo = (queryAgent) => {
|
|
2076
|
-
const model = queryAgent.model;
|
|
2077
|
-
const collectionName = model.collection.collectionName;
|
|
2078
|
-
const dbName = model.db.name;
|
|
2079
|
-
const query = queryAgent.getQuery();
|
|
2080
|
-
const queryOptions = queryAgent.getOptions();
|
|
2081
|
-
return { dbName, collectionName, query, queryOptions };
|
|
2082
|
-
};
|
|
2083
|
-
import_mongoose.default.Query.prototype.exec = function(...args) {
|
|
2084
|
-
const start = Date.now();
|
|
2085
|
-
return originalExec.apply(this, args).then((result) => {
|
|
2086
|
-
const duration = Date.now() - start;
|
|
2087
|
-
const { dbName, collectionName, query, queryOptions } = getQueryInfo(this);
|
|
2088
|
-
if (logging)
|
|
2089
|
-
mongoDBLogger.verbose(
|
|
2090
|
-
`Queried ${dbName}.${collectionName}.query(${JSON.stringify(query)}, ${JSON.stringify(
|
|
2091
|
-
queryOptions
|
|
2092
|
-
)}) - ${duration}ms`
|
|
2093
|
-
);
|
|
2094
|
-
return result;
|
|
2095
|
-
});
|
|
2096
|
-
};
|
|
2097
|
-
const originalAggregate = import_mongoose.default.Model.aggregate;
|
|
2098
|
-
const getAggregateInfo = (aggregateModel) => {
|
|
2099
|
-
const dbName = aggregateModel.db.db?.databaseName ?? "unknown";
|
|
2100
|
-
const collectionName = aggregateModel.collection.collectionName;
|
|
2101
|
-
return { dbName, collectionName };
|
|
2102
|
-
};
|
|
2103
|
-
import_mongoose.default.Model.aggregate = function(...args) {
|
|
2104
|
-
const startTime = Date.now();
|
|
2105
|
-
return originalAggregate.apply(this, args).then((result) => {
|
|
2106
|
-
const duration = Date.now() - startTime;
|
|
2107
|
-
const { dbName, collectionName } = getAggregateInfo(this);
|
|
2108
|
-
if (logging)
|
|
2109
|
-
mongoDBLogger.verbose(
|
|
2110
|
-
`Aggregated ${dbName}.${collectionName}.aggregate(${args.map((arg) => JSON.stringify(arg)).join(", ")}) - ${duration}ms`
|
|
2111
|
-
);
|
|
2112
|
-
return result;
|
|
2113
|
-
});
|
|
2114
|
-
};
|
|
2115
|
-
import_mongoose.default.set("transactionAsyncLocalStorage", true);
|
|
108
|
+
var getPredefinedObjectGql = (refName) => {
|
|
109
|
+
const objectGql = Reflect.getMetadata(refName, ObjectGqlStorage.prototype);
|
|
110
|
+
return objectGql;
|
|
2116
111
|
};
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
var import_common16 = require("@nestjs/common");
|
|
2120
|
-
var SearchClient = class {
|
|
2121
|
-
meili;
|
|
2122
|
-
async getIndexNames() {
|
|
2123
|
-
const { results } = await this.meili.getIndexes({ limit: 1e3 });
|
|
2124
|
-
return results.map((index) => index.uid);
|
|
2125
|
-
}
|
|
2126
|
-
async getSearchResult(indexName, option) {
|
|
2127
|
-
const { skip = 0, limit = DEFAULT_PAGE_SIZE, sort = "", searchString } = option;
|
|
2128
|
-
if (!searchString) {
|
|
2129
|
-
const { results, total } = await this.meili.index(indexName).getDocuments({ offset: skip, limit });
|
|
2130
|
-
return { docs: results, skip, limit, sort, total };
|
|
2131
|
-
}
|
|
2132
|
-
const { hits, estimatedTotalHits } = await this.meili.index(indexName).search(searchString, { offset: skip, limit });
|
|
2133
|
-
return { docs: hits, skip, limit, sort, total: estimatedTotalHits, query: searchString };
|
|
2134
|
-
}
|
|
2135
|
-
async upsertDocuments(indexName, documents) {
|
|
2136
|
-
const task = await this.meili.index(indexName).addDocuments(documents);
|
|
2137
|
-
return task;
|
|
2138
|
-
}
|
|
2139
|
-
async dropIndex(indexName) {
|
|
2140
|
-
const task = await this.meili.index(indexName).delete();
|
|
2141
|
-
return task;
|
|
2142
|
-
}
|
|
112
|
+
var setPredefinedObjectGql = (refName, objectGql) => {
|
|
113
|
+
Reflect.defineMetadata(refName, objectGql, ObjectGqlStorage.prototype);
|
|
2143
114
|
};
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
115
|
+
var gqlNestFieldMap = /* @__PURE__ */ new Map([
|
|
116
|
+
[import_base.ID, Nest.ID],
|
|
117
|
+
[import_base.Int, Nest.Int],
|
|
118
|
+
[import_base.Float, Nest.Float],
|
|
119
|
+
[import_base.JSON, import_graphql_type_json.default],
|
|
120
|
+
[Map, import_graphql_type_json.default]
|
|
121
|
+
]);
|
|
122
|
+
var applyNestField = (model, fieldMeta, type = "object") => {
|
|
123
|
+
if (fieldMeta.fieldType === "hidden" && type === "object")
|
|
124
|
+
return;
|
|
125
|
+
const modelRef = fieldMeta.isClass ? type === "object" ? generateGql(fieldMeta.modelRef) : fieldMeta.isScalar ? generateGqlInput(fieldMeta.modelRef) : Nest.ID : gqlNestFieldMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
|
|
126
|
+
(0, import_graphql.Field)(() => (0, import_base.arraiedModel)(modelRef, fieldMeta.arrDepth), { nullable: fieldMeta.nullable })(
|
|
127
|
+
model.prototype,
|
|
128
|
+
fieldMeta.key
|
|
129
|
+
);
|
|
2155
130
|
};
|
|
2156
|
-
|
|
2157
|
-
(0,
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
// pkgs/@akanjs/nest/src/databaseClient.ts
|
|
2164
|
-
var import_common19 = require("@nestjs/common");
|
|
2165
|
-
var import_mongoose2 = require("@nestjs/mongoose");
|
|
2166
|
-
var DatabaseClient = class {
|
|
2167
|
-
connection;
|
|
2168
|
-
getModel(modelName) {
|
|
2169
|
-
const model = this.connection.models[capitalize(modelName)];
|
|
2170
|
-
return model;
|
|
131
|
+
var generateGqlInput = (inputRef) => {
|
|
132
|
+
const classMeta = (0, import_constant.getClassMeta)(inputRef);
|
|
133
|
+
const predefinedInputGql = getPredefinedInqutGql(classMeta.refName);
|
|
134
|
+
if (predefinedInputGql)
|
|
135
|
+
return predefinedInputGql;
|
|
136
|
+
const fieldMetas = (0, import_constant.getFieldMetas)(inputRef);
|
|
137
|
+
class InputGql {
|
|
2171
138
|
}
|
|
139
|
+
const inputGql = classMeta.type === "scalar" ? InputGql : (0, import_constant.getInputModelRef)(classMeta.refName);
|
|
140
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
141
|
+
applyNestField(inputGql, fieldMeta, "input");
|
|
142
|
+
});
|
|
143
|
+
(0, import_graphql.InputType)(classMeta.refName + (classMeta.type === "scalar" ? "Input" : ""))(inputGql);
|
|
144
|
+
setPredefinedInqutGql(classMeta.refName, inputGql);
|
|
145
|
+
return inputGql;
|
|
2172
146
|
};
|
|
2173
|
-
|
|
2174
|
-
(0,
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
const originMethod = descriptor.value;
|
|
2186
|
-
descriptor.value = function(...args) {
|
|
2187
|
-
if (!this.connection)
|
|
2188
|
-
throw new Error(`No Connection in function ${key}`);
|
|
2189
|
-
return new Promise((resolve, reject) => {
|
|
2190
|
-
this.connection.transaction(async () => {
|
|
2191
|
-
const res = await originMethod.apply(this, args);
|
|
2192
|
-
resolve(res);
|
|
2193
|
-
}).catch(reject);
|
|
2194
|
-
});
|
|
2195
|
-
};
|
|
2196
|
-
return descriptor;
|
|
2197
|
-
};
|
|
2198
|
-
};
|
|
2199
|
-
|
|
2200
|
-
// pkgs/@akanjs/service/src/serviceDecorators.ts
|
|
2201
|
-
var import_reflect_metadata7 = require("reflect-metadata");
|
|
2202
|
-
var import_common21 = require("@nestjs/common");
|
|
2203
|
-
var import_mongoose3 = require("@nestjs/mongoose");
|
|
2204
|
-
var ServiceStorage = class {
|
|
2205
|
-
};
|
|
2206
|
-
var getServiceRefs = (refName) => {
|
|
2207
|
-
return Reflect.getMetadata(refName, ServiceStorage.prototype) ?? [];
|
|
2208
|
-
};
|
|
2209
|
-
var isServiceDefined = (srvRef) => {
|
|
2210
|
-
return Reflect.getMetadata("service", srvRef.prototype) ?? false;
|
|
2211
|
-
};
|
|
2212
|
-
var setServiceDefined = (srvRef) => {
|
|
2213
|
-
Reflect.defineMetadata("service", true, srvRef.prototype);
|
|
2214
|
-
};
|
|
2215
|
-
var getServiceMeta = (srvRef) => {
|
|
2216
|
-
return Reflect.getMetadata("serviceMeta", srvRef.prototype);
|
|
2217
|
-
};
|
|
2218
|
-
var isServiceEnabled = (srvRef) => {
|
|
2219
|
-
const meta = getServiceMeta(srvRef);
|
|
2220
|
-
return meta?.enabled ?? false;
|
|
2221
|
-
};
|
|
2222
|
-
var getServiceInjectMetaMapOnPrototype = (prototype) => {
|
|
2223
|
-
return Reflect.getMetadata("inject", prototype) ?? /* @__PURE__ */ new Map();
|
|
2224
|
-
};
|
|
2225
|
-
var serviceOf = (srvRef) => {
|
|
2226
|
-
if (isServiceDefined(srvRef))
|
|
2227
|
-
return srvRef;
|
|
2228
|
-
const injectMetaMap = getServiceInjectMetaMapOnPrototype(srvRef.prototype);
|
|
2229
|
-
for (const injectMeta of [...injectMetaMap.values()]) {
|
|
2230
|
-
if (injectMeta.type === "Db")
|
|
2231
|
-
(0, import_mongoose3.InjectModel)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
2232
|
-
else if (injectMeta.type === "Use")
|
|
2233
|
-
(0, import_common21.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
2234
|
-
else if (injectMeta.type === "Srv") {
|
|
2235
|
-
const services = getServiceRefs(injectMeta.name);
|
|
2236
|
-
if (!services.length)
|
|
2237
|
-
throw new Error(`Service ${injectMeta.name} not found`);
|
|
2238
|
-
(0, import_common21.Inject)(services.at(-1))(srvRef.prototype, injectMeta.key);
|
|
2239
|
-
} else if (injectMeta.type === "Queue")
|
|
2240
|
-
(0, import_common21.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
2241
|
-
else
|
|
2242
|
-
(0, import_common21.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
147
|
+
var generateGql = (objectRef) => {
|
|
148
|
+
const classMeta = (0, import_constant.getClassMeta)(objectRef);
|
|
149
|
+
if (classMeta.type === "light") {
|
|
150
|
+
const fullModelRefName = classMeta.refName.slice(5);
|
|
151
|
+
const fullModelRef = (0, import_constant.getFullModelRef)(fullModelRefName);
|
|
152
|
+
return generateGql(fullModelRef);
|
|
153
|
+
}
|
|
154
|
+
const predefinedObjectGql = getPredefinedObjectGql(classMeta.refName);
|
|
155
|
+
if (predefinedObjectGql)
|
|
156
|
+
return predefinedObjectGql;
|
|
157
|
+
const fieldMetas = (0, import_constant.getFieldMetas)(objectRef);
|
|
158
|
+
class ObjectGql {
|
|
2243
159
|
}
|
|
2244
|
-
(0,
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
160
|
+
const objectGql = classMeta.type === "scalar" ? ObjectGql : (0, import_constant.getFullModelRef)(classMeta.refName);
|
|
161
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
162
|
+
applyNestField(objectGql, fieldMeta);
|
|
163
|
+
});
|
|
164
|
+
(0, import_graphql.ObjectType)(classMeta.refName)(objectGql);
|
|
165
|
+
setPredefinedObjectGql(classMeta.refName, objectGql);
|
|
166
|
+
return objectGql;
|
|
2248
167
|
};
|
|
2249
168
|
|
|
2250
169
|
// pkgs/@akanjs/server/src/resolver.ts
|
|
2251
|
-
var
|
|
170
|
+
var import_base2 = require("@akanjs/base");
|
|
171
|
+
var import_common = require("@akanjs/common");
|
|
172
|
+
var import_constant2 = require("@akanjs/constant");
|
|
173
|
+
var import_nest = require("@akanjs/nest");
|
|
174
|
+
var import_service = require("@akanjs/service");
|
|
175
|
+
var import_signal = require("@akanjs/signal");
|
|
176
|
+
var import_common2 = require("@nestjs/common");
|
|
2252
177
|
var Nest2 = __toESM(require("@nestjs/graphql"));
|
|
2253
178
|
var import_graphql_type_json2 = __toESM(require("graphql-type-json"));
|
|
2254
179
|
var import_graphql_upload = require("graphql-upload");
|
|
2255
180
|
var scalarNestReturnMap = /* @__PURE__ */ new Map([
|
|
2256
|
-
[Upload, import_graphql_upload.GraphQLUpload],
|
|
2257
|
-
[ID, Nest2.ID],
|
|
2258
|
-
[Int, Nest2.Int],
|
|
2259
|
-
[Float, Nest2.Float],
|
|
2260
|
-
[
|
|
181
|
+
[import_base2.Upload, import_graphql_upload.GraphQLUpload],
|
|
182
|
+
[import_base2.ID, Nest2.ID],
|
|
183
|
+
[import_base2.Int, Nest2.Int],
|
|
184
|
+
[import_base2.Float, Nest2.Float],
|
|
185
|
+
[import_base2.JSON, import_graphql_type_json2.default],
|
|
2261
186
|
[Boolean, Boolean],
|
|
2262
187
|
[Date, Date],
|
|
2263
188
|
[String, String],
|
|
2264
189
|
[Map, import_graphql_type_json2.default]
|
|
2265
190
|
]);
|
|
2266
191
|
var getNestReturn = (returns, type = "object") => {
|
|
2267
|
-
const [model, arrDepth] = getNonArrayModel(returns());
|
|
192
|
+
const [model, arrDepth] = (0, import_base2.getNonArrayModel)(returns());
|
|
2268
193
|
const modelRef = scalarNestReturnMap.get(model) ?? (type === "object" ? generateGql(model) : generateGqlInput(model));
|
|
2269
|
-
return () => arraiedModel(modelRef, arrDepth);
|
|
194
|
+
return () => (0, import_base2.arraiedModel)(modelRef, arrDepth);
|
|
2270
195
|
};
|
|
2271
196
|
var internalArgMap = {
|
|
2272
197
|
Parent: Nest2.Parent,
|
|
2273
|
-
Account:
|
|
2274
|
-
UserIp:
|
|
2275
|
-
Access:
|
|
2276
|
-
Self:
|
|
2277
|
-
Me:
|
|
2278
|
-
Req:
|
|
2279
|
-
Res:
|
|
198
|
+
Account: import_nest.Account,
|
|
199
|
+
UserIp: import_nest.UserIp,
|
|
200
|
+
Access: import_nest.Access,
|
|
201
|
+
Self: import_nest.Self,
|
|
202
|
+
Me: import_nest.Me,
|
|
203
|
+
Req: import_nest.Req,
|
|
204
|
+
Res: import_nest.Res
|
|
2280
205
|
};
|
|
2281
206
|
var resolverOf = (sigRef, allSrvs) => {
|
|
2282
|
-
const Rsv = copySignal(sigRef);
|
|
2283
|
-
const sigMeta = getSigMeta(Rsv);
|
|
2284
|
-
const gqlMetas = getGqlMetas(Rsv);
|
|
207
|
+
const Rsv = (0, import_signal.copySignal)(sigRef);
|
|
208
|
+
const sigMeta = (0, import_signal.getSigMeta)(Rsv);
|
|
209
|
+
const gqlMetas = (0, import_signal.getGqlMetas)(Rsv);
|
|
2285
210
|
Object.keys(allSrvs).forEach((srv) => {
|
|
2286
|
-
if (!isServiceEnabled(allSrvs[srv]))
|
|
211
|
+
if (!(0, import_service.isServiceEnabled)(allSrvs[srv]))
|
|
2287
212
|
return;
|
|
2288
|
-
(0,
|
|
213
|
+
(0, import_common2.Inject)(allSrvs[srv])(Rsv.prototype, (0, import_common.lowerlize)(srv));
|
|
2289
214
|
});
|
|
2290
215
|
for (const gqlMeta of gqlMetas) {
|
|
2291
216
|
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "restapi" || !["Query", "Mutation"].includes(gqlMeta.type))
|
|
2292
217
|
continue;
|
|
2293
218
|
else if (gqlMeta.signalOption.sso)
|
|
2294
219
|
continue;
|
|
2295
|
-
const [argMetas, internalArgMetas] = getArgMetas(Rsv, gqlMeta.key);
|
|
220
|
+
const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(Rsv, gqlMeta.key);
|
|
2296
221
|
const descriptor = Object.getOwnPropertyDescriptor(Rsv.prototype, gqlMeta.key) ?? {};
|
|
2297
222
|
for (const argMeta of argMetas) {
|
|
2298
223
|
Nest2.Args({
|
|
@@ -2305,27 +230,27 @@ var resolverOf = (sigRef, allSrvs) => {
|
|
|
2305
230
|
const decorate = internalArgMap[internalArgMeta.type];
|
|
2306
231
|
decorate(internalArgMeta.option ?? {})(Rsv.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
2307
232
|
}
|
|
2308
|
-
(0,
|
|
233
|
+
(0, import_common2.UseGuards)(...gqlMeta.guards.map((guard) => import_nest.guards[guard]))(Rsv.prototype, gqlMeta.key, descriptor);
|
|
2309
234
|
if (gqlMeta.type === "Query")
|
|
2310
235
|
Nest2.Query(getNestReturn(gqlMeta.returns), gqlMeta.signalOption)(Rsv.prototype, gqlMeta.key, descriptor);
|
|
2311
236
|
else if (gqlMeta.type === "Mutation")
|
|
2312
237
|
Nest2.Mutation(getNestReturn(gqlMeta.returns), gqlMeta.signalOption)(Rsv.prototype, gqlMeta.key, descriptor);
|
|
2313
238
|
}
|
|
2314
|
-
const resolveFieldMetas = getResolveFieldMetas(Rsv);
|
|
239
|
+
const resolveFieldMetas = (0, import_signal.getResolveFieldMetas)(Rsv);
|
|
2315
240
|
if (sigMeta.returns) {
|
|
2316
241
|
const modelRef = sigMeta.returns();
|
|
2317
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
242
|
+
const fieldMetas = (0, import_constant2.getFieldMetas)(modelRef);
|
|
2318
243
|
fieldMetas.filter((fieldMeta) => fieldMeta.isClass && !fieldMeta.isScalar).forEach((fieldMeta) => {
|
|
2319
|
-
const classMeta = getClassMeta(fieldMeta.modelRef);
|
|
2320
|
-
const modelName = lowerlize(classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName);
|
|
2321
|
-
const className = capitalize(modelName);
|
|
244
|
+
const classMeta = (0, import_constant2.getClassMeta)(fieldMeta.modelRef);
|
|
245
|
+
const modelName = (0, import_common.lowerlize)(classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName);
|
|
246
|
+
const className = (0, import_common.capitalize)(modelName);
|
|
2322
247
|
const serviceName = `${modelName}Service`;
|
|
2323
248
|
Rsv.prototype[fieldMeta.key] = async function(parent) {
|
|
2324
249
|
const service = this[serviceName];
|
|
2325
250
|
return fieldMeta.arrDepth ? await service[`load${className}Many`](parent[fieldMeta.key]) : await service[`load${className}`](parent[fieldMeta.key]);
|
|
2326
251
|
};
|
|
2327
252
|
Nest2.Parent()(Rsv.prototype, fieldMeta.key, 0);
|
|
2328
|
-
Nest2.ResolveField(getNestReturn(() => arraiedModel(fieldMeta.modelRef, fieldMeta.arrDepth)))(
|
|
253
|
+
Nest2.ResolveField(getNestReturn(() => (0, import_base2.arraiedModel)(fieldMeta.modelRef, fieldMeta.arrDepth)))(
|
|
2329
254
|
Rsv.prototype,
|
|
2330
255
|
fieldMeta.key,
|
|
2331
256
|
Object.getOwnPropertyDescriptor(Rsv.prototype, fieldMeta.key) ?? {}
|
|
@@ -2333,7 +258,7 @@ var resolverOf = (sigRef, allSrvs) => {
|
|
|
2333
258
|
});
|
|
2334
259
|
}
|
|
2335
260
|
for (const resolveFieldMeta of resolveFieldMetas) {
|
|
2336
|
-
const [, internalArgMetas] = getArgMetas(Rsv, resolveFieldMeta.key);
|
|
261
|
+
const [, internalArgMetas] = (0, import_signal.getArgMetas)(Rsv, resolveFieldMeta.key);
|
|
2337
262
|
for (const internalArgMeta of internalArgMetas) {
|
|
2338
263
|
const decorate = internalArgMap[internalArgMeta.type];
|
|
2339
264
|
decorate(internalArgMeta.option ?? {})(Rsv.prototype, resolveFieldMeta.key, internalArgMeta.idx);
|
|
@@ -2352,87 +277,95 @@ var resolverOf = (sigRef, allSrvs) => {
|
|
|
2352
277
|
};
|
|
2353
278
|
|
|
2354
279
|
// pkgs/@akanjs/server/src/controller.ts
|
|
2355
|
-
var
|
|
2356
|
-
var
|
|
280
|
+
var import_base3 = require("@akanjs/base");
|
|
281
|
+
var import_common3 = require("@akanjs/common");
|
|
282
|
+
var import_nest2 = require("@akanjs/nest");
|
|
283
|
+
var import_service2 = require("@akanjs/service");
|
|
284
|
+
var import_signal2 = require("@akanjs/signal");
|
|
285
|
+
var import_common4 = require("@nestjs/common");
|
|
286
|
+
var import_passport = require("@nestjs/passport");
|
|
2357
287
|
var import_platform_express = require("@nestjs/platform-express");
|
|
2358
288
|
var internalArgMap2 = {
|
|
2359
289
|
// Parent: Nest.Parent,
|
|
2360
|
-
Account:
|
|
2361
|
-
UserIp:
|
|
2362
|
-
Access:
|
|
2363
|
-
Self:
|
|
2364
|
-
Me:
|
|
2365
|
-
Req:
|
|
2366
|
-
Res:
|
|
290
|
+
Account: import_nest2.Account,
|
|
291
|
+
UserIp: import_nest2.UserIp,
|
|
292
|
+
Access: import_nest2.Access,
|
|
293
|
+
Self: import_nest2.Self,
|
|
294
|
+
Me: import_nest2.Me,
|
|
295
|
+
Req: import_nest2.Req,
|
|
296
|
+
Res: import_nest2.Res
|
|
2367
297
|
};
|
|
2368
298
|
var controllerOf = (sigRef, allSrvs) => {
|
|
2369
|
-
const sigMeta = getSigMeta(sigRef);
|
|
2370
|
-
const gqlMetas = getGqlMetas(sigRef);
|
|
2371
|
-
const prefix = getControllerPrefix(sigMeta);
|
|
2372
|
-
const Ctrl = copySignal(sigRef);
|
|
299
|
+
const sigMeta = (0, import_signal2.getSigMeta)(sigRef);
|
|
300
|
+
const gqlMetas = (0, import_signal2.getGqlMetas)(sigRef);
|
|
301
|
+
const prefix = (0, import_signal2.getControllerPrefix)(sigMeta);
|
|
302
|
+
const Ctrl = (0, import_signal2.copySignal)(sigRef);
|
|
2373
303
|
Object.keys(allSrvs).forEach((srv) => {
|
|
2374
|
-
if (!isServiceEnabled(allSrvs[srv]))
|
|
304
|
+
if (!(0, import_service2.isServiceEnabled)(allSrvs[srv]))
|
|
2375
305
|
return;
|
|
2376
|
-
(0,
|
|
306
|
+
(0, import_common4.Inject)(allSrvs[srv])(Ctrl.prototype, (0, import_common3.lowerlize)(srv));
|
|
2377
307
|
});
|
|
2378
308
|
for (const gqlMeta of gqlMetas) {
|
|
2379
309
|
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "graphql" || !["Query", "Mutation"].includes(gqlMeta.type))
|
|
2380
310
|
continue;
|
|
2381
|
-
const [argMetas, internalArgMetas] = getArgMetas(Ctrl, gqlMeta.key);
|
|
311
|
+
const [argMetas, internalArgMetas] = (0, import_signal2.getArgMetas)(Ctrl, gqlMeta.key);
|
|
2382
312
|
internalArgMetas.forEach((internalArgMeta) => {
|
|
2383
313
|
const internalDecorator = internalArgMap2[internalArgMeta.type];
|
|
2384
314
|
internalDecorator(internalArgMeta.option ?? {})(Ctrl.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
2385
315
|
});
|
|
2386
316
|
const uploadArgMeta = argMetas.find((argMeta) => argMeta.type === "Upload");
|
|
2387
317
|
if (uploadArgMeta && gqlMeta.signalOption.onlyFor === "restapi") {
|
|
2388
|
-
const [modelRef, arrDepth] = getNonArrayModel(uploadArgMeta.returns());
|
|
2389
|
-
if (modelRef.prototype !== Upload.prototype)
|
|
318
|
+
const [modelRef, arrDepth] = (0, import_base3.getNonArrayModel)(uploadArgMeta.returns());
|
|
319
|
+
if (modelRef.prototype !== import_base3.Upload.prototype)
|
|
2390
320
|
throw new Error("Upload must be Upload");
|
|
2391
321
|
else if (!arrDepth)
|
|
2392
322
|
throw new Error(`Only Array of Upload is allowed - ${sigMeta.refName}/${gqlMeta.key}`);
|
|
2393
|
-
(0,
|
|
2394
|
-
(0,
|
|
323
|
+
(0, import_common4.UseInterceptors)((0, import_platform_express.FilesInterceptor)(uploadArgMeta.name))(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
324
|
+
(0, import_common4.UploadedFiles)(import_nest2.MulterToUploadPipe)(Ctrl.prototype, gqlMeta.key, uploadArgMeta.idx);
|
|
2395
325
|
}
|
|
2396
326
|
const queryArgMetas = argMetas.filter((argMeta) => argMeta.type === "Query");
|
|
2397
327
|
queryArgMetas.forEach((argMeta) => {
|
|
2398
|
-
const [modelRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
2399
|
-
(0,
|
|
328
|
+
const [modelRef, arrDepth] = (0, import_base3.getNonArrayModel)(argMeta.returns());
|
|
329
|
+
(0, import_common4.Query)(argMeta.name, ...(0, import_nest2.getQueryPipes)(modelRef, arrDepth))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
2400
330
|
});
|
|
2401
331
|
const paramArgMetas = argMetas.filter((argMeta) => argMeta.type === "Param");
|
|
2402
332
|
paramArgMetas.forEach((argMeta) => {
|
|
2403
|
-
(0,
|
|
333
|
+
(0, import_common4.Param)(argMeta.name)(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
2404
334
|
});
|
|
2405
|
-
const path = getControllerPath(gqlMeta, paramArgMetas);
|
|
335
|
+
const path = (0, import_signal2.getControllerPath)(gqlMeta, paramArgMetas);
|
|
2406
336
|
const bodyArgMetas = argMetas.filter((argMeta) => argMeta.type === "Body");
|
|
2407
337
|
if (bodyArgMetas.length)
|
|
2408
338
|
bodyArgMetas.forEach((argMeta) => {
|
|
2409
|
-
(0,
|
|
339
|
+
(0, import_common4.Body)(argMeta.name, ...(0, import_nest2.getBodyPipes)(argMeta))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
2410
340
|
});
|
|
2411
|
-
(0,
|
|
2412
|
-
...gqlMeta.guards.map((guard) =>
|
|
2413
|
-
...gqlMeta.signalOption.sso ? [(0,
|
|
341
|
+
(0, import_common4.UseGuards)(
|
|
342
|
+
...gqlMeta.guards.map((guard) => import_nest2.guards[guard]),
|
|
343
|
+
...gqlMeta.signalOption.sso ? [(0, import_passport.AuthGuard)(gqlMeta.signalOption.sso)] : []
|
|
2414
344
|
)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
2415
345
|
if (gqlMeta.type === "Query")
|
|
2416
|
-
(0,
|
|
346
|
+
(0, import_common4.Get)(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
2417
347
|
else if (gqlMeta.type === "Mutation")
|
|
2418
|
-
(0,
|
|
348
|
+
(0, import_common4.Post)(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
2419
349
|
}
|
|
2420
350
|
if (prefix)
|
|
2421
|
-
(0,
|
|
351
|
+
(0, import_common4.Controller)(prefix)(Ctrl);
|
|
2422
352
|
else
|
|
2423
|
-
(0,
|
|
353
|
+
(0, import_common4.Controller)()(Ctrl);
|
|
2424
354
|
return Ctrl;
|
|
2425
355
|
};
|
|
2426
356
|
|
|
2427
357
|
// pkgs/@akanjs/server/src/processor.ts
|
|
358
|
+
var import_common5 = require("@akanjs/common");
|
|
359
|
+
var import_service3 = require("@akanjs/service");
|
|
360
|
+
var import_signal3 = require("@akanjs/signal");
|
|
2428
361
|
var import_bull = require("@nestjs/bull");
|
|
2429
|
-
var
|
|
362
|
+
var import_common6 = require("@nestjs/common");
|
|
2430
363
|
var convertProcessFunction = (gqlMeta, argMetas, internalArgMetas, fn) => {
|
|
2431
364
|
return async function(job, done) {
|
|
2432
365
|
const args = [];
|
|
2433
366
|
argMetas.forEach((argMeta) => {
|
|
2434
367
|
if (argMeta.type === "Msg")
|
|
2435
|
-
args[argMeta.idx] = deserializeArg(argMeta, job.data[argMeta.idx]);
|
|
368
|
+
args[argMeta.idx] = (0, import_signal3.deserializeArg)(argMeta, job.data[argMeta.idx]);
|
|
2436
369
|
else
|
|
2437
370
|
throw new Error(`Invalid ArgMeta Type ${argMeta.type}`);
|
|
2438
371
|
});
|
|
@@ -2449,20 +382,20 @@ var convertProcessFunction = (gqlMeta, argMetas, internalArgMetas, fn) => {
|
|
|
2449
382
|
};
|
|
2450
383
|
};
|
|
2451
384
|
var processorOf = (sigRef, allSrvs) => {
|
|
2452
|
-
const sigMeta = getSigMeta(sigRef);
|
|
385
|
+
const sigMeta = (0, import_signal3.getSigMeta)(sigRef);
|
|
2453
386
|
const serverMode = process.env.SERVER_MODE ?? "federation";
|
|
2454
|
-
const gqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Process").filter(
|
|
387
|
+
const gqlMetas = (0, import_signal3.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process").filter(
|
|
2455
388
|
(gqlMeta) => gqlMeta.signalOption.serverType === "all" || serverMode === "all" || gqlMeta.signalOption.serverType === serverMode
|
|
2456
389
|
);
|
|
2457
390
|
class QueueProcessor {
|
|
2458
391
|
}
|
|
2459
392
|
Object.keys(allSrvs).forEach((srv) => {
|
|
2460
|
-
if (!isServiceEnabled(allSrvs[srv]))
|
|
393
|
+
if (!(0, import_service3.isServiceEnabled)(allSrvs[srv]))
|
|
2461
394
|
return;
|
|
2462
|
-
(0,
|
|
395
|
+
(0, import_common6.Inject)(allSrvs[srv])(QueueProcessor.prototype, (0, import_common5.lowerlize)(srv));
|
|
2463
396
|
});
|
|
2464
397
|
for (const gqlMeta of gqlMetas) {
|
|
2465
|
-
const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
398
|
+
const [argMetas, internalArgMetas] = (0, import_signal3.getArgMetas)(sigRef, gqlMeta.key);
|
|
2466
399
|
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
2467
400
|
descriptor.value = convertProcessFunction(
|
|
2468
401
|
gqlMeta,
|
|
@@ -2477,8 +410,8 @@ var processorOf = (sigRef, allSrvs) => {
|
|
|
2477
410
|
return QueueProcessor;
|
|
2478
411
|
};
|
|
2479
412
|
var queueOf = (sigRef, queue) => {
|
|
2480
|
-
const sigMeta = getSigMeta(sigRef);
|
|
2481
|
-
const gqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Process");
|
|
413
|
+
const sigMeta = (0, import_signal3.getSigMeta)(sigRef);
|
|
414
|
+
const gqlMetas = (0, import_signal3.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process");
|
|
2482
415
|
for (const gqlMeta of gqlMetas) {
|
|
2483
416
|
if (queue[gqlMeta.key])
|
|
2484
417
|
throw new Error(`Queue already has ${gqlMeta.key} in ${sigMeta.refName}`);
|
|
@@ -2487,467 +420,32 @@ var queueOf = (sigRef, queue) => {
|
|
|
2487
420
|
return queue;
|
|
2488
421
|
};
|
|
2489
422
|
|
|
2490
|
-
// pkgs/@akanjs/document/src/dbDecorators.ts
|
|
2491
|
-
var ModelDatabaseStorage = class {
|
|
2492
|
-
};
|
|
2493
|
-
var getAllDatabaseModelNames = () => {
|
|
2494
|
-
const modelNames = Reflect.getMetadataKeys(ModelDatabaseStorage.prototype) ?? [];
|
|
2495
|
-
return modelNames;
|
|
2496
|
-
};
|
|
2497
|
-
|
|
2498
|
-
// pkgs/@akanjs/document/src/schema.ts
|
|
2499
|
-
var import_mongoose4 = require("mongoose");
|
|
2500
|
-
var getDefaultSchemaOptions = () => ({
|
|
2501
|
-
toJSON: { getters: false, virtuals: true },
|
|
2502
|
-
toObject: { getters: false, virtuals: true },
|
|
2503
|
-
_id: true,
|
|
2504
|
-
id: true,
|
|
2505
|
-
timestamps: true,
|
|
2506
|
-
methods: {
|
|
2507
|
-
refresh: async function() {
|
|
2508
|
-
Object.assign(this, await this.constructor.findById(this._id));
|
|
2509
|
-
return this;
|
|
2510
|
-
}
|
|
2511
|
-
},
|
|
2512
|
-
statics: {
|
|
2513
|
-
pickOne: async function(query, projection) {
|
|
2514
|
-
const doc = await this.findOne(query, projection);
|
|
2515
|
-
if (!doc)
|
|
2516
|
-
throw new Error("No Document");
|
|
2517
|
-
return doc;
|
|
2518
|
-
},
|
|
2519
|
-
pickById: async function(docId, projection) {
|
|
2520
|
-
if (!docId)
|
|
2521
|
-
throw new Error("No Document ID");
|
|
2522
|
-
const doc = await this.findById(docId, projection);
|
|
2523
|
-
if (!doc)
|
|
2524
|
-
throw new Error("No Document");
|
|
2525
|
-
return doc;
|
|
2526
|
-
},
|
|
2527
|
-
sample: async function(query, size = 1, aggregations = []) {
|
|
2528
|
-
const objs = await this.aggregate([
|
|
2529
|
-
{ $match: convertAggregateMatch(query) },
|
|
2530
|
-
{ $sample: { size } },
|
|
2531
|
-
...aggregations
|
|
2532
|
-
]);
|
|
2533
|
-
return objs.map((obj) => new this(obj));
|
|
2534
|
-
},
|
|
2535
|
-
sampleOne: async function(query, aggregations = []) {
|
|
2536
|
-
const obj = await this.aggregate([
|
|
2537
|
-
{ $match: convertAggregateMatch(query) },
|
|
2538
|
-
{ $sample: { size: 1 } },
|
|
2539
|
-
...aggregations
|
|
2540
|
-
]);
|
|
2541
|
-
return obj.length ? new this(obj[0]) : null;
|
|
2542
|
-
},
|
|
2543
|
-
addSummary: async function(prefix = "total", num = 1) {
|
|
2544
|
-
const update = Array.isArray(prefix) ? {
|
|
2545
|
-
$inc: {
|
|
2546
|
-
...prefix.reduce((acc, cur) => ({ ...acc, [`${cur}${this.modelName}`]: num }), {})
|
|
2547
|
-
}
|
|
2548
|
-
} : { $inc: { [`${prefix}${this.modelName}`]: num } };
|
|
2549
|
-
await this.db.collection("summaries").updateOne({ status: "active" }, update);
|
|
2550
|
-
},
|
|
2551
|
-
moveSummary: async function(prev, next, num = 1) {
|
|
2552
|
-
await this.db.collection("summaries").updateOne(
|
|
2553
|
-
{ status: "active" },
|
|
2554
|
-
{
|
|
2555
|
-
$inc: {
|
|
2556
|
-
[`${prev}${this.modelName}`]: -num,
|
|
2557
|
-
[`${next}${this.modelName}`]: num
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
);
|
|
2561
|
-
},
|
|
2562
|
-
subSummary: async function(prefix = "total", num = 1) {
|
|
2563
|
-
const update = Array.isArray(prefix) ? {
|
|
2564
|
-
$inc: {
|
|
2565
|
-
...prefix.reduce((acc, cur) => ({ ...acc, [`${cur}${this.modelName}`]: -num }), {})
|
|
2566
|
-
}
|
|
2567
|
-
} : { $inc: { [`${prefix}${this.modelName}`]: -num } };
|
|
2568
|
-
await this.db.collection("summaries").updateOne({ status: "active" }, update);
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2571
|
-
});
|
|
2572
|
-
var convertOperatorValue = (value) => {
|
|
2573
|
-
if (Array.isArray(value))
|
|
2574
|
-
return value.map((v) => convertOperatorValue(v));
|
|
2575
|
-
else if (!value)
|
|
2576
|
-
return value;
|
|
2577
|
-
else if ((0, import_mongoose4.isValidObjectId)(value))
|
|
2578
|
-
return new import_mongoose4.Types.ObjectId(value);
|
|
2579
|
-
else if (isValidDate(value))
|
|
2580
|
-
return dayjs(value).toDate();
|
|
2581
|
-
else if (value.constructor !== Object)
|
|
2582
|
-
return value;
|
|
2583
|
-
else if (typeof value !== "object")
|
|
2584
|
-
return value;
|
|
2585
|
-
else
|
|
2586
|
-
return Object.fromEntries(
|
|
2587
|
-
Object.entries(value).map(([key, value2]) => [key, convertOperatorValue(value2)])
|
|
2588
|
-
);
|
|
2589
|
-
};
|
|
2590
|
-
var convertAggregateMatch = (query) => {
|
|
2591
|
-
return Object.fromEntries(
|
|
2592
|
-
Object.entries(query).map(([key, value]) => {
|
|
2593
|
-
return [key, convertOperatorValue(value)];
|
|
2594
|
-
})
|
|
2595
|
-
);
|
|
2596
|
-
};
|
|
2597
|
-
|
|
2598
|
-
// pkgs/@akanjs/document/src/dataLoader.ts
|
|
2599
|
-
var import_dataloader = __toESM(require("dataloader"));
|
|
2600
|
-
var import_lodash = require("lodash");
|
|
2601
|
-
var import_mongoose5 = require("mongoose");
|
|
2602
|
-
var Id = import_mongoose5.Types.ObjectId;
|
|
2603
|
-
var ObjectId = import_mongoose5.Schema.Types.ObjectId;
|
|
2604
|
-
var Mixed = import_mongoose5.Schema.Types.Mixed;
|
|
2605
|
-
var createLoader = (model, fieldName = "_id", defaultQuery = {}) => {
|
|
2606
|
-
return new import_dataloader.default(
|
|
2607
|
-
(fields) => {
|
|
2608
|
-
const query = { ...defaultQuery };
|
|
2609
|
-
query[fieldName] = { $in: fields };
|
|
2610
|
-
const data = model.find(query).then((list) => {
|
|
2611
|
-
const listByKey = (0, import_lodash.keyBy)(list, fieldName);
|
|
2612
|
-
return fields.map((id) => (0, import_lodash.get)(listByKey, id, null));
|
|
2613
|
-
});
|
|
2614
|
-
return data;
|
|
2615
|
-
},
|
|
2616
|
-
{ name: "dataloader", cache: false }
|
|
2617
|
-
);
|
|
2618
|
-
};
|
|
2619
|
-
var createArrayLoader = (model, fieldName = "_id", defaultQuery = {}) => {
|
|
2620
|
-
return new import_dataloader.default((fields) => {
|
|
2621
|
-
const query = { ...defaultQuery };
|
|
2622
|
-
query[fieldName] = { $in: fields };
|
|
2623
|
-
const data = model.find(query).then((list) => {
|
|
2624
|
-
return fields.map((field) => list.filter((item) => field === item[fieldName]));
|
|
2625
|
-
});
|
|
2626
|
-
return data;
|
|
2627
|
-
});
|
|
2628
|
-
};
|
|
2629
|
-
var createQueryLoader = (model, queryKeys, defaultQuery = {}) => {
|
|
2630
|
-
return new import_dataloader.default(
|
|
2631
|
-
(queries) => {
|
|
2632
|
-
const query = {
|
|
2633
|
-
$and: [{ $or: queries }, defaultQuery]
|
|
2634
|
-
};
|
|
2635
|
-
const getQueryKey = (query2) => queryKeys.map((key) => query2[key].toString()).join("");
|
|
2636
|
-
const data = model.find(query).then((list) => {
|
|
2637
|
-
const listByKey = (0, import_lodash.keyBy)(list, getQueryKey);
|
|
2638
|
-
return queries.map((query2) => (0, import_lodash.get)(listByKey, getQueryKey(query2), null));
|
|
2639
|
-
});
|
|
2640
|
-
return data;
|
|
2641
|
-
},
|
|
2642
|
-
{ name: "dataloader", cache: false }
|
|
2643
|
-
);
|
|
2644
|
-
};
|
|
2645
|
-
var getLoaderMetaMapByPrototype = (prototype) => {
|
|
2646
|
-
const loaderMetaMap = Reflect.getOwnMetadata("loaders", prototype) ?? /* @__PURE__ */ new Map();
|
|
2647
|
-
return loaderMetaMap;
|
|
2648
|
-
};
|
|
2649
|
-
var getLoaderMetas = (target) => {
|
|
2650
|
-
const metas = [...getLoaderMetaMapByPrototype(target.prototype).values()];
|
|
2651
|
-
return metas;
|
|
2652
|
-
};
|
|
2653
|
-
|
|
2654
|
-
// pkgs/@akanjs/document/src/database.ts
|
|
2655
|
-
var CacheDatabase = class {
|
|
2656
|
-
constructor(refName, redis) {
|
|
2657
|
-
this.refName = refName;
|
|
2658
|
-
this.redis = redis;
|
|
2659
|
-
this.logger = new Logger(`${refName}Cache`);
|
|
2660
|
-
}
|
|
2661
|
-
logger;
|
|
2662
|
-
async set(topic, key, value, option = {}) {
|
|
2663
|
-
const setOption = { PXAT: option.expireAt?.toDate().getTime() };
|
|
2664
|
-
await this.redis.set(`${this.refName}:${topic}:${key}`, value, setOption);
|
|
2665
|
-
}
|
|
2666
|
-
async get(topic, key) {
|
|
2667
|
-
const value = await this.redis.get(`${this.refName}:${topic}:${key}`);
|
|
2668
|
-
return value;
|
|
2669
|
-
}
|
|
2670
|
-
async delete(topic, key) {
|
|
2671
|
-
await this.redis.del(`${this.refName}:${topic}:${key}`);
|
|
2672
|
-
}
|
|
2673
|
-
};
|
|
2674
|
-
var SearchDatabase = class {
|
|
2675
|
-
constructor(refName, meili) {
|
|
2676
|
-
this.refName = refName;
|
|
2677
|
-
this.meili = meili;
|
|
2678
|
-
this.logger = new Logger(`${refName}Search`);
|
|
2679
|
-
this.index = meili.index(lowerlize(refName));
|
|
2680
|
-
}
|
|
2681
|
-
logger;
|
|
2682
|
-
index;
|
|
2683
|
-
async searchIds(searchText, option = {}) {
|
|
2684
|
-
const { skip = 0, limit = DEFAULT_PAGE_SIZE, sort } = option;
|
|
2685
|
-
if (!searchText) {
|
|
2686
|
-
const { results, total } = await this.index.getDocuments({ offset: skip ?? 0, limit: limit ?? 0 });
|
|
2687
|
-
return { ids: results.map((result) => result.id), total };
|
|
2688
|
-
}
|
|
2689
|
-
const { hits, estimatedTotalHits } = await this.index.search(searchText, {
|
|
2690
|
-
offset: skip ?? 0,
|
|
2691
|
-
limit: limit ?? 0,
|
|
2692
|
-
sort: sort ?? [],
|
|
2693
|
-
filter: option.filter,
|
|
2694
|
-
attributesToRetrieve: ["id"]
|
|
2695
|
-
});
|
|
2696
|
-
return { ids: hits.map((hit) => hit.id), total: estimatedTotalHits };
|
|
2697
|
-
}
|
|
2698
|
-
async count(searchText, option = {}) {
|
|
2699
|
-
const { skip = 0, limit = DEFAULT_PAGE_SIZE, sort = "" } = option;
|
|
2700
|
-
if (!searchText) {
|
|
2701
|
-
const { results, total } = await this.index.getDocuments({ offset: skip ?? 0, limit: limit ?? 0 });
|
|
2702
|
-
return total;
|
|
2703
|
-
}
|
|
2704
|
-
const { hits, estimatedTotalHits } = await this.index.search(searchText, {
|
|
2705
|
-
offset: skip ?? 0,
|
|
2706
|
-
limit: limit ?? 0,
|
|
2707
|
-
filter: option.filter,
|
|
2708
|
-
attributesToRetrieve: ["id"]
|
|
2709
|
-
});
|
|
2710
|
-
return estimatedTotalHits;
|
|
2711
|
-
}
|
|
2712
|
-
};
|
|
2713
|
-
var DatabaseModelStorage = class {
|
|
2714
|
-
__ModelType__ = "DatabaseModelStorage";
|
|
2715
|
-
};
|
|
2716
|
-
var databaseModelOf = (database, model, redis, meili) => {
|
|
2717
|
-
const [modelName, className] = [database.refName, capitalize(database.refName)];
|
|
2718
|
-
const insightFieldMetas = getFieldMetas(database.Insight);
|
|
2719
|
-
const accumulator = Object.fromEntries(insightFieldMetas.map((fieldMeta) => [fieldMeta.key, fieldMeta.accumulate]));
|
|
2720
|
-
const defaultInsight = Object.fromEntries(insightFieldMetas.map((fieldMeta) => [fieldMeta.key, fieldMeta.default]));
|
|
2721
|
-
const makeSafeQuery = (query) => ({ removedAt: { $exists: false }, ...query ?? {} });
|
|
2722
|
-
const makeSafeMatchStage = (query) => ({
|
|
2723
|
-
$match: { removedAt: { $exists: false }, ...convertAggregateMatch(query) }
|
|
2724
|
-
});
|
|
2725
|
-
const getListQuery = (query, queryOption) => {
|
|
2726
|
-
const find = makeSafeQuery(query);
|
|
2727
|
-
const sort = getFilterSort(database.Filter, queryOption?.sort ?? "latest");
|
|
2728
|
-
const skip = queryOption?.skip ?? 0;
|
|
2729
|
-
const limit = queryOption?.limit === null ? DEFAULT_PAGE_SIZE : queryOption?.limit ?? 0;
|
|
2730
|
-
const select = queryOption?.select;
|
|
2731
|
-
const sample = queryOption?.sample;
|
|
2732
|
-
return { find, sort, skip, limit, select, sample };
|
|
2733
|
-
};
|
|
2734
|
-
const getFindQuery = (query, queryOption) => {
|
|
2735
|
-
const find = makeSafeQuery(query);
|
|
2736
|
-
const sort = getFilterSort(database.Filter, queryOption?.sort ?? "latest");
|
|
2737
|
-
const skip = queryOption?.skip ?? 0;
|
|
2738
|
-
const select = queryOption?.select;
|
|
2739
|
-
const sample = queryOption?.sample ?? false;
|
|
2740
|
-
return { find, sort, skip, select, sample };
|
|
2741
|
-
};
|
|
2742
|
-
const getSearchSort = (sortKey) => {
|
|
2743
|
-
const sort = getFilterSort(database.Filter, sortKey ?? "latest");
|
|
2744
|
-
return Object.entries(sort).map(([key, value]) => `${key}:${value === 1 ? "asc" : "desc"}`);
|
|
2745
|
-
};
|
|
2746
|
-
const loader = createLoader(model);
|
|
2747
|
-
const cacheDatabase = new CacheDatabase(database.refName, redis);
|
|
2748
|
-
const searchDatabase = new SearchDatabase(database.refName, meili);
|
|
2749
|
-
const DatabaseModel = Reflect.getMetadata(database.refName, DatabaseModelStorage.prototype) ?? class DatabaseModel {
|
|
2750
|
-
logger = new Logger(`${modelName}Model`);
|
|
2751
|
-
__model = model;
|
|
2752
|
-
__cache = cacheDatabase;
|
|
2753
|
-
__search = searchDatabase;
|
|
2754
|
-
__loader = loader;
|
|
2755
|
-
async __list(query, queryOption) {
|
|
2756
|
-
const { find, sort, skip, limit, select, sample } = getListQuery(query, queryOption);
|
|
2757
|
-
return sample ? await this.__model.sample(find, limit) : await this.__model.find(find, select).sort(sort).skip(skip).limit(limit);
|
|
2758
|
-
}
|
|
2759
|
-
async __listIds(query, queryOption) {
|
|
2760
|
-
const { find, sort, skip, limit, sample } = getListQuery(query, queryOption);
|
|
2761
|
-
return (sample ? await this.__model.sample(find, limit, [{ $project: { _id: 1 } }]) : await this.__model.find(find).sort(sort).skip(skip).limit(limit).select("_id")).map(({ _id }) => _id.toString());
|
|
2762
|
-
}
|
|
2763
|
-
async __find(query, queryOption) {
|
|
2764
|
-
const { find, sort, skip, select, sample } = getFindQuery(query, queryOption);
|
|
2765
|
-
const doc = sample ? await this.__model.sampleOne(find) : await this.__model.findOne(find, select).sort(sort).skip(skip);
|
|
2766
|
-
if (!doc)
|
|
2767
|
-
return null;
|
|
2768
|
-
return doc;
|
|
2769
|
-
}
|
|
2770
|
-
async __findId(query, queryOption) {
|
|
2771
|
-
const { find, sort, skip, sample } = getFindQuery(query, queryOption);
|
|
2772
|
-
const doc = sample ? await this.__model.sampleOne(find, [{ $project: { _id: 1 } }]) : await this.__model.findOne(find).sort(sort).skip(skip).select("_id");
|
|
2773
|
-
if (!doc)
|
|
2774
|
-
return null;
|
|
2775
|
-
return doc._id.toString();
|
|
2776
|
-
}
|
|
2777
|
-
async __pick(query, queryOption) {
|
|
2778
|
-
const { find, sort, skip, select, sample } = getFindQuery(query, queryOption);
|
|
2779
|
-
const doc = sample ? await this.__model.sampleOne(find) : await this.__model.findOne(find, select).sort(sort).skip(skip);
|
|
2780
|
-
if (!doc)
|
|
2781
|
-
throw new Error(`No Document (${database.refName}): ${JSON.stringify(query)}`);
|
|
2782
|
-
return doc;
|
|
2783
|
-
}
|
|
2784
|
-
async __pickId(query, queryOption) {
|
|
2785
|
-
const { find, sort, skip, sample } = getFindQuery(query, queryOption);
|
|
2786
|
-
const doc = sample ? await this.__model.sampleOne(find, [{ $project: { _id: 1 } }]) : await this.__model.findOne(find).sort(sort).skip(skip).select("_id");
|
|
2787
|
-
if (!doc)
|
|
2788
|
-
throw new Error(`No Document (${database.refName}): ${JSON.stringify(query)}`);
|
|
2789
|
-
return doc._id.toString();
|
|
2790
|
-
}
|
|
2791
|
-
async __exists(query) {
|
|
2792
|
-
const find = makeSafeQuery(query);
|
|
2793
|
-
const existingId = await this.__model.exists(find);
|
|
2794
|
-
return existingId?.toString() ?? null;
|
|
2795
|
-
}
|
|
2796
|
-
async __count(query) {
|
|
2797
|
-
const find = makeSafeQuery(query);
|
|
2798
|
-
return await this.__model.countDocuments(find);
|
|
2799
|
-
}
|
|
2800
|
-
async __insight(query) {
|
|
2801
|
-
if (!accumulator)
|
|
2802
|
-
throw new Error(`No Insight (${database.refName})`);
|
|
2803
|
-
const res = await this.__model.aggregate([
|
|
2804
|
-
makeSafeMatchStage(query),
|
|
2805
|
-
{ $group: { _id: null, ...accumulator } }
|
|
2806
|
-
]);
|
|
2807
|
-
const data = res[0];
|
|
2808
|
-
return data ?? defaultInsight;
|
|
2809
|
-
}
|
|
2810
|
-
async getDefaultSummary(addQuery = {}) {
|
|
2811
|
-
if (!database.Summary)
|
|
2812
|
-
return {};
|
|
2813
|
-
const fieldMetas = getFieldMetas(database.Summary);
|
|
2814
|
-
const summary = {};
|
|
2815
|
-
await Promise.all(
|
|
2816
|
-
fieldMetas.filter((fieldMeta) => !!fieldMeta.query).map(async (fieldMeta) => {
|
|
2817
|
-
const query = typeof fieldMeta.query === "function" ? fieldMeta.query() : fieldMeta.query;
|
|
2818
|
-
summary[fieldMeta.key] = query ? await model.countDocuments({ ...query, ...addQuery }) : fieldMeta.default;
|
|
2819
|
-
})
|
|
2820
|
-
);
|
|
2821
|
-
return summary;
|
|
2822
|
-
}
|
|
2823
|
-
async [`get${className}`](id) {
|
|
2824
|
-
const doc = await this.__loader.load(id);
|
|
2825
|
-
if (!doc)
|
|
2826
|
-
throw new Error(`No Document (${database.refName}): ${id}`);
|
|
2827
|
-
return doc;
|
|
2828
|
-
}
|
|
2829
|
-
async [`load${className}`](id) {
|
|
2830
|
-
return id ? await this.__loader.load(id) : null;
|
|
2831
|
-
}
|
|
2832
|
-
async [`load${className}Many`](ids) {
|
|
2833
|
-
return await this.__loader.loadMany(ids);
|
|
2834
|
-
}
|
|
2835
|
-
async [`create${className}`](data) {
|
|
2836
|
-
return await new this.__model(data).save();
|
|
2837
|
-
}
|
|
2838
|
-
async [`update${className}`](id, data) {
|
|
2839
|
-
const doc = await this.__model.pickById(id);
|
|
2840
|
-
return await doc.set(data).save();
|
|
2841
|
-
}
|
|
2842
|
-
async [`remove${className}`](id) {
|
|
2843
|
-
const doc = await this.__model.pickById(id);
|
|
2844
|
-
return await doc.set({ removedAt: dayjs() }).save();
|
|
2845
|
-
}
|
|
2846
|
-
async [`search${className}`](searchText, queryOption = {}) {
|
|
2847
|
-
const { skip, limit, sort } = queryOption;
|
|
2848
|
-
const { ids, total } = await this.__search.searchIds(searchText, { skip, limit, sort: getSearchSort(sort) });
|
|
2849
|
-
const docs = await this.__loader.loadMany(ids);
|
|
2850
|
-
return { docs, count: total };
|
|
2851
|
-
}
|
|
2852
|
-
async [`searchDocs${className}`](searchText, queryOption = {}) {
|
|
2853
|
-
const { skip, limit, sort } = queryOption;
|
|
2854
|
-
const { ids } = await this.__search.searchIds(searchText, { skip, limit, sort: getSearchSort(sort) });
|
|
2855
|
-
return await this.__loader.loadMany(ids);
|
|
2856
|
-
}
|
|
2857
|
-
async [`searchCount${className}`](searchText) {
|
|
2858
|
-
return await this.__search.count(searchText);
|
|
2859
|
-
}
|
|
2860
|
-
};
|
|
2861
|
-
DatabaseModel.prototype[className] = model;
|
|
2862
|
-
DatabaseModel.prototype[`${modelName}Loader`] = loader;
|
|
2863
|
-
DatabaseModel.prototype[`${modelName}Cache`] = cacheDatabase;
|
|
2864
|
-
DatabaseModel.prototype[`${modelName}Search`] = searchDatabase;
|
|
2865
|
-
const getQueryDataFromKey = (queryKey, args) => {
|
|
2866
|
-
const lastArg = args.at(-1);
|
|
2867
|
-
const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
|
|
2868
|
-
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
2869
|
-
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
2870
|
-
const queryOption = hasQueryOption ? lastArg : {};
|
|
2871
|
-
return { query, queryOption };
|
|
2872
|
-
};
|
|
2873
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
|
|
2874
|
-
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
2875
|
-
queryKeys.forEach((queryKey) => {
|
|
2876
|
-
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
2877
|
-
DatabaseModel.prototype[`list${capitalize(queryKey)}`] = async function(...args) {
|
|
2878
|
-
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2879
|
-
return this.__list(query, queryOption);
|
|
2880
|
-
};
|
|
2881
|
-
DatabaseModel.prototype[`listIds${capitalize(queryKey)}`] = async function(...args) {
|
|
2882
|
-
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2883
|
-
return this.__listIds(query, queryOption);
|
|
2884
|
-
};
|
|
2885
|
-
DatabaseModel.prototype[`find${capitalize(queryKey)}`] = async function(...args) {
|
|
2886
|
-
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2887
|
-
return this.__find(query, queryOption);
|
|
2888
|
-
};
|
|
2889
|
-
DatabaseModel.prototype[`findId${capitalize(queryKey)}`] = async function(...args) {
|
|
2890
|
-
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2891
|
-
return this.__findId(query, queryOption);
|
|
2892
|
-
};
|
|
2893
|
-
DatabaseModel.prototype[`pick${capitalize(queryKey)}`] = async function(...args) {
|
|
2894
|
-
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2895
|
-
return this.__pick(query, queryOption);
|
|
2896
|
-
};
|
|
2897
|
-
DatabaseModel.prototype[`pickId${capitalize(queryKey)}`] = async function(...args) {
|
|
2898
|
-
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2899
|
-
return this.__pickId(query, queryOption);
|
|
2900
|
-
};
|
|
2901
|
-
DatabaseModel.prototype[`exists${capitalize(queryKey)}`] = async function(...args) {
|
|
2902
|
-
const query = queryFn(...args);
|
|
2903
|
-
return this.__exists(query);
|
|
2904
|
-
};
|
|
2905
|
-
DatabaseModel.prototype[`count${capitalize(queryKey)}`] = async function(...args) {
|
|
2906
|
-
const query = queryFn(...args);
|
|
2907
|
-
return this.__count(query);
|
|
2908
|
-
};
|
|
2909
|
-
DatabaseModel.prototype[`insight${capitalize(queryKey)}`] = async function(...args) {
|
|
2910
|
-
const query = queryFn(...args);
|
|
2911
|
-
return this.__insight(query);
|
|
2912
|
-
};
|
|
2913
|
-
});
|
|
2914
|
-
const loaderMetas = getLoaderMetas(database.Model);
|
|
2915
|
-
loaderMetas.forEach((loaderMeta) => {
|
|
2916
|
-
const loader2 = loaderMeta.type === "Field" ? createLoader(model, loaderMeta.fieldName) : loaderMeta.type === "ArrayField" ? createArrayLoader(model, loaderMeta.fieldName) : loaderMeta.type === "Query" ? createQueryLoader(model, loaderMeta.queryKeys ?? []) : null;
|
|
2917
|
-
DatabaseModel.prototype[loaderMeta.key] = loader2;
|
|
2918
|
-
});
|
|
2919
|
-
Object.getOwnPropertyNames(database.Model.prototype).forEach((key) => {
|
|
2920
|
-
DatabaseModel.prototype[key] = database.Model.prototype[key];
|
|
2921
|
-
});
|
|
2922
|
-
const createDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `create${className}`);
|
|
2923
|
-
if (createDescriptor)
|
|
2924
|
-
Transaction()(DatabaseModel.prototype, `create${className}`, createDescriptor);
|
|
2925
|
-
const updateDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `update${className}`);
|
|
2926
|
-
if (updateDescriptor)
|
|
2927
|
-
Transaction()(DatabaseModel.prototype, `update${className}`, updateDescriptor);
|
|
2928
|
-
const removeDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `remove${className}`);
|
|
2929
|
-
if (removeDescriptor)
|
|
2930
|
-
Transaction()(DatabaseModel.prototype, `remove${className}`, removeDescriptor);
|
|
2931
|
-
Reflect.defineMetadata(database.refName, DatabaseModel, DatabaseModelStorage.prototype);
|
|
2932
|
-
return new DatabaseModel();
|
|
2933
|
-
};
|
|
2934
|
-
|
|
2935
423
|
// pkgs/@akanjs/server/src/module.ts
|
|
424
|
+
var import_common10 = require("@akanjs/common");
|
|
425
|
+
var import_constant4 = require("@akanjs/constant");
|
|
426
|
+
var import_document2 = require("@akanjs/document");
|
|
427
|
+
var import_service5 = require("@akanjs/service");
|
|
428
|
+
var import_signal6 = require("@akanjs/signal");
|
|
2936
429
|
var import_bull2 = require("@nestjs/bull");
|
|
2937
|
-
var
|
|
2938
|
-
var
|
|
430
|
+
var import_common11 = require("@nestjs/common");
|
|
431
|
+
var import_mongoose2 = require("@nestjs/mongoose");
|
|
2939
432
|
|
|
2940
433
|
// pkgs/@akanjs/server/src/schema.ts
|
|
2941
|
-
var
|
|
434
|
+
var import_base4 = require("@akanjs/base");
|
|
435
|
+
var import_common7 = require("@akanjs/common");
|
|
436
|
+
var import_constant3 = require("@akanjs/constant");
|
|
437
|
+
var import_document = require("@akanjs/document");
|
|
438
|
+
var import_signal4 = require("@akanjs/signal");
|
|
439
|
+
var import_mongoose = require("mongoose");
|
|
2942
440
|
var ScalarSchemaStorage = class {
|
|
2943
441
|
};
|
|
2944
442
|
var SchemaStorage = class {
|
|
2945
443
|
};
|
|
2946
444
|
var scalarMongoTypeMap = /* @__PURE__ */ new Map([
|
|
2947
|
-
[ID, ObjectId],
|
|
2948
|
-
[Int, Number],
|
|
2949
|
-
[Float, Number],
|
|
2950
|
-
[
|
|
445
|
+
[import_base4.ID, import_document.ObjectId],
|
|
446
|
+
[import_base4.Int, Number],
|
|
447
|
+
[import_base4.Float, Number],
|
|
448
|
+
[import_base4.JSON, import_mongoose.Schema.Types.Mixed],
|
|
2951
449
|
[Map, Map],
|
|
2952
450
|
[String, String],
|
|
2953
451
|
[Boolean, Boolean],
|
|
@@ -2956,13 +454,13 @@ var scalarMongoTypeMap = /* @__PURE__ */ new Map([
|
|
|
2956
454
|
var applyMongoProp = (schemaProps, fieldMeta) => {
|
|
2957
455
|
if (["id", "createdAt", "updatedAt"].includes(fieldMeta.key) || fieldMeta.fieldType === "resolve")
|
|
2958
456
|
return;
|
|
2959
|
-
const type = fieldMeta.isClass ? fieldMeta.isScalar ? createSchema(fieldMeta.modelRef) : ObjectId : scalarMongoTypeMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
|
|
457
|
+
const type = fieldMeta.isClass ? fieldMeta.isScalar ? createSchema(fieldMeta.modelRef) : import_document.ObjectId : scalarMongoTypeMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
|
|
2960
458
|
let prop = {};
|
|
2961
459
|
if (fieldMeta.optArrDepth) {
|
|
2962
460
|
prop.type = type;
|
|
2963
461
|
prop.required = true;
|
|
2964
462
|
if (fieldMeta.isClass && !fieldMeta.refPath)
|
|
2965
|
-
prop.ref = getClassMeta(fieldMeta.modelRef).refName;
|
|
463
|
+
prop.ref = (0, import_constant3.getClassMeta)(fieldMeta.modelRef).refName;
|
|
2966
464
|
if (fieldMeta.refPath)
|
|
2967
465
|
prop.refPath = fieldMeta.refPath;
|
|
2968
466
|
if (typeof fieldMeta.min === "number")
|
|
@@ -2977,20 +475,20 @@ var applyMongoProp = (schemaProps, fieldMeta) => {
|
|
|
2977
475
|
prop.maxlength = fieldMeta.maxlength;
|
|
2978
476
|
if (fieldMeta.validate) {
|
|
2979
477
|
prop.validate = function(value) {
|
|
2980
|
-
return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? dayjs() : value, this) ?? true;
|
|
478
|
+
return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base4.dayjs)() : value, this) ?? true;
|
|
2981
479
|
};
|
|
2982
480
|
}
|
|
2983
|
-
prop = { type: arraiedModel(prop, fieldMeta.optArrDepth), default: [], required: true };
|
|
481
|
+
prop = { type: (0, import_base4.arraiedModel)(prop, fieldMeta.optArrDepth), default: [], required: true };
|
|
2984
482
|
if (fieldMeta.modelRef.prototype === Date.prototype) {
|
|
2985
|
-
prop.get = (dates) => dates.map((date) => dayjs(date));
|
|
483
|
+
prop.get = (dates) => dates.map((date) => (0, import_base4.dayjs)(date));
|
|
2986
484
|
prop.set = (days) => days.map((day) => day.toDate());
|
|
2987
485
|
}
|
|
2988
|
-
if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === ID.prototype) {
|
|
486
|
+
if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base4.ID.prototype) {
|
|
2989
487
|
prop.get = (ids) => ids.map((id) => id.toString());
|
|
2990
|
-
prop.set = (ids) => ids.map((id) => new
|
|
488
|
+
prop.set = (ids) => ids.map((id) => new import_mongoose.Types.ObjectId(id));
|
|
2991
489
|
}
|
|
2992
490
|
} else {
|
|
2993
|
-
prop.type = arraiedModel(type, fieldMeta.arrDepth);
|
|
491
|
+
prop.type = (0, import_base4.arraiedModel)(type, fieldMeta.arrDepth);
|
|
2994
492
|
prop.required = !fieldMeta.nullable;
|
|
2995
493
|
if (fieldMeta.isMap) {
|
|
2996
494
|
prop.of = scalarMongoTypeMap.get(fieldMeta.of) ?? createSchema(fieldMeta.of);
|
|
@@ -3001,15 +499,15 @@ var applyMongoProp = (schemaProps, fieldMeta) => {
|
|
|
3001
499
|
if (typeof fieldMeta.default === "function")
|
|
3002
500
|
prop.default = function() {
|
|
3003
501
|
const def = fieldMeta.default(this);
|
|
3004
|
-
return (0,
|
|
502
|
+
return (0, import_common7.isDayjs)(def) ? def.toDate() : def;
|
|
3005
503
|
};
|
|
3006
504
|
else
|
|
3007
|
-
prop.default = (0,
|
|
505
|
+
prop.default = (0, import_common7.isDayjs)(fieldMeta.default) ? fieldMeta.default.toDate() : fieldMeta.default instanceof import_base4.Enum ? [...fieldMeta.default.values] : fieldMeta.default;
|
|
3008
506
|
}
|
|
3009
507
|
if (typeof fieldMeta.immutable !== "undefined")
|
|
3010
508
|
prop.immutable = fieldMeta.immutable;
|
|
3011
509
|
if (fieldMeta.isClass && !fieldMeta.refPath)
|
|
3012
|
-
prop.ref = getClassMeta(fieldMeta.modelRef).refName;
|
|
510
|
+
prop.ref = (0, import_constant3.getClassMeta)(fieldMeta.modelRef).refName;
|
|
3013
511
|
if (fieldMeta.refPath)
|
|
3014
512
|
prop.refPath = fieldMeta.refPath;
|
|
3015
513
|
if (typeof fieldMeta.min === "number")
|
|
@@ -3029,60 +527,60 @@ var applyMongoProp = (schemaProps, fieldMeta) => {
|
|
|
3029
527
|
prop.set = (v) => v === null ? void 0 : v;
|
|
3030
528
|
}
|
|
3031
529
|
if (fieldMeta.modelRef.prototype === Date.prototype) {
|
|
3032
|
-
prop.get = (date) => date ? dayjs(date) : void 0;
|
|
3033
|
-
prop.set = (day) => day ? dayjs(day).toDate() : void 0;
|
|
530
|
+
prop.get = (date) => date ? (0, import_base4.dayjs)(date) : void 0;
|
|
531
|
+
prop.set = (day) => day ? (0, import_base4.dayjs)(day).toDate() : void 0;
|
|
3034
532
|
}
|
|
3035
|
-
if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === ID.prototype) {
|
|
533
|
+
if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base4.ID.prototype) {
|
|
3036
534
|
prop.get = (id) => id ? id.toString() : void 0;
|
|
3037
|
-
prop.set = (id) => id ? new
|
|
535
|
+
prop.set = (id) => id ? new import_mongoose.Types.ObjectId(id) : void 0;
|
|
3038
536
|
}
|
|
3039
537
|
if (fieldMeta.isClass && fieldMeta.isScalar && fieldMeta.default === null && !fieldMeta.nullable) {
|
|
3040
|
-
prop.default = makeDefault(fieldMeta.modelRef);
|
|
538
|
+
prop.default = (0, import_signal4.makeDefault)(fieldMeta.modelRef);
|
|
3041
539
|
}
|
|
3042
540
|
if (fieldMeta.validate) {
|
|
3043
541
|
prop.validate = function(value) {
|
|
3044
|
-
return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? dayjs() : value, this) ?? true;
|
|
542
|
+
return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base4.dayjs)() : value, this) ?? true;
|
|
3045
543
|
};
|
|
3046
544
|
}
|
|
3047
545
|
}
|
|
3048
546
|
schemaProps[fieldMeta.key] = prop;
|
|
3049
547
|
};
|
|
3050
548
|
var createSchema = (modelRef) => {
|
|
3051
|
-
const classMeta = getClassMeta(modelRef);
|
|
549
|
+
const classMeta = (0, import_constant3.getClassMeta)(modelRef);
|
|
3052
550
|
const schemaMeta = Reflect.getMetadata(classMeta.refName, ScalarSchemaStorage.prototype);
|
|
3053
551
|
if (schemaMeta)
|
|
3054
552
|
return schemaMeta;
|
|
3055
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
553
|
+
const fieldMetas = (0, import_constant3.getFieldMetas)(modelRef);
|
|
3056
554
|
const schemaProps = {};
|
|
3057
555
|
fieldMetas.forEach((fieldMeta) => {
|
|
3058
556
|
applyMongoProp(schemaProps, fieldMeta);
|
|
3059
557
|
});
|
|
3060
|
-
const schema = new
|
|
558
|
+
const schema = new import_mongoose.Schema(schemaProps);
|
|
3061
559
|
Reflect.defineMetadata(classMeta.refName, schema, ScalarSchemaStorage.prototype);
|
|
3062
560
|
return schema;
|
|
3063
561
|
};
|
|
3064
562
|
var schemaOf = (modelRef, docRef, middleware) => {
|
|
3065
|
-
const classMeta = getClassMeta(docRef);
|
|
563
|
+
const classMeta = (0, import_constant3.getClassMeta)(docRef);
|
|
3066
564
|
const schemaMeta = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
|
|
3067
565
|
if (schemaMeta)
|
|
3068
566
|
return schemaMeta;
|
|
3069
|
-
const fieldMetas = getFieldMetas(docRef);
|
|
567
|
+
const fieldMetas = (0, import_constant3.getFieldMetas)(docRef);
|
|
3070
568
|
const schemaProps = {
|
|
3071
569
|
createdAt: {
|
|
3072
570
|
type: Date,
|
|
3073
|
-
get: (date) => date ? dayjs(date) : date,
|
|
3074
|
-
set: (day) => day ? dayjs(day).toDate() : day
|
|
571
|
+
get: (date) => date ? (0, import_base4.dayjs)(date) : date,
|
|
572
|
+
set: (day) => day ? (0, import_base4.dayjs)(day).toDate() : day
|
|
3075
573
|
},
|
|
3076
574
|
updatedAt: {
|
|
3077
575
|
type: Date,
|
|
3078
|
-
get: (date) => date ? dayjs(date) : date,
|
|
3079
|
-
set: (day) => day ? dayjs(day).toDate() : day
|
|
576
|
+
get: (date) => date ? (0, import_base4.dayjs)(date) : date,
|
|
577
|
+
set: (day) => day ? (0, import_base4.dayjs)(day).toDate() : day
|
|
3080
578
|
}
|
|
3081
579
|
};
|
|
3082
580
|
fieldMetas.forEach((fieldMeta) => {
|
|
3083
581
|
applyMongoProp(schemaProps, fieldMeta);
|
|
3084
582
|
});
|
|
3085
|
-
const schema = new
|
|
583
|
+
const schema = new import_mongoose.Schema(schemaProps, (0, import_document.getDefaultSchemaOptions)());
|
|
3086
584
|
schema.methods.refresh = async function() {
|
|
3087
585
|
Object.assign(this, await this.constructor.findById(this._id));
|
|
3088
586
|
return this;
|
|
@@ -3107,36 +605,36 @@ var schemaOf = (modelRef, docRef, middleware) => {
|
|
|
3107
605
|
return schema;
|
|
3108
606
|
};
|
|
3109
607
|
var addSchema = (modelRef, docRef, inputRef, middleware) => {
|
|
3110
|
-
const originDocClassMeta = getClassMeta(docRef);
|
|
3111
|
-
const originInputClassMeta = getClassMeta(inputRef);
|
|
3112
|
-
const originDoc = getFullModelRef(originDocClassMeta.refName);
|
|
3113
|
-
const originInput = getInputModelRef(originInputClassMeta.refName);
|
|
3114
|
-
const classMeta = getClassMeta(docRef);
|
|
608
|
+
const originDocClassMeta = (0, import_constant3.getClassMeta)(docRef);
|
|
609
|
+
const originInputClassMeta = (0, import_constant3.getClassMeta)(inputRef);
|
|
610
|
+
const originDoc = (0, import_constant3.getFullModelRef)(originDocClassMeta.refName);
|
|
611
|
+
const originInput = (0, import_constant3.getInputModelRef)(originInputClassMeta.refName);
|
|
612
|
+
const classMeta = (0, import_constant3.getClassMeta)(docRef);
|
|
3115
613
|
const modelSchema = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
|
|
3116
614
|
if (!modelSchema)
|
|
3117
615
|
throw new Error(`Schema of ${classMeta.refName} not found`);
|
|
3118
|
-
const fieldMetas = getFieldMetas(docRef);
|
|
616
|
+
const fieldMetas = (0, import_constant3.getFieldMetas)(docRef);
|
|
3119
617
|
const schemaProps = {
|
|
3120
618
|
createdAt: {
|
|
3121
619
|
type: Date,
|
|
3122
|
-
get: (date) => date ? dayjs(date) : date,
|
|
3123
|
-
set: (day) => day ? dayjs(day).toDate() : day
|
|
620
|
+
get: (date) => date ? (0, import_base4.dayjs)(date) : date,
|
|
621
|
+
set: (day) => day ? (0, import_base4.dayjs)(day).toDate() : day
|
|
3124
622
|
},
|
|
3125
623
|
updatedAt: {
|
|
3126
624
|
type: Date,
|
|
3127
|
-
get: (date) => date ? dayjs(date) : date,
|
|
3128
|
-
set: (day) => day ? dayjs(day).toDate() : day
|
|
625
|
+
get: (date) => date ? (0, import_base4.dayjs)(date) : date,
|
|
626
|
+
set: (day) => day ? (0, import_base4.dayjs)(day).toDate() : day
|
|
3129
627
|
}
|
|
3130
628
|
};
|
|
3131
629
|
fieldMetas.forEach((fieldMeta) => {
|
|
3132
630
|
applyMongoProp(schemaProps, fieldMeta);
|
|
3133
631
|
applyNestField(originDoc, fieldMeta);
|
|
3134
632
|
});
|
|
3135
|
-
const inputFieldMetas = getFieldMetas(inputRef);
|
|
633
|
+
const inputFieldMetas = (0, import_constant3.getFieldMetas)(inputRef);
|
|
3136
634
|
inputFieldMetas.forEach((fieldMeta) => {
|
|
3137
635
|
applyNestField(originInput, fieldMeta, "input");
|
|
3138
636
|
});
|
|
3139
|
-
const schema = new
|
|
637
|
+
const schema = new import_mongoose.Schema(schemaProps, (0, import_document.getDefaultSchemaOptions)());
|
|
3140
638
|
modelSchema.add(schema);
|
|
3141
639
|
Object.getOwnPropertyNames(docRef.prototype).forEach((name) => {
|
|
3142
640
|
if (name === "constructor")
|
|
@@ -3149,18 +647,22 @@ var addSchema = (modelRef, docRef, inputRef, middleware) => {
|
|
|
3149
647
|
};
|
|
3150
648
|
|
|
3151
649
|
// pkgs/@akanjs/server/src/websocket.ts
|
|
3152
|
-
var
|
|
650
|
+
var import_common8 = require("@akanjs/common");
|
|
651
|
+
var import_nest3 = require("@akanjs/nest");
|
|
652
|
+
var import_service4 = require("@akanjs/service");
|
|
653
|
+
var import_signal5 = require("@akanjs/signal");
|
|
654
|
+
var import_common9 = require("@nestjs/common");
|
|
3153
655
|
var import_websockets = require("@nestjs/websockets");
|
|
3154
|
-
var
|
|
3155
|
-
var internalArgMap3 = { Account:
|
|
656
|
+
var import_operators = require("rxjs/operators");
|
|
657
|
+
var internalArgMap3 = { Account: import_nest3.Account, UserIp: import_nest3.UserIp, Access: import_nest3.Access, Self: import_nest3.Self, Me: import_nest3.Me, Ws: import_nest3.Ws };
|
|
3156
658
|
var TransformInterceptor = class {
|
|
3157
659
|
intercept(context, next) {
|
|
3158
660
|
const [, gqlKey] = [context.getArgByIndex(1), context.getArgByIndex(3)];
|
|
3159
|
-
return next.handle().pipe((0,
|
|
661
|
+
return next.handle().pipe((0, import_operators.map)((data) => ({ event: gqlKey, data })));
|
|
3160
662
|
}
|
|
3161
663
|
};
|
|
3162
664
|
TransformInterceptor = __decorateClass([
|
|
3163
|
-
(0,
|
|
665
|
+
(0, import_common9.Injectable)()
|
|
3164
666
|
], TransformInterceptor);
|
|
3165
667
|
var makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
3166
668
|
var getPubsubInterceptor = (argMetas) => {
|
|
@@ -3175,63 +677,63 @@ var getPubsubInterceptor = (argMetas) => {
|
|
|
3175
677
|
await socket.join(roomId);
|
|
3176
678
|
else
|
|
3177
679
|
await socket.leave(roomId);
|
|
3178
|
-
return next.handle().pipe((0,
|
|
680
|
+
return next.handle().pipe((0, import_operators.map)(() => ({ event: gqlKey, data: { roomId, __subscribe__ } })));
|
|
3179
681
|
}
|
|
3180
682
|
};
|
|
3181
683
|
PubsubInterceptor = __decorateClass([
|
|
3182
|
-
(0,
|
|
684
|
+
(0, import_common9.Injectable)()
|
|
3183
685
|
], PubsubInterceptor);
|
|
3184
686
|
return PubsubInterceptor;
|
|
3185
687
|
};
|
|
3186
688
|
var websocketOf = (sigRef, allSrvs) => {
|
|
3187
|
-
const sigMeta = getSigMeta(sigRef);
|
|
689
|
+
const sigMeta = (0, import_signal5.getSigMeta)(sigRef);
|
|
3188
690
|
class WsGateway {
|
|
3189
691
|
__sigRef__ = sigRef;
|
|
3190
692
|
}
|
|
3191
693
|
Object.keys(allSrvs).forEach((srv) => {
|
|
3192
|
-
if (!isServiceEnabled(allSrvs[srv]))
|
|
694
|
+
if (!(0, import_service4.isServiceEnabled)(allSrvs[srv]))
|
|
3193
695
|
return;
|
|
3194
|
-
(0,
|
|
696
|
+
(0, import_common9.Inject)(allSrvs[srv])(WsGateway.prototype, (0, import_common8.lowerlize)(srv));
|
|
3195
697
|
});
|
|
3196
|
-
const messageGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
|
|
698
|
+
const messageGqlMetas = (0, import_signal5.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
|
|
3197
699
|
for (const gqlMeta of messageGqlMetas) {
|
|
3198
700
|
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
3199
701
|
Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
3200
|
-
const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
702
|
+
const [argMetas, internalArgMetas] = (0, import_signal5.getArgMetas)(sigRef, gqlMeta.key);
|
|
3201
703
|
argMetas.forEach((argMeta) => {
|
|
3202
704
|
if (argMeta.type !== "Msg")
|
|
3203
705
|
throw new Error(`Argument of Message should be Msg ${sigMeta.refName}-${gqlMeta.key}-${argMeta.name}`);
|
|
3204
|
-
(0, import_websockets.MessageBody)(argMeta.name, ...getBodyPipes(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
706
|
+
(0, import_websockets.MessageBody)(argMeta.name, ...(0, import_nest3.getBodyPipes)(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
3205
707
|
});
|
|
3206
708
|
internalArgMetas.forEach((internalArgMeta) => {
|
|
3207
709
|
const internalDecorator = internalArgMap3[internalArgMeta.type];
|
|
3208
710
|
internalDecorator(internalArgMeta.option ?? {})(WsGateway.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
3209
711
|
});
|
|
3210
|
-
(0,
|
|
712
|
+
(0, import_common9.UseInterceptors)(TransformInterceptor)(WsGateway.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
3211
713
|
(0, import_websockets.SubscribeMessage)(gqlMeta.key)(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
3212
714
|
}
|
|
3213
|
-
const pubsubGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
715
|
+
const pubsubGqlMetas = (0, import_signal5.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
3214
716
|
for (const gqlMeta of pubsubGqlMetas) {
|
|
3215
717
|
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
3216
718
|
Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
3217
|
-
const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
719
|
+
const [argMetas, internalArgMetas] = (0, import_signal5.getArgMetas)(sigRef, gqlMeta.key);
|
|
3218
720
|
argMetas.forEach((argMeta) => {
|
|
3219
721
|
if (argMeta.type !== "Room")
|
|
3220
722
|
throw new Error(`Argument of Message should be Room ${sigMeta.refName}-${gqlMeta.key}-${argMeta.name}`);
|
|
3221
|
-
(0, import_websockets.MessageBody)(argMeta.name, ...getBodyPipes(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
723
|
+
(0, import_websockets.MessageBody)(argMeta.name, ...(0, import_nest3.getBodyPipes)(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
3222
724
|
});
|
|
3223
725
|
internalArgMetas.forEach((internalArgMeta) => {
|
|
3224
726
|
const internalDecorator = internalArgMap3[internalArgMeta.type];
|
|
3225
727
|
internalDecorator(internalArgMeta.option ?? {})(WsGateway.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
3226
728
|
});
|
|
3227
|
-
(0,
|
|
729
|
+
(0, import_common9.UseInterceptors)(getPubsubInterceptor(argMetas))(WsGateway.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
3228
730
|
(0, import_websockets.SubscribeMessage)(gqlMeta.key)(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
3229
731
|
}
|
|
3230
732
|
(0, import_websockets.WebSocketGateway)({ cors: { origin: "*" }, transports: ["websocket"] })(WsGateway);
|
|
3231
733
|
return WsGateway;
|
|
3232
734
|
};
|
|
3233
735
|
var websocketServerOf = (sigRef) => {
|
|
3234
|
-
const pubsubGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
736
|
+
const pubsubGqlMetas = (0, import_signal5.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
3235
737
|
let Websocket = class {
|
|
3236
738
|
server;
|
|
3237
739
|
};
|
|
@@ -3239,11 +741,11 @@ var websocketServerOf = (sigRef) => {
|
|
|
3239
741
|
(0, import_websockets.WebSocketServer)()
|
|
3240
742
|
], Websocket.prototype, "server", 2);
|
|
3241
743
|
Websocket = __decorateClass([
|
|
3242
|
-
(0,
|
|
744
|
+
(0, import_common9.Injectable)(),
|
|
3243
745
|
(0, import_websockets.WebSocketGateway)({ cors: { origin: "*" }, transports: ["websocket"] })
|
|
3244
746
|
], Websocket);
|
|
3245
747
|
for (const gqlMeta of pubsubGqlMetas) {
|
|
3246
|
-
const [argMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
748
|
+
const [argMetas] = (0, import_signal5.getArgMetas)(sigRef, gqlMeta.key);
|
|
3247
749
|
Websocket.prototype[gqlMeta.key] = function(...args) {
|
|
3248
750
|
const roomId = makeRoomId(
|
|
3249
751
|
gqlMeta.key,
|
|
@@ -3256,8 +758,8 @@ var websocketServerOf = (sigRef) => {
|
|
|
3256
758
|
};
|
|
3257
759
|
|
|
3258
760
|
// pkgs/@akanjs/server/src/module.ts
|
|
3259
|
-
var hasWebsocket = (signal) => getGqlMetas(signal).some((gqlMeta) => ["Message", "Pubsub"].includes(gqlMeta.type));
|
|
3260
|
-
var hasProcessor = (signal) => getGqlMetas(signal).some((gqlMeta) => gqlMeta.type === "Process");
|
|
761
|
+
var hasWebsocket = (signal) => (0, import_signal6.getGqlMetas)(signal).some((gqlMeta) => ["Message", "Pubsub"].includes(gqlMeta.type));
|
|
762
|
+
var hasProcessor = (signal) => (0, import_signal6.getGqlMetas)(signal).some((gqlMeta) => gqlMeta.type === "Process");
|
|
3261
763
|
var filterSrvs = (srvs) => Object.fromEntries(Object.entries(srvs).filter(([_, srv]) => !!srv));
|
|
3262
764
|
var databaseModuleOf = ({
|
|
3263
765
|
constant,
|
|
@@ -3269,17 +771,17 @@ var databaseModuleOf = ({
|
|
|
3269
771
|
providers = [],
|
|
3270
772
|
extended
|
|
3271
773
|
}, allSrvs) => {
|
|
3272
|
-
if (!isServiceEnabled(service))
|
|
774
|
+
if (!(0, import_service5.isServiceEnabled)(service))
|
|
3273
775
|
return null;
|
|
3274
|
-
const [modelName, className] = [lowerlize(constant.refName), capitalize(constant.refName)];
|
|
3275
|
-
const mongoToken = (0,
|
|
776
|
+
const [modelName, className] = [(0, import_common10.lowerlize)(constant.refName), (0, import_common10.capitalize)(constant.refName)];
|
|
777
|
+
const mongoToken = (0, import_mongoose2.getModelToken)(className);
|
|
3276
778
|
let DatabaseModule = class {
|
|
3277
779
|
};
|
|
3278
780
|
DatabaseModule = __decorateClass([
|
|
3279
|
-
(0,
|
|
3280
|
-
(0,
|
|
781
|
+
(0, import_common11.Global)(),
|
|
782
|
+
(0, import_common11.Module)({
|
|
3281
783
|
imports: [
|
|
3282
|
-
|
|
784
|
+
import_mongoose2.MongooseModule.forFeature([
|
|
3283
785
|
{
|
|
3284
786
|
name: className,
|
|
3285
787
|
schema: extended ? addSchema(database.Model, database.Doc, database.Input, database.Middleware) : schemaOf(database.Model, database.Doc, database.Middleware)
|
|
@@ -3293,19 +795,19 @@ var databaseModuleOf = ({
|
|
|
3293
795
|
] : []
|
|
3294
796
|
],
|
|
3295
797
|
providers: [
|
|
3296
|
-
serviceOf(service),
|
|
798
|
+
(0, import_service5.serviceOf)(service),
|
|
3297
799
|
resolverOf(signal, filterSrvs(allSrvs)),
|
|
3298
800
|
...hasProcessor(signal) ? [
|
|
3299
801
|
processorOf(signal, filterSrvs(allSrvs)),
|
|
3300
802
|
{ provide: `${className}Queue`, useFactory: (queue) => queue, inject: [(0, import_bull2.getQueueToken)(modelName)] }
|
|
3301
803
|
] : [],
|
|
3302
804
|
...hasWebsocket(signal) ? [websocketOf(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: websocketServerOf(signal) }] : [],
|
|
3303
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: capitalize(key), useValue })),
|
|
3304
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
|
|
805
|
+
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common10.capitalize)(key), useValue })),
|
|
806
|
+
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
3305
807
|
{
|
|
3306
808
|
provide: `${modelName}Model`,
|
|
3307
809
|
useFactory: (model, redis, meili) => {
|
|
3308
|
-
return databaseModelOf(database, model, redis, meili);
|
|
810
|
+
return (0, import_document2.databaseModelOf)(database, model, redis, meili);
|
|
3309
811
|
},
|
|
3310
812
|
inject: [mongoToken, "REDIS_CLIENT", "MEILI_CLIENT"]
|
|
3311
813
|
},
|
|
@@ -3318,15 +820,15 @@ var databaseModuleOf = ({
|
|
|
3318
820
|
return DatabaseModule;
|
|
3319
821
|
};
|
|
3320
822
|
var serviceModuleOf = ({ signal, service, uses = {}, useAsyncs = {}, providers = [] }, allSrvs) => {
|
|
3321
|
-
if (!isServiceEnabled(service))
|
|
823
|
+
if (!(0, import_service5.isServiceEnabled)(service))
|
|
3322
824
|
return null;
|
|
3323
|
-
const sigMeta = getSigMeta(signal);
|
|
3324
|
-
const [modelName, className] = [lowerlize(sigMeta.refName), capitalize(sigMeta.refName)];
|
|
825
|
+
const sigMeta = (0, import_signal6.getSigMeta)(signal);
|
|
826
|
+
const [modelName, className] = [(0, import_common10.lowerlize)(sigMeta.refName), (0, import_common10.capitalize)(sigMeta.refName)];
|
|
3325
827
|
let ServiceModule = class {
|
|
3326
828
|
};
|
|
3327
829
|
ServiceModule = __decorateClass([
|
|
3328
|
-
(0,
|
|
3329
|
-
(0,
|
|
830
|
+
(0, import_common11.Global)(),
|
|
831
|
+
(0, import_common11.Module)({
|
|
3330
832
|
imports: [
|
|
3331
833
|
...hasProcessor(signal) ? [
|
|
3332
834
|
import_bull2.BullModule.registerQueue({
|
|
@@ -3336,15 +838,15 @@ var serviceModuleOf = ({ signal, service, uses = {}, useAsyncs = {}, providers =
|
|
|
3336
838
|
] : []
|
|
3337
839
|
],
|
|
3338
840
|
providers: [
|
|
3339
|
-
serviceOf(service),
|
|
841
|
+
(0, import_service5.serviceOf)(service),
|
|
3340
842
|
resolverOf(signal, filterSrvs(allSrvs)),
|
|
3341
843
|
...hasWebsocket(signal) ? [websocketOf(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: websocketServerOf(signal) }] : [],
|
|
3342
844
|
...hasProcessor(signal) ? [
|
|
3343
845
|
processorOf(signal, filterSrvs(allSrvs)),
|
|
3344
846
|
{ provide: `${className}Queue`, useFactory: (queue) => queue, inject: [(0, import_bull2.getQueueToken)(modelName)] }
|
|
3345
847
|
] : [],
|
|
3346
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: capitalize(key), useValue })),
|
|
3347
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
|
|
848
|
+
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common10.capitalize)(key), useValue })),
|
|
849
|
+
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
3348
850
|
...providers
|
|
3349
851
|
],
|
|
3350
852
|
controllers: [controllerOf(signal, filterSrvs(allSrvs))],
|
|
@@ -3359,8 +861,8 @@ var scalarModuleOf = ({ signals, uses = {}, useAsyncs = {}, providers = [], enab
|
|
|
3359
861
|
let ScalarModule = class {
|
|
3360
862
|
};
|
|
3361
863
|
ScalarModule = __decorateClass([
|
|
3362
|
-
(0,
|
|
3363
|
-
(0,
|
|
864
|
+
(0, import_common11.Global)(),
|
|
865
|
+
(0, import_common11.Module)({
|
|
3364
866
|
imports: [],
|
|
3365
867
|
providers: [
|
|
3366
868
|
...signals.map((signal) => resolverOf(signal, filterSrvs(allSrvs))),
|
|
@@ -3368,8 +870,8 @@ var scalarModuleOf = ({ signals, uses = {}, useAsyncs = {}, providers = [], enab
|
|
|
3368
870
|
websocketOf(signal, filterSrvs(allSrvs)),
|
|
3369
871
|
{ provide: "Websocket", useClass: websocketServerOf(signal) }
|
|
3370
872
|
]).flat(),
|
|
3371
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: capitalize(key), useValue })),
|
|
3372
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
|
|
873
|
+
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common10.capitalize)(key), useValue })),
|
|
874
|
+
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
3373
875
|
...providers
|
|
3374
876
|
],
|
|
3375
877
|
controllers: signals.map((signal) => controllerOf(signal, filterSrvs(allSrvs)))
|
|
@@ -3379,24 +881,24 @@ var scalarModuleOf = ({ signals, uses = {}, useAsyncs = {}, providers = [], enab
|
|
|
3379
881
|
};
|
|
3380
882
|
var scalarModulesOf = ({ constants }, allSrvs) => {
|
|
3381
883
|
const signals = constants.filter((modelRef) => {
|
|
3382
|
-
const childRefs = getChildClassRefs(modelRef);
|
|
884
|
+
const childRefs = (0, import_constant4.getChildClassRefs)(modelRef);
|
|
3383
885
|
return childRefs.some((childRef) => {
|
|
3384
|
-
const classMeta = getClassMeta(childRef);
|
|
886
|
+
const classMeta = (0, import_constant4.getClassMeta)(childRef);
|
|
3385
887
|
return ["full", "light"].includes(classMeta.type);
|
|
3386
888
|
});
|
|
3387
889
|
}).map((modelRef) => {
|
|
3388
|
-
let ScalarSignal = class extends LogSignal({}) {
|
|
890
|
+
let ScalarSignal = class extends (0, import_signal6.LogSignal)({}) {
|
|
3389
891
|
};
|
|
3390
892
|
ScalarSignal = __decorateClass([
|
|
3391
|
-
Signal(() => modelRef)
|
|
893
|
+
(0, import_signal6.Signal)(() => modelRef)
|
|
3392
894
|
], ScalarSignal);
|
|
3393
895
|
return ScalarSignal;
|
|
3394
896
|
});
|
|
3395
897
|
let ScalarModule = class {
|
|
3396
898
|
};
|
|
3397
899
|
ScalarModule = __decorateClass([
|
|
3398
|
-
(0,
|
|
3399
|
-
(0,
|
|
900
|
+
(0, import_common11.Global)(),
|
|
901
|
+
(0, import_common11.Module)({
|
|
3400
902
|
imports: [],
|
|
3401
903
|
providers: [...signals.map((signal) => resolverOf(signal, filterSrvs(allSrvs)))]
|
|
3402
904
|
// controllers: signals.map((signal) => controllerOf(signal, filterSrvs(allSrvs))),
|
|
@@ -3410,18 +912,18 @@ var batchModuleOf = ({
|
|
|
3410
912
|
useAsyncs = {},
|
|
3411
913
|
providers = []
|
|
3412
914
|
}) => {
|
|
3413
|
-
if (!isServiceEnabled(service))
|
|
915
|
+
if (!(0, import_service5.isServiceEnabled)(service))
|
|
3414
916
|
return null;
|
|
3415
917
|
let BatchModule = class {
|
|
3416
918
|
};
|
|
3417
919
|
BatchModule = __decorateClass([
|
|
3418
|
-
(0,
|
|
3419
|
-
(0,
|
|
920
|
+
(0, import_common11.Global)(),
|
|
921
|
+
(0, import_common11.Module)({
|
|
3420
922
|
imports: [],
|
|
3421
923
|
providers: [
|
|
3422
|
-
serviceOf(service),
|
|
3423
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: capitalize(key), useValue })),
|
|
3424
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
|
|
924
|
+
(0, import_service5.serviceOf)(service),
|
|
925
|
+
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common10.capitalize)(key), useValue })),
|
|
926
|
+
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
3425
927
|
...providers
|
|
3426
928
|
],
|
|
3427
929
|
exports: [service]
|
|
@@ -3433,21 +935,21 @@ var useGlobals = ({ uses, useAsyncs, injects }) => {
|
|
|
3433
935
|
let GlobalsModule = class {
|
|
3434
936
|
};
|
|
3435
937
|
GlobalsModule = __decorateClass([
|
|
3436
|
-
(0,
|
|
3437
|
-
(0,
|
|
938
|
+
(0, import_common11.Global)(),
|
|
939
|
+
(0, import_common11.Module)({
|
|
3438
940
|
imports: [],
|
|
3439
941
|
providers: [
|
|
3440
942
|
...Object.entries(uses ?? {}).map(([key, useValue]) => ({
|
|
3441
|
-
provide: capitalize(key),
|
|
943
|
+
provide: (0, import_common10.capitalize)(key),
|
|
3442
944
|
useValue
|
|
3443
945
|
})),
|
|
3444
|
-
...Object.entries(useAsyncs ?? {}).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
|
|
3445
|
-
...Object.entries(injects ?? {}).map(([key, inject]) => ({ provide: capitalize(key), useClass: inject }))
|
|
946
|
+
...Object.entries(useAsyncs ?? {}).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
947
|
+
...Object.entries(injects ?? {}).map(([key, inject]) => ({ provide: (0, import_common10.capitalize)(key), useClass: inject }))
|
|
3446
948
|
],
|
|
3447
949
|
exports: [
|
|
3448
|
-
...Object.keys(uses ?? {}).map((key) => capitalize(key)),
|
|
3449
|
-
...Object.keys(useAsyncs ?? {}).map((key) => capitalize(key)),
|
|
3450
|
-
...Object.keys(injects ?? {}).map((key) => capitalize(key))
|
|
950
|
+
...Object.keys(uses ?? {}).map((key) => (0, import_common10.capitalize)(key)),
|
|
951
|
+
...Object.keys(useAsyncs ?? {}).map((key) => (0, import_common10.capitalize)(key)),
|
|
952
|
+
...Object.keys(injects ?? {}).map((key) => (0, import_common10.capitalize)(key))
|
|
3451
953
|
]
|
|
3452
954
|
})
|
|
3453
955
|
], GlobalsModule);
|
|
@@ -3455,13 +957,17 @@ var useGlobals = ({ uses, useAsyncs, injects }) => {
|
|
|
3455
957
|
};
|
|
3456
958
|
|
|
3457
959
|
// pkgs/@akanjs/server/src/boot.ts
|
|
3458
|
-
var
|
|
960
|
+
var import_base5 = require("@akanjs/base");
|
|
961
|
+
var import_common14 = require("@akanjs/common");
|
|
962
|
+
var import_nest4 = require("@akanjs/nest");
|
|
963
|
+
var import_signal7 = require("@akanjs/signal");
|
|
964
|
+
var import_apollo = require("@nestjs/apollo");
|
|
3459
965
|
var import_bull3 = require("@nestjs/bull");
|
|
3460
|
-
var
|
|
3461
|
-
var
|
|
3462
|
-
var
|
|
3463
|
-
var
|
|
3464
|
-
var
|
|
966
|
+
var import_common15 = require("@nestjs/common");
|
|
967
|
+
var import_core = require("@nestjs/core");
|
|
968
|
+
var import_graphql3 = require("@nestjs/graphql");
|
|
969
|
+
var import_mongoose4 = require("@nestjs/mongoose");
|
|
970
|
+
var import_schedule = require("@nestjs/schedule");
|
|
3465
971
|
var import_body_parser = require("body-parser");
|
|
3466
972
|
var import_cookie_parser = __toESM(require("cookie-parser"));
|
|
3467
973
|
var import_dgram = __toESM(require("dgram"));
|
|
@@ -3469,21 +975,24 @@ var import_events = __toESM(require("events"));
|
|
|
3469
975
|
var import_graphql_upload2 = require("graphql-upload");
|
|
3470
976
|
var import_meilisearch = require("meilisearch");
|
|
3471
977
|
var import_path = require("path");
|
|
3472
|
-
var
|
|
978
|
+
var import_redis = require("redis");
|
|
3473
979
|
|
|
3474
980
|
// pkgs/@akanjs/server/src/searchDaemon.ts
|
|
3475
|
-
var
|
|
3476
|
-
var
|
|
3477
|
-
var
|
|
3478
|
-
|
|
981
|
+
var import_common12 = require("@akanjs/common");
|
|
982
|
+
var import_constant5 = require("@akanjs/constant");
|
|
983
|
+
var import_document3 = require("@akanjs/document");
|
|
984
|
+
var import_common13 = require("@nestjs/common");
|
|
985
|
+
var import_mongoose3 = require("@nestjs/mongoose");
|
|
986
|
+
var hasTextField = (modelRef) => {
|
|
987
|
+
const fieldMetas = (0, import_constant5.getFieldMetas)(modelRef);
|
|
3479
988
|
return fieldMetas.some(
|
|
3480
|
-
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select &&
|
|
989
|
+
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
3481
990
|
);
|
|
3482
991
|
};
|
|
3483
992
|
var getTextFieldKeys = (modelRef) => {
|
|
3484
993
|
const allSearchFields = [];
|
|
3485
994
|
const allFilterFields = [];
|
|
3486
|
-
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
995
|
+
const fieldMetaMap = (0, import_constant5.getFieldMetaMap)(modelRef);
|
|
3487
996
|
const fieldMetas = [...fieldMetaMap.values()];
|
|
3488
997
|
const stringTextFields = fieldMetas.filter((fieldMeta) => !!fieldMeta.text).map((fieldMeta) => {
|
|
3489
998
|
if (fieldMeta.text === "filter")
|
|
@@ -3493,7 +1002,7 @@ var getTextFieldKeys = (modelRef) => {
|
|
|
3493
1002
|
return fieldMeta.key;
|
|
3494
1003
|
});
|
|
3495
1004
|
const scalarTextFields = fieldMetas.filter(
|
|
3496
|
-
(fieldMeta) => fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select &&
|
|
1005
|
+
(fieldMeta) => fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
3497
1006
|
).map((fieldMeta) => fieldMeta.key);
|
|
3498
1007
|
const deepFields = scalarTextFields.map((key) => {
|
|
3499
1008
|
const fieldMeta = fieldMetaMap.get(key);
|
|
@@ -3518,7 +1027,7 @@ var getTextFieldKeys = (modelRef) => {
|
|
|
3518
1027
|
};
|
|
3519
1028
|
};
|
|
3520
1029
|
var makeTextFilter = (modelRef) => {
|
|
3521
|
-
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
1030
|
+
const fieldMetaMap = (0, import_constant5.getFieldMetaMap)(modelRef);
|
|
3522
1031
|
const { stringTextFields, scalarTextFields } = getTextFieldKeys(modelRef);
|
|
3523
1032
|
const filterData = (data, assignObj = {}) => {
|
|
3524
1033
|
if (Array.isArray(data))
|
|
@@ -3540,8 +1049,8 @@ var makeTextFilter = (modelRef) => {
|
|
|
3540
1049
|
return filterData;
|
|
3541
1050
|
};
|
|
3542
1051
|
var getSortableAttributes = (refName) => {
|
|
3543
|
-
const cnst = getCnstMeta(refName);
|
|
3544
|
-
const sortMap = getFilterSortMap(cnst.Filter);
|
|
1052
|
+
const cnst = (0, import_constant5.getCnstMeta)(refName);
|
|
1053
|
+
const sortMap = (0, import_constant5.getFilterSortMap)(cnst.Filter);
|
|
3545
1054
|
const sortFields = Object.values(sortMap).filter((val) => typeof val === "object").map((sort) => Object.keys(sort)).flat();
|
|
3546
1055
|
return [...new Set(sortFields)];
|
|
3547
1056
|
};
|
|
@@ -3550,17 +1059,17 @@ var SearchDaemon = class {
|
|
|
3550
1059
|
this.connection = connection;
|
|
3551
1060
|
this.meili = meili;
|
|
3552
1061
|
}
|
|
3553
|
-
logger = new Logger("SearchDaemon");
|
|
1062
|
+
logger = new import_common12.Logger("SearchDaemon");
|
|
3554
1063
|
async onModuleInit() {
|
|
3555
|
-
const databaseModelNames = getAllDatabaseModelNames();
|
|
1064
|
+
const databaseModelNames = (0, import_document3.getAllDatabaseModelNames)();
|
|
3556
1065
|
const indexes = (await this.meili.getIndexes({ limit: 1e3 })).results;
|
|
3557
1066
|
const indexMap = new Map(indexes.map((index) => [index.uid, index]));
|
|
3558
1067
|
const indexCreationNames = [];
|
|
3559
1068
|
const indexUpdateNames = [];
|
|
3560
1069
|
for (const modelName of databaseModelNames) {
|
|
3561
|
-
const indexName = lowerlize(modelName);
|
|
3562
|
-
const modelRef = getFullModelRef(modelName);
|
|
3563
|
-
if (!
|
|
1070
|
+
const indexName = (0, import_common12.lowerlize)(modelName);
|
|
1071
|
+
const modelRef = (0, import_constant5.getFullModelRef)(modelName);
|
|
1072
|
+
if (!hasTextField(modelRef))
|
|
3564
1073
|
continue;
|
|
3565
1074
|
const index = indexMap.get(indexName);
|
|
3566
1075
|
if (!index)
|
|
@@ -3573,10 +1082,10 @@ var SearchDaemon = class {
|
|
|
3573
1082
|
for (const indexName of indexUpdateNames)
|
|
3574
1083
|
await this.meili.updateIndex(indexName, { primaryKey: "id" });
|
|
3575
1084
|
for (const modelName of databaseModelNames) {
|
|
3576
|
-
const indexName = lowerlize(modelName);
|
|
1085
|
+
const indexName = (0, import_common12.lowerlize)(modelName);
|
|
3577
1086
|
const model = this.connection.models[modelName];
|
|
3578
|
-
const modelRef = getFullModelRef(modelName);
|
|
3579
|
-
if (!
|
|
1087
|
+
const modelRef = (0, import_constant5.getFullModelRef)(modelName);
|
|
1088
|
+
if (!hasTextField(modelRef))
|
|
3580
1089
|
continue;
|
|
3581
1090
|
const searchIndex = this.meili.index(indexName);
|
|
3582
1091
|
const { stringTextFields, scalarTextFields, allSearchFields, allFilterFields } = getTextFieldKeys(modelRef);
|
|
@@ -3647,46 +1156,46 @@ var SearchDaemon = class {
|
|
|
3647
1156
|
}
|
|
3648
1157
|
};
|
|
3649
1158
|
SearchDaemon = __decorateClass([
|
|
3650
|
-
(0,
|
|
3651
|
-
__decorateParam(0, (0,
|
|
3652
|
-
__decorateParam(1, (0,
|
|
1159
|
+
(0, import_common13.Injectable)(),
|
|
1160
|
+
__decorateParam(0, (0, import_mongoose3.InjectConnection)()),
|
|
1161
|
+
__decorateParam(1, (0, import_common13.Inject)("MEILI_CLIENT"))
|
|
3653
1162
|
], SearchDaemon);
|
|
3654
1163
|
var SearchDaemonModule = class {
|
|
3655
1164
|
};
|
|
3656
1165
|
SearchDaemonModule = __decorateClass([
|
|
3657
|
-
(0,
|
|
3658
|
-
(0,
|
|
1166
|
+
(0, import_common13.Global)(),
|
|
1167
|
+
(0, import_common13.Module)({
|
|
3659
1168
|
providers: [SearchDaemon]
|
|
3660
1169
|
})
|
|
3661
1170
|
], SearchDaemonModule);
|
|
3662
1171
|
|
|
3663
1172
|
// pkgs/@akanjs/server/src/boot.ts
|
|
3664
1173
|
var createNestApp = async ({ registerModules, serverMode = "federation", env, log = true }) => {
|
|
3665
|
-
const backendLogger = new Logger("Backend");
|
|
1174
|
+
const backendLogger = new import_common14.Logger("Backend");
|
|
3666
1175
|
if (log)
|
|
3667
|
-
backendLogger.rawLog(logo);
|
|
3668
|
-
const jwtSecret = generateJwtSecret(env.appName, env.environment);
|
|
1176
|
+
backendLogger.rawLog(import_base5.logo);
|
|
1177
|
+
const jwtSecret = (0, import_nest4.generateJwtSecret)(env.appName, env.environment);
|
|
3669
1178
|
const [redisUri, mongoUri, meiliUri] = await Promise.all([
|
|
3670
|
-
env.redisUri ?? generateRedisUri({ ...env, ...env.redis?.sshOptions ? { sshOptions: env.redis.sshOptions } : {} }),
|
|
3671
|
-
env.mongoUri ?? generateMongoUri({
|
|
1179
|
+
env.redisUri ?? (0, import_nest4.generateRedisUri)({ ...env, ...env.redis?.sshOptions ? { sshOptions: env.redis.sshOptions } : {} }),
|
|
1180
|
+
env.mongoUri ?? (0, import_nest4.generateMongoUri)({
|
|
3672
1181
|
...env,
|
|
3673
1182
|
...env.mongo.username ? { username: env.mongo.username } : {},
|
|
3674
1183
|
password: env.mongo.password,
|
|
3675
1184
|
...env.mongo.sshOptions ? { sshOptions: env.mongo.sshOptions } : {}
|
|
3676
1185
|
}),
|
|
3677
|
-
env.meiliUri ?? generateMeiliUri(env)
|
|
1186
|
+
env.meiliUri ?? (0, import_nest4.generateMeiliUri)(env)
|
|
3678
1187
|
]);
|
|
3679
1188
|
if (env.operationMode === "local") {
|
|
3680
1189
|
backendLogger.verbose(`connect to redis: ${redisUri}`);
|
|
3681
1190
|
backendLogger.verbose(`connect to mongo: ${mongoUri}`);
|
|
3682
1191
|
backendLogger.verbose(`connect to meili: ${meiliUri}`);
|
|
3683
1192
|
}
|
|
3684
|
-
initMongoDB({ logging: baseEnv.environment !== "main", sendReport: false });
|
|
1193
|
+
(0, import_nest4.initMongoDB)({ logging: import_base5.baseEnv.environment !== "main", sendReport: false });
|
|
3685
1194
|
import_events.default.EventEmitter.defaultMaxListeners = 1e3;
|
|
3686
1195
|
let AuthMiddleWare = class {
|
|
3687
1196
|
use(req, res, next) {
|
|
3688
1197
|
const requestHeader = req;
|
|
3689
|
-
requestHeader.account = verifyToken(
|
|
1198
|
+
requestHeader.account = (0, import_nest4.verifyToken)(
|
|
3690
1199
|
jwtSecret,
|
|
3691
1200
|
requestHeader.headers.authorization ?? (requestHeader.cookies?.jwt ? `Bearer ${requestHeader.cookies.jwt}` : void 0)
|
|
3692
1201
|
);
|
|
@@ -3695,19 +1204,19 @@ var createNestApp = async ({ registerModules, serverMode = "federation", env, lo
|
|
|
3695
1204
|
}
|
|
3696
1205
|
};
|
|
3697
1206
|
AuthMiddleWare = __decorateClass([
|
|
3698
|
-
(0,
|
|
1207
|
+
(0, import_common15.Injectable)()
|
|
3699
1208
|
], AuthMiddleWare);
|
|
3700
|
-
const redisClient = await (0,
|
|
1209
|
+
const redisClient = await (0, import_redis.createClient)({ url: redisUri }).connect();
|
|
3701
1210
|
let SubDatabaseModule = class {
|
|
3702
1211
|
};
|
|
3703
1212
|
SubDatabaseModule = __decorateClass([
|
|
3704
|
-
(0,
|
|
3705
|
-
(0,
|
|
1213
|
+
(0, import_common15.Global)(),
|
|
1214
|
+
(0, import_common15.Module)({
|
|
3706
1215
|
providers: [
|
|
3707
1216
|
{ provide: "REDIS_CLIENT", useValue: redisClient },
|
|
3708
1217
|
{
|
|
3709
1218
|
provide: "MEILI_CLIENT",
|
|
3710
|
-
useFactory: () => new import_meilisearch.MeiliSearch({ host: meiliUri, apiKey: generateMeiliKey(env) })
|
|
1219
|
+
useFactory: () => new import_meilisearch.MeiliSearch({ host: meiliUri, apiKey: (0, import_nest4.generateMeiliKey)(env) })
|
|
3711
1220
|
}
|
|
3712
1221
|
],
|
|
3713
1222
|
exports: ["REDIS_CLIENT", "MEILI_CLIENT"]
|
|
@@ -3715,46 +1224,46 @@ var createNestApp = async ({ registerModules, serverMode = "federation", env, lo
|
|
|
3715
1224
|
], SubDatabaseModule);
|
|
3716
1225
|
let AppModule = class {
|
|
3717
1226
|
configure(consumer) {
|
|
3718
|
-
consumer.apply(AuthMiddleWare).forRoutes({ path: "*", method:
|
|
1227
|
+
consumer.apply(AuthMiddleWare).forRoutes({ path: "*", method: import_common15.RequestMethod.ALL });
|
|
3719
1228
|
}
|
|
3720
1229
|
};
|
|
3721
1230
|
AppModule = __decorateClass([
|
|
3722
|
-
(0,
|
|
1231
|
+
(0, import_common15.Module)({
|
|
3723
1232
|
imports: [
|
|
3724
1233
|
import_bull3.BullModule.forRoot({ redis: redisUri }),
|
|
3725
|
-
|
|
3726
|
-
|
|
1234
|
+
import_schedule.ScheduleModule.forRoot(),
|
|
1235
|
+
import_graphql3.GraphQLModule.forRootAsync({
|
|
3727
1236
|
imports: [],
|
|
3728
1237
|
useFactory: () => ({
|
|
3729
1238
|
useGlobalPrefix: true,
|
|
3730
1239
|
autoSchemaFile: (0, import_path.join)(process.cwd(), "src/schema.gql"),
|
|
3731
1240
|
sortSchema: true,
|
|
3732
|
-
playground: baseEnv.environment !== "main",
|
|
3733
|
-
introspection: baseEnv.environment !== "main",
|
|
1241
|
+
playground: import_base5.baseEnv.environment !== "main",
|
|
1242
|
+
introspection: import_base5.baseEnv.environment !== "main",
|
|
3734
1243
|
uploads: false,
|
|
3735
1244
|
debug: false
|
|
3736
1245
|
}),
|
|
3737
|
-
driver:
|
|
1246
|
+
driver: import_apollo.ApolloDriver
|
|
3738
1247
|
}),
|
|
3739
|
-
|
|
3740
|
-
useFactory: () => ({ uri: mongoUri, autoIndex: baseEnv.environment !== "main" })
|
|
1248
|
+
import_mongoose4.MongooseModule.forRootAsync({
|
|
1249
|
+
useFactory: () => ({ uri: mongoUri, autoIndex: import_base5.baseEnv.environment !== "main" })
|
|
3741
1250
|
}),
|
|
3742
1251
|
SubDatabaseModule,
|
|
3743
1252
|
useGlobals({
|
|
3744
|
-
injects: { SearchClient, DatabaseClient, CacheClient }
|
|
1253
|
+
injects: { SearchClient: import_nest4.SearchClient, DatabaseClient: import_nest4.DatabaseClient, CacheClient: import_nest4.CacheClient }
|
|
3745
1254
|
}),
|
|
3746
|
-
...["batch", "all"].includes(serverMode) && baseEnv.operationMode !== "edge" ? [SearchDaemonModule] : [],
|
|
1255
|
+
...["batch", "all"].includes(serverMode) && import_base5.baseEnv.operationMode !== "edge" ? [SearchDaemonModule] : [],
|
|
3747
1256
|
...registerModules(env).filter((m) => !!m)
|
|
3748
1257
|
],
|
|
3749
1258
|
providers: [DateScalar]
|
|
3750
1259
|
})
|
|
3751
1260
|
], AppModule);
|
|
3752
|
-
const app = await
|
|
3753
|
-
const redisIoAdapter = new RedisIoAdapter(app, { jwtSecret });
|
|
1261
|
+
const app = await import_core.NestFactory.create(AppModule, { logger: backendLogger });
|
|
1262
|
+
const redisIoAdapter = new import_nest4.RedisIoAdapter(app, { jwtSecret });
|
|
3754
1263
|
await redisIoAdapter.connectToRedis(redisUri);
|
|
3755
1264
|
app.enableShutdownHooks();
|
|
3756
1265
|
const udp = import_dgram.default.createSocket("udp4");
|
|
3757
|
-
client.setUdp(udp);
|
|
1266
|
+
import_signal7.client.setUdp(udp);
|
|
3758
1267
|
if (["federation", "all"].includes(serverMode)) {
|
|
3759
1268
|
app.setGlobalPrefix(process.env.GLOBAL_PREFIX ?? "/backend");
|
|
3760
1269
|
app.enableCors({
|
|
@@ -3770,10 +1279,10 @@ var createNestApp = async ({ registerModules, serverMode = "federation", env, lo
|
|
|
3770
1279
|
app.use((0, import_body_parser.urlencoded)({ limit: "100mb", extended: true }));
|
|
3771
1280
|
app.use("/backend/graphql", (0, import_graphql_upload2.graphqlUploadExpress)());
|
|
3772
1281
|
app.use((0, import_cookie_parser.default)());
|
|
3773
|
-
app.useGlobalInterceptors(new LoggingInterceptor());
|
|
3774
|
-
app.useGlobalInterceptors(new TimeoutInterceptor());
|
|
3775
|
-
app.useGlobalInterceptors(new CacheInterceptor(redisClient));
|
|
3776
|
-
app.useGlobalFilters(new AllExceptionsFilter());
|
|
1282
|
+
app.useGlobalInterceptors(new import_nest4.LoggingInterceptor());
|
|
1283
|
+
app.useGlobalInterceptors(new import_nest4.TimeoutInterceptor());
|
|
1284
|
+
app.useGlobalInterceptors(new import_nest4.CacheInterceptor(redisClient));
|
|
1285
|
+
app.useGlobalFilters(new import_nest4.AllExceptionsFilter());
|
|
3777
1286
|
await app.listen(process.env.PORT ?? env.port ?? 8080);
|
|
3778
1287
|
backendLogger.log(`\u{1F680} Server is running on: ${await app.getUrl()}`);
|
|
3779
1288
|
} else {
|
|
@@ -3795,6 +1304,3 @@ var createNestApp = async ({ registerModules, serverMode = "federation", env, lo
|
|
|
3795
1304
|
}
|
|
3796
1305
|
};
|
|
3797
1306
|
};
|
|
3798
|
-
//! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
|
|
3799
|
-
//! 임시 적용 테스트
|
|
3800
|
-
//! 잘되는지 확인 필요
|