@helia/verified-fetch 4.1.0 → 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.
Files changed (231) hide show
  1. package/README.md +6 -40
  2. package/dist/index.min.js +73 -534
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/constants.d.ts +2 -0
  5. package/dist/src/constants.d.ts.map +1 -1
  6. package/dist/src/constants.js +2 -0
  7. package/dist/src/constants.js.map +1 -1
  8. package/dist/src/index.d.ts +162 -68
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js +11 -43
  11. package/dist/src/index.js.map +1 -1
  12. package/dist/src/plugins/index.d.ts +0 -5
  13. package/dist/src/plugins/index.d.ts.map +1 -1
  14. package/dist/src/plugins/index.js +0 -4
  15. package/dist/src/plugins/index.js.map +1 -1
  16. package/dist/src/plugins/plugin-base.d.ts +8 -9
  17. package/dist/src/plugins/plugin-base.d.ts.map +1 -1
  18. package/dist/src/plugins/plugin-base.js +5 -6
  19. package/dist/src/plugins/plugin-base.js.map +1 -1
  20. package/dist/src/plugins/plugin-handle-car.d.ts +3 -3
  21. package/dist/src/plugins/plugin-handle-car.d.ts.map +1 -1
  22. package/dist/src/plugins/plugin-handle-car.js +38 -39
  23. package/dist/src/plugins/plugin-handle-car.js.map +1 -1
  24. package/dist/src/plugins/plugin-handle-ipld.d.ts +12 -0
  25. package/dist/src/plugins/plugin-handle-ipld.d.ts.map +1 -0
  26. package/dist/src/plugins/plugin-handle-ipld.js +83 -0
  27. package/dist/src/plugins/plugin-handle-ipld.js.map +1 -0
  28. package/dist/src/plugins/plugin-handle-ipns-record.d.ts +3 -3
  29. package/dist/src/plugins/plugin-handle-ipns-record.d.ts.map +1 -1
  30. package/dist/src/plugins/plugin-handle-ipns-record.js +25 -34
  31. package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
  32. package/dist/src/plugins/plugin-handle-tar.d.ts +3 -3
  33. package/dist/src/plugins/plugin-handle-tar.d.ts.map +1 -1
  34. package/dist/src/plugins/plugin-handle-tar.js +20 -22
  35. package/dist/src/plugins/plugin-handle-tar.js.map +1 -1
  36. package/dist/src/plugins/plugin-handle-unixfs.d.ts +14 -0
  37. package/dist/src/plugins/plugin-handle-unixfs.d.ts.map +1 -0
  38. package/dist/src/plugins/plugin-handle-unixfs.js +180 -0
  39. package/dist/src/plugins/plugin-handle-unixfs.js.map +1 -0
  40. package/dist/src/plugins/types.d.ts +1 -77
  41. package/dist/src/plugins/types.d.ts.map +1 -1
  42. package/dist/src/url-resolver.d.ts +29 -11
  43. package/dist/src/url-resolver.d.ts.map +1 -1
  44. package/dist/src/url-resolver.js +152 -74
  45. package/dist/src/url-resolver.js.map +1 -1
  46. package/dist/src/utils/content-type-parser.d.ts.map +1 -1
  47. package/dist/src/utils/content-type-parser.js +4 -3
  48. package/dist/src/utils/content-type-parser.js.map +1 -1
  49. package/dist/src/utils/content-types.d.ts +26 -0
  50. package/dist/src/utils/content-types.d.ts.map +1 -0
  51. package/dist/src/utils/content-types.js +137 -0
  52. package/dist/src/utils/content-types.js.map +1 -0
  53. package/dist/src/utils/convert-output.d.ts +17 -0
  54. package/dist/src/utils/convert-output.d.ts.map +1 -0
  55. package/dist/src/utils/convert-output.js +176 -0
  56. package/dist/src/utils/convert-output.js.map +1 -0
  57. package/dist/src/utils/error-to-response.d.ts +3 -0
  58. package/dist/src/utils/error-to-response.d.ts.map +1 -0
  59. package/dist/src/utils/error-to-response.js +40 -0
  60. package/dist/src/utils/error-to-response.js.map +1 -0
  61. package/dist/src/utils/get-content-disposition-filename.d.ts +1 -1
  62. package/dist/src/utils/get-content-disposition-filename.d.ts.map +1 -1
  63. package/dist/src/utils/get-content-disposition-filename.js +4 -0
  64. package/dist/src/utils/get-content-disposition-filename.js.map +1 -1
  65. package/dist/src/utils/get-e-tag.d.ts +20 -15
  66. package/dist/src/utils/get-e-tag.d.ts.map +1 -1
  67. package/dist/src/utils/get-e-tag.js +8 -22
  68. package/dist/src/utils/get-e-tag.js.map +1 -1
  69. package/dist/src/utils/get-offset-and-length.d.ts +12 -2
  70. package/dist/src/utils/get-offset-and-length.d.ts.map +1 -1
  71. package/dist/src/utils/get-offset-and-length.js +63 -21
  72. package/dist/src/utils/get-offset-and-length.js.map +1 -1
  73. package/dist/src/utils/get-range-header.d.ts +22 -0
  74. package/dist/src/utils/get-range-header.d.ts.map +1 -0
  75. package/dist/src/utils/get-range-header.js +69 -0
  76. package/dist/src/utils/get-range-header.js.map +1 -0
  77. package/dist/src/utils/parse-url-string.d.ts +2 -1
  78. package/dist/src/utils/parse-url-string.d.ts.map +1 -1
  79. package/dist/src/utils/parse-url-string.js +46 -71
  80. package/dist/src/utils/parse-url-string.js.map +1 -1
  81. package/dist/src/utils/resource-to-cache-key.d.ts +3 -3
  82. package/dist/src/utils/resource-to-cache-key.js +5 -5
  83. package/dist/src/utils/resource-to-cache-key.js.map +1 -1
  84. package/dist/src/utils/response-headers.d.ts +4 -14
  85. package/dist/src/utils/response-headers.d.ts.map +1 -1
  86. package/dist/src/utils/response-headers.js +36 -36
  87. package/dist/src/utils/response-headers.js.map +1 -1
  88. package/dist/src/utils/responses.d.ts +30 -11
  89. package/dist/src/utils/responses.d.ts.map +1 -1
  90. package/dist/src/utils/responses.js +146 -39
  91. package/dist/src/utils/responses.js.map +1 -1
  92. package/dist/src/verified-fetch.d.ts +16 -15
  93. package/dist/src/verified-fetch.d.ts.map +1 -1
  94. package/dist/src/verified-fetch.js +307 -236
  95. package/dist/src/verified-fetch.js.map +1 -1
  96. package/dist/typedoc-urls.json +64 -45
  97. package/package.json +4 -3
  98. package/src/constants.ts +3 -0
  99. package/src/index.ts +203 -71
  100. package/src/plugins/index.ts +0 -6
  101. package/src/plugins/plugin-base.ts +8 -10
  102. package/src/plugins/plugin-handle-car.ts +48 -46
  103. package/src/plugins/plugin-handle-ipld.ts +93 -0
  104. package/src/plugins/plugin-handle-ipns-record.ts +31 -41
  105. package/src/plugins/plugin-handle-tar.ts +25 -29
  106. package/src/plugins/plugin-handle-unixfs.ts +217 -0
  107. package/src/plugins/types.ts +0 -86
  108. package/src/url-resolver.ts +197 -83
  109. package/src/utils/content-type-parser.ts +4 -3
  110. package/src/utils/content-types.ts +159 -0
  111. package/src/utils/convert-output.ts +187 -0
  112. package/src/utils/error-to-response.ts +49 -0
  113. package/src/utils/get-content-disposition-filename.ts +7 -1
  114. package/src/utils/get-e-tag.ts +26 -35
  115. package/src/utils/get-offset-and-length.ts +75 -21
  116. package/src/utils/get-range-header.ts +107 -0
  117. package/src/utils/parse-url-string.ts +51 -80
  118. package/src/utils/resource-to-cache-key.ts +5 -5
  119. package/src/utils/response-headers.ts +40 -41
  120. package/src/utils/responses.ts +186 -45
  121. package/src/verified-fetch.ts +359 -267
  122. package/dist/src/plugins/plugin-handle-byte-range-context.d.ts +0 -14
  123. package/dist/src/plugins/plugin-handle-byte-range-context.d.ts.map +0 -1
  124. package/dist/src/plugins/plugin-handle-byte-range-context.js +0 -25
  125. package/dist/src/plugins/plugin-handle-byte-range-context.js.map +0 -1
  126. package/dist/src/plugins/plugin-handle-cbor.d.ts +0 -17
  127. package/dist/src/plugins/plugin-handle-cbor.d.ts.map +0 -1
  128. package/dist/src/plugins/plugin-handle-cbor.js +0 -94
  129. package/dist/src/plugins/plugin-handle-cbor.js.map +0 -1
  130. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts +0 -27
  131. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts.map +0 -1
  132. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js +0 -279
  133. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js.map +0 -1
  134. package/dist/src/plugins/plugin-handle-dag-cbor.d.ts +0 -17
  135. package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +0 -1
  136. package/dist/src/plugins/plugin-handle-dag-cbor.js +0 -66
  137. package/dist/src/plugins/plugin-handle-dag-cbor.js.map +0 -1
  138. package/dist/src/plugins/plugin-handle-dag-pb.d.ts +0 -17
  139. package/dist/src/plugins/plugin-handle-dag-pb.d.ts.map +0 -1
  140. package/dist/src/plugins/plugin-handle-dag-pb.js +0 -209
  141. package/dist/src/plugins/plugin-handle-dag-pb.js.map +0 -1
  142. package/dist/src/plugins/plugin-handle-dag-walk.d.ts +0 -21
  143. package/dist/src/plugins/plugin-handle-dag-walk.d.ts.map +0 -1
  144. package/dist/src/plugins/plugin-handle-dag-walk.js +0 -95
  145. package/dist/src/plugins/plugin-handle-dag-walk.js.map +0 -1
  146. package/dist/src/plugins/plugin-handle-dir-index-html.d.ts +0 -10
  147. package/dist/src/plugins/plugin-handle-dir-index-html.d.ts.map +0 -1
  148. package/dist/src/plugins/plugin-handle-dir-index-html.js +0 -59
  149. package/dist/src/plugins/plugin-handle-dir-index-html.js.map +0 -1
  150. package/dist/src/plugins/plugin-handle-json.d.ts +0 -12
  151. package/dist/src/plugins/plugin-handle-json.d.ts.map +0 -1
  152. package/dist/src/plugins/plugin-handle-json.js +0 -73
  153. package/dist/src/plugins/plugin-handle-json.js.map +0 -1
  154. package/dist/src/plugins/plugin-handle-raw.d.ts +0 -9
  155. package/dist/src/plugins/plugin-handle-raw.d.ts.map +0 -1
  156. package/dist/src/plugins/plugin-handle-raw.js +0 -92
  157. package/dist/src/plugins/plugin-handle-raw.js.map +0 -1
  158. package/dist/src/plugins/plugins.d.ts +0 -6
  159. package/dist/src/plugins/plugins.d.ts.map +0 -1
  160. package/dist/src/plugins/plugins.js +0 -6
  161. package/dist/src/plugins/plugins.js.map +0 -1
  162. package/dist/src/utils/byte-range-context.d.ts +0 -103
  163. package/dist/src/utils/byte-range-context.d.ts.map +0 -1
  164. package/dist/src/utils/byte-range-context.js +0 -504
  165. package/dist/src/utils/byte-range-context.js.map +0 -1
  166. package/dist/src/utils/dag-cbor-to-safe-json.d.ts +0 -15
  167. package/dist/src/utils/dag-cbor-to-safe-json.d.ts.map +0 -1
  168. package/dist/src/utils/dag-cbor-to-safe-json.js +0 -54
  169. package/dist/src/utils/dag-cbor-to-safe-json.js.map +0 -1
  170. package/dist/src/utils/dir-index-html.d.ts +0 -19
  171. package/dist/src/utils/dir-index-html.d.ts.map +0 -1
  172. package/dist/src/utils/dir-index-html.js +0 -438
  173. package/dist/src/utils/dir-index-html.js.map +0 -1
  174. package/dist/src/utils/get-peer-id-from-string.d.ts +0 -3
  175. package/dist/src/utils/get-peer-id-from-string.d.ts.map +0 -1
  176. package/dist/src/utils/get-peer-id-from-string.js +0 -10
  177. package/dist/src/utils/get-peer-id-from-string.js.map +0 -1
  178. package/dist/src/utils/get-resolved-accept-header.d.ts +0 -9
  179. package/dist/src/utils/get-resolved-accept-header.d.ts.map +0 -1
  180. package/dist/src/utils/get-resolved-accept-header.js +0 -27
  181. package/dist/src/utils/get-resolved-accept-header.js.map +0 -1
  182. package/dist/src/utils/get-stream-from-async-iterable.d.ts +0 -9
  183. package/dist/src/utils/get-stream-from-async-iterable.d.ts.map +0 -1
  184. package/dist/src/utils/get-stream-from-async-iterable.js +0 -43
  185. package/dist/src/utils/get-stream-from-async-iterable.js.map +0 -1
  186. package/dist/src/utils/handle-redirects.d.ts +0 -16
  187. package/dist/src/utils/handle-redirects.d.ts.map +0 -1
  188. package/dist/src/utils/handle-redirects.js +0 -84
  189. package/dist/src/utils/handle-redirects.js.map +0 -1
  190. package/dist/src/utils/is-accept-explicit.d.ts +0 -15
  191. package/dist/src/utils/is-accept-explicit.d.ts.map +0 -1
  192. package/dist/src/utils/is-accept-explicit.js +0 -26
  193. package/dist/src/utils/is-accept-explicit.js.map +0 -1
  194. package/dist/src/utils/request-headers.d.ts +0 -13
  195. package/dist/src/utils/request-headers.d.ts.map +0 -1
  196. package/dist/src/utils/request-headers.js +0 -63
  197. package/dist/src/utils/request-headers.js.map +0 -1
  198. package/dist/src/utils/select-output-type.d.ts +0 -17
  199. package/dist/src/utils/select-output-type.d.ts.map +0 -1
  200. package/dist/src/utils/select-output-type.js +0 -153
  201. package/dist/src/utils/select-output-type.js.map +0 -1
  202. package/dist/src/utils/tlru.d.ts +0 -15
  203. package/dist/src/utils/tlru.d.ts.map +0 -1
  204. package/dist/src/utils/tlru.js +0 -34
  205. package/dist/src/utils/tlru.js.map +0 -1
  206. package/dist/src/utils/walk-path.d.ts +0 -27
  207. package/dist/src/utils/walk-path.d.ts.map +0 -1
  208. package/dist/src/utils/walk-path.js +0 -45
  209. package/dist/src/utils/walk-path.js.map +0 -1
  210. package/src/plugins/plugin-handle-byte-range-context.ts +0 -30
  211. package/src/plugins/plugin-handle-cbor.ts +0 -107
  212. package/src/plugins/plugin-handle-dag-cbor-html-preview.ts +0 -295
  213. package/src/plugins/plugin-handle-dag-cbor.ts +0 -83
  214. package/src/plugins/plugin-handle-dag-pb.ts +0 -248
  215. package/src/plugins/plugin-handle-dag-walk.ts +0 -110
  216. package/src/plugins/plugin-handle-dir-index-html.ts +0 -72
  217. package/src/plugins/plugin-handle-json.ts +0 -80
  218. package/src/plugins/plugin-handle-raw.ts +0 -110
  219. package/src/plugins/plugins.ts +0 -5
  220. package/src/utils/byte-range-context.ts +0 -597
  221. package/src/utils/dag-cbor-to-safe-json.ts +0 -63
  222. package/src/utils/dir-index-html.ts +0 -505
  223. package/src/utils/get-peer-id-from-string.ts +0 -12
  224. package/src/utils/get-resolved-accept-header.ts +0 -42
  225. package/src/utils/get-stream-from-async-iterable.ts +0 -49
  226. package/src/utils/handle-redirects.ts +0 -109
  227. package/src/utils/is-accept-explicit.ts +0 -38
  228. package/src/utils/request-headers.ts +0 -65
  229. package/src/utils/select-output-type.ts +0 -175
  230. package/src/utils/tlru.ts +0 -42
  231. package/src/utils/walk-path.ts +0 -68
@@ -1,3 +1,5 @@
1
1
  export declare const CODEC_IDENTITY = 0;
2
2
  export declare const CODEC_CBOR = 81;
3
+ export declare const SESSION_CACHE_MAX_SIZE = 100;
4
+ export declare const SESSION_CACHE_TTL_MS: number;
3
5
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,IAAO,CAAA;AAClC,eAAO,MAAM,UAAU,KAAO,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,IAAO,CAAA;AAClC,eAAO,MAAM,UAAU,KAAO,CAAA;AAE9B,eAAO,MAAM,sBAAsB,MAAM,CAAA;AACzC,eAAO,MAAM,oBAAoB,QAAY,CAAA"}
@@ -1,3 +1,5 @@
1
1
  export const CODEC_IDENTITY = 0x00;
2
2
  export const CODEC_CBOR = 0x51;
3
+ export const SESSION_CACHE_MAX_SIZE = 100;
4
+ export const SESSION_CACHE_TTL_MS = 60 * 1000;
3
5
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA;AAClC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA;AAClC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAA;AAE9B,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAA;AACzC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,CAAA"}
@@ -659,16 +659,10 @@
659
659
  * create a mutable `PluginContext` object.
660
660
  *
661
661
  * 2. **Pipeline Execution:**
662
- * - The pipeline repeatedly checks, up to a maximum number of passes (default = 3), which plugins
663
- * are currently able to handle the request by calling each plugin’s `canHandle()` method.
662
+ * - The pipeline checks which plugins can handle the request by calling each plugin’s `canHandle()` method.
664
663
  * - Plugins that have not yet been called in the current run and return `true` for `canHandle()`
665
664
  * are invoked in sequence.
666
- * - If a plugin returns a final `Response` or throws a `PluginFatalError`, the pipeline immediately
667
- * stops and that response is returned.
668
- * - If a plugin returns `null`, it may have updated the context (for example, by
669
- * performing path walking), other plugins that said they `canHandle` will run.
670
- * - If no plugin modifies the context (i.e. no change to `context.modified`) and no final response is
671
- * produced after iterating through all plugins, the pipeline exits and a default “Not Supported”
665
+ * - If no plugin can handle the request, the pipeline exits and a “Not Supported”
672
666
  * response is returned.
673
667
  *
674
668
  * **Diagram of the Plugin Pipeline:**
@@ -696,29 +690,6 @@
696
690
  *
697
691
  * ---
698
692
  *
699
- * ### Non-default plugins provided by this library
700
- *
701
- * #### `dir-index-html-plugin`
702
- *
703
- * This plugin is used to serve dag-pb/unixfs without an `index.html` child as HTML directory listing of the content requested.
704
- *
705
- * #### `dag-cbor-html-preview-plugin`
706
- *
707
- * This plugin is used to serve the requested dag-cbor object as HTML when the Accept header includes `text/html`.
708
- *
709
- * @example Using the plugins
710
- *
711
- * ```typescript
712
- * import { createVerifiedFetch } from '@helia/verified-fetch'
713
- * import { dagCborHtmlPreviewPluginFactory, dirIndexHtmlPluginFactory } from '@helia/verified-fetch/plugins'
714
- * import { createHelia } from 'helia'
715
- *
716
- * const helia = await createHelia()
717
- * const fetch = await createVerifiedFetch(helia, {
718
- * plugins: [dagCborHtmlPreviewPluginFactory, dirIndexHtmlPluginFactory, ]
719
- * })
720
- * ```
721
- *
722
693
  * ### Extending Verified‑Fetch with Custom Plugins
723
694
  *
724
695
  * To add your own plugin:
@@ -742,25 +713,20 @@
742
713
  * // Optionally, list any codec codes your plugin supports:
743
714
  * codes = [] //
744
715
  *
745
- * canHandle(context: PluginContext): boolean {
716
+ * canHandle({ accept }: PluginContext): boolean {
746
717
  * // Only handle requests if the Accept header matches your custom type
747
718
  * // Or check context for pathDetails, custom values, etc...
748
- * return context.accept?.mimeType === 'application/vnd.my-custom-type'
719
+ * return accept.some(header => header.contentType.mediaType === 'application/vnd.my-custom-type')
749
720
  * }
750
721
  *
751
- * async handle(context: PluginContext): Promise<Response | null> {
752
- * // Perform any partial processing here, e.g., modify the context:
753
- * context.customProcessed = true
754
- *
755
- * // If you are ready to finalize the response:
722
+ * async handle(context: PluginContext): Promise<Response> {
723
+ * // Return the response:
756
724
  * return new Response('Hello, world!', {
757
725
  * status: 200,
758
726
  * headers: {
759
727
  * 'Content-Type': 'text/plain'
760
728
  * }
761
729
  * })
762
- *
763
- * // Or, if further processing is needed by another plugin, simply return null.
764
730
  * }
765
731
  * }
766
732
  * export const myCustomPluginFactory: VerifiedFetchPluginFactory = (opts: PluginOptions) => new MyCustomPlugin(opts)
@@ -805,18 +771,127 @@
805
771
  *
806
772
  * For a detailed explanation of the pipeline, please refer to the discussion in [Issue #167](https://github.com/ipfs/helia-verified-fetch/issues/167).
807
773
  */
808
- import type { VerifiedFetchPluginFactory } from './plugins/types.js';
774
+ import type { RangeHeader } from './utils/get-range-header.ts';
775
+ import type { ServerTiming } from './utils/server-timing.ts';
809
776
  import type { DNSLink, ResolveProgressEvents as ResolveDNSLinkProgressEvents } from '@helia/dnslink';
810
777
  import type { GetBlockProgressEvents, Helia } from '@helia/interface';
811
- import type { IPNSResolver } from '@helia/ipns';
812
- import type { AbortOptions, ServiceMap } from '@libp2p/interface';
778
+ import type { ResolveProgressEvents as ResolveIPNSNameProgressEvents, IPNSRoutingProgressEvents, IPNSResolver } from '@helia/ipns';
779
+ import type { AbortOptions, ServiceMap, Logger } from '@libp2p/interface';
813
780
  import type { DNSResolvers } from '@multiformats/dns';
814
781
  import type { DNSResolver } from '@multiformats/dns/resolvers';
815
782
  import type { HeliaInit } from 'helia';
816
- import type { ExporterProgressEvents } from 'ipfs-unixfs-exporter';
783
+ import type { Blockstore } from 'interface-blockstore';
784
+ import type { ExporterProgressEvents, UnixFSEntry } from 'ipfs-unixfs-exporter';
817
785
  import type { Libp2pOptions } from 'libp2p';
818
786
  import type { CID } from 'multiformats/cid';
819
787
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
788
+ export { MEDIA_TYPE_DAG_CBOR, MEDIA_TYPE_CBOR, MEDIA_TYPE_DAG_JSON, MEDIA_TYPE_JSON, MEDIA_TYPE_RAW, MEDIA_TYPE_OCTET_STREAM, MEDIA_TYPE_IPNS_RECORD, MEDIA_TYPE_CAR, MEDIA_TYPE_TAR, MEDIA_TYPE_DAG_PB } from './utils/content-types.js';
789
+ export interface ContentType {
790
+ /**
791
+ * The media type of this content type
792
+ */
793
+ mediaType: string;
794
+ /**
795
+ * A list of CID codecs that map to this content type
796
+ */
797
+ codecs: number[];
798
+ /**
799
+ * If false this content-type is mutable so should have an etag prefixed with
800
+ * W/
801
+ */
802
+ immutable: boolean;
803
+ /**
804
+ * A suffix used in etags
805
+ */
806
+ etag: string;
807
+ /**
808
+ * The file extension associated with this content type
809
+ */
810
+ extension: string;
811
+ /**
812
+ * Whether data of this type should be downloaded by default
813
+ */
814
+ disposition: 'inline' | 'attachment';
815
+ }
816
+ export interface AcceptHeader {
817
+ contentType: ContentType;
818
+ options: Record<string, string>;
819
+ }
820
+ export interface ContextDispositionHeader {
821
+ disposition: 'inline' | 'attachment';
822
+ filename: string;
823
+ }
824
+ /**
825
+ * Contains common components and functions required by plugins to handle a request.
826
+ * - Read-Only: Plugins can read but shouldn't rewrite them.
827
+ * - Persistent: Relevant even after the request completes (e.g., logging or metrics).
828
+ */
829
+ export interface PluginOptions {
830
+ logger: Logger;
831
+ contentTypeParser?: ContentTypeParser;
832
+ helia: Helia;
833
+ ipnsResolver: IPNSResolver;
834
+ }
835
+ /**
836
+ * Represents the ephemeral, modifiable state used by the pipeline.
837
+ * - Mutable: Evolves as you walk the plugin chain.
838
+ * - Shared Data: Allows plugins to communicate partial results, discovered data, or interim errors.
839
+ * - Ephemeral: Typically discarded once fetch(...) completes.
840
+ */
841
+ export interface PluginContext extends ResolveURLResult {
842
+ /**
843
+ * The resource that was requested by the user
844
+ */
845
+ readonly resource: string;
846
+ /**
847
+ * These are the response representations that are acceptable to return
848
+ */
849
+ readonly accept: AcceptHeader[];
850
+ /**
851
+ * If present the user requested a subset of bytes using the Range header
852
+ */
853
+ readonly range?: RangeHeader;
854
+ /**
855
+ * Any passed headers from the fetch init arg
856
+ */
857
+ headers: Headers;
858
+ /**
859
+ * A callback that receives progress events
860
+ */
861
+ onProgress?(evt: ProgressEvent): void;
862
+ /**
863
+ * Onward options to pass to async operations
864
+ */
865
+ options?: Omit<VerifiedFetchInit, 'signal'> & AbortOptions;
866
+ /**
867
+ * Any async operations should be invoked using server timings to allow
868
+ * introspection by the user
869
+ */
870
+ serverTiming: ServerTiming;
871
+ /**
872
+ * The blockstore is used to load data from the IPFS network
873
+ */
874
+ blockstore: Blockstore;
875
+ }
876
+ export interface VerifiedFetchPlugin {
877
+ readonly id: string;
878
+ /**
879
+ * Should return `true` if this plugin can handle the current request
880
+ */
881
+ canHandle(context: PluginContext): boolean;
882
+ /**
883
+ * Handle the current request
884
+ */
885
+ handle(context: PluginContext): Promise<Response>;
886
+ }
887
+ export interface VerifiedFetchPluginFactory {
888
+ (options: PluginOptions): VerifiedFetchPlugin;
889
+ }
890
+ export interface PluginErrorOptions {
891
+ fatal?: boolean;
892
+ details?: Record<string, any>;
893
+ response?: Response;
894
+ }
820
895
  export type RequestFormatShorthand = 'raw' | 'car' | 'tar' | 'ipns-record' | 'dag-json' | 'dag-cbor' | 'json' | 'cbor';
821
896
  export type SupportedBodyTypes = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array> | null;
822
897
  /**
@@ -841,7 +916,7 @@ export interface ResourceDetail {
841
916
  }
842
917
  export interface CIDDetail {
843
918
  cid: CID;
844
- path?: string[];
919
+ path?: string;
845
920
  }
846
921
  export interface CIDDetailError extends CIDDetail {
847
922
  error: Error;
@@ -899,11 +974,14 @@ export interface CreateVerifiedFetchInit {
899
974
  */
900
975
  allowInsecure?: boolean;
901
976
  /**
902
- * We will instantiate a libp2p node for you, but if you want to override the libp2p configuration,
903
- * you can pass it here.
977
+ * A libp2p node will be instantiated - if you want to override the libp2p
978
+ * configuration, you can pass it here.
904
979
  *
905
- * **WARNING**: We use Object.assign to merge the default libp2p configuration from Helia with the one you pass here,
906
- * which results in a shallow merge. If you need a deep merge, you should do it yourself before passing the
980
+ * **WARNING**: Object.assign is used to merge the default libp2p
981
+ * configuration from Helia with the one you pass here, which results in a
982
+ * shallow merge.
983
+ *
984
+ * If you need a deep merge, you should do it yourself before passing the
907
985
  * configuration here.
908
986
  */
909
987
  libp2pConfig?: Partial<Libp2pOptions<ServiceMap>>;
@@ -929,19 +1007,23 @@ export interface CreateVerifiedFetchOptions {
929
1007
  /**
930
1008
  * How long each blockstore session should stay in the cache for.
931
1009
  *
932
- * @default 60000
1010
+ * @default 60_000
933
1011
  */
934
1012
  sessionTTLms?: number;
935
1013
  /**
936
- * Whether to include server-timing headers in responses. This option can be overridden on a per-request basis.
1014
+ * Whether to include server-timing headers in responses. This option can be
1015
+ * overridden on a per-request basis.
937
1016
  *
938
1017
  * @default false
939
1018
  * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing
940
1019
  */
941
1020
  withServerTiming?: boolean;
942
1021
  /**
943
- * Plugins to use with the verified-fetch instance. Note that we have a set of default plugins that are always used.
944
- * If you want to replace one of the default plugins, you can do so by passing a plugin with the same name.
1022
+ * Plugins to use with the verified-fetch instance. Note that we have a set of
1023
+ * default plugins that are always used.
1024
+ *
1025
+ * If you want to replace one of the default plugins, you can do so by passing
1026
+ * a plugin with the same name.
945
1027
  */
946
1028
  plugins?: VerifiedFetchPluginFactory[];
947
1029
  /**
@@ -957,7 +1039,7 @@ export interface CreateVerifiedFetchOptions {
957
1039
  */
958
1040
  urlResolver?: URLResolver;
959
1041
  }
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;
1042
+ 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 | ResolveIPNSNameProgressEvents | IPNSRoutingProgressEvents;
961
1043
  /**
962
1044
  * Options for the `fetch` function returned by `createVerifiedFetch`.
963
1045
  *
@@ -1011,27 +1093,39 @@ export interface VerifiedFetchInit extends RequestInit, ProgressOptions<Verified
1011
1093
  * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing
1012
1094
  */
1013
1095
  withServerTiming?: boolean;
1096
+ /**
1097
+ * By default when a CID is fetched that resolves to a UnixFS directory, and
1098
+ * that directory contains an `index.html` file, respond with the index file
1099
+ * instead of the directory listing.
1100
+ *
1101
+ * @default true
1102
+ */
1103
+ supportDirectoryIndexes?: boolean;
1104
+ /**
1105
+ * If a `_redirects` file exists at the root of a DAG, use it to allow path
1106
+ * overrides within that DAG.
1107
+ *
1108
+ * @see https://specs.ipfs.tech/http-gateways/web-redirects-file/
1109
+ * @default true
1110
+ */
1111
+ supportWebRedirects?: boolean;
1014
1112
  }
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;
1113
+ export type URLProtocols = 'ipfs' | 'ipns' | 'dnslink';
1114
+ export interface ResolveURLOptions extends AbortOptions {
1115
+ session?: boolean;
1022
1116
  }
1023
1117
  export interface ResolveURLResult {
1024
1118
  url: URL;
1025
- cid: CID;
1026
- protocol: string;
1027
1119
  ttl: number;
1028
- path: string[];
1029
- fragment: string;
1030
- query: UrlQuery;
1031
- ipfsPath: string;
1120
+ blockstore: Blockstore;
1121
+ ipfsRoots: CID[];
1122
+ terminalElement: UnixFSEntry;
1032
1123
  }
1033
1124
  export interface URLResolver {
1034
- resolve(resource: Resource, options?: ResolveURLOptions): Promise<ResolveURLResult>;
1125
+ /**
1126
+ * Resolve the passed resource to a CID and associated metadata
1127
+ */
1128
+ resolve(url: URL, serverTiming: ServerTiming, options?: ResolveURLOptions): Promise<ResolveURLResult>;
1035
1129
  }
1036
1130
  /**
1037
1131
  * Create and return a Helia node
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,GAAG,CAAA;IACR,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,GAAG,EAAE,CAAA;IAChB,eAAe,EAAE,WAAW,CAAA;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,OAAO,CAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;CACvG;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAE,IAAI,CAAC,EAAE,KAAK,GAAG,uBAAuB,EAAE,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,aAAa,CAAC,CAkD/I;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,cAAc,oBAAoB,CAAA"}
package/dist/src/index.js CHANGED
@@ -659,16 +659,10 @@
659
659
  * create a mutable `PluginContext` object.
660
660
  *
661
661
  * 2. **Pipeline Execution:**
662
- * - The pipeline repeatedly checks, up to a maximum number of passes (default = 3), which plugins
663
- * are currently able to handle the request by calling each plugin’s `canHandle()` method.
662
+ * - The pipeline checks which plugins can handle the request by calling each plugin’s `canHandle()` method.
664
663
  * - Plugins that have not yet been called in the current run and return `true` for `canHandle()`
665
664
  * are invoked in sequence.
666
- * - If a plugin returns a final `Response` or throws a `PluginFatalError`, the pipeline immediately
667
- * stops and that response is returned.
668
- * - If a plugin returns `null`, it may have updated the context (for example, by
669
- * performing path walking), other plugins that said they `canHandle` will run.
670
- * - If no plugin modifies the context (i.e. no change to `context.modified`) and no final response is
671
- * produced after iterating through all plugins, the pipeline exits and a default “Not Supported”
665
+ * - If no plugin can handle the request, the pipeline exits and a “Not Supported”
672
666
  * response is returned.
673
667
  *
674
668
  * **Diagram of the Plugin Pipeline:**
@@ -696,29 +690,6 @@
696
690
  *
697
691
  * ---
698
692
  *
699
- * ### Non-default plugins provided by this library
700
- *
701
- * #### `dir-index-html-plugin`
702
- *
703
- * This plugin is used to serve dag-pb/unixfs without an `index.html` child as HTML directory listing of the content requested.
704
- *
705
- * #### `dag-cbor-html-preview-plugin`
706
- *
707
- * This plugin is used to serve the requested dag-cbor object as HTML when the Accept header includes `text/html`.
708
- *
709
- * @example Using the plugins
710
- *
711
- * ```typescript
712
- * import { createVerifiedFetch } from '@helia/verified-fetch'
713
- * import { dagCborHtmlPreviewPluginFactory, dirIndexHtmlPluginFactory } from '@helia/verified-fetch/plugins'
714
- * import { createHelia } from 'helia'
715
- *
716
- * const helia = await createHelia()
717
- * const fetch = await createVerifiedFetch(helia, {
718
- * plugins: [dagCborHtmlPreviewPluginFactory, dirIndexHtmlPluginFactory, ]
719
- * })
720
- * ```
721
- *
722
693
  * ### Extending Verified‑Fetch with Custom Plugins
723
694
  *
724
695
  * To add your own plugin:
@@ -742,25 +713,20 @@
742
713
  * // Optionally, list any codec codes your plugin supports:
743
714
  * codes = [] //
744
715
  *
745
- * canHandle(context: PluginContext): boolean {
716
+ * canHandle({ accept }: PluginContext): boolean {
746
717
  * // Only handle requests if the Accept header matches your custom type
747
718
  * // Or check context for pathDetails, custom values, etc...
748
- * return context.accept?.mimeType === 'application/vnd.my-custom-type'
719
+ * return accept.some(header => header.contentType.mediaType === 'application/vnd.my-custom-type')
749
720
  * }
750
721
  *
751
- * async handle(context: PluginContext): Promise<Response | null> {
752
- * // Perform any partial processing here, e.g., modify the context:
753
- * context.customProcessed = true
754
- *
755
- * // If you are ready to finalize the response:
722
+ * async handle(context: PluginContext): Promise<Response> {
723
+ * // Return the response:
756
724
  * return new Response('Hello, world!', {
757
725
  * status: 200,
758
726
  * headers: {
759
727
  * 'Content-Type': 'text/plain'
760
728
  * }
761
729
  * })
762
- *
763
- * // Or, if further processing is needed by another plugin, simply return null.
764
730
  * }
765
731
  * }
766
732
  * export const myCustomPluginFactory: VerifiedFetchPluginFactory = (opts: PluginOptions) => new MyCustomPlugin(opts)
@@ -806,13 +772,14 @@
806
772
  * For a detailed explanation of the pipeline, please refer to the discussion in [Issue #167](https://github.com/ipfs/helia-verified-fetch/issues/167).
807
773
  */
808
774
  import { bitswap, trustlessGateway } from '@helia/block-brokers';
809
- import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client';
775
+ import { delegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client';
810
776
  import { httpGatewayRouting, libp2pRouting } from '@helia/routers';
811
777
  import { dns } from '@multiformats/dns';
812
778
  import { createHelia } from 'helia';
813
779
  import { createLibp2p } from 'libp2p';
814
780
  import { getLibp2pConfig } from './utils/libp2p-defaults.js';
815
781
  import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.js';
782
+ export { MEDIA_TYPE_DAG_CBOR, MEDIA_TYPE_CBOR, MEDIA_TYPE_DAG_JSON, MEDIA_TYPE_JSON, MEDIA_TYPE_RAW, MEDIA_TYPE_OCTET_STREAM, MEDIA_TYPE_IPNS_RECORD, MEDIA_TYPE_CAR, MEDIA_TYPE_TAR, MEDIA_TYPE_DAG_PB } from './utils/content-types.js';
816
783
  /**
817
784
  * Create and return a Helia node
818
785
  */
@@ -824,8 +791,9 @@ export async function createVerifiedFetch(init, options) {
824
791
  libp2pConfig.dns = dns;
825
792
  const delegatedRouters = init?.routers ?? ['https://delegated-ipfs.dev'];
826
793
  for (let index = 0; index < delegatedRouters.length; index++) {
827
- const routerUrl = delegatedRouters[index];
828
- libp2pConfig.services[`delegatedRouting${index}`] = () => createDelegatedRoutingV1HttpApiClient(routerUrl);
794
+ libp2pConfig.services[`delegatedRouting${index}`] = delegatedRoutingV1HttpApiClient({
795
+ url: delegatedRouters[index]
796
+ });
829
797
  }
830
798
  // merge any passed options from init.libp2pConfig into libp2pConfig if it exists
831
799
  if (init?.libp2pConfig != null) {
@@ -1 +1 @@
1
- {"version":3,"file":"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} from './plugin-base.js';
5
- export type { PluginOptions, PluginContext, VerifiedFetchPluginFactory } from './types.js';
6
- export * from './plugins.js';
7
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
@@ -1,6 +1,2 @@
1
- /**
2
- * This file is the entry into all things we export from the `src/plugins` directory.
3
- */
4
1
  export { BasePlugin } from './plugin-base.js';
5
- export * from './plugins.js';
6
2
  //# 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,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
@@ -1,22 +1,21 @@
1
- import type { VerifiedFetchPlugin, PluginContext, PluginOptions } from './types.js';
1
+ import type { VerifiedFetchPlugin, PluginContext, PluginOptions } from '../index.js';
2
2
  import type { Logger } from '@libp2p/interface';
3
3
  /**
4
- * Base class for verified-fetch plugins. This class provides a basic implementation of the `FetchHandlerPlugin`
5
- * interface.
4
+ * Base class for verified-fetch plugins. This class provides a basic
5
+ * implementation of the `VerifiedFetchPlugin` interface.
6
6
  *
7
- * Subclasses must implement the `id` property and the `canHandle` and `handle` methods.
8
- * Subclasses may override the `codes` and `log` properties.
7
+ * Subclasses must implement the `id` property, the `canHandle`, and `handle`
8
+ * methods.
9
9
  *
10
- * If your plugin adds/edits the context supplied in `handle`, you should increment the `context.modified` property.
10
+ * Subclasses may override the `codes` and `log` properties.
11
11
  */
12
12
  export declare abstract class BasePlugin implements VerifiedFetchPlugin {
13
- readonly codes: number[];
14
13
  readonly pluginOptions: PluginOptions;
15
- abstract readonly id: string;
16
14
  protected _log?: Logger;
17
15
  get log(): Logger;
18
16
  constructor(options: PluginOptions);
17
+ abstract readonly id: string;
19
18
  abstract canHandle(context: PluginContext): boolean;
20
- abstract handle(context: PluginContext): Promise<Response | null>;
19
+ abstract handle(context: PluginContext): Promise<Response>;
21
20
  }
22
21
  //# sourceMappingURL=plugin-base.d.ts.map
@@ -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,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"}
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,aAAa,CAAA;AACpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;;;;;;;GAQG;AACH,8BAAsB,UAAW,YAAW,mBAAmB;IAC7D,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAA;IACrC,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IAEvB,IAAI,GAAG,IAAK,MAAM,CAOjB;gBAEY,OAAO,EAAE,aAAa;IAInC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,SAAS,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO;IACpD,QAAQ,CAAC,MAAM,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC;CAC5D"}
@@ -1,14 +1,13 @@
1
1
  /**
2
- * Base class for verified-fetch plugins. This class provides a basic implementation of the `FetchHandlerPlugin`
3
- * interface.
2
+ * Base class for verified-fetch plugins. This class provides a basic
3
+ * implementation of the `VerifiedFetchPlugin` interface.
4
4
  *
5
- * Subclasses must implement the `id` property and the `canHandle` and `handle` methods.
6
- * Subclasses may override the `codes` and `log` properties.
5
+ * Subclasses must implement the `id` property, the `canHandle`, and `handle`
6
+ * methods.
7
7
  *
8
- * If your plugin adds/edits the context supplied in `handle`, you should increment the `context.modified` property.
8
+ * Subclasses may override the `codes` and `log` properties.
9
9
  */
10
10
  export class BasePlugin {
11
- codes = [];
12
11
  pluginOptions;
13
12
  _log;
14
13
  get log() {
@@ -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,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
+ {"version":3,"file":"plugin-base.js","sourceRoot":"","sources":["../../../src/plugins/plugin-base.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,OAAgB,UAAU;IACrB,aAAa,CAAe;IAC3B,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,12 +1,12 @@
1
1
  import { BasePlugin } from './plugin-base.js';
2
- import type { PluginContext } from './types.js';
2
+ import type { PluginContext } from '../index.js';
3
3
  /**
4
4
  * Accepts a `CID` and returns a `Response` with a body stream that is a CAR
5
5
  * of the `DAG` referenced by the `CID`.
6
6
  */
7
7
  export declare class CarPlugin extends BasePlugin {
8
8
  readonly id = "car-plugin";
9
- canHandle(context: PluginContext): boolean;
10
- handle(context: PluginContext & Required<Pick<PluginContext, 'byteRangeContext'>>): Promise<Response>;
9
+ canHandle({ accept }: PluginContext): boolean;
10
+ handle(context: PluginContext): Promise<Response>;
11
11
  }
12
12
  //# sourceMappingURL=plugin-handle-car.d.ts.map
@@ -1 +1 @@
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;AAmC/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;CA6E7G"}
1
+ {"version":3,"file":"plugin-handle-car.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-car.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAkChD;;;GAGG;AACH,qBAAa,SAAU,SAAQ,UAAU;IACvC,QAAQ,CAAC,EAAE,gBAAe;IAE1B,SAAS,CAAE,EAAE,MAAM,EAAE,EAAE,aAAa,GAAG,OAAO;IAIxC,MAAM,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsFzD"}