@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,IAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -641,13 +641,13 @@
|
|
|
641
641
|
* Inspects the current `PluginContext` (which includes the CID, path, query, accept header, etc.)
|
|
642
642
|
* and returns `true` if the plugin can operate on the current state of the request.
|
|
643
643
|
*
|
|
644
|
-
* - **`handle(context: PluginContext): Promise<Response |
|
|
645
|
-
* Performs the plugin’s work. It
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
644
|
+
* - **`handle(context: PluginContext): Promise<Response | undefined>`**
|
|
645
|
+
* Performs the plugin’s work. It will only be executed if `canHandle` previously returned `true`.
|
|
646
|
+
* It may:
|
|
647
|
+
* - **Return a `Response`**: This stops the pipeline immediately and returns the response.
|
|
648
|
+
* - **Return `undefined`**: This indicates that the plugin has only partially processed the request
|
|
649
|
+
* (for example, by performing path walking or decoding) and the pipeline should continue.
|
|
650
|
+
* - **Throw an `Error`**: An Internal Server Error will be returned
|
|
651
651
|
*
|
|
652
652
|
* ### Plugin Pipeline
|
|
653
653
|
*
|
|
@@ -745,12 +745,12 @@
|
|
|
745
745
|
* canHandle(context: PluginContext): boolean {
|
|
746
746
|
* // Only handle requests if the Accept header matches your custom type
|
|
747
747
|
* // Or check context for pathDetails, custom values, etc...
|
|
748
|
-
* return context.accept === 'application/vnd.my-custom-type'
|
|
748
|
+
* return context.accept?.mimeType === 'application/vnd.my-custom-type'
|
|
749
749
|
* }
|
|
750
750
|
*
|
|
751
751
|
* async handle(context: PluginContext): Promise<Response | null> {
|
|
752
752
|
* // Perform any partial processing here, e.g., modify the context:
|
|
753
|
-
* context.customProcessed = true
|
|
753
|
+
* context.customProcessed = true
|
|
754
754
|
*
|
|
755
755
|
* // If you are ready to finalize the response:
|
|
756
756
|
* return new Response('Hello, world!', {
|
|
@@ -758,7 +758,7 @@
|
|
|
758
758
|
* headers: {
|
|
759
759
|
* 'Content-Type': 'text/plain'
|
|
760
760
|
* }
|
|
761
|
-
* })
|
|
761
|
+
* })
|
|
762
762
|
*
|
|
763
763
|
* // Or, if further processing is needed by another plugin, simply return null.
|
|
764
764
|
* }
|
|
@@ -784,47 +784,6 @@
|
|
|
784
784
|
* const fetch = await createVerifiedFetch(helia, { plugins })
|
|
785
785
|
* ```
|
|
786
786
|
*
|
|
787
|
-
* ---
|
|
788
|
-
*
|
|
789
|
-
* ### Error Handling in the Plugin Pipeline
|
|
790
|
-
*
|
|
791
|
-
* Verified‑Fetch distinguishes between two types of errors thrown by plugins:
|
|
792
|
-
*
|
|
793
|
-
* - **PluginError (Non‑Fatal):**
|
|
794
|
-
* - Use this when your plugin encounters an issue that should be logged but does not prevent the pipeline
|
|
795
|
-
* from continuing.
|
|
796
|
-
* - When a plugin throws a `PluginError`, the error is logged and the pipeline continues with the next plugin.
|
|
797
|
-
*
|
|
798
|
-
* - **PluginFatalError (Fatal):**
|
|
799
|
-
* - Use this when a critical error occurs that should immediately abort the request.
|
|
800
|
-
* - When a plugin throws a `PluginFatalError`, the pipeline immediately terminates and the provided error
|
|
801
|
-
* response is returned.
|
|
802
|
-
*
|
|
803
|
-
* @example Plugin error Handling
|
|
804
|
-
*
|
|
805
|
-
* ```typescript
|
|
806
|
-
* import { PluginError, PluginFatalError } from '@helia/verified-fetch'
|
|
807
|
-
*
|
|
808
|
-
* // async handle(context: PluginContext): Promise<Response | null> {
|
|
809
|
-
* const recoverable = Math.random() > 0.5 // Use more sophisticated logic here ;)
|
|
810
|
-
* if (recoverable === true) {
|
|
811
|
-
* throw new PluginError('MY_CUSTOM_WARNING', 'A non‑fatal issue occurred', {
|
|
812
|
-
* details: {
|
|
813
|
-
* someKey: 'Additional details here'
|
|
814
|
-
* }
|
|
815
|
-
* });
|
|
816
|
-
* }
|
|
817
|
-
*
|
|
818
|
-
* if (recoverable === false) {
|
|
819
|
-
* throw new PluginFatalError('MY_CUSTOM_FATAL', 'A critical error occurred', {
|
|
820
|
-
* response: new Response('Something happened', { status: 500 }) // Required: supply your own error response
|
|
821
|
-
* });
|
|
822
|
-
* }
|
|
823
|
-
*
|
|
824
|
-
* // Otherwise, continue processing...
|
|
825
|
-
* // }
|
|
826
|
-
* ```
|
|
827
|
-
*
|
|
828
787
|
* ### How the Plugin Pipeline Works
|
|
829
788
|
*
|
|
830
789
|
* - **Shared Context:**
|
|
@@ -842,16 +801,15 @@
|
|
|
842
801
|
* This means you do not have to specify a rigid order, each plugin simply checks the context and acts if appropriate.
|
|
843
802
|
*
|
|
844
803
|
* - **Error Handling:**
|
|
845
|
-
* -
|
|
846
|
-
* - A thrown `PluginFatalError` immediately stops the pipeline and returns the error response.
|
|
804
|
+
* - Any thrown error immediately stops the pipeline and returns the error response.
|
|
847
805
|
*
|
|
848
806
|
* For a detailed explanation of the pipeline, please refer to the discussion in [Issue #167](https://github.com/ipfs/helia-verified-fetch/issues/167).
|
|
849
807
|
*/
|
|
850
808
|
import type { VerifiedFetchPluginFactory } from './plugins/types.js';
|
|
851
|
-
import type {
|
|
809
|
+
import type { DNSLink, ResolveProgressEvents as ResolveDNSLinkProgressEvents } from '@helia/dnslink';
|
|
852
810
|
import type { GetBlockProgressEvents, Helia } from '@helia/interface';
|
|
853
|
-
import type {
|
|
854
|
-
import type { ServiceMap } from '@libp2p/interface';
|
|
811
|
+
import type { IPNSResolver } from '@helia/ipns';
|
|
812
|
+
import type { AbortOptions, ServiceMap } from '@libp2p/interface';
|
|
855
813
|
import type { DNSResolvers } from '@multiformats/dns';
|
|
856
814
|
import type { DNSResolver } from '@multiformats/dns/resolvers';
|
|
857
815
|
import type { HeliaInit } from 'helia';
|
|
@@ -859,6 +817,21 @@ import type { ExporterProgressEvents } from 'ipfs-unixfs-exporter';
|
|
|
859
817
|
import type { Libp2pOptions } from 'libp2p';
|
|
860
818
|
import type { CID } from 'multiformats/cid';
|
|
861
819
|
import type { ProgressEvent, ProgressOptions } from 'progress-events';
|
|
820
|
+
export type RequestFormatShorthand = 'raw' | 'car' | 'tar' | 'ipns-record' | 'dag-json' | 'dag-cbor' | 'json' | 'cbor';
|
|
821
|
+
export type SupportedBodyTypes = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array> | null;
|
|
822
|
+
/**
|
|
823
|
+
* A ContentTypeParser attempts to return the mime type of a given file. It
|
|
824
|
+
* receives the first chunk of the file data and the file name, if it is
|
|
825
|
+
* available. The function can be sync or async and if it returns/resolves to
|
|
826
|
+
* `undefined`, `application/octet-stream` will be used.
|
|
827
|
+
*/
|
|
828
|
+
export interface ContentTypeParser {
|
|
829
|
+
/**
|
|
830
|
+
* Attempt to determine a mime type, either via of the passed bytes or the
|
|
831
|
+
* filename if it is available.
|
|
832
|
+
*/
|
|
833
|
+
(bytes: Uint8Array, fileName?: string): Promise<string | undefined> | string | undefined;
|
|
834
|
+
}
|
|
862
835
|
/**
|
|
863
836
|
* The types for the first argument of the `verifiedFetch` function.
|
|
864
837
|
*/
|
|
@@ -868,7 +841,7 @@ export interface ResourceDetail {
|
|
|
868
841
|
}
|
|
869
842
|
export interface CIDDetail {
|
|
870
843
|
cid: CID;
|
|
871
|
-
path
|
|
844
|
+
path?: string;
|
|
872
845
|
}
|
|
873
846
|
export interface CIDDetailError extends CIDDetail {
|
|
874
847
|
error: Error;
|
|
@@ -971,10 +944,20 @@ export interface CreateVerifiedFetchOptions {
|
|
|
971
944
|
* If you want to replace one of the default plugins, you can do so by passing a plugin with the same name.
|
|
972
945
|
*/
|
|
973
946
|
plugins?: VerifiedFetchPluginFactory[];
|
|
947
|
+
/**
|
|
948
|
+
* Used to resolve IPNS names
|
|
949
|
+
*/
|
|
950
|
+
ipnsResolver?: IPNSResolver;
|
|
951
|
+
/**
|
|
952
|
+
* Used to resolve DNSLink entries to IPNS names or CIDs
|
|
953
|
+
*/
|
|
954
|
+
dnsLink?: DNSLink;
|
|
955
|
+
/**
|
|
956
|
+
* Used to turn URLs into CIDs/paths
|
|
957
|
+
*/
|
|
958
|
+
urlResolver?: URLResolver;
|
|
974
959
|
}
|
|
975
|
-
export type
|
|
976
|
-
export type BubbledProgressEvents = ExporterProgressEvents | GetBlockProgressEvents | ResolveDNSLinkProgressEvents;
|
|
977
|
-
export type VerifiedFetchProgressEvents = ProgressEvent<'verified-fetch:request:start', CIDDetail> | ProgressEvent<'verified-fetch:request:info', string> | ProgressEvent<'verified-fetch:request:progress:chunk', CIDDetail> | ProgressEvent<'verified-fetch:request:end', CIDDetail> | ProgressEvent<'verified-fetch:request:error', CIDDetailError>;
|
|
960
|
+
export type VerifiedFetchProgressEvents = ProgressEvent<'verified-fetch:request:start', CIDDetail> | ProgressEvent<'verified-fetch:request:info', string> | ProgressEvent<'verified-fetch:request:progress:chunk'> | ProgressEvent<'verified-fetch:request:end', CIDDetail> | ProgressEvent<'verified-fetch:request:error', CIDDetailError> | ExporterProgressEvents | GetBlockProgressEvents | ResolveDNSLinkProgressEvents;
|
|
978
961
|
/**
|
|
979
962
|
* Options for the `fetch` function returned by `createVerifiedFetch`.
|
|
980
963
|
*
|
|
@@ -982,7 +965,7 @@ export type VerifiedFetchProgressEvents = ProgressEvent<'verified-fetch:request:
|
|
|
982
965
|
* passed to `fetch` in browsers, plus an `onProgress` option to listen for
|
|
983
966
|
* progress events.
|
|
984
967
|
*/
|
|
985
|
-
export interface VerifiedFetchInit extends RequestInit, ProgressOptions<
|
|
968
|
+
export interface VerifiedFetchInit extends RequestInit, ProgressOptions<VerifiedFetchProgressEvents> {
|
|
986
969
|
/**
|
|
987
970
|
* If true, try to create a blockstore session - this can reduce overall
|
|
988
971
|
* network traffic by first querying for a set of peers that have the data we
|
|
@@ -1029,6 +1012,25 @@ export interface VerifiedFetchInit extends RequestInit, ProgressOptions<BubbledP
|
|
|
1029
1012
|
*/
|
|
1030
1013
|
withServerTiming?: boolean;
|
|
1031
1014
|
}
|
|
1015
|
+
export interface ResolveURLOptions extends ProgressOptions<VerifiedFetchProgressEvents>, AbortOptions {
|
|
1016
|
+
}
|
|
1017
|
+
export interface UrlQuery extends Record<string, string | unknown> {
|
|
1018
|
+
format?: RequestFormatShorthand;
|
|
1019
|
+
download?: boolean;
|
|
1020
|
+
filename?: string;
|
|
1021
|
+
'dag-scope'?: string;
|
|
1022
|
+
}
|
|
1023
|
+
export interface ResolveURLResult {
|
|
1024
|
+
cid: CID;
|
|
1025
|
+
protocol: string;
|
|
1026
|
+
ttl: number;
|
|
1027
|
+
path: string;
|
|
1028
|
+
query: UrlQuery;
|
|
1029
|
+
ipfsPath: string;
|
|
1030
|
+
}
|
|
1031
|
+
export interface URLResolver {
|
|
1032
|
+
resolve(resource: Resource, options?: ResolveURLOptions): Promise<ResolveURLResult>;
|
|
1033
|
+
}
|
|
1032
1034
|
/**
|
|
1033
1035
|
* Create and return a Helia node
|
|
1034
1036
|
*/
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsyBG;AAUH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,KAAK,EAAE,OA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,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;CACrF;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAE,IAAI,CAAC,EAAE,KAAK,GAAG,uBAAuB,EAAE,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,aAAa,CAAC,CAiD/I;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,cAAc,oBAAoB,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -641,13 +641,13 @@
|
|
|
641
641
|
* Inspects the current `PluginContext` (which includes the CID, path, query, accept header, etc.)
|
|
642
642
|
* and returns `true` if the plugin can operate on the current state of the request.
|
|
643
643
|
*
|
|
644
|
-
* - **`handle(context: PluginContext): Promise<Response |
|
|
645
|
-
* Performs the plugin’s work. It
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
644
|
+
* - **`handle(context: PluginContext): Promise<Response | undefined>`**
|
|
645
|
+
* Performs the plugin’s work. It will only be executed if `canHandle` previously returned `true`.
|
|
646
|
+
* It may:
|
|
647
|
+
* - **Return a `Response`**: This stops the pipeline immediately and returns the response.
|
|
648
|
+
* - **Return `undefined`**: This indicates that the plugin has only partially processed the request
|
|
649
|
+
* (for example, by performing path walking or decoding) and the pipeline should continue.
|
|
650
|
+
* - **Throw an `Error`**: An Internal Server Error will be returned
|
|
651
651
|
*
|
|
652
652
|
* ### Plugin Pipeline
|
|
653
653
|
*
|
|
@@ -745,12 +745,12 @@
|
|
|
745
745
|
* canHandle(context: PluginContext): boolean {
|
|
746
746
|
* // Only handle requests if the Accept header matches your custom type
|
|
747
747
|
* // Or check context for pathDetails, custom values, etc...
|
|
748
|
-
* return context.accept === 'application/vnd.my-custom-type'
|
|
748
|
+
* return context.accept?.mimeType === 'application/vnd.my-custom-type'
|
|
749
749
|
* }
|
|
750
750
|
*
|
|
751
751
|
* async handle(context: PluginContext): Promise<Response | null> {
|
|
752
752
|
* // Perform any partial processing here, e.g., modify the context:
|
|
753
|
-
* context.customProcessed = true
|
|
753
|
+
* context.customProcessed = true
|
|
754
754
|
*
|
|
755
755
|
* // If you are ready to finalize the response:
|
|
756
756
|
* return new Response('Hello, world!', {
|
|
@@ -758,7 +758,7 @@
|
|
|
758
758
|
* headers: {
|
|
759
759
|
* 'Content-Type': 'text/plain'
|
|
760
760
|
* }
|
|
761
|
-
* })
|
|
761
|
+
* })
|
|
762
762
|
*
|
|
763
763
|
* // Or, if further processing is needed by another plugin, simply return null.
|
|
764
764
|
* }
|
|
@@ -784,47 +784,6 @@
|
|
|
784
784
|
* const fetch = await createVerifiedFetch(helia, { plugins })
|
|
785
785
|
* ```
|
|
786
786
|
*
|
|
787
|
-
* ---
|
|
788
|
-
*
|
|
789
|
-
* ### Error Handling in the Plugin Pipeline
|
|
790
|
-
*
|
|
791
|
-
* Verified‑Fetch distinguishes between two types of errors thrown by plugins:
|
|
792
|
-
*
|
|
793
|
-
* - **PluginError (Non‑Fatal):**
|
|
794
|
-
* - Use this when your plugin encounters an issue that should be logged but does not prevent the pipeline
|
|
795
|
-
* from continuing.
|
|
796
|
-
* - When a plugin throws a `PluginError`, the error is logged and the pipeline continues with the next plugin.
|
|
797
|
-
*
|
|
798
|
-
* - **PluginFatalError (Fatal):**
|
|
799
|
-
* - Use this when a critical error occurs that should immediately abort the request.
|
|
800
|
-
* - When a plugin throws a `PluginFatalError`, the pipeline immediately terminates and the provided error
|
|
801
|
-
* response is returned.
|
|
802
|
-
*
|
|
803
|
-
* @example Plugin error Handling
|
|
804
|
-
*
|
|
805
|
-
* ```typescript
|
|
806
|
-
* import { PluginError, PluginFatalError } from '@helia/verified-fetch'
|
|
807
|
-
*
|
|
808
|
-
* // async handle(context: PluginContext): Promise<Response | null> {
|
|
809
|
-
* const recoverable = Math.random() > 0.5 // Use more sophisticated logic here ;)
|
|
810
|
-
* if (recoverable === true) {
|
|
811
|
-
* throw new PluginError('MY_CUSTOM_WARNING', 'A non‑fatal issue occurred', {
|
|
812
|
-
* details: {
|
|
813
|
-
* someKey: 'Additional details here'
|
|
814
|
-
* }
|
|
815
|
-
* });
|
|
816
|
-
* }
|
|
817
|
-
*
|
|
818
|
-
* if (recoverable === false) {
|
|
819
|
-
* throw new PluginFatalError('MY_CUSTOM_FATAL', 'A critical error occurred', {
|
|
820
|
-
* response: new Response('Something happened', { status: 500 }) // Required: supply your own error response
|
|
821
|
-
* });
|
|
822
|
-
* }
|
|
823
|
-
*
|
|
824
|
-
* // Otherwise, continue processing...
|
|
825
|
-
* // }
|
|
826
|
-
* ```
|
|
827
|
-
*
|
|
828
787
|
* ### How the Plugin Pipeline Works
|
|
829
788
|
*
|
|
830
789
|
* - **Shared Context:**
|
|
@@ -842,8 +801,7 @@
|
|
|
842
801
|
* This means you do not have to specify a rigid order, each plugin simply checks the context and acts if appropriate.
|
|
843
802
|
*
|
|
844
803
|
* - **Error Handling:**
|
|
845
|
-
* -
|
|
846
|
-
* - A thrown `PluginFatalError` immediately stops the pipeline and returns the error response.
|
|
804
|
+
* - Any thrown error immediately stops the pipeline and returns the error response.
|
|
847
805
|
*
|
|
848
806
|
* For a detailed explanation of the pipeline, please refer to the discussion in [Issue #167](https://github.com/ipfs/helia-verified-fetch/issues/167).
|
|
849
807
|
*/
|
|
@@ -894,7 +852,7 @@ export async function createVerifiedFetch(init, options) {
|
|
|
894
852
|
});
|
|
895
853
|
init.logger.forComponent('helia:verified-fetch').trace('created verified-fetch with libp2p config: %j', libp2pConfig);
|
|
896
854
|
}
|
|
897
|
-
const verifiedFetchInstance = new VerifiedFetchClass(
|
|
855
|
+
const verifiedFetchInstance = new VerifiedFetchClass(init, options);
|
|
898
856
|
async function verifiedFetch(resource, options) {
|
|
899
857
|
return verifiedFetchInstance.fetch(resource, options);
|
|
900
858
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsyBG;AAEH,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBA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AA;AACtB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,cAAc,oBAAoB,CAAA;AAElC,SAAS,OAAO,CAAE,GAAQ;IACxB,0EAA0E;IAC1E,OAAO,GAAG,EAAE,UAAU,IAAI,IAAI;QAC5B,GAAG,EAAE,SAAS,IAAI,IAAI;QACtB,GAAG,EAAE,EAAE,IAAI,IAAI;QACf,GAAG,EAAE,IAAI,IAAI,IAAI;QACjB,GAAG,EAAE,KAAK,IAAI,IAAI,CAAA;AACtB,CAAC;AAED,SAAS,SAAS,CAAE,SAAwC;IAC1D,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,OAAM;IACR,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC;YACT,SAAS,EAAE;gBACT,GAAG,EAAE,SAAS;aACf;SACF,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file is the entry into all things we export from the `src/plugins` directory.
|
|
3
3
|
*/
|
|
4
|
-
export { PluginError, PluginFatalError } from './errors.js';
|
|
5
4
|
export { BasePlugin } from './plugin-base.js';
|
|
6
5
|
export type { PluginOptions, PluginContext, VerifiedFetchPluginFactory } from './types.js';
|
|
7
6
|
export * from './plugins.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAC1F,cAAc,cAAc,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file is the entry into all things we export from the `src/plugins` directory.
|
|
3
3
|
*/
|
|
4
|
-
export { PluginError, PluginFatalError } from './errors.js';
|
|
5
4
|
export { BasePlugin } from './plugin-base.js';
|
|
6
5
|
export * from './plugins.js';
|
|
7
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,cAAc,cAAc,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-base.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;;;;;;;GAQG;AACH,8BAAsB,UAAW,YAAW,mBAAmB;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAK;IAC7B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAA;IACrC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IAC5B,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IAEvB,IAAI,GAAG,IAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"plugin-base.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;;;;;;;GAQG;AACH,8BAAsB,UAAW,YAAW,mBAAmB;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAK;IAC7B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAA;IACrC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IAC5B,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IAEvB,IAAI,GAAG,IAAK,MAAM,CAOjB;gBAEY,OAAO,EAAE,aAAa;IAInC,QAAQ,CAAC,SAAS,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO;IAEpD,QAAQ,CAAC,MAAM,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CACnE"}
|
|
@@ -12,9 +12,10 @@ export class BasePlugin {
|
|
|
12
12
|
pluginOptions;
|
|
13
13
|
_log;
|
|
14
14
|
get log() {
|
|
15
|
-
// instantiate the logger lazily because it depends on the id, which is not
|
|
15
|
+
// instantiate the logger lazily because it depends on the id, which is not
|
|
16
|
+
// set until after the constructor is called
|
|
16
17
|
if (this._log == null) {
|
|
17
|
-
this._log = this.pluginOptions.logger.
|
|
18
|
+
this._log = this.pluginOptions.logger.newScope(this.id);
|
|
18
19
|
}
|
|
19
20
|
return this._log;
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-base.js","sourceRoot":"","sources":["../../../src/plugins/plugin-base.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,OAAgB,UAAU;IACrB,KAAK,GAAa,EAAE,CAAA;IACpB,aAAa,CAAe;IAE3B,IAAI,CAAS;IAEvB,IAAI,GAAG;QACL,
|
|
1
|
+
{"version":3,"file":"plugin-base.js","sourceRoot":"","sources":["../../../src/plugins/plugin-base.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,OAAgB,UAAU;IACrB,KAAK,GAAa,EAAE,CAAA;IACpB,aAAa,CAAe;IAE3B,IAAI,CAAS;IAEvB,IAAI,GAAG;QACL,2EAA2E;QAC3E,4CAA4C;QAC5C,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACzD,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,YAAa,OAAsB;QACjC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAA;IAC9B,CAAC;CAKF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-handle-car.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-car.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin-handle-car.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-car.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAkC/C;;;GAGG;AACH,qBAAa,SAAU,SAAQ,UAAU;IACvC,QAAQ,CAAC,EAAE,gBAAe;IAE1B,SAAS,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO;IAYrC,MAAM,CAAE,OAAO,EAAE,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsE7G"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BlockExporter, car, CIDPath, SubgraphExporter, UnixFSExporter } from '@helia/car';
|
|
2
|
-
import { CarWriter } from '@ipld/car';
|
|
3
2
|
import { code as dagPbCode } from '@ipld/dag-pb';
|
|
3
|
+
import { createScalableCuckooFilter } from '@libp2p/utils';
|
|
4
4
|
import toBrowserReadableStream from 'it-to-browser-readablestream';
|
|
5
|
+
import { getOffsetAndLength } from "../utils/get-offset-and-length.js";
|
|
5
6
|
import { okRangeResponse } from '../utils/responses.js';
|
|
6
7
|
import { BasePlugin } from './plugin-base.js';
|
|
7
8
|
function getFilename({ cid, ipfsPath, query }) {
|
|
@@ -9,7 +10,10 @@ function getFilename({ cid, ipfsPath, query }) {
|
|
|
9
10
|
return query.filename;
|
|
10
11
|
}
|
|
11
12
|
// convert context.ipfsPath to a filename. replace all / with _, replace prefix protocol with empty string
|
|
12
|
-
const filename = ipfsPath
|
|
13
|
+
const filename = ipfsPath
|
|
14
|
+
.replace(/\/ipfs\//, '')
|
|
15
|
+
.replace(/\/ipns\//, '')
|
|
16
|
+
.replace(/\//g, '_');
|
|
13
17
|
return `${filename}.car`;
|
|
14
18
|
}
|
|
15
19
|
function getDagScope({ query }) {
|
|
@@ -17,6 +21,10 @@ function getDagScope({ query }) {
|
|
|
17
21
|
if (dagScope === 'all' || dagScope === 'entity' || dagScope === 'block') {
|
|
18
22
|
return dagScope;
|
|
19
23
|
}
|
|
24
|
+
// entity-bytes implies entity scope
|
|
25
|
+
if (query['entity-bytes']) {
|
|
26
|
+
return 'entity';
|
|
27
|
+
}
|
|
20
28
|
return 'all';
|
|
21
29
|
}
|
|
22
30
|
/**
|
|
@@ -26,17 +34,18 @@ function getDagScope({ query }) {
|
|
|
26
34
|
export class CarPlugin extends BasePlugin {
|
|
27
35
|
id = 'car-plugin';
|
|
28
36
|
canHandle(context) {
|
|
29
|
-
this.log('checking if we can handle %c with accept %s', context.cid, context.accept);
|
|
30
37
|
if (context.byteRangeContext == null) {
|
|
31
38
|
return false;
|
|
32
39
|
}
|
|
33
40
|
if (context.pathDetails == null) {
|
|
34
41
|
return false;
|
|
35
42
|
}
|
|
36
|
-
return context.accept?.startsWith('application/vnd.ipld.car') === true || context.query.format === 'car'; // application/vnd.ipld.car
|
|
43
|
+
return context.accept?.mimeType.startsWith('application/vnd.ipld.car') === true || context.query.format === 'car'; // application/vnd.ipld.car
|
|
37
44
|
}
|
|
38
45
|
async handle(context) {
|
|
39
|
-
const { options, pathDetails, cid } = context;
|
|
46
|
+
const { options, pathDetails, cid, query, accept } = context;
|
|
47
|
+
const order = accept?.options.order === 'dfs' ? 'dfs' : 'unk';
|
|
48
|
+
const duplicates = accept?.options.dups !== 'n';
|
|
40
49
|
if (pathDetails == null) {
|
|
41
50
|
throw new Error('attempted to handle request for car with no path details');
|
|
42
51
|
}
|
|
@@ -50,23 +59,32 @@ export class CarPlugin extends BasePlugin {
|
|
|
50
59
|
getCodec: helia.getCodec,
|
|
51
60
|
logger: helia.logger
|
|
52
61
|
});
|
|
53
|
-
const ipfsRootsWithoutDagRoot = pathDetails.ipfsRoots.filter(pathCid => !pathCid.equals(cid));
|
|
54
62
|
const carExportOptions = {
|
|
55
|
-
...options
|
|
63
|
+
...options,
|
|
64
|
+
includeTraversalBlocks: true
|
|
56
65
|
};
|
|
57
|
-
if (
|
|
58
|
-
carExportOptions.
|
|
66
|
+
if (!duplicates) {
|
|
67
|
+
carExportOptions.blockFilter = createScalableCuckooFilter(1024);
|
|
68
|
+
}
|
|
69
|
+
if (pathDetails.ipfsRoots.length > 1) {
|
|
70
|
+
carExportOptions.traversal = new CIDPath(pathDetails.ipfsRoots);
|
|
59
71
|
}
|
|
60
72
|
const dagScope = getDagScope(context);
|
|
61
|
-
|
|
62
|
-
const root = pathDetails.terminalElement.cid ?? cid;
|
|
73
|
+
const target = pathDetails.terminalElement.cid ?? cid;
|
|
63
74
|
if (dagScope === 'block') {
|
|
64
75
|
carExportOptions.exporter = new BlockExporter();
|
|
65
76
|
}
|
|
66
77
|
else if (dagScope === 'entity') {
|
|
67
|
-
// if its unixFS, we need to enumerate a directory, or get all blocks
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
// if its unixFS, we need to enumerate a directory, or get all/some blocks
|
|
79
|
+
// for the entity, otherwise, use blockExporter
|
|
80
|
+
if (target.code === dagPbCode) {
|
|
81
|
+
const options = {
|
|
82
|
+
listingOnly: true
|
|
83
|
+
};
|
|
84
|
+
const slice = getOffsetAndLength(pathDetails.terminalElement, query['entity-bytes']?.toString());
|
|
85
|
+
options.offset = slice.offset;
|
|
86
|
+
options.length = slice.length;
|
|
87
|
+
carExportOptions.exporter = new UnixFSExporter(options);
|
|
70
88
|
}
|
|
71
89
|
else {
|
|
72
90
|
carExportOptions.exporter = new BlockExporter();
|
|
@@ -75,21 +93,12 @@ export class CarPlugin extends BasePlugin {
|
|
|
75
93
|
else {
|
|
76
94
|
carExportOptions.exporter = new SubgraphExporter();
|
|
77
95
|
}
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
// the root passed to export should be the root CID of the DAG, not the terminal element.
|
|
85
|
-
c.export(cid, writer, carExportOptions)
|
|
86
|
-
.catch((err) => {
|
|
87
|
-
this.log.error('error exporting car - %e', err);
|
|
96
|
+
context.byteRangeContext.setBody(toBrowserReadableStream(c.export(target, carExportOptions)));
|
|
97
|
+
const response = okRangeResponse(context.resource, context.byteRangeContext.getBody('application/vnd.ipld.car; version=1'), {
|
|
98
|
+
byteRangeContext: context.byteRangeContext,
|
|
99
|
+
log: this.log
|
|
88
100
|
});
|
|
89
|
-
|
|
90
|
-
context.byteRangeContext.setBody(toBrowserReadableStream(iter()));
|
|
91
|
-
const response = okRangeResponse(context.resource, context.byteRangeContext.getBody('application/vnd.ipld.car; version=1'), { byteRangeContext: context.byteRangeContext, log: this.log });
|
|
92
|
-
response.headers.set('content-type', context.byteRangeContext.getContentType() ?? 'application/vnd.ipld.car; version=1');
|
|
101
|
+
response.headers.set('content-type', context.byteRangeContext.getContentType() ?? `application/vnd.ipld.car; version=1; order=${order}; dups=${duplicates ? 'y' : 'n'}`);
|
|
93
102
|
return response;
|
|
94
103
|
}
|
|
95
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-handle-car.js","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-car.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"plugin-handle-car.js","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-car.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC1F,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,uBAAuB,MAAM,8BAA8B,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAI7C,SAAS,WAAW,CAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAqD;IAC/F,IAAI,KAAK,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,QAAQ,CAAA;IACvB,CAAC;IAED,0GAA0G;IAC1G,MAAM,QAAQ,GAAG,QAAQ;SACtB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAEtB,OAAO,GAAG,QAAQ,MAAM,CAAA;AAC1B,CAAC;AAID,SAA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sourceRoot":"","sources":["../../../src/plugins/plugin-handle-dag-cbor-html-preview.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAMtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAmCtD;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,UAAU;IACtD,QAAQ,CAAC,EAAE,kCAAiC;IAC5C,QAAQ,CAAC,KAAK,QAAqB;IAEnC,SAAS,CAAE,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,aAAa,GAAG,OAAO;
|
|
1
|
+
{"version":3,"file":"plugin-handle-dag-cbor-html-preview.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-dag-cbor-html-preview.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAMtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAmCtD;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,UAAU;IACtD,QAAQ,CAAC,EAAE,kCAAiC;IAC5C,QAAQ,CAAC,KAAK,QAAqB;IAEnC,SAAS,CAAE,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,aAAa,GAAG,OAAO;IAoB1D,MAAM,CAAE,OAAO,EAAE,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,kBAAkB,GAAG,aAAa,CAAC,CAAC,GAAG;QAAE,WAAW,EAAE;YAAE,eAAe,EAAE,UAAU,CAAA;SAAE,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IA4B/K,OAAO,CAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,GAAG,EAAE,GAAG,CAAA;KAAE,GAAG,MAAM;IAgJ3F,SAAS,CAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM;IAiBnD,OAAO,CAAC,WAAW;IAgBnB,UAAU,CAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW,GAAE,MAAW,GAAG,MAAM;CAexE;AAED,eAAO,MAAM,+BAA+B,EAAE,0BAAyE,CAAA"}
|
|
@@ -45,7 +45,6 @@ export class DagCborHtmlPreviewPlugin extends BasePlugin {
|
|
|
45
45
|
id = 'dag-cbor-plugin-html-preview';
|
|
46
46
|
codes = [ipldDagCbor.code];
|
|
47
47
|
canHandle({ cid, accept, pathDetails }) {
|
|
48
|
-
this.log('checking if we can handle %c with accept %s', cid, accept);
|
|
49
48
|
if (pathDetails == null) {
|
|
50
49
|
return false;
|
|
51
50
|
}
|
|
@@ -55,7 +54,7 @@ export class DagCborHtmlPreviewPlugin extends BasePlugin {
|
|
|
55
54
|
if (cid.code !== ipldDagCbor.code) {
|
|
56
55
|
return false;
|
|
57
56
|
}
|
|
58
|
-
if (accept == null || !accept.includes('text/html')) {
|
|
57
|
+
if (accept == null || !accept?.mimeType.includes('text/html')) {
|
|
59
58
|
return false;
|
|
60
59
|
}
|
|
61
60
|
return isObjectNode(pathDetails.terminalElement);
|