From c3805218850224ed43d32ccb6a8862d4cd288717 Mon Sep 17 00:00:00 2001 From: "Sudipta.Kumar" Date: Wed, 14 May 2025 00:44:28 +0600 Subject: [PATCH 1/2] # Feature (4156): P3) Bug with deploying a client function after it as deployed as a server function - Refactoring npm client - Verification added for checking existing function by name and context --- .gitignore | 1 + package.json | 2 +- src/cli.ts | 2 +- src/commands/function.ts | 24 +++++++++++++++++++----- src/config.ts | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index f04a890..eacfa63 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,4 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* +.idea \ No newline at end of file diff --git a/package.json b/package.json index b47c567..ed54290 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "polyapi", - "version": "0.23.8", + "version": "0.23.9", "description": "Poly is a CLI tool to help create and manage your Poly definitions.", "license": "MIT", "repository": { diff --git a/src/cli.ts b/src/cli.ts index 81f1db7..357eaf1 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -230,7 +230,7 @@ void yargs return; } const { addOrUpdateCustomFunction } = await import('./commands/function'); - await addOrUpdateCustomFunction(DEFAULT_POLY_PATH, context, name, description, file, server, logsEnabled, generateContexts, executionApiKey); + await addOrUpdateCustomFunction(DEFAULT_POLY_PATH, context, name, description, file, client, server, logsEnabled, generateContexts, executionApiKey); }, ); }) diff --git a/src/commands/function.ts b/src/commands/function.ts index b1d4d8b..bac3bd0 100644 --- a/src/commands/function.ts +++ b/src/commands/function.ts @@ -15,6 +15,7 @@ export const addOrUpdateCustomFunction = async ( name: string, description: string | null, file: string, + client: boolean | undefined, server: boolean | undefined, logsEnabled: boolean | undefined, generateContexts: string | undefined, @@ -38,10 +39,21 @@ export const addOrUpdateCustomFunction = async ( const specs = await getSpecs([context], [name]); const functionSpec = specs.find(spec => spec.name === name && spec.context === context); const updating = !!functionSpec; - if (server === undefined && updating) { - server = functionSpec.type === 'serverFunction'; - } else { - server = server ?? false; + if (updating) { + const isConflictingType = + (client === true && functionSpec.type === 'serverFunction') || + (server === true && functionSpec.type === 'customFunction'); + + if (isConflictingType) { + const existingType = functionSpec.type === 'serverFunction' ? 'server' : 'client'; + const targetType = existingType === 'server' ? 'client' : 'server'; + + shell.echo( + chalk.yellowBright(`ERROR: Function already exists as a ${existingType} function.`) + '\n' + + chalk.yellow(`Please delete it before deploying as a ${targetType} function.`), + ); + return; + } } const typeSchemas = generateTypeSchemas(file, tsConfigBaseUrl, DeployableTypeEntries.map(d => d[0])); @@ -69,7 +81,9 @@ export const addOrUpdateCustomFunction = async ( shell.echo(chalk.green('DEPLOYED')); shell.echo(`Function ID: ${customFunction.id}`); - } else { + } + + if (client) { shell.echo('-n', `${updating ? 'Updating' : 'Adding'} Client Function to PolyAPI Catalog...`); customFunction = await createOrUpdateClientFunction(context, name, description, code, typeSchemas); shell.echo(chalk.green('DONE')); diff --git a/src/config.ts b/src/config.ts index e114d02..cc08b28 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,7 +3,7 @@ import dotenv from 'dotenv'; const getPolyConfigDirPath = (polyPath: string) => // If path does not start with `./` or `/` then we adjust! - /^\.?\/.*/.test(polyPath) ? polyPath : `${__dirname}/../../../../../${polyPath}`; + /^\.?\/.*/.test(polyPath) ? polyPath : `${__dirname}/../../../${polyPath}`; const getPolyConfigFilePath = (polyPath: string) => `${getPolyConfigDirPath(polyPath)}/.config.env`; From 0432ecbea9f05c6da08eacec8c18c6699e7509fc Mon Sep 17 00:00:00 2001 From: "Sudipta.Kumar" Date: Fri, 16 May 2025 00:27:30 +0600 Subject: [PATCH 2/2] # Feature (4156): P3) Bug with deploying a client function after it as deployed as a server function - color updated --- src/commands/function.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/function.ts b/src/commands/function.ts index bac3bd0..e5eb154 100644 --- a/src/commands/function.ts +++ b/src/commands/function.ts @@ -49,8 +49,8 @@ export const addOrUpdateCustomFunction = async ( const targetType = existingType === 'server' ? 'client' : 'server'; shell.echo( - chalk.yellowBright(`ERROR: Function already exists as a ${existingType} function.`) + '\n' + - chalk.yellow(`Please delete it before deploying as a ${targetType} function.`), + chalk.redBright(`ERROR: Function already exists as a ${existingType} function.`) + '\n' + + chalk.red(`Please delete it before deploying as a ${targetType} function.`), ); return; }