@helia/json 0.0.0 → 1.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 CHANGED
@@ -11,7 +11,7 @@
11
11
  [![codecov](https://img.shields.io/codecov/c/github/ipfs/helia-json.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia-json)
12
12
  [![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia-json/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia-json/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
13
13
 
14
- > Add/get IPLD blocks containing strings with your Helia node
14
+ > Add/get IPLD blocks containing json with your Helia node
15
15
 
16
16
  ## Table of contents <!-- omit in toc -->
17
17
 
@@ -29,7 +29,7 @@ $ npm i @helia/json
29
29
 
30
30
  ### Browser `<script>` tag
31
31
 
32
- Loading this module through a script tag will make it's exports available as `HeliaStrings` in the global namespace.
32
+ Loading this module through a script tag will make it's exports available as `HeliaJson` in the global namespace.
33
33
 
34
34
  ```html
35
35
  <script src="https://unpkg.com/@helia/json/dist/index.min.js"></script>
@@ -37,7 +37,7 @@ Loading this module through a script tag will make it's exports available as `He
37
37
 
38
38
  ## API Docs
39
39
 
40
- - <https://ipfs.github.io/helia-json/modules/_helia_strings.html>
40
+ - <https://ipfs.github.io/helia-json/modules/_helia_json.html>
41
41
 
42
42
  ## License
43
43
 
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 k=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var be=Object.prototype.hasOwnProperty;var ge=(r,e)=>{for(var t in e)k(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&&k(r,o,{get:()=>e[o],enumerable:!(n=le(e,o))||n.enumerable});return r};var me=r=>xe(k({},"__esModule",{value:!0}),r);var Ye={};ge(Ye,{json:()=>Ze});var ye=W,K=128,ve=127,Ae=~ve,Se=Math.pow(2,31);function W(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Se;)e[t++]=r&255|K,r/=128;for(;r&Ae;)e[t++]=r&255|K,r>>>=7;return e[t]=r|0,W.bytes=t-n+1,e}var Ee=I,Ue=128,H=127;function I(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw I.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&H)<<o:(i&H)*Math.pow(2,o),o+=7}while(i>=Ue);return I.bytes=s-n,t}var ze=Math.pow(2,7),Ce=Math.pow(2,14),Me=Math.pow(2,21),Ne=Math.pow(2,28),Oe=Math.pow(2,35),Te=Math.pow(2,42),Ve=Math.pow(2,49),De=Math.pow(2,56),Le=Math.pow(2,63),Be=function(r){return r<ze?1:r<Ce?2:r<Me?3:r<Ne?4:r<Oe?5:r<Te?6:r<Ve?7:r<De?8:r<Le?9:10},$e={encode:ye,decode:Ee,encodingLength:Be},ke=$e,O=ke;var T=(r,e=0)=>[O.decode(r,e),O.decode.bytes],z=(r,e,t=0)=>(O.encode(r,e,t),e),C=r=>O.encodingLength(r);var rt=new Uint8Array(0);var Y=(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},M=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 V=(r,e)=>{let t=e.byteLength,n=C(r),o=n+C(t),s=new Uint8Array(o+t);return z(r,s,0),z(t,s,n),s.set(e,o),new N(r,t,e,s)},_=r=>{let e=M(r),[t,n]=T(e),[o,s]=T(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new N(t,o,i,e)},ee=(r,e)=>{if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Y(r.bytes,t.bytes)}},N=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Ie(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,h=r.charAt(0),E=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function U(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 f=0,S=0,l=0,b=c.length;l!==b&&c[l]===0;)l++,f++;for(var g=(b-l)*p+1>>>0,u=new Uint8Array(g);l!==b;){for(var x=c[l],A=0,w=g-1;(x!==0||A<S)&&w!==-1;w--,A++)x+=256*u[w]>>>0,u[w]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");S=A,l++}for(var y=g-S;y!==g&&u[y]===0;)y++;for(var $=h.repeat(f);y<g;++y)$+=r.charAt(u[y]);return $}function B(c){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;var f=0;if(c[f]!==" "){for(var S=0,l=0;c[f]===h;)S++,f++;for(var b=(c.length-f)*E+1>>>0,g=new Uint8Array(b);c[f];){var u=t[c.charCodeAt(f)];if(u===255)return;for(var x=0,A=b-1;(u!==0||x<l)&&A!==-1;A--,x++)u+=a*g[A]>>>0,g[A]=u%256>>>0,u=u/256>>>0;if(u!==0)throw new Error("Non-zero carry");l=x,f++}if(c[f]!==" "){for(var w=b-l;w!==b&&g[w]===0;)w++;for(var y=new Uint8Array(S+(b-w)),$=S;w!==b;)y[$++]=g[w++];return y}}}function ue(c){var f=B(c);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:U,decodeUnsafe:B,decode:ue}}var Fe=Ie,je=Fe,re=je;var F=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")}},j=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 ne(this,e)}},q=class{constructor(e){this.decoders=e}or(e){return ne(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`)}},ne=(r,e)=>new q({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),R=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new F(e,t,n),this.decoder=new j(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},oe=({name:r,prefix:e,encode:t,decode:n})=>new R(r,e,t,n),J=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=re(t,e);return oe({prefix:r,name:e,encode:n,decode:s=>M(o(s))})},qe=(r,e,t,n)=>{let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,h=0,E=0;for(let p=0;p<s;++p){let U=o[r[p]];if(U===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<t|U,a+=t,a>=8&&(a-=8,i[E++]=255&h>>a)}if(a>=t||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return i},Re=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let h=0;h<r.length;++h)for(a=a<<8|r[h],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},m=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>oe({prefix:e,name:r,encode(o){return Re(o,n,t)},decode(o){return qe(o,n,t,r)}});var v=J({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ht=J({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var D=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ut=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),lt=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),wt=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),bt=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gt=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xt=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mt=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),yt=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var se=(r,e)=>{let{bytes:t,version:n}=r;switch(n){case 0:return Pe(t,P(r),e||v.encoder);default:return Qe(t,P(r),e||D.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},d=class{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!==L)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 d.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=V(e,t);return d.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 d.equals(this,e)}static equals(e,t){let n=t;return n&&e.code===n.code&&e.version===n.version&&ee(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 d)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new d(n,o,s,i||ce(n,o,s.bytes))}else if(t[Xe]===!0){let{version:n,multihash:o,code:s}=t,i=_(o);return d.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!==L)throw new Error(`Version 0 CID must use dag-pb (code: ${L}) block encoding`);return new d(e,t,n,n.bytes)}case 1:{let o=ce(e,t,n.bytes);return new d(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return d.create(0,L,e)}static createV1(e,t){return d.create(1,e,t)}static decode(e){let[t,n]=d.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=d.inspectBytes(e),n=t.size-t.multihashSize,o=M(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 N(t.multihashCode,t.digestSize,s,o);return[t.version===0?d.createV0(i):d.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[U,B]=T(e.subarray(t));return t+=B,U},o=n(),s=L;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(),h=n(),E=t+h,p=E-i;return{version:o,codec:s,multihashCode:a,digestSize:h,multihashSize:p,size:E}}static parse(e,t){let[n,o]=Je(e,t),s=d.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||v;return[v.prefix,t.decode(`${v.prefix}${r}`)]}case v.prefix:{let t=e||v;return[v.prefix,t.decode(r)]}case D.prefix:{let t=e||D;return[D.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!==v.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},L=112,Ge=18,ce=(r,e,t)=>{let n=C(r),o=n+C(e),s=new Uint8Array(o+t.byteLength);return z(r,s,0),z(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?V(this.code,t):t.then(n=>V(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")}),Nt=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=d.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 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});var ye=W,K=128,ve=127,Ae=~ve,Se=Math.pow(2,31);function W(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Se;)e[t++]=r&255|K,r/=128;for(;r&Ae;)e[t++]=r&255|K,r>>>=7;return e[t]=r|0,W.bytes=t-n+1,e}var Ce=k,Ee=128,H=127;function k(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw k.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&H)<<o:(i&H)*Math.pow(2,o),o+=7}while(i>=Ee);return k.bytes=s-n,t}var Ue=Math.pow(2,7),De=Math.pow(2,14),ze=Math.pow(2,21),Ie=Math.pow(2,28),Me=Math.pow(2,35),Ne=Math.pow(2,42),Oe=Math.pow(2,49),Te=Math.pow(2,56),Ve=Math.pow(2,63),Le=function(r){return r<Ue?1:r<De?2:r<ze?3:r<Ie?4:r<Me?5:r<Ne?6:r<Oe?7:r<Te?8:r<Ve?9:10},Be={encode:ye,decode:Ce,encodingLength:Le},$e=Be,I=$e;var M=(r,e=0)=>[I.decode(r,e),I.decode.bytes],E=(r,e,t=0)=>(I.encode(r,e,t),e),U=r=>I.encodingLength(r);var rt=new Uint8Array(0);var Y=(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},D=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 N=(r,e)=>{let t=e.byteLength,n=U(r),o=n+U(t),s=new Uint8Array(o+t);return E(r,s,0),E(t,s,n),s.set(e,o),new z(r,t,e,s)},_=r=>{let e=D(r),[t,n]=M(e),[o,s]=M(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new z(t,o,i,e)},ee=(r,e)=>{if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Y(r.bytes,t.bytes)}},z=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function ke(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 Fe=ke,je=Fe,re=je;var F=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")}},j=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 ne(this,e)}},q=class{constructor(e){this.decoders=e}or(e){return ne(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`)}},ne=(r,e)=>new q({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),R=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new F(e,t,n),this.decoder=new j(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},oe=({name:r,prefix:e,encode:t,decode:n})=>new R(r,e,t,n),J=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=re(t,e);return oe({prefix:r,name:e,encode:n,decode:s=>D(o(s))})},qe=(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},Re=(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})=>oe({prefix:e,name:r,encode(o){return Re(o,n,t)},decode(o){return qe(o,n,t,r)}});var y=J({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ht=J({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var O=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ut=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),lt=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),wt=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),bt=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gt=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xt=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mt=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),yt=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});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||O.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=N(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&&ee(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=_(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=D(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]=M(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 O.prefix:{let t=e||O;return[O.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=U(r),o=n+U(e),s=new Uint8Array(o+t.byteLength);return E(r,s,0),E(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?N(this.code,t):t.then(n=>N(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);})();
3
3
  return HeliaJson}));
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * `@helia/json` makes working with strings {@link https://github.com/ipfs/helia Helia} simple & straightforward.
4
+ * `@helia/json` makes working with JSON in {@link https://github.com/ipfs/helia Helia} simple & straightforward.
5
5
  *
6
- * See the {@link Strings Strings interface} for all available operations.
6
+ * See the {@link JSON} interface for all available operations.
7
7
  *
8
8
  * @example
9
9
  *
package/dist/src/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * `@helia/json` makes working with strings {@link https://github.com/ipfs/helia Helia} simple & straightforward.
4
+ * `@helia/json` makes working with JSON in {@link https://github.com/ipfs/helia Helia} simple & straightforward.
5
5
  *
6
- * See the {@link Strings Strings interface} for all available operations.
6
+ * See the {@link JSON} interface for all available operations.
7
7
  *
8
8
  * @example
9
9
  *
@@ -0,0 +1,7 @@
1
+ {
2
+ "AddOptions": "https://ipfs.github.io/helia-json/interfaces/AddOptions.html",
3
+ "GetOptions": "https://ipfs.github.io/helia-json/interfaces/GetOptions.html",
4
+ "JSON": "https://ipfs.github.io/helia-json/interfaces/JSON.html",
5
+ "JSONComponents": "https://ipfs.github.io/helia-json/interfaces/JSONComponents.html",
6
+ "json": "https://ipfs.github.io/helia-json/functions/json-1.html"
7
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@helia/json",
3
- "version": "0.0.0",
3
+ "version": "1.0.1",
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/strings#readme",
6
+ "homepage": "https://github.com/ipfs/helia-json/tree/master/packages/json#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/ipfs/helia-json.git"
@@ -14,10 +14,6 @@
14
14
  "keywords": [
15
15
  "IPFS"
16
16
  ],
17
- "engines": {
18
- "node": ">=16.0.0",
19
- "npm": ">=7.0.0"
20
- },
21
17
  "type": "module",
22
18
  "types": "./dist/src/index.d.ts",
23
19
  "files": [
@@ -128,7 +124,6 @@
128
124
  "lint": "aegir lint",
129
125
  "dep-check": "aegir dep-check",
130
126
  "build": "aegir build",
131
- "docs": "aegir docs",
132
127
  "test": "aegir test",
133
128
  "test:chrome": "aegir test -t browser --cov",
134
129
  "test:chrome-webworker": "aegir test -t webworker",
@@ -143,14 +138,10 @@
143
138
  "@libp2p/interfaces": "^3.3.1",
144
139
  "interface-blockstore": "^5.0.0",
145
140
  "multiformats": "^11.0.1",
146
- "progress-events": "^1.0.0",
147
- "uint8arrays": "^4.0.3"
141
+ "progress-events": "^1.0.0"
148
142
  },
149
143
  "devDependencies": {
150
- "aegir": "^39.0.3",
144
+ "aegir": "^40.0.11",
151
145
  "blockstore-core": "^4.0.1"
152
- },
153
- "typedoc": {
154
- "entryPoint": "./src/index.ts"
155
146
  }
156
147
  }
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * `@helia/json` makes working with strings {@link https://github.com/ipfs/helia Helia} simple & straightforward.
4
+ * `@helia/json` makes working with JSON in {@link https://github.com/ipfs/helia Helia} simple & straightforward.
5
5
  *
6
- * See the {@link Strings Strings interface} for all available operations.
6
+ * See the {@link JSON} interface for all available operations.
7
7
  *
8
8
  * @example
9
9
  *