@akanjs/server 0.0.46 → 0.0.48
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 +2 -1291
- package/package.json +1 -1
- package/src/boot.js +197 -0
- package/src/controller.js +98 -0
- package/src/gql.js +145 -0
- package/src/index.js +26 -0
- package/src/module.js +246 -0
- package/src/processor.js +87 -0
- package/src/resolver.js +141 -0
- package/src/schema.js +238 -0
- package/src/searchDaemon.js +223 -0
- package/src/types.js +15 -0
- package/src/websocket.js +141 -0
package/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
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
5
|
var __copyProps = (to, from, except, desc) => {
|
|
12
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -16,1291 +10,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
10
|
}
|
|
17
11
|
return to;
|
|
18
12
|
};
|
|
19
|
-
var
|
|
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
|
-
));
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
27
14
|
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);
|
|
38
|
-
|
|
39
|
-
// pkgs/@akanjs/server/index.ts
|
|
40
15
|
var server_exports = {};
|
|
41
|
-
__export(server_exports, {
|
|
42
|
-
DateScalar: () => DateScalar,
|
|
43
|
-
SearchDaemonModule: () => SearchDaemonModule,
|
|
44
|
-
addSchema: () => addSchema,
|
|
45
|
-
applyNestField: () => applyNestField,
|
|
46
|
-
batchModuleOf: () => batchModuleOf,
|
|
47
|
-
controllerOf: () => controllerOf,
|
|
48
|
-
createNestApp: () => createNestApp,
|
|
49
|
-
databaseModuleOf: () => databaseModuleOf,
|
|
50
|
-
generateGql: () => generateGql,
|
|
51
|
-
generateGqlInput: () => generateGqlInput,
|
|
52
|
-
makeTextFilter: () => makeTextFilter,
|
|
53
|
-
processorOf: () => processorOf,
|
|
54
|
-
queueOf: () => queueOf,
|
|
55
|
-
resolverOf: () => resolverOf,
|
|
56
|
-
scalarModuleOf: () => scalarModuleOf,
|
|
57
|
-
scalarModulesOf: () => scalarModulesOf,
|
|
58
|
-
schemaOf: () => schemaOf,
|
|
59
|
-
serviceModuleOf: () => serviceModuleOf,
|
|
60
|
-
useGlobals: () => useGlobals,
|
|
61
|
-
websocketOf: () => websocketOf,
|
|
62
|
-
websocketServerOf: () => websocketServerOf
|
|
63
|
-
});
|
|
64
16
|
module.exports = __toCommonJS(server_exports);
|
|
65
|
-
|
|
66
|
-
// pkgs/@akanjs/server/src/gql.ts
|
|
67
|
-
var import_base = require("@akanjs/base");
|
|
68
|
-
var import_constant = require("@akanjs/constant");
|
|
69
|
-
var Nest = __toESM(require("@nestjs/graphql"));
|
|
70
|
-
var import_graphql = require("@nestjs/graphql");
|
|
71
|
-
var import_dayjs = require("dayjs");
|
|
72
|
-
var import_graphql2 = require("graphql");
|
|
73
|
-
var import_graphql_type_json = __toESM(require("graphql-type-json"));
|
|
74
|
-
var DateScalar = class {
|
|
75
|
-
description = "Date custom scalar type";
|
|
76
|
-
parseValue(value) {
|
|
77
|
-
return (0, import_base.dayjs)(value);
|
|
78
|
-
}
|
|
79
|
-
serialize(value) {
|
|
80
|
-
if ((0, import_dayjs.isDayjs)(value))
|
|
81
|
-
return value.toDate();
|
|
82
|
-
else
|
|
83
|
-
return new Date(value);
|
|
84
|
-
}
|
|
85
|
-
parseLiteral(ast) {
|
|
86
|
-
if (ast.kind === import_graphql2.Kind.INT)
|
|
87
|
-
return (0, import_base.dayjs)(ast.value);
|
|
88
|
-
else if (ast.kind === import_graphql2.Kind.STRING)
|
|
89
|
-
return (0, import_base.dayjs)(ast.value);
|
|
90
|
-
else
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
DateScalar = __decorateClass([
|
|
95
|
-
Nest.Scalar("Date", () => Date)
|
|
96
|
-
], DateScalar);
|
|
97
|
-
var ObjectGqlStorage = class {
|
|
98
|
-
};
|
|
99
|
-
var InputGqlStorage = class {
|
|
100
|
-
};
|
|
101
|
-
var getPredefinedInqutGql = (refName) => {
|
|
102
|
-
const inputGql = Reflect.getMetadata(refName, InputGqlStorage.prototype);
|
|
103
|
-
return inputGql;
|
|
104
|
-
};
|
|
105
|
-
var setPredefinedInqutGql = (refName, inputGql) => {
|
|
106
|
-
Reflect.defineMetadata(refName, inputGql, InputGqlStorage.prototype);
|
|
107
|
-
};
|
|
108
|
-
var getPredefinedObjectGql = (refName) => {
|
|
109
|
-
const objectGql = Reflect.getMetadata(refName, ObjectGqlStorage.prototype);
|
|
110
|
-
return objectGql;
|
|
111
|
-
};
|
|
112
|
-
var setPredefinedObjectGql = (refName, objectGql) => {
|
|
113
|
-
Reflect.defineMetadata(refName, objectGql, ObjectGqlStorage.prototype);
|
|
114
|
-
};
|
|
115
|
-
var gqlNestFieldMap = /* @__PURE__ */ new Map([
|
|
116
|
-
[import_base.ID, Nest.ID],
|
|
117
|
-
[import_base.Int, Nest.Int],
|
|
118
|
-
[import_base.Float, Nest.Float],
|
|
119
|
-
[import_base.JSON, import_graphql_type_json.default],
|
|
120
|
-
[Map, import_graphql_type_json.default]
|
|
121
|
-
]);
|
|
122
|
-
var applyNestField = (model, fieldMeta, type = "object") => {
|
|
123
|
-
if (fieldMeta.fieldType === "hidden" && type === "object")
|
|
124
|
-
return;
|
|
125
|
-
const modelRef = fieldMeta.isClass ? type === "object" ? generateGql(fieldMeta.modelRef) : fieldMeta.isScalar ? generateGqlInput(fieldMeta.modelRef) : Nest.ID : gqlNestFieldMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
|
|
126
|
-
(0, import_graphql.Field)(() => (0, import_base.arraiedModel)(modelRef, fieldMeta.arrDepth), { nullable: fieldMeta.nullable })(
|
|
127
|
-
model.prototype,
|
|
128
|
-
fieldMeta.key
|
|
129
|
-
);
|
|
130
|
-
};
|
|
131
|
-
var generateGqlInput = (inputRef) => {
|
|
132
|
-
const classMeta = (0, import_constant.getClassMeta)(inputRef);
|
|
133
|
-
const predefinedInputGql = getPredefinedInqutGql(classMeta.refName);
|
|
134
|
-
if (predefinedInputGql)
|
|
135
|
-
return predefinedInputGql;
|
|
136
|
-
const fieldMetas = (0, import_constant.getFieldMetas)(inputRef);
|
|
137
|
-
class InputGql {
|
|
138
|
-
}
|
|
139
|
-
const inputGql = classMeta.type === "scalar" ? InputGql : (0, import_constant.getInputModelRef)(classMeta.refName);
|
|
140
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
141
|
-
applyNestField(inputGql, fieldMeta, "input");
|
|
142
|
-
});
|
|
143
|
-
(0, import_graphql.InputType)(classMeta.refName + (classMeta.type === "scalar" ? "Input" : ""))(inputGql);
|
|
144
|
-
setPredefinedInqutGql(classMeta.refName, inputGql);
|
|
145
|
-
return inputGql;
|
|
146
|
-
};
|
|
147
|
-
var generateGql = (objectRef) => {
|
|
148
|
-
const classMeta = (0, import_constant.getClassMeta)(objectRef);
|
|
149
|
-
if (classMeta.type === "light") {
|
|
150
|
-
const fullModelRefName = classMeta.refName.slice(5);
|
|
151
|
-
const fullModelRef = (0, import_constant.getFullModelRef)(fullModelRefName);
|
|
152
|
-
return generateGql(fullModelRef);
|
|
153
|
-
}
|
|
154
|
-
const predefinedObjectGql = getPredefinedObjectGql(classMeta.refName);
|
|
155
|
-
if (predefinedObjectGql)
|
|
156
|
-
return predefinedObjectGql;
|
|
157
|
-
const fieldMetas = (0, import_constant.getFieldMetas)(objectRef);
|
|
158
|
-
class ObjectGql {
|
|
159
|
-
}
|
|
160
|
-
const objectGql = classMeta.type === "scalar" ? ObjectGql : (0, import_constant.getFullModelRef)(classMeta.refName);
|
|
161
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
162
|
-
applyNestField(objectGql, fieldMeta);
|
|
163
|
-
});
|
|
164
|
-
(0, import_graphql.ObjectType)(classMeta.refName)(objectGql);
|
|
165
|
-
setPredefinedObjectGql(classMeta.refName, objectGql);
|
|
166
|
-
return objectGql;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// pkgs/@akanjs/server/src/resolver.ts
|
|
170
|
-
var import_base2 = require("@akanjs/base");
|
|
171
|
-
var import_common = require("@akanjs/common");
|
|
172
|
-
var import_constant2 = require("@akanjs/constant");
|
|
173
|
-
var import_nest = require("@akanjs/nest");
|
|
174
|
-
var import_service = require("@akanjs/service");
|
|
175
|
-
var import_signal = require("@akanjs/signal");
|
|
176
|
-
var import_common2 = require("@nestjs/common");
|
|
177
|
-
var Nest2 = __toESM(require("@nestjs/graphql"));
|
|
178
|
-
var import_graphql_type_json2 = __toESM(require("graphql-type-json"));
|
|
179
|
-
var import_graphql_upload = require("graphql-upload");
|
|
180
|
-
var scalarNestReturnMap = /* @__PURE__ */ new Map([
|
|
181
|
-
[import_base2.Upload, import_graphql_upload.GraphQLUpload],
|
|
182
|
-
[import_base2.ID, Nest2.ID],
|
|
183
|
-
[import_base2.Int, Nest2.Int],
|
|
184
|
-
[import_base2.Float, Nest2.Float],
|
|
185
|
-
[import_base2.JSON, import_graphql_type_json2.default],
|
|
186
|
-
[Boolean, Boolean],
|
|
187
|
-
[Date, Date],
|
|
188
|
-
[String, String],
|
|
189
|
-
[Map, import_graphql_type_json2.default]
|
|
190
|
-
]);
|
|
191
|
-
var getNestReturn = (returns, type = "object") => {
|
|
192
|
-
const [model, arrDepth] = (0, import_base2.getNonArrayModel)(returns());
|
|
193
|
-
const modelRef = scalarNestReturnMap.get(model) ?? (type === "object" ? generateGql(model) : generateGqlInput(model));
|
|
194
|
-
return () => (0, import_base2.arraiedModel)(modelRef, arrDepth);
|
|
195
|
-
};
|
|
196
|
-
var internalArgMap = {
|
|
197
|
-
Parent: Nest2.Parent,
|
|
198
|
-
Account: import_nest.Account,
|
|
199
|
-
UserIp: import_nest.UserIp,
|
|
200
|
-
Access: import_nest.Access,
|
|
201
|
-
Self: import_nest.Self,
|
|
202
|
-
Me: import_nest.Me,
|
|
203
|
-
Req: import_nest.Req,
|
|
204
|
-
Res: import_nest.Res
|
|
205
|
-
};
|
|
206
|
-
var resolverOf = (sigRef, allSrvs) => {
|
|
207
|
-
const Rsv = (0, import_signal.copySignal)(sigRef);
|
|
208
|
-
const sigMeta = (0, import_signal.getSigMeta)(Rsv);
|
|
209
|
-
const gqlMetas = (0, import_signal.getGqlMetas)(Rsv);
|
|
210
|
-
Object.keys(allSrvs).forEach((srv) => {
|
|
211
|
-
if (!(0, import_service.isServiceEnabled)(allSrvs[srv]))
|
|
212
|
-
return;
|
|
213
|
-
(0, import_common2.Inject)(allSrvs[srv])(Rsv.prototype, (0, import_common.lowerlize)(srv));
|
|
214
|
-
});
|
|
215
|
-
for (const gqlMeta of gqlMetas) {
|
|
216
|
-
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "restapi" || !["Query", "Mutation"].includes(gqlMeta.type))
|
|
217
|
-
continue;
|
|
218
|
-
else if (gqlMeta.signalOption.sso)
|
|
219
|
-
continue;
|
|
220
|
-
const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(Rsv, gqlMeta.key);
|
|
221
|
-
const descriptor = Object.getOwnPropertyDescriptor(Rsv.prototype, gqlMeta.key) ?? {};
|
|
222
|
-
for (const argMeta of argMetas) {
|
|
223
|
-
Nest2.Args({
|
|
224
|
-
name: argMeta.name,
|
|
225
|
-
type: getNestReturn(argMeta.returns, "input"),
|
|
226
|
-
...argMeta.argsOption
|
|
227
|
-
})(Rsv.prototype, gqlMeta.key, argMeta.idx);
|
|
228
|
-
}
|
|
229
|
-
for (const internalArgMeta of internalArgMetas) {
|
|
230
|
-
const decorate = internalArgMap[internalArgMeta.type];
|
|
231
|
-
decorate(internalArgMeta.option ?? {})(Rsv.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
232
|
-
}
|
|
233
|
-
(0, import_common2.UseGuards)(...gqlMeta.guards.map((guard) => import_nest.guards[guard]))(Rsv.prototype, gqlMeta.key, descriptor);
|
|
234
|
-
if (gqlMeta.type === "Query")
|
|
235
|
-
Nest2.Query(getNestReturn(gqlMeta.returns), gqlMeta.signalOption)(Rsv.prototype, gqlMeta.key, descriptor);
|
|
236
|
-
else if (gqlMeta.type === "Mutation")
|
|
237
|
-
Nest2.Mutation(getNestReturn(gqlMeta.returns), gqlMeta.signalOption)(Rsv.prototype, gqlMeta.key, descriptor);
|
|
238
|
-
}
|
|
239
|
-
const resolveFieldMetas = (0, import_signal.getResolveFieldMetas)(Rsv);
|
|
240
|
-
if (sigMeta.returns) {
|
|
241
|
-
const modelRef = sigMeta.returns();
|
|
242
|
-
const fieldMetas = (0, import_constant2.getFieldMetas)(modelRef);
|
|
243
|
-
fieldMetas.filter((fieldMeta) => fieldMeta.isClass && !fieldMeta.isScalar).forEach((fieldMeta) => {
|
|
244
|
-
const classMeta = (0, import_constant2.getClassMeta)(fieldMeta.modelRef);
|
|
245
|
-
const modelName = (0, import_common.lowerlize)(classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName);
|
|
246
|
-
const className = (0, import_common.capitalize)(modelName);
|
|
247
|
-
const serviceName = `${modelName}Service`;
|
|
248
|
-
Rsv.prototype[fieldMeta.key] = async function(parent) {
|
|
249
|
-
const service = this[serviceName];
|
|
250
|
-
return fieldMeta.arrDepth ? await service[`load${className}Many`](parent[fieldMeta.key]) : await service[`load${className}`](parent[fieldMeta.key]);
|
|
251
|
-
};
|
|
252
|
-
Nest2.Parent()(Rsv.prototype, fieldMeta.key, 0);
|
|
253
|
-
Nest2.ResolveField(getNestReturn(() => (0, import_base2.arraiedModel)(fieldMeta.modelRef, fieldMeta.arrDepth)))(
|
|
254
|
-
Rsv.prototype,
|
|
255
|
-
fieldMeta.key,
|
|
256
|
-
Object.getOwnPropertyDescriptor(Rsv.prototype, fieldMeta.key) ?? {}
|
|
257
|
-
);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
for (const resolveFieldMeta of resolveFieldMetas) {
|
|
261
|
-
const [, internalArgMetas] = (0, import_signal.getArgMetas)(Rsv, resolveFieldMeta.key);
|
|
262
|
-
for (const internalArgMeta of internalArgMetas) {
|
|
263
|
-
const decorate = internalArgMap[internalArgMeta.type];
|
|
264
|
-
decorate(internalArgMeta.option ?? {})(Rsv.prototype, resolveFieldMeta.key, internalArgMeta.idx);
|
|
265
|
-
}
|
|
266
|
-
Nest2.ResolveField(getNestReturn(resolveFieldMeta.returns))(
|
|
267
|
-
Rsv.prototype,
|
|
268
|
-
resolveFieldMeta.key,
|
|
269
|
-
Object.getOwnPropertyDescriptor(Rsv.prototype, resolveFieldMeta.key) ?? {}
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
if (sigMeta.returns)
|
|
273
|
-
Nest2.Resolver(getNestReturn(sigMeta.returns))(Rsv);
|
|
274
|
-
else
|
|
275
|
-
Nest2.Resolver()(Rsv);
|
|
276
|
-
return Rsv;
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
// pkgs/@akanjs/server/src/controller.ts
|
|
280
|
-
var import_base3 = require("@akanjs/base");
|
|
281
|
-
var import_common3 = require("@akanjs/common");
|
|
282
|
-
var import_nest2 = require("@akanjs/nest");
|
|
283
|
-
var import_service2 = require("@akanjs/service");
|
|
284
|
-
var import_signal2 = require("@akanjs/signal");
|
|
285
|
-
var import_common4 = require("@nestjs/common");
|
|
286
|
-
var import_passport = require("@nestjs/passport");
|
|
287
|
-
var import_platform_express = require("@nestjs/platform-express");
|
|
288
|
-
var internalArgMap2 = {
|
|
289
|
-
// Parent: Nest.Parent,
|
|
290
|
-
Account: import_nest2.Account,
|
|
291
|
-
UserIp: import_nest2.UserIp,
|
|
292
|
-
Access: import_nest2.Access,
|
|
293
|
-
Self: import_nest2.Self,
|
|
294
|
-
Me: import_nest2.Me,
|
|
295
|
-
Req: import_nest2.Req,
|
|
296
|
-
Res: import_nest2.Res
|
|
297
|
-
};
|
|
298
|
-
var controllerOf = (sigRef, allSrvs) => {
|
|
299
|
-
const sigMeta = (0, import_signal2.getSigMeta)(sigRef);
|
|
300
|
-
const gqlMetas = (0, import_signal2.getGqlMetas)(sigRef);
|
|
301
|
-
const prefix = (0, import_signal2.getControllerPrefix)(sigMeta);
|
|
302
|
-
const Ctrl = (0, import_signal2.copySignal)(sigRef);
|
|
303
|
-
Object.keys(allSrvs).forEach((srv) => {
|
|
304
|
-
if (!(0, import_service2.isServiceEnabled)(allSrvs[srv]))
|
|
305
|
-
return;
|
|
306
|
-
(0, import_common4.Inject)(allSrvs[srv])(Ctrl.prototype, (0, import_common3.lowerlize)(srv));
|
|
307
|
-
});
|
|
308
|
-
for (const gqlMeta of gqlMetas) {
|
|
309
|
-
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "graphql" || !["Query", "Mutation"].includes(gqlMeta.type))
|
|
310
|
-
continue;
|
|
311
|
-
const [argMetas, internalArgMetas] = (0, import_signal2.getArgMetas)(Ctrl, gqlMeta.key);
|
|
312
|
-
internalArgMetas.forEach((internalArgMeta) => {
|
|
313
|
-
const internalDecorator = internalArgMap2[internalArgMeta.type];
|
|
314
|
-
internalDecorator(internalArgMeta.option ?? {})(Ctrl.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
315
|
-
});
|
|
316
|
-
const uploadArgMeta = argMetas.find((argMeta) => argMeta.type === "Upload");
|
|
317
|
-
if (uploadArgMeta && gqlMeta.signalOption.onlyFor === "restapi") {
|
|
318
|
-
const [modelRef, arrDepth] = (0, import_base3.getNonArrayModel)(uploadArgMeta.returns());
|
|
319
|
-
if (modelRef.prototype !== import_base3.Upload.prototype)
|
|
320
|
-
throw new Error("Upload must be Upload");
|
|
321
|
-
else if (!arrDepth)
|
|
322
|
-
throw new Error(`Only Array of Upload is allowed - ${sigMeta.refName}/${gqlMeta.key}`);
|
|
323
|
-
(0, import_common4.UseInterceptors)((0, import_platform_express.FilesInterceptor)(uploadArgMeta.name))(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
324
|
-
(0, import_common4.UploadedFiles)(import_nest2.MulterToUploadPipe)(Ctrl.prototype, gqlMeta.key, uploadArgMeta.idx);
|
|
325
|
-
}
|
|
326
|
-
const queryArgMetas = argMetas.filter((argMeta) => argMeta.type === "Query");
|
|
327
|
-
queryArgMetas.forEach((argMeta) => {
|
|
328
|
-
const [modelRef, arrDepth] = (0, import_base3.getNonArrayModel)(argMeta.returns());
|
|
329
|
-
(0, import_common4.Query)(argMeta.name, ...(0, import_nest2.getQueryPipes)(modelRef, arrDepth))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
330
|
-
});
|
|
331
|
-
const paramArgMetas = argMetas.filter((argMeta) => argMeta.type === "Param");
|
|
332
|
-
paramArgMetas.forEach((argMeta) => {
|
|
333
|
-
(0, import_common4.Param)(argMeta.name)(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
334
|
-
});
|
|
335
|
-
const path = (0, import_signal2.getControllerPath)(gqlMeta, paramArgMetas);
|
|
336
|
-
const bodyArgMetas = argMetas.filter((argMeta) => argMeta.type === "Body");
|
|
337
|
-
if (bodyArgMetas.length)
|
|
338
|
-
bodyArgMetas.forEach((argMeta) => {
|
|
339
|
-
(0, import_common4.Body)(argMeta.name, ...(0, import_nest2.getBodyPipes)(argMeta))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
340
|
-
});
|
|
341
|
-
(0, import_common4.UseGuards)(
|
|
342
|
-
...gqlMeta.guards.map((guard) => import_nest2.guards[guard]),
|
|
343
|
-
...gqlMeta.signalOption.sso ? [(0, import_passport.AuthGuard)(gqlMeta.signalOption.sso)] : []
|
|
344
|
-
)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
345
|
-
if (gqlMeta.type === "Query")
|
|
346
|
-
(0, import_common4.Get)(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
347
|
-
else if (gqlMeta.type === "Mutation")
|
|
348
|
-
(0, import_common4.Post)(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
349
|
-
}
|
|
350
|
-
if (prefix)
|
|
351
|
-
(0, import_common4.Controller)(prefix)(Ctrl);
|
|
352
|
-
else
|
|
353
|
-
(0, import_common4.Controller)()(Ctrl);
|
|
354
|
-
return Ctrl;
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
// pkgs/@akanjs/server/src/processor.ts
|
|
358
|
-
var import_common5 = require("@akanjs/common");
|
|
359
|
-
var import_service3 = require("@akanjs/service");
|
|
360
|
-
var import_signal3 = require("@akanjs/signal");
|
|
361
|
-
var import_bull = require("@nestjs/bull");
|
|
362
|
-
var import_common6 = require("@nestjs/common");
|
|
363
|
-
var convertProcessFunction = (gqlMeta, argMetas, internalArgMetas, fn) => {
|
|
364
|
-
return async function(job, done) {
|
|
365
|
-
const args = [];
|
|
366
|
-
argMetas.forEach((argMeta) => {
|
|
367
|
-
if (argMeta.type === "Msg")
|
|
368
|
-
args[argMeta.idx] = (0, import_signal3.deserializeArg)(argMeta, job.data[argMeta.idx]);
|
|
369
|
-
else
|
|
370
|
-
throw new Error(`Invalid ArgMeta Type ${argMeta.type}`);
|
|
371
|
-
});
|
|
372
|
-
internalArgMetas.forEach((internalArgMeta) => {
|
|
373
|
-
if (internalArgMeta.type === "Job")
|
|
374
|
-
args[internalArgMeta.idx] = job;
|
|
375
|
-
else
|
|
376
|
-
throw new Error(`Invalid InternalArgMeta Type ${internalArgMeta.type}`);
|
|
377
|
-
});
|
|
378
|
-
this.logger?.log(`Process-${gqlMeta.key} started`);
|
|
379
|
-
const result = await fn.apply(this, args);
|
|
380
|
-
this.logger?.log(`Process-${gqlMeta.key} finished`);
|
|
381
|
-
done(null, result);
|
|
382
|
-
};
|
|
383
|
-
};
|
|
384
|
-
var processorOf = (sigRef, allSrvs) => {
|
|
385
|
-
const sigMeta = (0, import_signal3.getSigMeta)(sigRef);
|
|
386
|
-
const serverMode = process.env.SERVER_MODE ?? "federation";
|
|
387
|
-
const gqlMetas = (0, import_signal3.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process").filter(
|
|
388
|
-
(gqlMeta) => gqlMeta.signalOption.serverType === "all" || serverMode === "all" || gqlMeta.signalOption.serverType === serverMode
|
|
389
|
-
);
|
|
390
|
-
class QueueProcessor {
|
|
391
|
-
}
|
|
392
|
-
Object.keys(allSrvs).forEach((srv) => {
|
|
393
|
-
if (!(0, import_service3.isServiceEnabled)(allSrvs[srv]))
|
|
394
|
-
return;
|
|
395
|
-
(0, import_common6.Inject)(allSrvs[srv])(QueueProcessor.prototype, (0, import_common5.lowerlize)(srv));
|
|
396
|
-
});
|
|
397
|
-
for (const gqlMeta of gqlMetas) {
|
|
398
|
-
const [argMetas, internalArgMetas] = (0, import_signal3.getArgMetas)(sigRef, gqlMeta.key);
|
|
399
|
-
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
400
|
-
descriptor.value = convertProcessFunction(
|
|
401
|
-
gqlMeta,
|
|
402
|
-
argMetas,
|
|
403
|
-
internalArgMetas,
|
|
404
|
-
descriptor.value
|
|
405
|
-
);
|
|
406
|
-
Object.defineProperty(QueueProcessor.prototype, gqlMeta.key, descriptor);
|
|
407
|
-
(0, import_bull.Process)(gqlMeta.key)(QueueProcessor.prototype, gqlMeta.key, descriptor);
|
|
408
|
-
}
|
|
409
|
-
(0, import_bull.Processor)(sigMeta.refName)(QueueProcessor);
|
|
410
|
-
return QueueProcessor;
|
|
411
|
-
};
|
|
412
|
-
var queueOf = (sigRef, queue) => {
|
|
413
|
-
const sigMeta = (0, import_signal3.getSigMeta)(sigRef);
|
|
414
|
-
const gqlMetas = (0, import_signal3.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process");
|
|
415
|
-
for (const gqlMeta of gqlMetas) {
|
|
416
|
-
if (queue[gqlMeta.key])
|
|
417
|
-
throw new Error(`Queue already has ${gqlMeta.key} in ${sigMeta.refName}`);
|
|
418
|
-
queue[gqlMeta.key] = (...args) => queue.add(gqlMeta.key, args);
|
|
419
|
-
}
|
|
420
|
-
return queue;
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
// pkgs/@akanjs/server/src/module.ts
|
|
424
|
-
var import_common10 = require("@akanjs/common");
|
|
425
|
-
var import_constant4 = require("@akanjs/constant");
|
|
426
|
-
var import_document2 = require("@akanjs/document");
|
|
427
|
-
var import_service5 = require("@akanjs/service");
|
|
428
|
-
var import_signal6 = require("@akanjs/signal");
|
|
429
|
-
var import_bull2 = require("@nestjs/bull");
|
|
430
|
-
var import_common11 = require("@nestjs/common");
|
|
431
|
-
var import_mongoose2 = require("@nestjs/mongoose");
|
|
432
|
-
|
|
433
|
-
// pkgs/@akanjs/server/src/schema.ts
|
|
434
|
-
var import_base4 = require("@akanjs/base");
|
|
435
|
-
var import_common7 = require("@akanjs/common");
|
|
436
|
-
var import_constant3 = require("@akanjs/constant");
|
|
437
|
-
var import_document = require("@akanjs/document");
|
|
438
|
-
var import_signal4 = require("@akanjs/signal");
|
|
439
|
-
var import_mongoose = require("mongoose");
|
|
440
|
-
var ScalarSchemaStorage = class {
|
|
441
|
-
};
|
|
442
|
-
var SchemaStorage = class {
|
|
443
|
-
};
|
|
444
|
-
var scalarMongoTypeMap = /* @__PURE__ */ new Map([
|
|
445
|
-
[import_base4.ID, import_document.ObjectId],
|
|
446
|
-
[import_base4.Int, Number],
|
|
447
|
-
[import_base4.Float, Number],
|
|
448
|
-
[import_base4.JSON, import_mongoose.Schema.Types.Mixed],
|
|
449
|
-
[Map, Map],
|
|
450
|
-
[String, String],
|
|
451
|
-
[Boolean, Boolean],
|
|
452
|
-
[Date, Date]
|
|
453
|
-
]);
|
|
454
|
-
var applyMongoProp = (schemaProps, fieldMeta) => {
|
|
455
|
-
if (["id", "createdAt", "updatedAt"].includes(fieldMeta.key) || fieldMeta.fieldType === "resolve")
|
|
456
|
-
return;
|
|
457
|
-
const type = fieldMeta.isClass ? fieldMeta.isScalar ? createSchema(fieldMeta.modelRef) : import_document.ObjectId : scalarMongoTypeMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
|
|
458
|
-
let prop = {};
|
|
459
|
-
if (fieldMeta.optArrDepth) {
|
|
460
|
-
prop.type = type;
|
|
461
|
-
prop.required = true;
|
|
462
|
-
if (fieldMeta.isClass && !fieldMeta.refPath)
|
|
463
|
-
prop.ref = (0, import_constant3.getClassMeta)(fieldMeta.modelRef).refName;
|
|
464
|
-
if (fieldMeta.refPath)
|
|
465
|
-
prop.refPath = fieldMeta.refPath;
|
|
466
|
-
if (typeof fieldMeta.min === "number")
|
|
467
|
-
prop.min = fieldMeta.min;
|
|
468
|
-
if (typeof fieldMeta.max === "number")
|
|
469
|
-
prop.max = fieldMeta.max;
|
|
470
|
-
if (fieldMeta.enum)
|
|
471
|
-
prop.enum = [...fieldMeta.enum.values, ...fieldMeta.nullable ? [null] : []];
|
|
472
|
-
if (typeof fieldMeta.minlength === "number")
|
|
473
|
-
prop.minlength = fieldMeta.minlength;
|
|
474
|
-
if (typeof fieldMeta.maxlength === "number")
|
|
475
|
-
prop.maxlength = fieldMeta.maxlength;
|
|
476
|
-
if (fieldMeta.validate) {
|
|
477
|
-
prop.validate = function(value) {
|
|
478
|
-
return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base4.dayjs)() : value, this) ?? true;
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
prop = { type: (0, import_base4.arraiedModel)(prop, fieldMeta.optArrDepth), default: [], required: true };
|
|
482
|
-
if (fieldMeta.modelRef.prototype === Date.prototype) {
|
|
483
|
-
prop.get = (dates) => dates.map((date) => (0, import_base4.dayjs)(date));
|
|
484
|
-
prop.set = (days) => days.map((day) => day.toDate());
|
|
485
|
-
}
|
|
486
|
-
if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base4.ID.prototype) {
|
|
487
|
-
prop.get = (ids) => ids.map((id) => id.toString());
|
|
488
|
-
prop.set = (ids) => ids.map((id) => new import_mongoose.Types.ObjectId(id));
|
|
489
|
-
}
|
|
490
|
-
} else {
|
|
491
|
-
prop.type = (0, import_base4.arraiedModel)(type, fieldMeta.arrDepth);
|
|
492
|
-
prop.required = !fieldMeta.nullable;
|
|
493
|
-
if (fieldMeta.isMap) {
|
|
494
|
-
prop.of = scalarMongoTypeMap.get(fieldMeta.of) ?? createSchema(fieldMeta.of);
|
|
495
|
-
if (!fieldMeta.default)
|
|
496
|
-
prop.default = /* @__PURE__ */ new Map();
|
|
497
|
-
}
|
|
498
|
-
if (fieldMeta.default !== null) {
|
|
499
|
-
if (typeof fieldMeta.default === "function")
|
|
500
|
-
prop.default = function() {
|
|
501
|
-
const def = fieldMeta.default(this);
|
|
502
|
-
return (0, import_common7.isDayjs)(def) ? def.toDate() : def;
|
|
503
|
-
};
|
|
504
|
-
else
|
|
505
|
-
prop.default = (0, import_common7.isDayjs)(fieldMeta.default) ? fieldMeta.default.toDate() : fieldMeta.default instanceof import_base4.Enum ? [...fieldMeta.default.values] : fieldMeta.default;
|
|
506
|
-
}
|
|
507
|
-
if (typeof fieldMeta.immutable !== "undefined")
|
|
508
|
-
prop.immutable = fieldMeta.immutable;
|
|
509
|
-
if (fieldMeta.isClass && !fieldMeta.refPath)
|
|
510
|
-
prop.ref = (0, import_constant3.getClassMeta)(fieldMeta.modelRef).refName;
|
|
511
|
-
if (fieldMeta.refPath)
|
|
512
|
-
prop.refPath = fieldMeta.refPath;
|
|
513
|
-
if (typeof fieldMeta.min === "number")
|
|
514
|
-
prop.min = fieldMeta.min;
|
|
515
|
-
if (typeof fieldMeta.max === "number")
|
|
516
|
-
prop.max = fieldMeta.max;
|
|
517
|
-
if (fieldMeta.enum)
|
|
518
|
-
prop.enum = [...fieldMeta.enum.values, ...fieldMeta.nullable ? [null] : []];
|
|
519
|
-
if (typeof fieldMeta.select === "boolean")
|
|
520
|
-
prop.select = fieldMeta.select;
|
|
521
|
-
if (typeof fieldMeta.minlength === "number")
|
|
522
|
-
prop.minlength = fieldMeta.minlength;
|
|
523
|
-
if (typeof fieldMeta.maxlength === "number")
|
|
524
|
-
prop.maxlength = fieldMeta.maxlength;
|
|
525
|
-
if (fieldMeta.nullable) {
|
|
526
|
-
prop.get = (v) => v === void 0 ? void 0 : v;
|
|
527
|
-
prop.set = (v) => v === null ? void 0 : v;
|
|
528
|
-
}
|
|
529
|
-
if (fieldMeta.modelRef.prototype === Date.prototype) {
|
|
530
|
-
prop.get = (date) => date ? (0, import_base4.dayjs)(date) : void 0;
|
|
531
|
-
prop.set = (day) => day ? (0, import_base4.dayjs)(day).toDate() : void 0;
|
|
532
|
-
}
|
|
533
|
-
if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base4.ID.prototype) {
|
|
534
|
-
prop.get = (id) => id ? id.toString() : void 0;
|
|
535
|
-
prop.set = (id) => id ? new import_mongoose.Types.ObjectId(id) : void 0;
|
|
536
|
-
}
|
|
537
|
-
if (fieldMeta.isClass && fieldMeta.isScalar && fieldMeta.default === null && !fieldMeta.nullable) {
|
|
538
|
-
prop.default = (0, import_signal4.makeDefault)(fieldMeta.modelRef);
|
|
539
|
-
}
|
|
540
|
-
if (fieldMeta.validate) {
|
|
541
|
-
prop.validate = function(value) {
|
|
542
|
-
return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base4.dayjs)() : value, this) ?? true;
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
schemaProps[fieldMeta.key] = prop;
|
|
547
|
-
};
|
|
548
|
-
var createSchema = (modelRef) => {
|
|
549
|
-
const classMeta = (0, import_constant3.getClassMeta)(modelRef);
|
|
550
|
-
const schemaMeta = Reflect.getMetadata(classMeta.refName, ScalarSchemaStorage.prototype);
|
|
551
|
-
if (schemaMeta)
|
|
552
|
-
return schemaMeta;
|
|
553
|
-
const fieldMetas = (0, import_constant3.getFieldMetas)(modelRef);
|
|
554
|
-
const schemaProps = {};
|
|
555
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
556
|
-
applyMongoProp(schemaProps, fieldMeta);
|
|
557
|
-
});
|
|
558
|
-
const schema = new import_mongoose.Schema(schemaProps);
|
|
559
|
-
Reflect.defineMetadata(classMeta.refName, schema, ScalarSchemaStorage.prototype);
|
|
560
|
-
return schema;
|
|
561
|
-
};
|
|
562
|
-
var schemaOf = (modelRef, docRef, middleware) => {
|
|
563
|
-
const classMeta = (0, import_constant3.getClassMeta)(docRef);
|
|
564
|
-
const schemaMeta = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
|
|
565
|
-
if (schemaMeta)
|
|
566
|
-
return schemaMeta;
|
|
567
|
-
const fieldMetas = (0, import_constant3.getFieldMetas)(docRef);
|
|
568
|
-
const schemaProps = {
|
|
569
|
-
createdAt: {
|
|
570
|
-
type: Date,
|
|
571
|
-
get: (date) => date ? (0, import_base4.dayjs)(date) : date,
|
|
572
|
-
set: (day) => day ? (0, import_base4.dayjs)(day).toDate() : day
|
|
573
|
-
},
|
|
574
|
-
updatedAt: {
|
|
575
|
-
type: Date,
|
|
576
|
-
get: (date) => date ? (0, import_base4.dayjs)(date) : date,
|
|
577
|
-
set: (day) => day ? (0, import_base4.dayjs)(day).toDate() : day
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
581
|
-
applyMongoProp(schemaProps, fieldMeta);
|
|
582
|
-
});
|
|
583
|
-
const schema = new import_mongoose.Schema(schemaProps, (0, import_document.getDefaultSchemaOptions)());
|
|
584
|
-
schema.methods.refresh = async function() {
|
|
585
|
-
Object.assign(this, await this.constructor.findById(this._id));
|
|
586
|
-
return this;
|
|
587
|
-
};
|
|
588
|
-
Object.getOwnPropertyNames(docRef.prototype).forEach((name) => {
|
|
589
|
-
if (name === "constructor")
|
|
590
|
-
return;
|
|
591
|
-
schema.methods[name] = Object.getOwnPropertyDescriptor(docRef.prototype, name)?.value;
|
|
592
|
-
});
|
|
593
|
-
schema.pre("save", async function(next) {
|
|
594
|
-
const model = this.constructor;
|
|
595
|
-
if (this.isNew)
|
|
596
|
-
model.addSummary(["total", this.status]);
|
|
597
|
-
else if (!!this.removedAt && this.isModified("removedAt"))
|
|
598
|
-
model.subSummary(["total", this.status]);
|
|
599
|
-
next();
|
|
600
|
-
});
|
|
601
|
-
const onSchema = Object.getOwnPropertyDescriptor(middleware.prototype, "onSchema")?.value;
|
|
602
|
-
onSchema?.(schema);
|
|
603
|
-
schema.index({ removedAt: -1 });
|
|
604
|
-
Reflect.defineMetadata(classMeta.refName, schema, SchemaStorage.prototype);
|
|
605
|
-
return schema;
|
|
606
|
-
};
|
|
607
|
-
var addSchema = (modelRef, docRef, inputRef, middleware) => {
|
|
608
|
-
const originDocClassMeta = (0, import_constant3.getClassMeta)(docRef);
|
|
609
|
-
const originInputClassMeta = (0, import_constant3.getClassMeta)(inputRef);
|
|
610
|
-
const originDoc = (0, import_constant3.getFullModelRef)(originDocClassMeta.refName);
|
|
611
|
-
const originInput = (0, import_constant3.getInputModelRef)(originInputClassMeta.refName);
|
|
612
|
-
const classMeta = (0, import_constant3.getClassMeta)(docRef);
|
|
613
|
-
const modelSchema = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
|
|
614
|
-
if (!modelSchema)
|
|
615
|
-
throw new Error(`Schema of ${classMeta.refName} not found`);
|
|
616
|
-
const fieldMetas = (0, import_constant3.getFieldMetas)(docRef);
|
|
617
|
-
const schemaProps = {
|
|
618
|
-
createdAt: {
|
|
619
|
-
type: Date,
|
|
620
|
-
get: (date) => date ? (0, import_base4.dayjs)(date) : date,
|
|
621
|
-
set: (day) => day ? (0, import_base4.dayjs)(day).toDate() : day
|
|
622
|
-
},
|
|
623
|
-
updatedAt: {
|
|
624
|
-
type: Date,
|
|
625
|
-
get: (date) => date ? (0, import_base4.dayjs)(date) : date,
|
|
626
|
-
set: (day) => day ? (0, import_base4.dayjs)(day).toDate() : day
|
|
627
|
-
}
|
|
628
|
-
};
|
|
629
|
-
fieldMetas.forEach((fieldMeta) => {
|
|
630
|
-
applyMongoProp(schemaProps, fieldMeta);
|
|
631
|
-
applyNestField(originDoc, fieldMeta);
|
|
632
|
-
});
|
|
633
|
-
const inputFieldMetas = (0, import_constant3.getFieldMetas)(inputRef);
|
|
634
|
-
inputFieldMetas.forEach((fieldMeta) => {
|
|
635
|
-
applyNestField(originInput, fieldMeta, "input");
|
|
636
|
-
});
|
|
637
|
-
const schema = new import_mongoose.Schema(schemaProps, (0, import_document.getDefaultSchemaOptions)());
|
|
638
|
-
modelSchema.add(schema);
|
|
639
|
-
Object.getOwnPropertyNames(docRef.prototype).forEach((name) => {
|
|
640
|
-
if (name === "constructor")
|
|
641
|
-
return;
|
|
642
|
-
modelSchema.methods[name] = Object.getOwnPropertyDescriptor(docRef.prototype, name)?.value;
|
|
643
|
-
});
|
|
644
|
-
const onSchema = Object.getOwnPropertyDescriptor(middleware.prototype, "onSchema")?.value;
|
|
645
|
-
onSchema?.(modelSchema);
|
|
646
|
-
return modelSchema;
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
// pkgs/@akanjs/server/src/websocket.ts
|
|
650
|
-
var import_common8 = require("@akanjs/common");
|
|
651
|
-
var import_nest3 = require("@akanjs/nest");
|
|
652
|
-
var import_service4 = require("@akanjs/service");
|
|
653
|
-
var import_signal5 = require("@akanjs/signal");
|
|
654
|
-
var import_common9 = require("@nestjs/common");
|
|
655
|
-
var import_websockets = require("@nestjs/websockets");
|
|
656
|
-
var import_operators = require("rxjs/operators");
|
|
657
|
-
var internalArgMap3 = { Account: import_nest3.Account, UserIp: import_nest3.UserIp, Access: import_nest3.Access, Self: import_nest3.Self, Me: import_nest3.Me, Ws: import_nest3.Ws };
|
|
658
|
-
var TransformInterceptor = class {
|
|
659
|
-
intercept(context, next) {
|
|
660
|
-
const [, gqlKey] = [context.getArgByIndex(1), context.getArgByIndex(3)];
|
|
661
|
-
return next.handle().pipe((0, import_operators.map)((data) => ({ event: gqlKey, data })));
|
|
662
|
-
}
|
|
663
|
-
};
|
|
664
|
-
TransformInterceptor = __decorateClass([
|
|
665
|
-
(0, import_common9.Injectable)()
|
|
666
|
-
], TransformInterceptor);
|
|
667
|
-
var makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
668
|
-
var getPubsubInterceptor = (argMetas) => {
|
|
669
|
-
let PubsubInterceptor = class {
|
|
670
|
-
async intercept(context, next) {
|
|
671
|
-
const [socket, { __subscribe__, ...body }, gqlKey] = [context.getArgByIndex(0), context.getArgByIndex(1), context.getArgByIndex(3)];
|
|
672
|
-
const roomId = makeRoomId(
|
|
673
|
-
gqlKey,
|
|
674
|
-
argMetas.map((argMeta) => body[argMeta.name])
|
|
675
|
-
);
|
|
676
|
-
if (__subscribe__)
|
|
677
|
-
await socket.join(roomId);
|
|
678
|
-
else
|
|
679
|
-
await socket.leave(roomId);
|
|
680
|
-
return next.handle().pipe((0, import_operators.map)(() => ({ event: gqlKey, data: { roomId, __subscribe__ } })));
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
PubsubInterceptor = __decorateClass([
|
|
684
|
-
(0, import_common9.Injectable)()
|
|
685
|
-
], PubsubInterceptor);
|
|
686
|
-
return PubsubInterceptor;
|
|
687
|
-
};
|
|
688
|
-
var websocketOf = (sigRef, allSrvs) => {
|
|
689
|
-
const sigMeta = (0, import_signal5.getSigMeta)(sigRef);
|
|
690
|
-
class WsGateway {
|
|
691
|
-
__sigRef__ = sigRef;
|
|
692
|
-
}
|
|
693
|
-
Object.keys(allSrvs).forEach((srv) => {
|
|
694
|
-
if (!(0, import_service4.isServiceEnabled)(allSrvs[srv]))
|
|
695
|
-
return;
|
|
696
|
-
(0, import_common9.Inject)(allSrvs[srv])(WsGateway.prototype, (0, import_common8.lowerlize)(srv));
|
|
697
|
-
});
|
|
698
|
-
const messageGqlMetas = (0, import_signal5.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
|
|
699
|
-
for (const gqlMeta of messageGqlMetas) {
|
|
700
|
-
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
701
|
-
Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
702
|
-
const [argMetas, internalArgMetas] = (0, import_signal5.getArgMetas)(sigRef, gqlMeta.key);
|
|
703
|
-
argMetas.forEach((argMeta) => {
|
|
704
|
-
if (argMeta.type !== "Msg")
|
|
705
|
-
throw new Error(`Argument of Message should be Msg ${sigMeta.refName}-${gqlMeta.key}-${argMeta.name}`);
|
|
706
|
-
(0, import_websockets.MessageBody)(argMeta.name, ...(0, import_nest3.getBodyPipes)(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
707
|
-
});
|
|
708
|
-
internalArgMetas.forEach((internalArgMeta) => {
|
|
709
|
-
const internalDecorator = internalArgMap3[internalArgMeta.type];
|
|
710
|
-
internalDecorator(internalArgMeta.option ?? {})(WsGateway.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
711
|
-
});
|
|
712
|
-
(0, import_common9.UseInterceptors)(TransformInterceptor)(WsGateway.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
713
|
-
(0, import_websockets.SubscribeMessage)(gqlMeta.key)(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
714
|
-
}
|
|
715
|
-
const pubsubGqlMetas = (0, import_signal5.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
716
|
-
for (const gqlMeta of pubsubGqlMetas) {
|
|
717
|
-
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
718
|
-
Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
719
|
-
const [argMetas, internalArgMetas] = (0, import_signal5.getArgMetas)(sigRef, gqlMeta.key);
|
|
720
|
-
argMetas.forEach((argMeta) => {
|
|
721
|
-
if (argMeta.type !== "Room")
|
|
722
|
-
throw new Error(`Argument of Message should be Room ${sigMeta.refName}-${gqlMeta.key}-${argMeta.name}`);
|
|
723
|
-
(0, import_websockets.MessageBody)(argMeta.name, ...(0, import_nest3.getBodyPipes)(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
724
|
-
});
|
|
725
|
-
internalArgMetas.forEach((internalArgMeta) => {
|
|
726
|
-
const internalDecorator = internalArgMap3[internalArgMeta.type];
|
|
727
|
-
internalDecorator(internalArgMeta.option ?? {})(WsGateway.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
728
|
-
});
|
|
729
|
-
(0, import_common9.UseInterceptors)(getPubsubInterceptor(argMetas))(WsGateway.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
730
|
-
(0, import_websockets.SubscribeMessage)(gqlMeta.key)(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
731
|
-
}
|
|
732
|
-
(0, import_websockets.WebSocketGateway)({ cors: { origin: "*" }, transports: ["websocket"] })(WsGateway);
|
|
733
|
-
return WsGateway;
|
|
734
|
-
};
|
|
735
|
-
var websocketServerOf = (sigRef) => {
|
|
736
|
-
const pubsubGqlMetas = (0, import_signal5.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
737
|
-
let Websocket = class {
|
|
738
|
-
server;
|
|
739
|
-
};
|
|
740
|
-
__decorateClass([
|
|
741
|
-
(0, import_websockets.WebSocketServer)()
|
|
742
|
-
], Websocket.prototype, "server", 2);
|
|
743
|
-
Websocket = __decorateClass([
|
|
744
|
-
(0, import_common9.Injectable)(),
|
|
745
|
-
(0, import_websockets.WebSocketGateway)({ cors: { origin: "*" }, transports: ["websocket"] })
|
|
746
|
-
], Websocket);
|
|
747
|
-
for (const gqlMeta of pubsubGqlMetas) {
|
|
748
|
-
const [argMetas] = (0, import_signal5.getArgMetas)(sigRef, gqlMeta.key);
|
|
749
|
-
Websocket.prototype[gqlMeta.key] = function(...args) {
|
|
750
|
-
const roomId = makeRoomId(
|
|
751
|
-
gqlMeta.key,
|
|
752
|
-
argMetas.map((argMeta) => args[argMeta.idx])
|
|
753
|
-
);
|
|
754
|
-
this.server.to(roomId).emit(roomId, args.at(-1));
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
return Websocket;
|
|
758
|
-
};
|
|
759
|
-
|
|
760
|
-
// pkgs/@akanjs/server/src/module.ts
|
|
761
|
-
var hasWebsocket = (signal) => (0, import_signal6.getGqlMetas)(signal).some((gqlMeta) => ["Message", "Pubsub"].includes(gqlMeta.type));
|
|
762
|
-
var hasProcessor = (signal) => (0, import_signal6.getGqlMetas)(signal).some((gqlMeta) => gqlMeta.type === "Process");
|
|
763
|
-
var filterSrvs = (srvs) => Object.fromEntries(Object.entries(srvs).filter(([_, srv]) => !!srv));
|
|
764
|
-
var databaseModuleOf = ({
|
|
765
|
-
constant,
|
|
766
|
-
database,
|
|
767
|
-
signal,
|
|
768
|
-
service,
|
|
769
|
-
uses = {},
|
|
770
|
-
useAsyncs = {},
|
|
771
|
-
providers = [],
|
|
772
|
-
extended
|
|
773
|
-
}, allSrvs) => {
|
|
774
|
-
if (!(0, import_service5.isServiceEnabled)(service))
|
|
775
|
-
return null;
|
|
776
|
-
const [modelName, className] = [(0, import_common10.lowerlize)(constant.refName), (0, import_common10.capitalize)(constant.refName)];
|
|
777
|
-
const mongoToken = (0, import_mongoose2.getModelToken)(className);
|
|
778
|
-
let DatabaseModule = class {
|
|
779
|
-
};
|
|
780
|
-
DatabaseModule = __decorateClass([
|
|
781
|
-
(0, import_common11.Global)(),
|
|
782
|
-
(0, import_common11.Module)({
|
|
783
|
-
imports: [
|
|
784
|
-
import_mongoose2.MongooseModule.forFeature([
|
|
785
|
-
{
|
|
786
|
-
name: className,
|
|
787
|
-
schema: extended ? addSchema(database.Model, database.Doc, database.Input, database.Middleware) : schemaOf(database.Model, database.Doc, database.Middleware)
|
|
788
|
-
}
|
|
789
|
-
]),
|
|
790
|
-
...hasProcessor(signal) ? [
|
|
791
|
-
import_bull2.BullModule.registerQueue({
|
|
792
|
-
name: modelName,
|
|
793
|
-
defaultJobOptions: { removeOnComplete: true, removeOnFail: true }
|
|
794
|
-
})
|
|
795
|
-
] : []
|
|
796
|
-
],
|
|
797
|
-
providers: [
|
|
798
|
-
(0, import_service5.serviceOf)(service),
|
|
799
|
-
resolverOf(signal, filterSrvs(allSrvs)),
|
|
800
|
-
...hasProcessor(signal) ? [
|
|
801
|
-
processorOf(signal, filterSrvs(allSrvs)),
|
|
802
|
-
{ provide: `${className}Queue`, useFactory: (queue) => queue, inject: [(0, import_bull2.getQueueToken)(modelName)] }
|
|
803
|
-
] : [],
|
|
804
|
-
...hasWebsocket(signal) ? [websocketOf(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: websocketServerOf(signal) }] : [],
|
|
805
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common10.capitalize)(key), useValue })),
|
|
806
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
807
|
-
{
|
|
808
|
-
provide: `${modelName}Model`,
|
|
809
|
-
useFactory: (model, redis, meili) => {
|
|
810
|
-
return (0, import_document2.databaseModelOf)(database, model, redis, meili);
|
|
811
|
-
},
|
|
812
|
-
inject: [mongoToken, "REDIS_CLIENT", "MEILI_CLIENT"]
|
|
813
|
-
},
|
|
814
|
-
...providers
|
|
815
|
-
],
|
|
816
|
-
controllers: [controllerOf(signal, filterSrvs(allSrvs))],
|
|
817
|
-
exports: [service]
|
|
818
|
-
})
|
|
819
|
-
], DatabaseModule);
|
|
820
|
-
return DatabaseModule;
|
|
821
|
-
};
|
|
822
|
-
var serviceModuleOf = ({ signal, service, uses = {}, useAsyncs = {}, providers = [] }, allSrvs) => {
|
|
823
|
-
if (!(0, import_service5.isServiceEnabled)(service))
|
|
824
|
-
return null;
|
|
825
|
-
const sigMeta = (0, import_signal6.getSigMeta)(signal);
|
|
826
|
-
const [modelName, className] = [(0, import_common10.lowerlize)(sigMeta.refName), (0, import_common10.capitalize)(sigMeta.refName)];
|
|
827
|
-
let ServiceModule = class {
|
|
828
|
-
};
|
|
829
|
-
ServiceModule = __decorateClass([
|
|
830
|
-
(0, import_common11.Global)(),
|
|
831
|
-
(0, import_common11.Module)({
|
|
832
|
-
imports: [
|
|
833
|
-
...hasProcessor(signal) ? [
|
|
834
|
-
import_bull2.BullModule.registerQueue({
|
|
835
|
-
name: modelName,
|
|
836
|
-
defaultJobOptions: { removeOnComplete: true, removeOnFail: true }
|
|
837
|
-
})
|
|
838
|
-
] : []
|
|
839
|
-
],
|
|
840
|
-
providers: [
|
|
841
|
-
(0, import_service5.serviceOf)(service),
|
|
842
|
-
resolverOf(signal, filterSrvs(allSrvs)),
|
|
843
|
-
...hasWebsocket(signal) ? [websocketOf(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: websocketServerOf(signal) }] : [],
|
|
844
|
-
...hasProcessor(signal) ? [
|
|
845
|
-
processorOf(signal, filterSrvs(allSrvs)),
|
|
846
|
-
{ provide: `${className}Queue`, useFactory: (queue) => queue, inject: [(0, import_bull2.getQueueToken)(modelName)] }
|
|
847
|
-
] : [],
|
|
848
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common10.capitalize)(key), useValue })),
|
|
849
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
850
|
-
...providers
|
|
851
|
-
],
|
|
852
|
-
controllers: [controllerOf(signal, filterSrvs(allSrvs))],
|
|
853
|
-
exports: [service]
|
|
854
|
-
})
|
|
855
|
-
], ServiceModule);
|
|
856
|
-
return ServiceModule;
|
|
857
|
-
};
|
|
858
|
-
var scalarModuleOf = ({ signals, uses = {}, useAsyncs = {}, providers = [], enabled = true }, allSrvs) => {
|
|
859
|
-
if (!enabled)
|
|
860
|
-
return null;
|
|
861
|
-
let ScalarModule = class {
|
|
862
|
-
};
|
|
863
|
-
ScalarModule = __decorateClass([
|
|
864
|
-
(0, import_common11.Global)(),
|
|
865
|
-
(0, import_common11.Module)({
|
|
866
|
-
imports: [],
|
|
867
|
-
providers: [
|
|
868
|
-
...signals.map((signal) => resolverOf(signal, filterSrvs(allSrvs))),
|
|
869
|
-
...signals.filter(hasWebsocket).map((signal) => [
|
|
870
|
-
websocketOf(signal, filterSrvs(allSrvs)),
|
|
871
|
-
{ provide: "Websocket", useClass: websocketServerOf(signal) }
|
|
872
|
-
]).flat(),
|
|
873
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common10.capitalize)(key), useValue })),
|
|
874
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
875
|
-
...providers
|
|
876
|
-
],
|
|
877
|
-
controllers: signals.map((signal) => controllerOf(signal, filterSrvs(allSrvs)))
|
|
878
|
-
})
|
|
879
|
-
], ScalarModule);
|
|
880
|
-
return ScalarModule;
|
|
881
|
-
};
|
|
882
|
-
var scalarModulesOf = ({ constants }, allSrvs) => {
|
|
883
|
-
const signals = constants.filter((modelRef) => {
|
|
884
|
-
const childRefs = (0, import_constant4.getChildClassRefs)(modelRef);
|
|
885
|
-
return childRefs.some((childRef) => {
|
|
886
|
-
const classMeta = (0, import_constant4.getClassMeta)(childRef);
|
|
887
|
-
return ["full", "light"].includes(classMeta.type);
|
|
888
|
-
});
|
|
889
|
-
}).map((modelRef) => {
|
|
890
|
-
let ScalarSignal = class extends (0, import_signal6.LogSignal)({}) {
|
|
891
|
-
};
|
|
892
|
-
ScalarSignal = __decorateClass([
|
|
893
|
-
(0, import_signal6.Signal)(() => modelRef)
|
|
894
|
-
], ScalarSignal);
|
|
895
|
-
return ScalarSignal;
|
|
896
|
-
});
|
|
897
|
-
let ScalarModule = class {
|
|
898
|
-
};
|
|
899
|
-
ScalarModule = __decorateClass([
|
|
900
|
-
(0, import_common11.Global)(),
|
|
901
|
-
(0, import_common11.Module)({
|
|
902
|
-
imports: [],
|
|
903
|
-
providers: [...signals.map((signal) => resolverOf(signal, filterSrvs(allSrvs)))]
|
|
904
|
-
// controllers: signals.map((signal) => controllerOf(signal, filterSrvs(allSrvs))),
|
|
905
|
-
})
|
|
906
|
-
], ScalarModule);
|
|
907
|
-
return ScalarModule;
|
|
908
|
-
};
|
|
909
|
-
var batchModuleOf = ({
|
|
910
|
-
service,
|
|
911
|
-
uses = {},
|
|
912
|
-
useAsyncs = {},
|
|
913
|
-
providers = []
|
|
914
|
-
}) => {
|
|
915
|
-
if (!(0, import_service5.isServiceEnabled)(service))
|
|
916
|
-
return null;
|
|
917
|
-
let BatchModule = class {
|
|
918
|
-
};
|
|
919
|
-
BatchModule = __decorateClass([
|
|
920
|
-
(0, import_common11.Global)(),
|
|
921
|
-
(0, import_common11.Module)({
|
|
922
|
-
imports: [],
|
|
923
|
-
providers: [
|
|
924
|
-
(0, import_service5.serviceOf)(service),
|
|
925
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common10.capitalize)(key), useValue })),
|
|
926
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
927
|
-
...providers
|
|
928
|
-
],
|
|
929
|
-
exports: [service]
|
|
930
|
-
})
|
|
931
|
-
], BatchModule);
|
|
932
|
-
return BatchModule;
|
|
933
|
-
};
|
|
934
|
-
var useGlobals = ({ uses, useAsyncs, injects }) => {
|
|
935
|
-
let GlobalsModule = class {
|
|
936
|
-
};
|
|
937
|
-
GlobalsModule = __decorateClass([
|
|
938
|
-
(0, import_common11.Global)(),
|
|
939
|
-
(0, import_common11.Module)({
|
|
940
|
-
imports: [],
|
|
941
|
-
providers: [
|
|
942
|
-
...Object.entries(uses ?? {}).map(([key, useValue]) => ({
|
|
943
|
-
provide: (0, import_common10.capitalize)(key),
|
|
944
|
-
useValue
|
|
945
|
-
})),
|
|
946
|
-
...Object.entries(useAsyncs ?? {}).map(([key, useFactory]) => ({ provide: (0, import_common10.capitalize)(key), useFactory })),
|
|
947
|
-
...Object.entries(injects ?? {}).map(([key, inject]) => ({ provide: (0, import_common10.capitalize)(key), useClass: inject }))
|
|
948
|
-
],
|
|
949
|
-
exports: [
|
|
950
|
-
...Object.keys(uses ?? {}).map((key) => (0, import_common10.capitalize)(key)),
|
|
951
|
-
...Object.keys(useAsyncs ?? {}).map((key) => (0, import_common10.capitalize)(key)),
|
|
952
|
-
...Object.keys(injects ?? {}).map((key) => (0, import_common10.capitalize)(key))
|
|
953
|
-
]
|
|
954
|
-
})
|
|
955
|
-
], GlobalsModule);
|
|
956
|
-
return GlobalsModule;
|
|
957
|
-
};
|
|
958
|
-
|
|
959
|
-
// pkgs/@akanjs/server/src/boot.ts
|
|
960
|
-
var import_base5 = require("@akanjs/base");
|
|
961
|
-
var import_common14 = require("@akanjs/common");
|
|
962
|
-
var import_nest4 = require("@akanjs/nest");
|
|
963
|
-
var import_signal7 = require("@akanjs/signal");
|
|
964
|
-
var import_apollo = require("@nestjs/apollo");
|
|
965
|
-
var import_bull3 = require("@nestjs/bull");
|
|
966
|
-
var import_common15 = require("@nestjs/common");
|
|
967
|
-
var import_core = require("@nestjs/core");
|
|
968
|
-
var import_graphql3 = require("@nestjs/graphql");
|
|
969
|
-
var import_mongoose4 = require("@nestjs/mongoose");
|
|
970
|
-
var import_schedule = require("@nestjs/schedule");
|
|
971
|
-
var import_body_parser = require("body-parser");
|
|
972
|
-
var import_cookie_parser = __toESM(require("cookie-parser"));
|
|
973
|
-
var import_dgram = __toESM(require("dgram"));
|
|
974
|
-
var import_events = __toESM(require("events"));
|
|
975
|
-
var import_graphql_upload2 = require("graphql-upload");
|
|
976
|
-
var import_meilisearch = require("meilisearch");
|
|
977
|
-
var import_path = require("path");
|
|
978
|
-
var import_redis = require("redis");
|
|
979
|
-
|
|
980
|
-
// pkgs/@akanjs/server/src/searchDaemon.ts
|
|
981
|
-
var import_common12 = require("@akanjs/common");
|
|
982
|
-
var import_constant5 = require("@akanjs/constant");
|
|
983
|
-
var import_document3 = require("@akanjs/document");
|
|
984
|
-
var import_common13 = require("@nestjs/common");
|
|
985
|
-
var import_mongoose3 = require("@nestjs/mongoose");
|
|
986
|
-
var hasTextField = (modelRef) => {
|
|
987
|
-
const fieldMetas = (0, import_constant5.getFieldMetas)(modelRef);
|
|
988
|
-
return fieldMetas.some(
|
|
989
|
-
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
990
|
-
);
|
|
991
|
-
};
|
|
992
|
-
var getTextFieldKeys = (modelRef) => {
|
|
993
|
-
const allSearchFields = [];
|
|
994
|
-
const allFilterFields = [];
|
|
995
|
-
const fieldMetaMap = (0, import_constant5.getFieldMetaMap)(modelRef);
|
|
996
|
-
const fieldMetas = [...fieldMetaMap.values()];
|
|
997
|
-
const stringTextFields = fieldMetas.filter((fieldMeta) => !!fieldMeta.text).map((fieldMeta) => {
|
|
998
|
-
if (fieldMeta.text === "filter")
|
|
999
|
-
allFilterFields.push(fieldMeta.key);
|
|
1000
|
-
else if (fieldMeta.text === "search")
|
|
1001
|
-
allSearchFields.push(fieldMeta.key);
|
|
1002
|
-
return fieldMeta.key;
|
|
1003
|
-
});
|
|
1004
|
-
const scalarTextFields = fieldMetas.filter(
|
|
1005
|
-
(fieldMeta) => fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
1006
|
-
).map((fieldMeta) => fieldMeta.key);
|
|
1007
|
-
const deepFields = scalarTextFields.map((key) => {
|
|
1008
|
-
const fieldMeta = fieldMetaMap.get(key);
|
|
1009
|
-
if (!fieldMeta)
|
|
1010
|
-
throw new Error(`No fieldMeta for ${key}`);
|
|
1011
|
-
const { stringTextFields: stringTextFields2, allTextFields, allSearchFields: allSearchFields2, allFilterFields: allFilterFields2 } = getTextFieldKeys(
|
|
1012
|
-
fieldMeta.modelRef
|
|
1013
|
-
);
|
|
1014
|
-
allFilterFields2.push(...allSearchFields2.map((field) => `${key}.${field}`));
|
|
1015
|
-
allSearchFields2.push(...stringTextFields2.map((field) => `${key}.${field}`));
|
|
1016
|
-
return [
|
|
1017
|
-
...stringTextFields2.map((field) => `${key}.${field}`),
|
|
1018
|
-
...allTextFields.map((field) => `${key}.${field}`)
|
|
1019
|
-
];
|
|
1020
|
-
}).flat();
|
|
1021
|
-
return {
|
|
1022
|
-
stringTextFields,
|
|
1023
|
-
scalarTextFields,
|
|
1024
|
-
allTextFields: [...stringTextFields, ...deepFields],
|
|
1025
|
-
allSearchFields,
|
|
1026
|
-
allFilterFields
|
|
1027
|
-
};
|
|
1028
|
-
};
|
|
1029
|
-
var makeTextFilter = (modelRef) => {
|
|
1030
|
-
const fieldMetaMap = (0, import_constant5.getFieldMetaMap)(modelRef);
|
|
1031
|
-
const { stringTextFields, scalarTextFields } = getTextFieldKeys(modelRef);
|
|
1032
|
-
const filterData = (data, assignObj = {}) => {
|
|
1033
|
-
if (Array.isArray(data))
|
|
1034
|
-
return data.map((d) => filterData(d));
|
|
1035
|
-
return Object.assign(
|
|
1036
|
-
Object.fromEntries([
|
|
1037
|
-
...stringTextFields.map((key) => [key, data[key]]),
|
|
1038
|
-
...scalarTextFields.map((key) => {
|
|
1039
|
-
const fieldMeta = fieldMetaMap.get(key);
|
|
1040
|
-
if (!fieldMeta)
|
|
1041
|
-
throw new Error(`No fieldMeta for ${key}`);
|
|
1042
|
-
const filterFunc = makeTextFilter(fieldMeta.modelRef);
|
|
1043
|
-
return [key, filterFunc(data[key])];
|
|
1044
|
-
})
|
|
1045
|
-
]),
|
|
1046
|
-
assignObj
|
|
1047
|
-
);
|
|
1048
|
-
};
|
|
1049
|
-
return filterData;
|
|
1050
|
-
};
|
|
1051
|
-
var getSortableAttributes = (refName) => {
|
|
1052
|
-
const cnst = (0, import_constant5.getCnstMeta)(refName);
|
|
1053
|
-
const sortMap = (0, import_constant5.getFilterSortMap)(cnst.Filter);
|
|
1054
|
-
const sortFields = Object.values(sortMap).filter((val) => typeof val === "object").map((sort) => Object.keys(sort)).flat();
|
|
1055
|
-
return [...new Set(sortFields)];
|
|
1056
|
-
};
|
|
1057
|
-
var SearchDaemon = class {
|
|
1058
|
-
constructor(connection, meili) {
|
|
1059
|
-
this.connection = connection;
|
|
1060
|
-
this.meili = meili;
|
|
1061
|
-
}
|
|
1062
|
-
logger = new import_common12.Logger("SearchDaemon");
|
|
1063
|
-
async onModuleInit() {
|
|
1064
|
-
const databaseModelNames = (0, import_document3.getAllDatabaseModelNames)();
|
|
1065
|
-
const indexes = (await this.meili.getIndexes({ limit: 1e3 })).results;
|
|
1066
|
-
const indexMap = new Map(indexes.map((index) => [index.uid, index]));
|
|
1067
|
-
const indexCreationNames = [];
|
|
1068
|
-
const indexUpdateNames = [];
|
|
1069
|
-
for (const modelName of databaseModelNames) {
|
|
1070
|
-
const indexName = (0, import_common12.lowerlize)(modelName);
|
|
1071
|
-
const modelRef = (0, import_constant5.getFullModelRef)(modelName);
|
|
1072
|
-
if (!hasTextField(modelRef))
|
|
1073
|
-
continue;
|
|
1074
|
-
const index = indexMap.get(indexName);
|
|
1075
|
-
if (!index)
|
|
1076
|
-
indexCreationNames.push(indexName);
|
|
1077
|
-
else if (index.primaryKey !== "id")
|
|
1078
|
-
indexUpdateNames.push(indexName);
|
|
1079
|
-
}
|
|
1080
|
-
for (const indexName of indexCreationNames)
|
|
1081
|
-
await this.meili.createIndex(indexName, { primaryKey: "id" });
|
|
1082
|
-
for (const indexName of indexUpdateNames)
|
|
1083
|
-
await this.meili.updateIndex(indexName, { primaryKey: "id" });
|
|
1084
|
-
for (const modelName of databaseModelNames) {
|
|
1085
|
-
const indexName = (0, import_common12.lowerlize)(modelName);
|
|
1086
|
-
const model = this.connection.models[modelName];
|
|
1087
|
-
const modelRef = (0, import_constant5.getFullModelRef)(modelName);
|
|
1088
|
-
if (!hasTextField(modelRef))
|
|
1089
|
-
continue;
|
|
1090
|
-
const searchIndex = this.meili.index(indexName);
|
|
1091
|
-
const { stringTextFields, scalarTextFields, allSearchFields, allFilterFields } = getTextFieldKeys(modelRef);
|
|
1092
|
-
const settings = await searchIndex.getSettings();
|
|
1093
|
-
const allSearchFieldSet = new Set(allSearchFields);
|
|
1094
|
-
const allFilterFieldSet = new Set(allFilterFields);
|
|
1095
|
-
const searchFieldSet = new Set(settings.searchableAttributes);
|
|
1096
|
-
const filterFieldSet = new Set(settings.filterableAttributes);
|
|
1097
|
-
const needUpdateSetting = !allSearchFields.every((field) => searchFieldSet.has(field)) || !allFilterFields.every((field) => filterFieldSet.has(field)) || !settings.searchableAttributes?.every((field) => allSearchFieldSet.has(field)) || !settings.filterableAttributes?.every((field) => allFilterFieldSet.has(field));
|
|
1098
|
-
if (needUpdateSetting) {
|
|
1099
|
-
this.logger.info(`update index settings (${modelName})`);
|
|
1100
|
-
await searchIndex.updateSettings({
|
|
1101
|
-
searchableAttributes: allSearchFields,
|
|
1102
|
-
filterableAttributes: allFilterFields,
|
|
1103
|
-
sortableAttributes: getSortableAttributes(indexName)
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
const stringTextFieldSet = new Set(stringTextFields);
|
|
1107
|
-
const scalarTextFieldSet = new Set(scalarTextFields);
|
|
1108
|
-
const filterText = makeTextFilter(modelRef);
|
|
1109
|
-
model.watch().on("change", async (data) => {
|
|
1110
|
-
try {
|
|
1111
|
-
const id = data.documentKey._id.toString();
|
|
1112
|
-
if (data.operationType === "delete") {
|
|
1113
|
-
this.logger.trace(`delete text doc (${modelName}): ${id}`);
|
|
1114
|
-
return await searchIndex.deleteDocument(id);
|
|
1115
|
-
} else if (data.operationType === "insert") {
|
|
1116
|
-
this.logger.trace(`insert text doc (${modelName}): ${data.documentKey._id}`);
|
|
1117
|
-
if (!data.fullDocument)
|
|
1118
|
-
throw new Error("No fullDocument");
|
|
1119
|
-
const textFilteredData = filterText(data.fullDocument);
|
|
1120
|
-
return await searchIndex.addDocuments([textFilteredData]);
|
|
1121
|
-
} else if (data.operationType === "update") {
|
|
1122
|
-
const updatedFields = data.updateDescription?.updatedFields ?? {};
|
|
1123
|
-
const isRemoved = !!updatedFields.removedAt;
|
|
1124
|
-
if (isRemoved) {
|
|
1125
|
-
this.logger.trace(`remove text doc (${modelName}): ${id}`);
|
|
1126
|
-
return await searchIndex.deleteDocument(id);
|
|
1127
|
-
}
|
|
1128
|
-
this.logger.trace(`update text doc (${modelName}): ${data.documentKey._id}`);
|
|
1129
|
-
const updatedFieldKeys = Object.keys(updatedFields);
|
|
1130
|
-
const removedFieldKeys = data.updateDescription?.removedFields ?? [];
|
|
1131
|
-
const isScalarTextFieldUpdated = [...updatedFieldKeys, ...removedFieldKeys].map((key) => key.split(".")[0]).some((key) => scalarTextFieldSet.has(key));
|
|
1132
|
-
if (isScalarTextFieldUpdated) {
|
|
1133
|
-
const doc = await model.findById(data.documentKey._id);
|
|
1134
|
-
if (!doc)
|
|
1135
|
-
this.logger.error(`No doc for ${data.documentKey._id}`);
|
|
1136
|
-
const textFilteredData = filterText(doc, { id });
|
|
1137
|
-
return await searchIndex.updateDocuments([textFilteredData]);
|
|
1138
|
-
} else {
|
|
1139
|
-
const updateKeys = updatedFieldKeys.filter((key) => stringTextFieldSet.has(key));
|
|
1140
|
-
const removeKeys = removedFieldKeys.filter((key) => stringTextFieldSet.has(key));
|
|
1141
|
-
if (!updateKeys.length && !removeKeys.length)
|
|
1142
|
-
return;
|
|
1143
|
-
const textFilteredData = Object.fromEntries([
|
|
1144
|
-
["id", id],
|
|
1145
|
-
...updateKeys.map((key) => [key, updatedFields[key]]),
|
|
1146
|
-
...removeKeys.map((key) => [key, null])
|
|
1147
|
-
]);
|
|
1148
|
-
return await searchIndex.updateDocuments([textFilteredData]);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
} catch (e) {
|
|
1152
|
-
this.logger.error(e);
|
|
1153
|
-
}
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
};
|
|
1158
|
-
SearchDaemon = __decorateClass([
|
|
1159
|
-
(0, import_common13.Injectable)(),
|
|
1160
|
-
__decorateParam(0, (0, import_mongoose3.InjectConnection)()),
|
|
1161
|
-
__decorateParam(1, (0, import_common13.Inject)("MEILI_CLIENT"))
|
|
1162
|
-
], SearchDaemon);
|
|
1163
|
-
var SearchDaemonModule = class {
|
|
1164
|
-
};
|
|
1165
|
-
SearchDaemonModule = __decorateClass([
|
|
1166
|
-
(0, import_common13.Global)(),
|
|
1167
|
-
(0, import_common13.Module)({
|
|
1168
|
-
providers: [SearchDaemon]
|
|
1169
|
-
})
|
|
1170
|
-
], SearchDaemonModule);
|
|
1171
|
-
|
|
1172
|
-
// pkgs/@akanjs/server/src/boot.ts
|
|
1173
|
-
var createNestApp = async ({ registerModules, serverMode = "federation", env, log = true }) => {
|
|
1174
|
-
const backendLogger = new import_common14.Logger("Backend");
|
|
1175
|
-
if (log)
|
|
1176
|
-
backendLogger.rawLog(import_base5.logo);
|
|
1177
|
-
const jwtSecret = (0, import_nest4.generateJwtSecret)(env.appName, env.environment);
|
|
1178
|
-
const [redisUri, mongoUri, meiliUri] = await Promise.all([
|
|
1179
|
-
env.redisUri ?? (0, import_nest4.generateRedisUri)({ ...env, ...env.redis?.sshOptions ? { sshOptions: env.redis.sshOptions } : {} }),
|
|
1180
|
-
env.mongoUri ?? (0, import_nest4.generateMongoUri)({
|
|
1181
|
-
...env,
|
|
1182
|
-
...env.mongo.username ? { username: env.mongo.username } : {},
|
|
1183
|
-
password: env.mongo.password,
|
|
1184
|
-
...env.mongo.sshOptions ? { sshOptions: env.mongo.sshOptions } : {}
|
|
1185
|
-
}),
|
|
1186
|
-
env.meiliUri ?? (0, import_nest4.generateMeiliUri)(env)
|
|
1187
|
-
]);
|
|
1188
|
-
if (env.operationMode === "local") {
|
|
1189
|
-
backendLogger.verbose(`connect to redis: ${redisUri}`);
|
|
1190
|
-
backendLogger.verbose(`connect to mongo: ${mongoUri}`);
|
|
1191
|
-
backendLogger.verbose(`connect to meili: ${meiliUri}`);
|
|
1192
|
-
}
|
|
1193
|
-
(0, import_nest4.initMongoDB)({ logging: import_base5.baseEnv.environment !== "main", sendReport: false });
|
|
1194
|
-
import_events.default.EventEmitter.defaultMaxListeners = 1e3;
|
|
1195
|
-
let AuthMiddleWare = class {
|
|
1196
|
-
use(req, res, next) {
|
|
1197
|
-
const requestHeader = req;
|
|
1198
|
-
requestHeader.account = (0, import_nest4.verifyToken)(
|
|
1199
|
-
jwtSecret,
|
|
1200
|
-
requestHeader.headers.authorization ?? (requestHeader.cookies?.jwt ? `Bearer ${requestHeader.cookies.jwt}` : void 0)
|
|
1201
|
-
);
|
|
1202
|
-
requestHeader.userAgent = requestHeader["user-agent"];
|
|
1203
|
-
next();
|
|
1204
|
-
}
|
|
1205
|
-
};
|
|
1206
|
-
AuthMiddleWare = __decorateClass([
|
|
1207
|
-
(0, import_common15.Injectable)()
|
|
1208
|
-
], AuthMiddleWare);
|
|
1209
|
-
const redisClient = await (0, import_redis.createClient)({ url: redisUri }).connect();
|
|
1210
|
-
let SubDatabaseModule = class {
|
|
1211
|
-
};
|
|
1212
|
-
SubDatabaseModule = __decorateClass([
|
|
1213
|
-
(0, import_common15.Global)(),
|
|
1214
|
-
(0, import_common15.Module)({
|
|
1215
|
-
providers: [
|
|
1216
|
-
{ provide: "REDIS_CLIENT", useValue: redisClient },
|
|
1217
|
-
{
|
|
1218
|
-
provide: "MEILI_CLIENT",
|
|
1219
|
-
useFactory: () => new import_meilisearch.MeiliSearch({ host: meiliUri, apiKey: (0, import_nest4.generateMeiliKey)(env) })
|
|
1220
|
-
}
|
|
1221
|
-
],
|
|
1222
|
-
exports: ["REDIS_CLIENT", "MEILI_CLIENT"]
|
|
1223
|
-
})
|
|
1224
|
-
], SubDatabaseModule);
|
|
1225
|
-
let AppModule = class {
|
|
1226
|
-
configure(consumer) {
|
|
1227
|
-
consumer.apply(AuthMiddleWare).forRoutes({ path: "*", method: import_common15.RequestMethod.ALL });
|
|
1228
|
-
}
|
|
1229
|
-
};
|
|
1230
|
-
AppModule = __decorateClass([
|
|
1231
|
-
(0, import_common15.Module)({
|
|
1232
|
-
imports: [
|
|
1233
|
-
import_bull3.BullModule.forRoot({ redis: redisUri }),
|
|
1234
|
-
import_schedule.ScheduleModule.forRoot(),
|
|
1235
|
-
import_graphql3.GraphQLModule.forRootAsync({
|
|
1236
|
-
imports: [],
|
|
1237
|
-
useFactory: () => ({
|
|
1238
|
-
useGlobalPrefix: true,
|
|
1239
|
-
autoSchemaFile: (0, import_path.join)(process.cwd(), "src/schema.gql"),
|
|
1240
|
-
sortSchema: true,
|
|
1241
|
-
playground: import_base5.baseEnv.environment !== "main",
|
|
1242
|
-
introspection: import_base5.baseEnv.environment !== "main",
|
|
1243
|
-
uploads: false,
|
|
1244
|
-
debug: false
|
|
1245
|
-
}),
|
|
1246
|
-
driver: import_apollo.ApolloDriver
|
|
1247
|
-
}),
|
|
1248
|
-
import_mongoose4.MongooseModule.forRootAsync({
|
|
1249
|
-
useFactory: () => ({ uri: mongoUri, autoIndex: import_base5.baseEnv.environment !== "main" })
|
|
1250
|
-
}),
|
|
1251
|
-
SubDatabaseModule,
|
|
1252
|
-
useGlobals({
|
|
1253
|
-
injects: { SearchClient: import_nest4.SearchClient, DatabaseClient: import_nest4.DatabaseClient, CacheClient: import_nest4.CacheClient }
|
|
1254
|
-
}),
|
|
1255
|
-
...["batch", "all"].includes(serverMode) && import_base5.baseEnv.operationMode !== "edge" ? [SearchDaemonModule] : [],
|
|
1256
|
-
...registerModules(env).filter((m) => !!m)
|
|
1257
|
-
],
|
|
1258
|
-
providers: [DateScalar]
|
|
1259
|
-
})
|
|
1260
|
-
], AppModule);
|
|
1261
|
-
const app = await import_core.NestFactory.create(AppModule, { logger: backendLogger });
|
|
1262
|
-
const redisIoAdapter = new import_nest4.RedisIoAdapter(app, { jwtSecret });
|
|
1263
|
-
await redisIoAdapter.connectToRedis(redisUri);
|
|
1264
|
-
app.enableShutdownHooks();
|
|
1265
|
-
const udp = import_dgram.default.createSocket("udp4");
|
|
1266
|
-
import_signal7.client.setUdp(udp);
|
|
1267
|
-
if (["federation", "all"].includes(serverMode)) {
|
|
1268
|
-
app.setGlobalPrefix(process.env.GLOBAL_PREFIX ?? "/backend");
|
|
1269
|
-
app.enableCors({
|
|
1270
|
-
origin: "*",
|
|
1271
|
-
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
|
|
1272
|
-
preflightContinue: false,
|
|
1273
|
-
optionsSuccessStatus: 204,
|
|
1274
|
-
allowedHeaders: "DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,apollo-require-preflight"
|
|
1275
|
-
});
|
|
1276
|
-
if (env.operationMode !== "local" && process.env.USE_REDIS_IO_ADAPTER !== "false")
|
|
1277
|
-
app.useWebSocketAdapter(redisIoAdapter);
|
|
1278
|
-
app.use((0, import_body_parser.json)({ limit: "100mb" }));
|
|
1279
|
-
app.use((0, import_body_parser.urlencoded)({ limit: "100mb", extended: true }));
|
|
1280
|
-
app.use("/backend/graphql", (0, import_graphql_upload2.graphqlUploadExpress)());
|
|
1281
|
-
app.use((0, import_cookie_parser.default)());
|
|
1282
|
-
app.useGlobalInterceptors(new import_nest4.LoggingInterceptor());
|
|
1283
|
-
app.useGlobalInterceptors(new import_nest4.TimeoutInterceptor());
|
|
1284
|
-
app.useGlobalInterceptors(new import_nest4.CacheInterceptor(redisClient));
|
|
1285
|
-
app.useGlobalFilters(new import_nest4.AllExceptionsFilter());
|
|
1286
|
-
await app.listen(process.env.PORT ?? env.port ?? 8080);
|
|
1287
|
-
backendLogger.log(`\u{1F680} Server is running on: ${await app.getUrl()}`);
|
|
1288
|
-
} else {
|
|
1289
|
-
await app.init();
|
|
1290
|
-
backendLogger.log(`\u{1F680} Batch Server is running`);
|
|
1291
|
-
}
|
|
1292
|
-
if (module.hot) {
|
|
1293
|
-
module.hot.accept();
|
|
1294
|
-
module.hot.dispose(() => {
|
|
1295
|
-
void app.close();
|
|
1296
|
-
});
|
|
1297
|
-
}
|
|
1298
|
-
return {
|
|
1299
|
-
nestApp: app,
|
|
1300
|
-
close: async () => {
|
|
1301
|
-
await app.close();
|
|
1302
|
-
await redisIoAdapter.destroy();
|
|
1303
|
-
await redisClient.quit();
|
|
1304
|
-
}
|
|
1305
|
-
};
|
|
1306
|
-
};
|
|
17
|
+
__reExport(server_exports, require("./src"), module.exports);
|