Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate type definitions from JSDoc #293

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{*.json,.stylelintrc,.eslintrc,.babelrc}]
[{*.yml,*.json,.stylelintrc,.eslintrc,.babelrc}]
indent_size = 2
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
coverage/
example/
dist/
94 changes: 49 additions & 45 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
name: Release and Publish

on:
push:
branches:
- master
- alpha
- beta
- next
push:
branches:
- master
- alpha
- beta
- next

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: npm install
run: |
npm install
- name: npm lint
run: |
npm run lint
- name: npm test
run: |
npm test

release:
name: Release
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: npm install
run: |
npm install
- name: npx semantic-release
run: |
npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: npm install
run: npm install

- name: npm lint
run: npm run lint

- name: npm test
run: npm test

- name: Typecheck
run: npm run types

release:
name: Release
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: npm install
run: npm install

- name: Generate type definitions
run: npm run types

- name: npx semantic-release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
50 changes: 23 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,26 @@ name: Run Lint and Tests
on: push

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: |
npm install
env:
CI: true
- name: npm lint
run: |
npm run lint
env:
CI: true
- name: npm test
run: |
npm test
env:
CI: true
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: npm install

- name: npm lint
run: npm run lint

- name: npm test
run: npm test

- name: Typecheck
run: npm run types
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ coverage/
node_modules/
*.log
.vscode
dist/
.tap
types/
81 changes: 0 additions & 81 deletions example/server.js

This file was deleted.

52 changes: 39 additions & 13 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import * as schemas from '@podium/schemas';
import * as utils from '@podium/utils';
import Proxy from 'http-proxy';

/**
* @typedef {object} PodiumProxyOptions
* @property {string} [pathname="/"]
* @property {string} [prefix="/podium-resource"]
* @property {number} [timeout=20000]
* @property {number} [maxAge=Infinity]
* @property {import('abslog').AbstractLoggerOptions | null} [logger=null]
*/

export default class PodiumProxy {
#pathname;
#prefix;
Expand All @@ -16,6 +25,11 @@ export default class PodiumProxy {
#histogram;
#pathnameEntries;
#pathnameParser;

/**
* @constructor
* @param {PodiumProxyOptions} options
*/
constructor({
pathname = '/',
prefix = '/podium-resource',
Expand All @@ -27,18 +41,21 @@ export default class PodiumProxy {
this.#log = abslog(logger);

this.#pathnameEntries = [];
this.#pathnameParser = pathToRegexp(utils.pathnameBuilder(
this.#pathname,
this.#prefix,
':podiumPodletName',
':podiumProxyName',
':podiumProxyExtras*',
), this.#pathnameEntries);

// eslint-disable-next-line new-cap
this.#proxy = new Proxy.createProxy({
this.#pathnameParser = pathToRegexp(
utils.pathnameBuilder(
this.#pathname,
this.#prefix,
':podiumPodletName',
':podiumProxyName',
':podiumProxyExtras*',
),
this.#pathnameEntries,
);

this.#proxy = Proxy.createProxy({
proxyTimeout: timeout,
});

this.#proxy.on('error', (error) => {
this.#log.error(
'Error emitted by proxy in @podium/proxy module',
Expand Down Expand Up @@ -84,7 +101,12 @@ export default class PodiumProxy {
return this.#registry;
}

register(name = '', manifest = {}) {
/**
* Register a podlet in the proxy. This will read the proxy configuration from the manifest.
* @param {string} name
* @param {import('@podium/schemas').PodletManifestSchema} manifest
*/
register(name, manifest) {
if (schemas.name(name).error)
throw new Error(
'The value for the required argument "name" is not defined or not valid.',
Expand Down Expand Up @@ -117,7 +139,7 @@ export default class PodiumProxy {
// and the manifest only support an array for the proxy property.
Object.keys(obj.proxy).forEach((key) => {
this.#registry.set(`${name}/${key}`, obj.proxy[key]);

const path = utils.pathnameBuilder(
this.#pathname,
this.#prefix,
Expand All @@ -131,6 +153,10 @@ export default class PodiumProxy {
}
}

/**
* @param {import('@podium/utils').HttpIncoming} incoming
* @returns {Promise<import('@podium/utils').HttpIncoming | undefined>} The incoming request with the `.proxy` property set to true if successfully proxied, or `undefined` if the incoming request didn't match anything registered in the proxy.
*/
process(incoming) {
if (
Object.prototype.toString.call(incoming) !==
Expand Down Expand Up @@ -264,4 +290,4 @@ export default class PodiumProxy {
get [Symbol.toStringTag]() {
return 'PodiumProxy';
}
};
}
Loading