@squidcloud/client 1.0.147 → 1.0.149

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