@akanjs/server 0.9.41 → 0.9.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/src/base.module.js +1 -2
- package/cjs/src/boot.js +10 -7
- package/cjs/src/controller.js +4 -3
- package/cjs/src/module.js +42 -92
- package/cjs/src/processor.js +16 -12
- package/cjs/src/resolver.js +4 -3
- package/cjs/src/schedule.js +231 -0
- package/cjs/src/schema.js +37 -12
- package/cjs/src/searchDaemon.js +1 -3
- package/cjs/src/websocket.js +14 -21
- package/esm/src/base.module.js +1 -2
- package/esm/src/boot.js +10 -7
- package/esm/src/controller.js +5 -4
- package/esm/src/module.js +49 -97
- package/esm/src/processor.js +16 -12
- package/esm/src/resolver.js +5 -4
- package/esm/src/schedule.js +210 -0
- package/esm/src/schema.js +46 -13
- package/esm/src/searchDaemon.js +1 -3
- package/esm/src/websocket.js +13 -20
- package/package.json +2 -1
- package/src/module.d.ts +5 -44
- package/src/processor.d.ts +1 -2
- package/src/schedule.d.ts +4 -0
- package/src/schema.d.ts +1 -0
- package/src/websocket.d.ts +3 -5
package/cjs/src/base.module.js
CHANGED
|
@@ -27,8 +27,7 @@ const registerBaseModule = (option) => {
|
|
|
27
27
|
return (0, import_module.serviceModuleOf)(
|
|
28
28
|
{
|
|
29
29
|
signal: import_signal.BaseSignal,
|
|
30
|
-
service: import_service.BaseService
|
|
31
|
-
uses: { onCleanup: option.onCleanup }
|
|
30
|
+
service: import_service.BaseService
|
|
32
31
|
},
|
|
33
32
|
import_service.allSrvs
|
|
34
33
|
);
|
package/cjs/src/boot.js
CHANGED
|
@@ -60,6 +60,7 @@ var import_redis = require("redis");
|
|
|
60
60
|
var import_base2 = require("./base.module");
|
|
61
61
|
var import_gql = require("./gql");
|
|
62
62
|
var import_module = require("./module");
|
|
63
|
+
var import_schedule2 = require("./schedule");
|
|
63
64
|
var import_searchDaemon = require("./searchDaemon");
|
|
64
65
|
const createNestApp = async ({ registerModules, serverMode = "federation", env, log = true }) => {
|
|
65
66
|
const backendLogger = new import_common.Logger("Backend");
|
|
@@ -98,9 +99,9 @@ const createNestApp = async ({ registerModules, serverMode = "federation", env,
|
|
|
98
99
|
(0, import_common2.Injectable)()
|
|
99
100
|
], AuthMiddleWare);
|
|
100
101
|
const redisClient = await (0, import_redis.createClient)({ url: redisUri }).connect();
|
|
101
|
-
let
|
|
102
|
+
let GlobalProvideModule = class {
|
|
102
103
|
};
|
|
103
|
-
|
|
104
|
+
GlobalProvideModule = __decorateClass([
|
|
104
105
|
(0, import_common2.Global)(),
|
|
105
106
|
(0, import_common2.Module)({
|
|
106
107
|
providers: [
|
|
@@ -108,11 +109,12 @@ const createNestApp = async ({ registerModules, serverMode = "federation", env,
|
|
|
108
109
|
{
|
|
109
110
|
provide: "MEILI_CLIENT",
|
|
110
111
|
useFactory: () => new import_meilisearch.MeiliSearch({ host: meiliUri, apiKey: (0, import_nest.generateMeiliKey)(env) })
|
|
111
|
-
}
|
|
112
|
+
},
|
|
113
|
+
{ provide: "GLOBAL_ENV", useValue: env }
|
|
112
114
|
],
|
|
113
|
-
exports: ["REDIS_CLIENT", "MEILI_CLIENT"]
|
|
115
|
+
exports: ["REDIS_CLIENT", "MEILI_CLIENT", "GLOBAL_ENV"]
|
|
114
116
|
})
|
|
115
|
-
],
|
|
117
|
+
], GlobalProvideModule);
|
|
116
118
|
let AppModule = class {
|
|
117
119
|
configure(consumer) {
|
|
118
120
|
consumer.apply(AuthMiddleWare).forRoutes({ path: "*", method: import_common2.RequestMethod.ALL });
|
|
@@ -139,12 +141,13 @@ const createNestApp = async ({ registerModules, serverMode = "federation", env,
|
|
|
139
141
|
import_mongoose.MongooseModule.forRootAsync({
|
|
140
142
|
useFactory: () => ({ uri: mongoUri, autoIndex: import_base.baseEnv.environment !== "main" })
|
|
141
143
|
}),
|
|
142
|
-
|
|
144
|
+
GlobalProvideModule,
|
|
143
145
|
(0, import_module.useGlobals)({
|
|
144
146
|
injects: { SearchClient: import_nest.SearchClient, DatabaseClient: import_nest.DatabaseClient, CacheClient: import_nest.CacheClient }
|
|
145
147
|
}),
|
|
146
148
|
...["batch", "all"].includes(serverMode) && import_base.baseEnv.operationMode !== "edge" ? [import_searchDaemon.SearchDaemonModule] : [],
|
|
147
|
-
...[(0, import_base2.registerBaseModule)(env), ...registerModules(env)].filter((m) => !!m)
|
|
149
|
+
...[(0, import_base2.registerBaseModule)(env), ...registerModules(env)].filter((m) => !!m),
|
|
150
|
+
(0, import_schedule2.makeScheduleModule)(serverMode, env)
|
|
148
151
|
],
|
|
149
152
|
providers: [import_gql.DateScalar]
|
|
150
153
|
})
|
package/cjs/src/controller.js
CHANGED
|
@@ -43,10 +43,11 @@ const controllerOf = (sigRef, allSrvs) => {
|
|
|
43
43
|
const gqlMetas = (0, import_signal.getGqlMetas)(sigRef);
|
|
44
44
|
const prefix = (0, import_signal.getControllerPrefix)(sigMeta);
|
|
45
45
|
const Ctrl = (0, import_signal.copySignal)(sigRef);
|
|
46
|
-
Object.keys(allSrvs).forEach((
|
|
47
|
-
if (!(0, import_service.isServiceEnabled)(allSrvs[
|
|
46
|
+
Object.keys(allSrvs).forEach((srvName) => {
|
|
47
|
+
if (!(0, import_service.isServiceEnabled)(allSrvs[srvName]))
|
|
48
48
|
return;
|
|
49
|
-
|
|
49
|
+
const srvRef = (0, import_service.getServiceRefs)(srvName)[0];
|
|
50
|
+
(0, import_common2.Inject)(srvRef)(Ctrl.prototype, (0, import_common.lowerlize)(srvName));
|
|
50
51
|
});
|
|
51
52
|
for (const gqlMeta of gqlMetas) {
|
|
52
53
|
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "graphql" || !["Query", "Mutation"].includes(gqlMeta.type))
|
package/cjs/src/module.js
CHANGED
|
@@ -26,9 +26,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
26
26
|
};
|
|
27
27
|
var module_exports = {};
|
|
28
28
|
__export(module_exports, {
|
|
29
|
-
batchModuleOf: () => batchModuleOf,
|
|
30
29
|
databaseModuleOf: () => databaseModuleOf,
|
|
31
|
-
scalarModuleOf: () => scalarModuleOf,
|
|
32
30
|
scalarModulesOf: () => scalarModulesOf,
|
|
33
31
|
serviceModuleOf: () => serviceModuleOf,
|
|
34
32
|
useGlobals: () => useGlobals
|
|
@@ -50,20 +48,12 @@ var import_websocket = require("./websocket");
|
|
|
50
48
|
const hasWebsocket = (signal) => (0, import_signal.getGqlMetas)(signal).some((gqlMeta) => ["Message", "Pubsub"].includes(gqlMeta.type));
|
|
51
49
|
const hasProcessor = (signal) => (0, import_signal.getGqlMetas)(signal).some((gqlMeta) => gqlMeta.type === "Process");
|
|
52
50
|
const filterSrvs = (srvs) => Object.fromEntries(Object.entries(srvs).filter(([_, srv]) => !!srv));
|
|
53
|
-
const databaseModuleOf = ({
|
|
54
|
-
constant,
|
|
55
|
-
database,
|
|
56
|
-
signal,
|
|
57
|
-
service,
|
|
58
|
-
uses = {},
|
|
59
|
-
useAsyncs = {},
|
|
60
|
-
providers = [],
|
|
61
|
-
extended
|
|
62
|
-
}, allSrvs) => {
|
|
51
|
+
const databaseModuleOf = ({ constant, database, signal, service }, allSrvs) => {
|
|
63
52
|
if (!(0, import_service.isServiceEnabled)(service))
|
|
64
53
|
return null;
|
|
65
54
|
const [modelName, className] = [(0, import_common.lowerlize)(constant.refName), (0, import_common.capitalize)(constant.refName)];
|
|
66
55
|
const mongoToken = (0, import_mongoose.getModelToken)(className);
|
|
56
|
+
const srvRef = (0, import_service.serviceOf)(service);
|
|
67
57
|
let DatabaseModule = class {
|
|
68
58
|
};
|
|
69
59
|
DatabaseModule = __decorateClass([
|
|
@@ -73,7 +63,7 @@ const databaseModuleOf = ({
|
|
|
73
63
|
import_mongoose.MongooseModule.forFeature([
|
|
74
64
|
{
|
|
75
65
|
name: className,
|
|
76
|
-
schema:
|
|
66
|
+
schema: (0, import_schema.hasSchema)(constant.Full) ? (0, import_schema.addSchema)(database.Model, database.Doc, database.Input, database.Middleware) : (0, import_schema.schemaOf)(database.Model, database.Doc, database.Middleware)
|
|
77
67
|
}
|
|
78
68
|
]),
|
|
79
69
|
...hasProcessor(signal) ? [
|
|
@@ -84,15 +74,11 @@ const databaseModuleOf = ({
|
|
|
84
74
|
] : []
|
|
85
75
|
],
|
|
86
76
|
providers: [
|
|
87
|
-
|
|
77
|
+
...service === srvRef ? [srvRef] : [],
|
|
88
78
|
(0, import_resolver.resolverOf)(signal, filterSrvs(allSrvs)),
|
|
89
|
-
...
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
] : [],
|
|
93
|
-
...hasWebsocket(signal) ? [(0, import_websocket.websocketOf)(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: (0, import_websocket.websocketServerOf)(signal) }] : [],
|
|
94
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common.capitalize)(key), useValue })),
|
|
95
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
79
|
+
...hasWebsocket(signal) ? [(0, import_websocket.websocketOf)(signal, filterSrvs(allSrvs))] : [],
|
|
80
|
+
...hasProcessor(signal) ? [(0, import_processor.processorOf)(signal, filterSrvs(allSrvs))] : [],
|
|
81
|
+
{ provide: `${className}Signal`, useClass: makeSigForSrv(signal) },
|
|
96
82
|
{
|
|
97
83
|
provide: `${modelName}Model`,
|
|
98
84
|
useFactory: (model, redis, meili) => {
|
|
@@ -100,74 +86,52 @@ const databaseModuleOf = ({
|
|
|
100
86
|
},
|
|
101
87
|
inject: [mongoToken, "REDIS_CLIENT", "MEILI_CLIENT"]
|
|
102
88
|
},
|
|
103
|
-
...
|
|
89
|
+
...(0, import_service.makeProvidersForSrv)(srvRef)
|
|
104
90
|
],
|
|
105
91
|
controllers: [(0, import_controller.controllerOf)(signal, filterSrvs(allSrvs))],
|
|
106
|
-
exports: [
|
|
92
|
+
exports: service === srvRef ? [srvRef] : []
|
|
107
93
|
})
|
|
108
94
|
], DatabaseModule);
|
|
109
95
|
return DatabaseModule;
|
|
110
96
|
};
|
|
111
|
-
const serviceModuleOf = ({ signal, service
|
|
97
|
+
const serviceModuleOf = ({ signal, service }, allSrvs) => {
|
|
112
98
|
if (!(0, import_service.isServiceEnabled)(service))
|
|
113
99
|
return null;
|
|
114
|
-
const
|
|
115
|
-
|
|
100
|
+
const serviceMeta = (0, import_service.getServiceMeta)(service);
|
|
101
|
+
if (!serviceMeta)
|
|
102
|
+
throw new Error(`Service ${service} is not a valid service`);
|
|
103
|
+
const refName = serviceMeta.name.replace("Service", "");
|
|
104
|
+
const [modelName, className] = [(0, import_common.lowerlize)(refName), (0, import_common.capitalize)(refName)];
|
|
105
|
+
const srvRef = (0, import_service.serviceOf)(service);
|
|
116
106
|
let ServiceModule = class {
|
|
117
107
|
};
|
|
118
108
|
ServiceModule = __decorateClass([
|
|
119
109
|
(0, import_common2.Global)(),
|
|
120
110
|
(0, import_common2.Module)({
|
|
121
|
-
imports: [
|
|
111
|
+
imports: signal ? [
|
|
122
112
|
...hasProcessor(signal) ? [
|
|
123
113
|
import_bull.BullModule.registerQueue({
|
|
124
114
|
name: modelName,
|
|
125
115
|
defaultJobOptions: { removeOnComplete: true, removeOnFail: true }
|
|
126
116
|
})
|
|
127
117
|
] : []
|
|
128
|
-
],
|
|
118
|
+
] : [],
|
|
129
119
|
providers: [
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
(0, import_processor.processorOf)(signal, filterSrvs(allSrvs)),
|
|
135
|
-
{ provide: `${className}
|
|
120
|
+
...service === srvRef ? [srvRef] : [],
|
|
121
|
+
...signal ? [
|
|
122
|
+
(0, import_resolver.resolverOf)(signal, filterSrvs(allSrvs)),
|
|
123
|
+
...hasWebsocket(signal) ? [(0, import_websocket.websocketOf)(signal, filterSrvs(allSrvs))] : [],
|
|
124
|
+
...hasProcessor(signal) ? [(0, import_processor.processorOf)(signal, filterSrvs(allSrvs))] : [],
|
|
125
|
+
{ provide: `${className}Signal`, useClass: makeSigForSrv(signal) }
|
|
136
126
|
] : [],
|
|
137
|
-
...
|
|
138
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
139
|
-
...providers
|
|
127
|
+
...(0, import_service.makeProvidersForSrv)(srvRef)
|
|
140
128
|
],
|
|
141
|
-
controllers: [(0, import_controller.controllerOf)(signal, filterSrvs(allSrvs))],
|
|
142
|
-
exports: [
|
|
129
|
+
controllers: signal ? [(0, import_controller.controllerOf)(signal, filterSrvs(allSrvs))] : [],
|
|
130
|
+
exports: service === srvRef ? [srvRef] : []
|
|
143
131
|
})
|
|
144
132
|
], ServiceModule);
|
|
145
133
|
return ServiceModule;
|
|
146
134
|
};
|
|
147
|
-
const scalarModuleOf = ({ signals, uses = {}, useAsyncs = {}, providers = [], enabled = true }, allSrvs) => {
|
|
148
|
-
if (!enabled)
|
|
149
|
-
return null;
|
|
150
|
-
let ScalarModule = class {
|
|
151
|
-
};
|
|
152
|
-
ScalarModule = __decorateClass([
|
|
153
|
-
(0, import_common2.Global)(),
|
|
154
|
-
(0, import_common2.Module)({
|
|
155
|
-
imports: [],
|
|
156
|
-
providers: [
|
|
157
|
-
...signals.map((signal) => (0, import_resolver.resolverOf)(signal, filterSrvs(allSrvs))),
|
|
158
|
-
...signals.filter(hasWebsocket).map((signal) => [
|
|
159
|
-
(0, import_websocket.websocketOf)(signal, filterSrvs(allSrvs)),
|
|
160
|
-
{ provide: "Websocket", useClass: (0, import_websocket.websocketServerOf)(signal) }
|
|
161
|
-
]).flat(),
|
|
162
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common.capitalize)(key), useValue })),
|
|
163
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
164
|
-
...providers
|
|
165
|
-
],
|
|
166
|
-
controllers: signals.map((signal) => (0, import_controller.controllerOf)(signal, filterSrvs(allSrvs)))
|
|
167
|
-
})
|
|
168
|
-
], ScalarModule);
|
|
169
|
-
return ScalarModule;
|
|
170
|
-
};
|
|
171
135
|
const scalarModulesOf = ({ constants }, allSrvs) => {
|
|
172
136
|
const signals = constants.filter((modelRef) => {
|
|
173
137
|
const childRefs = (0, import_constant.getChildClassRefs)(modelRef);
|
|
@@ -194,32 +158,7 @@ const scalarModulesOf = ({ constants }, allSrvs) => {
|
|
|
194
158
|
], ScalarModule);
|
|
195
159
|
return ScalarModule;
|
|
196
160
|
};
|
|
197
|
-
const
|
|
198
|
-
service,
|
|
199
|
-
uses = {},
|
|
200
|
-
useAsyncs = {},
|
|
201
|
-
providers = []
|
|
202
|
-
}) => {
|
|
203
|
-
if (!(0, import_service.isServiceEnabled)(service))
|
|
204
|
-
return null;
|
|
205
|
-
let BatchModule = class {
|
|
206
|
-
};
|
|
207
|
-
BatchModule = __decorateClass([
|
|
208
|
-
(0, import_common2.Global)(),
|
|
209
|
-
(0, import_common2.Module)({
|
|
210
|
-
imports: [],
|
|
211
|
-
providers: [
|
|
212
|
-
(0, import_service.serviceOf)(service),
|
|
213
|
-
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common.capitalize)(key), useValue })),
|
|
214
|
-
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
215
|
-
...providers
|
|
216
|
-
],
|
|
217
|
-
exports: [service]
|
|
218
|
-
})
|
|
219
|
-
], BatchModule);
|
|
220
|
-
return BatchModule;
|
|
221
|
-
};
|
|
222
|
-
const useGlobals = ({ uses, useAsyncs, injects }) => {
|
|
161
|
+
const useGlobals = ({ uses, useAsyncs, providers = [], injects }) => {
|
|
223
162
|
let GlobalsModule = class {
|
|
224
163
|
};
|
|
225
164
|
GlobalsModule = __decorateClass([
|
|
@@ -232,7 +171,8 @@ const useGlobals = ({ uses, useAsyncs, injects }) => {
|
|
|
232
171
|
useValue
|
|
233
172
|
})),
|
|
234
173
|
...Object.entries(useAsyncs ?? {}).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
235
|
-
...Object.entries(injects ?? {}).map(([key, inject]) => ({ provide: (0, import_common.capitalize)(key), useClass: inject }))
|
|
174
|
+
...Object.entries(injects ?? {}).map(([key, inject]) => ({ provide: (0, import_common.capitalize)(key), useClass: inject })),
|
|
175
|
+
...providers
|
|
236
176
|
],
|
|
237
177
|
exports: [
|
|
238
178
|
...Object.keys(uses ?? {}).map((key) => (0, import_common.capitalize)(key)),
|
|
@@ -243,11 +183,21 @@ const useGlobals = ({ uses, useAsyncs, injects }) => {
|
|
|
243
183
|
], GlobalsModule);
|
|
244
184
|
return GlobalsModule;
|
|
245
185
|
};
|
|
186
|
+
const makeSigForSrv = (sigRef) => {
|
|
187
|
+
let Sig = class {
|
|
188
|
+
};
|
|
189
|
+
Sig = __decorateClass([
|
|
190
|
+
(0, import_common2.Injectable)()
|
|
191
|
+
], Sig);
|
|
192
|
+
if (hasWebsocket(sigRef))
|
|
193
|
+
(0, import_websocket.applyWebsocketSignal)(Sig, sigRef);
|
|
194
|
+
if (hasProcessor(sigRef))
|
|
195
|
+
(0, import_processor.applyQueueSignal)(Sig, sigRef);
|
|
196
|
+
return Sig;
|
|
197
|
+
};
|
|
246
198
|
// Annotate the CommonJS export names for ESM import in node:
|
|
247
199
|
0 && (module.exports = {
|
|
248
|
-
batchModuleOf,
|
|
249
200
|
databaseModuleOf,
|
|
250
|
-
scalarModuleOf,
|
|
251
201
|
scalarModulesOf,
|
|
252
202
|
serviceModuleOf,
|
|
253
203
|
useGlobals
|
package/cjs/src/processor.js
CHANGED
|
@@ -17,8 +17,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var processor_exports = {};
|
|
19
19
|
__export(processor_exports, {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
applyQueueSignal: () => applyQueueSignal,
|
|
21
|
+
processorOf: () => processorOf
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(processor_exports);
|
|
24
24
|
var import_common = require("@akanjs/common");
|
|
@@ -51,14 +51,15 @@ const processorOf = (sigRef, allSrvs) => {
|
|
|
51
51
|
const sigMeta = (0, import_signal.getSigMeta)(sigRef);
|
|
52
52
|
const serverMode = process.env.SERVER_MODE ?? "federation";
|
|
53
53
|
const gqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process").filter(
|
|
54
|
-
(gqlMeta) => gqlMeta.signalOption.
|
|
54
|
+
(gqlMeta) => gqlMeta.signalOption.serverMode === "all" || serverMode === "all" || gqlMeta.signalOption.serverMode === serverMode
|
|
55
55
|
);
|
|
56
56
|
class QueueProcessor {
|
|
57
57
|
}
|
|
58
|
-
Object.keys(allSrvs).forEach((
|
|
59
|
-
if (!(0, import_service.isServiceEnabled)(allSrvs[
|
|
58
|
+
Object.keys(allSrvs).forEach((srvName) => {
|
|
59
|
+
if (!(0, import_service.isServiceEnabled)(allSrvs[srvName]))
|
|
60
60
|
return;
|
|
61
|
-
|
|
61
|
+
const srvRef = (0, import_service.getServiceRefs)(srvName)[0];
|
|
62
|
+
(0, import_common2.Inject)(srvRef)(QueueProcessor.prototype, (0, import_common.lowerlize)(srvName));
|
|
62
63
|
});
|
|
63
64
|
for (const gqlMeta of gqlMetas) {
|
|
64
65
|
const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
|
|
@@ -75,18 +76,21 @@ const processorOf = (sigRef, allSrvs) => {
|
|
|
75
76
|
(0, import_bull.Processor)(sigMeta.refName)(QueueProcessor);
|
|
76
77
|
return QueueProcessor;
|
|
77
78
|
};
|
|
78
|
-
const
|
|
79
|
+
const applyQueueSignal = (targetRef, sigRef) => {
|
|
79
80
|
const sigMeta = (0, import_signal.getSigMeta)(sigRef);
|
|
80
81
|
const gqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process");
|
|
82
|
+
(0, import_common2.Inject)((0, import_bull.getQueueToken)(sigMeta.refName))(targetRef.prototype, "queue");
|
|
81
83
|
for (const gqlMeta of gqlMetas) {
|
|
82
|
-
if (
|
|
84
|
+
if (targetRef.prototype[gqlMeta.key])
|
|
83
85
|
throw new Error(`Queue already has ${gqlMeta.key} in ${sigMeta.refName}`);
|
|
84
|
-
|
|
86
|
+
targetRef.prototype[gqlMeta.key] = function(...args) {
|
|
87
|
+
return this.queue.add(gqlMeta.key, args);
|
|
88
|
+
};
|
|
85
89
|
}
|
|
86
|
-
return
|
|
90
|
+
return targetRef;
|
|
87
91
|
};
|
|
88
92
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
93
|
0 && (module.exports = {
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
applyQueueSignal,
|
|
95
|
+
processorOf
|
|
92
96
|
});
|
package/cjs/src/resolver.js
CHANGED
|
@@ -71,10 +71,11 @@ const resolverOf = (sigRef, allSrvs) => {
|
|
|
71
71
|
const Rsv = (0, import_signal.copySignal)(sigRef);
|
|
72
72
|
const sigMeta = (0, import_signal.getSigMeta)(Rsv);
|
|
73
73
|
const gqlMetas = (0, import_signal.getGqlMetas)(Rsv);
|
|
74
|
-
Object.keys(allSrvs).forEach((
|
|
75
|
-
if (!(0, import_service.isServiceEnabled)(allSrvs[
|
|
74
|
+
Object.keys(allSrvs).forEach((srvName) => {
|
|
75
|
+
if (!(0, import_service.isServiceEnabled)(allSrvs[srvName]))
|
|
76
76
|
return;
|
|
77
|
-
|
|
77
|
+
const srvRef = (0, import_service.getServiceRefs)(srvName)[0];
|
|
78
|
+
(0, import_common2.Inject)(srvRef)(Rsv.prototype, (0, import_common.lowerlize)(srvName));
|
|
78
79
|
});
|
|
79
80
|
for (const gqlMeta of gqlMetas) {
|
|
80
81
|
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "restapi" || !["Query", "Mutation"].includes(gqlMeta.type))
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result)
|
|
25
|
+
__defProp(target, key, result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
var __publicField = (obj, key, value) => {
|
|
29
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
var __accessCheck = (obj, member, msg) => {
|
|
33
|
+
if (!member.has(obj))
|
|
34
|
+
throw TypeError("Cannot " + msg);
|
|
35
|
+
};
|
|
36
|
+
var __privateGet = (obj, member, getter) => {
|
|
37
|
+
__accessCheck(obj, member, "read from private field");
|
|
38
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
39
|
+
};
|
|
40
|
+
var __privateAdd = (obj, member, value) => {
|
|
41
|
+
if (member.has(obj))
|
|
42
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
43
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
44
|
+
};
|
|
45
|
+
var schedule_exports = {};
|
|
46
|
+
__export(schedule_exports, {
|
|
47
|
+
makeScheduleModule: () => makeScheduleModule
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(schedule_exports);
|
|
50
|
+
var import_common = require("@akanjs/common");
|
|
51
|
+
var import_service = require("@akanjs/service");
|
|
52
|
+
var import_signal = require("@akanjs/signal");
|
|
53
|
+
var import_common2 = require("@nestjs/common");
|
|
54
|
+
var import_cron = require("cron");
|
|
55
|
+
const makeScheduleModule = (serverMode, backendEnv) => {
|
|
56
|
+
var _cronMap, _timeoutMap, _intervalMap, _lockMap;
|
|
57
|
+
const srvRefs = (0, import_service.getAllServiceRefs)();
|
|
58
|
+
const sigRefs = (0, import_signal.getAllSignalRefs)();
|
|
59
|
+
const initMetas = [];
|
|
60
|
+
const cronMetas = [];
|
|
61
|
+
const intervalMetas = [];
|
|
62
|
+
const timeoutMetas = [];
|
|
63
|
+
const destroyMetas = [];
|
|
64
|
+
sigRefs.forEach((sigRef) => {
|
|
65
|
+
const gqlMetas = (0, import_signal.getGqlMetas)(sigRef);
|
|
66
|
+
gqlMetas.forEach((gqlMeta) => {
|
|
67
|
+
const { enabled, operationMode, serverMode: targetServerMode, scheduleType } = gqlMeta.signalOption;
|
|
68
|
+
if (gqlMeta.type !== "Schedule")
|
|
69
|
+
return;
|
|
70
|
+
else if (!enabled)
|
|
71
|
+
return;
|
|
72
|
+
else if (operationMode && !operationMode.includes(backendEnv.operationMode))
|
|
73
|
+
return;
|
|
74
|
+
else if (targetServerMode && targetServerMode !== "all" && serverMode !== "all" && targetServerMode !== serverMode)
|
|
75
|
+
return;
|
|
76
|
+
switch (scheduleType) {
|
|
77
|
+
case "init":
|
|
78
|
+
initMetas.push(gqlMeta);
|
|
79
|
+
break;
|
|
80
|
+
case "cron":
|
|
81
|
+
cronMetas.push(gqlMeta);
|
|
82
|
+
break;
|
|
83
|
+
case "interval":
|
|
84
|
+
intervalMetas.push(gqlMeta);
|
|
85
|
+
break;
|
|
86
|
+
case "timeout":
|
|
87
|
+
timeoutMetas.push(gqlMeta);
|
|
88
|
+
break;
|
|
89
|
+
case "destroy":
|
|
90
|
+
destroyMetas.push(gqlMeta);
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
let Schedule = class {
|
|
98
|
+
constructor() {
|
|
99
|
+
__publicField(this, "logger", new import_common2.Logger("Schedule"));
|
|
100
|
+
__privateAdd(this, _cronMap, /* @__PURE__ */ new Map());
|
|
101
|
+
__privateAdd(this, _timeoutMap, /* @__PURE__ */ new Map());
|
|
102
|
+
__privateAdd(this, _intervalMap, /* @__PURE__ */ new Map());
|
|
103
|
+
__privateAdd(this, _lockMap, /* @__PURE__ */ new Map());
|
|
104
|
+
}
|
|
105
|
+
async onModuleInit() {
|
|
106
|
+
await Promise.all(
|
|
107
|
+
initMetas.map(async (gqlMeta) => {
|
|
108
|
+
const fn = gqlMeta.descriptor.value;
|
|
109
|
+
const before = Date.now();
|
|
110
|
+
this.logger.debug(`Init Before ${gqlMeta.key} / ${before}`);
|
|
111
|
+
await fn.apply(this);
|
|
112
|
+
const after = Date.now();
|
|
113
|
+
this.logger.debug(`Init After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
timeoutMetas.forEach((gqlMeta) => {
|
|
117
|
+
const fn = gqlMeta.descriptor.value;
|
|
118
|
+
const timeout = gqlMeta.signalOption.scheduleTime;
|
|
119
|
+
const timer = setTimeout(async () => {
|
|
120
|
+
const before = Date.now();
|
|
121
|
+
this.logger.debug(`Timemout Before ${gqlMeta.key} / ${before}`);
|
|
122
|
+
await fn.apply(this);
|
|
123
|
+
const after = Date.now();
|
|
124
|
+
this.logger.debug(`Timemout After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
125
|
+
__privateGet(this, _timeoutMap).delete(fn);
|
|
126
|
+
}, timeout);
|
|
127
|
+
__privateGet(this, _timeoutMap).set(fn, timer);
|
|
128
|
+
});
|
|
129
|
+
intervalMetas.forEach((gqlMeta) => {
|
|
130
|
+
const lock = gqlMeta.signalOption.lock;
|
|
131
|
+
const fn = gqlMeta.descriptor.value;
|
|
132
|
+
const interval = gqlMeta.signalOption.scheduleTime;
|
|
133
|
+
const timer = setInterval(async () => {
|
|
134
|
+
if (lock) {
|
|
135
|
+
if (__privateGet(this, _lockMap).get(fn)) {
|
|
136
|
+
this.logger.warn(`${gqlMeta.key} is locked, skipping...`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
__privateGet(this, _lockMap).set(fn, true);
|
|
140
|
+
}
|
|
141
|
+
const before = Date.now();
|
|
142
|
+
this.logger.debug(`Interval Before ${gqlMeta.key} / ${before}`);
|
|
143
|
+
await fn.apply(this);
|
|
144
|
+
const after = Date.now();
|
|
145
|
+
this.logger.debug(`Interval After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
146
|
+
if (lock)
|
|
147
|
+
__privateGet(this, _lockMap).set(fn, false);
|
|
148
|
+
}, interval);
|
|
149
|
+
__privateGet(this, _intervalMap).set(fn, timer);
|
|
150
|
+
});
|
|
151
|
+
cronMetas.forEach((gqlMeta) => {
|
|
152
|
+
const lock = gqlMeta.signalOption.lock;
|
|
153
|
+
const fn = gqlMeta.descriptor.value;
|
|
154
|
+
const cronTime = gqlMeta.signalOption.scheduleCron;
|
|
155
|
+
if (!cronTime)
|
|
156
|
+
throw new Error(`Cron time is not found for ${gqlMeta.key}`);
|
|
157
|
+
const cronJob = import_cron.CronJob.from({
|
|
158
|
+
cronTime,
|
|
159
|
+
onTick: async () => {
|
|
160
|
+
if (lock) {
|
|
161
|
+
if (__privateGet(this, _lockMap).get(fn)) {
|
|
162
|
+
this.logger.warn(`${gqlMeta.key} is locked, skipping...`);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
__privateGet(this, _lockMap).set(fn, true);
|
|
166
|
+
}
|
|
167
|
+
const before = Date.now();
|
|
168
|
+
this.logger.debug(`Cron Before ${gqlMeta.key} / ${before}`);
|
|
169
|
+
await fn.apply(this);
|
|
170
|
+
const after = Date.now();
|
|
171
|
+
this.logger.debug(`Cron After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
172
|
+
if (lock)
|
|
173
|
+
__privateGet(this, _lockMap).set(fn, false);
|
|
174
|
+
},
|
|
175
|
+
start: true
|
|
176
|
+
});
|
|
177
|
+
__privateGet(this, _cronMap).set(fn, cronJob);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async onModuleDestroy() {
|
|
181
|
+
__privateGet(this, _timeoutMap).forEach((timer, fn) => {
|
|
182
|
+
clearTimeout(timer);
|
|
183
|
+
__privateGet(this, _timeoutMap).delete(fn);
|
|
184
|
+
});
|
|
185
|
+
__privateGet(this, _intervalMap).forEach((timer, fn) => {
|
|
186
|
+
clearInterval(timer);
|
|
187
|
+
__privateGet(this, _intervalMap).delete(fn);
|
|
188
|
+
});
|
|
189
|
+
await Promise.all(
|
|
190
|
+
[...__privateGet(this, _cronMap).entries()].map(async ([fn, cronJob]) => {
|
|
191
|
+
await cronJob.stop();
|
|
192
|
+
__privateGet(this, _cronMap).delete(fn);
|
|
193
|
+
})
|
|
194
|
+
);
|
|
195
|
+
await Promise.all(
|
|
196
|
+
destroyMetas.map(async (gqlMeta) => {
|
|
197
|
+
const fn = gqlMeta.descriptor.value;
|
|
198
|
+
const before = Date.now();
|
|
199
|
+
this.logger.debug(`Destroy Before ${gqlMeta.key} / ${before}`);
|
|
200
|
+
await fn.apply(this);
|
|
201
|
+
const after = Date.now();
|
|
202
|
+
this.logger.debug(`Destroy After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
203
|
+
})
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
_cronMap = new WeakMap();
|
|
208
|
+
_timeoutMap = new WeakMap();
|
|
209
|
+
_intervalMap = new WeakMap();
|
|
210
|
+
_lockMap = new WeakMap();
|
|
211
|
+
Schedule = __decorateClass([
|
|
212
|
+
(0, import_common2.Injectable)()
|
|
213
|
+
], Schedule);
|
|
214
|
+
srvRefs.forEach((srvRef) => {
|
|
215
|
+
const serviceMeta = (0, import_service.getServiceMeta)(srvRef);
|
|
216
|
+
if (!serviceMeta)
|
|
217
|
+
throw new Error(`Service ${srvRef.name} is not found`);
|
|
218
|
+
(0, import_common2.Inject)(srvRef)(Schedule.prototype, (0, import_common.lowerlize)(serviceMeta.name));
|
|
219
|
+
});
|
|
220
|
+
let ScheduleModule = class {
|
|
221
|
+
};
|
|
222
|
+
ScheduleModule = __decorateClass([
|
|
223
|
+
(0, import_common2.Global)(),
|
|
224
|
+
(0, import_common2.Module)({ providers: [Schedule] })
|
|
225
|
+
], ScheduleModule);
|
|
226
|
+
return ScheduleModule;
|
|
227
|
+
};
|
|
228
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
+
0 && (module.exports = {
|
|
230
|
+
makeScheduleModule
|
|
231
|
+
});
|