@helia/dag-json 4.1.0-34d3ecd7 → 4.1.0-93aa4645
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/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +1 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +9 -5
package/dist/src/index.d.ts
CHANGED
|
@@ -28,17 +28,15 @@ import { CID } from 'multiformats/cid';
|
|
|
28
28
|
import type { GetBlockProgressEvents, ProviderOptions, PutBlockProgressEvents } from '@helia/interface/blocks';
|
|
29
29
|
import type { AbortOptions } from '@libp2p/interface';
|
|
30
30
|
import type { Blockstore } from 'interface-blockstore';
|
|
31
|
-
import type { BlockCodec } from 'multiformats/codecs/interface';
|
|
32
31
|
import type { MultihashHasher } from 'multiformats/hashes/interface';
|
|
33
32
|
import type { ProgressOptions } from 'progress-events';
|
|
34
33
|
export interface DAGJSONComponents {
|
|
35
34
|
blockstore: Blockstore;
|
|
36
35
|
}
|
|
37
36
|
export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
|
|
38
|
-
hasher
|
|
37
|
+
hasher?: MultihashHasher;
|
|
39
38
|
}
|
|
40
39
|
export interface GetOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents>, ProviderOptions {
|
|
41
|
-
codec: BlockCodec<any, unknown>;
|
|
42
40
|
}
|
|
43
41
|
/**
|
|
44
42
|
* The JSON interface provides a simple and intuitive way to add/get objects
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"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|
* ```
|
|
26
26
|
*/
|
|
27
|
+
import { InvalidCodecError } from '@helia/interface';
|
|
27
28
|
import * as codec from '@ipld/dag-json';
|
|
28
29
|
import toBuffer from 'it-to-buffer';
|
|
29
30
|
import { CID } from 'multiformats/cid';
|
|
@@ -41,6 +42,9 @@ class DefaultDAGJSON {
|
|
|
41
42
|
return cid;
|
|
42
43
|
}
|
|
43
44
|
async get(cid, options = {}) {
|
|
45
|
+
if (cid.code !== codec.code) {
|
|
46
|
+
throw new InvalidCodecError('The passed CID had an incorrect codec, it may correspond to a non-DAG-JSON block');
|
|
47
|
+
}
|
|
44
48
|
const buf = await toBuffer(this.components.blockstore.get(cid, options));
|
|
45
49
|
return codec.decode(buf);
|
|
46
50
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,OAAO,QAAQ,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,OAAO,QAAQ,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAqEjD,MAAM,cAAc;IACD,UAAU,CAAmB;IAE9C,YAAa,UAA6B;QACxC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,GAAQ,EAAE,UAAsB,EAAE;QAC3C,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACzD,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAE1C,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;QAEvD,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,KAAK,CAAC,GAAG,CAAM,GAAQ,EAAE,UAAsB,EAAE;QAC/C,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;YAC5B,MAAM,IAAI,iBAAiB,CAAC,kFAAkF,CAAC,CAAA;QACjH,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;QAExE,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAE,KAAiC;IACxD,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,CAAA;AAClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/dag-json",
|
|
3
|
-
"version": "4.1.0-
|
|
3
|
+
"version": "4.1.0-93aa4645",
|
|
4
4
|
"description": "Add/get IPLD blocks containing dag-json with your Helia node",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/dag-json#readme",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"test:electron-main": "aegir test -t electron-main"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@helia/interface": "5.4.0-
|
|
50
|
+
"@helia/interface": "5.4.0-93aa4645",
|
|
51
51
|
"@ipld/dag-json": "^10.2.5",
|
|
52
52
|
"@libp2p/interface": "^3.0.2",
|
|
53
53
|
"interface-blockstore": "^6.0.1",
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
import { InvalidCodecError } from '@helia/interface'
|
|
28
29
|
import * as codec from '@ipld/dag-json'
|
|
29
30
|
import toBuffer from 'it-to-buffer'
|
|
30
31
|
import { CID } from 'multiformats/cid'
|
|
@@ -32,7 +33,6 @@ import { sha256 } from 'multiformats/hashes/sha2'
|
|
|
32
33
|
import type { GetBlockProgressEvents, ProviderOptions, PutBlockProgressEvents } from '@helia/interface/blocks'
|
|
33
34
|
import type { AbortOptions } from '@libp2p/interface'
|
|
34
35
|
import type { Blockstore } from 'interface-blockstore'
|
|
35
|
-
import type { BlockCodec } from 'multiformats/codecs/interface'
|
|
36
36
|
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
37
37
|
import type { ProgressOptions } from 'progress-events'
|
|
38
38
|
|
|
@@ -41,11 +41,11 @@ export interface DAGJSONComponents {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
|
|
44
|
-
hasher
|
|
44
|
+
hasher?: MultihashHasher
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export interface GetOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents>, ProviderOptions {
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
@@ -105,7 +105,7 @@ class DefaultDAGJSON implements DAGJSON {
|
|
|
105
105
|
this.components = components
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
async add (obj: any, options:
|
|
108
|
+
async add (obj: any, options: AddOptions = {}): Promise<CID> {
|
|
109
109
|
const buf = codec.encode(obj)
|
|
110
110
|
const hash = await (options.hasher ?? sha256).digest(buf)
|
|
111
111
|
const cid = CID.createV1(codec.code, hash)
|
|
@@ -115,7 +115,11 @@ class DefaultDAGJSON implements DAGJSON {
|
|
|
115
115
|
return cid
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
async get <T> (cid: CID, options:
|
|
118
|
+
async get <T> (cid: CID, options: GetOptions = {}): Promise<T> {
|
|
119
|
+
if (cid.code !== codec.code) {
|
|
120
|
+
throw new InvalidCodecError('The passed CID had an incorrect codec, it may correspond to a non-DAG-JSON block')
|
|
121
|
+
}
|
|
122
|
+
|
|
119
123
|
const buf = await toBuffer(this.components.blockstore.get(cid, options))
|
|
120
124
|
|
|
121
125
|
return codec.decode(buf)
|