@akanjs/server 0.0.97 → 0.0.99
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.cjs +21 -0
- package/index.js +1 -21
- package/package.json +4 -4
- package/src/boot.cjs +200 -0
- package/src/boot.js +84 -94
- package/src/controller.cjs +102 -0
- package/src/controller.js +70 -63
- package/src/gql.cjs +152 -0
- package/src/gql.js +35 -64
- package/src/index.cjs +39 -0
- package/src/index.js +10 -39
- package/src/module.cjs +255 -0
- package/src/module.js +77 -103
- package/src/processor.cjs +92 -0
- package/src/processor.js +22 -41
- package/src/resolver.cjs +145 -0
- package/src/resolver.js +49 -76
- package/src/{schema.mjs → schema.cjs} +78 -54
- package/src/schema.js +54 -78
- package/src/{searchDaemon.mjs → searchDaemon.cjs} +45 -29
- package/src/searchDaemon.js +29 -45
- package/src/types.cjs +15 -0
- package/src/types.js +0 -15
- package/src/websocket.cjs +146 -0
- package/src/websocket.js +33 -55
- package/index.mjs +0 -1
- package/src/boot.mjs +0 -190
- package/src/controller.mjs +0 -109
- package/src/gql.mjs +0 -123
- package/src/index.mjs +0 -10
- package/src/module.mjs +0 -229
- package/src/processor.mjs +0 -73
- package/src/resolver.mjs +0 -118
- package/src/types.mjs +0 -0
- package/src/websocket.mjs +0 -124
package/src/searchDaemon.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
3
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
19
4
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
5
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -25,19 +10,19 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
10
|
return result;
|
|
26
11
|
};
|
|
27
12
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
import { Logger, lowerlize } from "@akanjs/common";
|
|
14
|
+
import {
|
|
15
|
+
getCnstMeta,
|
|
16
|
+
getFieldMetaMap,
|
|
17
|
+
getFieldMetas,
|
|
18
|
+
getFilterSortMap,
|
|
19
|
+
getFullModelRef
|
|
20
|
+
} from "@akanjs/constant";
|
|
21
|
+
import { getAllDatabaseModelNames } from "@akanjs/document";
|
|
22
|
+
import { Global, Inject, Injectable, Module } from "@nestjs/common";
|
|
23
|
+
import { InjectConnection } from "@nestjs/mongoose";
|
|
39
24
|
const hasTextField = (modelRef) => {
|
|
40
|
-
const fieldMetas =
|
|
25
|
+
const fieldMetas = getFieldMetas(modelRef);
|
|
41
26
|
return fieldMetas.some(
|
|
42
27
|
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
43
28
|
);
|
|
@@ -45,7 +30,7 @@ const hasTextField = (modelRef) => {
|
|
|
45
30
|
const getTextFieldKeys = (modelRef) => {
|
|
46
31
|
const allSearchFields = [];
|
|
47
32
|
const allFilterFields = [];
|
|
48
|
-
const fieldMetaMap =
|
|
33
|
+
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
49
34
|
const fieldMetas = [...fieldMetaMap.values()];
|
|
50
35
|
const stringTextFields = fieldMetas.filter((fieldMeta) => !!fieldMeta.text).map((fieldMeta) => {
|
|
51
36
|
if (fieldMeta.text === "filter")
|
|
@@ -80,7 +65,7 @@ const getTextFieldKeys = (modelRef) => {
|
|
|
80
65
|
};
|
|
81
66
|
};
|
|
82
67
|
const makeTextFilter = (modelRef) => {
|
|
83
|
-
const fieldMetaMap =
|
|
68
|
+
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
84
69
|
const { stringTextFields, scalarTextFields } = getTextFieldKeys(modelRef);
|
|
85
70
|
const filterData = (data, assignObj = {}) => {
|
|
86
71
|
if (Array.isArray(data))
|
|
@@ -102,8 +87,8 @@ const makeTextFilter = (modelRef) => {
|
|
|
102
87
|
return filterData;
|
|
103
88
|
};
|
|
104
89
|
const getSortableAttributes = (refName) => {
|
|
105
|
-
const cnst =
|
|
106
|
-
const sortMap =
|
|
90
|
+
const cnst = getCnstMeta(refName);
|
|
91
|
+
const sortMap = getFilterSortMap(cnst.Filter);
|
|
107
92
|
const sortFields = Object.values(sortMap).filter((val) => typeof val === "object").map((sort) => Object.keys(sort)).flat();
|
|
108
93
|
return [...new Set(sortFields)];
|
|
109
94
|
};
|
|
@@ -112,16 +97,16 @@ let SearchDaemon = class {
|
|
|
112
97
|
this.connection = connection;
|
|
113
98
|
this.meili = meili;
|
|
114
99
|
}
|
|
115
|
-
logger = new
|
|
100
|
+
logger = new Logger("SearchDaemon");
|
|
116
101
|
async onModuleInit() {
|
|
117
|
-
const databaseModelNames =
|
|
102
|
+
const databaseModelNames = getAllDatabaseModelNames();
|
|
118
103
|
const indexes = (await this.meili.getIndexes({ limit: 1e3 })).results;
|
|
119
104
|
const indexMap = new Map(indexes.map((index) => [index.uid, index]));
|
|
120
105
|
const indexCreationNames = [];
|
|
121
106
|
const indexUpdateNames = [];
|
|
122
107
|
for (const modelName of databaseModelNames) {
|
|
123
|
-
const indexName =
|
|
124
|
-
const modelRef =
|
|
108
|
+
const indexName = lowerlize(modelName);
|
|
109
|
+
const modelRef = getFullModelRef(modelName);
|
|
125
110
|
if (!hasTextField(modelRef))
|
|
126
111
|
continue;
|
|
127
112
|
const index = indexMap.get(indexName);
|
|
@@ -135,9 +120,9 @@ let SearchDaemon = class {
|
|
|
135
120
|
for (const indexName of indexUpdateNames)
|
|
136
121
|
await this.meili.updateIndex(indexName, { primaryKey: "id" });
|
|
137
122
|
for (const modelName of databaseModelNames) {
|
|
138
|
-
const indexName =
|
|
123
|
+
const indexName = lowerlize(modelName);
|
|
139
124
|
const model = this.connection.models[modelName];
|
|
140
|
-
const modelRef =
|
|
125
|
+
const modelRef = getFullModelRef(modelName);
|
|
141
126
|
if (!hasTextField(modelRef))
|
|
142
127
|
continue;
|
|
143
128
|
const searchIndex = this.meili.index(indexName);
|
|
@@ -209,20 +194,19 @@ let SearchDaemon = class {
|
|
|
209
194
|
}
|
|
210
195
|
};
|
|
211
196
|
SearchDaemon = __decorateClass([
|
|
212
|
-
|
|
213
|
-
__decorateParam(0,
|
|
214
|
-
__decorateParam(1,
|
|
197
|
+
Injectable(),
|
|
198
|
+
__decorateParam(0, InjectConnection()),
|
|
199
|
+
__decorateParam(1, Inject("MEILI_CLIENT"))
|
|
215
200
|
], SearchDaemon);
|
|
216
201
|
let SearchDaemonModule = class {
|
|
217
202
|
};
|
|
218
203
|
SearchDaemonModule = __decorateClass([
|
|
219
|
-
|
|
220
|
-
|
|
204
|
+
Global(),
|
|
205
|
+
Module({
|
|
221
206
|
providers: [SearchDaemon]
|
|
222
207
|
})
|
|
223
208
|
], SearchDaemonModule);
|
|
224
|
-
|
|
225
|
-
0 && (module.exports = {
|
|
209
|
+
export {
|
|
226
210
|
SearchDaemonModule,
|
|
227
211
|
makeTextFilter
|
|
228
|
-
}
|
|
212
|
+
};
|
package/src/types.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
package/src/types.js
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var types_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
19
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
21
|
+
if (decorator = decorators[i])
|
|
22
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
23
|
+
if (kind && result)
|
|
24
|
+
__defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var websocket_exports = {};
|
|
28
|
+
__export(websocket_exports, {
|
|
29
|
+
websocketOf: () => websocketOf,
|
|
30
|
+
websocketServerOf: () => websocketServerOf
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(websocket_exports);
|
|
33
|
+
var import_common = require("@akanjs/common");
|
|
34
|
+
var import_nest = require("@akanjs/nest");
|
|
35
|
+
var import_service = require("@akanjs/service");
|
|
36
|
+
var import_signal = require("@akanjs/signal");
|
|
37
|
+
var import_common2 = require("@nestjs/common");
|
|
38
|
+
var import_websockets = require("@nestjs/websockets");
|
|
39
|
+
var import_operators = require("rxjs/operators");
|
|
40
|
+
const internalArgMap = { Account: import_nest.Account, UserIp: import_nest.UserIp, Access: import_nest.Access, Self: import_nest.Self, Me: import_nest.Me, Ws: import_nest.Ws };
|
|
41
|
+
let TransformInterceptor = class {
|
|
42
|
+
intercept(context, next) {
|
|
43
|
+
const [, gqlKey] = [context.getArgByIndex(1), context.getArgByIndex(3)];
|
|
44
|
+
return next.handle().pipe((0, import_operators.map)((data) => ({ event: gqlKey, data })));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
TransformInterceptor = __decorateClass([
|
|
48
|
+
(0, import_common2.Injectable)()
|
|
49
|
+
], TransformInterceptor);
|
|
50
|
+
const makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
51
|
+
const getPubsubInterceptor = (argMetas) => {
|
|
52
|
+
let PubsubInterceptor = class {
|
|
53
|
+
async intercept(context, next) {
|
|
54
|
+
const [socket, { __subscribe__, ...body }, gqlKey] = [context.getArgByIndex(0), context.getArgByIndex(1), context.getArgByIndex(3)];
|
|
55
|
+
const roomId = makeRoomId(
|
|
56
|
+
gqlKey,
|
|
57
|
+
argMetas.map((argMeta) => body[argMeta.name])
|
|
58
|
+
);
|
|
59
|
+
if (__subscribe__)
|
|
60
|
+
await socket.join(roomId);
|
|
61
|
+
else
|
|
62
|
+
await socket.leave(roomId);
|
|
63
|
+
return next.handle().pipe((0, import_operators.map)(() => ({ event: gqlKey, data: { roomId, __subscribe__ } })));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
PubsubInterceptor = __decorateClass([
|
|
67
|
+
(0, import_common2.Injectable)()
|
|
68
|
+
], PubsubInterceptor);
|
|
69
|
+
return PubsubInterceptor;
|
|
70
|
+
};
|
|
71
|
+
const websocketOf = (sigRef, allSrvs) => {
|
|
72
|
+
const sigMeta = (0, import_signal.getSigMeta)(sigRef);
|
|
73
|
+
class WsGateway {
|
|
74
|
+
__sigRef__ = sigRef;
|
|
75
|
+
}
|
|
76
|
+
Object.keys(allSrvs).forEach((srv) => {
|
|
77
|
+
if (!(0, import_service.isServiceEnabled)(allSrvs[srv]))
|
|
78
|
+
return;
|
|
79
|
+
(0, import_common2.Inject)(allSrvs[srv])(WsGateway.prototype, (0, import_common.lowerlize)(srv));
|
|
80
|
+
});
|
|
81
|
+
const messageGqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
|
|
82
|
+
for (const gqlMeta of messageGqlMetas) {
|
|
83
|
+
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
84
|
+
Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
85
|
+
const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
|
|
86
|
+
argMetas.forEach((argMeta) => {
|
|
87
|
+
if (argMeta.type !== "Msg")
|
|
88
|
+
throw new Error(`Argument of Message should be Msg ${sigMeta.refName}-${gqlMeta.key}-${argMeta.name}`);
|
|
89
|
+
(0, import_websockets.MessageBody)(argMeta.name, ...(0, import_nest.getBodyPipes)(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
90
|
+
});
|
|
91
|
+
internalArgMetas.forEach((internalArgMeta) => {
|
|
92
|
+
const internalDecorator = internalArgMap[internalArgMeta.type];
|
|
93
|
+
internalDecorator(internalArgMeta.option ?? {})(WsGateway.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
94
|
+
});
|
|
95
|
+
(0, import_common2.UseInterceptors)(TransformInterceptor)(WsGateway.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
96
|
+
(0, import_websockets.SubscribeMessage)(gqlMeta.key)(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
97
|
+
}
|
|
98
|
+
const pubsubGqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
99
|
+
for (const gqlMeta of pubsubGqlMetas) {
|
|
100
|
+
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
101
|
+
Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
102
|
+
const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
|
|
103
|
+
argMetas.forEach((argMeta) => {
|
|
104
|
+
if (argMeta.type !== "Room")
|
|
105
|
+
throw new Error(`Argument of Message should be Room ${sigMeta.refName}-${gqlMeta.key}-${argMeta.name}`);
|
|
106
|
+
(0, import_websockets.MessageBody)(argMeta.name, ...(0, import_nest.getBodyPipes)(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
107
|
+
});
|
|
108
|
+
internalArgMetas.forEach((internalArgMeta) => {
|
|
109
|
+
const internalDecorator = internalArgMap[internalArgMeta.type];
|
|
110
|
+
internalDecorator(internalArgMeta.option ?? {})(WsGateway.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
111
|
+
});
|
|
112
|
+
(0, import_common2.UseInterceptors)(getPubsubInterceptor(argMetas))(WsGateway.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
113
|
+
(0, import_websockets.SubscribeMessage)(gqlMeta.key)(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
114
|
+
}
|
|
115
|
+
(0, import_websockets.WebSocketGateway)({ cors: { origin: "*" }, transports: ["websocket"] })(WsGateway);
|
|
116
|
+
return WsGateway;
|
|
117
|
+
};
|
|
118
|
+
const websocketServerOf = (sigRef) => {
|
|
119
|
+
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);
|
|
130
|
+
for (const gqlMeta of pubsubGqlMetas) {
|
|
131
|
+
const [argMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
|
|
132
|
+
Websocket.prototype[gqlMeta.key] = function(...args) {
|
|
133
|
+
const roomId = makeRoomId(
|
|
134
|
+
gqlMeta.key,
|
|
135
|
+
argMetas.map((argMeta) => args[argMeta.idx])
|
|
136
|
+
);
|
|
137
|
+
this.server.to(roomId).emit(roomId, args.at(-1));
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return Websocket;
|
|
141
|
+
};
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
websocketOf,
|
|
145
|
+
websocketServerOf
|
|
146
|
+
});
|
package/src/websocket.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
3
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
19
4
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
5
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -24,28 +9,22 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
24
9
|
__defProp(target, key, result);
|
|
25
10
|
return result;
|
|
26
11
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var import_service = require("@akanjs/service");
|
|
36
|
-
var import_signal = require("@akanjs/signal");
|
|
37
|
-
var import_common2 = require("@nestjs/common");
|
|
38
|
-
var import_websockets = require("@nestjs/websockets");
|
|
39
|
-
var import_operators = require("rxjs/operators");
|
|
40
|
-
const internalArgMap = { Account: import_nest.Account, UserIp: import_nest.UserIp, Access: import_nest.Access, Self: import_nest.Self, Me: import_nest.Me, Ws: import_nest.Ws };
|
|
12
|
+
import { lowerlize } from "@akanjs/common";
|
|
13
|
+
import { Access, Account, getBodyPipes, Me, Self, UserIp, Ws } from "@akanjs/nest";
|
|
14
|
+
import { isServiceEnabled } from "@akanjs/service";
|
|
15
|
+
import { getArgMetas, getGqlMetas, getSigMeta } from "@akanjs/signal";
|
|
16
|
+
import { Inject, Injectable, UseInterceptors } from "@nestjs/common";
|
|
17
|
+
import { MessageBody, SubscribeMessage, WebSocketGateway, WebSocketServer } from "@nestjs/websockets";
|
|
18
|
+
import { map } from "rxjs/operators";
|
|
19
|
+
const internalArgMap = { Account, UserIp, Access, Self, Me, Ws };
|
|
41
20
|
let TransformInterceptor = class {
|
|
42
21
|
intercept(context, next) {
|
|
43
22
|
const [, gqlKey] = [context.getArgByIndex(1), context.getArgByIndex(3)];
|
|
44
|
-
return next.handle().pipe(
|
|
23
|
+
return next.handle().pipe(map((data) => ({ event: gqlKey, data })));
|
|
45
24
|
}
|
|
46
25
|
};
|
|
47
26
|
TransformInterceptor = __decorateClass([
|
|
48
|
-
|
|
27
|
+
Injectable()
|
|
49
28
|
], TransformInterceptor);
|
|
50
29
|
const makeRoomId = (gqlKey, argValues) => `${gqlKey}-${argValues.join("-")}`;
|
|
51
30
|
const getPubsubInterceptor = (argMetas) => {
|
|
@@ -60,75 +39,75 @@ const getPubsubInterceptor = (argMetas) => {
|
|
|
60
39
|
await socket.join(roomId);
|
|
61
40
|
else
|
|
62
41
|
await socket.leave(roomId);
|
|
63
|
-
return next.handle().pipe(
|
|
42
|
+
return next.handle().pipe(map(() => ({ event: gqlKey, data: { roomId, __subscribe__ } })));
|
|
64
43
|
}
|
|
65
44
|
};
|
|
66
45
|
PubsubInterceptor = __decorateClass([
|
|
67
|
-
|
|
46
|
+
Injectable()
|
|
68
47
|
], PubsubInterceptor);
|
|
69
48
|
return PubsubInterceptor;
|
|
70
49
|
};
|
|
71
50
|
const websocketOf = (sigRef, allSrvs) => {
|
|
72
|
-
const sigMeta =
|
|
51
|
+
const sigMeta = getSigMeta(sigRef);
|
|
73
52
|
class WsGateway {
|
|
74
53
|
__sigRef__ = sigRef;
|
|
75
54
|
}
|
|
76
55
|
Object.keys(allSrvs).forEach((srv) => {
|
|
77
|
-
if (!
|
|
56
|
+
if (!isServiceEnabled(allSrvs[srv]))
|
|
78
57
|
return;
|
|
79
|
-
|
|
58
|
+
Inject(allSrvs[srv])(WsGateway.prototype, lowerlize(srv));
|
|
80
59
|
});
|
|
81
|
-
const messageGqlMetas =
|
|
60
|
+
const messageGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
|
|
82
61
|
for (const gqlMeta of messageGqlMetas) {
|
|
83
62
|
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
84
63
|
Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
85
|
-
const [argMetas, internalArgMetas] =
|
|
64
|
+
const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
86
65
|
argMetas.forEach((argMeta) => {
|
|
87
66
|
if (argMeta.type !== "Msg")
|
|
88
67
|
throw new Error(`Argument of Message should be Msg ${sigMeta.refName}-${gqlMeta.key}-${argMeta.name}`);
|
|
89
|
-
|
|
68
|
+
MessageBody(argMeta.name, ...getBodyPipes(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
90
69
|
});
|
|
91
70
|
internalArgMetas.forEach((internalArgMeta) => {
|
|
92
71
|
const internalDecorator = internalArgMap[internalArgMeta.type];
|
|
93
72
|
internalDecorator(internalArgMeta.option ?? {})(WsGateway.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
94
73
|
});
|
|
95
|
-
|
|
96
|
-
|
|
74
|
+
UseInterceptors(TransformInterceptor)(WsGateway.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
75
|
+
SubscribeMessage(gqlMeta.key)(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
97
76
|
}
|
|
98
|
-
const pubsubGqlMetas =
|
|
77
|
+
const pubsubGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
99
78
|
for (const gqlMeta of pubsubGqlMetas) {
|
|
100
79
|
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
101
80
|
Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
102
|
-
const [argMetas, internalArgMetas] =
|
|
81
|
+
const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
103
82
|
argMetas.forEach((argMeta) => {
|
|
104
83
|
if (argMeta.type !== "Room")
|
|
105
84
|
throw new Error(`Argument of Message should be Room ${sigMeta.refName}-${gqlMeta.key}-${argMeta.name}`);
|
|
106
|
-
|
|
85
|
+
MessageBody(argMeta.name, ...getBodyPipes(argMeta))(WsGateway.prototype, gqlMeta.key, argMeta.idx);
|
|
107
86
|
});
|
|
108
87
|
internalArgMetas.forEach((internalArgMeta) => {
|
|
109
88
|
const internalDecorator = internalArgMap[internalArgMeta.type];
|
|
110
89
|
internalDecorator(internalArgMeta.option ?? {})(WsGateway.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
111
90
|
});
|
|
112
|
-
|
|
113
|
-
|
|
91
|
+
UseInterceptors(getPubsubInterceptor(argMetas))(WsGateway.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
92
|
+
SubscribeMessage(gqlMeta.key)(WsGateway.prototype, gqlMeta.key, descriptor);
|
|
114
93
|
}
|
|
115
|
-
|
|
94
|
+
WebSocketGateway({ cors: { origin: "*" }, transports: ["websocket"] })(WsGateway);
|
|
116
95
|
return WsGateway;
|
|
117
96
|
};
|
|
118
97
|
const websocketServerOf = (sigRef) => {
|
|
119
|
-
const pubsubGqlMetas =
|
|
98
|
+
const pubsubGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
|
|
120
99
|
let Websocket = class {
|
|
121
100
|
server;
|
|
122
101
|
};
|
|
123
102
|
__decorateClass([
|
|
124
|
-
|
|
103
|
+
WebSocketServer()
|
|
125
104
|
], Websocket.prototype, "server", 2);
|
|
126
105
|
Websocket = __decorateClass([
|
|
127
|
-
|
|
128
|
-
|
|
106
|
+
Injectable(),
|
|
107
|
+
WebSocketGateway({ cors: { origin: "*" }, transports: ["websocket"] })
|
|
129
108
|
], Websocket);
|
|
130
109
|
for (const gqlMeta of pubsubGqlMetas) {
|
|
131
|
-
const [argMetas] =
|
|
110
|
+
const [argMetas] = getArgMetas(sigRef, gqlMeta.key);
|
|
132
111
|
Websocket.prototype[gqlMeta.key] = function(...args) {
|
|
133
112
|
const roomId = makeRoomId(
|
|
134
113
|
gqlMeta.key,
|
|
@@ -139,8 +118,7 @@ const websocketServerOf = (sigRef) => {
|
|
|
139
118
|
}
|
|
140
119
|
return Websocket;
|
|
141
120
|
};
|
|
142
|
-
|
|
143
|
-
0 && (module.exports = {
|
|
121
|
+
export {
|
|
144
122
|
websocketOf,
|
|
145
123
|
websocketServerOf
|
|
146
|
-
}
|
|
124
|
+
};
|
package/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src";
|