@livequery/nestjs 1.0.37 → 1.0.38
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.js +5 -1
- package/build/src/LivequeryInterceptor.js +3 -1
- package/package.json +1 -1
- package/build/src/ControllerMetadata.d.ts +0 -13
- package/build/src/ControllerMetadata.js +0 -29
- package/build/src/UseDataSource.d.ts +0 -15
- package/build/src/UseDataSource.js +0 -41
- package/build/src/pathResolver.d.ts +0 -11
- package/build/src/pathResolver.js +0 -28
package/build/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -37,9 +37,10 @@ let LivequeryInterceptor = class LivequeryInterceptor {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
const { ref, is_collection, collection_ref, doc_id, } = PathHelper_1.PathHelper.livequeryPathExtractor(req._parsedUrl.pathname);
|
|
40
|
-
const { collection_ref: schema_collection_ref } = PathHelper_1.PathHelper.livequeryPathExtractor(req.route.path);
|
|
40
|
+
const { collection_ref: schema_collection_ref, ref: schema_ref } = PathHelper_1.PathHelper.livequeryPathExtractor(req.route.path);
|
|
41
41
|
req.livequery = {
|
|
42
42
|
ref,
|
|
43
|
+
schema_ref,
|
|
43
44
|
collection_ref,
|
|
44
45
|
schema_collection_ref,
|
|
45
46
|
is_collection,
|
|
@@ -56,6 +57,7 @@ let LivequeryInterceptor = class LivequeryInterceptor {
|
|
|
56
57
|
body: req.body,
|
|
57
58
|
method: req.method.toLowerCase()
|
|
58
59
|
};
|
|
60
|
+
console.log({ req: req.livequery });
|
|
59
61
|
const socket_id = req.headers.socket_id;
|
|
60
62
|
socket_id && this.LivequeryWebsocketSync?.listen(socket_id, collection_ref, doc_id);
|
|
61
63
|
return next.handle().pipe((0, operators_1.map)(data => ({ data })));
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const ControllerMetadata: {
|
|
2
|
-
create_method_decorator: <T>() => [(data: T) => {
|
|
3
|
-
(target: Function): void;
|
|
4
|
-
(target: Object, propertyKey: string | symbol): void;
|
|
5
|
-
}, (target: {
|
|
6
|
-
new ();
|
|
7
|
-
}) => {
|
|
8
|
-
data: T;
|
|
9
|
-
method: string;
|
|
10
|
-
ref: string;
|
|
11
|
-
schema_ref: string;
|
|
12
|
-
}[]];
|
|
13
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControllerMetadata = void 0;
|
|
4
|
-
const const_1 = require("./const");
|
|
5
|
-
exports.ControllerMetadata = {
|
|
6
|
-
create_method_decorator: () => {
|
|
7
|
-
const key = Symbol();
|
|
8
|
-
const decorator = (data) => Reflect.metadata(key, data);
|
|
9
|
-
const get_metadata = (target) => {
|
|
10
|
-
const collection_path = Reflect.getMetadata('path', target) || '';
|
|
11
|
-
const methods = Object.getOwnPropertyNames(target.prototype);
|
|
12
|
-
return methods
|
|
13
|
-
.filter(method => Reflect.hasMetadata(key, target.prototype, method))
|
|
14
|
-
.map(method => {
|
|
15
|
-
const data = Reflect.getMetadata(key, target.prototype, method);
|
|
16
|
-
const method_path = Reflect.getMetadata('path', target.prototype[method]) || '';
|
|
17
|
-
const refs = `${collection_path}/${method_path}`
|
|
18
|
-
.replaceAll(':', '')
|
|
19
|
-
.split('/')
|
|
20
|
-
.filter(s => s.length > 0)
|
|
21
|
-
.slice(const_1.COLLECTION_REF_SLICE_INDEX);
|
|
22
|
-
const ref = refs.join('/');
|
|
23
|
-
const schema_ref = refs.filter((_, i) => i % 2 == 0).join('/');
|
|
24
|
-
return { data, method, ref, schema_ref };
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
return [decorator, get_metadata];
|
|
28
|
-
}
|
|
29
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { LivequeryRequest, QueryData } from '@livequery/types';
|
|
2
|
-
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
3
|
-
import { ModuleRef } from '@nestjs/core';
|
|
4
|
-
import { Observable } from 'rxjs';
|
|
5
|
-
export declare type Datasource = {
|
|
6
|
-
query(query: LivequeryRequest): Promise<QueryData>;
|
|
7
|
-
};
|
|
8
|
-
export declare class UseDataSourceInterceptor implements NestInterceptor {
|
|
9
|
-
private moduleRef;
|
|
10
|
-
constructor(moduleRef: ModuleRef);
|
|
11
|
-
intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
|
|
12
|
-
}
|
|
13
|
-
export declare const UseDatasource: (datasource: {
|
|
14
|
-
new (): Datasource;
|
|
15
|
-
}) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.UseDatasource = exports.UseDataSourceInterceptor = void 0;
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
|
-
const core_1 = require("@nestjs/core");
|
|
15
|
-
const operators_1 = require("rxjs/operators");
|
|
16
|
-
const DataSourceMetadataKey = Symbol();
|
|
17
|
-
let UseDataSourceInterceptor = class UseDataSourceInterceptor {
|
|
18
|
-
constructor(moduleRef) {
|
|
19
|
-
this.moduleRef = moduleRef;
|
|
20
|
-
}
|
|
21
|
-
async intercept(context, next) {
|
|
22
|
-
const datasource_factory = Reflect.getMetadata(DataSourceMetadataKey, context.getClass().prototype, context.getHandler().name);
|
|
23
|
-
const datasource = await this.moduleRef.get(datasource_factory);
|
|
24
|
-
const req = context.switchToHttp().getRequest();
|
|
25
|
-
const livequery = req.__livequery_request;
|
|
26
|
-
const livequery_response = await datasource.query(livequery);
|
|
27
|
-
req.__livequery_response = livequery_response;
|
|
28
|
-
return next.handle().pipe(operators_1.map(response => {
|
|
29
|
-
if (response == undefined)
|
|
30
|
-
return livequery_response;
|
|
31
|
-
return response;
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
UseDataSourceInterceptor = __decorate([
|
|
36
|
-
common_1.Injectable(),
|
|
37
|
-
__metadata("design:paramtypes", [core_1.ModuleRef])
|
|
38
|
-
], UseDataSourceInterceptor);
|
|
39
|
-
exports.UseDataSourceInterceptor = UseDataSourceInterceptor;
|
|
40
|
-
const UseDatasource = (datasource) => common_1.applyDecorators(Reflect.metadata(DataSourceMetadataKey, datasource), common_1.UseInterceptors(UseDataSourceInterceptor));
|
|
41
|
-
exports.UseDatasource = UseDatasource;
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
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;
|