@livequery/nestjs 1.0.31 → 1.0.34

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './src/LivequeryRequest';
2
+ export * from './src/LivequeryResponse';
2
3
  export * from './src/LivequeryInterceptor';
3
4
  export * from './src/LivequeryWebsocketSync';
4
5
  export * from './src/PathHelper';
5
- export * from './src/UseDatasource';
package/build/index.js CHANGED
@@ -11,7 +11,7 @@ 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);
14
15
  __exportStar(require("./src/LivequeryInterceptor"), exports);
15
16
  __exportStar(require("./src/LivequeryWebsocketSync"), exports);
16
17
  __exportStar(require("./src/PathHelper"), exports);
17
- __exportStar(require("./src/UseDatasource"), exports);
@@ -5,6 +5,8 @@ export declare class LivequeryInterceptor implements NestInterceptor {
5
5
  constructor(LivequeryWebsocketSync?: LivequeryWebsocketSync);
6
6
  intercept(context: ExecutionContext, next: CallHandler): import("rxjs").Observable<{
7
7
  data: any;
8
+ } | {
9
+ error: any;
8
10
  }>;
9
11
  }
10
12
  export declare const UseLivequeryInterceptor: () => MethodDecorator & ClassDecorator;
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.UseLivequeryInterceptor = exports.LivequeryInterceptor = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
17
  const LivequeryWebsocketSync_1 = require("./LivequeryWebsocketSync");
18
+ const rxjs_1 = require("rxjs");
18
19
  const operators_1 = require("rxjs/operators");
19
- const LivequeryRequest_1 = require("./LivequeryRequest");
20
20
  const PathHelper_1 = require("./PathHelper");
21
21
  let LivequeryInterceptor = class LivequeryInterceptor {
22
22
  LivequeryWebsocketSync;
@@ -39,7 +39,7 @@ let LivequeryInterceptor = class LivequeryInterceptor {
39
39
  });
40
40
  const { ref, is_collection, collection_ref, doc_id, } = PathHelper_1.PathHelper.livequeryPathExtractor(req._parsedUrl.pathname);
41
41
  const { collection_ref: schema_collection_ref } = PathHelper_1.PathHelper.livequeryPathExtractor(req.route.path);
42
- req[LivequeryRequest_1.LivequeryRequestKey] = {
42
+ req.livequery = {
43
43
  ref,
44
44
  collection_ref,
45
45
  schema_collection_ref,
@@ -59,7 +59,7 @@ let LivequeryInterceptor = class LivequeryInterceptor {
59
59
  };
60
60
  const socket_id = req.headers.socket_id;
61
61
  socket_id && this.LivequeryWebsocketSync?.listen(socket_id, collection_ref, doc_id);
62
- return next.handle().pipe((0, operators_1.map)(data => ({ data })));
62
+ return next.handle().pipe((0, operators_1.map)(data => ({ data })), (0, operators_1.catchError)(error => (0, rxjs_1.of)({ error })));
63
63
  }
64
64
  };
65
65
  LivequeryInterceptor = __decorate([
@@ -1,2 +1 @@
1
- export declare const LivequeryRequestKey: unique symbol;
2
1
  export declare const LivequeryRequest: (...dataOrPipes: unknown[]) => ParameterDecorator;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LivequeryRequest = exports.LivequeryRequestKey = void 0;
3
+ exports.LivequeryRequest = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
- exports.LivequeryRequestKey = Symbol();
6
5
  exports.LivequeryRequest = (0, common_1.createParamDecorator)((data, ctx) => {
7
6
  const request = ctx.switchToHttp().getRequest();
8
- return request[exports.LivequeryRequestKey];
7
+ return request.livequery;
9
8
  });
@@ -1,3 +1,7 @@
1
- import { QueryData } from '@livequery/types';
1
+ export declare type LivequeryResponse<T = any> = {
2
+ items: T[];
3
+ page_info?: {
4
+ has_more: boolean;
5
+ };
6
+ };
2
7
  export declare const LivequeryResponse: (...dataOrPipes: unknown[]) => ParameterDecorator;
3
- export declare const createLivequeryResponse: <T>(items: T[]) => QueryData<T>;
@@ -1,17 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLivequeryResponse = exports.LivequeryResponse = void 0;
3
+ exports.LivequeryResponse = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
- exports.LivequeryResponse = common_1.createParamDecorator((data, ctx) => {
6
- const request = ctx.switchToHttp().getRequest();
7
- return request.__livequery_response;
8
- });
9
- const createLivequeryResponse = (items) => {
10
- return {
11
- data: {
12
- items
13
- },
14
- error: null
15
- };
16
- };
17
- exports.createLivequeryResponse = createLivequeryResponse;
5
+ exports.LivequeryResponse = (0, common_1.createParamDecorator)((data, ctx) => ctx.switchToHttp().getRequest().livequery_response);
@@ -16,7 +16,7 @@ class PathHelper {
16
16
  const ref = refs.join('/');
17
17
  const collection_ref = is_collection ? ref : refs.slice(0, refs.length - 1).join('/');
18
18
  const schema_ref = refs.filter((_, i) => i % 2 == 0).join('/');
19
- const doc_id = is_collection ? refs[refs.length - 1] : null;
19
+ const doc_id = is_collection ? null : refs[refs.length - 1];
20
20
  return { ref, schema_ref, is_collection, doc_id, collection_ref };
21
21
  }
22
22
  static nestjsPathResolver(target, method) {
@@ -7,12 +7,13 @@ declare type Datasource = {
7
7
  export declare class UseDatasource {
8
8
  private moduleRef;
9
9
  private reflector;
10
- static readonly UseDatasourceMetadata: unique symbol;
11
10
  private static ControllerList;
12
11
  constructor(moduleRef: ModuleRef, reflector: Reflector);
13
- static createDatasourceMapper<T>(factory: {
12
+ static createDatasourceMapper<T = {}>(factory: {
14
13
  new (): Datasource;
15
- }): [(options: T) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void, () => {
14
+ }): [(options: T & {
15
+ _manual_query?: boolean;
16
+ }) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void, () => {
16
17
  paths: {
17
18
  ref: string;
18
19
  schema_ref: string;
@@ -20,14 +20,16 @@ const rxjs_1 = require("rxjs");
20
20
  let UseDatasource = UseDatasource_1 = class UseDatasource {
21
21
  moduleRef;
22
22
  reflector;
23
- static UseDatasourceMetadata = Symbol();
24
23
  static ControllerList = [];
25
24
  constructor(moduleRef, reflector) {
26
25
  this.moduleRef = moduleRef;
27
26
  this.reflector = reflector;
28
27
  }
29
28
  static createDatasourceMapper(factory) {
30
- const decorator = (options) => (0, common_1.applyDecorators)((0, common_1.UseInterceptors)(LivequeryInterceptor_1.LivequeryInterceptor), (0, common_1.UseInterceptors)(this), (0, common_1.SetMetadata)(this.UseDatasourceMetadata, { options, factory }), (target, method) => this.ControllerList.push({
29
+ const decorator = (options) => (0, common_1.applyDecorators)((0, common_1.UseInterceptors)(LivequeryInterceptor_1.LivequeryInterceptor), ...options._manual_query == true ? [] : [
30
+ (0, common_1.SetMetadata)(UseDatasource_1, { options, factory }),
31
+ (0, common_1.UseInterceptors)(this)
32
+ ], (target, method) => this.ControllerList.push({
31
33
  target: target.constructor,
32
34
  method,
33
35
  options
@@ -43,7 +45,7 @@ let UseDatasource = UseDatasource_1 = class UseDatasource {
43
45
  async intercept(context, next) {
44
46
  const request = context.switchToHttp().getRequest();
45
47
  const livequery = request[LivequeryRequest_1.LivequeryRequestKey];
46
- const { factory } = this.reflector.get(UseDatasource_1.UseDatasourceMetadata, context.getHandler());
48
+ const { factory } = this.reflector.get(UseDatasource_1, context.getHandler());
47
49
  const ds = await this.moduleRef.get(factory);
48
50
  const result = await ds.query(livequery);
49
51
  return next.handle().pipe((0, rxjs_1.map)(data => data ?? result));
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.31",
6
+ "version": "1.0.34",
7
7
  "description": "",
8
8
  "main": "build/index.js",
9
9
  "types": "build/index.d.ts",