@akanjs/test 0.0.40 → 0.0.41

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.d.ts CHANGED
@@ -1,3 +1 @@
1
- export { sampleOf } from './src/sampleOf.js';
2
- export { sample } from './src/sample.js';
3
- import 'dayjs';
1
+ export * from "./src";
package/index.js CHANGED
@@ -1,21 +1,626 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var index_exports = {};
16
- module.exports = __toCommonJS(index_exports);
17
- __reExport(index_exports, require("./src"), module.exports);
18
- // Annotate the CommonJS export names for ESM import in node:
19
- 0 && (module.exports = {
20
- ...require("./src")
21
- });
1
+ (() => {
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined")
12
+ return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+
32
+ // pkgs/@akanjs/base/src/base.ts
33
+ var version = "0.9.0";
34
+ var logo = `
35
+ _ _ _
36
+ / \\ | | ____ _ _ __ (_)___
37
+ / _ \\ | |/ / _' | '_ \\ | / __|
38
+ / ___ \\| < (_| | | | |_ | \\__ \\
39
+ /_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
40
+ |__/ ver ${version}
41
+ ? See more details on docs https://www.akanjs.com/docs
42
+ \u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
43
+
44
+ `;
45
+
46
+ // pkgs/@akanjs/base/src/baseEnv.ts
47
+ var appName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
48
+ var repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
49
+ var serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
50
+ if (appName === "unknown")
51
+ throw new Error("environment variable NEXT_PUBLIC_APP_NAME is required");
52
+ if (repoName === "unknown")
53
+ throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
54
+ if (serveDomain === "unknown")
55
+ throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
56
+ var environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
57
+ var operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
58
+ var operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
59
+ var networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
60
+ var tunnelUsername = process.env.SSU_TUNNEL_USERNAME ?? "root";
61
+ var tunnelPassword = process.env.SSU_TUNNEL_PASSWORD ?? repoName;
62
+ var baseEnv = {
63
+ repoName,
64
+ serveDomain,
65
+ appName,
66
+ environment,
67
+ operationType,
68
+ operationMode,
69
+ networkType,
70
+ tunnelUsername,
71
+ tunnelPassword
72
+ };
73
+ var side = typeof window === "undefined" ? "server" : "client";
74
+ var renderMode = process.env.RENDER_ENV ?? "ssr";
75
+ var clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
76
+ var clientPort = parseInt(
77
+ process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
78
+ );
79
+ var clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
80
+ var clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
81
+ 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");
82
+ var serverPort = parseInt(
83
+ process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
84
+ );
85
+ var serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
86
+ var serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
87
+ var serverGraphqlUri = `${serverHttpUri}/graphql`;
88
+ var serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
89
+ var serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
90
+ var baseClientEnv = {
91
+ ...baseEnv,
92
+ side,
93
+ renderMode,
94
+ websocket: true,
95
+ clientHost,
96
+ clientPort,
97
+ clientHttpProtocol,
98
+ clientHttpUri,
99
+ serverHost,
100
+ serverPort,
101
+ serverHttpProtocol,
102
+ serverHttpUri,
103
+ serverGraphqlUri,
104
+ serverWsProtocol,
105
+ serverWsUri
106
+ };
107
+
108
+ // pkgs/@akanjs/base/src/scalar.ts
109
+ var import_dayjs = __toESM(__require("dayjs"));
110
+ var dayjs = import_dayjs.default;
111
+ var Int = class {
112
+ __Scalar__;
113
+ };
114
+ var Upload = class {
115
+ __Scalar__;
116
+ filename;
117
+ mimetype;
118
+ encoding;
119
+ createReadStream;
120
+ };
121
+ var Float = class {
122
+ __Scalar__;
123
+ };
124
+ var ID = class {
125
+ __Scalar__;
126
+ };
127
+ var JSON = class {
128
+ __Scalar__;
129
+ };
130
+ var getNonArrayModel = (arraiedModel) => {
131
+ let arrDepth = 0;
132
+ let target = arraiedModel;
133
+ while (Array.isArray(target)) {
134
+ target = target[0];
135
+ arrDepth++;
136
+ }
137
+ return [target, arrDepth];
138
+ };
139
+ var scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON, Map]);
140
+ var scalarNameMap = /* @__PURE__ */ new Map([
141
+ [ID, "ID"],
142
+ [Int, "Int"],
143
+ [Float, "Float"],
144
+ [String, "String"],
145
+ [Boolean, "Boolean"],
146
+ [Date, "Date"],
147
+ [Upload, "Upload"],
148
+ [JSON, "JSON"],
149
+ [Map, "Map"]
150
+ ]);
151
+ var scalarArgMap = /* @__PURE__ */ new Map([
152
+ [ID, null],
153
+ [String, ""],
154
+ [Boolean, false],
155
+ [Date, dayjs(/* @__PURE__ */ new Date(-1))],
156
+ [Int, 0],
157
+ [Float, 0],
158
+ [JSON, {}],
159
+ [Map, {}]
160
+ ]);
161
+ var scalarDefaultMap = /* @__PURE__ */ new Map([
162
+ [ID, null],
163
+ [String, ""],
164
+ [Boolean, false],
165
+ [Date, dayjs(/* @__PURE__ */ new Date(-1))],
166
+ [Int, 0],
167
+ [Float, 0],
168
+ [JSON, {}]
169
+ ]);
170
+ var isGqlScalar = (modelRef) => scalarSet.has(modelRef);
171
+ var isGqlMap = (modelRef) => modelRef === Map;
172
+
173
+ // pkgs/@akanjs/common/src/isDayjs.ts
174
+ var import_dayjs2 = __require("dayjs");
175
+
176
+ // pkgs/@akanjs/common/src/isQueryEqual.ts
177
+ var import_dayjs3 = __toESM(__require("dayjs"));
178
+
179
+ // pkgs/@akanjs/common/src/isValidDate.ts
180
+ var import_dayjs4 = __toESM(__require("dayjs"));
181
+ var import_customParseFormat = __toESM(__require("dayjs/plugin/customParseFormat"));
182
+ import_dayjs4.default.extend(import_customParseFormat.default);
183
+
184
+ // pkgs/@akanjs/common/src/randomPick.ts
185
+ var randomPick = (arr) => arr[Math.floor(Math.random() * arr.length)];
186
+
187
+ // pkgs/@akanjs/common/src/randomPicks.ts
188
+ var randomPicks = (arr, count = 1, allowDuplicate = false) => {
189
+ if (!allowDuplicate && arr.length <= count)
190
+ return arr;
191
+ const idxs = [];
192
+ let pickIdx;
193
+ for (let i = 0; i < count; i++) {
194
+ do {
195
+ pickIdx = Math.floor(Math.random() * arr.length);
196
+ } while (!allowDuplicate && idxs.includes(pickIdx));
197
+ idxs.push(pickIdx);
198
+ }
199
+ return idxs.map((idx) => arr[idx]);
200
+ };
201
+
202
+ // pkgs/@akanjs/common/src/pluralize.ts
203
+ var import_pluralize = __toESM(__require("pluralize"));
204
+
205
+ // pkgs/@akanjs/common/src/Logger.ts
206
+ var import_dayjs5 = __toESM(__require("dayjs"));
207
+ var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
208
+ var clc = {
209
+ bold: (text) => `\x1B[1m${text}\x1B[0m`,
210
+ green: (text) => `\x1B[32m${text}\x1B[39m`,
211
+ yellow: (text) => `\x1B[33m${text}\x1B[39m`,
212
+ red: (text) => `\x1B[31m${text}\x1B[39m`,
213
+ magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
214
+ cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
215
+ };
216
+ var colorizeMap = {
217
+ trace: clc.bold,
218
+ verbose: clc.cyanBright,
219
+ debug: clc.magentaBright,
220
+ log: clc.green,
221
+ info: clc.green,
222
+ warn: clc.yellow,
223
+ error: clc.red
224
+ };
225
+ var Logger = class _Logger {
226
+ static #ignoreCtxSet = /* @__PURE__ */ new Set([
227
+ "InstanceLoader",
228
+ "RoutesResolver",
229
+ "RouterExplorer",
230
+ "NestFactory",
231
+ "WebSocketsController",
232
+ "GraphQLModule",
233
+ "NestApplication"
234
+ ]);
235
+ static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
236
+ static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
237
+ static #startAt = (0, import_dayjs5.default)();
238
+ static setLevel(level) {
239
+ this.level = level;
240
+ this.#levelIdx = logLevels.findIndex((l) => l === level);
241
+ }
242
+ name;
243
+ constructor(name) {
244
+ this.name = name;
245
+ }
246
+ trace(msg, context = "") {
247
+ if (_Logger.#levelIdx <= 0)
248
+ _Logger.#printMessages(this.name ?? "App", msg, context, "trace");
249
+ }
250
+ verbose(msg, context = "") {
251
+ if (_Logger.#levelIdx <= 1)
252
+ _Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
253
+ }
254
+ debug(msg, context = "") {
255
+ if (_Logger.#levelIdx <= 2)
256
+ _Logger.#printMessages(this.name ?? "App", msg, context, "debug");
257
+ }
258
+ log(msg, context = "") {
259
+ if (_Logger.#levelIdx <= 3)
260
+ _Logger.#printMessages(this.name ?? "App", msg, context, "log");
261
+ }
262
+ info(msg, context = "") {
263
+ if (_Logger.#levelIdx <= 4)
264
+ _Logger.#printMessages(this.name ?? "App", msg, context, "info");
265
+ }
266
+ warn(msg, context = "") {
267
+ if (_Logger.#levelIdx <= 5)
268
+ _Logger.#printMessages(this.name ?? "App", msg, context, "warn");
269
+ }
270
+ error(msg, context = "") {
271
+ if (_Logger.#levelIdx <= 6)
272
+ _Logger.#printMessages(this.name ?? "App", msg, context, "error");
273
+ }
274
+ raw(msg, method) {
275
+ _Logger.rawLog(msg, method);
276
+ }
277
+ rawLog(msg, method) {
278
+ _Logger.rawLog(msg, method);
279
+ }
280
+ static trace(msg, context = "") {
281
+ if (_Logger.#levelIdx <= 0)
282
+ _Logger.#printMessages("App", msg, context, "trace");
283
+ }
284
+ static verbose(msg, context = "") {
285
+ if (_Logger.#levelIdx <= 1)
286
+ _Logger.#printMessages("App", msg, context, "verbose");
287
+ }
288
+ static debug(msg, context = "") {
289
+ if (_Logger.#levelIdx <= 2)
290
+ _Logger.#printMessages("App", msg, context, "debug");
291
+ }
292
+ static log(msg, context = "") {
293
+ if (_Logger.#levelIdx <= 3)
294
+ _Logger.#printMessages("App", msg, context, "log");
295
+ }
296
+ static info(msg, context = "") {
297
+ if (_Logger.#levelIdx <= 4)
298
+ _Logger.#printMessages("App", msg, context, "info");
299
+ }
300
+ static warn(msg, context = "") {
301
+ if (_Logger.#levelIdx <= 5)
302
+ _Logger.#printMessages("App", msg, context, "warn");
303
+ }
304
+ static error(msg, context = "") {
305
+ if (_Logger.#levelIdx <= 6)
306
+ _Logger.#printMessages("App", msg, context, "error");
307
+ }
308
+ static #colorize(msg, logLevel) {
309
+ return colorizeMap[logLevel](msg);
310
+ }
311
+ static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
312
+ if (this.#ignoreCtxSet.has(context))
313
+ return;
314
+ const now = (0, import_dayjs5.default)();
315
+ const processMsg = this.#colorize(
316
+ `[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
317
+ logLevel
318
+ );
319
+ const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
320
+ const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
321
+ const contextMsg = context ? clc.yellow(`[${context}] `) : "";
322
+ const contentMsg = this.#colorize(content, logLevel);
323
+ const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
324
+ if (typeof window === "undefined")
325
+ process[writeStreamType].write(
326
+ `${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
327
+ `
328
+ );
329
+ else
330
+ console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
331
+ `);
332
+ }
333
+ static rawLog(msg, method) {
334
+ this.raw(`${msg}
335
+ `, method);
336
+ }
337
+ static raw(msg, method) {
338
+ if (typeof window === "undefined" && method !== "console" && global.process)
339
+ global.process.stdout.write(msg);
340
+ else
341
+ console.log(msg);
342
+ }
343
+ };
344
+
345
+ // pkgs/@akanjs/constant/src/scalar.ts
346
+ var import_reflect_metadata = __require("reflect-metadata");
347
+ var scalarExampleMap = /* @__PURE__ */ new Map([
348
+ [ID, "1234567890abcdef12345678"],
349
+ [Int, 0],
350
+ [Float, 0],
351
+ [String, "String"],
352
+ [Boolean, true],
353
+ [Date, (/* @__PURE__ */ new Date()).toISOString()],
354
+ [Upload, "FileUpload"],
355
+ [JSON, {}],
356
+ [Map, {}]
357
+ ]);
358
+ var getClassMeta = (modelRef) => {
359
+ const [target] = getNonArrayModel(modelRef);
360
+ const classMeta = Reflect.getMetadata("class", target.prototype);
361
+ if (!classMeta)
362
+ throw new Error(`No ClassMeta for this target ${target.name}`);
363
+ return classMeta;
364
+ };
365
+ var getFieldMetas = (modelRef) => {
366
+ const [target] = getNonArrayModel(modelRef);
367
+ const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
368
+ const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
369
+ return [...metadataMap.values()].sort((a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0));
370
+ };
371
+ var getFieldMetaMapOnPrototype = (prototype) => {
372
+ const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
373
+ return new Map(metadataMap);
374
+ };
375
+ var setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
376
+ Reflect.defineMetadata("fields", new Map(metadataMap), prototype);
377
+ };
378
+
379
+ // pkgs/@akanjs/constant/src/fieldMeta.ts
380
+ var applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
381
+ const isArray = arrDepth > 0;
382
+ const isClass = !isGqlScalar(modelRef);
383
+ const isMap = isGqlMap(modelRef);
384
+ const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
385
+ const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
386
+ if (isMap && !option.of)
387
+ throw new Error("Map type must have 'of' option");
388
+ return (prototype, key) => {
389
+ const metadata = {
390
+ nullable: option.nullable ?? false,
391
+ ref: option.ref,
392
+ refPath: option.refPath,
393
+ refType: option.refType,
394
+ default: option.default ?? (isArray ? [] : null),
395
+ type: option.type,
396
+ fieldType: option.fieldType ?? "property",
397
+ immutable: option.immutable ?? false,
398
+ min: option.min,
399
+ max: option.max,
400
+ enum: option.enum,
401
+ select: option.select ?? true,
402
+ minlength: option.minlength,
403
+ maxlength: option.maxlength,
404
+ query: option.query,
405
+ accumulate: option.accumulate,
406
+ example: option.example,
407
+ validate: option.validate,
408
+ key,
409
+ name,
410
+ isClass,
411
+ isScalar: type === "scalar",
412
+ modelRef,
413
+ arrDepth,
414
+ isArray,
415
+ optArrDepth: optionArrDepth,
416
+ isMap,
417
+ of: option.of,
418
+ text: option.text
419
+ };
420
+ const metadataMap = getFieldMetaMapOnPrototype(prototype);
421
+ metadataMap.set(key, metadata);
422
+ setFieldMetaMapOnPrototype(prototype, metadataMap);
423
+ };
424
+ };
425
+ var makeField = (customOption) => (returns, fieldOption) => {
426
+ const [modelRef, arrDepth] = getNonArrayModel(returns());
427
+ if (!fieldOption)
428
+ return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
429
+ const [opt, optArrDepth] = getNonArrayModel(fieldOption);
430
+ return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
431
+ };
432
+ var Field = {
433
+ Prop: makeField({ fieldType: "property" }),
434
+ Hidden: makeField({ fieldType: "hidden", nullable: true }),
435
+ Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
436
+ Resolve: makeField({ fieldType: "resolve" })
437
+ };
438
+
439
+ // pkgs/@akanjs/constant/src/constantDecorator.ts
440
+ var import_reflect_metadata2 = __require("reflect-metadata");
441
+
442
+ // pkgs/@akanjs/constant/src/filterMeta.ts
443
+ var setFilterMeta = (filterRef, filterMeta) => {
444
+ const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
445
+ if (existingFilterMeta)
446
+ Object.assign(filterMeta.sort, existingFilterMeta.sort);
447
+ Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
448
+ };
449
+ var getFilterKeyMetaMapOnPrototype = (prototype) => {
450
+ const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
451
+ return new Map(metadataMap);
452
+ };
453
+ var setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
454
+ Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
455
+ };
456
+ var applyFilterKeyMeta = (option) => {
457
+ return (prototype, key, descriptor) => {
458
+ const metadata = { key, ...option, descriptor };
459
+ const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
460
+ metadataMap.set(key, metadata);
461
+ setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
462
+ };
463
+ };
464
+ var makeFilter = (customOption) => (fieldOption) => {
465
+ return applyFilterKeyMeta({ ...customOption, ...fieldOption });
466
+ };
467
+ var getFilterArgMetasOnPrototype = (prototype, key) => {
468
+ const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
469
+ return filterArgMetas;
470
+ };
471
+ var setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
472
+ Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
473
+ };
474
+ var applyFilterArgMeta = (name, returns, argOption) => {
475
+ return (prototype, key, idx) => {
476
+ const [modelRef, arrDepth] = getNonArrayModel(returns());
477
+ const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
478
+ const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
479
+ const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
480
+ filterArgMetas[idx] = filterArgMeta;
481
+ setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
482
+ };
483
+ };
484
+ var Filter = {
485
+ Mongo: makeFilter({ type: "mongo" }),
486
+ // Meili: makeFilter({ fieldType: "hidden", nullable: true }),
487
+ Arg: applyFilterArgMeta
488
+ };
489
+
490
+ // pkgs/@akanjs/constant/src/baseGql.ts
491
+ var import_reflect_metadata3 = __require("reflect-metadata");
492
+ var defaultFieldMeta = {
493
+ fieldType: "property",
494
+ immutable: false,
495
+ select: true,
496
+ isClass: false,
497
+ isScalar: true,
498
+ nullable: false,
499
+ isArray: false,
500
+ arrDepth: 0,
501
+ optArrDepth: 0,
502
+ default: null,
503
+ isMap: false
504
+ };
505
+ var idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
506
+ var createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
507
+ var updatedAtFieldMeta = { ...defaultFieldMeta, key: "updatedAt", name: "Date", modelRef: Date };
508
+ var removedAtFieldMeta = {
509
+ ...defaultFieldMeta,
510
+ key: "removedAt",
511
+ name: "Date",
512
+ modelRef: Date,
513
+ nullable: true,
514
+ default: null
515
+ };
516
+
517
+ // pkgs/@akanjs/constant/src/classMeta.ts
518
+ var import_reflect_metadata4 = __require("reflect-metadata");
519
+ var InputModelStorage = class {
520
+ };
521
+ var LightModelStorage = class {
522
+ };
523
+ var FullModelStorage = class {
524
+ };
525
+ var ScalarModelStorage = class {
526
+ };
527
+ var FilterModelStorage = class {
528
+ };
529
+ var hasTextField = (modelRef) => {
530
+ const fieldMetas = getFieldMetas(modelRef);
531
+ return fieldMetas.some(
532
+ (fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
533
+ );
534
+ };
535
+ var applyClassMeta = (type, modelType, storage) => {
536
+ return function(refName) {
537
+ return function(target) {
538
+ const modelRef = target;
539
+ const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
540
+ Reflect.defineMetadata("class", classMeta, modelRef.prototype);
541
+ Reflect.defineMetadata(refName, modelRef, storage.prototype);
542
+ };
543
+ };
544
+ };
545
+ var applyFilterMeta = (storage) => {
546
+ return function(refName) {
547
+ return function(target) {
548
+ const modelRef = target;
549
+ setFilterMeta(modelRef, { refName, sort: {} });
550
+ Reflect.defineMetadata(refName, modelRef, storage.prototype);
551
+ };
552
+ };
553
+ };
554
+ var Model = {
555
+ Light: applyClassMeta("light", "data", LightModelStorage),
556
+ Object: applyClassMeta("full", "ephemeral", FullModelStorage),
557
+ Full: applyClassMeta("full", "data", FullModelStorage),
558
+ Input: applyClassMeta("input", "data", InputModelStorage),
559
+ Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
560
+ Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
561
+ Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
562
+ Filter: applyFilterMeta(FilterModelStorage)
563
+ };
564
+
565
+ // pkgs/@akanjs/test/src/sample.ts
566
+ var import_chance = __toESM(__require("chance"));
567
+ var chance = new import_chance.default();
568
+ var sample = Object.assign(chance, {
569
+ dayjs: (opt) => dayjs(chance.date({ ...opt, min: opt?.min?.toDate(), max: opt?.max?.toDate() })),
570
+ pick: randomPick,
571
+ picks: randomPicks
572
+ });
573
+
574
+ // pkgs/@akanjs/test/src/sampleOf.ts
575
+ var getFieldTypeExample = {
576
+ email: () => sample.email(),
577
+ password: () => sample.string({ length: 8 }),
578
+ url: () => sample.url()
579
+ };
580
+ var scalarSampleMap = /* @__PURE__ */ new Map([
581
+ [ID, () => sample.hash({ length: 24 })],
582
+ [Int, () => sample.integer({ min: -1e4, max: 1e4 })],
583
+ [Float, () => sample.floating({ min: -1e4, max: 1e4 })],
584
+ [String, () => sample.string({ length: 100 })],
585
+ [Boolean, () => sample.bool()],
586
+ [Date, () => sample.dayjs()],
587
+ [Upload, () => "FileUpload"],
588
+ [JSON, () => ({})]
589
+ ]);
590
+ var getScalarSample = (ref, fieldMeta) => {
591
+ if (fieldMeta.type) {
592
+ return getFieldTypeExample[fieldMeta.type]();
593
+ } else if (typeof fieldMeta.min === "number") {
594
+ return fieldMeta.min;
595
+ } else if (typeof fieldMeta.max === "number") {
596
+ return fieldMeta.max;
597
+ } else {
598
+ return scalarSampleMap.get(ref)?.() ?? null;
599
+ }
600
+ };
601
+ var makeSample = (fieldMeta) => {
602
+ if (fieldMeta.default)
603
+ return typeof fieldMeta.default === "function" ? fieldMeta.default() : fieldMeta.default;
604
+ else if (fieldMeta.enum)
605
+ return randomPick([...fieldMeta.enum.values]);
606
+ if (isGqlScalar(fieldMeta.modelRef))
607
+ return getScalarSample(fieldMeta.modelRef, fieldMeta);
608
+ return Object.fromEntries(
609
+ getFieldMetas(fieldMeta.modelRef).map(
610
+ (fieldMeta2) => [
611
+ fieldMeta2.key,
612
+ fieldMeta2.arrDepth ? [] : fieldMeta2.isClass && !fieldMeta2.isScalar ? null : makeSample(fieldMeta2)
613
+ ]
614
+ )
615
+ );
616
+ };
617
+ var sampleOf = (modelRef) => {
618
+ return Object.fromEntries(
619
+ getFieldMetas(modelRef).map((fieldMeta) => [
620
+ fieldMeta.key,
621
+ fieldMeta.arrDepth ? [] : fieldMeta.isClass && !fieldMeta.isScalar ? null : makeSample(fieldMeta)
622
+ ])
623
+ );
624
+ };
625
+ })();
626
+ //! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/test",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,5 +14,10 @@
14
14
  "engines": {
15
15
  "node": ">=22"
16
16
  },
17
- "dependencies": {}
17
+ "dependencies": {
18
+ "chance": "^1.1.12",
19
+ "dayjs": "^1.11.13",
20
+ "pluralize": "^8.0.0",
21
+ "reflect-metadata": "^0.2.2"
22
+ }
18
23
  }
package/src/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export { sampleOf } from './sampleOf.js';
2
- export { sample } from './sample.js';
3
- import 'dayjs';
1
+ export { sampleOf } from "./sampleOf";
2
+ export { sample } from "./sample";