@akanjs/signal 0.9.55 → 0.9.57
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/apiInfo.js +19 -37
- package/cjs/src/base.signal.js +3 -0
- package/cjs/src/doc.js +7 -9
- package/cjs/src/internalApiInfo.js +9 -4
- package/cjs/src/signalDecorators.js +50 -299
- package/cjs/src/signalInfo.js +9 -1
- package/cjs/src/sliceInfo.js +15 -14
- package/esm/src/apiInfo.js +24 -38
- package/esm/src/base.signal.js +4 -1
- package/esm/src/doc.js +8 -10
- package/esm/src/internalApiInfo.js +10 -5
- package/esm/src/signalDecorators.js +51 -300
- package/esm/src/signalInfo.js +9 -1
- package/esm/src/sliceInfo.js +21 -15
- package/package.json +1 -1
- package/src/apiInfo.d.ts +24 -24
- package/src/base.signal.d.ts +22 -98
- package/src/doc.d.ts +5 -5
- package/src/fetch.d.ts +8 -8
- package/src/gql.d.ts +17 -32
- package/src/internalApiInfo.d.ts +26 -24
- package/src/signalDecorators.d.ts +35 -204
- package/src/signalInfo.d.ts +15 -7
- package/src/sliceInfo.d.ts +25 -33
package/cjs/src/signalInfo.js
CHANGED
|
@@ -143,7 +143,14 @@ const signalInfo = {
|
|
|
143
143
|
const refName2 = isGqlScalar ? import_base.scalarNameMap.get(returnRef) : import_constant.constantInfo.getRefName(returnRef);
|
|
144
144
|
serializedSignal.endpoint[key] = {
|
|
145
145
|
type: (0, import_common.lowerlize)(gqlMeta.type),
|
|
146
|
-
signalOption:
|
|
146
|
+
signalOption: {
|
|
147
|
+
nullable: gqlMeta.signalOption.nullable,
|
|
148
|
+
path: gqlMeta.signalOption.path,
|
|
149
|
+
onlyFor: gqlMeta.signalOption.onlyFor,
|
|
150
|
+
partial: gqlMeta.signalOption.partial,
|
|
151
|
+
guards: gqlMeta.signalOption.guards?.map((guard) => guard.name),
|
|
152
|
+
name: gqlMeta.signalOption.name
|
|
153
|
+
},
|
|
147
154
|
returns: { refName: refName2, modelType, arrDepth },
|
|
148
155
|
args: argMetas.map((argMeta) => {
|
|
149
156
|
const [argRef, arrDepth2] = (0, import_base.getNonArrayModel)(argMeta.returns());
|
|
@@ -172,6 +179,7 @@ const signalInfo = {
|
|
|
172
179
|
return signalInfo.buildFetch(signalInfo.serializedSignals);
|
|
173
180
|
},
|
|
174
181
|
buildFetch(signals = [], cnstInfo = import_constant.constantInfo) {
|
|
182
|
+
global.signals = signals;
|
|
175
183
|
const databaseSignals = signals.filter((signal) => cnstInfo.database.has(signal.refName));
|
|
176
184
|
const serviceSignals = signals.filter((signal) => !cnstInfo.database.has(signal.refName));
|
|
177
185
|
const fetchComponent = Object.assign(
|
package/cjs/src/sliceInfo.js
CHANGED
|
@@ -26,31 +26,28 @@ var import_common = require("@akanjs/common");
|
|
|
26
26
|
var import_signalDecorators = require("./signalDecorators");
|
|
27
27
|
var import_signalInfo = require("./signalInfo");
|
|
28
28
|
class SliceInfo {
|
|
29
|
+
refName;
|
|
29
30
|
full;
|
|
30
31
|
light;
|
|
31
32
|
insight;
|
|
33
|
+
argNames = [];
|
|
32
34
|
args = [];
|
|
33
35
|
internalArgs = [];
|
|
34
36
|
signalOption;
|
|
35
|
-
guards;
|
|
36
37
|
execFn = null;
|
|
37
|
-
constructor(full, light, insight,
|
|
38
|
+
constructor(refName, full, light, insight, signalOption = {}) {
|
|
39
|
+
this.refName = refName;
|
|
38
40
|
this.full = full;
|
|
39
41
|
this.light = light;
|
|
40
42
|
this.insight = insight;
|
|
41
|
-
this.signalOption =
|
|
42
|
-
this.guards = [
|
|
43
|
-
.../* @__PURE__ */ new Set([
|
|
44
|
-
...guards,
|
|
45
|
-
...typeof signalOptionOrGuard === "string" ? [signalOptionOrGuard] : ["Public"]
|
|
46
|
-
])
|
|
47
|
-
];
|
|
43
|
+
this.signalOption = signalOption;
|
|
48
44
|
}
|
|
49
45
|
param(name, argRef, option) {
|
|
50
46
|
if (this.execFn)
|
|
51
47
|
throw new Error("Query function is already set");
|
|
52
48
|
else if (this.args.at(-1)?.option?.nullable)
|
|
53
49
|
throw new Error("Last argument is nullable");
|
|
50
|
+
this.argNames.push(name);
|
|
54
51
|
this.args.push({ type: "Param", name, argRef, option });
|
|
55
52
|
return this;
|
|
56
53
|
}
|
|
@@ -59,12 +56,14 @@ class SliceInfo {
|
|
|
59
56
|
throw new Error("Query function is already set");
|
|
60
57
|
else if (this.args.at(-1)?.option?.nullable)
|
|
61
58
|
throw new Error("Last argument is nullable");
|
|
59
|
+
this.argNames.push(name);
|
|
62
60
|
this.args.push({ type: "Body", name, argRef, option });
|
|
63
61
|
return this;
|
|
64
62
|
}
|
|
65
63
|
search(name, argRef, option) {
|
|
66
64
|
if (this.execFn)
|
|
67
65
|
throw new Error("Query function is already set");
|
|
66
|
+
this.argNames.push(name);
|
|
68
67
|
this.args.push({ type: "Query", name, argRef, option: { ...option, nullable: true } });
|
|
69
68
|
return this;
|
|
70
69
|
}
|
|
@@ -89,11 +88,15 @@ class SliceInfo {
|
|
|
89
88
|
const gqlMetaMap = (0, import_signalDecorators.getGqlMetaMapOnPrototype)(sigRef.prototype);
|
|
90
89
|
const argMetas = this.args.map((arg, idx) => {
|
|
91
90
|
const [singleArgRef, argArrDepth] = (0, import_base.getNonArrayModel)(arg.argRef);
|
|
92
|
-
const
|
|
91
|
+
const isEnumValue = (0, import_base.isEnum)(singleArgRef);
|
|
92
|
+
const returnRef = (0, import_base.arraiedModel)(
|
|
93
|
+
isEnumValue ? singleArgRef.type : singleArgRef,
|
|
94
|
+
argArrDepth
|
|
95
|
+
);
|
|
93
96
|
return {
|
|
94
97
|
name: arg.name,
|
|
95
98
|
returns: () => returnRef,
|
|
96
|
-
argsOption: { ...arg.option, enum:
|
|
99
|
+
argsOption: { ...arg.option, enum: isEnumValue ? arg.argRef : void 0 },
|
|
97
100
|
key,
|
|
98
101
|
idx,
|
|
99
102
|
type: arg.type
|
|
@@ -151,7 +154,6 @@ class SliceInfo {
|
|
|
151
154
|
signalOption: this.signalOption,
|
|
152
155
|
key: listKey,
|
|
153
156
|
descriptor: { value: listFn, writable: true, enumerable: false, configurable: true },
|
|
154
|
-
guards: this.guards,
|
|
155
157
|
type: "Query"
|
|
156
158
|
};
|
|
157
159
|
gqlMetaMap.set(listKey, listApiMeta);
|
|
@@ -177,7 +179,6 @@ class SliceInfo {
|
|
|
177
179
|
signalOption: this.signalOption,
|
|
178
180
|
key: insightKey,
|
|
179
181
|
descriptor: { value: insightFn, writable: true, enumerable: false, configurable: true },
|
|
180
|
-
guards: this.guards,
|
|
181
182
|
type: "Query"
|
|
182
183
|
};
|
|
183
184
|
gqlMetaMap.set(insightKey, insightApiMeta);
|
|
@@ -190,4 +191,4 @@ class SliceInfo {
|
|
|
190
191
|
(0, import_signalDecorators.setGqlMetaMapOnPrototype)(sigRef.prototype, gqlMetaMap);
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
|
-
const sliceInit = (full, light, insight) => (
|
|
194
|
+
const sliceInit = (refName, full, light, insight) => (signalOption) => new SliceInfo(refName, full, light, insight, signalOption);
|
package/esm/src/apiInfo.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
arraiedModel,
|
|
3
|
+
getNonArrayModel,
|
|
4
|
+
isEnum
|
|
5
|
+
} from "@akanjs/base";
|
|
2
6
|
import {
|
|
3
7
|
getGqlMetaMapOnPrototype,
|
|
4
8
|
setArgMetas,
|
|
@@ -7,34 +11,30 @@ import {
|
|
|
7
11
|
import { signalInfo } from "./signalInfo";
|
|
8
12
|
class ApiInfo {
|
|
9
13
|
type;
|
|
14
|
+
argNames = [];
|
|
10
15
|
args = [];
|
|
11
16
|
internalArgs = [];
|
|
12
17
|
returnRef;
|
|
13
18
|
signalOption;
|
|
14
|
-
guards;
|
|
15
19
|
execFn = null;
|
|
16
|
-
constructor(type, returnRef,
|
|
20
|
+
constructor(type, returnRef, signalOption = {}) {
|
|
17
21
|
this.type = type;
|
|
18
22
|
this.returnRef = returnRef;
|
|
19
|
-
this.signalOption =
|
|
20
|
-
this.guards = [
|
|
21
|
-
.../* @__PURE__ */ new Set([
|
|
22
|
-
...guards,
|
|
23
|
-
...typeof signalOptionOrGuard === "string" ? [signalOptionOrGuard] : ["Public"]
|
|
24
|
-
])
|
|
25
|
-
];
|
|
23
|
+
this.signalOption = signalOption;
|
|
26
24
|
}
|
|
27
25
|
param(name, argRef, option) {
|
|
28
26
|
if (this.execFn)
|
|
29
27
|
throw new Error("Query function is already set");
|
|
30
28
|
else if (this.args.at(-1)?.option?.nullable)
|
|
31
29
|
throw new Error("Last argument is nullable");
|
|
30
|
+
this.argNames.push(name);
|
|
32
31
|
this.args.push({ type: "Param", name, argRef, option });
|
|
33
32
|
return this;
|
|
34
33
|
}
|
|
35
34
|
body(name, argRef, option) {
|
|
36
35
|
if (this.execFn)
|
|
37
36
|
throw new Error("Query function is already set");
|
|
37
|
+
this.argNames.push(name);
|
|
38
38
|
this.args.push({ type: "Body", name, argRef, option });
|
|
39
39
|
return this;
|
|
40
40
|
}
|
|
@@ -43,6 +43,7 @@ class ApiInfo {
|
|
|
43
43
|
throw new Error("Query function is already set");
|
|
44
44
|
else if (this.args.at(-1)?.option?.nullable)
|
|
45
45
|
throw new Error("Last argument is nullable");
|
|
46
|
+
this.argNames.push(name);
|
|
46
47
|
this.args.push({ type: "Room", name, argRef, option });
|
|
47
48
|
return this;
|
|
48
49
|
}
|
|
@@ -51,12 +52,14 @@ class ApiInfo {
|
|
|
51
52
|
throw new Error("Query function is already set");
|
|
52
53
|
else if (this.args.at(-1)?.option?.nullable)
|
|
53
54
|
throw new Error("Last argument is nullable");
|
|
55
|
+
this.argNames.push(name);
|
|
54
56
|
this.args.push({ type: "Msg", name, argRef, option });
|
|
55
57
|
return this;
|
|
56
58
|
}
|
|
57
59
|
search(name, argRef, option) {
|
|
58
60
|
if (this.execFn)
|
|
59
61
|
throw new Error("Query function is already set");
|
|
62
|
+
this.argNames.push(name);
|
|
60
63
|
this.args.push({ type: "Query", name, argRef, option: { ...option, nullable: true } });
|
|
61
64
|
return this;
|
|
62
65
|
}
|
|
@@ -86,13 +89,12 @@ class ApiInfo {
|
|
|
86
89
|
const [singleReturnRef, returnArrDepth] = getNonArrayModel(this.returnRef);
|
|
87
90
|
const apiMeta = {
|
|
88
91
|
returns: () => arraiedModel(
|
|
89
|
-
singleReturnRef
|
|
92
|
+
isEnum(singleReturnRef) ? singleReturnRef.type : singleReturnRef,
|
|
90
93
|
returnArrDepth
|
|
91
94
|
),
|
|
92
95
|
signalOption: this.signalOption,
|
|
93
96
|
key,
|
|
94
97
|
descriptor: { value: this.execFn, writable: true, enumerable: false, configurable: true },
|
|
95
|
-
guards: this.guards,
|
|
96
98
|
type: ApiInfo.#typeTempMap[this.type]
|
|
97
99
|
};
|
|
98
100
|
sigRef.prototype[key] = this.execFn;
|
|
@@ -101,11 +103,15 @@ class ApiInfo {
|
|
|
101
103
|
setGqlMetaMapOnPrototype(sigRef.prototype, metadataMap);
|
|
102
104
|
const argMetas = this.args.map((arg, idx) => {
|
|
103
105
|
const [singleArgRef, argArrDepth] = getNonArrayModel(arg.argRef);
|
|
104
|
-
const
|
|
106
|
+
const isEnumValue = isEnum(singleArgRef);
|
|
107
|
+
const returnRef = arraiedModel(
|
|
108
|
+
isEnumValue ? singleArgRef.type : singleArgRef,
|
|
109
|
+
argArrDepth
|
|
110
|
+
);
|
|
105
111
|
return {
|
|
106
112
|
name: arg.name,
|
|
107
113
|
returns: () => returnRef,
|
|
108
|
-
argsOption: { ...arg.option, enum:
|
|
114
|
+
argsOption: { ...arg.option, enum: isEnumValue ? arg.argRef : void 0 },
|
|
109
115
|
key,
|
|
110
116
|
idx,
|
|
111
117
|
type: arg.type
|
|
@@ -121,30 +127,10 @@ class ApiInfo {
|
|
|
121
127
|
}
|
|
122
128
|
}
|
|
123
129
|
const makeApiBuilder = () => ({
|
|
124
|
-
query: (returnRef,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
...guards
|
|
129
|
-
),
|
|
130
|
-
mutation: (returnRef, signalOptionOrGuard, ...guards) => new ApiInfo(
|
|
131
|
-
"mutation",
|
|
132
|
-
returnRef,
|
|
133
|
-
signalOptionOrGuard,
|
|
134
|
-
...guards
|
|
135
|
-
),
|
|
136
|
-
pubsub: (returnRef, signalOptionOrGuard, ...guards) => new ApiInfo(
|
|
137
|
-
"pubsub",
|
|
138
|
-
returnRef,
|
|
139
|
-
signalOptionOrGuard,
|
|
140
|
-
...guards
|
|
141
|
-
),
|
|
142
|
-
message: (returnRef, signalOptionOrGuard, ...guards) => new ApiInfo(
|
|
143
|
-
"message",
|
|
144
|
-
returnRef,
|
|
145
|
-
signalOptionOrGuard,
|
|
146
|
-
...guards
|
|
147
|
-
)
|
|
130
|
+
query: (returnRef, signalOption) => new ApiInfo("query", returnRef, signalOption),
|
|
131
|
+
mutation: (returnRef, signalOption) => new ApiInfo("mutation", returnRef, signalOption),
|
|
132
|
+
pubsub: (returnRef, signalOption) => new ApiInfo("pubsub", returnRef, signalOption),
|
|
133
|
+
message: (returnRef, signalOption) => new ApiInfo("message", returnRef, signalOption)
|
|
148
134
|
});
|
|
149
135
|
export {
|
|
150
136
|
ApiInfo,
|
package/esm/src/base.signal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSON } from "@akanjs/base";
|
|
2
2
|
import { getAllDictionary, getDictionary } from "@akanjs/dictionary";
|
|
3
|
-
import { endpoint, internal, mergeSignals } from "./signalDecorators";
|
|
3
|
+
import { endpoint, internal, mergeSignals, serverSignalOf } from "./signalDecorators";
|
|
4
4
|
import { signalInfo } from "./signalInfo";
|
|
5
5
|
const srvBase = { refName: "base" };
|
|
6
6
|
class BaseInternal extends internal(srvBase, ({ interval }) => ({
|
|
@@ -57,7 +57,10 @@ class BaseEndpoint extends endpoint(srvBase, ({ query, mutation, message, pubsub
|
|
|
57
57
|
}
|
|
58
58
|
class BaseSignal extends mergeSignals(BaseEndpoint, BaseInternal) {
|
|
59
59
|
}
|
|
60
|
+
class Base extends serverSignalOf(BaseSignal) {
|
|
61
|
+
}
|
|
60
62
|
export {
|
|
63
|
+
Base,
|
|
61
64
|
BaseEndpoint,
|
|
62
65
|
BaseInternal,
|
|
63
66
|
BaseSignal
|
package/esm/src/doc.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { arraiedModel, getNonArrayModel, isGqlScalar, JSON as GqlJSON } from "@akanjs/base";
|
|
2
|
-
import { getFieldMetas, getScalarExample } from "@akanjs/constant";
|
|
3
|
-
import { getArgMetas, getGqlMeta } from "./signalDecorators";
|
|
2
|
+
import { constantInfo, getFieldMetas, getScalarExample } from "@akanjs/constant";
|
|
4
3
|
class ResponseExampleStorage {
|
|
5
4
|
}
|
|
6
5
|
const getPredefinedRequestExample = (modelRef) => {
|
|
@@ -53,26 +52,25 @@ const getRequestExample = (ref) => {
|
|
|
53
52
|
Reflect.defineMetadata(ref, example, RequestExampleStorage.prototype);
|
|
54
53
|
return example;
|
|
55
54
|
};
|
|
56
|
-
const makeRequestExample = (
|
|
57
|
-
|
|
58
|
-
return getExampleData(argMetas);
|
|
55
|
+
const makeRequestExample = (gqlMeta) => {
|
|
56
|
+
return getExampleData(gqlMeta.args);
|
|
59
57
|
};
|
|
60
58
|
const getExampleData = (argMetas, signalType = "graphql") => Object.fromEntries(
|
|
61
59
|
argMetas.filter((argMeta) => argMeta.type !== "Upload").map((argMeta) => {
|
|
62
|
-
const
|
|
60
|
+
const argRef = constantInfo.getModelRef(argMeta.refName, argMeta.modelType);
|
|
63
61
|
const example = argMeta.argsOption.example ?? getRequestExample(argRef);
|
|
64
62
|
return [
|
|
65
63
|
argMeta.name,
|
|
66
64
|
arraiedModel(
|
|
67
65
|
signalType === "restapi" && argRef.prototype === GqlJSON.prototype ? JSON.stringify(example, null, 2) : example,
|
|
68
|
-
|
|
66
|
+
argMeta.arrDepth
|
|
69
67
|
)
|
|
70
68
|
];
|
|
71
69
|
})
|
|
72
70
|
);
|
|
73
|
-
const makeResponseExample = (
|
|
74
|
-
const
|
|
75
|
-
const example = getResponseExample(gqlMeta.returns
|
|
71
|
+
const makeResponseExample = (gqlMeta) => {
|
|
72
|
+
const returnRef = constantInfo.getModelRef(gqlMeta.returns.refName, gqlMeta.returns.modelType);
|
|
73
|
+
const example = getResponseExample(arraiedModel(returnRef, gqlMeta.returns.arrDepth));
|
|
76
74
|
return example;
|
|
77
75
|
};
|
|
78
76
|
export {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isEnum, JSON } from "@akanjs/base";
|
|
2
2
|
import {
|
|
3
3
|
getGqlMetaMapOnPrototype,
|
|
4
4
|
getResolveFieldMetaMapOnPrototype,
|
|
@@ -9,6 +9,7 @@ class InternalApiInfo {
|
|
|
9
9
|
type;
|
|
10
10
|
args = [];
|
|
11
11
|
internalArgs = [];
|
|
12
|
+
defaultArgs = [];
|
|
12
13
|
returnRef;
|
|
13
14
|
signalOption;
|
|
14
15
|
execFn = null;
|
|
@@ -16,6 +17,10 @@ class InternalApiInfo {
|
|
|
16
17
|
this.type = type;
|
|
17
18
|
this.returnRef = returnRef;
|
|
18
19
|
this.signalOption = signalOption;
|
|
20
|
+
if (type === "resolveField")
|
|
21
|
+
this.defaultArgs.push("Parent");
|
|
22
|
+
else if (type === "process")
|
|
23
|
+
this.defaultArgs.push("Job");
|
|
19
24
|
}
|
|
20
25
|
msg(name, argRef, option) {
|
|
21
26
|
if (this.execFn)
|
|
@@ -59,12 +64,12 @@ class InternalApiInfo {
|
|
|
59
64
|
Reflect.defineMetadata("resolveField", metadataMap, sigRef.prototype);
|
|
60
65
|
} else {
|
|
61
66
|
const metadataMap = getGqlMetaMapOnPrototype(sigRef.prototype);
|
|
67
|
+
const isEnumValue = isEnum(this.returnRef);
|
|
62
68
|
const internalApiMeta = {
|
|
63
|
-
returns: () =>
|
|
69
|
+
returns: () => isEnumValue ? this.returnRef.type : this.returnRef,
|
|
64
70
|
signalOption: this.signalOption,
|
|
65
71
|
key,
|
|
66
72
|
descriptor: { value: this.execFn, writable: true, enumerable: false, configurable: true },
|
|
67
|
-
guards: ["None"],
|
|
68
73
|
type: InternalApiInfo.#typeTempMap[this.type]
|
|
69
74
|
};
|
|
70
75
|
sigRef.prototype[key] = this.execFn;
|
|
@@ -74,7 +79,7 @@ class InternalApiInfo {
|
|
|
74
79
|
const argMetas = this.args.map((arg, idx) => ({
|
|
75
80
|
name: arg.name,
|
|
76
81
|
returns: () => arg.argRef,
|
|
77
|
-
argsOption: { ...arg.option, enum: arg.argRef
|
|
82
|
+
argsOption: { ...arg.option, enum: isEnum(arg.argRef) ? arg.argRef : void 0 },
|
|
78
83
|
key,
|
|
79
84
|
idx,
|
|
80
85
|
type: arg.type
|
|
@@ -82,7 +87,7 @@ class InternalApiInfo {
|
|
|
82
87
|
const internalArgMetas = this.internalArgs.map((arg, idx) => ({
|
|
83
88
|
type: arg.type,
|
|
84
89
|
key,
|
|
85
|
-
idx,
|
|
90
|
+
idx: this.defaultArgs.length + this.args.length + idx,
|
|
86
91
|
option: arg.option
|
|
87
92
|
}));
|
|
88
93
|
setArgMetas(sigRef, key, argMetas, internalArgMetas);
|