@helia/verified-fetch 4.1.1 → 5.0.0
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 +6 -40
- package/dist/index.min.js +73 -534
- package/dist/index.min.js.map +4 -4
- package/dist/src/constants.d.ts +2 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +2 -0
- package/dist/src/constants.js.map +1 -1
- package/dist/src/index.d.ts +162 -68
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -40
- package/dist/src/index.js.map +1 -1
- package/dist/src/plugins/index.d.ts +0 -5
- package/dist/src/plugins/index.d.ts.map +1 -1
- package/dist/src/plugins/index.js +0 -4
- package/dist/src/plugins/index.js.map +1 -1
- package/dist/src/plugins/plugin-base.d.ts +8 -9
- package/dist/src/plugins/plugin-base.d.ts.map +1 -1
- package/dist/src/plugins/plugin-base.js +5 -6
- package/dist/src/plugins/plugin-base.js.map +1 -1
- package/dist/src/plugins/plugin-handle-car.d.ts +3 -3
- package/dist/src/plugins/plugin-handle-car.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-car.js +38 -39
- package/dist/src/plugins/plugin-handle-car.js.map +1 -1
- package/dist/src/plugins/plugin-handle-ipld.d.ts +12 -0
- package/dist/src/plugins/plugin-handle-ipld.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-ipld.js +83 -0
- package/dist/src/plugins/plugin-handle-ipld.js.map +1 -0
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts +3 -3
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.js +25 -34
- package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
- package/dist/src/plugins/plugin-handle-tar.d.ts +3 -3
- package/dist/src/plugins/plugin-handle-tar.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-tar.js +20 -22
- package/dist/src/plugins/plugin-handle-tar.js.map +1 -1
- package/dist/src/plugins/plugin-handle-unixfs.d.ts +14 -0
- package/dist/src/plugins/plugin-handle-unixfs.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-unixfs.js +180 -0
- package/dist/src/plugins/plugin-handle-unixfs.js.map +1 -0
- package/dist/src/plugins/types.d.ts +1 -77
- package/dist/src/plugins/types.d.ts.map +1 -1
- package/dist/src/url-resolver.d.ts +29 -11
- package/dist/src/url-resolver.d.ts.map +1 -1
- package/dist/src/url-resolver.js +152 -74
- package/dist/src/url-resolver.js.map +1 -1
- package/dist/src/utils/content-type-parser.d.ts.map +1 -1
- package/dist/src/utils/content-type-parser.js +4 -3
- package/dist/src/utils/content-type-parser.js.map +1 -1
- package/dist/src/utils/content-types.d.ts +26 -0
- package/dist/src/utils/content-types.d.ts.map +1 -0
- package/dist/src/utils/content-types.js +137 -0
- package/dist/src/utils/content-types.js.map +1 -0
- package/dist/src/utils/convert-output.d.ts +17 -0
- package/dist/src/utils/convert-output.d.ts.map +1 -0
- package/dist/src/utils/convert-output.js +176 -0
- package/dist/src/utils/convert-output.js.map +1 -0
- package/dist/src/utils/error-to-response.d.ts +3 -0
- package/dist/src/utils/error-to-response.d.ts.map +1 -0
- package/dist/src/utils/error-to-response.js +40 -0
- package/dist/src/utils/error-to-response.js.map +1 -0
- package/dist/src/utils/get-content-disposition-filename.d.ts +1 -1
- package/dist/src/utils/get-content-disposition-filename.d.ts.map +1 -1
- package/dist/src/utils/get-content-disposition-filename.js +4 -0
- package/dist/src/utils/get-content-disposition-filename.js.map +1 -1
- package/dist/src/utils/get-e-tag.d.ts +20 -15
- package/dist/src/utils/get-e-tag.d.ts.map +1 -1
- package/dist/src/utils/get-e-tag.js +8 -22
- package/dist/src/utils/get-e-tag.js.map +1 -1
- package/dist/src/utils/get-offset-and-length.d.ts +12 -2
- package/dist/src/utils/get-offset-and-length.d.ts.map +1 -1
- package/dist/src/utils/get-offset-and-length.js +63 -21
- package/dist/src/utils/get-offset-and-length.js.map +1 -1
- package/dist/src/utils/get-range-header.d.ts +22 -0
- package/dist/src/utils/get-range-header.d.ts.map +1 -0
- package/dist/src/utils/get-range-header.js +69 -0
- package/dist/src/utils/get-range-header.js.map +1 -0
- package/dist/src/utils/parse-url-string.d.ts +2 -1
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js +46 -71
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/resource-to-cache-key.d.ts +3 -3
- package/dist/src/utils/resource-to-cache-key.js +5 -5
- package/dist/src/utils/resource-to-cache-key.js.map +1 -1
- package/dist/src/utils/response-headers.d.ts +4 -14
- package/dist/src/utils/response-headers.d.ts.map +1 -1
- package/dist/src/utils/response-headers.js +36 -36
- package/dist/src/utils/response-headers.js.map +1 -1
- package/dist/src/utils/responses.d.ts +30 -11
- package/dist/src/utils/responses.d.ts.map +1 -1
- package/dist/src/utils/responses.js +146 -39
- package/dist/src/utils/responses.js.map +1 -1
- package/dist/src/verified-fetch.d.ts +16 -15
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +302 -238
- package/dist/src/verified-fetch.js.map +1 -1
- package/dist/typedoc-urls.json +64 -45
- package/package.json +4 -3
- package/src/constants.ts +3 -0
- package/src/index.ts +199 -68
- package/src/plugins/index.ts +0 -6
- package/src/plugins/plugin-base.ts +8 -10
- package/src/plugins/plugin-handle-car.ts +48 -46
- package/src/plugins/plugin-handle-ipld.ts +93 -0
- package/src/plugins/plugin-handle-ipns-record.ts +31 -41
- package/src/plugins/plugin-handle-tar.ts +25 -29
- package/src/plugins/plugin-handle-unixfs.ts +217 -0
- package/src/plugins/types.ts +0 -86
- package/src/url-resolver.ts +197 -83
- package/src/utils/content-type-parser.ts +4 -3
- package/src/utils/content-types.ts +159 -0
- package/src/utils/convert-output.ts +187 -0
- package/src/utils/error-to-response.ts +49 -0
- package/src/utils/get-content-disposition-filename.ts +7 -1
- package/src/utils/get-e-tag.ts +26 -35
- package/src/utils/get-offset-and-length.ts +75 -21
- package/src/utils/get-range-header.ts +107 -0
- package/src/utils/parse-url-string.ts +51 -80
- package/src/utils/resource-to-cache-key.ts +5 -5
- package/src/utils/response-headers.ts +40 -41
- package/src/utils/responses.ts +186 -45
- package/src/verified-fetch.ts +353 -270
- package/dist/src/plugins/plugin-handle-byte-range-context.d.ts +0 -14
- package/dist/src/plugins/plugin-handle-byte-range-context.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-byte-range-context.js +0 -25
- package/dist/src/plugins/plugin-handle-byte-range-context.js.map +0 -1
- package/dist/src/plugins/plugin-handle-cbor.d.ts +0 -17
- package/dist/src/plugins/plugin-handle-cbor.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-cbor.js +0 -94
- package/dist/src/plugins/plugin-handle-cbor.js.map +0 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts +0 -27
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js +0 -279
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js.map +0 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts +0 -17
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.js +0 -66
- package/dist/src/plugins/plugin-handle-dag-cbor.js.map +0 -1
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts +0 -17
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-dag-pb.js +0 -209
- package/dist/src/plugins/plugin-handle-dag-pb.js.map +0 -1
- package/dist/src/plugins/plugin-handle-dag-walk.d.ts +0 -21
- package/dist/src/plugins/plugin-handle-dag-walk.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-dag-walk.js +0 -95
- package/dist/src/plugins/plugin-handle-dag-walk.js.map +0 -1
- package/dist/src/plugins/plugin-handle-dir-index-html.d.ts +0 -10
- package/dist/src/plugins/plugin-handle-dir-index-html.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-dir-index-html.js +0 -59
- package/dist/src/plugins/plugin-handle-dir-index-html.js.map +0 -1
- package/dist/src/plugins/plugin-handle-json.d.ts +0 -12
- package/dist/src/plugins/plugin-handle-json.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-json.js +0 -73
- package/dist/src/plugins/plugin-handle-json.js.map +0 -1
- package/dist/src/plugins/plugin-handle-raw.d.ts +0 -9
- package/dist/src/plugins/plugin-handle-raw.d.ts.map +0 -1
- package/dist/src/plugins/plugin-handle-raw.js +0 -92
- package/dist/src/plugins/plugin-handle-raw.js.map +0 -1
- package/dist/src/plugins/plugins.d.ts +0 -6
- package/dist/src/plugins/plugins.d.ts.map +0 -1
- package/dist/src/plugins/plugins.js +0 -6
- package/dist/src/plugins/plugins.js.map +0 -1
- package/dist/src/utils/byte-range-context.d.ts +0 -103
- package/dist/src/utils/byte-range-context.d.ts.map +0 -1
- package/dist/src/utils/byte-range-context.js +0 -504
- package/dist/src/utils/byte-range-context.js.map +0 -1
- package/dist/src/utils/dag-cbor-to-safe-json.d.ts +0 -15
- package/dist/src/utils/dag-cbor-to-safe-json.d.ts.map +0 -1
- package/dist/src/utils/dag-cbor-to-safe-json.js +0 -54
- package/dist/src/utils/dag-cbor-to-safe-json.js.map +0 -1
- package/dist/src/utils/dir-index-html.d.ts +0 -19
- package/dist/src/utils/dir-index-html.d.ts.map +0 -1
- package/dist/src/utils/dir-index-html.js +0 -438
- package/dist/src/utils/dir-index-html.js.map +0 -1
- package/dist/src/utils/get-peer-id-from-string.d.ts +0 -3
- package/dist/src/utils/get-peer-id-from-string.d.ts.map +0 -1
- package/dist/src/utils/get-peer-id-from-string.js +0 -10
- package/dist/src/utils/get-peer-id-from-string.js.map +0 -1
- package/dist/src/utils/get-resolved-accept-header.d.ts +0 -9
- package/dist/src/utils/get-resolved-accept-header.d.ts.map +0 -1
- package/dist/src/utils/get-resolved-accept-header.js +0 -27
- package/dist/src/utils/get-resolved-accept-header.js.map +0 -1
- package/dist/src/utils/get-stream-from-async-iterable.d.ts +0 -9
- package/dist/src/utils/get-stream-from-async-iterable.d.ts.map +0 -1
- package/dist/src/utils/get-stream-from-async-iterable.js +0 -43
- package/dist/src/utils/get-stream-from-async-iterable.js.map +0 -1
- package/dist/src/utils/handle-redirects.d.ts +0 -16
- package/dist/src/utils/handle-redirects.d.ts.map +0 -1
- package/dist/src/utils/handle-redirects.js +0 -84
- package/dist/src/utils/handle-redirects.js.map +0 -1
- package/dist/src/utils/is-accept-explicit.d.ts +0 -15
- package/dist/src/utils/is-accept-explicit.d.ts.map +0 -1
- package/dist/src/utils/is-accept-explicit.js +0 -26
- package/dist/src/utils/is-accept-explicit.js.map +0 -1
- package/dist/src/utils/request-headers.d.ts +0 -13
- package/dist/src/utils/request-headers.d.ts.map +0 -1
- package/dist/src/utils/request-headers.js +0 -63
- package/dist/src/utils/request-headers.js.map +0 -1
- package/dist/src/utils/select-output-type.d.ts +0 -17
- package/dist/src/utils/select-output-type.d.ts.map +0 -1
- package/dist/src/utils/select-output-type.js +0 -153
- package/dist/src/utils/select-output-type.js.map +0 -1
- package/dist/src/utils/tlru.d.ts +0 -15
- package/dist/src/utils/tlru.d.ts.map +0 -1
- package/dist/src/utils/tlru.js +0 -34
- package/dist/src/utils/tlru.js.map +0 -1
- package/dist/src/utils/walk-path.d.ts +0 -27
- package/dist/src/utils/walk-path.d.ts.map +0 -1
- package/dist/src/utils/walk-path.js +0 -45
- package/dist/src/utils/walk-path.js.map +0 -1
- package/src/plugins/plugin-handle-byte-range-context.ts +0 -30
- package/src/plugins/plugin-handle-cbor.ts +0 -107
- package/src/plugins/plugin-handle-dag-cbor-html-preview.ts +0 -295
- package/src/plugins/plugin-handle-dag-cbor.ts +0 -83
- package/src/plugins/plugin-handle-dag-pb.ts +0 -248
- package/src/plugins/plugin-handle-dag-walk.ts +0 -110
- package/src/plugins/plugin-handle-dir-index-html.ts +0 -72
- package/src/plugins/plugin-handle-json.ts +0 -80
- package/src/plugins/plugin-handle-raw.ts +0 -110
- package/src/plugins/plugins.ts +0 -5
- package/src/utils/byte-range-context.ts +0 -597
- package/src/utils/dag-cbor-to-safe-json.ts +0 -63
- package/src/utils/dir-index-html.ts +0 -505
- package/src/utils/get-peer-id-from-string.ts +0 -12
- package/src/utils/get-resolved-accept-header.ts +0 -42
- package/src/utils/get-stream-from-async-iterable.ts +0 -49
- package/src/utils/handle-redirects.ts +0 -109
- package/src/utils/is-accept-explicit.ts +0 -38
- package/src/utils/request-headers.ts +0 -65
- package/src/utils/select-output-type.ts +0 -175
- package/src/utils/tlru.ts +0 -42
- package/src/utils/walk-path.ts +0 -69
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { VerifiedFetchInit } from '../index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Converts an async iterator of Uint8Array bytes to a stream and returns the first chunk of bytes
|
|
4
|
-
*/
|
|
5
|
-
export declare function getStreamFromAsyncIterable(iterator: AsyncIterable<Uint8Array>, options?: Pick<VerifiedFetchInit, 'onProgress' | 'signal'>): Promise<{
|
|
6
|
-
stream: ReadableStream<Uint8Array>;
|
|
7
|
-
firstChunk: Uint8Array;
|
|
8
|
-
}>;
|
|
9
|
-
//# sourceMappingURL=get-stream-from-async-iterable.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-stream-from-async-iterable.d.ts","sourceRoot":"","sources":["../../../src/utils/get-stream-from-async-iterable.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD;;GAEG;AACH,wBAAsB,0BAA0B,CAAE,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CAwC1N"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AbortError } from '@libp2p/interface';
|
|
2
|
-
import { CustomProgressEvent } from 'progress-events';
|
|
3
|
-
import { NoContentError } from '../errors.js';
|
|
4
|
-
/**
|
|
5
|
-
* Converts an async iterator of Uint8Array bytes to a stream and returns the first chunk of bytes
|
|
6
|
-
*/
|
|
7
|
-
export async function getStreamFromAsyncIterable(iterator, options) {
|
|
8
|
-
const reader = iterator[Symbol.asyncIterator]();
|
|
9
|
-
const { value: firstChunk, done } = await reader.next();
|
|
10
|
-
if (done === true) {
|
|
11
|
-
throw new NoContentError();
|
|
12
|
-
}
|
|
13
|
-
const stream = new ReadableStream({
|
|
14
|
-
async start(controller) {
|
|
15
|
-
// the initial value is already available
|
|
16
|
-
options?.onProgress?.(new CustomProgressEvent('verified-fetch:request:progress:chunk'));
|
|
17
|
-
controller.enqueue(firstChunk);
|
|
18
|
-
},
|
|
19
|
-
async pull(controller) {
|
|
20
|
-
const { value, done } = await reader.next();
|
|
21
|
-
if (options?.signal?.aborted) {
|
|
22
|
-
controller.error(new AbortError(options.signal.reason ?? 'signal aborted by user'));
|
|
23
|
-
controller.close();
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (done === true) {
|
|
27
|
-
if (value != null) {
|
|
28
|
-
options?.onProgress?.(new CustomProgressEvent('verified-fetch:request:progress:chunk'));
|
|
29
|
-
controller.enqueue(value);
|
|
30
|
-
}
|
|
31
|
-
controller.close();
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
options?.onProgress?.(new CustomProgressEvent('verified-fetch:request:progress:chunk'));
|
|
35
|
-
controller.enqueue(value);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
stream,
|
|
40
|
-
firstChunk
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=get-stream-from-async-iterable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-stream-from-async-iterable.js","sourceRoot":"","sources":["../../../src/utils/get-stream-from-async-iterable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAE,QAAmC,EAAE,OAA0D;IAC/I,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;IAC/C,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IAEvD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,cAAc,EAAE,CAAA;IAC5B,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC;QAChC,KAAK,CAAC,KAAK,CAAE,UAAU;YACrB,yCAAyC;YACzC,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAO,uCAAuC,CAAC,CAAC,CAAA;YAC7F,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAChC,CAAC;QACD,KAAK,CAAC,IAAI,CAAE,UAAU;YACpB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;YAC3C,IAAI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;gBAC7B,UAAU,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,wBAAwB,CAAC,CAAC,CAAA;gBACnF,UAAU,CAAC,KAAK,EAAE,CAAA;gBAClB,OAAM;YACR,CAAC;YAED,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBAClB,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;oBAClB,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAO,uCAAuC,CAAC,CAAC,CAAA;oBAC7F,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;gBAC3B,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,CAAA;gBAClB,OAAM;YACR,CAAC;YAED,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAO,uCAAuC,CAAC,CAAC,CAAA;YAC7F,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;KACF,CAAC,CAAA;IAEF,OAAO;QACL,MAAM;QACN,UAAU;KACX,CAAA;AACH,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { VerifiedFetchInit, Resource } from '../index.js';
|
|
2
|
-
import type { AbortOptions, ComponentLogger } from '@libp2p/interface';
|
|
3
|
-
import type { CID } from 'multiformats/cid';
|
|
4
|
-
interface GetRedirectResponse {
|
|
5
|
-
cid: CID;
|
|
6
|
-
resource: Resource;
|
|
7
|
-
options?: Omit<VerifiedFetchInit, 'signal'> & AbortOptions;
|
|
8
|
-
logger: ComponentLogger;
|
|
9
|
-
/**
|
|
10
|
-
* Only used in testing.
|
|
11
|
-
*/
|
|
12
|
-
fetch?: typeof globalThis.fetch;
|
|
13
|
-
}
|
|
14
|
-
export declare function getRedirectResponse({ resource, options, logger, cid, fetch }: GetRedirectResponse): Promise<null | Response>;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=handle-redirects.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handle-redirects.d.ts","sourceRoot":"","sources":["../../../src/utils/handle-redirects.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,UAAU,mBAAmB;IAC3B,GAAG,EAAE,GAAG,CAAA;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,GAAG,YAAY,CAAA;IAC1D,MAAM,EAAE,eAAe,CAAA;IAEvB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAChC;AAWD,wBAAsB,mBAAmB,CAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,KAAwB,EAAE,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,CAgFtJ"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { SubdomainNotSupportedError } from '../errors.js';
|
|
2
|
-
import { parseURLString } from './parse-url-string.js';
|
|
3
|
-
import { movedPermanentlyResponse } from './responses.js';
|
|
4
|
-
function maybeAddTrailingSlash(path) {
|
|
5
|
-
// if it has an extension-like ending, don't add a trailing slash
|
|
6
|
-
if (path.match(/\.[a-zA-Z0-9]{1,4}$/) != null) {
|
|
7
|
-
return path;
|
|
8
|
-
}
|
|
9
|
-
return path.endsWith('/') ? path : `${path}/`;
|
|
10
|
-
}
|
|
11
|
-
// See https://specs.ipfs.tech/http-gateways/path-gateway/#location-response-header
|
|
12
|
-
export async function getRedirectResponse({ resource, options, logger, cid, fetch = globalThis.fetch }) {
|
|
13
|
-
const log = logger.forComponent('helia:verified-fetch:get-redirect-response');
|
|
14
|
-
if (typeof resource !== 'string' || options == null || ['ipfs://', 'ipns://'].some((prefix) => resource.startsWith(prefix))) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const headers = new Headers(options?.headers);
|
|
18
|
-
const forwardedHost = headers.get('x-forwarded-host');
|
|
19
|
-
const headerHost = headers.get('host');
|
|
20
|
-
const forwardedFor = headers.get('x-forwarded-for');
|
|
21
|
-
if (forwardedFor == null && forwardedHost == null && headerHost == null) {
|
|
22
|
-
log.trace('no redirect info found in headers');
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
log.trace('checking for redirect info');
|
|
26
|
-
// if x-forwarded-host is passed, we need to set the location header to the
|
|
27
|
-
// subdomain so that the browser can redirect to the correct subdomain
|
|
28
|
-
try {
|
|
29
|
-
const urlParts = parseURLString(resource);
|
|
30
|
-
const reqUrl = new URL(resource);
|
|
31
|
-
const actualHost = forwardedHost ?? reqUrl.host;
|
|
32
|
-
const subdomainUrl = new URL(reqUrl);
|
|
33
|
-
if (urlParts.protocol === 'ipfs' && cid.version === 0) {
|
|
34
|
-
subdomainUrl.host = `${cid.toV1()}.ipfs.${actualHost}`;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
subdomainUrl.host = `${urlParts.cidOrPeerIdOrDnsLink}.${urlParts.protocol}.${actualHost}`;
|
|
38
|
-
}
|
|
39
|
-
if (headerHost?.includes(urlParts.protocol) === true && subdomainUrl.host.includes(headerHost)) {
|
|
40
|
-
log.trace('request was for a subdomain already, not setting location header');
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
if (headerHost != null && !subdomainUrl.host.includes(headerHost)) {
|
|
44
|
-
log.trace('host header is not the same as the subdomain url host, not setting location header');
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
if (reqUrl.host === subdomainUrl.host) {
|
|
48
|
-
log.trace('req url is the same as the subdomain url, not setting location header');
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
subdomainUrl.pathname = maybeAddTrailingSlash(reqUrl.pathname.replace(`/${urlParts.cidOrPeerIdOrDnsLink}`, '').replace(`/${urlParts.protocol}`, ''));
|
|
52
|
-
log.trace('subdomain url %s', subdomainUrl.href);
|
|
53
|
-
const pathUrl = new URL(reqUrl, `${reqUrl.protocol}//${actualHost}`);
|
|
54
|
-
pathUrl.pathname = maybeAddTrailingSlash(reqUrl.pathname);
|
|
55
|
-
log.trace('path url %s', pathUrl.href);
|
|
56
|
-
// try to query subdomain with HEAD request to see if it's supported
|
|
57
|
-
try {
|
|
58
|
-
const subdomainTest = await fetch(subdomainUrl, { method: 'HEAD' });
|
|
59
|
-
if (subdomainTest.ok) {
|
|
60
|
-
log('subdomain supported, redirecting to subdomain');
|
|
61
|
-
return movedPermanentlyResponse(resource.toString(), subdomainUrl.href);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
log('subdomain not supported, subdomain failed with status %s %s', subdomainTest.status, subdomainTest.statusText);
|
|
65
|
-
throw new SubdomainNotSupportedError('subdomain not supported');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
log('subdomain not supported - %e', err);
|
|
70
|
-
if (pathUrl.href === reqUrl.href) {
|
|
71
|
-
log('path url is the same as the request url, not setting location header');
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
// pathUrl is different from request URL (maybe even with just a trailing slash)
|
|
75
|
-
return movedPermanentlyResponse(resource.toString(), pathUrl.href);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
// if it's not a full URL, we have nothing left to do.
|
|
80
|
-
log.error('error setting location header for x-forwarded-host', e);
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=handle-redirects.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handle-redirects.js","sourceRoot":"","sources":["../../../src/utils/handle-redirects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA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ED,gFAAgF;YAChF,OAAO,wBAAwB,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QACpE,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,sDAAsD;QACtD,GAAG,CAAC,KAAK,CAAC,oDAAoD,EAAE,CAAC,CAAC,CAAA;IACpE,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { UrlQuery } from '../index.ts';
|
|
2
|
-
export interface IsAcceptExplicitOptions {
|
|
3
|
-
query?: UrlQuery;
|
|
4
|
-
headers: Headers;
|
|
5
|
-
}
|
|
6
|
-
export declare function isExplicitAcceptHeader(headers: Headers): boolean;
|
|
7
|
-
export declare function isExplicitFormatQuery(query?: UrlQuery): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* The user can provide an explicit `accept` header in the request headers or a
|
|
10
|
-
* `format` query parameter in the URL.
|
|
11
|
-
*
|
|
12
|
-
* If either of these are provided, this function returns true.
|
|
13
|
-
*/
|
|
14
|
-
export declare function isExplicitIpldAcceptRequest({ query, headers }: IsAcceptExplicitOptions): boolean;
|
|
15
|
-
//# sourceMappingURL=is-accept-explicit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-accept-explicit.d.ts","sourceRoot":"","sources":["../../../src/utils/is-accept-explicit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,wBAAgB,sBAAsB,CAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CASjE;AAED,wBAAgB,qBAAqB,CAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAQhE;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAEjG"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { FORMAT_TO_MIME_TYPE } from './select-output-type.js';
|
|
2
|
-
export function isExplicitAcceptHeader(headers) {
|
|
3
|
-
const incomingAcceptHeader = headers.get('accept');
|
|
4
|
-
if (incomingAcceptHeader == null) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
return Object.values(FORMAT_TO_MIME_TYPE)
|
|
8
|
-
.some(mimeType => incomingAcceptHeader.includes(mimeType));
|
|
9
|
-
}
|
|
10
|
-
export function isExplicitFormatQuery(query) {
|
|
11
|
-
const formatQuery = query?.format;
|
|
12
|
-
if (formatQuery != null && Object.keys(FORMAT_TO_MIME_TYPE).includes(formatQuery)) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* The user can provide an explicit `accept` header in the request headers or a
|
|
19
|
-
* `format` query parameter in the URL.
|
|
20
|
-
*
|
|
21
|
-
* If either of these are provided, this function returns true.
|
|
22
|
-
*/
|
|
23
|
-
export function isExplicitIpldAcceptRequest({ query, headers }) {
|
|
24
|
-
return isExplicitAcceptHeader(headers) || isExplicitFormatQuery(query);
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=is-accept-explicit.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-accept-explicit.js","sourceRoot":"","sources":["../../../src/utils/is-accept-explicit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAQ7D,MAAM,UAAU,sBAAsB,CAAE,OAAgB;IACtD,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAElD,IAAI,oBAAoB,IAAI,IAAI,EAAE,CAAC;QACjC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;SACtC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,oBAAoB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;AAC9D,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAE,KAAgB;IACrD,MAAM,WAAW,GAAG,KAAK,EAAE,MAAM,CAAA;IAEjC,IAAI,WAAW,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAClF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAE,EAAE,KAAK,EAAE,OAAO,EAA2B;IACtF,OAAO,sBAAsB,CAAC,OAAO,CAAC,IAAI,qBAAqB,CAAC,KAAK,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare function getHeader(headers: HeadersInit | undefined, header: string): string | undefined;
|
|
2
|
-
/**
|
|
3
|
-
* Given two ints from a Range header, and potential fileSize, returns:
|
|
4
|
-
* 1. number of bytes the response should contain.
|
|
5
|
-
* 2. the start index of the range. // inclusive
|
|
6
|
-
* 3. the end index of the range. // inclusive
|
|
7
|
-
*/
|
|
8
|
-
export declare function calculateByteRangeIndexes(start: number | undefined, end: number | undefined, fileSize?: number): {
|
|
9
|
-
byteSize?: number;
|
|
10
|
-
start?: number;
|
|
11
|
-
end?: number;
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=request-headers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-headers.d.ts","sourceRoot":"","sources":["../../../src/utils/request-headers.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAE,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiB/F;AAED;;;;;GAKG;AAEH,wBAAgB,yBAAyB,CAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAoCrK"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { InvalidRangeError } from '../errors.js';
|
|
2
|
-
export function getHeader(headers, header) {
|
|
3
|
-
if (headers == null) {
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
if (headers instanceof Headers) {
|
|
7
|
-
return headers.get(header) ?? undefined;
|
|
8
|
-
}
|
|
9
|
-
if (Array.isArray(headers)) {
|
|
10
|
-
const entry = headers.find(([key]) => key.toLowerCase() === header.toLowerCase());
|
|
11
|
-
return entry?.[1];
|
|
12
|
-
}
|
|
13
|
-
const key = Object.keys(headers).find(k => k.toLowerCase() === header.toLowerCase());
|
|
14
|
-
if (key == null) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
return headers[key];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Given two ints from a Range header, and potential fileSize, returns:
|
|
21
|
-
* 1. number of bytes the response should contain.
|
|
22
|
-
* 2. the start index of the range. // inclusive
|
|
23
|
-
* 3. the end index of the range. // inclusive
|
|
24
|
-
*/
|
|
25
|
-
// eslint-disable-next-line complexity
|
|
26
|
-
export function calculateByteRangeIndexes(start, end, fileSize) {
|
|
27
|
-
if ((start ?? 0) > (end ?? Infinity)) {
|
|
28
|
-
throw new InvalidRangeError('Invalid range: Range-start index is greater than range-end index.');
|
|
29
|
-
}
|
|
30
|
-
if (start != null && (end ?? 0) >= (fileSize ?? Infinity)) {
|
|
31
|
-
throw new InvalidRangeError('Invalid range: Range-end index is greater than or equal to the size of the file.');
|
|
32
|
-
}
|
|
33
|
-
if (start == null && (end ?? 0) > (fileSize ?? Infinity)) {
|
|
34
|
-
throw new InvalidRangeError('Invalid range: Range-end index is greater than the size of the file.');
|
|
35
|
-
}
|
|
36
|
-
if (start != null && start < 0) {
|
|
37
|
-
throw new InvalidRangeError('Invalid range: Range-start index cannot be negative.');
|
|
38
|
-
}
|
|
39
|
-
if (start != null && end != null) {
|
|
40
|
-
return { byteSize: end - start + 1, start, end };
|
|
41
|
-
}
|
|
42
|
-
else if (start == null && end != null) {
|
|
43
|
-
// suffix byte range requested
|
|
44
|
-
if (fileSize == null) {
|
|
45
|
-
return { end };
|
|
46
|
-
}
|
|
47
|
-
if (end === fileSize) {
|
|
48
|
-
return { byteSize: fileSize, start: 0, end: fileSize - 1 };
|
|
49
|
-
}
|
|
50
|
-
return { byteSize: end, start: fileSize - end, end: fileSize - 1 };
|
|
51
|
-
}
|
|
52
|
-
else if (start != null && end == null) {
|
|
53
|
-
if (fileSize == null) {
|
|
54
|
-
// we only have the start index, and no fileSize, so we can't return a valid range.
|
|
55
|
-
return { start };
|
|
56
|
-
}
|
|
57
|
-
const end = fileSize - 1;
|
|
58
|
-
const byteSize = fileSize - start;
|
|
59
|
-
return { byteSize, start, end };
|
|
60
|
-
}
|
|
61
|
-
return { byteSize: fileSize, start: 0, end: fileSize != null ? fileSize - 1 : 0 };
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=request-headers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-headers.js","sourceRoot":"","sources":["../../../src/utils/request-headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,MAAM,UAAU,SAAS,CAAE,OAAgC,EAAE,MAAc;IACzE,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,OAAO,YAAY,OAAO,EAAE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AAE,GAAG,EAAE,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AACnF,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RequestFormatShorthand } from '../index.js';
|
|
2
|
-
import type { CID } from 'multiformats/cid';
|
|
3
|
-
export interface AcceptHeader {
|
|
4
|
-
mimeType: string;
|
|
5
|
-
options: Record<string, string>;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Selects an output mime-type based on the CID and a passed `Accept` header
|
|
9
|
-
*/
|
|
10
|
-
export declare function selectOutputType(cid: CID, accept?: string): AcceptHeader | undefined;
|
|
11
|
-
export declare const FORMAT_TO_MIME_TYPE: Record<RequestFormatShorthand, string>;
|
|
12
|
-
/**
|
|
13
|
-
* Converts a `format=...` query param to a mime type as would be found in the
|
|
14
|
-
* `Accept` header, if a valid mapping is available
|
|
15
|
-
*/
|
|
16
|
-
export declare function queryFormatToAcceptHeader(format?: RequestFormatShorthand): string | undefined;
|
|
17
|
-
//# sourceMappingURL=select-output-type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-output-type.d.ts","sourceRoot":"","sources":["../../../src/utils/select-output-type.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAqE3C,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAMrF;AAiED,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAStE,CAAA;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAE,MAAM,CAAC,EAAE,sBAAsB,GAAG,MAAM,GAAG,SAAS,CAI9F"}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { code as dagCborCode } from '@ipld/dag-cbor';
|
|
2
|
-
import { code as dagJsonCode } from '@ipld/dag-json';
|
|
3
|
-
import { code as dagPbCode } from '@ipld/dag-pb';
|
|
4
|
-
import { code as jsonCode } from 'multiformats/codecs/json';
|
|
5
|
-
import { code as rawCode } from 'multiformats/codecs/raw';
|
|
6
|
-
import { CODEC_CBOR } from "../constants.js";
|
|
7
|
-
/**
|
|
8
|
-
* This maps supported response types for each codec supported by verified-fetch
|
|
9
|
-
*/
|
|
10
|
-
const CID_TYPE_MAP = {
|
|
11
|
-
[dagCborCode]: [
|
|
12
|
-
'application/json',
|
|
13
|
-
'application/vnd.ipld.dag-cbor',
|
|
14
|
-
'application/cbor',
|
|
15
|
-
'application/vnd.ipld.dag-json',
|
|
16
|
-
'application/octet-stream',
|
|
17
|
-
'application/vnd.ipld.raw',
|
|
18
|
-
'application/vnd.ipfs.ipns-record',
|
|
19
|
-
'application/vnd.ipld.car',
|
|
20
|
-
'text/html'
|
|
21
|
-
],
|
|
22
|
-
[dagJsonCode]: [
|
|
23
|
-
'application/json',
|
|
24
|
-
'application/vnd.ipld.dag-cbor',
|
|
25
|
-
'application/cbor',
|
|
26
|
-
'application/vnd.ipld.dag-json',
|
|
27
|
-
'application/octet-stream',
|
|
28
|
-
'application/vnd.ipld.raw',
|
|
29
|
-
'application/vnd.ipfs.ipns-record',
|
|
30
|
-
'application/vnd.ipld.car'
|
|
31
|
-
],
|
|
32
|
-
[jsonCode]: [
|
|
33
|
-
'application/json',
|
|
34
|
-
'application/vnd.ipld.dag-cbor',
|
|
35
|
-
'application/cbor',
|
|
36
|
-
'application/vnd.ipld.dag-json',
|
|
37
|
-
'application/octet-stream',
|
|
38
|
-
'application/vnd.ipld.raw',
|
|
39
|
-
'application/vnd.ipfs.ipns-record',
|
|
40
|
-
'application/vnd.ipld.car'
|
|
41
|
-
],
|
|
42
|
-
[dagPbCode]: [
|
|
43
|
-
'application/octet-stream',
|
|
44
|
-
'application/json',
|
|
45
|
-
'application/vnd.ipld.dag-cbor',
|
|
46
|
-
'application/cbor',
|
|
47
|
-
'application/vnd.ipld.dag-json',
|
|
48
|
-
'application/vnd.ipld.raw',
|
|
49
|
-
'application/vnd.ipfs.ipns-record',
|
|
50
|
-
'application/vnd.ipld.car',
|
|
51
|
-
'application/x-tar'
|
|
52
|
-
],
|
|
53
|
-
[rawCode]: [
|
|
54
|
-
'application/octet-stream',
|
|
55
|
-
'application/vnd.ipld.raw',
|
|
56
|
-
'application/vnd.ipfs.ipns-record',
|
|
57
|
-
'application/vnd.ipld.dag-json',
|
|
58
|
-
'application/vnd.ipld.car',
|
|
59
|
-
'application/x-tar'
|
|
60
|
-
],
|
|
61
|
-
[CODEC_CBOR]: [
|
|
62
|
-
'application/json',
|
|
63
|
-
'application/vnd.ipld.dag-cbor',
|
|
64
|
-
'application/cbor',
|
|
65
|
-
'application/vnd.ipld.dag-json',
|
|
66
|
-
'application/octet-stream',
|
|
67
|
-
'application/vnd.ipld.raw',
|
|
68
|
-
'application/vnd.ipfs.ipns-record',
|
|
69
|
-
'application/vnd.ipld.car',
|
|
70
|
-
'text/html'
|
|
71
|
-
]
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Selects an output mime-type based on the CID and a passed `Accept` header
|
|
75
|
-
*/
|
|
76
|
-
export function selectOutputType(cid, accept) {
|
|
77
|
-
const cidMimeTypes = CID_TYPE_MAP[cid.code] ?? [];
|
|
78
|
-
if (accept != null) {
|
|
79
|
-
return chooseMimeType(accept, cidMimeTypes);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function chooseMimeType(accept, validMimeTypes) {
|
|
83
|
-
const requestedMimeTypes = accept
|
|
84
|
-
.split(',')
|
|
85
|
-
.map(s => {
|
|
86
|
-
const parts = s.trim().split(';');
|
|
87
|
-
const options = {
|
|
88
|
-
q: '0'
|
|
89
|
-
};
|
|
90
|
-
for (let i = 1; i < parts.length; i++) {
|
|
91
|
-
const [key, value] = parts[i].split('=').map(s => s.trim());
|
|
92
|
-
options[key] = value;
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
mimeType: `${parts[0]}`.trim(),
|
|
96
|
-
options
|
|
97
|
-
};
|
|
98
|
-
})
|
|
99
|
-
.sort((a, b) => {
|
|
100
|
-
if (a.options.q === b.options.q) {
|
|
101
|
-
return 0;
|
|
102
|
-
}
|
|
103
|
-
if (a.options.q > b.options.q) {
|
|
104
|
-
return -1;
|
|
105
|
-
}
|
|
106
|
-
return 1;
|
|
107
|
-
});
|
|
108
|
-
for (const headerFormat of requestedMimeTypes) {
|
|
109
|
-
for (const mimeType of validMimeTypes) {
|
|
110
|
-
if (headerFormat.mimeType.includes(mimeType)) {
|
|
111
|
-
return headerFormat;
|
|
112
|
-
}
|
|
113
|
-
if (headerFormat.mimeType === '*/*') {
|
|
114
|
-
return {
|
|
115
|
-
mimeType,
|
|
116
|
-
options: headerFormat.options
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
if (headerFormat.mimeType.startsWith('*/') && mimeType.split('/')[1] === headerFormat.mimeType.split('/')[1]) {
|
|
120
|
-
return {
|
|
121
|
-
mimeType,
|
|
122
|
-
options: headerFormat.options
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
if (headerFormat.mimeType.endsWith('/*') && mimeType.split('/')[0] === headerFormat.mimeType.split('/')[0]) {
|
|
126
|
-
return {
|
|
127
|
-
mimeType,
|
|
128
|
-
options: headerFormat.options
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
export const FORMAT_TO_MIME_TYPE = {
|
|
135
|
-
raw: 'application/vnd.ipld.raw',
|
|
136
|
-
car: 'application/vnd.ipld.car',
|
|
137
|
-
'dag-json': 'application/vnd.ipld.dag-json',
|
|
138
|
-
'dag-cbor': 'application/vnd.ipld.dag-cbor',
|
|
139
|
-
json: 'application/json',
|
|
140
|
-
cbor: 'application/cbor',
|
|
141
|
-
'ipns-record': 'application/vnd.ipfs.ipns-record',
|
|
142
|
-
tar: 'application/x-tar'
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Converts a `format=...` query param to a mime type as would be found in the
|
|
146
|
-
* `Accept` header, if a valid mapping is available
|
|
147
|
-
*/
|
|
148
|
-
export function queryFormatToAcceptHeader(format) {
|
|
149
|
-
if (format != null) {
|
|
150
|
-
return FORMAT_TO_MIME_TYPE[format];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
//# sourceMappingURL=select-output-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-output-type.js","sourceRoot":"","sources":["../../../src/utils/select-output-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI5C;;GAEG;AACH,MAAM,YAAY,GAA6B;IAC7C,CAAC,WAAW,CAAC,EAAE;QACb,kBAAkB;QAClB,+BAA+B;QAC/B,kBAAkB;QAClB,+BAA+B;QAC/B,0BAA0B;QAC1B,0BAA0B;QAC1B,kCAAkC;QAClC,0BAA0B;QAC1B,WAAW;KACZ;IACD,CAAC,WAAW,CAAC,EAAE;QACb,kBAAkB;QAClB,+BA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6
|
-
export declare class TLRU<T> {
|
|
7
|
-
private readonly lru;
|
|
8
|
-
constructor(maxSize: number);
|
|
9
|
-
get(key: string): T | undefined;
|
|
10
|
-
set(key: string, value: T, ttlMs: number): void;
|
|
11
|
-
has(key: string): boolean;
|
|
12
|
-
remove(key: string): void;
|
|
13
|
-
clear(): void;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=tlru.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tlru.d.ts","sourceRoot":"","sources":["../../../src/utils/tlru.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qBAAa,IAAI,CAAC,CAAC;IACjB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAqB;gBAE5B,OAAO,EAAE,MAAM;IAI5B,GAAG,CAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIhC,GAAG,CAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAMhD,GAAG,CAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAU1B,MAAM,CAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAI1B,KAAK,IAAK,IAAI;CAGf"}
|
package/dist/src/utils/tlru.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import QuickLRU from 'quick-lru';
|
|
2
|
-
/**
|
|
3
|
-
* Time Aware Least Recent Used Cache
|
|
4
|
-
*
|
|
5
|
-
* @see https://arxiv.org/pdf/1801.00390
|
|
6
|
-
*/
|
|
7
|
-
export class TLRU {
|
|
8
|
-
lru;
|
|
9
|
-
constructor(maxSize) {
|
|
10
|
-
this.lru = new QuickLRU({ maxSize });
|
|
11
|
-
}
|
|
12
|
-
get(key) {
|
|
13
|
-
return this.lru.get(key);
|
|
14
|
-
}
|
|
15
|
-
set(key, value, ttlMs) {
|
|
16
|
-
this.lru.set(key, value, {
|
|
17
|
-
maxAge: Date.now() + ttlMs
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
has(key) {
|
|
21
|
-
const value = this.get(key);
|
|
22
|
-
if (value != null) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
remove(key) {
|
|
28
|
-
this.lru.delete(key);
|
|
29
|
-
}
|
|
30
|
-
clear() {
|
|
31
|
-
this.lru.clear();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=tlru.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tlru.js","sourceRoot":"","sources":["../../../src/utils/tlru.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAA;AAEhC;;;;GAIG;AACH,MAAM,OAAO,IAAI;IACE,GAAG,CAAqB;IAEzC,YAAa,OAAe;QAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IACtC,CAAC;IAED,GAAG,CAAE,GAAW;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;IAED,GAAG,CAAE,GAAW,EAAE,KAAQ,EAAE,KAAa;QACvC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE;YACvB,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;SAC3B,CAAC,CAAA;IACJ,CAAC;IAED,GAAG,CAAE,GAAW;QACd,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE3B,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,CAAE,GAAW;QACjB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { PluginContext } from '../plugins/types.js';
|
|
2
|
-
import type { Logger } from '@libp2p/interface';
|
|
3
|
-
import type { Blockstore } from 'interface-blockstore';
|
|
4
|
-
import type { ExporterOptions, ReadableStorage, ObjectNode, UnixFSEntry } from 'ipfs-unixfs-exporter';
|
|
5
|
-
import type { CID } from 'multiformats/cid';
|
|
6
|
-
export interface PathWalkerOptions extends ExporterOptions {
|
|
7
|
-
}
|
|
8
|
-
export interface PathWalkerResponse {
|
|
9
|
-
ipfsRoots: CID[];
|
|
10
|
-
terminalElement: UnixFSEntry;
|
|
11
|
-
}
|
|
12
|
-
export interface PathWalkerFn {
|
|
13
|
-
(blockstore: ReadableStorage, path: string, options?: PathWalkerOptions): Promise<PathWalkerResponse>;
|
|
14
|
-
}
|
|
15
|
-
export declare function isObjectNode(node: UnixFSEntry): node is ObjectNode;
|
|
16
|
-
/**
|
|
17
|
-
* Attempts to walk the path in the blockstore, returning ipfsRoots needed to resolve the path, and the terminal element.
|
|
18
|
-
* If the signal is aborted, the function will throw an AbortError
|
|
19
|
-
* If a terminal element is not found, a notFoundResponse is returned
|
|
20
|
-
* If another unknown error occurs, a badGatewayResponse is returned
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
export declare function handlePathWalking({ cid, path, resource, options, blockstore, log }: PluginContext & {
|
|
24
|
-
blockstore: Blockstore;
|
|
25
|
-
log: Logger;
|
|
26
|
-
}): Promise<PathWalkerResponse | Response>;
|
|
27
|
-
//# sourceMappingURL=walk-path.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"walk-path.d.ts","sourceRoot":"","sources":["../../../src/utils/walk-path.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACrG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,MAAM,WAAW,iBAAkB,SAAQ,eAAe;CAEzD;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,GAAG,EAAE,CAAA;IAChB,eAAe,EAAE,WAAW,CAAA;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,UAAU,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACtG;AAqBD,wBAAgB,YAAY,CAAE,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,UAAU,CAEnE;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAE,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,aAAa,GAAG;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,kBAAkB,GAAG,QAAQ,CAAC,CAe3L"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { DoesNotExistError } from '@helia/unixfs/errors';
|
|
2
|
-
import { AbortError } from '@libp2p/interface';
|
|
3
|
-
import { walkPath as exporterWalk } from 'ipfs-unixfs-exporter';
|
|
4
|
-
import { badGatewayResponse, notFoundResponse } from './responses.js';
|
|
5
|
-
async function walkPath(blockstore, path, options) {
|
|
6
|
-
const ipfsRoots = [];
|
|
7
|
-
let terminalElement;
|
|
8
|
-
for await (const entry of exporterWalk(path, blockstore, options)) {
|
|
9
|
-
ipfsRoots.push(entry.cid);
|
|
10
|
-
terminalElement = entry;
|
|
11
|
-
}
|
|
12
|
-
if (terminalElement == null) {
|
|
13
|
-
throw new DoesNotExistError('No terminal element found');
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
ipfsRoots,
|
|
17
|
-
terminalElement
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export function isObjectNode(node) {
|
|
21
|
-
return node.type === 'object';
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Attempts to walk the path in the blockstore, returning ipfsRoots needed to resolve the path, and the terminal element.
|
|
25
|
-
* If the signal is aborted, the function will throw an AbortError
|
|
26
|
-
* If a terminal element is not found, a notFoundResponse is returned
|
|
27
|
-
* If another unknown error occurs, a badGatewayResponse is returned
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
export async function handlePathWalking({ cid, path, resource, options, blockstore, log }) {
|
|
31
|
-
try {
|
|
32
|
-
return await walkPath(blockstore, `${cid}/${path.join('/')}`, options);
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
if (options?.signal?.aborted) {
|
|
36
|
-
throw new AbortError(options?.signal?.reason);
|
|
37
|
-
}
|
|
38
|
-
if (['ERR_NO_PROP', 'ERR_NO_TERMINAL_ELEMENT', 'ERR_NOT_FOUND'].includes(err.code)) {
|
|
39
|
-
return notFoundResponse(resource);
|
|
40
|
-
}
|
|
41
|
-
log.error('error walking path "%s" - %e', path, err);
|
|
42
|
-
return badGatewayResponse(resource, 'Error walking path');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=walk-path.js.map
|