@dxos/hypercore 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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.
@@ -79,8 +79,8 @@ import { StorageType, createStorage } from "@dxos/random-access-storage";
79
79
  import hypercore from "@dxos/vendor-hypercore/hypercore";
80
80
 
81
81
  // src/util.ts
82
- import util from "@dxos/node-std/util";
83
- var py = (obj, fn) => util.promisify(fn.bind(obj));
82
+ import { promisify } from "@dxos/node-std/util";
83
+ var py = (obj, fn) => promisify(fn.bind(obj));
84
84
 
85
85
  // src/hypercore-factory.ts
86
86
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/hypercore/src/hypercore-factory.ts";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/crypto.ts", "../../../src/defaults.ts", "../../../src/hypercore-factory.ts", "../../../src/util.ts", "../../../src/iterator.ts"],
4
- "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nexport { default as hypercore } from '@dxos/vendor-hypercore/hypercore';\nexport type {\n Hypercore,\n HypercoreOptions,\n HypercoreProperties,\n ReadStreamOptions,\n} from '@dxos/vendor-hypercore/hypercore';\n\nexport * from './crypto';\nexport * from './defaults';\nexport * from './hypercore-factory';\nexport * from './iterator';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { callbackify } from 'node:util';\n\nimport { type Codec, type EncodingOptions } from '@dxos/codec-protobuf';\nimport { type Signer, verifySignature } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { type PublicKey } from '@dxos/keys';\nimport { arrayToBuffer } from '@dxos/util';\nimport { type AbstractValueEncoding, type Crypto } from '@dxos/vendor-hypercore/hypercore';\n\n/**\n * Create encoding (e.g., from protobuf codec).\n */\nexport const createCodecEncoding = <T>(codec: Codec<T>, opts?: EncodingOptions): AbstractValueEncoding<T> => ({\n encode: (obj: T) => arrayToBuffer(codec.encode(obj, opts)),\n decode: (buffer: Buffer) => codec.decode(buffer, opts),\n});\n\n/**\n * Create a custom hypercore crypto signer.\n */\n// TODO(burdon): Create test without adding deps.\nexport const createCrypto = (signer: Signer, publicKey: PublicKey): Crypto => {\n invariant(signer);\n invariant(publicKey);\n\n return {\n sign: (message, secretKey, cb) => {\n callbackify(signer.sign.bind(signer!))(publicKey, message, (err, result) => {\n if (err) {\n cb(err, null);\n return;\n }\n\n cb(null, arrayToBuffer(result));\n });\n },\n\n verify: async (message, signature, key, cb) => {\n // NOTE: Uses the public key passed into function.\n callbackify(verifySignature)(publicKey, message, signature, cb);\n },\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport type {\n HypercoreOptions,\n ReadStreamOptions,\n ReplicationOptions,\n WriteStreamOptions,\n} from '@dxos/vendor-hypercore/hypercore';\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-feed--hypercorestorage-key-options\n */\nexport const defaultFeedOptions: HypercoreOptions = {\n createIfMissing: true,\n valueEncoding: 'binary',\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatereadstreamoptions\n */\nexport const defaultReadStreamOptions: ReadStreamOptions = {\n start: 0,\n end: Infinity,\n snapshot: true,\n tail: false,\n live: false,\n timeout: 0,\n wait: true,\n batch: 1,\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatewritestreamopts\n */\nexport const defaultWriteStreamOptions: WriteStreamOptions = {\n maxBlockSize: Infinity,\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options\n */\nexport const defaultReplicateOptions: ReplicationOptions = {\n live: false,\n ack: false,\n download: true,\n upload: true,\n encrypted: true,\n noise: true,\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { type Directory, StorageType, createStorage } from '@dxos/random-access-storage';\nimport hypercore from '@dxos/vendor-hypercore/hypercore';\nimport type { Hypercore, HypercoreOptions } from '@dxos/vendor-hypercore/hypercore';\n\nimport { py } from './util';\n\n/**\n * Creates feeds with default properties.\n */\nexport class HypercoreFactory<T> {\n constructor(\n private readonly _root: Directory = createStorage({ type: StorageType.RAM }).createDirectory(),\n private readonly _options?: HypercoreOptions,\n ) {\n invariant(this._root);\n }\n\n /**\n * Creates a feed using a storage factory prefixed with the feed's key.\n * NOTE: We have to use our `random-access-storage` implementation since the native ones\n * do not behave uniformly across platforms.\n */\n createFeed(publicKey: Buffer, options?: HypercoreOptions): Hypercore<T> {\n const directory = this._root.createDirectory(publicKey.toString('hex'));\n const storage = (filename: string) => directory.getOrCreateFile(filename).native;\n return hypercore(storage, publicKey, Object.assign({}, this._options, options));\n }\n\n /**\n * Creates and opens a feed.\n */\n async openFeed(publicKey: Buffer, options?: HypercoreOptions): Promise<Hypercore<T>> {\n const feed = this.createFeed(publicKey, options);\n await py(feed, feed.open)(); // TODO(burdon): Sometimes strange bug if done inside function.\n return feed;\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport util from 'node:util';\n\nexport const py = (obj: any, fn: Function) => util.promisify(fn.bind(obj));\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Readable } from 'readable-stream';\nimport { type Readable as StreamXReadable } from 'streamx';\n\n/**\n * Wraps streamx.Readable (hypercore.createReadStream) to a standard Readable stream.\n *\n * The read-stream package is mirror of the streams implementations in Node.js 18.9.0.\n * This function is here to standardize the cast in case there are incompatibilities\n * across different platforms.\n *\n * Hypercore createReadStream returns a `streamx` Readable, which does not close properly on destroy.\n *\n * https://github.com/nodejs/readable-stream\n * https://nodejs.org/api/stream.html#readable-streams\n * https://nodejs.org/dist/v18.9.0/docs/api/stream.html#readablewrapstream\n */\nexport const createReadable = (stream: StreamXReadable): Readable => {\n return new Readable({ objectMode: true }).wrap(stream as any);\n};\n\n/**\n * Converts streamx.Readable (hypercore.createReadStream) to an async iterator.\n *\n * https://github.com/tc39/proposal-async-iteration\n * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#async-iteration\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\n */\nexport const createAsyncIterator = (stream: Readable): AsyncIterator<any> => {\n return stream[Symbol.asyncIterator]();\n};\n"],
5
- "mappings": ";AAIA,SAAoBA,WAAXC,gBAA4B;;;ACArC,SAASC,mBAAmB;AAG5B,SAAsBC,uBAAuB;AAC7C,SAASC,iBAAiB;AAE1B,SAASC,qBAAqB;;AAMvB,IAAMC,sBAAsB,CAAIC,OAAiBC,UAAsD;EAC5GC,QAAQ,CAACC,QAAWL,cAAcE,MAAME,OAAOC,KAAKF,IAAAA,CAAAA;EACpDG,QAAQ,CAACC,WAAmBL,MAAMI,OAAOC,QAAQJ,IAAAA;AACnD;AAMO,IAAMK,eAAe,CAACC,QAAgBC,cAAAA;AAC3CX,YAAUU,QAAAA,QAAAA;;;;;;;;;AACVV,YAAUW,WAAAA,QAAAA;;;;;;;;;AAEV,SAAO;IACLC,MAAM,CAACC,SAASC,WAAWC,OAAAA;AACzBjB,kBAAYY,OAAOE,KAAKI,KAAKN,MAAAA,CAAAA,EAAUC,WAAWE,SAAS,CAACI,KAAKC,WAAAA;AAC/D,YAAID,KAAK;AACPF,aAAGE,KAAK,IAAA;AACR;QACF;AAEAF,WAAG,MAAMd,cAAciB,MAAAA,CAAAA;MACzB,CAAA;IACF;IAEAC,QAAQ,OAAON,SAASO,WAAWC,KAAKN,OAAAA;AAEtCjB,kBAAYC,eAAAA,EAAiBY,WAAWE,SAASO,WAAWL,EAAAA;IAC9D;EACF;AACF;;;AChCO,IAAMO,qBAAuC;EAClDC,iBAAiB;EACjBC,eAAe;AACjB;AAKO,IAAMC,2BAA8C;EACzDC,OAAO;EACPC,KAAKC;EACLC,UAAU;EACVC,MAAM;EACNC,MAAM;EACNC,SAAS;EACTC,MAAM;EACNC,OAAO;AACT;AAKO,IAAMC,4BAAgD;EAC3DC,cAAcR;AAChB;AAKO,IAAMS,0BAA8C;EACzDN,MAAM;EACNO,KAAK;EACLC,UAAU;EACVC,QAAQ;EACRC,WAAW;EACXC,OAAO;AACT;;;AC9CA,SAASC,aAAAA,kBAAiB;AAC1B,SAAyBC,aAAaC,qBAAqB;AAC3D,OAAOC,eAAe;;;ACFtB,OAAOC,UAAU;AAEV,IAAMC,KAAK,CAACC,KAAUC,OAAiBC,KAAKC,UAAUF,GAAGG,KAAKJ,GAAAA,CAAAA;;;;ADQ9D,IAAMK,mBAAN,MAAMA;;;EACX,YACmBC,QAAmBC,cAAc;IAAEC,MAAMC,YAAYC;EAAI,CAAA,EAAGC,gBAAe,GAC3EC,UACjB;SAFiBN,QAAAA;SACAM,WAAAA;AAEjBC,IAAAA,WAAU,KAAKP,OAAK,QAAA;;;;;;;;;EACtB;;;;;;EAOAQ,WAAWC,WAAmBC,SAA0C;AACtE,UAAMC,YAAY,KAAKX,MAAMK,gBAAgBI,UAAUG,SAAS,KAAA,CAAA;AAChE,UAAMC,UAAU,CAACC,aAAqBH,UAAUI,gBAAgBD,QAAAA,EAAUE;AAC1E,WAAOC,UAAUJ,SAASJ,WAAWS,OAAOC,OAAO,CAAC,GAAG,KAAKb,UAAUI,OAAAA,CAAAA;EACxE;;;;EAKA,MAAMU,SAASX,WAAmBC,SAAmD;AACnF,UAAMW,OAAO,KAAKb,WAAWC,WAAWC,OAAAA;AACxC,UAAMY,GAAGD,MAAMA,KAAKE,IAAI,EAAA;AACxB,WAAOF;EACT;AACF;;;AErCA,SAASG,gBAAgB;AAgBlB,IAAMC,iBAAiB,CAACC,WAAAA;AAC7B,SAAO,IAAIC,SAAS;IAAEC,YAAY;EAAK,CAAA,EAAGC,KAAKH,MAAAA;AACjD;AAUO,IAAMI,sBAAsB,CAACJ,WAAAA;AAClC,SAAOA,OAAOK,OAAOC,aAAa,EAAC;AACrC;",
6
- "names": ["hypercore", "default", "callbackify", "verifySignature", "invariant", "arrayToBuffer", "createCodecEncoding", "codec", "opts", "encode", "obj", "decode", "buffer", "createCrypto", "signer", "publicKey", "sign", "message", "secretKey", "cb", "bind", "err", "result", "verify", "signature", "key", "defaultFeedOptions", "createIfMissing", "valueEncoding", "defaultReadStreamOptions", "start", "end", "Infinity", "snapshot", "tail", "live", "timeout", "wait", "batch", "defaultWriteStreamOptions", "maxBlockSize", "defaultReplicateOptions", "ack", "download", "upload", "encrypted", "noise", "invariant", "StorageType", "createStorage", "hypercore", "util", "py", "obj", "fn", "util", "promisify", "bind", "HypercoreFactory", "_root", "createStorage", "type", "StorageType", "RAM", "createDirectory", "_options", "invariant", "createFeed", "publicKey", "options", "directory", "toString", "storage", "filename", "getOrCreateFile", "native", "hypercore", "Object", "assign", "openFeed", "feed", "py", "open", "Readable", "createReadable", "stream", "Readable", "objectMode", "wrap", "createAsyncIterator", "Symbol", "asyncIterator"]
4
+ "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nexport { default as hypercore } from '@dxos/vendor-hypercore/hypercore';\nexport type {\n Hypercore,\n HypercoreOptions,\n HypercoreProperties,\n ReadStreamOptions,\n} from '@dxos/vendor-hypercore/hypercore';\n\nexport * from './crypto';\nexport * from './defaults';\nexport * from './hypercore-factory';\nexport * from './iterator';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { callbackify } from 'node:util';\n\nimport { type Codec, type EncodingOptions } from '@dxos/codec-protobuf';\nimport { type Signer, verifySignature } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { type PublicKey } from '@dxos/keys';\nimport { arrayToBuffer } from '@dxos/util';\nimport { type AbstractValueEncoding, type Crypto } from '@dxos/vendor-hypercore/hypercore';\n\n/**\n * Create encoding (e.g., from protobuf codec).\n */\nexport const createCodecEncoding = <T>(codec: Codec<T>, opts?: EncodingOptions): AbstractValueEncoding<T> => ({\n encode: (obj: T) => arrayToBuffer(codec.encode(obj, opts)),\n decode: (buffer: Buffer) => codec.decode(buffer, opts),\n});\n\n/**\n * Create a custom hypercore crypto signer.\n */\n// TODO(burdon): Create test without adding deps.\nexport const createCrypto = (signer: Signer, publicKey: PublicKey): Crypto => {\n invariant(signer);\n invariant(publicKey);\n\n return {\n sign: (message, secretKey, cb) => {\n callbackify(signer.sign.bind(signer!))(publicKey, message, (err, result) => {\n if (err) {\n cb(err, null);\n return;\n }\n\n cb(null, arrayToBuffer(result));\n });\n },\n\n verify: async (message, signature, key, cb) => {\n // NOTE: Uses the public key passed into function.\n callbackify(verifySignature)(publicKey, message, signature, cb);\n },\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport type {\n HypercoreOptions,\n ReadStreamOptions,\n ReplicationOptions,\n WriteStreamOptions,\n} from '@dxos/vendor-hypercore/hypercore';\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-feed--hypercorestorage-key-options\n */\nexport const defaultFeedOptions: HypercoreOptions = {\n createIfMissing: true,\n valueEncoding: 'binary',\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatereadstreamoptions\n */\nexport const defaultReadStreamOptions: ReadStreamOptions = {\n start: 0,\n end: Infinity,\n snapshot: true,\n tail: false,\n live: false,\n timeout: 0,\n wait: true,\n batch: 1,\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatewritestreamopts\n */\nexport const defaultWriteStreamOptions: WriteStreamOptions = {\n maxBlockSize: Infinity,\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options\n */\nexport const defaultReplicateOptions: ReplicationOptions = {\n live: false,\n ack: false,\n download: true,\n upload: true,\n encrypted: true,\n noise: true,\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { type Directory, StorageType, createStorage } from '@dxos/random-access-storage';\nimport hypercore from '@dxos/vendor-hypercore/hypercore';\nimport type { Hypercore, HypercoreOptions } from '@dxos/vendor-hypercore/hypercore';\n\nimport { py } from './util';\n\n/**\n * Creates feeds with default properties.\n */\nexport class HypercoreFactory<T> {\n constructor(\n private readonly _root: Directory = createStorage({ type: StorageType.RAM }).createDirectory(),\n private readonly _options?: HypercoreOptions,\n ) {\n invariant(this._root);\n }\n\n /**\n * Creates a feed using a storage factory prefixed with the feed's key.\n * NOTE: We have to use our `random-access-storage` implementation since the native ones\n * do not behave uniformly across platforms.\n */\n createFeed(publicKey: Buffer, options?: HypercoreOptions): Hypercore<T> {\n const directory = this._root.createDirectory(publicKey.toString('hex'));\n const storage = (filename: string) => directory.getOrCreateFile(filename).native;\n return hypercore(storage, publicKey, Object.assign({}, this._options, options));\n }\n\n /**\n * Creates and opens a feed.\n */\n async openFeed(publicKey: Buffer, options?: HypercoreOptions): Promise<Hypercore<T>> {\n const feed = this.createFeed(publicKey, options);\n await py(feed, feed.open)(); // TODO(burdon): Sometimes strange bug if done inside function.\n return feed;\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { promisify } from 'node:util';\n\nexport const py = (obj: any, fn: Function) => promisify(fn.bind(obj));\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Readable } from 'readable-stream';\nimport { type Readable as StreamXReadable } from 'streamx';\n\n/**\n * Wraps streamx.Readable (hypercore.createReadStream) to a standard Readable stream.\n *\n * The read-stream package is mirror of the streams implementations in Node.js 18.9.0.\n * This function is here to standardize the cast in case there are incompatibilities\n * across different platforms.\n *\n * Hypercore createReadStream returns a `streamx` Readable, which does not close properly on destroy.\n *\n * https://github.com/nodejs/readable-stream\n * https://nodejs.org/api/stream.html#readable-streams\n * https://nodejs.org/dist/v18.9.0/docs/api/stream.html#readablewrapstream\n */\nexport const createReadable = (stream: StreamXReadable): Readable => {\n return new Readable({ objectMode: true }).wrap(stream as any);\n};\n\n/**\n * Converts streamx.Readable (hypercore.createReadStream) to an async iterator.\n *\n * https://github.com/tc39/proposal-async-iteration\n * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#async-iteration\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\n */\nexport const createAsyncIterator = (stream: Readable): AsyncIterator<any> => {\n return stream[Symbol.asyncIterator]();\n};\n"],
5
+ "mappings": ";AAIA,SAAoBA,WAAXC,gBAA4B;;;ACArC,SAASC,mBAAmB;AAG5B,SAAsBC,uBAAuB;AAC7C,SAASC,iBAAiB;AAE1B,SAASC,qBAAqB;;AAMvB,IAAMC,sBAAsB,CAAIC,OAAiBC,UAAsD;EAC5GC,QAAQ,CAACC,QAAWL,cAAcE,MAAME,OAAOC,KAAKF,IAAAA,CAAAA;EACpDG,QAAQ,CAACC,WAAmBL,MAAMI,OAAOC,QAAQJ,IAAAA;AACnD;AAMO,IAAMK,eAAe,CAACC,QAAgBC,cAAAA;AAC3CX,YAAUU,QAAAA,QAAAA;;;;;;;;;AACVV,YAAUW,WAAAA,QAAAA;;;;;;;;;AAEV,SAAO;IACLC,MAAM,CAACC,SAASC,WAAWC,OAAAA;AACzBjB,kBAAYY,OAAOE,KAAKI,KAAKN,MAAAA,CAAAA,EAAUC,WAAWE,SAAS,CAACI,KAAKC,WAAAA;AAC/D,YAAID,KAAK;AACPF,aAAGE,KAAK,IAAA;AACR;QACF;AAEAF,WAAG,MAAMd,cAAciB,MAAAA,CAAAA;MACzB,CAAA;IACF;IAEAC,QAAQ,OAAON,SAASO,WAAWC,KAAKN,OAAAA;AAEtCjB,kBAAYC,eAAAA,EAAiBY,WAAWE,SAASO,WAAWL,EAAAA;IAC9D;EACF;AACF;;;AChCO,IAAMO,qBAAuC;EAClDC,iBAAiB;EACjBC,eAAe;AACjB;AAKO,IAAMC,2BAA8C;EACzDC,OAAO;EACPC,KAAKC;EACLC,UAAU;EACVC,MAAM;EACNC,MAAM;EACNC,SAAS;EACTC,MAAM;EACNC,OAAO;AACT;AAKO,IAAMC,4BAAgD;EAC3DC,cAAcR;AAChB;AAKO,IAAMS,0BAA8C;EACzDN,MAAM;EACNO,KAAK;EACLC,UAAU;EACVC,QAAQ;EACRC,WAAW;EACXC,OAAO;AACT;;;AC9CA,SAASC,aAAAA,kBAAiB;AAC1B,SAAyBC,aAAaC,qBAAqB;AAC3D,OAAOC,eAAe;;;ACFtB,SAASC,iBAAiB;AAEnB,IAAMC,KAAK,CAACC,KAAUC,OAAiBC,UAAUD,GAAGE,KAAKH,GAAAA,CAAAA;;;;ADQzD,IAAMI,mBAAN,MAAMA;;;EACX,YACmBC,QAAmBC,cAAc;IAAEC,MAAMC,YAAYC;EAAI,CAAA,EAAGC,gBAAe,GAC3EC,UACjB;SAFiBN,QAAAA;SACAM,WAAAA;AAEjBC,IAAAA,WAAU,KAAKP,OAAK,QAAA;;;;;;;;;EACtB;;;;;;EAOAQ,WAAWC,WAAmBC,SAA0C;AACtE,UAAMC,YAAY,KAAKX,MAAMK,gBAAgBI,UAAUG,SAAS,KAAA,CAAA;AAChE,UAAMC,UAAU,CAACC,aAAqBH,UAAUI,gBAAgBD,QAAAA,EAAUE;AAC1E,WAAOC,UAAUJ,SAASJ,WAAWS,OAAOC,OAAO,CAAC,GAAG,KAAKb,UAAUI,OAAAA,CAAAA;EACxE;;;;EAKA,MAAMU,SAASX,WAAmBC,SAAmD;AACnF,UAAMW,OAAO,KAAKb,WAAWC,WAAWC,OAAAA;AACxC,UAAMY,GAAGD,MAAMA,KAAKE,IAAI,EAAA;AACxB,WAAOF;EACT;AACF;;;AErCA,SAASG,gBAAgB;AAgBlB,IAAMC,iBAAiB,CAACC,WAAAA;AAC7B,SAAO,IAAIC,SAAS;IAAEC,YAAY;EAAK,CAAA,EAAGC,KAAKH,MAAAA;AACjD;AAUO,IAAMI,sBAAsB,CAACJ,WAAAA;AAClC,SAAOA,OAAOK,OAAOC,aAAa,EAAC;AACrC;",
6
+ "names": ["hypercore", "default", "callbackify", "verifySignature", "invariant", "arrayToBuffer", "createCodecEncoding", "codec", "opts", "encode", "obj", "decode", "buffer", "createCrypto", "signer", "publicKey", "sign", "message", "secretKey", "cb", "bind", "err", "result", "verify", "signature", "key", "defaultFeedOptions", "createIfMissing", "valueEncoding", "defaultReadStreamOptions", "start", "end", "Infinity", "snapshot", "tail", "live", "timeout", "wait", "batch", "defaultWriteStreamOptions", "maxBlockSize", "defaultReplicateOptions", "ack", "download", "upload", "encrypted", "noise", "invariant", "StorageType", "createStorage", "hypercore", "promisify", "py", "obj", "fn", "promisify", "bind", "HypercoreFactory", "_root", "createStorage", "type", "StorageType", "RAM", "createDirectory", "_options", "invariant", "createFeed", "publicKey", "options", "directory", "toString", "storage", "filename", "getOrCreateFile", "native", "hypercore", "Object", "assign", "openFeed", "feed", "py", "open", "Readable", "createReadable", "stream", "Readable", "objectMode", "wrap", "createAsyncIterator", "Symbol", "asyncIterator"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/crypto.ts":{"bytes":4950,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/defaults.ts":{"bytes":3761,"imports":[],"format":"esm"},"src/util.ts":{"bytes":788,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"src/hypercore-factory.ts":{"bytes":5214,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"src/iterator.ts":{"bytes":3956,"imports":[{"path":"readable-stream","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":1172,"imports":[{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"src/crypto.ts","kind":"import-statement","original":"./crypto"},{"path":"src/defaults.ts","kind":"import-statement","original":"./defaults"},{"path":"src/hypercore-factory.ts","kind":"import-statement","original":"./hypercore-factory"},{"path":"src/iterator.ts","kind":"import-statement","original":"./iterator"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9475},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"readable-stream","kind":"import-statement","external":true}],"exports":["HypercoreFactory","createAsyncIterator","createCodecEncoding","createCrypto","createReadable","defaultFeedOptions","defaultReadStreamOptions","defaultReplicateOptions","defaultWriteStreamOptions","hypercore"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":72},"src/crypto.ts":{"bytesInOutput":1121},"src/defaults.ts":{"bytesInOutput":426},"src/hypercore-factory.ts":{"bytesInOutput":1329},"src/util.ts":{"bytesInOutput":92},"src/iterator.ts":{"bytesInOutput":230}},"bytes":3695}}}
1
+ {"inputs":{"src/crypto.ts":{"bytes":4950,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/defaults.ts":{"bytes":3761,"imports":[],"format":"esm"},"src/util.ts":{"bytes":780,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"src/hypercore-factory.ts":{"bytes":5214,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"src/iterator.ts":{"bytes":3956,"imports":[{"path":"readable-stream","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":1172,"imports":[{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"src/crypto.ts","kind":"import-statement","original":"./crypto"},{"path":"src/defaults.ts","kind":"import-statement","original":"./defaults"},{"path":"src/hypercore-factory.ts","kind":"import-statement","original":"./hypercore-factory"},{"path":"src/iterator.ts","kind":"import-statement","original":"./iterator"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9473},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"readable-stream","kind":"import-statement","external":true}],"exports":["HypercoreFactory","createAsyncIterator","createCodecEncoding","createCrypto","createReadable","defaultFeedOptions","defaultReadStreamOptions","defaultReplicateOptions","defaultWriteStreamOptions","hypercore"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":72},"src/crypto.ts":{"bytesInOutput":1121},"src/defaults.ts":{"bytesInOutput":426},"src/hypercore-factory.ts":{"bytesInOutput":1329},"src/util.ts":{"bytesInOutput":96},"src/iterator.ts":{"bytesInOutput":230}},"bytes":3699}}}
@@ -81,8 +81,8 @@ import { StorageType, createStorage } from "@dxos/random-access-storage";
81
81
  import hypercore from "@dxos/vendor-hypercore/hypercore";
82
82
 
83
83
  // src/util.ts
84
- import util from "node:util";
85
- var py = (obj, fn) => util.promisify(fn.bind(obj));
84
+ import { promisify } from "node:util";
85
+ var py = (obj, fn) => promisify(fn.bind(obj));
86
86
 
87
87
  // src/hypercore-factory.ts
88
88
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/hypercore/src/hypercore-factory.ts";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/crypto.ts", "../../../src/defaults.ts", "../../../src/hypercore-factory.ts", "../../../src/util.ts", "../../../src/iterator.ts"],
4
- "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nexport { default as hypercore } from '@dxos/vendor-hypercore/hypercore';\nexport type {\n Hypercore,\n HypercoreOptions,\n HypercoreProperties,\n ReadStreamOptions,\n} from '@dxos/vendor-hypercore/hypercore';\n\nexport * from './crypto';\nexport * from './defaults';\nexport * from './hypercore-factory';\nexport * from './iterator';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { callbackify } from 'node:util';\n\nimport { type Codec, type EncodingOptions } from '@dxos/codec-protobuf';\nimport { type Signer, verifySignature } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { type PublicKey } from '@dxos/keys';\nimport { arrayToBuffer } from '@dxos/util';\nimport { type AbstractValueEncoding, type Crypto } from '@dxos/vendor-hypercore/hypercore';\n\n/**\n * Create encoding (e.g., from protobuf codec).\n */\nexport const createCodecEncoding = <T>(codec: Codec<T>, opts?: EncodingOptions): AbstractValueEncoding<T> => ({\n encode: (obj: T) => arrayToBuffer(codec.encode(obj, opts)),\n decode: (buffer: Buffer) => codec.decode(buffer, opts),\n});\n\n/**\n * Create a custom hypercore crypto signer.\n */\n// TODO(burdon): Create test without adding deps.\nexport const createCrypto = (signer: Signer, publicKey: PublicKey): Crypto => {\n invariant(signer);\n invariant(publicKey);\n\n return {\n sign: (message, secretKey, cb) => {\n callbackify(signer.sign.bind(signer!))(publicKey, message, (err, result) => {\n if (err) {\n cb(err, null);\n return;\n }\n\n cb(null, arrayToBuffer(result));\n });\n },\n\n verify: async (message, signature, key, cb) => {\n // NOTE: Uses the public key passed into function.\n callbackify(verifySignature)(publicKey, message, signature, cb);\n },\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport type {\n HypercoreOptions,\n ReadStreamOptions,\n ReplicationOptions,\n WriteStreamOptions,\n} from '@dxos/vendor-hypercore/hypercore';\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-feed--hypercorestorage-key-options\n */\nexport const defaultFeedOptions: HypercoreOptions = {\n createIfMissing: true,\n valueEncoding: 'binary',\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatereadstreamoptions\n */\nexport const defaultReadStreamOptions: ReadStreamOptions = {\n start: 0,\n end: Infinity,\n snapshot: true,\n tail: false,\n live: false,\n timeout: 0,\n wait: true,\n batch: 1,\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatewritestreamopts\n */\nexport const defaultWriteStreamOptions: WriteStreamOptions = {\n maxBlockSize: Infinity,\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options\n */\nexport const defaultReplicateOptions: ReplicationOptions = {\n live: false,\n ack: false,\n download: true,\n upload: true,\n encrypted: true,\n noise: true,\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { type Directory, StorageType, createStorage } from '@dxos/random-access-storage';\nimport hypercore from '@dxos/vendor-hypercore/hypercore';\nimport type { Hypercore, HypercoreOptions } from '@dxos/vendor-hypercore/hypercore';\n\nimport { py } from './util';\n\n/**\n * Creates feeds with default properties.\n */\nexport class HypercoreFactory<T> {\n constructor(\n private readonly _root: Directory = createStorage({ type: StorageType.RAM }).createDirectory(),\n private readonly _options?: HypercoreOptions,\n ) {\n invariant(this._root);\n }\n\n /**\n * Creates a feed using a storage factory prefixed with the feed's key.\n * NOTE: We have to use our `random-access-storage` implementation since the native ones\n * do not behave uniformly across platforms.\n */\n createFeed(publicKey: Buffer, options?: HypercoreOptions): Hypercore<T> {\n const directory = this._root.createDirectory(publicKey.toString('hex'));\n const storage = (filename: string) => directory.getOrCreateFile(filename).native;\n return hypercore(storage, publicKey, Object.assign({}, this._options, options));\n }\n\n /**\n * Creates and opens a feed.\n */\n async openFeed(publicKey: Buffer, options?: HypercoreOptions): Promise<Hypercore<T>> {\n const feed = this.createFeed(publicKey, options);\n await py(feed, feed.open)(); // TODO(burdon): Sometimes strange bug if done inside function.\n return feed;\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport util from 'node:util';\n\nexport const py = (obj: any, fn: Function) => util.promisify(fn.bind(obj));\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Readable } from 'readable-stream';\nimport { type Readable as StreamXReadable } from 'streamx';\n\n/**\n * Wraps streamx.Readable (hypercore.createReadStream) to a standard Readable stream.\n *\n * The read-stream package is mirror of the streams implementations in Node.js 18.9.0.\n * This function is here to standardize the cast in case there are incompatibilities\n * across different platforms.\n *\n * Hypercore createReadStream returns a `streamx` Readable, which does not close properly on destroy.\n *\n * https://github.com/nodejs/readable-stream\n * https://nodejs.org/api/stream.html#readable-streams\n * https://nodejs.org/dist/v18.9.0/docs/api/stream.html#readablewrapstream\n */\nexport const createReadable = (stream: StreamXReadable): Readable => {\n return new Readable({ objectMode: true }).wrap(stream as any);\n};\n\n/**\n * Converts streamx.Readable (hypercore.createReadStream) to an async iterator.\n *\n * https://github.com/tc39/proposal-async-iteration\n * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#async-iteration\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\n */\nexport const createAsyncIterator = (stream: Readable): AsyncIterator<any> => {\n return stream[Symbol.asyncIterator]();\n};\n"],
5
- "mappings": ";;;AAIA,SAAoBA,WAAXC,gBAA4B;;;ACArC,SAASC,mBAAmB;AAG5B,SAAsBC,uBAAuB;AAC7C,SAASC,iBAAiB;AAE1B,SAASC,qBAAqB;;AAMvB,IAAMC,sBAAsB,CAAIC,OAAiBC,UAAsD;EAC5GC,QAAQ,CAACC,QAAWL,cAAcE,MAAME,OAAOC,KAAKF,IAAAA,CAAAA;EACpDG,QAAQ,CAACC,WAAmBL,MAAMI,OAAOC,QAAQJ,IAAAA;AACnD;AAMO,IAAMK,eAAe,CAACC,QAAgBC,cAAAA;AAC3CX,YAAUU,QAAAA,QAAAA;;;;;;;;;AACVV,YAAUW,WAAAA,QAAAA;;;;;;;;;AAEV,SAAO;IACLC,MAAM,CAACC,SAASC,WAAWC,OAAAA;AACzBjB,kBAAYY,OAAOE,KAAKI,KAAKN,MAAAA,CAAAA,EAAUC,WAAWE,SAAS,CAACI,KAAKC,WAAAA;AAC/D,YAAID,KAAK;AACPF,aAAGE,KAAK,IAAA;AACR;QACF;AAEAF,WAAG,MAAMd,cAAciB,MAAAA,CAAAA;MACzB,CAAA;IACF;IAEAC,QAAQ,OAAON,SAASO,WAAWC,KAAKN,OAAAA;AAEtCjB,kBAAYC,eAAAA,EAAiBY,WAAWE,SAASO,WAAWL,EAAAA;IAC9D;EACF;AACF;;;AChCO,IAAMO,qBAAuC;EAClDC,iBAAiB;EACjBC,eAAe;AACjB;AAKO,IAAMC,2BAA8C;EACzDC,OAAO;EACPC,KAAKC;EACLC,UAAU;EACVC,MAAM;EACNC,MAAM;EACNC,SAAS;EACTC,MAAM;EACNC,OAAO;AACT;AAKO,IAAMC,4BAAgD;EAC3DC,cAAcR;AAChB;AAKO,IAAMS,0BAA8C;EACzDN,MAAM;EACNO,KAAK;EACLC,UAAU;EACVC,QAAQ;EACRC,WAAW;EACXC,OAAO;AACT;;;AC9CA,SAASC,aAAAA,kBAAiB;AAC1B,SAAyBC,aAAaC,qBAAqB;AAC3D,OAAOC,eAAe;;;ACFtB,OAAOC,UAAU;AAEV,IAAMC,KAAK,CAACC,KAAUC,OAAiBC,KAAKC,UAAUF,GAAGG,KAAKJ,GAAAA,CAAAA;;;;ADQ9D,IAAMK,mBAAN,MAAMA;;;EACX,YACmBC,QAAmBC,cAAc;IAAEC,MAAMC,YAAYC;EAAI,CAAA,EAAGC,gBAAe,GAC3EC,UACjB;SAFiBN,QAAAA;SACAM,WAAAA;AAEjBC,IAAAA,WAAU,KAAKP,OAAK,QAAA;;;;;;;;;EACtB;;;;;;EAOAQ,WAAWC,WAAmBC,SAA0C;AACtE,UAAMC,YAAY,KAAKX,MAAMK,gBAAgBI,UAAUG,SAAS,KAAA,CAAA;AAChE,UAAMC,UAAU,CAACC,aAAqBH,UAAUI,gBAAgBD,QAAAA,EAAUE;AAC1E,WAAOC,UAAUJ,SAASJ,WAAWS,OAAOC,OAAO,CAAC,GAAG,KAAKb,UAAUI,OAAAA,CAAAA;EACxE;;;;EAKA,MAAMU,SAASX,WAAmBC,SAAmD;AACnF,UAAMW,OAAO,KAAKb,WAAWC,WAAWC,OAAAA;AACxC,UAAMY,GAAGD,MAAMA,KAAKE,IAAI,EAAA;AACxB,WAAOF;EACT;AACF;;;AErCA,SAASG,gBAAgB;AAgBlB,IAAMC,iBAAiB,CAACC,WAAAA;AAC7B,SAAO,IAAIC,SAAS;IAAEC,YAAY;EAAK,CAAA,EAAGC,KAAKH,MAAAA;AACjD;AAUO,IAAMI,sBAAsB,CAACJ,WAAAA;AAClC,SAAOA,OAAOK,OAAOC,aAAa,EAAC;AACrC;",
6
- "names": ["hypercore", "default", "callbackify", "verifySignature", "invariant", "arrayToBuffer", "createCodecEncoding", "codec", "opts", "encode", "obj", "decode", "buffer", "createCrypto", "signer", "publicKey", "sign", "message", "secretKey", "cb", "bind", "err", "result", "verify", "signature", "key", "defaultFeedOptions", "createIfMissing", "valueEncoding", "defaultReadStreamOptions", "start", "end", "Infinity", "snapshot", "tail", "live", "timeout", "wait", "batch", "defaultWriteStreamOptions", "maxBlockSize", "defaultReplicateOptions", "ack", "download", "upload", "encrypted", "noise", "invariant", "StorageType", "createStorage", "hypercore", "util", "py", "obj", "fn", "util", "promisify", "bind", "HypercoreFactory", "_root", "createStorage", "type", "StorageType", "RAM", "createDirectory", "_options", "invariant", "createFeed", "publicKey", "options", "directory", "toString", "storage", "filename", "getOrCreateFile", "native", "hypercore", "Object", "assign", "openFeed", "feed", "py", "open", "Readable", "createReadable", "stream", "Readable", "objectMode", "wrap", "createAsyncIterator", "Symbol", "asyncIterator"]
4
+ "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nexport { default as hypercore } from '@dxos/vendor-hypercore/hypercore';\nexport type {\n Hypercore,\n HypercoreOptions,\n HypercoreProperties,\n ReadStreamOptions,\n} from '@dxos/vendor-hypercore/hypercore';\n\nexport * from './crypto';\nexport * from './defaults';\nexport * from './hypercore-factory';\nexport * from './iterator';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { callbackify } from 'node:util';\n\nimport { type Codec, type EncodingOptions } from '@dxos/codec-protobuf';\nimport { type Signer, verifySignature } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { type PublicKey } from '@dxos/keys';\nimport { arrayToBuffer } from '@dxos/util';\nimport { type AbstractValueEncoding, type Crypto } from '@dxos/vendor-hypercore/hypercore';\n\n/**\n * Create encoding (e.g., from protobuf codec).\n */\nexport const createCodecEncoding = <T>(codec: Codec<T>, opts?: EncodingOptions): AbstractValueEncoding<T> => ({\n encode: (obj: T) => arrayToBuffer(codec.encode(obj, opts)),\n decode: (buffer: Buffer) => codec.decode(buffer, opts),\n});\n\n/**\n * Create a custom hypercore crypto signer.\n */\n// TODO(burdon): Create test without adding deps.\nexport const createCrypto = (signer: Signer, publicKey: PublicKey): Crypto => {\n invariant(signer);\n invariant(publicKey);\n\n return {\n sign: (message, secretKey, cb) => {\n callbackify(signer.sign.bind(signer!))(publicKey, message, (err, result) => {\n if (err) {\n cb(err, null);\n return;\n }\n\n cb(null, arrayToBuffer(result));\n });\n },\n\n verify: async (message, signature, key, cb) => {\n // NOTE: Uses the public key passed into function.\n callbackify(verifySignature)(publicKey, message, signature, cb);\n },\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport type {\n HypercoreOptions,\n ReadStreamOptions,\n ReplicationOptions,\n WriteStreamOptions,\n} from '@dxos/vendor-hypercore/hypercore';\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-feed--hypercorestorage-key-options\n */\nexport const defaultFeedOptions: HypercoreOptions = {\n createIfMissing: true,\n valueEncoding: 'binary',\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatereadstreamoptions\n */\nexport const defaultReadStreamOptions: ReadStreamOptions = {\n start: 0,\n end: Infinity,\n snapshot: true,\n tail: false,\n live: false,\n timeout: 0,\n wait: true,\n batch: 1,\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatewritestreamopts\n */\nexport const defaultWriteStreamOptions: WriteStreamOptions = {\n maxBlockSize: Infinity,\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options\n */\nexport const defaultReplicateOptions: ReplicationOptions = {\n live: false,\n ack: false,\n download: true,\n upload: true,\n encrypted: true,\n noise: true,\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { type Directory, StorageType, createStorage } from '@dxos/random-access-storage';\nimport hypercore from '@dxos/vendor-hypercore/hypercore';\nimport type { Hypercore, HypercoreOptions } from '@dxos/vendor-hypercore/hypercore';\n\nimport { py } from './util';\n\n/**\n * Creates feeds with default properties.\n */\nexport class HypercoreFactory<T> {\n constructor(\n private readonly _root: Directory = createStorage({ type: StorageType.RAM }).createDirectory(),\n private readonly _options?: HypercoreOptions,\n ) {\n invariant(this._root);\n }\n\n /**\n * Creates a feed using a storage factory prefixed with the feed's key.\n * NOTE: We have to use our `random-access-storage` implementation since the native ones\n * do not behave uniformly across platforms.\n */\n createFeed(publicKey: Buffer, options?: HypercoreOptions): Hypercore<T> {\n const directory = this._root.createDirectory(publicKey.toString('hex'));\n const storage = (filename: string) => directory.getOrCreateFile(filename).native;\n return hypercore(storage, publicKey, Object.assign({}, this._options, options));\n }\n\n /**\n * Creates and opens a feed.\n */\n async openFeed(publicKey: Buffer, options?: HypercoreOptions): Promise<Hypercore<T>> {\n const feed = this.createFeed(publicKey, options);\n await py(feed, feed.open)(); // TODO(burdon): Sometimes strange bug if done inside function.\n return feed;\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { promisify } from 'node:util';\n\nexport const py = (obj: any, fn: Function) => promisify(fn.bind(obj));\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Readable } from 'readable-stream';\nimport { type Readable as StreamXReadable } from 'streamx';\n\n/**\n * Wraps streamx.Readable (hypercore.createReadStream) to a standard Readable stream.\n *\n * The read-stream package is mirror of the streams implementations in Node.js 18.9.0.\n * This function is here to standardize the cast in case there are incompatibilities\n * across different platforms.\n *\n * Hypercore createReadStream returns a `streamx` Readable, which does not close properly on destroy.\n *\n * https://github.com/nodejs/readable-stream\n * https://nodejs.org/api/stream.html#readable-streams\n * https://nodejs.org/dist/v18.9.0/docs/api/stream.html#readablewrapstream\n */\nexport const createReadable = (stream: StreamXReadable): Readable => {\n return new Readable({ objectMode: true }).wrap(stream as any);\n};\n\n/**\n * Converts streamx.Readable (hypercore.createReadStream) to an async iterator.\n *\n * https://github.com/tc39/proposal-async-iteration\n * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#async-iteration\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\n */\nexport const createAsyncIterator = (stream: Readable): AsyncIterator<any> => {\n return stream[Symbol.asyncIterator]();\n};\n"],
5
+ "mappings": ";;;AAIA,SAAoBA,WAAXC,gBAA4B;;;ACArC,SAASC,mBAAmB;AAG5B,SAAsBC,uBAAuB;AAC7C,SAASC,iBAAiB;AAE1B,SAASC,qBAAqB;;AAMvB,IAAMC,sBAAsB,CAAIC,OAAiBC,UAAsD;EAC5GC,QAAQ,CAACC,QAAWL,cAAcE,MAAME,OAAOC,KAAKF,IAAAA,CAAAA;EACpDG,QAAQ,CAACC,WAAmBL,MAAMI,OAAOC,QAAQJ,IAAAA;AACnD;AAMO,IAAMK,eAAe,CAACC,QAAgBC,cAAAA;AAC3CX,YAAUU,QAAAA,QAAAA;;;;;;;;;AACVV,YAAUW,WAAAA,QAAAA;;;;;;;;;AAEV,SAAO;IACLC,MAAM,CAACC,SAASC,WAAWC,OAAAA;AACzBjB,kBAAYY,OAAOE,KAAKI,KAAKN,MAAAA,CAAAA,EAAUC,WAAWE,SAAS,CAACI,KAAKC,WAAAA;AAC/D,YAAID,KAAK;AACPF,aAAGE,KAAK,IAAA;AACR;QACF;AAEAF,WAAG,MAAMd,cAAciB,MAAAA,CAAAA;MACzB,CAAA;IACF;IAEAC,QAAQ,OAAON,SAASO,WAAWC,KAAKN,OAAAA;AAEtCjB,kBAAYC,eAAAA,EAAiBY,WAAWE,SAASO,WAAWL,EAAAA;IAC9D;EACF;AACF;;;AChCO,IAAMO,qBAAuC;EAClDC,iBAAiB;EACjBC,eAAe;AACjB;AAKO,IAAMC,2BAA8C;EACzDC,OAAO;EACPC,KAAKC;EACLC,UAAU;EACVC,MAAM;EACNC,MAAM;EACNC,SAAS;EACTC,MAAM;EACNC,OAAO;AACT;AAKO,IAAMC,4BAAgD;EAC3DC,cAAcR;AAChB;AAKO,IAAMS,0BAA8C;EACzDN,MAAM;EACNO,KAAK;EACLC,UAAU;EACVC,QAAQ;EACRC,WAAW;EACXC,OAAO;AACT;;;AC9CA,SAASC,aAAAA,kBAAiB;AAC1B,SAAyBC,aAAaC,qBAAqB;AAC3D,OAAOC,eAAe;;;ACFtB,SAASC,iBAAiB;AAEnB,IAAMC,KAAK,CAACC,KAAUC,OAAiBC,UAAUD,GAAGE,KAAKH,GAAAA,CAAAA;;;;ADQzD,IAAMI,mBAAN,MAAMA;;;EACX,YACmBC,QAAmBC,cAAc;IAAEC,MAAMC,YAAYC;EAAI,CAAA,EAAGC,gBAAe,GAC3EC,UACjB;SAFiBN,QAAAA;SACAM,WAAAA;AAEjBC,IAAAA,WAAU,KAAKP,OAAK,QAAA;;;;;;;;;EACtB;;;;;;EAOAQ,WAAWC,WAAmBC,SAA0C;AACtE,UAAMC,YAAY,KAAKX,MAAMK,gBAAgBI,UAAUG,SAAS,KAAA,CAAA;AAChE,UAAMC,UAAU,CAACC,aAAqBH,UAAUI,gBAAgBD,QAAAA,EAAUE;AAC1E,WAAOC,UAAUJ,SAASJ,WAAWS,OAAOC,OAAO,CAAC,GAAG,KAAKb,UAAUI,OAAAA,CAAAA;EACxE;;;;EAKA,MAAMU,SAASX,WAAmBC,SAAmD;AACnF,UAAMW,OAAO,KAAKb,WAAWC,WAAWC,OAAAA;AACxC,UAAMY,GAAGD,MAAMA,KAAKE,IAAI,EAAA;AACxB,WAAOF;EACT;AACF;;;AErCA,SAASG,gBAAgB;AAgBlB,IAAMC,iBAAiB,CAACC,WAAAA;AAC7B,SAAO,IAAIC,SAAS;IAAEC,YAAY;EAAK,CAAA,EAAGC,KAAKH,MAAAA;AACjD;AAUO,IAAMI,sBAAsB,CAACJ,WAAAA;AAClC,SAAOA,OAAOK,OAAOC,aAAa,EAAC;AACrC;",
6
+ "names": ["hypercore", "default", "callbackify", "verifySignature", "invariant", "arrayToBuffer", "createCodecEncoding", "codec", "opts", "encode", "obj", "decode", "buffer", "createCrypto", "signer", "publicKey", "sign", "message", "secretKey", "cb", "bind", "err", "result", "verify", "signature", "key", "defaultFeedOptions", "createIfMissing", "valueEncoding", "defaultReadStreamOptions", "start", "end", "Infinity", "snapshot", "tail", "live", "timeout", "wait", "batch", "defaultWriteStreamOptions", "maxBlockSize", "defaultReplicateOptions", "ack", "download", "upload", "encrypted", "noise", "invariant", "StorageType", "createStorage", "hypercore", "promisify", "py", "obj", "fn", "promisify", "bind", "HypercoreFactory", "_root", "createStorage", "type", "StorageType", "RAM", "createDirectory", "_options", "invariant", "createFeed", "publicKey", "options", "directory", "toString", "storage", "filename", "getOrCreateFile", "native", "hypercore", "Object", "assign", "openFeed", "feed", "py", "open", "Readable", "createReadable", "stream", "Readable", "objectMode", "wrap", "createAsyncIterator", "Symbol", "asyncIterator"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/crypto.ts":{"bytes":4950,"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/defaults.ts":{"bytes":3761,"imports":[],"format":"esm"},"src/util.ts":{"bytes":788,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"src/hypercore-factory.ts":{"bytes":5214,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"src/iterator.ts":{"bytes":3956,"imports":[{"path":"readable-stream","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":1172,"imports":[{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"src/crypto.ts","kind":"import-statement","original":"./crypto"},{"path":"src/defaults.ts","kind":"import-statement","original":"./defaults"},{"path":"src/hypercore-factory.ts","kind":"import-statement","original":"./hypercore-factory"},{"path":"src/iterator.ts","kind":"import-statement","original":"./iterator"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9477},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"readable-stream","kind":"import-statement","external":true}],"exports":["HypercoreFactory","createAsyncIterator","createCodecEncoding","createCrypto","createReadable","defaultFeedOptions","defaultReadStreamOptions","defaultReplicateOptions","defaultWriteStreamOptions","hypercore"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":72},"src/crypto.ts":{"bytesInOutput":1111},"src/defaults.ts":{"bytesInOutput":426},"src/hypercore-factory.ts":{"bytesInOutput":1329},"src/util.ts":{"bytesInOutput":82},"src/iterator.ts":{"bytesInOutput":230}},"bytes":3768}}}
1
+ {"inputs":{"src/crypto.ts":{"bytes":4950,"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/defaults.ts":{"bytes":3761,"imports":[],"format":"esm"},"src/util.ts":{"bytes":780,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"src/hypercore-factory.ts":{"bytes":5214,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"src/iterator.ts":{"bytes":3956,"imports":[{"path":"readable-stream","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":1172,"imports":[{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"src/crypto.ts","kind":"import-statement","original":"./crypto"},{"path":"src/defaults.ts","kind":"import-statement","original":"./defaults"},{"path":"src/hypercore-factory.ts","kind":"import-statement","original":"./hypercore-factory"},{"path":"src/iterator.ts","kind":"import-statement","original":"./iterator"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9475},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/vendor-hypercore/hypercore","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"readable-stream","kind":"import-statement","external":true}],"exports":["HypercoreFactory","createAsyncIterator","createCodecEncoding","createCrypto","createReadable","defaultFeedOptions","defaultReadStreamOptions","defaultReplicateOptions","defaultWriteStreamOptions","hypercore"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":72},"src/crypto.ts":{"bytesInOutput":1111},"src/defaults.ts":{"bytesInOutput":426},"src/hypercore-factory.ts":{"bytesInOutput":1329},"src/util.ts":{"bytesInOutput":86},"src/iterator.ts":{"bytesInOutput":230}},"bytes":3772}}}
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,EAAE,GAAI,KAAK,GAAG,EAAE,IAAI,QAAQ,aAAiC,CAAC"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,EAAE,GAAI,KAAK,GAAG,EAAE,IAAI,QAAQ,aAA4B,CAAC"}