Skip to content

Commit

Permalink
Add JSDocs for at least some type safety
Browse files Browse the repository at this point in the history
  • Loading branch information
benjervis committed Dec 16, 2024
1 parent ba68e19 commit b058bc4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/runtimes/js/src/helpers/bundle-url-common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Get the URL without the filename (last / segment)
/** Get the URL without the filename (last / segment)
*
* @param {string} url
* @returns {string} The URL with the file name removed
*/
function getBaseURL(url) {
return url.slice(0, url.lastIndexOf('/')) + '/';
}
Expand Down
9 changes: 9 additions & 0 deletions packages/runtimes/js/src/helpers/bundle-url-shards.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ const {getBaseURL, stackTraceUrlRegexp} = require('./bundle-url-common');

const bundleURL = {};

/**
* Retrieves the sharded bundle URL based on the bundle name and the maximum number of shards.
*
* @param {string} bundleName - The file name of the requested bundle.
* @param {number} maxShards - The maximum number of domain shards available.
* @param {Error} inputError - An error object to extract the stack trace from
* (for testing purposes).
* @returns {string} The URL of the sharded bundle, without file name.
*/
function getShardedBundleURL(bundleName, maxShards, inputError) {
let value = bundleURL[bundleName];

Expand Down
11 changes: 11 additions & 0 deletions packages/runtimes/js/src/helpers/bundle-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ const {getBaseURL, stackTraceUrlRegexp} = require('./bundle-url-common');

const bundleURL = {};

/**
* Retrieves the cached bundle URL for a given identifier.
* If the URL is not cached, it computes and stores it in the cache.
*
* @param {string} id - The identifier for the bundle.
* @returns {string} The URL of the bundle, without file name.
*/
function getBundleURLCached(id) {
let value = bundleURL[id];

Expand All @@ -28,6 +35,10 @@ function getBundleURL() {
return '/';
}

/**
* @param {string} url
* @returns {string}
*/
function getOrigin(url) {
return new URL(url).origin;
}
Expand Down

0 comments on commit b058bc4

Please sign in to comment.