@strata-sync/client 0.1.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/AGENTS.md +24 -0
- package/README.md +63 -0
- package/package.json +32 -0
- package/src/client.ts +1051 -0
- package/src/identity-map.ts +294 -0
- package/src/index.ts +33 -0
- package/src/outbox-manager.ts +399 -0
- package/src/query.ts +224 -0
- package/src/sync-orchestrator.ts +1041 -0
- package/src/types.ts +425 -0
- package/tests/rebase-integration.test.ts +920 -0
- package/tests/reverse-linear-sync-engine.test.ts +701 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +31 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @strata-sync/client
|
|
2
|
+
|
|
3
|
+
Client orchestration, outbox management, delta processing, and query execution.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
- `npm run build` — compile TypeScript (`tsc -p tsconfig.build.json`)
|
|
8
|
+
- `npm run dev` — watch mode (`tsc --watch -p tsconfig.build.json`)
|
|
9
|
+
- `npm run test` — run tests (`vitest run`)
|
|
10
|
+
- `npm run lint` — lint with Biome
|
|
11
|
+
- `npm run check-types` — type check without emitting
|
|
12
|
+
|
|
13
|
+
## Gotchas
|
|
14
|
+
|
|
15
|
+
- Uses `tsconfig.build.json` for builds (not the default `tsconfig.json`) — the build config excludes test files
|
|
16
|
+
- Depends on both `@strata-sync/core` and `@strata-sync/yjs` — both must be built first
|
|
17
|
+
- The outbox batches mutations for offline-first support — mutations are not sent immediately when offline
|
|
18
|
+
- Identity map deduplicates model instances — never create model instances outside the identity map
|
|
19
|
+
|
|
20
|
+
## Conventions
|
|
21
|
+
|
|
22
|
+
- SyncClient is the single orchestrator — all sync lifecycle goes through it
|
|
23
|
+
- Queries use predicate functions for filtering (`where: (item) => boolean`)
|
|
24
|
+
- Outbox entries are ordered and must be replayed in sequence on reconnect
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @strata-sync/client
|
|
2
|
+
|
|
3
|
+
Client orchestration, outbox management, delta processing, and query execution for the Strata Sync.
|
|
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)
|
|
12
|
+
- **Query execution** — filtering, lazy loading, and predicate-based queries
|
|
13
|
+
- **Connection state** — manages online/offline/syncing states
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @strata-sync/client
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Dependencies: `@strata-sync/core`, `@strata-sync/yjs`
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { SyncClient } from "@strata-sync/client";
|
|
27
|
+
|
|
28
|
+
const client = new SyncClient({ /* config */ });
|
|
29
|
+
|
|
30
|
+
// Create (optimistic by default)
|
|
31
|
+
await client.create("Issue", {
|
|
32
|
+
id: crypto.randomUUID(),
|
|
33
|
+
title: "New issue",
|
|
34
|
+
workspaceId,
|
|
35
|
+
createdAt: Date.now(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Update
|
|
39
|
+
await client.update("Issue", issueId, {
|
|
40
|
+
title: "Updated title",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Delete
|
|
44
|
+
await client.delete("Issue", issueId);
|
|
45
|
+
|
|
46
|
+
// Query
|
|
47
|
+
const issues = client.query("Issue", {
|
|
48
|
+
where: (i) => i.workspaceId === workspaceId,
|
|
49
|
+
limit: 50,
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Package Structure
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
src/
|
|
57
|
+
├── client.ts — Main SyncClient class
|
|
58
|
+
├── sync-orchestrator.ts — Lifecycle management
|
|
59
|
+
├── outbox-manager.ts — Mutation batching for offline-first
|
|
60
|
+
├── identity-map.ts — Object deduplication
|
|
61
|
+
├── query.ts — Query execution engine
|
|
62
|
+
└── types.ts — Shared type definitions
|
|
63
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@strata-sync/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json",
|
|
18
|
+
"dev": "tsc --watch -p tsconfig.build.json",
|
|
19
|
+
"lint": "biome lint .",
|
|
20
|
+
"check-types": "tsc --noEmit",
|
|
21
|
+
"test": "vitest run"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@strata-sync/core": "*",
|
|
25
|
+
"@strata-sync/yjs": "*"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.9.3",
|
|
29
|
+
"@biomejs/biome": "^2.3.12",
|
|
30
|
+
"vitest": "^4.0.18"
|
|
31
|
+
}
|
|
32
|
+
}
|