@akanjs/signal 0.0.44 → 0.0.45
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.js +2215 -2143
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,186 +1,259 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
29
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
30
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
31
|
+
if (decorator = decorators[i])
|
|
32
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
33
|
+
if (kind && result)
|
|
34
|
+
__defProp(target, key, result);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
39
|
+
// pkgs/@akanjs/signal/index.ts
|
|
40
|
+
var signal_exports = {};
|
|
41
|
+
__export(signal_exports, {
|
|
42
|
+
Access: () => Access,
|
|
43
|
+
Account: () => Account,
|
|
44
|
+
Arg: () => Arg,
|
|
45
|
+
CrystalizeStorage: () => CrystalizeStorage,
|
|
46
|
+
DbSignal: () => DbSignal,
|
|
47
|
+
DefaultStorage: () => DefaultStorage,
|
|
48
|
+
FragmentStorage: () => FragmentStorage,
|
|
49
|
+
GqlStorage: () => GqlStorage,
|
|
50
|
+
Job: () => Job,
|
|
51
|
+
LogSignal: () => LogSignal,
|
|
52
|
+
Me: () => Me,
|
|
53
|
+
Message: () => Message,
|
|
54
|
+
Mutation: () => Mutation,
|
|
55
|
+
Parent: () => Parent,
|
|
56
|
+
Process: () => Process,
|
|
57
|
+
Pubsub: () => Pubsub,
|
|
58
|
+
PurifyStorage: () => PurifyStorage,
|
|
59
|
+
Query: () => Query,
|
|
60
|
+
Req: () => Req,
|
|
61
|
+
Res: () => Res,
|
|
62
|
+
ResolveField: () => ResolveField,
|
|
63
|
+
Self: () => Self,
|
|
64
|
+
Signal: () => Signal,
|
|
65
|
+
SignalStorage: () => SignalStorage,
|
|
66
|
+
UserIp: () => UserIp,
|
|
67
|
+
Ws: () => Ws,
|
|
68
|
+
argTypes: () => argTypes,
|
|
69
|
+
baseFetch: () => baseFetch,
|
|
70
|
+
client: () => client,
|
|
71
|
+
copySignal: () => copySignal,
|
|
72
|
+
createArgMetaDecorator: () => createArgMetaDecorator,
|
|
73
|
+
defaultAccount: () => defaultAccount,
|
|
74
|
+
deserializeArg: () => deserializeArg,
|
|
75
|
+
done: () => done,
|
|
76
|
+
emit: () => emit,
|
|
77
|
+
endpointTypes: () => endpointTypes,
|
|
78
|
+
fetchOf: () => fetchOf,
|
|
79
|
+
getAllSignalRefs: () => getAllSignalRefs,
|
|
80
|
+
getArgMetas: () => getArgMetas,
|
|
81
|
+
getControllerPath: () => getControllerPath,
|
|
82
|
+
getControllerPrefix: () => getControllerPrefix,
|
|
83
|
+
getExampleData: () => getExampleData,
|
|
84
|
+
getGqlMeta: () => getGqlMeta,
|
|
85
|
+
getGqlMetaMapOnPrototype: () => getGqlMetaMapOnPrototype,
|
|
86
|
+
getGqlMetas: () => getGqlMetas,
|
|
87
|
+
getGqlOnStorage: () => getGqlOnStorage,
|
|
88
|
+
getGqlStr: () => getGqlStr,
|
|
89
|
+
getResolveFieldMetas: () => getResolveFieldMetas,
|
|
90
|
+
getSigMeta: () => getSigMeta,
|
|
91
|
+
getSignalRefsOnStorage: () => getSignalRefsOnStorage,
|
|
92
|
+
gqlOf: () => gqlOf,
|
|
93
|
+
guardTypes: () => guardTypes,
|
|
94
|
+
immerify: () => immerify,
|
|
95
|
+
internalArgTypes: () => internalArgTypes,
|
|
96
|
+
makeCrystalize: () => makeCrystalize,
|
|
97
|
+
makeDefault: () => makeDefault,
|
|
98
|
+
makeFetch: () => makeFetch,
|
|
99
|
+
makeFragment: () => makeFragment,
|
|
100
|
+
makePurify: () => makePurify,
|
|
101
|
+
makeRequestExample: () => makeRequestExample,
|
|
102
|
+
makeResponseExample: () => makeResponseExample,
|
|
103
|
+
resolve: () => resolve,
|
|
104
|
+
roleTypes: () => roleTypes,
|
|
105
|
+
scalarUtilOf: () => scalarUtilOf,
|
|
106
|
+
serializeArg: () => serializeArg,
|
|
107
|
+
setArgMetas: () => setArgMetas,
|
|
108
|
+
setGqlMetaMapOnPrototype: () => setGqlMetaMapOnPrototype,
|
|
109
|
+
signalTypes: () => signalTypes,
|
|
110
|
+
ssoTypes: () => ssoTypes,
|
|
111
|
+
subscribe: () => subscribe
|
|
112
|
+
});
|
|
113
|
+
module.exports = __toCommonJS(signal_exports);
|
|
114
|
+
|
|
115
|
+
// pkgs/@akanjs/base/src/base.ts
|
|
116
|
+
var Enum = class {
|
|
117
|
+
constructor(values) {
|
|
118
|
+
this.values = values;
|
|
119
|
+
this.valueMap = new Map(values.map((value, idx) => [value, idx]));
|
|
120
|
+
}
|
|
121
|
+
value;
|
|
122
|
+
// for type
|
|
123
|
+
valueMap;
|
|
124
|
+
has(value) {
|
|
125
|
+
return this.valueMap.has(value);
|
|
126
|
+
}
|
|
127
|
+
indexOf(value) {
|
|
128
|
+
const idx = this.valueMap.get(value);
|
|
129
|
+
if (idx === void 0)
|
|
130
|
+
throw new Error(`Value ${value} is not in enum`);
|
|
131
|
+
return idx;
|
|
132
|
+
}
|
|
133
|
+
find(callback) {
|
|
134
|
+
const val = this.values.find(callback);
|
|
135
|
+
if (val === void 0)
|
|
136
|
+
throw new Error(`Value not found in enum`);
|
|
137
|
+
return val;
|
|
138
|
+
}
|
|
139
|
+
findIndex(callback) {
|
|
140
|
+
const idx = this.values.findIndex(callback);
|
|
141
|
+
if (idx === -1)
|
|
142
|
+
throw new Error(`Value not found in enum`);
|
|
143
|
+
return idx;
|
|
144
|
+
}
|
|
145
|
+
filter(callback) {
|
|
146
|
+
return this.values.filter(callback);
|
|
147
|
+
}
|
|
148
|
+
map(callback) {
|
|
149
|
+
return this.values.map(callback);
|
|
150
|
+
}
|
|
151
|
+
forEach(callback) {
|
|
152
|
+
this.values.forEach(callback);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var DataList = class _DataList {
|
|
156
|
+
// [immerable] = true;
|
|
157
|
+
#idMap;
|
|
158
|
+
length;
|
|
159
|
+
values;
|
|
160
|
+
constructor(data = []) {
|
|
161
|
+
this.values = Array.isArray(data) ? [...data] : [...data.values];
|
|
162
|
+
this.#idMap = new Map(this.values.map((value, idx) => [value.id, idx]));
|
|
163
|
+
this.length = this.values.length;
|
|
164
|
+
}
|
|
165
|
+
indexOf(id) {
|
|
166
|
+
const idx = this.#idMap.get(id);
|
|
167
|
+
if (idx === void 0)
|
|
168
|
+
throw new Error(`Value ${id} is not in list`);
|
|
169
|
+
return idx;
|
|
170
|
+
}
|
|
171
|
+
set(value) {
|
|
172
|
+
const idx = this.#idMap.get(value.id);
|
|
173
|
+
if (idx !== void 0)
|
|
174
|
+
this.values = [...this.values.slice(0, idx), value, ...this.values.slice(idx + 1)];
|
|
175
|
+
else {
|
|
176
|
+
this.#idMap.set(value.id, this.length);
|
|
177
|
+
this.values = [...this.values, value];
|
|
178
|
+
this.length++;
|
|
108
179
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.values.splice(idx, 1);
|
|
115
|
-
this.values.slice(idx).forEach((value, i) => this.#idMap.set(value.id, i + idx));
|
|
116
|
-
this.length--;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
delete(id) {
|
|
183
|
+
const idx = this.#idMap.get(id);
|
|
184
|
+
if (idx === void 0)
|
|
117
185
|
return this;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
this.#idMap.delete(id);
|
|
187
|
+
this.values.splice(idx, 1);
|
|
188
|
+
this.values.slice(idx).forEach((value, i) => this.#idMap.set(value.id, i + idx));
|
|
189
|
+
this.length--;
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
get(id) {
|
|
193
|
+
const idx = this.#idMap.get(id);
|
|
194
|
+
if (idx === void 0)
|
|
195
|
+
return void 0;
|
|
196
|
+
return this.values[idx];
|
|
197
|
+
}
|
|
198
|
+
at(idx) {
|
|
199
|
+
return this.values.at(idx);
|
|
200
|
+
}
|
|
201
|
+
pickAt(idx) {
|
|
202
|
+
const value = this.values.at(idx);
|
|
203
|
+
if (value === void 0)
|
|
204
|
+
throw new Error(`Value at ${idx} is undefined`);
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
pick(id) {
|
|
208
|
+
return this.values[this.indexOf(id)];
|
|
209
|
+
}
|
|
210
|
+
has(id) {
|
|
211
|
+
return this.#idMap.has(id);
|
|
212
|
+
}
|
|
213
|
+
find(fn) {
|
|
214
|
+
const val = this.values.find(fn);
|
|
215
|
+
return val;
|
|
216
|
+
}
|
|
217
|
+
findIndex(fn) {
|
|
218
|
+
const val = this.values.findIndex(fn);
|
|
219
|
+
return val;
|
|
220
|
+
}
|
|
221
|
+
some(fn) {
|
|
222
|
+
return this.values.some(fn);
|
|
223
|
+
}
|
|
224
|
+
every(fn) {
|
|
225
|
+
return this.values.every(fn);
|
|
226
|
+
}
|
|
227
|
+
forEach(fn) {
|
|
228
|
+
this.values.forEach(fn);
|
|
229
|
+
}
|
|
230
|
+
map(fn) {
|
|
231
|
+
return this.values.map(fn);
|
|
232
|
+
}
|
|
233
|
+
flatMap(fn) {
|
|
234
|
+
return this.values.flatMap(fn);
|
|
235
|
+
}
|
|
236
|
+
sort(fn) {
|
|
237
|
+
return new _DataList(this.values.sort(fn));
|
|
238
|
+
}
|
|
239
|
+
filter(fn) {
|
|
240
|
+
return new _DataList(this.values.filter(fn));
|
|
241
|
+
}
|
|
242
|
+
reduce(fn, initialValue) {
|
|
243
|
+
return this.values.reduce(fn, initialValue);
|
|
244
|
+
}
|
|
245
|
+
slice(start, end = this.length) {
|
|
246
|
+
return new _DataList(this.values.slice(start, end));
|
|
247
|
+
}
|
|
248
|
+
save() {
|
|
249
|
+
return new _DataList(this);
|
|
250
|
+
}
|
|
251
|
+
[Symbol.iterator]() {
|
|
252
|
+
return this.values[Symbol.iterator]();
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
var version = "0.9.0";
|
|
256
|
+
var logo = `
|
|
184
257
|
_ _ _
|
|
185
258
|
/ \\ | | ____ _ _ __ (_)___
|
|
186
259
|
/ _ \\ | |/ / _' | '_ \\ | / __|
|
|
@@ -192,1857 +265,1823 @@
|
|
|
192
265
|
|
|
193
266
|
`;
|
|
194
267
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
268
|
+
// pkgs/@akanjs/base/src/baseEnv.ts
|
|
269
|
+
var appName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
|
|
270
|
+
var repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
|
|
271
|
+
var serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
|
|
272
|
+
if (appName === "unknown")
|
|
273
|
+
throw new Error("environment variable NEXT_PUBLIC_APP_NAME is required");
|
|
274
|
+
if (repoName === "unknown")
|
|
275
|
+
throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
|
|
276
|
+
if (serveDomain === "unknown")
|
|
277
|
+
throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
|
|
278
|
+
var environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
279
|
+
var operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
|
|
280
|
+
var operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
|
|
281
|
+
var networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
|
|
282
|
+
var tunnelUsername = process.env.SSU_TUNNEL_USERNAME ?? "root";
|
|
283
|
+
var tunnelPassword = process.env.SSU_TUNNEL_PASSWORD ?? repoName;
|
|
284
|
+
var baseEnv = {
|
|
285
|
+
repoName,
|
|
286
|
+
serveDomain,
|
|
287
|
+
appName,
|
|
288
|
+
environment,
|
|
289
|
+
operationType,
|
|
290
|
+
operationMode,
|
|
291
|
+
networkType,
|
|
292
|
+
tunnelUsername,
|
|
293
|
+
tunnelPassword
|
|
294
|
+
};
|
|
295
|
+
var side = typeof window === "undefined" ? "server" : "client";
|
|
296
|
+
var renderMode = process.env.RENDER_ENV ?? "ssr";
|
|
297
|
+
var clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
|
|
298
|
+
var clientPort = parseInt(
|
|
299
|
+
process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
|
|
300
|
+
);
|
|
301
|
+
var clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
|
|
302
|
+
var clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
|
|
303
|
+
var serverHost = process.env.SERVER_HOST ?? (operationMode === "local" ? typeof window === "undefined" ? "localhost" : window.location.host.split(":")[0] : renderMode === "csr" ? `${appName}-${environment}.${serveDomain}` : side === "client" ? window.location.host.split(":")[0] : operationMode === "cloud" ? `backend-svc.${appName}-${environment}.svc.cluster.local` : "localhost");
|
|
304
|
+
var serverPort = parseInt(
|
|
305
|
+
process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
|
|
306
|
+
);
|
|
307
|
+
var serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
|
|
308
|
+
var serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
|
|
309
|
+
var serverGraphqlUri = `${serverHttpUri}/graphql`;
|
|
310
|
+
var serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
|
|
311
|
+
var serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
|
|
312
|
+
var baseClientEnv = {
|
|
313
|
+
...baseEnv,
|
|
314
|
+
side,
|
|
315
|
+
renderMode,
|
|
316
|
+
websocket: true,
|
|
317
|
+
clientHost,
|
|
318
|
+
clientPort,
|
|
319
|
+
clientHttpProtocol,
|
|
320
|
+
clientHttpUri,
|
|
321
|
+
serverHost,
|
|
322
|
+
serverPort,
|
|
323
|
+
serverHttpProtocol,
|
|
324
|
+
serverHttpUri,
|
|
325
|
+
serverGraphqlUri,
|
|
326
|
+
serverWsProtocol,
|
|
327
|
+
serverWsUri
|
|
328
|
+
};
|
|
256
329
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
// pkgs/@akanjs/base/src/scalar.ts
|
|
331
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
332
|
+
var dayjs = import_dayjs.default;
|
|
333
|
+
var Int = class {
|
|
334
|
+
__Scalar__;
|
|
335
|
+
};
|
|
336
|
+
var Upload = class {
|
|
337
|
+
__Scalar__;
|
|
338
|
+
filename;
|
|
339
|
+
mimetype;
|
|
340
|
+
encoding;
|
|
341
|
+
createReadStream;
|
|
342
|
+
};
|
|
343
|
+
var Float = class {
|
|
344
|
+
__Scalar__;
|
|
345
|
+
};
|
|
346
|
+
var ID = class {
|
|
347
|
+
__Scalar__;
|
|
348
|
+
};
|
|
349
|
+
var JSON2 = class {
|
|
350
|
+
__Scalar__;
|
|
351
|
+
};
|
|
352
|
+
var getNonArrayModel = (arraiedModel2) => {
|
|
353
|
+
let arrDepth = 0;
|
|
354
|
+
let target = arraiedModel2;
|
|
355
|
+
while (Array.isArray(target)) {
|
|
356
|
+
target = target[0];
|
|
357
|
+
arrDepth++;
|
|
358
|
+
}
|
|
359
|
+
return [target, arrDepth];
|
|
360
|
+
};
|
|
361
|
+
var arraiedModel = (modelRef, arrDepth = 0) => {
|
|
362
|
+
let target = modelRef;
|
|
363
|
+
for (let i = 0; i < arrDepth; i++)
|
|
364
|
+
target = [target];
|
|
365
|
+
return target;
|
|
366
|
+
};
|
|
367
|
+
var applyFnToArrayObjects = (arraiedData, fn) => {
|
|
368
|
+
if (Array.isArray(arraiedData))
|
|
369
|
+
return arraiedData.map((data) => applyFnToArrayObjects(data, fn));
|
|
370
|
+
return fn(arraiedData);
|
|
371
|
+
};
|
|
372
|
+
var scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON2, Map]);
|
|
373
|
+
var scalarNameMap = /* @__PURE__ */ new Map([
|
|
374
|
+
[ID, "ID"],
|
|
375
|
+
[Int, "Int"],
|
|
376
|
+
[Float, "Float"],
|
|
377
|
+
[String, "String"],
|
|
378
|
+
[Boolean, "Boolean"],
|
|
379
|
+
[Date, "Date"],
|
|
380
|
+
[Upload, "Upload"],
|
|
381
|
+
[JSON2, "JSON"],
|
|
382
|
+
[Map, "Map"]
|
|
383
|
+
]);
|
|
384
|
+
var scalarArgMap = /* @__PURE__ */ new Map([
|
|
385
|
+
[ID, null],
|
|
386
|
+
[String, ""],
|
|
387
|
+
[Boolean, false],
|
|
388
|
+
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
389
|
+
[Int, 0],
|
|
390
|
+
[Float, 0],
|
|
391
|
+
[JSON2, {}],
|
|
392
|
+
[Map, {}]
|
|
393
|
+
]);
|
|
394
|
+
var scalarDefaultMap = /* @__PURE__ */ new Map([
|
|
395
|
+
[ID, null],
|
|
396
|
+
[String, ""],
|
|
397
|
+
[Boolean, false],
|
|
398
|
+
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
399
|
+
[Int, 0],
|
|
400
|
+
[Float, 0],
|
|
401
|
+
[JSON2, {}]
|
|
402
|
+
]);
|
|
403
|
+
var isGqlScalar = (modelRef) => scalarSet.has(modelRef);
|
|
404
|
+
var isGqlMap = (modelRef) => modelRef === Map;
|
|
332
405
|
|
|
333
|
-
|
|
334
|
-
|
|
406
|
+
// pkgs/@akanjs/common/src/isDayjs.ts
|
|
407
|
+
var import_dayjs2 = require("dayjs");
|
|
335
408
|
|
|
336
|
-
|
|
337
|
-
|
|
409
|
+
// pkgs/@akanjs/common/src/isQueryEqual.ts
|
|
410
|
+
var import_dayjs3 = __toESM(require("dayjs"));
|
|
338
411
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
412
|
+
// pkgs/@akanjs/common/src/isValidDate.ts
|
|
413
|
+
var import_dayjs4 = __toESM(require("dayjs"));
|
|
414
|
+
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
415
|
+
import_dayjs4.default.extend(import_customParseFormat.default);
|
|
343
416
|
|
|
344
|
-
|
|
345
|
-
|
|
417
|
+
// pkgs/@akanjs/common/src/pluralize.ts
|
|
418
|
+
var import_pluralize = __toESM(require("pluralize"));
|
|
346
419
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
});
|
|
355
|
-
current = Object.getPrototypeOf(current);
|
|
356
|
-
}
|
|
357
|
-
return descriptors;
|
|
358
|
-
};
|
|
359
|
-
var applyMixins = (derivedCtor, constructors, avoidKeys) => {
|
|
360
|
-
constructors.forEach((baseCtor) => {
|
|
361
|
-
Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
|
|
362
|
-
if (name === "constructor" || avoidKeys?.has(name))
|
|
363
|
-
return;
|
|
364
|
-
Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
|
|
365
|
-
});
|
|
420
|
+
// pkgs/@akanjs/common/src/applyMixins.ts
|
|
421
|
+
var getAllPropertyDescriptors = (objRef) => {
|
|
422
|
+
const descriptors = {};
|
|
423
|
+
let current = objRef.prototype;
|
|
424
|
+
while (current) {
|
|
425
|
+
Object.getOwnPropertyNames(current).forEach((name) => {
|
|
426
|
+
descriptors[name] ??= Object.getOwnPropertyDescriptor(current, name);
|
|
366
427
|
});
|
|
367
|
-
|
|
428
|
+
current = Object.getPrototypeOf(current);
|
|
429
|
+
}
|
|
430
|
+
return descriptors;
|
|
431
|
+
};
|
|
432
|
+
var applyMixins = (derivedCtor, constructors, avoidKeys) => {
|
|
433
|
+
constructors.forEach((baseCtor) => {
|
|
434
|
+
Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
|
|
435
|
+
if (name === "constructor" || avoidKeys?.has(name))
|
|
436
|
+
return;
|
|
437
|
+
Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
};
|
|
368
441
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
442
|
+
// pkgs/@akanjs/common/src/capitalize.ts
|
|
443
|
+
var capitalize = (str) => {
|
|
444
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
445
|
+
};
|
|
373
446
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
447
|
+
// pkgs/@akanjs/common/src/Logger.ts
|
|
448
|
+
var import_dayjs5 = __toESM(require("dayjs"));
|
|
449
|
+
var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
450
|
+
var clc = {
|
|
451
|
+
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
452
|
+
green: (text) => `\x1B[32m${text}\x1B[39m`,
|
|
453
|
+
yellow: (text) => `\x1B[33m${text}\x1B[39m`,
|
|
454
|
+
red: (text) => `\x1B[31m${text}\x1B[39m`,
|
|
455
|
+
magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
|
|
456
|
+
cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
|
|
457
|
+
};
|
|
458
|
+
var colorizeMap = {
|
|
459
|
+
trace: clc.bold,
|
|
460
|
+
verbose: clc.cyanBright,
|
|
461
|
+
debug: clc.magentaBright,
|
|
462
|
+
log: clc.green,
|
|
463
|
+
info: clc.green,
|
|
464
|
+
warn: clc.yellow,
|
|
465
|
+
error: clc.red
|
|
466
|
+
};
|
|
467
|
+
var Logger = class _Logger {
|
|
468
|
+
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
469
|
+
"InstanceLoader",
|
|
470
|
+
"RoutesResolver",
|
|
471
|
+
"RouterExplorer",
|
|
472
|
+
"NestFactory",
|
|
473
|
+
"WebSocketsController",
|
|
474
|
+
"GraphQLModule",
|
|
475
|
+
"NestApplication"
|
|
476
|
+
]);
|
|
477
|
+
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
478
|
+
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
479
|
+
static #startAt = (0, import_dayjs5.default)();
|
|
480
|
+
static setLevel(level) {
|
|
481
|
+
this.level = level;
|
|
482
|
+
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
483
|
+
}
|
|
484
|
+
name;
|
|
485
|
+
constructor(name) {
|
|
486
|
+
this.name = name;
|
|
487
|
+
}
|
|
488
|
+
trace(msg, context = "") {
|
|
489
|
+
if (_Logger.#levelIdx <= 0)
|
|
490
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
491
|
+
}
|
|
492
|
+
verbose(msg, context = "") {
|
|
493
|
+
if (_Logger.#levelIdx <= 1)
|
|
494
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
495
|
+
}
|
|
496
|
+
debug(msg, context = "") {
|
|
497
|
+
if (_Logger.#levelIdx <= 2)
|
|
498
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
499
|
+
}
|
|
500
|
+
log(msg, context = "") {
|
|
501
|
+
if (_Logger.#levelIdx <= 3)
|
|
502
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
503
|
+
}
|
|
504
|
+
info(msg, context = "") {
|
|
505
|
+
if (_Logger.#levelIdx <= 4)
|
|
506
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
507
|
+
}
|
|
508
|
+
warn(msg, context = "") {
|
|
509
|
+
if (_Logger.#levelIdx <= 5)
|
|
510
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
511
|
+
}
|
|
512
|
+
error(msg, context = "") {
|
|
513
|
+
if (_Logger.#levelIdx <= 6)
|
|
514
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
515
|
+
}
|
|
516
|
+
raw(msg, method) {
|
|
517
|
+
_Logger.rawLog(msg, method);
|
|
518
|
+
}
|
|
519
|
+
rawLog(msg, method) {
|
|
520
|
+
_Logger.rawLog(msg, method);
|
|
521
|
+
}
|
|
522
|
+
static trace(msg, context = "") {
|
|
523
|
+
if (_Logger.#levelIdx <= 0)
|
|
524
|
+
_Logger.#printMessages("App", msg, context, "trace");
|
|
525
|
+
}
|
|
526
|
+
static verbose(msg, context = "") {
|
|
527
|
+
if (_Logger.#levelIdx <= 1)
|
|
528
|
+
_Logger.#printMessages("App", msg, context, "verbose");
|
|
529
|
+
}
|
|
530
|
+
static debug(msg, context = "") {
|
|
531
|
+
if (_Logger.#levelIdx <= 2)
|
|
532
|
+
_Logger.#printMessages("App", msg, context, "debug");
|
|
533
|
+
}
|
|
534
|
+
static log(msg, context = "") {
|
|
535
|
+
if (_Logger.#levelIdx <= 3)
|
|
536
|
+
_Logger.#printMessages("App", msg, context, "log");
|
|
537
|
+
}
|
|
538
|
+
static info(msg, context = "") {
|
|
539
|
+
if (_Logger.#levelIdx <= 4)
|
|
540
|
+
_Logger.#printMessages("App", msg, context, "info");
|
|
541
|
+
}
|
|
542
|
+
static warn(msg, context = "") {
|
|
543
|
+
if (_Logger.#levelIdx <= 5)
|
|
544
|
+
_Logger.#printMessages("App", msg, context, "warn");
|
|
545
|
+
}
|
|
546
|
+
static error(msg, context = "") {
|
|
547
|
+
if (_Logger.#levelIdx <= 6)
|
|
548
|
+
_Logger.#printMessages("App", msg, context, "error");
|
|
549
|
+
}
|
|
550
|
+
static #colorize(msg, logLevel) {
|
|
551
|
+
return colorizeMap[logLevel](msg);
|
|
552
|
+
}
|
|
553
|
+
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
554
|
+
if (this.#ignoreCtxSet.has(context))
|
|
555
|
+
return;
|
|
556
|
+
const now = (0, import_dayjs5.default)();
|
|
557
|
+
const processMsg = this.#colorize(
|
|
558
|
+
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
559
|
+
logLevel
|
|
560
|
+
);
|
|
561
|
+
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
562
|
+
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
563
|
+
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
564
|
+
const contentMsg = this.#colorize(content, logLevel);
|
|
565
|
+
const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
|
|
566
|
+
if (typeof window === "undefined")
|
|
567
|
+
process[writeStreamType].write(
|
|
568
|
+
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
496
569
|
`
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
570
|
+
);
|
|
571
|
+
else
|
|
572
|
+
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
500
573
|
`);
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
574
|
+
}
|
|
575
|
+
static rawLog(msg, method) {
|
|
576
|
+
this.raw(`${msg}
|
|
504
577
|
`, method);
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
578
|
+
}
|
|
579
|
+
static raw(msg, method) {
|
|
580
|
+
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
581
|
+
global.process.stdout.write(msg);
|
|
582
|
+
else
|
|
583
|
+
console.log(msg);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
513
586
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
587
|
+
// pkgs/@akanjs/common/src/lowerlize.ts
|
|
588
|
+
var lowerlize = (str) => {
|
|
589
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
590
|
+
};
|
|
518
591
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
592
|
+
// pkgs/@akanjs/common/src/sleep.ts
|
|
593
|
+
var sleep = async (ms) => {
|
|
594
|
+
return new Promise((resolve2) => {
|
|
595
|
+
setTimeout(() => {
|
|
596
|
+
resolve2(true);
|
|
597
|
+
}, ms);
|
|
598
|
+
});
|
|
599
|
+
};
|
|
527
600
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
539
|
-
});
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
on(event, callback) {
|
|
543
|
-
this.socket.on(event, callback);
|
|
544
|
-
}
|
|
545
|
-
removeListener(event, callback) {
|
|
546
|
-
this.socket.removeListener(event, callback);
|
|
547
|
-
}
|
|
548
|
-
removeAllListeners() {
|
|
549
|
-
this.socket.removeAllListeners();
|
|
550
|
-
}
|
|
551
|
-
hasListeners(event) {
|
|
552
|
-
return this.socket.hasListeners(event);
|
|
553
|
-
}
|
|
554
|
-
emit(key, data) {
|
|
555
|
-
this.socket.emit(key, data);
|
|
556
|
-
}
|
|
557
|
-
subscribe(option) {
|
|
558
|
-
if (!this.roomSubscribeMap.has(option.roomId)) {
|
|
559
|
-
this.roomSubscribeMap.set(option.roomId, option);
|
|
601
|
+
// pkgs/@akanjs/signal/src/client.ts
|
|
602
|
+
var import_core = require("@urql/core");
|
|
603
|
+
var import_socket = require("socket.io-client");
|
|
604
|
+
var SocketIo = class {
|
|
605
|
+
socket;
|
|
606
|
+
roomSubscribeMap = /* @__PURE__ */ new Map();
|
|
607
|
+
constructor(uri) {
|
|
608
|
+
this.socket = (0, import_socket.io)(uri, { transports: ["websocket"] });
|
|
609
|
+
this.socket.on("connect", () => {
|
|
610
|
+
this.roomSubscribeMap.forEach((option) => {
|
|
560
611
|
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
561
|
-
}
|
|
562
|
-
this.socket.on(option.roomId, option.handleEvent);
|
|
563
|
-
}
|
|
564
|
-
unsubscribe(roomId, handleEvent) {
|
|
565
|
-
this.socket.removeListener(roomId, handleEvent);
|
|
566
|
-
const option = this.roomSubscribeMap.get(roomId);
|
|
567
|
-
if (this.hasListeners(roomId) || !option)
|
|
568
|
-
return;
|
|
569
|
-
this.roomSubscribeMap.delete(roomId);
|
|
570
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: false });
|
|
571
|
-
}
|
|
572
|
-
disconnect() {
|
|
573
|
-
this.socket.disconnect();
|
|
574
|
-
return this;
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
var Client = class _Client {
|
|
578
|
-
static globalIoMap = /* @__PURE__ */ new Map();
|
|
579
|
-
static tokenStore = /* @__PURE__ */ new Map();
|
|
580
|
-
async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
|
|
581
|
-
if (baseClientEnv.side === "server")
|
|
582
|
-
return true;
|
|
583
|
-
while (!this.getIo(ws).socket.connected) {
|
|
584
|
-
Logger.verbose("waiting for websocket to initialize...");
|
|
585
|
-
await sleep(300);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
isInitialized = false;
|
|
589
|
-
uri = baseClientEnv.serverGraphqlUri;
|
|
590
|
-
ws = baseClientEnv.serverWsUri;
|
|
591
|
-
udp = null;
|
|
592
|
-
gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
|
|
593
|
-
jwt = null;
|
|
594
|
-
async getJwt() {
|
|
595
|
-
const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
|
|
596
|
-
if (isNextServer) {
|
|
597
|
-
const nextHeaders = __require("next/headers");
|
|
598
|
-
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
599
|
-
} else
|
|
600
|
-
return _Client.tokenStore.get(this) ?? null;
|
|
601
|
-
}
|
|
602
|
-
io = null;
|
|
603
|
-
init(data = {}) {
|
|
604
|
-
Object.assign(this, data);
|
|
605
|
-
this.setLink(data.uri);
|
|
606
|
-
this.setIo(data.ws);
|
|
607
|
-
this.isInitialized = true;
|
|
608
|
-
}
|
|
609
|
-
setIo(ws = baseClientEnv.serverWsUri) {
|
|
610
|
-
this.ws = ws;
|
|
611
|
-
const existingIo = _Client.globalIoMap.get(ws);
|
|
612
|
-
if (existingIo) {
|
|
613
|
-
this.io = existingIo;
|
|
614
|
-
return;
|
|
615
|
-
}
|
|
616
|
-
this.io = new SocketIo(ws);
|
|
617
|
-
_Client.globalIoMap.set(ws, this.io);
|
|
618
|
-
}
|
|
619
|
-
getIo(ws = baseClientEnv.serverWsUri) {
|
|
620
|
-
const existingIo = _Client.globalIoMap.get(ws);
|
|
621
|
-
if (existingIo)
|
|
622
|
-
return existingIo;
|
|
623
|
-
const io2 = new SocketIo(ws);
|
|
624
|
-
_Client.globalIoMap.set(ws, io2);
|
|
625
|
-
return io2;
|
|
626
|
-
}
|
|
627
|
-
setLink(uri = baseClientEnv.serverGraphqlUri) {
|
|
628
|
-
this.uri = uri;
|
|
629
|
-
this.gql = (0, import_core.createClient)({
|
|
630
|
-
url: this.uri,
|
|
631
|
-
fetch,
|
|
632
|
-
exchanges: [import_core.cacheExchange, import_core.fetchExchange],
|
|
633
|
-
// requestPolicy: "network-only",
|
|
634
|
-
fetchOptions: () => {
|
|
635
|
-
return {
|
|
636
|
-
headers: {
|
|
637
|
-
"apollo-require-preflight": "true",
|
|
638
|
-
...this.jwt ? { authorization: `Bearer ${this.jwt}` } : {}
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
612
|
});
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
on(event, callback) {
|
|
616
|
+
this.socket.on(event, callback);
|
|
617
|
+
}
|
|
618
|
+
removeListener(event, callback) {
|
|
619
|
+
this.socket.removeListener(event, callback);
|
|
620
|
+
}
|
|
621
|
+
removeAllListeners() {
|
|
622
|
+
this.socket.removeAllListeners();
|
|
623
|
+
}
|
|
624
|
+
hasListeners(event) {
|
|
625
|
+
return this.socket.hasListeners(event);
|
|
626
|
+
}
|
|
627
|
+
emit(key, data) {
|
|
628
|
+
this.socket.emit(key, data);
|
|
629
|
+
}
|
|
630
|
+
subscribe(option) {
|
|
631
|
+
if (!this.roomSubscribeMap.has(option.roomId)) {
|
|
632
|
+
this.roomSubscribeMap.set(option.roomId, option);
|
|
633
|
+
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
643
634
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
635
|
+
this.socket.on(option.roomId, option.handleEvent);
|
|
636
|
+
}
|
|
637
|
+
unsubscribe(roomId, handleEvent) {
|
|
638
|
+
this.socket.removeListener(roomId, handleEvent);
|
|
639
|
+
const option = this.roomSubscribeMap.get(roomId);
|
|
640
|
+
if (this.hasListeners(roomId) || !option)
|
|
641
|
+
return;
|
|
642
|
+
this.roomSubscribeMap.delete(roomId);
|
|
643
|
+
this.socket.emit(option.key, { ...option.message, __subscribe__: false });
|
|
644
|
+
}
|
|
645
|
+
disconnect() {
|
|
646
|
+
this.socket.disconnect();
|
|
647
|
+
return this;
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
var Client = class _Client {
|
|
651
|
+
static globalIoMap = /* @__PURE__ */ new Map();
|
|
652
|
+
static tokenStore = /* @__PURE__ */ new Map();
|
|
653
|
+
async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
|
|
654
|
+
if (baseClientEnv.side === "server")
|
|
655
|
+
return true;
|
|
656
|
+
while (!this.getIo(ws).socket.connected) {
|
|
657
|
+
Logger.verbose("waiting for websocket to initialize...");
|
|
658
|
+
await sleep(300);
|
|
666
659
|
}
|
|
667
|
-
}
|
|
668
|
-
|
|
660
|
+
}
|
|
661
|
+
isInitialized = false;
|
|
662
|
+
uri = baseClientEnv.serverGraphqlUri;
|
|
663
|
+
ws = baseClientEnv.serverWsUri;
|
|
664
|
+
udp = null;
|
|
665
|
+
gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
|
|
666
|
+
jwt = null;
|
|
667
|
+
async getJwt() {
|
|
668
|
+
const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
|
|
669
|
+
if (isNextServer) {
|
|
670
|
+
const nextHeaders = require("next/headers");
|
|
671
|
+
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
672
|
+
} else
|
|
673
|
+
return _Client.tokenStore.get(this) ?? null;
|
|
674
|
+
}
|
|
675
|
+
io = null;
|
|
676
|
+
init(data = {}) {
|
|
677
|
+
Object.assign(this, data);
|
|
678
|
+
this.setLink(data.uri);
|
|
679
|
+
this.setIo(data.ws);
|
|
680
|
+
this.isInitialized = true;
|
|
681
|
+
}
|
|
682
|
+
setIo(ws = baseClientEnv.serverWsUri) {
|
|
683
|
+
this.ws = ws;
|
|
684
|
+
const existingIo = _Client.globalIoMap.get(ws);
|
|
685
|
+
if (existingIo) {
|
|
686
|
+
this.io = existingIo;
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
this.io = new SocketIo(ws);
|
|
690
|
+
_Client.globalIoMap.set(ws, this.io);
|
|
691
|
+
}
|
|
692
|
+
getIo(ws = baseClientEnv.serverWsUri) {
|
|
693
|
+
const existingIo = _Client.globalIoMap.get(ws);
|
|
694
|
+
if (existingIo)
|
|
695
|
+
return existingIo;
|
|
696
|
+
const io2 = new SocketIo(ws);
|
|
697
|
+
_Client.globalIoMap.set(ws, io2);
|
|
698
|
+
return io2;
|
|
699
|
+
}
|
|
700
|
+
setLink(uri = baseClientEnv.serverGraphqlUri) {
|
|
701
|
+
this.uri = uri;
|
|
702
|
+
this.gql = (0, import_core.createClient)({
|
|
703
|
+
url: this.uri,
|
|
704
|
+
fetch,
|
|
705
|
+
exchanges: [import_core.cacheExchange, import_core.fetchExchange],
|
|
706
|
+
// requestPolicy: "network-only",
|
|
707
|
+
fetchOptions: () => {
|
|
708
|
+
return {
|
|
709
|
+
headers: {
|
|
710
|
+
"apollo-require-preflight": "true",
|
|
711
|
+
...this.jwt ? { authorization: `Bearer ${this.jwt}` } : {}
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
setJwt(jwt) {
|
|
718
|
+
_Client.tokenStore.set(this, jwt);
|
|
719
|
+
}
|
|
720
|
+
reset() {
|
|
721
|
+
this.io?.disconnect();
|
|
722
|
+
this.io = null;
|
|
723
|
+
this.jwt = null;
|
|
724
|
+
}
|
|
725
|
+
clone(data = {}) {
|
|
726
|
+
const newClient = new _Client();
|
|
727
|
+
newClient.init({ ...this, ...data });
|
|
728
|
+
if (data.jwt)
|
|
729
|
+
_Client.tokenStore.set(newClient, data.jwt);
|
|
730
|
+
return newClient;
|
|
731
|
+
}
|
|
732
|
+
terminate() {
|
|
733
|
+
this.reset();
|
|
734
|
+
_Client.globalIoMap.forEach((io2) => io2.disconnect());
|
|
735
|
+
this.isInitialized = false;
|
|
736
|
+
}
|
|
737
|
+
setUdp(udp) {
|
|
738
|
+
this.udp = udp;
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
var client = new Client();
|
|
669
742
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
743
|
+
// pkgs/@akanjs/constant/src/scalar.ts
|
|
744
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
745
|
+
var scalarExampleMap = /* @__PURE__ */ new Map([
|
|
746
|
+
[ID, "1234567890abcdef12345678"],
|
|
747
|
+
[Int, 0],
|
|
748
|
+
[Float, 0],
|
|
749
|
+
[String, "String"],
|
|
750
|
+
[Boolean, true],
|
|
751
|
+
[Date, (/* @__PURE__ */ new Date()).toISOString()],
|
|
752
|
+
[Upload, "FileUpload"],
|
|
753
|
+
[JSON2, {}],
|
|
754
|
+
[Map, {}]
|
|
755
|
+
]);
|
|
756
|
+
var getScalarExample = (ref) => scalarExampleMap.get(ref) ?? null;
|
|
757
|
+
var getGqlTypeStr = (ref) => scalarNameMap.get(ref) ?? getClassMeta(ref).refName;
|
|
758
|
+
var getClassMeta = (modelRef) => {
|
|
759
|
+
const [target] = getNonArrayModel(modelRef);
|
|
760
|
+
const classMeta = Reflect.getMetadata("class", target.prototype);
|
|
761
|
+
if (!classMeta)
|
|
762
|
+
throw new Error(`No ClassMeta for this target ${target.name}`);
|
|
763
|
+
return classMeta;
|
|
764
|
+
};
|
|
765
|
+
var getFieldMetas = (modelRef) => {
|
|
766
|
+
const [target] = getNonArrayModel(modelRef);
|
|
767
|
+
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
768
|
+
const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
|
|
769
|
+
return [...metadataMap.values()].sort((a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0));
|
|
770
|
+
};
|
|
771
|
+
var getFieldMetaMap = (modelRef) => {
|
|
772
|
+
const [target] = getNonArrayModel(modelRef);
|
|
773
|
+
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
774
|
+
return new Map(metadataMap);
|
|
775
|
+
};
|
|
776
|
+
var getFieldMetaMapOnPrototype = (prototype) => {
|
|
777
|
+
const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
|
|
778
|
+
return new Map(metadataMap);
|
|
779
|
+
};
|
|
780
|
+
var setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
781
|
+
Reflect.defineMetadata("fields", new Map(metadataMap), prototype);
|
|
782
|
+
};
|
|
710
783
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
};
|
|
752
|
-
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
753
|
-
metadataMap.set(key, metadata);
|
|
754
|
-
setFieldMetaMapOnPrototype(prototype, metadataMap);
|
|
784
|
+
// pkgs/@akanjs/constant/src/fieldMeta.ts
|
|
785
|
+
var applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
786
|
+
const isArray = arrDepth > 0;
|
|
787
|
+
const isClass = !isGqlScalar(modelRef);
|
|
788
|
+
const isMap = isGqlMap(modelRef);
|
|
789
|
+
const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
|
|
790
|
+
const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
|
|
791
|
+
if (isMap && !option.of)
|
|
792
|
+
throw new Error("Map type must have 'of' option");
|
|
793
|
+
return (prototype, key) => {
|
|
794
|
+
const metadata = {
|
|
795
|
+
nullable: option.nullable ?? false,
|
|
796
|
+
ref: option.ref,
|
|
797
|
+
refPath: option.refPath,
|
|
798
|
+
refType: option.refType,
|
|
799
|
+
default: option.default ?? (isArray ? [] : null),
|
|
800
|
+
type: option.type,
|
|
801
|
+
fieldType: option.fieldType ?? "property",
|
|
802
|
+
immutable: option.immutable ?? false,
|
|
803
|
+
min: option.min,
|
|
804
|
+
max: option.max,
|
|
805
|
+
enum: option.enum,
|
|
806
|
+
select: option.select ?? true,
|
|
807
|
+
minlength: option.minlength,
|
|
808
|
+
maxlength: option.maxlength,
|
|
809
|
+
query: option.query,
|
|
810
|
+
accumulate: option.accumulate,
|
|
811
|
+
example: option.example,
|
|
812
|
+
validate: option.validate,
|
|
813
|
+
key,
|
|
814
|
+
name,
|
|
815
|
+
isClass,
|
|
816
|
+
isScalar: type === "scalar",
|
|
817
|
+
modelRef,
|
|
818
|
+
arrDepth,
|
|
819
|
+
isArray,
|
|
820
|
+
optArrDepth: optionArrDepth,
|
|
821
|
+
isMap,
|
|
822
|
+
of: option.of,
|
|
823
|
+
text: option.text
|
|
755
824
|
};
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
}
|
|
825
|
+
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
826
|
+
metadataMap.set(key, metadata);
|
|
827
|
+
setFieldMetaMapOnPrototype(prototype, metadataMap);
|
|
828
|
+
};
|
|
829
|
+
};
|
|
830
|
+
var makeField = (customOption) => (returns, fieldOption) => {
|
|
831
|
+
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
832
|
+
if (!fieldOption)
|
|
833
|
+
return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
|
|
834
|
+
const [opt, optArrDepth] = getNonArrayModel(fieldOption);
|
|
835
|
+
return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
|
|
836
|
+
};
|
|
837
|
+
var Field = {
|
|
838
|
+
Prop: makeField({ fieldType: "property" }),
|
|
839
|
+
Hidden: makeField({ fieldType: "hidden", nullable: true }),
|
|
840
|
+
Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
|
|
841
|
+
Resolve: makeField({ fieldType: "resolve" })
|
|
842
|
+
};
|
|
770
843
|
|
|
771
|
-
|
|
772
|
-
|
|
844
|
+
// pkgs/@akanjs/constant/src/constantDecorator.ts
|
|
845
|
+
var import_reflect_metadata2 = require("reflect-metadata");
|
|
773
846
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
847
|
+
// pkgs/@akanjs/constant/src/filterMeta.ts
|
|
848
|
+
var setFilterMeta = (filterRef, filterMeta) => {
|
|
849
|
+
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
850
|
+
if (existingFilterMeta)
|
|
851
|
+
Object.assign(filterMeta.sort, existingFilterMeta.sort);
|
|
852
|
+
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
853
|
+
};
|
|
854
|
+
var getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
855
|
+
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
856
|
+
return new Map(metadataMap);
|
|
857
|
+
};
|
|
858
|
+
var setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
859
|
+
Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
|
|
860
|
+
};
|
|
861
|
+
var applyFilterKeyMeta = (option) => {
|
|
862
|
+
return (prototype, key, descriptor) => {
|
|
863
|
+
const metadata = { key, ...option, descriptor };
|
|
864
|
+
const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
|
|
865
|
+
metadataMap.set(key, metadata);
|
|
866
|
+
setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
var makeFilter = (customOption) => (fieldOption) => {
|
|
870
|
+
return applyFilterKeyMeta({ ...customOption, ...fieldOption });
|
|
871
|
+
};
|
|
872
|
+
var getFilterArgMetasOnPrototype = (prototype, key) => {
|
|
873
|
+
const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
|
|
874
|
+
return filterArgMetas;
|
|
875
|
+
};
|
|
876
|
+
var setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
|
|
877
|
+
Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
|
|
878
|
+
};
|
|
879
|
+
var applyFilterArgMeta = (name, returns, argOption) => {
|
|
880
|
+
return (prototype, key, idx) => {
|
|
881
|
+
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
882
|
+
const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
|
|
883
|
+
const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
|
|
884
|
+
const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
|
|
885
|
+
filterArgMetas[idx] = filterArgMeta;
|
|
886
|
+
setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
|
|
887
|
+
};
|
|
888
|
+
};
|
|
889
|
+
var Filter = {
|
|
890
|
+
Mongo: makeFilter({ type: "mongo" }),
|
|
891
|
+
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
892
|
+
Arg: applyFilterArgMeta
|
|
893
|
+
};
|
|
821
894
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
895
|
+
// pkgs/@akanjs/constant/src/baseGql.ts
|
|
896
|
+
var import_reflect_metadata3 = require("reflect-metadata");
|
|
897
|
+
var defaultFieldMeta = {
|
|
898
|
+
fieldType: "property",
|
|
899
|
+
immutable: false,
|
|
900
|
+
select: true,
|
|
901
|
+
isClass: false,
|
|
902
|
+
isScalar: true,
|
|
903
|
+
nullable: false,
|
|
904
|
+
isArray: false,
|
|
905
|
+
arrDepth: 0,
|
|
906
|
+
optArrDepth: 0,
|
|
907
|
+
default: null,
|
|
908
|
+
isMap: false
|
|
909
|
+
};
|
|
910
|
+
var idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
|
|
911
|
+
var createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
|
|
912
|
+
var updatedAtFieldMeta = { ...defaultFieldMeta, key: "updatedAt", name: "Date", modelRef: Date };
|
|
913
|
+
var removedAtFieldMeta = {
|
|
914
|
+
...defaultFieldMeta,
|
|
915
|
+
key: "removedAt",
|
|
916
|
+
name: "Date",
|
|
917
|
+
modelRef: Date,
|
|
918
|
+
nullable: true,
|
|
919
|
+
default: null
|
|
920
|
+
};
|
|
848
921
|
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
};
|
|
922
|
+
// pkgs/@akanjs/constant/src/classMeta.ts
|
|
923
|
+
var import_reflect_metadata4 = require("reflect-metadata");
|
|
924
|
+
var InputModelStorage = class {
|
|
925
|
+
};
|
|
926
|
+
var LightModelStorage = class {
|
|
927
|
+
};
|
|
928
|
+
var FullModelStorage = class {
|
|
929
|
+
};
|
|
930
|
+
var ScalarModelStorage = class {
|
|
931
|
+
};
|
|
932
|
+
var FilterModelStorage = class {
|
|
933
|
+
};
|
|
934
|
+
var hasTextField = (modelRef) => {
|
|
935
|
+
const fieldMetas = getFieldMetas(modelRef);
|
|
936
|
+
return fieldMetas.some(
|
|
937
|
+
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
938
|
+
);
|
|
939
|
+
};
|
|
940
|
+
var applyClassMeta = (type, modelType, storage) => {
|
|
941
|
+
return function(refName) {
|
|
942
|
+
return function(target) {
|
|
943
|
+
const modelRef = target;
|
|
944
|
+
const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
|
|
945
|
+
Reflect.defineMetadata("class", classMeta, modelRef.prototype);
|
|
946
|
+
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
875
947
|
};
|
|
876
948
|
};
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
949
|
+
};
|
|
950
|
+
var applyFilterMeta = (storage) => {
|
|
951
|
+
return function(refName) {
|
|
952
|
+
return function(target) {
|
|
953
|
+
const modelRef = target;
|
|
954
|
+
setFilterMeta(modelRef, { refName, sort: {} });
|
|
955
|
+
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
884
956
|
};
|
|
885
957
|
};
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
958
|
+
};
|
|
959
|
+
var Model = {
|
|
960
|
+
Light: applyClassMeta("light", "data", LightModelStorage),
|
|
961
|
+
Object: applyClassMeta("full", "ephemeral", FullModelStorage),
|
|
962
|
+
Full: applyClassMeta("full", "data", FullModelStorage),
|
|
963
|
+
Input: applyClassMeta("input", "data", InputModelStorage),
|
|
964
|
+
Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
|
|
965
|
+
Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
|
|
966
|
+
Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
|
|
967
|
+
Filter: applyFilterMeta(FilterModelStorage)
|
|
968
|
+
};
|
|
969
|
+
var getLightModelRef = (modelRef) => {
|
|
970
|
+
const classMeta = getClassMeta(modelRef);
|
|
971
|
+
if (classMeta.type !== "full")
|
|
972
|
+
return modelRef;
|
|
973
|
+
const lightModelRef = Reflect.getMetadata(`Light${classMeta.refName}`, LightModelStorage.prototype);
|
|
974
|
+
if (!lightModelRef)
|
|
975
|
+
throw new Error(`LightModel not found - ${classMeta.refName}`);
|
|
976
|
+
return lightModelRef;
|
|
977
|
+
};
|
|
905
978
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
979
|
+
// pkgs/@akanjs/signal/src/immerify.ts
|
|
980
|
+
var import_immer = require("immer");
|
|
981
|
+
var immerify = (modelRef, objOrArr) => {
|
|
982
|
+
if (Array.isArray(objOrArr))
|
|
983
|
+
return objOrArr.map((val) => immerify(modelRef, val));
|
|
984
|
+
const fieldMetas = getFieldMetas(modelRef);
|
|
985
|
+
const immeredObj = Object.assign({}, objOrArr, { [import_immer.immerable]: true });
|
|
986
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
987
|
+
if (fieldMeta.isScalar && fieldMeta.isClass && !!objOrArr[fieldMeta.key])
|
|
988
|
+
immeredObj[fieldMeta.key] = immerify(fieldMeta.modelRef, objOrArr[fieldMeta.key]);
|
|
989
|
+
});
|
|
990
|
+
return immeredObj;
|
|
991
|
+
};
|
|
919
992
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
};
|
|
1011
|
-
}
|
|
1012
|
-
var createArgMetaDecorator = (type) => {
|
|
1013
|
-
return function(option = {}) {
|
|
1014
|
-
return function(prototype, key, idx) {
|
|
1015
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1016
|
-
argMetas[idx] = { key, idx, type, option };
|
|
1017
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1018
|
-
};
|
|
1019
|
-
};
|
|
1020
|
-
};
|
|
1021
|
-
var Account = createArgMetaDecorator("Account");
|
|
1022
|
-
var defaultAccount = {
|
|
1023
|
-
__InternalArg__: "Account",
|
|
1024
|
-
appName: baseEnv.appName,
|
|
1025
|
-
environment: baseEnv.environment
|
|
1026
|
-
};
|
|
1027
|
-
var Self = createArgMetaDecorator("Self");
|
|
1028
|
-
var Me = createArgMetaDecorator("Me");
|
|
1029
|
-
var UserIp = createArgMetaDecorator("UserIp");
|
|
1030
|
-
var Access = createArgMetaDecorator("Access");
|
|
1031
|
-
var Req = createArgMetaDecorator("Req");
|
|
1032
|
-
var Res = createArgMetaDecorator("Res");
|
|
1033
|
-
var Ws = createArgMetaDecorator("Ws");
|
|
1034
|
-
var Job = createArgMetaDecorator("Job");
|
|
1035
|
-
var getQuery = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1036
|
-
return (prototype, key, descriptor) => {
|
|
1037
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1038
|
-
metadataMap.set(key, {
|
|
1039
|
-
returns,
|
|
1040
|
-
signalOption,
|
|
1041
|
-
key,
|
|
1042
|
-
descriptor,
|
|
1043
|
-
guards: [allow, ...guards],
|
|
1044
|
-
type: "Query"
|
|
1045
|
-
});
|
|
1046
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1047
|
-
};
|
|
1048
|
-
};
|
|
1049
|
-
var getMutation = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1050
|
-
return (prototype, key, descriptor) => {
|
|
1051
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1052
|
-
metadataMap.set(key, {
|
|
1053
|
-
returns,
|
|
1054
|
-
signalOption,
|
|
1055
|
-
key,
|
|
1056
|
-
descriptor,
|
|
1057
|
-
guards: [allow, ...guards],
|
|
1058
|
-
type: "Mutation"
|
|
1059
|
-
});
|
|
1060
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1061
|
-
};
|
|
1062
|
-
};
|
|
1063
|
-
var getMessage = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1064
|
-
return (prototype, key, descriptor) => {
|
|
1065
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1066
|
-
metadataMap.set(key, {
|
|
1067
|
-
returns,
|
|
1068
|
-
signalOption,
|
|
1069
|
-
key,
|
|
1070
|
-
descriptor,
|
|
1071
|
-
guards: [allow, ...guards],
|
|
1072
|
-
type: "Message"
|
|
1073
|
-
});
|
|
1074
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1075
|
-
};
|
|
1076
|
-
};
|
|
1077
|
-
var getPubsub = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1078
|
-
return (prototype, key, descriptor) => {
|
|
1079
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1080
|
-
metadataMap.set(key, {
|
|
1081
|
-
returns,
|
|
1082
|
-
signalOption,
|
|
1083
|
-
key,
|
|
1084
|
-
descriptor,
|
|
1085
|
-
guards: [allow, ...guards],
|
|
1086
|
-
type: "Pubsub"
|
|
1087
|
-
});
|
|
1088
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1089
|
-
};
|
|
1090
|
-
};
|
|
1091
|
-
var getProcess = (serverType) => function(returns, signalOption = {}) {
|
|
1092
|
-
return (prototype, key, descriptor) => {
|
|
1093
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1094
|
-
metadataMap.set(key, {
|
|
1095
|
-
returns,
|
|
1096
|
-
signalOption: { ...signalOption, serverType: lowerlize(serverType) },
|
|
1097
|
-
key,
|
|
1098
|
-
descriptor,
|
|
1099
|
-
guards: ["None"],
|
|
1100
|
-
type: "Process"
|
|
1101
|
-
});
|
|
1102
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1103
|
-
};
|
|
1104
|
-
};
|
|
1105
|
-
var Query = {
|
|
1106
|
-
Public: getQuery("Public"),
|
|
1107
|
-
Every: getQuery("Every"),
|
|
1108
|
-
Admin: getQuery("Admin"),
|
|
1109
|
-
User: getQuery("User"),
|
|
1110
|
-
SuperAdmin: getQuery("SuperAdmin"),
|
|
1111
|
-
None: getQuery("None"),
|
|
1112
|
-
Owner: getQuery("Owner")
|
|
1113
|
-
};
|
|
1114
|
-
var Mutation = {
|
|
1115
|
-
Public: getMutation("Public"),
|
|
1116
|
-
Every: getMutation("Every"),
|
|
1117
|
-
Admin: getMutation("Admin"),
|
|
1118
|
-
User: getMutation("User"),
|
|
1119
|
-
SuperAdmin: getMutation("SuperAdmin"),
|
|
1120
|
-
None: getMutation("None"),
|
|
1121
|
-
Owner: getMutation("Owner")
|
|
1122
|
-
};
|
|
1123
|
-
var Message = {
|
|
1124
|
-
Public: getMessage("Public"),
|
|
1125
|
-
Every: getMessage("Every"),
|
|
1126
|
-
Admin: getMessage("Admin"),
|
|
1127
|
-
User: getMessage("User"),
|
|
1128
|
-
SuperAdmin: getMessage("SuperAdmin"),
|
|
1129
|
-
None: getMessage("None"),
|
|
1130
|
-
Owner: getMessage("Owner")
|
|
1131
|
-
};
|
|
1132
|
-
var Pubsub = {
|
|
1133
|
-
Public: getPubsub("Public"),
|
|
1134
|
-
Every: getPubsub("Every"),
|
|
1135
|
-
Admin: getPubsub("Admin"),
|
|
1136
|
-
User: getPubsub("User"),
|
|
1137
|
-
SuperAdmin: getPubsub("SuperAdmin"),
|
|
1138
|
-
None: getPubsub("None"),
|
|
1139
|
-
Owner: getPubsub("Owner")
|
|
1140
|
-
};
|
|
1141
|
-
var Process = {
|
|
1142
|
-
Federation: getProcess("Federation"),
|
|
1143
|
-
Batch: getProcess("Batch"),
|
|
1144
|
-
All: getProcess("All")
|
|
1145
|
-
};
|
|
1146
|
-
function ResolveField(returns, argsOption = {}) {
|
|
1147
|
-
return function(target, key, descriptor) {
|
|
1148
|
-
const metadataMap = getResolveFieldMetaMapOnPrototype(target);
|
|
1149
|
-
metadataMap.set(key, { returns, argsOption, key, descriptor });
|
|
1150
|
-
Reflect.defineMetadata("resolveField", metadataMap, target);
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
var getArg = (type) => function(name, returns, argsOption = {}) {
|
|
1154
|
-
return function(prototype, key, idx) {
|
|
1155
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1156
|
-
argMetas[idx] = { name, returns, argsOption, key, idx, type };
|
|
1157
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1158
|
-
};
|
|
1159
|
-
};
|
|
1160
|
-
var Arg = {
|
|
1161
|
-
Body: getArg("Body"),
|
|
1162
|
-
Param: getArg("Param"),
|
|
1163
|
-
Query: getArg("Query"),
|
|
1164
|
-
Upload: getArg("Upload"),
|
|
1165
|
-
Msg: getArg("Msg"),
|
|
1166
|
-
Room: getArg("Room")
|
|
993
|
+
// pkgs/@akanjs/signal/src/signalDecorators.ts
|
|
994
|
+
var import_reflect_metadata5 = require("reflect-metadata");
|
|
995
|
+
var ssoTypes = ["github", "google", "facebook", "apple", "naver", "kakao"];
|
|
996
|
+
var SignalStorage = class {
|
|
997
|
+
};
|
|
998
|
+
var getAllSignalRefs = () => {
|
|
999
|
+
const signalNames = Reflect.getOwnMetadataKeys(SignalStorage.prototype);
|
|
1000
|
+
const sigRefs = signalNames?.reduce((acc, signalName) => [...acc, ...getSignalRefsOnStorage(signalName)], []) ?? [];
|
|
1001
|
+
return sigRefs;
|
|
1002
|
+
};
|
|
1003
|
+
var getSignalRefsOnStorage = (refName) => {
|
|
1004
|
+
const sigRefs = Reflect.getMetadata(refName, SignalStorage.prototype);
|
|
1005
|
+
return sigRefs ?? [];
|
|
1006
|
+
};
|
|
1007
|
+
var setSignalRefOnStorage = (refName, signalRef) => {
|
|
1008
|
+
Reflect.defineMetadata(refName, [...getSignalRefsOnStorage(refName), signalRef], SignalStorage.prototype);
|
|
1009
|
+
};
|
|
1010
|
+
var resolve = (data) => data;
|
|
1011
|
+
var emit = (data) => data;
|
|
1012
|
+
var done = (data) => data;
|
|
1013
|
+
var subscribe = () => void 0;
|
|
1014
|
+
var signalTypes = ["graphql", "restapi"];
|
|
1015
|
+
var endpointTypes = ["Query", "Mutation", "Message", "Pubsub", "Process"];
|
|
1016
|
+
var guardTypes = ["Public", "None", "User", "Admin", "SuperAdmin", "Every", "Owner"];
|
|
1017
|
+
var roleTypes = ["Public", "User", "Admin", "SuperAdmin"];
|
|
1018
|
+
var argTypes = ["Body", "Param", "Query", "Upload", "Msg", "Room"];
|
|
1019
|
+
var internalArgTypes = [
|
|
1020
|
+
"Account",
|
|
1021
|
+
"Me",
|
|
1022
|
+
"Self",
|
|
1023
|
+
"UserIp",
|
|
1024
|
+
"Access",
|
|
1025
|
+
"Parent",
|
|
1026
|
+
"Req",
|
|
1027
|
+
"Res",
|
|
1028
|
+
"Ws",
|
|
1029
|
+
"Job"
|
|
1030
|
+
];
|
|
1031
|
+
var getDefaultArg = (argRef) => {
|
|
1032
|
+
const [modelRef, arrDepth] = getNonArrayModel(argRef);
|
|
1033
|
+
if (arrDepth)
|
|
1034
|
+
return [];
|
|
1035
|
+
const scalarArg = scalarArgMap.get(modelRef);
|
|
1036
|
+
if (scalarArg)
|
|
1037
|
+
return scalarArg;
|
|
1038
|
+
else
|
|
1039
|
+
return {};
|
|
1040
|
+
};
|
|
1041
|
+
function Signal(returnsOrObj) {
|
|
1042
|
+
const returns = typeof returnsOrObj === "function" ? returnsOrObj : void 0;
|
|
1043
|
+
const prefix = typeof returnsOrObj === "object" ? returnsOrObj.prefix : void 0;
|
|
1044
|
+
return function(target) {
|
|
1045
|
+
if (returns) {
|
|
1046
|
+
const modelRef = returns();
|
|
1047
|
+
const classMeta = getClassMeta(modelRef);
|
|
1048
|
+
const gqlMetas = getGqlMetas(target);
|
|
1049
|
+
const modelName = lowerlize(classMeta.refName);
|
|
1050
|
+
const listName = `${modelName}ListIn`;
|
|
1051
|
+
const slices = [
|
|
1052
|
+
{ refName: modelName, sliceName: modelName, argLength: 1, defaultArgs: [{}] },
|
|
1053
|
+
...gqlMetas.filter((gqlMeta) => {
|
|
1054
|
+
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
1055
|
+
if (!name.includes(listName))
|
|
1056
|
+
return false;
|
|
1057
|
+
const [retRef, arrDepth] = getNonArrayModel(gqlMeta.returns());
|
|
1058
|
+
return retRef.prototype === modelRef.prototype && arrDepth === 1;
|
|
1059
|
+
}).map((gqlMeta) => {
|
|
1060
|
+
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
1061
|
+
const sliceName = name.replace(listName, `${modelName}In`);
|
|
1062
|
+
const [argMetas] = getArgMetas(target, gqlMeta.key);
|
|
1063
|
+
const skipIdx = argMetas.findIndex((argMeta) => argMeta.name === "skip");
|
|
1064
|
+
if (skipIdx === -1)
|
|
1065
|
+
throw new Error(`Invalid Args for ${sliceName}`);
|
|
1066
|
+
const argLength = skipIdx;
|
|
1067
|
+
const queryArgRefs = argMetas.slice(0, skipIdx).map((argMeta) => argMeta.returns());
|
|
1068
|
+
const defaultArgs = queryArgRefs.map(
|
|
1069
|
+
(queryArgRef, idx) => argMetas[idx].argsOption.nullable ? null : getDefaultArg(queryArgRef)
|
|
1070
|
+
);
|
|
1071
|
+
return { refName: modelName, sliceName, argLength, defaultArgs };
|
|
1072
|
+
})
|
|
1073
|
+
];
|
|
1074
|
+
setSigMeta(target, { returns, prefix, slices, refName: modelName });
|
|
1075
|
+
setSignalRefOnStorage(modelName, target);
|
|
1076
|
+
} else {
|
|
1077
|
+
const refName = typeof returnsOrObj === "object" ? lowerlize(returnsOrObj.name) : void 0;
|
|
1078
|
+
if (!refName)
|
|
1079
|
+
throw new Error("Signal name is required");
|
|
1080
|
+
setSigMeta(target, { returns, prefix, slices: [], refName });
|
|
1081
|
+
setSignalRefOnStorage(refName, target);
|
|
1082
|
+
}
|
|
1167
1083
|
};
|
|
1168
|
-
|
|
1084
|
+
}
|
|
1085
|
+
var createArgMetaDecorator = (type) => {
|
|
1086
|
+
return function(option = {}) {
|
|
1169
1087
|
return function(prototype, key, idx) {
|
|
1170
1088
|
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1171
|
-
argMetas[idx] = { key, idx, type
|
|
1089
|
+
argMetas[idx] = { key, idx, type, option };
|
|
1172
1090
|
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1173
1091
|
};
|
|
1174
|
-
}
|
|
1175
|
-
function LogSignal(srv) {
|
|
1176
|
-
class BaseSignal {
|
|
1177
|
-
}
|
|
1178
|
-
return BaseSignal;
|
|
1179
|
-
}
|
|
1180
|
-
function DbSignal(constant, srv, option) {
|
|
1181
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1182
|
-
const meta = getClassMeta(constant.Full);
|
|
1183
|
-
const serviceName = `${lowerlize(meta.refName)}Service`;
|
|
1184
|
-
const [modelName, className] = [lowerlize(meta.refName), capitalize(meta.refName)];
|
|
1185
|
-
const names = {
|
|
1186
|
-
modelId: `${modelName}Id`,
|
|
1187
|
-
model: modelName,
|
|
1188
|
-
lightModel: `light${className}`,
|
|
1189
|
-
modelList: `${modelName}List`,
|
|
1190
|
-
modelInsight: `${modelName}Insight`,
|
|
1191
|
-
modelExists: `${modelName}Exists`,
|
|
1192
|
-
getModel: `get${className}`,
|
|
1193
|
-
createModel: `create${className}`,
|
|
1194
|
-
updateModel: `update${className}`,
|
|
1195
|
-
removeModel: `remove${className}`
|
|
1196
|
-
};
|
|
1197
|
-
class BaseSignal {
|
|
1198
|
-
async [_a = names.lightModel](id) {
|
|
1199
|
-
const service = this[serviceName];
|
|
1200
|
-
const model = await service[names.getModel](id);
|
|
1201
|
-
return resolve(model);
|
|
1202
|
-
}
|
|
1203
|
-
async [_b = names.model](id) {
|
|
1204
|
-
const service = this[serviceName];
|
|
1205
|
-
const model = await service[names.getModel](id);
|
|
1206
|
-
return resolve(model);
|
|
1207
|
-
}
|
|
1208
|
-
async [_c = names.modelList](query2, skip, limit, sort) {
|
|
1209
|
-
const service = this[serviceName];
|
|
1210
|
-
const models = query2?.$search ? await service.__searchDocs(query2.$search, { skip, limit, sort }) : await service.__list(query2, { skip, limit, sort });
|
|
1211
|
-
return resolve(models);
|
|
1212
|
-
}
|
|
1213
|
-
async [_d = names.modelInsight](query2) {
|
|
1214
|
-
const service = this[serviceName];
|
|
1215
|
-
const insight = query2.$search ? { ...makeDefault(constant.Insight), count: await service.__searchCount(query2.$search) } : await service.__insight(query2);
|
|
1216
|
-
return resolve(insight);
|
|
1217
|
-
}
|
|
1218
|
-
async [_e = names.modelExists](query2) {
|
|
1219
|
-
const service = this[serviceName];
|
|
1220
|
-
const exists = await service.__exists(query2);
|
|
1221
|
-
return resolve(exists);
|
|
1222
|
-
}
|
|
1223
|
-
async [_f = names.createModel](data) {
|
|
1224
|
-
const service = this[serviceName];
|
|
1225
|
-
const model = await service[names.createModel](data);
|
|
1226
|
-
return resolve(model);
|
|
1227
|
-
}
|
|
1228
|
-
async [_g = names.updateModel](id, data) {
|
|
1229
|
-
const service = this[serviceName];
|
|
1230
|
-
const model = await service[names.updateModel](id, data);
|
|
1231
|
-
return resolve(model);
|
|
1232
|
-
}
|
|
1233
|
-
async [_h = names.removeModel](id) {
|
|
1234
|
-
const service = this[serviceName];
|
|
1235
|
-
const model = await service[names.removeModel](id);
|
|
1236
|
-
return resolve(model);
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
__decorateClass([
|
|
1240
|
-
option.guards.get(() => constant.Light),
|
|
1241
|
-
__decorateParam(0, Arg.Param(names.modelId, () => ID))
|
|
1242
|
-
], BaseSignal.prototype, _a, 1);
|
|
1243
|
-
__decorateClass([
|
|
1244
|
-
option.guards.get(() => constant.Full),
|
|
1245
|
-
__decorateParam(0, Arg.Param(names.modelId, () => ID))
|
|
1246
|
-
], BaseSignal.prototype, _b, 1);
|
|
1247
|
-
__decorateClass([
|
|
1248
|
-
Query.Admin(() => [constant.Full]),
|
|
1249
|
-
__decorateParam(0, Arg.Query("query", () => JSON2)),
|
|
1250
|
-
__decorateParam(1, Arg.Query("skip", () => Int, { nullable: true, example: 0 })),
|
|
1251
|
-
__decorateParam(2, Arg.Query("limit", () => Int, { nullable: true, example: 20 })),
|
|
1252
|
-
__decorateParam(3, Arg.Query("sort", () => String, { nullable: true, example: "latest" }))
|
|
1253
|
-
], BaseSignal.prototype, _c, 1);
|
|
1254
|
-
__decorateClass([
|
|
1255
|
-
Query.Admin(() => constant.Insight),
|
|
1256
|
-
__decorateParam(0, Arg.Query("query", () => JSON2))
|
|
1257
|
-
], BaseSignal.prototype, _d, 1);
|
|
1258
|
-
__decorateClass([
|
|
1259
|
-
Query.Admin(() => Boolean),
|
|
1260
|
-
__decorateParam(0, Arg.Query("query", () => JSON2))
|
|
1261
|
-
], BaseSignal.prototype, _e, 1);
|
|
1262
|
-
__decorateClass([
|
|
1263
|
-
option.guards.cru(() => constant.Full),
|
|
1264
|
-
__decorateParam(0, Arg.Body(`data`, () => constant.Input))
|
|
1265
|
-
], BaseSignal.prototype, _f, 1);
|
|
1266
|
-
__decorateClass([
|
|
1267
|
-
option.guards.cru(() => constant.Full),
|
|
1268
|
-
__decorateParam(0, Arg.Param(names.modelId, () => ID)),
|
|
1269
|
-
__decorateParam(1, Arg.Body("data", () => constant.Input))
|
|
1270
|
-
], BaseSignal.prototype, _g, 1);
|
|
1271
|
-
__decorateClass([
|
|
1272
|
-
option.guards.cru(() => constant.Full, { partial: ["status", "removedAt"] }),
|
|
1273
|
-
__decorateParam(0, Arg.Param(names.modelId, () => ID))
|
|
1274
|
-
], BaseSignal.prototype, _h, 1);
|
|
1275
|
-
return BaseSignal;
|
|
1276
|
-
}
|
|
1277
|
-
var getSigMeta = (sigRef) => {
|
|
1278
|
-
const sigMeta = Reflect.getMetadata("signal", sigRef.prototype);
|
|
1279
|
-
if (!sigMeta)
|
|
1280
|
-
throw new Error(`No SignalMeta found for ${sigRef.name}`);
|
|
1281
|
-
return sigMeta;
|
|
1282
|
-
};
|
|
1283
|
-
var setSigMeta = (sigRef, sigMeta) => {
|
|
1284
|
-
Reflect.defineMetadata("signal", sigMeta, sigRef.prototype);
|
|
1285
|
-
};
|
|
1286
|
-
var getGqlMeta = (sigRef, key) => {
|
|
1287
|
-
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
1288
|
-
if (!gqlMetaMap)
|
|
1289
|
-
throw new Error(`No GqlMeta found for ${sigRef.name}`);
|
|
1290
|
-
const gqlMeta = gqlMetaMap.get(key);
|
|
1291
|
-
if (!gqlMeta)
|
|
1292
|
-
throw new Error(`No GqlMeta found for ${key}`);
|
|
1293
|
-
return gqlMeta;
|
|
1294
1092
|
};
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1093
|
+
};
|
|
1094
|
+
var Account = createArgMetaDecorator("Account");
|
|
1095
|
+
var defaultAccount = {
|
|
1096
|
+
__InternalArg__: "Account",
|
|
1097
|
+
appName: baseEnv.appName,
|
|
1098
|
+
environment: baseEnv.environment
|
|
1099
|
+
};
|
|
1100
|
+
var Self = createArgMetaDecorator("Self");
|
|
1101
|
+
var Me = createArgMetaDecorator("Me");
|
|
1102
|
+
var UserIp = createArgMetaDecorator("UserIp");
|
|
1103
|
+
var Access = createArgMetaDecorator("Access");
|
|
1104
|
+
var Req = createArgMetaDecorator("Req");
|
|
1105
|
+
var Res = createArgMetaDecorator("Res");
|
|
1106
|
+
var Ws = createArgMetaDecorator("Ws");
|
|
1107
|
+
var Job = createArgMetaDecorator("Job");
|
|
1108
|
+
var getQuery = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1109
|
+
return (prototype, key, descriptor) => {
|
|
1110
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1111
|
+
metadataMap.set(key, {
|
|
1112
|
+
returns,
|
|
1113
|
+
signalOption,
|
|
1114
|
+
key,
|
|
1115
|
+
descriptor,
|
|
1116
|
+
guards: [allow, ...guards],
|
|
1117
|
+
type: "Query"
|
|
1118
|
+
});
|
|
1119
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1120
|
+
};
|
|
1121
|
+
};
|
|
1122
|
+
var getMutation = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1123
|
+
return (prototype, key, descriptor) => {
|
|
1124
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1125
|
+
metadataMap.set(key, {
|
|
1126
|
+
returns,
|
|
1127
|
+
signalOption,
|
|
1128
|
+
key,
|
|
1129
|
+
descriptor,
|
|
1130
|
+
guards: [allow, ...guards],
|
|
1131
|
+
type: "Mutation"
|
|
1132
|
+
});
|
|
1133
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1134
|
+
};
|
|
1135
|
+
};
|
|
1136
|
+
var getMessage = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1137
|
+
return (prototype, key, descriptor) => {
|
|
1138
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1139
|
+
metadataMap.set(key, {
|
|
1140
|
+
returns,
|
|
1141
|
+
signalOption,
|
|
1142
|
+
key,
|
|
1143
|
+
descriptor,
|
|
1144
|
+
guards: [allow, ...guards],
|
|
1145
|
+
type: "Message"
|
|
1146
|
+
});
|
|
1147
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1148
|
+
};
|
|
1149
|
+
};
|
|
1150
|
+
var getPubsub = (allow) => function(returns, signalOption = {}, guards = []) {
|
|
1151
|
+
return (prototype, key, descriptor) => {
|
|
1152
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1153
|
+
metadataMap.set(key, {
|
|
1154
|
+
returns,
|
|
1155
|
+
signalOption,
|
|
1156
|
+
key,
|
|
1157
|
+
descriptor,
|
|
1158
|
+
guards: [allow, ...guards],
|
|
1159
|
+
type: "Pubsub"
|
|
1160
|
+
});
|
|
1161
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1162
|
+
};
|
|
1163
|
+
};
|
|
1164
|
+
var getProcess = (serverType) => function(returns, signalOption = {}) {
|
|
1165
|
+
return (prototype, key, descriptor) => {
|
|
1166
|
+
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
1167
|
+
metadataMap.set(key, {
|
|
1168
|
+
returns,
|
|
1169
|
+
signalOption: { ...signalOption, serverType: lowerlize(serverType) },
|
|
1170
|
+
key,
|
|
1171
|
+
descriptor,
|
|
1172
|
+
guards: ["None"],
|
|
1173
|
+
type: "Process"
|
|
1174
|
+
});
|
|
1175
|
+
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
1176
|
+
};
|
|
1177
|
+
};
|
|
1178
|
+
var Query = {
|
|
1179
|
+
Public: getQuery("Public"),
|
|
1180
|
+
Every: getQuery("Every"),
|
|
1181
|
+
Admin: getQuery("Admin"),
|
|
1182
|
+
User: getQuery("User"),
|
|
1183
|
+
SuperAdmin: getQuery("SuperAdmin"),
|
|
1184
|
+
None: getQuery("None"),
|
|
1185
|
+
Owner: getQuery("Owner")
|
|
1186
|
+
};
|
|
1187
|
+
var Mutation = {
|
|
1188
|
+
Public: getMutation("Public"),
|
|
1189
|
+
Every: getMutation("Every"),
|
|
1190
|
+
Admin: getMutation("Admin"),
|
|
1191
|
+
User: getMutation("User"),
|
|
1192
|
+
SuperAdmin: getMutation("SuperAdmin"),
|
|
1193
|
+
None: getMutation("None"),
|
|
1194
|
+
Owner: getMutation("Owner")
|
|
1195
|
+
};
|
|
1196
|
+
var Message = {
|
|
1197
|
+
Public: getMessage("Public"),
|
|
1198
|
+
Every: getMessage("Every"),
|
|
1199
|
+
Admin: getMessage("Admin"),
|
|
1200
|
+
User: getMessage("User"),
|
|
1201
|
+
SuperAdmin: getMessage("SuperAdmin"),
|
|
1202
|
+
None: getMessage("None"),
|
|
1203
|
+
Owner: getMessage("Owner")
|
|
1204
|
+
};
|
|
1205
|
+
var Pubsub = {
|
|
1206
|
+
Public: getPubsub("Public"),
|
|
1207
|
+
Every: getPubsub("Every"),
|
|
1208
|
+
Admin: getPubsub("Admin"),
|
|
1209
|
+
User: getPubsub("User"),
|
|
1210
|
+
SuperAdmin: getPubsub("SuperAdmin"),
|
|
1211
|
+
None: getPubsub("None"),
|
|
1212
|
+
Owner: getPubsub("Owner")
|
|
1213
|
+
};
|
|
1214
|
+
var Process = {
|
|
1215
|
+
Federation: getProcess("Federation"),
|
|
1216
|
+
Batch: getProcess("Batch"),
|
|
1217
|
+
All: getProcess("All")
|
|
1218
|
+
};
|
|
1219
|
+
function ResolveField(returns, argsOption = {}) {
|
|
1220
|
+
return function(target, key, descriptor) {
|
|
1221
|
+
const metadataMap = getResolveFieldMetaMapOnPrototype(target);
|
|
1222
|
+
metadataMap.set(key, { returns, argsOption, key, descriptor });
|
|
1223
|
+
Reflect.defineMetadata("resolveField", metadataMap, target);
|
|
1334
1224
|
};
|
|
1335
|
-
|
|
1336
|
-
|
|
1225
|
+
}
|
|
1226
|
+
var getArg = (type) => function(name, returns, argsOption = {}) {
|
|
1227
|
+
return function(prototype, key, idx) {
|
|
1228
|
+
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1229
|
+
argMetas[idx] = { name, returns, argsOption, key, idx, type };
|
|
1230
|
+
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1231
|
+
};
|
|
1232
|
+
};
|
|
1233
|
+
var Arg = {
|
|
1234
|
+
Body: getArg("Body"),
|
|
1235
|
+
Param: getArg("Param"),
|
|
1236
|
+
Query: getArg("Query"),
|
|
1237
|
+
Upload: getArg("Upload"),
|
|
1238
|
+
Msg: getArg("Msg"),
|
|
1239
|
+
Room: getArg("Room")
|
|
1240
|
+
};
|
|
1241
|
+
function Parent() {
|
|
1242
|
+
return function(prototype, key, idx) {
|
|
1243
|
+
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1244
|
+
argMetas[idx] = { key, idx, type: "Parent" };
|
|
1245
|
+
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1337
1246
|
};
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1247
|
+
}
|
|
1248
|
+
function LogSignal(srv) {
|
|
1249
|
+
class BaseSignal {
|
|
1250
|
+
}
|
|
1251
|
+
return BaseSignal;
|
|
1252
|
+
}
|
|
1253
|
+
function DbSignal(constant, srv, option) {
|
|
1254
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1255
|
+
const meta = getClassMeta(constant.Full);
|
|
1256
|
+
const serviceName = `${lowerlize(meta.refName)}Service`;
|
|
1257
|
+
const [modelName, className] = [lowerlize(meta.refName), capitalize(meta.refName)];
|
|
1258
|
+
const names = {
|
|
1259
|
+
modelId: `${modelName}Id`,
|
|
1260
|
+
model: modelName,
|
|
1261
|
+
lightModel: `light${className}`,
|
|
1262
|
+
modelList: `${modelName}List`,
|
|
1263
|
+
modelInsight: `${modelName}Insight`,
|
|
1264
|
+
modelExists: `${modelName}Exists`,
|
|
1265
|
+
getModel: `get${className}`,
|
|
1266
|
+
createModel: `create${className}`,
|
|
1267
|
+
updateModel: `update${className}`,
|
|
1268
|
+
removeModel: `remove${className}`
|
|
1269
|
+
};
|
|
1270
|
+
class BaseSignal {
|
|
1271
|
+
async [_a = names.lightModel](id) {
|
|
1272
|
+
const service = this[serviceName];
|
|
1273
|
+
const model = await service[names.getModel](id);
|
|
1274
|
+
return resolve(model);
|
|
1275
|
+
}
|
|
1276
|
+
async [_b = names.model](id) {
|
|
1277
|
+
const service = this[serviceName];
|
|
1278
|
+
const model = await service[names.getModel](id);
|
|
1279
|
+
return resolve(model);
|
|
1280
|
+
}
|
|
1281
|
+
async [_c = names.modelList](query2, skip, limit, sort) {
|
|
1282
|
+
const service = this[serviceName];
|
|
1283
|
+
const models = query2?.$search ? await service.__searchDocs(query2.$search, { skip, limit, sort }) : await service.__list(query2, { skip, limit, sort });
|
|
1284
|
+
return resolve(models);
|
|
1285
|
+
}
|
|
1286
|
+
async [_d = names.modelInsight](query2) {
|
|
1287
|
+
const service = this[serviceName];
|
|
1288
|
+
const insight = query2.$search ? { ...makeDefault(constant.Insight), count: await service.__searchCount(query2.$search) } : await service.__insight(query2);
|
|
1289
|
+
return resolve(insight);
|
|
1290
|
+
}
|
|
1291
|
+
async [_e = names.modelExists](query2) {
|
|
1292
|
+
const service = this[serviceName];
|
|
1293
|
+
const exists = await service.__exists(query2);
|
|
1294
|
+
return resolve(exists);
|
|
1295
|
+
}
|
|
1296
|
+
async [_f = names.createModel](data) {
|
|
1297
|
+
const service = this[serviceName];
|
|
1298
|
+
const model = await service[names.createModel](data);
|
|
1299
|
+
return resolve(model);
|
|
1300
|
+
}
|
|
1301
|
+
async [_g = names.updateModel](id, data) {
|
|
1302
|
+
const service = this[serviceName];
|
|
1303
|
+
const model = await service[names.updateModel](id, data);
|
|
1304
|
+
return resolve(model);
|
|
1305
|
+
}
|
|
1306
|
+
async [_h = names.removeModel](id) {
|
|
1307
|
+
const service = this[serviceName];
|
|
1308
|
+
const model = await service[names.removeModel](id);
|
|
1309
|
+
return resolve(model);
|
|
1355
1310
|
}
|
|
1356
|
-
return CopiedSignal;
|
|
1357
|
-
};
|
|
1358
|
-
|
|
1359
|
-
// pkgs/@akanjs/signal/src/gql.ts
|
|
1360
|
-
function graphql(literals, ...args) {
|
|
1361
|
-
if (typeof literals === "string")
|
|
1362
|
-
literals = [literals];
|
|
1363
|
-
let result = literals[0];
|
|
1364
|
-
args.forEach((arg, i) => {
|
|
1365
|
-
if (arg && arg.kind === "Document")
|
|
1366
|
-
result += arg.loc.source.body;
|
|
1367
|
-
else
|
|
1368
|
-
result += arg;
|
|
1369
|
-
result += literals[i + 1];
|
|
1370
|
-
});
|
|
1371
|
-
return result;
|
|
1372
1311
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1312
|
+
__decorateClass([
|
|
1313
|
+
option.guards.get(() => constant.Light),
|
|
1314
|
+
__decorateParam(0, Arg.Param(names.modelId, () => ID))
|
|
1315
|
+
], BaseSignal.prototype, _a, 1);
|
|
1316
|
+
__decorateClass([
|
|
1317
|
+
option.guards.get(() => constant.Full),
|
|
1318
|
+
__decorateParam(0, Arg.Param(names.modelId, () => ID))
|
|
1319
|
+
], BaseSignal.prototype, _b, 1);
|
|
1320
|
+
__decorateClass([
|
|
1321
|
+
Query.Admin(() => [constant.Full]),
|
|
1322
|
+
__decorateParam(0, Arg.Query("query", () => JSON2)),
|
|
1323
|
+
__decorateParam(1, Arg.Query("skip", () => Int, { nullable: true, example: 0 })),
|
|
1324
|
+
__decorateParam(2, Arg.Query("limit", () => Int, { nullable: true, example: 20 })),
|
|
1325
|
+
__decorateParam(3, Arg.Query("sort", () => String, { nullable: true, example: "latest" }))
|
|
1326
|
+
], BaseSignal.prototype, _c, 1);
|
|
1327
|
+
__decorateClass([
|
|
1328
|
+
Query.Admin(() => constant.Insight),
|
|
1329
|
+
__decorateParam(0, Arg.Query("query", () => JSON2))
|
|
1330
|
+
], BaseSignal.prototype, _d, 1);
|
|
1331
|
+
__decorateClass([
|
|
1332
|
+
Query.Admin(() => Boolean),
|
|
1333
|
+
__decorateParam(0, Arg.Query("query", () => JSON2))
|
|
1334
|
+
], BaseSignal.prototype, _e, 1);
|
|
1335
|
+
__decorateClass([
|
|
1336
|
+
option.guards.cru(() => constant.Full),
|
|
1337
|
+
__decorateParam(0, Arg.Body(`data`, () => constant.Input))
|
|
1338
|
+
], BaseSignal.prototype, _f, 1);
|
|
1339
|
+
__decorateClass([
|
|
1340
|
+
option.guards.cru(() => constant.Full),
|
|
1341
|
+
__decorateParam(0, Arg.Param(names.modelId, () => ID)),
|
|
1342
|
+
__decorateParam(1, Arg.Body("data", () => constant.Input))
|
|
1343
|
+
], BaseSignal.prototype, _g, 1);
|
|
1344
|
+
__decorateClass([
|
|
1345
|
+
option.guards.cru(() => constant.Full, { partial: ["status", "removedAt"] }),
|
|
1346
|
+
__decorateParam(0, Arg.Param(names.modelId, () => ID))
|
|
1347
|
+
], BaseSignal.prototype, _h, 1);
|
|
1348
|
+
return BaseSignal;
|
|
1349
|
+
}
|
|
1350
|
+
var getSigMeta = (sigRef) => {
|
|
1351
|
+
const sigMeta = Reflect.getMetadata("signal", sigRef.prototype);
|
|
1352
|
+
if (!sigMeta)
|
|
1353
|
+
throw new Error(`No SignalMeta found for ${sigRef.name}`);
|
|
1354
|
+
return sigMeta;
|
|
1355
|
+
};
|
|
1356
|
+
var setSigMeta = (sigRef, sigMeta) => {
|
|
1357
|
+
Reflect.defineMetadata("signal", sigMeta, sigRef.prototype);
|
|
1358
|
+
};
|
|
1359
|
+
var getGqlMeta = (sigRef, key) => {
|
|
1360
|
+
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
1361
|
+
if (!gqlMetaMap)
|
|
1362
|
+
throw new Error(`No GqlMeta found for ${sigRef.name}`);
|
|
1363
|
+
const gqlMeta = gqlMetaMap.get(key);
|
|
1364
|
+
if (!gqlMeta)
|
|
1365
|
+
throw new Error(`No GqlMeta found for ${key}`);
|
|
1366
|
+
return gqlMeta;
|
|
1367
|
+
};
|
|
1368
|
+
var getGqlMetaMapOnPrototype = (prototype) => {
|
|
1369
|
+
const gqlMetaMap = Reflect.getMetadata("gql", prototype);
|
|
1370
|
+
return gqlMetaMap ?? /* @__PURE__ */ new Map();
|
|
1371
|
+
};
|
|
1372
|
+
var getGqlMetas = (sigRef) => {
|
|
1373
|
+
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
1374
|
+
return gqlMetaMap ? [...gqlMetaMap.values()] : [];
|
|
1375
|
+
};
|
|
1376
|
+
var setGqlMetaMapOnPrototype = (prototype, gqlMetaMap) => {
|
|
1377
|
+
Reflect.defineMetadata("gql", gqlMetaMap, prototype);
|
|
1378
|
+
};
|
|
1379
|
+
var getArgMetas = (sigRef, key) => {
|
|
1380
|
+
const metas = Reflect.getMetadata("args", sigRef.prototype, key) ?? [];
|
|
1381
|
+
const argMetas = metas.filter((meta) => !!meta.returns);
|
|
1382
|
+
const internalArgMetas = metas.filter((meta) => !meta.returns);
|
|
1383
|
+
return [argMetas, internalArgMetas];
|
|
1384
|
+
};
|
|
1385
|
+
var getArgMetasOnPrototype = (prototype, key) => {
|
|
1386
|
+
return Reflect.getMetadata("args", prototype, key) ?? [];
|
|
1387
|
+
};
|
|
1388
|
+
var setArgMetas = (sigRef, key, argMetas, internalArgMetas) => {
|
|
1389
|
+
Reflect.defineMetadata("args", [...argMetas, ...internalArgMetas], sigRef.prototype, key);
|
|
1390
|
+
};
|
|
1391
|
+
var setArgMetasOnPrototype = (prototype, key, argMetas) => {
|
|
1392
|
+
Reflect.defineMetadata("args", argMetas, prototype, key);
|
|
1393
|
+
};
|
|
1394
|
+
var getResolveFieldMetaMapOnPrototype = (prototype) => {
|
|
1395
|
+
const resolveFieldMetaMap = Reflect.getMetadata("resolveField", prototype);
|
|
1396
|
+
return resolveFieldMetaMap ?? /* @__PURE__ */ new Map();
|
|
1397
|
+
};
|
|
1398
|
+
var getResolveFieldMetas = (sigRef) => {
|
|
1399
|
+
const resolveFieldMetaMap = Reflect.getMetadata("resolveField", sigRef.prototype);
|
|
1400
|
+
return resolveFieldMetaMap ? [...resolveFieldMetaMap.values()] : [];
|
|
1401
|
+
};
|
|
1402
|
+
var setResolveFieldMetaMapOnPrototype = (prototype, resolveFieldMetaMap) => {
|
|
1403
|
+
Reflect.defineMetadata("resolveField", resolveFieldMetaMap, prototype);
|
|
1404
|
+
};
|
|
1405
|
+
var getControllerPrefix = (sigMeta) => {
|
|
1406
|
+
return sigMeta.returns ? lowerlize(getClassMeta(sigMeta.returns()).refName) : sigMeta.prefix;
|
|
1407
|
+
};
|
|
1408
|
+
var getControllerPath = (gqlMeta, paramArgMetas) => {
|
|
1409
|
+
return gqlMeta.signalOption.path ?? [gqlMeta.signalOption.name ?? gqlMeta.key, ...paramArgMetas.map((argMeta) => `:${argMeta.name}`)].join("/");
|
|
1410
|
+
};
|
|
1411
|
+
var copySignal = (sigRef) => {
|
|
1412
|
+
class CopiedSignal {
|
|
1413
|
+
}
|
|
1414
|
+
applyMixins(CopiedSignal, [sigRef]);
|
|
1415
|
+
const sigMeta = getSigMeta(sigRef);
|
|
1416
|
+
setSigMeta(CopiedSignal, sigMeta);
|
|
1417
|
+
const gqlMetaMap = getGqlMetaMapOnPrototype(sigRef.prototype);
|
|
1418
|
+
setGqlMetaMapOnPrototype(CopiedSignal.prototype, new Map(gqlMetaMap));
|
|
1419
|
+
const resolveFieldMetaMap = getResolveFieldMetaMapOnPrototype(sigRef.prototype);
|
|
1420
|
+
setResolveFieldMetaMapOnPrototype(CopiedSignal.prototype, new Map(resolveFieldMetaMap));
|
|
1421
|
+
for (const endpointMeta of [...gqlMetaMap.values(), ...resolveFieldMetaMap.values()]) {
|
|
1422
|
+
const argMetas = getArgMetasOnPrototype(sigRef.prototype, endpointMeta.key);
|
|
1423
|
+
setArgMetasOnPrototype(CopiedSignal.prototype, endpointMeta.key, [...argMetas]);
|
|
1424
|
+
const paramtypes = Reflect.getMetadata("design:paramtypes", sigRef.prototype, endpointMeta.key);
|
|
1425
|
+
const argParamtypes = argMetas.filter((argMeta) => !!argMeta.returns).map((argMeta) => Object);
|
|
1426
|
+
Reflect.defineMetadata("design:paramtypes", paramtypes ?? argParamtypes, CopiedSignal.prototype, endpointMeta.key);
|
|
1427
|
+
Reflect.defineMetadata("design:paramtypes", paramtypes ?? argParamtypes, CopiedSignal.prototype, endpointMeta.key);
|
|
1428
|
+
}
|
|
1429
|
+
return CopiedSignal;
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
// pkgs/@akanjs/signal/src/gql.ts
|
|
1433
|
+
function graphql(literals, ...args) {
|
|
1434
|
+
if (typeof literals === "string")
|
|
1435
|
+
literals = [literals];
|
|
1436
|
+
let result = literals[0];
|
|
1437
|
+
args.forEach((arg, i) => {
|
|
1438
|
+
if (arg && arg.kind === "Document")
|
|
1439
|
+
result += arg.loc.source.body;
|
|
1440
|
+
else
|
|
1441
|
+
result += arg;
|
|
1442
|
+
result += literals[i + 1];
|
|
1443
|
+
});
|
|
1444
|
+
return result;
|
|
1445
|
+
}
|
|
1446
|
+
var GqlStorage = class {
|
|
1447
|
+
};
|
|
1448
|
+
var FragmentStorage = class {
|
|
1449
|
+
};
|
|
1450
|
+
var PurifyStorage = class {
|
|
1451
|
+
};
|
|
1452
|
+
var DefaultStorage = class {
|
|
1453
|
+
};
|
|
1454
|
+
var CrystalizeStorage = class {
|
|
1455
|
+
};
|
|
1456
|
+
var scalarUtilOf = (name, target) => {
|
|
1457
|
+
const refName = getClassMeta(target).refName;
|
|
1458
|
+
const [fieldName, className] = [lowerlize(refName), capitalize(refName)];
|
|
1459
|
+
const graphQL = {
|
|
1460
|
+
refName,
|
|
1461
|
+
[className]: target,
|
|
1462
|
+
[`default${className}`]: immerify(target, Object.assign(new target(), makeDefault(target))),
|
|
1463
|
+
[`purify${className}`]: makePurify(target),
|
|
1464
|
+
[`crystalize${className}`]: makeCrystalize(target),
|
|
1465
|
+
[`${fieldName}Fragment`]: makeFragment(target)
|
|
1466
|
+
};
|
|
1467
|
+
return graphQL;
|
|
1468
|
+
};
|
|
1469
|
+
var getGqlOnStorage = (refName) => {
|
|
1470
|
+
const modelGql = Reflect.getMetadata(refName, GqlStorage.prototype);
|
|
1471
|
+
if (!modelGql)
|
|
1472
|
+
throw new Error("Gql is not defined");
|
|
1473
|
+
return modelGql;
|
|
1474
|
+
};
|
|
1475
|
+
var setGqlOnStorage = (refName, modelGql) => {
|
|
1476
|
+
Reflect.defineMetadata(refName, modelGql, GqlStorage.prototype);
|
|
1477
|
+
};
|
|
1478
|
+
var gqlOf = (constant, sigRef, option = {}) => {
|
|
1479
|
+
const refName = constant.refName;
|
|
1480
|
+
const [fieldName, className] = [lowerlize(refName), capitalize(refName)];
|
|
1481
|
+
const sigMeta = getSigMeta(sigRef);
|
|
1482
|
+
const names = {
|
|
1483
|
+
refName,
|
|
1484
|
+
model: fieldName,
|
|
1485
|
+
Model: className,
|
|
1486
|
+
_model: `_${fieldName}`,
|
|
1487
|
+
lightModel: `light${className}`,
|
|
1488
|
+
_lightModel: `_light${className}`,
|
|
1489
|
+
purifyModel: `purify${className}`,
|
|
1490
|
+
crystalizeModel: `crystalize${className}`,
|
|
1491
|
+
lightCrystalizeModel: `lightCrystalize${className}`,
|
|
1492
|
+
crystalizeModelInsight: `crystalize${className}Insight`,
|
|
1493
|
+
defaultModel: `default${className}`,
|
|
1494
|
+
defaultModelInsight: `default${className}Insight`,
|
|
1495
|
+
mergeModel: `merge${className}`,
|
|
1496
|
+
viewModel: `view${className}`,
|
|
1497
|
+
getModelView: `get${className}View`,
|
|
1498
|
+
modelView: `${fieldName}View`,
|
|
1499
|
+
modelViewAt: `${fieldName}ViewAt`,
|
|
1500
|
+
editModel: `edit${className}`,
|
|
1501
|
+
getModelEdit: `get${className}Edit`,
|
|
1502
|
+
modelEdit: `${fieldName}Edit`,
|
|
1503
|
+
listModel: `list${className}`,
|
|
1504
|
+
modelList: `${fieldName}List`,
|
|
1505
|
+
modelObjList: `${fieldName}ObjList`,
|
|
1506
|
+
modelInsight: `${fieldName}Insight`,
|
|
1507
|
+
modelObjInsight: `${fieldName}ObjInsight`,
|
|
1508
|
+
updateModel: `update${className}`,
|
|
1509
|
+
modelObj: `${fieldName}Obj`,
|
|
1510
|
+
_modelList: `_${fieldName}List`,
|
|
1511
|
+
modelInit: `${fieldName}Init`,
|
|
1512
|
+
pageOfModel: `pageOf${className}`,
|
|
1513
|
+
lastPageOfModel: `lastPageOf${className}`,
|
|
1514
|
+
limitOfModel: `limitOf${className}`,
|
|
1515
|
+
queryArgsOfModel: `queryArgsOf${className}`,
|
|
1516
|
+
sortOfModel: `sortOf${className}`,
|
|
1517
|
+
modelInitAt: `${fieldName}InitAt`,
|
|
1518
|
+
initModel: `init${className}`,
|
|
1519
|
+
getModelInit: `get${className}Init`,
|
|
1520
|
+
addModelFiles: `add${className}Files`
|
|
1521
|
+
};
|
|
1522
|
+
const base = {
|
|
1523
|
+
refName,
|
|
1524
|
+
[names.purifyModel]: makePurify(constant.Input, option),
|
|
1525
|
+
[names.crystalizeModel]: makeCrystalize(constant.Full, option),
|
|
1526
|
+
[names.lightCrystalizeModel]: makeCrystalize(constant.Light, option),
|
|
1527
|
+
[names.crystalizeModelInsight]: makeCrystalize(constant.Insight, option),
|
|
1528
|
+
[names.defaultModel]: immerify(
|
|
1529
|
+
constant.Full,
|
|
1530
|
+
Object.assign(new constant.Full(), makeDefault(constant.Full, option))
|
|
1531
|
+
),
|
|
1532
|
+
[names.defaultModelInsight]: Object.assign(
|
|
1533
|
+
new constant.Insight(),
|
|
1534
|
+
makeDefault(constant.Insight, option)
|
|
1535
|
+
)
|
|
1536
|
+
};
|
|
1537
|
+
const gql = Object.assign(option.overwrite ?? { client }, fetchOf(sigRef));
|
|
1538
|
+
const util = {
|
|
1539
|
+
[names.addModelFiles]: async (files, id, option2) => {
|
|
1540
|
+
const fileGql = getGqlOnStorage("file");
|
|
1541
|
+
const metas = Array.from(files).map((file) => ({ lastModifiedAt: new Date(file.lastModified), size: file.size }));
|
|
1542
|
+
return await fileGql.addFiles(
|
|
1543
|
+
files,
|
|
1544
|
+
metas,
|
|
1545
|
+
names.model,
|
|
1546
|
+
id,
|
|
1547
|
+
option2
|
|
1548
|
+
);
|
|
1549
|
+
},
|
|
1550
|
+
[names.mergeModel]: async (modelOrId, data, option2) => {
|
|
1551
|
+
const model = typeof modelOrId === "string" ? await gql[names._model](modelOrId) : modelOrId;
|
|
1552
|
+
const input = base[names.purifyModel]({ ...model, ...data });
|
|
1553
|
+
if (!input)
|
|
1554
|
+
throw new Error("Error");
|
|
1555
|
+
return await gql[names.updateModel](model.id, input, option2);
|
|
1556
|
+
},
|
|
1557
|
+
[names.viewModel]: async (id, option2) => {
|
|
1558
|
+
const modelObj = await gql[names._model](id, option2);
|
|
1559
|
+
return {
|
|
1560
|
+
[names.model]: base[names.crystalizeModel](modelObj),
|
|
1561
|
+
[names.modelView]: {
|
|
1498
1562
|
refName: names.model,
|
|
1499
|
-
[names.modelObj]:
|
|
1563
|
+
[names.modelObj]: modelObj,
|
|
1500
1564
|
[names.modelViewAt]: /* @__PURE__ */ new Date()
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
},
|
|
1568
|
+
[names.getModelView]: async (id, option2) => {
|
|
1569
|
+
const modelView = await gql[names._model](id, option2);
|
|
1570
|
+
return {
|
|
1571
|
+
refName: names.model,
|
|
1572
|
+
[names.modelObj]: modelView,
|
|
1573
|
+
[names.modelViewAt]: /* @__PURE__ */ new Date()
|
|
1574
|
+
};
|
|
1575
|
+
},
|
|
1576
|
+
[names.editModel]: async (id, option2) => {
|
|
1577
|
+
const modelObj = await gql[names._model](id, option2);
|
|
1578
|
+
return {
|
|
1579
|
+
[names.model]: base[names.crystalizeModel](modelObj),
|
|
1580
|
+
[names.modelEdit]: {
|
|
1581
|
+
refName: names.model,
|
|
1582
|
+
[names.modelObj]: modelObj,
|
|
1583
|
+
[names.modelViewAt]: /* @__PURE__ */ new Date()
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1586
|
+
},
|
|
1587
|
+
[names.getModelEdit]: async (id, option2) => {
|
|
1588
|
+
const modelEdit = await gql[names.editModel](id, option2);
|
|
1589
|
+
return modelEdit[names.modelEdit];
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
const sliceUtil = Object.fromEntries(
|
|
1593
|
+
sigMeta.slices.reduce((acc, { sliceName, argLength, defaultArgs }) => {
|
|
1594
|
+
const namesOfSlice = {
|
|
1595
|
+
modelList: sliceName.replace(names.model, names.modelList),
|
|
1596
|
+
// modelListInSelf
|
|
1597
|
+
modelInsight: sliceName.replace(names.model, names.modelInsight),
|
|
1598
|
+
// modelInsightInSelf
|
|
1599
|
+
modelInit: sliceName.replace(names.model, names.modelInit),
|
|
1600
|
+
// modelInitInSelf
|
|
1601
|
+
initModel: sliceName.replace(names.model, names.initModel),
|
|
1602
|
+
// initModelInSelf
|
|
1603
|
+
getModelInit: sliceName.replace(names.model, names.getModelInit)
|
|
1604
|
+
// getModelInitInSelf
|
|
1605
|
+
};
|
|
1606
|
+
const getInitFn = async (...args) => {
|
|
1607
|
+
const queryArgLength = Math.min(args.length, argLength);
|
|
1608
|
+
const queryArgs = [
|
|
1609
|
+
...new Array(queryArgLength).fill(null).map((_, i) => args[i]),
|
|
1610
|
+
...queryArgLength < argLength ? new Array(argLength - queryArgLength).fill(null).map((_, i) => defaultArgs[i + queryArgLength] ?? null) : []
|
|
1611
|
+
];
|
|
1612
|
+
const fetchInitOption = args[argLength] ?? {};
|
|
1613
|
+
const { page = 1, limit = 20, sort = "latest", insight } = fetchInitOption;
|
|
1614
|
+
const skip = (page - 1) * limit;
|
|
1615
|
+
const [modelObjList, modelObjInsight] = await Promise.all([
|
|
1616
|
+
gql[`_${namesOfSlice.modelList}`](
|
|
1617
|
+
...queryArgs,
|
|
1618
|
+
skip,
|
|
1619
|
+
limit,
|
|
1620
|
+
sort,
|
|
1621
|
+
fetchInitOption
|
|
1622
|
+
),
|
|
1623
|
+
gql[`_${namesOfSlice.modelInsight}`](...queryArgs, fetchInitOption)
|
|
1624
|
+
]);
|
|
1625
|
+
const count = modelObjInsight.count;
|
|
1505
1626
|
return {
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
};
|
|
1519
|
-
const sliceUtil = Object.fromEntries(
|
|
1520
|
-
sigMeta.slices.reduce((acc, { sliceName, argLength, defaultArgs }) => {
|
|
1521
|
-
const namesOfSlice = {
|
|
1522
|
-
modelList: sliceName.replace(names.model, names.modelList),
|
|
1523
|
-
// modelListInSelf
|
|
1524
|
-
modelInsight: sliceName.replace(names.model, names.modelInsight),
|
|
1525
|
-
// modelInsightInSelf
|
|
1526
|
-
modelInit: sliceName.replace(names.model, names.modelInit),
|
|
1527
|
-
// modelInitInSelf
|
|
1528
|
-
initModel: sliceName.replace(names.model, names.initModel),
|
|
1529
|
-
// initModelInSelf
|
|
1530
|
-
getModelInit: sliceName.replace(names.model, names.getModelInit)
|
|
1531
|
-
// getModelInitInSelf
|
|
1532
|
-
};
|
|
1533
|
-
const getInitFn = async (...args) => {
|
|
1534
|
-
const queryArgLength = Math.min(args.length, argLength);
|
|
1535
|
-
const queryArgs = [
|
|
1536
|
-
...new Array(queryArgLength).fill(null).map((_, i) => args[i]),
|
|
1537
|
-
...queryArgLength < argLength ? new Array(argLength - queryArgLength).fill(null).map((_, i) => defaultArgs[i + queryArgLength] ?? null) : []
|
|
1538
|
-
];
|
|
1539
|
-
const fetchInitOption = args[argLength] ?? {};
|
|
1540
|
-
const { page = 1, limit = 20, sort = "latest", insight } = fetchInitOption;
|
|
1541
|
-
const skip = (page - 1) * limit;
|
|
1542
|
-
const [modelObjList, modelObjInsight] = await Promise.all([
|
|
1543
|
-
gql[`_${namesOfSlice.modelList}`](
|
|
1544
|
-
...queryArgs,
|
|
1545
|
-
skip,
|
|
1546
|
-
limit,
|
|
1547
|
-
sort,
|
|
1548
|
-
fetchInitOption
|
|
1549
|
-
),
|
|
1550
|
-
gql[`_${namesOfSlice.modelInsight}`](...queryArgs, fetchInitOption)
|
|
1551
|
-
]);
|
|
1552
|
-
const count = modelObjInsight.count;
|
|
1553
|
-
return {
|
|
1554
|
-
// Client Component용
|
|
1555
|
-
refName: names.model,
|
|
1556
|
-
sliceName,
|
|
1557
|
-
argLength,
|
|
1558
|
-
[names.modelObjList]: modelObjList,
|
|
1559
|
-
[names.modelObjInsight]: modelObjInsight,
|
|
1560
|
-
[names.pageOfModel]: page,
|
|
1561
|
-
[names.lastPageOfModel]: Math.max(Math.floor((count - 1) / limit) + 1, 1),
|
|
1562
|
-
[names.limitOfModel]: limit,
|
|
1563
|
-
[names.queryArgsOfModel]: JSON.parse(JSON.stringify(queryArgs)),
|
|
1564
|
-
[names.sortOfModel]: sort,
|
|
1565
|
-
[names.modelInitAt]: /* @__PURE__ */ new Date()
|
|
1566
|
-
};
|
|
1627
|
+
// Client Component용
|
|
1628
|
+
refName: names.model,
|
|
1629
|
+
sliceName,
|
|
1630
|
+
argLength,
|
|
1631
|
+
[names.modelObjList]: modelObjList,
|
|
1632
|
+
[names.modelObjInsight]: modelObjInsight,
|
|
1633
|
+
[names.pageOfModel]: page,
|
|
1634
|
+
[names.lastPageOfModel]: Math.max(Math.floor((count - 1) / limit) + 1, 1),
|
|
1635
|
+
[names.limitOfModel]: limit,
|
|
1636
|
+
[names.queryArgsOfModel]: JSON.parse(JSON.stringify(queryArgs)),
|
|
1637
|
+
[names.sortOfModel]: sort,
|
|
1638
|
+
[names.modelInitAt]: /* @__PURE__ */ new Date()
|
|
1567
1639
|
};
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
)
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1640
|
+
};
|
|
1641
|
+
const initFn = async (...args) => {
|
|
1642
|
+
const modelInit = await getInitFn(...args);
|
|
1643
|
+
const modelObjList = modelInit[names.modelObjList];
|
|
1644
|
+
const modelObjInsight = modelInit[names.modelObjInsight];
|
|
1645
|
+
const modelList = new DataList(
|
|
1646
|
+
modelObjList.map((modelObj) => base[names.lightCrystalizeModel](modelObj))
|
|
1647
|
+
);
|
|
1648
|
+
const modelInsight = base[names.crystalizeModelInsight](modelObjInsight);
|
|
1649
|
+
return {
|
|
1650
|
+
[namesOfSlice.modelList]: modelList,
|
|
1651
|
+
// Server Component용
|
|
1652
|
+
[namesOfSlice.modelInsight]: modelInsight,
|
|
1653
|
+
// Server Component용
|
|
1654
|
+
[namesOfSlice.modelInit]: modelInit
|
|
1583
1655
|
};
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
)
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
)
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
result[metadata.key] = metadata.default;
|
|
1626
|
-
} else if (metadata.isArray)
|
|
1627
|
-
result[metadata.key] = [];
|
|
1628
|
-
else if (metadata.nullable)
|
|
1629
|
-
result[metadata.key] = null;
|
|
1630
|
-
else if (metadata.isClass)
|
|
1631
|
-
result[metadata.key] = metadata.isScalar ? makeDefault(metadata.modelRef) : null;
|
|
1656
|
+
};
|
|
1657
|
+
return [...acc, [namesOfSlice.getModelInit, getInitFn], [namesOfSlice.initModel, initFn]];
|
|
1658
|
+
}, [])
|
|
1659
|
+
);
|
|
1660
|
+
const overwriteSlices = option.overwrite ? option.overwrite.slices.filter(
|
|
1661
|
+
(slice) => !sigMeta.slices.some((s) => s.sliceName === slice.sliceName)
|
|
1662
|
+
) : [];
|
|
1663
|
+
const modelGql = Object.assign(option.overwrite ?? {}, {
|
|
1664
|
+
...gql,
|
|
1665
|
+
...base,
|
|
1666
|
+
...util,
|
|
1667
|
+
...sliceUtil,
|
|
1668
|
+
slices: [...overwriteSlices, ...sigMeta.slices]
|
|
1669
|
+
});
|
|
1670
|
+
setGqlOnStorage(refName, modelGql);
|
|
1671
|
+
return modelGql;
|
|
1672
|
+
};
|
|
1673
|
+
var getPredefinedDefault = (refName) => {
|
|
1674
|
+
const defaultData = Reflect.getMetadata(refName, DefaultStorage.prototype);
|
|
1675
|
+
return defaultData;
|
|
1676
|
+
};
|
|
1677
|
+
var setPredefinedDefault = (refName, defaultData) => {
|
|
1678
|
+
Reflect.defineMetadata(refName, defaultData, DefaultStorage.prototype);
|
|
1679
|
+
};
|
|
1680
|
+
var makeDefault = (target, option = {}) => {
|
|
1681
|
+
const classMeta = getClassMeta(target);
|
|
1682
|
+
const predefinedDefault = getPredefinedDefault(classMeta.refName);
|
|
1683
|
+
if (predefinedDefault && !option.overwrite)
|
|
1684
|
+
return predefinedDefault;
|
|
1685
|
+
if (option.isChild && classMeta.type !== "scalar")
|
|
1686
|
+
return null;
|
|
1687
|
+
const metadatas = getFieldMetas(target);
|
|
1688
|
+
const result = {};
|
|
1689
|
+
for (const metadata of metadatas) {
|
|
1690
|
+
if (metadata.fieldType === "hidden")
|
|
1691
|
+
result[metadata.key] = null;
|
|
1692
|
+
else if (metadata.default) {
|
|
1693
|
+
if (typeof metadata.default === "function")
|
|
1694
|
+
result[metadata.key] = metadata.default();
|
|
1695
|
+
else if (metadata.default instanceof Enum)
|
|
1696
|
+
result[metadata.key] = [...metadata.default.values];
|
|
1632
1697
|
else
|
|
1633
|
-
result[metadata.key] =
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1698
|
+
result[metadata.key] = metadata.default;
|
|
1699
|
+
} else if (metadata.isArray)
|
|
1700
|
+
result[metadata.key] = [];
|
|
1701
|
+
else if (metadata.nullable)
|
|
1702
|
+
result[metadata.key] = null;
|
|
1703
|
+
else if (metadata.isClass)
|
|
1704
|
+
result[metadata.key] = metadata.isScalar ? makeDefault(metadata.modelRef) : null;
|
|
1705
|
+
else
|
|
1706
|
+
result[metadata.key] = scalarDefaultMap.get(metadata.modelRef);
|
|
1707
|
+
}
|
|
1708
|
+
setPredefinedDefault(classMeta.refName, result);
|
|
1709
|
+
return result;
|
|
1710
|
+
};
|
|
1711
|
+
var query = async (fetchClient, query2, variables = {}, option = {}) => {
|
|
1712
|
+
const jwt = option.url ? null : await fetchClient.getJwt();
|
|
1713
|
+
const { data, error } = await fetchClient.gql.query(query2, variables, {
|
|
1714
|
+
fetch,
|
|
1715
|
+
url: option.url ?? fetchClient.uri,
|
|
1716
|
+
requestPolicy: typeof option.cache === "string" ? option.cache : option.cache === true ? "cache-first" : "network-only",
|
|
1717
|
+
fetchOptions: {
|
|
1718
|
+
...typeof option.cache === "number" ? { next: { revalidate: option.cache } } : option.cache === true ? { cache: "force-cache" } : { cache: "no-store" },
|
|
1719
|
+
headers: {
|
|
1720
|
+
"apollo-require-preflight": "true",
|
|
1721
|
+
...jwt ? { authorization: `Bearer ${jwt}` } : {},
|
|
1722
|
+
...option.token ? { authorization: `Bearer ${option.token}` } : {}
|
|
1651
1723
|
}
|
|
1652
|
-
}).toPromise();
|
|
1653
|
-
if (!data) {
|
|
1654
|
-
const content = error?.graphQLErrors[0]?.message ?? "Unknown Error";
|
|
1655
|
-
if (option.onError) {
|
|
1656
|
-
option.onError(content);
|
|
1657
|
-
return;
|
|
1658
|
-
} else
|
|
1659
|
-
throw new Error(content);
|
|
1660
1724
|
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1725
|
+
}).toPromise();
|
|
1726
|
+
if (!data) {
|
|
1727
|
+
const content = error?.graphQLErrors[0]?.message ?? "Unknown Error";
|
|
1728
|
+
if (option.onError) {
|
|
1729
|
+
option.onError(content);
|
|
1730
|
+
return;
|
|
1731
|
+
} else
|
|
1732
|
+
throw new Error(content);
|
|
1733
|
+
}
|
|
1734
|
+
return data;
|
|
1735
|
+
};
|
|
1736
|
+
var mutate = async (fetchClient, mutation, variables = {}, option = {}) => {
|
|
1737
|
+
const jwt = option.url ? null : await fetchClient.getJwt();
|
|
1738
|
+
const { data, error } = await fetchClient.gql.mutation(mutation, variables, {
|
|
1739
|
+
fetch,
|
|
1740
|
+
url: option.url ?? fetchClient.uri,
|
|
1741
|
+
requestPolicy: "network-only",
|
|
1742
|
+
fetchOptions: {
|
|
1743
|
+
cache: "no-store",
|
|
1744
|
+
headers: {
|
|
1745
|
+
"apollo-require-preflight": "true",
|
|
1746
|
+
...jwt ? { authorization: `Bearer ${jwt}` } : {},
|
|
1747
|
+
...option.token ? { authorization: `Bearer ${option.token}` } : {}
|
|
1676
1748
|
}
|
|
1677
|
-
}).toPromise();
|
|
1678
|
-
if (!data) {
|
|
1679
|
-
const content = error?.graphQLErrors[0]?.message ?? "Unknown Error";
|
|
1680
|
-
if (option.onError) {
|
|
1681
|
-
option.onError(content);
|
|
1682
|
-
return;
|
|
1683
|
-
} else
|
|
1684
|
-
throw new Error(content);
|
|
1685
1749
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1750
|
+
}).toPromise();
|
|
1751
|
+
if (!data) {
|
|
1752
|
+
const content = error?.graphQLErrors[0]?.message ?? "Unknown Error";
|
|
1753
|
+
if (option.onError) {
|
|
1754
|
+
option.onError(content);
|
|
1755
|
+
return;
|
|
1756
|
+
} else
|
|
1757
|
+
throw new Error(content);
|
|
1758
|
+
}
|
|
1759
|
+
return data;
|
|
1760
|
+
};
|
|
1761
|
+
var scalarPurifyMap = /* @__PURE__ */ new Map([
|
|
1762
|
+
[Date, (value) => dayjs(value).toDate()],
|
|
1763
|
+
[String, (value) => value],
|
|
1764
|
+
[ID, (value) => value],
|
|
1765
|
+
[Boolean, (value) => value],
|
|
1766
|
+
[Int, (value) => value],
|
|
1767
|
+
[Float, (value) => value],
|
|
1768
|
+
[JSON2, (value) => value]
|
|
1769
|
+
]);
|
|
1770
|
+
var getPurifyFn = (modelRef) => {
|
|
1771
|
+
const [valueRef] = getNonArrayModel(modelRef);
|
|
1772
|
+
return scalarPurifyMap.get(valueRef) ?? ((value) => value);
|
|
1773
|
+
};
|
|
1774
|
+
var purify = (metadata, value, self) => {
|
|
1775
|
+
if (metadata.nullable && (value === null || value === void 0 || typeof value === "number" && isNaN(value) || typeof value === "string" && !value.length))
|
|
1776
|
+
return null;
|
|
1777
|
+
if (metadata.isArray) {
|
|
1778
|
+
if (!Array.isArray(value))
|
|
1779
|
+
throw new Error(`Invalid Array Value in ${metadata.key} for value ${value}`);
|
|
1780
|
+
if (metadata.minlength && value.length < metadata.minlength)
|
|
1781
|
+
throw new Error(`Invalid Array Length (Min) in ${metadata.key} for value ${value}`);
|
|
1782
|
+
else if (metadata.maxlength && value.length > metadata.maxlength)
|
|
1783
|
+
throw new Error(`Invalid Array Length (Max) in ${metadata.key} for value ${value}`);
|
|
1784
|
+
else if (metadata.optArrDepth === 0 && metadata.validate && !metadata.validate(value, self))
|
|
1785
|
+
throw new Error(`Invalid Array Value (Failed to pass validation) in ${metadata.key} for value ${value}`);
|
|
1786
|
+
return value.map((v) => purify({ ...metadata, isArray: false }, v, v));
|
|
1787
|
+
}
|
|
1788
|
+
if (metadata.isMap && metadata.of) {
|
|
1789
|
+
const purifyFn2 = getPurifyFn(metadata.of);
|
|
1790
|
+
return Object.fromEntries(
|
|
1791
|
+
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, purifyFn2)])
|
|
1792
|
+
);
|
|
1793
|
+
}
|
|
1794
|
+
if (metadata.isClass)
|
|
1795
|
+
return makePurify(metadata.modelRef)(value, true);
|
|
1796
|
+
if (metadata.name === "Date" && dayjs(value).isBefore(dayjs(/* @__PURE__ */ new Date("0000"))))
|
|
1797
|
+
throw new Error(`Invalid Date Value (Default) in ${metadata.key} for value ${value}`);
|
|
1798
|
+
if (["String", "ID"].includes(metadata.name) && (value === "" || !value))
|
|
1799
|
+
throw new Error(`Invalid String Value (Default) in ${metadata.key} for value ${value}`);
|
|
1800
|
+
if (metadata.validate && !metadata.validate(value, self))
|
|
1801
|
+
throw new Error(`Invalid Value (Failed to pass validation) / ${value} in ${metadata.key}`);
|
|
1802
|
+
if (!metadata.nullable && !value && value !== 0 && value !== false)
|
|
1803
|
+
throw new Error(`Invalid Value (Nullable) in ${metadata.key} for value ${value}`);
|
|
1804
|
+
const purifyFn = getPurifyFn(metadata.modelRef);
|
|
1805
|
+
return purifyFn(value);
|
|
1806
|
+
};
|
|
1807
|
+
var getPredefinedPurifyFn = (refName) => {
|
|
1808
|
+
const purify2 = Reflect.getMetadata(refName, PurifyStorage.prototype);
|
|
1809
|
+
return purify2;
|
|
1810
|
+
};
|
|
1811
|
+
var setPredefinedPurifyFn = (refName, purify2) => {
|
|
1812
|
+
Reflect.defineMetadata(refName, purify2, PurifyStorage.prototype);
|
|
1813
|
+
};
|
|
1814
|
+
var makePurify = (target, option = {}) => {
|
|
1815
|
+
const classMeta = getClassMeta(target);
|
|
1816
|
+
const purifyFn = getPredefinedPurifyFn(classMeta.refName);
|
|
1817
|
+
if (purifyFn && !option.overwrite)
|
|
1818
|
+
return purifyFn;
|
|
1819
|
+
const metadatas = getFieldMetas(target);
|
|
1820
|
+
const fn = (self, isChild) => {
|
|
1821
|
+
try {
|
|
1822
|
+
if (isChild && classMeta.type !== "scalar") {
|
|
1823
|
+
const id = self.id;
|
|
1824
|
+
if (!id)
|
|
1825
|
+
throw new Error(`Invalid Value (No ID) for id ${classMeta.refName}`);
|
|
1826
|
+
return id;
|
|
1827
|
+
}
|
|
1828
|
+
const result = {};
|
|
1829
|
+
for (const metadata of metadatas) {
|
|
1830
|
+
const value = self[metadata.key];
|
|
1831
|
+
result[metadata.key] = purify(metadata, value, self);
|
|
1832
|
+
}
|
|
1833
|
+
return result;
|
|
1834
|
+
} catch (err) {
|
|
1835
|
+
if (isChild)
|
|
1836
|
+
throw new Error(err);
|
|
1837
|
+
Logger.debug(err);
|
|
1703
1838
|
return null;
|
|
1704
|
-
if (metadata.isArray) {
|
|
1705
|
-
if (!Array.isArray(value))
|
|
1706
|
-
throw new Error(`Invalid Array Value in ${metadata.key} for value ${value}`);
|
|
1707
|
-
if (metadata.minlength && value.length < metadata.minlength)
|
|
1708
|
-
throw new Error(`Invalid Array Length (Min) in ${metadata.key} for value ${value}`);
|
|
1709
|
-
else if (metadata.maxlength && value.length > metadata.maxlength)
|
|
1710
|
-
throw new Error(`Invalid Array Length (Max) in ${metadata.key} for value ${value}`);
|
|
1711
|
-
else if (metadata.optArrDepth === 0 && metadata.validate && !metadata.validate(value, self))
|
|
1712
|
-
throw new Error(`Invalid Array Value (Failed to pass validation) in ${metadata.key} for value ${value}`);
|
|
1713
|
-
return value.map((v) => purify({ ...metadata, isArray: false }, v, v));
|
|
1714
1839
|
}
|
|
1715
|
-
if (metadata.isMap && metadata.of) {
|
|
1716
|
-
const purifyFn2 = getPurifyFn(metadata.of);
|
|
1717
|
-
return Object.fromEntries(
|
|
1718
|
-
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, purifyFn2)])
|
|
1719
|
-
);
|
|
1720
|
-
}
|
|
1721
|
-
if (metadata.isClass)
|
|
1722
|
-
return makePurify(metadata.modelRef)(value, true);
|
|
1723
|
-
if (metadata.name === "Date" && dayjs(value).isBefore(dayjs(/* @__PURE__ */ new Date("0000"))))
|
|
1724
|
-
throw new Error(`Invalid Date Value (Default) in ${metadata.key} for value ${value}`);
|
|
1725
|
-
if (["String", "ID"].includes(metadata.name) && (value === "" || !value))
|
|
1726
|
-
throw new Error(`Invalid String Value (Default) in ${metadata.key} for value ${value}`);
|
|
1727
|
-
if (metadata.validate && !metadata.validate(value, self))
|
|
1728
|
-
throw new Error(`Invalid Value (Failed to pass validation) / ${value} in ${metadata.key}`);
|
|
1729
|
-
if (!metadata.nullable && !value && value !== 0 && value !== false)
|
|
1730
|
-
throw new Error(`Invalid Value (Nullable) in ${metadata.key} for value ${value}`);
|
|
1731
|
-
const purifyFn = getPurifyFn(metadata.modelRef);
|
|
1732
|
-
return purifyFn(value);
|
|
1733
|
-
};
|
|
1734
|
-
var getPredefinedPurifyFn = (refName) => {
|
|
1735
|
-
const purify2 = Reflect.getMetadata(refName, PurifyStorage.prototype);
|
|
1736
|
-
return purify2;
|
|
1737
|
-
};
|
|
1738
|
-
var setPredefinedPurifyFn = (refName, purify2) => {
|
|
1739
|
-
Reflect.defineMetadata(refName, purify2, PurifyStorage.prototype);
|
|
1740
1840
|
};
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1841
|
+
setPredefinedPurifyFn(classMeta.refName, fn);
|
|
1842
|
+
return fn;
|
|
1843
|
+
};
|
|
1844
|
+
var scalarCrystalizeMap = /* @__PURE__ */ new Map([
|
|
1845
|
+
[Date, (value) => dayjs(value)],
|
|
1846
|
+
[String, (value) => value],
|
|
1847
|
+
[ID, (value) => value],
|
|
1848
|
+
[Boolean, (value) => value],
|
|
1849
|
+
[Int, (value) => value],
|
|
1850
|
+
[Float, (value) => value],
|
|
1851
|
+
[JSON2, (value) => value]
|
|
1852
|
+
]);
|
|
1853
|
+
var crystalize = (metadata, value) => {
|
|
1854
|
+
if (value === void 0 || value === null)
|
|
1855
|
+
return value;
|
|
1856
|
+
if (metadata.isArray && Array.isArray(value))
|
|
1857
|
+
return value.map((v) => crystalize({ ...metadata, isArray: false }, v));
|
|
1858
|
+
if (metadata.isMap) {
|
|
1859
|
+
const [valueRef] = getNonArrayModel(metadata.of);
|
|
1860
|
+
const crystalizeValue = scalarCrystalizeMap.get(valueRef) ?? ((value2) => value2);
|
|
1861
|
+
return new Map(
|
|
1862
|
+
Object.entries(value).map(([key, val]) => [key, applyFnToArrayObjects(val, crystalizeValue)])
|
|
1863
|
+
);
|
|
1864
|
+
}
|
|
1865
|
+
if (metadata.isClass)
|
|
1866
|
+
return makeCrystalize(metadata.modelRef)(value, true);
|
|
1867
|
+
if (metadata.name === "Date")
|
|
1868
|
+
return dayjs(value);
|
|
1869
|
+
return (scalarCrystalizeMap.get(metadata.modelRef) ?? ((value2) => value2))(value);
|
|
1870
|
+
};
|
|
1871
|
+
var getPredefinedCrystalizeFn = (refName) => {
|
|
1872
|
+
const crystalize2 = Reflect.getMetadata(refName, CrystalizeStorage.prototype);
|
|
1873
|
+
return crystalize2;
|
|
1874
|
+
};
|
|
1875
|
+
var setPredefinedCrystalizeFn = (refName, crystalize2) => {
|
|
1876
|
+
Reflect.defineMetadata(refName, crystalize2, CrystalizeStorage.prototype);
|
|
1877
|
+
};
|
|
1878
|
+
var makeCrystalize = (target, option = {}) => {
|
|
1879
|
+
const classMeta = getClassMeta(target);
|
|
1880
|
+
const crystalizeFn = getPredefinedCrystalizeFn(classMeta.refName);
|
|
1881
|
+
if (crystalizeFn && !option.overwrite && !option.partial?.length)
|
|
1882
|
+
return crystalizeFn;
|
|
1883
|
+
const fieldMetaMap = getFieldMetaMap(target);
|
|
1884
|
+
const fieldKeys = option.partial?.length ? classMeta.type === "scalar" ? option.partial : ["id", ...option.partial, "updatedAt"] : [...fieldMetaMap.keys()];
|
|
1885
|
+
const metadatas = fieldKeys.map((key) => fieldMetaMap.get(key));
|
|
1886
|
+
const fn = (self, isChild) => {
|
|
1887
|
+
try {
|
|
1888
|
+
const result = Object.assign(new target(), self);
|
|
1889
|
+
for (const metadata of metadatas.filter((m) => !!self[m.key])) {
|
|
1890
|
+
if (metadata.fieldType === "hidden")
|
|
1891
|
+
continue;
|
|
1892
|
+
result[metadata.key] = crystalize(metadata, self[metadata.key]);
|
|
1766
1893
|
}
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
[Date, (value) => dayjs(value)],
|
|
1773
|
-
[String, (value) => value],
|
|
1774
|
-
[ID, (value) => value],
|
|
1775
|
-
[Boolean, (value) => value],
|
|
1776
|
-
[Int, (value) => value],
|
|
1777
|
-
[Float, (value) => value],
|
|
1778
|
-
[JSON2, (value) => value]
|
|
1779
|
-
]);
|
|
1780
|
-
var crystalize = (metadata, value) => {
|
|
1781
|
-
if (value === void 0 || value === null)
|
|
1782
|
-
return value;
|
|
1783
|
-
if (metadata.isArray && Array.isArray(value))
|
|
1784
|
-
return value.map((v) => crystalize({ ...metadata, isArray: false }, v));
|
|
1785
|
-
if (metadata.isMap) {
|
|
1786
|
-
const [valueRef] = getNonArrayModel(metadata.of);
|
|
1787
|
-
const crystalizeValue = scalarCrystalizeMap.get(valueRef) ?? ((value2) => value2);
|
|
1788
|
-
return new Map(
|
|
1789
|
-
Object.entries(value).map(([key, val]) => [key, applyFnToArrayObjects(val, crystalizeValue)])
|
|
1790
|
-
);
|
|
1894
|
+
return result;
|
|
1895
|
+
} catch (err) {
|
|
1896
|
+
if (isChild)
|
|
1897
|
+
throw new Error(err);
|
|
1898
|
+
return null;
|
|
1791
1899
|
}
|
|
1792
|
-
if (metadata.isClass)
|
|
1793
|
-
return makeCrystalize(metadata.modelRef)(value, true);
|
|
1794
|
-
if (metadata.name === "Date")
|
|
1795
|
-
return dayjs(value);
|
|
1796
|
-
return (scalarCrystalizeMap.get(metadata.modelRef) ?? ((value2) => value2))(value);
|
|
1797
|
-
};
|
|
1798
|
-
var getPredefinedCrystalizeFn = (refName) => {
|
|
1799
|
-
const crystalize2 = Reflect.getMetadata(refName, CrystalizeStorage.prototype);
|
|
1800
|
-
return crystalize2;
|
|
1801
|
-
};
|
|
1802
|
-
var setPredefinedCrystalizeFn = (refName, crystalize2) => {
|
|
1803
|
-
Reflect.defineMetadata(refName, crystalize2, CrystalizeStorage.prototype);
|
|
1804
|
-
};
|
|
1805
|
-
var makeCrystalize = (target, option = {}) => {
|
|
1806
|
-
const classMeta = getClassMeta(target);
|
|
1807
|
-
const crystalizeFn = getPredefinedCrystalizeFn(classMeta.refName);
|
|
1808
|
-
if (crystalizeFn && !option.overwrite && !option.partial?.length)
|
|
1809
|
-
return crystalizeFn;
|
|
1810
|
-
const fieldMetaMap = getFieldMetaMap(target);
|
|
1811
|
-
const fieldKeys = option.partial?.length ? classMeta.type === "scalar" ? option.partial : ["id", ...option.partial, "updatedAt"] : [...fieldMetaMap.keys()];
|
|
1812
|
-
const metadatas = fieldKeys.map((key) => fieldMetaMap.get(key));
|
|
1813
|
-
const fn = (self, isChild) => {
|
|
1814
|
-
try {
|
|
1815
|
-
const result = Object.assign(new target(), self);
|
|
1816
|
-
for (const metadata of metadatas.filter((m) => !!self[m.key])) {
|
|
1817
|
-
if (metadata.fieldType === "hidden")
|
|
1818
|
-
continue;
|
|
1819
|
-
result[metadata.key] = crystalize(metadata, self[metadata.key]);
|
|
1820
|
-
}
|
|
1821
|
-
return result;
|
|
1822
|
-
} catch (err) {
|
|
1823
|
-
if (isChild)
|
|
1824
|
-
throw new Error(err);
|
|
1825
|
-
return null;
|
|
1826
|
-
}
|
|
1827
|
-
};
|
|
1828
|
-
if (!option.partial?.length)
|
|
1829
|
-
setPredefinedCrystalizeFn(classMeta.refName, fn);
|
|
1830
|
-
return fn;
|
|
1831
1900
|
};
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1901
|
+
if (!option.partial?.length)
|
|
1902
|
+
setPredefinedCrystalizeFn(classMeta.refName, fn);
|
|
1903
|
+
return fn;
|
|
1904
|
+
};
|
|
1905
|
+
var fragmentize = (target, fragMap = /* @__PURE__ */ new Map(), partial) => {
|
|
1906
|
+
const classMeta = getClassMeta(target);
|
|
1907
|
+
const metadatas = getFieldMetas(target);
|
|
1908
|
+
const selectKeys = partial ? ["id", ...partial, "updatedAt"] : metadatas.map((metadata) => metadata.key);
|
|
1909
|
+
const selectKeySet = new Set(selectKeys);
|
|
1910
|
+
const fragment = `fragment ${lowerlize(classMeta.refName)}Fragment on ${capitalize(
|
|
1911
|
+
classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName
|
|
1912
|
+
)} {
|
|
1840
1913
|
` + metadatas.filter((metadata) => metadata.fieldType !== "hidden" && selectKeySet.has(metadata.key)).map((metadata) => {
|
|
1841
|
-
|
|
1914
|
+
return metadata.isClass ? ` ${metadata.key} {
|
|
1842
1915
|
...${lowerlize(metadata.name)}Fragment
|
|
1843
1916
|
}` : ` ${metadata.key}`;
|
|
1844
|
-
|
|
1917
|
+
}).join(`
|
|
1845
1918
|
`) + `
|
|
1846
1919
|
}`;
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1920
|
+
fragMap.set(classMeta.refName, fragment);
|
|
1921
|
+
metadatas.filter((metadata) => metadata.fieldType !== "hidden" && selectKeySet.has(metadata.key) && metadata.isClass).forEach((metadata) => fragmentize(metadata.modelRef, fragMap));
|
|
1922
|
+
return fragMap;
|
|
1923
|
+
};
|
|
1924
|
+
var getPredefinedFragment = (refName) => {
|
|
1925
|
+
const fragment = Reflect.getMetadata(refName, FragmentStorage.prototype);
|
|
1926
|
+
return fragment;
|
|
1927
|
+
};
|
|
1928
|
+
var setPredefinedFragment = (refName, fragment) => {
|
|
1929
|
+
Reflect.defineMetadata(refName, fragment, FragmentStorage.prototype);
|
|
1930
|
+
};
|
|
1931
|
+
var makeFragment = (target, option = {}) => {
|
|
1932
|
+
const classMeta = getClassMeta(target);
|
|
1933
|
+
const fragment = getPredefinedFragment(classMeta.refName);
|
|
1934
|
+
if (fragment && !option.overwrite && !option.excludeSelf && !option.partial?.length)
|
|
1853
1935
|
return fragment;
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
setPredefinedFragment(classMeta.refName, gqlStr);
|
|
1869
|
-
return gqlStr;
|
|
1870
|
-
};
|
|
1871
|
-
var getGqlStr = (modelRef, gqlMeta, argMetas, returnRef, partial) => {
|
|
1872
|
-
const isScalar = isGqlScalar(modelRef);
|
|
1873
|
-
const argStr = makeArgStr(argMetas);
|
|
1874
|
-
const argAssignStr = makeArgAssignStr(argMetas);
|
|
1875
|
-
const returnStr = makeReturnStr(returnRef, partial);
|
|
1876
|
-
const gqlStr = `${isScalar ? "" : makeFragment(returnRef, { excludeSelf: !!partial?.length, partial })}
|
|
1936
|
+
const fragMap = new Map(fragmentize(target, /* @__PURE__ */ new Map(), option.partial));
|
|
1937
|
+
if (option.excludeSelf)
|
|
1938
|
+
fragMap.delete(classMeta.refName);
|
|
1939
|
+
const gqlStr = [...fragMap.values()].join("\n");
|
|
1940
|
+
if (!option.excludeSelf)
|
|
1941
|
+
setPredefinedFragment(classMeta.refName, gqlStr);
|
|
1942
|
+
return gqlStr;
|
|
1943
|
+
};
|
|
1944
|
+
var getGqlStr = (modelRef, gqlMeta, argMetas, returnRef, partial) => {
|
|
1945
|
+
const isScalar = isGqlScalar(modelRef);
|
|
1946
|
+
const argStr = makeArgStr(argMetas);
|
|
1947
|
+
const argAssignStr = makeArgAssignStr(argMetas);
|
|
1948
|
+
const returnStr = makeReturnStr(returnRef, partial);
|
|
1949
|
+
const gqlStr = `${isScalar ? "" : makeFragment(returnRef, { excludeSelf: !!partial?.length, partial })}
|
|
1877
1950
|
${lowerlize(gqlMeta.type) + " " + gqlMeta.key + argStr}{
|
|
1878
1951
|
${gqlMeta.key}${argAssignStr}${returnStr}
|
|
1879
1952
|
}
|
|
1880
1953
|
`;
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
const io2 = this.client.getIo(fetchPolicy.url);
|
|
2005
|
-
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2006
|
-
io2.emit(gqlMeta.key, message);
|
|
2007
|
-
Logger.debug(`socket emit: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2008
|
-
});
|
|
2009
|
-
}
|
|
2010
|
-
};
|
|
2011
|
-
const listenEvent = function(handleEvent, fetchPolicy = {}) {
|
|
2012
|
-
const crystalize2 = (data) => {
|
|
2013
|
-
if (isScalar) {
|
|
2014
|
-
if (returnRef.prototype === Date.prototype)
|
|
2015
|
-
return dayjs(data);
|
|
2016
|
-
else
|
|
2017
|
-
return data;
|
|
2018
|
-
} else if (Array.isArray(data))
|
|
2019
|
-
return data.map((d) => crystalize2(d));
|
|
2020
|
-
else
|
|
2021
|
-
return makeCrystalize(returnRef)(data);
|
|
2022
|
-
};
|
|
2023
|
-
const handle = (data) => {
|
|
2024
|
-
Logger.debug(`socket listened: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2025
|
-
handleEvent(crystalize2(data));
|
|
2026
|
-
};
|
|
1954
|
+
return gqlStr;
|
|
1955
|
+
};
|
|
1956
|
+
var scalarSerializeMap = /* @__PURE__ */ new Map([
|
|
1957
|
+
[Date, (value) => dayjs(value).toDate()],
|
|
1958
|
+
[String, (value) => value],
|
|
1959
|
+
[ID, (value) => value],
|
|
1960
|
+
[Boolean, (value) => value],
|
|
1961
|
+
[Int, (value) => value],
|
|
1962
|
+
[Float, (value) => value],
|
|
1963
|
+
[JSON2, (value) => value]
|
|
1964
|
+
]);
|
|
1965
|
+
var getSerializeFn = (inputRef) => {
|
|
1966
|
+
const serializeFn = scalarSerializeMap.get(inputRef);
|
|
1967
|
+
if (!serializeFn)
|
|
1968
|
+
return (value) => value;
|
|
1969
|
+
else
|
|
1970
|
+
return serializeFn;
|
|
1971
|
+
};
|
|
1972
|
+
var serializeInput = (value, inputRef, arrDepth) => {
|
|
1973
|
+
if (arrDepth && Array.isArray(value))
|
|
1974
|
+
return value.map((v) => serializeInput(v, inputRef, arrDepth - 1));
|
|
1975
|
+
else if (inputRef.prototype === Map.prototype) {
|
|
1976
|
+
const [valueRef] = getNonArrayModel(inputRef);
|
|
1977
|
+
const serializeFn = getSerializeFn(valueRef);
|
|
1978
|
+
return Object.fromEntries(
|
|
1979
|
+
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, serializeFn)])
|
|
1980
|
+
);
|
|
1981
|
+
} else if (isGqlScalar(inputRef)) {
|
|
1982
|
+
const serializeFn = getSerializeFn(inputRef);
|
|
1983
|
+
return serializeFn(value);
|
|
1984
|
+
}
|
|
1985
|
+
const classMeta = getClassMeta(inputRef);
|
|
1986
|
+
if (classMeta.type !== "scalar")
|
|
1987
|
+
return value;
|
|
1988
|
+
else
|
|
1989
|
+
return Object.fromEntries(
|
|
1990
|
+
getFieldMetas(inputRef).map((fieldMeta) => [
|
|
1991
|
+
fieldMeta.key,
|
|
1992
|
+
serializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
|
|
1993
|
+
])
|
|
1994
|
+
);
|
|
1995
|
+
};
|
|
1996
|
+
var serializeArg = (argMeta, value) => {
|
|
1997
|
+
const [returnRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
1998
|
+
if (argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
1999
|
+
return null;
|
|
2000
|
+
else if (!argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
2001
|
+
throw new Error(`Invalid Value (Nullable) in ${argMeta.name} for value ${value}`);
|
|
2002
|
+
return serializeInput(value, returnRef, arrDepth);
|
|
2003
|
+
};
|
|
2004
|
+
var scalarDeserializeMap = /* @__PURE__ */ new Map([
|
|
2005
|
+
[Date, (value) => dayjs(value)],
|
|
2006
|
+
[String, (value) => value],
|
|
2007
|
+
[ID, (value) => value],
|
|
2008
|
+
[Boolean, (value) => value],
|
|
2009
|
+
[Int, (value) => value],
|
|
2010
|
+
[Float, (value) => value],
|
|
2011
|
+
[JSON2, (value) => value]
|
|
2012
|
+
]);
|
|
2013
|
+
var getDeserializeFn = (inputRef) => {
|
|
2014
|
+
const deserializeFn = scalarDeserializeMap.get(inputRef);
|
|
2015
|
+
if (!deserializeFn)
|
|
2016
|
+
return (value) => value;
|
|
2017
|
+
return deserializeFn;
|
|
2018
|
+
};
|
|
2019
|
+
var deserializeInput = (value, inputRef, arrDepth) => {
|
|
2020
|
+
if (arrDepth && Array.isArray(value))
|
|
2021
|
+
return value.map((v) => deserializeInput(v, inputRef, arrDepth - 1));
|
|
2022
|
+
else if (inputRef.prototype === Map.prototype) {
|
|
2023
|
+
const [valueRef] = getNonArrayModel(inputRef);
|
|
2024
|
+
const deserializeFn = getDeserializeFn(valueRef);
|
|
2025
|
+
return Object.fromEntries(
|
|
2026
|
+
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, deserializeFn)])
|
|
2027
|
+
);
|
|
2028
|
+
} else if (isGqlScalar(inputRef)) {
|
|
2029
|
+
const deserializeFn = getDeserializeFn(inputRef);
|
|
2030
|
+
return deserializeFn(value);
|
|
2031
|
+
}
|
|
2032
|
+
const classMeta = getClassMeta(inputRef);
|
|
2033
|
+
if (classMeta.type !== "scalar")
|
|
2034
|
+
return value;
|
|
2035
|
+
else
|
|
2036
|
+
return Object.fromEntries(
|
|
2037
|
+
getFieldMetas(inputRef).map((fieldMeta) => [
|
|
2038
|
+
fieldMeta.key,
|
|
2039
|
+
deserializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
|
|
2040
|
+
])
|
|
2041
|
+
);
|
|
2042
|
+
};
|
|
2043
|
+
var deserializeArg = (argMeta, value) => {
|
|
2044
|
+
const [returnRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
2045
|
+
if (argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
2046
|
+
return null;
|
|
2047
|
+
else if (!argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
2048
|
+
throw new Error(`Invalid Value (Nullable) in ${argMeta.name} for value ${value}`);
|
|
2049
|
+
return deserializeInput(value, returnRef, arrDepth);
|
|
2050
|
+
};
|
|
2051
|
+
var fetchOf = (sigRef) => {
|
|
2052
|
+
const gqls = {};
|
|
2053
|
+
const gqlMetas = getGqlMetas(sigRef);
|
|
2054
|
+
gqlMetas.filter((gqlMeta) => !gqlMeta.signalOption.default).forEach((gqlMeta) => {
|
|
2055
|
+
if (gqlMeta.type === "Message") {
|
|
2056
|
+
const [returnRef, arrDepth] = getNonArrayModel(gqlMeta.returns());
|
|
2057
|
+
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
2058
|
+
const isScalar = isGqlScalar(returnRef);
|
|
2059
|
+
const emitEvent = function(...args) {
|
|
2060
|
+
const fetchPolicy = args[argMetas.length] ?? { crystalize: true };
|
|
2061
|
+
if (!this.client.io && !fetchPolicy.url) {
|
|
2062
|
+
Logger.warn(`${gqlMeta.key} emit suppressed - socket is not connected`);
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
const message = Object.fromEntries(
|
|
2066
|
+
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
2067
|
+
);
|
|
2068
|
+
if (fetchPolicy.transport === "udp") {
|
|
2069
|
+
if (!this.client.udp)
|
|
2070
|
+
throw new Error("UDP is not set");
|
|
2071
|
+
const uri = fetchPolicy.url ?? "udpout:localhost:4000";
|
|
2072
|
+
const [host, port] = uri.split(":").slice(1);
|
|
2073
|
+
this.client.udp.send(JSON.stringify(message), parseInt(port), host);
|
|
2074
|
+
Logger.debug(`udp emit: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2075
|
+
return;
|
|
2076
|
+
} else {
|
|
2027
2077
|
const io2 = this.client.getIo(fetchPolicy.url);
|
|
2028
|
-
this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2029
|
-
io2.
|
|
2030
|
-
|
|
2031
|
-
Logger.debug(`socket listen start: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2078
|
+
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2079
|
+
io2.emit(gqlMeta.key, message);
|
|
2080
|
+
Logger.debug(`socket emit: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2032
2081
|
});
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
io2.removeListener(gqlMeta.key, handle);
|
|
2037
|
-
};
|
|
2038
|
-
};
|
|
2039
|
-
gqls[gqlMeta.key] = emitEvent;
|
|
2040
|
-
gqls[`listen${capitalize(gqlMeta.key)}`] = listenEvent;
|
|
2041
|
-
} else if (gqlMeta.type === "Pubsub") {
|
|
2042
|
-
const [returnRef] = getNonArrayModel(gqlMeta.returns());
|
|
2043
|
-
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
2044
|
-
const isScalar = isGqlScalar(returnRef);
|
|
2045
|
-
const makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
2082
|
+
}
|
|
2083
|
+
};
|
|
2084
|
+
const listenEvent = function(handleEvent, fetchPolicy = {}) {
|
|
2046
2085
|
const crystalize2 = (data) => {
|
|
2047
2086
|
if (isScalar) {
|
|
2048
2087
|
if (returnRef.prototype === Date.prototype)
|
|
@@ -2054,202 +2093,235 @@ ${lowerlize(gqlMeta.type) + " " + gqlMeta.key + argStr}{
|
|
|
2054
2093
|
else
|
|
2055
2094
|
return makeCrystalize(returnRef)(data);
|
|
2056
2095
|
};
|
|
2057
|
-
const
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
const message = Object.fromEntries(
|
|
2061
|
-
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
2062
|
-
);
|
|
2063
|
-
const handleEvent = (data) => {
|
|
2064
|
-
if (data.__subscribe__)
|
|
2065
|
-
return;
|
|
2066
|
-
onData(crystalize2(data));
|
|
2067
|
-
};
|
|
2068
|
-
const roomId = makeRoomId(
|
|
2069
|
-
gqlMeta.key,
|
|
2070
|
-
argMetas.map((argMeta) => message[argMeta.name])
|
|
2071
|
-
);
|
|
2072
|
-
const io2 = this.client.getIo(fetchPolicy.url);
|
|
2073
|
-
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2074
|
-
Logger.debug(`socket subscribe start: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2075
|
-
io2.subscribe({ key: gqlMeta.key, roomId, message, handleEvent });
|
|
2076
|
-
});
|
|
2077
|
-
return async () => {
|
|
2078
|
-
await this.client.waitUntilWebSocketConnected(fetchPolicy.url);
|
|
2079
|
-
Logger.debug(`socket unsubscribe: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2080
|
-
io2.unsubscribe(roomId, handleEvent);
|
|
2081
|
-
};
|
|
2096
|
+
const handle = (data) => {
|
|
2097
|
+
Logger.debug(`socket listened: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2098
|
+
handleEvent(crystalize2(data));
|
|
2082
2099
|
};
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
Logger.debug(`
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
};
|
|
2108
|
-
try {
|
|
2109
|
-
const res = (await (gqlMeta.type === "Query" ? query : mutate)(
|
|
2110
|
-
this.client,
|
|
2111
|
-
graphql(getGqlStr(modelRef, gqlMeta, argMetas, returnRef, partial)),
|
|
2112
|
-
Object.fromEntries(
|
|
2113
|
-
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
2114
|
-
),
|
|
2115
|
-
fetchPolicy
|
|
2116
|
-
))[name];
|
|
2117
|
-
const data = resolve2 ? crystalize2(res) : res;
|
|
2118
|
-
Logger.debug(
|
|
2119
|
-
`fetch: ${gqlMeta.key} end: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")} ${Date.now() - now}ms`
|
|
2120
|
-
);
|
|
2100
|
+
const io2 = this.client.getIo(fetchPolicy.url);
|
|
2101
|
+
this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2102
|
+
io2.removeListener(gqlMeta.key, handle);
|
|
2103
|
+
io2.on(gqlMeta.key, handle);
|
|
2104
|
+
Logger.debug(`socket listen start: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2105
|
+
});
|
|
2106
|
+
return async () => {
|
|
2107
|
+
await this.client.waitUntilWebSocketConnected(fetchPolicy.url);
|
|
2108
|
+
Logger.debug(`socket listen end: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2109
|
+
io2.removeListener(gqlMeta.key, handle);
|
|
2110
|
+
};
|
|
2111
|
+
};
|
|
2112
|
+
gqls[gqlMeta.key] = emitEvent;
|
|
2113
|
+
gqls[`listen${capitalize(gqlMeta.key)}`] = listenEvent;
|
|
2114
|
+
} else if (gqlMeta.type === "Pubsub") {
|
|
2115
|
+
const [returnRef] = getNonArrayModel(gqlMeta.returns());
|
|
2116
|
+
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
2117
|
+
const isScalar = isGqlScalar(returnRef);
|
|
2118
|
+
const makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
2119
|
+
const crystalize2 = (data) => {
|
|
2120
|
+
if (isScalar) {
|
|
2121
|
+
if (returnRef.prototype === Date.prototype)
|
|
2122
|
+
return dayjs(data);
|
|
2123
|
+
else
|
|
2121
2124
|
return data;
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2125
|
+
} else if (Array.isArray(data))
|
|
2126
|
+
return data.map((d) => crystalize2(d));
|
|
2127
|
+
else
|
|
2128
|
+
return makeCrystalize(returnRef)(data);
|
|
2129
|
+
};
|
|
2130
|
+
const subscribeEvent = function(...args) {
|
|
2131
|
+
const onData = args[argMetas.length];
|
|
2132
|
+
const fetchPolicy = args[argMetas.length + 1] ?? { crystalize: true };
|
|
2133
|
+
const message = Object.fromEntries(
|
|
2134
|
+
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
2135
|
+
);
|
|
2136
|
+
const handleEvent = (data) => {
|
|
2137
|
+
if (data.__subscribe__)
|
|
2138
|
+
return;
|
|
2139
|
+
onData(crystalize2(data));
|
|
2126
2140
|
};
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2141
|
+
const roomId = makeRoomId(
|
|
2142
|
+
gqlMeta.key,
|
|
2143
|
+
argMetas.map((argMeta) => message[argMeta.name])
|
|
2144
|
+
);
|
|
2145
|
+
const io2 = this.client.getIo(fetchPolicy.url);
|
|
2146
|
+
void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
|
|
2147
|
+
Logger.debug(`socket subscribe start: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2148
|
+
io2.subscribe({ key: gqlMeta.key, roomId, message, handleEvent });
|
|
2149
|
+
});
|
|
2150
|
+
return async () => {
|
|
2151
|
+
await this.client.waitUntilWebSocketConnected(fetchPolicy.url);
|
|
2152
|
+
Logger.debug(`socket unsubscribe: ${gqlMeta.key}: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2153
|
+
io2.unsubscribe(roomId, handleEvent);
|
|
2154
|
+
};
|
|
2155
|
+
};
|
|
2156
|
+
gqls[`subscribe${capitalize(gqlMeta.key)}`] = subscribeEvent;
|
|
2157
|
+
} else if (gqlMeta.type === "Query" || gqlMeta.type === "Mutation") {
|
|
2158
|
+
const name = gqlMeta.signalOption.name ?? gqlMeta.key;
|
|
2159
|
+
const makeReq = ({ resolve: resolve2 }) => async function(...args) {
|
|
2160
|
+
Logger.debug(`fetch: ${gqlMeta.key} start: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
|
2161
|
+
const now = Date.now();
|
|
2162
|
+
const [argMetas] = getArgMetas(sigRef, gqlMeta.signalOption.name ?? gqlMeta.key);
|
|
2163
|
+
const [modelRef, arrDepth] = getNonArrayModel(gqlMeta.returns());
|
|
2164
|
+
const isScalar = isGqlScalar(modelRef);
|
|
2165
|
+
const returnRef = isScalar || !arrDepth ? modelRef : getLightModelRef(modelRef);
|
|
2166
|
+
const fetchPolicy = args[argMetas.length] ?? { crystalize: true };
|
|
2167
|
+
const partial = fetchPolicy.partial ?? gqlMeta.signalOption.partial;
|
|
2168
|
+
const crystalize2 = (data) => {
|
|
2169
|
+
if (fetchPolicy.crystalize === false)
|
|
2170
|
+
return data;
|
|
2171
|
+
if (isScalar) {
|
|
2172
|
+
if (returnRef.prototype === Date.prototype)
|
|
2173
|
+
return dayjs(data);
|
|
2174
|
+
else
|
|
2175
|
+
return data;
|
|
2176
|
+
} else if (Array.isArray(data))
|
|
2177
|
+
return data.map((d) => crystalize2(d));
|
|
2178
|
+
else
|
|
2179
|
+
return makeCrystalize(returnRef, { partial })(data);
|
|
2180
|
+
};
|
|
2181
|
+
try {
|
|
2182
|
+
const res = (await (gqlMeta.type === "Query" ? query : mutate)(
|
|
2183
|
+
this.client,
|
|
2184
|
+
graphql(getGqlStr(modelRef, gqlMeta, argMetas, returnRef, partial)),
|
|
2185
|
+
Object.fromEntries(
|
|
2186
|
+
argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
|
|
2187
|
+
),
|
|
2188
|
+
fetchPolicy
|
|
2189
|
+
))[name];
|
|
2190
|
+
const data = resolve2 ? crystalize2(res) : res;
|
|
2191
|
+
Logger.debug(
|
|
2192
|
+
`fetch: ${gqlMeta.key} end: ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")} ${Date.now() - now}ms`
|
|
2193
|
+
);
|
|
2194
|
+
return data;
|
|
2195
|
+
} catch (e) {
|
|
2196
|
+
Logger.error(`fetch: ${gqlMeta.key} error: ${e}`);
|
|
2197
|
+
throw e;
|
|
2198
|
+
}
|
|
2199
|
+
};
|
|
2200
|
+
gqls[name] = makeReq({ resolve: true });
|
|
2201
|
+
gqls[`_${name}`] = makeReq({ resolve: false });
|
|
2202
|
+
}
|
|
2203
|
+
});
|
|
2204
|
+
return gqls;
|
|
2205
|
+
};
|
|
2206
|
+
var makeFetch = (fetch1, fetch2, fetch3, fetch4, fetch5, fetch6, fetch7, fetch8, fetch9, fetch10) => {
|
|
2207
|
+
return Object.assign(fetch1, fetch2, fetch3, fetch4, fetch5, fetch6, fetch7, fetch8, fetch9, fetch10);
|
|
2208
|
+
};
|
|
2209
|
+
var makeArgStr = (argMetas) => {
|
|
2210
|
+
return argMetas.length ? `(${argMetas.map((argMeta) => {
|
|
2211
|
+
const [argRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
2212
|
+
const argRefType = isGqlScalar(argRef) ? "gqlScalar" : getClassMeta(argRef).type === "scalar" ? "scalar" : "model";
|
|
2213
|
+
const gqlTypeStr = "[".repeat(arrDepth) + (getGqlTypeStr(argRef) + (argRefType === "scalar" ? "Input" : "")) + "!]".repeat(arrDepth);
|
|
2214
|
+
return `$${argMeta.name}: ` + gqlTypeStr + (argMeta.argsOption.nullable ? "" : "!");
|
|
2215
|
+
}).join(", ")})` : "";
|
|
2216
|
+
};
|
|
2217
|
+
var makeArgAssignStr = (argMetas) => {
|
|
2218
|
+
return argMetas.length ? `(${argMetas.map((argMeta) => `${argMeta.name}: $${argMeta.name}`).join(", ")})` : "";
|
|
2219
|
+
};
|
|
2220
|
+
var makeReturnStr = (returnRef, partial) => {
|
|
2221
|
+
const isScalar = isGqlScalar(returnRef);
|
|
2222
|
+
if (isScalar)
|
|
2223
|
+
return "";
|
|
2224
|
+
const classMeta = getClassMeta(returnRef);
|
|
2225
|
+
if (!partial?.length)
|
|
2226
|
+
return ` {
|
|
2154
2227
|
...${lowerlize(classMeta.refName)}Fragment
|
|
2155
2228
|
}`;
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2229
|
+
const targetKeys = classMeta.type === "scalar" ? partial : [.../* @__PURE__ */ new Set(["id", ...partial, "updatedAt"])];
|
|
2230
|
+
const fieldMetaMap = getFieldMetaMap(returnRef);
|
|
2231
|
+
return ` {
|
|
2159
2232
|
${targetKeys.map((key) => fieldMetaMap.get(key)).filter((metadata) => metadata && metadata.fieldType !== "hidden").map(
|
|
2160
|
-
|
|
2233
|
+
(fieldMeta) => fieldMeta.isClass ? ` ${fieldMeta.key} {
|
|
2161
2234
|
...${lowerlize(fieldMeta.name)}Fragment
|
|
2162
2235
|
}` : ` ${fieldMeta.key}`
|
|
2163
|
-
|
|
2236
|
+
).join("\n")}
|
|
2164
2237
|
}`;
|
|
2165
|
-
|
|
2238
|
+
};
|
|
2166
2239
|
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2240
|
+
// pkgs/@akanjs/signal/src/doc.ts
|
|
2241
|
+
var ResponseExampleStorage = class {
|
|
2242
|
+
};
|
|
2243
|
+
var getPredefinedRequestExample = (modelRef) => {
|
|
2244
|
+
return Reflect.getMetadata(modelRef, ResponseExampleStorage.prototype);
|
|
2245
|
+
};
|
|
2246
|
+
var getResponseExample = (ref) => {
|
|
2247
|
+
const [modelRef, arrDepth] = getNonArrayModel(ref);
|
|
2248
|
+
const existing = getPredefinedRequestExample(modelRef);
|
|
2249
|
+
if (existing)
|
|
2250
|
+
return existing;
|
|
2251
|
+
const isScalar = isGqlScalar(modelRef);
|
|
2252
|
+
if (isScalar)
|
|
2253
|
+
return arraiedModel(getScalarExample(modelRef), arrDepth);
|
|
2254
|
+
const fieldMetas = getFieldMetas(modelRef);
|
|
2255
|
+
const example = {};
|
|
2256
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
2257
|
+
if (fieldMeta.example)
|
|
2258
|
+
example[fieldMeta.key] = fieldMeta.example;
|
|
2259
|
+
else if (fieldMeta.enum)
|
|
2260
|
+
example[fieldMeta.key] = arraiedModel(fieldMeta.enum.values[0], fieldMeta.arrDepth);
|
|
2261
|
+
else
|
|
2262
|
+
example[fieldMeta.key] = getResponseExample(fieldMeta.modelRef);
|
|
2263
|
+
});
|
|
2264
|
+
const result = arraiedModel(example, arrDepth);
|
|
2265
|
+
Reflect.defineMetadata(ref, result, ResponseExampleStorage.prototype);
|
|
2266
|
+
return result;
|
|
2267
|
+
};
|
|
2268
|
+
var RequestExampleStorage = class {
|
|
2269
|
+
};
|
|
2270
|
+
var getRequestExample = (ref) => {
|
|
2271
|
+
const existing = getPredefinedRequestExample(ref);
|
|
2272
|
+
if (existing)
|
|
2273
|
+
return existing;
|
|
2274
|
+
const fieldMetas = getFieldMetas(ref);
|
|
2275
|
+
const example = {};
|
|
2276
|
+
const isScalar = isGqlScalar(ref);
|
|
2277
|
+
if (isScalar)
|
|
2278
|
+
return getScalarExample(ref);
|
|
2279
|
+
else {
|
|
2183
2280
|
fieldMetas.forEach((fieldMeta) => {
|
|
2184
|
-
if (fieldMeta.
|
|
2185
|
-
example[fieldMeta.key] =
|
|
2186
|
-
else if (fieldMeta.enum)
|
|
2187
|
-
example[fieldMeta.key] = arraiedModel(fieldMeta.enum.values[0], fieldMeta.arrDepth);
|
|
2281
|
+
if (!fieldMeta.isScalar && fieldMeta.isClass)
|
|
2282
|
+
example[fieldMeta.key] = "ObjectID";
|
|
2188
2283
|
else
|
|
2189
|
-
example[fieldMeta.key] =
|
|
2284
|
+
example[fieldMeta.key] = fieldMeta.example ?? fieldMeta.enum ? arraiedModel(fieldMeta.example ?? (fieldMeta.enum?.values)[0], fieldMeta.optArrDepth) : arraiedModel(getRequestExample(fieldMeta.modelRef), fieldMeta.arrDepth);
|
|
2190
2285
|
});
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
const
|
|
2202
|
-
const example =
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
var makeRequestExample = (sigRef, key) => {
|
|
2218
|
-
const [argMetas] = getArgMetas(sigRef, key);
|
|
2219
|
-
return getExampleData(argMetas);
|
|
2220
|
-
};
|
|
2221
|
-
var getExampleData = (argMetas, signalType = "graphql") => Object.fromEntries(
|
|
2222
|
-
argMetas.filter((argMeta) => argMeta.type !== "Upload").map((argMeta) => {
|
|
2223
|
-
const [argRef, argArrDepth] = getNonArrayModel(argMeta.returns());
|
|
2224
|
-
const example = argMeta.argsOption.example ?? getRequestExample(argRef);
|
|
2225
|
-
return [
|
|
2226
|
-
argMeta.name,
|
|
2227
|
-
arraiedModel(
|
|
2228
|
-
signalType === "restapi" && argRef.prototype === JSON2.prototype ? JSON.stringify(example, null, 2) : example,
|
|
2229
|
-
argArrDepth
|
|
2230
|
-
)
|
|
2231
|
-
];
|
|
2232
|
-
})
|
|
2233
|
-
);
|
|
2234
|
-
var makeResponseExample = (sigRef, key) => {
|
|
2235
|
-
const gqlMeta = getGqlMeta(sigRef, key);
|
|
2236
|
-
const example = getResponseExample(gqlMeta.returns());
|
|
2237
|
-
return example;
|
|
2238
|
-
};
|
|
2286
|
+
}
|
|
2287
|
+
Reflect.defineMetadata(ref, example, RequestExampleStorage.prototype);
|
|
2288
|
+
return example;
|
|
2289
|
+
};
|
|
2290
|
+
var makeRequestExample = (sigRef, key) => {
|
|
2291
|
+
const [argMetas] = getArgMetas(sigRef, key);
|
|
2292
|
+
return getExampleData(argMetas);
|
|
2293
|
+
};
|
|
2294
|
+
var getExampleData = (argMetas, signalType = "graphql") => Object.fromEntries(
|
|
2295
|
+
argMetas.filter((argMeta) => argMeta.type !== "Upload").map((argMeta) => {
|
|
2296
|
+
const [argRef, argArrDepth] = getNonArrayModel(argMeta.returns());
|
|
2297
|
+
const example = argMeta.argsOption.example ?? getRequestExample(argRef);
|
|
2298
|
+
return [
|
|
2299
|
+
argMeta.name,
|
|
2300
|
+
arraiedModel(
|
|
2301
|
+
signalType === "restapi" && argRef.prototype === JSON2.prototype ? JSON.stringify(example, null, 2) : example,
|
|
2302
|
+
argArrDepth
|
|
2303
|
+
)
|
|
2304
|
+
];
|
|
2305
|
+
})
|
|
2306
|
+
);
|
|
2307
|
+
var makeResponseExample = (sigRef, key) => {
|
|
2308
|
+
const gqlMeta = getGqlMeta(sigRef, key);
|
|
2309
|
+
const example = getResponseExample(gqlMeta.returns());
|
|
2310
|
+
return example;
|
|
2311
|
+
};
|
|
2239
2312
|
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
})();
|
|
2313
|
+
// pkgs/@akanjs/signal/src/baseFetch.ts
|
|
2314
|
+
var nativeFetch = fetch;
|
|
2315
|
+
var baseFetch = Object.assign(nativeFetch, {
|
|
2316
|
+
client,
|
|
2317
|
+
clone: function(option = {}) {
|
|
2318
|
+
return {
|
|
2319
|
+
...this,
|
|
2320
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
2321
|
+
client: this.client.clone(option)
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
});
|
|
2253
2325
|
//! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
|
|
2254
2326
|
//! 임시 적용 테스트
|
|
2255
2327
|
//! 앱에서 다른 앱 넘어갈 때 언마운트 되버리면서 subscribe가 끊기는 일이 있음.
|