@akanjs/signal 0.9.47 → 0.9.49

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.
@@ -0,0 +1,167 @@
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 apiInfo_exports = {};
19
+ __export(apiInfo_exports, {
20
+ ApiInfo: () => ApiInfo,
21
+ makeApiBuilder: () => makeApiBuilder
22
+ });
23
+ module.exports = __toCommonJS(apiInfo_exports);
24
+ var import_base = require("@akanjs/base");
25
+ var import_signalDecorators = require("./signalDecorators");
26
+ var import_signalInfo = require("./signalInfo");
27
+ class ApiInfo {
28
+ type;
29
+ args = [];
30
+ internalArgs = [];
31
+ returnRef;
32
+ signalOption;
33
+ guards;
34
+ execFn = null;
35
+ constructor(type, returnRef, signalOptionOrGuard, ...guards) {
36
+ this.type = type;
37
+ this.returnRef = returnRef;
38
+ this.signalOption = typeof signalOptionOrGuard === "string" ? {} : signalOptionOrGuard ?? {};
39
+ this.guards = [
40
+ .../* @__PURE__ */ new Set([
41
+ ...guards,
42
+ ...typeof signalOptionOrGuard === "string" ? [signalOptionOrGuard] : ["Public"]
43
+ ])
44
+ ];
45
+ }
46
+ param(name, argRef, option) {
47
+ if (this.execFn)
48
+ throw new Error("Query function is already set");
49
+ else if (this.args.at(-1)?.option?.nullable)
50
+ throw new Error("Last argument is nullable");
51
+ this.args.push({ type: "Param", name, argRef, option });
52
+ return this;
53
+ }
54
+ body(name, argRef, option) {
55
+ if (this.execFn)
56
+ throw new Error("Query function is already set");
57
+ this.args.push({ type: "Body", name, argRef, option });
58
+ return this;
59
+ }
60
+ room(name, argRef, option) {
61
+ if (this.execFn)
62
+ throw new Error("Query function is already set");
63
+ else if (this.args.at(-1)?.option?.nullable)
64
+ throw new Error("Last argument is nullable");
65
+ this.args.push({ type: "Room", name, argRef, option });
66
+ return this;
67
+ }
68
+ msg(name, argRef, option) {
69
+ if (this.execFn)
70
+ throw new Error("Query function is already set");
71
+ else if (this.args.at(-1)?.option?.nullable)
72
+ throw new Error("Last argument is nullable");
73
+ this.args.push({ type: "Msg", name, argRef, option });
74
+ return this;
75
+ }
76
+ search(name, argRef, option) {
77
+ if (this.execFn)
78
+ throw new Error("Query function is already set");
79
+ this.args.push({ type: "Query", name, argRef, option: { ...option, nullable: true } });
80
+ return this;
81
+ }
82
+ with(argType, option) {
83
+ if (this.execFn)
84
+ throw new Error("Query function is already set");
85
+ this.internalArgs.push({ type: argType, option });
86
+ return this;
87
+ }
88
+ exec(execFn) {
89
+ if (this.execFn)
90
+ throw new Error("Query function is already set");
91
+ this.execFn = execFn;
92
+ return this;
93
+ }
94
+ static #typeTempMap = {
95
+ query: "Query",
96
+ mutation: "Mutation",
97
+ pubsub: "Pubsub",
98
+ message: "Message"
99
+ };
100
+ applyApiMeta(sigRef, key) {
101
+ const execFn = this.execFn;
102
+ if (!execFn)
103
+ throw new Error("Exec function is not set");
104
+ import_signalInfo.signalInfo.setHandlerKey(execFn, key);
105
+ const [singleReturnRef, returnArrDepth] = (0, import_base.getNonArrayModel)(this.returnRef);
106
+ const apiMeta = {
107
+ returns: () => (0, import_base.arraiedModel)(
108
+ singleReturnRef instanceof import_base.Enum ? singleReturnRef.type : singleReturnRef,
109
+ returnArrDepth
110
+ ),
111
+ signalOption: this.signalOption,
112
+ key,
113
+ descriptor: { value: this.execFn, writable: true, enumerable: false, configurable: true },
114
+ guards: this.guards,
115
+ type: ApiInfo.#typeTempMap[this.type]
116
+ };
117
+ sigRef.prototype[key] = this.execFn;
118
+ const metadataMap = (0, import_signalDecorators.getGqlMetaMapOnPrototype)(sigRef.prototype);
119
+ metadataMap.set(key, apiMeta);
120
+ (0, import_signalDecorators.setGqlMetaMapOnPrototype)(sigRef.prototype, metadataMap);
121
+ const argMetas = this.args.map((arg, idx) => {
122
+ const [singleArgRef, argArrDepth] = (0, import_base.getNonArrayModel)(arg.argRef);
123
+ const returnRef = (0, import_base.arraiedModel)(singleArgRef instanceof import_base.Enum ? singleArgRef.type : singleArgRef, argArrDepth);
124
+ return {
125
+ name: arg.name,
126
+ returns: () => returnRef,
127
+ argsOption: { ...arg.option, enum: arg.argRef instanceof import_base.Enum ? arg.argRef : void 0 },
128
+ key,
129
+ idx,
130
+ type: arg.type
131
+ };
132
+ });
133
+ const internalArgMetas = this.internalArgs.map((arg, idx) => ({
134
+ type: arg.type,
135
+ key,
136
+ idx: this.args.length + idx,
137
+ option: arg.option
138
+ }));
139
+ (0, import_signalDecorators.setArgMetas)(sigRef, key, argMetas, internalArgMetas);
140
+ }
141
+ }
142
+ const makeApiBuilder = () => ({
143
+ query: (returnRef, signalOptionOrGuard, ...guards) => new ApiInfo(
144
+ "query",
145
+ returnRef,
146
+ signalOptionOrGuard,
147
+ ...guards
148
+ ),
149
+ mutation: (returnRef, signalOptionOrGuard, ...guards) => new ApiInfo(
150
+ "mutation",
151
+ returnRef,
152
+ signalOptionOrGuard,
153
+ ...guards
154
+ ),
155
+ pubsub: (returnRef, signalOptionOrGuard, ...guards) => new ApiInfo(
156
+ "pubsub",
157
+ returnRef,
158
+ signalOptionOrGuard,
159
+ ...guards
160
+ ),
161
+ message: (returnRef, signalOptionOrGuard, ...guards) => new ApiInfo(
162
+ "message",
163
+ returnRef,
164
+ signalOptionOrGuard,
165
+ ...guards
166
+ )
167
+ });
@@ -15,107 +15,69 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var __decorateClass = (decorators, target, key, kind) => {
19
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
- if (decorator = decorators[i])
22
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
- if (kind && result)
24
- __defProp(target, key, result);
25
- return result;
26
- };
27
- var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
28
18
  var base_signal_exports = {};
29
19
  __export(base_signal_exports, {
20
+ BaseEndpoint: () => BaseEndpoint,
21
+ BaseInternal: () => BaseInternal,
30
22
  BaseSignal: () => BaseSignal
31
23
  });
32
24
  module.exports = __toCommonJS(base_signal_exports);
33
25
  var import_base = require("@akanjs/base");
34
- var import_constant = require("@akanjs/constant");
26
+ var import_dictionary = require("@akanjs/dictionary");
35
27
  var import_signalDecorators = require("./signalDecorators");
36
- let BaseSignal = class extends (0, import_signalDecorators.LogSignal)(import_constant.Srvs) {
37
- publishPing() {
28
+ var import_signalInfo = require("./signalInfo");
29
+ const srvBase = { refName: "base" };
30
+ class BaseInternal extends (0, import_signalDecorators.internal)(srvBase, ({ interval }) => ({
31
+ publishPing: interval(3e3).exec(function() {
38
32
  this.baseService.publishPing();
39
- }
40
- ping() {
41
- return (0, import_signalDecorators.resolve)("ping");
42
- }
43
- pingBody(data) {
44
- return (0, import_signalDecorators.resolve)(global.JSON.stringify(data));
45
- }
46
- pingParam(id) {
47
- return (0, import_signalDecorators.resolve)(id);
48
- }
49
- pingQuery(id) {
50
- return (0, import_signalDecorators.resolve)(id);
51
- }
52
- pingEvery() {
53
- return (0, import_signalDecorators.resolve)("pingEvery");
54
- }
55
- pingUser() {
56
- return (0, import_signalDecorators.resolve)("pingUser");
57
- }
58
- pingAdmin() {
59
- return (0, import_signalDecorators.resolve)("pingAdmin");
60
- }
61
- async cleanup() {
33
+ })
34
+ })) {
35
+ }
36
+ class BaseEndpoint extends (0, import_signalDecorators.endpoint)(srvBase, ({ query, mutation, message, pubsub }) => ({
37
+ ping: query(String, { cache: 3e3 }).exec(function() {
38
+ return "ping";
39
+ }),
40
+ pingBody: query(String, { cache: 1e4 }).body("data", String).exec(function() {
41
+ return "pingBody";
42
+ }),
43
+ pingParam: query(String, { cache: 1e4 }).param("id", String).exec(function() {
44
+ return "pingParam";
45
+ }),
46
+ pingQuery: query(String, { nullable: true }).search("id", String).exec(function(id) {
47
+ return id;
48
+ }),
49
+ pingEvery: query(String).exec(function() {
50
+ return "pingEvery";
51
+ }),
52
+ pingUser: query(String).exec(function() {
53
+ return "pingUser";
54
+ }),
55
+ pingAdmin: query(String).exec(function() {
56
+ return "pingAdmin";
57
+ }),
58
+ getDictionary: query(import_base.JSON).param("lang", String).exec(function(lang) {
59
+ const dictionary = (0, import_dictionary.getDictionary)(lang);
60
+ return dictionary;
61
+ }),
62
+ getAllDictionary: query(import_base.JSON).exec(function() {
63
+ const dictionary = (0, import_dictionary.getAllDictionary)();
64
+ return dictionary;
65
+ }),
66
+ cleanup: mutation(Boolean).exec(async function() {
62
67
  if (process.env.NODE_ENV !== "test")
63
68
  throw new Error("cleanup is only available in test environment");
64
69
  await this.baseService.cleanup();
65
- return (0, import_signalDecorators.resolve)(true);
66
- }
67
- wsPing(data) {
68
- return (0, import_signalDecorators.emit)(data);
69
- }
70
- pubsubPing() {
71
- return (0, import_signalDecorators.subscribe)();
72
- }
73
- getDictionary(lang) {
74
- const dictionary = this.baseService.getDictionary(lang);
75
- return (0, import_signalDecorators.resolve)(dictionary);
76
- }
77
- };
78
- __decorateClass([
79
- import_signalDecorators.Schedule.Interval(3e3)
80
- ], BaseSignal.prototype, "publishPing", 1);
81
- __decorateClass([
82
- import_signalDecorators.Query.Public(() => String, { cache: 3e3 })
83
- ], BaseSignal.prototype, "ping", 1);
84
- __decorateClass([
85
- import_signalDecorators.Query.Public(() => String, { cache: 1e4 }),
86
- __decorateParam(0, import_signalDecorators.Arg.Body("data", () => import_base.JSON))
87
- ], BaseSignal.prototype, "pingBody", 1);
88
- __decorateClass([
89
- import_signalDecorators.Query.Public(() => String, { cache: 1e4 }),
90
- __decorateParam(0, import_signalDecorators.Arg.Param("id", () => String))
91
- ], BaseSignal.prototype, "pingParam", 1);
92
- __decorateClass([
93
- import_signalDecorators.Query.Public(() => String),
94
- __decorateParam(0, import_signalDecorators.Arg.Query("id", () => String))
95
- ], BaseSignal.prototype, "pingQuery", 1);
96
- __decorateClass([
97
- import_signalDecorators.Query.Every(() => String)
98
- ], BaseSignal.prototype, "pingEvery", 1);
99
- __decorateClass([
100
- import_signalDecorators.Query.User(() => String)
101
- ], BaseSignal.prototype, "pingUser", 1);
102
- __decorateClass([
103
- import_signalDecorators.Query.Admin(() => String)
104
- ], BaseSignal.prototype, "pingAdmin", 1);
105
- __decorateClass([
106
- import_signalDecorators.Mutation.Public(() => Boolean)
107
- ], BaseSignal.prototype, "cleanup", 1);
108
- __decorateClass([
109
- import_signalDecorators.Message.Public(() => String),
110
- __decorateParam(0, import_signalDecorators.Arg.Msg("data", () => String))
111
- ], BaseSignal.prototype, "wsPing", 1);
112
- __decorateClass([
113
- import_signalDecorators.Pubsub.Public(() => String)
114
- ], BaseSignal.prototype, "pubsubPing", 1);
115
- __decorateClass([
116
- import_signalDecorators.Query.Public(() => import_base.JSON),
117
- __decorateParam(0, import_signalDecorators.Arg.Param("lang", () => String))
118
- ], BaseSignal.prototype, "getDictionary", 1);
119
- BaseSignal = __decorateClass([
120
- (0, import_signalDecorators.Signal)({ name: "Base" })
121
- ], BaseSignal);
70
+ return true;
71
+ }),
72
+ wsPing: message(String).exec(function() {
73
+ return "wsPing";
74
+ }),
75
+ pubsubPing: pubsub(String).exec(function() {
76
+ }),
77
+ getSignals: query(import_base.JSON).exec(function() {
78
+ return import_signalInfo.signalInfo.serializedSignals;
79
+ })
80
+ })) {
81
+ }
82
+ class BaseSignal extends (0, import_signalDecorators.mergeSignals)(BaseEndpoint, BaseInternal) {
83
+ }
@@ -21,8 +21,7 @@ __export(baseFetch_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(baseFetch_exports);
23
23
  var import_client = require("./client");
24
- const nativeFetch = fetch;
25
- const baseFetch = Object.assign(nativeFetch, {
24
+ const baseFetch = Object.assign(global.fetch, {
26
25
  client: import_client.client,
27
26
  clone: function(option = {}) {
28
27
  return {
package/cjs/src/fetch.js CHANGED
@@ -23,6 +23,8 @@ module.exports = __toCommonJS(fetch_exports);
23
23
  var import_base = require("./base.signal");
24
24
  var import_baseFetch = require("./baseFetch");
25
25
  var import_gql = require("./gql");
26
+ var import_signalInfo = require("./signalInfo");
27
+ import_signalInfo.signalInfo.registerSignals(import_base.BaseSignal);
26
28
  const fetch = (0, import_gql.makeFetch)(import_baseFetch.baseFetch, {
27
29
  ...(0, import_gql.fetchOf)(import_base.BaseSignal)
28
30
  });