@squidcloud/client 1.0.78 → 1.0.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/cjs/index.js +3 -3
  2. package/dist/common/src/ai-assistant.context.d.ts +12 -12
  3. package/dist/common/src/ai-assistant.schemas.d.ts +1 -1
  4. package/dist/common/src/ai-assistant.types.d.ts +2 -2
  5. package/dist/common/src/api-call.context.d.ts +13 -13
  6. package/dist/common/src/api.types.d.ts +4 -4
  7. package/dist/common/src/application.schemas.d.ts +1 -1
  8. package/dist/common/src/application.types.d.ts +184 -184
  9. package/dist/common/src/backend-function.schemas.d.ts +1 -1
  10. package/dist/common/src/backend-function.types.d.ts +1 -1
  11. package/dist/common/src/backend-run.types.d.ts +2 -2
  12. package/dist/common/src/bundle-api.types.d.ts +36 -36
  13. package/dist/common/src/bundle-data.types.d.ts +4 -4
  14. package/dist/common/src/communication.types.d.ts +12 -12
  15. package/dist/common/src/context.types.d.ts +40 -40
  16. package/dist/common/src/distributed-lock.context.d.ts +5 -5
  17. package/dist/common/src/document.types.d.ts +22 -22
  18. package/dist/common/src/graphql.context.d.ts +7 -7
  19. package/dist/common/src/graphql.types.d.ts +9 -9
  20. package/dist/common/src/heartbeat.types.d.ts +1 -1
  21. package/dist/common/src/http-status.enum.d.ts +50 -50
  22. package/dist/common/src/index.d.ts +54 -54
  23. package/dist/common/src/integrations/ai_assistant.types.d.ts +30 -30
  24. package/dist/common/src/integrations/api.types.d.ts +80 -80
  25. package/dist/common/src/integrations/auth.types.d.ts +39 -39
  26. package/dist/common/src/integrations/database.types.d.ts +236 -236
  27. package/dist/common/src/integrations/index.d.ts +101 -101
  28. package/dist/common/src/integrations/observability.types.d.ts +23 -23
  29. package/dist/common/src/logger.types.d.ts +21 -21
  30. package/dist/common/src/metrics.types.d.ts +1 -1
  31. package/dist/common/src/mutation.context.d.ts +14 -14
  32. package/dist/common/src/mutation.schemas.d.ts +1 -1
  33. package/dist/common/src/mutation.types.d.ts +53 -53
  34. package/dist/common/src/named-query.context.d.ts +4 -4
  35. package/dist/common/src/named-query.schemas.d.ts +1 -1
  36. package/dist/common/src/named-query.types.d.ts +1 -1
  37. package/dist/common/src/query/index.d.ts +2 -2
  38. package/dist/common/src/query/query-context.d.ts +109 -42
  39. package/dist/common/src/query/simple-query-builder.d.ts +117 -117
  40. package/dist/common/src/query.schemas.d.ts +3 -3
  41. package/dist/common/src/query.types.d.ts +57 -57
  42. package/dist/common/src/regions.d.ts +1 -1
  43. package/dist/common/src/schema/schema.types.d.ts +54 -54
  44. package/dist/common/src/secret.schemas.d.ts +1 -1
  45. package/dist/common/src/secret.types.d.ts +8 -8
  46. package/dist/common/src/security.types.d.ts +1 -1
  47. package/dist/common/src/socket.schemas.d.ts +1 -1
  48. package/dist/common/src/socket.types.d.ts +1 -1
  49. package/dist/common/src/time-units.d.ts +1 -1
  50. package/dist/common/src/trigger.types.d.ts +1 -1
  51. package/dist/common/src/types.d.ts +8 -8
  52. package/dist/common/src/utils/array.d.ts +1 -1
  53. package/dist/common/src/utils/assert.d.ts +1 -1
  54. package/dist/common/src/utils/error.d.ts +4 -4
  55. package/dist/common/src/utils/http.d.ts +2 -2
  56. package/dist/common/src/utils/id.d.ts +2 -2
  57. package/dist/common/src/utils/lock.manager.d.ts +14 -14
  58. package/dist/common/src/utils/nullish.d.ts +1 -1
  59. package/dist/common/src/utils/object.d.ts +6 -6
  60. package/dist/common/src/utils/serialization.d.ts +6 -6
  61. package/dist/common/src/utils/transforms.d.ts +18 -18
  62. package/dist/common/src/utils/url.d.ts +1 -1
  63. package/dist/common/src/utils/validation.d.ts +30 -30
  64. package/dist/common/src/webhook-response.d.ts +1 -1
  65. package/dist/esm/index.js +3 -3
  66. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -1239
  67. package/dist/typescript-client/src/ai-assistant-client.d.ts +167 -167
  68. package/dist/typescript-client/src/ai-client.factory.d.ts +11 -11
  69. package/dist/typescript-client/src/api.manager.d.ts +15 -15
  70. package/dist/typescript-client/src/auth.manager.d.ts +23 -23
  71. package/dist/typescript-client/src/backend-function.manager.d.ts +13 -13
  72. package/dist/typescript-client/src/client-id.service.d.ts +25 -25
  73. package/dist/typescript-client/src/collection-reference.d.ts +80 -81
  74. package/dist/typescript-client/src/collection-reference.factory.d.ts +13 -16
  75. package/dist/typescript-client/src/connection-details.d.ts +23 -23
  76. package/dist/typescript-client/src/data.manager.d.ts +172 -172
  77. package/dist/typescript-client/src/destruct.manager.d.ts +12 -12
  78. package/dist/typescript-client/src/distributed-lock.manager.d.ts +19 -19
  79. package/dist/typescript-client/src/document-identity.service.d.ts +12 -12
  80. package/dist/typescript-client/src/document-reference.d.ts +134 -134
  81. package/dist/typescript-client/src/document-reference.factory.d.ts +12 -9
  82. package/dist/typescript-client/src/document-store.d.ts +11 -11
  83. package/dist/typescript-client/src/graphql-client.d.ts +12 -12
  84. package/dist/typescript-client/src/graphql-client.factory.d.ts +9 -9
  85. package/dist/typescript-client/src/index.d.ts +8 -8
  86. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +10 -10
  87. package/dist/typescript-client/src/named-query.manager.d.ts +12 -12
  88. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +72 -72
  89. package/dist/typescript-client/src/query/query-builder.factory.d.ts +89 -89
  90. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +135 -135
  91. package/dist/typescript-client/src/query/query.types.d.ts +14 -14
  92. package/dist/typescript-client/src/rpc.manager.d.ts +28 -28
  93. package/dist/typescript-client/src/socket.manager.d.ts +32 -32
  94. package/dist/typescript-client/src/squid.d.ts +218 -218
  95. package/dist/typescript-client/src/state/action.applier.d.ts +7 -7
  96. package/dist/typescript-client/src/state/actions.d.ts +29 -29
  97. package/dist/typescript-client/src/state/path_trie.d.ts +27 -27
  98. package/dist/typescript-client/src/state/state.service.d.ts +22 -22
  99. package/dist/typescript-client/src/state/state.service.spec.d.ts +1 -1
  100. package/dist/typescript-client/src/testing/setup-tests.d.ts +1 -1
  101. package/dist/typescript-client/src/types.d.ts +2 -2
  102. package/package.json +1 -1
@@ -1,72 +1,72 @@
1
- import { BaseQueryBuilderInterface, DocumentData, FieldName, Operator, PrimitiveFieldType } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { DocumentReference } from '../document-reference';
4
- import { Alias } from './query.types';
5
- /**
6
- * A query builder that can participate in a join.
7
- * To learn more about join queries, see
8
- * {@link https://docs.squid.cloud/docs/client-sdk/queries#joining-data-across-collections-and-integrations}.
9
- */
10
- export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType> | undefined>> extends BaseQueryBuilderInterface<ReturnType> {
11
- private readonly collectionName;
12
- private readonly integrationId;
13
- private readonly querySubscriptionManager;
14
- private readonly documentReferenceFactory;
15
- private readonly alias;
16
- private readonly joinQueryBuilderFactory;
17
- private readonly queryBuilderFactory;
18
- private readonly simpleQueryBuilder;
19
- private readonly joins;
20
- /** Record that maps the right alias to the left condition */
21
- private readonly joinConditions;
22
- /**
23
- * Adds a condition to the query.
24
- *
25
- * @param fieldName The name of the field to query
26
- * @param operator The operator to use
27
- * @param value The value to compare against
28
- * @returns The query builder
29
- */
30
- where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
31
- /**
32
- * Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
33
- * if none is provided.
34
- *
35
- * @param limit The maximum number of results to return
36
- * @returns The query builder
37
- */
38
- limit(limit: number): this;
39
- /**
40
- * Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them
41
- * determines the order in which they are applied.
42
- * @param fieldName The name of the field to sort by
43
- * @param asc Whether to sort in ascending order. Defaults to true.
44
- * @returns The query builder
45
- */
46
- sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
47
- /**
48
- * Joins this query with another join query and return a new query builder that can be used to query the joined
49
- * documents.
50
- * @param queryBuilder The query builder to join with
51
- * @param leftFieldName The name of the field on the left side of the join
52
- * @param rightFieldName The name of the field on the right side of the join
53
- * @returns A new query builder that can be used to query the joined documents
54
- */
55
- join<J extends DocumentData, RightAlias extends Alias, RightReturnType extends Record<RightAlias, DocumentReference<J> | undefined>>(queryBuilder: JoinQueryBuilder<J, RightAlias, RightReturnType>, leftFieldName: keyof DocumentType & FieldName, rightFieldName: keyof J & FieldName): JoinQueryBuilder<DocumentType, MyAlias, ReturnType & Partial<RightReturnType>>;
56
- /**
57
- * Returns a promise that resolves to the query results.
58
- *
59
- * @returns A promise that resolves to the query results
60
- */
61
- snapshot(): Promise<Array<ReturnType>>;
62
- /**
63
- * Returns an observable that emits the query results and updates whenever the query results change unless
64
- * `subscribe=false` is provided.
65
- *
66
- * Important: Make sure to unsubscribe from the observable when you are done with it.
67
- *
68
- * @param subscribe Whether to subscribe to the query. Defaults to true.
69
- * @returns An observable for the query results
70
- */
71
- snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
72
- }
1
+ import { BaseQueryBuilderInterface, DocumentData, FieldName, Operator, PrimitiveFieldType } from '@squidcloud/common';
2
+ import { Observable } from 'rxjs';
3
+ import { DocumentReference } from '../document-reference';
4
+ import { Alias } from './query.types';
5
+ /**
6
+ * A query builder that can participate in a join.
7
+ * To learn more about join queries, see
8
+ * {@link https://docs.squid.cloud/docs/client-sdk/queries#joining-data-across-collections-and-integrations}.
9
+ */
10
+ export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType> | undefined>> extends BaseQueryBuilderInterface<ReturnType> {
11
+ private readonly collectionName;
12
+ private readonly integrationId;
13
+ private readonly querySubscriptionManager;
14
+ private readonly documentReferenceFactory;
15
+ private readonly alias;
16
+ private readonly joinQueryBuilderFactory;
17
+ private readonly queryBuilderFactory;
18
+ private readonly simpleQueryBuilder;
19
+ private readonly joins;
20
+ /** Record that maps the right alias to the left condition */
21
+ private readonly joinConditions;
22
+ /**
23
+ * Adds a condition to the query.
24
+ *
25
+ * @param fieldName The name of the field to query
26
+ * @param operator The operator to use
27
+ * @param value The value to compare against
28
+ * @returns The query builder
29
+ */
30
+ where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
31
+ /**
32
+ * Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
33
+ * if none is provided.
34
+ *
35
+ * @param limit The maximum number of results to return
36
+ * @returns The query builder
37
+ */
38
+ limit(limit: number): this;
39
+ /**
40
+ * Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them
41
+ * determines the order in which they are applied.
42
+ * @param fieldName The name of the field to sort by
43
+ * @param asc Whether to sort in ascending order. Defaults to true.
44
+ * @returns The query builder
45
+ */
46
+ sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
47
+ /**
48
+ * Joins this query with another join query and return a new query builder that can be used to query the joined
49
+ * documents.
50
+ * @param queryBuilder The query builder to join with
51
+ * @param leftFieldName The name of the field on the left side of the join
52
+ * @param rightFieldName The name of the field on the right side of the join
53
+ * @returns A new query builder that can be used to query the joined documents
54
+ */
55
+ join<J extends DocumentData, RightAlias extends Alias, RightReturnType extends Record<RightAlias, DocumentReference<J> | undefined>>(queryBuilder: JoinQueryBuilder<J, RightAlias, RightReturnType>, leftFieldName: keyof DocumentType & FieldName, rightFieldName: keyof J & FieldName): JoinQueryBuilder<DocumentType, MyAlias, ReturnType & Partial<RightReturnType>>;
56
+ /**
57
+ * Returns a promise that resolves to the query results.
58
+ *
59
+ * @returns A promise that resolves to the query results
60
+ */
61
+ snapshot(): Promise<Array<ReturnType>>;
62
+ /**
63
+ * Returns an observable that emits the query results and updates whenever the query results change unless
64
+ * `subscribe=false` is provided.
65
+ *
66
+ * Important: Make sure to unsubscribe from the observable when you are done with it.
67
+ *
68
+ * @param subscribe Whether to subscribe to the query. Defaults to true.
69
+ * @returns An observable for the query results
70
+ */
71
+ snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
72
+ }
@@ -1,89 +1,89 @@
1
- import { CollectionName, DocumentData, FieldSort, IntegrationId, SimpleQueryBuilder, SquidDocId } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import DocumentIdentityService from '../document-identity.service';
4
- import { DocumentReference } from '../document-reference';
5
- import { DocumentReferenceFactory } from '../document-reference.factory';
6
- import { QuerySubscriptionManager } from './query-subscription.manager';
7
- export declare class QueryBuilderFactory {
8
- private readonly querySubscriptionManager;
9
- private readonly documentReferenceFactory;
10
- private readonly documentIdentityService;
11
- constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, documentIdentityService: DocumentIdentityService);
12
- getForDocument<DocumentType extends DocumentData>(squidDocId: SquidDocId): QueryBuilder<DocumentType>;
13
- get<DocumentType extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): QueryBuilder<DocumentType>;
14
- }
15
- /** An interface for the different actions that can be performed on a query. */
16
- export interface QueryActions<DocumentType extends DocumentData> {
17
- /**
18
- * Returns a promise that resolves to the query results.
19
- *
20
- * @returns A promise that resolves to the query results.
21
- */
22
- snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
23
- /**
24
- * Returns an observable that emits the query results and updates whenever the query results change unless
25
- * `subscribe=false` is provided.
26
- *
27
- * Important: Make sure to unsubscribe from the observable when you are done with it.
28
- *
29
- * @param subscribe Whether to subscribe to changes to the query results. Defaults to `true`.
30
- * @returns An observable for the query results.
31
- */
32
- snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
33
- /**
34
- * Similar to `snapshots` but returns an observable that emits the changes to the query results. The first result
35
- * will contain only inserts.
36
- *
37
- * @returns An observable for the query changes.
38
- */
39
- changes(): Observable<Changes<DocumentType>>;
40
- }
41
- /** A query builder that can be used to build a query that returns a list of documents. */
42
- export declare class QueryBuilder<DocumentType extends DocumentData> extends SimpleQueryBuilder<DocumentType> implements QueryActions<DocumentType> {
43
- private readonly querySubscriptionManager;
44
- private readonly documentReferenceFactory;
45
- private readonly queryBuilderFactory;
46
- private readonly documentIdentityService;
47
- private forceFetchFromServer;
48
- getSortOrder(): FieldSort<DocumentType>[];
49
- /**
50
- * @inheritDoc
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;
58
- /**
59
- * @inheritDoc
60
- */
61
- snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
62
- /**
63
- * @inheritDoc
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 { CollectionName, DocumentData, FieldSort, IntegrationId, SimpleQueryBuilder, SquidDocId } from '@squidcloud/common';
2
+ import { Observable } from 'rxjs';
3
+ import DocumentIdentityService from '../document-identity.service';
4
+ import { DocumentReference } from '../document-reference';
5
+ import { DocumentReferenceFactory } from '../document-reference.factory';
6
+ import { QuerySubscriptionManager } from './query-subscription.manager';
7
+ export declare class QueryBuilderFactory {
8
+ private readonly querySubscriptionManager;
9
+ private readonly documentReferenceFactory;
10
+ private readonly documentIdentityService;
11
+ constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, documentIdentityService: DocumentIdentityService);
12
+ getForDocument<DocumentType extends DocumentData>(squidDocId: SquidDocId): QueryBuilder<DocumentType>;
13
+ get<DocumentType extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): QueryBuilder<DocumentType>;
14
+ }
15
+ /** An interface for the different actions that can be performed on a query. */
16
+ export interface QueryActions<DocumentType extends DocumentData> {
17
+ /**
18
+ * Returns a promise that resolves to the query results.
19
+ *
20
+ * @returns A promise that resolves to the query results.
21
+ */
22
+ snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
23
+ /**
24
+ * Returns an observable that emits the query results and updates whenever the query results change unless
25
+ * `subscribe=false` is provided.
26
+ *
27
+ * Important: Make sure to unsubscribe from the observable when you are done with it.
28
+ *
29
+ * @param subscribe Whether to subscribe to changes to the query results. Defaults to `true`.
30
+ * @returns An observable for the query results.
31
+ */
32
+ snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
33
+ /**
34
+ * Similar to `snapshots` but returns an observable that emits the changes to the query results. The first result
35
+ * will contain only inserts.
36
+ *
37
+ * @returns An observable for the query changes.
38
+ */
39
+ changes(): Observable<Changes<DocumentType>>;
40
+ }
41
+ /** A query builder that can be used to build a query that returns a list of documents. */
42
+ export declare class QueryBuilder<DocumentType extends DocumentData> extends SimpleQueryBuilder<DocumentType> implements QueryActions<DocumentType> {
43
+ private readonly querySubscriptionManager;
44
+ private readonly documentReferenceFactory;
45
+ private readonly queryBuilderFactory;
46
+ private readonly documentIdentityService;
47
+ private forceFetchFromServer;
48
+ getSortOrder(): FieldSort<DocumentType>[];
49
+ /**
50
+ * @inheritDoc
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;
58
+ /**
59
+ * @inheritDoc
60
+ */
61
+ snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
62
+ /**
63
+ * @inheritDoc
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,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
+ }
@@ -1,14 +1,14 @@
1
- import { FieldName } from '@squidcloud/common';
2
- /**
3
- * An alias for a join result. This is used to disambiguate fields in the result.
4
- */
5
- export type Alias = string;
6
- /**
7
- * A join condition.
8
- * The join conditions defines the alias for the left side of the join and the field names to join on.
9
- */
10
- export interface JoinCondition {
11
- leftAlias: Alias;
12
- leftFieldName: FieldName;
13
- rightFieldName: FieldName;
14
- }
1
+ import { FieldName } from '@squidcloud/common';
2
+ /**
3
+ * An alias for a join result. This is used to disambiguate fields in the result.
4
+ */
5
+ export type Alias = string;
6
+ /**
7
+ * A join condition.
8
+ * The join conditions defines the alias for the left side of the join and the field names to join on.
9
+ */
10
+ export interface JoinCondition {
11
+ leftAlias: Alias;
12
+ leftFieldName: FieldName;
13
+ rightFieldName: FieldName;
14
+ }