@squidcloud/client
    Preparing search index...

    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()

    Index

    Constructors

    • Creates a new instance of Squid with the given options.

      Parameters

      • options: SquidOptions

        The options for initializing the Squid instance.

      Returns Squid

    Properties

    options: SquidOptions

    The options for initializing the Squid instance.

    Accessors

    • get appId(): string

      Returns the application ID of the current Squid instance.

      Returns string

    Methods

    • 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

      • 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.

    • Returns the AdminClient instance for performing administrative operations.

      Returns AdminClient

    • Returns a set of AI specific clients.

      Returns AiClient

      A set of AI specific clients.

    • Returns a set of functionality for interacting with API integrations.

      Returns ApiClient

    • 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

      • T extends DocumentData

        The type of the documents in the collection.

      Parameters

      • collectionName: string

        The name of the collection.

      • integrationId: string = BUILT_IN_DB_INTEGRATION_ID

        The id of the integration, default to built_in_db.

      Returns CollectionReference<T>

      A reference to the collection in the provided integration.

    • 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.

    • Executes a backend function identified by its name, passing the provided parameters, and returns a promise with the result.

      For detailed information on backend functions in Squid, see the documentation.

      Files support:

      • To send a file to the backend, simply include it as one of the parameters; it will be received as a SquidFile on the backend.
      • Arrays of files can also be passed directly as parameters.

      Type Parameters

      • T = any

        The expected type of the result returned by the backend function.

      Parameters

      • functionName: string

        The name of the backend function to execute.

      • ...params: any[]

        A list of parameters to pass to the backend function.

      Returns Promise<T>

      A promise that resolves to the result of the backend function.

    • 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/client-sdk/database/native-queries#native-mongodb-queries.

      Type Parameters

      • T = any

      Parameters

      • 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.

    • Executes a native relational query with the given parameters and returns a promise with the result. See https://docs.getsquid.ai/docs/client-sdk/database/native-queries.

      Type Parameters

      • T = any

      Parameters

      • 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.

    • Returns a client for accessing personal (user-specific) file storage.

      Parameters

      • integrationId: string

        The storage integration ID to use.

      Returns PersonalStorageClient

    • Returns a queue manager for the given topic name and integration id. Using the queue manager you can consume and produce messages

      Type Parameters

      • T

      Parameters

      • topicName: string
      • integrationId: string = BUILT_IN_QUEUE_INTEGRATION_ID

      Returns QueueManager<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

      • T = any

      Parameters

      • 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.

    • 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

      • 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.

    • Returns a client for accessing file storage for the current app. Defaults to the built-in storage integration if none is provided.

      Parameters

      • integrationId: string = 'built_in_storage'

        The storage integration ID (default is 'built_in_storage').

      Returns StorageClient

    • Returns a set of functionality for interacting with the web.

      Returns WebClient

    • Executes the given callback while holding a lock for the given mutex. The lock will be released when the callback finishes.

      Type Parameters

      • T

      Parameters

      • 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.

    • Returns the global Squid instance with the given options, creating a new instance if one with the same options does not exist.

      Parameters

      • options: SquidOptions

        The options for initializing the Squid instance.

      Returns Squid

      A global Squid instance with the given options.

    • Returns all the global Squid instances.

      Returns Squid[]

      An array of all the global Squid instances.