@squidcloud/client 1.0.127 → 1.0.129

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 (108) hide show
  1. package/dist/cjs/index.js +9488 -9813
  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 +21 -21
  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 +66 -66
  8. package/dist/common/src/application.types.d.ts +143 -143
  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 +39 -39
  13. package/dist/common/src/bundle-data.types.d.ts +4 -4
  14. package/dist/common/src/communication.types.d.ts +8 -8
  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 +274 -248
  27. package/dist/common/src/integrations/index.d.ts +134 -129
  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/base-query-builder.d.ts +147 -147
  38. package/dist/common/src/query/index.d.ts +4 -4
  39. package/dist/common/src/query/pagination.d.ts +62 -62
  40. package/dist/common/src/query/query-context.d.ts +137 -137
  41. package/dist/common/src/query/serialized-query.types.d.ts +24 -24
  42. package/dist/common/src/query.types.d.ts +64 -64
  43. package/dist/common/src/regions.d.ts +1 -1
  44. package/dist/common/src/schema/schema.types.d.ts +54 -54
  45. package/dist/common/src/secret.schemas.d.ts +1 -1
  46. package/dist/common/src/secret.types.d.ts +22 -22
  47. package/dist/common/src/security.types.d.ts +1 -1
  48. package/dist/common/src/socket.schemas.d.ts +1 -1
  49. package/dist/common/src/socket.types.d.ts +5 -5
  50. package/dist/common/src/time-units.d.ts +1 -1
  51. package/dist/common/src/trigger.types.d.ts +1 -1
  52. package/dist/common/src/types.d.ts +14 -14
  53. package/dist/common/src/utils/array.d.ts +1 -1
  54. package/dist/common/src/utils/assert.d.ts +1 -1
  55. package/dist/common/src/utils/error.d.ts +4 -4
  56. package/dist/common/src/utils/global.utils.d.ts +1 -1
  57. package/dist/common/src/utils/http.d.ts +2 -2
  58. package/dist/common/src/utils/id.d.ts +2 -2
  59. package/dist/common/src/utils/lock.manager.d.ts +14 -14
  60. package/dist/common/src/utils/object.d.ts +5 -5
  61. package/dist/common/src/utils/serialization.d.ts +6 -6
  62. package/dist/common/src/utils/transforms.d.ts +18 -18
  63. package/dist/common/src/utils/url.d.ts +1 -1
  64. package/dist/common/src/utils/validation.d.ts +25 -25
  65. package/dist/common/src/webhook-response.d.ts +1 -1
  66. package/dist/common/src/websocket.impl.d.ts +21 -21
  67. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -1239
  68. package/dist/typescript-client/src/ai-assistant-client.d.ts +174 -174
  69. package/dist/typescript-client/src/ai-client.factory.d.ts +11 -11
  70. package/dist/typescript-client/src/api.manager.d.ts +11 -15
  71. package/dist/typescript-client/src/auth.manager.d.ts +23 -23
  72. package/dist/typescript-client/src/backend-function.manager.d.ts +9 -13
  73. package/dist/typescript-client/src/client-id.service.d.ts +27 -27
  74. package/dist/typescript-client/src/collection-reference.d.ts +80 -80
  75. package/dist/typescript-client/src/collection-reference.factory.d.ts +13 -13
  76. package/dist/typescript-client/src/connection-details.d.ts +23 -23
  77. package/dist/typescript-client/src/data.manager.d.ts +173 -173
  78. package/dist/typescript-client/src/destruct.manager.d.ts +12 -12
  79. package/dist/typescript-client/src/distributed-lock.manager.d.ts +16 -16
  80. package/dist/typescript-client/src/document-identity.service.d.ts +12 -12
  81. package/dist/typescript-client/src/document-reference.d.ts +140 -140
  82. package/dist/typescript-client/src/document-reference.factory.d.ts +13 -13
  83. package/dist/typescript-client/src/document-store.d.ts +14 -11
  84. package/dist/typescript-client/src/graphql-client.d.ts +14 -14
  85. package/dist/typescript-client/src/graphql-client.factory.d.ts +11 -11
  86. package/dist/typescript-client/src/index.d.ts +9 -9
  87. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +10 -10
  88. package/dist/typescript-client/src/named-query.manager.d.ts +12 -12
  89. package/dist/typescript-client/src/query/deserializer.d.ts +3 -3
  90. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +161 -161
  91. package/dist/typescript-client/src/query/local-query-manager.d.ts +9 -9
  92. package/dist/typescript-client/src/query/query-builder.factory.d.ts +77 -77
  93. package/dist/typescript-client/src/query/query-sender.d.ts +33 -33
  94. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +130 -130
  95. package/dist/typescript-client/src/query/query.types.d.ts +49 -49
  96. package/dist/typescript-client/src/rate-limiter.d.ts +32 -32
  97. package/dist/typescript-client/src/rpc.manager.d.ts +29 -29
  98. package/dist/typescript-client/src/secret.client.d.ts +22 -22
  99. package/dist/typescript-client/src/socket.manager.d.ts +39 -35
  100. package/dist/typescript-client/src/squid.d.ts +222 -222
  101. package/dist/typescript-client/src/state/action.applier.d.ts +7 -7
  102. package/dist/typescript-client/src/state/actions.d.ts +29 -29
  103. package/dist/typescript-client/src/state/path_trie.d.ts +27 -27
  104. package/dist/typescript-client/src/state/state.service.d.ts +22 -22
  105. package/dist/typescript-client/src/state/state.service.spec.d.ts +1 -1
  106. package/dist/typescript-client/src/testing/setup-tests.d.ts +1 -1
  107. package/dist/typescript-client/src/types.d.ts +2 -2
  108. package/package.json +1 -1
@@ -1,80 +1,80 @@
1
- import { Alias, DocId, DocIdObj, DocumentData, SnapshotEmitter } from '@squidcloud/common';
2
- import { DocumentReference } from './document-reference';
3
- import { JoinQueryBuilder } from './query/join-query-builder.factory';
4
- import { QueryBuilder } from './query/query-builder.factory';
5
- /**
6
- * Holds a reference to a data collection. A collection reference is a reference to a collection in a database. You
7
- * can use it to read or write data to the collection. A collection can refer to a table in a relational database or a
8
- * collection in a NoSQL database.
9
- *
10
- * Read more about collection references in the
11
- * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/collection-reference documentation}.
12
- * @typeParam T The type of the document data.
13
- */
14
- export declare class CollectionReference<T extends DocumentData> {
15
- private readonly collectionName;
16
- private integrationId;
17
- private readonly documentReferenceFactory;
18
- private readonly queryBuilderFactory;
19
- private readonly querySubscriptionManager;
20
- /** A string that uniquely identifies this collection reference. */
21
- refId: string;
22
- /**
23
- * Returns a document reference for the given document id.
24
- * The document id is an object that maps the primary keys of the collection (as defined in the Squid Cloud Console)
25
- * to their values. There are a few exceptions:
26
- * 1 - String document id is only supported for the `built_in_db` when a schema was not defined.
27
- * 2 - Not all the fields in the document id are required. If a field is not provided, it will be generated on the
28
- * server once the document is created (if the integration supports it).
29
- * 3 - When a document id is not provided, it will be treated as an empty object or empty string.
30
- * 4 - When the document id is just a `string` and not provided (applies only for the `built_in_db`), it will be
31
- * generated on the server.
32
- * 5 - If the collection in the `built_in_db` does not have a schema, the document id must be provided as a string.
33
- *
34
- * Examples:
35
- * ```typescript
36
- * // For a collection in the built_in_db that does not have a schema
37
- * const docRef = collectionRef.doc('my-doc-id');
38
- * const docRef = collectionRef.doc({id: my-doc-id'});
39
- *
40
- * // For a collection with a single primary key field called "id"
41
- * const docRef = collectionRef.doc({id: 'my-doc-id'});
42
- *
43
- * // For a collection with a composite primary key
44
- * const docRef = collectionRef.doc({id1: 'my-doc-id1', id2: 'my-doc-id2'});
45
- * const docRef = collectionRef.doc({id1: 'my-doc-id1'}); // id2 will be generated on the server if the integration
46
- * supports it
47
- *
48
- * // For a collection from the `built_in_db` without a defined schema when an id is not provided
49
- * const docRef = collectionRef.doc(); // The id will be generated on the server
50
- * ```
51
- *
52
- * @param docId The document id as an object for the different fields in the primary key or a string.
53
- * @returns A document reference for the given document id.
54
- */
55
- doc(docId?: DocId | DocIdObj): DocumentReference<T>;
56
- /**
57
- * Creates a `QueryBuilder` that can be used to query the collection.
58
- *
59
- * @returns A `QueryBuilder` that can be used to query the collection.
60
- */
61
- query(): QueryBuilder<T>;
62
- /**
63
- * Creates a `JoinQueryBuilder` that can be used to query the collection
64
- * Note that when using a join query, you have to provide an alias for the query and for every other query
65
- * participating in the join.
66
- *
67
- * @param alias The alias for the query.
68
- * @returns A `JoinQueryBuilder` that can be used to query the collection and joins with other queries.
69
- */
70
- joinQuery<A extends Alias>(alias: A): JoinQueryBuilder<Record<A, []>, Record<A, T>, A, A>;
71
- /**
72
- * Performs `or` on a list of queries. All the queries need to be on the same collection.
73
- * The result will be a merge of all the queries sorted by the same sort condition of the first query.
74
- * Duplicate items will be removed.
75
- * @param builders The list of query builders to merge. (A query builder can be returned from the {@link query}
76
- * method).
77
- * @returns A query builder that can be used to perform the `or` operation.
78
- */
79
- or(...builders: QueryBuilder<T>[]): SnapshotEmitter<DocumentReference<T>>;
80
- }
1
+ import { Alias, DocId, DocIdObj, DocumentData, SnapshotEmitter } from '@squidcloud/common';
2
+ import { DocumentReference } from './document-reference';
3
+ import { JoinQueryBuilder } from './query/join-query-builder.factory';
4
+ import { QueryBuilder } from './query/query-builder.factory';
5
+ /**
6
+ * Holds a reference to a data collection. A collection reference is a reference to a collection in a database. You
7
+ * can use it to read or write data to the collection. A collection can refer to a table in a relational database or a
8
+ * collection in a NoSQL database.
9
+ *
10
+ * Read more about collection references in the
11
+ * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/collection-reference documentation}.
12
+ * @typeParam T The type of the document data.
13
+ */
14
+ export declare class CollectionReference<T extends DocumentData> {
15
+ private readonly collectionName;
16
+ private integrationId;
17
+ private readonly documentReferenceFactory;
18
+ private readonly queryBuilderFactory;
19
+ private readonly querySubscriptionManager;
20
+ /** A string that uniquely identifies this collection reference. */
21
+ refId: string;
22
+ /**
23
+ * Returns a document reference for the given document id.
24
+ * The document id is an object that maps the primary keys of the collection (as defined in the Squid Cloud Console)
25
+ * to their values. There are a few exceptions:
26
+ * 1 - String document id is only supported for the `built_in_db` when a schema was not defined.
27
+ * 2 - Not all the fields in the document id are required. If a field is not provided, it will be generated on the
28
+ * server once the document is created (if the integration supports it).
29
+ * 3 - When a document id is not provided, it will be treated as an empty object or empty string.
30
+ * 4 - When the document id is just a `string` and not provided (applies only for the `built_in_db`), it will be
31
+ * generated on the server.
32
+ * 5 - If the collection in the `built_in_db` does not have a schema, the document id must be provided as a string.
33
+ *
34
+ * Examples:
35
+ * ```typescript
36
+ * // For a collection in the built_in_db that does not have a schema
37
+ * const docRef = collectionRef.doc('my-doc-id');
38
+ * const docRef = collectionRef.doc({id: my-doc-id'});
39
+ *
40
+ * // For a collection with a single primary key field called "id"
41
+ * const docRef = collectionRef.doc({id: 'my-doc-id'});
42
+ *
43
+ * // For a collection with a composite primary key
44
+ * const docRef = collectionRef.doc({id1: 'my-doc-id1', id2: 'my-doc-id2'});
45
+ * const docRef = collectionRef.doc({id1: 'my-doc-id1'}); // id2 will be generated on the server if the integration
46
+ * supports it
47
+ *
48
+ * // For a collection from the `built_in_db` without a defined schema when an id is not provided
49
+ * const docRef = collectionRef.doc(); // The id will be generated on the server
50
+ * ```
51
+ *
52
+ * @param docId The document id as an object for the different fields in the primary key or a string.
53
+ * @returns A document reference for the given document id.
54
+ */
55
+ doc(docId?: DocId | DocIdObj): DocumentReference<T>;
56
+ /**
57
+ * Creates a `QueryBuilder` that can be used to query the collection.
58
+ *
59
+ * @returns A `QueryBuilder` that can be used to query the collection.
60
+ */
61
+ query(): QueryBuilder<T>;
62
+ /**
63
+ * Creates a `JoinQueryBuilder` that can be used to query the collection
64
+ * Note that when using a join query, you have to provide an alias for the query and for every other query
65
+ * participating in the join.
66
+ *
67
+ * @param alias The alias for the query.
68
+ * @returns A `JoinQueryBuilder` that can be used to query the collection and joins with other queries.
69
+ */
70
+ joinQuery<A extends Alias>(alias: A): JoinQueryBuilder<Record<A, []>, Record<A, T>, A, A>;
71
+ /**
72
+ * Performs `or` on a list of queries. All the queries need to be on the same collection.
73
+ * The result will be a merge of all the queries sorted by the same sort condition of the first query.
74
+ * Duplicate items will be removed.
75
+ * @param builders The list of query builders to merge. (A query builder can be returned from the {@link query}
76
+ * method).
77
+ * @returns A query builder that can be used to perform the `or` operation.
78
+ */
79
+ or(...builders: QueryBuilder<T>[]): SnapshotEmitter<DocumentReference<T>>;
80
+ }
@@ -1,13 +1,13 @@
1
- import { CollectionName, DocumentData, IntegrationId } from '@squidcloud/common';
2
- import { CollectionReference } from './collection-reference';
3
- import { DocumentReferenceFactory } from './document-reference.factory';
4
- import { QueryBuilderFactory } from './query/query-builder.factory';
5
- import { QuerySubscriptionManager } from './query/query-subscription.manager';
6
- export declare class CollectionReferenceFactory {
7
- private readonly documentReferenceFactory;
8
- private readonly queryBuilderFactory;
9
- private readonly querySubscriptionManager;
10
- private readonly collections;
11
- constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, querySubscriptionManager: QuerySubscriptionManager);
12
- get<T extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): CollectionReference<T>;
13
- }
1
+ import { CollectionName, DocumentData, IntegrationId } from '@squidcloud/common';
2
+ import { CollectionReference } from './collection-reference';
3
+ import { DocumentReferenceFactory } from './document-reference.factory';
4
+ import { QueryBuilderFactory } from './query/query-builder.factory';
5
+ import { QuerySubscriptionManager } from './query/query-subscription.manager';
6
+ export declare class CollectionReferenceFactory {
7
+ private readonly documentReferenceFactory;
8
+ private readonly queryBuilderFactory;
9
+ private readonly querySubscriptionManager;
10
+ private readonly collections;
11
+ constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, querySubscriptionManager: QuerySubscriptionManager);
12
+ get<T extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): CollectionReference<T>;
13
+ }
@@ -1,23 +1,23 @@
1
- import { ClientId } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- /**
4
- * Provides information about the connection to the Squid Server.
5
- */
6
- export declare class ConnectionDetails {
7
- private readonly clientIdService;
8
- private readonly socketManager;
9
- private isConnected;
10
- /** Whether the Squid Client SDK is currently connected to the Squid Server. */
11
- get connected(): boolean;
12
- /**
13
- * A unique client ID that is assigned to the client. This client ID is also available to the different backend
14
- * function in the context object.
15
- * Note: The client ID may change after a long disconnect.
16
- */
17
- get clientId(): ClientId;
18
- /**
19
- * Returns an observable that emits true when the client is connected to the server and false when the client is
20
- * disconnected from the server.
21
- */
22
- observeConnected(): Observable<boolean>;
23
- }
1
+ import { ClientId } from '@squidcloud/common';
2
+ import { Observable } from 'rxjs';
3
+ /**
4
+ * Provides information about the connection to the Squid Server.
5
+ */
6
+ export declare class ConnectionDetails {
7
+ private readonly clientIdService;
8
+ private readonly socketManager;
9
+ private isConnected;
10
+ /** Whether the Squid Client SDK is currently connected to the Squid Server. */
11
+ get connected(): boolean;
12
+ /**
13
+ * A unique client ID that is assigned to the client. This client ID is also available to the different backend
14
+ * function in the context object.
15
+ * Note: The client ID may change after a long disconnect.
16
+ */
17
+ get clientId(): ClientId;
18
+ /**
19
+ * Returns an observable that emits true when the client is connected to the server and false when the client is
20
+ * disconnected from the server.
21
+ */
22
+ observeConnected(): Observable<boolean>;
23
+ }
@@ -1,173 +1,173 @@
1
- import { DocTimestamp, LockManager, Mutation, SquidDocId, SquidDocument } from '@squidcloud/common';
2
- import { QuerySender } from './query/query-sender';
3
- import { DestructManager } from './destruct.manager';
4
- import DocumentIdentityService from './document-identity.service';
5
- import { DocumentStore } from './document-store';
6
- import { MutationSender } from './mutation/mutation-sender';
7
- import { QueryBuilderFactory } from './query/query-builder.factory';
8
- import { QuerySubscriptionManager } from './query/query-subscription.manager';
9
- import { SocketManager } from './socket.manager';
10
- import { TransactionId } from './types';
11
- export interface DocTimestampMetadata {
12
- timestamp: DocTimestamp;
13
- expireTimestamp?: number;
14
- }
15
- export declare class DataManager {
16
- private readonly documentStore;
17
- private readonly mutationSender;
18
- private readonly socketManager;
19
- private readonly querySubscriptionManager;
20
- private readonly queryBuilderFactory;
21
- private readonly lockManager;
22
- private readonly destructManager;
23
- private readonly documentIdentityService;
24
- private readonly querySender;
25
- private readonly docIdToLocalTimestamp;
26
- private currentTransactionId;
27
- /**
28
- * During a batch, any update to a document that may trigger an update to a query is collected here and once the batch
29
- * ends, the relevant subscribes to these queries will be updated.
30
- */
31
- private readonly batchClientRequestIds;
32
- /**
33
- * In this map we save timestamps for documents that are available locally or recently deleted but need to remain
34
- * here so if a mutation comes from the server we know whether to apply it or not based on the timestamp. For
35
- * example, if a document is removed locally and immediately after, an update is received from the server - In that
36
- * case, it may be the update pre-dates the data that was available locally a second ago. For that reason, the
37
- * timestamp needs to be kept and even for removed documents it will be kept for ~20 seconds more.
38
- *
39
- * Eventually, this map is used as a gatekeeper for preventing old versions of a document (based on timestamp) to
40
- * appear on the client.
41
- */
42
- private readonly docIdToServerTimestamp;
43
- /**
44
- * In the case of a local change (outgoing change) without a server timestamp, an incoming server update cannot be
45
- * applied and needs to be queued until the local state allows it. In this case the incoming update will be queued in
46
- * this map. Any future incoming server update to the same document will override the previous update in case it has
47
- * a later timestamp.
48
- */
49
- private readonly pendingIncomingUpdates;
50
- /**
51
- * A mutation sent to the server will be stored in this map until it receives a timestamp from the server. These
52
- * mutations were already applied locally and were sent to the server or about to be sent if sentToServer=false
53
- * (or are queued in the MutationSender due to a lock). The existence of these pending mutations indicates the data
54
- * manager to:
55
- * 1 - Not apply any incoming server mutation while there are outgoing mutations without a timestamp
56
- * 2 - Not delete the local document even if there are no queries related to this document - there is a chance
57
- * that there will be a future query that will need this document and the query needs to return the local version
58
- * of the document.
59
- * 3 - Even when all outgoing mutations have a timestamp, it may be that there is a pending query in flight that will
60
- * need to return the document. In this case, the local document may be different from the server. Hence, it
61
- * cannot accept the server change and will wait for another update from the server. For this purpose, timestamp
62
- * will be stored in docsToTimestamp for ~20 more seconds.
63
- *
64
- * Note: Only one entry per squidDocId can be with sentToServer=false. This is true since all updates to the same doc
65
- * in the same batch are appended (and reduced) to the same outgoing mutation object.
66
- */
67
- private readonly pendingOutgoingMutations;
68
- private readonly pendingOutgoingMutationsChanged;
69
- /**
70
- * A subject for whether there are outgoing mutations. If there are outgoing mutations, any incoming update from the
71
- * server will be delayed until all the outgoing mutations will be acknowledged by the server.
72
- * This mechanism is needed to avoid this case:
73
- *
74
- * collection.docRef('a').delete();
75
- * collection.snapshots().subscribe((res) => {
76
- * // The result here may include doc with id='a' since the delete mutation was not acknowledged.
77
- * });
78
- *
79
- * If we wait for the acknowledgment message, we will have a server timestamp and will be able to ignore the incoming
80
- * result for document with id='a'.
81
- */
82
- private readonly outgoingMutationsEmpty;
83
- /**
84
- * When applying an outgoing mutation, there may be a short time that the mutation is not yet inserted into the
85
- * pending outgoing mutations map. In this case, we mark the document id as known to be dirty and remove it from the
86
- * set once the pending outgoing mutations map is updated.
87
- */
88
- private readonly knownDirtyDocs;
89
- private readonly failedDocsToResync;
90
- private readonly refreshDocIdToTimestamp;
91
- private deleteExpiredTimestampsInterval;
92
- private handleIncomingMessagesForTests;
93
- constructor(documentStore: DocumentStore, mutationSender: MutationSender, socketManager: SocketManager, querySubscriptionManager: QuerySubscriptionManager, queryBuilderFactory: QueryBuilderFactory, lockManager: LockManager, destructManager: DestructManager, documentIdentityService: DocumentIdentityService, querySender: QuerySender);
94
- getProperties(squidDocId: SquidDocId): SquidDocument | undefined;
95
- /** Whether a document has changes that are out of sync with the server. */
96
- isDirty(squidDocId: SquidDocId): boolean;
97
- /**
98
- * Runs the provided function without sending mutations to the server while collecting the updates to the different
99
- * queries. Local updates will still be applied. Once the batch finishes, all the updates will be sent to the server
100
- * and the different queries will be notified. runInTransaction may be invoked inside another runInTransaction, only
101
- * the top level batch will trigger updates to the server.
102
- */
103
- runInTransaction(fn: (transactionId: TransactionId) => Promise<void>, transactionId?: TransactionId): Promise<void>;
104
- /** Applies a mutation done from the client (from DocumentReference) and sends it to the server. */
105
- applyOutgoingMutation(mutation: Mutation, transactionId: TransactionId | undefined): Promise<void>;
106
- /** Same as runInTransaction with the exception that the passed function runs synchronously. */
107
- private runInTransactionSync;
108
- /** Remove properties from the document record that should not be sent to the server. */
109
- private removeInternalProperties;
110
- /** Listens and handles mutations and snapshots notifications from the socketManager. */
111
- private handleNotifications;
112
- private handleIncomingMutations;
113
- private handleIncomingQuerySnapshots;
114
- /**
115
- * Returns a boolean for whether some updates were ignored because the client knows of a later timestamp for those
116
- * documents.
117
- */
118
- private applyIncomingUpdates;
119
- private maybeApplyIncomingUpdate;
120
- private destruct;
121
- private stopDeleteExpiredTimestampsJob;
122
- /**
123
- * Removes entries from the docToTimestamp map for all the documents that are no longer relevant for this client.
124
- * If a document is currently tracked, we forget it.
125
- * Cases a document is considered not relevant anymore:
126
- * 1 - There are no outgoing or incoming updates for this document AND:
127
- * a - The document was deleted on the server and this client already received a notification about it OR
128
- * b - The document no longer has a query that will keep it up-to-date
129
- */
130
- private startDeleteExpiredTimestampsJob;
131
- /**
132
- * Whether the document is tracked by any pending mutations or ongoing queries.
133
- */
134
- isTracked(squidDocId: string): boolean;
135
- /**
136
- * Whether a document exists locally, but is no longer tracked by any mutations or queries. This is often the case
137
- * for in-memory DocumentReferences that are not part of any query.
138
- */
139
- isForgotten(squidDocId: SquidDocId): boolean;
140
- /**
141
- * Whether a document only exists locally. This means that the document has never by sent to or received from the
142
- * server.
143
- */
144
- isLocalOnly(squidDocId: SquidDocId): boolean;
145
- /**
146
- * Whether the document has even been acknowledged by the server. Acknowledgements occur when an incoming query or
147
- * mutation is received, and when an outgoing mutation is acknowledged.
148
- */
149
- hasBeenAcknowledged(squidDocId: SquidDocId): boolean;
150
- /**
151
- * Updates the document with the new properties, returns true if an update was done or false in case the doc did not
152
- * change.
153
- */
154
- private updateDocumentFromSnapshot;
155
- private finishTransaction;
156
- private sendAllUnsentOutgoingMutations;
157
- private sendMutationsForIntegration;
158
- private removeOutgoingMutation;
159
- private resyncFailedUpdates;
160
- private refreshUpdatedDocuments;
161
- private groupOutgoingMutationsByIntegrationId;
162
- /**
163
- * Handles the case that due to some change (an incoming or outgoing change to a document), a document becomes orphan.
164
- * That is, there are no ongoing queries that will keep it up-to-date.
165
- * An orphan document should not stay locally since it may be stale after some time.
166
- */
167
- private handleOrphanDocs;
168
- private acknowledgeDocument;
169
- private setExpiration;
170
- private forgetDocument;
171
- private migrateDocIds;
172
- private hasPendingSentMutations;
173
- }
1
+ import { DocTimestamp, LockManager, Mutation, SquidDocId, SquidDocument } from '@squidcloud/common';
2
+ import { QuerySender } from './query/query-sender';
3
+ import { DestructManager } from './destruct.manager';
4
+ import DocumentIdentityService from './document-identity.service';
5
+ import { DocumentStore } from './document-store';
6
+ import { MutationSender } from './mutation/mutation-sender';
7
+ import { QueryBuilderFactory } from './query/query-builder.factory';
8
+ import { QuerySubscriptionManager } from './query/query-subscription.manager';
9
+ import { SocketManager } from './socket.manager';
10
+ import { TransactionId } from './types';
11
+ export interface DocTimestampMetadata {
12
+ timestamp: DocTimestamp;
13
+ expireTimestamp?: number;
14
+ }
15
+ export declare class DataManager {
16
+ private readonly documentStore;
17
+ private readonly mutationSender;
18
+ private readonly socketManager;
19
+ private readonly querySubscriptionManager;
20
+ private readonly queryBuilderFactory;
21
+ private readonly lockManager;
22
+ private readonly destructManager;
23
+ private readonly documentIdentityService;
24
+ private readonly querySender;
25
+ private readonly docIdToLocalTimestamp;
26
+ private currentTransactionId;
27
+ /**
28
+ * During a batch, any update to a document that may trigger an update to a query is collected here and once the batch
29
+ * ends, the relevant subscribes to these queries will be updated.
30
+ */
31
+ private readonly batchClientRequestIds;
32
+ /**
33
+ * In this map we save timestamps for documents that are available locally or recently deleted but need to remain
34
+ * here so if a mutation comes from the server we know whether to apply it or not based on the timestamp. For
35
+ * example, if a document is removed locally and immediately after, an update is received from the server - In that
36
+ * case, it may be the update pre-dates the data that was available locally a second ago. For that reason, the
37
+ * timestamp needs to be kept and even for removed documents it will be kept for ~20 seconds more.
38
+ *
39
+ * Eventually, this map is used as a gatekeeper for preventing old versions of a document (based on timestamp) to
40
+ * appear on the client.
41
+ */
42
+ private readonly docIdToServerTimestamp;
43
+ /**
44
+ * In the case of a local change (outgoing change) without a server timestamp, an incoming server update cannot be
45
+ * applied and needs to be queued until the local state allows it. In this case the incoming update will be queued in
46
+ * this map. Any future incoming server update to the same document will override the previous update in case it has
47
+ * a later timestamp.
48
+ */
49
+ private readonly pendingIncomingUpdates;
50
+ /**
51
+ * A mutation sent to the server will be stored in this map until it receives a timestamp from the server. These
52
+ * mutations were already applied locally and were sent to the server or about to be sent if sentToServer=false
53
+ * (or are queued in the MutationSender due to a lock). The existence of these pending mutations indicates the data
54
+ * manager to:
55
+ * 1 - Not apply any incoming server mutation while there are outgoing mutations without a timestamp
56
+ * 2 - Not delete the local document even if there are no queries related to this document - there is a chance
57
+ * that there will be a future query that will need this document and the query needs to return the local version
58
+ * of the document.
59
+ * 3 - Even when all outgoing mutations have a timestamp, it may be that there is a pending query in flight that will
60
+ * need to return the document. In this case, the local document may be different from the server. Hence, it
61
+ * cannot accept the server change and will wait for another update from the server. For this purpose, timestamp
62
+ * will be stored in docsToTimestamp for ~20 more seconds.
63
+ *
64
+ * Note: Only one entry per squidDocId can be with sentToServer=false. This is true since all updates to the same doc
65
+ * in the same batch are appended (and reduced) to the same outgoing mutation object.
66
+ */
67
+ private readonly pendingOutgoingMutations;
68
+ private readonly pendingOutgoingMutationsChanged;
69
+ /**
70
+ * A subject for whether there are outgoing mutations. If there are outgoing mutations, any incoming update from the
71
+ * server will be delayed until all the outgoing mutations will be acknowledged by the server.
72
+ * This mechanism is needed to avoid this case:
73
+ *
74
+ * collection.docRef('a').delete();
75
+ * collection.snapshots().subscribe((res) => {
76
+ * // The result here may include doc with id='a' since the delete mutation was not acknowledged.
77
+ * });
78
+ *
79
+ * If we wait for the acknowledgment message, we will have a server timestamp and will be able to ignore the incoming
80
+ * result for document with id='a'.
81
+ */
82
+ private readonly outgoingMutationsEmpty;
83
+ /**
84
+ * When applying an outgoing mutation, there may be a short time that the mutation is not yet inserted into the
85
+ * pending outgoing mutations map. In this case, we mark the document id as known to be dirty and remove it from the
86
+ * set once the pending outgoing mutations map is updated.
87
+ */
88
+ private readonly knownDirtyDocs;
89
+ private readonly failedDocsToResync;
90
+ private readonly refreshDocIdToTimestamp;
91
+ private deleteExpiredTimestampsInterval;
92
+ private handleIncomingMessagesForTests;
93
+ constructor(documentStore: DocumentStore, mutationSender: MutationSender, socketManager: SocketManager, querySubscriptionManager: QuerySubscriptionManager, queryBuilderFactory: QueryBuilderFactory, lockManager: LockManager, destructManager: DestructManager, documentIdentityService: DocumentIdentityService, querySender: QuerySender);
94
+ getProperties(squidDocId: SquidDocId): SquidDocument | undefined;
95
+ /** Whether a document has changes that are out of sync with the server. */
96
+ isDirty(squidDocId: SquidDocId): boolean;
97
+ /**
98
+ * Runs the provided function without sending mutations to the server while collecting the updates to the different
99
+ * queries. Local updates will still be applied. Once the batch finishes, all the updates will be sent to the server
100
+ * and the different queries will be notified. runInTransaction may be invoked inside another runInTransaction, only
101
+ * the top level batch will trigger updates to the server.
102
+ */
103
+ runInTransaction(fn: (transactionId: TransactionId) => Promise<void>, transactionId?: TransactionId): Promise<void>;
104
+ /** Applies a mutation done from the client (from DocumentReference) and sends it to the server. */
105
+ applyOutgoingMutation(mutation: Mutation, transactionId: TransactionId | undefined): Promise<void>;
106
+ /** Same as runInTransaction with the exception that the passed function runs synchronously. */
107
+ private runInTransactionSync;
108
+ /** Remove properties from the document record that should not be sent to the server. */
109
+ private removeInternalProperties;
110
+ /** Listens and handles mutations and snapshots notifications from the socketManager. */
111
+ private handleNotifications;
112
+ private handleIncomingMutations;
113
+ private handleIncomingQuerySnapshots;
114
+ /**
115
+ * Returns a boolean for whether some updates were ignored because the client knows of a later timestamp for those
116
+ * documents.
117
+ */
118
+ private applyIncomingUpdates;
119
+ private maybeApplyIncomingUpdate;
120
+ private destruct;
121
+ private stopDeleteExpiredTimestampsJob;
122
+ /**
123
+ * Removes entries from the docToTimestamp map for all the documents that are no longer relevant for this client.
124
+ * If a document is currently tracked, we forget it.
125
+ * Cases a document is considered not relevant anymore:
126
+ * 1 - There are no outgoing or incoming updates for this document AND:
127
+ * a - The document was deleted on the server and this client already received a notification about it OR
128
+ * b - The document no longer has a query that will keep it up-to-date
129
+ */
130
+ private startDeleteExpiredTimestampsJob;
131
+ /**
132
+ * Whether the document is tracked by any pending mutations or ongoing queries.
133
+ */
134
+ isTracked(squidDocId: string): boolean;
135
+ /**
136
+ * Whether a document exists locally, but is no longer tracked by any mutations or queries. This is often the case
137
+ * for in-memory DocumentReferences that are not part of any query.
138
+ */
139
+ isForgotten(squidDocId: SquidDocId): boolean;
140
+ /**
141
+ * Whether a document only exists locally. This means that the document has never by sent to or received from the
142
+ * server.
143
+ */
144
+ isLocalOnly(squidDocId: SquidDocId): boolean;
145
+ /**
146
+ * Whether the document has even been acknowledged by the server. Acknowledgements occur when an incoming query or
147
+ * mutation is received, and when an outgoing mutation is acknowledged.
148
+ */
149
+ hasBeenAcknowledged(squidDocId: SquidDocId): boolean;
150
+ /**
151
+ * Updates the document with the new properties, returns true if an update was done or false in case the doc did not
152
+ * change.
153
+ */
154
+ private updateDocumentFromSnapshot;
155
+ private finishTransaction;
156
+ private sendAllUnsentOutgoingMutations;
157
+ private sendMutationsForIntegration;
158
+ private removeOutgoingMutation;
159
+ private resyncFailedUpdates;
160
+ private refreshUpdatedDocuments;
161
+ private groupOutgoingMutationsByIntegrationId;
162
+ /**
163
+ * Handles the case that due to some change (an incoming or outgoing change to a document), a document becomes orphan.
164
+ * That is, there are no ongoing queries that will keep it up-to-date.
165
+ * An orphan document should not stay locally since it may be stale after some time.
166
+ */
167
+ private handleOrphanDocs;
168
+ private acknowledgeDocument;
169
+ private setExpiration;
170
+ private forgetDocument;
171
+ private migrateDocIds;
172
+ private hasPendingSentMutations;
173
+ }
@@ -1,12 +1,12 @@
1
- import { Observable } from 'rxjs';
2
- export type DestructorFn = () => Promise<void> | void;
3
- export declare class DestructManager {
4
- private readonly predestructors;
5
- private readonly destructors;
6
- private readonly isDestructedSubject;
7
- get isDestructing(): boolean;
8
- observeIsDestructing(): Observable<void>;
9
- onPreDestruct(fn: DestructorFn): void;
10
- onDestruct(fn: DestructorFn): void;
11
- destruct(): Promise<void>;
12
- }
1
+ import { Observable } from 'rxjs';
2
+ export type DestructorFn = () => Promise<void> | void;
3
+ export declare class DestructManager {
4
+ private readonly predestructors;
5
+ private readonly destructors;
6
+ private readonly isDestructedSubject;
7
+ get isDestructing(): boolean;
8
+ observeIsDestructing(): Observable<void>;
9
+ onPreDestruct(fn: DestructorFn): void;
10
+ onDestruct(fn: DestructorFn): void;
11
+ destruct(): Promise<void>;
12
+ }