Skip to main content

@squidcloud/backend

Classes

Interfaces

Type Aliases

ActionMethodDecorator

Ƭ ActionMethodDecorator<U>: <T>(target: Object, propertyName: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>

Type parameters

Name
U

Type declaration

▸ <T>(target, propertyName, descriptor): TypedPropertyDescriptor<T>

Type parameters
NameType
Textends U
Parameters
NameType
targetObject
propertyNamestring
descriptorTypedPropertyDescriptor<T>
Returns

TypedPropertyDescriptor<T>


AiFunctionAction

Ƭ AiFunctionAction<T>: (params: T) => any

Type parameters

NameType
Textends Record<string, any> = any

Type declaration

▸ (params): any

Parameters
NameType
paramsT
Returns

any


ApiHeaders

Ƭ ApiHeaders: Record<string, string | number | boolean>

The headers of an API call.


ClientConnectionStateChangeAction

Ƭ ClientConnectionStateChangeAction: (clientId: ClientId, clientConnectionState: ClientConnectionState) => Promise<void> | void

Type declaration

▸ (clientId, clientConnectionState): Promise<void> | void

Parameters
NameType
clientIdClientId
clientConnectionStateClientConnectionState
Returns

Promise<void> | void


ContextCondition

Ƭ ContextCondition<Doc, F>: InContextCondition<Doc, F> | NotInContextCondition<Doc, F> | OtherContextCondition<Doc, F>

A Context condition - a condition that replaces multiple '==' or '!=' conditions with 'in' and 'not in'.

Type parameters

NameType
Docextends DocumentData = any
Fextends Paths<Doc> = Paths<Doc>

ContextConditions

Ƭ ContextConditions<Doc, F>: ContextCondition<Doc, F>[]

A list of context conditions

Type parameters

NameType
Docextends DocumentData = any
Fextends Paths<Doc> = Paths<Doc>

ContextOperator

Ƭ ContextOperator: Exclude<Operator, "==" | "!="> | "in" | "not in"


ExecutableAction

Ƭ ExecutableAction: (...args: any[]) => any

Type declaration

▸ (...args): any

Parameters
NameType
...argsany[]
Returns

any


GeneralConditions

Ƭ GeneralConditions<Doc, F>: GeneralCondition<Doc, F>[]

A list of general conditions.

Type parameters

NameType
Docextends DocumentData = any
Fextends Paths<Doc> = Paths<Doc>

GenericValue

Ƭ GenericValue<Doc, F, O>: O extends "in" ? DeepRecord<Doc>[F][] | null : O extends "not in" ? DeepRecord<Doc>[F][] | null : DeepRecord<Doc>[F] | null

A generic value that can exist in a query.

Type parameters

NameType
Docany
Fextends Paths<Doc> = Paths<Doc>
Oextends AllOperators = any

LimitedAction

Ƭ LimitedAction: () => any | Promise<any>

Type declaration

▸ (): any | Promise<any>

Returns

any | Promise<any>


LimiterConfig

Ƭ LimiterConfig: Object

Type declaration

NameType
quotaLimit?number | QuotaLimitOptions | QuotaLimitOptions[]
rateLimit?number | RateLimitOptions | RateLimitOptions[]

LimiterScope

Ƭ LimiterScope: "ip" | "user" | "global"


NativeQueryContext

Ƭ NativeQueryContext: RelationalNativeQueryContext | MongoNativeQueryContext


NativeQueryRequestType

Ƭ NativeQueryRequestType: "relational" | "mongo"


QuotaRenewPeriod

Ƭ QuotaRenewPeriod: "hourly" | "daily" | "weekly" | "monthly" | "quarterly" | "annually"


SchedulerAction

Ƭ SchedulerAction: () => void | Promise<void>

Type declaration

▸ (): void | Promise<void>

Returns

void | Promise<void>


SecureAiChatbotAction

Ƭ SecureAiChatbotAction<T>: T extends "all" ? () => boolean | Promise<boolean> : T extends "chat" ? (context: AiChatbotChatContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean> : (context: AiChatbotMutationContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean>

Type parameters

NameType
Textends AiChatbotActionType

SecureApiAction

Ƭ SecureApiAction: (context: ApiCallContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean>


SecureDatabaseAction

Ƭ SecureDatabaseAction<T>: T extends "all" ? () => boolean | Promise<boolean> : T extends "read" ? (context: QueryContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean> : (context: MutationContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean>

Type parameters

NameType
Textends DatabaseActionType

SecureDistributedLockAction

Ƭ SecureDistributedLockAction: (context: DistributedLockContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean>


SecureGraphQLAction

Ƭ SecureGraphQLAction: (context: GraphqlContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean>


SecureNativeQueryAction

Ƭ SecureNativeQueryAction: (context: NativeQueryContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean>


SecureStorageAction

Ƭ SecureStorageAction<T>: T extends "all" ? () => boolean | Promise<boolean> : (context: StorageContext) => boolean | Promise<boolean>

Type parameters

NameType
Textends StorageActionType

SecureTopicAction

Ƭ SecureTopicAction<T>: T extends "all" ? () => boolean | Promise<boolean> : T extends "read" ? (context: TopicReadContext) => boolean | Promise<boolean> | () => boolean | Promise<boolean> : (context: TopicWriteContext<T>) => boolean | Promise<boolean> | () => boolean | Promise<boolean>

Type parameters

NameType
Textends TopicActionType

TriggerAction

Ƭ TriggerAction: (request: TriggerRequest) => void | Promise<void> | () => void | Promise<void>


WebhookAction

Ƭ WebhookAction: (request: WebhookRequest) => any | () => any

Functions

aiFunction

aiFunction<ParamType>(description, params): ActionMethodDecorator<AiFunctionAction<ParamType>>

Decorator that marks a function for exposing it to the AI assistant. The function accepts a JSON object as described in the description of the function in the annotation.

TODO - add docs To read more about exposing an executable, see the documentation.

Type parameters

NameType
ParamTypeextends Record<string, any> = any

Parameters

NameType
descriptionstring
paramsAiFunctionParam[]

Returns

ActionMethodDecorator<AiFunctionAction<ParamType>>


clientConnectionStateHandler

clientConnectionStateHandler(): ActionMethodDecorator<ClientConnectionStateChangeAction>

Decorator that marks a function for handling a client connection state change

Returns

ActionMethodDecorator<ClientConnectionStateChangeAction>


executable

executable(): ActionMethodDecorator<ExecutableAction>

Decorator that marks a function for exposing it as an executable. The function can accept any parameter that can be serialized to JSON and return any parameter that can be serialized to JSON.

Once the function is exposed, it can be called from the Squid Cloud SDK using the executeFunction method. To read more about exposing an executable, see the documentation.

Returns

ActionMethodDecorator<ExecutableAction>


limiterConfigToOptions

limiterConfigToOptions(config): LimiterOptions

Convert LimiterConfig to LimiterOptions.

This decouples the required syntax for the developer from the internal implementation.

Parameters

NameTypeDescription
configLimiterConfigLimiterConfig to convert.

Returns

LimiterOptions


limits

limits(options): ActionMethodDecorator<LimitedAction>

A decorator that can be used to rate/quota limit a function. In its simplest form, the decorator can take the query rate that is allowed for the given function and/or how many total calls are permitted and will enforce those limits.

It will either execute the function or return an Error if the rate/quota limits are exceeded.

Rate Limit behavior:

  • The rate limit unit is QPS (Queries Per Second).
  • Bursts of up to 3x the given rate are permitted.
  • The consumption bucket refills gradually.

Quota Limit behavior:

  • Has a renewPeriod field that defaults to "monthly".
  • The "monthly" period is defined as 30 days.
  • The "quarterly" period is defined as 90 days.
  • Renews occur at the top of the hour (##:00 for HH:mm).
  • No carry-over of unused quota from one period to the next.
  • Changes to the limit value for a specific limit combo (function & scope & renewPeriod) will reset the active count. For example, if a user has made 10 calls and the limit is changed from 20 to 15, the user will be able to make 15 more calls (not 5).

Limits can be defined with more specifics and multiple limits can be defined for a single function.

Examples:

  • Basic definition using defaults:
    @limits({ rateLimit: 5 }) // Only rate limit.
    @limits({ quotaLimit: 20 }) // Only quota limit.
    @limits({ rateLimit: 5, quotaLimit: 20 }) // Both rate and quota.
    Defaults to "global" scope and "monthly" renewPeriod.
  • As objects defining scope and renewPeriod:
    @limits({
    rateLimit: {
    value: 5,
    scope: 'global'
    },
    quotaLimit: {
    value: 20,
    scope: 'global',
    renewPeriod: 'monthly'
    }
    })
  • As arrays of objects defining scope and renewPeriod
    @limits({
    rateLimit: [
    { value: 5, scope: 'global' },
    { value: 2, scope: 'user' }
    ],
    quotaLimit: [
    { value: 20, scope: 'global', renewPeriod: 'monthly' },
    { value: 5000, scope: 'ip', renewPeriod: 'annually' }
    ]
    })

All matching limits are consumed for each call. For example, an "IP" scoped limit will be consumed in addition to a "global" scoped limit.

Parameters

NameTypeDescription
optionsLimiterConfigLimiterConfig object specifying what kind of limits are desired.

Returns

ActionMethodDecorator<LimitedAction>


scheduler

scheduler(id, cronExpression, exclusive?): ActionMethodDecorator<SchedulerAction>

Decorator that marks a function as a scheduler. The function will be called according to the provided cron expression.

To read more about schedulers, see the documentation.

Parameters

NameTypeDescription
idstringThe ID of the scheduler. Should be unique.
cronExpression`${string} ${string} ${string} ${string} ${string}` | `${string} ${string} ${string} ${string}`The cron expression (in UTC) to schedule the function on.
exclusive?booleanWhether the scheduler should be exclusive. If set to true, the scheduler will not trigger if the previous scheduler is still running. Default: true.

Returns

ActionMethodDecorator<SchedulerAction>

scheduler(options): ActionMethodDecorator<SchedulerAction>

Decorator that marks a function as a scheduler. The function will be called according to the provided cron expression.

To read more about schedulers, see the documentation.

Parameters

NameType
optionsSchedulerOptions

Returns

ActionMethodDecorator<SchedulerAction>


secureAiChatbot

secureAiChatbot<T>(integrationId, type, profileId?): ActionMethodDecorator<SecureAiChatbotAction<T>>

A decorator that can be used to secure an AI chatbot. The decorator takes the AI Chatbot integration ID, the action type (chat or mutate), and an optional profile ID. If no profile ID is provided, the function will secure all requests to the integration (for the given action type).

The function should return a boolean or a Promise of a boolean indicating whether the action is allowed. The function takes a context object as a parameter. The context object contains information about the action.

To read more about securing an AI chatbot, see the documentation.

Type parameters

NameType
Textends AiChatbotActionType

Parameters

NameTypeDescription
integrationIdstringThe ID of the integration to secure.
typeTThe type of action to secure.
profileId?stringThe ID of the profile to secure.

Returns

ActionMethodDecorator<SecureAiChatbotAction<T>>


secureApi

secureApi(integrationId, endpointId?): ActionMethodDecorator<SecureApiAction>

Decorator that marks a function for securing an API or an endpoint inside an API. The decorator takes the API integration ID, and an optional endpoint ID. If no endpoint ID is provided, the function will secure the whole API.

The function should return a boolean or a Promise of a boolean indicating whether the action is allowed. The function takes a context object as a parameter. The context object contains information about the action.

To read more about securing an API, see the documentation.

Parameters

NameTypeDescription
integrationIdstringThe ID of the integration to secure.
endpointId?stringThe ID of the endpoint to secure.

Returns

ActionMethodDecorator<SecureApiAction>


secureCollection

secureCollection<T>(collectionName, type, integrationId?): ActionMethodDecorator<SecureDatabaseAction<T>>

Decorator that marks a function for securing a collection inside a database. The decorator takes the collection, type of action, and an optional integration ID. If no integration ID is provided, the built_in_db integration is used.

The function should return a boolean or a Promise of a boolean indicating whether the action is allowed. In addition, depending on the action, the function can take a context object as a parameter. The context object contains information about the action.

To read more about securing a collection rules, see the documentation.

Type parameters

NameType
Textends DatabaseActionType

Parameters

NameTypeDescription
collectionNamestringThe name of the collection to secure.
typeTThe type of action to secure.
integrationId?stringThe ID of the integration to secure.

Returns

ActionMethodDecorator<SecureDatabaseAction<T>>


secureDatabase

secureDatabase<T>(type, integrationId?): ActionMethodDecorator<SecureDatabaseAction<T>>

Decorator that marks a function for securing a database. The decorator takes a type of action and an optional integration ID. If no integration ID is provided, the built_in_db integration is used.

The function should return a boolean or a Promise of a boolean indicating whether the action is allowed. In addition, depending on the action, the function can take a context object as a parameter. The context object contains information about the action.

To read more about securing a database, see the documentation.

Type parameters

NameType
Textends DatabaseActionType

Parameters

NameTypeDescription
typeTThe type of action to secure.
integrationId?stringThe ID of the integration to secure.

Returns

ActionMethodDecorator<SecureDatabaseAction<T>>


secureDistributedLock

secureDistributedLock(mutex?): ActionMethodDecorator<SecureDistributedLockAction>

A decorator that can be used to secure a distributed lock. Distributed locks are secured by default and can be invoked only if the decorated function allows it. The function returns a boolean or a Promise of a boolean that indicates whether the lock can be acquired or not.

The function accepts a context object as a parameter. The context object contains information about the mutex and the request.

Parameters

NameTypeDescription
mutex?stringThe mutex to lock on. If none provided, the rule will apply for all mutexes.

Returns

ActionMethodDecorator<SecureDistributedLockAction>


secureGraphQL

secureGraphQL(integrationId): ActionMethodDecorator<SecureGraphQLAction>

Decorator that marks a function for securing a GraphQL integration.

The function should return a boolean or a Promise of a boolean indicating whether the action is allowed. The function takes a context object as a parameter. The context object contains information about the action.

To read more about securing a GraphQL integration, see the documentation.

Parameters

NameType
integrationIdstring

Returns

ActionMethodDecorator<SecureGraphQLAction>


secureNativeQuery

secureNativeQuery(integrationId): ActionMethodDecorator<SecureNativeQueryAction>

A decorator that can be used to secure a native query. Native queries are not secured by default and must be explicitly secured using this decorator. The decorated function must return a boolean or a Promise of a boolean that indicates whether the query can be executed or not.

The function accepts a context object as a parameter. The context object contains information about the query.

To read more about securing a Native Query, see the documentation.

Parameters

NameTypeDescription
integrationIdstringThe database integration ID.

Returns

ActionMethodDecorator<SecureNativeQueryAction>

A decorator function that can be used to secure a native query.


secureStorage

secureStorage<T>(type, integrationId?): ActionMethodDecorator<SecureStorageAction<T>>

Type parameters

NameType
Textends StorageActionType

Parameters

NameType
typeT
integrationId?string

Returns

ActionMethodDecorator<SecureStorageAction<T>>


secureTopic

secureTopic<T>(topicName, type, integrationId?): ActionMethodDecorator<SecureTopicAction<T>>

Decorator that marks a function for securing a topic in a message queue. The decorator takes the topic name, type of action, and an optional integration ID. If no integration ID is provided, the built_in_queue integration is used.

The function should return a boolean or a Promise of a boolean indicating whether the action is allowed.

To read more about securing a topic, see the documentation.

Type parameters

NameType
Textends TopicActionType

Parameters

NameTypeDescription
topicNamestringThe name of the topic to secure.
typeTThe type of action to secure.
integrationId?stringThe ID of the integration to secure.

Returns

ActionMethodDecorator<SecureTopicAction<T>>


trigger

trigger(id, collectionName, integrationId?): ActionMethodDecorator<TriggerAction>

Decorator that marks a function as a trigger to a change in a collection. The function will be called each time a change is made to the collection. The function accepts a context object as a parameter. The context object contains information about the change.

To read more about triggers, see the documentation.

Parameters

NameTypeDescription
idstringThe ID of the trigger. Should be unique.
collectionNamestringThe name of the collection to trigger on.
integrationId?stringThe ID of the integration to trigger on. If not provided, the built_in_db integration is used.

Returns

ActionMethodDecorator<TriggerAction>

trigger(options): ActionMethodDecorator<TriggerAction>

Decorator that marks a function as a trigger to a change in a collection. The function will be called each time a change is made to the collection. The function accepts a context object as a parameter. The context object contains information about the change.

To read more about triggers, see the documentation.

Parameters

NameType
optionsTriggerOptions

Returns

ActionMethodDecorator<TriggerAction>


webhook

webhook(id): ActionMethodDecorator<WebhookAction>

Decorator that marks a function as a webhook. The function will be called when a webhook is triggered. Once the webhook is created, it will be exposed as a URL with the provided webhook ID with this format: https://<your app Id>.<app region>.squid.cloud/webhooks/<webhook-id>.

The function accepts a context object as a parameter. The context object contains information about the webhook. The function can return any value that can be serialized to JSON or a WebhookResponse object that can be created using: this.createWebhookResponse(<params>).

To read more about webhooks, see the documentation.

Parameters

NameTypeDescription
idstringThe ID of the webhook. Should be unique.

Returns

ActionMethodDecorator<WebhookAction>