@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
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
5
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
6
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7
|
+
if (decorator = decorators[i])
|
|
8
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
+
if (kind && result)
|
|
10
|
+
__defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
var __publicField = (obj, key, value) => {
|
|
14
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
var __accessCheck = (obj, member, msg) => {
|
|
18
|
+
if (!member.has(obj))
|
|
19
|
+
throw TypeError("Cannot " + msg);
|
|
20
|
+
};
|
|
21
|
+
var __privateGet = (obj, member, getter) => {
|
|
22
|
+
__accessCheck(obj, member, "read from private field");
|
|
23
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
24
|
+
};
|
|
25
|
+
var __privateAdd = (obj, member, value) => {
|
|
26
|
+
if (member.has(obj))
|
|
27
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
28
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
29
|
+
};
|
|
30
|
+
import { lowerlize } from "@akanjs/common";
|
|
31
|
+
import { getAllServiceRefs, getServiceMeta } from "@akanjs/service";
|
|
32
|
+
import { getAllSignalRefs, getGqlMetas } from "@akanjs/signal";
|
|
33
|
+
import { Global, Inject, Injectable, Logger, Module } from "@nestjs/common";
|
|
34
|
+
import { CronJob } from "cron";
|
|
35
|
+
const makeScheduleModule = (serverMode, backendEnv) => {
|
|
36
|
+
var _cronMap, _timeoutMap, _intervalMap, _lockMap;
|
|
37
|
+
const srvRefs = getAllServiceRefs();
|
|
38
|
+
const sigRefs = getAllSignalRefs();
|
|
39
|
+
const initMetas = [];
|
|
40
|
+
const cronMetas = [];
|
|
41
|
+
const intervalMetas = [];
|
|
42
|
+
const timeoutMetas = [];
|
|
43
|
+
const destroyMetas = [];
|
|
44
|
+
sigRefs.forEach((sigRef) => {
|
|
45
|
+
const gqlMetas = getGqlMetas(sigRef);
|
|
46
|
+
gqlMetas.forEach((gqlMeta) => {
|
|
47
|
+
const { enabled, operationMode, serverMode: targetServerMode, scheduleType } = gqlMeta.signalOption;
|
|
48
|
+
if (gqlMeta.type !== "Schedule")
|
|
49
|
+
return;
|
|
50
|
+
else if (!enabled)
|
|
51
|
+
return;
|
|
52
|
+
else if (operationMode && !operationMode.includes(backendEnv.operationMode))
|
|
53
|
+
return;
|
|
54
|
+
else if (targetServerMode && targetServerMode !== "all" && serverMode !== "all" && targetServerMode !== serverMode)
|
|
55
|
+
return;
|
|
56
|
+
switch (scheduleType) {
|
|
57
|
+
case "init":
|
|
58
|
+
initMetas.push(gqlMeta);
|
|
59
|
+
break;
|
|
60
|
+
case "cron":
|
|
61
|
+
cronMetas.push(gqlMeta);
|
|
62
|
+
break;
|
|
63
|
+
case "interval":
|
|
64
|
+
intervalMetas.push(gqlMeta);
|
|
65
|
+
break;
|
|
66
|
+
case "timeout":
|
|
67
|
+
timeoutMetas.push(gqlMeta);
|
|
68
|
+
break;
|
|
69
|
+
case "destroy":
|
|
70
|
+
destroyMetas.push(gqlMeta);
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
let Schedule = class {
|
|
78
|
+
constructor() {
|
|
79
|
+
__publicField(this, "logger", new Logger("Schedule"));
|
|
80
|
+
__privateAdd(this, _cronMap, /* @__PURE__ */ new Map());
|
|
81
|
+
__privateAdd(this, _timeoutMap, /* @__PURE__ */ new Map());
|
|
82
|
+
__privateAdd(this, _intervalMap, /* @__PURE__ */ new Map());
|
|
83
|
+
__privateAdd(this, _lockMap, /* @__PURE__ */ new Map());
|
|
84
|
+
}
|
|
85
|
+
async onModuleInit() {
|
|
86
|
+
await Promise.all(
|
|
87
|
+
initMetas.map(async (gqlMeta) => {
|
|
88
|
+
const fn = gqlMeta.descriptor.value;
|
|
89
|
+
const before = Date.now();
|
|
90
|
+
this.logger.debug(`Init Before ${gqlMeta.key} / ${before}`);
|
|
91
|
+
await fn.apply(this);
|
|
92
|
+
const after = Date.now();
|
|
93
|
+
this.logger.debug(`Init After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
timeoutMetas.forEach((gqlMeta) => {
|
|
97
|
+
const fn = gqlMeta.descriptor.value;
|
|
98
|
+
const timeout = gqlMeta.signalOption.scheduleTime;
|
|
99
|
+
const timer = setTimeout(async () => {
|
|
100
|
+
const before = Date.now();
|
|
101
|
+
this.logger.debug(`Timemout Before ${gqlMeta.key} / ${before}`);
|
|
102
|
+
await fn.apply(this);
|
|
103
|
+
const after = Date.now();
|
|
104
|
+
this.logger.debug(`Timemout After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
105
|
+
__privateGet(this, _timeoutMap).delete(fn);
|
|
106
|
+
}, timeout);
|
|
107
|
+
__privateGet(this, _timeoutMap).set(fn, timer);
|
|
108
|
+
});
|
|
109
|
+
intervalMetas.forEach((gqlMeta) => {
|
|
110
|
+
const lock = gqlMeta.signalOption.lock;
|
|
111
|
+
const fn = gqlMeta.descriptor.value;
|
|
112
|
+
const interval = gqlMeta.signalOption.scheduleTime;
|
|
113
|
+
const timer = setInterval(async () => {
|
|
114
|
+
if (lock) {
|
|
115
|
+
if (__privateGet(this, _lockMap).get(fn)) {
|
|
116
|
+
this.logger.warn(`${gqlMeta.key} is locked, skipping...`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
__privateGet(this, _lockMap).set(fn, true);
|
|
120
|
+
}
|
|
121
|
+
const before = Date.now();
|
|
122
|
+
this.logger.debug(`Interval Before ${gqlMeta.key} / ${before}`);
|
|
123
|
+
await fn.apply(this);
|
|
124
|
+
const after = Date.now();
|
|
125
|
+
this.logger.debug(`Interval After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
126
|
+
if (lock)
|
|
127
|
+
__privateGet(this, _lockMap).set(fn, false);
|
|
128
|
+
}, interval);
|
|
129
|
+
__privateGet(this, _intervalMap).set(fn, timer);
|
|
130
|
+
});
|
|
131
|
+
cronMetas.forEach((gqlMeta) => {
|
|
132
|
+
const lock = gqlMeta.signalOption.lock;
|
|
133
|
+
const fn = gqlMeta.descriptor.value;
|
|
134
|
+
const cronTime = gqlMeta.signalOption.scheduleCron;
|
|
135
|
+
if (!cronTime)
|
|
136
|
+
throw new Error(`Cron time is not found for ${gqlMeta.key}`);
|
|
137
|
+
const cronJob = CronJob.from({
|
|
138
|
+
cronTime,
|
|
139
|
+
onTick: async () => {
|
|
140
|
+
if (lock) {
|
|
141
|
+
if (__privateGet(this, _lockMap).get(fn)) {
|
|
142
|
+
this.logger.warn(`${gqlMeta.key} is locked, skipping...`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
__privateGet(this, _lockMap).set(fn, true);
|
|
146
|
+
}
|
|
147
|
+
const before = Date.now();
|
|
148
|
+
this.logger.debug(`Cron Before ${gqlMeta.key} / ${before}`);
|
|
149
|
+
await fn.apply(this);
|
|
150
|
+
const after = Date.now();
|
|
151
|
+
this.logger.debug(`Cron After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
152
|
+
if (lock)
|
|
153
|
+
__privateGet(this, _lockMap).set(fn, false);
|
|
154
|
+
},
|
|
155
|
+
start: true
|
|
156
|
+
});
|
|
157
|
+
__privateGet(this, _cronMap).set(fn, cronJob);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async onModuleDestroy() {
|
|
161
|
+
__privateGet(this, _timeoutMap).forEach((timer, fn) => {
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
__privateGet(this, _timeoutMap).delete(fn);
|
|
164
|
+
});
|
|
165
|
+
__privateGet(this, _intervalMap).forEach((timer, fn) => {
|
|
166
|
+
clearInterval(timer);
|
|
167
|
+
__privateGet(this, _intervalMap).delete(fn);
|
|
168
|
+
});
|
|
169
|
+
await Promise.all(
|
|
170
|
+
[...__privateGet(this, _cronMap).entries()].map(async ([fn, cronJob]) => {
|
|
171
|
+
await cronJob.stop();
|
|
172
|
+
__privateGet(this, _cronMap).delete(fn);
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
await Promise.all(
|
|
176
|
+
destroyMetas.map(async (gqlMeta) => {
|
|
177
|
+
const fn = gqlMeta.descriptor.value;
|
|
178
|
+
const before = Date.now();
|
|
179
|
+
this.logger.debug(`Destroy Before ${gqlMeta.key} / ${before}`);
|
|
180
|
+
await fn.apply(this);
|
|
181
|
+
const after = Date.now();
|
|
182
|
+
this.logger.debug(`Destroy After ${gqlMeta.key} / ${after} (${after - before}ms)`);
|
|
183
|
+
})
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
_cronMap = new WeakMap();
|
|
188
|
+
_timeoutMap = new WeakMap();
|
|
189
|
+
_intervalMap = new WeakMap();
|
|
190
|
+
_lockMap = new WeakMap();
|
|
191
|
+
Schedule = __decorateClass([
|
|
192
|
+
Injectable()
|
|
193
|
+
], Schedule);
|
|
194
|
+
srvRefs.forEach((srvRef) => {
|
|
195
|
+
const serviceMeta = getServiceMeta(srvRef);
|
|
196
|
+
if (!serviceMeta)
|
|
197
|
+
throw new Error(`Service ${srvRef.name} is not found`);
|
|
198
|
+
Inject(srvRef)(Schedule.prototype, lowerlize(serviceMeta.name));
|
|
199
|
+
});
|
|
200
|
+
let ScheduleModule = class {
|
|
201
|
+
};
|
|
202
|
+
ScheduleModule = __decorateClass([
|
|
203
|
+
Global(),
|
|
204
|
+
Module({ providers: [Schedule] })
|
|
205
|
+
], ScheduleModule);
|
|
206
|
+
return ScheduleModule;
|
|
207
|
+
};
|
|
208
|
+
export {
|
|
209
|
+
makeScheduleModule
|
|
210
|
+
};
|
package/esm/src/schema.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
applyFnToArrayObjects,
|
|
3
|
+
arraiedModel,
|
|
4
|
+
dayjs,
|
|
5
|
+
Enum,
|
|
6
|
+
Float,
|
|
7
|
+
ID,
|
|
8
|
+
Int,
|
|
9
|
+
JSON
|
|
10
|
+
} from "@akanjs/base";
|
|
2
11
|
import { isDayjs } from "@akanjs/common";
|
|
3
12
|
import { getClassMeta, getFieldMetas, getFullModelRef, getInputModelRef } from "@akanjs/constant";
|
|
4
13
|
import { getDefaultSchemaOptions, ObjectId } from "@akanjs/document";
|
|
@@ -9,6 +18,24 @@ class ScalarSchemaStorage {
|
|
|
9
18
|
}
|
|
10
19
|
class SchemaStorage {
|
|
11
20
|
}
|
|
21
|
+
const getSchemaMetaByName = (refName) => {
|
|
22
|
+
const schemaMeta = Reflect.getMetadata(refName, SchemaStorage.prototype);
|
|
23
|
+
return schemaMeta;
|
|
24
|
+
};
|
|
25
|
+
const setSchemaMetaByName = (refName, schema) => {
|
|
26
|
+
Reflect.defineMetadata(refName, schema, SchemaStorage.prototype);
|
|
27
|
+
};
|
|
28
|
+
const hasSchema = (modelRef) => {
|
|
29
|
+
const classMeta = getClassMeta(modelRef);
|
|
30
|
+
return !!getSchemaMetaByName(classMeta.refName);
|
|
31
|
+
};
|
|
32
|
+
const getScalarSchemaMetaByName = (refName) => {
|
|
33
|
+
const schemaMeta = Reflect.getMetadata(refName, ScalarSchemaStorage.prototype);
|
|
34
|
+
return schemaMeta;
|
|
35
|
+
};
|
|
36
|
+
const setScalarSchemaMetaByName = (refName, schema) => {
|
|
37
|
+
Reflect.defineMetadata(refName, schema, ScalarSchemaStorage.prototype);
|
|
38
|
+
};
|
|
12
39
|
const scalarMongoTypeMap = /* @__PURE__ */ new Map([
|
|
13
40
|
[ID, ObjectId],
|
|
14
41
|
[Int, Number],
|
|
@@ -48,12 +75,12 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
|
|
|
48
75
|
}
|
|
49
76
|
prop = { type: arraiedModel(prop, fieldMeta.optArrDepth), default: [], required: true };
|
|
50
77
|
if (fieldMeta.modelRef.prototype === Date.prototype) {
|
|
51
|
-
prop.get = (dates) => dates
|
|
52
|
-
prop.set = (days) => days
|
|
78
|
+
prop.get = (dates) => applyFnToArrayObjects(dates, (date) => dayjs(date));
|
|
79
|
+
prop.set = (days) => applyFnToArrayObjects(days, (day) => day.toDate());
|
|
53
80
|
}
|
|
54
81
|
if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === ID.prototype) {
|
|
55
|
-
prop.get = (ids) => ids
|
|
56
|
-
prop.set = (ids) => ids
|
|
82
|
+
prop.get = (ids) => applyFnToArrayObjects(ids, (id) => id.toString());
|
|
83
|
+
prop.set = (ids) => applyFnToArrayObjects(ids, (id) => new Types.ObjectId(id));
|
|
57
84
|
}
|
|
58
85
|
} else {
|
|
59
86
|
prop.type = arraiedModel(type, fieldMeta.arrDepth);
|
|
@@ -95,12 +122,17 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
|
|
|
95
122
|
prop.set = (v) => v === null ? void 0 : v;
|
|
96
123
|
}
|
|
97
124
|
if (fieldMeta.modelRef.prototype === Date.prototype) {
|
|
98
|
-
prop.get = (date) => date ? dayjs(
|
|
99
|
-
prop.set = (day) => day ? dayjs(
|
|
125
|
+
prop.get = (date) => applyFnToArrayObjects(date, (date2) => date2 ? dayjs(date2) : void 0);
|
|
126
|
+
prop.set = (day) => applyFnToArrayObjects(day, (day2) => day2 ? dayjs(day2).toDate() : void 0);
|
|
100
127
|
}
|
|
101
128
|
if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === ID.prototype) {
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
if (fieldMeta.arrDepth === 0) {
|
|
130
|
+
prop.get = (id) => id ? id.toString() : void 0;
|
|
131
|
+
prop.set = (id) => id ? new Types.ObjectId(id) : void 0;
|
|
132
|
+
} else {
|
|
133
|
+
prop.get = (val) => applyFnToArrayObjects(val, (id) => id ? id.toString() : void 0);
|
|
134
|
+
prop.set = (val) => applyFnToArrayObjects(val, (id) => id ? new Types.ObjectId(id) : void 0);
|
|
135
|
+
}
|
|
104
136
|
}
|
|
105
137
|
if (fieldMeta.isClass && fieldMeta.isScalar && fieldMeta.default === null && !fieldMeta.nullable) {
|
|
106
138
|
prop.default = makeDefault(fieldMeta.modelRef);
|
|
@@ -115,7 +147,7 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
|
|
|
115
147
|
};
|
|
116
148
|
const createSchema = (modelRef) => {
|
|
117
149
|
const classMeta = getClassMeta(modelRef);
|
|
118
|
-
const schemaMeta =
|
|
150
|
+
const schemaMeta = getScalarSchemaMetaByName(classMeta.refName);
|
|
119
151
|
if (schemaMeta)
|
|
120
152
|
return schemaMeta;
|
|
121
153
|
const fieldMetas = getFieldMetas(modelRef);
|
|
@@ -124,12 +156,12 @@ const createSchema = (modelRef) => {
|
|
|
124
156
|
applyMongoProp(schemaProps, fieldMeta);
|
|
125
157
|
});
|
|
126
158
|
const schema = new Schema(schemaProps);
|
|
127
|
-
|
|
159
|
+
setScalarSchemaMetaByName(classMeta.refName, schema);
|
|
128
160
|
return schema;
|
|
129
161
|
};
|
|
130
162
|
const schemaOf = (modelRef, docRef, middleware) => {
|
|
131
163
|
const classMeta = getClassMeta(docRef);
|
|
132
|
-
const schemaMeta =
|
|
164
|
+
const schemaMeta = getSchemaMetaByName(classMeta.refName);
|
|
133
165
|
if (schemaMeta)
|
|
134
166
|
return schemaMeta;
|
|
135
167
|
const fieldMetas = getFieldMetas(docRef);
|
|
@@ -169,7 +201,7 @@ const schemaOf = (modelRef, docRef, middleware) => {
|
|
|
169
201
|
const onSchema = Object.getOwnPropertyDescriptor(middleware.prototype, "onSchema")?.value;
|
|
170
202
|
onSchema?.(schema);
|
|
171
203
|
schema.index({ removedAt: -1 });
|
|
172
|
-
|
|
204
|
+
setSchemaMetaByName(classMeta.refName, schema);
|
|
173
205
|
return schema;
|
|
174
206
|
};
|
|
175
207
|
const addSchema = (modelRef, docRef, inputRef, middleware) => {
|
|
@@ -215,5 +247,6 @@ const addSchema = (modelRef, docRef, inputRef, middleware) => {
|
|
|
215
247
|
};
|
|
216
248
|
export {
|
|
217
249
|
addSchema,
|
|
250
|
+
hasSchema,
|
|
218
251
|
schemaOf
|
|
219
252
|
};
|
package/esm/src/searchDaemon.js
CHANGED
|
@@ -202,9 +202,7 @@ let SearchDaemonModule = class {
|
|
|
202
202
|
};
|
|
203
203
|
SearchDaemonModule = __decorateClass([
|
|
204
204
|
Global(),
|
|
205
|
-
Module({
|
|
206
|
-
providers: [SearchDaemon]
|
|
207
|
-
})
|
|
205
|
+
Module({ providers: [SearchDaemon] })
|
|
208
206
|
], SearchDaemonModule);
|
|
209
207
|
export {
|
|
210
208
|
SearchDaemonModule,
|
package/esm/src/websocket.js
CHANGED
|
@@ -11,7 +11,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
11
11
|
};
|
|
12
12
|
import { lowerlize } from "@akanjs/common";
|
|
13
13
|
import { Access, Account, getBodyPipes, Me, Self, UserIp, Ws } from "@akanjs/nest";
|
|
14
|
-
import { isServiceEnabled } from "@akanjs/service";
|
|
14
|
+
import { getServiceRefs, isServiceEnabled } from "@akanjs/service";
|
|
15
15
|
import { getArgMetas, getGqlMetas, getSigMeta } from "@akanjs/signal";
|
|
16
16
|
import { Inject, Injectable, UseInterceptors } from "@nestjs/common";
|
|
17
17
|
import { MessageBody, SubscribeMessage, WebSocketGateway, WebSocketServer } from "@nestjs/websockets";
|
|
@@ -52,10 +52,11 @@ const websocketOf = (sigRef, allSrvs) => {
|
|
|
52
52
|
class WsGateway {
|
|
53
53
|
__sigRef__ = sigRef;
|
|
54
54
|
}
|
|
55
|
-
Object.keys(allSrvs).forEach((
|
|
56
|
-
if (!isServiceEnabled(allSrvs[
|
|
55
|
+
Object.keys(allSrvs).forEach((srvName) => {
|
|
56
|
+
if (!isServiceEnabled(allSrvs[srvName]))
|
|
57
57
|
return;
|
|
58
|
-
|
|
58
|
+
const srvRef = getServiceRefs(srvName)[0];
|
|
59
|
+
Inject(srvRef)(WsGateway.prototype, lowerlize(srvName));
|
|
59
60
|
});
|
|
60
61
|
const messageGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
|
|
61
62
|
for (const gqlMeta of messageGqlMetas) {
|
|
@@ -94,31 +95,23 @@ const websocketOf = (sigRef, allSrvs) => {
|
|
|
94
95
|
WebSocketGateway({ cors: { origin: "*" }, transports: ["websocket"] })(WsGateway);
|
|
95
96
|
return WsGateway;
|
|
96
97
|
};
|
|
97
|
-
const
|
|
98
|
+
const applyWebsocketSignal = (targetRef, sigRef) => {
|
|
98
99
|
const pubsubGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
__decorateClass([
|
|
103
|
-
WebSocketServer()
|
|
104
|
-
], Websocket.prototype, "server", 2);
|
|
105
|
-
Websocket = __decorateClass([
|
|
106
|
-
Injectable(),
|
|
107
|
-
WebSocketGateway({ cors: { origin: "*" }, transports: ["websocket"] })
|
|
108
|
-
], Websocket);
|
|
100
|
+
WebSocketGateway({ cors: { origin: "*" }, transports: ["websocket"] })(targetRef);
|
|
101
|
+
WebSocketServer()(targetRef.prototype, "websocket");
|
|
109
102
|
for (const gqlMeta of pubsubGqlMetas) {
|
|
110
103
|
const [argMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
111
|
-
|
|
104
|
+
targetRef.prototype[gqlMeta.key] = function(...args) {
|
|
112
105
|
const roomId = makeRoomId(
|
|
113
106
|
gqlMeta.key,
|
|
114
107
|
argMetas.map((argMeta) => args[argMeta.idx])
|
|
115
108
|
);
|
|
116
|
-
this.
|
|
109
|
+
this.websocket.to(roomId).emit(roomId, args.at(-1));
|
|
117
110
|
};
|
|
118
111
|
}
|
|
119
|
-
return
|
|
112
|
+
return targetRef;
|
|
120
113
|
};
|
|
121
114
|
export {
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
applyWebsocketSignal,
|
|
116
|
+
websocketOf
|
|
124
117
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/server",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.43",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@nestjs/websockets": "^10.4.15",
|
|
31
31
|
"body-parser": "^1.20.3",
|
|
32
32
|
"cookie-parser": "^1.4.7",
|
|
33
|
+
"cron": "^4.3.3",
|
|
33
34
|
"dayjs": "^1.11.13",
|
|
34
35
|
"graphql": "^16.10.0",
|
|
35
36
|
"graphql-type-json": "^0.3.2",
|
package/src/module.d.ts
CHANGED
|
@@ -7,44 +7,15 @@ interface DatabaseModuleCreateOptions {
|
|
|
7
7
|
database: Database<string, any, any, any, any, any, any, any, any>;
|
|
8
8
|
signal: Type;
|
|
9
9
|
service: Type;
|
|
10
|
-
uses?: {
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
};
|
|
13
|
-
useAsyncs?: {
|
|
14
|
-
[key: string]: () => Promise<any>;
|
|
15
|
-
};
|
|
16
|
-
providers?: Type[];
|
|
17
|
-
extended?: boolean;
|
|
18
10
|
}
|
|
19
|
-
export declare const databaseModuleOf: ({ constant, database, signal, service
|
|
11
|
+
export declare const databaseModuleOf: ({ constant, database, signal, service }: DatabaseModuleCreateOptions, allSrvs: {
|
|
20
12
|
[key: string]: Type | undefined;
|
|
21
13
|
}) => DynamicModule | null;
|
|
22
14
|
interface ServiceModuleCreateOptions {
|
|
23
|
-
signal
|
|
15
|
+
signal?: Type;
|
|
24
16
|
service: Type;
|
|
25
|
-
uses?: {
|
|
26
|
-
[key: string]: any;
|
|
27
|
-
};
|
|
28
|
-
useAsyncs?: {
|
|
29
|
-
[key: string]: () => Promise<any>;
|
|
30
|
-
};
|
|
31
|
-
providers?: Type[];
|
|
32
17
|
}
|
|
33
|
-
export declare const serviceModuleOf: ({ signal, service
|
|
34
|
-
[key: string]: Type | undefined;
|
|
35
|
-
}) => DynamicModule | null;
|
|
36
|
-
interface ScalarModuleCreateOptions {
|
|
37
|
-
signals: Type[];
|
|
38
|
-
uses?: {
|
|
39
|
-
[key: string]: any;
|
|
40
|
-
};
|
|
41
|
-
useAsyncs?: {
|
|
42
|
-
[key: string]: () => Promise<any>;
|
|
43
|
-
};
|
|
44
|
-
providers?: Type[];
|
|
45
|
-
enabled?: boolean;
|
|
46
|
-
}
|
|
47
|
-
export declare const scalarModuleOf: ({ signals, uses, useAsyncs, providers, enabled }: ScalarModuleCreateOptions, allSrvs: {
|
|
18
|
+
export declare const serviceModuleOf: ({ signal, service }: ServiceModuleCreateOptions, allSrvs: {
|
|
48
19
|
[key: string]: Type | undefined;
|
|
49
20
|
}) => DynamicModule | null;
|
|
50
21
|
interface ScalarModulesCreateOptions {
|
|
@@ -53,17 +24,6 @@ interface ScalarModulesCreateOptions {
|
|
|
53
24
|
export declare const scalarModulesOf: ({ constants }: ScalarModulesCreateOptions, allSrvs: {
|
|
54
25
|
[key: string]: Type | undefined;
|
|
55
26
|
}) => DynamicModule | null;
|
|
56
|
-
interface BatchModuleCreateOptions {
|
|
57
|
-
service: Type;
|
|
58
|
-
uses?: {
|
|
59
|
-
[key: string]: any;
|
|
60
|
-
};
|
|
61
|
-
useAsyncs?: {
|
|
62
|
-
[key: string]: () => Promise<any>;
|
|
63
|
-
};
|
|
64
|
-
providers?: Type[];
|
|
65
|
-
}
|
|
66
|
-
export declare const batchModuleOf: ({ service, uses, useAsyncs, providers, }: BatchModuleCreateOptions) => DynamicModule | null;
|
|
67
27
|
interface UseGlobalsCreateOptions {
|
|
68
28
|
uses?: {
|
|
69
29
|
[key: string]: any;
|
|
@@ -71,9 +31,10 @@ interface UseGlobalsCreateOptions {
|
|
|
71
31
|
useAsyncs?: {
|
|
72
32
|
[key: string]: () => Promise<any>;
|
|
73
33
|
};
|
|
34
|
+
providers?: Type[];
|
|
74
35
|
injects?: {
|
|
75
36
|
[key: string]: Type;
|
|
76
37
|
};
|
|
77
38
|
}
|
|
78
|
-
export declare const useGlobals: ({ uses, useAsyncs, injects }: UseGlobalsCreateOptions) => DynamicModule;
|
|
39
|
+
export declare const useGlobals: ({ uses, useAsyncs, providers, injects }: UseGlobalsCreateOptions) => DynamicModule;
|
|
79
40
|
export {};
|
package/src/processor.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Type } from "@akanjs/base";
|
|
2
|
-
import type { Queue } from "bull";
|
|
3
2
|
export declare const processorOf: (sigRef: Type, allSrvs: {
|
|
4
3
|
[key: string]: Type;
|
|
5
4
|
}) => {
|
|
6
5
|
new (): {};
|
|
7
6
|
};
|
|
8
|
-
export declare const
|
|
7
|
+
export declare const applyQueueSignal: (targetRef: Type, sigRef: Type) => Type;
|
package/src/schema.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from "@akanjs/base";
|
|
2
2
|
import { BaseMiddleware } from "@akanjs/document";
|
|
3
3
|
import { Schema } from "mongoose";
|
|
4
|
+
export declare const hasSchema: (modelRef: Type) => boolean;
|
|
4
5
|
export declare const schemaOf: <Mdl, Doc, Middleware extends BaseMiddleware>(modelRef: Type<Mdl>, docRef: Type<Doc>, middleware: Type<Middleware>) => Schema<null, Mdl, Doc, undefined, null, Mdl>;
|
|
5
6
|
export declare const addSchema: <Mdl, Doc, Input, Middleware extends BaseMiddleware>(modelRef: Type<Mdl>, docRef: Type<Doc>, inputRef: Type<Input>, middleware: Type<Middleware>) => Schema<null, Mdl, Doc, undefined, null, Mdl>;
|
package/src/websocket.d.ts
CHANGED
|
@@ -10,8 +10,6 @@ export declare const websocketOf: (sigRef: Type, allSrvs: {
|
|
|
10
10
|
__sigRef__: Type;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
export declare const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
};
|
|
13
|
+
export declare const applyWebsocketSignal: (targetRef: Type, sigRef: Type) => Type<{
|
|
14
|
+
websocket: Server;
|
|
15
|
+
}>;
|