@squidcloud/client 1.0.71 → 1.0.73
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/communication.types.d.ts +0 -10
- package/dist/common/src/heartbeat.types.d.ts +1 -0
- package/dist/common/src/index.d.ts +1 -1
- package/dist/common/src/integrations/auth.types.d.ts +12 -2
- package/dist/common/src/integrations/index.d.ts +4 -2
- package/dist/common/src/query/query-context.d.ts +6 -1
- package/dist/common/src/query/simple-query-builder.d.ts +5 -25
- package/dist/common/src/query.schemas.d.ts +3 -1
- package/dist/common/src/query.types.d.ts +8 -1
- package/dist/index.js +2 -2
- package/dist/typescript-client/src/destruct.manager.d.ts +1 -1
- package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +2 -2
- package/dist/typescript-client/src/query/query-builder.factory.d.ts +6 -0
- package/dist/typescript-client/src/query/query-subscription.manager.d.ts +76 -5
- package/package.json +1 -1
- package/dist/common/src/auth.types.d.ts +0 -1
|
@@ -5,7 +5,7 @@ export declare class DestructManager {
|
|
|
5
5
|
private readonly destructors;
|
|
6
6
|
private readonly isDestructedSubject;
|
|
7
7
|
get isDestructing(): boolean;
|
|
8
|
-
|
|
8
|
+
observeIsDestructing(): Observable<void>;
|
|
9
9
|
onPreDestruct(fn: DestructorFn): void;
|
|
10
10
|
onDestruct(fn: DestructorFn): void;
|
|
11
11
|
destruct(): Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DocumentData, FieldName, Operator, PrimitiveFieldType } from '@squidcloud/common';
|
|
1
|
+
import { BaseQueryBuilderInterface, DocumentData, FieldName, Operator, PrimitiveFieldType } from '@squidcloud/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { DocumentReference } from '../document-reference';
|
|
4
4
|
import { Alias } from './query.types';
|
|
@@ -7,7 +7,7 @@ import { Alias } from './query.types';
|
|
|
7
7
|
* To learn more about join queries, see
|
|
8
8
|
* {@link https://docs.squid.cloud/docs/client-sdk/queries#joining-data-across-collections-and-integrations}.
|
|
9
9
|
*/
|
|
10
|
-
export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType> | undefined>> {
|
|
10
|
+
export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType> | undefined>> extends BaseQueryBuilderInterface<ReturnType> {
|
|
11
11
|
private readonly collectionName;
|
|
12
12
|
private readonly integrationId;
|
|
13
13
|
private readonly querySubscriptionManager;
|
|
@@ -44,11 +44,17 @@ export declare class QueryBuilder<DocumentType extends DocumentData> extends Sim
|
|
|
44
44
|
private readonly documentReferenceFactory;
|
|
45
45
|
private readonly queryBuilderFactory;
|
|
46
46
|
private readonly documentIdentityService;
|
|
47
|
+
private forceFetchFromServer;
|
|
47
48
|
getSortOrder(): FieldSort<DocumentType>[];
|
|
48
49
|
/**
|
|
49
50
|
* @inheritDoc
|
|
50
51
|
*/
|
|
51
52
|
snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
|
|
53
|
+
/**
|
|
54
|
+
* Forces the query to return data from the server even if there is a query that already returned the requested
|
|
55
|
+
* result.
|
|
56
|
+
*/
|
|
57
|
+
setForceFetchFromServer(): this;
|
|
52
58
|
/**
|
|
53
59
|
* @inheritDoc
|
|
54
60
|
*/
|
|
@@ -12,9 +12,24 @@ export declare class QuerySubscriptionManager {
|
|
|
12
12
|
private readonly documentStore;
|
|
13
13
|
private readonly destructManager;
|
|
14
14
|
private readonly documentIdentityService;
|
|
15
|
+
/**
|
|
16
|
+
* As long as there are mutations in flight we do not want to send queries because it causes race conditions,
|
|
17
|
+
* preventing parallel queries and mutations simplifies the mental model.
|
|
18
|
+
*/
|
|
15
19
|
readonly safeToSendQueriesToServer: BehaviorSubject<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* An observable used by the data manager, the query subscription manager (this class) identifies when a document no
|
|
22
|
+
* longer has queries that it is part of their result, such document is considered orphan. The data manager will mark
|
|
23
|
+
* as orphan.
|
|
24
|
+
*/
|
|
16
25
|
onOrphanDocuments: Subject<string[]>;
|
|
26
|
+
/** All the currently running queries with their full state. */
|
|
17
27
|
private readonly ongoingQueries;
|
|
28
|
+
/**
|
|
29
|
+
* The number of queries that are currently in-flight (about to be sent to the server or sent but did not get a
|
|
30
|
+
* response yet). This is used by the data manager to prevent it from sending mutations while there are in-flight
|
|
31
|
+
* queries.
|
|
32
|
+
*/
|
|
18
33
|
private readonly inflightQueriesCount;
|
|
19
34
|
/**
|
|
20
35
|
* The two maps below maintain the relation between document ids we know about locally to clientRequestIds (queries).
|
|
@@ -22,11 +37,31 @@ export declare class QuerySubscriptionManager {
|
|
|
22
37
|
*/
|
|
23
38
|
private readonly clientRequestIdToLocalDocuments;
|
|
24
39
|
private readonly localDocumentToClientRequestIds;
|
|
40
|
+
/**
|
|
41
|
+
* A data structure for mapping queries to allow reverse queries search (given a document, find all the matching
|
|
42
|
+
* queries)
|
|
43
|
+
*/
|
|
25
44
|
private readonly queryMappingManager;
|
|
26
45
|
constructor(rpcManager: RpcManager, clientIdService: ClientIdService, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
|
|
46
|
+
/**
|
|
47
|
+
* Returns true if the client knows about this clientRequestId. It may happen that it will return false in the case
|
|
48
|
+
* that the client unsubscribed from a query but the server sent a mutation update for this clientRequestId.
|
|
49
|
+
*/
|
|
27
50
|
hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the query associated with the given clientRequestId. Throws error if the clientRequestId is not known.
|
|
53
|
+
*/
|
|
28
54
|
getQuery(clientRequestId: ClientRequestId): Query;
|
|
29
|
-
|
|
55
|
+
/**
|
|
56
|
+
* A query receives updates from two different sources:
|
|
57
|
+
* 1 - An initial snapshot from the server or from a parent query
|
|
58
|
+
* 2 - Incremental updates from the server (or from a parent query before the query is registered)
|
|
59
|
+
*
|
|
60
|
+
* If an incremental update is received before the snapshot was received, we cannot process it for this query.
|
|
61
|
+
* This boolean indicates whether the initial snapshot was received.
|
|
62
|
+
*/
|
|
63
|
+
setGotInitialResult(clientRequestId: ClientRequestId): void;
|
|
64
|
+
/** Given a document, returns all the queries that should be notified with the new document properties. */
|
|
30
65
|
findQueriesForDocument(doc: SquidDocument, squidDocId: SquidDocId): Array<QuerySubscriptionId>;
|
|
31
66
|
/**
|
|
32
67
|
* Given the new document's properties, finds all the queries that should be notified with the new properties and
|
|
@@ -35,12 +70,33 @@ export declare class QuerySubscriptionManager {
|
|
|
35
70
|
* will need to be notified due to the change of properties).
|
|
36
71
|
*/
|
|
37
72
|
setClientRequestIdsForLocalDoc(squidDocId: SquidDocId, properties: SquidDocument | undefined): Array<ClientRequestId>;
|
|
73
|
+
/**
|
|
74
|
+
* Due to an error when syncing a document, all the queries that are subscribed to this document should be notified
|
|
75
|
+
* and error out.
|
|
76
|
+
*/
|
|
38
77
|
errorOutAllQueries(squidDocId: SquidDocId, err: any): void;
|
|
78
|
+
/** Notifies to all the given queries (identified by their clientRequestId) with the updated query result. */
|
|
39
79
|
notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
|
|
40
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Given an ongoing query, search for candidate ongoing queries that can serve as a parent.
|
|
82
|
+
* If there is a parent query, the result of that query can be used for serving the current query.
|
|
83
|
+
* We will still register the current query on the server, but we do not need to run the query, apply security rules,
|
|
84
|
+
* etc.
|
|
85
|
+
*/
|
|
86
|
+
private findValidParentQuery;
|
|
87
|
+
processQuery(query: Query, rootAlias: Alias, joins: Record<string, Query>, joinConditions: Record<Alias, JoinCondition>, subscribe: boolean, forceFetchFromServer: boolean): Observable<Array<Record<Alias, SquidDocument | undefined>>>;
|
|
88
|
+
/**
|
|
89
|
+
* Returns whether the given document ID has a query that has this document ID as a result.
|
|
90
|
+
* A document without a query is considered "un-tracked".
|
|
91
|
+
*/
|
|
41
92
|
hasOngoingQueryForDocId(squidDocId: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Removes a query from the mapping and updates the orphan documents as needed.
|
|
95
|
+
*/
|
|
42
96
|
private removeClientRequestIdMapping;
|
|
97
|
+
/** Will resolve once all the in-flight queries are done. */
|
|
43
98
|
waitForAllQueriesToFinish(): Promise<void>;
|
|
99
|
+
/** Register logic for cleaning up the query when it is unsubscribed. */
|
|
44
100
|
private registerQueryFinalizer;
|
|
45
101
|
/** Creates a graph of ongoing queries and returns the root of the graph. */
|
|
46
102
|
private createOngoingQueryGraph;
|
|
@@ -49,16 +105,31 @@ export declare class QuerySubscriptionManager {
|
|
|
49
105
|
private join;
|
|
50
106
|
private getOngoingQueriesBfs;
|
|
51
107
|
private updateOngoingQueryWithNewDataFromSupportingQuery;
|
|
52
|
-
private
|
|
108
|
+
private allOngoingQueriesGotInitialResult;
|
|
53
109
|
private completeAllSupportedQueries;
|
|
54
110
|
private predestruct;
|
|
55
111
|
unsubscribe(): void;
|
|
56
112
|
hasSubscription(clientRequestId: ClientRequestId): boolean;
|
|
57
113
|
/** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
|
|
58
|
-
private
|
|
114
|
+
private sendQueryToServerOrUseParentQuery;
|
|
59
115
|
/**
|
|
60
|
-
*
|
|
116
|
+
* Uses the parent query as the source of data for the given ongoing query until the ongoing query is registered on
|
|
117
|
+
* the server. It prevents the parent query from being unsubscribed until the query is registered on the server and
|
|
118
|
+
* the first snapshot is received from the parent query.
|
|
119
|
+
* 1 - Prevents the parent query from being unsubscribed
|
|
120
|
+
* 2 - Connects the results of the parent query to the result of the current ongoing query
|
|
121
|
+
* 3 - Registers the query on the server
|
|
61
122
|
*/
|
|
123
|
+
private useParentOngoingQuery;
|
|
124
|
+
/**
|
|
125
|
+
* Sends the /query request to the server. It:
|
|
126
|
+
* 1 - Waits for when it is safe to send a query to the server (no in-flight mutations)
|
|
127
|
+
* 2 - Increments the number of inflightQueriesCount to prevent parallel mutations
|
|
128
|
+
* 3 - Handles errors
|
|
129
|
+
* 4 - Marks the query as registered
|
|
130
|
+
*/
|
|
131
|
+
private sendQueryToServer;
|
|
132
|
+
/** naive way to refresh queries/subscriptions when we have a new client id */
|
|
62
133
|
private refreshOngoingQueries;
|
|
63
134
|
private migrateDocIds;
|
|
64
135
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|