From 69c54a5b5bdd4806d24a06fdfa1db8ca5be24634 Mon Sep 17 00:00:00 2001 From: hugoalh <32359235+hugoalh@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:04:44 +0800 Subject: [PATCH] Update workflow --- .../announce-new-release-discord.yml | 2 +- .github/workflows/codeql-analysis.yml | 8 +- ...nodejs-publish-npm.yml => publish-npm.yml} | 10 +- .github/workflows/scan-virus.yml | 4 +- .github/workflows/sync-labels.yml | 8 +- dist/exfetch.d.ts | 360 --------------- dist/exfetch.d.ts.map | 1 - dist/exfetch.js | 411 ------------------ dist/header/link.d.ts | 69 --- dist/header/link.d.ts.map | 1 - dist/header/link.js | 259 ----------- dist/header/retry-after.d.ts | 27 -- dist/header/retry-after.d.ts.map | 1 - dist/header/retry-after.js | 67 --- dist/main.d.ts | 4 - dist/main.d.ts.map | 1 - dist/main.js | 3 - package.json | 3 + 18 files changed, 19 insertions(+), 1220 deletions(-) rename .github/workflows/{nodejs-publish-npm.yml => publish-npm.yml} (56%) delete mode 100644 dist/exfetch.d.ts delete mode 100644 dist/exfetch.d.ts.map delete mode 100644 dist/exfetch.js delete mode 100644 dist/header/link.d.ts delete mode 100644 dist/header/link.d.ts.map delete mode 100644 dist/header/link.js delete mode 100644 dist/header/retry-after.d.ts delete mode 100644 dist/header/retry-after.d.ts.map delete mode 100644 dist/header/retry-after.js delete mode 100644 dist/main.d.ts delete mode 100644 dist/main.d.ts.map delete mode 100644 dist/main.js diff --git a/.github/workflows/announce-new-release-discord.yml b/.github/workflows/announce-new-release-discord.yml index ae53734..1256df3 100644 --- a/.github/workflows/announce-new-release-discord.yml +++ b/.github/workflows/announce-new-release-discord.yml @@ -4,10 +4,10 @@ on: release: types: - "published" -permissions: {} jobs: main: name: "Main" + permissions: {} runs-on: "ubuntu-latest" steps: - name: "Send Discord Webhook" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 14b61c4..33f7a43 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,5 +1,5 @@ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json -name: "CodeQL - Analysis" +name: "CodeQL Analysis" on: push: branches: @@ -13,10 +13,10 @@ on: - "reopened" - "synchronize" workflow_dispatch: -permissions: - contents: "read" - security-events: "write" jobs: main: name: "Main" + permissions: + contents: "read" + security-events: "write" uses: "hugoalh/hugoalh/.github/workflows/call-codeql-analysis-0.yml@main" diff --git a/.github/workflows/nodejs-publish-npm.yml b/.github/workflows/publish-npm.yml similarity index 56% rename from .github/workflows/nodejs-publish-npm.yml rename to .github/workflows/publish-npm.yml index ff9ff4c..f7d3c81 100644 --- a/.github/workflows/nodejs-publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -1,15 +1,15 @@ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json -name: "NodeJS - Publish - NPM" +name: "Publish NPM" on: release: types: - "published" -permissions: - contents: "write" - id-token: "write" jobs: main: name: "Main" - uses: "hugoalh/hugoalh/.github/workflows/call-nodejs-publish-npm-0.yml@main" + permissions: + contents: "write" + id-token: "write" + uses: "hugoalh/hugoalh/.github/workflows/call-publish-npm-0.yml@main" secrets: NPM_TOKEN: "${{secrets.NPM_TOKEN}}" diff --git a/.github/workflows/scan-virus.yml b/.github/workflows/scan-virus.yml index 13ef8f6..2b2c176 100644 --- a/.github/workflows/scan-virus.yml +++ b/.github/workflows/scan-virus.yml @@ -35,11 +35,11 @@ on: options: - "False" - "True" -permissions: - contents: "read" jobs: main: name: "Main" + permissions: + contents: "read" uses: "hugoalh/hugoalh/.github/workflows/call-scan-virus-0.yml@main" with: git_integrate: "${{github.event.inputs.git_integrate || 'False'}}" diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index f81f1b7..52ea791 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -7,11 +7,11 @@ on: paths: - ".github/labels.yml" workflow_dispatch: -permissions: - contents: "read" - issues: "write" - pull-requests: "write" jobs: main: name: "Main" + permissions: + contents: "read" + issues: "write" + pull-requests: "write" uses: "hugoalh/hugoalh/.github/workflows/call-sync-labels-0.yml@main" diff --git a/dist/exfetch.d.ts b/dist/exfetch.d.ts deleted file mode 100644 index 3e066cb..0000000 --- a/dist/exfetch.d.ts +++ /dev/null @@ -1,360 +0,0 @@ -import { HTTPHeaderLink } from "./header/link.js"; -/** - * exFetch HTTP status codes that retryable. - */ -export declare const httpStatusCodesRetryable: readonly number[]; -/** - * exFetch default user agent. - */ -export declare const userAgentDefault: string; -/** - * @access private - */ -interface ExFetchDelayOptionsInternal { - /** - * Maximum time per delay, by milliseconds. - */ - maximum: number; - /** - * Minimum time per delay, by milliseconds. - */ - minimum: number; -} -/** - * exFetch delay options. - */ -export interface ExFetchDelayOptions extends Partial { - /** @alias maximum */ max?: this["maximum"]; - /** @alias minimum */ min?: this["minimum"]; -} -/** - * exFetch event common payload. - * @access private - */ -interface ExFetchEventCommonPayload { - /** - * Status code of the current response. - */ - statusCode: Response["status"]; - /** - * Status text of the current response. - */ - statusText: Response["statusText"]; -} -/** - * exFetch paginate event payload. - */ -export interface ExFetchEventPaginatePayload { - /** - * Current count of the paginates, begin from `1`. - */ - countCurrent: number; - /** - * Maximum number of the paginates allowed. - */ - countMaximum: number; - /** - * Will paginate to the next page after this amount of time, by milliseconds. - */ - paginateAfter: number; - /** - * Will paginate to this URL. - */ - paginateURL: URL; -} -/** - * exFetch redirect event payload. - */ -export interface ExFetchEventRedirectPayload extends ExFetchEventCommonPayload { - /** - * Current count of the redirects, begin from `1`. - */ - countCurrent: number; - /** - * Maximum number of the redirects allowed. - */ - countMaximum: number; - /** - * Will redirect after this amount of time, by milliseconds. - */ - redirectAfter: number; - /** - * Will redirect to this URL. - */ - redirectURL: URL; -} -/** - * exFetch retry event payload. - */ -export interface ExFetchEventRetryPayload extends ExFetchEventCommonPayload { - /** - * Current count of the retries, begin from `1`. - */ - countCurrent: number; - /** - * Maximum number of the retries allowed. - */ - countMaximum: number; - /** - * Will retry after this amount of time, by milliseconds. - */ - retryAfter: number; - /** - * Will retry this URL. - */ - retryURL: URL; -} -/** - * exFetch paginate link up payload. - */ -export interface ExFetchPaginateLinkUpPayload { - /** - * Header link of the current page. - */ - currentHeaderLink: HTTPHeaderLink; - /** - * URL of the current page. - */ - currentURL: URL; -} -/** - * @access private - */ -interface ExFetchPaginateOptionsInternal { - /** - * Amount of time to delay between the paginates, by milliseconds. - */ - delay: ExFetchDelayOptionsInternal; - /** - * Custom function for correctly link up to the next page, useful for the endpoints which not correctly return an absolute or relative URL. - * @param {ExFetchPaginateLinkUpPayload} param Link up payload of the paginate. - * @returns {URL | null | undefined} URL of the next page. - */ - linkUpNextPage: (param: ExFetchPaginateLinkUpPayload) => URL | null | undefined; - /** - * Maximum amount of paginates to allow. - * @default Infinity // Unlimited - */ - maximum: number; - /** - * Event listener for the paginates. - * @param {ExFetchEventPaginatePayload} param Event payload of the paginate. - * @returns {void} - */ - onEvent?: (param: ExFetchEventPaginatePayload) => void; - /** - * Whether to throw an error when the latest page response provide an invalid HTTP header `Link`. - * @default true - */ - throwOnInvalidHeaderLink: boolean; -} -/** - * exFetch paginate options. - */ -export interface ExFetchPaginateOptions extends Partial> { - /** - * Amount of time to delay between the paginates, by milliseconds. - * @default 0 - */ - delay?: number | ExFetchDelayOptions; -} -/** - * @access private - */ -interface ExFetchRedirectOptionsInternal { - /** - * Amount of time to delay between the redirects, by milliseconds. - */ - delay: ExFetchDelayOptionsInternal; - /** - * Maximum amount of redirects to allow. - * @default Infinity - */ - maximum: number; - /** - * Event listener for the redirects. - * @param {ExFetchEventRedirectPayload} param Event payload of the redirect. - * @returns {void} - */ - onEvent?: (param: ExFetchEventRedirectPayload) => void; -} -/** - * exFetch redirect options. - */ -export interface ExFetchRedirectOptions extends Partial> { - /** - * Amount of time to delay between the redirects, by milliseconds. - * @default 0 - */ - delay?: number | ExFetchDelayOptions; -} -/** - * @access private - */ -interface ExFetchRetryOptionsInternal { - /** - * Amount of time to delay between the attempts, by milliseconds. This only apply when the endpoint have not provide any retry information in the response. - */ - delay: ExFetchDelayOptionsInternal; - /** - * Maximum amount of attempts to allow. - * @default 4 - */ - maximum: number; - /** - * Event listener for the retries. - * @param {ExFetchEventRetryPayload} param Event payload of the retry. - * @returns {void} - */ - onEvent?: (param: ExFetchEventRetryPayload) => void; -} -/** - * exFetch retry options. - */ -export interface ExFetchRetryOptions extends Partial> { - /** - * Amount of time to delay between the attempts, by milliseconds. This only apply when the endpoint have not provide any retry information in the response. - * @default - * { - * maximum: 60000, - * minimum: 1000 - * } - */ - delay?: number | ExFetchDelayOptions; -} -/** - * exFetch options. - */ -export interface ExFetchOptions { - /** - * Custom HTTP status codes that retryable. - * - * WARNING: This will override the default when defined; To add and/or delete some of the HTTP status codes, use methods `addHTTPStatusCodeRetryable` and/or `deleteHTTPStatusCodeRetryable` instead. - * @default undefined - */ - httpStatusCodesRetryable?: number[] | Set; - /** - * Paginate options. - */ - paginate?: ExFetchPaginateOptions; - /** - * Redirect options. This only apply when define property `redirect` as `"follow"` in the request, and define property `maximum` in this option. - */ - redirect?: ExFetchRedirectOptions; - /** - * Retry options. - */ - retry?: ExFetchRetryOptions; - /** - * Timeout of the request (include the redirects and the retries), by milliseconds. This only apply when have not define property `signal` in the request. - * @default Infinity // Disable - */ - timeout?: number; - /** - * Custom user agent. This only apply when have not define HTTP header `User-Agent` in the request. - * @default `Deno/${Deno.version.deno}-${Deno.build.target} exFetch/${ExFetch.version}`. - */ - userAgent?: string; -} -/** - * Extend `fetch`. - */ -export declare class ExFetch { - #private; - /** - * Create a new extend `fetch` instance. - * @param {ExFetchOptions} [options={}] Options. - */ - constructor(options?: ExFetchOptions); - /** - * Add HTTP status code that retryable. - * @param {number} value Value. - * @returns {this} - */ - addHTTPStatusCodeRetryable(value: number): this; - /** - * Add HTTP status code that retryable. - * @param {number[]} values Values. - * @returns {this} - */ - addHTTPStatusCodeRetryable(values: number[]): this; - /** - * Add HTTP status code that retryable. - * @param {...number} values Values. - * @returns {this} - */ - addHTTPStatusCodeRetryable(...values: number[]): this; - /** - * Delete HTTP status code that not retryable. - * @param {number} value Value. - * @returns {this} - */ - deleteHTTPStatusCodeRetryable(value: number): this; - /** - * Delete HTTP status code that not retryable. - * @param {number[]} values Values. - * @returns {this} - */ - deleteHTTPStatusCodeRetryable(values: number[]): this; - /** - * Delete HTTP status code that not retryable. - * @param {...number} values Values. - * @returns {this} - */ - deleteHTTPStatusCodeRetryable(...values: number[]): this; - /** - * Fetch a resource from the network with extend features. - * @param {string | URL} input URL of the resource. - * @param {Parameters[1]} [init] Custom setting that apply to the request. - * @returns {Promise} Response. - */ - fetch(input: string | URL, init?: Parameters[1]): Promise; - /** - * Fetch paginate resources from the network. - * - * IMPORTANT: Only support URL paginate. - * @param {string | URL} input URL of the first page of the resources. - * @param {Parameters[1]} init Custom setting that apply to each request. - * @param {ExFetchPaginateOptions} [optionsOverride={}] Options. - * @returns {Promise} Responses. - */ - fetchPaginate(input: string | URL, init?: Parameters[1], optionsOverride?: ExFetchPaginateOptions): Promise; - /** - * Fetch a resource from the network. - * @param {string | URL} input URL of the resource. - * @param {Parameters[1]} init Custom setting that apply to the request. - * @param {ExFetchOptions} [options={}] Options. - * @returns {Promise} Response. - */ - static fetch(input: string | URL, init?: Parameters[1], options?: ExFetchOptions): Promise; - /** - * Fetch paginate resources from the network. - * - * IMPORTANT: Only support URL paginate. - * @param {string | URL} input URL of the first page of the resources. - * @param {Parameters[1]} init Custom setting that apply to each request. - * @param {ExFetchOptions} [options={}] Options. - * @returns {Promise} Responses. - */ - static fetchPaginate(input: string | URL, init?: Parameters[1], options?: ExFetchOptions): Promise; -} -export default ExFetch; -/** - * Fetch a resource from the network. - * @param {string | URL} input URL of the resource. - * @param {Parameters[1]} init Custom setting that apply to the request. - * @param {ExFetchOptions} [options={}] Options. - * @returns {Promise} Response. - */ -export declare function exFetch(input: string | URL, init?: Parameters[1], options?: ExFetchOptions): Promise; -/** - * Fetch paginate resources from the network. - * - * IMPORTANT: Only support URL paginate. - * @param {string | URL} input URL of the first page of the resources. - * @param {Parameters[1]} init Custom setting that apply to each request. - * @param {ExFetchOptions} [options={}] Options. - * @returns {Promise} Responses. - */ -export declare function exFetchPaginate(input: string | URL, init?: Parameters[1], options?: ExFetchOptions): Promise; -//# sourceMappingURL=exfetch.d.ts.map \ No newline at end of file diff --git a/dist/exfetch.d.ts.map b/dist/exfetch.d.ts.map deleted file mode 100644 index 6d17dfe..0000000 --- a/dist/exfetch.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"exfetch.d.ts","sourceRoot":"","sources":["../src/exfetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAA4B,MAAM,kBAAkB,CAAC;AAY5E;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAUpD,CAAC;AACH;;GAEG;AACH,eAAO,MAAM,gBAAgB,QAAsF,CAAC;AACpH;;GAEG;AACH,UAAU,2BAA2B;IACpC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CAChB;AACD;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,OAAO,CAAC,2BAA2B,CAAC;IAChF,qBAAqB,CAAA,GAAG,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3C,qBAAqB,CAAA,GAAG,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;CAC3C;AACD;;;GAGG;AACH,UAAU,yBAAyB;IAClC;;OAEG;IACH,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC/B;;OAEG;IACH,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;CACnC;AACD;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC3C;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH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BAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEhI;AACD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAE1I"} \ No newline at end of file diff --git a/dist/exfetch.js b/dist/exfetch.js deleted file mode 100644 index 24ffe1a..0000000 --- a/dist/exfetch.js +++ /dev/null @@ -1,411 +0,0 @@ -import { randomInt } from "node:crypto"; -import { HTTPHeaderLink } from "./header/link.js"; -import { HTTPHeaderRetryAfter } from "./header/retry-after.js"; -/** - * exFetch HTTP status codes that redirectable. - */ -const httpStatusCodesRedirectable = Object.freeze([ - 301, - 302, - 303, - 307, - 308 -]); -/** - * exFetch HTTP status codes that retryable. - */ -export const httpStatusCodesRetryable = Object.freeze([ - 408, - 429, - 500, - 502, - 503, - 504, - 506, - 507, - 508 -]); -/** - * exFetch default user agent. - */ -export const userAgentDefault = `NodeJS/${process.versions.node}-${process.platform}-${process.arch} exFetch/0.2.1`; -/** - * Resolve delay options. - * @access private - * @param {string} prefix - * @param {number | ExFetchDelayOptions} input - * @param {ExFetchDelayOptionsInternal} original - * @returns {ExFetchDelayOptionsInternal} - */ -function resolveDelayOptions(prefix, input, original) { - if (typeof input === "number") { - if (!(Number.isSafeInteger(input) && input >= 0)) { - throw new RangeError(`Argument \`${prefix}\` is not a number which is integer, positive, and safe!`); - } - return { - maximum: input, - minimum: input - }; - } - input.maximum ??= input.max; - input.minimum ??= input.min; - const optionsResolve = { ...original }; - if (typeof input.maximum !== "undefined") { - if (!(Number.isSafeInteger(input.maximum) && input.maximum >= 0)) { - throw new RangeError(`Argument \`${prefix}.maximum\` is not a number which is integer, positive, and safe!`); - } - optionsResolve.maximum = input.maximum; - } - if (typeof input.minimum !== "undefined") { - if (!(Number.isSafeInteger(input.minimum) && input.minimum >= 0)) { - throw new RangeError(`Argument \`${prefix}.minimum\` is not a number which is integer, positive, and safe!`); - } - optionsResolve.minimum = input.minimum; - } - if (optionsResolve.minimum > optionsResolve.maximum) { - throw new RangeError(`Argument \`${prefix}.minimum\` is large than argument \`${prefix}.maximum\`!`); - } - return optionsResolve; -} -/** - * Resolve delay time. - * @access private - * @param {ExFetchDelayOptionsInternal} param - * @returns {number} Delay time. - */ -function resolveDelayTime({ maximum, minimum }) { - if (maximum === minimum) { - return maximum; - } - return randomInt(minimum, maximum); -} -/** - * @access private - * @param {string} prefix - * @param {ExFetchPaginateOptions} input - * @param {ExFetchPaginateOptionsInternal} original - * @returns {ExFetchPaginateOptionsInternal} - */ -function resolvePaginateOptions(prefix, input, original) { - const optionsResolve = { ...original }; - if (typeof input.delay !== "undefined") { - optionsResolve.delay = resolveDelayOptions(`${prefix}.delay`, input.delay, original.delay); - } - if (typeof input.linkUpNextPage !== "undefined") { - optionsResolve.linkUpNextPage = input.linkUpNextPage; - } - if (typeof input.maximum !== "undefined") { - if (input.maximum !== Infinity && !(Number.isSafeInteger(input.maximum) && input.maximum > 0)) { - throw new RangeError(`Argument \`${prefix}.maximum\` is not \`Infinity\`, or a number which is integer, safe, and > 0!`); - } - optionsResolve.maximum = input.maximum; - } - if (typeof input.onEvent !== "undefined") { - optionsResolve.onEvent = input.onEvent; - } - if (typeof input.throwOnInvalidHeaderLink !== "undefined") { - optionsResolve.throwOnInvalidHeaderLink = input.throwOnInvalidHeaderLink; - } - return optionsResolve; -} -/** - * Start a `Promise` based delay with `AbortSignal`. - * @param {number} value Time of the delay, by milliseconds. `0` means execute "immediately", or more accurately, the next event cycle. - * @param {AbortSignal | undefined} [signal] A signal object that allow to communicate with a DOM request and abort it if required via an `AbortController` object. - * @returns {Promise} - */ -function setDelay(value, signal) { - if (value <= 0) { - return Promise.resolve(); - } - if (signal?.aborted) { - return Promise.reject(signal.reason); - } - return new Promise((resolve, reject) => { - function abort() { - clearTimeout(id); - reject(signal?.reason); - } - function done() { - signal?.removeEventListener("abort", abort); - resolve(); - } - const id = setTimeout(done, value); - signal?.addEventListener("abort", abort, { once: true }); - }); -} -/** - * Extend `fetch`. - */ -export class ExFetch { - #httpStatusCodesRetryable; - #paginate = { - delay: { - maximum: 0, - minimum: 0 - }, - linkUpNextPage: ({ currentHeaderLink, currentURL }) => { - const currentHeaderLinkEntryNextPage = currentHeaderLink.getByRel("next"); - if (currentHeaderLinkEntryNextPage.length > 0) { - return new URL(currentHeaderLinkEntryNextPage[0][0], currentURL); - } - return; - }, - maximum: Infinity, - onEvent: undefined, - throwOnInvalidHeaderLink: true - }; - #redirect = { - delay: { - maximum: 0, - minimum: 0 - }, - maximum: Infinity, - onEvent: undefined - }; - #retry = { - delay: { - maximum: 60000, - minimum: 1000 - }, - maximum: 4, - onEvent: undefined - }; - #timeout = Infinity; - #userAgent = userAgentDefault; - /** - * Create a new extend `fetch` instance. - * @param {ExFetchOptions} [options={}] Options. - */ - constructor(options = {}) { - this.#httpStatusCodesRetryable = new Set((typeof options.httpStatusCodesRetryable === "undefined") ? httpStatusCodesRetryable : options.httpStatusCodesRetryable); - this.#paginate = resolvePaginateOptions("options.paginate", options.paginate ?? {}, this.#paginate); - if (typeof options.redirect?.delay !== "undefined") { - this.#redirect.delay = resolveDelayOptions("options.redirect.delay", options.redirect.delay, this.#redirect.delay); - } - if (typeof options.redirect?.maximum !== "undefined") { - if (!(Number.isSafeInteger(options.redirect.maximum) && options.redirect.maximum >= 0)) { - throw new RangeError(`Argument \`options.redirect.maximum\` is not a number which is integer, positive, and safe!`); - } - this.#redirect.maximum = options.redirect.maximum; - } - this.#redirect.onEvent = options.redirect?.onEvent; - if (typeof options.retry?.delay !== "undefined") { - this.#retry.delay = resolveDelayOptions("options.retry.delay", options.retry.delay, this.#retry.delay); - } - if (typeof options.retry?.maximum !== "undefined") { - if (!(Number.isSafeInteger(options.retry.maximum) && options.retry.maximum >= 0)) { - throw new RangeError(`Argument \`options.retry.maximum\` is not a number which is integer, positive, and safe!`); - } - this.#retry.maximum = options.retry.maximum; - } - this.#retry.onEvent = options.retry?.onEvent; - if (typeof options.timeout !== "undefined") { - if (options.timeout !== Infinity && !(Number.isSafeInteger(options.timeout) && options.timeout > 0)) { - throw new RangeError(`Argument \`options.timeout\` is not \`Infinity\`, or a number which is integer, positive, safe, and > 0!`); - } - this.#timeout = options.timeout; - } - if (typeof options.userAgent !== "undefined") { - this.#userAgent = options.userAgent; - } - } - addHTTPStatusCodeRetryable(...values) { - for (const value of values.flat(Infinity)) { - this.#httpStatusCodesRetryable.add(value); - } - return this; - } - deleteHTTPStatusCodeRetryable(...values) { - for (const value of values.flat(Infinity)) { - this.#httpStatusCodesRetryable.delete(value); - } - return this; - } - /** - * Fetch a resource from the network with extend features. - * @param {string | URL} input URL of the resource. - * @param {Parameters[1]} [init] Custom setting that apply to the request. - * @returns {Promise} Response. - */ - async fetch(input, init) { - if (new URL(input).protocol === "file:") { - return fetch(input, init); - } - const requestHeaders = new Headers(init?.headers); - if (!requestHeaders.has("User-Agent") && this.#userAgent.length > 0) { - requestHeaders.set("User-Agent", this.#userAgent); - } - const requestRedirectControl = this.#redirect.maximum !== Infinity && (typeof init === "undefined" || - typeof init.redirect === "undefined" || - init.redirect === "follow"); - let requestSignal = init?.signal ?? undefined; - if (typeof requestSignal === "undefined" && this.#timeout !== Infinity) { - requestSignal = AbortSignal.timeout(this.#timeout); - } - let requestFetchInput = input; - const requestFetchInit = { - ...init, - headers: requestHeaders, - redirect: requestRedirectControl ? "manual" : init?.redirect, - signal: requestSignal - }; - let redirects = 0; - let retries = 0; - let response; - do { - response = await fetch(requestFetchInput, requestFetchInit); - if (response.status === 304) { - break; - } - if (requestRedirectControl && httpStatusCodesRedirectable.includes(response.status)) { - if (redirects >= this.#redirect.maximum) { - break; - } - const redirectURL = response.headers.get("Location"); - if (redirectURL === null) { - break; - } - redirects += 1; - try { - requestFetchInput = new URL(redirectURL, input); - } - catch { - break; - } - const delayTime = resolveDelayTime(this.#redirect.delay); - if (typeof this.#redirect.onEvent !== "undefined") { - void this.#redirect.onEvent({ - countCurrent: redirects, - countMaximum: this.#redirect.maximum, - redirectAfter: delayTime, - redirectURL: new URL(requestFetchInput), - statusCode: response.status, - statusText: response.statusText - }); - } - await setDelay(delayTime, requestSignal); - continue; - } - if (response.ok || - retries >= this.#retry.maximum || - !this.#httpStatusCodesRetryable.has(response.status)) { - break; - } - retries += 1; - let delayTime; - try { - delayTime = new HTTPHeaderRetryAfter(response).getRemainTimeMilliseconds(); - } - catch { - delayTime = resolveDelayTime(this.#retry.delay); - } - if (typeof this.#retry.onEvent !== "undefined") { - void this.#retry.onEvent({ - countCurrent: retries, - countMaximum: this.#retry.maximum, - retryAfter: delayTime, - retryURL: new URL(requestFetchInput), - statusCode: response.status, - statusText: response.statusText - }); - } - await setDelay(delayTime, requestSignal); - } while (retries <= this.#retry.maximum); - return response; - } - /** - * Fetch paginate resources from the network. - * - * IMPORTANT: Only support URL paginate. - * @param {string | URL} input URL of the first page of the resources. - * @param {Parameters[1]} init Custom setting that apply to each request. - * @param {ExFetchPaginateOptions} [optionsOverride={}] Options. - * @returns {Promise} Responses. - */ - async fetchPaginate(input, init, optionsOverride = {}) { - const options = resolvePaginateOptions("optionsOverride", optionsOverride, this.#paginate); - const responses = []; - for (let page = 1, uri = new URL(input); page <= options.maximum && typeof uri !== "undefined" && uri !== null; page += 1) { - if (page > 1) { - const delayTime = resolveDelayTime(options.delay); - if (typeof options.onEvent !== "undefined") { - void options.onEvent({ - countCurrent: page, - countMaximum: options.maximum, - paginateAfter: delayTime, - paginateURL: new URL(uri) - }); - } - await setDelay(delayTime, init?.signal ?? undefined); - } - const uriLookUp = uri; - uri = undefined; - const response = await this.fetch(uriLookUp, init); - responses.push(response); - if (response.ok) { - let responseHeaderLink; - try { - responseHeaderLink = HTTPHeaderLink.parse(response); - } - catch (error) { - if (options.throwOnInvalidHeaderLink) { - throw new SyntaxError(`[${uriLookUp.toString()}] ${error?.message ?? error}`); - } - } - if (typeof responseHeaderLink !== "undefined") { - uri = options.linkUpNextPage({ - currentHeaderLink: responseHeaderLink, - currentURL: uriLookUp - }); - } - } - } - return responses; - } - /** - * Fetch a resource from the network. - * @param {string | URL} input URL of the resource. - * @param {Parameters[1]} init Custom setting that apply to the request. - * @param {ExFetchOptions} [options={}] Options. - * @returns {Promise} Response. - */ - static fetch(input, init, options = {}) { - return new this(options).fetch(input, init); - } - /** - * Fetch paginate resources from the network. - * - * IMPORTANT: Only support URL paginate. - * @param {string | URL} input URL of the first page of the resources. - * @param {Parameters[1]} init Custom setting that apply to each request. - * @param {ExFetchOptions} [options={}] Options. - * @returns {Promise} Responses. - */ - static fetchPaginate(input, init, options = {}) { - return new this(options).fetchPaginate(input, init); - } -} -export default ExFetch; -/** - * Fetch a resource from the network. - * @param {string | URL} input URL of the resource. - * @param {Parameters[1]} init Custom setting that apply to the request. - * @param {ExFetchOptions} [options={}] Options. - * @returns {Promise} Response. - */ -export function exFetch(input, init, options = {}) { - return new ExFetch(options).fetch(input, init); -} -/** - * Fetch paginate resources from the network. - * - * IMPORTANT: Only support URL paginate. - * @param {string | URL} input URL of the first page of the resources. - * @param {Parameters[1]} init Custom setting that apply to each request. - * @param {ExFetchOptions} [options={}] Options. - * @returns {Promise} Responses. - */ -export function exFetchPaginate(input, init, options = {}) { - return new ExFetch(options).fetchPaginate(input, init); -} diff --git a/dist/header/link.d.ts b/dist/header/link.d.ts deleted file mode 100644 index 2a124f8..0000000 --- a/dist/header/link.d.ts +++ /dev/null @@ -1,69 +0,0 @@ -/** - * HTTP header `Link` entry. - */ -export type HTTPHeaderLinkEntry = [ - uri: string, - parameters: { - [key: string]: string; - } -]; -/** - * Handle HTTP header `Link` according to RFC 8288 standard. - */ -export declare class HTTPHeaderLink { - #private; - /** - * @param {string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response} [value] - */ - constructor(value?: string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response); - /** - * Add entries. - * @param {string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response} value Entries. - * @returns {this} - */ - add(value: string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response): this; - /** - * Return all of the entries. - * @returns {HTTPHeaderLinkEntry[]} Entries. - */ - entries(): HTTPHeaderLinkEntry[]; - /** - * Get entries by parameter. - * @param {string} key Key of the parameter. - * @param {string} value Value of the parameter. - * @returns {HTTPHeaderLinkEntry[]} Entries. - */ - getByParameter(key: string, value: string): HTTPHeaderLinkEntry[]; - /** - * Get entries by parameter `rel`. - * @param {string} value Value of the parameter `rel`. - * @returns {HTTPHeaderLinkEntry[]} Entries. - */ - getByRel(value: string): HTTPHeaderLinkEntry[]; - /** - * Whether have entries that match parameter. - * @param {string} key Key of the parameter. - * @param {string} value Value of the parameter. - * @returns {boolean} Result. - */ - hasParameter(key: string, value: string): boolean; - /** - * Stringify entries. - * @returns {string} Stringified entries. - */ - toString(): string; - /** - * Parse HTTP header `Link` according to RFC 8288 standard. - * @param {string | Headers | HTTPHeaderLink | Response} value - * @returns {HTTPHeaderLink} - */ - static parse(value: string | Headers | HTTPHeaderLink | Response): HTTPHeaderLink; - /** - * Stringify as HTTP header `Link` according to RFC 8288 standard. - * @param {HTTPHeaderLinkEntry[]} value - * @returns {string} - */ - static stringify(value: HTTPHeaderLinkEntry[]): string; -} -export default HTTPHeaderLink; -//# sourceMappingURL=link.d.ts.map \ No newline at end of file diff --git a/dist/header/link.d.ts.map b/dist/header/link.d.ts.map deleted file mode 100644 index 8c54159..0000000 --- a/dist/header/link.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/header/link.ts"],"names":[],"mappings":"AA+BA;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IACjC,GAAG,EAAE,MAAM;IACX,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KAAE;CACtC,CAAC;AACF;;GAEG;AACH,qBAAa,cAAc;;IAE1B;;OAEG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,mBAAmB,EAAE,GAAG,QAAQ;IAgHxF;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,mBAAmB,EAAE,GAAG,QAAQ,GAAG,IAAI;IA6BtF;;;OAGG;IACH,OAAO,IAAI,mBAAmB,EAAE;IAGhC;;;;;OAKG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,mBAAmB,EAAE;IAWjE;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,EAAE;IAQ9C;;;;;OAKG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAGjD;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAUlB;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,QAAQ,GAAG,cAAc;IAGjF;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,mBAAmB,EAAE,GAAG,MAAM;CAGtD;AACD,eAAe,cAAc,CAAC"} \ No newline at end of file diff --git a/dist/header/link.js b/dist/header/link.js deleted file mode 100644 index 31482a2..0000000 --- a/dist/header/link.js +++ /dev/null @@ -1,259 +0,0 @@ -import { isStringCaseLower } from "@hugoalh/advanced-determine/string/is-case-lower"; -import { isStringSingleLine } from "@hugoalh/advanced-determine/string/is-singleline"; -const httpHeaderLinkParametersNeedLowerCase = new Set([ - "rel", - "type" -]); -/** - * Check URI. - * @access private - * @param {string} uri - * @returns {void} - */ -function checkURI(uri) { - if (!isStringSingleLine(uri) || - /[\s\t]/u.test(uri)) { - throw new SyntaxError(`${uri} is not a valid URI!`); - } -} -/** - * Cursor whitespace skipper. - * @access private - * @param {string} value - * @param {number} cursor - * @returns {number} Number of moves. - */ -function cursorWhitespaceSkipper(value, cursor) { - const valueAfterCursor = value.slice(cursor); - return (valueAfterCursor.length - valueAfterCursor.trimStart().length); -} -/** - * Handle HTTP header `Link` according to RFC 8288 standard. - */ -export class HTTPHeaderLink { - #entries = []; - /** - * @param {string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response} [value] - */ - constructor(value) { - if (typeof value !== "undefined") { - this.add(value); - } - } - /** - * Parse HTTP header `Link` from string. - * @access private - * @param {string} value - * @returns {void} - */ - #parse(value) { - if (value.length === 0) { - return; - } - const valueResolve = value.replace(/[\uFEFF\u00A0]/gu, ""); // Remove Unicode characters of BOM (Byte Order Mark) and no-break space. - for (let cursor = 0; cursor < valueResolve.length; cursor += 1) { - cursor += cursorWhitespaceSkipper(valueResolve, cursor); - if (valueResolve.charAt(cursor) !== "<") { - throw new SyntaxError(`Unexpected character "${valueResolve.charAt(cursor)}" at position ${cursor}; Expect character "<"!`); - } - cursor += 1; - const cursorEndURI = valueResolve.indexOf(">", cursor); - if (cursorEndURI === -1) { - throw new SyntaxError(`Missing end of URI delimiter character ">" after position ${cursor}!`); - } - if (cursorEndURI === cursor) { - throw new SyntaxError(`Missing URI at position ${cursor}!`); - } - const uriSlice = valueResolve.slice(cursor, cursorEndURI); - checkURI(uriSlice); - const uri = decodeURI(uriSlice); - const parameters = {}; - cursor = cursorEndURI + 1; - cursor += cursorWhitespaceSkipper(valueResolve, cursor); - if (cursor === valueResolve.length || - valueResolve.charAt(cursor) === ",") { - this.#entries.push([uri, parameters]); - continue; - } - if (valueResolve.charAt(cursor) !== ";") { - throw new SyntaxError(`Unexpected character "${valueResolve.charAt(cursor)}" at position ${cursor}; Expect character ";"!`); - } - cursor += 1; - while (cursor < valueResolve.length) { - cursor += cursorWhitespaceSkipper(valueResolve, cursor); - const parameterKey = valueResolve.slice(cursor).match(/^[\w-]+\*?/u)?.[0].toLowerCase(); - if (typeof parameterKey === "undefined") { - throw new SyntaxError(`Unexpected character "${valueResolve.charAt(cursor)}" at position ${cursor}; Expect a valid parameter key!`); - } - cursor += parameterKey.length; - cursor += cursorWhitespaceSkipper(valueResolve, cursor); - if (cursor === valueResolve.length || - valueResolve.charAt(cursor) === ",") { - parameters[parameterKey] = ""; - break; - } - if (valueResolve.charAt(cursor) === ";") { - parameters[parameterKey] = ""; - cursor += 1; - continue; - } - if (valueResolve.charAt(cursor) !== "=") { - throw new SyntaxError(`Unexpected character "${valueResolve.charAt(cursor)}" at position ${cursor}; Expect character "="!`); - } - cursor += 1; - cursor += cursorWhitespaceSkipper(valueResolve, cursor); - let parameterValue = ""; - if (valueResolve.charAt(cursor) === "\"") { - cursor += 1; - while (cursor < valueResolve.length) { - if (valueResolve.charAt(cursor) === "\"") { - cursor += 1; - break; - } - if (valueResolve.charAt(cursor) === "\\") { - cursor += 1; - } - parameterValue += valueResolve.charAt(cursor); - cursor += 1; - } - } - else { - const cursorDiffParameterValue = valueResolve.slice(cursor).search(/[\s;,]/u); - if (cursorDiffParameterValue === -1) { - parameterValue += valueResolve.slice(cursor); - cursor += parameterValue.length; - } - else { - parameterValue += valueResolve.slice(cursor, cursorDiffParameterValue); - cursor += cursorDiffParameterValue; - } - } - parameters[parameterKey] = httpHeaderLinkParametersNeedLowerCase.has(parameterKey) ? parameterValue.toLowerCase() : parameterValue; - cursor += cursorWhitespaceSkipper(valueResolve, cursor); - if (cursor === valueResolve.length || - valueResolve.charAt(cursor) === ",") { - break; - } - if (valueResolve.charAt(cursor) === ";") { - cursor += 1; - continue; - } - throw new SyntaxError(`Unexpected character "${valueResolve.charAt(cursor)}" at position ${cursor}; Expect character ",", character ";", or end of the string!`); - } - this.#entries.push([uri, parameters]); - } - } - /** - * Add entries. - * @param {string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response} value Entries. - * @returns {this} - */ - add(value) { - if (value instanceof Headers) { - this.#parse(value.get("Link") ?? ""); - } - else if (value instanceof HTTPHeaderLink) { - this.#entries.push(...value.#entries); - } - else if (Array.isArray(value)) { - for (const entry of value) { - const [uri, parameters] = entry; - checkURI(uri); - Object.entries(parameters).forEach(([parameterKey, parameterValue]) => { - if (!isStringCaseLower(parameterKey) || - !(/^[\w-]+\*?$/u.test(parameterKey))) { - throw new SyntaxError(`\`${parameterKey}\` is not a valid parameter key!`); - } - if (httpHeaderLinkParametersNeedLowerCase.has(parameterKey) && !isStringCaseLower(parameterValue)) { - throw new SyntaxError(`\`${parameterValue}\` is not a valid parameter value!`); - } - }); - this.#entries.push([uri, { ...parameters }]); - } - } - else if (value instanceof Response) { - this.#parse(value.headers.get("Link") ?? ""); - } - else { - this.#parse(value); - } - return this; - } - /** - * Return all of the entries. - * @returns {HTTPHeaderLinkEntry[]} Entries. - */ - entries() { - return this.#entries; - } - /** - * Get entries by parameter. - * @param {string} key Key of the parameter. - * @param {string} value Value of the parameter. - * @returns {HTTPHeaderLinkEntry[]} Entries. - */ - getByParameter(key, value) { - if (!isStringCaseLower(key)) { - throw new SyntaxError(`\`${key}\` is not a valid parameter key!`); - } - if (key === "rel") { - return this.getByRel(value); - } - return this.#entries.filter((entry) => { - return (entry[1][key] === value); - }); - } - /** - * Get entries by parameter `rel`. - * @param {string} value Value of the parameter `rel`. - * @returns {HTTPHeaderLinkEntry[]} Entries. - */ - getByRel(value) { - if (!isStringCaseLower(value)) { - throw new SyntaxError(`\`${value}\` is not a valid parameter \`rel\` value!`); - } - return this.#entries.filter((entity) => { - return (entity[1].rel?.toLowerCase() === value); - }); - } - /** - * Whether have entries that match parameter. - * @param {string} key Key of the parameter. - * @param {string} value Value of the parameter. - * @returns {boolean} Result. - */ - hasParameter(key, value) { - return (this.getByParameter(key, value).length > 0); - } - /** - * Stringify entries. - * @returns {string} Stringified entries. - */ - toString() { - return this.#entries.map((entry) => { - const [uri, parameters] = entry; - let result = `<${encodeURI(uri)}>`; - for (const [key, value] of Object.entries(parameters)) { - result += (value.length > 0) ? `; ${key}="${value.replace(/"/g, "\\\"")}"` : `; ${key}`; - } - return result; - }).join(", "); - } - /** - * Parse HTTP header `Link` according to RFC 8288 standard. - * @param {string | Headers | HTTPHeaderLink | Response} value - * @returns {HTTPHeaderLink} - */ - static parse(value) { - return new this(value); - } - /** - * Stringify as HTTP header `Link` according to RFC 8288 standard. - * @param {HTTPHeaderLinkEntry[]} value - * @returns {string} - */ - static stringify(value) { - return new this(value).toString(); - } -} -export default HTTPHeaderLink; diff --git a/dist/header/retry-after.d.ts b/dist/header/retry-after.d.ts deleted file mode 100644 index 03bd226..0000000 --- a/dist/header/retry-after.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Handle HTTP header `Retry-After` according to RFC 9110 standard. - */ -export declare class HTTPHeaderRetryAfter { - #private; - /** - * @param {number | string | Date | Headers | HTTPHeaderRetryAfter | Response} value - */ - constructor(value: number | string | Date | Headers | HTTPHeaderRetryAfter | Response); - /** - * Get `Date`. - * @returns {Date} - */ - getDate(): Date; - /** - * Get remain time in milliseconds. - * @returns {number} Remain time in milliseconds. - */ - getRemainTimeMilliseconds(): number; - /** - * Get remain time in seconds. - * @returns {number} Remain time in seconds. - */ - getRemainTimeSeconds(): number; -} -export default HTTPHeaderRetryAfter; -//# sourceMappingURL=retry-after.d.ts.map \ No newline at end of file diff --git a/dist/header/retry-after.d.ts.map b/dist/header/retry-after.d.ts.map deleted file mode 100644 index dbd7a45..0000000 --- a/dist/header/retry-after.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"retry-after.d.ts","sourceRoot":"","sources":["../../src/header/retry-after.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,oBAAoB;;IAEhC;;OAEG;gBACS,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,oBAAoB,GAAG,QAAQ;IA4BrF;;;OAGG;IACH,OAAO,IAAI,IAAI;IAGf;;;OAGG;IACH,yBAAyB,IAAI,MAAM;IAInC;;;OAGG;IACH,oBAAoB,IAAI,MAAM;CAG9B;AACD,eAAe,oBAAoB,CAAC"} \ No newline at end of file diff --git a/dist/header/retry-after.js b/dist/header/retry-after.js deleted file mode 100644 index c7712d1..0000000 --- a/dist/header/retry-after.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Handle HTTP header `Retry-After` according to RFC 9110 standard. - */ -export class HTTPHeaderRetryAfter { - #timestamp; - /** - * @param {number | string | Date | Headers | HTTPHeaderRetryAfter | Response} value - */ - constructor(value) { - if (typeof value === "number") { - if (!(value >= 0)) { - throw new RangeError(`Argument \`value\` is not a number which is positive!`); - } - this.#timestamp = new Date(Date.now() + value * 1000); - } - else if (value instanceof Date) { - this.#timestamp = new Date(value); - } - else if (value instanceof HTTPHeaderRetryAfter) { - this.#timestamp = new Date(value.#timestamp); - } - else { - let valueRaw; - if (value instanceof Headers) { - valueRaw = value.get("Retry-After") ?? ""; - } - else if (value instanceof Response) { - valueRaw = value.headers.get("Retry-After") ?? ""; - } - else { - valueRaw = value; - } - if (/^[A-Z][a-z][a-z], \d\d [A-Z][a-z][a-z] \d\d\d\d \d\d:\d\d:\d\d GMT$/u.test(valueRaw)) { - this.#timestamp = new Date(valueRaw); - } - else if (/^\d+$/u.test(valueRaw)) { - this.#timestamp = new Date(Date.now() + Number(valueRaw) * 1000); - } - else { - throw new SyntaxError(`\`${valueRaw}\` is not a valid HTTP header \`Retry-After\` syntax!`); - } - } - } - /** - * Get `Date`. - * @returns {Date} - */ - getDate() { - return this.#timestamp; - } - /** - * Get remain time in milliseconds. - * @returns {number} Remain time in milliseconds. - */ - getRemainTimeMilliseconds() { - const remainMilliseconds = this.#timestamp.valueOf() - Date.now(); - return ((remainMilliseconds >= 0) ? remainMilliseconds : 0); - } - /** - * Get remain time in seconds. - * @returns {number} Remain time in seconds. - */ - getRemainTimeSeconds() { - return (this.getRemainTimeMilliseconds() / 1000); - } -} -export default HTTPHeaderRetryAfter; diff --git a/dist/main.d.ts b/dist/main.d.ts deleted file mode 100644 index c2614da..0000000 --- a/dist/main.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default, ExFetch, exFetch, exFetchPaginate, httpStatusCodesRetryable, userAgentDefault, type ExFetchDelayOptions, type ExFetchEventPaginatePayload, type ExFetchEventRedirectPayload, type ExFetchEventRetryPayload, type ExFetchOptions, type ExFetchPaginateLinkUpPayload, type ExFetchPaginateOptions, type ExFetchRedirectOptions, type ExFetchRetryOptions } from "./exfetch.js"; -export { HTTPHeaderLink, type HTTPHeaderLinkEntry } from "./header/link.js"; -export { HTTPHeaderRetryAfter } from "./header/retry-after.js"; -//# sourceMappingURL=main.d.ts.map \ No newline at end of file diff --git a/dist/main.d.ts.map b/dist/main.d.ts.map deleted file mode 100644 index 1ec3799..0000000 --- a/dist/main.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,KAAK,2BAA2B,EAAE,KAAK,2BAA2B,EAAE,KAAK,wBAAwB,EAAE,KAAK,cAAc,EAAE,KAAK,4BAA4B,EAAE,KAAK,sBAAsB,EAAE,KAAK,sBAAsB,EAAE,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC/X,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"} \ No newline at end of file diff --git a/dist/main.js b/dist/main.js deleted file mode 100644 index 94d3a08..0000000 --- a/dist/main.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default, ExFetch, exFetch, exFetchPaginate, httpStatusCodesRetryable, userAgentDefault } from "./exfetch.js"; -export { HTTPHeaderLink } from "./header/link.js"; -export { HTTPHeaderRetryAfter } from "./header/retry-after.js"; diff --git a/package.json b/package.json index 7cfe209..dc22257 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,9 @@ "type": "git", "url": "git+https://github.com/hugoalh-studio/exfetch-nodejs.git" }, + "scripts": { + "build": "tsc" + }, "dependencies": { "@hugoalh/advanced-determine": "^14.0.1" },