Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: podium-lib/utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.0.5
Choose a base ref
...
head repository: podium-lib/utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.0.6
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on May 13, 2024

  1. fix: add back generics to httpincoming (#237)

    Disappeared in the JSDoc rewrite
    wkillerud authored May 13, 2024
    Copy the full SHA
    4c70da7 View commit details
  2. chore(release): 5.0.6 [skip ci]

    ## [5.0.6](v5.0.5...v5.0.6) (2024-05-13)
    
    ### Bug Fixes
    
    * add back generics to httpincoming ([#237](#237)) ([4c70da7](4c70da7))
    semantic-release-bot committed May 13, 2024
    Copy the full SHA
    1d6b5a6 View commit details
Showing with 33 additions and 4 deletions.
  1. +7 −0 CHANGELOG.md
  2. +10 −3 lib/http-incoming.js
  3. +1 −1 package.json
  4. +15 −0 tests/http-incoming.test.js
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [5.0.6](https://github.com/podium-lib/utils/compare/v5.0.5...v5.0.6) (2024-05-13)


### Bug Fixes

* add back generics to httpincoming ([#237](https://github.com/podium-lib/utils/issues/237)) ([4c70da7](https://github.com/podium-lib/utils/commit/4c70da7699e05321005575105ea3d99673b9a07d))

## [5.0.5](https://github.com/podium-lib/utils/compare/v5.0.4...v5.0.5) (2024-05-07)


13 changes: 10 additions & 3 deletions lib/http-incoming.js
Original file line number Diff line number Diff line change
@@ -10,18 +10,20 @@ const urlFromRequest = (request) => {
};

/**
* @template {Record<string, unknown>} [T=Record<string, unknown>]
* @typedef {object} PodiumHttpIncoming
* @property {string} name
* @property {object} context
* @property {object} view
* @property {URL} url
* @property {Array<import('./asset-css.js').CssAsset | string>} css
* @property {Array<import('./asset-js.js').JavaScriptAsset | string>} js
* @property {object} [params]
* @property {T} [params]
* @property {boolean} [development]
* @property {boolean} [proxy]
*/

/** @template {Record<string, unknown>} [T=Record<string, unknown>] */
export default class HttpIncoming {
#development;
#response;
@@ -48,15 +50,17 @@ export default class HttpIncoming {
#js;

/**
* @constructor
* @param {object} [request={}] The incoming HTTP request
* @param {object} [response={}] The HTTP response
* @param {object} [params={}] Parameters such as locale. Typically res.locals.
* @param {T} [params={}] Parameters such as locale. Typically res.locals.
*
* @example
* ```js
* const incoming = new HttpIncoming(req, res, res.locals);
* ```
*/
// @ts-expect-error Not happy about the generics, but this is safe
constructor(request = {}, response = {}, params = {}) {
this.#development = false;
this.#response = response;
@@ -143,6 +147,9 @@ export default class HttpIncoming {
throw new Error('Cannot set read-only property.');
}

/**
* @returns {T}
*/
get params() {
return this.#params;
}
@@ -201,7 +208,7 @@ export default class HttpIncoming {
}

/**
* @returns {PodiumHttpIncoming}
* @returns {PodiumHttpIncoming<T>}
*/
toJSON() {
return {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@podium/utils",
"version": "5.0.5",
"version": "5.0.6",
"description": "Common generic utility methods shared by @podium modules.",
"type": "module",
"license": "MIT",
15 changes: 15 additions & 0 deletions tests/http-incoming.test.js
Original file line number Diff line number Diff line change
@@ -125,6 +125,7 @@ tap.test('PodiumHttpIncoming.params - set value', (t) => {
const incoming = new HttpIncoming(ADVANCED_REQ, SIMPLE_RES);
t.throws(
() => {
// @ts-ignore Testing bad input
incoming.params = 'foo';
},
/Cannot set read-only property./,
@@ -311,3 +312,17 @@ tap.test(
t.end();
},
);

tap.test('generic typing works as expected', (t) => {
// really only here for tsc

/**
* @template {{ [key: string]: unknown }} T
* @param {( incoming: HttpIncoming<T>, fragment: string, ...args: unknown[]) => string} fn
* @returns {void}
*/
// eslint-disable-next-line no-unused-vars
function view(fn) {}
t.ok(view);
t.end();
});