@dxos/timeframe 0.8.3 → 0.8.4-main.1f223c7

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/timeframe",
3
- "version": "0.8.3",
3
+ "version": "0.8.4-main.1f223c7",
4
4
  "description": "Timeframe vector clock.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -10,12 +10,12 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
+ "types": "./dist/types/src/index.d.ts",
13
14
  "browser": "./dist/lib/browser/index.mjs",
14
15
  "node": {
15
16
  "require": "./dist/lib/node/index.cjs",
16
17
  "default": "./dist/lib/node-esm/index.mjs"
17
- },
18
- "types": "./dist/types/src/index.d.ts"
18
+ }
19
19
  }
20
20
  },
21
21
  "types": "dist/types/src/index.d.ts",
@@ -27,11 +27,11 @@
27
27
  "src"
28
28
  ],
29
29
  "dependencies": {
30
- "@dxos/keys": "0.8.3",
31
- "@dxos/log": "0.8.3",
32
- "@dxos/node-std": "0.8.3",
33
- "@dxos/util": "0.8.3",
34
- "@dxos/debug": "0.8.3"
30
+ "@dxos/debug": "0.8.4-main.1f223c7",
31
+ "@dxos/log": "0.8.4-main.1f223c7",
32
+ "@dxos/keys": "0.8.4-main.1f223c7",
33
+ "@dxos/util": "0.8.4-main.1f223c7",
34
+ "@dxos/node-std": "0.8.4-main.1f223c7"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
package/src/timeframe.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { inspect } from 'node:util';
6
6
 
7
- import { equalsSymbol, type Equatable } from '@dxos/debug';
7
+ import { type Equatable, equalsSymbol } from '@dxos/debug';
8
8
  import { type PublicKey } from '@dxos/keys';
9
9
 
10
10
  type Entry = {
@@ -1,141 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var node_exports = {};
20
- __export(node_exports, {
21
- Timeframe: () => Timeframe
22
- });
23
- module.exports = __toCommonJS(node_exports);
24
- var import_node_util = require("node:util");
25
- var import_debug = require("@dxos/debug");
26
- var Timeframe = class _Timeframe {
27
- constructor(frames = []) {
28
- this._frames = /* @__PURE__ */ new Map();
29
- for (const [key, seq] of frames) {
30
- this.set(key, seq);
31
- }
32
- }
33
- toJSON() {
34
- return this.frames().reduce((frames, [key, seq]) => {
35
- frames[key.truncate()] = seq;
36
- return frames;
37
- }, {});
38
- }
39
- toString() {
40
- return `(${this.frames().map(([key, seq]) => `${key.truncate()}[${seq}]`).join(", ")})`;
41
- }
42
- equals(object) {
43
- return this.size() === object.size() && this.frames().every(([key, seq]) => object.get(key) === seq);
44
- }
45
- // TODO(burdon): Rename getFrame.
46
- get(key) {
47
- return this._frames.get(key.toHex())?.seq;
48
- }
49
- // TODO(burdon): Rename setFrame.
50
- set(key, seq) {
51
- const hex = key.toHex();
52
- this._frames.set(hex, {
53
- key,
54
- seq
55
- });
56
- }
57
- // TODO(burdon): Change to getter.
58
- frames() {
59
- return Array.from(this._frames.values()).map(({ key, seq }) => [
60
- key,
61
- seq
62
- ]);
63
- }
64
- // TODO(burdon): Change to getter.
65
- size() {
66
- return this._frames.size;
67
- }
68
- // TODO(burdon): Change to getter (empty).
69
- isEmpty() {
70
- return this.size() === 0;
71
- }
72
- /**
73
- * Returns a new timeframe with specified keys removed.
74
- * @param keys
75
- */
76
- withoutKeys(keys) {
77
- return new _Timeframe(this.frames().filter(([frameKey]) => keys.every((key) => !key.equals(frameKey))));
78
- }
79
- map(fn) {
80
- return new _Timeframe(this.frames().map(fn));
81
- }
82
- /**
83
- * Returns a total amount of messages represented by this timeframe.
84
- */
85
- totalMessages() {
86
- return Array.from(this._frames.values()).reduce((result, { seq }) => result + seq + 1, 0);
87
- }
88
- /**
89
- * Returns a total amount of messages that are present in this timeframe but are missing in `base`.
90
- */
91
- newMessages(base) {
92
- return Array.from(this._frames.entries()).reduce((result, [hex, { seq }]) => result + Math.max(seq - (base._frames.get(hex)?.seq ?? -1), 0), 0);
93
- }
94
- /**
95
- * Used by NodeJS to get textual representation of this object in `console.log`.
96
- */
97
- [import_node_util.inspect.custom]() {
98
- return `Timeframe${this.toString()}`;
99
- }
100
- [import_debug.equalsSymbol](other) {
101
- if (!(other instanceof _Timeframe)) {
102
- return false;
103
- }
104
- return this.equals(other);
105
- }
106
- /**
107
- * Merges the values, updating the highest sequence numbers.
108
- * @param timeframes
109
- */
110
- static merge(...timeframes) {
111
- const result = new _Timeframe();
112
- for (const timeframe of timeframes) {
113
- for (const [hex, entry] of timeframe._frames) {
114
- const currentEntry = result._frames.get(hex);
115
- if (currentEntry === void 0 || entry.seq > currentEntry.seq) {
116
- result._frames.set(hex, entry);
117
- }
118
- }
119
- }
120
- return result;
121
- }
122
- /**
123
- * Compares two timeframes and returns an array of frames from the first timeframe where the sequence number
124
- * is greater than the associated sequence number from the second timeframe.
125
- */
126
- static dependencies(tf1, tf2) {
127
- const result = new _Timeframe();
128
- for (const [hex, entry] of tf1._frames) {
129
- const otherEntry = tf2._frames.get(hex);
130
- if (otherEntry === void 0 || otherEntry.seq < entry.seq) {
131
- result._frames.set(hex, entry);
132
- }
133
- }
134
- return result;
135
- }
136
- };
137
- // Annotate the CommonJS export names for ESM import in node:
138
- 0 && (module.exports = {
139
- Timeframe
140
- });
141
- //# sourceMappingURL=index.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/timeframe.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { equalsSymbol, type Equatable } from '@dxos/debug';\nimport { type PublicKey } from '@dxos/keys';\n\ntype Entry = {\n key: PublicKey;\n seq: number;\n};\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 Map<string, Entry>();\n\n constructor(frames: [PublicKey, number][] = []) {\n for (const [key, seq] of frames) {\n this.set(key, seq);\n }\n }\n\n toJSON(): Record<string, number> {\n return this.frames().reduce((frames: Record<string, number>, [key, seq]) => {\n frames[key.truncate()] = seq;\n return frames;\n }, {});\n }\n\n toString(): string {\n return `(${this.frames()\n .map(([key, seq]) => `${key.truncate()}[${seq}]`)\n .join(', ')})`;\n }\n\n equals(object: Timeframe): boolean {\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): number | undefined {\n return this._frames.get(key.toHex())?.seq;\n }\n\n // TODO(burdon): Rename setFrame.\n set(key: PublicKey, seq: number): void {\n const hex = key.toHex();\n this._frames.set(hex, { key, seq });\n }\n\n // TODO(burdon): Change to getter.\n frames(): [PublicKey, number][] {\n return Array.from(this._frames.values()).map(({ key, seq }) => [key, seq]);\n }\n\n // TODO(burdon): Change to getter.\n size(): number {\n return this._frames.size;\n }\n\n // TODO(burdon): Change to getter (empty).\n isEmpty(): boolean {\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(this.frames().filter(([frameKey]) => keys.every((key) => !key.equals(frameKey))));\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): number {\n return Array.from(this._frames.entries()).reduce(\n (result, [hex, { seq }]) => result + Math.max(seq - (base._frames.get(hex)?.seq ?? -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](): string {\n return `Timeframe${this.toString()}`;\n }\n\n [equalsSymbol](other: any): boolean {\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 [hex, entry] of timeframe._frames) {\n const currentEntry = result._frames.get(hex);\n if (currentEntry === undefined || entry.seq > currentEntry.seq) {\n result._frames.set(hex, entry);\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 [hex, entry] of tf1._frames) {\n const otherEntry = tf2._frames.get(hex);\n if (otherEntry === undefined || otherEntry.seq < entry.seq) {\n result._frames.set(hex, entry);\n }\n }\n\n return result;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,uBAAwB;AAExB,mBAA6C;AAWtC,IAAMA,YAAN,MAAMA,WAAAA;EAGX,YAAYC,SAAgC,CAAA,GAAI;AAF/BC,SAAAA,UAAU,oBAAIC,IAAAA;AAG7B,eAAW,CAACC,KAAKC,GAAAA,KAAQJ,QAAQ;A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D,IAAI9C,QAAQe,IAAIE,GAAAA;AACnC,UAAI8B,eAAeJ,UAAaI,WAAW5C,MAAMsC,MAAMtC,KAAK;AAC1DyB,eAAO5B,QAAQI,IAAIa,KAAKwB,KAAAA;MAC1B;IACF;AAEA,WAAOb;EACT;AACF;",
6
- "names": ["Timeframe", "frames", "_frames", "Map", "key", "seq", "set", "toJSON", "reduce", "truncate", "toString", "map", "join", "equals", "object", "size", "every", "get", "toHex", "hex", "Array", "from", "values", "isEmpty", "withoutKeys", "keys", "filter", "frameKey", "fn", "totalMessages", "result", "newMessages", "base", "entries", "Math", "max", "inspect", "custom", "equalsSymbol", "other", "merge", "timeframes", "timeframe", "entry", "currentEntry", "undefined", "dependencies", "tf1", "tf2", "otherEntry"]
7
- }
@@ -1 +0,0 @@
1
- {"inputs":{"packages/common/timeframe/src/timeframe.ts":{"bytes":13817,"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/debug","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":7155},"packages/common/timeframe/dist/lib/node/index.cjs":{"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true}],"exports":["Timeframe"],"entryPoint":"packages/common/timeframe/src/index.ts","inputs":{"packages/common/timeframe/src/timeframe.ts":{"bytesInOutput":3267},"packages/common/timeframe/src/index.ts":{"bytesInOutput":0}},"bytes":3372}}}