8311 serverless function functions can be executed with any input (#8380)
- remove ts-morph - update inputSchema shape  https://github.com/user-attachments/assets/913cd305-9e7c-48da-b20f-c974a8ac7cea ## TODO - have inputTypes to match the inputSchema type (string, number, boolean, etc...), only string for now - handle required/optional inputs - handle case when inputSchema changes, fix data reset when switching function
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
export const handler = async (
|
||||
event: object,
|
||||
context: object,
|
||||
): Promise<object> => {
|
||||
export const main = async (params: {
|
||||
a: string;
|
||||
b: number;
|
||||
}): Promise<object> => {
|
||||
const { a, b } = params;
|
||||
|
||||
// Your code here
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
@ -227,7 +227,7 @@ export class LambdaDriver implements ServerlessDriver {
|
||||
ZipFile: await fs.readFile(lambdaZipPath),
|
||||
},
|
||||
FunctionName: serverlessFunction.id,
|
||||
Handler: 'src/index.handler',
|
||||
Handler: 'src/index.main',
|
||||
Layers: [layerArn],
|
||||
Environment: {
|
||||
Variables: envVariables,
|
||||
|
||||
@ -94,9 +94,9 @@ export class LocalDriver implements ServerlessDriver {
|
||||
process.env = ${JSON.stringify(envVariables)}
|
||||
|
||||
process.on('message', async (message) => {
|
||||
const { event, context } = message;
|
||||
const { params } = message;
|
||||
try {
|
||||
const result = await index_1.handler(event, context);
|
||||
const result = await index_1.main(params);
|
||||
process.send(result);
|
||||
} catch (error) {
|
||||
process.send({
|
||||
@ -245,7 +245,7 @@ export class LocalDriver implements ServerlessDriver {
|
||||
}
|
||||
});
|
||||
|
||||
child.send({ event: payload });
|
||||
child.send({ params: payload });
|
||||
});
|
||||
} catch (error) {
|
||||
return {
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
@ObjectType()
|
||||
export class FunctionParameter {
|
||||
@IsString()
|
||||
@Field(() => String)
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
@Field(() => String)
|
||||
type: string;
|
||||
}
|
||||
@ -18,10 +18,11 @@ import {
|
||||
IsString,
|
||||
IsUUID,
|
||||
} from 'class-validator';
|
||||
import GraphQLJSON from 'graphql-type-json';
|
||||
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
import { FunctionParameter } from 'src/engine/metadata-modules/serverless-function/dtos/function-parameter.dto';
|
||||
import { ServerlessFunctionSyncStatus } from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
|
||||
import { InputSchema } from 'src/modules/code-introspection/types/input-schema.type';
|
||||
|
||||
registerEnumType(ServerlessFunctionSyncStatus, {
|
||||
name: 'ServerlessFunctionSyncStatus',
|
||||
@ -65,9 +66,8 @@ export class ServerlessFunctionDTO {
|
||||
@Field(() => [String], { nullable: false })
|
||||
publishedVersions: string[];
|
||||
|
||||
@IsArray()
|
||||
@Field(() => [FunctionParameter], { nullable: true })
|
||||
latestVersionInputSchema: FunctionParameter[] | null;
|
||||
@Field(() => GraphQLJSON, { nullable: true })
|
||||
latestVersionInputSchema: InputSchema;
|
||||
|
||||
@IsEnum(ServerlessFunctionSyncStatus)
|
||||
@IsNotEmpty()
|
||||
|
||||
@ -29,7 +29,7 @@ export class ServerlessFunctionPublicationListener {
|
||||
serverlessFunctionVersion: string;
|
||||
}>,
|
||||
): Promise<void> {
|
||||
payload.events.forEach(async (event) => {
|
||||
for (const event of payload.events) {
|
||||
const sourceCode =
|
||||
await this.serverlessFunctionService.getServerlessFunctionSourceCode(
|
||||
payload.workspaceId,
|
||||
@ -48,12 +48,12 @@ export class ServerlessFunctionPublicationListener {
|
||||
}
|
||||
|
||||
const latestVersionInputSchema =
|
||||
await this.codeIntrospectionService.getFunctionInputSchema(indexCode);
|
||||
this.codeIntrospectionService.getFunctionInputSchema(indexCode);
|
||||
|
||||
await this.serverlessFunctionRepository.update(
|
||||
{ id: event.serverlessFunctionId },
|
||||
{ latestVersionInputSchema },
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { FunctionParameter } from 'src/engine/metadata-modules/serverless-function/dtos/function-parameter.dto';
|
||||
import { InputSchema } from 'src/modules/code-introspection/types/input-schema.type';
|
||||
|
||||
export enum ServerlessFunctionSyncStatus {
|
||||
NOT_READY = 'NOT_READY',
|
||||
@ -35,7 +35,7 @@ export class ServerlessFunctionEntity {
|
||||
publishedVersions: string[];
|
||||
|
||||
@Column({ nullable: true, type: 'jsonb' })
|
||||
latestVersionInputSchema: FunctionParameter[];
|
||||
latestVersionInputSchema: InputSchema;
|
||||
|
||||
@Column({ nullable: false, default: ServerlessFunctionRuntime.NODE18 })
|
||||
runtime: ServerlessFunctionRuntime;
|
||||
|
||||
Reference in New Issue
Block a user