diff --git a/docs/reference/Source_Documentation.md b/docs/reference/Source_Documentation.md index d7f54e30..a28afd5c 100644 --- a/docs/reference/Source_Documentation.md +++ b/docs/reference/Source_Documentation.md @@ -23,10 +23,6 @@ But this does provide an opportunity to allow multiple caching systems.
Module that access' and returns the server wide configuration.
Provides an interface of a large collection of functions to interact -with and retrieve data from the cloud hosted database instance.
-The Development initializer of main.js
as well as managing the startup of a locally created Docker SQL
Server. This uses pg-test to set up a database hosted on local Docker. Migrating all data as needed,
@@ -632,463 +628,6 @@ Or from environment variables. Prioritizing environment variables.
```js
const { search_algorithm } = require("./config.js").getConfig();
```
-
-
-## database
-Provides an interface of a large collection of functions to interact
-with and retrieve data from the cloud hosted database instance.
-
-
-* [database](#module_database)
- * [~setupSQL()](#module_database..setupSQL) ⇒ object
- * [~shutdownSQL()](#module_database..shutdownSQL)
- * [~packageNameAvailability(name)](#module_database..packageNameAvailability) ⇒ object
- * [~insertNewPackage(pack)](#module_database..insertNewPackage) ⇒ object
- * [~insertNewPackageVersion(packJSON, oldName)](#module_database..insertNewPackageVersion) ⇒ object
- * [~applyFeatures(featureObj, packName, packVersion)](#module_database..applyFeatures)
- * [~insertNewPackageName(newName, oldName)](#module_database..insertNewPackageName) ⇒ object
- * [~insertNewUser(username, id, avatar)](#module_database..insertNewUser) ⇒ object
- * [~getPackageByName(name, user)](#module_database..getPackageByName) ⇒ object
- * [~getPackageByNameSimple(name)](#module_database..getPackageByNameSimple) ⇒ object
- * [~getPackageVersionByNameAndVersion(name, version)](#module_database..getPackageVersionByNameAndVersion) ⇒ object
- * [~getPackageCollectionByName(packArray)](#module_database..getPackageCollectionByName) ⇒ object
- * [~getPackageCollectionByID(packArray)](#module_database..getPackageCollectionByID) ⇒ object
- * [~updatePackageStargazers(name, pointer)](#module_database..updatePackageStargazers) ⇒ object
- * [~updatePackageIncrementDownloadByName(name)](#module_database..updatePackageIncrementDownloadByName) ⇒ object
- * [~updatePackageDecrementDownloadByName(name)](#module_database..updatePackageDecrementDownloadByName) ⇒ object
- * [~removePackageByName(name, exterminate)](#module_database..removePackageByName) ⇒ object
- * [~removePackageVersion(packName, semVer)](#module_database..removePackageVersion) ⇒ object
- * [~getFeaturedPackages()](#module_database..getFeaturedPackages) ⇒ object
- * [~getFeaturedThemes()](#module_database..getFeaturedThemes) ⇒ object
- * [~getUserByName(username)](#module_database..getUserByName) ⇒ object
- * [~getUserByNodeID(id)](#module_database..getUserByNodeID) ⇒ object
- * [~getUserByID(id)](#module_database..getUserByID) ⇒ object
- * [~updateIncrementStar(user, pack)](#module_database..updateIncrementStar) ⇒ object
- * [~updateDecrementStar(user, pack)](#module_database..updateDecrementStar) ⇒ object
- * [~getStarredPointersByUserID(userid)](#module_database..getStarredPointersByUserID) ⇒ object
- * [~getStarringUsersByPointer(pointer)](#module_database..getStarringUsersByPointer) ⇒ object
- * [~getUserCollectionById(ids)](#module_database..getUserCollectionById) ⇒ object
- * [~getSortedPackages(page, dir, method, [themes])](#module_database..getSortedPackages) ⇒ object
- * [~getOrderField(method, sqlStorage)](#module_database..getOrderField) ⇒ object
\| null
- * [~authStoreStateKey(stateKey)](#module_database..authStoreStateKey) ⇒ object
- * [~authCheckAndDeleteStateKey(stateKey, timestamp)](#module_database..authCheckAndDeleteStateKey) ⇒ object
-
-
-
-### database~setupSQL() ⇒ object
-Initialize the connection to the PostgreSQL database.
-In order to avoid the initialization multiple times,
-the logical nullish assignment (??=) can be used in the caller.
-Exceptions thrown here should be caught and handled in the caller.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- PostgreSQL connection object.
-
-
-### database~shutdownSQL()
-Ensures any Database connection is properly, and safely closed before exiting.
-
-**Kind**: inner method of [database
](#module_database)
-
-
-### database~packageNameAvailability(name) ⇒ object
-Determines if a name is ready to be used for a new package. Useful in the stage of the publication
-of a new package where checking if the package exists is not enough because a name could be not
-available if a deleted package was using it in the past.
-Useful also to check if a name is available for the renaming of a published package.
-This function simply checks if the provided name is present in "names" table.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A Server Status Object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| name | string
| The candidate name for a new package. |
-
-
-
-### database~insertNewPackage(pack) ⇒ object
-Insert a new package inside the DB taking a `Server Object Full` as argument.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A Server Status Object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| pack | object
| The `Server Object Full` package. |
-
-
-
-### database~insertNewPackageVersion(packJSON, oldName) ⇒ object
-Adds a new package version to the db.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| packJSON | object
| A full `package.json` file for the wanted version. |
-| oldName | string
\| null
| If provided, the old name to be replaced for the renaming of the package. |
-
-
-
-### database~applyFeatures(featureObj, packName, packVersion)
-Takes a Feature Object, and applies it's data to the appropriate package
-
-**Kind**: inner method of [database
](#module_database)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| featureObj | object
| The object containing all feature declarations. |
-| featureObj.hasGrammar | boolean
| If present, and true, means this package version provides a grammar. |
-| featureObj.hasSnippets | boolean
| If present, and true, means this package version provides snippets. |
-| featureObj.supportedLanguages | Array.<string>
| If present, defines an array of strings specifying the extensions, or file names supported by this grammar. |
-| packName | string
| The name of the package to be affected. |
-| packVersion | string
| The regular semver version of the package |
-
-
-
-### database~insertNewPackageName(newName, oldName) ⇒ object
-Insert a new package name with the same pointer as the old name.
-This essentially renames an existing package.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-**Todo**
-
-- [ ] This function has been left only for testing purpose since it has been integrated
-inside insertNewPackageVersion, so it should be removed when we can test the rename process
-directly on the endpoint.
-
-
-| Param | Type | Description |
-| --- | --- | --- |
-| newName | string
| The new name to create in the DB. |
-| oldName | string
| The original name of which to use the pointer of. |
-
-
-
-### database~insertNewUser(username, id, avatar) ⇒ object
-Insert a new user into the database.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| username | string
| Username of the user. |
-| id | object
| Identifier code of the user. |
-| avatar | object
| The avatar of the user. |
-
-
-
-### database~getPackageByName(name, user) ⇒ object
-Takes a package name and returns the raw SQL package with all its versions.
-This module is also used to get the data to be sent to utils.constructPackageObjectFull()
-in order to convert the query result in Package Object Full format.
-In that case it's recommended to set the user flag as true for security reasons.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| name | string
| The name of the package. |
-| user | bool
| Whether the packages has to be exposed outside or not. If true, all sensitive data like primary and foreign keys are not selected. Even if the keys are ignored by utils.constructPackageObjectFull(), it's still safe to not inclue them in case, by mistake, we publish the return of this module. |
-
-
-
-### database~getPackageByNameSimple(name) ⇒ object
-Internal util used by other functions in this module to get the package row by the given name.
-It's like getPackageByName(), but with a simple and faster query.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| name | string
| The name of the package. |
-
-
-
-### database~getPackageVersionByNameAndVersion(name, version) ⇒ object
-Uses the name of a package and it's version to return the version info.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| name | string
| The name of the package to query. |
-| version | string
| The version of the package to query. |
-
-
-
-### database~getPackageCollectionByName(packArray) ⇒ object
-Takes a package name array, and returns an array of the package objects.
-You must ensure that the packArray passed is compatible. This function does not coerce compatibility.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| packArray | Array.<string>
| An array of package name strings. |
-
-
-
-### database~getPackageCollectionByID(packArray) ⇒ object
-Takes a package pointer array, and returns an array of the package objects.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| packArray | Array.<int>
| An array of package id. |
-
-
-
-### database~updatePackageStargazers(name, pointer) ⇒ object
-Internal util that uses the package name (or pointer if provided) to update its stargazers count.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- The effected server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| name | string
| The package name. |
-| pointer | string
| The package id (if given, the search by name is skipped). |
-
-
-
-### database~updatePackageIncrementDownloadByName(name) ⇒ object
-Uses the package name to increment the download count by one.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- The modified server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| name | string
| The package name. |
-
-
-
-### database~updatePackageDecrementDownloadByName(name) ⇒ object
-Uses the package name to decrement the download count by one.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- The modified server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| name | string
| The package name. |
-
-
-
-### database~removePackageByName(name, exterminate) ⇒ object
-Given a package name, removes its record alongside its names, versions, stars.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| name | string
| The package name. |
-| exterminate | boolean
| A flag that if true will totally remove the package. Including the normally reserved name. Should never be used in production, enables a supply chain vulnerability. |
-
-
-
-### database~removePackageVersion(packName, semVer) ⇒ object
-Mark a version of a specific package as deleted. This does not delete the record,
-just mark the boolean deleted flag as true, but only if one published version remains available.
-This also makes sure that a new latest version is selected in case the previous one is removed.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| packName | string
| The package name. |
-| semVer | string
| The version to remove. |
-
-
-
-### database~getFeaturedPackages() ⇒ object
-Collects the hardcoded featured packages array from the storage.js
-module. Then uses this.getPackageCollectionByName to retrieve details of the
-package.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-
-### database~getFeaturedThemes() ⇒ object
-Collects the hardcoded featured themes array from the storage.js module.
-Then uses this.getPackageCollectionByName to retrieve details of the package.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-
-### database~getUserByName(username) ⇒ object
-Get a users details providing their username.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| username | string
| User name string. |
-
-
-
-### database~getUserByNodeID(id) ⇒ object
-Get user details providing their Node ID.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| id | string
| Users Node ID. |
-
-
-
-### database~getUserByID(id) ⇒ object
-Get user details providing their ID.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A Server status Object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| id | int
| User ID |
-
-
-
-### database~updateIncrementStar(user, pack) ⇒ object
-Register the star given by a user to a package.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| user | int
| A User Object that should star the package. |
-| pack | string
| Package name that get the new star. |
-
-
-
-### database~updateDecrementStar(user, pack) ⇒ object
-Register the removal of the star on a package by a user.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| user | int
| User Object who remove the star. |
-| pack | string
| Package name that get the star removed. |
-
-
-
-### database~getStarredPointersByUserID(userid) ⇒ object
-Get all packages which the user gave the star.
-The result of this function should not be returned to the user because it contains pointers UUID.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| userid | int
| ID of the user. |
-
-
-
-### database~getStarringUsersByPointer(pointer) ⇒ object
-Use the pointer of a package to collect all users that have starred it.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| pointer | string
| The ID of the package. |
-
-
-
-### database~getUserCollectionById(ids) ⇒ object
-Returns an array of Users and their associated data via the ids.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object with the array of users collected.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| ids | array
| The IDs of users to collect the data of. |
-
-
-
-### database~getSortedPackages(page, dir, method, [themes]) ⇒ object
-Takes the page, direction, and sort method returning the raw sql package
-data for each. This monolithic function handles trunication of the packages,
-and sorting, aiming to provide back the raw data, and allow later functions to
-then reconstruct the JSON as needed.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object containing the results and the pagination object.
-
-| Param | Type | Default | Description |
-| --- | --- | --- | --- |
-| page | int
| | Page number. |
-| dir | string
| | String flag for asc/desc order. |
-| method | string
| | The sort method. |
-| [themes] | boolean
| false
| Optional Parameter to specify if this should only return themes. |
-
-
-
-### database~getOrderField(method, sqlStorage) ⇒ object
\| null
-Internal method to parse the sort method and return the related database field/column.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
\| null
- The string field associated to the sort method or null if the method is not recognized.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| method | string
| The sort method. |
-| sqlStorage | object
| The database class instance used parse the proper field. |
-
-
-
-### database~authStoreStateKey(stateKey) ⇒ object
-Gets a state key from login process and saves it on the database.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| stateKey | string
| The key code string. |
-
-
-
-### database~authCheckAndDeleteStateKey(stateKey, timestamp) ⇒ object
-Gets a state key from oauth process and delete it from the database.
-It's used to verify if the request for the authentication is valid. The code should be first generated in the
-initial stage of the login and then deleted by this function.
-If the deletion is successful, the returned record is used to retrieve the created timestamp of the state key
-and check if it's not expired (considering a specific timeout).
-A custom timestamp can be passed as argument for testing purpose, otherwise the current timestamp is considered.
-
-**Kind**: inner method of [database
](#module_database)
-**Returns**: object
- A server status object.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| stateKey | string
| The key code string to delete. |
-| timestamp | string
| A string in SQL timestamp format to check against the created timestamp of the given state key. If not provided, the current UNIX timestamp is used. |
-
## dev\_server
diff --git a/docs/resources/complexity-report.md b/docs/resources/complexity-report.md
index 37b2fd31..0adea923 100644
--- a/docs/resources/complexity-report.md
+++ b/docs/resources/complexity-report.md
@@ -1,12 +1,12 @@
-# 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%
+# Complexity report, 1/27/2024
+
+* Mean per-function logical LOC: 14.458333333333334
+* Mean per-function parameter count: 0.15916666666666668
+* Mean per-function cyclomatic complexity: 1.2483333333333335
+* Mean per-function Halstead effort: 3318.2315431289767
+* Mean per-module maintainability index: 68.928875276727
+* First-order density: 0.8333333333333334%
+* Change cost: 5.305555555555555%
* Core size: 100%
## /home/runner/work/package-backend/package-backend/jest.config.js
@@ -229,6 +229,36 @@
* Maintainability index: 85.19382950159975
* Dependency count: 27
+## /home/runner/work/package-backend/package-backend/src/database/_constants.js
+
+* Physical LOC: 6
+* Logical LOC: 5
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 20%
+* Maintainability index: 74.35668985133891
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/database/_utils.js
+
+* Physical LOC: 19
+* Logical LOC: 15
+* Mean parameter count: 2
+* Cyclomatic complexity: 6
+* Cyclomatic complexity density: 40%
+* Maintainability index: 65.95338088382414
+* Dependency count: 0
+* Function: **getOrderField**
+ * Line No.: 9
+ * Physical LOC: 15
+ * Logical LOC: 12
+ * Parameter count: 2
+ * Cyclomatic complexity: 6
+ * Cyclomatic complexity density: 50%
+ * Halstead difficulty: 2.25
+ * Halstead volume: 75.28421251514429
+ * Halstead effort: 169.38947815907466
+
## /home/runner/work/package-backend/package-backend/src/models/ssoHTML.js
* Physical LOC: 12
diff --git a/src/database/_clause.js b/src/database/_clause.js
index 68583ce6..70cd8880 100644
--- a/src/database/_clause.js
+++ b/src/database/_clause.js
@@ -79,5 +79,5 @@ module.exports = {
filterClause,
ownerClause,
serviceClause,
- fileExtensionClause
-}
+ fileExtensionClause,
+};
diff --git a/src/database/_constants.js b/src/database/_constants.js
index 27db1b8d..7c7196e2 100644
--- a/src/database/_constants.js
+++ b/src/database/_constants.js
@@ -3,6 +3,6 @@
module.exports = {
defaults: {
engine: { atom: "*" },
- license: "NONE"
- }
+ license: "NONE",
+ },
};
diff --git a/src/database/_export.js b/src/database/_export.js
index fc1bf68b..a706b4c4 100644
--- a/src/database/_export.js
+++ b/src/database/_export.js
@@ -6,14 +6,8 @@
const fs = require("fs");
const postgres = require("postgres");
const logger = require("../logger.js");
-const {
- DB_HOST,
- DB_USER,
- DB_PASS,
- DB_DB,
- DB_PORT,
- DB_SSL_CERT
-} = require("../config.js").getConfig();
+const { DB_HOST, DB_USER, DB_PASS, DB_DB, DB_PORT, DB_SSL_CERT } =
+ require("../config.js").getConfig();
// While the below method of exporting the additional database modules is nonstandard
// it lets us accomplish several things:
@@ -28,27 +22,27 @@ let sqlStorage; // SQL Object to interact with the DB
function setupSQL() {
return process.env.PULSAR_STATUS === "dev" && process.env.MOCK_DB !== "false"
- ? postgres({
- host: DB_HOST,
- username: DB_USER,
- database: DB_DB,
- port: DB_PORT
- })
- : postgres({
- host: DB_HOST,
- username: DB_USER,
- password: DB_PASS,
- database: DB_DB,
- port: DB_PORT,
- ssl: {
- rejectUnauthorized: true,
- ca: fs.readFileSync(DB_SSL_CERT).toString()
- }
- });
+ ? postgres({
+ host: DB_HOST,
+ username: DB_USER,
+ database: DB_DB,
+ port: DB_PORT,
+ })
+ : postgres({
+ host: DB_HOST,
+ username: DB_USER,
+ password: DB_PASS,
+ database: DB_DB,
+ port: DB_PORT,
+ ssl: {
+ rejectUnauthorized: true,
+ ca: fs.readFileSync(DB_SSL_CERT).toString(),
+ },
+ });
}
function getSqlStorage() {
- return sqlStorage ??= setupSQL();
+ return (sqlStorage ??= setupSQL());
}
function wrapper(modToUse) {
@@ -56,22 +50,19 @@ function wrapper(modToUse) {
return async (...args) => {
// Wrap all function calls in a try catch with a singular error handler
try {
-
// Call the function passing the `sqlStorage` object can other provided params
return modToUse.exec(getSqlStorage(), ...args);
-
- } catch(err) {
+ } catch (err) {
// Generic Error Catcher for all database modules
return {
ok: false,
content: "Generic Error",
short: "server_error",
- error: err
+ error: err,
};
-
}
};
-};
+}
const exportObj = {
shutdownSQL: async () => {
@@ -79,7 +70,7 @@ const exportObj = {
await sqlStorage.end();
logger.generic(1, "SQL Server Shutdown!");
}
- }
+ },
};
// Add all other modules here:
diff --git a/src/database/_utils.js b/src/database/_utils.js
index 27304491..d16cffb7 100644
--- a/src/database/_utils.js
+++ b/src/database/_utils.js
@@ -23,5 +23,5 @@ function getOrderField(method, sql) {
}
module.exports = {
- getOrderField
+ getOrderField,
};
diff --git a/src/database/applyFeatures.js b/src/database/applyFeatures.js
index c0d2900d..1b815641 100644
--- a/src/database/applyFeatures.js
+++ b/src/database/applyFeatures.js
@@ -85,5 +85,5 @@ module.exports = {
return {
ok: true,
};
- }
+ },
};
diff --git a/src/database/authCheckAndDeleteStateKey.js b/src/database/authCheckAndDeleteStateKey.js
index d8f387f5..492b0fd0 100644
--- a/src/database/authCheckAndDeleteStateKey.js
+++ b/src/database/authCheckAndDeleteStateKey.js
@@ -52,5 +52,5 @@ module.exports = {
}
return { ok: true, content: command[0].keycode };
- }
+ },
};
diff --git a/src/database/authStoreStateKey.js b/src/database/authStoreStateKey.js
index cd54bce9..17284b24 100644
--- a/src/database/authStoreStateKey.js
+++ b/src/database/authStoreStateKey.js
@@ -22,5 +22,5 @@ module.exports = {
content: `The state key has not been saved on the database.`,
short: "server_error",
};
- }
+ },
};
diff --git a/src/database/getFeaturedPackages.js b/src/database/getFeaturedPackages.js
index ef3566d8..4f8e17d2 100644
--- a/src/database/getFeaturedPackages.js
+++ b/src/database/getFeaturedPackages.js
@@ -8,7 +8,8 @@
*/
const storage = require("../storage.js");
-const getPackageCollectionByName = require("./getPackageCollectionByName.js").exec;
+const getPackageCollectionByName =
+ require("./getPackageCollectionByName.js").exec;
module.exports = {
safe: false,
@@ -20,5 +21,5 @@ module.exports = {
}
return await getPackageCollectionByName(sql, featuredArray.content);
- }
+ },
};
diff --git a/src/database/getFeaturedThemes.js b/src/database/getFeaturedThemes.js
index 908498d6..2b950c09 100644
--- a/src/database/getFeaturedThemes.js
+++ b/src/database/getFeaturedThemes.js
@@ -6,7 +6,8 @@
* @returns {object} A server status object.
*/
const storage = require("../storage.js");
-const getPackageCollectionByName = require("./getPackageCollectionByName.js").exec;
+const getPackageCollectionByName =
+ require("./getPackageCollectionByName.js").exec;
module.exports = {
safe: false,
@@ -18,5 +19,5 @@ module.exports = {
}
return await getPackageCollectionByName(sql, featuredThemeArray.content);
- }
+ },
};
diff --git a/src/database/getPackageByName.js b/src/database/getPackageByName.js
index 0f68747c..e0bc60a1 100644
--- a/src/database/getPackageByName.js
+++ b/src/database/getPackageByName.js
@@ -25,9 +25,7 @@ module.exports = {
JSONB_AGG(
JSON_BUILD_OBJECT(
${
- user
- ? sql``
- : sql`'id', v.id, 'package', v.package,`
+ user ? sql`` : sql`'id', v.id, 'package', v.package,`
} 'semver', v.semver, 'license', v.license, 'engine', v.engine, 'meta', v.meta,
'hasGrammar', v.has_grammar, 'hasSnippets', v.has_snippets,
'supportedLanguages', v.supported_languages
@@ -47,5 +45,5 @@ module.exports = {
content: `package ${name} not found.`,
short: "not_found",
};
- }
+ },
};
diff --git a/src/database/getPackageByNameSimple.js b/src/database/getPackageByNameSimple.js
index 65e5f796..4013fdc2 100644
--- a/src/database/getPackageByNameSimple.js
+++ b/src/database/getPackageByNameSimple.js
@@ -22,5 +22,5 @@ module.exports = {
content: `Package ${name} not found.`,
short: "not_found",
};
- }
+ },
};
diff --git a/src/database/getPackageCollectionByID.js b/src/database/getPackageCollectionByID.js
index ecb31d48..3400c4da 100644
--- a/src/database/getPackageCollectionByID.js
+++ b/src/database/getPackageCollectionByID.js
@@ -21,5 +21,5 @@ module.exports = {
return command.count !== 0
? { ok: true, content: command }
: { ok: false, content: "No packages found.", short: "Not Found" };
- }
+ },
};
diff --git a/src/database/getPackageCollectionByName.js b/src/database/getPackageCollectionByName.js
index 5ab58058..3c94a44b 100644
--- a/src/database/getPackageCollectionByName.js
+++ b/src/database/getPackageCollectionByName.js
@@ -27,5 +27,5 @@ module.exports = {
return command.count !== 0
? { ok: true, content: command }
: { ok: false, content: "No packages found.", short: "not_found" };
- }
+ },
};
diff --git a/src/database/getPackageVersionByNameAndVersion.js b/src/database/getPackageVersionByNameAndVersion.js
index 2c7bc68c..ec786451 100644
--- a/src/database/getPackageVersionByNameAndVersion.js
+++ b/src/database/getPackageVersionByNameAndVersion.js
@@ -24,5 +24,5 @@ module.exports = {
content: `Package ${name} and Version ${version} not found.`,
short: "not_found",
};
- }
+ },
};
diff --git a/src/database/getSortedPackages.js b/src/database/getSortedPackages.js
index fa6658de..9e4113f6 100644
--- a/src/database/getSortedPackages.js
+++ b/src/database/getSortedPackages.js
@@ -48,7 +48,11 @@ module.exports = {
INNER JOIN versions AS v ON (p.pointer = v.package AND v.deleted IS FALSE
${clause.queryClause(sql, opts)}
${clause.filterClause(sql, opts)}
- ${themes === true ? clause.filterClause(sql, { filter: "theme" }) : sql``})
+ ${
+ themes === true
+ ? clause.filterClause(sql, { filter: "theme" })
+ : sql``
+ })
WHERE p.name IS NOT NULL
@@ -60,9 +64,7 @@ module.exports = {
)
SELECT *, COUNT(*) OVER() AS query_result_count
FROM latest_versions
- ORDER BY ${orderType} ${
- opts.direction === "desc" ? sql`DESC` : sql`ASC`
- }
+ ORDER BY ${orderType} ${opts.direction === "desc" ? sql`DESC` : sql`ASC`}
LIMIT ${limit}
OFFSET ${offset};
`;
@@ -82,5 +84,5 @@ module.exports = {
limit,
},
};
- }
+ },
};
diff --git a/src/database/getStarredPointersByUserID.js b/src/database/getStarredPointersByUserID.js
index 77f03c65..af8b36b9 100644
--- a/src/database/getStarredPointersByUserID.js
+++ b/src/database/getStarredPointersByUserID.js
@@ -25,5 +25,5 @@ module.exports = {
: [];
return { ok: true, content: packArray };
- }
+ },
};
diff --git a/src/database/getStarringUsersByPointer.js b/src/database/getStarringUsersByPointer.js
index 9c5cd739..9e8e308f 100644
--- a/src/database/getStarringUsersByPointer.js
+++ b/src/database/getStarringUsersByPointer.js
@@ -31,5 +31,5 @@ module.exports = {
}
return { ok: true, content: userArray };
- }
+ },
};
diff --git a/src/database/getUserByID.js b/src/database/getUserByID.js
index 87f456a3..2f6f4c31 100644
--- a/src/database/getUserByID.js
+++ b/src/database/getUserByID.js
@@ -29,5 +29,5 @@ module.exports = {
content: `Unable to get user by ID: ${id}`,
short: "server_error",
};
- }
+ },
};
diff --git a/src/database/getUserByName.js b/src/database/getUserByName.js
index f41a7ad4..333eda37 100644
--- a/src/database/getUserByName.js
+++ b/src/database/getUserByName.js
@@ -21,5 +21,5 @@ module.exports = {
content: `Unable to query for user: ${username}`,
short: "not_found",
};
- }
+ },
};
diff --git a/src/database/getUserByNodeID.js b/src/database/getUserByNodeID.js
index 885c1365..29fc5929 100644
--- a/src/database/getUserByNodeID.js
+++ b/src/database/getUserByNodeID.js
@@ -29,5 +29,5 @@ module.exports = {
content: `Unable to get User By NODE_ID: ${id}`,
short: "server_error",
};
- }
+ },
};
diff --git a/src/database/getUserCollectionById.js b/src/database/getUserCollectionById.js
index 134eaf05..f038c23a 100644
--- a/src/database/getUserCollectionById.js
+++ b/src/database/getUserCollectionById.js
@@ -33,5 +33,5 @@ module.exports = {
}
return { ok: true, content: userArray };
- }
+ },
};
diff --git a/src/database/insertNewPackage.js b/src/database/insertNewPackage.js
index 9709d16f..5e9f330d 100644
--- a/src/database/insertNewPackage.js
+++ b/src/database/insertNewPackage.js
@@ -109,5 +109,5 @@ module.exports = {
error: err,
};
});
- }
+ },
};
diff --git a/src/database/insertNewPackageName.js b/src/database/insertNewPackageName.js
index 9ae2b4d0..6b25f785 100644
--- a/src/database/insertNewPackageName.js
+++ b/src/database/insertNewPackageName.js
@@ -76,5 +76,5 @@ module.exports = {
error: err,
};
});
- }
+ },
};
diff --git a/src/database/insertNewPackageVersion.js b/src/database/insertNewPackageVersion.js
index 439abfc3..e4667d14 100644
--- a/src/database/insertNewPackageVersion.js
+++ b/src/database/insertNewPackageVersion.js
@@ -102,7 +102,8 @@ module.exports = {
// The only requirement is that the provided semver is not already present
// in the database for the targeted package.
- const license = packJSON.metadata.license ?? _constants.defaults.license;
+ const license =
+ packJSON.metadata.license ?? _constants.defaults.license;
const engine = packJSON.metadata.engines ?? _constants.defaults.engine;
let addVer = {};
@@ -155,5 +156,5 @@ module.exports = {
error: err,
};
});
- }
+ },
};
diff --git a/src/database/insertNewUser.js b/src/database/insertNewUser.js
index ecc544f8..e951adea 100644
--- a/src/database/insertNewUser.js
+++ b/src/database/insertNewUser.js
@@ -24,5 +24,5 @@ module.exports = {
content: `Unable to create user: ${username}`,
short: "Server Error",
};
- }
+ },
};
diff --git a/src/database/packageNameAvailability.js b/src/database/packageNameAvailability.js
index ab9ff205..39d516f6 100644
--- a/src/database/packageNameAvailability.js
+++ b/src/database/packageNameAvailability.js
@@ -21,13 +21,12 @@ module.exports = {
return command.count === 0
? {
ok: true,
- content: `${name} is available to be used for a new package.`
+ content: `${name} is available to be used for a new package.`,
}
: {
ok: false,
content: `${name} is not available to be used for a new package.`,
- short: "not_found"
+ short: "not_found",
};
-
- }
+ },
};
diff --git a/src/database/removePackageByName.js b/src/database/removePackageByName.js
index 259ed14e..57b83a01 100644
--- a/src/database/removePackageByName.js
+++ b/src/database/removePackageByName.js
@@ -14,70 +14,70 @@ const getPackageByNameSimple = require("./getPackageByNameSimple.js").exec;
module.exports = {
safe: false,
exec: async (sql, name, exterminate = false) => {
- return await sql
- .begin(async (sqlTrans) => {
- // Retrieve the package pointer
- const packID = await getPackageByNameSimple(sql, name);
+ return await sql
+ .begin(async (sqlTrans) => {
+ // Retrieve the package pointer
+ const packID = await getPackageByNameSimple(sql, name);
- if (!packID.ok) {
- // The package does not exist, but we return ok since it's like
- // it has been deleted.
- return { ok: true, content: `${name} package does not exist.` };
- }
+ if (!packID.ok) {
+ // The package does not exist, but we return ok since it's like
+ // it has been deleted.
+ return { ok: true, content: `${name} package does not exist.` };
+ }
- const pointer = packID.content.pointer;
+ const pointer = packID.content.pointer;
- // Remove versions of the package
- const commandVers = await sqlTrans`
+ // Remove versions of the package
+ const commandVers = await sqlTrans`
DELETE FROM versions
WHERE package = ${pointer}
RETURNING semver;
`;
- if (commandVers.count === 0) {
- throw `Failed to delete any versions for: ${name}`;
- }
+ if (commandVers.count === 0) {
+ throw `Failed to delete any versions for: ${name}`;
+ }
- // Remove stars assigned to the package
- await sqlTrans`
+ // Remove stars assigned to the package
+ await sqlTrans`
DELETE FROM stars
WHERE package = ${pointer}
RETURNING userid;
`;
- const commandPack = await sqlTrans`
+ const commandPack = await sqlTrans`
DELETE FROM packages
WHERE pointer = ${pointer}
RETURNING name;
`;
- if (commandPack.count === 0) {
- // nothing was returning, the delete probably failed
- throw `Failed to Delete Package for: ${name}`;
- }
+ if (commandPack.count === 0) {
+ // nothing was returning, the delete probably failed
+ throw `Failed to Delete Package for: ${name}`;
+ }
- if (commandPack[0].name !== name) {
- throw `Attempted to delete ${commandPack[0].name} rather than ${name}`;
- }
+ if (commandPack[0].name !== name) {
+ throw `Attempted to delete ${commandPack[0].name} rather than ${name}`;
+ }
- if (exterminate) {
- await sqlTrans`
+ if (exterminate) {
+ await sqlTrans`
DELETE FROM names
WHERE pointer = ${pointer}
`; // We can't return name here, since it's set to null on package deletion
- }
+ }
- return { ok: true, content: `Successfully Deleted Package: ${name}` };
- })
- .catch((err) => {
- return typeof err === "string"
- ? { ok: false, content: err, short: "server_error" }
- : {
- ok: false,
- content: `A generic error occurred while inserting ${name} package`,
- short: "server_error",
- error: err,
- };
- });
- }
+ return { ok: true, content: `Successfully Deleted Package: ${name}` };
+ })
+ .catch((err) => {
+ return typeof err === "string"
+ ? { ok: false, content: err, short: "server_error" }
+ : {
+ ok: false,
+ content: `A generic error occurred while inserting ${name} package`,
+ short: "server_error",
+ error: err,
+ };
+ });
+ },
};
diff --git a/src/database/removePackageVersion.js b/src/database/removePackageVersion.js
index 196cf49e..c66345f1 100644
--- a/src/database/removePackageVersion.js
+++ b/src/database/removePackageVersion.js
@@ -74,5 +74,5 @@ module.exports = {
error: err,
};
});
- }
+ },
};
diff --git a/src/database/updateDecrementStar.js b/src/database/updateDecrementStar.js
index 385c1bb6..5ce0f03a 100644
--- a/src/database/updateDecrementStar.js
+++ b/src/database/updateDecrementStar.js
@@ -64,5 +64,5 @@ module.exports = {
ok: true,
content: "Package Successfully Unstarred",
};
- }
+ },
};
diff --git a/src/database/updateIncrementStar.js b/src/database/updateIncrementStar.js
index a72b94c0..f1b9158a 100644
--- a/src/database/updateIncrementStar.js
+++ b/src/database/updateIncrementStar.js
@@ -68,5 +68,5 @@ module.exports = {
content: `Package Already Starred`,
};
}
- }
+ },
};
diff --git a/src/database/updatePackageDecrementDownloadByName.js b/src/database/updatePackageDecrementDownloadByName.js
index b16416c3..b68b62f1 100644
--- a/src/database/updatePackageDecrementDownloadByName.js
+++ b/src/database/updatePackageDecrementDownloadByName.js
@@ -24,5 +24,5 @@ module.exports = {
content: "Unable to decrement Package Download Count",
short: "server_error",
};
- }
+ },
};
diff --git a/src/database/updatePackageIncrementDownloadByName.js b/src/database/updatePackageIncrementDownloadByName.js
index 62f9ae88..bccb9a86 100644
--- a/src/database/updatePackageIncrementDownloadByName.js
+++ b/src/database/updatePackageIncrementDownloadByName.js
@@ -24,5 +24,5 @@ module.exports = {
content: "Unable to Update Package Download",
short: "Server Error",
};
- }
+ },
};
diff --git a/src/database/updatePackageStargazers.js b/src/database/updatePackageStargazers.js
index aa1a4b7e..2b6fb8d2 100644
--- a/src/database/updatePackageStargazers.js
+++ b/src/database/updatePackageStargazers.js
@@ -44,5 +44,5 @@ module.exports = {
content: "Unable to Update Package Stargazers",
short: "server_error",
};
- }
+ },
};
diff --git a/tests/http/getPackagesPackageName.test.js b/tests/http/getPackagesPackageName.test.js
index f9642b84..375f7ed7 100644
--- a/tests/http/getPackagesPackageName.test.js
+++ b/tests/http/getPackagesPackageName.test.js
@@ -5,7 +5,6 @@ const context = require("../../src/context.js");
const genPackage = require("../helpers/package.jest.js");
describe("Behaves as expected", () => {
-
test("Returns 'not_found' when package doesn't exist", async () => {
const sso = await endpoint.logic(
{
diff --git a/tests/http/getUsersLogin.test.js b/tests/http/getUsersLogin.test.js
index cd30303b..68633530 100644
--- a/tests/http/getUsersLogin.test.js
+++ b/tests/http/getUsersLogin.test.js
@@ -4,7 +4,6 @@ const context = require("../../src/context.js");
const userObject = require("../models/userObjectPublic.js");
describe("Behaves as expected", () => {
-
test("Returns bad SSO on failure", async () => {
const userName = "our-test-user";