Skip to main content

Executables

Squid Executables provide the client with a function that runs on the server. Executables are useful for functions that require access to secrets, execute queries not authorized for the current user, or access internal-only systems, among other things.

To make a backend function available to the client, decorate a function within a class that extends the SquidService class with the @executable decorator.

Caution

When working with Squid executables, it's important to keep in mind that these backend functions can be accessed directly from the client and have unlimited permissions to access backend resources and secrets. This means that you need to take extra care to make sure that only authorized users are able to execute them.

The following is an example of an Executable.

Backend code
import { executable, SquidService } from '@squidcloud/backend';

export class ExampleService extends SquidService {
@executable()
concat(str1: string, str2: string): string {
return `${str1}${str2}`;
}
}

To allow Squid to discover the executable and the rest of the functions in the same service, make sure the service is exported in the service/index.ts file:

service/index.ts
export * from './example-service';

This function can be executed from the client using the Squid Client SDK:

Client code
const result = await squid.executeFunction('concat', 'string1', 'string2');
console.log(result); // Prints `string1string2'