@dxos/feed 0.0.0 → 0.8.4-main.52d7546f51
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/README.md +7 -2
- package/dist/lib/neutral/chunk-UOP2Q6KY.mjs +744 -0
- package/dist/lib/neutral/chunk-UOP2Q6KY.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +17 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/testing/index.mjs +173 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/errors.d.ts +106 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/feed-store.d.ts +86 -0
- package/dist/types/src/feed-store.d.ts.map +1 -0
- package/dist/types/src/feed-store.test.d.ts +2 -0
- package/dist/types/src/feed-store.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/sync-client.d.ts +53 -0
- package/dist/types/src/sync-client.d.ts.map +1 -0
- package/dist/types/src/sync-server.d.ts +27 -0
- package/dist/types/src/sync-server.d.ts.map +1 -0
- package/dist/types/src/sync.test.d.ts +2 -0
- package/dist/types/src/sync.test.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/test-builder.d.ts +78 -0
- package/dist/types/src/testing/test-builder.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +20 -13
- package/src/errors.ts +38 -0
- package/src/feed-store.test.ts +283 -35
- package/src/feed-store.ts +479 -132
- package/src/index.ts +3 -1
- package/src/sync-client.ts +188 -0
- package/src/sync-server.ts +92 -0
- package/src/sync.test.ts +151 -91
- package/src/testing/index.ts +1 -1
- package/src/testing/test-builder.ts +223 -0
- package/src/protocol.ts +0 -110
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type * as SqlClient from '@effect/sql/SqlClient';
|
|
2
|
+
import * as Effect from 'effect/Effect';
|
|
3
|
+
import type { SpaceId } from '@dxos/keys';
|
|
4
|
+
import { type FeedProtocol } from '@dxos/protocols';
|
|
5
|
+
import type { SqlTransaction } from '@dxos/sql-sqlite';
|
|
6
|
+
import type { FeedStore } from './feed-store';
|
|
7
|
+
type ProtocolMessage = FeedProtocol.ProtocolMessage;
|
|
8
|
+
type QueryRequestMessage = Extract<ProtocolMessage, {
|
|
9
|
+
_tag: 'QueryRequest';
|
|
10
|
+
}>;
|
|
11
|
+
type AppendRequestMessage = Extract<ProtocolMessage, {
|
|
12
|
+
_tag: 'AppendRequest';
|
|
13
|
+
}>;
|
|
14
|
+
type RequestMessage = QueryRequestMessage | AppendRequestMessage;
|
|
15
|
+
export type SyncClientOptions = {
|
|
16
|
+
/** This client's peer id. Set as senderPeerId on all requests. */
|
|
17
|
+
peerId: string;
|
|
18
|
+
/** The server's peer id. Set as recipientPeerId on all requests. */
|
|
19
|
+
serverPeerId?: string;
|
|
20
|
+
feedStore: FeedStore;
|
|
21
|
+
/** Send a protocol message to the server. Returns Effect. */
|
|
22
|
+
sendMessage: (message: RequestMessage) => Effect.Effect<void, unknown, never>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Client-side sync: pull/push by sending protocol messages and handling responses.
|
|
26
|
+
* Sets senderPeerId = peerId and recipientPeerId = serverPeerId on all requests.
|
|
27
|
+
* Uses a map of requestId -> Deferred to match responses to in-flight requests.
|
|
28
|
+
* handleMessage completes the Deferred for the requestId (if any) and removes the handler; no handler = noop.
|
|
29
|
+
*/
|
|
30
|
+
export declare class SyncClient {
|
|
31
|
+
#private;
|
|
32
|
+
constructor(options: SyncClientOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Receive a message from the server. If a handler is registered for the message's requestId, complete it and remove; else noop.
|
|
35
|
+
*/
|
|
36
|
+
handleMessage(message: ProtocolMessage): Effect.Effect<void, never, never>;
|
|
37
|
+
pull(opts: {
|
|
38
|
+
spaceId: SpaceId;
|
|
39
|
+
feedNamespace: string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}): Effect.Effect<{
|
|
42
|
+
done: boolean;
|
|
43
|
+
}, unknown, SqlClient.SqlClient | SqlTransaction.SqlTransaction>;
|
|
44
|
+
push(opts: {
|
|
45
|
+
spaceId: SpaceId;
|
|
46
|
+
feedNamespace: string;
|
|
47
|
+
limit?: number;
|
|
48
|
+
}): Effect.Effect<{
|
|
49
|
+
done: boolean;
|
|
50
|
+
}, unknown, SqlClient.SqlClient | SqlTransaction.SqlTransaction>;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=sync-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-client.d.ts","sourceRoot":"","sources":["../../../src/sync-client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,SAAS,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,KAAK,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC;AAEpD,KAAK,mBAAmB,GAAG,OAAO,CAAC,eAAe,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAC9E,KAAK,oBAAoB,GAAG,OAAO,CAAC,eAAe,EAAE;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC,CAAC;AAChF,KAAK,cAAc,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;AAKjE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,6DAA6D;IAC7D,WAAW,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;CAC/E,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,UAAU;;gBAOT,OAAO,EAAE,iBAAiB;IAsBtC;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC;IAY1E,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,MAAM,CAAC,MAAM,CAAC;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,EAAE,OAAO,EAAE,SAAS,CAAC,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC;IA6ClG,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,MAAM,CAAC,MAAM,CAAC;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,EAAE,OAAO,EAAE,SAAS,CAAC,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC;CAiDnG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as SqlClient from '@effect/sql/SqlClient';
|
|
2
|
+
import * as Effect from 'effect/Effect';
|
|
3
|
+
import { type FeedProtocol } from '@dxos/protocols';
|
|
4
|
+
import type { SqlTransaction } from '@dxos/sql-sqlite';
|
|
5
|
+
import type { FeedStore } from './feed-store';
|
|
6
|
+
type ProtocolMessage = FeedProtocol.ProtocolMessage;
|
|
7
|
+
export type SyncServerOptions = {
|
|
8
|
+
/** This server's peer id. Set as senderPeerId on all replies. */
|
|
9
|
+
peerId: string;
|
|
10
|
+
feedStore: FeedStore;
|
|
11
|
+
/** Send a protocol message to a client. Receives full message (recipient is set by server). Returns Effect. */
|
|
12
|
+
sendMessage: (message: ProtocolMessage) => Effect.Effect<void, unknown, never>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Server-side sync: receives protocol messages, runs query/append against the store, sends responses.
|
|
16
|
+
* Reusable for many peers: sets senderPeerId = peerId and recipientPeerId = incoming message's senderPeerId on replies.
|
|
17
|
+
*/
|
|
18
|
+
export declare class SyncServer {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(options: SyncServerOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Receive a message from a client. Handles QueryRequest and AppendRequest; sends response via sendMessage with correct peer ids.
|
|
23
|
+
*/
|
|
24
|
+
handleMessage(message: ProtocolMessage): Effect.Effect<void, unknown, SqlClient.SqlClient | SqlTransaction.SqlTransaction>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=sync-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-server.d.ts","sourceRoot":"","sources":["../../../src/sync-server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,KAAK,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC;AAIpD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,+GAA+G;IAC/G,WAAW,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;CAChF,CAAC;AAEF;;;GAGG;AACH,qBAAa,UAAU;;gBAKT,OAAO,EAAE,iBAAiB;IAMtC;;OAEG;IACH,aAAa,CACX,OAAO,EAAE,eAAe,GACvB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC;CA8CrF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.test.d.ts","sourceRoot":"","sources":["../../../src/sync.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type * as SqlClient from '@effect/sql/SqlClient';
|
|
2
|
+
import * as Effect from 'effect/Effect';
|
|
3
|
+
import * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
4
|
+
import { Resource } from '@dxos/context';
|
|
5
|
+
import { type SpaceId } from '@dxos/keys';
|
|
6
|
+
import { FeedProtocol } from '@dxos/protocols';
|
|
7
|
+
import { SqlTransaction } from '@dxos/sql-sqlite';
|
|
8
|
+
import * as SqlExport from '@dxos/sql-sqlite/SqlExport';
|
|
9
|
+
import { FeedStore } from '../feed-store';
|
|
10
|
+
import { SyncClient } from '../sync-client';
|
|
11
|
+
import { SyncServer } from '../sync-server';
|
|
12
|
+
type ProtocolMessage = FeedProtocol.ProtocolMessage;
|
|
13
|
+
type AppendRequest = FeedProtocol.AppendRequest;
|
|
14
|
+
type QueryRequest = FeedProtocol.QueryRequest;
|
|
15
|
+
export declare class TestBuilder extends Resource {
|
|
16
|
+
#private;
|
|
17
|
+
constructor({ numPeers, spaceId, feedNamespace, logSql, }: {
|
|
18
|
+
numPeers: number;
|
|
19
|
+
spaceId: SpaceId;
|
|
20
|
+
feedNamespace?: string;
|
|
21
|
+
logSql?: boolean;
|
|
22
|
+
});
|
|
23
|
+
get peers(): TestPeer[];
|
|
24
|
+
get server(): TestPeer;
|
|
25
|
+
protected _open(): Promise<void>;
|
|
26
|
+
protected _close(): Promise<void>;
|
|
27
|
+
pull(client: TestPeer, { limit }?: {
|
|
28
|
+
limit?: number;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
done: boolean;
|
|
31
|
+
}>;
|
|
32
|
+
push(client: TestPeer, { limit }?: {
|
|
33
|
+
limit?: number;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
done: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export declare class TestPeer extends Resource {
|
|
39
|
+
#private;
|
|
40
|
+
constructor({ isServer, actorId, serverPeerId, sendMessage, logSql, }: {
|
|
41
|
+
isServer: boolean;
|
|
42
|
+
actorId: string;
|
|
43
|
+
serverPeerId?: string;
|
|
44
|
+
sendMessage: (msg: ProtocolMessage) => Effect.Effect<void, unknown, never>;
|
|
45
|
+
logSql?: boolean;
|
|
46
|
+
});
|
|
47
|
+
get peerId(): string;
|
|
48
|
+
get feedStore(): FeedStore;
|
|
49
|
+
get runtime(): ManagedRuntime.ManagedRuntime<SqlClient.SqlClient | SqlTransaction.SqlTransaction | SqlExport.SqlExport, never>;
|
|
50
|
+
get syncClient(): SyncClient | undefined;
|
|
51
|
+
get syncServer(): SyncServer | undefined;
|
|
52
|
+
protected _open(): Promise<void>;
|
|
53
|
+
protected _close(): Promise<void>;
|
|
54
|
+
export(): Promise<Uint8Array>;
|
|
55
|
+
getSyncState({ spaceId, feedNamespace }: {
|
|
56
|
+
spaceId: SpaceId;
|
|
57
|
+
feedNamespace: string;
|
|
58
|
+
}): Promise<number>;
|
|
59
|
+
query(req: QueryRequest): Promise<FeedProtocol.QueryResponse>;
|
|
60
|
+
append(req: AppendRequest): Promise<FeedProtocol.AppendResponse>;
|
|
61
|
+
appendLocal(req: Parameters<FeedStore['appendLocal']>[0]): Promise<FeedProtocol.Block[]>;
|
|
62
|
+
pull({ spaceId, feedNamespace, limit }: {
|
|
63
|
+
spaceId: SpaceId;
|
|
64
|
+
feedNamespace: string;
|
|
65
|
+
limit?: number;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
done: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
push({ spaceId, feedNamespace, limit }: {
|
|
70
|
+
spaceId: SpaceId;
|
|
71
|
+
feedNamespace: string;
|
|
72
|
+
limit?: number;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
done: boolean;
|
|
75
|
+
}>;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=test-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-builder.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-builder.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,SAAS,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,SAAS,MAAM,4BAA4B,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,KAAK,eAAe,GAAG,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