@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/schema.js CHANGED
@@ -18,6 +18,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
18
18
  var schema_exports = {};
19
19
  __export(schema_exports, {
20
20
  addSchema: () => addSchema,
21
+ hasSchema: () => hasSchema,
21
22
  schemaOf: () => schemaOf
22
23
  });
23
24
  module.exports = __toCommonJS(schema_exports);
@@ -32,6 +33,24 @@ class ScalarSchemaStorage {
32
33
  }
33
34
  class SchemaStorage {
34
35
  }
36
+ const getSchemaMetaByName = (refName) => {
37
+ const schemaMeta = Reflect.getMetadata(refName, SchemaStorage.prototype);
38
+ return schemaMeta;
39
+ };
40
+ const setSchemaMetaByName = (refName, schema) => {
41
+ Reflect.defineMetadata(refName, schema, SchemaStorage.prototype);
42
+ };
43
+ const hasSchema = (modelRef) => {
44
+ const classMeta = (0, import_constant.getClassMeta)(modelRef);
45
+ return !!getSchemaMetaByName(classMeta.refName);
46
+ };
47
+ const getScalarSchemaMetaByName = (refName) => {
48
+ const schemaMeta = Reflect.getMetadata(refName, ScalarSchemaStorage.prototype);
49
+ return schemaMeta;
50
+ };
51
+ const setScalarSchemaMetaByName = (refName, schema) => {
52
+ Reflect.defineMetadata(refName, schema, ScalarSchemaStorage.prototype);
53
+ };
35
54
  const scalarMongoTypeMap = /* @__PURE__ */ new Map([
36
55
  [import_base.ID, import_document.ObjectId],
37
56
  [import_base.Int, Number],
@@ -71,12 +90,12 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
71
90
  }
72
91
  prop = { type: (0, import_base.arraiedModel)(prop, fieldMeta.optArrDepth), default: [], required: true };
73
92
  if (fieldMeta.modelRef.prototype === Date.prototype) {
74
- prop.get = (dates) => dates.map((date) => (0, import_base.dayjs)(date));
75
- prop.set = (days) => days.map((day) => day.toDate());
93
+ prop.get = (dates) => (0, import_base.applyFnToArrayObjects)(dates, (date) => (0, import_base.dayjs)(date));
94
+ prop.set = (days) => (0, import_base.applyFnToArrayObjects)(days, (day) => day.toDate());
76
95
  }
77
96
  if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base.ID.prototype) {
78
- prop.get = (ids) => ids.map((id) => id.toString());
79
- prop.set = (ids) => ids.map((id) => new import_mongoose.Types.ObjectId(id));
97
+ prop.get = (ids) => (0, import_base.applyFnToArrayObjects)(ids, (id) => id.toString());
98
+ prop.set = (ids) => (0, import_base.applyFnToArrayObjects)(ids, (id) => new import_mongoose.Types.ObjectId(id));
80
99
  }
81
100
  } else {
82
101
  prop.type = (0, import_base.arraiedModel)(type, fieldMeta.arrDepth);
@@ -118,12 +137,17 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
118
137
  prop.set = (v) => v === null ? void 0 : v;
119
138
  }
120
139
  if (fieldMeta.modelRef.prototype === Date.prototype) {
121
- prop.get = (date) => date ? (0, import_base.dayjs)(date) : void 0;
122
- prop.set = (day) => day ? (0, import_base.dayjs)(day).toDate() : void 0;
140
+ prop.get = (date) => (0, import_base.applyFnToArrayObjects)(date, (date2) => date2 ? (0, import_base.dayjs)(date2) : void 0);
141
+ prop.set = (day) => (0, import_base.applyFnToArrayObjects)(day, (day2) => day2 ? (0, import_base.dayjs)(day2).toDate() : void 0);
123
142
  }
124
143
  if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base.ID.prototype) {
125
- prop.get = (id) => id ? id.toString() : void 0;
126
- prop.set = (id) => id ? new import_mongoose.Types.ObjectId(id) : void 0;
144
+ if (fieldMeta.arrDepth === 0) {
145
+ prop.get = (id) => id ? id.toString() : void 0;
146
+ prop.set = (id) => id ? new import_mongoose.Types.ObjectId(id) : void 0;
147
+ } else {
148
+ prop.get = (val) => (0, import_base.applyFnToArrayObjects)(val, (id) => id ? id.toString() : void 0);
149
+ prop.set = (val) => (0, import_base.applyFnToArrayObjects)(val, (id) => id ? new import_mongoose.Types.ObjectId(id) : void 0);
150
+ }
127
151
  }
128
152
  if (fieldMeta.isClass && fieldMeta.isScalar && fieldMeta.default === null && !fieldMeta.nullable) {
129
153
  prop.default = (0, import_signal.makeDefault)(fieldMeta.modelRef);
@@ -138,7 +162,7 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
138
162
  };
139
163
  const createSchema = (modelRef) => {
140
164
  const classMeta = (0, import_constant.getClassMeta)(modelRef);
141
- const schemaMeta = Reflect.getMetadata(classMeta.refName, ScalarSchemaStorage.prototype);
165
+ const schemaMeta = getScalarSchemaMetaByName(classMeta.refName);
142
166
  if (schemaMeta)
143
167
  return schemaMeta;
144
168
  const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
@@ -147,12 +171,12 @@ const createSchema = (modelRef) => {
147
171
  applyMongoProp(schemaProps, fieldMeta);
148
172
  });
149
173
  const schema = new import_mongoose.Schema(schemaProps);
150
- Reflect.defineMetadata(classMeta.refName, schema, ScalarSchemaStorage.prototype);
174
+ setScalarSchemaMetaByName(classMeta.refName, schema);
151
175
  return schema;
152
176
  };
153
177
  const schemaOf = (modelRef, docRef, middleware) => {
154
178
  const classMeta = (0, import_constant.getClassMeta)(docRef);
155
- const schemaMeta = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
179
+ const schemaMeta = getSchemaMetaByName(classMeta.refName);
156
180
  if (schemaMeta)
157
181
  return schemaMeta;
158
182
  const fieldMetas = (0, import_constant.getFieldMetas)(docRef);
@@ -192,7 +216,7 @@ const schemaOf = (modelRef, docRef, middleware) => {
192
216
  const onSchema = Object.getOwnPropertyDescriptor(middleware.prototype, "onSchema")?.value;
193
217
  onSchema?.(schema);
194
218
  schema.index({ removedAt: -1 });
195
- Reflect.defineMetadata(classMeta.refName, schema, SchemaStorage.prototype);
219
+ setSchemaMetaByName(classMeta.refName, schema);
196
220
  return schema;
197
221
  };
198
222
  const addSchema = (modelRef, docRef, inputRef, middleware) => {
@@ -239,5 +263,6 @@ const addSchema = (modelRef, docRef, inputRef, middleware) => {
239
263
  // Annotate the CommonJS export names for ESM import in node:
240
264
  0 && (module.exports = {
241
265
  addSchema,
266
+ hasSchema,
242
267
  schemaOf
243
268
  });
@@ -217,9 +217,7 @@ let SearchDaemonModule = class {
217
217
  };
218
218
  SearchDaemonModule = __decorateClass([
219
219
  (0, import_common2.Global)(),
220
- (0, import_common2.Module)({
221
- providers: [SearchDaemon]
222
- })
220
+ (0, import_common2.Module)({ providers: [SearchDaemon] })
223
221
  ], SearchDaemonModule);
224
222
  // Annotate the CommonJS export names for ESM import in node:
225
223
  0 && (module.exports = {
@@ -26,8 +26,8 @@ var __decorateClass = (decorators, target, key, kind) => {
26
26
  };
27
27
  var websocket_exports = {};
28
28
  __export(websocket_exports, {
29
- websocketOf: () => websocketOf,
30
- websocketServerOf: () => websocketServerOf
29
+ applyWebsocketSignal: () => applyWebsocketSignal,
30
+ websocketOf: () => websocketOf
31
31
  });
32
32
  module.exports = __toCommonJS(websocket_exports);
33
33
  var import_common = require("@akanjs/common");
@@ -73,10 +73,11 @@ const websocketOf = (sigRef, allSrvs) => {
73
73
  class WsGateway {
74
74
  __sigRef__ = sigRef;
75
75
  }
76
- Object.keys(allSrvs).forEach((srv) => {
77
- if (!(0, import_service.isServiceEnabled)(allSrvs[srv]))
76
+ Object.keys(allSrvs).forEach((srvName) => {
77
+ if (!(0, import_service.isServiceEnabled)(allSrvs[srvName]))
78
78
  return;
79
- (0, import_common2.Inject)(allSrvs[srv])(WsGateway.prototype, (0, import_common.lowerlize)(srv));
79
+ const srvRef = (0, import_service.getServiceRefs)(srvName)[0];
80
+ (0, import_common2.Inject)(srvRef)(WsGateway.prototype, (0, import_common.lowerlize)(srvName));
80
81
  });
81
82
  const messageGqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
82
83
  for (const gqlMeta of messageGqlMetas) {
@@ -115,32 +116,24 @@ const websocketOf = (sigRef, allSrvs) => {
115
116
  (0, import_websockets.WebSocketGateway)({ cors: { origin: "*" }, transports: ["websocket"] })(WsGateway);
116
117
  return WsGateway;
117
118
  };
118
- const websocketServerOf = (sigRef) => {
119
+ const applyWebsocketSignal = (targetRef, sigRef) => {
119
120
  const pubsubGqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
120
- let Websocket = class {
121
- server;
122
- };
123
- __decorateClass([
124
- (0, import_websockets.WebSocketServer)()
125
- ], Websocket.prototype, "server", 2);
126
- Websocket = __decorateClass([
127
- (0, import_common2.Injectable)(),
128
- (0, import_websockets.WebSocketGateway)({ cors: { origin: "*" }, transports: ["websocket"] })
129
- ], Websocket);
121
+ (0, import_websockets.WebSocketGateway)({ cors: { origin: "*" }, transports: ["websocket"] })(targetRef);
122
+ (0, import_websockets.WebSocketServer)()(targetRef.prototype, "websocket");
130
123
  for (const gqlMeta of pubsubGqlMetas) {
131
124
  const [argMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
132
- Websocket.prototype[gqlMeta.key] = function(...args) {
125
+ targetRef.prototype[gqlMeta.key] = function(...args) {
133
126
  const roomId = makeRoomId(
134
127
  gqlMeta.key,
135
128
  argMetas.map((argMeta) => args[argMeta.idx])
136
129
  );
137
- this.server.to(roomId).emit(roomId, args.at(-1));
130
+ this.websocket.to(roomId).emit(roomId, args.at(-1));
138
131
  };
139
132
  }
140
- return Websocket;
133
+ return targetRef;
141
134
  };
142
135
  // Annotate the CommonJS export names for ESM import in node:
143
136
  0 && (module.exports = {
144
- websocketOf,
145
- websocketServerOf
137
+ applyWebsocketSignal,
138
+ websocketOf
146
139
  });
@@ -5,8 +5,7 @@ const registerBaseModule = (option) => {
5
5
  return serviceModuleOf(
6
6
  {
7
7
  signal: BaseSignal,
8
- service: BaseService,
9
- uses: { onCleanup: option.onCleanup }
8
+ service: BaseService
10
9
  },
11
10
  allSrvs
12
11
  );
package/esm/src/boot.js CHANGED
@@ -51,6 +51,7 @@ import { createClient } from "redis";
51
51
  import { registerBaseModule } from "./base.module";
52
52
  import { DateScalar } from "./gql";
53
53
  import { useGlobals } from "./module";
54
+ import { makeScheduleModule } from "./schedule";
54
55
  import { SearchDaemonModule } from "./searchDaemon";
55
56
  const createNestApp = async ({ registerModules, serverMode = "federation", env, log = true }) => {
56
57
  const backendLogger = new Logger("Backend");
@@ -89,9 +90,9 @@ const createNestApp = async ({ registerModules, serverMode = "federation", env,
89
90
  Injectable()
90
91
  ], AuthMiddleWare);
91
92
  const redisClient = await createClient({ url: redisUri }).connect();
92
- let SubDatabaseModule = class {
93
+ let GlobalProvideModule = class {
93
94
  };
94
- SubDatabaseModule = __decorateClass([
95
+ GlobalProvideModule = __decorateClass([
95
96
  Global(),
96
97
  Module({
97
98
  providers: [
@@ -99,11 +100,12 @@ const createNestApp = async ({ registerModules, serverMode = "federation", env,
99
100
  {
100
101
  provide: "MEILI_CLIENT",
101
102
  useFactory: () => new MeiliSearch({ host: meiliUri, apiKey: generateMeiliKey(env) })
102
- }
103
+ },
104
+ { provide: "GLOBAL_ENV", useValue: env }
103
105
  ],
104
- exports: ["REDIS_CLIENT", "MEILI_CLIENT"]
106
+ exports: ["REDIS_CLIENT", "MEILI_CLIENT", "GLOBAL_ENV"]
105
107
  })
106
- ], SubDatabaseModule);
108
+ ], GlobalProvideModule);
107
109
  let AppModule = class {
108
110
  configure(consumer) {
109
111
  consumer.apply(AuthMiddleWare).forRoutes({ path: "*", method: RequestMethod.ALL });
@@ -130,12 +132,13 @@ const createNestApp = async ({ registerModules, serverMode = "federation", env,
130
132
  MongooseModule.forRootAsync({
131
133
  useFactory: () => ({ uri: mongoUri, autoIndex: baseEnv.environment !== "main" })
132
134
  }),
133
- SubDatabaseModule,
135
+ GlobalProvideModule,
134
136
  useGlobals({
135
137
  injects: { SearchClient, DatabaseClient, CacheClient }
136
138
  }),
137
139
  ...["batch", "all"].includes(serverMode) && baseEnv.operationMode !== "edge" ? [SearchDaemonModule] : [],
138
- ...[registerBaseModule(env), ...registerModules(env)].filter((m) => !!m)
140
+ ...[registerBaseModule(env), ...registerModules(env)].filter((m) => !!m),
141
+ makeScheduleModule(serverMode, env)
139
142
  ],
140
143
  providers: [DateScalar]
141
144
  })
@@ -13,7 +13,7 @@ import {
13
13
  Self,
14
14
  UserIp
15
15
  } from "@akanjs/nest";
16
- import { isServiceEnabled } from "@akanjs/service";
16
+ import { getServiceRefs, isServiceEnabled } from "@akanjs/service";
17
17
  import {
18
18
  copySignal,
19
19
  getArgMetas,
@@ -51,10 +51,11 @@ const controllerOf = (sigRef, allSrvs) => {
51
51
  const gqlMetas = getGqlMetas(sigRef);
52
52
  const prefix = getControllerPrefix(sigMeta);
53
53
  const Ctrl = copySignal(sigRef);
54
- Object.keys(allSrvs).forEach((srv) => {
55
- if (!isServiceEnabled(allSrvs[srv]))
54
+ Object.keys(allSrvs).forEach((srvName) => {
55
+ if (!isServiceEnabled(allSrvs[srvName]))
56
56
  return;
57
- Inject(allSrvs[srv])(Ctrl.prototype, lowerlize(srv));
57
+ const srvRef = getServiceRefs(srvName)[0];
58
+ Inject(srvRef)(Ctrl.prototype, lowerlize(srvName));
58
59
  });
59
60
  for (const gqlMeta of gqlMetas) {
60
61
  if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "graphql" || !["Query", "Mutation"].includes(gqlMeta.type))
package/esm/src/module.js CHANGED
@@ -12,33 +12,25 @@ var __decorateClass = (decorators, target, key, kind) => {
12
12
  import { capitalize, lowerlize } from "@akanjs/common";
13
13
  import { getChildClassRefs, getClassMeta } from "@akanjs/constant";
14
14
  import { databaseModelOf } from "@akanjs/document";
15
- import { isServiceEnabled, serviceOf } from "@akanjs/service";
16
- import { getGqlMetas, getSigMeta, LogSignal, Signal } from "@akanjs/signal";
17
- import { BullModule, getQueueToken } from "@nestjs/bull";
18
- import { Global, Module } from "@nestjs/common";
15
+ import { getServiceMeta, isServiceEnabled, makeProvidersForSrv, serviceOf } from "@akanjs/service";
16
+ import { getGqlMetas, LogSignal, Signal } from "@akanjs/signal";
17
+ import { BullModule } from "@nestjs/bull";
18
+ import { Global, Injectable, Module } from "@nestjs/common";
19
19
  import { getModelToken, MongooseModule } from "@nestjs/mongoose";
20
20
  import { controllerOf } from "./controller";
21
- import { processorOf } from "./processor";
21
+ import { applyQueueSignal, processorOf } from "./processor";
22
22
  import { resolverOf } from "./resolver";
23
- import { addSchema, schemaOf } from "./schema";
24
- import { websocketOf, websocketServerOf } from "./websocket";
23
+ import { addSchema, hasSchema, schemaOf } from "./schema";
24
+ import { applyWebsocketSignal, websocketOf } from "./websocket";
25
25
  const hasWebsocket = (signal) => getGqlMetas(signal).some((gqlMeta) => ["Message", "Pubsub"].includes(gqlMeta.type));
26
26
  const hasProcessor = (signal) => getGqlMetas(signal).some((gqlMeta) => gqlMeta.type === "Process");
27
27
  const filterSrvs = (srvs) => Object.fromEntries(Object.entries(srvs).filter(([_, srv]) => !!srv));
28
- const databaseModuleOf = ({
29
- constant,
30
- database,
31
- signal,
32
- service,
33
- uses = {},
34
- useAsyncs = {},
35
- providers = [],
36
- extended
37
- }, allSrvs) => {
28
+ const databaseModuleOf = ({ constant, database, signal, service }, allSrvs) => {
38
29
  if (!isServiceEnabled(service))
39
30
  return null;
40
31
  const [modelName, className] = [lowerlize(constant.refName), capitalize(constant.refName)];
41
32
  const mongoToken = getModelToken(className);
33
+ const srvRef = serviceOf(service);
42
34
  let DatabaseModule = class {
43
35
  };
44
36
  DatabaseModule = __decorateClass([
@@ -48,7 +40,7 @@ const databaseModuleOf = ({
48
40
  MongooseModule.forFeature([
49
41
  {
50
42
  name: className,
51
- schema: extended ? addSchema(database.Model, database.Doc, database.Input, database.Middleware) : schemaOf(database.Model, database.Doc, database.Middleware)
43
+ schema: hasSchema(constant.Full) ? addSchema(database.Model, database.Doc, database.Input, database.Middleware) : schemaOf(database.Model, database.Doc, database.Middleware)
52
44
  }
53
45
  ]),
54
46
  ...hasProcessor(signal) ? [
@@ -59,15 +51,11 @@ const databaseModuleOf = ({
59
51
  ] : []
60
52
  ],
61
53
  providers: [
62
- serviceOf(service),
54
+ ...service === srvRef ? [srvRef] : [],
63
55
  resolverOf(signal, filterSrvs(allSrvs)),
64
- ...hasProcessor(signal) ? [
65
- processorOf(signal, filterSrvs(allSrvs)),
66
- { provide: `${className}Queue`, useFactory: (queue) => queue, inject: [getQueueToken(modelName)] }
67
- ] : [],
68
- ...hasWebsocket(signal) ? [websocketOf(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: websocketServerOf(signal) }] : [],
69
- ...Object.entries(uses).map(([key, useValue]) => ({ provide: capitalize(key), useValue })),
70
- ...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
56
+ ...hasWebsocket(signal) ? [websocketOf(signal, filterSrvs(allSrvs))] : [],
57
+ ...hasProcessor(signal) ? [processorOf(signal, filterSrvs(allSrvs))] : [],
58
+ { provide: `${className}Signal`, useClass: makeSigForSrv(signal) },
71
59
  {
72
60
  provide: `${modelName}Model`,
73
61
  useFactory: (model, redis, meili) => {
@@ -75,74 +63,52 @@ const databaseModuleOf = ({
75
63
  },
76
64
  inject: [mongoToken, "REDIS_CLIENT", "MEILI_CLIENT"]
77
65
  },
78
- ...providers
66
+ ...makeProvidersForSrv(srvRef)
79
67
  ],
80
68
  controllers: [controllerOf(signal, filterSrvs(allSrvs))],
81
- exports: [service]
69
+ exports: service === srvRef ? [srvRef] : []
82
70
  })
83
71
  ], DatabaseModule);
84
72
  return DatabaseModule;
85
73
  };
86
- const serviceModuleOf = ({ signal, service, uses = {}, useAsyncs = {}, providers = [] }, allSrvs) => {
74
+ const serviceModuleOf = ({ signal, service }, allSrvs) => {
87
75
  if (!isServiceEnabled(service))
88
76
  return null;
89
- const sigMeta = getSigMeta(signal);
90
- const [modelName, className] = [lowerlize(sigMeta.refName), capitalize(sigMeta.refName)];
77
+ const serviceMeta = getServiceMeta(service);
78
+ if (!serviceMeta)
79
+ throw new Error(`Service ${service} is not a valid service`);
80
+ const refName = serviceMeta.name.replace("Service", "");
81
+ const [modelName, className] = [lowerlize(refName), capitalize(refName)];
82
+ const srvRef = serviceOf(service);
91
83
  let ServiceModule = class {
92
84
  };
93
85
  ServiceModule = __decorateClass([
94
86
  Global(),
95
87
  Module({
96
- imports: [
88
+ imports: signal ? [
97
89
  ...hasProcessor(signal) ? [
98
90
  BullModule.registerQueue({
99
91
  name: modelName,
100
92
  defaultJobOptions: { removeOnComplete: true, removeOnFail: true }
101
93
  })
102
94
  ] : []
103
- ],
95
+ ] : [],
104
96
  providers: [
105
- serviceOf(service),
106
- resolverOf(signal, filterSrvs(allSrvs)),
107
- ...hasWebsocket(signal) ? [websocketOf(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: websocketServerOf(signal) }] : [],
108
- ...hasProcessor(signal) ? [
109
- processorOf(signal, filterSrvs(allSrvs)),
110
- { provide: `${className}Queue`, useFactory: (queue) => queue, inject: [getQueueToken(modelName)] }
97
+ ...service === srvRef ? [srvRef] : [],
98
+ ...signal ? [
99
+ resolverOf(signal, filterSrvs(allSrvs)),
100
+ ...hasWebsocket(signal) ? [websocketOf(signal, filterSrvs(allSrvs))] : [],
101
+ ...hasProcessor(signal) ? [processorOf(signal, filterSrvs(allSrvs))] : [],
102
+ { provide: `${className}Signal`, useClass: makeSigForSrv(signal) }
111
103
  ] : [],
112
- ...Object.entries(uses).map(([key, useValue]) => ({ provide: capitalize(key), useValue })),
113
- ...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
114
- ...providers
104
+ ...makeProvidersForSrv(srvRef)
115
105
  ],
116
- controllers: [controllerOf(signal, filterSrvs(allSrvs))],
117
- exports: [service]
106
+ controllers: signal ? [controllerOf(signal, filterSrvs(allSrvs))] : [],
107
+ exports: service === srvRef ? [srvRef] : []
118
108
  })
119
109
  ], ServiceModule);
120
110
  return ServiceModule;
121
111
  };
122
- const scalarModuleOf = ({ signals, uses = {}, useAsyncs = {}, providers = [], enabled = true }, allSrvs) => {
123
- if (!enabled)
124
- return null;
125
- let ScalarModule = class {
126
- };
127
- ScalarModule = __decorateClass([
128
- Global(),
129
- Module({
130
- imports: [],
131
- providers: [
132
- ...signals.map((signal) => resolverOf(signal, filterSrvs(allSrvs))),
133
- ...signals.filter(hasWebsocket).map((signal) => [
134
- websocketOf(signal, filterSrvs(allSrvs)),
135
- { provide: "Websocket", useClass: websocketServerOf(signal) }
136
- ]).flat(),
137
- ...Object.entries(uses).map(([key, useValue]) => ({ provide: capitalize(key), useValue })),
138
- ...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
139
- ...providers
140
- ],
141
- controllers: signals.map((signal) => controllerOf(signal, filterSrvs(allSrvs)))
142
- })
143
- ], ScalarModule);
144
- return ScalarModule;
145
- };
146
112
  const scalarModulesOf = ({ constants }, allSrvs) => {
147
113
  const signals = constants.filter((modelRef) => {
148
114
  const childRefs = getChildClassRefs(modelRef);
@@ -169,32 +135,7 @@ const scalarModulesOf = ({ constants }, allSrvs) => {
169
135
  ], ScalarModule);
170
136
  return ScalarModule;
171
137
  };
172
- const batchModuleOf = ({
173
- service,
174
- uses = {},
175
- useAsyncs = {},
176
- providers = []
177
- }) => {
178
- if (!isServiceEnabled(service))
179
- return null;
180
- let BatchModule = class {
181
- };
182
- BatchModule = __decorateClass([
183
- Global(),
184
- Module({
185
- imports: [],
186
- providers: [
187
- serviceOf(service),
188
- ...Object.entries(uses).map(([key, useValue]) => ({ provide: capitalize(key), useValue })),
189
- ...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
190
- ...providers
191
- ],
192
- exports: [service]
193
- })
194
- ], BatchModule);
195
- return BatchModule;
196
- };
197
- const useGlobals = ({ uses, useAsyncs, injects }) => {
138
+ const useGlobals = ({ uses, useAsyncs, providers = [], injects }) => {
198
139
  let GlobalsModule = class {
199
140
  };
200
141
  GlobalsModule = __decorateClass([
@@ -207,7 +148,8 @@ const useGlobals = ({ uses, useAsyncs, injects }) => {
207
148
  useValue
208
149
  })),
209
150
  ...Object.entries(useAsyncs ?? {}).map(([key, useFactory]) => ({ provide: capitalize(key), useFactory })),
210
- ...Object.entries(injects ?? {}).map(([key, inject]) => ({ provide: capitalize(key), useClass: inject }))
151
+ ...Object.entries(injects ?? {}).map(([key, inject]) => ({ provide: capitalize(key), useClass: inject })),
152
+ ...providers
211
153
  ],
212
154
  exports: [
213
155
  ...Object.keys(uses ?? {}).map((key) => capitalize(key)),
@@ -218,10 +160,20 @@ const useGlobals = ({ uses, useAsyncs, injects }) => {
218
160
  ], GlobalsModule);
219
161
  return GlobalsModule;
220
162
  };
163
+ const makeSigForSrv = (sigRef) => {
164
+ let Sig = class {
165
+ };
166
+ Sig = __decorateClass([
167
+ Injectable()
168
+ ], Sig);
169
+ if (hasWebsocket(sigRef))
170
+ applyWebsocketSignal(Sig, sigRef);
171
+ if (hasProcessor(sigRef))
172
+ applyQueueSignal(Sig, sigRef);
173
+ return Sig;
174
+ };
221
175
  export {
222
- batchModuleOf,
223
176
  databaseModuleOf,
224
- scalarModuleOf,
225
177
  scalarModulesOf,
226
178
  serviceModuleOf,
227
179
  useGlobals
@@ -1,12 +1,12 @@
1
1
  import { lowerlize } from "@akanjs/common";
2
- import { isServiceEnabled } from "@akanjs/service";
2
+ import { getServiceRefs, isServiceEnabled } from "@akanjs/service";
3
3
  import {
4
4
  deserializeArg,
5
5
  getArgMetas,
6
6
  getGqlMetas,
7
7
  getSigMeta
8
8
  } from "@akanjs/signal";
9
- import { Process, Processor } from "@nestjs/bull";
9
+ import { getQueueToken, Process, Processor } from "@nestjs/bull";
10
10
  import { Inject } from "@nestjs/common";
11
11
  const convertProcessFunction = (gqlMeta, argMetas, internalArgMetas, fn) => {
12
12
  return async function(job, done) {
@@ -33,14 +33,15 @@ const processorOf = (sigRef, allSrvs) => {
33
33
  const sigMeta = getSigMeta(sigRef);
34
34
  const serverMode = process.env.SERVER_MODE ?? "federation";
35
35
  const gqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Process").filter(
36
- (gqlMeta) => gqlMeta.signalOption.serverType === "all" || serverMode === "all" || gqlMeta.signalOption.serverType === serverMode
36
+ (gqlMeta) => gqlMeta.signalOption.serverMode === "all" || serverMode === "all" || gqlMeta.signalOption.serverMode === serverMode
37
37
  );
38
38
  class QueueProcessor {
39
39
  }
40
- Object.keys(allSrvs).forEach((srv) => {
41
- if (!isServiceEnabled(allSrvs[srv]))
40
+ Object.keys(allSrvs).forEach((srvName) => {
41
+ if (!isServiceEnabled(allSrvs[srvName]))
42
42
  return;
43
- Inject(allSrvs[srv])(QueueProcessor.prototype, lowerlize(srv));
43
+ const srvRef = getServiceRefs(srvName)[0];
44
+ Inject(srvRef)(QueueProcessor.prototype, lowerlize(srvName));
44
45
  });
45
46
  for (const gqlMeta of gqlMetas) {
46
47
  const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
@@ -57,17 +58,20 @@ const processorOf = (sigRef, allSrvs) => {
57
58
  Processor(sigMeta.refName)(QueueProcessor);
58
59
  return QueueProcessor;
59
60
  };
60
- const queueOf = (sigRef, queue) => {
61
+ const applyQueueSignal = (targetRef, sigRef) => {
61
62
  const sigMeta = getSigMeta(sigRef);
62
63
  const gqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Process");
64
+ Inject(getQueueToken(sigMeta.refName))(targetRef.prototype, "queue");
63
65
  for (const gqlMeta of gqlMetas) {
64
- if (queue[gqlMeta.key])
66
+ if (targetRef.prototype[gqlMeta.key])
65
67
  throw new Error(`Queue already has ${gqlMeta.key} in ${sigMeta.refName}`);
66
- queue[gqlMeta.key] = (...args) => queue.add(gqlMeta.key, args);
68
+ targetRef.prototype[gqlMeta.key] = function(...args) {
69
+ return this.queue.add(gqlMeta.key, args);
70
+ };
67
71
  }
68
- return queue;
72
+ return targetRef;
69
73
  };
70
74
  export {
71
- processorOf,
72
- queueOf
75
+ applyQueueSignal,
76
+ processorOf
73
77
  };
@@ -2,7 +2,7 @@ import { arraiedModel, Float, getNonArrayModel, ID, Int, JSON, Upload } from "@a
2
2
  import { capitalize, lowerlize } from "@akanjs/common";
3
3
  import { getClassMeta, getFieldMetas } from "@akanjs/constant";
4
4
  import { Access, Account, guards, Me, Req, Res, Self, UserIp } from "@akanjs/nest";
5
- import { isServiceEnabled } from "@akanjs/service";
5
+ import { getServiceRefs, isServiceEnabled } from "@akanjs/service";
6
6
  import {
7
7
  copySignal,
8
8
  getArgMetas,
@@ -45,10 +45,11 @@ const resolverOf = (sigRef, allSrvs) => {
45
45
  const Rsv = copySignal(sigRef);
46
46
  const sigMeta = getSigMeta(Rsv);
47
47
  const gqlMetas = getGqlMetas(Rsv);
48
- Object.keys(allSrvs).forEach((srv) => {
49
- if (!isServiceEnabled(allSrvs[srv]))
48
+ Object.keys(allSrvs).forEach((srvName) => {
49
+ if (!isServiceEnabled(allSrvs[srvName]))
50
50
  return;
51
- Inject(allSrvs[srv])(Rsv.prototype, lowerlize(srv));
51
+ const srvRef = getServiceRefs(srvName)[0];
52
+ Inject(srvRef)(Rsv.prototype, lowerlize(srvName));
52
53
  });
53
54
  for (const gqlMeta of gqlMetas) {
54
55
  if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "restapi" || !["Query", "Mutation"].includes(gqlMeta.type))