@helia/verified-fetch 3.2.3 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -52
- package/dist/index.min.js +86 -71
- package/dist/index.min.js.map +4 -4
- package/dist/src/constants.d.ts +2 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +2 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/index.d.ts +63 -61
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -54
- package/dist/src/index.js.map +1 -1
- package/dist/src/plugins/index.d.ts +0 -1
- package/dist/src/plugins/index.d.ts.map +1 -1
- package/dist/src/plugins/index.js +0 -1
- package/dist/src/plugins/index.js.map +1 -1
- package/dist/src/plugins/plugin-base.d.ts.map +1 -1
- package/dist/src/plugins/plugin-base.js +3 -2
- package/dist/src/plugins/plugin-base.js.map +1 -1
- package/dist/src/plugins/plugin-handle-car.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-car.js +37 -28
- package/dist/src/plugins/plugin-handle-car.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js +1 -2
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.js +5 -6
- package/dist/src/plugins/plugin-handle-dag-cbor.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-pb.js +24 -27
- package/dist/src/plugins/plugin-handle-dag-pb.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-walk.d.ts +8 -4
- package/dist/src/plugins/plugin-handle-dag-walk.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-walk.js +13 -9
- package/dist/src/plugins/plugin-handle-dag-walk.js.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.js +16 -24
- package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
- package/dist/src/plugins/plugin-handle-json.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-json.js +5 -5
- package/dist/src/plugins/plugin-handle-json.js.map +1 -1
- package/dist/src/plugins/plugin-handle-raw.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-raw.js +21 -12
- package/dist/src/plugins/plugin-handle-raw.js.map +1 -1
- package/dist/src/plugins/plugin-handle-tar.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-tar.js +1 -2
- package/dist/src/plugins/plugin-handle-tar.js.map +1 -1
- package/dist/src/plugins/types.d.ts +15 -15
- package/dist/src/plugins/types.d.ts.map +1 -1
- package/dist/src/url-resolver.d.ts +21 -0
- package/dist/src/url-resolver.d.ts.map +1 -0
- package/dist/src/url-resolver.js +118 -0
- package/dist/src/url-resolver.js.map +1 -0
- package/dist/src/utils/byte-range-context.d.ts +3 -3
- package/dist/src/utils/byte-range-context.d.ts.map +1 -1
- package/dist/src/utils/byte-range-context.js +1 -1
- package/dist/src/utils/byte-range-context.js.map +1 -1
- package/dist/src/utils/content-type-parser.d.ts.map +1 -1
- package/dist/src/utils/content-type-parser.js +0 -10
- package/dist/src/utils/content-type-parser.js.map +1 -1
- package/dist/src/utils/error-to-object.d.ts +6 -0
- package/dist/src/utils/error-to-object.d.ts.map +1 -0
- package/dist/src/utils/error-to-object.js +20 -0
- package/dist/src/utils/error-to-object.js.map +1 -0
- package/dist/src/utils/get-content-type.d.ts +3 -3
- package/dist/src/utils/get-content-type.d.ts.map +1 -1
- package/dist/src/utils/get-content-type.js +1 -1
- package/dist/src/utils/get-content-type.js.map +1 -1
- package/dist/src/utils/get-e-tag.d.ts +1 -1
- package/dist/src/utils/get-offset-and-length.d.ts +6 -0
- package/dist/src/utils/get-offset-and-length.d.ts.map +1 -0
- package/dist/src/utils/get-offset-and-length.js +46 -0
- package/dist/src/utils/get-offset-and-length.js.map +1 -0
- package/dist/src/utils/get-resolved-accept-header.d.ts +2 -2
- package/dist/src/utils/get-resolved-accept-header.d.ts.map +1 -1
- package/dist/src/utils/get-stream-from-async-iterable.d.ts +2 -2
- package/dist/src/utils/get-stream-from-async-iterable.d.ts.map +1 -1
- package/dist/src/utils/get-stream-from-async-iterable.js +2 -2
- package/dist/src/utils/get-stream-from-async-iterable.js.map +1 -1
- package/dist/src/utils/handle-redirects.d.ts.map +1 -1
- package/dist/src/utils/handle-redirects.js +3 -3
- package/dist/src/utils/handle-redirects.js.map +1 -1
- package/dist/src/utils/ipfs-path-to-string.d.ts +6 -0
- package/dist/src/utils/ipfs-path-to-string.d.ts.map +1 -0
- package/dist/src/utils/ipfs-path-to-string.js +10 -0
- package/dist/src/utils/ipfs-path-to-string.js.map +1 -0
- package/dist/src/utils/is-accept-explicit.d.ts +6 -4
- package/dist/src/utils/is-accept-explicit.d.ts.map +1 -1
- package/dist/src/utils/is-accept-explicit.js +7 -4
- package/dist/src/utils/is-accept-explicit.js.map +1 -1
- package/dist/src/utils/parse-url-string.d.ts +1 -55
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js +16 -217
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/response-headers.d.ts +1 -1
- package/dist/src/utils/response-headers.d.ts.map +1 -1
- package/dist/src/utils/responses.d.ts +3 -2
- package/dist/src/utils/responses.d.ts.map +1 -1
- package/dist/src/utils/responses.js +12 -1
- package/dist/src/utils/responses.js.map +1 -1
- package/dist/src/utils/select-output-type.d.ts +6 -2
- package/dist/src/utils/select-output-type.d.ts.map +1 -1
- package/dist/src/utils/select-output-type.js +28 -37
- package/dist/src/utils/select-output-type.js.map +1 -1
- package/dist/src/utils/server-timing.d.ts +5 -11
- package/dist/src/utils/server-timing.d.ts.map +1 -1
- package/dist/src/utils/server-timing.js +17 -15
- package/dist/src/utils/server-timing.js.map +1 -1
- package/dist/src/utils/walk-path.js +2 -2
- package/dist/src/utils/walk-path.js.map +1 -1
- package/dist/src/verified-fetch.d.ts +3 -10
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +99 -80
- package/dist/src/verified-fetch.js.map +1 -1
- package/dist/typedoc-urls.json +13 -4
- package/package.json +35 -36
- package/src/constants.ts +1 -0
- package/src/index.ts +79 -70
- package/src/plugins/index.ts +0 -1
- package/src/plugins/plugin-base.ts +3 -2
- package/src/plugins/plugin-handle-car.ts +53 -31
- package/src/plugins/plugin-handle-dag-cbor-html-preview.ts +4 -3
- package/src/plugins/plugin-handle-dag-cbor.ts +8 -6
- package/src/plugins/plugin-handle-dag-pb.ts +34 -26
- package/src/plugins/plugin-handle-dag-walk.ts +15 -9
- package/src/plugins/plugin-handle-ipns-record.ts +21 -24
- package/src/plugins/plugin-handle-json.ts +6 -5
- package/src/plugins/plugin-handle-raw.ts +27 -13
- package/src/plugins/plugin-handle-tar.ts +3 -2
- package/src/plugins/types.ts +18 -16
- package/src/url-resolver.ts +159 -0
- package/src/utils/byte-range-context.ts +4 -4
- package/src/utils/content-type-parser.ts +5 -11
- package/src/utils/error-to-object.ts +22 -0
- package/src/utils/get-content-type.ts +5 -4
- package/src/utils/get-e-tag.ts +1 -1
- package/src/utils/get-offset-and-length.ts +54 -0
- package/src/utils/get-resolved-accept-header.ts +2 -2
- package/src/utils/get-stream-from-async-iterable.ts +4 -4
- package/src/utils/handle-redirects.ts +10 -3
- package/src/utils/ipfs-path-to-string.ts +9 -0
- package/src/utils/is-accept-explicit.ts +14 -7
- package/src/utils/parse-url-string.ts +20 -286
- package/src/utils/response-headers.ts +1 -1
- package/src/utils/responses.ts +16 -2
- package/src/utils/select-output-type.ts +38 -44
- package/src/utils/server-timing.ts +17 -30
- package/src/utils/walk-path.ts +2 -2
- package/src/verified-fetch.ts +119 -92
- package/dist/src/plugins/errors.d.ts +0 -25
- package/dist/src/plugins/errors.d.ts.map +0 -1
- package/dist/src/plugins/errors.js +0 -33
- package/dist/src/plugins/errors.js.map +0 -1
- package/dist/src/types.d.ts +0 -16
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -2
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils/parse-resource.d.ts +0 -18
- package/dist/src/utils/parse-resource.d.ts.map +0 -1
- package/dist/src/utils/parse-resource.js +0 -27
- package/dist/src/utils/parse-resource.js.map +0 -1
- package/src/plugins/errors.ts +0 -37
- package/src/types.ts +0 -17
- package/src/utils/parse-resource.ts +0 -42
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/plugins/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE7E;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAC7B,IAAI,SAAgB;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,QAAQ,CAAC,EAAE,GAAG,CAAA;gBAER,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB;CAOzE;AAED;;;;;;;GAOG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;IACxC,IAAI,SAAqB;gBAEnB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB;CAI7E"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* If a plugin encounters an error, it should throw an instance of this class.
|
|
3
|
-
*/
|
|
4
|
-
export class PluginError extends Error {
|
|
5
|
-
name = 'PluginError';
|
|
6
|
-
code;
|
|
7
|
-
fatal;
|
|
8
|
-
details;
|
|
9
|
-
response;
|
|
10
|
-
constructor(code, message, options) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.code = code;
|
|
13
|
-
this.fatal = options?.fatal ?? false;
|
|
14
|
-
this.details = options?.details;
|
|
15
|
-
this.response = options?.response;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* If a plugin encounters a fatal error and verified-fetch should not continue processing the request, it should throw
|
|
20
|
-
* an instance of this class.
|
|
21
|
-
*
|
|
22
|
-
* Note that you should be very careful when throwing a `PluginFatalError`, as it will stop the request from being
|
|
23
|
-
* processed further. If you do not have a response to return to the client, you should consider throwing a
|
|
24
|
-
* `PluginError` instead.
|
|
25
|
-
*/
|
|
26
|
-
export class PluginFatalError extends PluginError {
|
|
27
|
-
name = 'PluginFatalError';
|
|
28
|
-
constructor(code, message, options) {
|
|
29
|
-
super(code, message, { ...options, fatal: true });
|
|
30
|
-
this.name = 'PluginFatalError';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/plugins/errors.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC7B,IAAI,GAAG,aAAa,CAAA;IACpB,IAAI,CAAQ;IACZ,KAAK,CAAS;IACd,OAAO,CAAsB;IAC7B,QAAQ,CAAM;IAErB,YAAa,IAAY,EAAE,OAAe,EAAE,OAA4B;QACtE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,KAAK,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAA;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,CAAA;IACnC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IACxC,IAAI,GAAG,kBAAkB,CAAA;IAEhC,YAAa,IAAY,EAAE,OAAe,EAAE,OAAgC;QAC1E,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACjD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAChC,CAAC;CACF"}
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type RequestFormatShorthand = 'raw' | 'car' | 'tar' | 'ipns-record' | 'dag-json' | 'dag-cbor' | 'json' | 'cbor';
|
|
2
|
-
export type SupportedBodyTypes = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array> | null;
|
|
3
|
-
/**
|
|
4
|
-
* A ContentTypeParser attempts to return the mime type of a given file. It
|
|
5
|
-
* receives the first chunk of the file data and the file name, if it is
|
|
6
|
-
* available. The function can be sync or async and if it returns/resolves to
|
|
7
|
-
* `undefined`, `application/octet-stream` will be used.
|
|
8
|
-
*/
|
|
9
|
-
export interface ContentTypeParser {
|
|
10
|
-
/**
|
|
11
|
-
* Attempt to determine a mime type, either via of the passed bytes or the
|
|
12
|
-
* filename if it is available.
|
|
13
|
-
*/
|
|
14
|
-
(bytes: Uint8Array, fileName?: string): Promise<string | undefined> | string | undefined;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;AAEtH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;AAE7G;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAA;CACzF"}
|
package/dist/src/types.js
DELETED
package/dist/src/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ParseUrlStringOptions, ParsedUrlStringResults } from './parse-url-string.js';
|
|
2
|
-
import type { Resource } from '../index.js';
|
|
3
|
-
import type { IPNS } from '@helia/ipns';
|
|
4
|
-
import type { ComponentLogger } from '@libp2p/interface';
|
|
5
|
-
export interface ParseResourceComponents {
|
|
6
|
-
ipns: IPNS;
|
|
7
|
-
logger: ComponentLogger;
|
|
8
|
-
}
|
|
9
|
-
export interface ParseResourceOptions extends ParseUrlStringOptions {
|
|
10
|
-
withServerTiming?: boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Handles the different use cases for the `resource` argument.
|
|
14
|
-
* The resource can represent an IPFS path, IPNS path, or CID.
|
|
15
|
-
* If the resource represents an IPNS path, we need to resolve it to a CID.
|
|
16
|
-
*/
|
|
17
|
-
export declare function parseResource(resource: Resource, { ipns, logger }: ParseResourceComponents, { withServerTiming, ...options }?: ParseResourceOptions): Promise<ParsedUrlStringResults>;
|
|
18
|
-
//# sourceMappingURL=parse-resource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-resource.d.ts","sourceRoot":"","sources":["../../../src/utils/parse-resource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAC1F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AACD;;;;GAIG;AACH,wBAAsB,aAAa,CAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,uBAAuB,EAAE,EAAE,gBAAwB,EAAE,GAAG,OAAO,EAAE,GAAE,oBAAkD,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAqBjO"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { CID } from 'multiformats/cid';
|
|
2
|
-
import { parseUrlString } from './parse-url-string.js';
|
|
3
|
-
/**
|
|
4
|
-
* Handles the different use cases for the `resource` argument.
|
|
5
|
-
* The resource can represent an IPFS path, IPNS path, or CID.
|
|
6
|
-
* If the resource represents an IPNS path, we need to resolve it to a CID.
|
|
7
|
-
*/
|
|
8
|
-
export async function parseResource(resource, { ipns, logger }, { withServerTiming = false, ...options } = { withServerTiming: false }) {
|
|
9
|
-
if (typeof resource === 'string') {
|
|
10
|
-
return parseUrlString({ urlString: resource, ipns, logger, withServerTiming }, options);
|
|
11
|
-
}
|
|
12
|
-
const cid = CID.asCID(resource);
|
|
13
|
-
if (cid != null) {
|
|
14
|
-
// an actual CID
|
|
15
|
-
return {
|
|
16
|
-
cid,
|
|
17
|
-
protocol: 'ipfs',
|
|
18
|
-
path: '',
|
|
19
|
-
query: {},
|
|
20
|
-
ipfsPath: `/ipfs/${cid.toString()}`,
|
|
21
|
-
ttl: 29030400, // 1 year for ipfs content
|
|
22
|
-
serverTimings: []
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${resource}`);
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=parse-resource.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-resource.js","sourceRoot":"","sources":["../../../src/utils/parse-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AActD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAE,QAAkB,EAAE,EAAE,IAAI,EAAE,MAAM,EAA2B,EAAE,EAAE,gBAAgB,GAAG,KAAK,EAAE,GAAG,OAAO,KAA2B,EAAE,gBAAgB,EAAE,KAAK,EAAE;IAC9L,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,cAAc,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAA;IACzF,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAE/B,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,gBAAgB;QAChB,OAAO;YACL,GAAG;YACH,QAAQ,EAAE,MAAM;YAChB,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,SAAS,GAAG,CAAC,QAAQ,EAAE,EAAE;YACnC,GAAG,EAAE,QAAQ,EAAE,0BAA0B;YACzC,aAAa,EAAE,EAAE;SACe,CAAA;IACpC,CAAC;IAED,MAAM,IAAI,SAAS,CAAC,yDAAyD,QAAQ,EAAE,CAAC,CAAA;AAC1F,CAAC"}
|
package/src/plugins/errors.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { FatalPluginErrorOptions, PluginErrorOptions } from './types.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* If a plugin encounters an error, it should throw an instance of this class.
|
|
5
|
-
*/
|
|
6
|
-
export class PluginError extends Error {
|
|
7
|
-
public name = 'PluginError'
|
|
8
|
-
public code: string
|
|
9
|
-
public fatal: boolean
|
|
10
|
-
public details?: Record<string, any>
|
|
11
|
-
public response?: any
|
|
12
|
-
|
|
13
|
-
constructor (code: string, message: string, options?: PluginErrorOptions) {
|
|
14
|
-
super(message)
|
|
15
|
-
this.code = code
|
|
16
|
-
this.fatal = options?.fatal ?? false
|
|
17
|
-
this.details = options?.details
|
|
18
|
-
this.response = options?.response
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* If a plugin encounters a fatal error and verified-fetch should not continue processing the request, it should throw
|
|
24
|
-
* an instance of this class.
|
|
25
|
-
*
|
|
26
|
-
* Note that you should be very careful when throwing a `PluginFatalError`, as it will stop the request from being
|
|
27
|
-
* processed further. If you do not have a response to return to the client, you should consider throwing a
|
|
28
|
-
* `PluginError` instead.
|
|
29
|
-
*/
|
|
30
|
-
export class PluginFatalError extends PluginError {
|
|
31
|
-
public name = 'PluginFatalError'
|
|
32
|
-
|
|
33
|
-
constructor (code: string, message: string, options: FatalPluginErrorOptions) {
|
|
34
|
-
super(code, message, { ...options, fatal: true })
|
|
35
|
-
this.name = 'PluginFatalError'
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type RequestFormatShorthand = 'raw' | 'car' | 'tar' | 'ipns-record' | 'dag-json' | 'dag-cbor' | 'json' | 'cbor'
|
|
2
|
-
|
|
3
|
-
export type SupportedBodyTypes = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array> | null
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A ContentTypeParser attempts to return the mime type of a given file. It
|
|
7
|
-
* receives the first chunk of the file data and the file name, if it is
|
|
8
|
-
* available. The function can be sync or async and if it returns/resolves to
|
|
9
|
-
* `undefined`, `application/octet-stream` will be used.
|
|
10
|
-
*/
|
|
11
|
-
export interface ContentTypeParser {
|
|
12
|
-
/**
|
|
13
|
-
* Attempt to determine a mime type, either via of the passed bytes or the
|
|
14
|
-
* filename if it is available.
|
|
15
|
-
*/
|
|
16
|
-
(bytes: Uint8Array, fileName?: string): Promise<string | undefined> | string | undefined
|
|
17
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { CID } from 'multiformats/cid'
|
|
2
|
-
import { parseUrlString } from './parse-url-string.js'
|
|
3
|
-
import type { ParseUrlStringOptions, ParsedUrlStringResults } from './parse-url-string.js'
|
|
4
|
-
import type { Resource } from '../index.js'
|
|
5
|
-
import type { IPNS } from '@helia/ipns'
|
|
6
|
-
import type { ComponentLogger } from '@libp2p/interface'
|
|
7
|
-
|
|
8
|
-
export interface ParseResourceComponents {
|
|
9
|
-
ipns: IPNS
|
|
10
|
-
logger: ComponentLogger
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface ParseResourceOptions extends ParseUrlStringOptions {
|
|
14
|
-
withServerTiming?: boolean
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Handles the different use cases for the `resource` argument.
|
|
18
|
-
* The resource can represent an IPFS path, IPNS path, or CID.
|
|
19
|
-
* If the resource represents an IPNS path, we need to resolve it to a CID.
|
|
20
|
-
*/
|
|
21
|
-
export async function parseResource (resource: Resource, { ipns, logger }: ParseResourceComponents, { withServerTiming = false, ...options }: ParseResourceOptions = { withServerTiming: false }): Promise<ParsedUrlStringResults> {
|
|
22
|
-
if (typeof resource === 'string') {
|
|
23
|
-
return parseUrlString({ urlString: resource, ipns, logger, withServerTiming }, options)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const cid = CID.asCID(resource)
|
|
27
|
-
|
|
28
|
-
if (cid != null) {
|
|
29
|
-
// an actual CID
|
|
30
|
-
return {
|
|
31
|
-
cid,
|
|
32
|
-
protocol: 'ipfs',
|
|
33
|
-
path: '',
|
|
34
|
-
query: {},
|
|
35
|
-
ipfsPath: `/ipfs/${cid.toString()}`,
|
|
36
|
-
ttl: 29030400, // 1 year for ipfs content
|
|
37
|
-
serverTimings: []
|
|
38
|
-
} satisfies ParsedUrlStringResults
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${resource}`)
|
|
42
|
-
}
|