@squidcloud/client 1.0.168 → 1.0.169
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +17 -10
- package/dist/internal-common/src/public-types/ai-assistant.public-types.d.ts +25 -0
- package/dist/internal-common/src/public-types/ai-chatbot.public-context.d.ts +12 -0
- package/dist/internal-common/src/public-types/ai-chatbot.public-types.d.ts +31 -0
- package/dist/internal-common/src/public-types/api-call.public-context.d.ts +14 -0
- package/dist/internal-common/src/public-types/application.public-types.d.ts +149 -0
- package/dist/internal-common/src/public-types/base-query-builder.public-types.d.ts +147 -0
- package/dist/internal-common/src/public-types/bundle-api.public-types.d.ts +57 -0
- package/dist/internal-common/src/public-types/bundle-data.public-types.d.ts +8 -0
- package/dist/internal-common/src/public-types/communication.public-types.d.ts +12 -0
- package/dist/internal-common/src/public-types/context.public-types.d.ts +40 -0
- package/dist/internal-common/src/public-types/distributed-lock.public-context.d.ts +4 -0
- package/dist/internal-common/src/public-types/document.public-types.d.ts +32 -0
- package/dist/internal-common/src/public-types/graphql.public-context.d.ts +7 -0
- package/dist/internal-common/src/public-types/graphql.public-types.d.ts +9 -0
- package/dist/internal-common/src/public-types/http-status.enum.d.ts +50 -0
- package/dist/internal-common/src/public-types/integration.public-types.d.ts +61 -0
- package/dist/internal-common/src/public-types/integrations/ai_chatbot.types.d.ts +32 -0
- package/dist/internal-common/src/public-types/integrations/api.types.d.ts +81 -0
- package/dist/internal-common/src/public-types/integrations/auth.types.d.ts +54 -0
- package/dist/internal-common/src/public-types/integrations/database.types.d.ts +206 -0
- package/dist/internal-common/src/public-types/integrations/observability.types.d.ts +24 -0
- package/dist/internal-common/src/public-types/integrations/queue-types.d.ts +40 -0
- package/dist/internal-common/src/public-types/integrations/schemas.d.ts +70 -0
- package/dist/internal-common/src/public-types/mutation.public-context.d.ts +14 -0
- package/dist/internal-common/src/public-types/mutation.public-types.d.ts +53 -0
- package/dist/internal-common/src/public-types/native-query.public-context.d.ts +7 -0
- package/dist/internal-common/src/public-types/native-query.public-types.d.ts +16 -0
- package/dist/internal-common/src/public-types/pagination.public-types.d.ts +62 -0
- package/dist/internal-common/src/public-types/query.public-context.d.ts +137 -0
- package/dist/internal-common/src/public-types/query.public-types.d.ts +64 -0
- package/dist/internal-common/src/public-types/regions.public-types.d.ts +5 -0
- package/dist/internal-common/src/public-types/schema.public-types.d.ts +46 -0
- package/dist/internal-common/src/public-types/secret.public-types.d.ts +16 -0
- package/dist/internal-common/src/public-types/serialized-query.public-types.d.ts +24 -0
- package/dist/internal-common/src/public-types/socket.public-types.d.ts +5 -0
- package/dist/internal-common/src/public-types/topic.public-context.d.ts +10 -0
- package/dist/internal-common/src/public-types/typescript.public-types.d.ts +15 -0
- package/dist/internal-common/src/public-utils/id-utils.d.ts +6 -0
- package/dist/internal-common/src/types/ai-assistant.types.d.ts +1 -0
- package/dist/internal-common/src/types/ai-chatbot.types.d.ts +1 -0
- package/dist/internal-common/src/types/api.types.d.ts +2 -0
- package/dist/internal-common/src/types/backend-function.types.d.ts +1 -0
- package/dist/internal-common/src/types/backend-run.types.d.ts +1 -0
- package/dist/internal-common/src/types/bundle-data.types.d.ts +1 -0
- package/dist/internal-common/src/types/communication.types.d.ts +1 -0
- package/dist/internal-common/src/types/document.types.d.ts +1 -0
- package/dist/internal-common/src/types/mutation.types.d.ts +1 -0
- package/dist/internal-common/src/types/openapi.types.d.ts +1 -0
- package/dist/internal-common/src/types/query.types.d.ts +1 -0
- package/dist/internal-common/src/types/secret.types.d.ts +11 -0
- package/dist/internal-common/src/types/socket.types.d.ts +1 -0
- package/dist/internal-common/src/utils/array.d.ts +1 -0
- package/dist/internal-common/src/utils/assert.d.ts +1 -0
- package/dist/internal-common/src/utils/global.utils.d.ts +1 -0
- package/dist/internal-common/src/utils/http.d.ts +2 -0
- package/dist/internal-common/src/utils/lock.manager.d.ts +14 -0
- package/dist/internal-common/src/utils/object.d.ts +5 -0
- package/dist/internal-common/src/utils/serialization.d.ts +5 -0
- package/dist/internal-common/src/utils/validation.d.ts +24 -0
- package/dist/internal-common/src/websocket.impl.d.ts +21 -0
- package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -0
- package/dist/typescript-client/src/ai-assistant-client.d.ts +73 -0
- package/dist/typescript-client/src/ai-chatbot-client.d.ts +168 -0
- package/dist/typescript-client/src/ai-chatbot-client.factory.d.ts +1 -0
- package/dist/typescript-client/src/ai.types.d.ts +60 -0
- package/dist/typescript-client/src/api.manager.d.ts +11 -0
- package/dist/typescript-client/src/auth.manager.d.ts +27 -0
- package/dist/typescript-client/src/backend-function.manager.d.ts +9 -0
- package/dist/typescript-client/src/backend-transforms.d.ts +0 -0
- package/dist/typescript-client/src/client-id.service.d.ts +27 -0
- package/dist/typescript-client/src/collection-reference.d.ts +80 -0
- package/dist/typescript-client/src/collection-reference.factory.d.ts +1 -0
- package/dist/typescript-client/src/connection-details.d.ts +23 -0
- package/dist/typescript-client/src/data.manager.d.ts +5 -0
- package/dist/typescript-client/src/destruct.manager.d.ts +13 -0
- package/dist/typescript-client/src/distributed-lock.manager.d.ts +16 -0
- package/dist/typescript-client/src/document-identity.service.d.ts +1 -0
- package/dist/typescript-client/src/document-reference.d.ts +149 -0
- package/dist/typescript-client/src/document-reference.factory.d.ts +1 -0
- package/dist/typescript-client/src/document-store.d.ts +14 -0
- package/dist/typescript-client/src/graphql-client.d.ts +14 -0
- package/dist/typescript-client/src/graphql-client.factory.d.ts +11 -0
- package/dist/typescript-client/src/index.d.ts +11 -0
- package/dist/typescript-client/src/mutation/mutation-sender.d.ts +1 -0
- package/dist/typescript-client/src/native-query-manager.d.ts +7 -0
- package/dist/typescript-client/src/public-types.d.ts +37 -0
- package/dist/typescript-client/src/public-utils.d.ts +1 -0
- package/dist/typescript-client/src/query/deserializer.d.ts +3 -0
- package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +161 -0
- package/dist/typescript-client/src/query/local-query-manager.d.ts +1 -0
- package/dist/typescript-client/src/query/query-builder.factory.d.ts +77 -0
- package/dist/typescript-client/src/query/query-sender.d.ts +1 -0
- package/dist/typescript-client/src/query/query-subscription.manager.d.ts +2 -0
- package/dist/typescript-client/src/query/query.types.d.ts +49 -0
- package/dist/typescript-client/src/queue.manager.d.ts +7 -0
- package/dist/typescript-client/src/rate-limiter.d.ts +32 -0
- package/dist/typescript-client/src/rpc.manager.d.ts +30 -0
- package/dist/typescript-client/src/secret.client.d.ts +23 -0
- package/dist/typescript-client/src/socket.manager.d.ts +1 -0
- package/dist/typescript-client/src/squid.d.ts +245 -0
- package/dist/typescript-client/src/state/state.service.spec.d.ts +1 -0
- package/dist/typescript-client/src/testing/setup-tests.d.ts +1 -0
- package/dist/typescript-client/src/types.d.ts +6 -0
- package/package.json +3 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { DocumentData } from './public-types';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { TransactionId } from './types';
|
|
4
|
+
import { DeepRecord, Paths } from '../../internal-common/src/public-types/typescript.public-types';
|
|
5
|
+
/**
|
|
6
|
+
* Holds a reference to a document. A document reference is a reference to a specific record in a collection. You can
|
|
7
|
+
* use it to read or write data to the document. A document can refer to a row in a table in a relational database or a
|
|
8
|
+
* document in a NoSQL database. Additionally, a document reference can refer to a non-existent document, which you can
|
|
9
|
+
* use to create a new document.
|
|
10
|
+
*
|
|
11
|
+
* Read more about document references in the
|
|
12
|
+
* {@link https://docs.squid.cloud/docs/development-tools/client-sdk/document-reference documentation}.
|
|
13
|
+
* @typeParam T The type of the document data.
|
|
14
|
+
*/
|
|
15
|
+
export declare class DocumentReference<T extends DocumentData = any> {
|
|
16
|
+
private _squidDocId;
|
|
17
|
+
private readonly dataManager;
|
|
18
|
+
private readonly queryBuilderFactory;
|
|
19
|
+
/** A string that uniquely identifies this document reference. */
|
|
20
|
+
refId: string;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the document data. Throws an error if the document does not exist.
|
|
23
|
+
*
|
|
24
|
+
* @returns The document data.
|
|
25
|
+
* @throws Error if the document does not exist.
|
|
26
|
+
*/
|
|
27
|
+
get data(): T;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a read-only internal copy of the document data. This works similar to `this.data`, except it does not
|
|
30
|
+
* perform a defensive copy. The caller may not modify this object, on penalty of unexpected behavior.
|
|
31
|
+
*
|
|
32
|
+
* @returns The document data.
|
|
33
|
+
* @throws Error if the document does not exist.
|
|
34
|
+
*/
|
|
35
|
+
get dataRef(): T;
|
|
36
|
+
/**
|
|
37
|
+
* Returns whether data has been populated for this document reference. Data
|
|
38
|
+
* will not present if a document has not been queried, does not exist, or
|
|
39
|
+
* has been deleted.
|
|
40
|
+
*
|
|
41
|
+
* @returns Whether the document has data.
|
|
42
|
+
*/
|
|
43
|
+
get hasData(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* A promise that resolves with the latest data from the server or undefined if the document does not exist on the
|
|
46
|
+
* server.
|
|
47
|
+
*
|
|
48
|
+
* @returns A promise that resolves with latest data from the server or undefined if the document does not exist on
|
|
49
|
+
* the server.
|
|
50
|
+
*/
|
|
51
|
+
snapshot(): Promise<T | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Returns an observable that emits the latest data from the server or undefined if the document is deleted or does
|
|
54
|
+
* not exist on the server.
|
|
55
|
+
*
|
|
56
|
+
* @returns An observable that emits the latest data from the server or undefined if the document is deleted or does
|
|
57
|
+
* not exist on the server.
|
|
58
|
+
*/
|
|
59
|
+
snapshots(): Observable<T | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the data that is currently available on the client or undefined if data has not yet been populated.
|
|
62
|
+
*
|
|
63
|
+
* @returns The data that is currently available on the client or undefined if data has not yet been populated.
|
|
64
|
+
*/
|
|
65
|
+
peek(): T | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Returns whether the locally available version of the document may not be the latest version on the server.
|
|
68
|
+
*
|
|
69
|
+
* @returns Whether the locally available version of the document may not be the latest version on the server.
|
|
70
|
+
*/
|
|
71
|
+
isDirty(): boolean;
|
|
72
|
+
private isTracked;
|
|
73
|
+
/**
|
|
74
|
+
* Updates the document with the given data.
|
|
75
|
+
* The `update` will be reflected optimistically locally and will be applied to the server later.
|
|
76
|
+
* If a transactionId is provided, the `update` will be applied to the server as an atomic operation together with
|
|
77
|
+
* the rest of the operations in the transaction and the `update` will not reflect locally until the transaction is
|
|
78
|
+
* completed locally.
|
|
79
|
+
*
|
|
80
|
+
* The returned promise will resolve once the `update` has been applied to the server or immediately if the `update`
|
|
81
|
+
* is part of a transaction.
|
|
82
|
+
*
|
|
83
|
+
* @param data The data to update - can be partial.
|
|
84
|
+
* @param transactionId The transaction to use for this operation. If not provided, the operation will be applied
|
|
85
|
+
* immediately.
|
|
86
|
+
*/
|
|
87
|
+
update(data: Partial<DeepRecord<T>>, transactionId?: TransactionId): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Similar to {@link update}, but only updates the given path.
|
|
90
|
+
* @param path The path to update.
|
|
91
|
+
* @param value The value to set at the given path.
|
|
92
|
+
* @param transactionId The transaction to use for this operation. If not provided, the operation will be applied
|
|
93
|
+
* immediately.
|
|
94
|
+
*/
|
|
95
|
+
setInPath<K extends Paths<T>>(path: K, value: DeepRecord<T>[K], transactionId?: TransactionId): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Similar to `update`, but only deletes the given path.
|
|
98
|
+
* @param path The path to delete.
|
|
99
|
+
* @param transactionId The transaction to use for this operation. If not provided, the operation will be applied
|
|
100
|
+
* immediately.
|
|
101
|
+
*/
|
|
102
|
+
deleteInPath(path: Paths<T>, transactionId?: TransactionId): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Increments the value at the given path by the given value. The value may be both positive and negative.
|
|
105
|
+
* @param path The path to the value to increment.
|
|
106
|
+
* @param value The value to increment by.
|
|
107
|
+
* @param transactionId The transaction to use for this operation. If not provided, the operation will be applied
|
|
108
|
+
* immediately.
|
|
109
|
+
*/
|
|
110
|
+
incrementInPath(path: Paths<T>, value: number, transactionId?: TransactionId): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Decrements the value at the given path by the given value. The value may be both positive and negative.
|
|
113
|
+
* @param path The path to the value to decrement.
|
|
114
|
+
* @param value The value to decrement by.
|
|
115
|
+
* @param transactionId The transaction to use for this operation. If not provided, the operation will be applied
|
|
116
|
+
* immediately.
|
|
117
|
+
*/
|
|
118
|
+
decrementInPath(path: Paths<T>, value: number, transactionId?: TransactionId): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Inserts the document with the given data. If the document already exists, the operation will be treated as
|
|
121
|
+
* `upsert`. The `insert` will be reflected optimistically locally and will be applied to the server later. If a
|
|
122
|
+
* transactionId is provided, the `insert` will be applied to the server as an atomic operation together with the
|
|
123
|
+
* rest
|
|
124
|
+
* of the operations in the transaction and the `insert` will not reflect locally until the transaction is completed
|
|
125
|
+
* locally.
|
|
126
|
+
*
|
|
127
|
+
* The returned promise will resolve once the `insert` has been applied to the server or immediately if the `insert`
|
|
128
|
+
* is part of a transaction.
|
|
129
|
+
*
|
|
130
|
+
* @param data The data to insert.
|
|
131
|
+
* @param transactionId The transaction to use for this operation. If not provided, the operation will be applied
|
|
132
|
+
* immediately.
|
|
133
|
+
*/
|
|
134
|
+
insert(data: T, transactionId?: TransactionId): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Deletes the document.
|
|
137
|
+
* The `delete` will be reflected optimistically locally and will be applied to the server later.
|
|
138
|
+
* If a transactionId is provided, the `delete` will be applied to the server as an atomic operation together with
|
|
139
|
+
* the rest of the operations in the transaction and the `delete` will not reflect locally until the transaction is
|
|
140
|
+
* completed locally.
|
|
141
|
+
*
|
|
142
|
+
* The returned promise will resolve once the `delete` has been applied to the server or immediately if the `delete`
|
|
143
|
+
* is part of a transaction.
|
|
144
|
+
*
|
|
145
|
+
* @param transactionId The transaction to use for this operation. If not provided, the operation will be applied
|
|
146
|
+
* immediately.
|
|
147
|
+
*/
|
|
148
|
+
delete(transactionId?: TransactionId): Promise<void>;
|
|
149
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FieldType, Query, SquidDocId, SquidDocument } from './public-types';
|
|
2
|
+
export declare class DocumentStore {
|
|
3
|
+
private readonly squidDocIdToDoc;
|
|
4
|
+
saveDocument(squidDocId: SquidDocId, properties: SquidDocument | undefined): SquidDocument | undefined;
|
|
5
|
+
hasData(squidDocId: SquidDocId): boolean;
|
|
6
|
+
getDocument(squidDocId: SquidDocId): SquidDocument;
|
|
7
|
+
getDocumentOrUndefined(squidDocId: SquidDocId): SquidDocument | undefined;
|
|
8
|
+
compareValues(a: FieldType | undefined, b: FieldType | undefined): number;
|
|
9
|
+
compareSquidDocs(a: SquidDocument, b: SquidDocument, sortFieldNames: string[], sortOrders: ('asc' | 'desc')[]): number;
|
|
10
|
+
group(sortedDocs: SquidDocument[], sortFieldNames: string[]): SquidDocument[][];
|
|
11
|
+
sortAndLimitDocs(docIdSet: Set<SquidDocId>, query: Query): Array<SquidDocument>;
|
|
12
|
+
private removeInternalProperties;
|
|
13
|
+
migrateDocId(squidDocId: SquidDocId, newSquidDocId: SquidDocId): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RpcManager } from './rpc.manager';
|
|
2
|
+
import { GraphQLRequest, IntegrationId, SupportedSquidRegion } from './public-types';
|
|
3
|
+
/** A GraphQL client that can be used to query and mutate data. */
|
|
4
|
+
export declare class GraphQLClient {
|
|
5
|
+
private readonly rpcManager;
|
|
6
|
+
private readonly region;
|
|
7
|
+
private readonly appId;
|
|
8
|
+
private readonly client;
|
|
9
|
+
constructor(rpcManager: RpcManager, integrationId: IntegrationId, region: SupportedSquidRegion, appId: string);
|
|
10
|
+
/** Executes a GraphQL query and returns a promise with the result. */
|
|
11
|
+
query<T = any>(request: GraphQLRequest): Promise<T>;
|
|
12
|
+
/** Executes a GraphQL mutation and returns a promise with the result. */
|
|
13
|
+
mutate<T = Record<string, any>>(request: GraphQLRequest): Promise<T | null | undefined>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GraphQLClient } from './graphql-client';
|
|
2
|
+
import { RpcManager } from './rpc.manager';
|
|
3
|
+
import { IntegrationId, SupportedSquidRegion } from './public-types';
|
|
4
|
+
export declare class GraphQLClientFactory {
|
|
5
|
+
private readonly rpcManager;
|
|
6
|
+
private readonly region;
|
|
7
|
+
private readonly appId;
|
|
8
|
+
private readonly clientsMap;
|
|
9
|
+
constructor(rpcManager: RpcManager, region: SupportedSquidRegion, appId: string);
|
|
10
|
+
get(integrationId: IntegrationId): GraphQLClient;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './public-types';
|
|
2
|
+
export * from './public-utils';
|
|
3
|
+
export { AiChatbotProfileReference } from './ai-chatbot-client';
|
|
4
|
+
export { Changes, QueryBuilder } from './query/query-builder.factory';
|
|
5
|
+
export { CollectionReference } from './collection-reference';
|
|
6
|
+
export { DocumentReference } from './document-reference';
|
|
7
|
+
export { GraphQLClient } from './graphql-client';
|
|
8
|
+
export { JoinQueryBuilder } from './query/join-query-builder.factory';
|
|
9
|
+
export { Squid, SquidOptions } from './squid';
|
|
10
|
+
export { TransactionId } from './types';
|
|
11
|
+
export { deserializeQuery } from './query/deserializer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RpcManager } from './rpc.manager';
|
|
2
|
+
import { IntegrationId, NativeQueryRequest } from './public-types';
|
|
3
|
+
export declare class NativeQueryManager {
|
|
4
|
+
private readonly rpcManager;
|
|
5
|
+
constructor(rpcManager: RpcManager);
|
|
6
|
+
executeNativeQuery<T>(integrationId: IntegrationId, request: NativeQueryRequest): Promise<T>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export * from '../../internal-common/src/public-types/ai-assistant.public-types';
|
|
2
|
+
export * from '../../internal-common/src/public-types/ai-chatbot.public-context';
|
|
3
|
+
export * from '../../internal-common/src/public-types/ai-chatbot.public-types';
|
|
4
|
+
export * from '../../internal-common/src/public-types/api-call.public-context';
|
|
5
|
+
export * from '../../internal-common/src/public-types/application.public-types';
|
|
6
|
+
export * from '../../internal-common/src/public-types/base-query-builder.public-types';
|
|
7
|
+
export * from '../../internal-common/src/public-types/bundle-api.public-types';
|
|
8
|
+
export * from '../../internal-common/src/public-types/bundle-data.public-types';
|
|
9
|
+
export * from '../../internal-common/src/public-types/communication.public-types';
|
|
10
|
+
export * from '../../internal-common/src/public-types/context.public-types';
|
|
11
|
+
export * from '../../internal-common/src/public-types/distributed-lock.public-context';
|
|
12
|
+
export * from '../../internal-common/src/public-types/document.public-types';
|
|
13
|
+
export * from '../../internal-common/src/public-types/graphql.public-context';
|
|
14
|
+
export * from '../../internal-common/src/public-types/graphql.public-types';
|
|
15
|
+
export * from '../../internal-common/src/public-types/http-status.enum';
|
|
16
|
+
export * from '../../internal-common/src/public-types/integration.public-types';
|
|
17
|
+
export * from '../../internal-common/src/public-types/integrations/ai_chatbot.types';
|
|
18
|
+
export * from '../../internal-common/src/public-types/integrations/api.types';
|
|
19
|
+
export * from '../../internal-common/src/public-types/integrations/auth.types';
|
|
20
|
+
export * from '../../internal-common/src/public-types/integrations/database.types';
|
|
21
|
+
export * from '../../internal-common/src/public-types/integrations/observability.types';
|
|
22
|
+
export * from '../../internal-common/src/public-types/integrations/queue-types';
|
|
23
|
+
export * from '../../internal-common/src/public-types/integrations/schemas';
|
|
24
|
+
export * from '../../internal-common/src/public-types/mutation.public-context';
|
|
25
|
+
export * from '../../internal-common/src/public-types/mutation.public-types';
|
|
26
|
+
export * from '../../internal-common/src/public-types/native-query.public-context';
|
|
27
|
+
export * from '../../internal-common/src/public-types/native-query.public-types';
|
|
28
|
+
export * from '../../internal-common/src/public-types/pagination.public-types';
|
|
29
|
+
export * from '../../internal-common/src/public-types/query.public-context';
|
|
30
|
+
export * from '../../internal-common/src/public-types/query.public-types';
|
|
31
|
+
export * from '../../internal-common/src/public-types/regions.public-types';
|
|
32
|
+
export * from '../../internal-common/src/public-types/schema.public-types';
|
|
33
|
+
export * from '../../internal-common/src/public-types/secret.public-types';
|
|
34
|
+
export * from '../../internal-common/src/public-types/serialized-query.public-types';
|
|
35
|
+
export * from '../../internal-common/src/public-types/socket.public-types';
|
|
36
|
+
export * from '../../internal-common/src/public-types/topic.public-context';
|
|
37
|
+
export * from '../../internal-common/src/public-types/typescript.public-types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../internal-common/src/public-utils/id-utils';
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { DocumentReference } from '../document-reference';
|
|
3
|
+
import { QueryBuilder } from './query-builder.factory';
|
|
4
|
+
import { Alias, BaseQueryBuilder, DocumentData, FieldName, FieldSort, HasDereference, Operator, Pagination, PaginationOptions, PrimitiveFieldType, SerializedJoinQuery, SimpleCondition, SnapshotEmitter } from '../public-types';
|
|
5
|
+
type WithDocumentReferences<T extends Record<any, DocumentData>> = {
|
|
6
|
+
[k in keyof T]: DocumentReference<Required<T>[k]>;
|
|
7
|
+
};
|
|
8
|
+
type Grouped<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, any>, RootAlias extends Alias> = Aliases[RootAlias] extends [] ? Required<ReturnType>[RootAlias] : Record<RootAlias, Required<ReturnType>[RootAlias]> & OtherGroups<Aliases, ReturnType, Aliases[RootAlias]>;
|
|
9
|
+
type OtherGroups<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, any>, ManyRootAliases extends Alias[]> = ManyRootAliases extends [infer First extends Alias, ...infer Rest extends Alias[]] ? Record<First, Array<Grouped<Aliases, ReturnType, First>>> & OtherGroups<Aliases, ReturnType, Rest> : Record<Alias, never>;
|
|
10
|
+
interface HasGrouped {
|
|
11
|
+
/**
|
|
12
|
+
* Transforms this join query result to a nested data structure. For example, a join between teachers and students
|
|
13
|
+
* normally returns a result of the form:
|
|
14
|
+
* [
|
|
15
|
+
* { teacher: {name: 'Mr. Smith'}, student: {name: 'John Doe'} },
|
|
16
|
+
* { teacher: {name: 'Mr. Smith'}, student: {name: 'Jane Smith'} },
|
|
17
|
+
* { teacher: {name: 'Mr. EmptyClass'}, student: undefined },
|
|
18
|
+
* ]
|
|
19
|
+
* into a result of the form:
|
|
20
|
+
* [
|
|
21
|
+
* { teacher: {name: 'Mr. Smith'}, students: [
|
|
22
|
+
* { name: 'John Doe' },
|
|
23
|
+
* { name: 'Jane Smith' },
|
|
24
|
+
* ]},
|
|
25
|
+
* { teacher: {name: 'Mr. EmptyClass'}, students: [] },
|
|
26
|
+
* ]
|
|
27
|
+
*/
|
|
28
|
+
grouped(): any;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A query builder that can participate in a join.
|
|
32
|
+
* To learn more about join queries, see the
|
|
33
|
+
* {@link https://docs.squid.cloud/docs/development-tools/client-sdk/queries#joining-data-across-collections-and-integrations documentation}.
|
|
34
|
+
*/
|
|
35
|
+
export declare class JoinQueryBuilder<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, LatestAlias extends Alias, RootAlias extends Alias> extends BaseQueryBuilder<ReturnType> implements SnapshotEmitter<WithDocumentReferences<ReturnType>>, HasGrouped, HasDereference {
|
|
36
|
+
private readonly collectionName;
|
|
37
|
+
private readonly integrationId;
|
|
38
|
+
private readonly querySubscriptionManager;
|
|
39
|
+
private readonly documentReferenceFactory;
|
|
40
|
+
private readonly queryBuilderFactory;
|
|
41
|
+
private readonly latestAlias;
|
|
42
|
+
private readonly joins;
|
|
43
|
+
private readonly joinConditions;
|
|
44
|
+
private readonly queryBuilder;
|
|
45
|
+
/**
|
|
46
|
+
* Adds a condition to the query.
|
|
47
|
+
*
|
|
48
|
+
* @param fieldName The name of the field to query
|
|
49
|
+
* @param operator The operator to use
|
|
50
|
+
* @param value The value to compare against
|
|
51
|
+
* @returns The query builder
|
|
52
|
+
*/
|
|
53
|
+
where(fieldName: (keyof ReturnType[LatestAlias] & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
|
|
54
|
+
/**
|
|
55
|
+
* Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
|
|
56
|
+
* if none is provided.
|
|
57
|
+
*
|
|
58
|
+
* @param limit The maximum number of results to return
|
|
59
|
+
* @returns The query builder
|
|
60
|
+
*/
|
|
61
|
+
limit(limit: number): this;
|
|
62
|
+
getLimit(): number;
|
|
63
|
+
/**
|
|
64
|
+
* Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them
|
|
65
|
+
* determines the order in which they are applied.
|
|
66
|
+
* @param fieldName The name of the field to sort by
|
|
67
|
+
* @param asc Whether to sort in ascending order. Defaults to true.
|
|
68
|
+
* @returns The query builder
|
|
69
|
+
*/
|
|
70
|
+
sortBy(fieldName: keyof ReturnType[RootAlias] & FieldName, asc?: boolean): this;
|
|
71
|
+
/**
|
|
72
|
+
* Joins this query with another join query and return a new query builder that can be used to query the joined
|
|
73
|
+
* documents.
|
|
74
|
+
* @param queryBuilder The query builder to join with
|
|
75
|
+
* @param alias TODO
|
|
76
|
+
* @param joinFields TODO
|
|
77
|
+
* @param options TODO
|
|
78
|
+
* @returns A new query builder that can be used to query the joined documents
|
|
79
|
+
*/
|
|
80
|
+
join<NewAlias extends string, NewReturnType extends DocumentData, LeftAlias extends Extract<keyof ReturnType, Alias>, IsInner extends boolean = false>(queryBuilder: QueryBuilder<NewReturnType>, alias: Exclude<NewAlias, keyof ReturnType>, joinFields: {
|
|
81
|
+
left: keyof Required<ReturnType>[LeftAlias] & FieldName;
|
|
82
|
+
right: keyof NewReturnType & FieldName;
|
|
83
|
+
}, options: {
|
|
84
|
+
leftAlias: LeftAlias;
|
|
85
|
+
isInner?: IsInner;
|
|
86
|
+
}): JoinQueryBuilder<Omit<Aliases, LeftAlias> & Record<LeftAlias, [...Aliases[LeftAlias], NewAlias]> & Record<NewAlias, []>, ReturnType & (IsInner extends true ? Record<NewAlias, NewReturnType> : Partial<Record<NewAlias, NewReturnType>>), NewAlias, RootAlias>;
|
|
87
|
+
join<NewAlias extends string, NewReturnType extends DocumentData, IsInner extends boolean = false>(queryBuilder: QueryBuilder<NewReturnType>, alias: Exclude<NewAlias, keyof ReturnType>, joinFields: {
|
|
88
|
+
left: keyof Required<ReturnType>[LatestAlias] & FieldName;
|
|
89
|
+
right: keyof NewReturnType & FieldName;
|
|
90
|
+
}, options?: {
|
|
91
|
+
isInner?: IsInner;
|
|
92
|
+
}): JoinQueryBuilder<Omit<Aliases, LatestAlias> & Record<LatestAlias, [...Aliases[LatestAlias], NewAlias]> & Record<NewAlias, []>, ReturnType & (IsInner extends true ? Record<NewAlias, NewReturnType> : Partial<Record<NewAlias, NewReturnType>>), NewAlias, RootAlias>;
|
|
93
|
+
/** @inheritDoc */
|
|
94
|
+
snapshot(): Promise<Array<WithDocumentReferences<ReturnType>>>;
|
|
95
|
+
/** @inheritDoc */
|
|
96
|
+
snapshots(subscribe?: boolean): Observable<Array<WithDocumentReferences<ReturnType>>>;
|
|
97
|
+
/**
|
|
98
|
+
* @inheritDoc
|
|
99
|
+
*/
|
|
100
|
+
peek(): Array<WithDocumentReferences<ReturnType>>;
|
|
101
|
+
/** @inheritDoc */
|
|
102
|
+
grouped(): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
103
|
+
/** @inheritDoc */
|
|
104
|
+
dereference(): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
105
|
+
getSortOrders(): Array<FieldSort<any>>;
|
|
106
|
+
clone(): JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>;
|
|
107
|
+
addCompositeCondition(conditions: Array<SimpleCondition>): JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>;
|
|
108
|
+
flipSortOrder(): JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>;
|
|
109
|
+
extractData(data: WithDocumentReferences<ReturnType>): Required<ReturnType>[RootAlias];
|
|
110
|
+
serialize(): SerializedJoinQuery;
|
|
111
|
+
paginate(options?: Partial<PaginationOptions>): Pagination<WithDocumentReferences<ReturnType>>;
|
|
112
|
+
}
|
|
113
|
+
declare class DereferencedJoin<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, RootAlias extends Alias, LatestAlias extends Alias> implements SnapshotEmitter<ReturnType>, HasGrouped {
|
|
114
|
+
private readonly joinQueryBuilder;
|
|
115
|
+
constructor(joinQueryBuilder: JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>);
|
|
116
|
+
/** @inheritDoc */
|
|
117
|
+
grouped(): SnapshotEmitter<Grouped<Aliases, ReturnType, RootAlias>>;
|
|
118
|
+
/** @inheritDoc */
|
|
119
|
+
snapshot(): Promise<Array<ReturnType>>;
|
|
120
|
+
/** @inheritDoc */
|
|
121
|
+
snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
|
|
122
|
+
/**
|
|
123
|
+
* @inheritDoc
|
|
124
|
+
*/
|
|
125
|
+
peek(): Array<ReturnType>;
|
|
126
|
+
getSortOrders(): Array<FieldSort<any>>;
|
|
127
|
+
clone(): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
128
|
+
addCompositeCondition(conditions: Array<SimpleCondition>): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
129
|
+
flipSortOrder(): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
130
|
+
limit(limit: number): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
131
|
+
extractData(data: ReturnType): any;
|
|
132
|
+
paginate(options?: Partial<PaginationOptions>): Pagination<ReturnType>;
|
|
133
|
+
serialize(): SerializedJoinQuery;
|
|
134
|
+
getLimit(): number;
|
|
135
|
+
}
|
|
136
|
+
declare class GroupedJoin<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, RootAlias extends Alias, LatestAlias extends Alias> implements SnapshotEmitter<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>, HasDereference {
|
|
137
|
+
readonly joinQueryBuilder: JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>;
|
|
138
|
+
/** internal */
|
|
139
|
+
constructor(joinQueryBuilder: JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>);
|
|
140
|
+
/** @inheritDoc */
|
|
141
|
+
snapshot(): Promise<Array<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>>;
|
|
142
|
+
/** @inheritDoc */
|
|
143
|
+
snapshots(subscribe?: boolean): Observable<Array<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>>;
|
|
144
|
+
/**
|
|
145
|
+
* @inheritDoc
|
|
146
|
+
*/
|
|
147
|
+
peek(): Array<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>;
|
|
148
|
+
/** @inheritDoc */
|
|
149
|
+
dereference(): SnapshotEmitter<Grouped<Aliases, ReturnType, RootAlias>>;
|
|
150
|
+
private groupData;
|
|
151
|
+
getSortOrders(): Array<FieldSort<any>>;
|
|
152
|
+
clone(): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
153
|
+
addCompositeCondition(conditions: Array<SimpleCondition>): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
154
|
+
flipSortOrder(): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
155
|
+
limit(limit: number): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
156
|
+
getLimit(): number;
|
|
157
|
+
extractData(data: Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>): any;
|
|
158
|
+
serialize(): SerializedJoinQuery;
|
|
159
|
+
paginate(options?: Partial<PaginationOptions>): Pagination<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>;
|
|
160
|
+
}
|
|
161
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { DocumentReference } from '../document-reference';
|
|
3
|
+
import { BaseQueryBuilder, DocumentData, FieldName, FieldSort, HasDereference, Operator, Pagination, PaginationOptions, PrimitiveFieldType, SerializedSimpleQuery, SimpleCondition, SnapshotEmitter } from '../public-types';
|
|
4
|
+
/** A query builder that can be used to build a query that returns a list of documents. */
|
|
5
|
+
export declare class QueryBuilder<DocumentType extends DocumentData> extends BaseQueryBuilder<DocumentType> implements SnapshotEmitter<DocumentReference<DocumentType>>, HasDereference {
|
|
6
|
+
private readonly collectionName;
|
|
7
|
+
private readonly integrationId;
|
|
8
|
+
private readonly querySubscriptionManager;
|
|
9
|
+
private readonly localQueryManager;
|
|
10
|
+
private readonly documentReferenceFactory;
|
|
11
|
+
private readonly queryBuilderFactory;
|
|
12
|
+
private readonly documentIdentityService;
|
|
13
|
+
private forceFetchFromServer;
|
|
14
|
+
/** @inheritDoc */
|
|
15
|
+
where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
|
|
16
|
+
/** @inheritDoc */
|
|
17
|
+
limit(limit: number): this;
|
|
18
|
+
getLimit(): number;
|
|
19
|
+
limitBy(limit: number, ...fields: FieldName[]): this;
|
|
20
|
+
/** @inheritDoc */
|
|
21
|
+
sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
|
|
22
|
+
private mergeConditions;
|
|
23
|
+
getSortOrder(): FieldSort<DocumentType>[];
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
|
|
28
|
+
/**
|
|
29
|
+
* Forces the query to return data from the server even if there is a query that already returned the requested
|
|
30
|
+
* result.
|
|
31
|
+
*/
|
|
32
|
+
setForceFetchFromServer(): this;
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
peek(): Array<DocumentReference<DocumentType>>;
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
changes(): Observable<Changes<DocumentType>>;
|
|
45
|
+
/**
|
|
46
|
+
* A unique hash for the query. Identical queries should return the same hash
|
|
47
|
+
* value.
|
|
48
|
+
*
|
|
49
|
+
* @returns The query's hash string.
|
|
50
|
+
*/
|
|
51
|
+
get hash(): string;
|
|
52
|
+
/** @inheritDoc */
|
|
53
|
+
dereference(): SnapshotEmitter<DocumentType>;
|
|
54
|
+
getSortOrders(): Array<FieldSort<any>>;
|
|
55
|
+
clone(): QueryBuilder<DocumentType>;
|
|
56
|
+
addCompositeCondition(conditions: Array<SimpleCondition>): QueryBuilder<DocumentType>;
|
|
57
|
+
flipSortOrder(): QueryBuilder<DocumentType>;
|
|
58
|
+
serialize(): SerializedSimpleQuery;
|
|
59
|
+
extractData(data: DocumentReference<DocumentType>): DocumentType;
|
|
60
|
+
paginate(options?: Partial<PaginationOptions>): Pagination<DocumentReference<DocumentType>>;
|
|
61
|
+
}
|
|
62
|
+
/** Describes the changes to a query result. */
|
|
63
|
+
export declare class Changes<DocumentType extends DocumentData> {
|
|
64
|
+
/** The newly inserted documents to the query result */
|
|
65
|
+
readonly inserts: Array<DocumentReference<DocumentType>>;
|
|
66
|
+
/** The documents that were updated in the query result */
|
|
67
|
+
readonly updates: Array<DocumentReference<DocumentType>>;
|
|
68
|
+
/** The actual document data that was deleted from the query result */
|
|
69
|
+
readonly deletes: Array<DocumentType>;
|
|
70
|
+
constructor(
|
|
71
|
+
/** The newly inserted documents to the query result */
|
|
72
|
+
inserts: Array<DocumentReference<DocumentType>>,
|
|
73
|
+
/** The documents that were updated in the query result */
|
|
74
|
+
updates: Array<DocumentReference<DocumentType>>,
|
|
75
|
+
/** The actual document data that was deleted from the query result */
|
|
76
|
+
deletes: Array<DocumentType>);
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';
|
|
2
|
+
import { Alias, ClientRequestId, JoinCondition, Query, SquidDocument } from '../public-types';
|
|
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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AuthManager } from './auth.manager';
|
|
2
|
+
import { ClientIdService } from './client-id.service';
|
|
3
|
+
import { DestructManager } from './destruct.manager';
|
|
4
|
+
import { BlobAndFilename } from './types';
|
|
5
|
+
import { SupportedSquidRegion } from './public-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: unknown, 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
|
+
}
|