@squidcloud/client 1.0.147 → 1.0.149
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/cjs/index.js +8793 -8803
- package/dist/common/src/ai-assistant.types.d.ts +25 -25
- package/dist/common/src/ai-chatbot.context.d.ts +12 -12
- package/dist/common/src/ai-chatbot.schemas.d.ts +1 -1
- package/dist/common/src/ai-chatbot.types.d.ts +27 -27
- package/dist/common/src/api-call.context.d.ts +13 -13
- package/dist/common/src/api.types.d.ts +4 -4
- package/dist/common/src/application.schemas.d.ts +66 -66
- package/dist/common/src/application.types.d.ts +141 -143
- package/dist/common/src/backend-function.schemas.d.ts +1 -1
- package/dist/common/src/backend-function.types.d.ts +1 -1
- package/dist/common/src/backend-run.types.d.ts +2 -2
- package/dist/common/src/bundle-api.types.d.ts +41 -43
- package/dist/common/src/bundle-data.types.d.ts +5 -5
- package/dist/common/src/communication.types.d.ts +10 -8
- package/dist/common/src/context.types.d.ts +40 -40
- package/dist/common/src/distributed-lock.context.d.ts +4 -4
- package/dist/common/src/document.types.d.ts +22 -22
- package/dist/common/src/graphql.context.d.ts +7 -7
- package/dist/common/src/graphql.types.d.ts +9 -9
- package/dist/common/src/heartbeat.types.d.ts +1 -1
- package/dist/common/src/http-status.enum.d.ts +50 -50
- package/dist/common/src/index.d.ts +54 -57
- package/dist/common/src/integrations/ai_chatbot.types.d.ts +31 -31
- package/dist/common/src/integrations/api.types.d.ts +80 -80
- package/dist/common/src/integrations/auth.types.d.ts +47 -47
- package/dist/common/src/integrations/database.types.d.ts +274 -274
- package/dist/common/src/integrations/index.d.ts +134 -134
- package/dist/common/src/integrations/observability.types.d.ts +23 -23
- package/dist/common/src/logger.types.d.ts +21 -21
- package/dist/common/src/metrics.types.d.ts +1 -1
- package/dist/common/src/mutation.context.d.ts +14 -14
- package/dist/common/src/mutation.schemas.d.ts +1 -1
- package/dist/common/src/mutation.types.d.ts +53 -53
- package/dist/common/src/native-query.context.d.ts +7 -7
- package/dist/common/src/native-query.types.d.ts +16 -16
- package/dist/common/src/query/base-query-builder.d.ts +147 -147
- package/dist/common/src/query/index.d.ts +4 -4
- package/dist/common/src/query/pagination.d.ts +62 -62
- package/dist/common/src/query/query-context.d.ts +137 -137
- package/dist/common/src/query/serialized-query.types.d.ts +24 -24
- package/dist/common/src/query.types.d.ts +64 -64
- package/dist/common/src/regions.d.ts +1 -1
- package/dist/common/src/schema/schema.types.d.ts +54 -54
- package/dist/common/src/secret.schemas.d.ts +1 -1
- package/dist/common/src/secret.types.d.ts +22 -22
- package/dist/common/src/security.types.d.ts +1 -1
- package/dist/common/src/socket.schemas.d.ts +1 -1
- package/dist/common/src/socket.types.d.ts +5 -5
- package/dist/common/src/time-units.d.ts +1 -1
- package/dist/common/src/trigger.types.d.ts +1 -1
- package/dist/common/src/types.d.ts +14 -14
- package/dist/common/src/utils/array.d.ts +1 -1
- package/dist/common/src/utils/assert.d.ts +1 -1
- package/dist/common/src/utils/error.d.ts +4 -4
- package/dist/common/src/utils/global.utils.d.ts +1 -1
- package/dist/common/src/utils/http.d.ts +2 -2
- package/dist/common/src/utils/id.d.ts +2 -2
- package/dist/common/src/utils/lock.manager.d.ts +14 -14
- package/dist/common/src/utils/object.d.ts +5 -5
- package/dist/common/src/utils/serialization.d.ts +5 -6
- package/dist/common/src/utils/transforms.d.ts +18 -18
- package/dist/common/src/utils/url.d.ts +1 -1
- package/dist/common/src/utils/validation.d.ts +25 -25
- package/dist/common/src/webhook-response.d.ts +1 -1
- package/dist/common/src/websocket.impl.d.ts +21 -21
- package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -1239
- package/dist/typescript-client/src/ai-assistant-client.d.ts +73 -73
- package/dist/typescript-client/src/ai-chatbot-client.d.ts +174 -174
- package/dist/typescript-client/src/ai-chatbot-client.factory.d.ts +8 -8
- package/dist/typescript-client/src/ai.types.d.ts +61 -61
- package/dist/typescript-client/src/api.manager.d.ts +11 -11
- package/dist/typescript-client/src/auth.manager.d.ts +26 -26
- package/dist/typescript-client/src/backend-function.manager.d.ts +9 -9
- package/dist/typescript-client/src/client-id.service.d.ts +27 -27
- package/dist/typescript-client/src/collection-reference.d.ts +80 -80
- package/dist/typescript-client/src/collection-reference.factory.d.ts +13 -13
- package/dist/typescript-client/src/connection-details.d.ts +23 -23
- package/dist/typescript-client/src/data.manager.d.ts +174 -173
- package/dist/typescript-client/src/destruct.manager.d.ts +12 -12
- package/dist/typescript-client/src/distributed-lock.manager.d.ts +16 -16
- package/dist/typescript-client/src/document-identity.service.d.ts +12 -12
- package/dist/typescript-client/src/document-reference.d.ts +140 -140
- package/dist/typescript-client/src/document-reference.factory.d.ts +13 -13
- package/dist/typescript-client/src/document-store.d.ts +14 -14
- package/dist/typescript-client/src/graphql-client.d.ts +14 -14
- package/dist/typescript-client/src/graphql-client.factory.d.ts +11 -11
- package/dist/typescript-client/src/index.d.ts +9 -9
- package/dist/typescript-client/src/mutation/mutation-sender.d.ts +10 -10
- package/dist/typescript-client/src/native-query-manager.d.ts +7 -7
- package/dist/typescript-client/src/query/deserializer.d.ts +3 -3
- package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +161 -161
- package/dist/typescript-client/src/query/local-query-manager.d.ts +9 -9
- package/dist/typescript-client/src/query/query-builder.factory.d.ts +77 -77
- package/dist/typescript-client/src/query/query-sender.d.ts +33 -33
- package/dist/typescript-client/src/query/query-subscription.manager.d.ts +131 -130
- package/dist/typescript-client/src/query/query.types.d.ts +49 -49
- package/dist/typescript-client/src/rate-limiter.d.ts +32 -32
- package/dist/typescript-client/src/rpc.manager.d.ts +30 -30
- package/dist/typescript-client/src/secret.client.d.ts +22 -22
- package/dist/typescript-client/src/socket.manager.d.ts +43 -43
- package/dist/typescript-client/src/squid.d.ts +238 -269
- package/dist/typescript-client/src/state/state.service.spec.d.ts +1 -1
- package/dist/typescript-client/src/testing/setup-tests.d.ts +1 -1
- package/dist/typescript-client/src/types.d.ts +2 -2
- package/package.json +3 -2
- package/dist/common/src/named-query.context.d.ts +0 -4
- package/dist/common/src/named-query.schemas.d.ts +0 -1
- package/dist/common/src/named-query.types.d.ts +0 -1
- package/dist/typescript-client/src/named-query.manager.d.ts +0 -11
|
@@ -1,130 +1,131 @@
|
|
|
1
|
-
import { Alias, ClientRequestId, JoinCondition, Query, QueryResultData, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
|
|
2
|
-
import { Observable, Subject } from 'rxjs';
|
|
3
|
-
import { ClientIdService } from '../client-id.service';
|
|
4
|
-
import { DestructManager } from '../destruct.manager';
|
|
5
|
-
import DocumentIdentityService from '../document-identity.service';
|
|
6
|
-
import { DocumentStore } from '../document-store';
|
|
7
|
-
import { RpcManager } from '../rpc.manager';
|
|
8
|
-
import { QuerySender } from './query-sender';
|
|
9
|
-
import { OngoingQuery } from './query.types';
|
|
10
|
-
export declare const FETCH_BEYOND_LIMIT = 100;
|
|
11
|
-
export declare const LIMIT_UNDERFLOW_TRIGGER = 20;
|
|
12
|
-
export declare class QuerySubscriptionManager {
|
|
13
|
-
private readonly rpcManager;
|
|
14
|
-
private readonly clientIdService;
|
|
15
|
-
private readonly documentStore;
|
|
16
|
-
private readonly destructManager;
|
|
17
|
-
private readonly documentIdentityService;
|
|
18
|
-
private readonly querySender;
|
|
19
|
-
/**
|
|
20
|
-
* An observable used by the data manager, the query subscription manager (this class) identifies when a document no
|
|
21
|
-
* longer has queries that it is part of their result, such document is considered orphan. The data manager will mark
|
|
22
|
-
* as orphan.
|
|
23
|
-
*/
|
|
24
|
-
onOrphanDocuments: Subject<string[]>;
|
|
25
|
-
/** All the currently running queries with their full state. */
|
|
26
|
-
private readonly ongoingQueries;
|
|
27
|
-
/**
|
|
28
|
-
* The two maps below maintain the relation between document ids we know about locally to clientRequestIds (queries).
|
|
29
|
-
* This relation is used for determining whether a document can be safely removed.
|
|
30
|
-
*/
|
|
31
|
-
private readonly clientRequestIdToLocalDocuments;
|
|
32
|
-
private readonly localDocumentToClientRequestIds;
|
|
33
|
-
/**
|
|
34
|
-
* A data structure for mapping queries to allow reverse queries search (given a document, find all the matching
|
|
35
|
-
* queries)
|
|
36
|
-
*/
|
|
37
|
-
private readonly queryMappingManager;
|
|
38
|
-
private readonly queryResultsSubject;
|
|
39
|
-
constructor(rpcManager: RpcManager, clientIdService: ClientIdService, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService, querySender: QuerySender);
|
|
40
|
-
observeQueryResults(): Observable<QueryResultData>;
|
|
41
|
-
/**
|
|
42
|
-
* Returns true if the client knows about this clientRequestId. It may happen that it will return false in the case
|
|
43
|
-
* that the client unsubscribed from a query but the server sent a mutation update for this clientRequestId.
|
|
44
|
-
*/
|
|
45
|
-
hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Returns the query associated with the given clientRequestId. Throws error if the clientRequestId is not known.
|
|
48
|
-
*/
|
|
49
|
-
getQuery(clientRequestId: ClientRequestId): Query;
|
|
50
|
-
/**
|
|
51
|
-
* A query receives updates from
|
|
52
|
-
* 1 - An initial snapshot from the server or from a parent query
|
|
53
|
-
* 2 - Incremental updates from the server (or from a parent query before the query is registered)
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
private
|
|
99
|
-
private
|
|
100
|
-
private
|
|
101
|
-
private
|
|
102
|
-
private
|
|
103
|
-
private
|
|
104
|
-
private
|
|
105
|
-
private
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
* the
|
|
113
|
-
* the
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
private
|
|
130
|
-
|
|
1
|
+
import { Alias, ClientRequestId, JoinCondition, Query, QueryResultData, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
|
|
2
|
+
import { Observable, Subject } from 'rxjs';
|
|
3
|
+
import { ClientIdService } from '../client-id.service';
|
|
4
|
+
import { DestructManager } from '../destruct.manager';
|
|
5
|
+
import DocumentIdentityService from '../document-identity.service';
|
|
6
|
+
import { DocumentStore } from '../document-store';
|
|
7
|
+
import { RpcManager } from '../rpc.manager';
|
|
8
|
+
import { QuerySender } from './query-sender';
|
|
9
|
+
import { OngoingQuery } from './query.types';
|
|
10
|
+
export declare const FETCH_BEYOND_LIMIT = 100;
|
|
11
|
+
export declare const LIMIT_UNDERFLOW_TRIGGER = 20;
|
|
12
|
+
export declare class QuerySubscriptionManager {
|
|
13
|
+
private readonly rpcManager;
|
|
14
|
+
private readonly clientIdService;
|
|
15
|
+
private readonly documentStore;
|
|
16
|
+
private readonly destructManager;
|
|
17
|
+
private readonly documentIdentityService;
|
|
18
|
+
private readonly querySender;
|
|
19
|
+
/**
|
|
20
|
+
* An observable used by the data manager, the query subscription manager (this class) identifies when a document no
|
|
21
|
+
* longer has queries that it is part of their result, such document is considered orphan. The data manager will mark
|
|
22
|
+
* as orphan.
|
|
23
|
+
*/
|
|
24
|
+
onOrphanDocuments: Subject<string[]>;
|
|
25
|
+
/** All the currently running queries with their full state. */
|
|
26
|
+
private readonly ongoingQueries;
|
|
27
|
+
/**
|
|
28
|
+
* The two maps below maintain the relation between document ids we know about locally to clientRequestIds (queries).
|
|
29
|
+
* This relation is used for determining whether a document can be safely removed.
|
|
30
|
+
*/
|
|
31
|
+
private readonly clientRequestIdToLocalDocuments;
|
|
32
|
+
private readonly localDocumentToClientRequestIds;
|
|
33
|
+
/**
|
|
34
|
+
* A data structure for mapping queries to allow reverse queries search (given a document, find all the matching
|
|
35
|
+
* queries)
|
|
36
|
+
*/
|
|
37
|
+
private readonly queryMappingManager;
|
|
38
|
+
private readonly queryResultsSubject;
|
|
39
|
+
constructor(rpcManager: RpcManager, clientIdService: ClientIdService, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService, querySender: QuerySender);
|
|
40
|
+
observeQueryResults(): Observable<QueryResultData>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns true if the client knows about this clientRequestId. It may happen that it will return false in the case
|
|
43
|
+
* that the client unsubscribed from a query but the server sent a mutation update for this clientRequestId.
|
|
44
|
+
*/
|
|
45
|
+
hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the query associated with the given clientRequestId. Throws error if the clientRequestId is not known.
|
|
48
|
+
*/
|
|
49
|
+
getQuery(clientRequestId: ClientRequestId): Query;
|
|
50
|
+
/**
|
|
51
|
+
* A query receives updates from three different sources:
|
|
52
|
+
* 1 - An initial snapshot from the server or from a parent query
|
|
53
|
+
* 2 - Incremental updates from the server (or from a parent query before the query is registered)
|
|
54
|
+
* 3 - A new snapshot if the query is refreshed after connection has been lost.
|
|
55
|
+
*
|
|
56
|
+
* If an incremental update is received before the snapshot was received, we cannot process it for this query.
|
|
57
|
+
* This boolean indicates whether the initial snapshot was received.
|
|
58
|
+
*/
|
|
59
|
+
setGotInitialResult(clientRequestId: ClientRequestId): void;
|
|
60
|
+
/** Given a document, returns all the queries that should be notified with the new document properties. */
|
|
61
|
+
findQueriesForDocument(doc: SquidDocument, squidDocId: SquidDocId): Array<QuerySubscriptionId>;
|
|
62
|
+
/**
|
|
63
|
+
* Given the new document's properties, finds all the queries that should be notified with the new properties and
|
|
64
|
+
* updates the internal mappings (squidDocId --> client request Ids and, clientRequestId --> squidDocIds).
|
|
65
|
+
* Returns an array with all the previous and current client request ids (basically all the client request ids that
|
|
66
|
+
* will need to be notified due to the change of properties).
|
|
67
|
+
*/
|
|
68
|
+
setClientRequestIdsForLocalDoc(squidDocId: SquidDocId, properties: SquidDocument | undefined): Array<ClientRequestId>;
|
|
69
|
+
/**
|
|
70
|
+
* Due to an error when syncing a document, all the queries that are subscribed to this document should be notified
|
|
71
|
+
* and error out.
|
|
72
|
+
*/
|
|
73
|
+
errorOutAllQueries(squidDocId: SquidDocId, err: any): void;
|
|
74
|
+
/** Notifies to all the given queries (identified by their clientRequestId) with the updated query result. */
|
|
75
|
+
notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
|
|
76
|
+
private isValidParent;
|
|
77
|
+
/**
|
|
78
|
+
* Given an ongoing query, search for candidate ongoing queries that can serve as a parent.
|
|
79
|
+
* If there is a parent query, the result of that query can be used for serving the current query.
|
|
80
|
+
* We will still register the current query on the server, but we do not need to run the query, apply security rules,
|
|
81
|
+
* etc.
|
|
82
|
+
*/
|
|
83
|
+
private findValidParentOfOngoingQuery;
|
|
84
|
+
findValidParentOfQuery(query: Query): OngoingQuery | undefined;
|
|
85
|
+
processQuery(query: Query, rootAlias: Alias, joins: Record<string, Query>, joinConditions: Record<Alias, JoinCondition>, subscribe: boolean, forceFetchFromServer: boolean): Observable<Array<Record<Alias, SquidDocument | undefined>>>;
|
|
86
|
+
/**
|
|
87
|
+
* Returns whether the given document ID has a query that has this document ID as a result.
|
|
88
|
+
* A document without a query is considered "un-tracked".
|
|
89
|
+
*/
|
|
90
|
+
hasOngoingQueryForDocId(squidDocId: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Removes a query from the mapping and updates the orphan documents as needed.
|
|
93
|
+
*/
|
|
94
|
+
private removeClientRequestIdMapping;
|
|
95
|
+
/** Register logic for cleaning up the query when it is unsubscribed. */
|
|
96
|
+
private registerQueryFinalizer;
|
|
97
|
+
/** Creates a graph of ongoing queries and returns the root of the graph. */
|
|
98
|
+
private createOngoingQueryGraph;
|
|
99
|
+
private collectAllObservables;
|
|
100
|
+
private joinResults;
|
|
101
|
+
private join;
|
|
102
|
+
private getOngoingQueriesBfs;
|
|
103
|
+
private updateOngoingQueryWithNewDataFromSupportingQuery;
|
|
104
|
+
private allOngoingQueriesGotInitialResult;
|
|
105
|
+
private completeAllSupportedQueries;
|
|
106
|
+
private preDestruct;
|
|
107
|
+
unsubscribe(): void;
|
|
108
|
+
hasSubscription(clientRequestId: ClientRequestId): boolean;
|
|
109
|
+
/** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
|
|
110
|
+
private sendQueryToServerOrUseParentQuery;
|
|
111
|
+
/**
|
|
112
|
+
* Uses the parent query as the source of data for the given ongoing query until the ongoing query is registered on
|
|
113
|
+
* the server. It prevents the parent query from being unsubscribed until the query is registered on the server and
|
|
114
|
+
* the first snapshot is received from the parent query.
|
|
115
|
+
* 1 - Prevents the parent query from being unsubscribed
|
|
116
|
+
* 2 - Connects the results of the parent query to the result of the current ongoing query
|
|
117
|
+
* 3 - Registers the query on the server
|
|
118
|
+
*/
|
|
119
|
+
private useParentOngoingQuery;
|
|
120
|
+
/**
|
|
121
|
+
* Sends the /query request to the server. It:
|
|
122
|
+
* 1 - Waits for when it is safe to send a query to the server (no in-flight mutations)
|
|
123
|
+
* 2 - Increments the number of inflightQueriesCount to prevent parallel mutations
|
|
124
|
+
* 3 - Handles errors
|
|
125
|
+
* 4 - Marks the query as registered
|
|
126
|
+
*/
|
|
127
|
+
private sendQueryToServer;
|
|
128
|
+
/** naive way to refresh queries/subscriptions when we have a new client id */
|
|
129
|
+
private refreshOngoingQueries;
|
|
130
|
+
private migrateDocIds;
|
|
131
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { Alias, ClientRequestId, JoinCondition, Query, SquidDocument } from '@squidcloud/common';
|
|
2
|
-
import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';
|
|
3
|
-
export interface OngoingQuery {
|
|
4
|
-
clientRequestId: ClientRequestId;
|
|
5
|
-
query: Query;
|
|
6
|
-
supportedQueries: Array<OngoingQuery>;
|
|
7
|
-
supportingOngoingQuery?: OngoingQuery;
|
|
8
|
-
gotInitialResponse: boolean;
|
|
9
|
-
activated: boolean;
|
|
10
|
-
joinCondition?: JoinCondition;
|
|
11
|
-
alias: Alias;
|
|
12
|
-
dataSubject: BehaviorSubject<Array<SquidDocument> | null>;
|
|
13
|
-
queryRegistered: BehaviorSubject<boolean>;
|
|
14
|
-
/**
|
|
15
|
-
* In case that this query is a parent of another query (that is, the other query is a subset of this query), this
|
|
16
|
-
* query should not be unsubscribed from the server until we registered the child query in the server.
|
|
17
|
-
*/
|
|
18
|
-
unsubscribeBlockerCount: BehaviorSubject<number>;
|
|
19
|
-
subscribe: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* In case of joins, and if this ongoing query is the root, this field emits all the supported observables
|
|
22
|
-
* for example A.join(B, {...some join condition...}).join(C, {...some join condition}.
|
|
23
|
-
* This field will emit [A.subject.pipe(), B.subject.pipe(), C.subject.pipe()]. Any new supported queries will be
|
|
24
|
-
* added here.
|
|
25
|
-
*/
|
|
26
|
-
allObservables?: ReplaySubject<Array<Observable<DocsAndAlias>>>;
|
|
27
|
-
isEmptyForJoin: boolean;
|
|
28
|
-
done: boolean;
|
|
29
|
-
isInFlight: boolean;
|
|
30
|
-
forceFetchFromServer: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* If there's a limit, we request `limit + FETCH_BEYOND_LIMIT` documents from the server.
|
|
33
|
-
* If we got that many documents, that means there may be even more. In that case, if our result set goes below
|
|
34
|
-
* `limit + LIMIT_UNDERFLOW_TRIGGER` documents (due to local or remote deletions), we need to resend the query to the
|
|
35
|
-
* server to potentially get more documents.
|
|
36
|
-
* If the number of documents is less than `limit + FETCH_BEYOND_LIMIT`, that means there are not that many documents
|
|
37
|
-
* on the server, so we don't need to resend the query regardless of how small our result size is or becomes.
|
|
38
|
-
*/
|
|
39
|
-
limitUnderflowState: LimitUnderflowState;
|
|
40
|
-
}
|
|
41
|
-
export declare enum LimitUnderflowState {
|
|
42
|
-
UNKNOWN = 0,
|
|
43
|
-
DISABLED = 1,
|
|
44
|
-
ENABLED = 2
|
|
45
|
-
}
|
|
46
|
-
export interface DocsAndAlias {
|
|
47
|
-
docs: Array<SquidDocument>;
|
|
48
|
-
alias: Alias;
|
|
49
|
-
}
|
|
1
|
+
import { Alias, ClientRequestId, JoinCondition, Query, SquidDocument } from '@squidcloud/common';
|
|
2
|
+
import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';
|
|
3
|
+
export interface OngoingQuery {
|
|
4
|
+
clientRequestId: ClientRequestId;
|
|
5
|
+
query: Query;
|
|
6
|
+
supportedQueries: Array<OngoingQuery>;
|
|
7
|
+
supportingOngoingQuery?: OngoingQuery;
|
|
8
|
+
gotInitialResponse: boolean;
|
|
9
|
+
activated: boolean;
|
|
10
|
+
joinCondition?: JoinCondition;
|
|
11
|
+
alias: Alias;
|
|
12
|
+
dataSubject: BehaviorSubject<Array<SquidDocument> | null>;
|
|
13
|
+
queryRegistered: BehaviorSubject<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* In case that this query is a parent of another query (that is, the other query is a subset of this query), this
|
|
16
|
+
* query should not be unsubscribed from the server until we registered the child query in the server.
|
|
17
|
+
*/
|
|
18
|
+
unsubscribeBlockerCount: BehaviorSubject<number>;
|
|
19
|
+
subscribe: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* In case of joins, and if this ongoing query is the root, this field emits all the supported observables
|
|
22
|
+
* for example A.join(B, {...some join condition...}).join(C, {...some join condition}.
|
|
23
|
+
* This field will emit [A.subject.pipe(), B.subject.pipe(), C.subject.pipe()]. Any new supported queries will be
|
|
24
|
+
* added here.
|
|
25
|
+
*/
|
|
26
|
+
allObservables?: ReplaySubject<Array<Observable<DocsAndAlias>>>;
|
|
27
|
+
isEmptyForJoin: boolean;
|
|
28
|
+
done: boolean;
|
|
29
|
+
isInFlight: boolean;
|
|
30
|
+
forceFetchFromServer: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* If there's a limit, we request `limit + FETCH_BEYOND_LIMIT` documents from the server.
|
|
33
|
+
* If we got that many documents, that means there may be even more. In that case, if our result set goes below
|
|
34
|
+
* `limit + LIMIT_UNDERFLOW_TRIGGER` documents (due to local or remote deletions), we need to resend the query to the
|
|
35
|
+
* server to potentially get more documents.
|
|
36
|
+
* If the number of documents is less than `limit + FETCH_BEYOND_LIMIT`, that means there are not that many documents
|
|
37
|
+
* on the server, so we don't need to resend the query regardless of how small our result size is or becomes.
|
|
38
|
+
*/
|
|
39
|
+
limitUnderflowState: LimitUnderflowState;
|
|
40
|
+
}
|
|
41
|
+
export declare enum LimitUnderflowState {
|
|
42
|
+
UNKNOWN = 0,
|
|
43
|
+
DISABLED = 1,
|
|
44
|
+
ENABLED = 2
|
|
45
|
+
}
|
|
46
|
+
export interface DocsAndAlias {
|
|
47
|
+
docs: Array<SquidDocument>;
|
|
48
|
+
alias: Alias;
|
|
49
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
export declare class RateLimiter {
|
|
2
|
-
private readonly capacity;
|
|
3
|
-
private readonly seconds;
|
|
4
|
-
private tokens;
|
|
5
|
-
private lastRefillTimestamp;
|
|
6
|
-
private readonly refillRatePerMs;
|
|
7
|
-
/**
|
|
8
|
-
* Creates a new rate limiter. It limits the number of requests using two parameters:
|
|
9
|
-
* - capacity: the maximum number of tokens (actions) that can be stored at any given time
|
|
10
|
-
* - seconds: the number of seconds it takes to refill the bucket to its maximum capacity
|
|
11
|
-
*
|
|
12
|
-
* We then can calculate the refillRatePerMs: the number of tokens (actions) that are added to the bucket every
|
|
13
|
-
* millisecond
|
|
14
|
-
*
|
|
15
|
-
* Example:
|
|
16
|
-
* Say we want to allow maximum 60 requests in a period of 5 seconds. We can create a rate limiter with:
|
|
17
|
-
* - capacity: 60
|
|
18
|
-
* - seconds: 5
|
|
19
|
-
* And we will get refillRatePerMs: 60 / (5 * 1000) = 0.012
|
|
20
|
-
*
|
|
21
|
-
* To use:
|
|
22
|
-
* const rateLimiter = new RateLimiter(60, 5);
|
|
23
|
-
* await rateLimiter.consume();
|
|
24
|
-
*
|
|
25
|
-
* @param capacity
|
|
26
|
-
* @param refillRatePerMs
|
|
27
|
-
*/
|
|
28
|
-
constructor(capacity: number, seconds: number);
|
|
29
|
-
consume(): Promise<void>;
|
|
30
|
-
private attemptConsume;
|
|
31
|
-
private refill;
|
|
32
|
-
}
|
|
1
|
+
export declare class RateLimiter {
|
|
2
|
+
private readonly capacity;
|
|
3
|
+
private readonly seconds;
|
|
4
|
+
private tokens;
|
|
5
|
+
private lastRefillTimestamp;
|
|
6
|
+
private readonly refillRatePerMs;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new rate limiter. It limits the number of requests using two parameters:
|
|
9
|
+
* - capacity: the maximum number of tokens (actions) that can be stored at any given time
|
|
10
|
+
* - seconds: the number of seconds it takes to refill the bucket to its maximum capacity
|
|
11
|
+
*
|
|
12
|
+
* We then can calculate the refillRatePerMs: the number of tokens (actions) that are added to the bucket every
|
|
13
|
+
* millisecond
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* Say we want to allow maximum 60 requests in a period of 5 seconds. We can create a rate limiter with:
|
|
17
|
+
* - capacity: 60
|
|
18
|
+
* - seconds: 5
|
|
19
|
+
* And we will get refillRatePerMs: 60 / (5 * 1000) = 0.012
|
|
20
|
+
*
|
|
21
|
+
* To use:
|
|
22
|
+
* const rateLimiter = new RateLimiter(60, 5);
|
|
23
|
+
* await rateLimiter.consume();
|
|
24
|
+
*
|
|
25
|
+
* @param capacity
|
|
26
|
+
* @param refillRatePerMs
|
|
27
|
+
*/
|
|
28
|
+
constructor(capacity: number, seconds: number);
|
|
29
|
+
consume(): Promise<void>;
|
|
30
|
+
private attemptConsume;
|
|
31
|
+
private refill;
|
|
32
|
+
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { SupportedSquidRegion } from '@squidcloud/common';
|
|
2
|
-
import { AuthManager } from './auth.manager';
|
|
3
|
-
import { ClientIdService } from './client-id.service';
|
|
4
|
-
import { DestructManager } from './destruct.manager';
|
|
5
|
-
import { BlobAndFilename } from './types';
|
|
6
|
-
export declare class RpcManager {
|
|
7
|
-
private readonly region;
|
|
8
|
-
private readonly appId;
|
|
9
|
-
private readonly authManager;
|
|
10
|
-
private readonly clientIdService;
|
|
11
|
-
private readonly staticHeaders;
|
|
12
|
-
private readonly onGoingRpcCounter;
|
|
13
|
-
private readonly rateLimiters;
|
|
14
|
-
constructor(region: SupportedSquidRegion, appId: string, destructManager: DestructManager, headers: Record<string, string> | undefined, authManager: AuthManager, clientIdService: ClientIdService);
|
|
15
|
-
private getAuthHeaders;
|
|
16
|
-
awaitAllSettled(): Promise<void>;
|
|
17
|
-
setStaticHeader(key: string, value: string): void;
|
|
18
|
-
deleteStaticHeader(key: string): void;
|
|
19
|
-
getStaticHeaders(): Record<string, string>;
|
|
20
|
-
post<T>(path: string, message: any, files?: Array<File | BlobAndFilename>, filesFieldName?: string): Promise<T>;
|
|
21
|
-
private tryDeserializing;
|
|
22
|
-
private getRateLimiterBucket;
|
|
23
|
-
}
|
|
24
|
-
export declare class RpcError extends Error {
|
|
25
|
-
readonly statusCode: number;
|
|
26
|
-
readonly statusText: string;
|
|
27
|
-
readonly headers: Headers;
|
|
28
|
-
readonly url: string;
|
|
29
|
-
constructor(statusCode: number, statusText: string, headers: Headers, url: string, message?: string);
|
|
30
|
-
}
|
|
1
|
+
import { SupportedSquidRegion } from '@squidcloud/common';
|
|
2
|
+
import { AuthManager } from './auth.manager';
|
|
3
|
+
import { ClientIdService } from './client-id.service';
|
|
4
|
+
import { DestructManager } from './destruct.manager';
|
|
5
|
+
import { BlobAndFilename } from './types';
|
|
6
|
+
export declare class RpcManager {
|
|
7
|
+
private readonly region;
|
|
8
|
+
private readonly appId;
|
|
9
|
+
private readonly authManager;
|
|
10
|
+
private readonly clientIdService;
|
|
11
|
+
private readonly staticHeaders;
|
|
12
|
+
private readonly onGoingRpcCounter;
|
|
13
|
+
private readonly rateLimiters;
|
|
14
|
+
constructor(region: SupportedSquidRegion, appId: string, destructManager: DestructManager, headers: Record<string, string> | undefined, authManager: AuthManager, clientIdService: ClientIdService);
|
|
15
|
+
private getAuthHeaders;
|
|
16
|
+
awaitAllSettled(): Promise<void>;
|
|
17
|
+
setStaticHeader(key: string, value: string): void;
|
|
18
|
+
deleteStaticHeader(key: string): void;
|
|
19
|
+
getStaticHeaders(): Record<string, string>;
|
|
20
|
+
post<T>(path: string, message: any, files?: Array<File | BlobAndFilename>, filesFieldName?: string): Promise<T>;
|
|
21
|
+
private tryDeserializing;
|
|
22
|
+
private getRateLimiterBucket;
|
|
23
|
+
}
|
|
24
|
+
export declare class RpcError extends Error {
|
|
25
|
+
readonly statusCode: number;
|
|
26
|
+
readonly statusText: string;
|
|
27
|
+
readonly headers: Headers;
|
|
28
|
+
readonly url: string;
|
|
29
|
+
constructor(statusCode: number, statusText: string, headers: Headers, url: string, message?: string);
|
|
30
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { SecretEntry, SecretKey, SecretValue, SetSecretRequestEntry } from '@squidcloud/common';
|
|
2
|
-
import { RpcManager } from './rpc.manager';
|
|
3
|
-
export declare class SecretClient {
|
|
4
|
-
private readonly rpcManager;
|
|
5
|
-
constructor(rpcManager: RpcManager);
|
|
6
|
-
get(key: SecretKey): Promise<SecretEntry | undefined>;
|
|
7
|
-
getAll(): Promise<Record<SecretKey, SecretEntry>>;
|
|
8
|
-
upsert(key: SecretKey, value: SecretValue): Promise<SecretEntry>;
|
|
9
|
-
upsertMany(entries: Array<SetSecretRequestEntry>): Promise<Array<SecretEntry>>;
|
|
10
|
-
delete(key: SecretKey): Promise<void>;
|
|
11
|
-
deleteMany(keys: Array<SecretKey>): Promise<void>;
|
|
12
|
-
get apiKeys(): ApiKeysSecretClient;
|
|
13
|
-
}
|
|
14
|
-
declare class ApiKeysSecretClient {
|
|
15
|
-
private readonly rpcManager;
|
|
16
|
-
constructor(rpcManager: RpcManager);
|
|
17
|
-
get(key: SecretKey): Promise<SecretEntry | undefined>;
|
|
18
|
-
getAll(): Promise<Record<SecretKey, SecretEntry>>;
|
|
19
|
-
upsert(key: SecretKey): Promise<SecretEntry>;
|
|
20
|
-
delete(key: SecretKey): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
1
|
+
import { SecretEntry, SecretKey, SecretValue, SetSecretRequestEntry } from '@squidcloud/common';
|
|
2
|
+
import { RpcManager } from './rpc.manager';
|
|
3
|
+
export declare class SecretClient {
|
|
4
|
+
private readonly rpcManager;
|
|
5
|
+
constructor(rpcManager: RpcManager);
|
|
6
|
+
get(key: SecretKey): Promise<SecretEntry | undefined>;
|
|
7
|
+
getAll(): Promise<Record<SecretKey, SecretEntry>>;
|
|
8
|
+
upsert(key: SecretKey, value: SecretValue): Promise<SecretEntry>;
|
|
9
|
+
upsertMany(entries: Array<SetSecretRequestEntry>): Promise<Array<SecretEntry>>;
|
|
10
|
+
delete(key: SecretKey): Promise<void>;
|
|
11
|
+
deleteMany(keys: Array<SecretKey>): Promise<void>;
|
|
12
|
+
get apiKeys(): ApiKeysSecretClient;
|
|
13
|
+
}
|
|
14
|
+
declare class ApiKeysSecretClient {
|
|
15
|
+
private readonly rpcManager;
|
|
16
|
+
constructor(rpcManager: RpcManager);
|
|
17
|
+
get(key: SecretKey): Promise<SecretEntry | undefined>;
|
|
18
|
+
getAll(): Promise<Record<SecretKey, SecretEntry>>;
|
|
19
|
+
upsert(key: SecretKey): Promise<SecretEntry>;
|
|
20
|
+
delete(key: SecretKey): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { MessageFromClient, MessageToClient, SupportedSquidRegion } from '@squidcloud/common';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import { AuthManager } from './auth.manager';
|
|
4
|
-
import { ClientIdService } from './client-id.service';
|
|
5
|
-
import { DestructManager } from './destruct.manager';
|
|
6
|
-
export declare class SocketManager {
|
|
7
|
-
private readonly clientIdService;
|
|
8
|
-
private readonly region;
|
|
9
|
-
private readonly appId;
|
|
10
|
-
private readonly messageNotificationWrapper;
|
|
11
|
-
private readonly destructManager;
|
|
12
|
-
private readonly authManager;
|
|
13
|
-
private readonly webSocketObserver;
|
|
14
|
-
private readonly allMessagesObserver;
|
|
15
|
-
private readonly connectionReady;
|
|
16
|
-
private readonly seenMessageIds;
|
|
17
|
-
private socket;
|
|
18
|
-
private destructSubject;
|
|
19
|
-
private lastTick;
|
|
20
|
-
/**
|
|
21
|
-
* On a client disconnecting, we wait for a bit to see if the client reconnects,
|
|
22
|
-
* if no reconnect happens within the timeout, we consider the client to be too old.
|
|
23
|
-
* This value means we wait for 5 minutes before considering the client to be too old.
|
|
24
|
-
* Note: we make this a function so that we can easily override it in tests.
|
|
25
|
-
*/
|
|
26
|
-
private clientTooOldThreshold;
|
|
27
|
-
private tickInterval;
|
|
28
|
-
constructor(clientIdService: ClientIdService, region: SupportedSquidRegion, appId: string, messageNotificationWrapper: (fn: () => any) => any, destructManager: DestructManager, authManager: AuthManager);
|
|
29
|
-
refreshClient(): void;
|
|
30
|
-
tick(): void;
|
|
31
|
-
observeNotifications<T extends MessageToClient>(): Observable<T>;
|
|
32
|
-
observeConnectionReady(): Observable<boolean>;
|
|
33
|
-
sendMessage(message: MessageFromClient): void;
|
|
34
|
-
private sendMessageAsync;
|
|
35
|
-
/** Sends 'kill' message ignoring 'connectionReady' observable. */
|
|
36
|
-
private sendKillMessage;
|
|
37
|
-
private connect;
|
|
38
|
-
disconnect(): void;
|
|
39
|
-
private onConnectionReady;
|
|
40
|
-
private onMessage;
|
|
41
|
-
private setupMessageAcknowledgments;
|
|
42
|
-
private destruct;
|
|
43
|
-
}
|
|
1
|
+
import { MessageFromClient, MessageToClient, SupportedSquidRegion } from '@squidcloud/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { AuthManager } from './auth.manager';
|
|
4
|
+
import { ClientIdService } from './client-id.service';
|
|
5
|
+
import { DestructManager } from './destruct.manager';
|
|
6
|
+
export declare class SocketManager {
|
|
7
|
+
private readonly clientIdService;
|
|
8
|
+
private readonly region;
|
|
9
|
+
private readonly appId;
|
|
10
|
+
private readonly messageNotificationWrapper;
|
|
11
|
+
private readonly destructManager;
|
|
12
|
+
private readonly authManager;
|
|
13
|
+
private readonly webSocketObserver;
|
|
14
|
+
private readonly allMessagesObserver;
|
|
15
|
+
private readonly connectionReady;
|
|
16
|
+
private readonly seenMessageIds;
|
|
17
|
+
private socket;
|
|
18
|
+
private destructSubject;
|
|
19
|
+
private lastTick;
|
|
20
|
+
/**
|
|
21
|
+
* On a client disconnecting, we wait for a bit to see if the client reconnects,
|
|
22
|
+
* if no reconnect happens within the timeout, we consider the client to be too old.
|
|
23
|
+
* This value means we wait for 5 minutes before considering the client to be too old.
|
|
24
|
+
* Note: we make this a function so that we can easily override it in tests.
|
|
25
|
+
*/
|
|
26
|
+
private clientTooOldThreshold;
|
|
27
|
+
private tickInterval;
|
|
28
|
+
constructor(clientIdService: ClientIdService, region: SupportedSquidRegion, appId: string, messageNotificationWrapper: (fn: () => any) => any, destructManager: DestructManager, authManager: AuthManager);
|
|
29
|
+
refreshClient(): void;
|
|
30
|
+
tick(): void;
|
|
31
|
+
observeNotifications<T extends MessageToClient>(): Observable<T>;
|
|
32
|
+
observeConnectionReady(): Observable<boolean>;
|
|
33
|
+
sendMessage(message: MessageFromClient): void;
|
|
34
|
+
private sendMessageAsync;
|
|
35
|
+
/** Sends 'kill' message ignoring 'connectionReady' observable. */
|
|
36
|
+
private sendKillMessage;
|
|
37
|
+
private connect;
|
|
38
|
+
disconnect(): void;
|
|
39
|
+
private onConnectionReady;
|
|
40
|
+
private onMessage;
|
|
41
|
+
private setupMessageAcknowledgments;
|
|
42
|
+
private destruct;
|
|
43
|
+
}
|