diff --git a/docs/reference/Source_Documentation.md b/docs/reference/Source_Documentation.md index 6cefc903..d7f54e30 100644 --- a/docs/reference/Source_Documentation.md +++ b/docs/reference/Source_Documentation.md @@ -1274,9 +1274,6 @@ A helper for any functions that are agnostic in handlers. * [utils](#module_utils) * [~isPackageNameBanned(name)](#module_utils..isPackageNameBanned) ⇒ object - * [~constructPackageObjectFull(pack)](#module_utils..constructPackageObjectFull) ⇒ object - * [~constructPackageObjectShort(pack)](#module_utils..constructPackageObjectShort) ⇒ object \| array - * [~constructPackageObjectJSON(pack)](#module_utils..constructPackageObjectJSON) ⇒ object * [~engineFilter()](#module_utils..engineFilter) ⇒ object * [~semverArray(semver)](#module_utils..semverArray) ⇒ array \| null * [~semverGt(a1, a2)](#module_utils..semverGt) ⇒ boolean @@ -1301,59 +1298,6 @@ false otherwise. | --- | --- | --- | | name | string | The name of the package to check if it is banned. | - - -### utils~constructPackageObjectFull(pack) ⇒ object -Takes the raw return of a full row from database.getPackageByName() and -constructs a standardized package object full from it. -This should be called only on the data provided by database.getPackageByName(), -otherwise the behavior is unexpected. - -**Kind**: inner method of [utils](#module_utils) -**Returns**: object - A properly formatted and converted Package Object Full. -**See** - -- [https://github.com/confused-Techie/atom-backend/blob/main/docs/returns.md#package-object-full](https://github.com/confused-Techie/atom-backend/blob/main/docs/returns.md#package-object-full) -- [https://github.com/confused-Techie/atom-backend/blob/main/docs/queries.md#retrieve-single-package--package-object-full](https://github.com/confused-Techie/atom-backend/blob/main/docs/queries.md#retrieve-single-package--package-object-full) - - -| Param | Type | Description | -| --- | --- | --- | -| pack | object | The anticipated raw SQL return that contains all data to construct a Package Object Full. | - - - -### utils~constructPackageObjectShort(pack) ⇒ object \| array -Takes a single or array of rows from the db, and returns a JSON -construction of package object shorts - -**Kind**: inner method of [utils](#module_utils) -**Returns**: object \| array - A properly formatted and converted Package Object Short. -**See** - -- [https://github.com/confused-Techie/atom-backend/blob/main/docs/returns.md#package-object-short](https://github.com/confused-Techie/atom-backend/blob/main/docs/returns.md#package-object-short) -- [https://github.com/confused-Techie/atom-backend/blob/main/docs/queries.md#retrieve-many-sorted-packages--package-object-short](https://github.com/confused-Techie/atom-backend/blob/main/docs/queries.md#retrieve-many-sorted-packages--package-object-short) - - -| Param | Type | Description | -| --- | --- | --- | -| pack | object | The anticipated raw SQL return that contains all data to construct a Package Object Short. | - - - -### utils~constructPackageObjectJSON(pack) ⇒ object -Takes the return of getPackageVersionByNameAndVersion and returns -a recreation of the package.json with a modified dist.tarball key, pointing -to this server for download. - -**Kind**: inner method of [utils](#module_utils) -**Returns**: object - A properly formatted Package Object Mini. -**See**: [https://github.com/confused-Techie/atom-backend/blob/main/docs/returns.md#package-object-mini](https://github.com/confused-Techie/atom-backend/blob/main/docs/returns.md#package-object-mini) - -| Param | Type | Description | -| --- | --- | --- | -| pack | object | The expected raw SQL return of `getPackageVersionByNameAndVersion` | - ### utils~engineFilter() ⇒ object diff --git a/docs/resources/complexity-report.md b/docs/resources/complexity-report.md index 410f21e3..37b2fd31 100644 --- a/docs/resources/complexity-report.md +++ b/docs/resources/complexity-report.md @@ -1,12 +1,12 @@ -# Complexity report, 1/20/2024 - -* Mean per-function logical LOC: 14.271929824561404 -* Mean per-function parameter count: 0.1324561403508772 -* Mean per-function cyclomatic complexity: 1.1736842105263159 -* Mean per-function Halstead effort: 3371.505283870604 -* Mean per-module maintainability index: 69.2796371850002 -* First-order density: 0.9233610341643583% -* Change cost: 5.786395814096645% +# Complexity report, 1/23/2024 + +* Mean per-function logical LOC: 14.663793103448276 +* Mean per-function parameter count: 0.13017241379310346 +* Mean per-function cyclomatic complexity: 1.170689655172414 +* Mean per-function Halstead effort: 3426.6136676441265 +* Mean per-module maintainability index: 68.88659389428372 +* First-order density: 0.89179548156956% +* Change cost: 5.618311533888228% * Core size: 100% ## /home/runner/work/package-backend/package-backend/jest.config.js @@ -61,13 +61,13 @@ ## /home/runner/work/package-backend/package-backend/src/context.js -* Physical LOC: 15 -* Logical LOC: 14 +* Physical LOC: 20 +* Logical LOC: 18 * Mean parameter count: 0 * Cyclomatic complexity: 1 -* Cyclomatic complexity density: 7.142857142857142% -* Maintainability index: 60.516428793372064 -* Dependency count: 13 +* Cyclomatic complexity density: 5.555555555555555% +* Maintainability index: 57.55605134290526 +* Dependency count: 16 ## /home/runner/work/package-backend/package-backend/docs/resources/jsdoc_typedef.js @@ -529,6 +529,16 @@ * Maintainability index: 73.83569622868538 * Dependency count: 2 +## /home/runner/work/package-backend/package-backend/tests/models/packageObjectJSON.js + +* Physical LOC: 43 +* Logical LOC: 33 +* Mean parameter count: 0 +* Cyclomatic complexity: 1 +* Cyclomatic complexity density: 3.0303030303030303% +* Maintainability index: 49.44350377391116 +* Dependency count: 0 + ## /home/runner/work/package-backend/package-backend/tests/models/packageObjectShort.js * Physical LOC: 137 diff --git a/src/context.js b/src/context.js index 8e4fcf84..d34d23d0 100644 --- a/src/context.js +++ b/src/context.js @@ -19,5 +19,5 @@ module.exports = { constructPackageObjectFull: require("./models/constructPackageObjectFull.js"), constructPackageObjectShort: require("./models/constructPackageObjectShort.js"), constructPackageObjectJSON: require("./models/constructPackageObjectJSON.js"), - } + }, }; diff --git a/src/controllers/getPackagesPackageNameVersionsVersionName.js b/src/controllers/getPackagesPackageNameVersionsVersionName.js index fb8e4b65..1ffce47a 100644 --- a/src/controllers/getPackagesPackageNameVersionsVersionName.js +++ b/src/controllers/getPackagesPackageNameVersionsVersionName.js @@ -9,10 +9,10 @@ module.exports = { 200: { description: "The `package.json` among other details of the package.", content: { - "application/json": "$packageObjectJSON" - } - } - } + "application/json": "$packageObjectJSON", + }, + }, + }, }, endpoint: { method: "GET", diff --git a/src/controllers/getPackagesPackageNameVersionsVersionNameTarball.js b/src/controllers/getPackagesPackageNameVersionsVersionNameTarball.js index 097cf5cd..49ea077b 100644 --- a/src/controllers/getPackagesPackageNameVersionsVersionNameTarball.js +++ b/src/controllers/getPackagesPackageNameVersionsVersionNameTarball.js @@ -10,9 +10,9 @@ module.exports = { "Previously undocumented endpoint. Allows for installation of a package.", responses: { 302: { - description: "Redirect to the GitHub tarball URL." - } - } + description: "Redirect to the GitHub tarball URL.", + }, + }, }, endpoint: { method: "GET", diff --git a/src/controllers/getThemesFeatured.js b/src/controllers/getThemesFeatured.js index a49367b3..52d7cda9 100644 --- a/src/controllers/getThemesFeatured.js +++ b/src/controllers/getThemesFeatured.js @@ -37,7 +37,9 @@ module.exports = { return sso.notOk().addContent(col).addCalls("db.getFeaturedThemes", col); } - const newCol = await context.models.constructPackageObjectShort(col.content); + const newCol = await context.models.constructPackageObjectShort( + col.content + ); const sso = new context.sso(); diff --git a/src/models/constructPackageObjectFull.js b/src/models/constructPackageObjectFull.js index 7525cb01..9ee34932 100644 --- a/src/models/constructPackageObjectFull.js +++ b/src/models/constructPackageObjectFull.js @@ -14,8 +14,7 @@ const logger = require("../logger.js"); const { server_url } = require("../config.js").getConfig(); -module.exports = -async function constructPackageObjectFull(pack) { +module.exports = async function constructPackageObjectFull(pack) { const parseVersions = (vers) => { let retVer = {}; @@ -60,4 +59,4 @@ async function constructPackageObjectFull(pack) { logger.generic(6, "Built Package Object Full without Error"); return newPack; -} +}; diff --git a/src/models/constructPackageObjectJSON.js b/src/models/constructPackageObjectJSON.js index 51d0d6b4..c841d3cb 100644 --- a/src/models/constructPackageObjectJSON.js +++ b/src/models/constructPackageObjectJSON.js @@ -12,8 +12,7 @@ const logger = require("../logger.js"); const { server_url } = require("../config.js").getConfig(); -module.exports = -async function constructPackageObjectJSON(pack) { +module.exports = async function constructPackageObjectJSON(pack) { const parseVersionObject = (v) => { let newPack = v.meta; if (newPack.sha) { @@ -43,4 +42,4 @@ async function constructPackageObjectJSON(pack) { logger.generic(66, "Array Package Object JSON finished without Error"); return arrPack; -} +}; diff --git a/src/models/constructPackageObjectShort.js b/src/models/constructPackageObjectShort.js index 69d776d2..c6e103fb 100644 --- a/src/models/constructPackageObjectShort.js +++ b/src/models/constructPackageObjectShort.js @@ -12,8 +12,7 @@ const logger = require("../logger.js"); -module.exports = -async function constructPackageObjectShort(pack) { +module.exports = async function constructPackageObjectShort(pack) { const parsePackageObject = (p) => { let newPack = p.data; newPack.downloads = p.downloads; @@ -77,4 +76,4 @@ async function constructPackageObjectShort(pack) { logger.generic(6, "Single Package Object Short Constructor without Error"); return parsePackageObject(pack); -} +}; diff --git a/tests/models/packageObjectJSON.js b/tests/models/packageObjectJSON.js index 4a974866..b2639fd4 100644 --- a/tests/models/packageObjectJSON.js +++ b/tests/models/packageObjectJSON.js @@ -1,19 +1,15 @@ module.exports = { schema: { - description: "The `package.json` of a package with an added `dist.tarball` object.", + description: + "The `package.json` of a package with an added `dist.tarball` object.", type: "object", - required: [ - "name", - "version", - "engines", - "dist" - ], + required: ["name", "version", "engines", "dist"], properties: { name: { type: "string" }, version: { type: "object" }, engines: { type: "object" }, - dist: { type: "object" } - } + dist: { type: "object" }, + }, }, example: { // This is the full return of `language-robots-txt` @@ -23,24 +19,25 @@ module.exports = { author: "confused-Techie", license: "MIT", scripts: { - test: "pulsar --test spec" + test: "pulsar --test spec", }, version: "1.0.8", - keywords: [ "text-mate", "pulsar-package", "pulsar-edit" ], + keywords: ["text-mate", "pulsar-package", "pulsar-edit"], repository: "https://github.com/confused-Techei/language-robots-txt", description: "Robots.txt Syntax Highlighting in Pulsar", dist: { - tarball: "https://api.pulsar-edit.dev/api/packages/language-robots-txt/versions/1.0.8/tarball" - } + tarball: + "https://api.pulsar-edit.dev/api/packages/language-robots-txt/versions/1.0.8/tarball", + }, }, test: Joi.object({ name: Joi.string().required(), version: Joi.string().required(), engines: Joi.object({ - atom: Joi.string().required() + atom: Joi.string().required(), }).required(), dist: Joi.object({ - tarball: Joi.string().required() + tarball: Joi.string().required(), }).required(), }).required(), }; diff --git a/tests/unit/models/constructPackageObjectFull.test.js b/tests/unit/models/constructPackageObjectFull.test.js index 5713f773..7768dcfd 100644 --- a/tests/unit/models/constructPackageObjectFull.test.js +++ b/tests/unit/models/constructPackageObjectFull.test.js @@ -2,7 +2,6 @@ const pof = require("../../../src/models/constructPackageObjectFull.js"); const schema = require("../../models/packageObjectFull.js").test; describe("Parses Data, as expected to be returned by the Database", () => { - test("Correctly Parses normal data", async () => { const data = { pointer: "1234", @@ -18,7 +17,7 @@ describe("Parses Data, as expected to be returned by the Database", () => { metadata: { name: "test-package", license: "MIT", - version: "1.0.0" + version: "1.0.0", }, releases: { latest: "1.0.0" }, versions: { @@ -26,14 +25,14 @@ describe("Parses Data, as expected to be returned by the Database", () => { sha: "1234", name: "test-package", version: "1.0.0", - tarball_url: "https://nowhere.com" - } + tarball_url: "https://nowhere.com", + }, }, repository: { url: "https://github.com/pulsar-edit/test-package", - type: "git" + type: "git", }, - creation_method: "Test Package" + creation_method: "Test Package", }, owner: "pulsar-edit", stargazers_count: "1", @@ -44,7 +43,7 @@ describe("Parses Data, as expected to be returned by the Database", () => { sha: "1234", name: "test-package", version: "1.0.0", - tarball_url: "https://nowhere.com" + tarball_url: "https://nowhere.com", }, engine: { atom: "*" }, semver: "1.0.0", @@ -52,9 +51,9 @@ describe("Parses Data, as expected to be returned by the Database", () => { package: "1234", hasGrammar: false, hasSnippets: false, - supportedLanguages: null - } - ] + supportedLanguages: null, + }, + ], }; const parsed = await pof(data); diff --git a/tests/unit/models/constructPackageObjectJSON.test.js b/tests/unit/models/constructPackageObjectJSON.test.js index 033e79bc..50e4138f 100644 --- a/tests/unit/models/constructPackageObjectJSON.test.js +++ b/tests/unit/models/constructPackageObjectJSON.test.js @@ -2,7 +2,6 @@ const poj = require("../../../src/models/constructPackageObjectJSON.js"); const schema = require("../../models/packageObjectJSON.js").test; describe("Parses Data, as expected to be returned by the Database", () => { - test("Correctly Parses normal data", async () => { const data = { semver: "1.0.0", @@ -12,8 +11,8 @@ describe("Parses Data, as expected to be returned by the Database", () => { sha: "1234", name: "package-test", version: "1.0.0", - tarball_url: "https://nowhere.com" - } + tarball_url: "https://nowhere.com", + }, }; const parsed = await poj(data); diff --git a/tests/unit/models/constructPackageObjectShort.test.js b/tests/unit/models/constructPackageObjectShort.test.js index 96005163..bbfd13aa 100644 --- a/tests/unit/models/constructPackageObjectShort.test.js +++ b/tests/unit/models/constructPackageObjectShort.test.js @@ -2,7 +2,6 @@ const pos = require("../../../src/models/constructPackageObjectShort.js"); const schema = require("../../models/packageObjectShort.js").test; describe("Parses Data, as expected to be returned by the Database", () => { - test("Correctly Parses normal data", async () => { const data = { name: "test-package", @@ -13,7 +12,7 @@ describe("Parses Data, as expected to be returned by the Database", () => { metadata: { name: "test-package", license: "MIT", - version: "1.0.0" + version: "1.0.0", }, releases: { latest: "1.0.0" }, versions: { @@ -21,14 +20,14 @@ describe("Parses Data, as expected to be returned by the Database", () => { sha: "1234", name: "test-package", version: "1.0.0", - tarball_url: "https://nowhere.com" - } + tarball_url: "https://nowhere.com", + }, }, repository: { url: "https://github.com/pulsar-edit/test-package", - type: "git" + type: "git", }, - creation_method: "Test Package" + creation_method: "Test Package", }, downloads: "0", owner: "pulsar-edit", @@ -36,7 +35,7 @@ describe("Parses Data, as expected to be returned by the Database", () => { semver: "1.0.0", created: "2024-01-20T00:46:57.014Z", updated: "2024-01-20T00:46:57.014Z", - creation_method: "Test Package" + creation_method: "Test Package", }; const parsed = await pos(data);