@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.
@@ -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: gqlMeta.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(
@@ -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, signalOptionOrGuard, ...guards) {
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 = typeof signalOptionOrGuard === "string" ? {} : signalOptionOrGuard ?? {};
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 returnRef = (0, import_base.arraiedModel)(singleArgRef instanceof import_base.Enum ? singleArgRef.type : singleArgRef, argArrDepth);
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: arg.argRef instanceof import_base.Enum ? arg.argRef : void 0 },
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) => (signalOptionOrGuard, ...guards) => new SliceInfo(full, light, insight, signalOptionOrGuard, ...guards);
194
+ const sliceInit = (refName, full, light, insight) => (signalOption) => new SliceInfo(refName, full, light, insight, signalOption);
@@ -1,4 +1,8 @@
1
- import { arraiedModel, Enum, getNonArrayModel } from "@akanjs/base";
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, signalOptionOrGuard, ...guards) {
20
+ constructor(type, returnRef, signalOption = {}) {
17
21
  this.type = type;
18
22
  this.returnRef = returnRef;
19
- this.signalOption = typeof signalOptionOrGuard === "string" ? {} : signalOptionOrGuard ?? {};
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 instanceof Enum ? singleReturnRef.type : 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 returnRef = arraiedModel(singleArgRef instanceof Enum ? singleArgRef.type : singleArgRef, argArrDepth);
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: arg.argRef instanceof Enum ? arg.argRef : void 0 },
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, signalOptionOrGuard, ...guards) => new ApiInfo(
125
- "query",
126
- returnRef,
127
- signalOptionOrGuard,
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,
@@ -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 = (sigRef, key) => {
57
- const [argMetas] = getArgMetas(sigRef, key);
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 [argRef, argArrDepth] = getNonArrayModel(argMeta.returns());
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
- argArrDepth
66
+ argMeta.arrDepth
69
67
  )
70
68
  ];
71
69
  })
72
70
  );
73
- const makeResponseExample = (sigRef, key) => {
74
- const gqlMeta = getGqlMeta(sigRef, key);
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 { Enum, JSON } from "@akanjs/base";
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: () => this.returnRef instanceof Enum ? this.returnRef.type : this.returnRef,
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 instanceof Enum ? arg.argRef : void 0 },
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);