@akanjs/document 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 +54 -1517
- package/package.json +2 -30
package/index.js
CHANGED
|
@@ -25,33 +25,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
29
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
30
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
31
|
-
if (decorator = decorators[i])
|
|
32
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
33
|
-
if (kind && result)
|
|
34
|
-
__defProp(target, key, result);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
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
28
|
|
|
56
29
|
// pkgs/@akanjs/document/index.ts
|
|
57
30
|
var document_exports = {};
|
|
@@ -83,584 +56,10 @@ __export(document_exports, {
|
|
|
83
56
|
});
|
|
84
57
|
module.exports = __toCommonJS(document_exports);
|
|
85
58
|
|
|
86
|
-
// pkgs/@akanjs/constant/src/types.ts
|
|
87
|
-
var DEFAULT_PAGE_SIZE = 20;
|
|
88
|
-
|
|
89
|
-
// pkgs/@akanjs/base/src/base.ts
|
|
90
|
-
var version = "0.9.0";
|
|
91
|
-
var logo = `
|
|
92
|
-
_ _ _
|
|
93
|
-
/ \\ | | ____ _ _ __ (_)___
|
|
94
|
-
/ _ \\ | |/ / _' | '_ \\ | / __|
|
|
95
|
-
/ ___ \\| < (_| | | | |_ | \\__ \\
|
|
96
|
-
/_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
|
|
97
|
-
|__/ ver ${version}
|
|
98
|
-
? See more details on docs https://www.akanjs.com/docs
|
|
99
|
-
\u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
|
|
100
|
-
|
|
101
|
-
`;
|
|
102
|
-
|
|
103
|
-
// pkgs/@akanjs/base/src/baseEnv.ts
|
|
104
|
-
var appName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
|
|
105
|
-
var repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
|
|
106
|
-
var serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
|
|
107
|
-
if (appName === "unknown")
|
|
108
|
-
throw new Error("environment variable NEXT_PUBLIC_APP_NAME is required");
|
|
109
|
-
if (repoName === "unknown")
|
|
110
|
-
throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
|
|
111
|
-
if (serveDomain === "unknown")
|
|
112
|
-
throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
|
|
113
|
-
var environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
114
|
-
var operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
|
|
115
|
-
var operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
|
|
116
|
-
var networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
|
|
117
|
-
var tunnelUsername = process.env.SSU_TUNNEL_USERNAME ?? "root";
|
|
118
|
-
var tunnelPassword = process.env.SSU_TUNNEL_PASSWORD ?? repoName;
|
|
119
|
-
var baseEnv = {
|
|
120
|
-
repoName,
|
|
121
|
-
serveDomain,
|
|
122
|
-
appName,
|
|
123
|
-
environment,
|
|
124
|
-
operationType,
|
|
125
|
-
operationMode,
|
|
126
|
-
networkType,
|
|
127
|
-
tunnelUsername,
|
|
128
|
-
tunnelPassword
|
|
129
|
-
};
|
|
130
|
-
var side = typeof window === "undefined" ? "server" : "client";
|
|
131
|
-
var renderMode = process.env.RENDER_ENV ?? "ssr";
|
|
132
|
-
var clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
|
|
133
|
-
var clientPort = parseInt(
|
|
134
|
-
process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
|
|
135
|
-
);
|
|
136
|
-
var clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
|
|
137
|
-
var clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
|
|
138
|
-
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");
|
|
139
|
-
var serverPort = parseInt(
|
|
140
|
-
process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
|
|
141
|
-
);
|
|
142
|
-
var serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
|
|
143
|
-
var serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
|
|
144
|
-
var serverGraphqlUri = `${serverHttpUri}/graphql`;
|
|
145
|
-
var serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
|
|
146
|
-
var serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
|
|
147
|
-
var baseClientEnv = {
|
|
148
|
-
...baseEnv,
|
|
149
|
-
side,
|
|
150
|
-
renderMode,
|
|
151
|
-
websocket: true,
|
|
152
|
-
clientHost,
|
|
153
|
-
clientPort,
|
|
154
|
-
clientHttpProtocol,
|
|
155
|
-
clientHttpUri,
|
|
156
|
-
serverHost,
|
|
157
|
-
serverPort,
|
|
158
|
-
serverHttpProtocol,
|
|
159
|
-
serverHttpUri,
|
|
160
|
-
serverGraphqlUri,
|
|
161
|
-
serverWsProtocol,
|
|
162
|
-
serverWsUri
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// pkgs/@akanjs/base/src/scalar.ts
|
|
166
|
-
var import_dayjs = __toESM(require("dayjs"));
|
|
167
|
-
var dayjs = import_dayjs.default;
|
|
168
|
-
var Int = class {
|
|
169
|
-
__Scalar__;
|
|
170
|
-
};
|
|
171
|
-
var Upload = class {
|
|
172
|
-
__Scalar__;
|
|
173
|
-
filename;
|
|
174
|
-
mimetype;
|
|
175
|
-
encoding;
|
|
176
|
-
createReadStream;
|
|
177
|
-
};
|
|
178
|
-
var Float = class {
|
|
179
|
-
__Scalar__;
|
|
180
|
-
};
|
|
181
|
-
var ID = class {
|
|
182
|
-
__Scalar__;
|
|
183
|
-
};
|
|
184
|
-
var JSON2 = class {
|
|
185
|
-
__Scalar__;
|
|
186
|
-
};
|
|
187
|
-
var getNonArrayModel = (arraiedModel2) => {
|
|
188
|
-
let arrDepth = 0;
|
|
189
|
-
let target = arraiedModel2;
|
|
190
|
-
while (Array.isArray(target)) {
|
|
191
|
-
target = target[0];
|
|
192
|
-
arrDepth++;
|
|
193
|
-
}
|
|
194
|
-
return [target, arrDepth];
|
|
195
|
-
};
|
|
196
|
-
var scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON2, Map]);
|
|
197
|
-
var scalarNameMap = /* @__PURE__ */ new Map([
|
|
198
|
-
[ID, "ID"],
|
|
199
|
-
[Int, "Int"],
|
|
200
|
-
[Float, "Float"],
|
|
201
|
-
[String, "String"],
|
|
202
|
-
[Boolean, "Boolean"],
|
|
203
|
-
[Date, "Date"],
|
|
204
|
-
[Upload, "Upload"],
|
|
205
|
-
[JSON2, "JSON"],
|
|
206
|
-
[Map, "Map"]
|
|
207
|
-
]);
|
|
208
|
-
var scalarArgMap = /* @__PURE__ */ new Map([
|
|
209
|
-
[ID, null],
|
|
210
|
-
[String, ""],
|
|
211
|
-
[Boolean, false],
|
|
212
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
213
|
-
[Int, 0],
|
|
214
|
-
[Float, 0],
|
|
215
|
-
[JSON2, {}],
|
|
216
|
-
[Map, {}]
|
|
217
|
-
]);
|
|
218
|
-
var scalarDefaultMap = /* @__PURE__ */ new Map([
|
|
219
|
-
[ID, null],
|
|
220
|
-
[String, ""],
|
|
221
|
-
[Boolean, false],
|
|
222
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
223
|
-
[Int, 0],
|
|
224
|
-
[Float, 0],
|
|
225
|
-
[JSON2, {}]
|
|
226
|
-
]);
|
|
227
|
-
var isGqlScalar = (modelRef) => scalarSet.has(modelRef);
|
|
228
|
-
var isGqlMap = (modelRef) => modelRef === Map;
|
|
229
|
-
|
|
230
|
-
// pkgs/@akanjs/constant/src/scalar.ts
|
|
231
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
232
|
-
var scalarExampleMap = /* @__PURE__ */ new Map([
|
|
233
|
-
[ID, "1234567890abcdef12345678"],
|
|
234
|
-
[Int, 0],
|
|
235
|
-
[Float, 0],
|
|
236
|
-
[String, "String"],
|
|
237
|
-
[Boolean, true],
|
|
238
|
-
[Date, (/* @__PURE__ */ new Date()).toISOString()],
|
|
239
|
-
[Upload, "FileUpload"],
|
|
240
|
-
[JSON2, {}],
|
|
241
|
-
[Map, {}]
|
|
242
|
-
]);
|
|
243
|
-
var getClassMeta = (modelRef) => {
|
|
244
|
-
const [target] = getNonArrayModel(modelRef);
|
|
245
|
-
const classMeta = Reflect.getMetadata("class", target.prototype);
|
|
246
|
-
if (!classMeta)
|
|
247
|
-
throw new Error(`No ClassMeta for this target ${target.name}`);
|
|
248
|
-
return classMeta;
|
|
249
|
-
};
|
|
250
|
-
var getFieldMetas = (modelRef) => {
|
|
251
|
-
const [target] = getNonArrayModel(modelRef);
|
|
252
|
-
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
253
|
-
const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
|
|
254
|
-
return [...metadataMap.values()].sort((a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0));
|
|
255
|
-
};
|
|
256
|
-
var getFieldMetaMap = (modelRef) => {
|
|
257
|
-
const [target] = getNonArrayModel(modelRef);
|
|
258
|
-
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
259
|
-
return new Map(metadataMap);
|
|
260
|
-
};
|
|
261
|
-
var setFieldMetaMap = (modelRef, metadataMap) => {
|
|
262
|
-
const [target] = getNonArrayModel(modelRef);
|
|
263
|
-
Reflect.defineMetadata("fields", new Map(metadataMap), target.prototype);
|
|
264
|
-
};
|
|
265
|
-
var getFieldMetaMapOnPrototype = (prototype) => {
|
|
266
|
-
const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
|
|
267
|
-
return new Map(metadataMap);
|
|
268
|
-
};
|
|
269
|
-
var setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
270
|
-
Reflect.defineMetadata("fields", new Map(metadataMap), prototype);
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
// pkgs/@akanjs/constant/src/fieldMeta.ts
|
|
274
|
-
var applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
275
|
-
const isArray = arrDepth > 0;
|
|
276
|
-
const isClass = !isGqlScalar(modelRef);
|
|
277
|
-
const isMap = isGqlMap(modelRef);
|
|
278
|
-
const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
|
|
279
|
-
const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
|
|
280
|
-
if (isMap && !option.of)
|
|
281
|
-
throw new Error("Map type must have 'of' option");
|
|
282
|
-
return (prototype, key) => {
|
|
283
|
-
const metadata = {
|
|
284
|
-
nullable: option.nullable ?? false,
|
|
285
|
-
ref: option.ref,
|
|
286
|
-
refPath: option.refPath,
|
|
287
|
-
refType: option.refType,
|
|
288
|
-
default: option.default ?? (isArray ? [] : null),
|
|
289
|
-
type: option.type,
|
|
290
|
-
fieldType: option.fieldType ?? "property",
|
|
291
|
-
immutable: option.immutable ?? false,
|
|
292
|
-
min: option.min,
|
|
293
|
-
max: option.max,
|
|
294
|
-
enum: option.enum,
|
|
295
|
-
select: option.select ?? true,
|
|
296
|
-
minlength: option.minlength,
|
|
297
|
-
maxlength: option.maxlength,
|
|
298
|
-
query: option.query,
|
|
299
|
-
accumulate: option.accumulate,
|
|
300
|
-
example: option.example,
|
|
301
|
-
validate: option.validate,
|
|
302
|
-
key,
|
|
303
|
-
name,
|
|
304
|
-
isClass,
|
|
305
|
-
isScalar: type === "scalar",
|
|
306
|
-
modelRef,
|
|
307
|
-
arrDepth,
|
|
308
|
-
isArray,
|
|
309
|
-
optArrDepth: optionArrDepth,
|
|
310
|
-
isMap,
|
|
311
|
-
of: option.of,
|
|
312
|
-
text: option.text
|
|
313
|
-
};
|
|
314
|
-
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
315
|
-
metadataMap.set(key, metadata);
|
|
316
|
-
setFieldMetaMapOnPrototype(prototype, metadataMap);
|
|
317
|
-
};
|
|
318
|
-
};
|
|
319
|
-
var makeField = (customOption) => (returns, fieldOption) => {
|
|
320
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
321
|
-
if (!fieldOption)
|
|
322
|
-
return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
|
|
323
|
-
const [opt, optArrDepth] = getNonArrayModel(fieldOption);
|
|
324
|
-
return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
|
|
325
|
-
};
|
|
326
|
-
var Field = {
|
|
327
|
-
Prop: makeField({ fieldType: "property" }),
|
|
328
|
-
Hidden: makeField({ fieldType: "hidden", nullable: true }),
|
|
329
|
-
Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
|
|
330
|
-
Resolve: makeField({ fieldType: "resolve" })
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
// pkgs/@akanjs/constant/src/constantDecorator.ts
|
|
334
|
-
var import_reflect_metadata2 = require("reflect-metadata");
|
|
335
|
-
|
|
336
|
-
// pkgs/@akanjs/constant/src/filterMeta.ts
|
|
337
|
-
var getFilterMeta = (filterRef) => {
|
|
338
|
-
const filterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
339
|
-
if (!filterMeta)
|
|
340
|
-
throw new Error("filterMeta is not defined");
|
|
341
|
-
return filterMeta;
|
|
342
|
-
};
|
|
343
|
-
var setFilterMeta = (filterRef, filterMeta) => {
|
|
344
|
-
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
345
|
-
if (existingFilterMeta)
|
|
346
|
-
Object.assign(filterMeta.sort, existingFilterMeta.sort);
|
|
347
|
-
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
348
|
-
};
|
|
349
|
-
var getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
350
|
-
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
351
|
-
return new Map(metadataMap);
|
|
352
|
-
};
|
|
353
|
-
var setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
354
|
-
Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
|
|
355
|
-
};
|
|
356
|
-
var applyFilterKeyMeta = (option) => {
|
|
357
|
-
return (prototype, key, descriptor) => {
|
|
358
|
-
const metadata = { key, ...option, descriptor };
|
|
359
|
-
const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
|
|
360
|
-
metadataMap.set(key, metadata);
|
|
361
|
-
setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
|
|
362
|
-
};
|
|
363
|
-
};
|
|
364
|
-
var makeFilter = (customOption) => (fieldOption) => {
|
|
365
|
-
return applyFilterKeyMeta({ ...customOption, ...fieldOption });
|
|
366
|
-
};
|
|
367
|
-
var getFilterArgMetasOnPrototype = (prototype, key) => {
|
|
368
|
-
const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
|
|
369
|
-
return filterArgMetas;
|
|
370
|
-
};
|
|
371
|
-
var setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
|
|
372
|
-
Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
|
|
373
|
-
};
|
|
374
|
-
var applyFilterArgMeta = (name, returns, argOption) => {
|
|
375
|
-
return (prototype, key, idx) => {
|
|
376
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
377
|
-
const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
|
|
378
|
-
const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
|
|
379
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
|
|
380
|
-
filterArgMetas[idx] = filterArgMeta;
|
|
381
|
-
setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
|
|
382
|
-
};
|
|
383
|
-
};
|
|
384
|
-
var getFilterQuery = (filterRef, key) => {
|
|
385
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(filterRef.prototype);
|
|
386
|
-
const filterKeyMeta = filterKeyMetaMap.get(key);
|
|
387
|
-
if (!filterKeyMeta?.descriptor.value)
|
|
388
|
-
throw new Error(`filterKeyMeta is not defined for key: ${key}`);
|
|
389
|
-
return filterKeyMeta.descriptor.value;
|
|
390
|
-
};
|
|
391
|
-
var getFilterSort = (filterRef, key) => {
|
|
392
|
-
const filterMeta = getFilterMeta(filterRef);
|
|
393
|
-
const sort = filterMeta.sort[key];
|
|
394
|
-
return sort;
|
|
395
|
-
};
|
|
396
|
-
var Filter = {
|
|
397
|
-
Mongo: makeFilter({ type: "mongo" }),
|
|
398
|
-
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
399
|
-
Arg: applyFilterArgMeta
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
// pkgs/@akanjs/constant/src/baseGql.ts
|
|
403
|
-
var import_reflect_metadata3 = require("reflect-metadata");
|
|
404
|
-
|
|
405
|
-
// pkgs/@akanjs/common/src/isDayjs.ts
|
|
406
|
-
var import_dayjs2 = require("dayjs");
|
|
407
|
-
|
|
408
|
-
// pkgs/@akanjs/common/src/isQueryEqual.ts
|
|
409
|
-
var import_dayjs3 = __toESM(require("dayjs"));
|
|
410
|
-
|
|
411
|
-
// pkgs/@akanjs/common/src/isValidDate.ts
|
|
412
|
-
var import_dayjs4 = __toESM(require("dayjs"));
|
|
413
|
-
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
414
|
-
import_dayjs4.default.extend(import_customParseFormat.default);
|
|
415
|
-
var isValidDate = (d) => {
|
|
416
|
-
const format = "YYYY-MM-DD";
|
|
417
|
-
if (typeof d === "string") {
|
|
418
|
-
return (0, import_dayjs4.default)(d, format).isValid();
|
|
419
|
-
} else if ((0, import_dayjs2.isDayjs)(d))
|
|
420
|
-
return d.isValid();
|
|
421
|
-
else
|
|
422
|
-
return d instanceof Date && !isNaN(d.getTime());
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
// pkgs/@akanjs/common/src/pluralize.ts
|
|
426
|
-
var import_pluralize = __toESM(require("pluralize"));
|
|
427
|
-
|
|
428
|
-
// pkgs/@akanjs/common/src/capitalize.ts
|
|
429
|
-
var capitalize = (str) => {
|
|
430
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
// pkgs/@akanjs/common/src/Logger.ts
|
|
434
|
-
var import_dayjs5 = __toESM(require("dayjs"));
|
|
435
|
-
var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
436
|
-
var clc = {
|
|
437
|
-
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
438
|
-
green: (text) => `\x1B[32m${text}\x1B[39m`,
|
|
439
|
-
yellow: (text) => `\x1B[33m${text}\x1B[39m`,
|
|
440
|
-
red: (text) => `\x1B[31m${text}\x1B[39m`,
|
|
441
|
-
magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
|
|
442
|
-
cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
|
|
443
|
-
};
|
|
444
|
-
var colorizeMap = {
|
|
445
|
-
trace: clc.bold,
|
|
446
|
-
verbose: clc.cyanBright,
|
|
447
|
-
debug: clc.magentaBright,
|
|
448
|
-
log: clc.green,
|
|
449
|
-
info: clc.green,
|
|
450
|
-
warn: clc.yellow,
|
|
451
|
-
error: clc.red
|
|
452
|
-
};
|
|
453
|
-
var Logger = class _Logger {
|
|
454
|
-
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
455
|
-
"InstanceLoader",
|
|
456
|
-
"RoutesResolver",
|
|
457
|
-
"RouterExplorer",
|
|
458
|
-
"NestFactory",
|
|
459
|
-
"WebSocketsController",
|
|
460
|
-
"GraphQLModule",
|
|
461
|
-
"NestApplication"
|
|
462
|
-
]);
|
|
463
|
-
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
464
|
-
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
465
|
-
static #startAt = (0, import_dayjs5.default)();
|
|
466
|
-
static setLevel(level) {
|
|
467
|
-
this.level = level;
|
|
468
|
-
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
469
|
-
}
|
|
470
|
-
name;
|
|
471
|
-
constructor(name) {
|
|
472
|
-
this.name = name;
|
|
473
|
-
}
|
|
474
|
-
trace(msg, context = "") {
|
|
475
|
-
if (_Logger.#levelIdx <= 0)
|
|
476
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
477
|
-
}
|
|
478
|
-
verbose(msg, context = "") {
|
|
479
|
-
if (_Logger.#levelIdx <= 1)
|
|
480
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
481
|
-
}
|
|
482
|
-
debug(msg, context = "") {
|
|
483
|
-
if (_Logger.#levelIdx <= 2)
|
|
484
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
485
|
-
}
|
|
486
|
-
log(msg, context = "") {
|
|
487
|
-
if (_Logger.#levelIdx <= 3)
|
|
488
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
489
|
-
}
|
|
490
|
-
info(msg, context = "") {
|
|
491
|
-
if (_Logger.#levelIdx <= 4)
|
|
492
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
493
|
-
}
|
|
494
|
-
warn(msg, context = "") {
|
|
495
|
-
if (_Logger.#levelIdx <= 5)
|
|
496
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
497
|
-
}
|
|
498
|
-
error(msg, context = "") {
|
|
499
|
-
if (_Logger.#levelIdx <= 6)
|
|
500
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
501
|
-
}
|
|
502
|
-
raw(msg, method) {
|
|
503
|
-
_Logger.rawLog(msg, method);
|
|
504
|
-
}
|
|
505
|
-
rawLog(msg, method) {
|
|
506
|
-
_Logger.rawLog(msg, method);
|
|
507
|
-
}
|
|
508
|
-
static trace(msg, context = "") {
|
|
509
|
-
if (_Logger.#levelIdx <= 0)
|
|
510
|
-
_Logger.#printMessages("App", msg, context, "trace");
|
|
511
|
-
}
|
|
512
|
-
static verbose(msg, context = "") {
|
|
513
|
-
if (_Logger.#levelIdx <= 1)
|
|
514
|
-
_Logger.#printMessages("App", msg, context, "verbose");
|
|
515
|
-
}
|
|
516
|
-
static debug(msg, context = "") {
|
|
517
|
-
if (_Logger.#levelIdx <= 2)
|
|
518
|
-
_Logger.#printMessages("App", msg, context, "debug");
|
|
519
|
-
}
|
|
520
|
-
static log(msg, context = "") {
|
|
521
|
-
if (_Logger.#levelIdx <= 3)
|
|
522
|
-
_Logger.#printMessages("App", msg, context, "log");
|
|
523
|
-
}
|
|
524
|
-
static info(msg, context = "") {
|
|
525
|
-
if (_Logger.#levelIdx <= 4)
|
|
526
|
-
_Logger.#printMessages("App", msg, context, "info");
|
|
527
|
-
}
|
|
528
|
-
static warn(msg, context = "") {
|
|
529
|
-
if (_Logger.#levelIdx <= 5)
|
|
530
|
-
_Logger.#printMessages("App", msg, context, "warn");
|
|
531
|
-
}
|
|
532
|
-
static error(msg, context = "") {
|
|
533
|
-
if (_Logger.#levelIdx <= 6)
|
|
534
|
-
_Logger.#printMessages("App", msg, context, "error");
|
|
535
|
-
}
|
|
536
|
-
static #colorize(msg, logLevel) {
|
|
537
|
-
return colorizeMap[logLevel](msg);
|
|
538
|
-
}
|
|
539
|
-
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
540
|
-
if (this.#ignoreCtxSet.has(context))
|
|
541
|
-
return;
|
|
542
|
-
const now = (0, import_dayjs5.default)();
|
|
543
|
-
const processMsg = this.#colorize(
|
|
544
|
-
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
545
|
-
logLevel
|
|
546
|
-
);
|
|
547
|
-
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
548
|
-
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
549
|
-
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
550
|
-
const contentMsg = this.#colorize(content, logLevel);
|
|
551
|
-
const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
|
|
552
|
-
if (typeof window === "undefined")
|
|
553
|
-
process[writeStreamType].write(
|
|
554
|
-
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
555
|
-
`
|
|
556
|
-
);
|
|
557
|
-
else
|
|
558
|
-
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
559
|
-
`);
|
|
560
|
-
}
|
|
561
|
-
static rawLog(msg, method) {
|
|
562
|
-
this.raw(`${msg}
|
|
563
|
-
`, method);
|
|
564
|
-
}
|
|
565
|
-
static raw(msg, method) {
|
|
566
|
-
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
567
|
-
global.process.stdout.write(msg);
|
|
568
|
-
else
|
|
569
|
-
console.log(msg);
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
// pkgs/@akanjs/common/src/lowerlize.ts
|
|
574
|
-
var lowerlize = (str) => {
|
|
575
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
// pkgs/@akanjs/common/src/sleep.ts
|
|
579
|
-
var sleep = async (ms) => {
|
|
580
|
-
return new Promise((resolve) => {
|
|
581
|
-
setTimeout(() => {
|
|
582
|
-
resolve(true);
|
|
583
|
-
}, ms);
|
|
584
|
-
});
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
// pkgs/@akanjs/constant/src/baseGql.ts
|
|
588
|
-
var defaultFieldMeta = {
|
|
589
|
-
fieldType: "property",
|
|
590
|
-
immutable: false,
|
|
591
|
-
select: true,
|
|
592
|
-
isClass: false,
|
|
593
|
-
isScalar: true,
|
|
594
|
-
nullable: false,
|
|
595
|
-
isArray: false,
|
|
596
|
-
arrDepth: 0,
|
|
597
|
-
optArrDepth: 0,
|
|
598
|
-
default: null,
|
|
599
|
-
isMap: false
|
|
600
|
-
};
|
|
601
|
-
var idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
|
|
602
|
-
var createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
|
|
603
|
-
var updatedAtFieldMeta = { ...defaultFieldMeta, key: "updatedAt", name: "Date", modelRef: Date };
|
|
604
|
-
var removedAtFieldMeta = {
|
|
605
|
-
...defaultFieldMeta,
|
|
606
|
-
key: "removedAt",
|
|
607
|
-
name: "Date",
|
|
608
|
-
modelRef: Date,
|
|
609
|
-
nullable: true,
|
|
610
|
-
default: null
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
// pkgs/@akanjs/constant/src/classMeta.ts
|
|
614
|
-
var import_reflect_metadata4 = require("reflect-metadata");
|
|
615
|
-
var InputModelStorage = class {
|
|
616
|
-
};
|
|
617
|
-
var LightModelStorage = class {
|
|
618
|
-
};
|
|
619
|
-
var FullModelStorage = class {
|
|
620
|
-
};
|
|
621
|
-
var ScalarModelStorage = class {
|
|
622
|
-
};
|
|
623
|
-
var FilterModelStorage = class {
|
|
624
|
-
};
|
|
625
|
-
var hasTextField = (modelRef) => {
|
|
626
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
627
|
-
return fieldMetas.some(
|
|
628
|
-
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
629
|
-
);
|
|
630
|
-
};
|
|
631
|
-
var applyClassMeta = (type, modelType, storage) => {
|
|
632
|
-
return function(refName) {
|
|
633
|
-
return function(target) {
|
|
634
|
-
const modelRef = target;
|
|
635
|
-
const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
|
|
636
|
-
Reflect.defineMetadata("class", classMeta, modelRef.prototype);
|
|
637
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
638
|
-
};
|
|
639
|
-
};
|
|
640
|
-
};
|
|
641
|
-
var applyFilterMeta = (storage) => {
|
|
642
|
-
return function(refName) {
|
|
643
|
-
return function(target) {
|
|
644
|
-
const modelRef = target;
|
|
645
|
-
setFilterMeta(modelRef, { refName, sort: {} });
|
|
646
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
647
|
-
};
|
|
648
|
-
};
|
|
649
|
-
};
|
|
650
|
-
var Model = {
|
|
651
|
-
Light: applyClassMeta("light", "data", LightModelStorage),
|
|
652
|
-
Object: applyClassMeta("full", "ephemeral", FullModelStorage),
|
|
653
|
-
Full: applyClassMeta("full", "data", FullModelStorage),
|
|
654
|
-
Input: applyClassMeta("input", "data", InputModelStorage),
|
|
655
|
-
Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
|
|
656
|
-
Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
|
|
657
|
-
Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
|
|
658
|
-
Filter: applyFilterMeta(FilterModelStorage)
|
|
659
|
-
};
|
|
660
|
-
|
|
661
59
|
// pkgs/@akanjs/document/src/dbDecorators.ts
|
|
662
|
-
var
|
|
663
|
-
|
|
60
|
+
var import_constant = require("@akanjs/constant");
|
|
61
|
+
var dbOf = (refName, Input, Doc, Model2, Middleware, Obj, Insight, Filter, Summary) => {
|
|
62
|
+
return { refName, Input, Doc, Model: Model2, Middleware, Obj, Insight, Filter, Summary };
|
|
664
63
|
};
|
|
665
64
|
var InputDatabaseStorage = class {
|
|
666
65
|
};
|
|
@@ -678,38 +77,38 @@ var Database = {
|
|
|
678
77
|
Input: (returns) => {
|
|
679
78
|
return function(target) {
|
|
680
79
|
const modelRef = returns();
|
|
681
|
-
const classMeta = getClassMeta(modelRef);
|
|
80
|
+
const classMeta = (0, import_constant.getClassMeta)(modelRef);
|
|
682
81
|
Reflect.defineMetadata(classMeta.refName, target, InputDatabaseStorage.prototype);
|
|
683
82
|
};
|
|
684
83
|
},
|
|
685
84
|
Document: (returns) => {
|
|
686
85
|
return function(target) {
|
|
687
86
|
const modelRef = returns();
|
|
688
|
-
const classMeta = getClassMeta(modelRef);
|
|
87
|
+
const classMeta = (0, import_constant.getClassMeta)(modelRef);
|
|
689
88
|
Reflect.defineMetadata(classMeta.refName, target, DocumentDatabaseStorage.prototype);
|
|
690
89
|
};
|
|
691
90
|
},
|
|
692
91
|
Model: (returns) => {
|
|
693
92
|
return function(target) {
|
|
694
93
|
const modelRef = returns();
|
|
695
|
-
const classMeta = getClassMeta(modelRef);
|
|
94
|
+
const classMeta = (0, import_constant.getClassMeta)(modelRef);
|
|
696
95
|
Reflect.defineMetadata(classMeta.refName, target, ModelDatabaseStorage.prototype);
|
|
697
96
|
};
|
|
698
97
|
},
|
|
699
98
|
Middleware: (returns) => {
|
|
700
99
|
return function(target) {
|
|
701
100
|
const modelRef = returns();
|
|
702
|
-
const classMeta = getClassMeta(modelRef);
|
|
101
|
+
const classMeta = (0, import_constant.getClassMeta)(modelRef);
|
|
703
102
|
Reflect.defineMetadata(classMeta.refName, target, MiddlewareDatabaseStorage.prototype);
|
|
704
103
|
};
|
|
705
104
|
}
|
|
706
105
|
};
|
|
707
|
-
var
|
|
106
|
+
var Model = (docRef, cnst) => {
|
|
708
107
|
class DefaultModel {
|
|
709
108
|
}
|
|
710
109
|
return DefaultModel;
|
|
711
110
|
};
|
|
712
|
-
var into =
|
|
111
|
+
var into = Model;
|
|
713
112
|
var AddModel = (modelRef, cnst) => {
|
|
714
113
|
return modelRef;
|
|
715
114
|
};
|
|
@@ -723,9 +122,9 @@ var InputOrDocument = (inputRef) => {
|
|
|
723
122
|
return inputRef;
|
|
724
123
|
};
|
|
725
124
|
var AddInputOrDocument = (modelRef, addRef) => {
|
|
726
|
-
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
727
|
-
const addFieldMetas = getFieldMetaMap(addRef);
|
|
728
|
-
setFieldMetaMap(modelRef, new Map([...fieldMetaMap, ...addFieldMetas]));
|
|
125
|
+
const fieldMetaMap = (0, import_constant.getFieldMetaMap)(modelRef);
|
|
126
|
+
const addFieldMetas = (0, import_constant.getFieldMetaMap)(addRef);
|
|
127
|
+
(0, import_constant.setFieldMetaMap)(modelRef, new Map([...fieldMetaMap, ...addFieldMetas]));
|
|
729
128
|
return modelRef;
|
|
730
129
|
};
|
|
731
130
|
var beyond = (model, doc) => {
|
|
@@ -736,6 +135,8 @@ var beyond = (model, doc) => {
|
|
|
736
135
|
};
|
|
737
136
|
|
|
738
137
|
// pkgs/@akanjs/document/src/schema.ts
|
|
138
|
+
var import_base = require("@akanjs/base");
|
|
139
|
+
var import_common = require("@akanjs/common");
|
|
739
140
|
var import_mongoose = require("mongoose");
|
|
740
141
|
var getDefaultSchemaOptions = () => ({
|
|
741
142
|
toJSON: { getters: false, virtuals: true },
|
|
@@ -816,8 +217,8 @@ var convertOperatorValue = (value) => {
|
|
|
816
217
|
return value;
|
|
817
218
|
else if ((0, import_mongoose.isValidObjectId)(value))
|
|
818
219
|
return new import_mongoose.Types.ObjectId(value);
|
|
819
|
-
else if (isValidDate(value))
|
|
820
|
-
return dayjs(value).toDate();
|
|
220
|
+
else if ((0, import_common.isValidDate)(value))
|
|
221
|
+
return (0, import_base.dayjs)(value).toDate();
|
|
821
222
|
else if (value.constructor !== Object)
|
|
822
223
|
return value;
|
|
823
224
|
else if (typeof value !== "object")
|
|
@@ -835,882 +236,19 @@ var convertAggregateMatch = (query) => {
|
|
|
835
236
|
);
|
|
836
237
|
};
|
|
837
238
|
|
|
838
|
-
// pkgs/@akanjs/
|
|
839
|
-
var
|
|
840
|
-
var
|
|
841
|
-
var
|
|
842
|
-
|
|
843
|
-
roomSubscribeMap = /* @__PURE__ */ new Map();
|
|
844
|
-
constructor(uri) {
|
|
845
|
-
this.socket = (0, import_socket.io)(uri, { transports: ["websocket"] });
|
|
846
|
-
this.socket.on("connect", () => {
|
|
847
|
-
this.roomSubscribeMap.forEach((option) => {
|
|
848
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
849
|
-
});
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
on(event, callback) {
|
|
853
|
-
this.socket.on(event, callback);
|
|
854
|
-
}
|
|
855
|
-
removeListener(event, callback) {
|
|
856
|
-
this.socket.removeListener(event, callback);
|
|
857
|
-
}
|
|
858
|
-
removeAllListeners() {
|
|
859
|
-
this.socket.removeAllListeners();
|
|
860
|
-
}
|
|
861
|
-
hasListeners(event) {
|
|
862
|
-
return this.socket.hasListeners(event);
|
|
863
|
-
}
|
|
864
|
-
emit(key, data) {
|
|
865
|
-
this.socket.emit(key, data);
|
|
866
|
-
}
|
|
867
|
-
subscribe(option) {
|
|
868
|
-
if (!this.roomSubscribeMap.has(option.roomId)) {
|
|
869
|
-
this.roomSubscribeMap.set(option.roomId, option);
|
|
870
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
871
|
-
}
|
|
872
|
-
this.socket.on(option.roomId, option.handleEvent);
|
|
873
|
-
}
|
|
874
|
-
unsubscribe(roomId, handleEvent) {
|
|
875
|
-
this.socket.removeListener(roomId, handleEvent);
|
|
876
|
-
const option = this.roomSubscribeMap.get(roomId);
|
|
877
|
-
if (this.hasListeners(roomId) || !option)
|
|
878
|
-
return;
|
|
879
|
-
this.roomSubscribeMap.delete(roomId);
|
|
880
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: false });
|
|
881
|
-
}
|
|
882
|
-
disconnect() {
|
|
883
|
-
this.socket.disconnect();
|
|
884
|
-
return this;
|
|
885
|
-
}
|
|
886
|
-
};
|
|
887
|
-
var Client = class _Client {
|
|
888
|
-
static globalIoMap = /* @__PURE__ */ new Map();
|
|
889
|
-
static tokenStore = /* @__PURE__ */ new Map();
|
|
890
|
-
async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
|
|
891
|
-
if (baseClientEnv.side === "server")
|
|
892
|
-
return true;
|
|
893
|
-
while (!this.getIo(ws).socket.connected) {
|
|
894
|
-
Logger.verbose("waiting for websocket to initialize...");
|
|
895
|
-
await sleep(300);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
isInitialized = false;
|
|
899
|
-
uri = baseClientEnv.serverGraphqlUri;
|
|
900
|
-
ws = baseClientEnv.serverWsUri;
|
|
901
|
-
udp = null;
|
|
902
|
-
gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
|
|
903
|
-
jwt = null;
|
|
904
|
-
async getJwt() {
|
|
905
|
-
const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
|
|
906
|
-
if (isNextServer) {
|
|
907
|
-
const nextHeaders = require("next/headers");
|
|
908
|
-
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
909
|
-
} else
|
|
910
|
-
return _Client.tokenStore.get(this) ?? null;
|
|
911
|
-
}
|
|
912
|
-
io = null;
|
|
913
|
-
init(data = {}) {
|
|
914
|
-
Object.assign(this, data);
|
|
915
|
-
this.setLink(data.uri);
|
|
916
|
-
this.setIo(data.ws);
|
|
917
|
-
this.isInitialized = true;
|
|
918
|
-
}
|
|
919
|
-
setIo(ws = baseClientEnv.serverWsUri) {
|
|
920
|
-
this.ws = ws;
|
|
921
|
-
const existingIo = _Client.globalIoMap.get(ws);
|
|
922
|
-
if (existingIo) {
|
|
923
|
-
this.io = existingIo;
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
this.io = new SocketIo(ws);
|
|
927
|
-
_Client.globalIoMap.set(ws, this.io);
|
|
928
|
-
}
|
|
929
|
-
getIo(ws = baseClientEnv.serverWsUri) {
|
|
930
|
-
const existingIo = _Client.globalIoMap.get(ws);
|
|
931
|
-
if (existingIo)
|
|
932
|
-
return existingIo;
|
|
933
|
-
const io2 = new SocketIo(ws);
|
|
934
|
-
_Client.globalIoMap.set(ws, io2);
|
|
935
|
-
return io2;
|
|
936
|
-
}
|
|
937
|
-
setLink(uri = baseClientEnv.serverGraphqlUri) {
|
|
938
|
-
this.uri = uri;
|
|
939
|
-
this.gql = (0, import_core.createClient)({
|
|
940
|
-
url: this.uri,
|
|
941
|
-
fetch,
|
|
942
|
-
exchanges: [import_core.cacheExchange, import_core.fetchExchange],
|
|
943
|
-
// requestPolicy: "network-only",
|
|
944
|
-
fetchOptions: () => {
|
|
945
|
-
return {
|
|
946
|
-
headers: {
|
|
947
|
-
"apollo-require-preflight": "true",
|
|
948
|
-
...this.jwt ? { authorization: `Bearer ${this.jwt}` } : {}
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
setJwt(jwt3) {
|
|
955
|
-
_Client.tokenStore.set(this, jwt3);
|
|
956
|
-
}
|
|
957
|
-
reset() {
|
|
958
|
-
this.io?.disconnect();
|
|
959
|
-
this.io = null;
|
|
960
|
-
this.jwt = null;
|
|
961
|
-
}
|
|
962
|
-
clone(data = {}) {
|
|
963
|
-
const newClient = new _Client();
|
|
964
|
-
newClient.init({ ...this, ...data });
|
|
965
|
-
if (data.jwt)
|
|
966
|
-
_Client.tokenStore.set(newClient, data.jwt);
|
|
967
|
-
return newClient;
|
|
968
|
-
}
|
|
969
|
-
terminate() {
|
|
970
|
-
this.reset();
|
|
971
|
-
_Client.globalIoMap.forEach((io2) => io2.disconnect());
|
|
972
|
-
this.isInitialized = false;
|
|
973
|
-
}
|
|
974
|
-
setUdp(udp) {
|
|
975
|
-
this.udp = udp;
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
var client = new Client();
|
|
979
|
-
|
|
980
|
-
// pkgs/@akanjs/signal/src/immerify.ts
|
|
981
|
-
var import_immer = require("immer");
|
|
982
|
-
|
|
983
|
-
// pkgs/@akanjs/signal/src/signalDecorators.ts
|
|
984
|
-
var import_reflect_metadata5 = require("reflect-metadata");
|
|
985
|
-
var createArgMetaDecorator = (type) => {
|
|
986
|
-
return function(option = {}) {
|
|
987
|
-
return function(prototype, key, idx) {
|
|
988
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
989
|
-
argMetas[idx] = { key, idx, type, option };
|
|
990
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
991
|
-
};
|
|
992
|
-
};
|
|
993
|
-
};
|
|
994
|
-
var Account = createArgMetaDecorator("Account");
|
|
995
|
-
var defaultAccount = {
|
|
996
|
-
__InternalArg__: "Account",
|
|
997
|
-
appName: baseEnv.appName,
|
|
998
|
-
environment: baseEnv.environment
|
|
999
|
-
};
|
|
1000
|
-
var Self = createArgMetaDecorator("Self");
|
|
1001
|
-
var Me = createArgMetaDecorator("Me");
|
|
1002
|
-
var UserIp = createArgMetaDecorator("UserIp");
|
|
1003
|
-
var Access = createArgMetaDecorator("Access");
|
|
1004
|
-
var Req = createArgMetaDecorator("Req");
|
|
1005
|
-
var Res = createArgMetaDecorator("Res");
|
|
1006
|
-
var Ws = createArgMetaDecorator("Ws");
|
|
1007
|
-
var Job = createArgMetaDecorator("Job");
|
|
1008
|
-
var getQuery = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
1009
|
-
return (prototype, key, descriptor) => {
|
|
1010
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1011
|
-
metadataMap.set(key, {
|
|
1012
|
-
returns,
|
|
1013
|
-
signalOption,
|
|
1014
|
-
key,
|
|
1015
|
-
descriptor,
|
|
1016
|
-
guards: [allow2, ...guards],
|
|
1017
|
-
type: "Query"
|
|
1018
|
-
});
|
|
1019
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1020
|
-
};
|
|
1021
|
-
};
|
|
1022
|
-
var getMutation = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
1023
|
-
return (prototype, key, descriptor) => {
|
|
1024
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1025
|
-
metadataMap.set(key, {
|
|
1026
|
-
returns,
|
|
1027
|
-
signalOption,
|
|
1028
|
-
key,
|
|
1029
|
-
descriptor,
|
|
1030
|
-
guards: [allow2, ...guards],
|
|
1031
|
-
type: "Mutation"
|
|
1032
|
-
});
|
|
1033
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1034
|
-
};
|
|
1035
|
-
};
|
|
1036
|
-
var getMessage = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
1037
|
-
return (prototype, key, descriptor) => {
|
|
1038
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1039
|
-
metadataMap.set(key, {
|
|
1040
|
-
returns,
|
|
1041
|
-
signalOption,
|
|
1042
|
-
key,
|
|
1043
|
-
descriptor,
|
|
1044
|
-
guards: [allow2, ...guards],
|
|
1045
|
-
type: "Message"
|
|
1046
|
-
});
|
|
1047
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1048
|
-
};
|
|
1049
|
-
};
|
|
1050
|
-
var getPubsub = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
1051
|
-
return (prototype, key, descriptor) => {
|
|
1052
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1053
|
-
metadataMap.set(key, {
|
|
1054
|
-
returns,
|
|
1055
|
-
signalOption,
|
|
1056
|
-
key,
|
|
1057
|
-
descriptor,
|
|
1058
|
-
guards: [allow2, ...guards],
|
|
1059
|
-
type: "Pubsub"
|
|
1060
|
-
});
|
|
1061
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1062
|
-
};
|
|
1063
|
-
};
|
|
1064
|
-
var getProcess = (serverType) => function(returns, signalOption = {}) {
|
|
1065
|
-
return (prototype, key, descriptor) => {
|
|
1066
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1067
|
-
metadataMap.set(key, {
|
|
1068
|
-
returns,
|
|
1069
|
-
signalOption: { ...signalOption, serverType: lowerlize(serverType) },
|
|
1070
|
-
key,
|
|
1071
|
-
descriptor,
|
|
1072
|
-
guards: ["None"],
|
|
1073
|
-
type: "Process"
|
|
1074
|
-
});
|
|
1075
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1076
|
-
};
|
|
1077
|
-
};
|
|
1078
|
-
var Query = {
|
|
1079
|
-
Public: getQuery("Public"),
|
|
1080
|
-
Every: getQuery("Every"),
|
|
1081
|
-
Admin: getQuery("Admin"),
|
|
1082
|
-
User: getQuery("User"),
|
|
1083
|
-
SuperAdmin: getQuery("SuperAdmin"),
|
|
1084
|
-
None: getQuery("None"),
|
|
1085
|
-
Owner: getQuery("Owner")
|
|
1086
|
-
};
|
|
1087
|
-
var Mutation = {
|
|
1088
|
-
Public: getMutation("Public"),
|
|
1089
|
-
Every: getMutation("Every"),
|
|
1090
|
-
Admin: getMutation("Admin"),
|
|
1091
|
-
User: getMutation("User"),
|
|
1092
|
-
SuperAdmin: getMutation("SuperAdmin"),
|
|
1093
|
-
None: getMutation("None"),
|
|
1094
|
-
Owner: getMutation("Owner")
|
|
1095
|
-
};
|
|
1096
|
-
var Message = {
|
|
1097
|
-
Public: getMessage("Public"),
|
|
1098
|
-
Every: getMessage("Every"),
|
|
1099
|
-
Admin: getMessage("Admin"),
|
|
1100
|
-
User: getMessage("User"),
|
|
1101
|
-
SuperAdmin: getMessage("SuperAdmin"),
|
|
1102
|
-
None: getMessage("None"),
|
|
1103
|
-
Owner: getMessage("Owner")
|
|
1104
|
-
};
|
|
1105
|
-
var Pubsub = {
|
|
1106
|
-
Public: getPubsub("Public"),
|
|
1107
|
-
Every: getPubsub("Every"),
|
|
1108
|
-
Admin: getPubsub("Admin"),
|
|
1109
|
-
User: getPubsub("User"),
|
|
1110
|
-
SuperAdmin: getPubsub("SuperAdmin"),
|
|
1111
|
-
None: getPubsub("None"),
|
|
1112
|
-
Owner: getPubsub("Owner")
|
|
1113
|
-
};
|
|
1114
|
-
var Process = {
|
|
1115
|
-
Federation: getProcess("Federation"),
|
|
1116
|
-
Batch: getProcess("Batch"),
|
|
1117
|
-
All: getProcess("All")
|
|
1118
|
-
};
|
|
1119
|
-
var getArg = (type) => function(name, returns, argsOption = {}) {
|
|
1120
|
-
return function(prototype, key, idx) {
|
|
1121
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1122
|
-
argMetas[idx] = { name, returns, argsOption, key, idx, type };
|
|
1123
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1124
|
-
};
|
|
1125
|
-
};
|
|
1126
|
-
var Arg = {
|
|
1127
|
-
Body: getArg("Body"),
|
|
1128
|
-
Param: getArg("Param"),
|
|
1129
|
-
Query: getArg("Query"),
|
|
1130
|
-
Upload: getArg("Upload"),
|
|
1131
|
-
Msg: getArg("Msg"),
|
|
1132
|
-
Room: getArg("Room")
|
|
1133
|
-
};
|
|
1134
|
-
var getGqlMeta = (sigRef, key) => {
|
|
1135
|
-
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
1136
|
-
if (!gqlMetaMap)
|
|
1137
|
-
throw new Error(`No GqlMeta found for ${sigRef.name}`);
|
|
1138
|
-
const gqlMeta = gqlMetaMap.get(key);
|
|
1139
|
-
if (!gqlMeta)
|
|
1140
|
-
throw new Error(`No GqlMeta found for ${key}`);
|
|
1141
|
-
return gqlMeta;
|
|
1142
|
-
};
|
|
1143
|
-
var getGqlMetaMapOnPrototype = (prototype) => {
|
|
1144
|
-
const gqlMetaMap = Reflect.getMetadata("gql", prototype);
|
|
1145
|
-
return gqlMetaMap ?? /* @__PURE__ */ new Map();
|
|
1146
|
-
};
|
|
1147
|
-
var setGqlMetaMapOnPrototype = (prototype, gqlMetaMap) => {
|
|
1148
|
-
Reflect.defineMetadata("gql", gqlMetaMap, prototype);
|
|
1149
|
-
};
|
|
1150
|
-
var getArgMetasOnPrototype = (prototype, key) => {
|
|
1151
|
-
return Reflect.getMetadata("args", prototype, key) ?? [];
|
|
1152
|
-
};
|
|
1153
|
-
var setArgMetasOnPrototype = (prototype, key, argMetas) => {
|
|
1154
|
-
Reflect.defineMetadata("args", argMetas, prototype, key);
|
|
1155
|
-
};
|
|
1156
|
-
|
|
1157
|
-
// pkgs/@akanjs/signal/src/baseFetch.ts
|
|
1158
|
-
var nativeFetch = fetch;
|
|
1159
|
-
var baseFetch = Object.assign(nativeFetch, {
|
|
1160
|
-
client,
|
|
1161
|
-
clone: function(option = {}) {
|
|
1162
|
-
return {
|
|
1163
|
-
...this,
|
|
1164
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
1165
|
-
client: this.client.clone(option)
|
|
1166
|
-
};
|
|
1167
|
-
}
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1170
|
-
// pkgs/@akanjs/nest/src/authorization.ts
|
|
1171
|
-
var import_apollo = require("@nestjs/apollo");
|
|
1172
|
-
var jwt = __toESM(require("jsonwebtoken"));
|
|
1173
|
-
var allow = (account, roles, userId) => {
|
|
1174
|
-
if (!account)
|
|
1175
|
-
throw new import_apollo.AuthenticationError("No Authentication Account");
|
|
1176
|
-
for (const role of roles) {
|
|
1177
|
-
if (role === "user" && account.self?.roles.includes("user"))
|
|
1178
|
-
return true;
|
|
1179
|
-
else if (role === "admin" && account.me?.roles.includes("admin"))
|
|
1180
|
-
return true;
|
|
1181
|
-
else if (role === "superAdmin" && account.me?.roles.includes("superAdmin"))
|
|
1182
|
-
return true;
|
|
1183
|
-
}
|
|
1184
|
-
throw new import_apollo.AuthenticationError(
|
|
1185
|
-
`No Authentication With Roles: ${roles.join(", ")}, Your roles are ${[
|
|
1186
|
-
...account.self?.roles ?? [],
|
|
1187
|
-
...account.me?.roles ?? []
|
|
1188
|
-
].join(", ")}${!account.self?.roles.length && !account.me?.roles.length ? " (No Roles)" : ""}`
|
|
1189
|
-
);
|
|
1190
|
-
};
|
|
1191
|
-
|
|
1192
|
-
// pkgs/@akanjs/nest/src/authGuards.ts
|
|
1193
|
-
var import_common7 = require("@nestjs/common");
|
|
1194
|
-
var import_graphql = require("@nestjs/graphql");
|
|
1195
|
-
var getRequest = (context) => {
|
|
1196
|
-
const type = context.getType();
|
|
1197
|
-
if (type === "ws")
|
|
1198
|
-
throw new Error("Getting Request in Websocket is not allowed");
|
|
1199
|
-
return type === "http" ? context.switchToHttp().getRequest() : import_graphql.GqlExecutionContext.create(context).getContext().req;
|
|
1200
|
-
};
|
|
1201
|
-
var getResponse = (context) => {
|
|
1202
|
-
const type = context.getType();
|
|
1203
|
-
if (type === "ws")
|
|
1204
|
-
throw new Error("Getting Response in Websocket is not allowed");
|
|
1205
|
-
return type === "http" ? context.switchToHttp().getResponse() : import_graphql.GqlExecutionContext.create(context).getContext().req.res;
|
|
1206
|
-
};
|
|
1207
|
-
var getArgs = (context) => {
|
|
1208
|
-
const type = context.getType();
|
|
1209
|
-
if (type === "ws")
|
|
1210
|
-
throw new Error("Getting Args in Websocket is not allowed");
|
|
1211
|
-
if (type === "graphql")
|
|
1212
|
-
return import_graphql.GqlExecutionContext.create(context).getArgs();
|
|
1213
|
-
else if (type === "http") {
|
|
1214
|
-
const { params, query, body } = context.switchToHttp().getRequest();
|
|
1215
|
-
return { ...params, ...query, ...body };
|
|
1216
|
-
} else
|
|
1217
|
-
throw new Error("Getting Args in Unknown context is not allowed");
|
|
1218
|
-
};
|
|
1219
|
-
var Public = class {
|
|
1220
|
-
canActivate(context) {
|
|
1221
|
-
return true;
|
|
1222
|
-
}
|
|
1223
|
-
};
|
|
1224
|
-
Public = __decorateClass([
|
|
1225
|
-
(0, import_common7.Injectable)()
|
|
1226
|
-
], Public);
|
|
1227
|
-
var None = class {
|
|
1228
|
-
canActivate() {
|
|
1229
|
-
return false;
|
|
1230
|
-
}
|
|
1231
|
-
};
|
|
1232
|
-
None = __decorateClass([
|
|
1233
|
-
(0, import_common7.Injectable)()
|
|
1234
|
-
], None);
|
|
1235
|
-
var Every = class {
|
|
1236
|
-
canActivate(context) {
|
|
1237
|
-
const { account } = getRequest(context);
|
|
1238
|
-
return allow(account, ["user", "admin", "superAdmin"]);
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
|
-
Every = __decorateClass([
|
|
1242
|
-
(0, import_common7.Injectable)()
|
|
1243
|
-
], Every);
|
|
1244
|
-
var Owner = class {
|
|
1245
|
-
canActivate(context) {
|
|
1246
|
-
const { account } = getRequest(context);
|
|
1247
|
-
return allow(account, ["user", "admin", "superAdmin"]);
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
1250
|
-
Owner = __decorateClass([
|
|
1251
|
-
(0, import_common7.Injectable)()
|
|
1252
|
-
], Owner);
|
|
1253
|
-
var Admin = class {
|
|
1254
|
-
canActivate(context) {
|
|
1255
|
-
const { account } = getRequest(context);
|
|
1256
|
-
return allow(account, ["admin", "superAdmin"]);
|
|
1257
|
-
}
|
|
1258
|
-
};
|
|
1259
|
-
Admin = __decorateClass([
|
|
1260
|
-
(0, import_common7.Injectable)()
|
|
1261
|
-
], Admin);
|
|
1262
|
-
var SuperAdmin = class {
|
|
1263
|
-
canActivate(context) {
|
|
1264
|
-
const { account } = getRequest(context);
|
|
1265
|
-
return allow(account, ["superAdmin"]);
|
|
1266
|
-
}
|
|
1267
|
-
};
|
|
1268
|
-
SuperAdmin = __decorateClass([
|
|
1269
|
-
(0, import_common7.Injectable)()
|
|
1270
|
-
], SuperAdmin);
|
|
1271
|
-
var User = class {
|
|
1272
|
-
canActivate(context) {
|
|
1273
|
-
const { account } = getRequest(context);
|
|
1274
|
-
return allow(account, ["user"]);
|
|
1275
|
-
}
|
|
1276
|
-
};
|
|
1277
|
-
User = __decorateClass([
|
|
1278
|
-
(0, import_common7.Injectable)()
|
|
1279
|
-
], User);
|
|
1280
|
-
|
|
1281
|
-
// pkgs/@akanjs/nest/src/authentication.ts
|
|
1282
|
-
var import_common8 = require("@nestjs/common");
|
|
1283
|
-
var import_ua_parser_js = __toESM(require("ua-parser-js"));
|
|
1284
|
-
var Account3 = (0, import_common8.createParamDecorator)((option, context) => {
|
|
1285
|
-
const { account } = getRequest(context);
|
|
1286
|
-
return account;
|
|
1287
|
-
});
|
|
1288
|
-
var Self2 = (0, import_common8.createParamDecorator)((option, context) => {
|
|
1289
|
-
const { account } = getRequest(context);
|
|
1290
|
-
const self = account.self;
|
|
1291
|
-
if (!self && !option.nullable)
|
|
1292
|
-
throw new import_common8.UnauthorizedException("No or Invalid Account in Self (User)");
|
|
1293
|
-
return self;
|
|
1294
|
-
});
|
|
1295
|
-
var Me2 = (0, import_common8.createParamDecorator)((option, context) => {
|
|
1296
|
-
const { account } = getRequest(context);
|
|
1297
|
-
const me = account.me;
|
|
1298
|
-
if (!me && !option.nullable)
|
|
1299
|
-
throw new import_common8.UnauthorizedException("No or Invalid Account in Me (Admin)");
|
|
1300
|
-
return me;
|
|
1301
|
-
});
|
|
1302
|
-
var UserIp2 = (0, import_common8.createParamDecorator)((option, context) => {
|
|
1303
|
-
const req = getRequest(context);
|
|
1304
|
-
const ip = req.ip;
|
|
1305
|
-
if (!ip && !option.nullable)
|
|
1306
|
-
throw new import_common8.UnauthorizedException("Invalid IP");
|
|
1307
|
-
return { ip };
|
|
1308
|
-
});
|
|
1309
|
-
var Access2 = (0, import_common8.createParamDecorator)((option, context) => {
|
|
1310
|
-
const req = getRequest(context);
|
|
1311
|
-
const res = new import_ua_parser_js.default(req.userAgent).getResult();
|
|
1312
|
-
if (!req.userAgent && !option.nullable)
|
|
1313
|
-
throw new import_common8.UnauthorizedException("Invalid UserAgent");
|
|
1314
|
-
return {
|
|
1315
|
-
...req.geolocation ? JSON.parse(req.geolocation) : {},
|
|
1316
|
-
osName: res.os.name,
|
|
1317
|
-
osVersion: res.os.version,
|
|
1318
|
-
browserName: res.browser.name,
|
|
1319
|
-
browserVersion: res.browser.version,
|
|
1320
|
-
mobileModel: res.device.model,
|
|
1321
|
-
mobileVendor: res.device.vendor,
|
|
1322
|
-
deviceType: res.device.type ?? "desktop",
|
|
1323
|
-
at: dayjs(),
|
|
1324
|
-
period: 0
|
|
1325
|
-
};
|
|
1326
|
-
});
|
|
1327
|
-
var Req2 = (0, import_common8.createParamDecorator)((option, context) => {
|
|
1328
|
-
return getRequest(context);
|
|
1329
|
-
});
|
|
1330
|
-
var Res2 = (0, import_common8.createParamDecorator)((option, context) => {
|
|
1331
|
-
return getResponse(context);
|
|
1332
|
-
});
|
|
1333
|
-
var Ws2 = (0, import_common8.createParamDecorator)((option, context) => {
|
|
1334
|
-
const socket = context.getArgByIndex(0);
|
|
1335
|
-
const { __subscribe__ } = context.getArgByIndex(1);
|
|
1336
|
-
return {
|
|
1337
|
-
socket,
|
|
1338
|
-
subscribe: __subscribe__,
|
|
1339
|
-
onDisconnect: (handler) => {
|
|
1340
|
-
socket.on("disconnect", handler);
|
|
1341
|
-
},
|
|
1342
|
-
onSubscribe: (handler) => {
|
|
1343
|
-
if (__subscribe__)
|
|
1344
|
-
handler();
|
|
1345
|
-
},
|
|
1346
|
-
onUnsubscribe: (handler) => {
|
|
1347
|
-
if (!__subscribe__)
|
|
1348
|
-
handler();
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
});
|
|
1352
|
-
|
|
1353
|
-
// pkgs/@akanjs/nest/src/interceptors.ts
|
|
1354
|
-
var import_common10 = require("@nestjs/common");
|
|
1355
|
-
var import_graphql2 = require("@nestjs/graphql");
|
|
1356
|
-
var import_rxjs = require("rxjs");
|
|
1357
|
-
var import_operators = require("rxjs/operators");
|
|
1358
|
-
var _logger, _CACHE_PREFIX, _generateCacheKey, generateCacheKey_fn, _getCache, getCache_fn, _setCache, setCache_fn;
|
|
1359
|
-
var CacheInterceptor = class {
|
|
1360
|
-
constructor(redis) {
|
|
1361
|
-
this.redis = redis;
|
|
1362
|
-
__privateAdd(this, _generateCacheKey);
|
|
1363
|
-
__privateAdd(this, _getCache);
|
|
1364
|
-
__privateAdd(this, _setCache);
|
|
1365
|
-
__privateAdd(this, _logger, new Logger("CacheInterceptor"));
|
|
1366
|
-
__privateAdd(this, _CACHE_PREFIX, "signal:");
|
|
1367
|
-
}
|
|
1368
|
-
async intercept(context, next) {
|
|
1369
|
-
const handler = context.getHandler();
|
|
1370
|
-
const signalKey = handler.name;
|
|
1371
|
-
const gqlMeta = getGqlMeta(context.getClass(), signalKey);
|
|
1372
|
-
if (gqlMeta.type !== "Query" || !gqlMeta.signalOption.cache) {
|
|
1373
|
-
if (gqlMeta.signalOption.cache)
|
|
1374
|
-
__privateGet(this, _logger).warn(`CacheInterceptor: ${signalKey} is not Query endpoint or cache is not set`);
|
|
1375
|
-
return next.handle();
|
|
1376
|
-
}
|
|
1377
|
-
const args = getArgs(context);
|
|
1378
|
-
const cacheKey = __privateMethod(this, _generateCacheKey, generateCacheKey_fn).call(this, signalKey, args);
|
|
1379
|
-
const cachedData = await __privateMethod(this, _getCache, getCache_fn).call(this, cacheKey);
|
|
1380
|
-
if (cachedData) {
|
|
1381
|
-
__privateGet(this, _logger).debug(`Cache hit for key: ${cacheKey}`);
|
|
1382
|
-
return next.handle().pipe(
|
|
1383
|
-
(0, import_operators.map)(() => cachedData),
|
|
1384
|
-
(0, import_operators.catchError)((error) => {
|
|
1385
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1386
|
-
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
1387
|
-
return (0, import_rxjs.throwError)(() => error);
|
|
1388
|
-
})
|
|
1389
|
-
);
|
|
1390
|
-
}
|
|
1391
|
-
return next.handle().pipe(
|
|
1392
|
-
(0, import_operators.map)((data) => {
|
|
1393
|
-
const cacheDuration = gqlMeta.signalOption.cache;
|
|
1394
|
-
if (typeof cacheDuration === "number") {
|
|
1395
|
-
void __privateMethod(this, _setCache, setCache_fn).call(this, cacheKey, data, cacheDuration);
|
|
1396
|
-
__privateGet(this, _logger).debug(`Cache set for key: ${cacheKey}`);
|
|
1397
|
-
}
|
|
1398
|
-
return data;
|
|
1399
|
-
}),
|
|
1400
|
-
(0, import_operators.catchError)((error) => {
|
|
1401
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1402
|
-
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
1403
|
-
return (0, import_rxjs.throwError)(() => error);
|
|
1404
|
-
})
|
|
1405
|
-
);
|
|
1406
|
-
}
|
|
1407
|
-
};
|
|
1408
|
-
_logger = new WeakMap();
|
|
1409
|
-
_CACHE_PREFIX = new WeakMap();
|
|
1410
|
-
_generateCacheKey = new WeakSet();
|
|
1411
|
-
generateCacheKey_fn = function(signalKey, args) {
|
|
1412
|
-
return `${__privateGet(this, _CACHE_PREFIX)}${signalKey}:${JSON.stringify(args)}`;
|
|
1413
|
-
};
|
|
1414
|
-
_getCache = new WeakSet();
|
|
1415
|
-
getCache_fn = async function(key) {
|
|
1416
|
-
try {
|
|
1417
|
-
const cached = await this.redis.get(key);
|
|
1418
|
-
if (!cached)
|
|
1419
|
-
return null;
|
|
1420
|
-
const { data } = JSON.parse(cached);
|
|
1421
|
-
return data;
|
|
1422
|
-
} catch (error) {
|
|
1423
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1424
|
-
__privateGet(this, _logger).error(`Error retrieving cache for key ${key}: ${errorMessage}`);
|
|
1425
|
-
return null;
|
|
1426
|
-
}
|
|
1427
|
-
};
|
|
1428
|
-
_setCache = new WeakSet();
|
|
1429
|
-
setCache_fn = async function(key, data, ttlMs) {
|
|
1430
|
-
try {
|
|
1431
|
-
const cacheData = { data, timestamp: Date.now() };
|
|
1432
|
-
await this.redis.set(key, JSON.stringify(cacheData), { PX: ttlMs });
|
|
1433
|
-
} catch (error) {
|
|
1434
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1435
|
-
__privateGet(this, _logger).error(`Error setting cache for key ${key}: ${errorMessage}`);
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
CacheInterceptor = __decorateClass([
|
|
1439
|
-
(0, import_common10.Injectable)(),
|
|
1440
|
-
__decorateParam(0, (0, import_common10.Inject)("REDIS_CLIENT"))
|
|
1441
|
-
], CacheInterceptor);
|
|
1442
|
-
var TimeoutInterceptor = class {
|
|
1443
|
-
intercept(context, next) {
|
|
1444
|
-
const gqlMeta = getGqlMeta(context.getClass(), context.getHandler().name);
|
|
1445
|
-
const timeoutMs = gqlMeta.signalOption.timeout ?? 3e4;
|
|
1446
|
-
if (timeoutMs === 0)
|
|
1447
|
-
return next.handle();
|
|
1448
|
-
return next.handle().pipe(
|
|
1449
|
-
(0, import_operators.timeout)(timeoutMs),
|
|
1450
|
-
(0, import_operators.catchError)((err) => {
|
|
1451
|
-
if (err instanceof import_rxjs.TimeoutError)
|
|
1452
|
-
return (0, import_rxjs.throwError)(() => new import_common10.RequestTimeoutException());
|
|
1453
|
-
return (0, import_rxjs.throwError)(() => err);
|
|
1454
|
-
})
|
|
1455
|
-
);
|
|
1456
|
-
}
|
|
1457
|
-
};
|
|
1458
|
-
TimeoutInterceptor = __decorateClass([
|
|
1459
|
-
(0, import_common10.Injectable)()
|
|
1460
|
-
], TimeoutInterceptor);
|
|
1461
|
-
var LoggingInterceptor = class {
|
|
1462
|
-
logger = new Logger("IO");
|
|
1463
|
-
intercept(context, next) {
|
|
1464
|
-
const gqlReq = context.getArgByIndex(3);
|
|
1465
|
-
const req = getRequest(context);
|
|
1466
|
-
const reqType = gqlReq?.parentType?.name ?? req.method;
|
|
1467
|
-
const reqName = gqlReq?.fieldName ?? req.url;
|
|
1468
|
-
const before = Date.now();
|
|
1469
|
-
const ip = import_graphql2.GqlExecutionContext.create(context).getContext().req.ip;
|
|
1470
|
-
this.logger.debug(`Before ${reqType}-${reqName} / ${ip} / ${before}`);
|
|
1471
|
-
return next.handle().pipe(
|
|
1472
|
-
(0, import_operators.tap)(() => {
|
|
1473
|
-
const after = Date.now();
|
|
1474
|
-
this.logger.debug(`After ${reqType}-${reqName} / ${ip} / ${after} (${after - before}ms)`);
|
|
1475
|
-
})
|
|
1476
|
-
);
|
|
1477
|
-
}
|
|
1478
|
-
};
|
|
1479
|
-
LoggingInterceptor = __decorateClass([
|
|
1480
|
-
(0, import_common10.Injectable)()
|
|
1481
|
-
], LoggingInterceptor);
|
|
1482
|
-
|
|
1483
|
-
// pkgs/@akanjs/nest/src/redis-io.adapter.ts
|
|
1484
|
-
var import_platform_socket = require("@nestjs/platform-socket.io");
|
|
1485
|
-
var import_redis_adapter = require("@socket.io/redis-adapter");
|
|
1486
|
-
var import_redis = require("redis");
|
|
1487
|
-
|
|
1488
|
-
// pkgs/@akanjs/nest/src/pipes.ts
|
|
1489
|
-
var import_common12 = require("@nestjs/common");
|
|
1490
|
-
var import_stream = require("stream");
|
|
1491
|
-
var ArrayifyPipe = class {
|
|
1492
|
-
transform(value, metadata) {
|
|
1493
|
-
return Array.isArray(value) ? value : value.split(",");
|
|
1494
|
-
}
|
|
1495
|
-
};
|
|
1496
|
-
ArrayifyPipe = __decorateClass([
|
|
1497
|
-
(0, import_common12.Injectable)()
|
|
1498
|
-
], ArrayifyPipe);
|
|
1499
|
-
var IntPipe = class {
|
|
1500
|
-
transform(value, metadata) {
|
|
1501
|
-
return Array.isArray(value) ? value.map(parseInt) : [parseInt(value)];
|
|
1502
|
-
}
|
|
1503
|
-
};
|
|
1504
|
-
IntPipe = __decorateClass([
|
|
1505
|
-
(0, import_common12.Injectable)()
|
|
1506
|
-
], IntPipe);
|
|
1507
|
-
var FloatPipe = class {
|
|
1508
|
-
transform(value, metadata) {
|
|
1509
|
-
return Array.isArray(value) ? value.map(parseFloat) : [parseFloat(value)];
|
|
1510
|
-
}
|
|
1511
|
-
};
|
|
1512
|
-
FloatPipe = __decorateClass([
|
|
1513
|
-
(0, import_common12.Injectable)()
|
|
1514
|
-
], FloatPipe);
|
|
1515
|
-
var BooleanPipe = class {
|
|
1516
|
-
transform(value, metadata) {
|
|
1517
|
-
return Array.isArray(value) ? value.map((v) => Boolean(v)) : [Boolean(value)];
|
|
1518
|
-
}
|
|
1519
|
-
};
|
|
1520
|
-
BooleanPipe = __decorateClass([
|
|
1521
|
-
(0, import_common12.Injectable)()
|
|
1522
|
-
], BooleanPipe);
|
|
1523
|
-
var DayjsPipe = class {
|
|
1524
|
-
transform(value, metadata) {
|
|
1525
|
-
return Array.isArray(value) ? value.map(dayjs) : [dayjs(value)];
|
|
1526
|
-
}
|
|
1527
|
-
};
|
|
1528
|
-
DayjsPipe = __decorateClass([
|
|
1529
|
-
(0, import_common12.Injectable)()
|
|
1530
|
-
], DayjsPipe);
|
|
1531
|
-
var JSONPipe = class {
|
|
1532
|
-
transform(value, metadata) {
|
|
1533
|
-
const transformable = typeof value === "string" && value.length;
|
|
1534
|
-
const obj = transformable ? JSON.parse(atob(value)) : value;
|
|
1535
|
-
return obj;
|
|
1536
|
-
}
|
|
1537
|
-
};
|
|
1538
|
-
JSONPipe = __decorateClass([
|
|
1539
|
-
(0, import_common12.Injectable)()
|
|
1540
|
-
], JSONPipe);
|
|
1541
|
-
var convertToFileStream = (value) => ({
|
|
1542
|
-
filename: value.originalname,
|
|
1543
|
-
mimetype: value.mimetype,
|
|
1544
|
-
encoding: value.encoding,
|
|
1545
|
-
createReadStream: () => import_stream.Readable.from(value.buffer)
|
|
1546
|
-
});
|
|
1547
|
-
var MulterToUploadPipe = class {
|
|
1548
|
-
transform(value, metadata) {
|
|
1549
|
-
return Array.isArray(value) ? value.map(convertToFileStream) : convertToFileStream(value);
|
|
1550
|
-
}
|
|
1551
|
-
};
|
|
1552
|
-
MulterToUploadPipe = __decorateClass([
|
|
1553
|
-
(0, import_common12.Injectable)()
|
|
1554
|
-
], MulterToUploadPipe);
|
|
1555
|
-
|
|
1556
|
-
// pkgs/@akanjs/nest/src/exporter.ts
|
|
1557
|
-
var fs = __toESM(require("fs"));
|
|
1558
|
-
|
|
1559
|
-
// pkgs/@akanjs/nest/src/verifyPayment.ts
|
|
1560
|
-
var import_iap = __toESM(require("iap"));
|
|
1561
|
-
|
|
1562
|
-
// pkgs/@akanjs/nest/src/sso.ts
|
|
1563
|
-
var import_common13 = require("@nestjs/common");
|
|
1564
|
-
var import_passport = require("@nestjs/passport");
|
|
1565
|
-
var appleSignin = __toESM(require("apple-signin"));
|
|
1566
|
-
var jwt2 = __toESM(require("jsonwebtoken"));
|
|
1567
|
-
var import_passport_apple = require("passport-apple");
|
|
1568
|
-
var import_passport_facebook = require("passport-facebook");
|
|
1569
|
-
var import_passport_github = require("passport-github");
|
|
1570
|
-
var import_passport_google_oauth20 = require("passport-google-oauth20");
|
|
1571
|
-
var import_passport_kakao = require("passport-kakao");
|
|
1572
|
-
var import_passport_naver = require("passport-naver");
|
|
1573
|
-
|
|
1574
|
-
// pkgs/@akanjs/nest/src/exceptions.ts
|
|
1575
|
-
var import_common15 = require("@nestjs/common");
|
|
1576
|
-
var AllExceptionsFilter = class {
|
|
1577
|
-
logger = new Logger("Exception Filter");
|
|
1578
|
-
catch(exception, host) {
|
|
1579
|
-
if (host.getType() !== "http") {
|
|
1580
|
-
const gqlArgs = host.getArgByIndex(1);
|
|
1581
|
-
const gqlReq = host.getArgByIndex(3);
|
|
1582
|
-
const reqType2 = gqlReq?.parentType?.name ?? "unknown";
|
|
1583
|
-
const reqName2 = gqlReq?.fieldName ?? "unknown";
|
|
1584
|
-
this.logger.error(
|
|
1585
|
-
`GraphQL Error
|
|
1586
|
-
Request: ${reqType2}-${reqName2}
|
|
1587
|
-
Args: ${JSON.stringify(gqlArgs, null, 2)}
|
|
1588
|
-
${exception.stack}`
|
|
1589
|
-
);
|
|
1590
|
-
throw exception;
|
|
1591
|
-
}
|
|
1592
|
-
const ctx = host.switchToHttp();
|
|
1593
|
-
const res = ctx.getResponse();
|
|
1594
|
-
const req = ctx.getRequest();
|
|
1595
|
-
const reqType = req.method;
|
|
1596
|
-
const reqName = req.url;
|
|
1597
|
-
const status = exception instanceof import_common15.HttpException ? exception.getStatus() : null;
|
|
1598
|
-
if (status) {
|
|
1599
|
-
res.status(status).json({
|
|
1600
|
-
statusCode: status,
|
|
1601
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1602
|
-
path: req.url,
|
|
1603
|
-
message: exception instanceof import_common15.HttpException ? exception.getResponse() : exception.message
|
|
1604
|
-
});
|
|
1605
|
-
this.logger.error(
|
|
1606
|
-
`Http Error: ${status}
|
|
1607
|
-
Request: ${reqType}-${reqName}
|
|
1608
|
-
Body: ${JSON.stringify(req.body, null, 2)}
|
|
1609
|
-
${exception.stack}`
|
|
1610
|
-
);
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
};
|
|
1614
|
-
AllExceptionsFilter = __decorateClass([
|
|
1615
|
-
(0, import_common15.Catch)()
|
|
1616
|
-
], AllExceptionsFilter);
|
|
1617
|
-
|
|
1618
|
-
// pkgs/@akanjs/nest/src/generateSecrets.ts
|
|
1619
|
-
var import_crypto = require("crypto");
|
|
1620
|
-
var import_tunnel_ssh = require("tunnel-ssh");
|
|
1621
|
-
|
|
1622
|
-
// pkgs/@akanjs/nest/src/mongoose.ts
|
|
1623
|
-
var import_mongoose2 = __toESM(require("mongoose"));
|
|
1624
|
-
|
|
1625
|
-
// pkgs/@akanjs/nest/src/searchClient.ts
|
|
1626
|
-
var import_common17 = require("@nestjs/common");
|
|
1627
|
-
var SearchClient = class {
|
|
1628
|
-
meili;
|
|
1629
|
-
async getIndexNames() {
|
|
1630
|
-
const { results } = await this.meili.getIndexes({ limit: 1e3 });
|
|
1631
|
-
return results.map((index) => index.uid);
|
|
1632
|
-
}
|
|
1633
|
-
async getSearchResult(indexName, option) {
|
|
1634
|
-
const { skip = 0, limit = DEFAULT_PAGE_SIZE, sort = "", searchString } = option;
|
|
1635
|
-
if (!searchString) {
|
|
1636
|
-
const { results, total } = await this.meili.index(indexName).getDocuments({ offset: skip, limit });
|
|
1637
|
-
return { docs: results, skip, limit, sort, total };
|
|
1638
|
-
}
|
|
1639
|
-
const { hits, estimatedTotalHits } = await this.meili.index(indexName).search(searchString, { offset: skip, limit });
|
|
1640
|
-
return { docs: hits, skip, limit, sort, total: estimatedTotalHits, query: searchString };
|
|
1641
|
-
}
|
|
1642
|
-
async upsertDocuments(indexName, documents) {
|
|
1643
|
-
const task = await this.meili.index(indexName).addDocuments(documents);
|
|
1644
|
-
return task;
|
|
1645
|
-
}
|
|
1646
|
-
async dropIndex(indexName) {
|
|
1647
|
-
const task = await this.meili.index(indexName).delete();
|
|
1648
|
-
return task;
|
|
1649
|
-
}
|
|
1650
|
-
};
|
|
1651
|
-
__decorateClass([
|
|
1652
|
-
(0, import_common17.Inject)("MEILI_CLIENT")
|
|
1653
|
-
], SearchClient.prototype, "meili", 2);
|
|
1654
|
-
SearchClient = __decorateClass([
|
|
1655
|
-
(0, import_common17.Injectable)()
|
|
1656
|
-
], SearchClient);
|
|
1657
|
-
|
|
1658
|
-
// pkgs/@akanjs/nest/src/cacheClient.ts
|
|
1659
|
-
var import_common18 = require("@nestjs/common");
|
|
1660
|
-
var CacheClient = class {
|
|
1661
|
-
redis;
|
|
1662
|
-
};
|
|
1663
|
-
__decorateClass([
|
|
1664
|
-
(0, import_common18.Inject)("REDIS_CLIENT")
|
|
1665
|
-
], CacheClient.prototype, "redis", 2);
|
|
1666
|
-
CacheClient = __decorateClass([
|
|
1667
|
-
(0, import_common18.Injectable)()
|
|
1668
|
-
], CacheClient);
|
|
1669
|
-
|
|
1670
|
-
// pkgs/@akanjs/nest/src/databaseClient.ts
|
|
1671
|
-
var import_common20 = require("@nestjs/common");
|
|
1672
|
-
var import_mongoose3 = require("@nestjs/mongoose");
|
|
1673
|
-
var DatabaseClient = class {
|
|
1674
|
-
connection;
|
|
1675
|
-
getModel(modelName) {
|
|
1676
|
-
const model = this.connection.models[capitalize(modelName)];
|
|
1677
|
-
return model;
|
|
1678
|
-
}
|
|
1679
|
-
};
|
|
1680
|
-
__decorateClass([
|
|
1681
|
-
(0, import_mongoose3.InjectConnection)()
|
|
1682
|
-
], DatabaseClient.prototype, "connection", 2);
|
|
1683
|
-
DatabaseClient = __decorateClass([
|
|
1684
|
-
(0, import_common20.Injectable)()
|
|
1685
|
-
], DatabaseClient);
|
|
1686
|
-
|
|
1687
|
-
// pkgs/@akanjs/nest/src/decorators.ts
|
|
1688
|
-
var import_reflect_metadata6 = require("reflect-metadata");
|
|
1689
|
-
var import_schedule = require("@nestjs/schedule");
|
|
1690
|
-
var Transaction = () => {
|
|
1691
|
-
return function(target, key, descriptor) {
|
|
1692
|
-
const originMethod = descriptor.value;
|
|
1693
|
-
descriptor.value = function(...args) {
|
|
1694
|
-
if (!this.connection)
|
|
1695
|
-
throw new Error(`No Connection in function ${key}`);
|
|
1696
|
-
return new Promise((resolve, reject) => {
|
|
1697
|
-
this.connection.transaction(async () => {
|
|
1698
|
-
const res = await originMethod.apply(this, args);
|
|
1699
|
-
resolve(res);
|
|
1700
|
-
}).catch(reject);
|
|
1701
|
-
});
|
|
1702
|
-
};
|
|
1703
|
-
return descriptor;
|
|
1704
|
-
};
|
|
1705
|
-
};
|
|
239
|
+
// pkgs/@akanjs/document/src/database.ts
|
|
240
|
+
var import_base2 = require("@akanjs/base");
|
|
241
|
+
var import_common2 = require("@akanjs/common");
|
|
242
|
+
var import_constant2 = require("@akanjs/constant");
|
|
243
|
+
var import_nest = require("@akanjs/nest");
|
|
1706
244
|
|
|
1707
245
|
// pkgs/@akanjs/document/src/dataLoader.ts
|
|
1708
246
|
var import_dataloader = __toESM(require("dataloader"));
|
|
1709
247
|
var import_lodash = require("lodash");
|
|
1710
|
-
var
|
|
1711
|
-
var Id =
|
|
1712
|
-
var ObjectId =
|
|
1713
|
-
var Mixed =
|
|
248
|
+
var import_mongoose2 = require("mongoose");
|
|
249
|
+
var Id = import_mongoose2.Types.ObjectId;
|
|
250
|
+
var ObjectId = import_mongoose2.Schema.Types.ObjectId;
|
|
251
|
+
var Mixed = import_mongoose2.Schema.Types.Mixed;
|
|
1714
252
|
var createLoader = (model, fieldName = "_id", defaultQuery = {}) => {
|
|
1715
253
|
return new import_dataloader.default(
|
|
1716
254
|
(fields) => {
|
|
@@ -1809,7 +347,7 @@ var CacheDatabase = class {
|
|
|
1809
347
|
constructor(refName, redis) {
|
|
1810
348
|
this.refName = refName;
|
|
1811
349
|
this.redis = redis;
|
|
1812
|
-
this.logger = new Logger(`${refName}Cache`);
|
|
350
|
+
this.logger = new import_common2.Logger(`${refName}Cache`);
|
|
1813
351
|
}
|
|
1814
352
|
logger;
|
|
1815
353
|
async set(topic, key, value, option = {}) {
|
|
@@ -1828,13 +366,13 @@ var SearchDatabase = class {
|
|
|
1828
366
|
constructor(refName, meili) {
|
|
1829
367
|
this.refName = refName;
|
|
1830
368
|
this.meili = meili;
|
|
1831
|
-
this.logger = new Logger(`${refName}Search`);
|
|
1832
|
-
this.index = meili.index(lowerlize(refName));
|
|
369
|
+
this.logger = new import_common2.Logger(`${refName}Search`);
|
|
370
|
+
this.index = meili.index((0, import_common2.lowerlize)(refName));
|
|
1833
371
|
}
|
|
1834
372
|
logger;
|
|
1835
373
|
index;
|
|
1836
374
|
async searchIds(searchText, option = {}) {
|
|
1837
|
-
const { skip = 0, limit = DEFAULT_PAGE_SIZE, sort } = option;
|
|
375
|
+
const { skip = 0, limit = import_constant2.DEFAULT_PAGE_SIZE, sort } = option;
|
|
1838
376
|
if (!searchText) {
|
|
1839
377
|
const { results, total } = await this.index.getDocuments({ offset: skip ?? 0, limit: limit ?? 0 });
|
|
1840
378
|
return { ids: results.map((result) => result.id), total };
|
|
@@ -1849,7 +387,7 @@ var SearchDatabase = class {
|
|
|
1849
387
|
return { ids: hits.map((hit) => hit.id), total: estimatedTotalHits };
|
|
1850
388
|
}
|
|
1851
389
|
async count(searchText, option = {}) {
|
|
1852
|
-
const { skip = 0, limit = DEFAULT_PAGE_SIZE, sort = "" } = option;
|
|
390
|
+
const { skip = 0, limit = import_constant2.DEFAULT_PAGE_SIZE, sort = "" } = option;
|
|
1853
391
|
if (!searchText) {
|
|
1854
392
|
const { results, total } = await this.index.getDocuments({ offset: skip ?? 0, limit: limit ?? 0 });
|
|
1855
393
|
return total;
|
|
@@ -1867,8 +405,8 @@ var DatabaseModelStorage = class {
|
|
|
1867
405
|
__ModelType__ = "DatabaseModelStorage";
|
|
1868
406
|
};
|
|
1869
407
|
var databaseModelOf = (database, model, redis, meili) => {
|
|
1870
|
-
const [modelName, className] = [database.refName, capitalize(database.refName)];
|
|
1871
|
-
const insightFieldMetas = getFieldMetas(database.Insight);
|
|
408
|
+
const [modelName, className] = [database.refName, (0, import_common2.capitalize)(database.refName)];
|
|
409
|
+
const insightFieldMetas = (0, import_constant2.getFieldMetas)(database.Insight);
|
|
1872
410
|
const accumulator = Object.fromEntries(insightFieldMetas.map((fieldMeta) => [fieldMeta.key, fieldMeta.accumulate]));
|
|
1873
411
|
const defaultInsight = Object.fromEntries(insightFieldMetas.map((fieldMeta) => [fieldMeta.key, fieldMeta.default]));
|
|
1874
412
|
const makeSafeQuery = (query) => ({ removedAt: { $exists: false }, ...query ?? {} });
|
|
@@ -1877,30 +415,30 @@ var databaseModelOf = (database, model, redis, meili) => {
|
|
|
1877
415
|
});
|
|
1878
416
|
const getListQuery = (query, queryOption) => {
|
|
1879
417
|
const find = makeSafeQuery(query);
|
|
1880
|
-
const sort = getFilterSort(database.Filter, queryOption?.sort ?? "latest");
|
|
418
|
+
const sort = (0, import_constant2.getFilterSort)(database.Filter, queryOption?.sort ?? "latest");
|
|
1881
419
|
const skip = queryOption?.skip ?? 0;
|
|
1882
|
-
const limit = queryOption?.limit === null ? DEFAULT_PAGE_SIZE : queryOption?.limit ?? 0;
|
|
420
|
+
const limit = queryOption?.limit === null ? import_constant2.DEFAULT_PAGE_SIZE : queryOption?.limit ?? 0;
|
|
1883
421
|
const select = queryOption?.select;
|
|
1884
422
|
const sample = queryOption?.sample;
|
|
1885
423
|
return { find, sort, skip, limit, select, sample };
|
|
1886
424
|
};
|
|
1887
425
|
const getFindQuery = (query, queryOption) => {
|
|
1888
426
|
const find = makeSafeQuery(query);
|
|
1889
|
-
const sort = getFilterSort(database.Filter, queryOption?.sort ?? "latest");
|
|
427
|
+
const sort = (0, import_constant2.getFilterSort)(database.Filter, queryOption?.sort ?? "latest");
|
|
1890
428
|
const skip = queryOption?.skip ?? 0;
|
|
1891
429
|
const select = queryOption?.select;
|
|
1892
430
|
const sample = queryOption?.sample ?? false;
|
|
1893
431
|
return { find, sort, skip, select, sample };
|
|
1894
432
|
};
|
|
1895
433
|
const getSearchSort = (sortKey) => {
|
|
1896
|
-
const sort = getFilterSort(database.Filter, sortKey ?? "latest");
|
|
434
|
+
const sort = (0, import_constant2.getFilterSort)(database.Filter, sortKey ?? "latest");
|
|
1897
435
|
return Object.entries(sort).map(([key, value]) => `${key}:${value === 1 ? "asc" : "desc"}`);
|
|
1898
436
|
};
|
|
1899
437
|
const loader = createLoader(model);
|
|
1900
438
|
const cacheDatabase = new CacheDatabase(database.refName, redis);
|
|
1901
439
|
const searchDatabase = new SearchDatabase(database.refName, meili);
|
|
1902
440
|
const DatabaseModel = Reflect.getMetadata(database.refName, DatabaseModelStorage.prototype) ?? class DatabaseModel {
|
|
1903
|
-
logger = new Logger(`${modelName}Model`);
|
|
441
|
+
logger = new import_common2.Logger(`${modelName}Model`);
|
|
1904
442
|
__model = model;
|
|
1905
443
|
__cache = cacheDatabase;
|
|
1906
444
|
__search = searchDatabase;
|
|
@@ -1963,7 +501,7 @@ var databaseModelOf = (database, model, redis, meili) => {
|
|
|
1963
501
|
async getDefaultSummary(addQuery = {}) {
|
|
1964
502
|
if (!database.Summary)
|
|
1965
503
|
return {};
|
|
1966
|
-
const fieldMetas = getFieldMetas(database.Summary);
|
|
504
|
+
const fieldMetas = (0, import_constant2.getFieldMetas)(database.Summary);
|
|
1967
505
|
const summary = {};
|
|
1968
506
|
await Promise.all(
|
|
1969
507
|
fieldMetas.filter((fieldMeta) => !!fieldMeta.query).map(async (fieldMeta) => {
|
|
@@ -1994,7 +532,7 @@ var databaseModelOf = (database, model, redis, meili) => {
|
|
|
1994
532
|
}
|
|
1995
533
|
async [`remove${className}`](id) {
|
|
1996
534
|
const doc = await this.__model.pickById(id);
|
|
1997
|
-
return await doc.set({ removedAt: dayjs() }).save();
|
|
535
|
+
return await doc.set({ removedAt: (0, import_base2.dayjs)() }).save();
|
|
1998
536
|
}
|
|
1999
537
|
async [`search${className}`](searchText, queryOption = {}) {
|
|
2000
538
|
const { skip, limit, sort } = queryOption;
|
|
@@ -2018,48 +556,48 @@ var databaseModelOf = (database, model, redis, meili) => {
|
|
|
2018
556
|
const getQueryDataFromKey = (queryKey, args) => {
|
|
2019
557
|
const lastArg = args.at(-1);
|
|
2020
558
|
const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
|
|
2021
|
-
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
559
|
+
const queryFn = (0, import_constant2.getFilterQuery)(database.Filter, queryKey);
|
|
2022
560
|
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
2023
561
|
const queryOption = hasQueryOption ? lastArg : {};
|
|
2024
562
|
return { query, queryOption };
|
|
2025
563
|
};
|
|
2026
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
|
|
564
|
+
const filterKeyMetaMap = (0, import_constant2.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
|
|
2027
565
|
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
2028
566
|
queryKeys.forEach((queryKey) => {
|
|
2029
|
-
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
2030
|
-
DatabaseModel.prototype[`list${capitalize(queryKey)}`] = async function(...args) {
|
|
567
|
+
const queryFn = (0, import_constant2.getFilterQuery)(database.Filter, queryKey);
|
|
568
|
+
DatabaseModel.prototype[`list${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2031
569
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2032
570
|
return this.__list(query, queryOption);
|
|
2033
571
|
};
|
|
2034
|
-
DatabaseModel.prototype[`listIds${capitalize(queryKey)}`] = async function(...args) {
|
|
572
|
+
DatabaseModel.prototype[`listIds${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2035
573
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2036
574
|
return this.__listIds(query, queryOption);
|
|
2037
575
|
};
|
|
2038
|
-
DatabaseModel.prototype[`find${capitalize(queryKey)}`] = async function(...args) {
|
|
576
|
+
DatabaseModel.prototype[`find${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2039
577
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2040
578
|
return this.__find(query, queryOption);
|
|
2041
579
|
};
|
|
2042
|
-
DatabaseModel.prototype[`findId${capitalize(queryKey)}`] = async function(...args) {
|
|
580
|
+
DatabaseModel.prototype[`findId${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2043
581
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2044
582
|
return this.__findId(query, queryOption);
|
|
2045
583
|
};
|
|
2046
|
-
DatabaseModel.prototype[`pick${capitalize(queryKey)}`] = async function(...args) {
|
|
584
|
+
DatabaseModel.prototype[`pick${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2047
585
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2048
586
|
return this.__pick(query, queryOption);
|
|
2049
587
|
};
|
|
2050
|
-
DatabaseModel.prototype[`pickId${capitalize(queryKey)}`] = async function(...args) {
|
|
588
|
+
DatabaseModel.prototype[`pickId${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2051
589
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
2052
590
|
return this.__pickId(query, queryOption);
|
|
2053
591
|
};
|
|
2054
|
-
DatabaseModel.prototype[`exists${capitalize(queryKey)}`] = async function(...args) {
|
|
592
|
+
DatabaseModel.prototype[`exists${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2055
593
|
const query = queryFn(...args);
|
|
2056
594
|
return this.__exists(query);
|
|
2057
595
|
};
|
|
2058
|
-
DatabaseModel.prototype[`count${capitalize(queryKey)}`] = async function(...args) {
|
|
596
|
+
DatabaseModel.prototype[`count${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2059
597
|
const query = queryFn(...args);
|
|
2060
598
|
return this.__count(query);
|
|
2061
599
|
};
|
|
2062
|
-
DatabaseModel.prototype[`insight${capitalize(queryKey)}`] = async function(...args) {
|
|
600
|
+
DatabaseModel.prototype[`insight${(0, import_common2.capitalize)(queryKey)}`] = async function(...args) {
|
|
2063
601
|
const query = queryFn(...args);
|
|
2064
602
|
return this.__insight(query);
|
|
2065
603
|
};
|
|
@@ -2074,15 +612,14 @@ var databaseModelOf = (database, model, redis, meili) => {
|
|
|
2074
612
|
});
|
|
2075
613
|
const createDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `create${className}`);
|
|
2076
614
|
if (createDescriptor)
|
|
2077
|
-
Transaction()(DatabaseModel.prototype, `create${className}`, createDescriptor);
|
|
615
|
+
(0, import_nest.Transaction)()(DatabaseModel.prototype, `create${className}`, createDescriptor);
|
|
2078
616
|
const updateDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `update${className}`);
|
|
2079
617
|
if (updateDescriptor)
|
|
2080
|
-
Transaction()(DatabaseModel.prototype, `update${className}`, updateDescriptor);
|
|
618
|
+
(0, import_nest.Transaction)()(DatabaseModel.prototype, `update${className}`, updateDescriptor);
|
|
2081
619
|
const removeDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `remove${className}`);
|
|
2082
620
|
if (removeDescriptor)
|
|
2083
|
-
Transaction()(DatabaseModel.prototype, `remove${className}`, removeDescriptor);
|
|
621
|
+
(0, import_nest.Transaction)()(DatabaseModel.prototype, `remove${className}`, removeDescriptor);
|
|
2084
622
|
Reflect.defineMetadata(database.refName, DatabaseModel, DatabaseModelStorage.prototype);
|
|
2085
623
|
return new DatabaseModel();
|
|
2086
624
|
};
|
|
2087
|
-
//! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
|
|
2088
625
|
//! 잘되는지 확인 필요
|