メインコンテンツまでスキップ

Executables(実行可能関数)

サーバー上で実行される関数へのアクセスをクライアントに提供します。

Executables は、secrets、databases、connectors など、backend リソースへのアクセスが必要な関数に役立ちます。

backend 関数をクライアントから利用可能にするには、SquidService クラスを拡張したクラス内で、関数に @executable デコレーターを付与します。

Caution

Squid executables を扱う際は、これらの backend 関数がクライアントから直接アクセスでき、backend リソースや secrets へアクセスするための権限が無制限である点を重要な前提として認識してください。これは、認可されたユーザーのみが実行できるようにするため、追加の注意を払う必要があることを意味します。

以下は executable の例です:

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

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

Squid が executable および同じ service 内の他の関数を検出できるようにするため、service/index.ts ファイルで service が export されていることを確認してください:

export * from './example-service';

この関数は Squid Client SDK を使用してクライアントから実行できます。最初のパラメーターは executable 関数名で、その後に関数のシグネチャに一致するパラメーターを続けます:

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