@peerbit/blocks 2.1.0 → 2.1.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.
@@ -20,7 +20,7 @@ export declare class AnyBlockStore implements Blocks {
20
20
  has(cid: string): Promise<boolean>;
21
21
  start(): Promise<void>;
22
22
  stop(): Promise<void>;
23
- status(): import("@peerbit/any-store-interface").MaybePromise<"open" | "opening" | "closed" | "closing">;
23
+ status(): import("@peerbit/any-store-interface").MaybePromise<"opening" | "open" | "closing" | "closed">;
24
24
  waitFor(peer: PeerId | PublicSignKey): Promise<void>;
25
25
  size(): Promise<number>;
26
26
  persisted(): boolean | Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/blocks",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Block store streaming",
5
5
  "type": "module",
6
6
  "types": "./dist/src/index.d.ts",
@@ -79,7 +79,7 @@
79
79
  "dependencies": {
80
80
  "@dao-xyz/borsh": "^5.2.3",
81
81
  "@peerbit/any-store": "^2.1.0",
82
- "@peerbit/stream": "4.0.6",
82
+ "@peerbit/stream": "4.0.7",
83
83
  "@peerbit/blocks-interface": "1.3.0",
84
84
  "@peerbit/crypto": "2.3.0",
85
85
  "@ipld/dag-cbor": "^9.0.2",
@@ -1,28 +0,0 @@
1
- import * as dagCbor from "@ipld/dag-cbor";
2
- import { CID } from "multiformats";
3
- import { type Block } from "multiformats/block";
4
- import * as raw from "multiformats/codecs/raw";
5
- import type { MultihashHasher } from "multiformats/hashes/interface";
6
- export declare const defaultHasher: import("multiformats/dist/src/hashes/hasher").Hasher<"sha2-256", 18>;
7
- export declare const codecCodes: {
8
- 113: typeof dagCbor;
9
- 85: typeof raw;
10
- };
11
- export declare const codecMap: {
12
- raw: typeof raw;
13
- "dag-cbor": typeof dagCbor;
14
- };
15
- export declare const cidifyString: (str: string) => CID;
16
- export declare const stringifyCid: (cid: any) => string;
17
- export declare const checkDecodeBlock: (expectedCID: CID | string, bytes: Uint8Array, options: {
18
- hasher?: any;
19
- codec?: any;
20
- }) => Promise<Block<any, any, any, any>>;
21
- export declare const getBlockValue: <T>(block: Block<T, any, any, any>, links?: string[]) => Promise<T>;
22
- export declare const prepareBlockWrite: (value: any, codec: any, links?: string[]) => any;
23
- export declare const createBlock: (value: any, format: string, options?: {
24
- hasher?: MultihashHasher<number>;
25
- links?: string[];
26
- }) => Promise<Block<any, any, any, any>>;
27
- export declare const calculateRawCid: (bytes: Uint8Array) => Promise<string>;
28
- //# sourceMappingURL=block.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,KAAK,KAAK,EAAkB,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAOrE,eAAO,MAAM,aAAa,sEAAS,CAAC;AAEpC,eAAO,MAAM,UAAU;;;CAGtB,CAAC;AACF,eAAO,MAAM,QAAQ;;;CAGpB,CAAC;AAEF,eAAO,MAAM,YAAY,QAAS,MAAM,KAAG,GAM1C,CAAC;AAEF,eAAO,MAAM,YAAY,QAAS,GAAG,KAAG,MASvC,CAAC;AAEF,eAAO,MAAM,gBAAgB,gBACf,GAAG,GAAG,MAAM,SAClB,UAAU,WACR;IAAE,MAAM,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,GAAG,CAAA;CAAE,KACpC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAanC,CAAC;AACF,eAAO,MAAM,aAAa,GAAU,CAAC,SAC7B,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,UACtB,MAAM,EAAE,KACd,OAAO,CAAC,CAAC,CAiBX,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,GAAG,SAAS,GAAG,UAAU,MAAM,EAAE,QAazE,CAAC;AAEF,eAAO,MAAM,WAAW,UAChB,GAAG,UACF,MAAM,YACJ;IACT,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB,KACC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CASnC,CAAC;AAGF,eAAO,MAAM,eAAe,UAAiB,UAAU,oBAGtD,CAAA"}
package/dist/src/block.js DELETED
@@ -1,93 +0,0 @@
1
- import * as dagCbor from "@ipld/dag-cbor";
2
- import { CID } from "multiformats";
3
- import { base58btc } from "multiformats/bases/base58";
4
- import { decode, encode } from "multiformats/block";
5
- import * as raw from "multiformats/codecs/raw";
6
- import { sha256 } from "multiformats/hashes/sha2";
7
- const unsupportedCodecError = () => new Error("unsupported codec");
8
- const defaultBase = base58btc;
9
- export const defaultHasher = sha256;
10
- export const codecCodes = {
11
- [dagCbor.code]: dagCbor,
12
- [raw.code]: raw,
13
- };
14
- export const codecMap = {
15
- raw,
16
- "dag-cbor": dagCbor,
17
- };
18
- export const cidifyString = (str) => {
19
- if (!str) {
20
- return str; // TODO fix types
21
- }
22
- return CID.parse(str, defaultBase);
23
- };
24
- export const stringifyCid = (cid) => {
25
- if (!cid || typeof cid === "string") {
26
- return cid;
27
- }
28
- if (cid["/"]) {
29
- return defaultBase.encode(cid["/"]);
30
- }
31
- return cid.toString(defaultBase);
32
- };
33
- export const checkDecodeBlock = async (expectedCID, bytes, options) => {
34
- const cidObject = typeof expectedCID === "string" ? cidifyString(expectedCID) : expectedCID;
35
- const codec = options.codec || codecCodes[cidObject.code];
36
- const block = await decode({
37
- bytes,
38
- codec,
39
- hasher: options?.hasher || defaultHasher,
40
- });
41
- if (!block.cid.equals(cidObject)) {
42
- throw new Error("CID does not match");
43
- }
44
- return block;
45
- };
46
- export const getBlockValue = async (block, links) => {
47
- if (block.cid.code === dagCbor.code) {
48
- const value = block.value;
49
- links = links || [];
50
- links.forEach((prop) => {
51
- if (value[prop]) {
52
- value[prop] = Array.isArray(value[prop])
53
- ? value[prop].map(stringifyCid)
54
- : stringifyCid(value[prop]);
55
- }
56
- });
57
- return value;
58
- }
59
- if (block.cid.code === raw.code) {
60
- return block.value;
61
- }
62
- throw new Error("Unsupported");
63
- };
64
- export const prepareBlockWrite = (value, codec, links) => {
65
- if (!codec)
66
- throw unsupportedCodecError();
67
- if (codec.code === dagCbor.code) {
68
- links = links || [];
69
- links.forEach((prop) => {
70
- if (value[prop]) {
71
- value[prop] = Array.isArray(value[prop])
72
- ? value[prop].map(cidifyString)
73
- : cidifyString(value[prop]);
74
- }
75
- });
76
- }
77
- return value;
78
- };
79
- export const createBlock = async (value, format, options) => {
80
- const codec = codecMap[format];
81
- value = prepareBlockWrite(value, codec, options?.links);
82
- const block = await encode({
83
- value,
84
- codec,
85
- hasher: options?.hasher || defaultHasher,
86
- });
87
- return block;
88
- };
89
- export const calculateRawCid = async (bytes) => {
90
- const block = await createBlock(bytes, "raw");
91
- return stringifyCid(block.cid);
92
- };
93
- //# sourceMappingURL=block.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAc,MAAM,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAA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