@squidcloud/local-backend 1.0.148 → 1.0.151
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/dist/common/src/ai-assistant.types.d.ts +50 -50
- package/dist/common/src/ai-assistant.types.js +2 -2
- package/dist/common/src/ai-chatbot.context.d.ts +13 -13
- package/dist/common/src/ai-chatbot.context.js +19 -19
- package/dist/common/src/ai-chatbot.schemas.d.ts +18 -18
- package/dist/common/src/ai-chatbot.schemas.js +21 -21
- package/dist/common/src/ai-chatbot.types.d.ts +125 -123
- package/dist/common/src/ai-chatbot.types.js +18 -18
- package/dist/common/src/api-call.context.d.ts +13 -13
- package/dist/common/src/api-call.context.js +16 -16
- package/dist/common/src/api.types.d.ts +22 -22
- package/dist/common/src/api.types.js +2 -2
- package/dist/common/src/application.schemas.d.ts +1648 -1648
- package/dist/common/src/application.schemas.js +948 -948
- package/dist/common/src/application.types.d.ts +193 -193
- package/dist/common/src/application.types.js +89 -89
- package/dist/common/src/application.types.js.map +1 -1
- package/dist/common/src/backend-function.schemas.d.ts +3 -3
- package/dist/common/src/backend-function.schemas.js +11 -11
- package/dist/common/src/backend-function.types.d.ts +4 -4
- package/dist/common/src/backend-function.types.js +2 -2
- package/dist/common/src/backend-run.types.d.ts +54 -54
- package/dist/common/src/backend-run.types.js +92 -95
- package/dist/common/src/backend-run.types.js.map +1 -1
- package/dist/common/src/bundle-api.types.d.ts +65 -69
- package/dist/common/src/bundle-api.types.js +2 -2
- package/dist/common/src/bundle-data.types.d.ts +69 -74
- package/dist/common/src/bundle-data.types.js +2 -2
- package/dist/common/src/communication.types.d.ts +20 -19
- package/dist/common/src/communication.types.js +41 -40
- package/dist/common/src/communication.types.js.map +1 -1
- package/dist/common/src/context.types.d.ts +24 -24
- package/dist/common/src/context.types.js +2 -2
- package/dist/common/src/distributed-lock.context.d.ts +4 -4
- package/dist/common/src/distributed-lock.context.js +9 -9
- package/dist/common/src/document.types.d.ts +32 -32
- package/dist/common/src/document.types.js +50 -50
- package/dist/common/src/graphql.context.d.ts +14 -14
- package/dist/common/src/graphql.context.js +12 -12
- package/dist/common/src/graphql.types.d.ts +11 -11
- package/dist/common/src/graphql.types.js +34 -34
- package/dist/common/src/heartbeat.types.d.ts +4 -4
- package/dist/common/src/heartbeat.types.js +16 -16
- package/dist/common/src/http-status.enum.d.ts +50 -50
- package/dist/common/src/http-status.enum.js +54 -54
- package/dist/common/src/http-status.enum.js.map +1 -1
- package/dist/common/src/index.d.ts +54 -57
- package/dist/common/src/index.js +70 -73
- package/dist/common/src/index.js.map +1 -1
- package/dist/common/src/integrations/ai_chatbot.types.d.ts +31 -31
- package/dist/common/src/integrations/ai_chatbot.types.js +2 -2
- package/dist/common/src/integrations/api.types.d.ts +80 -80
- package/dist/common/src/integrations/api.types.js +2 -2
- package/dist/common/src/integrations/auth.types.d.ts +39 -39
- package/dist/common/src/integrations/auth.types.js +2 -2
- package/dist/common/src/integrations/database.types.d.ts +274 -274
- package/dist/common/src/integrations/database.types.js +2 -2
- package/dist/common/src/integrations/index.d.ts +134 -134
- package/dist/common/src/integrations/index.js +119 -119
- package/dist/common/src/integrations/index.js.map +1 -1
- package/dist/common/src/integrations/observability.types.d.ts +23 -23
- package/dist/common/src/integrations/observability.types.js +23 -23
- package/dist/common/src/logger.types.d.ts +21 -21
- package/dist/common/src/logger.types.js +11 -11
- package/dist/common/src/logger.types.js.map +1 -1
- package/dist/common/src/metrics.types.d.ts +73 -73
- package/dist/common/src/metrics.types.js +11 -11
- package/dist/common/src/mutation.context.d.ts +13 -13
- package/dist/common/src/mutation.context.js +26 -26
- package/dist/common/src/mutation.schemas.d.ts +5 -5
- package/dist/common/src/mutation.schemas.js +114 -114
- package/dist/common/src/mutation.types.d.ts +63 -63
- package/dist/common/src/mutation.types.js +142 -142
- package/dist/common/src/native-query.context.d.ts +7 -7
- package/dist/common/src/native-query.context.js +11 -11
- package/dist/common/src/native-query.types.d.ts +16 -16
- package/dist/common/src/native-query.types.js +2 -2
- package/dist/common/src/query/base-query-builder.d.ts +38 -38
- package/dist/common/src/query/base-query-builder.js +39 -39
- package/dist/common/src/query/index.d.ts +4 -4
- package/dist/common/src/query/index.js +20 -20
- package/dist/common/src/query/pagination.d.ts +46 -46
- package/dist/common/src/query/pagination.js +211 -211
- package/dist/common/src/query/query-context.d.ts +47 -47
- package/dist/common/src/query/query-context.js +159 -159
- package/dist/common/src/query/serialized-query.types.d.ts +24 -24
- package/dist/common/src/query/serialized-query.types.js +2 -2
- package/dist/common/src/query.types.d.ts +86 -86
- package/dist/common/src/query.types.js +97 -97
- package/dist/common/src/regions.d.ts +21 -21
- package/dist/common/src/regions.js +46 -46
- package/dist/common/src/schema/schema.types.d.ts +30 -30
- package/dist/common/src/schema/schema.types.js +173 -173
- package/dist/common/src/secret.schemas.d.ts +4 -4
- package/dist/common/src/secret.schemas.js +17 -17
- package/dist/common/src/secret.types.d.ts +68 -68
- package/dist/common/src/secret.types.js +5 -5
- package/dist/common/src/security.types.d.ts +3 -3
- package/dist/common/src/security.types.js +2 -2
- package/dist/common/src/socket.schemas.d.ts +3 -3
- package/dist/common/src/socket.schemas.js +57 -57
- package/dist/common/src/socket.types.d.ts +126 -126
- package/dist/common/src/socket.types.js +9 -9
- package/dist/common/src/socket.types.js.map +1 -1
- package/dist/common/src/time-units.d.ts +11 -11
- package/dist/common/src/time-units.js +14 -14
- package/dist/common/src/trigger.types.d.ts +15 -15
- package/dist/common/src/trigger.types.js +2 -2
- package/dist/common/src/types.d.ts +21 -21
- package/dist/common/src/types.js +2 -2
- package/dist/common/src/utils/array.d.ts +8 -8
- package/dist/common/src/utils/array.js +54 -54
- package/dist/common/src/utils/assert.d.ts +3 -3
- package/dist/common/src/utils/assert.js +14 -14
- package/dist/common/src/utils/error.d.ts +4 -4
- package/dist/common/src/utils/error.js +10 -10
- package/dist/common/src/utils/global.utils.d.ts +11 -11
- package/dist/common/src/utils/global.utils.js +50 -50
- package/dist/common/src/utils/http.d.ts +2 -2
- package/dist/common/src/utils/http.js +51 -51
- package/dist/common/src/utils/id.d.ts +2 -2
- package/dist/common/src/utils/id.js +21 -21
- package/dist/common/src/utils/lock.manager.d.ts +9 -9
- package/dist/common/src/utils/lock.manager.js +39 -39
- package/dist/common/src/utils/object.d.ts +5 -5
- package/dist/common/src/utils/object.js +75 -75
- package/dist/common/src/utils/serialization.d.ts +5 -5
- package/dist/common/src/utils/serialization.js +73 -73
- package/dist/common/src/utils/transforms.d.ts +18 -18
- package/dist/common/src/utils/transforms.js +104 -104
- package/dist/common/src/utils/url.d.ts +1 -1
- package/dist/common/src/utils/url.js +15 -15
- package/dist/common/src/utils/validation.d.ts +17 -17
- package/dist/common/src/utils/validation.js +199 -199
- package/dist/common/src/webhook-response.d.ts +6 -6
- package/dist/common/src/webhook-response.js +2 -2
- package/dist/common/src/websocket.impl.d.ts +21 -21
- package/dist/common/src/websocket.impl.js +79 -79
- package/dist/internal-common/src/code-executor.types.d.ts +13 -13
- package/dist/internal-common/src/code-executor.types.js +2 -2
- package/dist/internal-common/src/local-dev.types.d.ts +35 -35
- package/dist/internal-common/src/local-dev.types.js +2 -2
- package/dist/local-backend/package.json +48 -48
- package/dist/local-backend/src/index.d.ts +4 -4
- package/dist/local-backend/src/index.js +26 -26
- package/dist/local-backend/src/local-backend-socket.service.d.ts +18 -18
- package/dist/local-backend/src/local-backend-socket.service.js +107 -108
- package/dist/local-backend/src/local-backend-socket.service.js.map +1 -1
- package/dist/local-backend/src/local-backend.app.d.ts +2 -2
- package/dist/local-backend/src/local-backend.app.js +19 -19
- package/dist/local-backend/src/local-backend.controller.d.ts +8 -8
- package/dist/local-backend/src/local-backend.controller.js +48 -49
- package/dist/local-backend/src/local-backend.controller.js.map +1 -1
- package/dist/local-backend/src/local-backend.module.d.ts +8 -8
- package/dist/local-backend/src/local-backend.module.js +51 -53
- package/dist/local-backend/src/local-backend.module.js.map +1 -1
- package/dist/local-backend/src/local-backend.service.d.ts +15 -15
- package/dist/local-backend/src/local-backend.service.js +173 -176
- package/dist/local-backend/src/local-backend.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/common/src/named-query.context.d.ts +0 -4
- package/dist/common/src/named-query.context.js +0 -10
- package/dist/common/src/named-query.context.js.map +0 -1
- package/dist/common/src/named-query.schemas.d.ts +0 -3
- package/dist/common/src/named-query.schemas.js +0 -14
- package/dist/common/src/named-query.schemas.js.map +0 -1
- package/dist/common/src/named-query.types.d.ts +0 -8
- package/dist/common/src/named-query.types.js +0 -3
- package/dist/common/src/named-query.types.js.map +0 -1
- package/dist/internal-common/src/utils/logger-utils.d.ts +0 -3
- package/dist/internal-common/src/utils/logger-utils.js +0 -29
- package/dist/internal-common/src/utils/logger-utils.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './query-context';
|
|
2
|
-
export * from './base-query-builder';
|
|
3
|
-
export * from './serialized-query.types';
|
|
4
|
-
export * from './pagination';
|
|
1
|
+
export * from './query-context';
|
|
2
|
+
export * from './base-query-builder';
|
|
3
|
+
export * from './serialized-query.types';
|
|
4
|
+
export * from './pagination';
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./query-context"), exports);
|
|
18
|
-
__exportStar(require("./base-query-builder"), exports);
|
|
19
|
-
__exportStar(require("./serialized-query.types"), exports);
|
|
20
|
-
__exportStar(require("./pagination"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./query-context"), exports);
|
|
18
|
+
__exportStar(require("./base-query-builder"), exports);
|
|
19
|
+
__exportStar(require("./serialized-query.types"), exports);
|
|
20
|
+
__exportStar(require("./pagination"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { SnapshotEmitter } from './base-query-builder';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
export interface PaginationState<ReturnType> {
|
|
4
|
-
data: Array<ReturnType>;
|
|
5
|
-
hasNext: boolean;
|
|
6
|
-
hasPrev: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface PaginationOptions {
|
|
9
|
-
subscribe: boolean;
|
|
10
|
-
pageSize: number;
|
|
11
|
-
}
|
|
12
|
-
interface InternalState<ReturnType> {
|
|
13
|
-
data: ReturnType[];
|
|
14
|
-
extractedData: any[];
|
|
15
|
-
numBefore: number;
|
|
16
|
-
numAfter: number;
|
|
17
|
-
}
|
|
18
|
-
export declare class Pagination<ReturnType> {
|
|
19
|
-
private readonly options;
|
|
20
|
-
private internalStateObserver;
|
|
21
|
-
private firstElement;
|
|
22
|
-
private readonly isDestroyed;
|
|
23
|
-
private templateSnapshotEmitter;
|
|
24
|
-
private snapshotSubject;
|
|
25
|
-
private onFirstPage;
|
|
26
|
-
private navigatingToLastPage;
|
|
27
|
-
private lastElement;
|
|
28
|
-
constructor(snapshotEmitter: SnapshotEmitter<ReturnType>, options?: Partial<PaginationOptions>);
|
|
29
|
-
private goToFirstPage;
|
|
30
|
-
private static compareValues;
|
|
31
|
-
private compare;
|
|
32
|
-
private dataReceived;
|
|
33
|
-
private doNewQuery;
|
|
34
|
-
private waitForInternalState;
|
|
35
|
-
private internalStateToState;
|
|
36
|
-
unsubscribe(): void;
|
|
37
|
-
prevInternal(internalState: InternalState<ReturnType>): void;
|
|
38
|
-
prev(): Promise<PaginationState<ReturnType>>;
|
|
39
|
-
next(): Promise<PaginationState<ReturnType>>;
|
|
40
|
-
waitForData(): Promise<PaginationState<ReturnType>>;
|
|
41
|
-
observeState(): Observable<PaginationState<ReturnType>>;
|
|
42
|
-
first(): Promise<PaginationState<ReturnType>>;
|
|
43
|
-
refreshPage(): Promise<PaginationState<ReturnType>>;
|
|
44
|
-
last(): Promise<PaginationState<ReturnType>>;
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
1
|
+
import { SnapshotEmitter } from './base-query-builder';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export interface PaginationState<ReturnType> {
|
|
4
|
+
data: Array<ReturnType>;
|
|
5
|
+
hasNext: boolean;
|
|
6
|
+
hasPrev: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface PaginationOptions {
|
|
9
|
+
subscribe: boolean;
|
|
10
|
+
pageSize: number;
|
|
11
|
+
}
|
|
12
|
+
interface InternalState<ReturnType> {
|
|
13
|
+
data: ReturnType[];
|
|
14
|
+
extractedData: any[];
|
|
15
|
+
numBefore: number;
|
|
16
|
+
numAfter: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class Pagination<ReturnType> {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private internalStateObserver;
|
|
21
|
+
private firstElement;
|
|
22
|
+
private readonly isDestroyed;
|
|
23
|
+
private templateSnapshotEmitter;
|
|
24
|
+
private snapshotSubject;
|
|
25
|
+
private onFirstPage;
|
|
26
|
+
private navigatingToLastPage;
|
|
27
|
+
private lastElement;
|
|
28
|
+
constructor(snapshotEmitter: SnapshotEmitter<ReturnType>, options?: Partial<PaginationOptions>);
|
|
29
|
+
private goToFirstPage;
|
|
30
|
+
private static compareValues;
|
|
31
|
+
private compare;
|
|
32
|
+
private dataReceived;
|
|
33
|
+
private doNewQuery;
|
|
34
|
+
private waitForInternalState;
|
|
35
|
+
private internalStateToState;
|
|
36
|
+
unsubscribe(): void;
|
|
37
|
+
prevInternal(internalState: InternalState<ReturnType>): void;
|
|
38
|
+
prev(): Promise<PaginationState<ReturnType>>;
|
|
39
|
+
next(): Promise<PaginationState<ReturnType>>;
|
|
40
|
+
waitForData(): Promise<PaginationState<ReturnType>>;
|
|
41
|
+
observeState(): Observable<PaginationState<ReturnType>>;
|
|
42
|
+
first(): Promise<PaginationState<ReturnType>>;
|
|
43
|
+
refreshPage(): Promise<PaginationState<ReturnType>>;
|
|
44
|
+
last(): Promise<PaginationState<ReturnType>>;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Pagination = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
|
-
const object_1 = require("../utils/object");
|
|
6
|
-
const lodash_1 = require("lodash");
|
|
7
|
-
class Pagination {
|
|
8
|
-
constructor(snapshotEmitter, options = {}) {
|
|
9
|
-
this.internalStateObserver = new rxjs_1.BehaviorSubject(null);
|
|
10
|
-
this.firstElement = null;
|
|
11
|
-
this.isDestroyed = new rxjs_1.BehaviorSubject(false);
|
|
12
|
-
this.snapshotSubject = new rxjs_1.Subject();
|
|
13
|
-
this.onFirstPage = true;
|
|
14
|
-
this.navigatingToLastPage = false;
|
|
15
|
-
this.lastElement = null;
|
|
16
|
-
this.snapshotSubject.pipe((0, rxjs_1.switchAll)()).subscribe(data => this.dataReceived(data));
|
|
17
|
-
this.templateSnapshotEmitter = snapshotEmitter.clone();
|
|
18
|
-
this.options = Object.assign({ pageSize: 100, subscribe: true }, options);
|
|
19
|
-
this.goToFirstPage();
|
|
20
|
-
}
|
|
21
|
-
goToFirstPage() {
|
|
22
|
-
this.onFirstPage = true;
|
|
23
|
-
const firstPageSnapshot = this.templateSnapshotEmitter
|
|
24
|
-
.clone()
|
|
25
|
-
.limit(this.options.pageSize * 3)
|
|
26
|
-
.snapshots(this.options.subscribe);
|
|
27
|
-
this.snapshotSubject.next(firstPageSnapshot);
|
|
28
|
-
}
|
|
29
|
-
static compareValues(a, b) {
|
|
30
|
-
if (lodash_1.default.isNil(a)) {
|
|
31
|
-
return lodash_1.default.isNil(b) ? 0 : -1;
|
|
32
|
-
}
|
|
33
|
-
if (lodash_1.default.isNil(b)) {
|
|
34
|
-
return 1;
|
|
35
|
-
}
|
|
36
|
-
if (a > b) {
|
|
37
|
-
return 1;
|
|
38
|
-
}
|
|
39
|
-
else if (a < b) {
|
|
40
|
-
return -1;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
compare(doc1, doc2) {
|
|
47
|
-
if (lodash_1.default.isNil(doc2)) {
|
|
48
|
-
return 1;
|
|
49
|
-
}
|
|
50
|
-
for (const so of this.templateSnapshotEmitter.getSortOrders()) {
|
|
51
|
-
const currentComparison = Pagination.compareValues((0, object_1.getInPath)(doc1, so.fieldName), (0, object_1.getInPath)(doc2, so.fieldName));
|
|
52
|
-
if (currentComparison !== 0) {
|
|
53
|
-
if (so.asc) {
|
|
54
|
-
return currentComparison;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return -currentComparison;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return 0;
|
|
62
|
-
}
|
|
63
|
-
async dataReceived(data) {
|
|
64
|
-
const extractedData = data.map(s => this.templateSnapshotEmitter.extractData(s));
|
|
65
|
-
if (data.length === 0) {
|
|
66
|
-
if (this.onFirstPage) {
|
|
67
|
-
this.internalStateObserver.next({ numBefore: 0, numAfter: 0, data, extractedData });
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
this.goToFirstPage();
|
|
71
|
-
}
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (this.firstElement === null) {
|
|
75
|
-
if (this.lastElement !== null) {
|
|
76
|
-
const numAfter = extractedData.filter(s => this.compare(s, this.lastElement) === 1).length;
|
|
77
|
-
this.firstElement = extractedData[data.length - numAfter - this.options.pageSize];
|
|
78
|
-
this.lastElement = null;
|
|
79
|
-
}
|
|
80
|
-
else if (this.navigatingToLastPage) {
|
|
81
|
-
this.firstElement = extractedData[data.length - this.options.pageSize];
|
|
82
|
-
this.navigatingToLastPage = false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const numBefore = extractedData.filter(s => this.compare(s, this.firstElement) === -1).length;
|
|
86
|
-
const numAfter = Math.max(0, data.length - numBefore - this.options.pageSize);
|
|
87
|
-
if (numBefore === data.length) {
|
|
88
|
-
this.prevInternal({ numBefore, numAfter, data, extractedData });
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this.internalStateObserver.next({ numBefore, numAfter, data, extractedData });
|
|
92
|
-
}
|
|
93
|
-
doNewQuery(startingDoc, reverseOrder) {
|
|
94
|
-
this.onFirstPage = false;
|
|
95
|
-
if (reverseOrder) {
|
|
96
|
-
const newSnapshotEmitter = this.templateSnapshotEmitter
|
|
97
|
-
.clone()
|
|
98
|
-
.limit(this.options.pageSize * 3)
|
|
99
|
-
.flipSortOrder();
|
|
100
|
-
if (startingDoc) {
|
|
101
|
-
newSnapshotEmitter.addCompositeCondition(this.templateSnapshotEmitter.getSortOrders().map(sortOrder => {
|
|
102
|
-
return {
|
|
103
|
-
fieldName: sortOrder.fieldName,
|
|
104
|
-
operator: sortOrder.asc ? '<=' : '>=',
|
|
105
|
-
value: (0, object_1.getInPath)(startingDoc, sortOrder.fieldName) || null,
|
|
106
|
-
};
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
this.snapshotSubject.next(newSnapshotEmitter.snapshots(this.options.subscribe).pipe((0, rxjs_1.map)(s => s.reverse())));
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
const newSnapshotEmitter = this.templateSnapshotEmitter.clone().limit(this.options.pageSize * 3);
|
|
113
|
-
if (startingDoc) {
|
|
114
|
-
newSnapshotEmitter.addCompositeCondition(this.templateSnapshotEmitter.getSortOrders().map(sortOrder => {
|
|
115
|
-
return {
|
|
116
|
-
fieldName: sortOrder.fieldName,
|
|
117
|
-
operator: sortOrder.asc ? '>=' : '<=',
|
|
118
|
-
value: (0, object_1.getInPath)(startingDoc, sortOrder.fieldName) || null,
|
|
119
|
-
};
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
this.snapshotSubject.next(newSnapshotEmitter.snapshots(this.options.subscribe));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
async waitForInternalState() {
|
|
126
|
-
const internalState = this.internalStateObserver.value;
|
|
127
|
-
if (internalState !== null) {
|
|
128
|
-
return internalState;
|
|
129
|
-
}
|
|
130
|
-
return await (0, rxjs_1.firstValueFrom)((0, rxjs_1.race)(this.isDestroyed.pipe((0, rxjs_1.filter)(Boolean), (0, rxjs_1.map)(() => ({
|
|
131
|
-
data: [],
|
|
132
|
-
extractedData: [],
|
|
133
|
-
numBefore: 0,
|
|
134
|
-
numAfter: 0,
|
|
135
|
-
}))), this.internalStateObserver.pipe((0, rxjs_1.filter)((state) => state !== null), (0, rxjs_1.take)(1))));
|
|
136
|
-
}
|
|
137
|
-
internalStateToState(internalState) {
|
|
138
|
-
const { data, numBefore, numAfter, extractedData } = internalState;
|
|
139
|
-
return {
|
|
140
|
-
data: data
|
|
141
|
-
.filter((_, i) => this.compare(extractedData[i], this.firstElement) !== -1)
|
|
142
|
-
.slice(0, this.options.pageSize),
|
|
143
|
-
hasNext: numAfter > 0,
|
|
144
|
-
hasPrev: numBefore > 0,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
unsubscribe() {
|
|
148
|
-
this.isDestroyed.next(true);
|
|
149
|
-
this.isDestroyed.complete();
|
|
150
|
-
this.internalStateObserver.complete();
|
|
151
|
-
this.snapshotSubject.complete();
|
|
152
|
-
}
|
|
153
|
-
prevInternal(internalState) {
|
|
154
|
-
const { numBefore, numAfter, extractedData } = internalState;
|
|
155
|
-
this.firstElement = null;
|
|
156
|
-
this.lastElement = extractedData[numBefore - 1];
|
|
157
|
-
this.internalStateObserver.next(null);
|
|
158
|
-
this.doNewQuery(extractedData[extractedData.length - numAfter - 1], true);
|
|
159
|
-
}
|
|
160
|
-
async prev() {
|
|
161
|
-
this.prevInternal(await this.waitForInternalState());
|
|
162
|
-
return await this.waitForData();
|
|
163
|
-
}
|
|
164
|
-
async next() {
|
|
165
|
-
const { numBefore, extractedData } = await this.waitForInternalState();
|
|
166
|
-
if (numBefore + this.options.pageSize < extractedData.length) {
|
|
167
|
-
this.firstElement = extractedData[numBefore + this.options.pageSize];
|
|
168
|
-
}
|
|
169
|
-
this.internalStateObserver.next(null);
|
|
170
|
-
this.doNewQuery(extractedData[numBefore], false);
|
|
171
|
-
return await this.waitForData();
|
|
172
|
-
}
|
|
173
|
-
async waitForData() {
|
|
174
|
-
return this.internalStateToState(await this.waitForInternalState());
|
|
175
|
-
}
|
|
176
|
-
observeState() {
|
|
177
|
-
return this.internalStateObserver.pipe((0, rxjs_1.filter)((state) => state !== null), (0, rxjs_1.map)(state => {
|
|
178
|
-
return this.internalStateToState(state);
|
|
179
|
-
}));
|
|
180
|
-
}
|
|
181
|
-
async first() {
|
|
182
|
-
await this.waitForInternalState();
|
|
183
|
-
this.internalStateObserver.next(null);
|
|
184
|
-
this.firstElement = null;
|
|
185
|
-
this.lastElement = null;
|
|
186
|
-
this.goToFirstPage();
|
|
187
|
-
return await this.waitForData();
|
|
188
|
-
}
|
|
189
|
-
async refreshPage() {
|
|
190
|
-
const { extractedData } = await this.waitForInternalState();
|
|
191
|
-
this.internalStateObserver.next(null);
|
|
192
|
-
this.doNewQuery(extractedData[0], false);
|
|
193
|
-
return await this.waitForData();
|
|
194
|
-
}
|
|
195
|
-
async last() {
|
|
196
|
-
await this.waitForInternalState();
|
|
197
|
-
this.internalStateObserver.next(null);
|
|
198
|
-
this.firstElement = null;
|
|
199
|
-
this.lastElement = null;
|
|
200
|
-
this.navigatingToLastPage = true;
|
|
201
|
-
const lastPageSnapshot = this.templateSnapshotEmitter
|
|
202
|
-
.clone()
|
|
203
|
-
.limit(this.options.pageSize * 3)
|
|
204
|
-
.flipSortOrder()
|
|
205
|
-
.snapshots(this.options.subscribe)
|
|
206
|
-
.pipe((0, rxjs_1.map)(s => s.reverse()));
|
|
207
|
-
this.snapshotSubject.next(lastPageSnapshot);
|
|
208
|
-
return await this.waitForData();
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.Pagination = Pagination;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pagination = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const object_1 = require("../utils/object");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
class Pagination {
|
|
8
|
+
constructor(snapshotEmitter, options = {}) {
|
|
9
|
+
this.internalStateObserver = new rxjs_1.BehaviorSubject(null);
|
|
10
|
+
this.firstElement = null;
|
|
11
|
+
this.isDestroyed = new rxjs_1.BehaviorSubject(false);
|
|
12
|
+
this.snapshotSubject = new rxjs_1.Subject();
|
|
13
|
+
this.onFirstPage = true;
|
|
14
|
+
this.navigatingToLastPage = false;
|
|
15
|
+
this.lastElement = null;
|
|
16
|
+
this.snapshotSubject.pipe((0, rxjs_1.switchAll)()).subscribe(data => this.dataReceived(data));
|
|
17
|
+
this.templateSnapshotEmitter = snapshotEmitter.clone();
|
|
18
|
+
this.options = Object.assign({ pageSize: 100, subscribe: true }, options);
|
|
19
|
+
this.goToFirstPage();
|
|
20
|
+
}
|
|
21
|
+
goToFirstPage() {
|
|
22
|
+
this.onFirstPage = true;
|
|
23
|
+
const firstPageSnapshot = this.templateSnapshotEmitter
|
|
24
|
+
.clone()
|
|
25
|
+
.limit(this.options.pageSize * 3)
|
|
26
|
+
.snapshots(this.options.subscribe);
|
|
27
|
+
this.snapshotSubject.next(firstPageSnapshot);
|
|
28
|
+
}
|
|
29
|
+
static compareValues(a, b) {
|
|
30
|
+
if (lodash_1.default.isNil(a)) {
|
|
31
|
+
return lodash_1.default.isNil(b) ? 0 : -1;
|
|
32
|
+
}
|
|
33
|
+
if (lodash_1.default.isNil(b)) {
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
if (a > b) {
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
else if (a < b) {
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
compare(doc1, doc2) {
|
|
47
|
+
if (lodash_1.default.isNil(doc2)) {
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
for (const so of this.templateSnapshotEmitter.getSortOrders()) {
|
|
51
|
+
const currentComparison = Pagination.compareValues((0, object_1.getInPath)(doc1, so.fieldName), (0, object_1.getInPath)(doc2, so.fieldName));
|
|
52
|
+
if (currentComparison !== 0) {
|
|
53
|
+
if (so.asc) {
|
|
54
|
+
return currentComparison;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return -currentComparison;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
async dataReceived(data) {
|
|
64
|
+
const extractedData = data.map(s => this.templateSnapshotEmitter.extractData(s));
|
|
65
|
+
if (data.length === 0) {
|
|
66
|
+
if (this.onFirstPage) {
|
|
67
|
+
this.internalStateObserver.next({ numBefore: 0, numAfter: 0, data, extractedData });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.goToFirstPage();
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (this.firstElement === null) {
|
|
75
|
+
if (this.lastElement !== null) {
|
|
76
|
+
const numAfter = extractedData.filter(s => this.compare(s, this.lastElement) === 1).length;
|
|
77
|
+
this.firstElement = extractedData[data.length - numAfter - this.options.pageSize];
|
|
78
|
+
this.lastElement = null;
|
|
79
|
+
}
|
|
80
|
+
else if (this.navigatingToLastPage) {
|
|
81
|
+
this.firstElement = extractedData[data.length - this.options.pageSize];
|
|
82
|
+
this.navigatingToLastPage = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const numBefore = extractedData.filter(s => this.compare(s, this.firstElement) === -1).length;
|
|
86
|
+
const numAfter = Math.max(0, data.length - numBefore - this.options.pageSize);
|
|
87
|
+
if (numBefore === data.length) {
|
|
88
|
+
this.prevInternal({ numBefore, numAfter, data, extractedData });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.internalStateObserver.next({ numBefore, numAfter, data, extractedData });
|
|
92
|
+
}
|
|
93
|
+
doNewQuery(startingDoc, reverseOrder) {
|
|
94
|
+
this.onFirstPage = false;
|
|
95
|
+
if (reverseOrder) {
|
|
96
|
+
const newSnapshotEmitter = this.templateSnapshotEmitter
|
|
97
|
+
.clone()
|
|
98
|
+
.limit(this.options.pageSize * 3)
|
|
99
|
+
.flipSortOrder();
|
|
100
|
+
if (startingDoc) {
|
|
101
|
+
newSnapshotEmitter.addCompositeCondition(this.templateSnapshotEmitter.getSortOrders().map(sortOrder => {
|
|
102
|
+
return {
|
|
103
|
+
fieldName: sortOrder.fieldName,
|
|
104
|
+
operator: sortOrder.asc ? '<=' : '>=',
|
|
105
|
+
value: (0, object_1.getInPath)(startingDoc, sortOrder.fieldName) || null,
|
|
106
|
+
};
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
this.snapshotSubject.next(newSnapshotEmitter.snapshots(this.options.subscribe).pipe((0, rxjs_1.map)(s => s.reverse())));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const newSnapshotEmitter = this.templateSnapshotEmitter.clone().limit(this.options.pageSize * 3);
|
|
113
|
+
if (startingDoc) {
|
|
114
|
+
newSnapshotEmitter.addCompositeCondition(this.templateSnapshotEmitter.getSortOrders().map(sortOrder => {
|
|
115
|
+
return {
|
|
116
|
+
fieldName: sortOrder.fieldName,
|
|
117
|
+
operator: sortOrder.asc ? '>=' : '<=',
|
|
118
|
+
value: (0, object_1.getInPath)(startingDoc, sortOrder.fieldName) || null,
|
|
119
|
+
};
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
this.snapshotSubject.next(newSnapshotEmitter.snapshots(this.options.subscribe));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async waitForInternalState() {
|
|
126
|
+
const internalState = this.internalStateObserver.value;
|
|
127
|
+
if (internalState !== null) {
|
|
128
|
+
return internalState;
|
|
129
|
+
}
|
|
130
|
+
return await (0, rxjs_1.firstValueFrom)((0, rxjs_1.race)(this.isDestroyed.pipe((0, rxjs_1.filter)(Boolean), (0, rxjs_1.map)(() => ({
|
|
131
|
+
data: [],
|
|
132
|
+
extractedData: [],
|
|
133
|
+
numBefore: 0,
|
|
134
|
+
numAfter: 0,
|
|
135
|
+
}))), this.internalStateObserver.pipe((0, rxjs_1.filter)((state) => state !== null), (0, rxjs_1.take)(1))));
|
|
136
|
+
}
|
|
137
|
+
internalStateToState(internalState) {
|
|
138
|
+
const { data, numBefore, numAfter, extractedData } = internalState;
|
|
139
|
+
return {
|
|
140
|
+
data: data
|
|
141
|
+
.filter((_, i) => this.compare(extractedData[i], this.firstElement) !== -1)
|
|
142
|
+
.slice(0, this.options.pageSize),
|
|
143
|
+
hasNext: numAfter > 0,
|
|
144
|
+
hasPrev: numBefore > 0,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
unsubscribe() {
|
|
148
|
+
this.isDestroyed.next(true);
|
|
149
|
+
this.isDestroyed.complete();
|
|
150
|
+
this.internalStateObserver.complete();
|
|
151
|
+
this.snapshotSubject.complete();
|
|
152
|
+
}
|
|
153
|
+
prevInternal(internalState) {
|
|
154
|
+
const { numBefore, numAfter, extractedData } = internalState;
|
|
155
|
+
this.firstElement = null;
|
|
156
|
+
this.lastElement = extractedData[numBefore - 1];
|
|
157
|
+
this.internalStateObserver.next(null);
|
|
158
|
+
this.doNewQuery(extractedData[extractedData.length - numAfter - 1], true);
|
|
159
|
+
}
|
|
160
|
+
async prev() {
|
|
161
|
+
this.prevInternal(await this.waitForInternalState());
|
|
162
|
+
return await this.waitForData();
|
|
163
|
+
}
|
|
164
|
+
async next() {
|
|
165
|
+
const { numBefore, extractedData } = await this.waitForInternalState();
|
|
166
|
+
if (numBefore + this.options.pageSize < extractedData.length) {
|
|
167
|
+
this.firstElement = extractedData[numBefore + this.options.pageSize];
|
|
168
|
+
}
|
|
169
|
+
this.internalStateObserver.next(null);
|
|
170
|
+
this.doNewQuery(extractedData[numBefore], false);
|
|
171
|
+
return await this.waitForData();
|
|
172
|
+
}
|
|
173
|
+
async waitForData() {
|
|
174
|
+
return this.internalStateToState(await this.waitForInternalState());
|
|
175
|
+
}
|
|
176
|
+
observeState() {
|
|
177
|
+
return this.internalStateObserver.pipe((0, rxjs_1.filter)((state) => state !== null), (0, rxjs_1.map)(state => {
|
|
178
|
+
return this.internalStateToState(state);
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
async first() {
|
|
182
|
+
await this.waitForInternalState();
|
|
183
|
+
this.internalStateObserver.next(null);
|
|
184
|
+
this.firstElement = null;
|
|
185
|
+
this.lastElement = null;
|
|
186
|
+
this.goToFirstPage();
|
|
187
|
+
return await this.waitForData();
|
|
188
|
+
}
|
|
189
|
+
async refreshPage() {
|
|
190
|
+
const { extractedData } = await this.waitForInternalState();
|
|
191
|
+
this.internalStateObserver.next(null);
|
|
192
|
+
this.doNewQuery(extractedData[0], false);
|
|
193
|
+
return await this.waitForData();
|
|
194
|
+
}
|
|
195
|
+
async last() {
|
|
196
|
+
await this.waitForInternalState();
|
|
197
|
+
this.internalStateObserver.next(null);
|
|
198
|
+
this.firstElement = null;
|
|
199
|
+
this.lastElement = null;
|
|
200
|
+
this.navigatingToLastPage = true;
|
|
201
|
+
const lastPageSnapshot = this.templateSnapshotEmitter
|
|
202
|
+
.clone()
|
|
203
|
+
.limit(this.options.pageSize * 3)
|
|
204
|
+
.flipSortOrder()
|
|
205
|
+
.snapshots(this.options.subscribe)
|
|
206
|
+
.pipe((0, rxjs_1.map)(s => s.reverse()));
|
|
207
|
+
this.snapshotSubject.next(lastPageSnapshot);
|
|
208
|
+
return await this.waitForData();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.Pagination = Pagination;
|
|
212
212
|
//# sourceMappingURL=pagination.js.map
|