@helia/json 1.0.3 → 2.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 CHANGED
@@ -4,7 +4,7 @@
4
4
  </a>
5
5
  </p>
6
6
 
7
- # @helia/json <!-- omit in toc -->
7
+ # @helia/json
8
8
 
9
9
  [![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
10
10
  [![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
@@ -13,21 +13,36 @@
13
13
 
14
14
  > Add/get IPLD blocks containing json with your Helia node
15
15
 
16
- ## Table of contents <!-- omit in toc -->
16
+ # About
17
17
 
18
- - [Install](#install)
19
- - [Browser `<script>` tag](#browser-script-tag)
20
- - [API Docs](#api-docs)
21
- - [License](#license)
22
- - [Contribute](#contribute)
18
+ `@helia/json` makes working with JSON in Helia simple & straightforward.
23
19
 
24
- ## Install
20
+ See the JSON interface for all available operations.
21
+
22
+ ## Example
23
+
24
+ ```typescript
25
+ import { createHelia } from 'helia'
26
+ import { json } from '@helia/json'
27
+ import { CID } from 'multiformats/cid'
28
+
29
+ const j = json(helia)
30
+ const cid = await j.put({
31
+ hello: 'world'
32
+ })
33
+ const obj = await j.get(cid)
34
+
35
+ console.info(obj)
36
+ // { hello: 'world' }
37
+ ```
38
+
39
+ # Install
25
40
 
26
41
  ```console
27
42
  $ npm i @helia/json
28
43
  ```
29
44
 
30
- ### Browser `<script>` tag
45
+ ## Browser `<script>` tag
31
46
 
32
47
  Loading this module through a script tag will make it's exports available as `HeliaJson` in the global namespace.
33
48
 
@@ -35,18 +50,18 @@ Loading this module through a script tag will make it's exports available as `He
35
50
  <script src="https://unpkg.com/@helia/json/dist/index.min.js"></script>
36
51
  ```
37
52
 
38
- ## API Docs
53
+ # API Docs
39
54
 
40
55
  - <https://ipfs.github.io/helia-json/modules/_helia_json.html>
41
56
 
42
- ## License
57
+ # License
43
58
 
44
59
  Licensed under either of
45
60
 
46
61
  - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
47
62
  - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
48
63
 
49
- ## Contribute
64
+ # Contribute
50
65
 
51
66
  Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-json/issues).
52
67
 
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaJson = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaJson=(()=>{var $=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var be=Object.prototype.hasOwnProperty;var ge=(r,e)=>{for(var t in e)$(r,t,{get:e[t],enumerable:!0})},xe=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of we(e))!be.call(r,o)&&o!==t&&$(r,o,{get:()=>e[o],enumerable:!(n=le(e,o))||n.enumerable});return r};var me=r=>xe($({},"__esModule",{value:!0}),r);var Ye={};ge(Ye,{json:()=>Ze});function ye(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,d=r.charAt(0),S=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function C(c){if(c instanceof Uint8Array||(ArrayBuffer.isView(c)?c=new Uint8Array(c.buffer,c.byteOffset,c.byteLength):Array.isArray(c)&&(c=Uint8Array.from(c))),!(c instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(c.length===0)return"";for(var h=0,A=0,u=0,w=c.length;u!==w&&c[u]===0;)u++,h++;for(var b=(w-u)*f+1>>>0,p=new Uint8Array(b);u!==w;){for(var g=c[u],v=0,l=b-1;(g!==0||v<A)&&l!==-1;l--,v++)g+=256*p[l]>>>0,p[l]=g%a>>>0,g=g/a>>>0;if(g!==0)throw new Error("Non-zero carry");A=v,u++}for(var m=b-A;m!==b&&p[m]===0;)m++;for(var L=d.repeat(h);m<b;++m)L+=r.charAt(p[m]);return L}function V(c){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;var h=0;if(c[h]!==" "){for(var A=0,u=0;c[h]===d;)A++,h++;for(var w=(c.length-h)*S+1>>>0,b=new Uint8Array(w);c[h];){var p=t[c.charCodeAt(h)];if(p===255)return;for(var g=0,v=w-1;(p!==0||g<u)&&v!==-1;v--,g++)p+=a*b[v]>>>0,b[v]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");u=g,h++}if(c[h]!==" "){for(var l=w-u;l!==w&&b[l]===0;)l++;for(var m=new Uint8Array(A+(w-l)),L=A;l!==w;)m[L++]=b[l++];return m}}}function ue(c){var h=V(c);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:C,decodeUnsafe:V,decode:ue}}var ve=ye,Ae=ve,K=Ae;var tt=new Uint8Array(0);var H=(r,e)=>{if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0},E=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")};var k=class{constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},F=class{constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return W(this,e)}},j=class{constructor(e){this.decoders=e}or(e){return W(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},W=(r,e)=>new j({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),q=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new k(e,t,n),this.decoder=new F(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Z=({name:r,prefix:e,encode:t,decode:n})=>new q(r,e,t,n),R=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=K(t,e);return Z({prefix:r,name:e,encode:n,decode:s=>E(o(s))})},Se=(r,e,t,n)=>{let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,S=0;for(let f=0;f<s;++f){let C=o[r[f]];if(C===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|C,a+=t,a>=8&&(a-=8,i[S++]=255&d>>a)}if(a>=t||255&d<<8-a)throw new SyntaxError("Unexpected end of data");return i},Ce=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s},x=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>Z({prefix:e,name:r,encode(o){return Ce(o,n,t)},decode(o){return Se(o,n,t,r)}});var I=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ct=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),at=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),dt=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ht=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ft=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),pt=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ut=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),lt=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var y=R({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),gt=R({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ee=ee,Y=128,Ue=127,De=~Ue,ze=Math.pow(2,31);function ee(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ze;)e[t++]=r&255|Y,r/=128;for(;r&De;)e[t++]=r&255|Y,r>>>=7;return e[t]=r|0,ee.bytes=t-n+1,e}var Ie=J,Me=128,_=127;function J(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw J.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&_)<<o:(i&_)*Math.pow(2,o),o+=7}while(i>=Me);return J.bytes=s-n,t}var Ne=Math.pow(2,7),Oe=Math.pow(2,14),Te=Math.pow(2,21),Ve=Math.pow(2,28),Le=Math.pow(2,35),Be=Math.pow(2,42),$e=Math.pow(2,49),ke=Math.pow(2,56),Fe=Math.pow(2,63),je=function(r){return r<Ne?1:r<Oe?2:r<Te?3:r<Ve?4:r<Le?5:r<Be?6:r<$e?7:r<ke?8:r<Fe?9:10},qe={encode:Ee,decode:Ie,encodingLength:je},Re=qe,M=Re;var N=(r,e=0)=>[M.decode(r,e),M.decode.bytes],U=(r,e,t=0)=>(M.encode(r,e,t),e),D=r=>M.encodingLength(r);var O=(r,e)=>{let t=e.byteLength,n=D(r),o=n+D(t),s=new Uint8Array(o+t);return U(r,s,0),U(t,s,n),s.set(e,o),new z(r,t,e,s)},re=r=>{let e=E(r),[t,n]=N(e),[o,s]=N(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new z(t,o,i,e)},ne=(r,e)=>{if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&H(r.bytes,t.bytes)}},z=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var se=(r,e)=>{let{bytes:t,version:n}=r;switch(n){case 0:return Pe(t,P(r),e||y.encoder);default:return Qe(t,P(r),e||I.encoder)}};var ie=new WeakMap,P=r=>{let e=ie.get(r);if(e==null){let t=new Map;return ie.set(r,t),t}return e},B=class r{constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==T)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ge)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=O(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n&&e.code===n.code&&e.version===n.version&&ne(e.multihash,n.multihash)}toString(e){return se(this,e)}toJSON(){return{"/":se(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i||ce(n,o,s.bytes))}else if(t[Xe]===!0){let{version:n,multihash:o,code:s}=t,i=re(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==T)throw new Error(`Version 0 CID must use dag-pb (code: ${T}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ce(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,T,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=E(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new z(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[C,V]=N(e.subarray(t));return t+=V,C},o=n(),s=T;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),d=n(),S=t+d,f=S-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:f,size:S}}static parse(e,t){let[n,o]=Je(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return P(s).set(n,e),s}},Je=(r,e)=>{switch(r[0]){case"Q":{let t=e||y;return[y.prefix,t.decode(`${y.prefix}${r}`)]}case y.prefix:{let t=e||y;return[y.prefix,t.decode(r)]}case I.prefix:{let t=e||I;return[I.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}},Pe=(r,e,t)=>{let{prefix:n}=t;if(n!==y.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o},Qe=(r,e,t)=>{let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o},T=112,Ge=18,ce=(r,e,t)=>{let n=D(r),o=n+D(e),s=new Uint8Array(o+t.byteLength);return U(r,s,0),U(e,s,n),s.set(t,o),s},Xe=Symbol.for("@ipld/js-cid/CID");var Ke=new TextEncoder,He=new TextDecoder;var ae=512,de=r=>Ke.encode(JSON.stringify(r)),he=r=>JSON.parse(He.decode(r));var G=({name:r,code:e,encode:t})=>new Q(r,e,t),Q=class{constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?O(this.code,t):t.then(n=>O(this.code,n))}else throw Error("Unknown type, must be binary type")}};var fe=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),pe=G({name:"sha2-256",code:18,encode:fe("SHA-256")}),It=G({name:"sha2-512",code:19,encode:fe("SHA-512")});var X=class{components;constructor(e){this.components=e}async add(e,t={}){let n=de(e),o=await(t.hasher??pe).digest(n),s=B.createV1(ae,o);return await this.components.blockstore.put(s,n,t),s}async get(e,t={}){let n=await this.components.blockstore.get(e,t);return he(n)}};function Ze(r){return new X(r)}return me(Ye);})();
2
+ "use strict";var HeliaJson=(()=>{var $=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var we=Object.prototype.hasOwnProperty;var xe=(r,e)=>{for(var t in e)$(r,t,{get:e[t],enumerable:!0})},ge=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of be(e))!we.call(r,o)&&o!==t&&$(r,o,{get:()=>e[o],enumerable:!(n=le(e,o))||n.enumerable});return r};var ye=r=>ge($({},"__esModule",{value:!0}),r);var Ye={};xe(Ye,{json:()=>Ze});var et=new Uint8Array(0);function K(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function A(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function me(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,d=r.charAt(0),E=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function S(c){if(c instanceof Uint8Array||(ArrayBuffer.isView(c)?c=new Uint8Array(c.buffer,c.byteOffset,c.byteLength):Array.isArray(c)&&(c=Uint8Array.from(c))),!(c instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(c.length===0)return"";for(var h=0,C=0,p=0,b=c.length;p!==b&&c[p]===0;)p++,h++;for(var w=(b-p)*f+1>>>0,u=new Uint8Array(w);p!==b;){for(var x=c[p],v=0,l=w-1;(x!==0||v<C)&&l!==-1;l--,v++)x+=256*u[l]>>>0,u[l]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");C=v,p++}for(var y=w-C;y!==w&&u[y]===0;)y++;for(var L=d.repeat(h);y<w;++y)L+=r.charAt(u[y]);return L}function V(c){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;var h=0;if(c[h]!==" "){for(var C=0,p=0;c[h]===d;)C++,h++;for(var b=(c.length-h)*E+1>>>0,w=new Uint8Array(b);c[h];){var u=t[c.charCodeAt(h)];if(u===255)return;for(var x=0,v=b-1;(u!==0||x<p)&&v!==-1;v--,x++)u+=a*w[v]>>>0,w[v]=u%256>>>0,u=u/256>>>0;if(u!==0)throw new Error("Non-zero carry");p=x,h++}if(c[h]!==" "){for(var l=b-p;l!==b&&w[l]===0;)l++;for(var y=new Uint8Array(C+(b-l)),L=C;l!==b;)y[L++]=w[l++];return y}}}function pe(c){var h=V(c);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:S,decodeUnsafe:V,decode:pe}}var ve=me,Ce=ve,H=Ce;var k=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},F=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return W(this,e)}},j=class{decoders;constructor(e){this.decoders=e}or(e){return W(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function W(r,e){return new j({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var q=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new k(e,t,n),this.decoder=new F(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Z({name:r,prefix:e,encode:t,decode:n}){return new q(r,e,t,n)}function R({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=H(t,r);return Z({prefix:e,name:r,encode:n,decode:s=>A(o(s))})}function Ee(r,e,t,n){let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,E=0;for(let f=0;f<s;++f){let S=o[r[f]];if(S===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|S,a+=t,a>=8&&(a-=8,i[E++]=255&d>>a)}if(a>=t||255&d<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Se(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function g({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Z({prefix:e,name:r,encode(o){return Se(o,n,t)},decode(o){return Ee(o,n,t,r)}})}var I=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ct=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),at=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),dt=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ht=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ft=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ut=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),pt=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),lt=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var m=R({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xt=R({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ae=ee,Y=128,De=127,Ue=~De,ze=Math.pow(2,31);function ee(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ze;)e[t++]=r&255|Y,r/=128;for(;r&Ue;)e[t++]=r&255|Y,r>>>=7;return e[t]=r|0,ee.bytes=t-n+1,e}var Ie=J,Me=128,_=127;function J(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw J.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&_)<<o:(i&_)*Math.pow(2,o),o+=7}while(i>=Me);return J.bytes=s-n,t}var Ne=Math.pow(2,7),Oe=Math.pow(2,14),Te=Math.pow(2,21),Ve=Math.pow(2,28),Le=Math.pow(2,35),Be=Math.pow(2,42),$e=Math.pow(2,49),ke=Math.pow(2,56),Fe=Math.pow(2,63),je=function(r){return r<Ne?1:r<Oe?2:r<Te?3:r<Ve?4:r<Le?5:r<Be?6:r<$e?7:r<ke?8:r<Fe?9:10},qe={encode:Ae,decode:Ie,encodingLength:je},Re=qe,M=Re;function N(r,e=0){return[M.decode(r,e),M.decode.bytes]}function D(r,e,t=0){return M.encode(r,e,t),e}function U(r){return M.encodingLength(r)}function O(r,e){let t=e.byteLength,n=U(r),o=n+U(t),s=new Uint8Array(o+t);return D(r,s,0),D(t,s,n),s.set(e,o),new z(r,t,e,s)}function re(r){let e=A(r),[t,n]=N(e),[o,s]=N(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new z(t,o,i,e)}function ne(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&K(r.bytes,t.bytes)}}var z=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function se(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Pe(t,P(r),e??m.encoder);default:return Qe(t,P(r),e??I.encoder)}}var ie=new WeakMap;function P(r){let e=ie.get(r);if(e==null){let t=new Map;return ie.set(r,t),t}return e}var B=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==T)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ge)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=O(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&ne(e.multihash,n.multihash)}toString(e){return se(this,e)}toJSON(){return{"/":se(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??ce(n,o,s.bytes))}else if(t[Xe]===!0){let{version:n,multihash:o,code:s}=t,i=re(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==T)throw new Error(`Version 0 CID must use dag-pb (code: ${T}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ce(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,T,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=A(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new z(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[S,V]=N(e.subarray(t));return t+=V,S},o=n(),s=T;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),d=n(),E=t+d,f=E-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:f,size:E}}static parse(e,t){let[n,o]=Je(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return P(s).set(n,e),s}};function Je(r,e){switch(r[0]){case"Q":{let t=e??m;return[m.prefix,t.decode(`${m.prefix}${r}`)]}case m.prefix:{let t=e??m;return[m.prefix,t.decode(r)]}case I.prefix:{let t=e??I;return[I.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Pe(r,e,t){let{prefix:n}=t;if(n!==m.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Qe(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var T=112,Ge=18;function ce(r,e,t){let n=U(r),o=n+U(e),s=new Uint8Array(o+t.byteLength);return D(r,s,0),D(e,s,n),s.set(t,o),s}var Xe=Symbol.for("@ipld/js-cid/CID");var Ke=new TextEncoder,He=new TextDecoder;var ae=512;function de(r){return Ke.encode(JSON.stringify(r))}function he(r){return JSON.parse(He.decode(r))}function G({name:r,code:e,encode:t}){return new Q(r,e,t)}var Q=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?O(this.code,t):t.then(n=>O(this.code,n))}else throw Error("Unknown type, must be binary type")}};function fe(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ue=G({name:"sha2-256",code:18,encode:fe("SHA-256")}),It=G({name:"sha2-512",code:19,encode:fe("SHA-512")});var X=class{components;constructor(e){this.components=e}async add(e,t={}){let n=de(e),o=await(t.hasher??ue).digest(n),s=B.createV1(ae,o);return await this.components.blockstore.put(s,n,t),s}async get(e,t={}){let n=await this.components.blockstore.get(e,t);return he(n)}};function Ze(r){return new X(r)}return ye(Ye);})();
3
3
  return HeliaJson}));
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@helia/json",
3
- "version": "1.0.3",
3
+ "version": "2.0.0",
4
4
  "description": "Add/get IPLD blocks containing json with your Helia node",
5
5
  "license": "Apache-2.0 OR MIT",
6
- "homepage": "https://github.com/ipfs/helia-json/tree/master/packages/json#readme",
6
+ "homepage": "https://github.com/ipfs/helia-json/tree/main/packages/json#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/ipfs/helia-json.git"
@@ -11,6 +11,10 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ipfs/helia-json/issues"
13
13
  },
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "provenance": true
17
+ },
14
18
  "keywords": [
15
19
  "IPFS"
16
20
  ],
@@ -135,14 +139,14 @@
135
139
  "release": "aegir release"
136
140
  },
137
141
  "dependencies": {
138
- "@helia/interface": "^2.0.0",
142
+ "@helia/interface": "^3.0.0",
139
143
  "@libp2p/interfaces": "^3.3.1",
140
- "interface-blockstore": "^5.0.0",
141
- "multiformats": "^12.0.1",
144
+ "multiformats": "^13.0.0",
142
145
  "progress-events": "^1.0.0"
143
146
  },
144
147
  "devDependencies": {
145
- "aegir": "^41.0.0",
146
- "blockstore-core": "^4.0.1"
148
+ "aegir": "^42.0.1",
149
+ "blockstore-core": "^4.0.1",
150
+ "interface-blockstore": "^5.0.0"
147
151
  }
148
152
  }