From efc7f40c673bd9798ad7509f1da3409502782ac2 Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia <7854099+viferga@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:54:19 -0400 Subject: [PATCH 1/6] Threat warnings as errors for eslint --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 25ad7f8..d558bdd 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "unit": "npm run --silent test -- --ignore **/integration**", "prepublishOnly": "npm run --silent build", "build": "npm run --silent lint && tsc", - "lint": "eslint . --ignore-pattern dist", + "lint": "eslint . --max-warnings=0 --ignore-pattern dist", "postinstall": "npm run fix && npm run build", - "fix": "eslint . --ignore-pattern dist --fix", + "fix": "eslint . --max-warnings=0 --ignore-pattern dist --fix", "start": "npm run build && metacall dist/server.js" }, "repository": { From f1c1c489088ccf3d6d805a7b41baa11cecb9a2fd Mon Sep 17 00:00:00 2001 From: Himanshu Kumar Sharma <97340980+HeeManSu@users.noreply.github.com> Date: Wed, 13 Mar 2024 23:26:46 +0530 Subject: [PATCH 2/6] Removing eslint issue (#40) * Diff method eslint refactoring done * unknown is safer alternative of any and it don't throws any warning --- src/constants.ts | 4 ++++ src/utils/utils.ts | 20 +++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 02b0d0c..8ddc58b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -114,3 +114,7 @@ export interface childProcessResponse { type: keyof typeof protocol; data: unknown; } + +export interface InspectObject { + [key: string]: Array<{ name: string }>; +} diff --git a/src/utils/utils.ts b/src/utils/utils.ts index f7cfa18..9501d1f 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -10,7 +10,8 @@ import { NextFunction, Request, RequestHandler, Response } from 'express'; import { createInstallDependenciesScript, currentFile, - IAllApps + IAllApps, + InspectObject } from '../constants'; export const dirName = (gitUrl: string): string => @@ -119,23 +120,20 @@ export const getLangId = (input: string): LanguageId => { return extension as LanguageId; }; -//eslint-disable-next-line -export const diff = (object1: any, object2: any): any => { +export const diff = ( + object1: InspectObject, + object2: InspectObject +): InspectObject => { for (const key in object2) { - //eslint-disable-next-line if (Array.isArray(object2[key])) { - //eslint-disable-next-line object1[key] = object1[key].filter( - ( - item: any // eslint-disable-line - ) => !object2[key].find((i: any) => i.name === item.name) // eslint-disable-line + item => !object2[key].find(i => i.name === item.name) ); } } - - return object1; // eslint-disable-line + return object1; }; -export function isIAllApps(data: any): data is IAllApps { +export function isIAllApps(data: unknown): data is IAllApps { return typeof data === 'object' && data !== null; } From 8e594c620c9a4ce52ebc5f8922dcf22f7fab315a Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia <7854099+viferga@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:59:06 -0400 Subject: [PATCH 3/6] Solve issues in package.json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index d558bdd..f1b4f2b 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,13 @@ "name": "@metacall/faas", "version": "0.1.0", "description": "Reimplementation of MetaCall FaaS platform written in TypeScript.", - "main": "dist/index.js", + "main": "dist/server.js", "scripts": { "test": "npm run --silent build && mocha dist/test", "unit": "npm run --silent test -- --ignore **/integration**", "prepublishOnly": "npm run --silent build", "build": "npm run --silent lint && tsc", "lint": "eslint . --max-warnings=0 --ignore-pattern dist", - "postinstall": "npm run fix && npm run build", "fix": "eslint . --max-warnings=0 --ignore-pattern dist --fix", "start": "npm run build && metacall dist/server.js" }, From 39feaae8732301c56259c7f704bcb530b57175d1 Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia Date: Wed, 13 Mar 2024 18:38:04 +0100 Subject: [PATCH 4/6] Fixed outdated versions. --- .vscode/settings.json | 4 ++-- package-lock.json | 49 +++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4c5cf89..e9c6df6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,8 +2,8 @@ "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.organizeImports": true, - "source.fixAll": true + "source.organizeImports": "explicit", + "source.fixAll": "explicit" }, "editor.rulers": [ 80 diff --git a/package-lock.json b/package-lock.json index 8ea97e3..a1414a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "@metacall/faas", "version": "0.1.0", - "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { "@metacall/protocol": "^0.1.19", @@ -120,9 +119,9 @@ } }, "node_modules/@metacall/protocol": { - "version": "0.1.19", - "resolved": "https://registry.npmjs.org/@metacall/protocol/-/protocol-0.1.19.tgz", - "integrity": "sha512-THwgGC/++92n5pf94unEvkGP9LYVHB3vAsHjk61daO8riHKMRreBA4pHcNa0EmTa5iW5XEB6pL9IcMpEfzldSQ==", + "version": "0.1.25", + "resolved": "https://registry.npmjs.org/@metacall/protocol/-/protocol-0.1.25.tgz", + "integrity": "sha512-Maf9qAry1apWN91kXwiOrttrdkhnXLu/6pxLn2s2mFQKPcK4EI5W1kl5zRvJ/tMd0vEhHAVNzex+ZxoqKAFI6Q==", "hasInstallScript": true, "dependencies": { "@types/ignore-walk": "^4.0.0", @@ -1646,9 +1645,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", - "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", + "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", "funding": [ { "type": "individual", @@ -2955,9 +2954,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -3440,9 +3439,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -3650,9 +3649,9 @@ } }, "@metacall/protocol": { - "version": "0.1.19", - "resolved": "https://registry.npmjs.org/@metacall/protocol/-/protocol-0.1.19.tgz", - "integrity": "sha512-THwgGC/++92n5pf94unEvkGP9LYVHB3vAsHjk61daO8riHKMRreBA4pHcNa0EmTa5iW5XEB6pL9IcMpEfzldSQ==", + "version": "0.1.25", + "resolved": "https://registry.npmjs.org/@metacall/protocol/-/protocol-0.1.25.tgz", + "integrity": "sha512-Maf9qAry1apWN91kXwiOrttrdkhnXLu/6pxLn2s2mFQKPcK4EI5W1kl5zRvJ/tMd0vEhHAVNzex+ZxoqKAFI6Q==", "requires": { "@types/ignore-walk": "^4.0.0", "@types/jsonwebtoken": "^8.5.8", @@ -4818,9 +4817,9 @@ "dev": true }, "follow-redirects": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", - "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==" + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", + "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==" }, "form-data": { "version": "3.0.1", @@ -5751,9 +5750,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", "requires": { "lru-cache": "^6.0.0" } @@ -6130,9 +6129,9 @@ } }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true }, "workerpool": { From 9405db21e40b112d92d24f1941608084e1b3f936 Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia Date: Wed, 13 Mar 2024 18:38:12 +0100 Subject: [PATCH 5/6] Add types to delete. --- src/controller/delete.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/delete.ts b/src/controller/delete.ts index 07ea895..1ff4426 100644 --- a/src/controller/delete.ts +++ b/src/controller/delete.ts @@ -11,7 +11,7 @@ import { deleteStatusMessage } from '../utils/resposeTexts'; export default ( req: Omit & { body: deleteBody }, res: Response -) => { +): Response => { // Extract the suffix (application name) of the application from the request body const { suffix: app } = req.body; From 97eaf35f0dad6474f1651e45f61a63295e640d02 Mon Sep 17 00:00:00 2001 From: Himanshu Kumar Sharma <97340980+HeeManSu@users.noreply.github.com> Date: Wed, 13 Mar 2024 23:46:00 +0530 Subject: [PATCH 6/6] Handle package empty error in deploy controller (#39) * next middleware added * packageEmpty error handling done --- src/api.ts | 75 ++++++++++++++++++++++++++-------------------- src/utils/utils.ts | 6 ++-- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/api.ts b/src/api.ts index 08f9da8..aa6201e 100644 --- a/src/api.ts +++ b/src/api.ts @@ -32,6 +32,7 @@ import { isIAllApps } from './utils/utils'; +import { PackageError } from '@metacall/protocol/package'; import { appsDirectory } from './utils/config'; const appsDir = appsDirectory(); @@ -213,49 +214,57 @@ export const fetchFileList = catchAsync( export const deploy = catchAsync( async ( req: Omit & { body: deployBody }, - res: Response + res: Response, + next: NextFunction ) => { - req.body.resourceType == 'Repository' && (await calculatePackages()); + try { + req.body.resourceType == 'Repository' && + (await calculatePackages(next)); - // TODO Currently Deploy function will only work for workdir, we will add the addRepo + // TODO Currently Deploy function will only work for workdir, we will add the addRepo - await installDependencies(); + await installDependencies(); - const desiredPath = path.join(__dirname, '/worker/index.js'); + const desiredPath = path.join(__dirname, '/worker/index.js'); - const proc = spawn('metacall', [desiredPath], { - stdio: ['pipe', 'pipe', 'pipe', 'ipc'] - }); + const proc = spawn('metacall', [desiredPath], { + stdio: ['pipe', 'pipe', 'pipe', 'ipc'] + }); - proc.send({ - type: protocol.l, - currentFile - }); + proc.send({ + type: protocol.l, + currentFile + }); - proc.stdout?.on('data', (data: Buffer) => { - console.log(data.toString().green); - }); - proc.stderr?.on('data', (data: Buffer) => { - console.log(data.toString().red); - }); + proc.stdout?.on('data', (data: Buffer) => { + console.log(data.toString().green); + }); + proc.stderr?.on('data', (data: Buffer) => { + console.log(data.toString().red); + }); - proc.on('message', (data: childProcessResponse) => { - if (data.type === protocol.g) { - if (isIAllApps(data.data)) { - const appName = Object.keys(data.data)[0]; - cps[appName] = proc; - allApplications[appName] = data.data[appName]; + proc.on('message', (data: childProcessResponse) => { + if (data.type === protocol.g) { + if (isIAllApps(data.data)) { + const appName = Object.keys(data.data)[0]; + cps[appName] = proc; + allApplications[appName] = data.data[appName]; + } } - } - }); - - res.status(200).json({ - suffix: hostname(), - prefix: currentFile.id, - version: 'v1' - }); + }); - // Handle err == PackageError.Empty, use next function for error handling + res.status(200).json({ + suffix: hostname(), + prefix: currentFile.id, + version: 'v1' + }); + } catch (err) { + // Check if the error is PackageError.Empty + if (err === PackageError.Empty) { + return next(err); + } + return next(err); + } } ); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 9501d1f..fe51283 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -32,10 +32,12 @@ export const installDependencies = async (): Promise => { }; //check if repo contains metacall-*.json if not create and calculate runners then install dependencies -export const calculatePackages = async (): Promise => { +export const calculatePackages = async (next: NextFunction): Promise => { const data = await generatePackage(currentFile.path); - if (data.error == PackageError.Empty) throw PackageError.Empty; + if (data.error == PackageError.Empty) { + return next(new Error(PackageError.Empty)); + } // currentFile.jsons = JSON.parse(data.jsons.toString()); FIXME Fix this line currentFile.runners = data.runners; };