@livequery/nestjs 1.0.25 → 1.0.29
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/build/index.d.ts +1 -3
- package/build/index.js +1 -3
- package/build/src/LivequeryInterceptor.js +15 -15
- package/build/src/LivequeryRequest.d.ts +1 -0
- package/build/src/LivequeryRequest.js +4 -3
- package/build/src/LivequeryWebsocketSync.js +14 -13
- package/build/src/const.d.ts +1 -1
- package/build/src/const.js +2 -2
- package/build/src/pathResolver.d.ts +8 -0
- package/build/src/pathResolver.js +29 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from './src/LivequeryRequest';
|
|
2
|
-
export * from './src/LivequeryResponse';
|
|
3
2
|
export * from './src/LivequeryInterceptor';
|
|
4
3
|
export * from './src/LivequeryWebsocketSync';
|
|
5
|
-
export * from './src/
|
|
6
|
-
export * from './src/UseDataSource';
|
|
4
|
+
export * from './src/pathResolver';
|
package/build/index.js
CHANGED
|
@@ -11,8 +11,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./src/LivequeryRequest"), exports);
|
|
14
|
-
__exportStar(require("./src/LivequeryResponse"), exports);
|
|
15
14
|
__exportStar(require("./src/LivequeryInterceptor"), exports);
|
|
16
15
|
__exportStar(require("./src/LivequeryWebsocketSync"), exports);
|
|
17
|
-
__exportStar(require("./src/
|
|
18
|
-
__exportStar(require("./src/UseDataSource"), exports);
|
|
16
|
+
__exportStar(require("./src/pathResolver"), exports);
|
|
@@ -29,14 +29,15 @@ const LivequeryWebsocketSync_1 = require("./LivequeryWebsocketSync");
|
|
|
29
29
|
const const_1 = require("./const");
|
|
30
30
|
const rxjs_1 = require("rxjs");
|
|
31
31
|
const operators_1 = require("rxjs/operators");
|
|
32
|
+
const LivequeryRequest_1 = require("./LivequeryRequest");
|
|
32
33
|
let LivequeryInterceptor = class LivequeryInterceptor {
|
|
33
34
|
constructor(LivequeryWebsocketSync = null) {
|
|
34
35
|
this.LivequeryWebsocketSync = LivequeryWebsocketSync;
|
|
35
36
|
}
|
|
36
37
|
intercept(context, next) {
|
|
37
|
-
var _a;
|
|
38
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
38
39
|
const req = context.switchToHttp().getRequest();
|
|
39
|
-
const
|
|
40
|
+
const _l = req.query, { _limit = 20, _cursor, _order_by, _sort, _select } = _l, rest = __rest(_l, ["_limit", "_cursor", "_order_by", "_sort", "_select"]);
|
|
40
41
|
const filters = Object
|
|
41
42
|
.keys(rest)
|
|
42
43
|
.map(key => {
|
|
@@ -48,18 +49,17 @@ let LivequeryInterceptor = class LivequeryInterceptor {
|
|
|
48
49
|
return [name, expression || 'eq', rest[key]];
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
|
-
const refs = req._parsedUrl.pathname.split(
|
|
52
|
+
const refs = (_c = (_b = (_a = req._parsedUrl.pathname) === null || _a === void 0 ? void 0 : _a.split(const_1.LIVEQUERY_MAGIC_KEY)) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.split('/');
|
|
53
|
+
if (!refs)
|
|
54
|
+
throw new common_1.HttpException('CAN_NOT_DETECT_LIVEQUERY_KEY', 400);
|
|
52
55
|
const ref = refs.join('/');
|
|
53
56
|
const is_collection = refs.length % 2 == 1;
|
|
54
57
|
const collection_ref = refs.slice(0, refs.length - (is_collection ? 0 : 1)).join('/');
|
|
55
58
|
const doc_id = !is_collection && refs[refs.length - 1];
|
|
56
|
-
const schema_collection_ref = req.route.path
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
.join('/')
|
|
61
|
-
.replaceAll(':', '');
|
|
62
|
-
req.__livequery_request = {
|
|
59
|
+
const schema_collection_ref = (_j = (_h = (_g = (_f = (_e = (_d = req.route.path) === null || _d === void 0 ? void 0 : _d.split(const_1.LIVEQUERY_MAGIC_KEY)) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f.split('/')) === null || _g === void 0 ? void 0 : _g.filter((_, i) => i % 2 == 0)) === null || _h === void 0 ? void 0 : _h.join('/')) === null || _j === void 0 ? void 0 : _j.replaceAll(':', '');
|
|
60
|
+
if (!schema_collection_ref)
|
|
61
|
+
throw new common_1.HttpException('CAN_NOT_DETECT_LIVEQUERY_KEY', 400);
|
|
62
|
+
req[LivequeryRequest_1.LivequeryRequestKey] = {
|
|
63
63
|
ref,
|
|
64
64
|
collection_ref,
|
|
65
65
|
schema_collection_ref,
|
|
@@ -72,15 +72,15 @@ let LivequeryInterceptor = class LivequeryInterceptor {
|
|
|
72
72
|
keys: req.params
|
|
73
73
|
};
|
|
74
74
|
const socket_id = req.headers.socket_id;
|
|
75
|
-
socket_id && ((
|
|
76
|
-
return next.handle().pipe(operators_1.map(data => ({ data })), operators_1.catchError(error => rxjs_1.of({ error })));
|
|
75
|
+
socket_id && ((_k = this.LivequeryWebsocketSync) === null || _k === void 0 ? void 0 : _k.listen(socket_id, collection_ref, doc_id));
|
|
76
|
+
return next.handle().pipe((0, operators_1.map)(data => ({ data })), (0, operators_1.catchError)(error => (0, rxjs_1.of)({ error })));
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
LivequeryInterceptor = __decorate([
|
|
80
|
-
common_1.Injectable(),
|
|
81
|
-
__param(0, common_1.Optional()),
|
|
80
|
+
(0, common_1.Injectable)(),
|
|
81
|
+
__param(0, (0, common_1.Optional)()),
|
|
82
82
|
__metadata("design:paramtypes", [LivequeryWebsocketSync_1.LivequeryWebsocketSync])
|
|
83
83
|
], LivequeryInterceptor);
|
|
84
84
|
exports.LivequeryInterceptor = LivequeryInterceptor;
|
|
85
|
-
const UseLivequeryInterceptor = () => common_1.UseInterceptors(LivequeryInterceptor);
|
|
85
|
+
const UseLivequeryInterceptor = () => (0, common_1.UseInterceptors)(LivequeryInterceptor);
|
|
86
86
|
exports.UseLivequeryInterceptor = UseLivequeryInterceptor;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LivequeryRequest = void 0;
|
|
3
|
+
exports.LivequeryRequest = exports.LivequeryRequestKey = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
exports.
|
|
5
|
+
exports.LivequeryRequestKey = Symbol();
|
|
6
|
+
exports.LivequeryRequest = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
7
|
const request = ctx.switchToHttp().getRequest();
|
|
7
|
-
return request.
|
|
8
|
+
return request[exports.LivequeryRequestKey];
|
|
8
9
|
});
|
|
@@ -21,7 +21,7 @@ let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
|
21
21
|
this.connections = new Map();
|
|
22
22
|
this.refs = new Map();
|
|
23
23
|
this.changes = new rxjs_1.Subject();
|
|
24
|
-
this.changes.pipe(operators_1.mergeMap(change => {
|
|
24
|
+
this.changes.pipe((0, operators_1.mergeMap)(change => {
|
|
25
25
|
const map = new Map();
|
|
26
26
|
if (!map.has(change.ref))
|
|
27
27
|
map.set(change.ref, []);
|
|
@@ -39,9 +39,9 @@ let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
async handleDisconnect(socket) {
|
|
42
|
-
var _a;
|
|
42
|
+
var _a, _b;
|
|
43
43
|
for (const ref of ((_a = this.connections.get(socket.id)) === null || _a === void 0 ? void 0 : _a.refs) || []) {
|
|
44
|
-
this.refs.get(ref).delete(socket.id);
|
|
44
|
+
(_b = this.refs.get(ref)) === null || _b === void 0 ? void 0 : _b.delete(socket.id);
|
|
45
45
|
}
|
|
46
46
|
this.connections.delete(socket.id);
|
|
47
47
|
}
|
|
@@ -50,11 +50,12 @@ let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
|
50
50
|
socket.id = id;
|
|
51
51
|
}
|
|
52
52
|
unsubscribe({ ref }, socket) {
|
|
53
|
+
var _a, _b, _c, _d;
|
|
53
54
|
if (!this.connections.has(socket.id))
|
|
54
55
|
return;
|
|
55
|
-
this.connections.get(socket.id).refs.delete(ref);
|
|
56
|
-
this.refs.get(ref).delete(socket.id);
|
|
57
|
-
this.refs.get(ref).size == 0 && this.refs.delete(ref);
|
|
56
|
+
(_b = (_a = this.connections.get(socket.id)) === null || _a === void 0 ? void 0 : _a.refs) === null || _b === void 0 ? void 0 : _b.delete(ref);
|
|
57
|
+
(_c = this.refs.get(ref)) === null || _c === void 0 ? void 0 : _c.delete(socket.id);
|
|
58
|
+
((_d = this.refs.get(ref)) === null || _d === void 0 ? void 0 : _d.size) == 0 && this.refs.delete(ref);
|
|
58
59
|
}
|
|
59
60
|
listen(connection_id, collection_ref, doc_id) {
|
|
60
61
|
const cnn = this.connections.get(connection_id);
|
|
@@ -67,23 +68,23 @@ let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
70
|
__decorate([
|
|
70
|
-
websockets_1.SubscribeMessage('start'),
|
|
71
|
-
__param(0, websockets_1.MessageBody()),
|
|
72
|
-
__param(1, websockets_1.ConnectedSocket()),
|
|
71
|
+
(0, websockets_1.SubscribeMessage)('start'),
|
|
72
|
+
__param(0, (0, websockets_1.MessageBody)()),
|
|
73
|
+
__param(1, (0, websockets_1.ConnectedSocket)()),
|
|
73
74
|
__metadata("design:type", Function),
|
|
74
75
|
__metadata("design:paramtypes", [Object, Object]),
|
|
75
76
|
__metadata("design:returntype", void 0)
|
|
76
77
|
], LivequeryWebsocketSync.prototype, "subscribe", null);
|
|
77
78
|
__decorate([
|
|
78
|
-
websockets_1.SubscribeMessage('unsubscribe'),
|
|
79
|
-
__param(0, websockets_1.MessageBody()),
|
|
80
|
-
__param(1, websockets_1.ConnectedSocket()),
|
|
79
|
+
(0, websockets_1.SubscribeMessage)('unsubscribe'),
|
|
80
|
+
__param(0, (0, websockets_1.MessageBody)()),
|
|
81
|
+
__param(1, (0, websockets_1.ConnectedSocket)()),
|
|
81
82
|
__metadata("design:type", Function),
|
|
82
83
|
__metadata("design:paramtypes", [Object, Object]),
|
|
83
84
|
__metadata("design:returntype", void 0)
|
|
84
85
|
], LivequeryWebsocketSync.prototype, "unsubscribe", null);
|
|
85
86
|
LivequeryWebsocketSync = __decorate([
|
|
86
|
-
websockets_1.WebSocketGateway({ path: process.env.REALTIME_UPDATE_SOCKET_PATH || '/livequery/realtime-updates' }),
|
|
87
|
+
(0, websockets_1.WebSocketGateway)({ path: process.env.REALTIME_UPDATE_SOCKET_PATH || '/livequery/realtime-updates' }),
|
|
87
88
|
__metadata("design:paramtypes", [])
|
|
88
89
|
], LivequeryWebsocketSync);
|
|
89
90
|
exports.LivequeryWebsocketSync = LivequeryWebsocketSync;
|
package/build/src/const.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const LIVEQUERY_MAGIC_KEY: string;
|
package/build/src/const.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.LIVEQUERY_MAGIC_KEY = void 0;
|
|
4
|
+
exports.LIVEQUERY_MAGIC_KEY = process.env.LIVEQUERY_MAGIC_KEY || 'livequery';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _a, _PathHelper_toArray;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PathHelper = void 0;
|
|
10
|
+
const const_1 = require("./const");
|
|
11
|
+
class PathHelper {
|
|
12
|
+
static livequeryPathExtractor(path) {
|
|
13
|
+
var _b, _c, _d, _e;
|
|
14
|
+
const refs = (_e = (_d = (_c = (_b = path === null || path === void 0 ? void 0 : path.replaceAll(':', '')) === null || _b === void 0 ? void 0 : _b.split(const_1.LIVEQUERY_MAGIC_KEY)) === null || _c === void 0 ? void 0 : _c[1]) === null || _d === void 0 ? void 0 : _d.split('/')) === null || _e === void 0 ? void 0 : _e.filter(s => s.length > 0);
|
|
15
|
+
if (!refs)
|
|
16
|
+
return null;
|
|
17
|
+
const ref = refs.join('/');
|
|
18
|
+
const schema_ref = refs.filter((_, i) => i % 2 == 0).join('/');
|
|
19
|
+
return { ref, schema_ref };
|
|
20
|
+
}
|
|
21
|
+
static nestjsPathResolver(target, method) {
|
|
22
|
+
const collection_paths = __classPrivateFieldGet(this, _a, "f", _PathHelper_toArray).call(this, Reflect.getMetadata('path', target) || '');
|
|
23
|
+
const method_paths = __classPrivateFieldGet(this, _a, "f", _PathHelper_toArray).call(this, Reflect.getMetadata('path', target.prototype[method]) || '');
|
|
24
|
+
return collection_paths.map(collection_path => method_paths.map(method_path => `${collection_path}/${method_path}`)).flat(2);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.PathHelper = PathHelper;
|
|
28
|
+
_a = PathHelper;
|
|
29
|
+
_PathHelper_toArray = { value: (a) => typeof a == 'string' ? [a] : a };
|