diff --git a/src/core/resources/function/config.ts b/src/core/resources/function/config.ts index 1a592d36..563c3b25 100644 --- a/src/core/resources/function/config.ts +++ b/src/core/resources/function/config.ts @@ -6,10 +6,7 @@ import type { BackendFunction, FunctionConfig, } from "@/core/resources/function/schema.js"; -import { - FunctionConfigSchema, - FunctionSchema, -} from "@/core/resources/function/schema.js"; +import { FunctionConfigSchema } from "@/core/resources/function/schema.js"; import { pathExists, readJsonFile } from "@/core/utils/fs.js"; export async function readFunctionConfig( @@ -42,22 +39,13 @@ export async function readFunction( ); } - const files = await globby("*.{js,ts,json}", { + const filePaths = await globby("*.{js,ts,json}", { cwd: functionDir, absolute: true, }); - const functionData = { ...config, entryPath, files }; - const result = FunctionSchema.safeParse(functionData); - if (!result.success) { - throw new SchemaValidationError( - "Invalid function", - result.error, - configPath - ); - } - - return result.data; + const functionData: BackendFunction = { ...config, entryPath, filePaths }; + return functionData; } export async function readAllFunctions( diff --git a/src/core/resources/function/deploy.ts b/src/core/resources/function/deploy.ts index 88a52a76..0607d18f 100644 --- a/src/core/resources/function/deploy.ts +++ b/src/core/resources/function/deploy.ts @@ -12,7 +12,7 @@ async function loadFunctionCode( fn: BackendFunction ): Promise { const loadedFiles: FunctionFile[] = await Promise.all( - fn.files.map(async (filePath) => { + fn.filePaths.map(async (filePath) => { const content = await readTextFile(filePath); return { path: basename(filePath), content }; }) diff --git a/src/core/resources/function/schema.ts b/src/core/resources/function/schema.ts index e3021d63..c12adb45 100644 --- a/src/core/resources/function/schema.ts +++ b/src/core/resources/function/schema.ts @@ -16,9 +16,9 @@ export const FunctionConfigSchema = z.object({ entry: z.string().min(1, "Entry point cannot be empty"), }); -export const FunctionSchema = FunctionConfigSchema.extend({ +export const BackendFunctionSchema = FunctionConfigSchema.extend({ entryPath: z.string().min(1, "Entry path cannot be empty"), - files: z.array(z.string()).min(1, "Function must have at least one file"), + filePaths: z.array(z.string()).min(1, "Function must have at least one file"), }); export const FunctionDeploySchema = z.object({ @@ -38,7 +38,7 @@ export const DeployFunctionsResponseSchema = z.object({ }); export type FunctionConfig = z.infer; -export type BackendFunction = z.infer; +export type BackendFunction = z.infer; export type FunctionFile = z.infer; export type FunctionDeploy = z.infer; export type DeployFunctionsResponse = z.infer<