@livequery/core 1.0.11 → 2.0.69

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.
Files changed (52) hide show
  1. package/README.md +669 -0
  2. package/dist/LivequeryCollection.d.ts +43 -0
  3. package/dist/LivequeryCollection.d.ts.map +1 -0
  4. package/dist/LivequeryCore.d.ts +55 -0
  5. package/dist/LivequeryCore.d.ts.map +1 -0
  6. package/dist/LivequeryDocument.d.ts +15 -0
  7. package/dist/LivequeryDocument.d.ts.map +1 -0
  8. package/dist/LivequeryMemoryStorage.d.ts +16 -0
  9. package/dist/LivequeryMemoryStorage.d.ts.map +1 -0
  10. package/dist/LivequeryStorge.d.ts +12 -0
  11. package/dist/LivequeryStorge.d.ts.map +1 -0
  12. package/dist/LivequeryTransporter.d.ts +21 -0
  13. package/dist/LivequeryTransporter.d.ts.map +1 -0
  14. package/dist/helpers/filterDocs.d.ts +5 -0
  15. package/dist/helpers/filterDocs.d.ts.map +1 -0
  16. package/dist/index.d.ts +9 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +2423 -0
  19. package/dist/index.js.map +68 -0
  20. package/dist/types.d.ts +61 -0
  21. package/dist/types.d.ts.map +1 -0
  22. package/package.json +35 -29
  23. package/build/index.d.ts +0 -12
  24. package/build/index.js +0 -28
  25. package/build/src/FilterExpressions.d.ts +0 -12
  26. package/build/src/FilterExpressions.js +0 -15
  27. package/build/src/LivequeryResponse.d.ts +0 -9
  28. package/build/src/LivequeryResponse.js +0 -14
  29. package/build/src/QueryFilterParser.d.ts +0 -29
  30. package/build/src/QueryFilterParser.js +0 -43
  31. package/build/src/QueryRefParser.d.ts +0 -19
  32. package/build/src/QueryRefParser.js +0 -17
  33. package/build/src/SocketGateway.d.ts +0 -43
  34. package/build/src/SocketGateway.js +0 -142
  35. package/build/src/decorators/DecoratorBuilder.d.ts +0 -13
  36. package/build/src/decorators/DecoratorBuilder.js +0 -73
  37. package/build/src/decorators/HideFields.d.ts +0 -1
  38. package/build/src/decorators/HideFields.js +0 -10
  39. package/build/src/decorators/LivequeryBinding.d.ts +0 -1
  40. package/build/src/decorators/LivequeryBinding.js +0 -7
  41. package/build/src/decorators/Remix.d.ts +0 -2
  42. package/build/src/decorators/Remix.js +0 -7
  43. package/build/src/decorators/ShowOnly.d.ts +0 -1
  44. package/build/src/decorators/ShowOnly.js +0 -10
  45. package/build/src/helpers/Array2Map.d.ts +0 -6
  46. package/build/src/helpers/Array2Map.js +0 -28
  47. package/build/src/interceptors/livequery.interceptor.d.ts +0 -8
  48. package/build/src/interceptors/livequery.interceptor.js +0 -34
  49. package/build/src/interceptors/remix.interceptor.d.ts +0 -7
  50. package/build/src/interceptors/remix.interceptor.js +0 -34
  51. package/build/src/livequery.module.d.ts +0 -2
  52. package/build/src/livequery.module.js +0 -27
package/package.json CHANGED
@@ -1,31 +1,37 @@
1
1
  {
2
- "name": "@livequery/core",
3
- "repository": {
4
- "url": "git@github.com:livequery/core.git"
5
- },
6
- "version": "1.0.11",
7
- "description": "",
8
- "main": "build/index.js",
9
- "types": "build/index.d.ts",
10
- "files": [
11
- "build/**/*"
12
- ],
13
- "dependencies": {
14
- "@nestjs/common": "^7.6.5",
15
- "@nestjs/core": "^7.6.5",
16
- "@nestjs/websockets": "^7.6.5",
17
- "reflect-metadata": "^0.1.13",
18
- "rxjs": "^6.6.3"
19
- },
20
- "devDependencies": {
21
- "@types/node": "^14.14.20",
22
- "@types/express": "^4.17.11"
23
- },
24
- "scripts": {
25
- "test": "echo \"Error: no test specified\" && exit 1",
26
- "build": "tsc -b .",
27
- "deploy": "yarn build; git add .; git commit -m \"Update\"; git push origin master; npm publish"
28
- },
29
- "author": "",
30
- "license": "ISC"
2
+ "name": "@livequery/core",
3
+ "version": "2.0.69",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": false,
19
+ "scripts": {
20
+ "clean": "rm -rf dist",
21
+ "build:js": "bun build ./src/index.ts --outdir ./dist --target browser --format esm --sourcemap",
22
+ "build:types": "bunx tsc -p tsconfig.build.json",
23
+ "build": "bun run clean && bun run build:js && bun run build:types",
24
+ "build:watch": "bun build ./src/index.ts --outdir ./dist --target browser --format esm --watch",
25
+ "prepublishOnly": "bun run build"
26
+ },
27
+ "devDependencies": {
28
+ "@types/bun": "latest",
29
+ "@types/chrome": "^0.1.38",
30
+ "typescript": "^5"
31
+ },
32
+ "dependencies": {
33
+ "rxjs": "^7.8.2",
34
+ "uuidv7": "^1.2.1"
35
+ },
36
+ "private": false
31
37
  }
package/build/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export { HideFields } from "./src/decorators/HideFields";
2
- export { ShowOnly } from "./src/decorators/ShowOnly";
3
- export { RemixInterceptor } from "./src/interceptors/remix.interceptor";
4
- export { LivequeryInterceptor } from "./src/interceptors/livequery.interceptor";
5
- export { Array2Map } from "./src/helpers/Array2Map";
6
- export { DecoratorBuilder } from "./src/decorators/DecoratorBuilder";
7
- export { LivequeryBinding } from "./src/decorators/LivequeryBinding";
8
- export { Remix } from "./src/decorators/Remix";
9
- export { LivequeryModule } from "./src/livequery.module";
10
- export { createLivequeryResponse, LivequeryResponse } from "./src/LivequeryResponse";
11
- export { RealtimeUpdate, RealtimeUpdateItem, SocketEvent, SocketGateway, REF_ALIASES } from './src/SocketGateway';
12
- export { Livequery, LivequeryRequest, QueryFilterParser } from './src/QueryFilterParser';
package/build/index.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryFilterParser = exports.REF_ALIASES = exports.SocketGateway = exports.createLivequeryResponse = exports.LivequeryModule = exports.Remix = exports.LivequeryBinding = exports.DecoratorBuilder = exports.Array2Map = exports.LivequeryInterceptor = exports.RemixInterceptor = exports.ShowOnly = exports.HideFields = void 0;
4
- var HideFields_1 = require("./src/decorators/HideFields");
5
- Object.defineProperty(exports, "HideFields", { enumerable: true, get: function () { return HideFields_1.HideFields; } });
6
- var ShowOnly_1 = require("./src/decorators/ShowOnly");
7
- Object.defineProperty(exports, "ShowOnly", { enumerable: true, get: function () { return ShowOnly_1.ShowOnly; } });
8
- var remix_interceptor_1 = require("./src/interceptors/remix.interceptor");
9
- Object.defineProperty(exports, "RemixInterceptor", { enumerable: true, get: function () { return remix_interceptor_1.RemixInterceptor; } });
10
- var livequery_interceptor_1 = require("./src/interceptors/livequery.interceptor");
11
- Object.defineProperty(exports, "LivequeryInterceptor", { enumerable: true, get: function () { return livequery_interceptor_1.LivequeryInterceptor; } });
12
- var Array2Map_1 = require("./src/helpers/Array2Map");
13
- Object.defineProperty(exports, "Array2Map", { enumerable: true, get: function () { return Array2Map_1.Array2Map; } });
14
- var DecoratorBuilder_1 = require("./src/decorators/DecoratorBuilder");
15
- Object.defineProperty(exports, "DecoratorBuilder", { enumerable: true, get: function () { return DecoratorBuilder_1.DecoratorBuilder; } });
16
- var LivequeryBinding_1 = require("./src/decorators/LivequeryBinding");
17
- Object.defineProperty(exports, "LivequeryBinding", { enumerable: true, get: function () { return LivequeryBinding_1.LivequeryBinding; } });
18
- var Remix_1 = require("./src/decorators/Remix");
19
- Object.defineProperty(exports, "Remix", { enumerable: true, get: function () { return Remix_1.Remix; } });
20
- var livequery_module_1 = require("./src/livequery.module");
21
- Object.defineProperty(exports, "LivequeryModule", { enumerable: true, get: function () { return livequery_module_1.LivequeryModule; } });
22
- var LivequeryResponse_1 = require("./src/LivequeryResponse");
23
- Object.defineProperty(exports, "createLivequeryResponse", { enumerable: true, get: function () { return LivequeryResponse_1.createLivequeryResponse; } });
24
- var SocketGateway_1 = require("./src/SocketGateway");
25
- Object.defineProperty(exports, "SocketGateway", { enumerable: true, get: function () { return SocketGateway_1.SocketGateway; } });
26
- Object.defineProperty(exports, "REF_ALIASES", { enumerable: true, get: function () { return SocketGateway_1.REF_ALIASES; } });
27
- var QueryFilterParser_1 = require("./src/QueryFilterParser");
28
- Object.defineProperty(exports, "QueryFilterParser", { enumerable: true, get: function () { return QueryFilterParser_1.QueryFilterParser; } });
@@ -1,12 +0,0 @@
1
- export declare const FilterExpressions: {
2
- eq: (a: any, b: any) => boolean;
3
- ne: (a: any, b: any) => boolean;
4
- lt: (a: any, b: any) => boolean;
5
- lte: (a: any, b: any) => boolean;
6
- gt: (a: any, b: any) => boolean;
7
- gte: (a: any, b: any) => boolean;
8
- in: (a: any, b: any[]) => boolean;
9
- nin: (a: any, b: any[]) => boolean;
10
- array_contains: (a: any[], b: any[]) => boolean;
11
- };
12
- export declare const FilterExpressionsList: string[];
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FilterExpressionsList = exports.FilterExpressions = void 0;
4
- exports.FilterExpressions = {
5
- eq: (a, b) => a == b,
6
- ne: (a, b) => a != b,
7
- lt: (a, b) => a < b,
8
- lte: (a, b) => a <= b,
9
- gt: (a, b) => a > b,
10
- gte: (a, b) => a >= b,
11
- in: (a, b) => b.includes(a),
12
- nin: (a, b) => !b.includes(a),
13
- array_contains: (a, b) => a.some(i => b.includes(i))
14
- };
15
- exports.FilterExpressionsList = Object.keys(exports.FilterExpressions);
@@ -1,9 +0,0 @@
1
- export declare function createLivequeryResponse(items: any[], cursor?: string, has_more?: boolean): {
2
- data: {
3
- has_more: boolean;
4
- count: number;
5
- cursor: string;
6
- items: any[];
7
- };
8
- };
9
- export declare type LivequeryResponse = ReturnType<typeof createLivequeryResponse>;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLivequeryResponse = void 0;
4
- function createLivequeryResponse(items, cursor = null, has_more = false) {
5
- return {
6
- data: {
7
- has_more,
8
- count: items.length,
9
- cursor,
10
- items
11
- }
12
- };
13
- }
14
- exports.createLivequeryResponse = createLivequeryResponse;
@@ -1,29 +0,0 @@
1
- import { Request } from 'express';
2
- export declare type QueryFilter = {
3
- key: string;
4
- expression: 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte' | 'in' | 'nin' | 'array_contains';
5
- value: number | string | boolean | null;
6
- };
7
- export declare const QueryFilterParser: (request: Request) => {
8
- live_session: string;
9
- limit: number;
10
- filters: QueryFilter[];
11
- order_by: string;
12
- cursor: string;
13
- refs: {
14
- collection: string;
15
- id: string;
16
- }[];
17
- ref: string;
18
- sort: string;
19
- target_id: string;
20
- params: import("express-serve-static-core").ParamsDictionary;
21
- isCollection: boolean;
22
- collectionRef: string;
23
- select: string[];
24
- search: string;
25
- };
26
- export declare type Livequery = ReturnType<typeof QueryFilterParser>;
27
- export declare type LivequeryRequest = Request & {
28
- livequery: Livequery;
29
- };
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryFilterParser = void 0;
4
- const FilterExpressions_1 = require("./FilterExpressions");
5
- const QueryRefParser_1 = require("./QueryRefParser");
6
- const QueryFilterParser = (request) => {
7
- var _a;
8
- const { refs, ref, isCollection, collectionRef, target_id } = QueryRefParser_1.QueryRefParser(request);
9
- const live_session = request.headers.ws_connection_id;
10
- const limit = Math.min(Number(request.query._limit), 120) || 20;
11
- const cursor = (request.headers.cursor || request.query._cursor);
12
- const query = request.query;
13
- const order_by = query._order_by || 'created_at';
14
- const search = query._q;
15
- const select = (_a = query._fields) === null || _a === void 0 ? void 0 : _a.split(',');
16
- const filters = Object
17
- .entries(query)
18
- .filter(item => item[0][0] != '_')
19
- .map(([key, c]) => {
20
- const condition = c.includes('|') ? c : `eq|${JSON.stringify(c)}`;
21
- const [expression, value] = condition.trim().split('|');
22
- if (!FilterExpressions_1.FilterExpressionsList.includes(expression))
23
- throw 'INVAILD_FUNCTION';
24
- return { key, expression, value: JSON.parse(value) };
25
- });
26
- return {
27
- live_session,
28
- limit,
29
- filters,
30
- order_by,
31
- cursor,
32
- refs,
33
- ref,
34
- sort: request.query._sort == 'asc' ? 'asc' : 'desc',
35
- target_id,
36
- params: request.params,
37
- isCollection,
38
- collectionRef,
39
- select,
40
- search
41
- };
42
- };
43
- exports.QueryFilterParser = QueryFilterParser;
@@ -1,19 +0,0 @@
1
- import { Request } from 'express';
2
- export declare const QueryRefParser: (request: Request & {
3
- _parsedUrl: {
4
- pathname: string;
5
- };
6
- }) => {
7
- refs: {
8
- collection: string;
9
- id: string;
10
- }[];
11
- ref: string;
12
- collectionRef: string;
13
- target_id: string;
14
- params: {
15
- [key: string]: string | number | boolean;
16
- };
17
- isCollection: boolean;
18
- };
19
- export declare type LivequeryRef = ReturnType<typeof QueryRefParser>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryRefParser = void 0;
4
- const QueryRefParser = (request) => {
5
- const parts = request._parsedUrl.pathname.split('/').slice(2, 100);
6
- const isCollection = parts.length % 2 == 1;
7
- const collectionRef = parts.slice(0, parts.length - (isCollection ? 0 : 1)).join('/');
8
- const refs = new Array(Math.ceil(parts.length / 2)).fill(0).map((_, index) => ({
9
- collection: parts[index * 2],
10
- id: parts[index * 2 + 1],
11
- }));
12
- const target_id = refs[refs.length - 1].id;
13
- const ref = parts.join('/');
14
- const params = request.params;
15
- return { refs, ref, collectionRef, target_id, params, isCollection };
16
- };
17
- exports.QueryRefParser = QueryRefParser;
@@ -1,43 +0,0 @@
1
- import { Livequery } from "./QueryFilterParser";
2
- export declare const REALTIME_DATA_EVENT = "realtime-update";
3
- export declare type SocketEvent<T> = T & {
4
- event: string;
5
- };
6
- export declare type RealtimeUpdateItem<T> = {
7
- id: string;
8
- type: 'INSERT' | 'UPDATE' | 'DELETE';
9
- data: T;
10
- ref: string;
11
- };
12
- export declare type RealtimeUpdate<T extends {
13
- id: string;
14
- }> = SocketEvent<{
15
- items: RealtimeUpdateItem<T>[];
16
- ref: string;
17
- }>;
18
- export declare const REF_ALIASES: unique symbol;
19
- export declare type REF_ALIASES = {
20
- [ref: string]: string[];
21
- };
22
- export declare class SocketGateway {
23
- private refs;
24
- private connections;
25
- private changes;
26
- private refs_aliases;
27
- constructor(ref_aliases?: REF_ALIASES);
28
- private handleConnection;
29
- private handleDisconnect;
30
- subscribe(req: Livequery): void;
31
- broadcast<T extends {
32
- id: string;
33
- }>(change: RealtimeUpdateItem<T>): void;
34
- unsubscribe(data: {
35
- ref: string;
36
- }, socket: WebSocket & {
37
- id: string;
38
- }): void;
39
- private loop;
40
- private remap;
41
- private send_broadcast;
42
- private sync;
43
- }
@@ -1,142 +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
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.SocketGateway = exports.REF_ALIASES = exports.REALTIME_DATA_EVENT = void 0;
16
- const common_1 = require("@nestjs/common");
17
- const websockets_1 = require("@nestjs/websockets");
18
- const uuid_1 = require("uuid");
19
- const Array2Map_1 = require("./helpers/Array2Map");
20
- exports.REALTIME_DATA_EVENT = 'realtime-update';
21
- exports.REF_ALIASES = Symbol.for('REF_ALIAS');
22
- let SocketGateway = class SocketGateway {
23
- constructor(ref_aliases = {}) {
24
- this.refs = new Map();
25
- this.connections = new Map();
26
- this.changes = [];
27
- this.refs_aliases = new Map();
28
- this.loop();
29
- for (const ref in ref_aliases) {
30
- this.refs_aliases.set(ref, new Set([
31
- ...ref_aliases[ref],
32
- ...this.refs_aliases.get(ref) || []
33
- ]));
34
- }
35
- }
36
- async handleConnection(socket) {
37
- const id = uuid_1.v4();
38
- this.connections.set(id, { refs: new Set(), socket });
39
- socket.id = id;
40
- socket.send(JSON.stringify({ event: 'info', id }));
41
- }
42
- async handleDisconnect(socket) {
43
- var _a;
44
- for (const ref of ((_a = this.connections.get(socket.id)) === null || _a === void 0 ? void 0 : _a.refs) || []) {
45
- this.refs.get(ref).delete(socket.id);
46
- }
47
- this.connections.delete(socket.id);
48
- }
49
- subscribe(req) {
50
- var _a;
51
- const { ref } = req;
52
- if (this.connections.has(req.live_session)) {
53
- if (!this.refs.has(ref))
54
- this.refs.set(ref, new Set());
55
- this.refs.get(ref).add(req.live_session);
56
- (_a = this.connections.get(req.live_session)) === null || _a === void 0 ? void 0 : _a.refs.add(ref);
57
- }
58
- }
59
- broadcast(change) {
60
- this.changes.push(change);
61
- }
62
- unsubscribe(data, socket) {
63
- var _a;
64
- if (!this.connections.has(socket.id))
65
- return;
66
- const refs = [...this.connections.get(socket.id).refs];
67
- for (const ref of refs)
68
- (_a = this.refs.get(ref)) === null || _a === void 0 ? void 0 : _a.delete(socket.id);
69
- }
70
- async loop() {
71
- while (true) {
72
- await new Promise(s => setTimeout(s, 500));
73
- try {
74
- for (const [ref, list] of Array2Map_1.Array2Map.groupBy2Key(this.changes.splice(0, 500), 'ref', 'id')) {
75
- await this.send_broadcast(ref, [...list.values()]);
76
- }
77
- }
78
- catch (e) {
79
- console.log(e);
80
- }
81
- }
82
- }
83
- remap(ref, from, to) {
84
- const a = ref.split('/');
85
- const b = from.split('/');
86
- const keys = b.reduce((p, c, i) => {
87
- if (c.includes(':'))
88
- p[c] = a[i];
89
- return p;
90
- }, {});
91
- return to
92
- .split('/')
93
- .map((item) => item.includes(':') ? keys[item] : item)
94
- .join('/');
95
- }
96
- async send_broadcast(ref, changes) {
97
- changes = Array.isArray(changes) ? changes : [changes];
98
- this.sync(ref, changes);
99
- const refs = ref.split('/');
100
- const is_document = refs.length % 2 == 0;
101
- if (is_document) {
102
- const collection_ref = refs.slice(0, refs.length - 1).join('/');
103
- this.sync(collection_ref, changes);
104
- }
105
- const get_collections_ref = path => path.split('/').filter((_, i) => i % 2 == 1).join('/');
106
- const collections = get_collections_ref(ref);
107
- for (const [real_path, aliases] of this.refs_aliases) {
108
- for (const alias of aliases) {
109
- if (get_collections_ref(real_path) == collections) {
110
- const mapped_ref = this.remap(ref, real_path, alias);
111
- this.send_broadcast(mapped_ref, changes);
112
- }
113
- }
114
- }
115
- }
116
- sync(ref, changes) {
117
- var _a;
118
- const event = {
119
- event: exports.REALTIME_DATA_EVENT,
120
- items: changes.map(item => (Object.assign(Object.assign({}, item), { ref }))),
121
- ref
122
- };
123
- for (const connection_id of this.refs.get(ref) || []) {
124
- const socket = (_a = this.connections.get(connection_id)) === null || _a === void 0 ? void 0 : _a.socket;
125
- socket.send(JSON.stringify(event));
126
- }
127
- }
128
- };
129
- __decorate([
130
- websockets_1.SubscribeMessage('unsubscribe'),
131
- __param(0, websockets_1.MessageBody()),
132
- __param(1, websockets_1.ConnectedSocket()),
133
- __metadata("design:type", Function),
134
- __metadata("design:paramtypes", [Object, Object]),
135
- __metadata("design:returntype", void 0)
136
- ], SocketGateway.prototype, "unsubscribe", null);
137
- SocketGateway = __decorate([
138
- websockets_1.WebSocketGateway({ path: process.env.REALTIME_UPDATE_SOCKET_PATH || '/livequery/realtime-updates' }),
139
- __param(0, common_1.Optional()), __param(0, common_1.Inject(exports.REF_ALIASES)),
140
- __metadata("design:paramtypes", [Object])
141
- ], SocketGateway);
142
- exports.SocketGateway = SocketGateway;
@@ -1,13 +0,0 @@
1
- import 'reflect-metadata';
2
- export declare class DecoratorBuilder<T> {
3
- private classWrapper;
4
- static createMetadataStorage: <T_1>() => [(options: T_1) => (target: any) => void, (target: any) => T_1[]];
5
- private hooks;
6
- constructor(classWrapper?: (target: any, options: T) => any);
7
- createPropertyOrMethodDecorator<T>(methodWrapper?: (target: any, method: string, options: T) => any): [(options?: T) => (target: any, method: any, descriptor: any) => void, (target: any) => Map<string, T[]>];
8
- getClassDecorator(): (options?: T) => (C: any) => any;
9
- getExtendableClass(): (options?: T, C?: new (...args: any[]) => any) => {
10
- [x: string]: any;
11
- };
12
- getActivatorFunction(): (target: any, options?: T) => void;
13
- }
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DecoratorBuilder = void 0;
4
- require("reflect-metadata");
5
- class DecoratorBuilder {
6
- constructor(classWrapper = () => { }) {
7
- this.classWrapper = classWrapper;
8
- this.hooks = [];
9
- }
10
- createPropertyOrMethodDecorator(methodWrapper) {
11
- const token = Symbol();
12
- const decorator = (options) => (target, method, descriptor) => {
13
- const map = Reflect.getMetadata(token, target) || new Map();
14
- map.set(method, [...map.get(method) || [], options]);
15
- Reflect.defineMetadata(token, map, target);
16
- };
17
- methodWrapper && this.hooks.push(target => {
18
- const map = Reflect.getMetadata(token, target) || [];
19
- for (const [method, list] of map) {
20
- list.map(options => methodWrapper(target, method, options));
21
- }
22
- });
23
- const list_metadata = target => (Reflect.getMetadata(token, typeof target == 'object' ? target : new target) || new Map());
24
- return [decorator, list_metadata];
25
- }
26
- getClassDecorator() {
27
- const hooks = this.hooks;
28
- const classWrapper = this.classWrapper;
29
- return (options) => C => {
30
- return class extends C {
31
- constructor(...args) {
32
- super(...args);
33
- for (const hook of hooks)
34
- hook(this);
35
- classWrapper(this, options);
36
- }
37
- };
38
- };
39
- }
40
- getExtendableClass() {
41
- const hooks = this.hooks;
42
- const classWrapper = this.classWrapper;
43
- return (options = {}, C = class {
44
- }) => new class extends C {
45
- constructor(...args) {
46
- super(...args);
47
- for (const hook of hooks)
48
- hook(this);
49
- classWrapper(this, options);
50
- }
51
- };
52
- }
53
- getActivatorFunction() {
54
- const hooks = this.hooks;
55
- const classWrapper = this.classWrapper;
56
- return (target, options) => {
57
- for (const hook of hooks)
58
- hook(target);
59
- classWrapper(target, options);
60
- };
61
- }
62
- }
63
- exports.DecoratorBuilder = DecoratorBuilder;
64
- DecoratorBuilder.createMetadataStorage = () => {
65
- const token = Symbol();
66
- const decorator = (options) => target => {
67
- const list = Reflect.getMetadata(token, target) || [];
68
- list.push(options);
69
- Reflect.defineMetadata(token, list, target);
70
- };
71
- const list_metadata = target => (Reflect.getMetadata(token, target) || []);
72
- return [decorator, list_metadata];
73
- };
@@ -1 +0,0 @@
1
- export declare const HideFields: (fields: string[]) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HideFields = void 0;
4
- const common_1 = require("@nestjs/common");
5
- const Remix_1 = require("./Remix");
6
- const HideFields = (fields) => common_1.applyDecorators(Remix_1.Remix(data => {
7
- const keys = Object.keys(data).filter(k => !fields.includes(k));
8
- return keys.reduce((p, c) => (Object.assign(Object.assign({}, p), { [c]: data[c] })), {});
9
- }));
10
- exports.HideFields = HideFields;
@@ -1 +0,0 @@
1
- export declare const LivequeryBinding: () => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LivequeryBinding = void 0;
4
- const common_1 = require("@nestjs/common");
5
- const livequery_interceptor_1 = require("../interceptors/livequery.interceptor");
6
- const LivequeryBinding = () => common_1.applyDecorators(common_1.UseInterceptors(livequery_interceptor_1.LivequeryInterceptor));
7
- exports.LivequeryBinding = LivequeryBinding;
@@ -1,2 +0,0 @@
1
- import { RemixFunction } from '../interceptors/remix.interceptor';
2
- export declare const Remix: (mapper: RemixFunction) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Remix = void 0;
4
- const common_1 = require("@nestjs/common");
5
- const remix_interceptor_1 = require("../interceptors/remix.interceptor");
6
- const Remix = (mapper) => common_1.applyDecorators(remix_interceptor_1.RemixListDecorator(mapper), common_1.UseInterceptors(remix_interceptor_1.RemixInterceptor));
7
- exports.Remix = Remix;
@@ -1 +0,0 @@
1
- export declare const ShowOnly: (fields: string[]) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ShowOnly = void 0;
4
- const common_1 = require("@nestjs/common");
5
- const Remix_1 = require("./Remix");
6
- const ShowOnly = (fields) => common_1.applyDecorators(Remix_1.Remix(data => {
7
- const keys = Object.keys(data).filter(k => fields.includes(k));
8
- return keys.reduce((p, c) => (Object.assign(Object.assign({}, p), { [c]: data[c] })), {});
9
- }));
10
- exports.ShowOnly = ShowOnly;
@@ -1,6 +0,0 @@
1
- export declare class Array2Map {
2
- private static group_array_by_key;
3
- static groupByKey<T>(items: T[], group_key: keyof T): Map<string, T>;
4
- static groupBy2Key<T>(items: T[], group_key: keyof T, id_key: keyof T): Map<string, Map<string, T>>;
5
- static groupBy3Key<T>(items: T[], group_key1: keyof T, group_key2: keyof T, id_key: keyof T): Map<string, Map<string, Map<string, T>>>;
6
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Array2Map = void 0;
4
- class Array2Map {
5
- static group_array_by_key(items, ...keys) {
6
- const map = new Map();
7
- for (const item of items) {
8
- let cursor = map;
9
- for (const [index, key_name] of keys.entries()) {
10
- const key = item[key_name];
11
- if (!cursor.has(key))
12
- cursor.set(key, index + 1 < keys.length ? new Map() : item);
13
- cursor = cursor.get(key);
14
- }
15
- }
16
- return map;
17
- }
18
- static groupByKey(items, group_key) {
19
- return this.group_array_by_key(items, group_key);
20
- }
21
- static groupBy2Key(items, group_key, id_key) {
22
- return this.group_array_by_key(items, group_key, id_key);
23
- }
24
- static groupBy3Key(items, group_key1, group_key2, id_key) {
25
- return this.group_array_by_key(items, group_key1, group_key2, id_key);
26
- }
27
- }
28
- exports.Array2Map = Array2Map;