@livequery/nestjs 1.0.26 → 1.0.30
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 +21 -34
- package/build/src/LivequeryRequest.d.ts +1 -0
- package/build/src/LivequeryRequest.js +4 -3
- package/build/src/LivequeryWebsocketSync.js +16 -18
- package/build/src/PathHelper.d.ts +11 -0
- package/build/src/PathHelper.js +28 -0
- package/build/src/const.d.ts +1 -1
- package/build/src/const.js +2 -2
- package/build/src/pathResolver.d.ts +11 -0
- package/build/src/pathResolver.js +28 -0
- package/package.json +9 -4
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/PathHelper';
|
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/PathHelper"), exports);
|
|
@@ -11,32 +11,22 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
15
|
-
var t = {};
|
|
16
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
17
|
-
t[p] = s[p];
|
|
18
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
19
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
20
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
21
|
-
t[p[i]] = s[p[i]];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
15
|
exports.UseLivequeryInterceptor = exports.LivequeryInterceptor = void 0;
|
|
27
16
|
const common_1 = require("@nestjs/common");
|
|
28
17
|
const LivequeryWebsocketSync_1 = require("./LivequeryWebsocketSync");
|
|
29
|
-
const const_1 = require("./const");
|
|
30
18
|
const rxjs_1 = require("rxjs");
|
|
31
19
|
const operators_1 = require("rxjs/operators");
|
|
20
|
+
const LivequeryRequest_1 = require("./LivequeryRequest");
|
|
21
|
+
const PathHelper_1 = require("./PathHelper");
|
|
32
22
|
let LivequeryInterceptor = class LivequeryInterceptor {
|
|
23
|
+
LivequeryWebsocketSync;
|
|
33
24
|
constructor(LivequeryWebsocketSync = null) {
|
|
34
25
|
this.LivequeryWebsocketSync = LivequeryWebsocketSync;
|
|
35
26
|
}
|
|
36
27
|
intercept(context, next) {
|
|
37
|
-
var _a;
|
|
38
28
|
const req = context.switchToHttp().getRequest();
|
|
39
|
-
const
|
|
29
|
+
const { _limit = 20, _cursor, _order_by, _sort, _select, ...rest } = req.query;
|
|
40
30
|
const filters = Object
|
|
41
31
|
.keys(rest)
|
|
42
32
|
.map(key => {
|
|
@@ -48,39 +38,36 @@ let LivequeryInterceptor = class LivequeryInterceptor {
|
|
|
48
38
|
return [name, expression || 'eq', rest[key]];
|
|
49
39
|
}
|
|
50
40
|
});
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const collection_ref = refs.slice(0, refs.length - (is_collection ? 0 : 1)).join('/');
|
|
55
|
-
const doc_id = !is_collection && refs[refs.length - 1];
|
|
56
|
-
const schema_collection_ref = req.route.path
|
|
57
|
-
.split('/')
|
|
58
|
-
.slice(const_1.COLLECTION_REF_SLICE_INDEX + 1)
|
|
59
|
-
.filter((_, i) => i % 2 == 0)
|
|
60
|
-
.join('/')
|
|
61
|
-
.replaceAll(':', '');
|
|
62
|
-
req.__livequery_request = {
|
|
41
|
+
const { ref, is_collection, collection_ref, doc_id, } = PathHelper_1.PathHelper.livequeryPathExtractor(req._parsedUrl.pathname);
|
|
42
|
+
const { collection_ref: schema_collection_ref } = PathHelper_1.PathHelper.livequeryPathExtractor(req.route.path);
|
|
43
|
+
req[LivequeryRequest_1.LivequeryRequestKey] = {
|
|
63
44
|
ref,
|
|
64
45
|
collection_ref,
|
|
65
46
|
schema_collection_ref,
|
|
66
47
|
is_collection,
|
|
67
48
|
doc_id,
|
|
68
49
|
filters,
|
|
69
|
-
options:
|
|
50
|
+
options: {
|
|
51
|
+
_limit: Number(_limit),
|
|
52
|
+
_cursor,
|
|
70
53
|
_order_by,
|
|
71
|
-
_sort
|
|
72
|
-
|
|
54
|
+
_sort,
|
|
55
|
+
..._select ? { _select: JSON.parse(_select) } : {}
|
|
56
|
+
},
|
|
57
|
+
keys: req.params,
|
|
58
|
+
body: req.body,
|
|
59
|
+
method: req.method.toLowerCase()
|
|
73
60
|
};
|
|
74
61
|
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 })));
|
|
62
|
+
socket_id && this.LivequeryWebsocketSync?.listen(socket_id, collection_ref, doc_id);
|
|
63
|
+
return next.handle().pipe((0, operators_1.map)(data => ({ data })), (0, operators_1.catchError)(error => (0, rxjs_1.of)({ error })));
|
|
77
64
|
}
|
|
78
65
|
};
|
|
79
66
|
LivequeryInterceptor = __decorate([
|
|
80
|
-
common_1.Injectable(),
|
|
81
|
-
__param(0, common_1.Optional()),
|
|
67
|
+
(0, common_1.Injectable)(),
|
|
68
|
+
__param(0, (0, common_1.Optional)()),
|
|
82
69
|
__metadata("design:paramtypes", [LivequeryWebsocketSync_1.LivequeryWebsocketSync])
|
|
83
70
|
], LivequeryInterceptor);
|
|
84
71
|
exports.LivequeryInterceptor = LivequeryInterceptor;
|
|
85
|
-
const UseLivequeryInterceptor = () => common_1.UseInterceptors(LivequeryInterceptor);
|
|
72
|
+
const UseLivequeryInterceptor = () => (0, common_1.UseInterceptors)(LivequeryInterceptor);
|
|
86
73
|
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
|
});
|
|
@@ -17,11 +17,11 @@ const websockets_1 = require("@nestjs/websockets");
|
|
|
17
17
|
const rxjs_1 = require("rxjs");
|
|
18
18
|
const operators_1 = require("rxjs/operators");
|
|
19
19
|
let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
20
|
+
connections = new Map();
|
|
21
|
+
refs = new Map();
|
|
22
|
+
changes = new rxjs_1.Subject();
|
|
20
23
|
constructor() {
|
|
21
|
-
this.
|
|
22
|
-
this.refs = new Map();
|
|
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,8 @@ let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
async handleDisconnect(socket) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
(_b = this.refs.get(ref)) === null || _b === void 0 ? void 0 : _b.delete(socket.id);
|
|
42
|
+
for (const ref of this.connections.get(socket.id)?.refs || []) {
|
|
43
|
+
this.refs.get(ref)?.delete(socket.id);
|
|
45
44
|
}
|
|
46
45
|
this.connections.delete(socket.id);
|
|
47
46
|
}
|
|
@@ -50,12 +49,11 @@ let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
|
50
49
|
socket.id = id;
|
|
51
50
|
}
|
|
52
51
|
unsubscribe({ ref }, socket) {
|
|
53
|
-
var _a, _b, _c, _d;
|
|
54
52
|
if (!this.connections.has(socket.id))
|
|
55
53
|
return;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
this.connections.get(socket.id)?.refs?.delete(ref);
|
|
55
|
+
this.refs.get(ref)?.delete(socket.id);
|
|
56
|
+
this.refs.get(ref)?.size == 0 && this.refs.delete(ref);
|
|
59
57
|
}
|
|
60
58
|
listen(connection_id, collection_ref, doc_id) {
|
|
61
59
|
const cnn = this.connections.get(connection_id);
|
|
@@ -68,23 +66,23 @@ let LivequeryWebsocketSync = class LivequeryWebsocketSync {
|
|
|
68
66
|
}
|
|
69
67
|
};
|
|
70
68
|
__decorate([
|
|
71
|
-
websockets_1.SubscribeMessage('start'),
|
|
72
|
-
__param(0, websockets_1.MessageBody()),
|
|
73
|
-
__param(1, websockets_1.ConnectedSocket()),
|
|
69
|
+
(0, websockets_1.SubscribeMessage)('start'),
|
|
70
|
+
__param(0, (0, websockets_1.MessageBody)()),
|
|
71
|
+
__param(1, (0, websockets_1.ConnectedSocket)()),
|
|
74
72
|
__metadata("design:type", Function),
|
|
75
73
|
__metadata("design:paramtypes", [Object, Object]),
|
|
76
74
|
__metadata("design:returntype", void 0)
|
|
77
75
|
], LivequeryWebsocketSync.prototype, "subscribe", null);
|
|
78
76
|
__decorate([
|
|
79
|
-
websockets_1.SubscribeMessage('unsubscribe'),
|
|
80
|
-
__param(0, websockets_1.MessageBody()),
|
|
81
|
-
__param(1, websockets_1.ConnectedSocket()),
|
|
77
|
+
(0, websockets_1.SubscribeMessage)('unsubscribe'),
|
|
78
|
+
__param(0, (0, websockets_1.MessageBody)()),
|
|
79
|
+
__param(1, (0, websockets_1.ConnectedSocket)()),
|
|
82
80
|
__metadata("design:type", Function),
|
|
83
81
|
__metadata("design:paramtypes", [Object, Object]),
|
|
84
82
|
__metadata("design:returntype", void 0)
|
|
85
83
|
], LivequeryWebsocketSync.prototype, "unsubscribe", null);
|
|
86
84
|
LivequeryWebsocketSync = __decorate([
|
|
87
|
-
websockets_1.WebSocketGateway({ path: process.env.REALTIME_UPDATE_SOCKET_PATH || '/livequery/realtime-updates' }),
|
|
85
|
+
(0, websockets_1.WebSocketGateway)({ path: process.env.REALTIME_UPDATE_SOCKET_PATH || '/livequery/realtime-updates' }),
|
|
88
86
|
__metadata("design:paramtypes", [])
|
|
89
87
|
], LivequeryWebsocketSync);
|
|
90
88
|
exports.LivequeryWebsocketSync = LivequeryWebsocketSync;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class PathHelper {
|
|
2
|
+
#private;
|
|
3
|
+
static livequeryPathExtractor(path: string): {
|
|
4
|
+
ref: string;
|
|
5
|
+
schema_ref: string;
|
|
6
|
+
is_collection: boolean;
|
|
7
|
+
doc_id: string;
|
|
8
|
+
collection_ref: string;
|
|
9
|
+
};
|
|
10
|
+
static nestjsPathResolver(target: Function, method: string): string[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PathHelper = void 0;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
class PathHelper {
|
|
6
|
+
static #toArray = (a) => typeof a == 'string' ? [a] : a;
|
|
7
|
+
static livequeryPathExtractor(path) {
|
|
8
|
+
const refs = path
|
|
9
|
+
?.replaceAll(':', '')
|
|
10
|
+
?.split(const_1.LIVEQUERY_MAGIC_KEY)?.[1]
|
|
11
|
+
?.split('/')
|
|
12
|
+
?.filter(s => s.length > 0);
|
|
13
|
+
if (!refs)
|
|
14
|
+
throw 'LIVEQUERY_MAGIC_KEY_NOT_FOUND';
|
|
15
|
+
const is_collection = refs.length % 2 == 1;
|
|
16
|
+
const ref = refs.join('/');
|
|
17
|
+
const collection_ref = is_collection ? ref : refs.slice(0, refs.length - 1).join('/');
|
|
18
|
+
const schema_ref = refs.filter((_, i) => i % 2 == 0).join('/');
|
|
19
|
+
const doc_id = is_collection ? refs[refs.length - 1] : null;
|
|
20
|
+
return { ref, schema_ref, is_collection, doc_id, collection_ref };
|
|
21
|
+
}
|
|
22
|
+
static nestjsPathResolver(target, method) {
|
|
23
|
+
const collection_paths = this.#toArray(Reflect.getMetadata('path', target) || '');
|
|
24
|
+
const method_paths = this.#toArray(Reflect.getMetadata('path', target.prototype[method]) || '');
|
|
25
|
+
return collection_paths.map(collection_path => method_paths.map(method_path => `${collection_path}/${method_path}`)).flat(2);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.PathHelper = PathHelper;
|
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,11 @@
|
|
|
1
|
+
export declare class PathHelper {
|
|
2
|
+
#private;
|
|
3
|
+
static livequeryPathExtractor(path: string): {
|
|
4
|
+
ref: string;
|
|
5
|
+
schema_ref: string;
|
|
6
|
+
is_collection: boolean;
|
|
7
|
+
doc_id: string;
|
|
8
|
+
collection_ref: string;
|
|
9
|
+
};
|
|
10
|
+
static nestjsPathResolver(target: Function, method: string): string[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PathHelper = void 0;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
class PathHelper {
|
|
6
|
+
static #toArray = (a) => typeof a == 'string' ? [a] : a;
|
|
7
|
+
static livequeryPathExtractor(path) {
|
|
8
|
+
const refs = path
|
|
9
|
+
?.replaceAll(':', '')
|
|
10
|
+
?.split(const_1.LIVEQUERY_MAGIC_KEY)?.[1]
|
|
11
|
+
?.split('/')
|
|
12
|
+
?.filter(s => s.length > 0);
|
|
13
|
+
if (!refs)
|
|
14
|
+
throw 'LIVEQUERY_MAGIC_KEY_NOT_FOUND';
|
|
15
|
+
const is_collection = refs.length % 2 == 1;
|
|
16
|
+
const ref = refs.join('/');
|
|
17
|
+
const collection_ref = is_collection ? ref : refs.slice(0, refs.length - 1).join('/');
|
|
18
|
+
const schema_ref = refs.filter((_, i) => i % 2 == 0).join('/');
|
|
19
|
+
const doc_id = is_collection ? refs[refs.length - 1] : null;
|
|
20
|
+
return { ref, schema_ref, is_collection, doc_id, collection_ref };
|
|
21
|
+
}
|
|
22
|
+
static nestjsPathResolver(target, method) {
|
|
23
|
+
const collection_paths = this.#toArray(Reflect.getMetadata('path', target) || '');
|
|
24
|
+
const method_paths = this.#toArray(Reflect.getMetadata('path', target.prototype[method]) || '');
|
|
25
|
+
return collection_paths.map(collection_path => method_paths.map(method_path => `${collection_path}/${method_path}`)).flat(2);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.PathHelper = PathHelper;
|
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.30",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "build/index.js",
|
|
9
9
|
"types": "build/index.d.ts",
|
|
@@ -11,9 +11,14 @@
|
|
|
11
11
|
"build/**/*"
|
|
12
12
|
],
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@livequery/types": "^1.0.
|
|
14
|
+
"@livequery/types": "^1.0.34",
|
|
15
|
+
"@nestjs/common": "^8.2.3",
|
|
16
|
+
"@nestjs/core": "^8.2.3",
|
|
17
|
+
"@nestjs/websockets": "^8.2.3",
|
|
15
18
|
"@types/express": "^4.17.11",
|
|
16
|
-
"@types/node": "^14.14.20"
|
|
19
|
+
"@types/node": "^14.14.20",
|
|
20
|
+
"reflect-metadata": "^0.1.13",
|
|
21
|
+
"rxjs": "^7.4.0"
|
|
17
22
|
},
|
|
18
23
|
"peerDependencies": {
|
|
19
24
|
"@nestjs/common": "^7.6.17",
|
|
@@ -29,4 +34,4 @@
|
|
|
29
34
|
},
|
|
30
35
|
"author": "",
|
|
31
36
|
"license": "ISC"
|
|
32
|
-
}
|
|
37
|
+
}
|