@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,269 +1,238 @@
1
- import { ApiEndpointId, ApiKey, AppId, CollectionName, DocumentData, EnvironmentId, IntegrationId, QueryName, SquidDeveloperId, SupportedSquidRegion } from '@squidcloud/common';
2
- import { CollectionReference } from './collection-reference';
3
- import { ConnectionDetails } from './connection-details';
4
- import { DistributedLock } from './distributed-lock.manager';
5
- import { GraphQLClient } from './graphql-client';
6
- import { SecretClient } from './secret.client';
7
- import { TransactionId } from './types';
8
- import { AiClient } from './ai.types';
9
- /** The different options that can be used to initialize a Squid instance. */
10
- export interface SquidOptions {
11
- /**
12
- * A function that can be used to wrap messages coming from Squid to the application. This is useful for
13
- * different frameworks that need to wrap messages in order to detect changes (like Angular).
14
- * @param fn The function to wrap.
15
- */
16
- messageNotificationWrapper?: (fn: () => any) => any;
17
- /**
18
- * The application ID that is used to identify the application in Squid. The ID can be found in the Squid Cloud
19
- * Console.
20
- */
21
- appId: AppId;
22
- /**
23
- * The application API key, using the API key can be used to bypass security rules and other restrictions.
24
- * The API key can be found in the Squid Cloud Console.
25
- */
26
- apiKey?: ApiKey;
27
- /**
28
- * Access token provider for the Squid instance.
29
- * Used for managing the process of verifying the identity and authorization of users who attempt to access this
30
- * application via the current Squid instance.
31
- *
32
- * When the authProvider is set, the Squid service will fetch a token and include it with every request to the Squid
33
- * backend.
34
- *
35
- * On the backend, Squid will validate the access token.
36
- */
37
- authProvider?: SquidAuthProvider;
38
- /**
39
- * The region that the application is running in. This is used to determine the URL of the Squid Cloud API.
40
- */
41
- region: SupportedSquidRegion;
42
- /**
43
- * The environment ID to work with, if not specified the default environment (prod) will be used.
44
- */
45
- environmentId?: EnvironmentId;
46
- /**
47
- * The user ID of the developer that runs the environment locally.
48
- */
49
- squidDeveloperId?: SquidDeveloperId;
50
- /**
51
- * A list of API endpoints that can be used for overriding the default API endpoints for the different integrations.
52
- * This is useful for APIs that have multiple base urls hosted in different regions.
53
- */
54
- apiServerUrlOverrideMapping?: Record<IntegrationId, string>;
55
- }
56
- /** Authentication data provider for Squid requests. */
57
- export interface SquidAuthProvider {
58
- /**
59
- * Returns a valid AccessToken.
60
- * Called by Squid every time a Squid client makes requests to the Squid backend.
61
- */
62
- getToken(): Promise<string | undefined>;
63
- /**
64
- * Optional Auth integration id.
65
- * Sent as a part of all Squid requests to the backend.
66
- */
67
- integrationId?: string;
68
- }
69
- /**
70
- * The main entry point to the Squid Client SDK.
71
- *
72
- * The Squid class provides a comprehensive array of functionality for accessing the different integrations, executing
73
- * backend functions, managing data, and more. Upon instantiating the Squid class, you will have access to all of these
74
- * capabilities.
75
- */
76
- export declare class Squid {
77
- readonly options: SquidOptions;
78
- private readonly socketManager;
79
- private readonly rpcManager;
80
- private readonly dataManager;
81
- private readonly documentReferenceFactory;
82
- private readonly documentStore;
83
- private readonly lockManager;
84
- private readonly querySubscriptionManager;
85
- private readonly localQueryManager;
86
- private readonly queryBuilderFactory;
87
- private readonly collectionReferenceFactory;
88
- private readonly backendFunctionManager;
89
- private readonly namedQueryManager;
90
- private readonly nativeQueryManager;
91
- private readonly apiManager;
92
- private readonly graphqlClientFactory;
93
- private readonly destructManager;
94
- private readonly documentIdentityService;
95
- private readonly distributedLockManager;
96
- private readonly authManager;
97
- private readonly clientIdService;
98
- private readonly aiClientFactory;
99
- private readonly _connectionDetails;
100
- private readonly secretClient;
101
- private readonly querySender;
102
- private static readonly squidInstancesMap;
103
- private readonly aiClient;
104
- /**
105
- * Creates a new instance of Squid with the given options.
106
- *
107
- * @param options The options for initializing the Squid instance.
108
- */
109
- constructor(options: SquidOptions);
110
- /**
111
- * Returns the global Squid instance with the given options, creating a new instance if one with the same options
112
- * does not exist.
113
- *
114
- * @param options The options for initializing the Squid instance.
115
- * @returns A global Squid instance with the given options.
116
- */
117
- static getInstance(options: SquidOptions): Squid;
118
- /**
119
- * Returns all the global Squid instances.
120
- *
121
- * @returns An array of all the global Squid instances.
122
- */
123
- static getInstances(): Array<Squid>;
124
- /**
125
- * Sets the authorization access token (OAuth2.0) provider that will be sent to the server and will be used for
126
- * providing the `auth` object to the security rules.
127
- *
128
- * @param authProvider The OAuth2.0 access token provider invoked for every backend request by Squid.
129
- * When the provider returns undefined, no authorization information is sent.
130
- * When a new provider is set, all future Squid backend requests will use the new token provider, and exising
131
- * in-flight requests won't be affected.
132
- * @returns void
133
- */
134
- setAuthProvider(authProvider: SquidAuthProvider): void;
135
- /**
136
- * Returns a reference to the collection in the provided integration.
137
- *
138
- * If the integrationId is not provided, the `built_in_db` integration id will be used.
139
- *
140
- * For more information on the CollectionReference object, please refer to the
141
- * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/collection-reference documentation}.
142
- *
143
- * @param collectionName The name of the collection.
144
- * @param integrationId The id of the integration, default to `built_in_db`.
145
- * @returns A reference to the collection in the provided integration.
146
- * @typeParam T The type of the documents in the collection.
147
- */
148
- collection: <T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId) => CollectionReference<T>;
149
- /**
150
- * Runs the given callback as an atomic change. All the mutations that are executed using the provided transactionId
151
- * will be atomic. Note that mutations for different integrations will not be atomic.
152
- *
153
- * For more information about transactions in Squid, please refer to the
154
- * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/transactions documentation}.
155
- *
156
- * @param fn The callback to run as an atomic change. The function receives a transactionId that should be used for
157
- * all the mutations that should be atomic. The function should return a promise.
158
- *
159
- * @returns A promise that resolves when the transactions are committed on the server.
160
- */
161
- runInTransaction: <T = any>(fn: (transactionId: TransactionId) => Promise<T>) => Promise<T>;
162
- /**
163
- * Executes the given backend function with the given parameters and returns a promise with the result.
164
- *
165
- * For more information about backend functions in Squid, please refer to the
166
- * {@link https://docs.squid.cloud/docs/development-tools/backend/executables documentation}.
167
- *
168
- * @param functionName The name of the function to execute on the server.
169
- * @param params The parameters to pass to the function.
170
- * @returns A promise that resolves with the result of the function.
171
- * @typeParam T The type of the result of the function.
172
- */
173
- executeFunction: <T = any>(functionName: string, ...params: any[]) => Promise<T>;
174
- /**
175
- * Executes the given named query with the given parameters and returns a promise with the result.
176
- *
177
- * For more information about named queries in Squid, please refer to the
178
- * {@link https://docs.squid.cloud/docs/development-tools/backend/named-queries documentation}.
179
- *
180
- * @param integrationId The id of the integration that the named query is defined with.
181
- * @param queryName The name of the named query.
182
- * @param params The parameters to pass to the named query.
183
- * @returns A promise that resolves with the result of the named query.
184
- * @typeParam T The type of the result of the named query.
185
- */
186
- executeNamedQuery: <T = any>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>) => Promise<T[]>;
187
- /**
188
- * Executes a native relational query with the given parameters and returns a promise with the result.
189
- *
190
- * Native queries allow you to execute raw SQL or other database-specific queries directly against the database.
191
- * This can be useful when you need to perform operations that are not easily accomplished with named queries or
192
- * other high-level abstractions.
193
- *
194
- * @param integrationId The id of the integration that the query is associated with.
195
- * @param query The raw SQL or other database-specific query to execute.
196
- * @param params (Optional) The parameters to pass to the query. Defaults to an empty object.
197
- * @returns A promise that resolves with the result of the query.
198
- * @type {Promise<Array<SquidDocument>>}
199
- */
200
- executeNativeRelationalQuery: <T = any>(integrationId: IntegrationId, query: string, params?: Record<string, any>) => Promise<T[]>;
201
- /**
202
- * Executes a native MongoDB aggregation pipeline with the given parameters and returns a promise with the result.
203
- *
204
- * Native queries allow you to execute raw MongoDB queries directly against the database.
205
- * This can be particularly useful when you need to perform complex operations or aggregations that are not
206
- * easily accomplished with standard query methods or other high-level abstractions provided by the database driver
207
- * or ORM.
208
- *
209
- * @param {IntegrationId} integrationId - The id of the integration that the query is associated with.
210
- * @param {string} collectionName - The name of the MongoDB collection to run the aggregation pipeline against.
211
- * @param {Array<Record<string, any>>} [aggregationPipeline=[]] - The array of aggregation stages to be executed.
212
- * Each stage in the pipeline is an object specifying the operation to be performed.
213
- * @returns {Promise<Array<T>>} A promise that resolves with an array of documents resulting from the aggregation
214
- * pipeline. Each document in the array is of the generic type T, which can be specified when calling the function.
215
- * @template T - The type of the documents that are expected to be returned by the aggregation pipeline. If not
216
- * specified, any type is assumed by default.
217
- * @type {Promise<Array<SquidDocument>>}
218
- */
219
- executeNativeMongoQuery: <T = any>(integrationId: IntegrationId, collectionName: string, aggregationPipeline?: Array<Record<string, any>>) => Promise<T[]>;
220
- /**
221
- * Invokes the given HTTP API (defined by the integration ID and the endpoint ID) with the given request parameters
222
- * and returns a promise with the response. The structure of the request and the response is defined in the
223
- * integration's schema page.
224
- *
225
- * For more information about API integrations in Squid, please refer to the
226
- * {@link https://docs.squid.cloud/docs/integrations/api/httpapi documentation}.
227
- *
228
- * @param integrationId The id of the integration that the API is defined with.
229
- * @param endpointId The id of the endpoint in the API integration.
230
- * @param request The request parameters to pass to the API.
231
- * @returns A promise that resolves with the response of the API.
232
- * @typeParam T The type of the response of the API.
233
- */
234
- callApi: <T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>) => Promise<T>;
235
- /**
236
- * Returns a GraphQL client for the given integration. The GraphQL client can be used to execute GraphQL queries and
237
- * mutations. For more information about GraphQL in Squid, please refer to the
238
- * {@link https://docs.squid.cloud/docs/integrations/api/graphql documentation}.
239
- *
240
- * @param integrationId The id of the integration that the GraphQL API is defined with.
241
- * @returns A GraphQL client for the given integration.
242
- */
243
- graphql: (integrationId: IntegrationId) => GraphQLClient;
244
- /**
245
- * Returns a set of AI specific clients.
246
- *
247
- * @returns A set of AI specific clients.
248
- */
249
- ai: () => AiClient;
250
- get secrets(): SecretClient;
251
- /**
252
- * Returns a distributed lock for the given mutex. The lock can be used to synchronize access to a shared resource.
253
- * The lock will be released when the release method on the returned object is invoked or whenever the connection
254
- * with the server is lost.
255
- * @param mutex A string that uniquely identifies the lock.
256
- * @returns A promise that resolves with the lock object. The promise will reject if failed to acquire the lock.
257
- */
258
- acquireLock: (mutex: string) => Promise<DistributedLock>;
259
- /**
260
- * Destructs the Squid Client. Unsubscribes from all ongoing queries or requests, and clears the local data.
261
- * After invoking this method, the Squid client will not be usable.
262
- *
263
- * @returns A promise that resolves when the destruct process is complete.
264
- */
265
- destruct: () => Promise<void>;
266
- /** Provides information about the connection to the Squid Server. */
267
- connectionDetails: () => ConnectionDetails;
268
- private validateNotDestructed;
269
- }
1
+ import { ApiEndpointId, ApiKey, AppId, CollectionName, DocumentData, EnvironmentId, IntegrationId, SquidDeveloperId, SupportedSquidRegion } from '@squidcloud/common';
2
+ import { CollectionReference } from './collection-reference';
3
+ import { ConnectionDetails } from './connection-details';
4
+ import { DistributedLock } from './distributed-lock.manager';
5
+ import { GraphQLClient } from './graphql-client';
6
+ import { SecretClient } from './secret.client';
7
+ import { TransactionId } from './types';
8
+ import { AiClient } from './ai.types';
9
+ /** The different options that can be used to initialize a Squid instance. */
10
+ export interface SquidOptions {
11
+ /**
12
+ * A function that can be used to wrap messages coming from Squid to the application. This is useful for
13
+ * different frameworks that need to wrap messages in order to detect changes (like Angular).
14
+ * @param fn The function to wrap.
15
+ */
16
+ messageNotificationWrapper?: (fn: () => any) => any;
17
+ /**
18
+ * The application ID that is used to identify the application in Squid. The ID can be found in the Squid Cloud
19
+ * Console.
20
+ */
21
+ appId: AppId;
22
+ /**
23
+ * The application API key, using the API key can be used to bypass security rules and other restrictions.
24
+ * The API key can be found in the Squid Cloud Console.
25
+ */
26
+ apiKey?: ApiKey;
27
+ /**
28
+ * Access token provider for the Squid instance.
29
+ * Used for managing the process of verifying the identity and authorization of users who attempt to access this
30
+ * application via the current Squid instance.
31
+ *
32
+ * When the authProvider is set, the Squid service will fetch a token and include it with every request to the Squid
33
+ * backend.
34
+ *
35
+ * On the backend, Squid will validate the access token.
36
+ */
37
+ authProvider?: SquidAuthProvider;
38
+ /**
39
+ * The region that the application is running in. This is used to determine the URL of the Squid Cloud API.
40
+ */
41
+ region: SupportedSquidRegion;
42
+ /**
43
+ * The environment ID to work with, if not specified the default environment (prod) will be used.
44
+ */
45
+ environmentId?: EnvironmentId;
46
+ /**
47
+ * The user ID of the developer that runs the environment locally.
48
+ */
49
+ squidDeveloperId?: SquidDeveloperId;
50
+ /**
51
+ * A list of API endpoints that can be used for overriding the default API endpoints for the different integrations.
52
+ * This is useful for APIs that have multiple base urls hosted in different regions.
53
+ */
54
+ apiServerUrlOverrideMapping?: Record<IntegrationId, string>;
55
+ }
56
+ /** Authentication data provider for Squid requests. */
57
+ export interface SquidAuthProvider {
58
+ /**
59
+ * Returns a valid AccessToken.
60
+ * Called by Squid every time a Squid client makes requests to the Squid backend.
61
+ */
62
+ getToken(): Promise<string | undefined>;
63
+ /**
64
+ * Optional Auth integration id.
65
+ * Sent as a part of all Squid requests to the backend.
66
+ */
67
+ integrationId?: string;
68
+ }
69
+ /**
70
+ * The main entry point to the Squid Client SDK.
71
+ *
72
+ * The Squid class provides a comprehensive array of functionality for accessing the different integrations, executing
73
+ * backend functions, managing data, and more. Upon instantiating the Squid class, you will have access to all of these
74
+ * capabilities.
75
+ * All public Squid functions are bound to `this` and can be used with a destructuring patterns,
76
+ * like `const {setAuthProvider} = useSquid()`
77
+ */
78
+ export declare class Squid {
79
+ readonly options: SquidOptions;
80
+ private readonly socketManager;
81
+ private readonly rpcManager;
82
+ private readonly dataManager;
83
+ private readonly documentReferenceFactory;
84
+ private readonly documentStore;
85
+ private readonly lockManager;
86
+ private readonly querySubscriptionManager;
87
+ private readonly localQueryManager;
88
+ private readonly queryBuilderFactory;
89
+ private readonly collectionReferenceFactory;
90
+ private readonly backendFunctionManager;
91
+ private readonly nativeQueryManager;
92
+ private readonly apiManager;
93
+ private readonly graphqlClientFactory;
94
+ private readonly destructManager;
95
+ private readonly documentIdentityService;
96
+ private readonly distributedLockManager;
97
+ private readonly authManager;
98
+ private readonly clientIdService;
99
+ private readonly aiClientFactory;
100
+ private readonly _connectionDetails;
101
+ private readonly secretClient;
102
+ private readonly querySender;
103
+ private static readonly squidInstancesMap;
104
+ private readonly aiClient;
105
+ /**
106
+ * Creates a new instance of Squid with the given options.
107
+ *
108
+ * @param options The options for initializing the Squid instance.
109
+ */
110
+ constructor(options: SquidOptions);
111
+ /**
112
+ * Returns the global Squid instance with the given options, creating a new instance if one with the same options
113
+ * does not exist.
114
+ *
115
+ * @param options The options for initializing the Squid instance.
116
+ * @returns A global Squid instance with the given options.
117
+ */
118
+ static getInstance(options: SquidOptions): Squid;
119
+ /**
120
+ * Returns all the global Squid instances.
121
+ *
122
+ * @returns An array of all the global Squid instances.
123
+ */
124
+ static getInstances(): Array<Squid>;
125
+ /**
126
+ * Sets the authorization access token (OAuth2.0) provider that will be sent to the server and will be used for
127
+ * providing the `auth` object to the security rules.
128
+ *
129
+ * @param authProvider The OAuth2.0 access token provider invoked for every backend request by Squid.
130
+ * When the provider returns undefined, no authorization information is sent.
131
+ * When a new provider is set, all future Squid backend requests will use the new token provider, and exising
132
+ * in-flight requests won't be affected.
133
+ * @returns void.
134
+ */
135
+ setAuthProvider(authProvider: SquidAuthProvider): void;
136
+ /**
137
+ * Returns a reference to the collection in the provided integration.
138
+ *
139
+ * If the integrationId is not provided, the `built_in_db` integration id will be used.
140
+ *
141
+ * For more information on the CollectionReference object, please refer to the
142
+ * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/collection-reference documentation}.
143
+ *
144
+ * @param collectionName The name of the collection.
145
+ * @param integrationId The id of the integration, default to `built_in_db`.
146
+ * @returns A reference to the collection in the provided integration.
147
+ * @typeParam T The type of the documents in the collection.
148
+ */
149
+ collection<T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId): CollectionReference<T>;
150
+ /**
151
+ * Runs the given callback as an atomic change. All the mutations that are executed using the provided transactionId
152
+ * will be atomic. Note that mutations for different integrations will not be atomic.
153
+ *
154
+ * For more information about transactions in Squid, please refer to the
155
+ * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/transactions documentation}.
156
+ *
157
+ * @param fn The callback to run as an atomic change. The function receives a transactionId that should be used for
158
+ * all the mutations that should be atomic. The function should return a promise.
159
+ *
160
+ * @returns A promise that resolves when the transactions are committed on the server.
161
+ */
162
+ runInTransaction<T = any>(fn: (transactionId: TransactionId) => Promise<T>): Promise<T>;
163
+ /**
164
+ * Executes the given backend function with the given parameters and returns a promise with the result.
165
+ *
166
+ * For more information about backend functions in Squid, please refer to the
167
+ * {@link https://docs.squid.cloud/docs/development-tools/backend/executables documentation}.
168
+ *
169
+ * @param functionName The name of the function to execute on the server.
170
+ * @param params The parameters to pass to the function.
171
+ * @returns A promise that resolves with the result of the function.
172
+ * @typeParam T The type of the result of the function.
173
+ */
174
+ executeFunction<T = any>(functionName: string, ...params: any[]): Promise<T>;
175
+ /**
176
+ * Executes a native relational query with the given parameters and returns a promise with the result.
177
+ *
178
+ * Native queries allow you to execute raw SQL or other database-specific queries directly against the database.
179
+ * This can be useful when you need to perform operations that are not easily accomplished with other high-level
180
+ * abstractions.
181
+ *
182
+ * @param integrationId The id of the integration that the query is associated with.
183
+ * @param query The raw SQL or other database-specific query to execute.
184
+ * @param params (Optional) The parameters to pass to the query. Defaults to an empty object.
185
+ * @returns A promise that resolves with the result of the query.
186
+ * @type {Promise<Array<SquidDocument>>}
187
+ */
188
+ executeNativeRelationalQuery<T = any>(integrationId: IntegrationId, query: string, params?: Record<string, any>): Promise<Array<T>>;
189
+ /**
190
+ * Invokes the given HTTP API (defined by the integration ID and the endpoint ID) with the given request parameters
191
+ * and returns a promise with the response. The structure of the request and the response is defined in the
192
+ * integration's schema page.
193
+ *
194
+ * For more information about API integrations in Squid, please refer to the
195
+ * {@link https://docs.squid.cloud/docs/integrations/api/httpapi documentation}.
196
+ *
197
+ * @param integrationId The id of the integration that the API is defined with.
198
+ * @param endpointId The id of the endpoint in the API integration.
199
+ * @param request The request parameters to pass to the API.
200
+ * @returns A promise that resolves with the response of the API.
201
+ * @typeParam T The type of the response of the API.
202
+ */
203
+ callApi<T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>): Promise<T>;
204
+ /**
205
+ * Returns a GraphQL client for the given integration. The GraphQL client can be used to execute GraphQL queries and
206
+ * mutations. For more information about GraphQL in Squid, please refer to the
207
+ * {@link https://docs.squid.cloud/docs/integrations/api/graphql documentation}.
208
+ *
209
+ * @param integrationId The id of the integration that the GraphQL API is defined with.
210
+ * @returns A GraphQL client for the given integration.
211
+ */
212
+ graphql(integrationId: IntegrationId): GraphQLClient;
213
+ /**
214
+ * Returns a set of AI specific clients.
215
+ *
216
+ * @returns A set of AI specific clients.
217
+ */
218
+ ai(): AiClient;
219
+ get secrets(): SecretClient;
220
+ /**
221
+ * Returns a distributed lock for the given mutex. The lock can be used to synchronize access to a shared resource.
222
+ * The lock will be released when the release method on the returned object is invoked or whenever the connection
223
+ * with the server is lost.
224
+ * @param mutex A string that uniquely identifies the lock.
225
+ * @returns A promise that resolves with the lock object. The promise will reject if failed to acquire the lock.
226
+ */
227
+ acquireLock(mutex: string): Promise<DistributedLock>;
228
+ /**
229
+ * Destructs the Squid Client. Unsubscribes from all ongoing queries or requests, and clears the local data.
230
+ * After invoking this method, the Squid client will not be usable.
231
+ *
232
+ * @returns A promise that resolves when the destruct process is complete.
233
+ */
234
+ destruct(): Promise<void>;
235
+ /** Provides information about the connection to the Squid Server. */
236
+ connectionDetails(): ConnectionDetails;
237
+ private _validateNotDestructed;
238
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1 +1 @@
1
- declare const nodeCrypto: any;
1
+ export {};
@@ -1,2 +1,2 @@
1
- /** A transactionId - alias for string */
2
- export type TransactionId = string;
1
+ /** A transactionId - alias for string */
2
+ export type TransactionId = string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.147",
3
+ "version": "1.0.149",
4
4
  "description": "A typescript implementation of the Squid client",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/typescript-client/src/index.d.ts",
@@ -13,6 +13,7 @@
13
13
  "build:dev": "webpack --mode=development",
14
14
  "build:prod": "webpack --mode=production",
15
15
  "watch": "webpack --watch",
16
+ "lint": "eslint . --ext .ts",
16
17
  "test": "jest --detectOpenHandles",
17
18
  "test:watch": "jest --watch",
18
19
  "test:cov": "jest --coverage",
@@ -32,7 +33,7 @@
32
33
  "license": "ISC",
33
34
  "dependencies": {
34
35
  "@apollo/client": "^3.7.4",
35
- "@squidcloud/common": "1.0.147",
36
+ "@squidcloud/common": "1.0.149",
36
37
  "@supercharge/promise-pool": "^2.3.2",
37
38
  "axios": "^1.6.2",
38
39
  "cross-fetch": "^3.1.5",
@@ -1,4 +0,0 @@
1
- /** The context provided to the secure named query function. */
2
- export declare class NamedQueryContext {
3
- readonly params: Record<string, any>;
4
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- import { IntegrationId, QueryName } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { RpcManager } from './rpc.manager';
4
- import { SocketManager } from './socket.manager';
5
- export declare class NamedQueryManager {
6
- private readonly rpcManager;
7
- private readonly ongoingNamedQueryExecutions;
8
- constructor(rpcManager: RpcManager, socketManager: SocketManager);
9
- executeNamedQueryAndSubscribe<T>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>): Observable<Array<T>>;
10
- private handleNamedQueryResponse;
11
- }