@akanjs/signal 0.0.96 → 0.0.98
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.cjs +17 -0
- package/index.js +1 -17
- package/package.json +3 -3
- package/src/baseFetch.cjs +34 -0
- package/src/baseFetch.js +5 -24
- package/src/{client.mjs → client.cjs} +40 -21
- package/src/client.js +21 -40
- package/src/doc.cjs +101 -0
- package/src/doc.js +23 -42
- package/src/{gql.mjs → gql.cjs} +141 -144
- package/src/gql.js +144 -141
- package/src/immerify.cjs +35 -0
- package/src/immerify.js +7 -26
- package/src/index.cjs +30 -0
- package/src/index.js +9 -29
- package/src/{signalDecorators.mjs → signalDecorators.cjs} +95 -87
- package/src/signalDecorators.js +87 -95
- package/index.mjs +0 -1
- package/src/baseFetch.mjs +0 -15
- package/src/doc.mjs +0 -82
- package/src/immerify.mjs +0 -16
- package/src/index.mjs +0 -10
package/src/{gql.mjs → gql.cjs}
RENAMED
|
@@ -1,30 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var gql_exports = {};
|
|
19
|
+
__export(gql_exports, {
|
|
20
|
+
CrystalizeStorage: () => CrystalizeStorage,
|
|
21
|
+
DefaultStorage: () => DefaultStorage,
|
|
22
|
+
FragmentStorage: () => FragmentStorage,
|
|
23
|
+
GqlStorage: () => GqlStorage,
|
|
24
|
+
PurifyStorage: () => PurifyStorage,
|
|
25
|
+
deserializeArg: () => deserializeArg,
|
|
26
|
+
fetchOf: () => fetchOf,
|
|
27
|
+
getGqlOnStorage: () => getGqlOnStorage,
|
|
28
|
+
getGqlStr: () => getGqlStr,
|
|
29
|
+
gqlOf: () => gqlOf,
|
|
30
|
+
makeCrystalize: () => makeCrystalize,
|
|
31
|
+
makeDefault: () => makeDefault,
|
|
32
|
+
makeFetch: () => makeFetch,
|
|
33
|
+
makeFragment: () => makeFragment,
|
|
34
|
+
makePurify: () => makePurify,
|
|
35
|
+
scalarUtilOf: () => scalarUtilOf,
|
|
36
|
+
serializeArg: () => serializeArg
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(gql_exports);
|
|
39
|
+
var import_base = require("@akanjs/base");
|
|
40
|
+
var import_common = require("@akanjs/common");
|
|
41
|
+
var import_constant = require("@akanjs/constant");
|
|
42
|
+
var import__ = require(".");
|
|
43
|
+
var import_signalDecorators = require("./signalDecorators");
|
|
28
44
|
function graphql(literals, ...args) {
|
|
29
45
|
if (typeof literals === "string")
|
|
30
46
|
literals = [literals];
|
|
@@ -49,12 +65,12 @@ class DefaultStorage {
|
|
|
49
65
|
class CrystalizeStorage {
|
|
50
66
|
}
|
|
51
67
|
const scalarUtilOf = (name, target) => {
|
|
52
|
-
const refName = getClassMeta(target).refName;
|
|
53
|
-
const [fieldName, className] = [lowerlize(refName), capitalize(refName)];
|
|
68
|
+
const refName = (0, import_constant.getClassMeta)(target).refName;
|
|
69
|
+
const [fieldName, className] = [(0, import_common.lowerlize)(refName), (0, import_common.capitalize)(refName)];
|
|
54
70
|
const graphQL = {
|
|
55
71
|
refName,
|
|
56
72
|
[className]: target,
|
|
57
|
-
[`default${className}`]: immerify(target, Object.assign(new target(), makeDefault(target))),
|
|
73
|
+
[`default${className}`]: (0, import__.immerify)(target, Object.assign(new target(), makeDefault(target))),
|
|
58
74
|
[`purify${className}`]: makePurify(target),
|
|
59
75
|
[`crystalize${className}`]: makeCrystalize(target),
|
|
60
76
|
[`${fieldName}Fragment`]: makeFragment(target)
|
|
@@ -72,8 +88,8 @@ const setGqlOnStorage = (refName, modelGql) => {
|
|
|
72
88
|
};
|
|
73
89
|
const gqlOf = (constant, sigRef, option = {}) => {
|
|
74
90
|
const refName = constant.refName;
|
|
75
|
-
const [fieldName, className] = [lowerlize(refName), capitalize(refName)];
|
|
76
|
-
const sigMeta = getSigMeta(sigRef);
|
|
91
|
+
const [fieldName, className] = [(0, import_common.lowerlize)(refName), (0, import_common.capitalize)(refName)];
|
|
92
|
+
const sigMeta = (0, import_signalDecorators.getSigMeta)(sigRef);
|
|
77
93
|
const names = {
|
|
78
94
|
refName,
|
|
79
95
|
model: fieldName,
|
|
@@ -120,7 +136,7 @@ const gqlOf = (constant, sigRef, option = {}) => {
|
|
|
120
136
|
[names.crystalizeModel]: makeCrystalize(constant.Full, option),
|
|
121
137
|
[names.lightCrystalizeModel]: makeCrystalize(constant.Light, option),
|
|
122
138
|
[names.crystalizeModelInsight]: makeCrystalize(constant.Insight, option),
|
|
123
|
-
[names.defaultModel]: immerify(
|
|
139
|
+
[names.defaultModel]: (0, import__.immerify)(
|
|
124
140
|
constant.Full,
|
|
125
141
|
Object.assign(new constant.Full(), makeDefault(constant.Full, option))
|
|
126
142
|
),
|
|
@@ -129,7 +145,7 @@ const gqlOf = (constant, sigRef, option = {}) => {
|
|
|
129
145
|
makeDefault(constant.Insight, option)
|
|
130
146
|
)
|
|
131
147
|
};
|
|
132
|
-
const gql = Object.assign(option.overwrite ?? { client }, fetchOf(sigRef));
|
|
148
|
+
const gql = Object.assign(option.overwrite ?? { client: import__.client }, fetchOf(sigRef));
|
|
133
149
|
const util = {
|
|
134
150
|
[names.addModelFiles]: async (files, id, option2) => {
|
|
135
151
|
const fileGql = getGqlOnStorage("file");
|
|
@@ -237,7 +253,7 @@ const gqlOf = (constant, sigRef, option = {}) => {
|
|
|
237
253
|
const modelInit = await getInitFn(...args);
|
|
238
254
|
const modelObjList = modelInit[names.modelObjList];
|
|
239
255
|
const modelObjInsight = modelInit[names.modelObjInsight];
|
|
240
|
-
const modelList = new DataList(
|
|
256
|
+
const modelList = new import_base.DataList(
|
|
241
257
|
modelObjList.map((modelObj) => base[names.lightCrystalizeModel](modelObj))
|
|
242
258
|
);
|
|
243
259
|
const modelInsight = base[names.crystalizeModelInsight](modelObjInsight);
|
|
@@ -273,13 +289,13 @@ const setPredefinedDefault = (refName, defaultData) => {
|
|
|
273
289
|
Reflect.defineMetadata(refName, defaultData, DefaultStorage.prototype);
|
|
274
290
|
};
|
|
275
291
|
const makeDefault = (target, option = {}) => {
|
|
276
|
-
const classMeta = getClassMeta(target);
|
|
292
|
+
const classMeta = (0, import_constant.getClassMeta)(target);
|
|
277
293
|
const predefinedDefault = getPredefinedDefault(classMeta.refName);
|
|
278
294
|
if (predefinedDefault && !option.overwrite)
|
|
279
295
|
return predefinedDefault;
|
|
280
296
|
if (option.isChild && classMeta.type !== "scalar")
|
|
281
297
|
return null;
|
|
282
|
-
const metadatas = getFieldMetas(target);
|
|
298
|
+
const metadatas = (0, import_constant.getFieldMetas)(target);
|
|
283
299
|
const result = {};
|
|
284
300
|
for (const metadata of metadatas) {
|
|
285
301
|
if (metadata.fieldType === "hidden")
|
|
@@ -287,7 +303,7 @@ const makeDefault = (target, option = {}) => {
|
|
|
287
303
|
else if (metadata.default) {
|
|
288
304
|
if (typeof metadata.default === "function")
|
|
289
305
|
result[metadata.key] = metadata.default();
|
|
290
|
-
else if (metadata.default instanceof Enum)
|
|
306
|
+
else if (metadata.default instanceof import_base.Enum)
|
|
291
307
|
result[metadata.key] = [...metadata.default.values];
|
|
292
308
|
else
|
|
293
309
|
result[metadata.key] = metadata.default;
|
|
@@ -298,7 +314,7 @@ const makeDefault = (target, option = {}) => {
|
|
|
298
314
|
else if (metadata.isClass)
|
|
299
315
|
result[metadata.key] = metadata.isScalar ? makeDefault(metadata.modelRef) : null;
|
|
300
316
|
else
|
|
301
|
-
result[metadata.key] = scalarDefaultMap.get(metadata.modelRef);
|
|
317
|
+
result[metadata.key] = import_base.scalarDefaultMap.get(metadata.modelRef);
|
|
302
318
|
}
|
|
303
319
|
setPredefinedDefault(classMeta.refName, result);
|
|
304
320
|
return result;
|
|
@@ -354,16 +370,16 @@ const mutate = async (fetchClient, mutation, variables = {}, option = {}) => {
|
|
|
354
370
|
return data;
|
|
355
371
|
};
|
|
356
372
|
const scalarPurifyMap = /* @__PURE__ */ new Map([
|
|
357
|
-
[Date, (value) => dayjs(value).toDate()],
|
|
373
|
+
[Date, (value) => (0, import_base.dayjs)(value).toDate()],
|
|
358
374
|
[String, (value) => value],
|
|
359
|
-
[ID, (value) => value],
|
|
375
|
+
[import_base.ID, (value) => value],
|
|
360
376
|
[Boolean, (value) => value],
|
|
361
|
-
[Int, (value) => value],
|
|
362
|
-
[Float, (value) => value],
|
|
363
|
-
[
|
|
377
|
+
[import_base.Int, (value) => value],
|
|
378
|
+
[import_base.Float, (value) => value],
|
|
379
|
+
[import_base.JSON, (value) => value]
|
|
364
380
|
]);
|
|
365
381
|
const getPurifyFn = (modelRef) => {
|
|
366
|
-
const [valueRef] = getNonArrayModel(modelRef);
|
|
382
|
+
const [valueRef] = (0, import_base.getNonArrayModel)(modelRef);
|
|
367
383
|
return scalarPurifyMap.get(valueRef) ?? ((value) => value);
|
|
368
384
|
};
|
|
369
385
|
const purify = (metadata, value, self) => {
|
|
@@ -383,12 +399,12 @@ const purify = (metadata, value, self) => {
|
|
|
383
399
|
if (metadata.isMap && metadata.of) {
|
|
384
400
|
const purifyFn2 = getPurifyFn(metadata.of);
|
|
385
401
|
return Object.fromEntries(
|
|
386
|
-
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, purifyFn2)])
|
|
402
|
+
[...value.entries()].map(([key, val]) => [key, (0, import_base.applyFnToArrayObjects)(val, purifyFn2)])
|
|
387
403
|
);
|
|
388
404
|
}
|
|
389
405
|
if (metadata.isClass)
|
|
390
406
|
return makePurify(metadata.modelRef)(value, true);
|
|
391
|
-
if (metadata.name === "Date" && dayjs(value).isBefore(dayjs(/* @__PURE__ */ new Date("0000"))))
|
|
407
|
+
if (metadata.name === "Date" && (0, import_base.dayjs)(value).isBefore((0, import_base.dayjs)(/* @__PURE__ */ new Date("0000"))))
|
|
392
408
|
throw new Error(`Invalid Date Value (Default) in ${metadata.key} for value ${value}`);
|
|
393
409
|
if (["String", "ID"].includes(metadata.name) && (value === "" || !value))
|
|
394
410
|
throw new Error(`Invalid String Value (Default) in ${metadata.key} for value ${value}`);
|
|
@@ -407,11 +423,11 @@ const setPredefinedPurifyFn = (refName, purify2) => {
|
|
|
407
423
|
Reflect.defineMetadata(refName, purify2, PurifyStorage.prototype);
|
|
408
424
|
};
|
|
409
425
|
const makePurify = (target, option = {}) => {
|
|
410
|
-
const classMeta = getClassMeta(target);
|
|
426
|
+
const classMeta = (0, import_constant.getClassMeta)(target);
|
|
411
427
|
const purifyFn = getPredefinedPurifyFn(classMeta.refName);
|
|
412
428
|
if (purifyFn && !option.overwrite)
|
|
413
429
|
return purifyFn;
|
|
414
|
-
const metadatas = getFieldMetas(target);
|
|
430
|
+
const metadatas = (0, import_constant.getFieldMetas)(target);
|
|
415
431
|
const fn = (self, isChild) => {
|
|
416
432
|
try {
|
|
417
433
|
if (isChild && classMeta.type !== "scalar") {
|
|
@@ -429,7 +445,7 @@ const makePurify = (target, option = {}) => {
|
|
|
429
445
|
} catch (err) {
|
|
430
446
|
if (isChild)
|
|
431
447
|
throw new Error(err);
|
|
432
|
-
Logger.debug(err);
|
|
448
|
+
import_common.Logger.debug(err);
|
|
433
449
|
return null;
|
|
434
450
|
}
|
|
435
451
|
};
|
|
@@ -437,13 +453,13 @@ const makePurify = (target, option = {}) => {
|
|
|
437
453
|
return fn;
|
|
438
454
|
};
|
|
439
455
|
const scalarCrystalizeMap = /* @__PURE__ */ new Map([
|
|
440
|
-
[Date, (value) => dayjs(value)],
|
|
456
|
+
[Date, (value) => (0, import_base.dayjs)(value)],
|
|
441
457
|
[String, (value) => value],
|
|
442
|
-
[ID, (value) => value],
|
|
458
|
+
[import_base.ID, (value) => value],
|
|
443
459
|
[Boolean, (value) => value],
|
|
444
|
-
[Int, (value) => value],
|
|
445
|
-
[Float, (value) => value],
|
|
446
|
-
[
|
|
460
|
+
[import_base.Int, (value) => value],
|
|
461
|
+
[import_base.Float, (value) => value],
|
|
462
|
+
[import_base.JSON, (value) => value]
|
|
447
463
|
]);
|
|
448
464
|
const crystalize = (metadata, value) => {
|
|
449
465
|
if (value === void 0 || value === null)
|
|
@@ -451,16 +467,16 @@ const crystalize = (metadata, value) => {
|
|
|
451
467
|
if (metadata.isArray && Array.isArray(value))
|
|
452
468
|
return value.map((v) => crystalize({ ...metadata, isArray: false }, v));
|
|
453
469
|
if (metadata.isMap) {
|
|
454
|
-
const [valueRef] = getNonArrayModel(metadata.of);
|
|
470
|
+
const [valueRef] = (0, import_base.getNonArrayModel)(metadata.of);
|
|
455
471
|
const crystalizeValue = scalarCrystalizeMap.get(valueRef) ?? ((value2) => value2);
|
|
456
472
|
return new Map(
|
|
457
|
-
Object.entries(value).map(([key, val]) => [key, applyFnToArrayObjects(val, crystalizeValue)])
|
|
473
|
+
Object.entries(value).map(([key, val]) => [key, (0, import_base.applyFnToArrayObjects)(val, crystalizeValue)])
|
|
458
474
|
);
|
|
459
475
|
}
|
|
460
476
|
if (metadata.isClass)
|
|
461
477
|
return makeCrystalize(metadata.modelRef)(value, true);
|
|
462
478
|
if (metadata.name === "Date")
|
|
463
|
-
return dayjs(value);
|
|
479
|
+
return (0, import_base.dayjs)(value);
|
|
464
480
|
return (scalarCrystalizeMap.get(metadata.modelRef) ?? ((value2) => value2))(value);
|
|
465
481
|
};
|
|
466
482
|
const getPredefinedCrystalizeFn = (refName) => {
|
|
@@ -471,11 +487,11 @@ const setPredefinedCrystalizeFn = (refName, crystalize2) => {
|
|
|
471
487
|
Reflect.defineMetadata(refName, crystalize2, CrystalizeStorage.prototype);
|
|
472
488
|
};
|
|
473
489
|
const makeCrystalize = (target, option = {}) => {
|
|
474
|
-
const classMeta = getClassMeta(target);
|
|
490
|
+
const classMeta = (0, import_constant.getClassMeta)(target);
|
|
475
491
|
const crystalizeFn = getPredefinedCrystalizeFn(classMeta.refName);
|
|
476
492
|
if (crystalizeFn && !option.overwrite && !option.partial?.length)
|
|
477
493
|
return crystalizeFn;
|
|
478
|
-
const fieldMetaMap = getFieldMetaMap(target);
|
|
494
|
+
const fieldMetaMap = (0, import_constant.getFieldMetaMap)(target);
|
|
479
495
|
const fieldKeys = option.partial?.length ? classMeta.type === "scalar" ? option.partial : ["id", ...option.partial, "updatedAt"] : [...fieldMetaMap.keys()];
|
|
480
496
|
const metadatas = fieldKeys.map((key) => fieldMetaMap.get(key));
|
|
481
497
|
const fn = (self, isChild) => {
|
|
@@ -498,16 +514,16 @@ const makeCrystalize = (target, option = {}) => {
|
|
|
498
514
|
return fn;
|
|
499
515
|
};
|
|
500
516
|
const fragmentize = (target, fragMap = /* @__PURE__ */ new Map(), partial) => {
|
|
501
|
-
const classMeta = getClassMeta(target);
|
|
502
|
-
const metadatas = getFieldMetas(target);
|
|
517
|
+
const classMeta = (0, import_constant.getClassMeta)(target);
|
|
518
|
+
const metadatas = (0, import_constant.getFieldMetas)(target);
|
|
503
519
|
const selectKeys = partial ? ["id", ...partial, "updatedAt"] : metadatas.map((metadata) => metadata.key);
|
|
504
520
|
const selectKeySet = new Set(selectKeys);
|
|
505
|
-
const fragment = `fragment ${lowerlize(classMeta.refName)}Fragment on ${capitalize(
|
|
521
|
+
const fragment = `fragment ${(0, import_common.lowerlize)(classMeta.refName)}Fragment on ${(0, import_common.capitalize)(
|
|
506
522
|
classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName
|
|
507
523
|
)} {
|
|
508
524
|
` + metadatas.filter((metadata) => metadata.fieldType !== "hidden" && selectKeySet.has(metadata.key)).map((metadata) => {
|
|
509
525
|
return metadata.isClass ? ` ${metadata.key} {
|
|
510
|
-
...${lowerlize(metadata.name)}Fragment
|
|
526
|
+
...${(0, import_common.lowerlize)(metadata.name)}Fragment
|
|
511
527
|
}` : ` ${metadata.key}`;
|
|
512
528
|
}).join(`
|
|
513
529
|
`) + `
|
|
@@ -524,7 +540,7 @@ const setPredefinedFragment = (refName, fragment) => {
|
|
|
524
540
|
Reflect.defineMetadata(refName, fragment, FragmentStorage.prototype);
|
|
525
541
|
};
|
|
526
542
|
const makeFragment = (target, option = {}) => {
|
|
527
|
-
const classMeta = getClassMeta(target);
|
|
543
|
+
const classMeta = (0, import_constant.getClassMeta)(target);
|
|
528
544
|
const fragment = getPredefinedFragment(classMeta.refName);
|
|
529
545
|
if (fragment && !option.overwrite && !option.excludeSelf && !option.partial?.length)
|
|
530
546
|
return fragment;
|
|
@@ -537,25 +553,25 @@ const makeFragment = (target, option = {}) => {
|
|
|
537
553
|
return gqlStr;
|
|
538
554
|
};
|
|
539
555
|
const getGqlStr = (modelRef, gqlMeta, argMetas, returnRef, partial) => {
|
|
540
|
-
const isScalar = isGqlScalar(modelRef);
|
|
556
|
+
const isScalar = (0, import_base.isGqlScalar)(modelRef);
|
|
541
557
|
const argStr = makeArgStr(argMetas);
|
|
542
558
|
const argAssignStr = makeArgAssignStr(argMetas);
|
|
543
559
|
const returnStr = makeReturnStr(returnRef, partial);
|
|
544
560
|
const gqlStr = `${isScalar ? "" : makeFragment(returnRef, { excludeSelf: !!partial?.length, partial })}
|
|
545
|
-
${lowerlize(gqlMeta.type) + " " + gqlMeta.key + argStr}{
|
|
561
|
+
${(0, import_common.lowerlize)(gqlMeta.type) + " " + gqlMeta.key + argStr}{
|
|
546
562
|
${gqlMeta.key}${argAssignStr}${returnStr}
|
|
547
563
|
}
|
|
548
564
|
`;
|
|
549
565
|
return gqlStr;
|
|
550
566
|
};
|
|
551
567
|
const scalarSerializeMap = /* @__PURE__ */ new Map([
|
|
552
|
-
[Date, (value) => dayjs(value).toDate()],
|
|
568
|
+
[Date, (value) => (0, import_base.dayjs)(value).toDate()],
|
|
553
569
|
[String, (value) => value],
|
|
554
|
-
[ID, (value) => value],
|
|
570
|
+
[import_base.ID, (value) => value],
|
|
555
571
|
[Boolean, (value) => value],
|
|
556
|
-
[Int, (value) => value],
|
|
557
|
-
[Float, (value) => value],
|
|
558
|
-
[
|
|
572
|
+
[import_base.Int, (value) => value],
|
|
573
|
+
[import_base.Float, (value) => value],
|
|
574
|
+
[import_base.JSON, (value) => value]
|
|
559
575
|
]);
|
|
560
576
|
const getSerializeFn = (inputRef) => {
|
|
561
577
|
const serializeFn = scalarSerializeMap.get(inputRef);
|
|
@@ -568,28 +584,28 @@ const serializeInput = (value, inputRef, arrDepth) => {
|
|
|
568
584
|
if (arrDepth && Array.isArray(value))
|
|
569
585
|
return value.map((v) => serializeInput(v, inputRef, arrDepth - 1));
|
|
570
586
|
else if (inputRef.prototype === Map.prototype) {
|
|
571
|
-
const [valueRef] = getNonArrayModel(inputRef);
|
|
587
|
+
const [valueRef] = (0, import_base.getNonArrayModel)(inputRef);
|
|
572
588
|
const serializeFn = getSerializeFn(valueRef);
|
|
573
589
|
return Object.fromEntries(
|
|
574
|
-
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, serializeFn)])
|
|
590
|
+
[...value.entries()].map(([key, val]) => [key, (0, import_base.applyFnToArrayObjects)(val, serializeFn)])
|
|
575
591
|
);
|
|
576
|
-
} else if (isGqlScalar(inputRef)) {
|
|
592
|
+
} else if ((0, import_base.isGqlScalar)(inputRef)) {
|
|
577
593
|
const serializeFn = getSerializeFn(inputRef);
|
|
578
594
|
return serializeFn(value);
|
|
579
595
|
}
|
|
580
|
-
const classMeta = getClassMeta(inputRef);
|
|
596
|
+
const classMeta = (0, import_constant.getClassMeta)(inputRef);
|
|
581
597
|
if (classMeta.type !== "scalar")
|
|
582
598
|
return value;
|
|
583
599
|
else
|
|
584
600
|
return Object.fromEntries(
|
|
585
|
-
getFieldMetas(inputRef).map((fieldMeta) => [
|
|
601
|
+
(0, import_constant.getFieldMetas)(inputRef).map((fieldMeta) => [
|
|
586
602
|
fieldMeta.key,
|
|
587
603
|
serializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
|
|
588
604
|
])
|
|
589
605
|
);
|
|
590
606
|
};
|
|
591
607
|
const serializeArg = (argMeta, value) => {
|
|
592
|
-
const [returnRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
608
|
+
const [returnRef, arrDepth] = (0, import_base.getNonArrayModel)(argMeta.returns());
|
|
593
609
|
if (argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
594
610
|
return null;
|
|
595
611
|
else if (!argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
@@ -597,13 +613,13 @@ const serializeArg = (argMeta, value) => {
|
|
|
597
613
|
return serializeInput(value, returnRef, arrDepth);
|
|
598
614
|
};
|
|
599
615
|
const scalarDeserializeMap = /* @__PURE__ */ new Map([
|
|
600
|
-
[Date, (value) => dayjs(value)],
|
|
616
|
+
[Date, (value) => (0, import_base.dayjs)(value)],
|
|
601
617
|
[String, (value) => value],
|
|
602
|
-
[ID, (value) => value],
|
|
618
|
+
[import_base.ID, (value) => value],
|
|
603
619
|
[Boolean, (value) => value],
|
|
604
|
-
[Int, (value) => value],
|
|
605
|
-
[Float, (value) => value],
|
|
606
|
-
[
|
|
620
|
+
[import_base.Int, (value) => value],
|
|
621
|
+
[import_base.Float, (value) => value],
|
|
622
|
+
[import_base.JSON, (value) => value]
|
|
607
623
|
]);
|
|
608
624
|
const getDeserializeFn = (inputRef) => {
|
|
609
625
|
const deserializeFn = scalarDeserializeMap.get(inputRef);
|
|
@@ -615,28 +631,28 @@ const deserializeInput = (value, inputRef, arrDepth) => {
|
|
|
615
631
|
if (arrDepth && Array.isArray(value))
|
|
616
632
|
return value.map((v) => deserializeInput(v, inputRef, arrDepth - 1));
|
|
617
633
|
else if (inputRef.prototype === Map.prototype) {
|
|
618
|
-
const [valueRef] = getNonArrayModel(inputRef);
|
|
634
|
+
const [valueRef] = (0, import_base.getNonArrayModel)(inputRef);
|
|
619
635
|
const deserializeFn = getDeserializeFn(valueRef);
|
|
620
636
|
return Object.fromEntries(
|
|
621
|
-
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, deserializeFn)])
|
|
637
|
+
[...value.entries()].map(([key, val]) => [key, (0, import_base.applyFnToArrayObjects)(val, deserializeFn)])
|
|
622
638
|
);
|
|
623
|
-
} else if (isGqlScalar(inputRef)) {
|
|
639
|
+
} else if ((0, import_base.isGqlScalar)(inputRef)) {
|
|
624
640
|
const deserializeFn = getDeserializeFn(inputRef);
|
|
625
641
|
return deserializeFn(value);
|
|
626
642
|
}
|
|
627
|
-
const classMeta = getClassMeta(inputRef);
|
|
643
|
+
const classMeta = (0, import_constant.getClassMeta)(inputRef);
|
|
628
644
|
if (classMeta.type !== "scalar")
|
|
629
645
|
return value;
|
|
630
646
|
else
|
|
631
647
|
return Object.fromEntries(
|
|
632
|
-
getFieldMetas(inputRef).map((fieldMeta) => [
|
|
648
|
+
(0, import_constant.getFieldMetas)(inputRef).map((fieldMeta) => [
|
|
633
649
|
fieldMeta.key,
|
|
634
650
|
deserializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
|
|
635
651
|
])
|
|
636
652
|
);
|
|
637
653
|
};
|
|
638
654
|
const deserializeArg = (argMeta, value) => {
|
|
639
|
-
const [returnRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
655
|
+
const [returnRef, arrDepth] = (0, import_base.getNonArrayModel)(argMeta.returns());
|
|
640
656
|
if (argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
641
657
|
return null;
|
|
642
658
|
else if (!argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
@@ -645,16 +661,16 @@ const deserializeArg = (argMeta, value) => {
|
|
|
645
661
|
};
|
|
646
662
|
const fetchOf = (sigRef) => {
|
|
647
663
|
const gqls = {};
|
|
648
|
-
const gqlMetas = getGqlMetas(sigRef);
|
|
664
|
+
const gqlMetas = (0, import_signalDecorators.getGqlMetas)(sigRef);
|
|
649
665
|
gqlMetas.filter((gqlMeta) => !gqlMeta.signalOption.default).forEach((gqlMeta) => {
|
|
650
666
|
if (gqlMeta.type === "Message") {
|
|
651
|
-
const [returnRef, arrDepth] = getNonArrayModel(gqlMeta.returns());
|
|
652
|
-
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
653
|
-
const isScalar = isGqlScalar(returnRef);
|
|
667
|
+
const [returnRef, arrDepth] = (0, import_base.getNonArrayModel)(gqlMeta.returns());
|
|
668
|
+
const [argMetas] = (0, import_signalDecorators.getArgMetas)(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
669
|
+
const isScalar = (0, import_base.isGqlScalar)(returnRef);
|
|
654
670
|
const emitEvent = function(...args) {
|
|
655
671
|
const fetchPolicy = args[argMetas.length] ?? { crystalize: true };
|
|
656
672
|
if (!this.client.io && !fetchPolicy.url) {
|
|
657
|
-
Logger.warn(`${gqlMeta.key} emit suppressed - socket is not connected`);
|
|
673
|
+
import_common.Logger.warn(`${gqlMeta.key} emit suppressed - socket is not connected`);
|
|
658
674
|
return;
|
|
659
675
|
}
|
|
660
676
|
const message = Object.fromEntries(
|
|
@@ -666,13 +682,13 @@ const fetchOf = (sigRef) => {
|
|
|
666
682
|
const uri = fetchPolicy.url ?? "udpout:localhost:4000";
|
|
667
683
|
const [host, port] = uri.split(":").slice(1);
|
|
668
684
|
this.client.udp.send(JSON.stringify(message), parseInt(port), host);
|
|
669
|
-
Logger.debug(`udp emit: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
685
|
+
import_common.Logger.debug(`udp emit: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
670
686
|
return;
|
|
671
687
|
} else {
|
|
672
688
|
const io = this.client.getIo(fetchPolicy.url);
|
|
673
689
|
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
674
690
|
io.emit(gqlMeta.key, message);
|
|
675
|
-
Logger.debug(`socket emit: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
691
|
+
import_common.Logger.debug(`socket emit: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
676
692
|
});
|
|
677
693
|
}
|
|
678
694
|
};
|
|
@@ -680,7 +696,7 @@ const fetchOf = (sigRef) => {
|
|
|
680
696
|
const crystalize2 = (data) => {
|
|
681
697
|
if (isScalar) {
|
|
682
698
|
if (returnRef.prototype === Date.prototype)
|
|
683
|
-
return dayjs(data);
|
|
699
|
+
return (0, import_base.dayjs)(data);
|
|
684
700
|
else
|
|
685
701
|
return data;
|
|
686
702
|
} else if (Array.isArray(data))
|
|
@@ -689,32 +705,32 @@ const fetchOf = (sigRef) => {
|
|
|
689
705
|
return makeCrystalize(returnRef)(data);
|
|
690
706
|
};
|
|
691
707
|
const handle = (data) => {
|
|
692
|
-
Logger.debug(`socket listened: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
708
|
+
import_common.Logger.debug(`socket listened: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
693
709
|
handleEvent(crystalize2(data));
|
|
694
710
|
};
|
|
695
711
|
const io = this.client.getIo(fetchPolicy.url);
|
|
696
712
|
this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
697
713
|
io.removeListener(gqlMeta.key, handle);
|
|
698
714
|
io.on(gqlMeta.key, handle);
|
|
699
|
-
Logger.debug(`socket listen start: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
715
|
+
import_common.Logger.debug(`socket listen start: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
700
716
|
});
|
|
701
717
|
return async () => {
|
|
702
718
|
await this.client.waitUntilWebSocketConnected(fetchPolicy.url);
|
|
703
|
-
Logger.debug(`socket listen end: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
719
|
+
import_common.Logger.debug(`socket listen end: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
704
720
|
io.removeListener(gqlMeta.key, handle);
|
|
705
721
|
};
|
|
706
722
|
};
|
|
707
723
|
gqls[gqlMeta.key] = emitEvent;
|
|
708
|
-
gqls[`listen${capitalize(gqlMeta.key)}`] = listenEvent;
|
|
724
|
+
gqls[`listen${(0, import_common.capitalize)(gqlMeta.key)}`] = listenEvent;
|
|
709
725
|
} else if (gqlMeta.type === "Pubsub") {
|
|
710
|
-
const [returnRef] = getNonArrayModel(gqlMeta.returns());
|
|
711
|
-
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
712
|
-
const isScalar = isGqlScalar(returnRef);
|
|
726
|
+
const [returnRef] = (0, import_base.getNonArrayModel)(gqlMeta.returns());
|
|
727
|
+
const [argMetas] = (0, import_signalDecorators.getArgMetas)(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
728
|
+
const isScalar = (0, import_base.isGqlScalar)(returnRef);
|
|
713
729
|
const makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
714
730
|
const crystalize2 = (data) => {
|
|
715
731
|
if (isScalar) {
|
|
716
732
|
if (returnRef.prototype === Date.prototype)
|
|
717
|
-
return dayjs(data);
|
|
733
|
+
return (0, import_base.dayjs)(data);
|
|
718
734
|
else
|
|
719
735
|
return data;
|
|
720
736
|
} else if (Array.isArray(data))
|
|
@@ -739,26 +755,26 @@ const fetchOf = (sigRef) => {
|
|
|
739
755
|
);
|
|
740
756
|
const io = this.client.getIo(fetchPolicy.url);
|
|
741
757
|
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
742
|
-
Logger.debug(`socket subscribe start: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
758
|
+
import_common.Logger.debug(`socket subscribe start: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
743
759
|
io.subscribe({ key: gqlMeta.key, roomId, message, handleEvent });
|
|
744
760
|
});
|
|
745
761
|
return async () => {
|
|
746
762
|
//! 앱에서 다른 앱 넘어갈 때 언마운트 되버리면서 subscribe가 끊기는 일이 있음.
|
|
747
763
|
await this.client.waitUntilWebSocketConnected(fetchPolicy.url);
|
|
748
|
-
Logger.debug(`socket unsubscribe: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
764
|
+
import_common.Logger.debug(`socket unsubscribe: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
749
765
|
io.unsubscribe(roomId, handleEvent);
|
|
750
766
|
};
|
|
751
767
|
};
|
|
752
|
-
gqls[`subscribe${capitalize(gqlMeta.key)}`] = subscribeEvent;
|
|
768
|
+
gqls[`subscribe${(0, import_common.capitalize)(gqlMeta.key)}`] = subscribeEvent;
|
|
753
769
|
} else if (gqlMeta.type === "Query" || gqlMeta.type === "Mutation") {
|
|
754
770
|
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
755
771
|
const makeReq = ({ resolve }) => async function(...args) {
|
|
756
|
-
Logger.debug(`fetch: ${gqlMeta.key} start: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
772
|
+
import_common.Logger.debug(`fetch: ${gqlMeta.key} start: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
757
773
|
const now = Date.now();
|
|
758
|
-
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
759
|
-
const [modelRef, arrDepth] = getNonArrayModel(gqlMeta.returns());
|
|
760
|
-
const isScalar = isGqlScalar(modelRef);
|
|
761
|
-
const returnRef = isScalar || !arrDepth ? modelRef : getLightModelRef(modelRef);
|
|
774
|
+
const [argMetas] = (0, import_signalDecorators.getArgMetas)(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
775
|
+
const [modelRef, arrDepth] = (0, import_base.getNonArrayModel)(gqlMeta.returns());
|
|
776
|
+
const isScalar = (0, import_base.isGqlScalar)(modelRef);
|
|
777
|
+
const returnRef = isScalar || !arrDepth ? modelRef : (0, import_constant.getLightModelRef)(modelRef);
|
|
762
778
|
const fetchPolicy = args[argMetas.length] ?? { crystalize: true };
|
|
763
779
|
const partial = fetchPolicy.partial ?? gqlMeta.signalOption.partial;
|
|
764
780
|
const crystalize2 = (data) => {
|
|
@@ -766,7 +782,7 @@ const fetchOf = (sigRef) => {
|
|
|
766
782
|
return data;
|
|
767
783
|
if (isScalar) {
|
|
768
784
|
if (returnRef.prototype === Date.prototype)
|
|
769
|
-
return dayjs(data);
|
|
785
|
+
return (0, import_base.dayjs)(data);
|
|
770
786
|
else
|
|
771
787
|
return data;
|
|
772
788
|
} else if (Array.isArray(data))
|
|
@@ -784,12 +800,12 @@ const fetchOf = (sigRef) => {
|
|
|
784
800
|
fetchPolicy
|
|
785
801
|
))[name];
|
|
786
802
|
const data = resolve ? crystalize2(res) : res;
|
|
787
|
-
Logger.debug(
|
|
788
|
-
`fetch: ${gqlMeta.key} end: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")} ${Date.now() - now}ms`
|
|
803
|
+
import_common.Logger.debug(
|
|
804
|
+
`fetch: ${gqlMeta.key} end: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")} ${Date.now() - now}ms`
|
|
789
805
|
);
|
|
790
806
|
return data;
|
|
791
807
|
} catch (e) {
|
|
792
|
-
Logger.error(`fetch: ${gqlMeta.key} error: ${e}`);
|
|
808
|
+
import_common.Logger.error(`fetch: ${gqlMeta.key} error: ${e}`);
|
|
793
809
|
throw e;
|
|
794
810
|
}
|
|
795
811
|
};
|
|
@@ -804,9 +820,9 @@ const makeFetch = (fetch1, fetch2, fetch3, fetch4, fetch5, fetch6, fetch7, fetch
|
|
|
804
820
|
};
|
|
805
821
|
const makeArgStr = (argMetas) => {
|
|
806
822
|
return argMetas.length ? `(${argMetas.map((argMeta) => {
|
|
807
|
-
const [argRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
808
|
-
const argRefType = isGqlScalar(argRef) ? "gqlScalar" : getClassMeta(argRef).type === "scalar" ? "scalar" : "model";
|
|
809
|
-
const gqlTypeStr = "[".repeat(arrDepth) + (getGqlTypeStr(argRef) + (argRefType === "scalar" ? "Input" : "")) + "!]".repeat(arrDepth);
|
|
823
|
+
const [argRef, arrDepth] = (0, import_base.getNonArrayModel)(argMeta.returns());
|
|
824
|
+
const argRefType = (0, import_base.isGqlScalar)(argRef) ? "gqlScalar" : (0, import_constant.getClassMeta)(argRef).type === "scalar" ? "scalar" : "model";
|
|
825
|
+
const gqlTypeStr = "[".repeat(arrDepth) + ((0, import_constant.getGqlTypeStr)(argRef) + (argRefType === "scalar" ? "Input" : "")) + "!]".repeat(arrDepth);
|
|
810
826
|
return `$${argMeta.name}: ` + gqlTypeStr + (argMeta.argsOption.nullable ? "" : "!");
|
|
811
827
|
}).join(", ")})` : "";
|
|
812
828
|
};
|
|
@@ -814,40 +830,21 @@ const makeArgAssignStr = (argMetas) => {
|
|
|
814
830
|
return argMetas.length ? `(${argMetas.map((argMeta) => `${argMeta.name}: $${argMeta.name}`).join(", ")})` : "";
|
|
815
831
|
};
|
|
816
832
|
const makeReturnStr = (returnRef, partial) => {
|
|
817
|
-
const isScalar = isGqlScalar(returnRef);
|
|
833
|
+
const isScalar = (0, import_base.isGqlScalar)(returnRef);
|
|
818
834
|
if (isScalar)
|
|
819
835
|
return "";
|
|
820
|
-
const classMeta = getClassMeta(returnRef);
|
|
836
|
+
const classMeta = (0, import_constant.getClassMeta)(returnRef);
|
|
821
837
|
if (!partial?.length)
|
|
822
838
|
return ` {
|
|
823
|
-
...${lowerlize(classMeta.refName)}Fragment
|
|
839
|
+
...${(0, import_common.lowerlize)(classMeta.refName)}Fragment
|
|
824
840
|
}`;
|
|
825
841
|
const targetKeys = classMeta.type === "scalar" ? partial : [.../* @__PURE__ */ new Set(["id", ...partial, "updatedAt"])];
|
|
826
|
-
const fieldMetaMap = getFieldMetaMap(returnRef);
|
|
842
|
+
const fieldMetaMap = (0, import_constant.getFieldMetaMap)(returnRef);
|
|
827
843
|
return ` {
|
|
828
844
|
${targetKeys.map((key) => fieldMetaMap.get(key)).filter((metadata) => metadata && metadata.fieldType !== "hidden").map(
|
|
829
845
|
(fieldMeta) => fieldMeta.isClass ? ` ${fieldMeta.key} {
|
|
830
|
-
...${lowerlize(fieldMeta.name)}Fragment
|
|
846
|
+
...${(0, import_common.lowerlize)(fieldMeta.name)}Fragment
|
|
831
847
|
}` : ` ${fieldMeta.key}`
|
|
832
848
|
).join("\n")}
|
|
833
849
|
}`;
|
|
834
850
|
};
|
|
835
|
-
export {
|
|
836
|
-
CrystalizeStorage,
|
|
837
|
-
DefaultStorage,
|
|
838
|
-
FragmentStorage,
|
|
839
|
-
GqlStorage,
|
|
840
|
-
PurifyStorage,
|
|
841
|
-
deserializeArg,
|
|
842
|
-
fetchOf,
|
|
843
|
-
getGqlOnStorage,
|
|
844
|
-
getGqlStr,
|
|
845
|
-
gqlOf,
|
|
846
|
-
makeCrystalize,
|
|
847
|
-
makeDefault,
|
|
848
|
-
makeFetch,
|
|
849
|
-
makeFragment,
|
|
850
|
-
makePurify,
|
|
851
|
-
scalarUtilOf,
|
|
852
|
-
serializeArg
|
|
853
|
-
};
|