Skip to content

Commit 2abfc5a

Browse files
authored
# Feature (4156): P3) Bug with deploying a client function after it a… (#1)
* # 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 - color updated
1 parent 814377f commit 2abfc5a

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ dist
137137
.yarn/build-state.yml
138138
.yarn/install-state.gz
139139
.pnp.*
140+
.idea

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polyapi",
3-
"version": "0.23.8",
3+
"version": "0.23.9",
44
"description": "Poly is a CLI tool to help create and manage your Poly definitions.",
55
"license": "MIT",
66
"repository": {

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void yargs
230230
return;
231231
}
232232
const { addOrUpdateCustomFunction } = await import('./commands/function');
233-
await addOrUpdateCustomFunction(DEFAULT_POLY_PATH, context, name, description, file, server, logsEnabled, generateContexts, executionApiKey);
233+
await addOrUpdateCustomFunction(DEFAULT_POLY_PATH, context, name, description, file, client, server, logsEnabled, generateContexts, executionApiKey);
234234
},
235235
);
236236
})

src/commands/function.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const addOrUpdateCustomFunction = async (
1515
name: string,
1616
description: string | null,
1717
file: string,
18+
client: boolean | undefined,
1819
server: boolean | undefined,
1920
logsEnabled: boolean | undefined,
2021
generateContexts: string | undefined,
@@ -38,10 +39,21 @@ export const addOrUpdateCustomFunction = async (
3839
const specs = await getSpecs([context], [name]);
3940
const functionSpec = specs.find(spec => spec.name === name && spec.context === context);
4041
const updating = !!functionSpec;
41-
if (server === undefined && updating) {
42-
server = functionSpec.type === 'serverFunction';
43-
} else {
44-
server = server ?? false;
42+
if (updating) {
43+
const isConflictingType =
44+
(client === true && functionSpec.type === 'serverFunction') ||
45+
(server === true && functionSpec.type === 'customFunction');
46+
47+
if (isConflictingType) {
48+
const existingType = functionSpec.type === 'serverFunction' ? 'server' : 'client';
49+
const targetType = existingType === 'server' ? 'client' : 'server';
50+
51+
shell.echo(
52+
chalk.redBright(`ERROR: Function already exists as a ${existingType} function.`) + '\n' +
53+
chalk.red(`Please delete it before deploying as a ${targetType} function.`),
54+
);
55+
return;
56+
}
4557
}
4658

4759
const typeSchemas = generateTypeSchemas(file, tsConfigBaseUrl, DeployableTypeEntries.map(d => d[0]));
@@ -69,7 +81,9 @@ export const addOrUpdateCustomFunction = async (
6981
shell.echo(chalk.green('DEPLOYED'));
7082

7183
shell.echo(`Function ID: ${customFunction.id}`);
72-
} else {
84+
}
85+
86+
if (client) {
7387
shell.echo('-n', `${updating ? 'Updating' : 'Adding'} Client Function to PolyAPI Catalog...`);
7488
customFunction = await createOrUpdateClientFunction(context, name, description, code, typeSchemas);
7589
shell.echo(chalk.green('DONE'));

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import dotenv from 'dotenv';
33

44
const getPolyConfigDirPath = (polyPath: string) =>
55
// If path does not start with `./` or `/` then we adjust!
6-
/^\.?\/.*/.test(polyPath) ? polyPath : `${__dirname}/../../../../../${polyPath}`;
6+
/^\.?\/.*/.test(polyPath) ? polyPath : `${__dirname}/../../../${polyPath}`;
77

88
const getPolyConfigFilePath = (polyPath: string) =>
99
`${getPolyConfigDirPath(polyPath)}/.config.env`;

0 commit comments

Comments
 (0)