@dxos/echo-protocol 2.33.8-dev.8609bc45 → 2.33.9-dev.e605934d
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/dist/src/feeds/feed-store-iterator.d.ts +1 -1
- package/dist/src/feeds/feed-store-iterator.d.ts.map +1 -1
- package/dist/src/feeds/feed-store-iterator.js +3 -3
- package/dist/src/feeds/feed-store-iterator.js.map +1 -1
- package/dist/src/feeds/feed-store-iterator.test.js +7 -8
- package/dist/src/feeds/feed-store-iterator.test.js.map +1 -1
- package/dist/src/feeds/feed-writer.d.ts.map +1 -1
- package/dist/src/feeds/feed-writer.js +1 -2
- package/dist/src/feeds/feed-writer.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/proto/gen/dxos/credentials.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/feed.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/feed.js.map +1 -1
- package/dist/src/proto/gen/dxos/echo/invitation.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/invitation.js.map +1 -1
- package/dist/src/proto/gen/dxos/echo/metadata.d.ts +6 -5
- package/dist/src/proto/gen/dxos/echo/metadata.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/service.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/snapshot.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/testing.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/timeframe.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.js.map +1 -1
- package/dist/src/proto/gen/dxos/test/echo.d.ts +11 -0
- package/dist/src/proto/gen/dxos/test/echo.d.ts.map +1 -0
- package/dist/src/proto/gen/dxos/test/echo.js +3 -0
- package/dist/src/proto/gen/dxos/test/echo.js.map +1 -0
- package/dist/src/proto/gen/google/protobuf.d.ts.map +1 -1
- package/dist/src/proto/gen/index.d.ts +4 -0
- package/dist/src/proto/gen/index.d.ts.map +1 -1
- package/dist/src/proto/gen/index.js +1 -1
- package/dist/src/proto/gen/index.js.map +1 -1
- package/dist/src/proto/index.d.ts +3 -3
- package/dist/src/proto/index.d.ts.map +1 -1
- package/dist/src/proto/index.js +3 -3
- package/dist/src/proto/index.js.map +1 -1
- package/dist/src/proto/messages.d.ts +1 -1
- package/dist/src/proto/messages.d.ts.map +1 -1
- package/dist/src/proto/messages.js +1 -1
- package/dist/src/proto/messages.js.map +1 -1
- package/dist/src/proto/substitutions.d.ts +2 -2
- package/dist/src/proto/substitutions.d.ts.map +1 -1
- package/dist/src/proto/substitutions.js +1 -2
- package/dist/src/proto/substitutions.js.map +1 -1
- package/dist/src/types.d.ts +1 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/feeds/feed-store-iterator.test.ts +4 -5
- package/src/feeds/feed-store-iterator.ts +4 -5
- package/src/feeds/feed-writer.ts +1 -2
- package/src/index.ts +0 -1
- package/src/proto/defs/import.proto +5 -3
- package/src/proto/gen/dxos/credentials.ts +1 -0
- package/src/proto/gen/dxos/echo/feed.ts +1 -0
- package/src/proto/gen/dxos/echo/invitation.ts +1 -0
- package/src/proto/gen/dxos/echo/metadata.ts +7 -5
- package/src/proto/gen/dxos/echo/service.ts +1 -0
- package/src/proto/gen/dxos/echo/snapshot.ts +1 -0
- package/src/proto/gen/dxos/echo/testing.ts +1 -0
- package/src/proto/gen/dxos/echo/timeframe.ts +1 -0
- package/src/proto/gen/dxos/halo/keys.ts +1 -0
- package/src/proto/gen/dxos/test/echo.ts +22 -0
- package/src/proto/gen/google/protobuf.ts +1 -0
- package/src/proto/gen/index.ts +5 -1
- package/src/proto/index.ts +4 -3
- package/src/proto/messages.ts +3 -2
- package/src/proto/substitutions.ts +1 -3
- package/src/types.ts +1 -2
- package/dist/src/spacetime/index.d.ts +0 -3
- package/dist/src/spacetime/index.d.ts.map +0 -1
- package/dist/src/spacetime/index.js +0 -22
- package/dist/src/spacetime/index.js.map +0 -1
- package/dist/src/spacetime/substitutions.d.ts +0 -13
- package/dist/src/spacetime/substitutions.d.ts.map +0 -1
- package/dist/src/spacetime/substitutions.js +0 -22
- package/dist/src/spacetime/substitutions.js.map +0 -1
- package/dist/src/spacetime/timeframe.d.ts +0 -45
- package/dist/src/spacetime/timeframe.d.ts.map +0 -1
- package/dist/src/spacetime/timeframe.js +0 -102
- package/dist/src/spacetime/timeframe.js.map +0 -1
- package/dist/src/spacetime/timeframe.test.d.ts +0 -2
- package/dist/src/spacetime/timeframe.test.d.ts.map +0 -1
- package/dist/src/spacetime/timeframe.test.js +0 -118
- package/dist/src/spacetime/timeframe.test.js.map +0 -1
- package/src/spacetime/index.ts +0 -6
- package/src/spacetime/substitutions.ts +0 -20
- package/src/spacetime/timeframe.test.ts +0 -132
- package/src/spacetime/timeframe.ts +0 -120
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2020 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const debug_1 = __importDefault(require("debug"));
|
|
10
|
-
const crypto_1 = require("@dxos/crypto");
|
|
11
|
-
const protocols_1 = require("@dxos/protocols");
|
|
12
|
-
const timeframe_1 = require("./timeframe");
|
|
13
|
-
const log = (0, debug_1.default)('dxos:echo:spacetime:test');
|
|
14
|
-
const createFeedKey = () => {
|
|
15
|
-
const { publicKey } = (0, crypto_1.createKeyPair)();
|
|
16
|
-
return protocols_1.PublicKey.from(publicKey);
|
|
17
|
-
};
|
|
18
|
-
describe('spacetime', () => {
|
|
19
|
-
test('constructors', () => {
|
|
20
|
-
const feedKey = createFeedKey();
|
|
21
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey, 1]]);
|
|
22
|
-
log(tf1.toString());
|
|
23
|
-
expect(tf1).toBeTruthy();
|
|
24
|
-
});
|
|
25
|
-
test('merge/subtract', () => {
|
|
26
|
-
const feedKey1 = createFeedKey();
|
|
27
|
-
const feedKey2 = createFeedKey();
|
|
28
|
-
const feedKey3 = createFeedKey();
|
|
29
|
-
{
|
|
30
|
-
// Merge.
|
|
31
|
-
const tf1 = new timeframe_1.Timeframe();
|
|
32
|
-
const tf2 = new timeframe_1.Timeframe([[feedKey1, 2], [feedKey2, 1]]);
|
|
33
|
-
const tf3 = timeframe_1.Timeframe.merge(tf1, tf2);
|
|
34
|
-
expect(tf3.frames()).toHaveLength(2);
|
|
35
|
-
}
|
|
36
|
-
{
|
|
37
|
-
// Merge (no change).
|
|
38
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey1, 1], [feedKey2, 1]]);
|
|
39
|
-
const tf2 = new timeframe_1.Timeframe([[feedKey1, 2], [feedKey3, 1]]);
|
|
40
|
-
const tf3 = timeframe_1.Timeframe.merge(tf1, tf2);
|
|
41
|
-
expect(tf3.frames()).toHaveLength(3);
|
|
42
|
-
}
|
|
43
|
-
{
|
|
44
|
-
// Merge (no change).
|
|
45
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey1, 1]]);
|
|
46
|
-
const tf2 = new timeframe_1.Timeframe([[feedKey1, 3]]);
|
|
47
|
-
const tf3 = new timeframe_1.Timeframe([[feedKey1, 2]]);
|
|
48
|
-
const tf4 = timeframe_1.Timeframe.merge(tf1, tf2, tf3);
|
|
49
|
-
log(tf4.toString());
|
|
50
|
-
expect(tf4.frames()).toHaveLength(1);
|
|
51
|
-
expect(tf4.get(feedKey1)).toBe(3);
|
|
52
|
-
}
|
|
53
|
-
{
|
|
54
|
-
// Remove keys.
|
|
55
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey1, 1], [feedKey2, 2]]);
|
|
56
|
-
const tf2 = tf1.withoutKeys([feedKey1, feedKey3]);
|
|
57
|
-
expect(tf2.frames()).toHaveLength(1);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
test('dependencies', () => {
|
|
61
|
-
const feedKey1 = createFeedKey();
|
|
62
|
-
const feedKey2 = createFeedKey();
|
|
63
|
-
const feedKey3 = createFeedKey();
|
|
64
|
-
{
|
|
65
|
-
const tf1 = new timeframe_1.Timeframe();
|
|
66
|
-
const tf2 = new timeframe_1.Timeframe();
|
|
67
|
-
const tf3 = timeframe_1.Timeframe.dependencies(tf1, tf2);
|
|
68
|
-
log(tf3.toString());
|
|
69
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
70
|
-
}
|
|
71
|
-
{
|
|
72
|
-
const tf1 = new timeframe_1.Timeframe();
|
|
73
|
-
const tf2 = new timeframe_1.Timeframe([[feedKey1, 10], [feedKey2, 11]]);
|
|
74
|
-
const tf3 = timeframe_1.Timeframe.dependencies(tf1, tf2);
|
|
75
|
-
log(tf3.toString());
|
|
76
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
77
|
-
}
|
|
78
|
-
{
|
|
79
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey1, 10], [feedKey2, 10]]);
|
|
80
|
-
const tf2 = new timeframe_1.Timeframe();
|
|
81
|
-
const tf3 = timeframe_1.Timeframe.dependencies(tf1, tf2);
|
|
82
|
-
log(tf3.toString());
|
|
83
|
-
expect(tf3.frames()).toHaveLength(2);
|
|
84
|
-
}
|
|
85
|
-
// TODO(burdon): Test 0.
|
|
86
|
-
{
|
|
87
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey1, 0]]);
|
|
88
|
-
const tf2 = new timeframe_1.Timeframe([[feedKey1, 0]]);
|
|
89
|
-
const tf3 = timeframe_1.Timeframe.dependencies(tf1, tf2);
|
|
90
|
-
log(tf3.toString());
|
|
91
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
92
|
-
}
|
|
93
|
-
{
|
|
94
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey1, 1]]);
|
|
95
|
-
const tf2 = new timeframe_1.Timeframe([[feedKey1, 1]]);
|
|
96
|
-
const tf3 = timeframe_1.Timeframe.dependencies(tf1, tf2);
|
|
97
|
-
log(tf1.toString());
|
|
98
|
-
log(tf2.toString());
|
|
99
|
-
log(tf3.toString());
|
|
100
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
101
|
-
}
|
|
102
|
-
{
|
|
103
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey1, 10], [feedKey2, 10]]);
|
|
104
|
-
const tf2 = new timeframe_1.Timeframe([[feedKey1, 10], [feedKey2, 11]]);
|
|
105
|
-
const tf3 = timeframe_1.Timeframe.dependencies(tf1, tf2);
|
|
106
|
-
log(tf3.toString());
|
|
107
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
108
|
-
}
|
|
109
|
-
{
|
|
110
|
-
const tf1 = new timeframe_1.Timeframe([[feedKey1, 10], [feedKey2, 10], [feedKey3, 10]]);
|
|
111
|
-
const tf2 = new timeframe_1.Timeframe([[feedKey1, 10], [feedKey2, 9]]);
|
|
112
|
-
const tf3 = timeframe_1.Timeframe.dependencies(tf1, tf2);
|
|
113
|
-
log(tf3.toString());
|
|
114
|
-
expect(tf3.frames()).toHaveLength(2);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
//# sourceMappingURL=timeframe.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timeframe.test.js","sourceRoot":"","sources":["../../../src/spacetime/timeframe.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;AAEF,kDAA0B;AAE1B,yCAA6C;AAC7C,+CAA4C;AAE5C,2CAAwC;AAExC,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,0BAA0B,CAAC,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-
import { Timeframe } from './timeframe';
|
|
8
|
-
|
|
9
|
-
export const timeframeSubstitutions = {
|
|
10
|
-
'dxos.echo.timeframe.TimeframeVector': {
|
|
11
|
-
encode: (timeframe: Timeframe) => ({
|
|
12
|
-
frames: timeframe.frames().map(([feedKey, seq]) => ({ feedKey: feedKey.asUint8Array(), seq }))
|
|
13
|
-
}),
|
|
14
|
-
decode: (vector: any) => new Timeframe(
|
|
15
|
-
(vector.frames ?? [])
|
|
16
|
-
.filter((frame: any) => frame.feedKey != null && frame.seq != null)
|
|
17
|
-
.map((frame: any) => [PublicKey.from(new Uint8Array(frame.feedKey)), frame.seq])
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
};
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2020 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import debug from 'debug';
|
|
6
|
-
|
|
7
|
-
import { createKeyPair } from '@dxos/crypto';
|
|
8
|
-
import { PublicKey } from '@dxos/protocols';
|
|
9
|
-
|
|
10
|
-
import { Timeframe } from './timeframe';
|
|
11
|
-
|
|
12
|
-
const log = debug('dxos:echo:spacetime:test');
|
|
13
|
-
|
|
14
|
-
const createFeedKey = () => {
|
|
15
|
-
const { publicKey } = createKeyPair();
|
|
16
|
-
return PublicKey.from(publicKey);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe('spacetime', () => {
|
|
20
|
-
test('constructors', () => {
|
|
21
|
-
const feedKey = createFeedKey();
|
|
22
|
-
|
|
23
|
-
const tf1 = new Timeframe([[feedKey, 1]]);
|
|
24
|
-
log(tf1.toString());
|
|
25
|
-
expect(tf1).toBeTruthy();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('merge/subtract', () => {
|
|
29
|
-
const feedKey1 = createFeedKey();
|
|
30
|
-
const feedKey2 = createFeedKey();
|
|
31
|
-
const feedKey3 = createFeedKey();
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
// Merge.
|
|
35
|
-
const tf1 = new Timeframe();
|
|
36
|
-
const tf2 = new Timeframe([[feedKey1, 2], [feedKey2, 1]]);
|
|
37
|
-
const tf3 = Timeframe.merge(tf1, tf2);
|
|
38
|
-
expect(tf3.frames()).toHaveLength(2);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
// Merge (no change).
|
|
43
|
-
const tf1 = new Timeframe([[feedKey1, 1], [feedKey2, 1]]);
|
|
44
|
-
const tf2 = new Timeframe([[feedKey1, 2], [feedKey3, 1]]);
|
|
45
|
-
const tf3 = Timeframe.merge(tf1, tf2);
|
|
46
|
-
expect(tf3.frames()).toHaveLength(3);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
{
|
|
50
|
-
// Merge (no change).
|
|
51
|
-
const tf1 = new Timeframe([[feedKey1, 1]]);
|
|
52
|
-
const tf2 = new Timeframe([[feedKey1, 3]]);
|
|
53
|
-
const tf3 = new Timeframe([[feedKey1, 2]]);
|
|
54
|
-
const tf4 = Timeframe.merge(tf1, tf2, tf3);
|
|
55
|
-
log(tf4.toString());
|
|
56
|
-
expect(tf4.frames()).toHaveLength(1);
|
|
57
|
-
expect(tf4.get(feedKey1)).toBe(3);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
// Remove keys.
|
|
62
|
-
const tf1 = new Timeframe([[feedKey1, 1], [feedKey2, 2]]);
|
|
63
|
-
const tf2 = tf1.withoutKeys([feedKey1, feedKey3]);
|
|
64
|
-
expect(tf2.frames()).toHaveLength(1);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('dependencies', () => {
|
|
69
|
-
const feedKey1 = createFeedKey();
|
|
70
|
-
const feedKey2 = createFeedKey();
|
|
71
|
-
const feedKey3 = createFeedKey();
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
const tf1 = new Timeframe();
|
|
75
|
-
const tf2 = new Timeframe();
|
|
76
|
-
const tf3 = Timeframe.dependencies(tf1, tf2);
|
|
77
|
-
log(tf3.toString());
|
|
78
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
{
|
|
82
|
-
const tf1 = new Timeframe();
|
|
83
|
-
const tf2 = new Timeframe([[feedKey1, 10], [feedKey2, 11]]);
|
|
84
|
-
const tf3 = Timeframe.dependencies(tf1, tf2);
|
|
85
|
-
log(tf3.toString());
|
|
86
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
const tf1 = new Timeframe([[feedKey1, 10], [feedKey2, 10]]);
|
|
91
|
-
const tf2 = new Timeframe();
|
|
92
|
-
const tf3 = Timeframe.dependencies(tf1, tf2);
|
|
93
|
-
log(tf3.toString());
|
|
94
|
-
expect(tf3.frames()).toHaveLength(2);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// TODO(burdon): Test 0.
|
|
98
|
-
{
|
|
99
|
-
const tf1 = new Timeframe([[feedKey1, 0]]);
|
|
100
|
-
const tf2 = new Timeframe([[feedKey1, 0]]);
|
|
101
|
-
const tf3 = Timeframe.dependencies(tf1, tf2);
|
|
102
|
-
log(tf3.toString());
|
|
103
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
{
|
|
107
|
-
const tf1 = new Timeframe([[feedKey1, 1]]);
|
|
108
|
-
const tf2 = new Timeframe([[feedKey1, 1]]);
|
|
109
|
-
const tf3 = Timeframe.dependencies(tf1, tf2);
|
|
110
|
-
log(tf1.toString());
|
|
111
|
-
log(tf2.toString());
|
|
112
|
-
log(tf3.toString());
|
|
113
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
{
|
|
117
|
-
const tf1 = new Timeframe([[feedKey1, 10], [feedKey2, 10]]);
|
|
118
|
-
const tf2 = new Timeframe([[feedKey1, 10], [feedKey2, 11]]);
|
|
119
|
-
const tf3 = Timeframe.dependencies(tf1, tf2);
|
|
120
|
-
log(tf3.toString());
|
|
121
|
-
expect(tf3.frames()).toHaveLength(0);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
{
|
|
125
|
-
const tf1 = new Timeframe([[feedKey1, 10], [feedKey2, 10], [feedKey3, 10]]);
|
|
126
|
-
const tf2 = new Timeframe([[feedKey1, 10], [feedKey2, 9]]);
|
|
127
|
-
const tf3 = Timeframe.dependencies(tf1, tf2);
|
|
128
|
-
log(tf3.toString());
|
|
129
|
-
expect(tf3.frames()).toHaveLength(2);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2020 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { inspect } from 'util';
|
|
6
|
-
|
|
7
|
-
import { humanize } from '@dxos/crypto';
|
|
8
|
-
import { ComplexMap } from '@dxos/util';
|
|
9
|
-
|
|
10
|
-
import { FeedKey } from '../types';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A mapping of feed key to a sequence number on that feed.
|
|
14
|
-
* Describes how many messages have been processed.
|
|
15
|
-
*/
|
|
16
|
-
export class Timeframe {
|
|
17
|
-
private readonly _frames = new ComplexMap<FeedKey, number>(key => key.asUint8Array().toString());
|
|
18
|
-
|
|
19
|
-
constructor (frames: [FeedKey, number][] = []) {
|
|
20
|
-
for (const [key, seq] of frames) {
|
|
21
|
-
this._frames.set(key, seq);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get (key: FeedKey) {
|
|
26
|
-
return this._frames.get(key);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
set (key: FeedKey, value: number) {
|
|
30
|
-
this._frames.set(key, value);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// TODO(burdon): Change to getter.
|
|
34
|
-
frames (): [FeedKey, number][] {
|
|
35
|
-
return Array.from(this._frames.entries());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// TODO(burdon): Change to getter.
|
|
39
|
-
size () {
|
|
40
|
-
return this._frames.size;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// TODO(burdon): Change to getter (empty).
|
|
44
|
-
isEmpty () {
|
|
45
|
-
return this.size() === 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Returns a new timeframe with specified keys removed.
|
|
50
|
-
* @param keys
|
|
51
|
-
*/
|
|
52
|
-
withoutKeys (keys: FeedKey[]): Timeframe {
|
|
53
|
-
return new Timeframe(this.frames().filter(([frameKey]) => keys.every(key =>
|
|
54
|
-
Buffer.compare(key.asBuffer(), frameKey.asBuffer()) !== 0)));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns a total amount of messages represented by this timeframe.
|
|
59
|
-
*/
|
|
60
|
-
totalMessages (): number {
|
|
61
|
-
return Array.from(this._frames.values()).reduce((acc, seq) => acc + seq + 1, 0);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
toJSON () {
|
|
65
|
-
return this.frames().reduce((frames: Record<string, number>, [key, seq]) => {
|
|
66
|
-
frames[humanize(key)] = seq;
|
|
67
|
-
return frames;
|
|
68
|
-
}, {});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
toString () {
|
|
72
|
-
return `(${this.frames().map(([key, seq]) => `${humanize(key)} => ${seq}`).join(', ')})`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Used by NodeJS to get textual representation of this object when it's printed with a `console.log` statement.
|
|
77
|
-
*/
|
|
78
|
-
[inspect.custom] () {
|
|
79
|
-
return `Timeframe${this.toString()}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Merges the values, updating the highest sequence numbers.
|
|
84
|
-
* @param timeframes
|
|
85
|
-
*/
|
|
86
|
-
static merge (...timeframes: Timeframe[]): Timeframe {
|
|
87
|
-
const result = new Timeframe();
|
|
88
|
-
for (const timeframe of timeframes) {
|
|
89
|
-
for (const [key, seq] of timeframe.frames()) {
|
|
90
|
-
const current = result.get(key);
|
|
91
|
-
if (current === undefined || seq > current) {
|
|
92
|
-
result.set(key, seq);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Compares two timeframes and returns an array of frames from the first timeframe where the sequence number
|
|
102
|
-
* is greater than the associated sequence number from the second timeframe.
|
|
103
|
-
*
|
|
104
|
-
* @param tf1
|
|
105
|
-
* @param tf2
|
|
106
|
-
*/
|
|
107
|
-
static dependencies (
|
|
108
|
-
tf1: Timeframe, tf2: Timeframe
|
|
109
|
-
): Timeframe {
|
|
110
|
-
const result = new Timeframe();
|
|
111
|
-
for (const [key, seq] of tf1.frames()) {
|
|
112
|
-
const otherSeq = tf2.get(key);
|
|
113
|
-
if (otherSeq === undefined || otherSeq < seq) {
|
|
114
|
-
result.set(key, seq);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
}
|