@stratasync/client 0.2.0
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 +76 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +759 -0
- package/dist/client.js.map +1 -0
- package/dist/history-manager.d.ts +45 -0
- package/dist/history-manager.d.ts.map +1 -0
- package/dist/history-manager.js +266 -0
- package/dist/history-manager.js.map +1 -0
- package/dist/identity-map.d.ts +127 -0
- package/dist/identity-map.d.ts.map +1 -0
- package/dist/identity-map.js +295 -0
- package/dist/identity-map.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/outbox-manager.d.ts +122 -0
- package/dist/outbox-manager.d.ts.map +1 -0
- package/dist/outbox-manager.js +373 -0
- package/dist/outbox-manager.js.map +1 -0
- package/dist/query.d.ts +7 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +36 -0
- package/dist/query.js.map +1 -0
- package/dist/sync-orchestrator.d.ts +208 -0
- package/dist/sync-orchestrator.d.ts.map +1 -0
- package/dist/sync-orchestrator.js +1287 -0
- package/dist/sync-orchestrator.js.map +1 -0
- package/dist/types.d.ts +309 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @stratasync/client
|
|
2
|
+
|
|
3
|
+
Offline-first sync orchestration: identity maps, outbox batching, delta reconciliation, conflict resolution, undo/redo, and query execution.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
sync-client coordinates the client-side sync lifecycle:
|
|
8
|
+
|
|
9
|
+
- **SyncClient** — main orchestrator for the sync lifecycle
|
|
10
|
+
- **Outbox manager** — batches mutations for offline-first support
|
|
11
|
+
- **Identity map** — canonical in-memory object instances (deduplication via MobX reactivity)
|
|
12
|
+
- **Sync orchestrator** — state machine for bootstrap, delta subscription, and conflict resolution
|
|
13
|
+
- **History manager** — undo/redo with inverse operation tracking
|
|
14
|
+
- **Query execution** — predicate builders, sorting, and pagination against identity maps
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @stratasync/client
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Dependencies: `@stratasync/core`, `@stratasync/yjs`
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { createSyncClient } from "@stratasync/client";
|
|
28
|
+
|
|
29
|
+
const client = createSyncClient({
|
|
30
|
+
storage, // StorageAdapter (e.g. sync-storage-idb)
|
|
31
|
+
transport, // TransportAdapter (e.g. sync-transport-graphql)
|
|
32
|
+
reactivity, // ReactivityAdapter (e.g. sync-mobx)
|
|
33
|
+
schema: ModelRegistry.snapshot(),
|
|
34
|
+
userId,
|
|
35
|
+
groups,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await client.start();
|
|
39
|
+
|
|
40
|
+
// Create (optimistic by default)
|
|
41
|
+
await client.create("Task", {
|
|
42
|
+
id: crypto.randomUUID(),
|
|
43
|
+
title: "New task",
|
|
44
|
+
workspaceId,
|
|
45
|
+
createdAt: Date.now(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Update
|
|
49
|
+
await client.update("Task", taskId, {
|
|
50
|
+
title: "Updated title",
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Delete
|
|
54
|
+
await client.delete("Task", taskId);
|
|
55
|
+
|
|
56
|
+
// Query
|
|
57
|
+
const result = await client.query("Task", {
|
|
58
|
+
where: (i) => i.workspaceId === workspaceId,
|
|
59
|
+
limit: 50,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Package Structure
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
src/
|
|
67
|
+
index.ts — public API barrel export
|
|
68
|
+
client.ts — SyncClient factory and mutation coordination
|
|
69
|
+
sync-orchestrator.ts — state machine: bootstrap, delta application, rebase
|
|
70
|
+
outbox-manager.ts — offline mutation queue with batching and retry
|
|
71
|
+
identity-map.ts — per-model ObservableMap with MobX reactivity
|
|
72
|
+
history-manager.ts — undo/redo stack with inverse operation tracking
|
|
73
|
+
query.ts — predicate builders and executeQuery
|
|
74
|
+
types.ts — StorageAdapter, TransportAdapter, SyncClientOptions
|
|
75
|
+
utils.ts — getModelKey, getModelData, pickOriginal helpers
|
|
76
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SyncClient, SyncClientOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a sync client instance.
|
|
4
|
+
*
|
|
5
|
+
* Uses a closure to encapsulate mutable state (identity maps, outbox, history).
|
|
6
|
+
* The `clientRef` / `getClientRef` pattern exists because the client object
|
|
7
|
+
* literal needs to reference itself for history replay operations, but it
|
|
8
|
+
* hasn't been assigned yet at definition time.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createSyncClient: (options: SyncClientOptions) => SyncClient;
|
|
11
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAOV,UAAU,EAEV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAwEpB;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB,KAAG,UAg8B7D,CAAC"}
|