@dxos/hypercore 0.10.0 → 0.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/hypercore",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "Hypercore wrapper and utils.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,8 +16,7 @@
16
16
  ".": {
17
17
  "source": "./src/index.ts",
18
18
  "types": "./dist/types/src/index.d.ts",
19
- "browser": "./dist/lib/browser/index.mjs",
20
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "import": "./dist/lib/index.mjs"
21
20
  }
22
21
  },
23
22
  "types": "dist/types/src/index.d.ts",
@@ -28,24 +27,24 @@
28
27
  "dependencies": {
29
28
  "readable-stream": "^3.6.0",
30
29
  "streamx": "^2.12.5",
31
- "@dxos/async": "0.10.0",
32
- "@dxos/codec-protobuf": "0.10.0",
33
- "@dxos/crypto": "0.10.0",
34
- "@dxos/invariant": "0.10.0",
35
- "@dxos/keys": "0.10.0",
36
- "@dxos/node-std": "0.10.0",
37
- "@dxos/typings": "0.10.0",
38
- "@dxos/random-access-storage": "0.10.0",
39
- "@dxos/util": "0.10.0",
40
- "@dxos/vendor-hypercore": "0.10.0"
30
+ "@dxos/async": "0.11.1",
31
+ "@dxos/codec-protobuf": "0.11.1",
32
+ "@dxos/crypto": "0.11.1",
33
+ "@dxos/invariant": "0.11.1",
34
+ "@dxos/keys": "0.11.1",
35
+ "@dxos/node-std": "0.11.1",
36
+ "@dxos/random-access-storage": "0.11.1",
37
+ "@dxos/typings": "0.11.1",
38
+ "@dxos/util": "0.11.1",
39
+ "@dxos/vendor-hypercore": "0.11.1"
41
40
  },
42
41
  "devDependencies": {
43
42
  "@types/readable-stream": "^2.3.9",
44
43
  "hypercore-protocol": "^8.0.7",
45
- "@dxos/log": "0.10.0",
46
- "@dxos/util": "0.10.0",
47
- "@dxos/random": "0.10.0",
48
- "@dxos/tracing": "0.10.0"
44
+ "@dxos/log": "0.11.1",
45
+ "@dxos/random": "0.11.1",
46
+ "@dxos/tracing": "0.11.1",
47
+ "@dxos/util": "0.11.1"
49
48
  },
50
49
  "publishConfig": {
51
50
  "access": "public"
@@ -9,8 +9,7 @@ import { createKeyPair } from '@dxos/crypto';
9
9
  import { log } from '@dxos/log';
10
10
  import { random } from '@dxos/random';
11
11
  import { StorageType, createStorage } from '@dxos/random-access-storage';
12
- import { TRACE_PROCESSOR } from '@dxos/tracing';
13
- import { range, sum } from '@dxos/util';
12
+ import { range } from '@dxos/util';
14
13
 
15
14
  import { HypercoreFactory } from './hypercore-factory';
16
15
  import { createReadable } from './iterator';
@@ -376,21 +375,8 @@ describe('Replication', () => {
376
375
 
377
376
  const end = performance.now();
378
377
 
379
- // Make sure flushes are counted.
380
378
  await sleep(1000);
381
379
 
382
- TRACE_PROCESSOR.refresh();
383
-
384
- // console.log(inspect(TRACE_PROCESSOR.findResourcesByClassName('WebFile').map(r => [
385
- // r.data.info._fileName,
386
- // ...r.data.metrics!.map(m => [m.name, m.timeSeries!.tracks![0].total])
387
- // ])), false, null, true)
388
- const totalFlushes = sum(
389
- TRACE_PROCESSOR.findResourcesByClassName('WebFile').map(
390
- (resource) => resource.getMetric('_flushes')!.timeSeries!.tracks![0].total,
391
- ),
392
- );
393
-
394
380
  log.info('time', {
395
381
  timeMs: end - begin,
396
382
  numBlocks,
@@ -399,7 +385,6 @@ describe('Replication', () => {
399
385
  sparse,
400
386
  eagerUpdate,
401
387
  linear,
402
- totalFlushes,
403
388
  });
404
389
 
405
390
  expect(await core2.has(0, numBlocks)).to.eq(true);
@@ -1,123 +0,0 @@
1
- // src/index.ts
2
- import { default as default2 } from "@dxos/vendor-hypercore/hypercore";
3
-
4
- // src/crypto.ts
5
- import { callbackify } from "@dxos/node-std/util";
6
- import { verifySignature } from "@dxos/crypto";
7
- import { invariant } from "@dxos/invariant";
8
- import { arrayToBuffer } from "@dxos/util";
9
- var __dxlog_file = "/__w/dxos/dxos/packages/common/hypercore/src/crypto.ts";
10
- var createCodecEncoding = (codec, opts) => ({
11
- encode: (obj) => arrayToBuffer(codec.encode(obj, opts)),
12
- decode: (buffer) => codec.decode(buffer, opts)
13
- });
14
- var createCrypto = (signer, publicKey) => {
15
- invariant(signer, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 18, S: void 0, A: ["signer", ""] });
16
- invariant(publicKey, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 19, S: void 0, A: ["publicKey", ""] });
17
- return {
18
- sign: (message, secretKey, cb) => {
19
- callbackify(signer.sign.bind(signer))(publicKey, message, (err, result) => {
20
- if (err) {
21
- cb(err, null);
22
- return;
23
- }
24
- cb(null, arrayToBuffer(result));
25
- });
26
- },
27
- verify: async (message, signature, key, cb) => {
28
- callbackify(verifySignature)(publicKey, message, signature, cb);
29
- }
30
- };
31
- };
32
-
33
- // src/defaults.ts
34
- var defaultFeedOptions = {
35
- createIfMissing: true,
36
- valueEncoding: "binary"
37
- };
38
- var defaultReadStreamOptions = {
39
- start: 0,
40
- end: Infinity,
41
- snapshot: true,
42
- tail: false,
43
- live: false,
44
- timeout: 0,
45
- wait: true,
46
- batch: 1
47
- };
48
- var defaultWriteStreamOptions = {
49
- maxBlockSize: Infinity
50
- };
51
- var defaultReplicateOptions = {
52
- live: false,
53
- ack: false,
54
- download: true,
55
- upload: true,
56
- encrypted: true,
57
- noise: true
58
- };
59
-
60
- // src/hypercore-factory.ts
61
- import { invariant as invariant2 } from "@dxos/invariant";
62
- import { StorageType, createStorage } from "@dxos/random-access-storage";
63
- import hypercore from "@dxos/vendor-hypercore/hypercore";
64
-
65
- // src/util.ts
66
- import { promisify } from "@dxos/node-std/util";
67
- var py = (obj, fn) => promisify(fn.bind(obj));
68
-
69
- // src/hypercore-factory.ts
70
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/hypercore/src/hypercore-factory.ts";
71
- var HypercoreFactory = class {
72
- _root;
73
- _options;
74
- constructor(_root = createStorage({
75
- type: StorageType.RAM
76
- }).createDirectory(), _options) {
77
- this._root = _root;
78
- this._options = _options;
79
- invariant2(this._root, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 18, S: this, A: ["this._root", ""] });
80
- }
81
- /**
82
- * Creates a feed using a storage factory prefixed with the feed's key.
83
- * NOTE: We have to use our `random-access-storage` implementation since the native ones
84
- * do not behave uniformly across platforms.
85
- */
86
- createFeed(publicKey, options) {
87
- const directory = this._root.createDirectory(publicKey.toString("hex"));
88
- const storage = (filename) => directory.getOrCreateFile(filename).native;
89
- return hypercore(storage, publicKey, Object.assign({}, this._options, options));
90
- }
91
- /**
92
- * Creates and opens a feed.
93
- */
94
- async openFeed(publicKey, options) {
95
- const feed = this.createFeed(publicKey, options);
96
- await py(feed, feed.open)();
97
- return feed;
98
- }
99
- };
100
-
101
- // src/iterator.ts
102
- import { Readable } from "readable-stream";
103
- var createReadable = (stream) => {
104
- return new Readable({
105
- objectMode: true
106
- }).wrap(stream);
107
- };
108
- var createAsyncIterator = (stream) => {
109
- return stream[Symbol.asyncIterator]();
110
- };
111
- export {
112
- HypercoreFactory,
113
- createAsyncIterator,
114
- createCodecEncoding,
115
- createCrypto,
116
- createReadable,
117
- defaultFeedOptions,
118
- defaultReadStreamOptions,
119
- defaultReplicateOptions,
120
- defaultWriteStreamOptions,
121
- default2 as hypercore
122
- };
123
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 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 { 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;AAG9B,IAAA,eAAA;AAKEC,IAASC,sBAAgCA,CAAAA,OAAQC,UAAAA;EAChD,QAAA,CAAA,QAAA,cAAA,MAAA,OAAA,KAAA,IAAA,CAAA;EAEH,QAAA,CAAA,WAAA,MAAA,OAAA,QAAA,IAAA;;AAMEJ,IAAAA,eAAUK,CAAAA,QAAAA,cAAAA;AAEV,YAAO,QAAA,QAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,QAAA,GAAA,CAAA,UAAA,EAAA,EAAA,CAAA;YACC,WAAUC,QAAAA,EAA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AAAA,MAASG,gBAAkBC,UAAW,SAAKN,KAAQ,CAAEO;AACxE,UAAA,UAAA,CAAA,aAAA,UAAA,gBAAA,QAAA,EAAA;AAEA,WAAA,UAAA,SAAA,WAAA,OAAA,OAAA,CAAA,GAAA,KAAA,UAAA,OAAA,CAAA;;;;;QAKE,SAASC,WAAe,SAAK;AAC7B,UAAA,OAAOA,KAAAA,WAAAA,WAAAA,OAAAA;AACT,UAAA,GAAA,MAAA,KAAA,IAAA,EAAA;AACF,WAAA;;;;;AErCA,SAASC,gBAAgB;AAgBlB,IAAMC,iBAAiB,CAACC,WAAAA;AAC7B,SAAO,IAAIF,SAAS;IAAEG,YAAY;EAAK,CAAA,EAAGC,KAAKF,MAAAA;AACjD;AAUO,IAAMG,sBAAsB,CAACH,WAAAA;AAClC,SAAOA,OAAOI,OAAOC,aAAa,EAAC;AACrC;",
6
- "names": ["hypercore", "default", "callbackify", "verifySignature", "invariant", "arrayToBuffer", "decode", "buffer", "opts", "publicKey", "secretKey", "cb", "err", "verify", "message", "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", "bind", "__dxlog_file", "createDirectory", "_root", "_options", "invariant", "storage", "filename", "directory", "publicKey", "assign", "options", "feed", "Readable", "createReadable", "stream", "objectMode", "wrap", "createAsyncIterator", "Symbol", "asyncIterator"]
7
- }
@@ -1 +0,0 @@
1
- {"inputs":{"src/crypto.ts":{"bytes":4805,"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":3682,"imports":[],"format":"esm"},"src/util.ts":{"bytes":705,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"src/hypercore-factory.ts":{"bytes":5109,"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":3877,"imports":[{"path":"readable-stream","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":1096,"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":9210},"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":1097},"src/defaults.ts":{"bytesInOutput":426},"src/hypercore-factory.ts":{"bytesInOutput":1301},"src/util.ts":{"bytesInOutput":96},"src/iterator.ts":{"bytesInOutput":230}},"bytes":3647}}}
@@ -1,125 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // src/index.ts
4
- import { default as default2 } from "@dxos/vendor-hypercore/hypercore";
5
-
6
- // src/crypto.ts
7
- import { callbackify } from "node:util";
8
- import { verifySignature } from "@dxos/crypto";
9
- import { invariant } from "@dxos/invariant";
10
- import { arrayToBuffer } from "@dxos/util";
11
- var __dxlog_file = "/__w/dxos/dxos/packages/common/hypercore/src/crypto.ts";
12
- var createCodecEncoding = (codec, opts) => ({
13
- encode: (obj) => arrayToBuffer(codec.encode(obj, opts)),
14
- decode: (buffer) => codec.decode(buffer, opts)
15
- });
16
- var createCrypto = (signer, publicKey) => {
17
- invariant(signer, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 18, S: void 0, A: ["signer", ""] });
18
- invariant(publicKey, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 19, S: void 0, A: ["publicKey", ""] });
19
- return {
20
- sign: (message, secretKey, cb) => {
21
- callbackify(signer.sign.bind(signer))(publicKey, message, (err, result) => {
22
- if (err) {
23
- cb(err, null);
24
- return;
25
- }
26
- cb(null, arrayToBuffer(result));
27
- });
28
- },
29
- verify: async (message, signature, key, cb) => {
30
- callbackify(verifySignature)(publicKey, message, signature, cb);
31
- }
32
- };
33
- };
34
-
35
- // src/defaults.ts
36
- var defaultFeedOptions = {
37
- createIfMissing: true,
38
- valueEncoding: "binary"
39
- };
40
- var defaultReadStreamOptions = {
41
- start: 0,
42
- end: Infinity,
43
- snapshot: true,
44
- tail: false,
45
- live: false,
46
- timeout: 0,
47
- wait: true,
48
- batch: 1
49
- };
50
- var defaultWriteStreamOptions = {
51
- maxBlockSize: Infinity
52
- };
53
- var defaultReplicateOptions = {
54
- live: false,
55
- ack: false,
56
- download: true,
57
- upload: true,
58
- encrypted: true,
59
- noise: true
60
- };
61
-
62
- // src/hypercore-factory.ts
63
- import { invariant as invariant2 } from "@dxos/invariant";
64
- import { StorageType, createStorage } from "@dxos/random-access-storage";
65
- import hypercore from "@dxos/vendor-hypercore/hypercore";
66
-
67
- // src/util.ts
68
- import { promisify } from "node:util";
69
- var py = (obj, fn) => promisify(fn.bind(obj));
70
-
71
- // src/hypercore-factory.ts
72
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/hypercore/src/hypercore-factory.ts";
73
- var HypercoreFactory = class {
74
- _root;
75
- _options;
76
- constructor(_root = createStorage({
77
- type: StorageType.RAM
78
- }).createDirectory(), _options) {
79
- this._root = _root;
80
- this._options = _options;
81
- invariant2(this._root, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 18, S: this, A: ["this._root", ""] });
82
- }
83
- /**
84
- * Creates a feed using a storage factory prefixed with the feed's key.
85
- * NOTE: We have to use our `random-access-storage` implementation since the native ones
86
- * do not behave uniformly across platforms.
87
- */
88
- createFeed(publicKey, options) {
89
- const directory = this._root.createDirectory(publicKey.toString("hex"));
90
- const storage = (filename) => directory.getOrCreateFile(filename).native;
91
- return hypercore(storage, publicKey, Object.assign({}, this._options, options));
92
- }
93
- /**
94
- * Creates and opens a feed.
95
- */
96
- async openFeed(publicKey, options) {
97
- const feed = this.createFeed(publicKey, options);
98
- await py(feed, feed.open)();
99
- return feed;
100
- }
101
- };
102
-
103
- // src/iterator.ts
104
- import { Readable } from "readable-stream";
105
- var createReadable = (stream) => {
106
- return new Readable({
107
- objectMode: true
108
- }).wrap(stream);
109
- };
110
- var createAsyncIterator = (stream) => {
111
- return stream[Symbol.asyncIterator]();
112
- };
113
- export {
114
- HypercoreFactory,
115
- createAsyncIterator,
116
- createCodecEncoding,
117
- createCrypto,
118
- createReadable,
119
- defaultFeedOptions,
120
- defaultReadStreamOptions,
121
- defaultReplicateOptions,
122
- defaultWriteStreamOptions,
123
- default2 as hypercore
124
- };
125
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 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 { 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;AAG9B,IAAA,eAAA;AAKEC,IAASC,sBAAgCA,CAAAA,OAAQC,UAAAA;EAChD,QAA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,YAAGC,QAAiB,cAE9F;UAFiBC,YAAAA;qBACAC,GAAAA,UAAAA;AAEjBC,SAAAA,QAAU;AACZ,SAAA,WAAA;AAEA,IAAAA,WAAA,KAAA,OAAA,QAAA,EAAA,YAAA,YAAA,GAAAJ,eAAA,GAAA,IAAA,GAAA,MAAA,GAAA,CAAA,cAAA,EAAA,EAAA,CAAA;;;;;;;aAOQK,WAAWC,SAAqBC;AACtC,UAAA,YAAiBF,KAAAA,MAASG,gBAAkBC,UAAW,SAAKN,KAAQ,CAAEO;AACxE,UAAA,UAAA,CAAA,aAAA,UAAA,gBAAA,QAAA,EAAA;AAEA,WAAA,UAAA,SAAA,WAAA,OAAA,OAAA,CAAA,GAAA,KAAA,UAAA,OAAA,CAAA;;;;;QAKE,SAASC,WAAe,SAAK;AAC7B,UAAA,OAAOA,KAAAA,WAAAA,WAAAA,OAAAA;AACT,UAAA,GAAA,MAAA,KAAA,IAAA,EAAA;AACF,WAAA;;;;;AErCA,SAASC,gBAAgB;AAgBlB,IAAMC,iBAAiB,CAACC,WAAAA;AAC7B,SAAO,IAAIF,SAAS;IAAEG,YAAY;EAAK,CAAA,EAAGC,KAAKF,MAAAA;AACjD;AAUO,IAAMG,sBAAsB,CAACH,WAAAA;AAClC,SAAOA,OAAOI,OAAOC,aAAa,EAAC;AACrC;",
6
- "names": ["hypercore", "default", "callbackify", "verifySignature", "invariant", "arrayToBuffer", "decode", "buffer", "opts", "publicKey", "secretKey", "cb", "err", "verify", "message", "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", "bind", "__dxlog_file", "createDirectory", "_root", "_options", "invariant", "storage", "filename", "directory", "publicKey", "assign", "options", "feed", "Readable", "createReadable", "stream", "objectMode", "wrap", "createAsyncIterator", "Symbol", "asyncIterator"]
7
- }
@@ -1 +0,0 @@
1
- {"inputs":{"src/crypto.ts":{"bytes":4805,"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":3682,"imports":[],"format":"esm"},"src/util.ts":{"bytes":705,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"src/hypercore-factory.ts":{"bytes":5109,"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":3877,"imports":[{"path":"readable-stream","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":1096,"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":9212},"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":1087},"src/defaults.ts":{"bytesInOutput":426},"src/hypercore-factory.ts":{"bytesInOutput":1301},"src/util.ts":{"bytesInOutput":86},"src/iterator.ts":{"bytesInOutput":230}},"bytes":3720}}}