Function service (#227)

This commit is contained in:
Janos Dobronszki
2021-10-11 11:54:53 +01:00
committed by GitHub
parent ee1674dda6
commit 599b418c20
36 changed files with 1988 additions and 41 deletions

101
clients/ts/function/index.ts Executable file
View File

@@ -0,0 +1,101 @@
import * as m3o from "@m3o/m3o-node";
export class FunctionService {
private client: m3o.Client;
constructor(token: string) {
this.client = new m3o.Client({ token: token });
}
// Call a function
call(request: CallRequest): Promise<CallResponse> {
return this.client.call(
"function",
"Call",
request
) as Promise<CallResponse>;
}
//
delete(request: DeleteRequest): Promise<DeleteResponse> {
return this.client.call(
"function",
"Delete",
request
) as Promise<DeleteResponse>;
}
// Deploy a group of functions
deploy(request: DeployRequest): Promise<DeployResponse> {
return this.client.call(
"function",
"Deploy",
request
) as Promise<DeployResponse>;
}
//
list(request: ListRequest): Promise<ListResponse> {
return this.client.call(
"function",
"List",
request
) as Promise<ListResponse>;
}
}
export interface CallRequest {
// Name of the function
name?: string;
// Request body that will be passed to the function
request?: { [key: string]: any };
}
export interface CallResponse {
// Response body that the function returned
response?: { [key: string]: any };
}
export interface DeleteRequest {
name?: string;
project?: string;
}
export interface DeleteResponse {}
export interface DeployRequest {
// entry point, ie. handler name in the source code
// if not provided, defaults to the name parameter
entrypoint?: string;
// function name
name?: string;
// project is used for namespacing your functions
// optional. defaults to "default".
project?: string;
// github url to repo
repo?: string;
// optional subfolder path
subfolder?: string;
}
export interface DeployResponse {}
export interface Func {
// name of handler in source code
entrypoint?: string;
// function name
name?: string;
// project of function, optional
// defaults to literal "default"
// used to namespace functions
project?: string;
// git repo address
repo?: string;
// subfolder path to entrypoint
subfolder?: string;
}
export interface ListRequest {
// optional
project?: string;
}
export interface ListResponse {
functions?: Func[];
}

View File

@@ -9,6 +9,7 @@ import * as emoji from "./emoji";
import * as evchargers from "./evchargers";
import * as file from "./file";
import * as forex from "./forex";
import * as fx from "./function";
import * as geocoding from "./geocoding";
import * as helloworld from "./helloworld";
import * as holidays from "./holidays";
@@ -50,6 +51,7 @@ export class Client {
this.evchargersService = new evchargers.EvchargersService(token);
this.fileService = new file.FileService(token);
this.forexService = new forex.ForexService(token);
this.functionService = new fx.FunctionService(token);
this.geocodingService = new geocoding.GeocodingService(token);
this.helloworldService = new helloworld.HelloworldService(token);
this.holidaysService = new holidays.HolidaysService(token);
@@ -90,6 +92,7 @@ export class Client {
evchargersService: evchargers.EvchargersService;
fileService: file.FileService;
forexService: forex.ForexService;
functionService: fx.FunctionService;
geocodingService: geocoding.GeocodingService;
helloworldService: helloworld.HelloworldService;
holidaysService: holidays.HolidaysService;

View File

@@ -20,6 +20,7 @@
"./evchargers": "./dist/evchargers/index.js",
"./file": "./dist/file/index.js",
"./forex": "./dist/forex/index.js",
"./function": "./dist/function/index.js",
"./geocoding": "./dist/geocoding/index.js",
"./gifs": "./dist/gifs/index.js",
"./helloworld": "./dist/helloworld/index.js",
@@ -65,5 +66,5 @@
},
"type": "module",
"types": "dist/index.d.ts",
"version": "1.0.543"
"version": "1.0.544"
}