@livestore/cli 0.0.0-snapshot-2ac5fd340c97c9e07fe4c5dc6d31d5132aa6557c.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/.claude/settings.local.json +12 -0
- package/LICENSE +201 -0
- package/dist/cli +0 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +22 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/mcp-coach.d.ts +15 -0
- package/dist/commands/mcp-coach.d.ts.map +1 -0
- package/dist/commands/mcp-coach.js +87 -0
- package/dist/commands/mcp-coach.js.map +1 -0
- package/dist/commands/mcp-tools.d.ts +41 -0
- package/dist/commands/mcp-tools.d.ts.map +1 -0
- package/dist/commands/mcp-tools.js +148 -0
- package/dist/commands/mcp-tools.js.map +1 -0
- package/dist/commands/mcp.d.ts +5 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +67 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/new-project.d.ts +34 -0
- package/dist/commands/new-project.d.ts.map +1 -0
- package/dist/commands/new-project.js +163 -0
- package/dist/commands/new-project.js.map +1 -0
- package/dist/mcp-content/architecture.d.ts +2 -0
- package/dist/mcp-content/architecture.d.ts.map +1 -0
- package/dist/mcp-content/architecture.js +171 -0
- package/dist/mcp-content/architecture.js.map +1 -0
- package/dist/mcp-content/features.d.ts +2 -0
- package/dist/mcp-content/features.d.ts.map +1 -0
- package/dist/mcp-content/features.js +177 -0
- package/dist/mcp-content/features.js.map +1 -0
- package/dist/mcp-content/getting-started.d.ts +2 -0
- package/dist/mcp-content/getting-started.d.ts.map +1 -0
- package/dist/mcp-content/getting-started.js +405 -0
- package/dist/mcp-content/getting-started.js.map +1 -0
- package/dist/mcp-content/overview.d.ts +2 -0
- package/dist/mcp-content/overview.d.ts.map +1 -0
- package/dist/mcp-content/overview.js +120 -0
- package/dist/mcp-content/overview.js.map +1 -0
- package/dist/mcp-content/schemas/blog.d.ts +2 -0
- package/dist/mcp-content/schemas/blog.d.ts.map +1 -0
- package/dist/mcp-content/schemas/blog.js +223 -0
- package/dist/mcp-content/schemas/blog.js.map +1 -0
- package/dist/mcp-content/schemas/ecommerce.d.ts +2 -0
- package/dist/mcp-content/schemas/ecommerce.d.ts.map +1 -0
- package/dist/mcp-content/schemas/ecommerce.js +436 -0
- package/dist/mcp-content/schemas/ecommerce.js.map +1 -0
- package/dist/mcp-content/schemas/social.d.ts +2 -0
- package/dist/mcp-content/schemas/social.d.ts.map +1 -0
- package/dist/mcp-content/schemas/social.js +339 -0
- package/dist/mcp-content/schemas/social.js.map +1 -0
- package/dist/mcp-content/schemas/todo.d.ts +2 -0
- package/dist/mcp-content/schemas/todo.d.ts.map +1 -0
- package/dist/mcp-content/schemas/todo.js +172 -0
- package/dist/mcp-content/schemas/todo.js.map +1 -0
- package/dist/mod.d.ts +2 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +1 -0
- package/dist/test-tool.d.ts +2 -0
- package/dist/test-tool.d.ts.map +1 -0
- package/dist/test-tool.js +57 -0
- package/dist/test-tool.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +27 -0
- package/src/cli.ts +35 -0
- package/src/commands/mcp-coach.ts +121 -0
- package/src/commands/mcp-tools.ts +169 -0
- package/src/commands/mcp.ts +97 -0
- package/src/commands/new-project.ts +263 -0
- package/src/mcp-content/architecture.ts +170 -0
- package/src/mcp-content/features.ts +176 -0
- package/src/mcp-content/getting-started.ts +404 -0
- package/src/mcp-content/overview.ts +119 -0
- package/src/mcp-content/schemas/blog.ts +222 -0
- package/src/mcp-content/schemas/ecommerce.ts +435 -0
- package/src/mcp-content/schemas/social.ts +338 -0
- package/src/mcp-content/schemas/todo.ts +171 -0
- package/src/mod.ts +1 -0
- package/tsconfig.json +9 -0
@@ -0,0 +1,263 @@
|
|
1
|
+
import * as os from 'node:os'
|
2
|
+
import * as nodePath from 'node:path'
|
3
|
+
import {
|
4
|
+
Command,
|
5
|
+
Console,
|
6
|
+
Effect,
|
7
|
+
FileSystem,
|
8
|
+
HttpClient,
|
9
|
+
HttpClientRequest,
|
10
|
+
Option,
|
11
|
+
Schema,
|
12
|
+
} from '@livestore/utils/effect'
|
13
|
+
import { Cli } from '@livestore/utils/node'
|
14
|
+
|
15
|
+
// Schema for GitHub API response
|
16
|
+
const GitHubContentSchema = Schema.Struct({
|
17
|
+
name: Schema.String,
|
18
|
+
type: Schema.Literal('dir', 'file'),
|
19
|
+
path: Schema.String,
|
20
|
+
download_url: Schema.NullOr(Schema.String),
|
21
|
+
})
|
22
|
+
|
23
|
+
const GitHubContentsResponseSchema = Schema.Array(GitHubContentSchema)
|
24
|
+
|
25
|
+
// Error types
|
26
|
+
export class ExampleNotFoundError extends Schema.TaggedError<ExampleNotFoundError>()('ExampleNotFoundError', {
|
27
|
+
exampleName: Schema.String,
|
28
|
+
availableExamples: Schema.Array(Schema.String),
|
29
|
+
message: Schema.String,
|
30
|
+
}) {}
|
31
|
+
|
32
|
+
export class NetworkError extends Schema.TaggedError<NetworkError>()('NetworkError', {
|
33
|
+
cause: Schema.Unknown,
|
34
|
+
message: Schema.String,
|
35
|
+
}) {}
|
36
|
+
|
37
|
+
export class DirectoryExistsError extends Schema.TaggedError<DirectoryExistsError>()('DirectoryExistsError', {
|
38
|
+
path: Schema.String,
|
39
|
+
message: Schema.String,
|
40
|
+
}) {}
|
41
|
+
|
42
|
+
// Fetch available examples from GitHub
|
43
|
+
const fetchExamples = (branch: string) =>
|
44
|
+
Effect.gen(function* () {
|
45
|
+
const url = `https://api.github.com/repos/livestorejs/livestore/contents/examples?ref=${branch}`
|
46
|
+
|
47
|
+
yield* Effect.log(`Fetching examples from branch: ${branch}`)
|
48
|
+
|
49
|
+
const request = HttpClientRequest.get(url)
|
50
|
+
const response = yield* HttpClient.execute(request).pipe(
|
51
|
+
Effect.scoped,
|
52
|
+
Effect.catchAll(
|
53
|
+
(error) =>
|
54
|
+
new NetworkError({
|
55
|
+
cause: error,
|
56
|
+
message: `Failed to fetch examples from GitHub: ${error}`,
|
57
|
+
}),
|
58
|
+
),
|
59
|
+
)
|
60
|
+
|
61
|
+
const responseText = yield* response.text
|
62
|
+
|
63
|
+
const examples = yield* Schema.decodeUnknown(GitHubContentsResponseSchema)(JSON.parse(responseText)).pipe(
|
64
|
+
Effect.catchAll(
|
65
|
+
(error) =>
|
66
|
+
new NetworkError({
|
67
|
+
cause: error,
|
68
|
+
message: `Failed to parse GitHub API response: ${error}`,
|
69
|
+
}),
|
70
|
+
),
|
71
|
+
)
|
72
|
+
|
73
|
+
const exampleNames = examples
|
74
|
+
.filter((item) => item.type === 'dir')
|
75
|
+
.map((item) => item.name)
|
76
|
+
.sort()
|
77
|
+
|
78
|
+
yield* Effect.log(`Found ${exampleNames.length} examples: ${exampleNames.join(', ')}`)
|
79
|
+
|
80
|
+
return exampleNames
|
81
|
+
})
|
82
|
+
|
83
|
+
// Interactive example selection
|
84
|
+
const selectExample = (examples: string[]) =>
|
85
|
+
Effect.gen(function* () {
|
86
|
+
if (examples.length === 0) {
|
87
|
+
return yield* Effect.fail(new Error('No examples available'))
|
88
|
+
}
|
89
|
+
|
90
|
+
const prompt = Cli.Prompt.select({
|
91
|
+
message: '📦 Select a LiveStore example to create:',
|
92
|
+
choices: examples.map((example) => ({
|
93
|
+
title: example,
|
94
|
+
value: example,
|
95
|
+
description: `Create a new project using the ${example} example`,
|
96
|
+
})),
|
97
|
+
})
|
98
|
+
|
99
|
+
return yield* Cli.Prompt.run(prompt)
|
100
|
+
})
|
101
|
+
|
102
|
+
// Download and extract example using tiged approach
|
103
|
+
const downloadExample = (exampleName: string, branch: string, destinationPath: string) =>
|
104
|
+
Effect.gen(function* () {
|
105
|
+
yield* Console.log(`📥 Downloading example "${exampleName}" from branch "${branch}"...`)
|
106
|
+
|
107
|
+
const tempDir = yield* Effect.sync(() => os.tmpdir())
|
108
|
+
const tarballPath = nodePath.join(tempDir, `livestore-${branch}-${Date.now()}.tar.gz`)
|
109
|
+
const tarballUrl = `https://api.github.com/repos/livestorejs/livestore/tarball/${branch}`
|
110
|
+
|
111
|
+
// Download tarball directly
|
112
|
+
const request = HttpClientRequest.get(tarballUrl)
|
113
|
+
|
114
|
+
const response = yield* HttpClient.execute(request).pipe(
|
115
|
+
Effect.scoped,
|
116
|
+
Effect.catchAll(
|
117
|
+
(error) =>
|
118
|
+
new NetworkError({
|
119
|
+
cause: error,
|
120
|
+
message: `Failed to download tarball: ${error}`,
|
121
|
+
}),
|
122
|
+
),
|
123
|
+
)
|
124
|
+
|
125
|
+
const fs = yield* FileSystem.FileSystem
|
126
|
+
|
127
|
+
// Write tarball to temp file
|
128
|
+
const tarballBuffer = yield* response.arrayBuffer
|
129
|
+
yield* fs.writeFile(tarballPath, new Uint8Array(tarballBuffer))
|
130
|
+
|
131
|
+
// Create destination directory
|
132
|
+
yield* fs.makeDirectory(destinationPath, { recursive: true })
|
133
|
+
|
134
|
+
// Extract the tarball to a temporary directory first
|
135
|
+
const extractDir = nodePath.join(tempDir, `extract-${Date.now()}`)
|
136
|
+
yield* fs.makeDirectory(extractDir, { recursive: true })
|
137
|
+
|
138
|
+
// Extract tarball using Effect Command
|
139
|
+
yield* Command.make('tar', '-xzf', tarballPath, '-C', extractDir).pipe(
|
140
|
+
Command.exitCode,
|
141
|
+
Effect.catchAll(
|
142
|
+
(error) =>
|
143
|
+
new NetworkError({
|
144
|
+
cause: error,
|
145
|
+
message: `Failed to extract tarball: ${error}`,
|
146
|
+
}),
|
147
|
+
),
|
148
|
+
)
|
149
|
+
|
150
|
+
// Find the extracted directory (it will be named like livestorejs-livestore-{hash})
|
151
|
+
const extractedDirs = yield* fs.readDirectory(extractDir)
|
152
|
+
|
153
|
+
if (extractedDirs.length === 0) {
|
154
|
+
return yield* new NetworkError({
|
155
|
+
cause: 'No extracted directory found',
|
156
|
+
message: 'Failed to find extracted repository directory',
|
157
|
+
})
|
158
|
+
}
|
159
|
+
|
160
|
+
const repoDir = nodePath.join(extractDir, extractedDirs[0]!)
|
161
|
+
const exampleSourcePath = nodePath.join(repoDir, 'examples', exampleName)
|
162
|
+
|
163
|
+
// Check if the example exists
|
164
|
+
const exampleExists = yield* fs.exists(exampleSourcePath)
|
165
|
+
|
166
|
+
if (!exampleExists) {
|
167
|
+
return yield* new ExampleNotFoundError({
|
168
|
+
exampleName,
|
169
|
+
availableExamples: [],
|
170
|
+
message: `Example "${exampleName}" not found in the extracted repository`,
|
171
|
+
})
|
172
|
+
}
|
173
|
+
|
174
|
+
// Copy the example directory contents to the destination using Effect Command
|
175
|
+
yield* Command.make('cp', '-r', `${exampleSourcePath}/.`, destinationPath).pipe(
|
176
|
+
Command.exitCode,
|
177
|
+
Effect.catchAll(
|
178
|
+
(error) =>
|
179
|
+
new NetworkError({
|
180
|
+
cause: error,
|
181
|
+
message: `Failed to copy example files: ${error}`,
|
182
|
+
}),
|
183
|
+
),
|
184
|
+
)
|
185
|
+
|
186
|
+
// Clean up extract directory
|
187
|
+
yield* fs.remove(extractDir, { recursive: true }).pipe(Effect.catchAll(() => Effect.void))
|
188
|
+
|
189
|
+
// Clean up tarball
|
190
|
+
yield* fs.remove(tarballPath).pipe(Effect.catchAll(() => Effect.void))
|
191
|
+
|
192
|
+
yield* Console.log(`✅ Example "${exampleName}" created successfully at: ${destinationPath}`)
|
193
|
+
})
|
194
|
+
|
195
|
+
export const newProjectCommand = Cli.Command.make(
|
196
|
+
'new-project',
|
197
|
+
{
|
198
|
+
example: Cli.Options.text('example').pipe(
|
199
|
+
Cli.Options.optional,
|
200
|
+
Cli.Options.withDescription('Example name to create (bypasses interactive selection)'),
|
201
|
+
),
|
202
|
+
branch: Cli.Options.text('branch').pipe(
|
203
|
+
Cli.Options.withDefault('dev'),
|
204
|
+
Cli.Options.withDescription('Branch to fetch examples from'),
|
205
|
+
),
|
206
|
+
path: Cli.Args.text({ name: 'path' }).pipe(
|
207
|
+
Cli.Args.optional,
|
208
|
+
Cli.Args.withDescription('Destination path for the new project'),
|
209
|
+
),
|
210
|
+
},
|
211
|
+
Effect.fn(function* ({
|
212
|
+
example,
|
213
|
+
branch,
|
214
|
+
path,
|
215
|
+
}: {
|
216
|
+
example: Option.Option<string>
|
217
|
+
branch: string
|
218
|
+
path: Option.Option<string>
|
219
|
+
}) {
|
220
|
+
yield* Effect.log('🚀 Creating new LiveStore project...')
|
221
|
+
|
222
|
+
// Fetch available examples
|
223
|
+
const examples = yield* fetchExamples(branch)
|
224
|
+
|
225
|
+
if (examples.length === 0) {
|
226
|
+
yield* Console.log('❌ No examples found in the repository')
|
227
|
+
return yield* new ExampleNotFoundError({
|
228
|
+
exampleName: '',
|
229
|
+
availableExamples: [],
|
230
|
+
message: 'No examples available',
|
231
|
+
})
|
232
|
+
}
|
233
|
+
|
234
|
+
// Select example (from CLI option or interactive prompt)
|
235
|
+
const selectedExample = Option.isSome(example) ? example.value : yield* selectExample(examples)
|
236
|
+
|
237
|
+
// Validate selected example exists
|
238
|
+
if (!examples.includes(selectedExample)) {
|
239
|
+
yield* Console.log(`❌ Example "${selectedExample}" not found`)
|
240
|
+
yield* Console.log(`Available examples: ${examples.join(', ')}`)
|
241
|
+
return yield* new ExampleNotFoundError({
|
242
|
+
exampleName: selectedExample,
|
243
|
+
availableExamples: examples,
|
244
|
+
message: `Example "${selectedExample}" not found`,
|
245
|
+
})
|
246
|
+
}
|
247
|
+
|
248
|
+
// Determine destination path
|
249
|
+
const destinationPath = Option.isSome(path) ? nodePath.resolve(path.value) : nodePath.resolve(selectedExample)
|
250
|
+
|
251
|
+
// Download and extract the example
|
252
|
+
yield* downloadExample(selectedExample, branch, destinationPath)
|
253
|
+
|
254
|
+
// Success message
|
255
|
+
yield* Console.log('\n🎉 Project created successfully!')
|
256
|
+
yield* Console.log(`📁 Location: ${destinationPath}`)
|
257
|
+
yield* Console.log('\n📋 Next steps:')
|
258
|
+
yield* Console.log(` cd ${nodePath.basename(destinationPath)}`)
|
259
|
+
yield* Console.log(' pnpm install # Install dependencies')
|
260
|
+
yield* Console.log(' pnpm dev # Start development server')
|
261
|
+
yield* Console.log('\n💡 Tip: Run `git init` if you want to initialize version control')
|
262
|
+
}),
|
263
|
+
)
|
@@ -0,0 +1,170 @@
|
|
1
|
+
export const architectureContent = `# LiveStore Architecture: Local-First Data Management
|
2
|
+
|
3
|
+
LiveStore implements distributed systems principles from Martin Kleppmann's research on local-first software, ensuring data consistency, availability, and partition tolerance in collaborative applications.
|
4
|
+
|
5
|
+
## Core Architectural Principles
|
6
|
+
|
7
|
+
### 1. Local-First Data Storage
|
8
|
+
- **Immediate Response**: All operations execute against local SQLite database first
|
9
|
+
- **Offline Capability**: Full application functionality without network connectivity
|
10
|
+
- **Data Ownership**: Users maintain complete control over their data
|
11
|
+
- **Performance**: Sub-millisecond query responses from local storage
|
12
|
+
|
13
|
+
### 2. Event Sourcing & CRDT-Inspired Conflict Resolution
|
14
|
+
- **Immutable Event Log**: All changes recorded as immutable events
|
15
|
+
- **Deterministic Replay**: State reconstruction from event sequence
|
16
|
+
- **Conflict-Free Operations**: Events designed for commutative application
|
17
|
+
- **Causal Ordering**: Lamport timestamps ensure causally consistent ordering
|
18
|
+
|
19
|
+
### 3. Eventually Consistent Synchronization
|
20
|
+
- **Asynchronous Replication**: Events sync when network available
|
21
|
+
- **Convergence Guarantee**: All replicas converge to same state
|
22
|
+
- **Conflict Resolution**: Last-write-wins with semantic merging strategies
|
23
|
+
- **Incremental Sync**: Only transmit events since last synchronization
|
24
|
+
|
25
|
+
## System Components
|
26
|
+
|
27
|
+
### 🗄️ State Layer (SQLite + Materializers)
|
28
|
+
\`\`\`typescript
|
29
|
+
// Materialized views from event log
|
30
|
+
const materializers = State.SQLite.materializers(events, {
|
31
|
+
'TodoCreated': ({ id, text, createdAt }) =>
|
32
|
+
tables.todos.insert({ id, text, completed: false, createdAt }),
|
33
|
+
'TodoCompleted': ({ id }) =>
|
34
|
+
tables.todos.update({ completed: true }).where({ id })
|
35
|
+
})
|
36
|
+
\`\`\`
|
37
|
+
|
38
|
+
**Responsibilities:**
|
39
|
+
- Maintain denormalized query-optimized state
|
40
|
+
- Apply events to update materialized views
|
41
|
+
- Support efficient reactive queries
|
42
|
+
- Handle schema migrations
|
43
|
+
|
44
|
+
### 📝 Event System (Append-Only Log)
|
45
|
+
\`\`\`typescript
|
46
|
+
const events = {
|
47
|
+
todoCompleted: Events.synced({
|
48
|
+
name: 'v1.TodoCompleted',
|
49
|
+
schema: Schema.Struct({
|
50
|
+
id: Schema.String,
|
51
|
+
completedAt: Schema.Date // For conflict resolution
|
52
|
+
})
|
53
|
+
})
|
54
|
+
}
|
55
|
+
\`\`\`
|
56
|
+
|
57
|
+
**Characteristics:**
|
58
|
+
- Immutable event log (append-only)
|
59
|
+
- Cryptographically signed events for integrity
|
60
|
+
- Causal dependencies tracked via vector clocks
|
61
|
+
- Schema versioning for backward compatibility
|
62
|
+
|
63
|
+
### 🔄 Synchronization Engine
|
64
|
+
\`\`\`typescript
|
65
|
+
// Conflict resolution during sync
|
66
|
+
const mergeResult = SyncState.merge({
|
67
|
+
syncState: currentState,
|
68
|
+
payload: incomingEvents,
|
69
|
+
isEqualEvent: (a, b) => a.id === b.id && a.type === b.type
|
70
|
+
})
|
71
|
+
\`\`\`
|
72
|
+
|
73
|
+
**Merge Strategies:**
|
74
|
+
- **Advance**: New events extend current state
|
75
|
+
- **Rebase**: Rollback conflicting events, apply remote, replay local
|
76
|
+
- **Reject**: Ignore events that violate invariants
|
77
|
+
|
78
|
+
### 🌐 Network Layer & Adapters
|
79
|
+
\`\`\`typescript
|
80
|
+
// Platform-specific sync adapters
|
81
|
+
export const WebAdapter = {
|
82
|
+
storage: OPFSSQLiteStorage, // Origin Private File System
|
83
|
+
transport: WebSocketSync,
|
84
|
+
worker: SharedWorker // Cross-tab synchronization
|
85
|
+
}
|
86
|
+
\`\`\`
|
87
|
+
|
88
|
+
**Adapter Implementations:**
|
89
|
+
- **Web**: OPFS storage, SharedWorker coordination, WebSocket sync
|
90
|
+
- **Node**: File system storage, cluster coordination, HTTP/WebSocket
|
91
|
+
- **Mobile**: Native SQLite, background sync, push notifications
|
92
|
+
|
93
|
+
## Distributed Systems Properties
|
94
|
+
|
95
|
+
### CAP Theorem Considerations
|
96
|
+
- **Consistency**: Eventually consistent (not strongly consistent)
|
97
|
+
- **Availability**: Always available for reads/writes (local-first)
|
98
|
+
- **Partition Tolerance**: Continues operation during network partitions
|
99
|
+
|
100
|
+
*Trade-off: Chooses Availability + Partition Tolerance over strong Consistency*
|
101
|
+
|
102
|
+
### ACID Properties (Local Transactions)
|
103
|
+
- **Atomicity**: Event application is atomic within SQLite transaction
|
104
|
+
- **Consistency**: Materializers maintain data integrity constraints
|
105
|
+
- **Isolation**: Concurrent operations isolated via SQLite WAL mode
|
106
|
+
- **Durability**: Events persisted to disk before acknowledgment
|
107
|
+
|
108
|
+
### Conflict Resolution Strategies
|
109
|
+
|
110
|
+
1. **Semantic Conflict Resolution**
|
111
|
+
- Application-specific merge logic
|
112
|
+
- E.g., text editing uses operational transforms
|
113
|
+
|
114
|
+
2. **Last-Write-Wins (LWW)**
|
115
|
+
- Timestamps determine winner
|
116
|
+
- Simple but can lose data
|
117
|
+
|
118
|
+
3. **Multi-Value Registers**
|
119
|
+
- Preserve all conflicting values
|
120
|
+
- User or application resolves
|
121
|
+
|
122
|
+
4. **Commutative Operations**
|
123
|
+
- Operations designed to commute
|
124
|
+
- E.g., increment/decrement counters
|
125
|
+
|
126
|
+
## Performance & Scalability
|
127
|
+
|
128
|
+
### Query Performance
|
129
|
+
- **Reactive Queries**: Automatically update UI on data changes
|
130
|
+
- **Indexed Access**: SQLite B-tree indexes for fast lookups
|
131
|
+
- **Prepared Statements**: Query compilation cached for reuse
|
132
|
+
- **Batch Operations**: Multiple events applied in single transaction
|
133
|
+
|
134
|
+
### Memory Management
|
135
|
+
- **Incremental Loading**: Large datasets loaded on-demand
|
136
|
+
- **Query Result Caching**: Expensive query results cached
|
137
|
+
- **Event Log Compaction**: Periodic snapshotting and log truncation
|
138
|
+
- **Connection Pooling**: Database connections reused across operations
|
139
|
+
|
140
|
+
### Network Optimization
|
141
|
+
- **Delta Synchronization**: Only sync events since last checkpoint
|
142
|
+
- **Compression**: Event payloads compressed for network transfer
|
143
|
+
- **Batching**: Multiple events transmitted in single round-trip
|
144
|
+
- **Exponential Backoff**: Retry failed sync with increasing delays
|
145
|
+
|
146
|
+
## Security Model
|
147
|
+
|
148
|
+
### Data Integrity
|
149
|
+
- **Event Signatures**: Cryptographic signatures prevent tampering
|
150
|
+
- **Merkle Trees**: Efficient verification of event log integrity
|
151
|
+
- **Schema Validation**: All events validated against defined schemas
|
152
|
+
|
153
|
+
### Access Control
|
154
|
+
- **Client-Side Authorization**: Fine-grained permissions in local database
|
155
|
+
- **Sync Filtering**: Server filters events based on user permissions
|
156
|
+
- **Encryption**: End-to-end encryption for sensitive data
|
157
|
+
|
158
|
+
## Observability
|
159
|
+
|
160
|
+
### Distributed Tracing
|
161
|
+
- **Event Causality**: Trace event propagation across replicas
|
162
|
+
- **Sync Performance**: Monitor replication lag and throughput
|
163
|
+
- **Conflict Metrics**: Track merge conflicts and resolution strategies
|
164
|
+
|
165
|
+
### Health Monitoring
|
166
|
+
- **Storage Usage**: Local database size and growth rate
|
167
|
+
- **Network Health**: Connection quality and sync success rates
|
168
|
+
- **Error Tracking**: Failed operations and their root causes
|
169
|
+
|
170
|
+
This architecture enables applications that work seamlessly offline, sync reliably when online, and provide immediate feedback to users while maintaining data consistency across all replicas.`
|
@@ -0,0 +1,176 @@
|
|
1
|
+
export const featuresContent = `# LiveStore Features: Production-Ready Local-First Data
|
2
|
+
|
3
|
+
LiveStore provides battle-tested primitives for building collaborative, offline-capable applications with the reliability and performance of modern distributed systems.
|
4
|
+
|
5
|
+
## 🏠 Local-First Architecture
|
6
|
+
|
7
|
+
### Offline-First Operation
|
8
|
+
- **Zero Latency**: All operations execute against local SQLite database
|
9
|
+
- **Offline Capable**: Full application functionality without network connectivity
|
10
|
+
- **Network Resilient**: Graceful degradation during connectivity issues
|
11
|
+
- **Background Sync**: Automatic synchronization when network becomes available
|
12
|
+
|
13
|
+
### Immediate Consistency
|
14
|
+
- **Optimistic Updates**: UI updates immediately on user action
|
15
|
+
- **Rollback on Conflict**: Automatic rollback and retry on merge conflicts
|
16
|
+
- **Causal Consistency**: Operations maintain causal ordering across replicas
|
17
|
+
|
18
|
+
## 🔄 Event-Driven Synchronization
|
19
|
+
|
20
|
+
### Conflict-Free Event Model
|
21
|
+
\`\`\`typescript
|
22
|
+
// Events designed for conflict-free merging
|
23
|
+
const events = {
|
24
|
+
todoCreated: Events.synced({
|
25
|
+
name: 'v1.TodoCreated',
|
26
|
+
schema: Schema.Struct({
|
27
|
+
id: Schema.String, // Deterministic ordering
|
28
|
+
createdAt: Schema.Date, // Timestamp for LWW resolution
|
29
|
+
position: Schema.Number // Fractional indexing for reordering
|
30
|
+
})
|
31
|
+
})
|
32
|
+
}
|
33
|
+
\`\`\`
|
34
|
+
|
35
|
+
### Sophisticated Merge Strategies
|
36
|
+
- **Last-Write-Wins**: Timestamp-based conflict resolution
|
37
|
+
- **Semantic Merging**: Application-specific merge logic
|
38
|
+
- **Operational Transform**: Real-time collaborative text editing
|
39
|
+
- **CRDT Integration**: Conflict-free replicated data types
|
40
|
+
|
41
|
+
### Incremental Synchronization
|
42
|
+
- **Delta Sync**: Only transmit changes since last synchronization
|
43
|
+
- **Vector Clocks**: Efficient causal dependency tracking
|
44
|
+
- **Merkle Trees**: Efficient integrity verification
|
45
|
+
- **Batch Optimization**: Multiple events in single network round-trip
|
46
|
+
|
47
|
+
## 📊 Reactive Query Engine
|
48
|
+
|
49
|
+
### Real-Time Reactivity
|
50
|
+
\`\`\`typescript
|
51
|
+
// Queries automatically update when underlying data changes
|
52
|
+
const activeTodos$ = queryDb(
|
53
|
+
tables.todos
|
54
|
+
.select()
|
55
|
+
.where({ completed: false, deletedAt: null })
|
56
|
+
.orderBy('position'),
|
57
|
+
{ label: 'activeTodos' }
|
58
|
+
)
|
59
|
+
\`\`\`
|
60
|
+
|
61
|
+
### Advanced Query Capabilities
|
62
|
+
- **Joins & Aggregations**: Full SQL expressiveness
|
63
|
+
- **Reactive Subscriptions**: Automatic UI updates on data changes
|
64
|
+
- **Query Optimization**: SQLite query planner with B-tree indexes
|
65
|
+
- **Prepared Statements**: Cached query compilation for performance
|
66
|
+
|
67
|
+
### Framework Integrations
|
68
|
+
- **React**: \`useLiveQuery()\` hook for reactive components
|
69
|
+
- **Vue**: Composables for reactive data binding
|
70
|
+
- **Solid**: Reactive primitives integration
|
71
|
+
- **Svelte**: Store-based reactive updates
|
72
|
+
|
73
|
+
## 🔐 End-to-End Type Safety
|
74
|
+
|
75
|
+
### Schema-First Development
|
76
|
+
\`\`\`typescript
|
77
|
+
// Type safety from database to UI
|
78
|
+
const todoSchema = State.SQLite.table({
|
79
|
+
name: 'todos',
|
80
|
+
columns: {
|
81
|
+
id: State.SQLite.text({ primaryKey: true }),
|
82
|
+
title: State.SQLite.text(),
|
83
|
+
completed: State.SQLite.boolean()
|
84
|
+
}
|
85
|
+
})
|
86
|
+
|
87
|
+
// Fully typed queries
|
88
|
+
type Todo = typeof todoSchema.select.Type // { id: string, title: string, completed: boolean }
|
89
|
+
\`\`\`
|
90
|
+
|
91
|
+
### Runtime Validation
|
92
|
+
- **Schema Validation**: All events validated against Effect schemas
|
93
|
+
- **Migration Safety**: Type-safe schema evolution
|
94
|
+
- **Parse Don't Validate**: Schema types flow through entire application
|
95
|
+
|
96
|
+
## 🌐 Multi-Platform Support
|
97
|
+
|
98
|
+
### Web Platform
|
99
|
+
- **Origin Private File System**: Persistent storage in modern browsers
|
100
|
+
- **SharedWorker**: Cross-tab synchronization and resource sharing
|
101
|
+
- **IndexedDB Fallback**: Compatibility with older browsers
|
102
|
+
- **Service Worker**: Background synchronization
|
103
|
+
|
104
|
+
### Node.js Platform
|
105
|
+
- **File System Storage**: Native SQLite database files
|
106
|
+
- **Cluster Coordination**: Multi-process synchronization
|
107
|
+
- **HTTP/WebSocket Sync**: Flexible transport protocols
|
108
|
+
- **Background Jobs**: Scheduled synchronization tasks
|
109
|
+
|
110
|
+
### Mobile Platforms (Expo/React Native)
|
111
|
+
- **Native SQLite**: Platform-optimized database performance
|
112
|
+
- **Background Sync**: Synchronization during app backgrounding
|
113
|
+
- **Push Notifications**: Real-time update notifications
|
114
|
+
- **Secure Storage**: Encrypted local data storage
|
115
|
+
|
116
|
+
## 🚀 Performance & Scalability
|
117
|
+
|
118
|
+
### Query Performance
|
119
|
+
- **Sub-millisecond Queries**: Local SQLite performance
|
120
|
+
- **Efficient Indexing**: Automatic index recommendations
|
121
|
+
- **Result Set Streaming**: Large datasets loaded incrementally
|
122
|
+
- **Query Result Caching**: Expensive computations cached
|
123
|
+
|
124
|
+
### Memory Management
|
125
|
+
- **Lazy Loading**: Data loaded on-demand
|
126
|
+
- **Connection Pooling**: Database connections efficiently reused
|
127
|
+
- **Event Log Compaction**: Periodic snapshots prevent unbounded growth
|
128
|
+
- **Garbage Collection**: Automatic cleanup of obsolete data
|
129
|
+
|
130
|
+
### Network Optimization
|
131
|
+
- **Compression**: Event payloads compressed for transmission
|
132
|
+
- **Request Batching**: Multiple operations in single request
|
133
|
+
- **Connection Pooling**: HTTP/WebSocket connections reused
|
134
|
+
- **Exponential Backoff**: Intelligent retry strategies
|
135
|
+
|
136
|
+
## 🏗️ Developer Experience
|
137
|
+
|
138
|
+
### Testing & Debugging
|
139
|
+
\`\`\`typescript
|
140
|
+
// Built-in testing utilities
|
141
|
+
const testStore = createTestStore(schema)
|
142
|
+
|
143
|
+
// Deterministic event replay for testing
|
144
|
+
await testStore.replay([
|
145
|
+
events.todoCreated({ id: '1', title: 'Test todo' }),
|
146
|
+
events.todoCompleted({ id: '1' })
|
147
|
+
])
|
148
|
+
\`\`\`
|
149
|
+
|
150
|
+
### Developer Tools
|
151
|
+
- **Event Inspector**: Real-time event log visualization
|
152
|
+
- **Query Profiler**: Performance analysis for slow queries
|
153
|
+
- **Sync Monitor**: Network synchronization health dashboard
|
154
|
+
- **Schema Explorer**: Interactive database schema browsing
|
155
|
+
|
156
|
+
### Production Monitoring
|
157
|
+
- **Distributed Tracing**: Event propagation across replicas
|
158
|
+
- **Performance Metrics**: Query latency and throughput monitoring
|
159
|
+
- **Error Tracking**: Comprehensive error reporting and alerting
|
160
|
+
- **Health Checks**: Automated system health verification
|
161
|
+
|
162
|
+
## 🔒 Security & Privacy
|
163
|
+
|
164
|
+
### Data Protection
|
165
|
+
- **End-to-End Encryption**: Client-side encryption before transmission
|
166
|
+
- **Event Signatures**: Cryptographic integrity verification
|
167
|
+
- **Access Control**: Fine-grained permission system
|
168
|
+
- **Audit Logging**: Comprehensive security event logging
|
169
|
+
|
170
|
+
### Privacy by Design
|
171
|
+
- **Local Data Control**: Users maintain complete data ownership
|
172
|
+
- **Selective Sync**: Fine-grained control over data sharing
|
173
|
+
- **Data Minimization**: Only sync necessary data
|
174
|
+
- **GDPR Compliance**: Built-in privacy compliance features
|
175
|
+
|
176
|
+
LiveStore combines the reliability of traditional databases with the performance and user experience of local-first applications, enabling you to build applications that users love while maintaining the technical rigor of distributed systems.`
|