Class: Squid
The main entry point to the Squid Client SDK.
The Squid class provides a comprehensive array of functionality for accessing the different integrations, executing
backend functions, managing data, and more. Upon instantiating the Squid class, you will have access to all of these
capabilities.
All public Squid functions are bound to this
and can be used with a destructuring patterns,
like const {setAuthProvider} = useSquid()
Constructors
constructor
• new Squid(options
)
Creates a new instance of Squid with the given options.
Parameters
Name | Type | Description |
---|---|---|
options | SquidOptions | The options for initializing the Squid instance. |
Properties
options
• Readonly
options: SquidOptions
The options for initializing the Squid instance.
Accessors
observability
• get
observability(): ObservabilityClient
Returns
schedulers
• get
schedulers(): SchedulerClient
Returns
secrets
• get
secrets(): SecretClient
Returns
Methods
acquireLock
▸ acquireLock(mutex
): Promise
<DistributedLock
>
Returns a distributed lock for the given mutex. The lock can be used to synchronize access to a shared resource. The lock will be released when the release method on the returned object is invoked or whenever the connection with the server is lost.
Parameters
Name | Type | Description |
---|---|---|
mutex | string | A string that uniquely identifies the lock. |
Returns
Promise
<DistributedLock
>
A promise that resolves with the lock object. The promise will reject if failed to acquire the lock.
ai
▸ ai(): AiClient
Returns a set of AI specific clients.
Returns
A set of AI specific clients.
api
▸ api(): ApiClient
Returns
collection
▸ collection<T
>(collectionName
, integrationId?
): CollectionReference
<T
>
Returns a reference to the collection in the provided integration.
If the integrationId is not provided, the built_in_db
integration id will be used.
For more information on the CollectionReference object, please refer to the documentation.
Type parameters
Name | Type | Description |
---|---|---|
T | extends DocumentData | The type of the documents in the collection. |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
collectionName | string | undefined | The name of the collection. |
integrationId | string | IntegrationType.built_in_db | The id of the integration, default to built_in_db . |
Returns
A reference to the collection in the provided integration.
connectionDetails
▸ connectionDetails(): ConnectionDetails
Provides information about the connection to the Squid Server.
Returns
destruct
▸ destruct(): Promise
<void
>
Destructs the Squid Client. Unsubscribes from all ongoing queries or requests, and clears the local data. After invoking this method, the Squid client will not be usable.
Returns
Promise
<void
>
A promise that resolves when the destruct process is complete.
executeFunction
▸ executeFunction<T
>(functionName
, ...params
): Promise
<T
>
Executes the given backend function with the given parameters and returns a promise with the result.
For more information about backend functions in Squid, please refer to the documentation.
Type parameters
Name | Type | Description |
---|---|---|
T | any | The type of the result of the function. |
Parameters
Name | Type | Description |
---|---|---|
functionName | string | The name of the function to execute on the server. |
...params | any [] | The parameters to pass to the function. |
Returns
Promise
<T
>
A promise that resolves with the result of the function.
executeNativeMongoQuery
▸ executeNativeMongoQuery<T
>(integrationId
, collectionName
, aggregationPipeline
): Promise
<T
[]>
Executes a native Mongo/built-in-db query with the given pipeline and returns a promise with the result. See https://docs.getsquid.ai/docs/database/native-queries#native-mongodb-queries.
Type parameters
Name | Type |
---|---|
T | any |
Parameters
Name | Type | Description |
---|---|---|
integrationId | string | The id of the integration that the query is associated with. |
collectionName | string | The collection to query. |
aggregationPipeline | any [] | The aggregation pipeline for the query. |
Returns
Promise
<T
[]>
A promise that resolves with the result of the query.
executeNativeRelationalQuery
▸ executeNativeRelationalQuery<T
>(integrationId
, query
, params?
): Promise
<T
[]>
Executes a native relational query with the given parameters and returns a promise with the result. See https://docs.getsquid.ai/docs/database/native-queries.
Type parameters
Name | Type |
---|---|
T | any |
Parameters
Name | Type | Description |
---|---|---|
integrationId | string | The id of the integration that the query is associated with. |
query | string | The raw SQL or other database-specific query to execute. |
params | Record <string , any > | (Optional) The parameters to pass to the query. Defaults to an empty object. |
Returns
Promise
<T
[]>
A promise that resolves with the result of the query.
extraction
▸ extraction(): ExtractionClient
Returns
internal
▸ internal(): SquidInternalForGraphQl
An interface provided by Squid to @squidcloud/* packages but not exposed to users. @internal.
Returns
SquidInternalForGraphQl
personalStorage
▸ personalStorage(integrationId
): PersonalStorageClient
Parameters
Name | Type |
---|---|
integrationId | string |
Returns
queue
▸ queue<T
>(topicName
, integrationId?
): QueueManager
<T
>
Returns a queue manager for the given topic name and integration id. Using the queue manager you can consume and produce messages
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value |
---|---|---|
topicName | string | undefined |
integrationId | string | IntegrationType.built_in_queue |
Returns
QueueManager
<T
>
runInTransaction
▸ runInTransaction<T
>(fn
): Promise
<T
>
Runs the given callback as an atomic change. All the mutations that are executed using the provided transactionId will be atomic. Note that mutations for different integrations will not be atomic.
For more information about transactions in Squid, please refer to the documentation.
Type parameters
Name | Type |
---|---|
T | any |
Parameters
Name | Type | Description |
---|---|---|
fn | (transactionId : string ) => Promise <T > | The callback to run as an atomic change. The function receives a transactionId that should be used for all the mutations that should be atomic. The function should return a promise. |
Returns
Promise
<T
>
A promise that resolves when the transactions are committed on the server.
setAuthProvider
▸ setAuthProvider(authProvider
): void
Sets the authorization access token (OAuth2.0) provider that will be sent to the server and will be used for
providing the auth
object to the security rules.
Parameters
Name | Type | Description |
---|---|---|
authProvider | SquidAuthProvider | The OAuth2.0 access token provider invoked for every backend request by Squid. When the provider returns undefined, no authorization information is sent. When a new provider is set, all future Squid backend requests will use the new token provider, and exising in-flight requests won't be affected. |
Returns
void
void.
storage
▸ storage(integrationId?
): StorageClient
Parameters
Name | Type | Default value |
---|---|---|
integrationId | string | 'built_in_storage' |
Returns
withLock
▸ withLock<T
>(mutex
, fn
): Promise
<T
>
Executes the given callback while holding a lock for the given mutex. The lock will be released when the callback finishes.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
mutex | string | A string that uniquely identifies the lock. |
fn | (lock : DistributedLock ) => Promise <T > | The callback to execute while holding the lock. |
Returns
Promise
<T
>
A promise that resolves with the result of the callback. The promise will reject if failed to acquire the lock.
getInstance
▸ Static
getInstance(options
): Squid
Returns the global Squid instance with the given options, creating a new instance if one with the same options does not exist.
Parameters
Name | Type | Description |
---|---|---|
options | SquidOptions | The options for initializing the Squid instance. |
Returns
A global Squid instance with the given options.
getInstances
▸ Static
getInstances(): Squid
[]
Returns all the global Squid instances.
Returns
Squid
[]
An array of all the global Squid instances.