@livequery/nestjs 1.0.23 → 1.0.27
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 +17 -17
- package/build/src/LivequeryRequest.d.ts +1 -0
- package/build/src/LivequeryRequest.js +4 -3
- package/build/src/LivequeryWebsocketSync.d.ts +1 -1
- package/build/src/LivequeryWebsocketSync.js +18 -18
- package/build/src/UseDataSource.js +1 -1
- package/build/src/const.d.ts +1 -1
- package/build/src/const.js +2 -2
- package/build/src/pathResolver.d.ts +4 -0
- package/build/src/pathResolver.js +16 -0
- package/package.json +2 -2
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,37 +29,37 @@ 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 index_1 = require("index");
|
|
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 => {
|
|
43
44
|
const [name, expression] = key.split(':');
|
|
44
45
|
try {
|
|
45
|
-
return [name, expression || '
|
|
46
|
+
return [name, expression || 'eq', JSON.parse(rest[key])];
|
|
46
47
|
}
|
|
47
48
|
catch (e) {
|
|
48
|
-
return [name, expression || '
|
|
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[index_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,41 +50,41 @@ let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
|
50
50
|
socket.id = id;
|
|
51
51
|
}
|
|
52
52
|
unsubscribe({ ref }, socket) {
|
|
53
|
-
var _a;
|
|
53
|
+
var _a, _b, _c, _d;
|
|
54
54
|
if (!this.connections.has(socket.id))
|
|
55
55
|
return;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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);
|
|
59
59
|
}
|
|
60
|
-
listen(connection_id,
|
|
60
|
+
listen(connection_id, collection_ref, doc_id) {
|
|
61
61
|
const cnn = this.connections.get(connection_id);
|
|
62
62
|
if (cnn) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const ref = `${collection_ref}${doc_id ? `/${doc_id}` : ''}`;
|
|
64
|
+
!cnn.refs.has(collection_ref) && cnn.refs.add(ref);
|
|
65
|
+
!this.refs.has(ref) && this.refs.set(ref, new Set());
|
|
66
66
|
this.refs.get(ref).add(connection_id);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
__decorate([
|
|
71
|
-
websockets_1.SubscribeMessage('start'),
|
|
72
|
-
__param(0, websockets_1.MessageBody()),
|
|
73
|
-
__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)()),
|
|
74
74
|
__metadata("design:type", Function),
|
|
75
75
|
__metadata("design:paramtypes", [Object, Object]),
|
|
76
76
|
__metadata("design:returntype", void 0)
|
|
77
77
|
], LivequeryWebsocketSync.prototype, "subscribe", null);
|
|
78
78
|
__decorate([
|
|
79
|
-
websockets_1.SubscribeMessage('unsubscribe'),
|
|
80
|
-
__param(0, websockets_1.MessageBody()),
|
|
81
|
-
__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)()),
|
|
82
82
|
__metadata("design:type", Function),
|
|
83
83
|
__metadata("design:paramtypes", [Object, Object]),
|
|
84
84
|
__metadata("design:returntype", void 0)
|
|
85
85
|
], LivequeryWebsocketSync.prototype, "unsubscribe", null);
|
|
86
86
|
LivequeryWebsocketSync = __decorate([
|
|
87
|
-
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' }),
|
|
88
88
|
__metadata("design:paramtypes", [])
|
|
89
89
|
], LivequeryWebsocketSync);
|
|
90
90
|
exports.LivequeryWebsocketSync = LivequeryWebsocketSync;
|
|
@@ -13,7 +13,7 @@ exports.UseDatasource = exports.UseDataSourceInterceptor = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
15
|
const operators_1 = require("rxjs/operators");
|
|
16
|
-
const DataSourceMetadataKey =
|
|
16
|
+
const DataSourceMetadataKey = Symbol();
|
|
17
17
|
let UseDataSourceInterceptor = class UseDataSourceInterceptor {
|
|
18
18
|
constructor(moduleRef) {
|
|
19
19
|
this.moduleRef = moduleRef;
|
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,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pathResolver = void 0;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
const pathResolver = (target, method) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const collection_path = Reflect.getMetadata('path', target) || '';
|
|
8
|
+
const method_path = Reflect.getMetadata('path', target.prototype[method]) || '';
|
|
9
|
+
const refs = (_a = `${collection_path}/${method_path}`
|
|
10
|
+
.replaceAll(':', '')
|
|
11
|
+
.split(const_1.LIVEQUERY_MAGIC_KEY)) === null || _a === void 0 ? void 0 : _a[1].split('/').filter(s => s.length > 0);
|
|
12
|
+
const ref = refs.join('/');
|
|
13
|
+
const schema_ref = refs.filter((_, i) => i % 2 == 0).join('/');
|
|
14
|
+
return { ref, schema_ref };
|
|
15
|
+
};
|
|
16
|
+
exports.pathResolver = pathResolver;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"repository": {
|
|
4
4
|
"url": "git@github.com:livequery/nestjs.git"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.27",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "build/index.js",
|
|
9
9
|
"types": "build/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"build/**/*"
|
|
12
12
|
],
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@livequery/types": "^1.0.
|
|
14
|
+
"@livequery/types": "^1.0.29",
|
|
15
15
|
"@types/express": "^4.17.11",
|
|
16
16
|
"@types/node": "^14.14.20"
|
|
17
17
|
},
|