@akanjs/signal 1.0.5 → 1.0.6
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/cjs/src/doc.js +15 -17
- package/cjs/src/fetchInfo.js +11 -8
- package/cjs/src/graphql.js +10 -12
- package/cjs/src/immerify.js +3 -5
- package/esm/src/doc.js +16 -18
- package/esm/src/fetchInfo.js +12 -9
- package/esm/src/graphql.js +11 -13
- package/esm/src/immerify.js +3 -5
- package/package.json +1 -1
- package/src/gql.d.ts +4 -4
- package/src/immerify.d.ts +2 -2
- package/src/signalDecorators.d.ts +2 -2
- package/src/signalInfo.d.ts +10 -4
package/cjs/src/doc.js
CHANGED
|
@@ -40,15 +40,14 @@ const getResponseExample = (ref) => {
|
|
|
40
40
|
const isScalar = (0, import_base.isGqlScalar)(modelRef);
|
|
41
41
|
if (isScalar)
|
|
42
42
|
return (0, import_base.arraiedModel)((0, import_constant.getScalarExample)(modelRef), arrDepth);
|
|
43
|
-
const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
|
|
44
43
|
const example = {};
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
example[
|
|
48
|
-
else if (
|
|
49
|
-
example[
|
|
44
|
+
Object.entries(modelRef.field).forEach(([key, field]) => {
|
|
45
|
+
if (field.example)
|
|
46
|
+
example[key] = field.example;
|
|
47
|
+
else if (field.enum)
|
|
48
|
+
example[key] = (0, import_base.arraiedModel)(field.enum.values[0], field.arrDepth);
|
|
50
49
|
else
|
|
51
|
-
example[
|
|
50
|
+
example[key] = getResponseExample(field.modelRef);
|
|
52
51
|
});
|
|
53
52
|
const result = (0, import_base.arraiedModel)(example, arrDepth);
|
|
54
53
|
Reflect.defineMetadata(ref, result, ResponseExampleStorage.prototype);
|
|
@@ -56,24 +55,23 @@ const getResponseExample = (ref) => {
|
|
|
56
55
|
};
|
|
57
56
|
class RequestExampleStorage {
|
|
58
57
|
}
|
|
59
|
-
const getRequestExample = (
|
|
60
|
-
const existing = getPredefinedRequestExample(
|
|
58
|
+
const getRequestExample = (modelRef) => {
|
|
59
|
+
const existing = getPredefinedRequestExample(modelRef);
|
|
61
60
|
if (existing)
|
|
62
61
|
return existing;
|
|
63
|
-
const fieldMetas = (0, import_constant.getFieldMetas)(ref);
|
|
64
62
|
const example = {};
|
|
65
|
-
const isScalar = (0, import_base.isGqlScalar)(
|
|
63
|
+
const isScalar = (0, import_base.isGqlScalar)(modelRef);
|
|
66
64
|
if (isScalar)
|
|
67
|
-
return (0, import_constant.getScalarExample)(
|
|
65
|
+
return (0, import_constant.getScalarExample)(modelRef);
|
|
68
66
|
else {
|
|
69
|
-
|
|
70
|
-
if (!
|
|
71
|
-
example[
|
|
67
|
+
Object.entries(modelRef.field).forEach(([key, field]) => {
|
|
68
|
+
if (!field.isScalar && field.isClass)
|
|
69
|
+
example[key] = "ObjectID";
|
|
72
70
|
else
|
|
73
|
-
example[
|
|
71
|
+
example[key] = field.example ?? field.enum ? (0, import_base.arraiedModel)(field.example ?? (field.enum?.values)[0], field.optArrDepth) : (0, import_base.arraiedModel)(getRequestExample(field.modelRef), field.arrDepth);
|
|
74
72
|
});
|
|
75
73
|
}
|
|
76
|
-
Reflect.defineMetadata(
|
|
74
|
+
Reflect.defineMetadata(modelRef, example, RequestExampleStorage.prototype);
|
|
77
75
|
return example;
|
|
78
76
|
};
|
|
79
77
|
const makeRequestExample = (gqlMeta) => {
|
package/cjs/src/fetchInfo.js
CHANGED
|
@@ -70,7 +70,7 @@ const serviceFetchOf = (signal) => {
|
|
|
70
70
|
} else if (Array.isArray(data))
|
|
71
71
|
return data.map((d) => crystalize(d));
|
|
72
72
|
else
|
|
73
|
-
return
|
|
73
|
+
return new returnRef().set(data);
|
|
74
74
|
};
|
|
75
75
|
const handle = (data) => {
|
|
76
76
|
import_common.Logger.debug(`socket listened: ${key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
@@ -101,7 +101,7 @@ const serviceFetchOf = (signal) => {
|
|
|
101
101
|
} else if (Array.isArray(data))
|
|
102
102
|
return data.map((d) => crystalize(d));
|
|
103
103
|
else
|
|
104
|
-
return
|
|
104
|
+
return new returnRef().set(data);
|
|
105
105
|
};
|
|
106
106
|
const subscribeEvent = function(...args) {
|
|
107
107
|
const onData = args[endpoint.args.length];
|
|
@@ -153,7 +153,7 @@ const serviceFetchOf = (signal) => {
|
|
|
153
153
|
} else if (Array.isArray(data))
|
|
154
154
|
return data.map((d) => crystalize(d));
|
|
155
155
|
else
|
|
156
|
-
return
|
|
156
|
+
return new lightenedReturnRef().set(data);
|
|
157
157
|
};
|
|
158
158
|
try {
|
|
159
159
|
const res = (await (endpoint.type === "query" ? import_gql.query : import_gql.mutate)(
|
|
@@ -246,7 +246,10 @@ const databaseFetchOf = (signal, option = {}) => {
|
|
|
246
246
|
},
|
|
247
247
|
[names.mergeModel]: async (modelOrId, data, option2) => {
|
|
248
248
|
const model = typeof modelOrId === "string" ? await fetchInstance[names._model](modelOrId) : modelOrId;
|
|
249
|
-
const input = cnst.purify({
|
|
249
|
+
const input = cnst.input.purify({
|
|
250
|
+
...model,
|
|
251
|
+
...data
|
|
252
|
+
});
|
|
250
253
|
if (!input)
|
|
251
254
|
throw new Error("Error");
|
|
252
255
|
return await fetchInstance[names.updateModel](model.id, input, option2);
|
|
@@ -254,7 +257,7 @@ const databaseFetchOf = (signal, option = {}) => {
|
|
|
254
257
|
[names.viewModel]: async (id, option2) => {
|
|
255
258
|
const modelObj = await fetchInstance[names._model](id, option2);
|
|
256
259
|
return {
|
|
257
|
-
[names.model]: cnst.
|
|
260
|
+
[names.model]: new cnst.full().set(modelObj),
|
|
258
261
|
[names.modelView]: {
|
|
259
262
|
refName: names.model,
|
|
260
263
|
[names.modelObj]: modelObj,
|
|
@@ -273,7 +276,7 @@ const databaseFetchOf = (signal, option = {}) => {
|
|
|
273
276
|
[names.editModel]: async (id, option2) => {
|
|
274
277
|
const modelObj = await fetchInstance[names._model](id, option2);
|
|
275
278
|
return {
|
|
276
|
-
[names.model]: cnst.
|
|
279
|
+
[names.model]: new cnst.full().set(modelObj),
|
|
277
280
|
[names.modelEdit]: {
|
|
278
281
|
refName: names.model,
|
|
279
282
|
[names.modelObj]: modelObj,
|
|
@@ -344,9 +347,9 @@ const databaseFetchOf = (signal, option = {}) => {
|
|
|
344
347
|
const modelObjList = modelInit[names.modelObjList];
|
|
345
348
|
const modelObjInsight = modelInit[names.modelObjInsight];
|
|
346
349
|
const modelList = new import_base.DataList(
|
|
347
|
-
modelObjList.map((modelObj) => cnst.
|
|
350
|
+
modelObjList.map((modelObj) => new cnst.light().set(modelObj))
|
|
348
351
|
);
|
|
349
|
-
const modelInsight = cnst.
|
|
352
|
+
const modelInsight = new cnst.insight().set(modelObjInsight);
|
|
350
353
|
return {
|
|
351
354
|
[namesOfSlice.modelList]: modelList,
|
|
352
355
|
// Server Component용
|
package/cjs/src/graphql.js
CHANGED
|
@@ -56,12 +56,11 @@ const makeReturnStr = (returnRef, partial) => {
|
|
|
56
56
|
...${(0, import_common.lowerlize)(fragmentName)}Fragment
|
|
57
57
|
}`;
|
|
58
58
|
const targetKeys = import_constant.constantInfo.isScalar(returnRef) ? partial : [.../* @__PURE__ */ new Set(["id", ...partial, "updatedAt"])];
|
|
59
|
-
const fieldMetaMap = (0, import_constant.getFieldMetaMap)(returnRef);
|
|
60
59
|
return ` {
|
|
61
|
-
${targetKeys.map((key) =>
|
|
62
|
-
(
|
|
63
|
-
...${(0, import_common.lowerlize)((0, import_constant.getGqlTypeStr)(
|
|
64
|
-
}` : ` ${
|
|
60
|
+
${targetKeys.map((key) => [key, returnRef.field[key]]).filter(([_, field]) => field.fieldType !== "hidden").map(
|
|
61
|
+
([key, field]) => field.isClass ? ` ${key} {
|
|
62
|
+
...${(0, import_common.lowerlize)((0, import_constant.getGqlTypeStr)(field.modelRef))}Fragment
|
|
63
|
+
}` : ` ${key}`
|
|
65
64
|
).join("\n")}
|
|
66
65
|
}`;
|
|
67
66
|
};
|
|
@@ -69,19 +68,18 @@ const fragmentize = (modelRef, fragMap = /* @__PURE__ */ new Map(), partial) =>
|
|
|
69
68
|
const refName = import_constant.constantInfo.getRefName(modelRef);
|
|
70
69
|
const fragmentName = `${import_constant.constantInfo.isLight(modelRef) ? "Light" : ""}${(0, import_common.capitalize)(refName)}${import_constant.constantInfo.isInsight(modelRef) ? "Insight" : ""}`;
|
|
71
70
|
const gqlName = `${(0, import_common.capitalize)(refName)}${import_constant.constantInfo.isInsight(modelRef) ? "Insight" : ""}`;
|
|
72
|
-
const
|
|
73
|
-
const selectKeys = partial ? ["id", ...partial, "updatedAt"] : metadatas.map((metadata) => metadata.key);
|
|
71
|
+
const selectKeys = partial ? ["id", ...partial, "updatedAt"] : Object.keys(modelRef.field);
|
|
74
72
|
const selectKeySet = new Set(selectKeys);
|
|
75
73
|
const fragment = `fragment ${(0, import_common.lowerlize)(fragmentName)}Fragment on ${gqlName} {
|
|
76
|
-
` +
|
|
77
|
-
return
|
|
78
|
-
...${(0, import_common.lowerlize)(`${import_constant.constantInfo.isLight(
|
|
79
|
-
}` : ` ${
|
|
74
|
+
` + Object.entries(modelRef.field).filter(([key, field]) => field.fieldType !== "hidden" && selectKeySet.has(key)).map(([key, field]) => {
|
|
75
|
+
return field.isClass ? ` ${key} {
|
|
76
|
+
...${(0, import_common.lowerlize)(`${import_constant.constantInfo.isLight(field.modelRef) ? "Light" : ""}${(0, import_common.capitalize)(import_constant.constantInfo.getRefName(field.modelRef))}${import_constant.constantInfo.isInsight(field.modelRef) ? "Insight" : ""}`)}Fragment
|
|
77
|
+
}` : ` ${key}`;
|
|
80
78
|
}).join(`
|
|
81
79
|
`) + `
|
|
82
80
|
}`;
|
|
83
81
|
fragMap.set(fragmentName, fragment);
|
|
84
|
-
|
|
82
|
+
Object.entries(modelRef.field).filter(([key, field]) => field.fieldType !== "hidden" && selectKeySet.has(key) && field.isClass).forEach(([key, field]) => fragmentize(field.modelRef, fragMap));
|
|
85
83
|
return fragMap;
|
|
86
84
|
};
|
|
87
85
|
const makeFragment = (modelRef, option = {}) => {
|
package/cjs/src/immerify.js
CHANGED
|
@@ -20,16 +20,14 @@ __export(immerify_exports, {
|
|
|
20
20
|
immerify: () => immerify
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(immerify_exports);
|
|
23
|
-
var import_constant = require("@akanjs/constant");
|
|
24
23
|
var import_immer = require("immer");
|
|
25
24
|
const immerify = (modelRef, objOrArr) => {
|
|
26
25
|
if (Array.isArray(objOrArr))
|
|
27
26
|
return objOrArr.map((val) => immerify(modelRef, val));
|
|
28
|
-
const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
|
|
29
27
|
const immeredObj = Object.assign({}, objOrArr, { [import_immer.immerable]: true });
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
immeredObj[
|
|
28
|
+
Object.entries(modelRef.field).forEach(([key, field]) => {
|
|
29
|
+
if (field.isScalar && field.isClass && !!objOrArr[key])
|
|
30
|
+
immeredObj[key] = immerify(field.modelRef, objOrArr[key]);
|
|
33
31
|
});
|
|
34
32
|
return immeredObj;
|
|
35
33
|
};
|
package/esm/src/doc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { arraiedModel, getNonArrayModel, isGqlScalar, JSON as GqlJSON } from "@akanjs/base";
|
|
2
|
-
import { constantInfo,
|
|
2
|
+
import { constantInfo, getScalarExample } from "@akanjs/constant";
|
|
3
3
|
class ResponseExampleStorage {
|
|
4
4
|
}
|
|
5
5
|
const getPredefinedRequestExample = (modelRef) => {
|
|
@@ -16,15 +16,14 @@ const getResponseExample = (ref) => {
|
|
|
16
16
|
const isScalar = isGqlScalar(modelRef);
|
|
17
17
|
if (isScalar)
|
|
18
18
|
return arraiedModel(getScalarExample(modelRef), arrDepth);
|
|
19
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
20
19
|
const example = {};
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
example[
|
|
24
|
-
else if (
|
|
25
|
-
example[
|
|
20
|
+
Object.entries(modelRef.field).forEach(([key, field]) => {
|
|
21
|
+
if (field.example)
|
|
22
|
+
example[key] = field.example;
|
|
23
|
+
else if (field.enum)
|
|
24
|
+
example[key] = arraiedModel(field.enum.values[0], field.arrDepth);
|
|
26
25
|
else
|
|
27
|
-
example[
|
|
26
|
+
example[key] = getResponseExample(field.modelRef);
|
|
28
27
|
});
|
|
29
28
|
const result = arraiedModel(example, arrDepth);
|
|
30
29
|
Reflect.defineMetadata(ref, result, ResponseExampleStorage.prototype);
|
|
@@ -32,24 +31,23 @@ const getResponseExample = (ref) => {
|
|
|
32
31
|
};
|
|
33
32
|
class RequestExampleStorage {
|
|
34
33
|
}
|
|
35
|
-
const getRequestExample = (
|
|
36
|
-
const existing = getPredefinedRequestExample(
|
|
34
|
+
const getRequestExample = (modelRef) => {
|
|
35
|
+
const existing = getPredefinedRequestExample(modelRef);
|
|
37
36
|
if (existing)
|
|
38
37
|
return existing;
|
|
39
|
-
const fieldMetas = getFieldMetas(ref);
|
|
40
38
|
const example = {};
|
|
41
|
-
const isScalar = isGqlScalar(
|
|
39
|
+
const isScalar = isGqlScalar(modelRef);
|
|
42
40
|
if (isScalar)
|
|
43
|
-
return getScalarExample(
|
|
41
|
+
return getScalarExample(modelRef);
|
|
44
42
|
else {
|
|
45
|
-
|
|
46
|
-
if (!
|
|
47
|
-
example[
|
|
43
|
+
Object.entries(modelRef.field).forEach(([key, field]) => {
|
|
44
|
+
if (!field.isScalar && field.isClass)
|
|
45
|
+
example[key] = "ObjectID";
|
|
48
46
|
else
|
|
49
|
-
example[
|
|
47
|
+
example[key] = field.example ?? field.enum ? arraiedModel(field.example ?? (field.enum?.values)[0], field.optArrDepth) : arraiedModel(getRequestExample(field.modelRef), field.arrDepth);
|
|
50
48
|
});
|
|
51
49
|
}
|
|
52
|
-
Reflect.defineMetadata(
|
|
50
|
+
Reflect.defineMetadata(modelRef, example, RequestExampleStorage.prototype);
|
|
53
51
|
return example;
|
|
54
52
|
};
|
|
55
53
|
const makeRequestExample = (gqlMeta) => {
|
package/esm/src/fetchInfo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataList, dayjs, isGqlScalar } from "@akanjs/base";
|
|
2
2
|
import { capitalize, Logger, lowerlize } from "@akanjs/common";
|
|
3
|
-
import { constantInfo,
|
|
3
|
+
import { constantInfo, serializeArg } from "@akanjs/constant";
|
|
4
4
|
import { mutate, query, setGqlOnStorage } from "./gql";
|
|
5
5
|
import { getGqlStr, graphql } from "./graphql";
|
|
6
6
|
const serviceFetchOf = (signal) => {
|
|
@@ -47,7 +47,7 @@ const serviceFetchOf = (signal) => {
|
|
|
47
47
|
} else if (Array.isArray(data))
|
|
48
48
|
return data.map((d) => crystalize(d));
|
|
49
49
|
else
|
|
50
|
-
return
|
|
50
|
+
return new returnRef().set(data);
|
|
51
51
|
};
|
|
52
52
|
const handle = (data) => {
|
|
53
53
|
Logger.debug(`socket listened: ${key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
@@ -78,7 +78,7 @@ const serviceFetchOf = (signal) => {
|
|
|
78
78
|
} else if (Array.isArray(data))
|
|
79
79
|
return data.map((d) => crystalize(d));
|
|
80
80
|
else
|
|
81
|
-
return
|
|
81
|
+
return new returnRef().set(data);
|
|
82
82
|
};
|
|
83
83
|
const subscribeEvent = function(...args) {
|
|
84
84
|
const onData = args[endpoint.args.length];
|
|
@@ -130,7 +130,7 @@ const serviceFetchOf = (signal) => {
|
|
|
130
130
|
} else if (Array.isArray(data))
|
|
131
131
|
return data.map((d) => crystalize(d));
|
|
132
132
|
else
|
|
133
|
-
return
|
|
133
|
+
return new lightenedReturnRef().set(data);
|
|
134
134
|
};
|
|
135
135
|
try {
|
|
136
136
|
const res = (await (endpoint.type === "query" ? query : mutate)(
|
|
@@ -223,7 +223,10 @@ const databaseFetchOf = (signal, option = {}) => {
|
|
|
223
223
|
},
|
|
224
224
|
[names.mergeModel]: async (modelOrId, data, option2) => {
|
|
225
225
|
const model = typeof modelOrId === "string" ? await fetchInstance[names._model](modelOrId) : modelOrId;
|
|
226
|
-
const input = cnst.purify({
|
|
226
|
+
const input = cnst.input.purify({
|
|
227
|
+
...model,
|
|
228
|
+
...data
|
|
229
|
+
});
|
|
227
230
|
if (!input)
|
|
228
231
|
throw new Error("Error");
|
|
229
232
|
return await fetchInstance[names.updateModel](model.id, input, option2);
|
|
@@ -231,7 +234,7 @@ const databaseFetchOf = (signal, option = {}) => {
|
|
|
231
234
|
[names.viewModel]: async (id, option2) => {
|
|
232
235
|
const modelObj = await fetchInstance[names._model](id, option2);
|
|
233
236
|
return {
|
|
234
|
-
[names.model]: cnst.
|
|
237
|
+
[names.model]: new cnst.full().set(modelObj),
|
|
235
238
|
[names.modelView]: {
|
|
236
239
|
refName: names.model,
|
|
237
240
|
[names.modelObj]: modelObj,
|
|
@@ -250,7 +253,7 @@ const databaseFetchOf = (signal, option = {}) => {
|
|
|
250
253
|
[names.editModel]: async (id, option2) => {
|
|
251
254
|
const modelObj = await fetchInstance[names._model](id, option2);
|
|
252
255
|
return {
|
|
253
|
-
[names.model]: cnst.
|
|
256
|
+
[names.model]: new cnst.full().set(modelObj),
|
|
254
257
|
[names.modelEdit]: {
|
|
255
258
|
refName: names.model,
|
|
256
259
|
[names.modelObj]: modelObj,
|
|
@@ -321,9 +324,9 @@ const databaseFetchOf = (signal, option = {}) => {
|
|
|
321
324
|
const modelObjList = modelInit[names.modelObjList];
|
|
322
325
|
const modelObjInsight = modelInit[names.modelObjInsight];
|
|
323
326
|
const modelList = new DataList(
|
|
324
|
-
modelObjList.map((modelObj) => cnst.
|
|
327
|
+
modelObjList.map((modelObj) => new cnst.light().set(modelObj))
|
|
325
328
|
);
|
|
326
|
-
const modelInsight = cnst.
|
|
329
|
+
const modelInsight = new cnst.insight().set(modelObjInsight);
|
|
327
330
|
return {
|
|
328
331
|
[namesOfSlice.modelList]: modelList,
|
|
329
332
|
// Server Component용
|
package/esm/src/graphql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isGqlScalar } from "@akanjs/base";
|
|
2
2
|
import { capitalize, lowerlize } from "@akanjs/common";
|
|
3
|
-
import { constantInfo,
|
|
3
|
+
import { constantInfo, getGqlTypeStr } from "@akanjs/constant";
|
|
4
4
|
class FragmentStorage {
|
|
5
5
|
}
|
|
6
6
|
const getPredefinedFragment = (refName) => {
|
|
@@ -32,12 +32,11 @@ const makeReturnStr = (returnRef, partial) => {
|
|
|
32
32
|
...${lowerlize(fragmentName)}Fragment
|
|
33
33
|
}`;
|
|
34
34
|
const targetKeys = constantInfo.isScalar(returnRef) ? partial : [.../* @__PURE__ */ new Set(["id", ...partial, "updatedAt"])];
|
|
35
|
-
const fieldMetaMap = getFieldMetaMap(returnRef);
|
|
36
35
|
return ` {
|
|
37
|
-
${targetKeys.map((key) =>
|
|
38
|
-
(
|
|
39
|
-
...${lowerlize(getGqlTypeStr(
|
|
40
|
-
}` : ` ${
|
|
36
|
+
${targetKeys.map((key) => [key, returnRef.field[key]]).filter(([_, field]) => field.fieldType !== "hidden").map(
|
|
37
|
+
([key, field]) => field.isClass ? ` ${key} {
|
|
38
|
+
...${lowerlize(getGqlTypeStr(field.modelRef))}Fragment
|
|
39
|
+
}` : ` ${key}`
|
|
41
40
|
).join("\n")}
|
|
42
41
|
}`;
|
|
43
42
|
};
|
|
@@ -45,19 +44,18 @@ const fragmentize = (modelRef, fragMap = /* @__PURE__ */ new Map(), partial) =>
|
|
|
45
44
|
const refName = constantInfo.getRefName(modelRef);
|
|
46
45
|
const fragmentName = `${constantInfo.isLight(modelRef) ? "Light" : ""}${capitalize(refName)}${constantInfo.isInsight(modelRef) ? "Insight" : ""}`;
|
|
47
46
|
const gqlName = `${capitalize(refName)}${constantInfo.isInsight(modelRef) ? "Insight" : ""}`;
|
|
48
|
-
const
|
|
49
|
-
const selectKeys = partial ? ["id", ...partial, "updatedAt"] : metadatas.map((metadata) => metadata.key);
|
|
47
|
+
const selectKeys = partial ? ["id", ...partial, "updatedAt"] : Object.keys(modelRef.field);
|
|
50
48
|
const selectKeySet = new Set(selectKeys);
|
|
51
49
|
const fragment = `fragment ${lowerlize(fragmentName)}Fragment on ${gqlName} {
|
|
52
|
-
` +
|
|
53
|
-
return
|
|
54
|
-
...${lowerlize(`${constantInfo.isLight(
|
|
55
|
-
}` : ` ${
|
|
50
|
+
` + Object.entries(modelRef.field).filter(([key, field]) => field.fieldType !== "hidden" && selectKeySet.has(key)).map(([key, field]) => {
|
|
51
|
+
return field.isClass ? ` ${key} {
|
|
52
|
+
...${lowerlize(`${constantInfo.isLight(field.modelRef) ? "Light" : ""}${capitalize(constantInfo.getRefName(field.modelRef))}${constantInfo.isInsight(field.modelRef) ? "Insight" : ""}`)}Fragment
|
|
53
|
+
}` : ` ${key}`;
|
|
56
54
|
}).join(`
|
|
57
55
|
`) + `
|
|
58
56
|
}`;
|
|
59
57
|
fragMap.set(fragmentName, fragment);
|
|
60
|
-
|
|
58
|
+
Object.entries(modelRef.field).filter(([key, field]) => field.fieldType !== "hidden" && selectKeySet.has(key) && field.isClass).forEach(([key, field]) => fragmentize(field.modelRef, fragMap));
|
|
61
59
|
return fragMap;
|
|
62
60
|
};
|
|
63
61
|
const makeFragment = (modelRef, option = {}) => {
|
package/esm/src/immerify.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { getFieldMetas } from "@akanjs/constant";
|
|
2
1
|
import { immerable } from "immer";
|
|
3
2
|
const immerify = (modelRef, objOrArr) => {
|
|
4
3
|
if (Array.isArray(objOrArr))
|
|
5
4
|
return objOrArr.map((val) => immerify(modelRef, val));
|
|
6
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
7
5
|
const immeredObj = Object.assign({}, objOrArr, { [immerable]: true });
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
immeredObj[
|
|
6
|
+
Object.entries(modelRef.field).forEach(([key, field]) => {
|
|
7
|
+
if (field.isScalar && field.isClass && !!objOrArr[key])
|
|
8
|
+
immeredObj[key] = immerify(field.modelRef, objOrArr[key]);
|
|
11
9
|
});
|
|
12
10
|
return immeredObj;
|
|
13
11
|
};
|
package/package.json
CHANGED
package/src/gql.d.ts
CHANGED
|
@@ -16,9 +16,9 @@ export interface FetchInitForm<Input, Full, Filter extends FilterInstance, _Defa
|
|
|
16
16
|
insight?: boolean;
|
|
17
17
|
}
|
|
18
18
|
export type ServerInit<T extends string, Light, Insight = any, QueryArgs = any[], Filter extends FilterInstance = any, _CapitalizedT extends string = Capitalize<T>, _Sort = ExtractSort<Filter>> = SliceMeta & {
|
|
19
|
-
[K in `${T}ObjList`]: Light[];
|
|
19
|
+
[K in `${T}ObjList`]: GetStateObject<Light>[];
|
|
20
20
|
} & {
|
|
21
|
-
[K in `${T}ObjInsight`]: Insight
|
|
21
|
+
[K in `${T}ObjInsight`]: GetStateObject<Insight>;
|
|
22
22
|
} & {
|
|
23
23
|
[K in `pageOf${_CapitalizedT}`]: number;
|
|
24
24
|
} & {
|
|
@@ -36,7 +36,7 @@ export type ClientInit<T extends string, Light, Insight = any, QueryArgs = any[]
|
|
|
36
36
|
export type ServerView<T extends string, Model> = {
|
|
37
37
|
refName: T;
|
|
38
38
|
} & {
|
|
39
|
-
[K in `${T}Obj`]: Model
|
|
39
|
+
[K in `${T}Obj`]: GetStateObject<Model>;
|
|
40
40
|
} & {
|
|
41
41
|
[K in `${T}ViewAt`]: Date;
|
|
42
42
|
};
|
|
@@ -44,7 +44,7 @@ export type ClientView<T extends string, Model> = PromiseOrObject<ServerView<T,
|
|
|
44
44
|
export type ServerEdit<T extends string, Model> = {
|
|
45
45
|
refName: T;
|
|
46
46
|
} & {
|
|
47
|
-
[K in `${T}Obj`]: Model
|
|
47
|
+
[K in `${T}Obj`]: GetStateObject<Model>;
|
|
48
48
|
} & {
|
|
49
49
|
[K in `${T}ViewAt`]: Date;
|
|
50
50
|
};
|
package/src/immerify.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const immerify: <T extends object | object[]>(modelRef:
|
|
1
|
+
import { Cnst } from "@akanjs/constant";
|
|
2
|
+
export declare const immerify: <T extends object | object[]>(modelRef: Cnst, objOrArr: T) => T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { Assign, BaseInsight, BaseObject, Dayjs, EnumInstance, Environment, MergeAllTypes, Type, UnType } from "@akanjs/base";
|
|
3
|
-
import { DocumentModel, GqlReturn, PurifiedModel, QueryOf } from "@akanjs/constant";
|
|
3
|
+
import { Cnst, DocumentModel, GqlReturn, PurifiedModel, QueryOf } from "@akanjs/constant";
|
|
4
4
|
import type { Doc, ExtractSort, FilterInstance } from "@akanjs/document";
|
|
5
5
|
import type { Guard, InternalParam } from "@akanjs/nest";
|
|
6
6
|
import type { ServiceModule, Sig } from "@akanjs/service";
|
|
@@ -101,7 +101,7 @@ export declare const getDefaultArg: (argRef: Type | Type[]) => object;
|
|
|
101
101
|
export interface SignalMeta {
|
|
102
102
|
refName: string;
|
|
103
103
|
slices: SliceMeta[];
|
|
104
|
-
returns?: (of?: any) =>
|
|
104
|
+
returns?: (of?: any) => Cnst;
|
|
105
105
|
prefix?: string;
|
|
106
106
|
enabled: boolean;
|
|
107
107
|
}
|
package/src/signalInfo.d.ts
CHANGED
|
@@ -18,7 +18,13 @@ export declare const signalInfo: {
|
|
|
18
18
|
serialize(sigRef: Type): SerializedSignal;
|
|
19
19
|
initialize(): object;
|
|
20
20
|
buildFetch(signals?: SerializedSignal[], cnstInfo?: {
|
|
21
|
-
database: Map<string, import("@akanjs/constant").ConstantModel<string, any, any, any, any, any, Capitalize<string>, import("@akanjs/
|
|
21
|
+
database: Map<string, import("@akanjs/constant").ConstantModel<string, any, any, any, any, any, Capitalize<string>, import("@akanjs/base").GetStateObject<{
|
|
22
|
+
[x: string]: any;
|
|
23
|
+
}>, import("@akanjs/base").GetStateObject<{
|
|
24
|
+
[x: string]: any;
|
|
25
|
+
}>, import("@akanjs/base").GetStateObject<any>, import("@akanjs/base").GetStateObject<any>, import("@akanjs/base").GetStateObject<{
|
|
26
|
+
[x: string]: any;
|
|
27
|
+
}>, any, any, any, import("mongoose").FilterQuery<any>>>;
|
|
22
28
|
scalar: Map<string, import("@akanjs/constant").ScalarConstantModel<any, any, any, any, any>>;
|
|
23
29
|
modelRefNameMap: Map<new (...args: any[]) => any, string>;
|
|
24
30
|
getRefName<AllowEmpty extends boolean = false>(modelRef: Type, { allowEmpty }?: {
|
|
@@ -37,11 +43,11 @@ export declare const signalInfo: {
|
|
|
37
43
|
setDatabase(refName: string, cnst: import("@akanjs/constant").ConstantModel<string, any, any, any, any, any>): void;
|
|
38
44
|
getDatabase<AllowEmpty extends boolean = false>(refName: string, { allowEmpty }?: {
|
|
39
45
|
allowEmpty?: AllowEmpty;
|
|
40
|
-
}): AllowEmpty extends true ? import("@akanjs/constant").ConstantModel<string,
|
|
41
|
-
setScalar(refName: string, cnst: import("@akanjs/constant").ScalarConstantModel<string,
|
|
46
|
+
}): AllowEmpty extends true ? import("@akanjs/constant").ConstantModel<string, unknown, unknown, unknown, unknown, unknown> | undefined : import("@akanjs/constant").ConstantModel<string, unknown, unknown, unknown, unknown, unknown>;
|
|
47
|
+
setScalar(refName: string, cnst: import("@akanjs/constant").ScalarConstantModel<string, unknown, unknown, unknown, unknown>): void;
|
|
42
48
|
getScalar<AllowEmpty extends boolean = false>(refName: string, { allowEmpty }?: {
|
|
43
49
|
allowEmpty?: AllowEmpty;
|
|
44
|
-
}): AllowEmpty extends true ? import("@akanjs/constant").ScalarConstantModel<string,
|
|
50
|
+
}): AllowEmpty extends true ? import("@akanjs/constant").ScalarConstantModel<string, unknown, unknown, unknown, unknown> | undefined : import("@akanjs/constant").ScalarConstantModel<string, unknown, unknown, unknown, unknown>;
|
|
45
51
|
getModelRef(refName: string, modelType: "input" | "object" | "full" | "light" | "insight" | "scalar"): Type | import("@akanjs/base").GqlScalar;
|
|
46
52
|
}): object;
|
|
47
53
|
registerClient: (cnst: any) => Promise<{
|