@squidcloud/client 1.0.80 → 1.0.81
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 +5 -5
- package/dist/common/src/ai-assistant.context.d.ts +12 -12
- package/dist/common/src/ai-assistant.schemas.d.ts +1 -1
- package/dist/common/src/ai-assistant.types.d.ts +2 -2
- 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 +1 -1
- package/dist/common/src/application.types.d.ts +184 -184
- 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 +36 -36
- package/dist/common/src/bundle-data.types.d.ts +4 -4
- package/dist/common/src/communication.types.d.ts +12 -12
- package/dist/common/src/context.types.d.ts +40 -40
- package/dist/common/src/distributed-lock.context.d.ts +5 -5
- 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 -54
- package/dist/common/src/integrations/ai_assistant.types.d.ts +30 -30
- package/dist/common/src/integrations/api.types.d.ts +80 -80
- package/dist/common/src/integrations/auth.types.d.ts +39 -39
- package/dist/common/src/integrations/database.types.d.ts +236 -236
- package/dist/common/src/integrations/index.d.ts +101 -101
- 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/named-query.context.d.ts +4 -4
- package/dist/common/src/named-query.schemas.d.ts +1 -1
- package/dist/common/src/named-query.types.d.ts +1 -1
- package/dist/common/src/query/{simple-query-builder.d.ts → base-query-builder.d.ts} +122 -117
- package/dist/common/src/query/index.d.ts +2 -2
- package/dist/common/src/query/query-context.d.ts +109 -109
- package/dist/common/src/query.schemas.d.ts +3 -3
- package/dist/common/src/query.types.d.ts +57 -57
- 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 +8 -8
- 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 +1 -1
- 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 +8 -8
- 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/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/nullish.d.ts +1 -1
- package/dist/common/src/utils/object.d.ts +6 -6
- package/dist/common/src/utils/serialization.d.ts +6 -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 +30 -30
- package/dist/common/src/webhook-response.d.ts +1 -1
- package/dist/esm/index.js +5 -5
- package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -1239
- package/dist/typescript-client/src/ai-assistant-client.d.ts +167 -167
- package/dist/typescript-client/src/ai-client.factory.d.ts +11 -11
- package/dist/typescript-client/src/api.manager.d.ts +15 -15
- package/dist/typescript-client/src/auth.manager.d.ts +23 -23
- package/dist/typescript-client/src/backend-function.manager.d.ts +13 -13
- package/dist/typescript-client/src/client-id.service.d.ts +25 -25
- package/dist/typescript-client/src/collection-reference.d.ts +82 -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 +172 -172
- package/dist/typescript-client/src/destruct.manager.d.ts +12 -12
- package/dist/typescript-client/src/distributed-lock.manager.d.ts +19 -19
- package/dist/typescript-client/src/document-identity.service.d.ts +12 -12
- package/dist/typescript-client/src/document-reference.d.ts +134 -134
- package/dist/typescript-client/src/document-reference.factory.d.ts +12 -12
- package/dist/typescript-client/src/document-store.d.ts +11 -11
- package/dist/typescript-client/src/graphql-client.d.ts +12 -12
- package/dist/typescript-client/src/graphql-client.factory.d.ts +9 -9
- package/dist/typescript-client/src/index.d.ts +8 -8
- package/dist/typescript-client/src/mutation/mutation-sender.d.ts +10 -10
- package/dist/typescript-client/src/named-query.manager.d.ts +12 -12
- package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +110 -72
- package/dist/typescript-client/src/query/query-builder.factory.d.ts +64 -89
- package/dist/typescript-client/src/query/query-subscription.manager.d.ts +135 -135
- package/dist/typescript-client/src/query/query.types.d.ts +14 -14
- package/dist/typescript-client/src/rpc.manager.d.ts +28 -28
- package/dist/typescript-client/src/socket.manager.d.ts +32 -32
- package/dist/typescript-client/src/squid.d.ts +217 -218
- package/dist/typescript-client/src/state/action.applier.d.ts +7 -7
- package/dist/typescript-client/src/state/actions.d.ts +29 -29
- package/dist/typescript-client/src/state/path_trie.d.ts +27 -27
- package/dist/typescript-client/src/state/state.service.d.ts +22 -22
- 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 +1 -1
|
@@ -1,72 +1,110 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import { DocumentReference } from '../document-reference';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @param
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
|
|
1
|
+
import { BaseQueryBuilder, DocumentData, FieldName, HasDereference, Operator, PrimitiveFieldType, SnapshotEmitter } from '@squidcloud/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { DocumentReference } from '../document-reference';
|
|
4
|
+
import { QueryBuilder } from './query-builder.factory';
|
|
5
|
+
import { Alias } from './query.types';
|
|
6
|
+
type SimpleJoinQueryBuilder<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, LatestAlias extends Alias, RootAlias extends Alias> = Pick<JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>, 'join' | 'snapshot' | 'snapshots' | 'grouped' | 'dereference'>;
|
|
7
|
+
type WithDocumentReferences<T extends Record<any, DocumentData>> = {
|
|
8
|
+
[k in keyof T]: DocumentReference<Required<T>[k]>;
|
|
9
|
+
};
|
|
10
|
+
type Grouped<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, any>, RootAlias extends Alias> = Aliases[RootAlias] extends [] ? Required<ReturnType>[RootAlias] : Record<RootAlias, Required<ReturnType>[RootAlias]> & OtherGroups<Aliases, ReturnType, Aliases[RootAlias]>;
|
|
11
|
+
type OtherGroups<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, any>, ManyRootAliases extends Alias[]> = ManyRootAliases extends [infer First extends Alias, ...infer Rest extends Alias[]] ? Record<First, Array<Grouped<Aliases, ReturnType, First>>> & OtherGroups<Aliases, ReturnType, Rest> : Record<Alias, never>;
|
|
12
|
+
interface HasGrouped {
|
|
13
|
+
/**
|
|
14
|
+
* Transforms this join query result to a nested data structure. For example, a join between teachers and students
|
|
15
|
+
* normally returns a result of the form:
|
|
16
|
+
* [
|
|
17
|
+
* { teacher: {name: 'Mr. Smith'}, student: {name: 'John Doe'} },
|
|
18
|
+
* { teacher: {name: 'Mr. Smith'}, student: {name: 'Jane Smith'} },
|
|
19
|
+
* { teacher: {name: 'Mr. EmptyClass'}, student: undefined },
|
|
20
|
+
* ]
|
|
21
|
+
* into a result of the form:
|
|
22
|
+
* [
|
|
23
|
+
* { teacher: {name: 'Mr. Smith'}, students: [
|
|
24
|
+
* { name: 'John Doe' },
|
|
25
|
+
* { name: 'Jane Smith' },
|
|
26
|
+
* ]},
|
|
27
|
+
* { teacher: {name: 'Mr. EmptyClass'}, students: [] },
|
|
28
|
+
* ]
|
|
29
|
+
*/
|
|
30
|
+
grouped(): any;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A query builder that can participate in a join.
|
|
34
|
+
* To learn more about join queries, see
|
|
35
|
+
* {@link https://docs.squid.cloud/docs/client-sdk/queries#joining-data-across-collections-and-integrations}.
|
|
36
|
+
*/
|
|
37
|
+
export declare class JoinQueryBuilder<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, LatestAlias extends Alias, RootAlias extends Alias> extends BaseQueryBuilder<ReturnType> implements SnapshotEmitter<WithDocumentReferences<ReturnType>>, HasGrouped, HasDereference {
|
|
38
|
+
private readonly collectionName;
|
|
39
|
+
private readonly integrationId;
|
|
40
|
+
private readonly querySubscriptionManager;
|
|
41
|
+
private readonly documentReferenceFactory;
|
|
42
|
+
private readonly queryBuilderFactory;
|
|
43
|
+
private readonly latestAlias;
|
|
44
|
+
private readonly joins;
|
|
45
|
+
private readonly joinConditions;
|
|
46
|
+
private readonly queryBuilder;
|
|
47
|
+
/**
|
|
48
|
+
* Adds a condition to the query.
|
|
49
|
+
*
|
|
50
|
+
* @param fieldName The name of the field to query
|
|
51
|
+
* @param operator The operator to use
|
|
52
|
+
* @param value The value to compare against
|
|
53
|
+
* @returns The query builder
|
|
54
|
+
*/
|
|
55
|
+
where(fieldName: (keyof ReturnType[LatestAlias] & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
|
|
56
|
+
/**
|
|
57
|
+
* Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
|
|
58
|
+
* if none is provided.
|
|
59
|
+
*
|
|
60
|
+
* @param limit The maximum number of results to return
|
|
61
|
+
* @returns The query builder
|
|
62
|
+
*/
|
|
63
|
+
limit(limit: number): this;
|
|
64
|
+
/**
|
|
65
|
+
* Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them
|
|
66
|
+
* determines the order in which they are applied.
|
|
67
|
+
* @param fieldName The name of the field to sort by
|
|
68
|
+
* @param asc Whether to sort in ascending order. Defaults to true.
|
|
69
|
+
* @returns The query builder
|
|
70
|
+
*/
|
|
71
|
+
sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
|
|
72
|
+
/**
|
|
73
|
+
* Joins this query with another join query and return a new query builder that can be used to query the joined
|
|
74
|
+
* documents.
|
|
75
|
+
* @param queryBuilder The query builder to join with
|
|
76
|
+
* @param alias TODO
|
|
77
|
+
* @param joinFields TODO
|
|
78
|
+
* @param options TODO
|
|
79
|
+
* @returns A new query builder that can be used to query the joined documents
|
|
80
|
+
*/
|
|
81
|
+
join<NewAlias extends string, NewReturnType extends DocumentData, LeftAlias extends Extract<keyof ReturnType, Alias>>(queryBuilder: QueryBuilder<NewReturnType>, alias: Exclude<NewAlias, keyof ReturnType>, joinFields: {
|
|
82
|
+
left: keyof Required<ReturnType>[LeftAlias] & FieldName;
|
|
83
|
+
right: keyof NewReturnType & FieldName;
|
|
84
|
+
}, options: {
|
|
85
|
+
leftAlias: LeftAlias;
|
|
86
|
+
}): SimpleJoinQueryBuilder<Omit<Aliases, LeftAlias> & Record<LeftAlias, [...Aliases[LeftAlias], NewAlias]> & Record<NewAlias, []>, ReturnType & Partial<Record<NewAlias, NewReturnType>>, NewAlias, RootAlias>;
|
|
87
|
+
join<NewAlias extends string, NewReturnType extends DocumentData>(queryBuilder: QueryBuilder<NewReturnType>, alias: Exclude<NewAlias, keyof ReturnType>, joinFields: {
|
|
88
|
+
left: keyof Required<ReturnType>[LatestAlias] & FieldName;
|
|
89
|
+
right: keyof NewReturnType & FieldName;
|
|
90
|
+
}): SimpleJoinQueryBuilder<Omit<Aliases, LatestAlias> & Record<LatestAlias, [...Aliases[LatestAlias], NewAlias]> & Record<NewAlias, []>, ReturnType & Partial<Record<NewAlias, NewReturnType>>, NewAlias, RootAlias>;
|
|
91
|
+
/** @inheritDoc */
|
|
92
|
+
snapshot(): Promise<Array<WithDocumentReferences<ReturnType>>>;
|
|
93
|
+
/** @inheritDoc */
|
|
94
|
+
snapshots(subscribe?: boolean): Observable<Array<WithDocumentReferences<ReturnType>>>;
|
|
95
|
+
/** @inheritDoc */
|
|
96
|
+
grouped(): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
97
|
+
/** @inheritDoc */
|
|
98
|
+
dereference(): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
99
|
+
}
|
|
100
|
+
declare class DereferencedJoin<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, RootAlias extends Alias, LatestAlias extends Alias> implements SnapshotEmitter<ReturnType>, HasGrouped {
|
|
101
|
+
private readonly joinQueryBuilder;
|
|
102
|
+
constructor(joinQueryBuilder: JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>);
|
|
103
|
+
/** @inheritDoc */
|
|
104
|
+
grouped(): SnapshotEmitter<Grouped<Aliases, ReturnType, RootAlias>>;
|
|
105
|
+
/** @inheritDoc */
|
|
106
|
+
snapshot(): Promise<Array<ReturnType>>;
|
|
107
|
+
/** @inheritDoc */
|
|
108
|
+
snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
|
|
109
|
+
}
|
|
110
|
+
export {};
|
|
@@ -1,89 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private readonly querySubscriptionManager;
|
|
9
|
-
private readonly documentReferenceFactory;
|
|
10
|
-
private readonly
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
changes(): Observable<Changes<DocumentType>>;
|
|
66
|
-
/**
|
|
67
|
-
* A unique hash for the query. Identical queries should return the same hash
|
|
68
|
-
* value.
|
|
69
|
-
*
|
|
70
|
-
* @returns The query's hash string.
|
|
71
|
-
*/
|
|
72
|
-
get hash(): string;
|
|
73
|
-
}
|
|
74
|
-
/** Describes the changes to a query result. */
|
|
75
|
-
export declare class Changes<DocumentType extends DocumentData> {
|
|
76
|
-
/** The newly inserted documents to the query result */
|
|
77
|
-
readonly inserts: Array<DocumentReference<DocumentType>>;
|
|
78
|
-
/** The documents that were updated in the query result */
|
|
79
|
-
readonly updates: Array<DocumentReference<DocumentType>>;
|
|
80
|
-
/** The actual document data that was deleted from the query result */
|
|
81
|
-
readonly deletes: Array<DocumentType>;
|
|
82
|
-
constructor(
|
|
83
|
-
/** The newly inserted documents to the query result */
|
|
84
|
-
inserts: Array<DocumentReference<DocumentType>>,
|
|
85
|
-
/** The documents that were updated in the query result */
|
|
86
|
-
updates: Array<DocumentReference<DocumentType>>,
|
|
87
|
-
/** The actual document data that was deleted from the query result */
|
|
88
|
-
deletes: Array<DocumentType>);
|
|
89
|
-
}
|
|
1
|
+
import { BaseQueryBuilder, DocumentData, FieldName, FieldSort, HasDereference, Operator, PrimitiveFieldType, Query, SnapshotEmitter } from '@squidcloud/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { DocumentReference } from '../document-reference';
|
|
4
|
+
/** A query builder that can be used to build a query that returns a list of documents. */
|
|
5
|
+
export declare class QueryBuilder<DocumentType extends DocumentData> extends BaseQueryBuilder<DocumentType> implements SnapshotEmitter<DocumentReference<DocumentType>>, HasDereference {
|
|
6
|
+
private readonly collectionName;
|
|
7
|
+
private readonly integrationId;
|
|
8
|
+
private readonly querySubscriptionManager;
|
|
9
|
+
private readonly documentReferenceFactory;
|
|
10
|
+
private readonly queryBuilderFactory;
|
|
11
|
+
private readonly documentIdentityService;
|
|
12
|
+
private forceFetchFromServer;
|
|
13
|
+
protected readonly query: Query<DocumentType>;
|
|
14
|
+
/** @inheritDoc */
|
|
15
|
+
where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
|
|
16
|
+
/** @inheritDoc */
|
|
17
|
+
limit(limit: number): this;
|
|
18
|
+
/** @inheritDoc */
|
|
19
|
+
sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
|
|
20
|
+
private mergeConditions;
|
|
21
|
+
getSortOrder(): FieldSort<DocumentType>[];
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
|
|
26
|
+
/**
|
|
27
|
+
* Forces the query to return data from the server even if there is a query that already returned the requested
|
|
28
|
+
* result.
|
|
29
|
+
*/
|
|
30
|
+
setForceFetchFromServer(): this;
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
|
|
35
|
+
/**
|
|
36
|
+
* @inheritDoc
|
|
37
|
+
*/
|
|
38
|
+
changes(): Observable<Changes<DocumentType>>;
|
|
39
|
+
/**
|
|
40
|
+
* A unique hash for the query. Identical queries should return the same hash
|
|
41
|
+
* value.
|
|
42
|
+
*
|
|
43
|
+
* @returns The query's hash string.
|
|
44
|
+
*/
|
|
45
|
+
get hash(): string;
|
|
46
|
+
/** @inheritDoc */
|
|
47
|
+
dereference(): SnapshotEmitter<DocumentType>;
|
|
48
|
+
}
|
|
49
|
+
/** Describes the changes to a query result. */
|
|
50
|
+
export declare class Changes<DocumentType extends DocumentData> {
|
|
51
|
+
/** The newly inserted documents to the query result */
|
|
52
|
+
readonly inserts: Array<DocumentReference<DocumentType>>;
|
|
53
|
+
/** The documents that were updated in the query result */
|
|
54
|
+
readonly updates: Array<DocumentReference<DocumentType>>;
|
|
55
|
+
/** The actual document data that was deleted from the query result */
|
|
56
|
+
readonly deletes: Array<DocumentType>;
|
|
57
|
+
constructor(
|
|
58
|
+
/** The newly inserted documents to the query result */
|
|
59
|
+
inserts: Array<DocumentReference<DocumentType>>,
|
|
60
|
+
/** The documents that were updated in the query result */
|
|
61
|
+
updates: Array<DocumentReference<DocumentType>>,
|
|
62
|
+
/** The actual document data that was deleted from the query result */
|
|
63
|
+
deletes: Array<DocumentType>);
|
|
64
|
+
}
|
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import { ClientRequestId, Query, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
|
|
2
|
-
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
|
3
|
-
import { DestructManager } from '../destruct.manager';
|
|
4
|
-
import DocumentIdentityService from '../document-identity.service';
|
|
5
|
-
import { DocumentStore } from '../document-store';
|
|
6
|
-
import { RpcManager } from '../rpc.manager';
|
|
7
|
-
import { Alias, JoinCondition } from './query.types';
|
|
8
|
-
import { ClientIdService } from '../client-id.service';
|
|
9
|
-
export declare class QuerySubscriptionManager {
|
|
10
|
-
private readonly rpcManager;
|
|
11
|
-
private readonly clientIdService;
|
|
12
|
-
private readonly documentStore;
|
|
13
|
-
private readonly destructManager;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
25
|
-
onOrphanDocuments: Subject<string[]>;
|
|
26
|
-
/** All the currently running queries with their full state. */
|
|
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
|
-
*/
|
|
33
|
-
private readonly inflightQueriesCount;
|
|
34
|
-
/**
|
|
35
|
-
* The two maps below maintain the relation between document ids we know about locally to clientRequestIds (queries).
|
|
36
|
-
* This relation is used for determining whether a document can be safely removed.
|
|
37
|
-
*/
|
|
38
|
-
private readonly clientRequestIdToLocalDocuments;
|
|
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
|
-
*/
|
|
44
|
-
private readonly queryMappingManager;
|
|
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
|
-
*/
|
|
50
|
-
hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Returns the query associated with the given clientRequestId. Throws error if the clientRequestId is not known.
|
|
53
|
-
*/
|
|
54
|
-
getQuery(clientRequestId: ClientRequestId): Query;
|
|
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. */
|
|
65
|
-
findQueriesForDocument(doc: SquidDocument, squidDocId: SquidDocId): Array<QuerySubscriptionId>;
|
|
66
|
-
/**
|
|
67
|
-
* Given the new document's properties, finds all the queries that should be notified with the new properties and
|
|
68
|
-
* updates the internal mappings (squidDocId --> client request Ids and, clientRequestId --> squidDocIds).
|
|
69
|
-
* Returns an array with all the previous and current client request ids (basically all the client request ids that
|
|
70
|
-
* will need to be notified due to the change of properties).
|
|
71
|
-
*/
|
|
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
|
-
*/
|
|
77
|
-
errorOutAllQueries(squidDocId: SquidDocId, err: any): void;
|
|
78
|
-
/** Notifies to all the given queries (identified by their clientRequestId) with the updated query result. */
|
|
79
|
-
notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
|
|
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
|
-
*/
|
|
92
|
-
hasOngoingQueryForDocId(squidDocId: string): boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Removes a query from the mapping and updates the orphan documents as needed.
|
|
95
|
-
*/
|
|
96
|
-
private removeClientRequestIdMapping;
|
|
97
|
-
/** Will resolve once all the in-flight queries are done. */
|
|
98
|
-
waitForAllQueriesToFinish(): Promise<void>;
|
|
99
|
-
/** Register logic for cleaning up the query when it is unsubscribed. */
|
|
100
|
-
private registerQueryFinalizer;
|
|
101
|
-
/** Creates a graph of ongoing queries and returns the root of the graph. */
|
|
102
|
-
private createOngoingQueryGraph;
|
|
103
|
-
private collectAllObservables;
|
|
104
|
-
private joinResults;
|
|
105
|
-
private join;
|
|
106
|
-
private getOngoingQueriesBfs;
|
|
107
|
-
private updateOngoingQueryWithNewDataFromSupportingQuery;
|
|
108
|
-
private allOngoingQueriesGotInitialResult;
|
|
109
|
-
private completeAllSupportedQueries;
|
|
110
|
-
private predestruct;
|
|
111
|
-
unsubscribe(): void;
|
|
112
|
-
hasSubscription(clientRequestId: ClientRequestId): boolean;
|
|
113
|
-
/** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
|
|
114
|
-
private sendQueryToServerOrUseParentQuery;
|
|
115
|
-
/**
|
|
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
|
|
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 */
|
|
133
|
-
private refreshOngoingQueries;
|
|
134
|
-
private migrateDocIds;
|
|
135
|
-
}
|
|
1
|
+
import { ClientRequestId, Query, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
|
|
2
|
+
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
|
3
|
+
import { DestructManager } from '../destruct.manager';
|
|
4
|
+
import DocumentIdentityService from '../document-identity.service';
|
|
5
|
+
import { DocumentStore } from '../document-store';
|
|
6
|
+
import { RpcManager } from '../rpc.manager';
|
|
7
|
+
import { Alias, JoinCondition } from './query.types';
|
|
8
|
+
import { ClientIdService } from '../client-id.service';
|
|
9
|
+
export declare class QuerySubscriptionManager {
|
|
10
|
+
private readonly rpcManager;
|
|
11
|
+
private readonly clientIdService;
|
|
12
|
+
private readonly documentStore;
|
|
13
|
+
private readonly destructManager;
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
25
|
+
onOrphanDocuments: Subject<string[]>;
|
|
26
|
+
/** All the currently running queries with their full state. */
|
|
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
|
+
*/
|
|
33
|
+
private readonly inflightQueriesCount;
|
|
34
|
+
/**
|
|
35
|
+
* The two maps below maintain the relation between document ids we know about locally to clientRequestIds (queries).
|
|
36
|
+
* This relation is used for determining whether a document can be safely removed.
|
|
37
|
+
*/
|
|
38
|
+
private readonly clientRequestIdToLocalDocuments;
|
|
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
|
+
*/
|
|
44
|
+
private readonly queryMappingManager;
|
|
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
|
+
*/
|
|
50
|
+
hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the query associated with the given clientRequestId. Throws error if the clientRequestId is not known.
|
|
53
|
+
*/
|
|
54
|
+
getQuery(clientRequestId: ClientRequestId): Query;
|
|
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. */
|
|
65
|
+
findQueriesForDocument(doc: SquidDocument, squidDocId: SquidDocId): Array<QuerySubscriptionId>;
|
|
66
|
+
/**
|
|
67
|
+
* Given the new document's properties, finds all the queries that should be notified with the new properties and
|
|
68
|
+
* updates the internal mappings (squidDocId --> client request Ids and, clientRequestId --> squidDocIds).
|
|
69
|
+
* Returns an array with all the previous and current client request ids (basically all the client request ids that
|
|
70
|
+
* will need to be notified due to the change of properties).
|
|
71
|
+
*/
|
|
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
|
+
*/
|
|
77
|
+
errorOutAllQueries(squidDocId: SquidDocId, err: any): void;
|
|
78
|
+
/** Notifies to all the given queries (identified by their clientRequestId) with the updated query result. */
|
|
79
|
+
notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
|
|
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
|
+
*/
|
|
92
|
+
hasOngoingQueryForDocId(squidDocId: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Removes a query from the mapping and updates the orphan documents as needed.
|
|
95
|
+
*/
|
|
96
|
+
private removeClientRequestIdMapping;
|
|
97
|
+
/** Will resolve once all the in-flight queries are done. */
|
|
98
|
+
waitForAllQueriesToFinish(): Promise<void>;
|
|
99
|
+
/** Register logic for cleaning up the query when it is unsubscribed. */
|
|
100
|
+
private registerQueryFinalizer;
|
|
101
|
+
/** Creates a graph of ongoing queries and returns the root of the graph. */
|
|
102
|
+
private createOngoingQueryGraph;
|
|
103
|
+
private collectAllObservables;
|
|
104
|
+
private joinResults;
|
|
105
|
+
private join;
|
|
106
|
+
private getOngoingQueriesBfs;
|
|
107
|
+
private updateOngoingQueryWithNewDataFromSupportingQuery;
|
|
108
|
+
private allOngoingQueriesGotInitialResult;
|
|
109
|
+
private completeAllSupportedQueries;
|
|
110
|
+
private predestruct;
|
|
111
|
+
unsubscribe(): void;
|
|
112
|
+
hasSubscription(clientRequestId: ClientRequestId): boolean;
|
|
113
|
+
/** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
|
|
114
|
+
private sendQueryToServerOrUseParentQuery;
|
|
115
|
+
/**
|
|
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
|
|
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 */
|
|
133
|
+
private refreshOngoingQueries;
|
|
134
|
+
private migrateDocIds;
|
|
135
|
+
}
|