@dxos/timeframe 0.1.56-main.f3d4052 → 0.1.56-next.71eb10c

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.
@@ -5,7 +5,7 @@ import { inspect } from "@dxos/node-std/util";
5
5
  import { equalsSymbol } from "@dxos/debug";
6
6
  import { PublicKey } from "@dxos/keys";
7
7
  import { ComplexMap } from "@dxos/util";
8
- var Timeframe = class {
8
+ var Timeframe = class _Timeframe {
9
9
  constructor(frames = []) {
10
10
  this._frames = new ComplexMap(PublicKey.hash);
11
11
  for (const [key, seq] of frames) {
@@ -49,10 +49,10 @@ var Timeframe = class {
49
49
  * @param keys
50
50
  */
51
51
  withoutKeys(keys) {
52
- return new Timeframe(this.frames().filter(([frameKey]) => keys.every((key) => Buffer.compare(key.asBuffer(), frameKey.asBuffer()) !== 0)));
52
+ return new _Timeframe(this.frames().filter(([frameKey]) => keys.every((key) => Buffer.compare(key.asBuffer(), frameKey.asBuffer()) !== 0)));
53
53
  }
54
54
  map(fn) {
55
- return new Timeframe(this.frames().map(fn));
55
+ return new _Timeframe(this.frames().map(fn));
56
56
  }
57
57
  /**
58
58
  * Returns a total amount of messages represented by this timeframe.
@@ -64,10 +64,7 @@ var Timeframe = class {
64
64
  * Returns a total amount of messages that are present in this timeframe but are missing in `base`.
65
65
  */
66
66
  newMessages(base) {
67
- return Array.from(this._frames.entries()).reduce((result, [key, seq]) => {
68
- var _a;
69
- return result + Math.max(seq - ((_a = base.get(key)) != null ? _a : -1), 0);
70
- }, 0);
67
+ return Array.from(this._frames.entries()).reduce((result, [key, seq]) => result + Math.max(seq - (base.get(key) ?? -1), 0), 0);
71
68
  }
72
69
  /**
73
70
  * Used by NodeJS to get textual representation of this object in `console.log`.
@@ -76,7 +73,7 @@ var Timeframe = class {
76
73
  return `Timeframe${this.toString()}`;
77
74
  }
78
75
  [equalsSymbol](other) {
79
- if (!(other instanceof Timeframe)) {
76
+ if (!(other instanceof _Timeframe)) {
80
77
  return false;
81
78
  }
82
79
  return this.equals(other);
@@ -86,7 +83,7 @@ var Timeframe = class {
86
83
  * @param timeframes
87
84
  */
88
85
  static merge(...timeframes) {
89
- const result = new Timeframe();
86
+ const result = new _Timeframe();
90
87
  for (const timeframe of timeframes) {
91
88
  for (const [key, seq] of timeframe.frames()) {
92
89
  const current = result.get(key);
@@ -102,7 +99,7 @@ var Timeframe = class {
102
99
  * is greater than the associated sequence number from the second timeframe.
103
100
  */
104
101
  static dependencies(tf1, tf2) {
105
- const result = new Timeframe();
102
+ const result = new _Timeframe();
106
103
  for (const [key, seq] of tf1.frames()) {
107
104
  const otherSeq = tf2.get(key);
108
105
  if (otherSeq === void 0 || otherSeq < seq) {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/timeframe.ts"],
4
4
  "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { equalsSymbol, Equatable } from '@dxos/debug';\nimport { PublicKey } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\n/**\n * A vector clock that implements ordering over a set of feed messages.\n */\nexport class Timeframe implements Equatable {\n private readonly _frames = new ComplexMap<PublicKey, number>(PublicKey.hash);\n\n constructor(frames: [PublicKey, number][] = []) {\n for (const [key, seq] of frames) {\n this.set(key, seq);\n }\n }\n\n toJSON() {\n return this.frames().reduce((frames: Record<string, number>, [key, seq]) => {\n frames[key.truncate()] = seq;\n return frames;\n }, {});\n }\n\n toString() {\n return `(${this.frames()\n .map(([key, seq]) => `${key.truncate()}[${seq}]`)\n .join(', ')})`;\n }\n\n equals(object: Timeframe) {\n return this.size() === object.size() && this.frames().every(([key, seq]) => object.get(key) === seq);\n }\n\n // TODO(burdon): Rename getFrame.\n get(key: PublicKey) {\n return this._frames.get(key);\n }\n\n // TODO(burdon): Rename setFrame.\n set(key: PublicKey, value: number) {\n this._frames.set(key, value);\n }\n\n // TODO(burdon): Change to getter.\n frames(): [PublicKey, number][] {\n return Array.from(this._frames.entries()).filter((frame): frame is [PublicKey, number] => !!frame);\n }\n\n // TODO(burdon): Change to getter.\n size() {\n return this._frames.size;\n }\n\n // TODO(burdon): Change to getter (empty).\n isEmpty() {\n return this.size() === 0;\n }\n\n /**\n * Returns a new timeframe with specified keys removed.\n * @param keys\n */\n withoutKeys(keys: PublicKey[]): Timeframe {\n return new Timeframe(\n this.frames().filter(([frameKey]) =>\n keys.every((key) => Buffer.compare(key.asBuffer(), frameKey.asBuffer()) !== 0),\n ),\n );\n }\n\n map(fn: (frame: [key: PublicKey, seq: number]) => [PublicKey, number]): Timeframe {\n return new Timeframe(this.frames().map(fn));\n }\n\n /**\n * Returns a total amount of messages represented by this timeframe.\n */\n totalMessages(): number {\n return Array.from(this._frames.values()).reduce((result, seq) => result + seq + 1, 0);\n }\n\n /**\n * Returns a total amount of messages that are present in this timeframe but are missing in `base`.\n */\n newMessages(base: Timeframe) {\n return Array.from(this._frames.entries()).reduce(\n (result, [key, seq]) => result + Math.max(seq - (base.get(key) ?? -1), 0),\n 0,\n );\n }\n\n /**\n * Used by NodeJS to get textual representation of this object in `console.log`.\n */\n [inspect.custom]() {\n return `Timeframe${this.toString()}`;\n }\n\n [equalsSymbol](other: any) {\n if (!(other instanceof Timeframe)) {\n return false;\n }\n\n return this.equals(other);\n }\n\n /**\n * Merges the values, updating the highest sequence numbers.\n * @param timeframes\n */\n static merge(...timeframes: Timeframe[]): Timeframe {\n const result = new Timeframe();\n for (const timeframe of timeframes) {\n for (const [key, seq] of timeframe.frames()) {\n const current = result.get(key);\n if (current === undefined || seq > current) {\n result.set(key, seq);\n }\n }\n }\n\n return result;\n }\n\n /**\n * Compares two timeframes and returns an array of frames from the first timeframe where the sequence number\n * is greater than the associated sequence number from the second timeframe.\n */\n static dependencies(tf1: Timeframe, tf2: Timeframe): Timeframe {\n const result = new Timeframe();\n for (const [key, seq] of tf1.frames()) {\n const otherSeq = tf2.get(key);\n if (otherSeq === undefined || otherSeq < seq) {\n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ASC,YAAoC;AAClD,UAAMV,SAAS,IAAIrC,WAAAA;AACnB,eAAWgD,aAAaD,YAAY;AAClC,iBAAW,CAACxC,KAAKC,GAAAA,KAAQwC,UAAU9C,OAAM,GAAI;AAC3C,cAAM+C,UAAUZ,OAAOjB,IAAIb,GAAAA;AAC3B,YAAI0C,YAAYC,UAAa1C,MAAMyC,SAAS;AAC1CZ,iBAAO5B,IAAIF,KAAKC,GAAAA;QAClB;MACF;IACF;AAEA,WAAO6B;EACT;;;;;EAMA,OAAOc,aAAaC,KAAgBC,KAA2B;AAC7D,UAAMhB,SAAS,IAAIrC,WAAAA;AACnB,eAAW,CAACO,KAAKC,GAAAA,KAAQ4C,IAAIlD,OAAM,GAAI;AACrC,YAAMoD,WAAWD,IAAIjC,IAAIb,GAAAA;AACzB,UAAI+C,aAAaJ,UAAaI,WAAW9C,KAAK;AAC5C6B,eAAO5B,IAAIF,KAAKC,GAAAA;MAClB;IACF;AAEA,WAAO6B;EACT;AACF;",
6
6
  "names": ["inspect", "equalsSymbol", "PublicKey", "ComplexMap", "Timeframe", "constructor", "frames", "_frames", "ComplexMap", "PublicKey", "hash", "key", "seq", "set", "toJSON", "reduce", "truncate", "toString", "map", "join", "equals", "object", "size", "every", "get", "value", "Array", "from", "entries", "filter", "frame", "isEmpty", "withoutKeys", "keys", "frameKey", "Buffer", "compare", "asBuffer", "fn", "totalMessages", "values", "result", "newMessages", "base", "Math", "max", "inspect", "custom", "equalsSymbol", "other", "merge", "timeframes", "timeframe", "current", "undefined", "dependencies", "tf1", "tf2", "otherSeq"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/timeframe/src/timeframe.ts":{"bytes":13404,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}]},"packages/common/timeframe/src/index.ts":{"bytes":470,"imports":[{"path":"packages/common/timeframe/src/timeframe.ts","kind":"import-statement","original":"./timeframe"}]}},"outputs":{"packages/common/timeframe/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7002},"packages/common/timeframe/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Timeframe"],"entryPoint":"packages/common/timeframe/src/index.ts","inputs":{"packages/common/timeframe/src/timeframe.ts":{"bytesInOutput":3251},"packages/common/timeframe/src/index.ts":{"bytesInOutput":0}},"bytes":3390}}}
1
+ {"inputs":{"packages/common/timeframe/src/timeframe.ts":{"bytes":13404,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/timeframe/src/index.ts":{"bytes":470,"imports":[{"path":"packages/common/timeframe/src/timeframe.ts","kind":"import-statement","original":"./timeframe"}],"format":"esm"}},"outputs":{"packages/common/timeframe/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7007},"packages/common/timeframe/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Timeframe"],"entryPoint":"packages/common/timeframe/src/index.ts","inputs":{"packages/common/timeframe/src/timeframe.ts":{"bytesInOutput":3212},"packages/common/timeframe/src/index.ts":{"bytesInOutput":0}},"bytes":3351}}}
@@ -29,7 +29,7 @@ var import_node_util = require("node:util");
29
29
  var import_debug = require("@dxos/debug");
30
30
  var import_keys = require("@dxos/keys");
31
31
  var import_util = require("@dxos/util");
32
- var Timeframe = class {
32
+ var Timeframe = class _Timeframe {
33
33
  constructor(frames = []) {
34
34
  this._frames = new import_util.ComplexMap(import_keys.PublicKey.hash);
35
35
  for (const [key, seq] of frames) {
@@ -73,10 +73,10 @@ var Timeframe = class {
73
73
  * @param keys
74
74
  */
75
75
  withoutKeys(keys) {
76
- return new Timeframe(this.frames().filter(([frameKey]) => keys.every((key) => Buffer.compare(key.asBuffer(), frameKey.asBuffer()) !== 0)));
76
+ return new _Timeframe(this.frames().filter(([frameKey]) => keys.every((key) => Buffer.compare(key.asBuffer(), frameKey.asBuffer()) !== 0)));
77
77
  }
78
78
  map(fn) {
79
- return new Timeframe(this.frames().map(fn));
79
+ return new _Timeframe(this.frames().map(fn));
80
80
  }
81
81
  /**
82
82
  * Returns a total amount of messages represented by this timeframe.
@@ -88,10 +88,7 @@ var Timeframe = class {
88
88
  * Returns a total amount of messages that are present in this timeframe but are missing in `base`.
89
89
  */
90
90
  newMessages(base) {
91
- return Array.from(this._frames.entries()).reduce((result, [key, seq]) => {
92
- var _a;
93
- return result + Math.max(seq - ((_a = base.get(key)) != null ? _a : -1), 0);
94
- }, 0);
91
+ return Array.from(this._frames.entries()).reduce((result, [key, seq]) => result + Math.max(seq - (base.get(key) ?? -1), 0), 0);
95
92
  }
96
93
  /**
97
94
  * Used by NodeJS to get textual representation of this object in `console.log`.
@@ -100,7 +97,7 @@ var Timeframe = class {
100
97
  return `Timeframe${this.toString()}`;
101
98
  }
102
99
  [import_debug.equalsSymbol](other) {
103
- if (!(other instanceof Timeframe)) {
100
+ if (!(other instanceof _Timeframe)) {
104
101
  return false;
105
102
  }
106
103
  return this.equals(other);
@@ -110,7 +107,7 @@ var Timeframe = class {
110
107
  * @param timeframes
111
108
  */
112
109
  static merge(...timeframes) {
113
- const result = new Timeframe();
110
+ const result = new _Timeframe();
114
111
  for (const timeframe of timeframes) {
115
112
  for (const [key, seq] of timeframe.frames()) {
116
113
  const current = result.get(key);
@@ -126,7 +123,7 @@ var Timeframe = class {
126
123
  * is greater than the associated sequence number from the second timeframe.
127
124
  */
128
125
  static dependencies(tf1, tf2) {
129
- const result = new Timeframe();
126
+ const result = new _Timeframe();
130
127
  for (const [key, seq] of tf1.frames()) {
131
128
  const otherSeq = tf2.get(key);
132
129
  if (otherSeq === void 0 || otherSeq < seq) {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/timeframe.ts"],
4
4
  "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nexport * from './timeframe';\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { equalsSymbol, Equatable } from '@dxos/debug';\nimport { PublicKey } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\n/**\n * A vector clock that implements ordering over a set of feed messages.\n */\nexport class Timeframe implements Equatable {\n private readonly _frames = new ComplexMap<PublicKey, number>(PublicKey.hash);\n\n constructor(frames: [PublicKey, number][] = []) {\n for (const [key, seq] of frames) {\n this.set(key, seq);\n }\n }\n\n toJSON() {\n return this.frames().reduce((frames: Record<string, number>, [key, seq]) => {\n frames[key.truncate()] = seq;\n return frames;\n }, {});\n }\n\n toString() {\n return `(${this.frames()\n .map(([key, seq]) => `${key.truncate()}[${seq}]`)\n .join(', ')})`;\n }\n\n equals(object: Timeframe) {\n return this.size() === object.size() && this.frames().every(([key, seq]) => object.get(key) === seq);\n }\n\n // TODO(burdon): Rename getFrame.\n get(key: PublicKey) {\n return this._frames.get(key);\n }\n\n // TODO(burdon): Rename setFrame.\n set(key: PublicKey, value: number) {\n this._frames.set(key, value);\n }\n\n // TODO(burdon): Change to getter.\n frames(): [PublicKey, number][] {\n return Array.from(this._frames.entries()).filter((frame): frame is [PublicKey, number] => !!frame);\n }\n\n // TODO(burdon): Change to getter.\n size() {\n return this._frames.size;\n }\n\n // TODO(burdon): Change to getter (empty).\n isEmpty() {\n return this.size() === 0;\n }\n\n /**\n * Returns a new timeframe with specified keys removed.\n * @param keys\n */\n withoutKeys(keys: PublicKey[]): Timeframe {\n return new Timeframe(\n this.frames().filter(([frameKey]) =>\n keys.every((key) => Buffer.compare(key.asBuffer(), frameKey.asBuffer()) !== 0),\n ),\n );\n }\n\n map(fn: (frame: [key: PublicKey, seq: number]) => [PublicKey, number]): Timeframe {\n return new Timeframe(this.frames().map(fn));\n }\n\n /**\n * Returns a total amount of messages represented by this timeframe.\n */\n totalMessages(): number {\n return Array.from(this._frames.values()).reduce((result, seq) => result + seq + 1, 0);\n }\n\n /**\n * Returns a total amount of messages that are present in this timeframe but are missing in `base`.\n */\n newMessages(base: Timeframe) {\n return Array.from(this._frames.entries()).reduce(\n (result, [key, seq]) => result + Math.max(seq - (base.get(key) ?? -1), 0),\n 0,\n );\n }\n\n /**\n * Used by NodeJS to get textual representation of this object in `console.log`.\n */\n [inspect.custom]() {\n return `Timeframe${this.toString()}`;\n }\n\n [equalsSymbol](other: any) {\n if (!(other instanceof Timeframe)) {\n return false;\n }\n\n return this.equals(other);\n }\n\n /**\n * Merges the values, updating the highest sequence numbers.\n * @param timeframes\n */\n static merge(...timeframes: Timeframe[]): Timeframe {\n const result = new Timeframe();\n for (const timeframe of timeframes) {\n for (const [key, seq] of timeframe.frames()) {\n const current = result.get(key);\n if (current === undefined || seq > current) {\n result.set(key, seq);\n }\n }\n }\n\n return result;\n }\n\n /**\n * Compares two timeframes and returns an array of frames from the first timeframe where the sequence number\n * is greater than the associated sequence number from the second timeframe.\n */\n static dependencies(tf1: Timeframe, tf2: Timeframe): Timeframe {\n const result = new Timeframe();\n for (const [key, seq] of tf1.frames()) {\n const otherSeq = tf2.get(key);\n if (otherSeq === undefined || otherSeq < seq) {\n result.set(key, seq);\n }\n }\n\n return result;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACIA,uBAAwB;AAExB,mBAAwC;AACxC,kBAA0B;AAC1B,kBAA2B;AAKpB,IAAMA,YAAN,MAAMA;EAGXC,YAAYC,SAAgC,CAAA,G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IAAIb,GAAAA;AAC3B,YAAI0C,YAAYC,UAAa1C,MAAMyC,SAAS;AAC1CZ,iBAAO5B,IAAIF,KAAKC,GAAAA;QAClB;MACF;IACF;AAEA,WAAO6B;EACT;;;;;EAMA,OAAOc,aAAaC,KAAgBC,KAA2B;AAC7D,UAAMhB,SAAS,IAAIrC,WAAAA;AACnB,eAAW,CAACO,KAAKC,GAAAA,KAAQ4C,IAAIlD,OAAM,GAAI;AACrC,YAAMoD,WAAWD,IAAIjC,IAAIb,GAAAA;AACzB,UAAI+C,aAAaJ,UAAaI,WAAW9C,KAAK;AAC5C6B,eAAO5B,IAAIF,KAAKC,GAAAA;MAClB;IACF;AAEA,WAAO6B;EACT;AACF;",
6
6
  "names": ["Timeframe", "constructor", "frames", "_frames", "ComplexMap", "PublicKey", "hash", "key", "seq", "set", "toJSON", "reduce", "truncate", "toString", "map", "join", "equals", "object", "size", "every", "get", "value", "Array", "from", "entries", "filter", "frame", "isEmpty", "withoutKeys", "keys", "frameKey", "Buffer", "compare", "asBuffer", "fn", "totalMessages", "values", "result", "newMessages", "base", "Math", "max", "inspect", "custom", "equalsSymbol", "other", "merge", "timeframes", "timeframe", "current", "undefined", "dependencies", "tf1", "tf2", "otherSeq"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/timeframe/src/timeframe.ts":{"bytes":13404,"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}]},"packages/common/timeframe/src/index.ts":{"bytes":470,"imports":[{"path":"packages/common/timeframe/src/timeframe.ts","kind":"import-statement","original":"./timeframe"}]}},"outputs":{"packages/common/timeframe/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7055},"packages/common/timeframe/dist/lib/node/index.cjs":{"imports":[{"path":"node:util","kind":"require-call","external":true},{"path":"@dxos/debug","kind":"require-call","external":true},{"path":"@dxos/keys","kind":"require-call","external":true},{"path":"@dxos/util","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/common/timeframe/src/index.ts","inputs":{"packages/common/timeframe/src/index.ts":{"bytesInOutput":123},"packages/common/timeframe/src/timeframe.ts":{"bytesInOutput":3303}},"bytes":4453}}}
1
+ {"inputs":{"packages/common/timeframe/src/timeframe.ts":{"bytes":13404,"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/timeframe/src/index.ts":{"bytes":470,"imports":[{"path":"packages/common/timeframe/src/timeframe.ts","kind":"import-statement","original":"./timeframe"}],"format":"esm"}},"outputs":{"packages/common/timeframe/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7060},"packages/common/timeframe/dist/lib/node/index.cjs":{"imports":[{"path":"node:util","kind":"require-call","external":true},{"path":"@dxos/debug","kind":"require-call","external":true},{"path":"@dxos/keys","kind":"require-call","external":true},{"path":"@dxos/util","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/common/timeframe/src/index.ts","inputs":{"packages/common/timeframe/src/index.ts":{"bytesInOutput":123},"packages/common/timeframe/src/timeframe.ts":{"bytesInOutput":3264}},"bytes":4414}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/timeframe",
3
- "version": "0.1.56-main.f3d4052",
3
+ "version": "0.1.56-next.71eb10c",
4
4
  "description": "Timeframe vector clock.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,11 +16,11 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@dxos/debug": "0.1.56-main.f3d4052",
20
- "@dxos/keys": "0.1.56-main.f3d4052",
21
- "@dxos/log": "0.1.56-main.f3d4052",
22
- "@dxos/node-std": "0.1.56-main.f3d4052",
23
- "@dxos/util": "0.1.56-main.f3d4052"
19
+ "@dxos/debug": "0.1.56-next.71eb10c",
20
+ "@dxos/keys": "0.1.56-next.71eb10c",
21
+ "@dxos/log": "0.1.56-next.71eb10c",
22
+ "@dxos/node-std": "0.1.56-next.71eb10c",
23
+ "@dxos/util": "0.1.56-next.71eb10c"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"