@dxos/echo-pipeline 0.1.31 → 0.1.32-next.77d513e
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/lib/browser/{chunk-QMDRF3NL.mjs → chunk-EM5HSJ7J.mjs} +121 -86
- package/dist/lib/browser/chunk-EM5HSJ7J.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -5
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +12 -4
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +121 -87
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +126 -76
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/metadata/metadata-store.d.ts +1 -2
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts +10 -1
- package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/types/src/space/{data-pipeline-controller.d.ts → data-pipeline.d.ts} +10 -18
- package/dist/types/src/space/data-pipeline.d.ts.map +1 -0
- package/dist/types/src/space/index.d.ts +1 -1
- package/dist/types/src/space/index.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts +6 -4
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts +2 -2
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +2 -2
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/package.json +29 -29
- package/src/metadata/metadata-store.ts +1 -2
- package/src/pipeline/pipeline.ts +18 -3
- package/src/space/{data-pipeline-controller.ts → data-pipeline.ts} +61 -38
- package/src/space/index.ts +1 -1
- package/src/space/space.ts +22 -23
- package/src/testing/test-agent-builder.ts +10 -4
- package/src/testing/util.ts +2 -5
- package/dist/lib/browser/chunk-QMDRF3NL.mjs.map +0 -7
- package/dist/types/src/space/data-pipeline-controller.d.ts.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { PublicKey } from '@dxos/keys';
|
|
2
|
-
import { SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
3
|
-
import { IdentityRecord } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
2
|
+
import { SpaceMetadata, IdentityRecord } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
4
3
|
import { Directory } from '@dxos/random-access-storage';
|
|
5
4
|
import { Timeframe } from '@dxos/timeframe';
|
|
6
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-store.d.ts","sourceRoot":"","sources":["../../../../src/metadata/metadata-store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAgB,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"metadata-store.d.ts","sourceRoot":"","sources":["../../../../src/metadata/metadata-store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAgB,aAAa,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,SAAS,CAAC;IACf,WAAW,EAAE,SAAS,CAAC;CACxB;AASD,qBAAa,aAAa;IAKtB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJ7B,OAAO,CAAC,SAAS,CAAqC;gBAInC,UAAU,EAAE,SAAS;IAGxC,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,aAAa,EAAE,CAE5B;IAED;;OAEG;IAEG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YA6Bb,KAAK;IAwBnB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B,iBAAiB,IAAI,cAAc,GAAG,SAAS;IAIzC,iBAAiB,CAAC,MAAM,EAAE,cAAc;IAOxC,QAAQ,CAAC,MAAM,EAAE,aAAa;IAU9B,uBAAuB,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;IAQjE,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM;IAQtD,mBAAmB,CAAC,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS;CAQjG"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
+
import { Context } from '@dxos/context';
|
|
1
2
|
import { FeedSetIterator, FeedWrapper, FeedWriter } from '@dxos/feed-store';
|
|
2
3
|
import { FeedMessageBlock } from '@dxos/protocols';
|
|
3
4
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
4
5
|
import { Timeframe } from '@dxos/timeframe';
|
|
5
6
|
import { TimeframeClock } from './timeframe-clock';
|
|
6
7
|
export declare type WaitUntilReachedTargetParams = {
|
|
8
|
+
/**
|
|
9
|
+
* For cancellation.
|
|
10
|
+
*/
|
|
11
|
+
ctx?: Context;
|
|
7
12
|
timeout?: number;
|
|
13
|
+
/**
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
breakOnStall?: boolean;
|
|
8
17
|
};
|
|
9
18
|
/**
|
|
10
19
|
* External state accessor.
|
|
@@ -35,7 +44,7 @@ export declare class PipelineState {
|
|
|
35
44
|
*
|
|
36
45
|
* @param timeout Timeout in milliseconds to specify the maximum wait time.
|
|
37
46
|
*/
|
|
38
|
-
waitUntilReachedTargetTimeframe({ timeout }?: WaitUntilReachedTargetParams): Promise<void>;
|
|
47
|
+
waitUntilReachedTargetTimeframe({ ctx, timeout, breakOnStall }?: WaitUntilReachedTargetParams): Promise<void>;
|
|
39
48
|
}
|
|
40
49
|
export interface PipelineAccessor {
|
|
41
50
|
state: PipelineState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../../../src/pipeline/pipeline.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAwD,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEzG,oBAAY,4BAA4B,GAAG;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../../../src/pipeline/pipeline.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAmB,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAwD,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEzG,oBAAY,4BAA4B,GAAG;IACzC;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;GAEG;A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IAI5C,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,WAAW,CAAC;IAarC,KAAK;IAML,IAAI;IAOV;;;OAGG;IACI,OAAO,IAAI,aAAa,CAAC,gBAAgB,CAAC;CAelD"}
|
|
@@ -8,22 +8,10 @@ import { Timeframe } from '@dxos/timeframe';
|
|
|
8
8
|
import { DatabaseBackendHost, SnapshotManager } from '../dbhost';
|
|
9
9
|
import { MetadataStore } from '../metadata';
|
|
10
10
|
import { Pipeline } from '../pipeline';
|
|
11
|
-
export
|
|
11
|
+
export interface PipelineFactory {
|
|
12
12
|
openPipeline: (start: Timeframe) => Promise<Pipeline>;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Controls data pipeline in the space.
|
|
16
|
-
* Consumes mutations from the feed and applies them to the database.
|
|
17
|
-
*/
|
|
18
|
-
export interface DataPipelineController {
|
|
19
|
-
open(context: DataPipelineControllerContext): Promise<void>;
|
|
20
|
-
close(): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
export declare class NoopDataPipelineController implements DataPipelineController {
|
|
23
|
-
open(context: DataPipelineControllerContext): Promise<void>;
|
|
24
|
-
close(): Promise<void>;
|
|
25
13
|
}
|
|
26
|
-
export declare type
|
|
14
|
+
export declare type DataPipelineParams = {
|
|
27
15
|
modelFactory: ModelFactory;
|
|
28
16
|
snapshotManager: SnapshotManager;
|
|
29
17
|
metadataStore: MetadataStore;
|
|
@@ -37,21 +25,25 @@ export declare type DataPipelineControllerImplParams = {
|
|
|
37
25
|
* Consumes the pipeline and updates the database.
|
|
38
26
|
* Reacts to new epochs to restart the pipeline.
|
|
39
27
|
*/
|
|
40
|
-
export declare class
|
|
28
|
+
export declare class DataPipeline {
|
|
41
29
|
private readonly _params;
|
|
42
30
|
private _ctx;
|
|
43
31
|
private _spaceContext;
|
|
44
32
|
private _pipeline?;
|
|
45
33
|
private _snapshot?;
|
|
34
|
+
private _targetTimeframe?;
|
|
46
35
|
private _lastAutomaticSnapshotTimeframe;
|
|
36
|
+
private _isOpen;
|
|
47
37
|
readonly onTimeframeReached: Event<Timeframe>;
|
|
48
|
-
constructor(_params:
|
|
38
|
+
constructor(_params: DataPipelineParams);
|
|
49
39
|
_itemManager: ItemManager;
|
|
50
40
|
databaseBackend?: DatabaseBackendHost;
|
|
41
|
+
get isOpen(): boolean;
|
|
51
42
|
get pipelineState(): import("../pipeline/pipeline").PipelineState | undefined;
|
|
52
43
|
get snapshotTimeframe(): Timeframe | undefined;
|
|
53
44
|
getStartTimeframe(): Timeframe;
|
|
54
|
-
|
|
45
|
+
setTargetTimeframe(timeframe: Timeframe): void;
|
|
46
|
+
open(spaceContext: PipelineFactory): Promise<void>;
|
|
55
47
|
private _createPeriodicSnapshots;
|
|
56
48
|
private _saveSnapshot;
|
|
57
49
|
private _saveLatestTimeframe;
|
|
@@ -60,4 +52,4 @@ export declare class DataPipelineControllerImpl implements DataPipelineControlle
|
|
|
60
52
|
private _consumePipeline;
|
|
61
53
|
waitUntilTimeframe(timeframe: Timeframe): Promise<void>;
|
|
62
54
|
}
|
|
63
|
-
//# sourceMappingURL=data-pipeline
|
|
55
|
+
//# sourceMappingURL=data-pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-pipeline.d.ts","sourceRoot":"","sources":["../../../../src/space/data-pipeline.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAA0C,MAAM,aAAa,CAAC;AAE5E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,eAA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AU5B,KAAK;IAoBX,cAAc,IAAI,aAAa;YASjB,gBAAgB;IA+BxB,kBAAkB,CAAC,SAAS,EAAE,SAAS;CAI9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/space/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/space/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
|
|
@@ -4,9 +4,9 @@ import { FeedWrapper } from '@dxos/feed-store';
|
|
|
4
4
|
import { PublicKey } from '@dxos/keys';
|
|
5
5
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
6
6
|
import { Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
7
|
+
import { Timeframe } from '@dxos/timeframe';
|
|
7
8
|
import { AsyncCallback, Callback } from '@dxos/util';
|
|
8
|
-
import { PipelineAccessor } from '../pipeline';
|
|
9
|
-
import { DataPipelineController } from './data-pipeline-controller';
|
|
9
|
+
import { Pipeline, PipelineAccessor } from '../pipeline';
|
|
10
10
|
import { SpaceProtocol } from './space-protocol';
|
|
11
11
|
declare type FeedProvider = (feedKey: PublicKey) => Promise<FeedWrapper<FeedMessage>>;
|
|
12
12
|
export declare type SpaceParams = {
|
|
@@ -15,6 +15,9 @@ export declare type SpaceParams = {
|
|
|
15
15
|
genesisFeed: FeedWrapper<FeedMessage>;
|
|
16
16
|
feedProvider: FeedProvider;
|
|
17
17
|
};
|
|
18
|
+
export declare type CreatePipelineParams = {
|
|
19
|
+
start: Timeframe;
|
|
20
|
+
};
|
|
18
21
|
/**
|
|
19
22
|
* Spaces are globally addressable databases with access control.
|
|
20
23
|
*/
|
|
@@ -30,7 +33,6 @@ export declare class Space {
|
|
|
30
33
|
private _controlFeed?;
|
|
31
34
|
private _dataFeed?;
|
|
32
35
|
private _dataPipeline?;
|
|
33
|
-
private _dataPipelineController?;
|
|
34
36
|
constructor({ spaceKey, protocol, genesisFeed, feedProvider }: SpaceParams);
|
|
35
37
|
get key(): PublicKey;
|
|
36
38
|
get isOpen(): boolean;
|
|
@@ -53,7 +55,7 @@ export declare class Space {
|
|
|
53
55
|
*/
|
|
54
56
|
open(): Promise<void>;
|
|
55
57
|
close(): Promise<void>;
|
|
56
|
-
|
|
58
|
+
createDataPipeline({ start }: CreatePipelineParams): Promise<Pipeline>;
|
|
57
59
|
}
|
|
58
60
|
export {};
|
|
59
61
|
//# sourceMappingURL=space.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../../../../src/space/space.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAA4B,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAgB,UAAU,EAAE,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../../../../src/space/space.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAA4B,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,E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B,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,WAAW;IAgC1E,IACI,GAAG,cAEN;IAED,IAAI,MAAM,YAET;IAED,IAAI,cAAc,IAAI,SAAS,CAE9B;IAED,IAAI,cAAc,0BAEjB;IAED,IAAI,WAAW,0BAEd;IAED,IAAI,UAAU,2CAEb;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,gBAAgB,CAEtC;IAED,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,WAAW,CAAC;IAO7C,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,WAAW,CAAC;IAO1C;;OAEG;IACH,eAAe,IAAI,QAAQ,EAAE;IAI7B;;OAEG;IAKG,IAAI;IAeJ,KAAK;IAeL,kBAAkB,CAAC,EAAE,KAAK,EAAE,EAAE,oBAAoB;CAoBzD"}
|
|
@@ -7,7 +7,7 @@ import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
|
7
7
|
import { Storage } from '@dxos/random-access-storage';
|
|
8
8
|
import { Gossip, Presence } from '@dxos/teleport-extension-gossip';
|
|
9
9
|
import { Space, SpaceManager, SpaceProtocol } from '../space';
|
|
10
|
-
import {
|
|
10
|
+
import { DataPipeline } from '../space/data-pipeline';
|
|
11
11
|
import { TestFeedBuilder } from './test-feed-builder';
|
|
12
12
|
export declare type NetworkManagerProvider = () => NetworkManager;
|
|
13
13
|
export declare const MemoryNetworkManagerProvider: (signalContext: MemorySignalManagerContext) => NetworkManagerProvider;
|
|
@@ -45,7 +45,7 @@ export declare class TestAgent {
|
|
|
45
45
|
get spaces(): Space[];
|
|
46
46
|
getSpace(spaceKey: PublicKey): Space | undefined;
|
|
47
47
|
createSpaceManager(): SpaceManager;
|
|
48
|
-
createSpace(identityKey?: PublicKey, spaceKey?: PublicKey, genesisKey?: PublicKey): Promise<[Space,
|
|
48
|
+
createSpace(identityKey?: PublicKey, spaceKey?: PublicKey, genesisKey?: PublicKey): Promise<[Space, DataPipeline]>;
|
|
49
49
|
createSpaceProtocol(topic: PublicKey, gossip?: Gossip): SpaceProtocol;
|
|
50
50
|
createGossip(): Gossip;
|
|
51
51
|
createPresence(gossip?: Gossip): Presence;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-agent-builder.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-agent-builder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAuB,0BAA0B,EAA0B,MAAM,iBAAiB,CAAC;AAE1G,OAAO,EAAwD,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAiB,OAAO,EAAe,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAKnE,OAAO,EAA0C,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACtG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"test-agent-builder.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-agent-builder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAuB,0BAA0B,EAA0B,MAAM,iBAAiB,CAAC;AAE1G,OAAO,EAAwD,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAiB,OAAO,EAAe,MAAM,6BAA6B,CAAC;AACl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AW,EAAE,SAAS,EACtB,SAAS,EAAE,SAAS;IAMhC,KAAK;IAIX,IAAI,MAAM,YAET;IAED,QAAQ,CAAC,QAAQ,EAAE,SAAS;IAI5B,kBAAkB;IAOZ,WAAW,CACf,WAAW,GAAE,SAA4B,EACzC,QAAQ,CAAC,EAAE,SAAS,EACpB,UAAU,CAAC,EAAE,SAAS,GACrB,OAAO,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IA6CjC,mBAAmB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM;IAkBrD,YAAY;IAMZ,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM;CAQ/B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DatabaseBackendProxy, ItemManager } from '@dxos/echo-db';
|
|
2
2
|
import { ModelFactory } from '@dxos/model-factory';
|
|
3
3
|
import { DatabaseBackendHost, DataServiceHost } from '../dbhost';
|
|
4
|
-
import {
|
|
4
|
+
import { DataPipeline } from '../space';
|
|
5
5
|
export declare const createMemoryDatabase: (modelFactory: ModelFactory) => Promise<{
|
|
6
6
|
backend: DatabaseBackendHost;
|
|
7
7
|
itemManager: ItemManager;
|
|
@@ -10,5 +10,5 @@ export declare const createRemoteDatabaseFromDataServiceHost: (modelFactory: Mod
|
|
|
10
10
|
itemManager: ItemManager;
|
|
11
11
|
backend: DatabaseBackendProxy;
|
|
12
12
|
}>;
|
|
13
|
-
export declare const testLocalDatabase: (create:
|
|
13
|
+
export declare const testLocalDatabase: (create: DataPipeline, check?: DataPipeline) => Promise<void>;
|
|
14
14
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/testing/util.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAA6C,MAAM,WAAW,CAAC;AAC5G,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/testing/util.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAA6C,MAAM,WAAW,CAAC;AAC5G,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,eAAO,MAAM,oBAAoB,iBAAwB,YAAY;;;EAqBpE,CAAC;AAEF,eAAO,MAAM,uCAAuC,iBACpC,YAAY,mBACT,eAAe;;;EAejC,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAkB,YAAY,UAAS,YAAY,kBAmBhF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-pipeline",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.32-next.77d513e",
|
|
4
4
|
"description": "ECHO database.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -20,40 +20,40 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"debug": "^4.3.3",
|
|
23
|
-
"@dxos/async": "0.1.
|
|
24
|
-
"@dxos/codec-protobuf": "0.1.
|
|
25
|
-
"@dxos/context": "0.1.
|
|
26
|
-
"@dxos/credentials": "0.1.
|
|
27
|
-
"@dxos/crypto": "0.1.
|
|
28
|
-
"@dxos/debug": "0.1.
|
|
29
|
-
"@dxos/document-model": "0.1.
|
|
30
|
-
"@dxos/echo-db": "0.1.
|
|
31
|
-
"@dxos/feed-store": "0.1.
|
|
32
|
-
"@dxos/hypercore": "0.1.
|
|
33
|
-
"@dxos/keyring": "0.1.
|
|
34
|
-
"@dxos/keys": "0.1.
|
|
35
|
-
"@dxos/log": "0.1.
|
|
36
|
-
"@dxos/messaging": "0.1.
|
|
37
|
-
"@dxos/model-factory": "0.1.
|
|
38
|
-
"@dxos/network-manager": "0.1.
|
|
39
|
-
"@dxos/node-std": "0.1.
|
|
40
|
-
"@dxos/protocols": "0.1.
|
|
41
|
-
"@dxos/random-access-storage": "0.1.
|
|
42
|
-
"@dxos/rpc": "0.1.
|
|
43
|
-
"@dxos/teleport": "0.1.
|
|
44
|
-
"@dxos/teleport-extension-gossip": "0.1.
|
|
45
|
-
"@dxos/teleport-extension-object-sync": "0.1.
|
|
46
|
-
"@dxos/teleport-extension-replicator": "0.1.
|
|
47
|
-
"@dxos/timeframe": "0.1.
|
|
48
|
-
"@dxos/typings": "0.1.
|
|
49
|
-
"@dxos/util": "0.1.
|
|
23
|
+
"@dxos/async": "0.1.32-next.77d513e",
|
|
24
|
+
"@dxos/codec-protobuf": "0.1.32-next.77d513e",
|
|
25
|
+
"@dxos/context": "0.1.32-next.77d513e",
|
|
26
|
+
"@dxos/credentials": "0.1.32-next.77d513e",
|
|
27
|
+
"@dxos/crypto": "0.1.32-next.77d513e",
|
|
28
|
+
"@dxos/debug": "0.1.32-next.77d513e",
|
|
29
|
+
"@dxos/document-model": "0.1.32-next.77d513e",
|
|
30
|
+
"@dxos/echo-db": "0.1.32-next.77d513e",
|
|
31
|
+
"@dxos/feed-store": "0.1.32-next.77d513e",
|
|
32
|
+
"@dxos/hypercore": "0.1.32-next.77d513e",
|
|
33
|
+
"@dxos/keyring": "0.1.32-next.77d513e",
|
|
34
|
+
"@dxos/keys": "0.1.32-next.77d513e",
|
|
35
|
+
"@dxos/log": "0.1.32-next.77d513e",
|
|
36
|
+
"@dxos/messaging": "0.1.32-next.77d513e",
|
|
37
|
+
"@dxos/model-factory": "0.1.32-next.77d513e",
|
|
38
|
+
"@dxos/network-manager": "0.1.32-next.77d513e",
|
|
39
|
+
"@dxos/node-std": "0.1.32-next.77d513e",
|
|
40
|
+
"@dxos/protocols": "0.1.32-next.77d513e",
|
|
41
|
+
"@dxos/random-access-storage": "0.1.32-next.77d513e",
|
|
42
|
+
"@dxos/rpc": "0.1.32-next.77d513e",
|
|
43
|
+
"@dxos/teleport": "0.1.32-next.77d513e",
|
|
44
|
+
"@dxos/teleport-extension-gossip": "0.1.32-next.77d513e",
|
|
45
|
+
"@dxos/teleport-extension-object-sync": "0.1.32-next.77d513e",
|
|
46
|
+
"@dxos/teleport-extension-replicator": "0.1.32-next.77d513e",
|
|
47
|
+
"@dxos/timeframe": "0.1.32-next.77d513e",
|
|
48
|
+
"@dxos/typings": "0.1.32-next.77d513e",
|
|
49
|
+
"@dxos/util": "0.1.32-next.77d513e"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/debug": "^4.1.7",
|
|
53
53
|
"hypercore-protocol": "^8.0.7",
|
|
54
54
|
"source-map-support": "^0.5.12",
|
|
55
55
|
"wait-for-expect": "^3.0.2",
|
|
56
|
-
"@dxos/text-model": "0.1.
|
|
56
|
+
"@dxos/text-model": "0.1.32-next.77d513e"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
@@ -8,8 +8,7 @@ import { synchronized } from '@dxos/async';
|
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { schema } from '@dxos/protocols';
|
|
11
|
-
import { EchoMetadata, SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
12
|
-
import { IdentityRecord } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
11
|
+
import { EchoMetadata, SpaceMetadata, IdentityRecord } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
13
12
|
import { Directory } from '@dxos/random-access-storage';
|
|
14
13
|
import { Timeframe } from '@dxos/timeframe';
|
|
15
14
|
|
package/src/pipeline/pipeline.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import assert from 'node:assert';
|
|
6
6
|
|
|
7
7
|
import { sleep, Trigger } from '@dxos/async';
|
|
8
|
+
import { Context, rejectOnDispose } from '@dxos/context';
|
|
8
9
|
import { FeedSetIterator, FeedWrapper, FeedWriter } from '@dxos/feed-store';
|
|
9
10
|
import { PublicKey } from '@dxos/keys';
|
|
10
11
|
import { log } from '@dxos/log';
|
|
@@ -17,7 +18,16 @@ import { createMessageSelector } from './message-selector';
|
|
|
17
18
|
import { mapFeedIndexesToTimeframe, mapTimeframeToFeedIndexes, TimeframeClock } from './timeframe-clock';
|
|
18
19
|
|
|
19
20
|
export type WaitUntilReachedTargetParams = {
|
|
21
|
+
/**
|
|
22
|
+
* For cancellation.
|
|
23
|
+
*/
|
|
24
|
+
ctx?: Context;
|
|
20
25
|
timeout?: number;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
breakOnStall?: boolean;
|
|
21
31
|
};
|
|
22
32
|
|
|
23
33
|
/**
|
|
@@ -60,7 +70,7 @@ export class PipelineState {
|
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
get targetTimeframe() {
|
|
63
|
-
return this._targetTimeframe ?
|
|
73
|
+
return this._targetTimeframe ? this._targetTimeframe : new Timeframe();
|
|
64
74
|
}
|
|
65
75
|
|
|
66
76
|
async waitUntilTimeframe(target: Timeframe) {
|
|
@@ -78,7 +88,11 @@ export class PipelineState {
|
|
|
78
88
|
*
|
|
79
89
|
* @param timeout Timeout in milliseconds to specify the maximum wait time.
|
|
80
90
|
*/
|
|
81
|
-
async waitUntilReachedTargetTimeframe({
|
|
91
|
+
async waitUntilReachedTargetTimeframe({
|
|
92
|
+
ctx = new Context(),
|
|
93
|
+
timeout,
|
|
94
|
+
breakOnStall = true
|
|
95
|
+
}: WaitUntilReachedTargetParams = {}) {
|
|
82
96
|
log('waitUntilReachedTargetTimeframe', {
|
|
83
97
|
timeout,
|
|
84
98
|
current: this.timeframe,
|
|
@@ -89,13 +103,14 @@ export class PipelineState {
|
|
|
89
103
|
this._timeframeClock.update.waitForCondition(() => {
|
|
90
104
|
return Timeframe.dependencies(this.targetTimeframe, this.timeframe).isEmpty();
|
|
91
105
|
}),
|
|
92
|
-
this._iterator.stalled.discardParameter().waitForCount(1)
|
|
106
|
+
...(breakOnStall ? [this._iterator.stalled.discardParameter().waitForCount(1)] : [])
|
|
93
107
|
]);
|
|
94
108
|
|
|
95
109
|
let done = false;
|
|
96
110
|
|
|
97
111
|
if (timeout) {
|
|
98
112
|
return Promise.race([
|
|
113
|
+
rejectOnDispose(ctx),
|
|
99
114
|
this._reachedTargetPromise.then(() => {
|
|
100
115
|
done = true;
|
|
101
116
|
}),
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import assert from 'node:assert';
|
|
6
6
|
|
|
7
|
-
import { Event, scheduleTask, trackLeaks } from '@dxos/async';
|
|
7
|
+
import { Event, scheduleTask, synchronized, trackLeaks } from '@dxos/async';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
9
|
import { FeedInfo } from '@dxos/credentials';
|
|
10
10
|
import { failUndefined } from '@dxos/debug';
|
|
@@ -21,26 +21,11 @@ import { DatabaseBackendHost, SnapshotManager } from '../dbhost';
|
|
|
21
21
|
import { MetadataStore } from '../metadata';
|
|
22
22
|
import { Pipeline } from '../pipeline';
|
|
23
23
|
|
|
24
|
-
export
|
|
24
|
+
export interface PipelineFactory {
|
|
25
25
|
openPipeline: (start: Timeframe) => Promise<Pipeline>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Controls data pipeline in the space.
|
|
30
|
-
* Consumes mutations from the feed and applies them to the database.
|
|
31
|
-
*/
|
|
32
|
-
export interface DataPipelineController {
|
|
33
|
-
open(context: DataPipelineControllerContext): Promise<void>;
|
|
34
|
-
close(): Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class NoopDataPipelineController implements DataPipelineController {
|
|
38
|
-
async open(context: DataPipelineControllerContext): Promise<void> {}
|
|
39
|
-
|
|
40
|
-
async close(): Promise<void> {}
|
|
41
26
|
}
|
|
42
27
|
|
|
43
|
-
export type
|
|
28
|
+
export type DataPipelineParams = {
|
|
44
29
|
modelFactory: ModelFactory;
|
|
45
30
|
snapshotManager: SnapshotManager;
|
|
46
31
|
metadataStore: MetadataStore;
|
|
@@ -65,27 +50,38 @@ const AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL = 5000;
|
|
|
65
50
|
*/
|
|
66
51
|
const TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 500;
|
|
67
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Flag to disable automatic local snapshots.
|
|
55
|
+
*/
|
|
56
|
+
const DISABLE_SNAPSHOT_CACHE = false;
|
|
57
|
+
|
|
68
58
|
/**
|
|
69
59
|
* Controls data pipeline in the space.
|
|
70
60
|
* Consumes the pipeline and updates the database.
|
|
71
61
|
* Reacts to new epochs to restart the pipeline.
|
|
72
62
|
*/
|
|
73
63
|
@trackLeaks('open', 'close')
|
|
74
|
-
export class
|
|
64
|
+
export class DataPipeline {
|
|
75
65
|
private _ctx = new Context();
|
|
76
|
-
private _spaceContext!:
|
|
66
|
+
private _spaceContext!: PipelineFactory;
|
|
77
67
|
private _pipeline?: Pipeline;
|
|
78
68
|
private _snapshot?: SpaceSnapshot;
|
|
69
|
+
private _targetTimeframe?: Timeframe;
|
|
79
70
|
|
|
80
71
|
private _lastAutomaticSnapshotTimeframe = new Timeframe();
|
|
72
|
+
private _isOpen = false;
|
|
81
73
|
|
|
82
74
|
public readonly onTimeframeReached = new Event<Timeframe>();
|
|
83
75
|
|
|
84
|
-
constructor(private readonly _params:
|
|
76
|
+
constructor(private readonly _params: DataPipelineParams) {}
|
|
85
77
|
|
|
86
78
|
public _itemManager!: ItemManager;
|
|
87
79
|
public databaseBackend?: DatabaseBackendHost;
|
|
88
80
|
|
|
81
|
+
get isOpen() {
|
|
82
|
+
return this._isOpen;
|
|
83
|
+
}
|
|
84
|
+
|
|
89
85
|
get pipelineState() {
|
|
90
86
|
return this._pipeline?.state;
|
|
91
87
|
}
|
|
@@ -98,7 +94,17 @@ export class DataPipelineControllerImpl implements DataPipelineController {
|
|
|
98
94
|
return snapshotTimeframeToStartingTimeframe(this.snapshotTimeframe ?? new Timeframe());
|
|
99
95
|
}
|
|
100
96
|
|
|
101
|
-
|
|
97
|
+
setTargetTimeframe(timeframe: Timeframe) {
|
|
98
|
+
this._targetTimeframe = timeframe;
|
|
99
|
+
this._pipeline?.state.setTargetTimeframe(timeframe);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@synchronized
|
|
103
|
+
async open(spaceContext: PipelineFactory) {
|
|
104
|
+
if (this._isOpen) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
this._spaceContext = spaceContext;
|
|
103
109
|
if (this._params.snapshotId) {
|
|
104
110
|
this._snapshot = await this._params.snapshotManager.load(this._params.snapshotId);
|
|
@@ -106,6 +112,9 @@ export class DataPipelineControllerImpl implements DataPipelineController {
|
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
this._pipeline = await this._spaceContext.openPipeline(this.getStartTimeframe());
|
|
115
|
+
if (this._targetTimeframe) {
|
|
116
|
+
this._pipeline.state.setTargetTimeframe(this._targetTimeframe);
|
|
117
|
+
}
|
|
109
118
|
|
|
110
119
|
// Create database backend.
|
|
111
120
|
const feedWriter = createMappedFeedWriter<DataMessage, FeedMessage.Payload>(
|
|
@@ -125,6 +134,8 @@ export class DataPipelineControllerImpl implements DataPipelineController {
|
|
|
125
134
|
});
|
|
126
135
|
|
|
127
136
|
this._createPeriodicSnapshots();
|
|
137
|
+
|
|
138
|
+
this._isOpen = true;
|
|
128
139
|
}
|
|
129
140
|
|
|
130
141
|
private _createPeriodicSnapshots() {
|
|
@@ -133,22 +144,24 @@ export class DataPipelineControllerImpl implements DataPipelineController {
|
|
|
133
144
|
await this._saveLatestTimeframe();
|
|
134
145
|
});
|
|
135
146
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
if (!DISABLE_SNAPSHOT_CACHE) {
|
|
148
|
+
this.onTimeframeReached.debounce(AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL).on(this._ctx, async () => {
|
|
149
|
+
const latestTimeframe = this._pipeline?.state.timeframe;
|
|
150
|
+
if (!latestTimeframe) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
141
153
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
// Save snapshot.
|
|
155
|
+
if (
|
|
156
|
+
latestTimeframe.totalMessages() - this._lastAutomaticSnapshotTimeframe.totalMessages() >
|
|
157
|
+
MESSAGES_PER_SNAPSHOT
|
|
158
|
+
) {
|
|
159
|
+
const snapshot = await this._saveSnapshot();
|
|
160
|
+
this._lastAutomaticSnapshotTimeframe = snapshot.timeframe ?? failUndefined();
|
|
161
|
+
log('save', { snapshot });
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
152
165
|
}
|
|
153
166
|
|
|
154
167
|
private async _saveSnapshot() {
|
|
@@ -160,12 +173,21 @@ export class DataPipelineControllerImpl implements DataPipelineController {
|
|
|
160
173
|
|
|
161
174
|
private async _saveLatestTimeframe() {
|
|
162
175
|
const latestTimeframe = this._pipeline?.state.timeframe;
|
|
176
|
+
log('save latest timeframe', { latestTimeframe, spaceKey: this._params.spaceKey });
|
|
163
177
|
if (latestTimeframe) {
|
|
164
|
-
|
|
178
|
+
const newTimeframe = Timeframe.merge(this._targetTimeframe ?? new Timeframe(), latestTimeframe);
|
|
179
|
+
await this._params.metadataStore.setSpaceLatestTimeframe(this._params.spaceKey, newTimeframe);
|
|
165
180
|
}
|
|
166
181
|
}
|
|
167
182
|
|
|
183
|
+
@synchronized
|
|
168
184
|
async close() {
|
|
185
|
+
if (!this._isOpen) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
log('close');
|
|
189
|
+
this._isOpen = false;
|
|
190
|
+
|
|
169
191
|
try {
|
|
170
192
|
await this._saveLatestTimeframe();
|
|
171
193
|
await this._saveSnapshot();
|
|
@@ -180,6 +202,7 @@ export class DataPipelineControllerImpl implements DataPipelineController {
|
|
|
180
202
|
}
|
|
181
203
|
|
|
182
204
|
createSnapshot(): SpaceSnapshot {
|
|
205
|
+
assert(this.databaseBackend, 'Database backend is not initialized.');
|
|
183
206
|
return {
|
|
184
207
|
spaceKey: this._params.spaceKey.asUint8Array(),
|
|
185
208
|
timeframe: this._pipeline?.state.timeframe ?? new Timeframe(),
|
package/src/space/index.ts
CHANGED