@livestore/cli 0.4.0-dev.8 → 0.4.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.
Files changed (77) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/__tests__/fixtures/mock-config.d.ts +65 -0
  3. package/dist/__tests__/fixtures/mock-config.d.ts.map +1 -0
  4. package/dist/__tests__/fixtures/mock-config.js +94 -0
  5. package/dist/__tests__/fixtures/mock-config.js.map +1 -0
  6. package/dist/__tests__/sync-operations.test.d.ts +2 -0
  7. package/dist/__tests__/sync-operations.test.d.ts.map +1 -0
  8. package/dist/__tests__/sync-operations.test.js +167 -0
  9. package/dist/__tests__/sync-operations.test.js.map +1 -0
  10. package/dist/bin.js.map +1 -1
  11. package/dist/cli.d.ts +16 -2
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +3 -4
  14. package/dist/cli.js.map +1 -1
  15. package/dist/commands/import-export.d.ts +34 -0
  16. package/dist/commands/import-export.d.ts.map +1 -0
  17. package/dist/commands/import-export.js +135 -0
  18. package/dist/commands/import-export.js.map +1 -0
  19. package/dist/commands/mcp-coach.d.ts +13 -5
  20. package/dist/commands/mcp-coach.d.ts.map +1 -1
  21. package/dist/commands/mcp-coach.js +41 -45
  22. package/dist/commands/mcp-coach.js.map +1 -1
  23. package/dist/commands/mcp-tool-handlers.d.ts +6 -0
  24. package/dist/commands/mcp-tool-handlers.d.ts.map +1 -0
  25. package/dist/commands/{mcp-tools.js → mcp-tool-handlers.js} +79 -45
  26. package/dist/commands/mcp-tool-handlers.js.map +1 -0
  27. package/dist/commands/mcp-tools-defs.d.ts +133 -0
  28. package/dist/commands/mcp-tools-defs.d.ts.map +1 -0
  29. package/dist/commands/mcp-tools-defs.js +278 -0
  30. package/dist/commands/mcp-tools-defs.js.map +1 -0
  31. package/dist/commands/mcp.d.ts.map +1 -1
  32. package/dist/commands/mcp.js +2 -1
  33. package/dist/commands/mcp.js.map +1 -1
  34. package/dist/commands/new-project.d.ts +9 -2
  35. package/dist/commands/new-project.d.ts.map +1 -1
  36. package/dist/commands/new-project.js +72 -32
  37. package/dist/commands/new-project.js.map +1 -1
  38. package/dist/mcp-runtime/runtime.d.ts +48 -0
  39. package/dist/mcp-runtime/runtime.d.ts.map +1 -0
  40. package/dist/mcp-runtime/runtime.js +107 -0
  41. package/dist/mcp-runtime/runtime.js.map +1 -0
  42. package/dist/module-loader.d.ts +22 -0
  43. package/dist/module-loader.d.ts.map +1 -0
  44. package/dist/module-loader.js +75 -0
  45. package/dist/module-loader.js.map +1 -0
  46. package/dist/package-manager.d.ts +38 -0
  47. package/dist/package-manager.d.ts.map +1 -0
  48. package/dist/package-manager.js +33 -0
  49. package/dist/package-manager.js.map +1 -0
  50. package/dist/package-manager.test.d.ts +2 -0
  51. package/dist/package-manager.test.d.ts.map +1 -0
  52. package/dist/package-manager.test.js +57 -0
  53. package/dist/package-manager.test.js.map +1 -0
  54. package/dist/sync-operations.d.ts +121 -0
  55. package/dist/sync-operations.d.ts.map +1 -0
  56. package/dist/sync-operations.js +180 -0
  57. package/dist/sync-operations.js.map +1 -0
  58. package/package.json +71 -15
  59. package/src/__tests__/fixtures/mock-config.ts +112 -0
  60. package/src/__tests__/sync-operations.test.ts +232 -0
  61. package/src/bin.ts +1 -0
  62. package/src/cli.ts +4 -5
  63. package/src/commands/import-export.ts +283 -0
  64. package/src/commands/mcp-coach.ts +67 -67
  65. package/src/commands/{mcp-tools.ts → mcp-tool-handlers.ts} +93 -57
  66. package/src/commands/mcp-tools-defs.ts +318 -0
  67. package/src/commands/mcp.ts +3 -2
  68. package/src/commands/new-project.ts +90 -36
  69. package/src/mcp-runtime/runtime.ts +147 -0
  70. package/src/module-loader.ts +94 -0
  71. package/src/package-manager.test.ts +66 -0
  72. package/src/package-manager.ts +44 -0
  73. package/src/sync-operations.ts +360 -0
  74. package/dist/commands/mcp-tools.d.ts +0 -58
  75. package/dist/commands/mcp-tools.d.ts.map +0 -1
  76. package/dist/commands/mcp-tools.js.map +0 -1
  77. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,180 @@
1
+ import { UnknownError } from '@livestore/common';
2
+ import { LiveStoreEvent } from '@livestore/common/schema';
3
+ import { Cause, Chunk, Effect, KeyValueStore, Option, Schema, Stream, SubscriptionRef, } from '@livestore/utils/effect';
4
+ import { loadModuleConfig } from "./module-loader.js";
5
+ /** Connection timeout for sync backend ping (5 seconds) */
6
+ const CONNECTION_TIMEOUT_MS = 5000;
7
+ /**
8
+ * Schema for the export file format.
9
+ * Contains metadata about the export and an array of events in global encoded format.
10
+ */
11
+ export const ExportFileSchema = Schema.Struct({
12
+ /** Format version for future compatibility */
13
+ version: Schema.Literal(1),
14
+ /** Store identifier */
15
+ storeId: Schema.String,
16
+ /** ISO timestamp of when the export was created */
17
+ exportedAt: Schema.String,
18
+ /** Total number of events in the export */
19
+ eventCount: Schema.Number,
20
+ /** Array of events in global encoded format */
21
+ events: Schema.Array(LiveStoreEvent.Global.Encoded),
22
+ });
23
+ export class ConnectionError extends Schema.TaggedError('~@livestore/cli/ConnectionError')('ConnectionError', {
24
+ cause: Schema.Defect,
25
+ note: Schema.String,
26
+ }) {
27
+ }
28
+ export class ExportError extends Schema.TaggedError('~@livestore/cli/ExportError')('ExportError', {
29
+ cause: Schema.Defect,
30
+ note: Schema.String,
31
+ }) {
32
+ }
33
+ export class ImportError extends Schema.TaggedError('~@livestore/cli/ImportError')('ImportError', {
34
+ cause: Schema.Defect,
35
+ note: Schema.String,
36
+ }) {
37
+ }
38
+ /**
39
+ * Creates a sync backend connection from a user module and verifies connectivity.
40
+ * This is a simplified version of the MCP runtime that only creates the sync backend.
41
+ */
42
+ export const makeSyncBackend = ({ configPath, storeId, clientId, }) => Effect.gen(function* () {
43
+ const { syncBackendConstructor, syncPayload } = yield* loadModuleConfig({ configPath });
44
+ const syncBackend = yield* syncBackendConstructor({
45
+ storeId,
46
+ clientId,
47
+ /** syncPayload is validated against syncPayloadSchema by loadModuleConfig */
48
+ payload: syncPayload,
49
+ }).pipe(Effect.provide(KeyValueStore.layerMemory), UnknownError.mapToUnknownError);
50
+ /** Connect to the sync backend */
51
+ yield* syncBackend.connect.pipe(Effect.mapError((cause) => new ConnectionError({
52
+ cause,
53
+ note: `Failed to connect to sync backend: ${cause._tag === 'IsOfflineError' ? 'Backend is offline or unreachable' : String(cause)}`,
54
+ })));
55
+ /** Verify connectivity with a ping (with timeout) */
56
+ yield* syncBackend.ping.pipe(Effect.timeout(CONNECTION_TIMEOUT_MS), Effect.catchAll((cause) => {
57
+ if (Cause.isTimeoutException(cause) === true) {
58
+ return Effect.fail(new ConnectionError({
59
+ cause,
60
+ note: `Connection timeout: Sync backend did not respond within ${CONNECTION_TIMEOUT_MS}ms`,
61
+ }));
62
+ }
63
+ return Effect.fail(new ConnectionError({
64
+ cause,
65
+ note: `Failed to ping sync backend: ${cause._tag === 'IsOfflineError' ? 'Backend is offline or unreachable' : String(cause)}`,
66
+ }));
67
+ }));
68
+ return syncBackend;
69
+ });
70
+ const releaseSyncBackend = (syncBackend) => {
71
+ const maybeDisconnect = syncBackend.disconnect;
72
+ const releaseEffect = maybeDisconnect ?? SubscriptionRef.set(syncBackend.isConnected, false);
73
+ return releaseEffect.pipe(Effect.orElse(() => Effect.void));
74
+ };
75
+ /**
76
+ * Core export operation - pulls all events from sync backend.
77
+ * Returns the export data structure without writing to file.
78
+ */
79
+ export const pullEventsFromSyncBackend = ({ configPath, storeId, clientId, }) => Effect.acquireUseRelease(makeSyncBackend({ configPath, storeId, clientId }), (syncBackend) => Effect.gen(function* () {
80
+ const backendName = syncBackend.metadata.name;
81
+ const batchesChunk = yield* syncBackend.pull(Option.none(), { live: false }).pipe(Stream.takeUntil((item) => item.pageInfo._tag === 'NoMore'), Stream.runCollect, Effect.mapError((cause) => new ExportError({
82
+ cause,
83
+ note: `Failed to pull events from sync backend: ${String(cause)}`,
84
+ })));
85
+ const events = Chunk.toReadonlyArray(batchesChunk)
86
+ .flatMap((item) => item.batch)
87
+ .map((item) => item.eventEncoded);
88
+ const exportedAt = new Date().toISOString();
89
+ const exportData = {
90
+ version: 1,
91
+ storeId,
92
+ exportedAt,
93
+ eventCount: events.length,
94
+ events,
95
+ };
96
+ return {
97
+ storeId,
98
+ eventCount: events.length,
99
+ exportedAt,
100
+ backendName,
101
+ data: exportData,
102
+ };
103
+ }), releaseSyncBackend).pipe(Effect.withSpan('sync:pullEvents'));
104
+ /**
105
+ * Validates an export file for import.
106
+ * Returns validation info without actually importing.
107
+ */
108
+ export const validateExportData = ({ data, targetStoreId, }) => Effect.gen(function* () {
109
+ const exportData = yield* Schema.decodeUnknown(ExportFileSchema)(data).pipe(Effect.mapError((cause) => new ImportError({
110
+ cause: new Error(`Invalid export file format: ${String(cause)}`),
111
+ note: `Invalid export file format: ${String(cause)}`,
112
+ })));
113
+ return {
114
+ storeId: targetStoreId,
115
+ eventCount: exportData.events.length,
116
+ sourceStoreId: exportData.storeId,
117
+ storeIdMismatch: exportData.storeId !== targetStoreId,
118
+ };
119
+ });
120
+ /**
121
+ * Core import operation - pushes events to sync backend.
122
+ * Validates that the backend is empty before importing.
123
+ */
124
+ export const pushEventsToSyncBackend = ({ configPath, storeId, clientId, data, force, dryRun, onProgress, }) => Effect.acquireUseRelease(makeSyncBackend({ configPath, storeId, clientId }), (syncBackend) => Effect.gen(function* () {
125
+ const exportData = yield* Schema.decodeUnknown(ExportFileSchema)(data).pipe(Effect.mapError((cause) => new ImportError({
126
+ cause: new Error(`Invalid export file format: ${String(cause)}`),
127
+ note: `Invalid export file format: ${String(cause)}`,
128
+ })));
129
+ if (exportData.storeId !== storeId && force === false) {
130
+ return yield* new ImportError({
131
+ cause: new Error(`Store ID mismatch: file has '${exportData.storeId}', expected '${storeId}'`),
132
+ note: `The export file was created for a different store. Use force option to import anyway.`,
133
+ });
134
+ }
135
+ if (dryRun === true) {
136
+ return {
137
+ storeId,
138
+ eventCount: exportData.events.length,
139
+ dryRun: true,
140
+ };
141
+ }
142
+ const backendName = syncBackend.metadata.name;
143
+ /** Check if events already exist by pulling from the backend first (short-circuit on first non-empty batch) */
144
+ const existingBatchOption = yield* syncBackend.pull(Option.none(), { live: false }).pipe(Stream.filter((item) => item.batch.length > 0), Stream.runHead, Effect.mapError((cause) => new ImportError({
145
+ cause,
146
+ note: `Failed to check existing events: ${String(cause)}`,
147
+ })));
148
+ if (Option.isSome(existingBatchOption) === true) {
149
+ const existingBatch = existingBatchOption.value;
150
+ const estimatedCount = existingBatch.pageInfo._tag === 'MoreKnown'
151
+ ? existingBatch.batch.length + existingBatch.pageInfo.remaining
152
+ : existingBatch.batch.length;
153
+ return yield* new ImportError({
154
+ cause: new Error(`Sync backend already contains at least ${estimatedCount} events`),
155
+ note: `Cannot import into a non-empty sync backend. The sync backend must be empty.`,
156
+ });
157
+ }
158
+ /** Push events in batches of 100 (sync backend constraint) */
159
+ const batchSize = 100;
160
+ const total = exportData.events.length;
161
+ let pushed = 0;
162
+ for (let i = 0; i < exportData.events.length; i += batchSize) {
163
+ const batch = exportData.events.slice(i, i + batchSize);
164
+ yield* syncBackend.push(batch).pipe(Effect.mapError((cause) => new ImportError({
165
+ cause,
166
+ note: `Failed to push events at position ${i}: ${String(cause)}`,
167
+ })));
168
+ pushed += batch.length;
169
+ if (onProgress !== undefined) {
170
+ yield* onProgress(pushed, total);
171
+ }
172
+ }
173
+ return {
174
+ storeId,
175
+ eventCount: exportData.events.length,
176
+ dryRun: false,
177
+ backendName,
178
+ };
179
+ }), releaseSyncBackend).pipe(Effect.withSpan('sync:pushEvents'));
180
+ //# sourceMappingURL=sync-operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-operations.js","sourceRoot":"","sources":["../src/sync-operations.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EACL,KAAK,EACL,KAAK,EACL,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CAAA;IAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAA;QAEvD,KAAK,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CACjC,MAAM,CAAC,QAAQ,CACb,CAAC,KAAK,EAAE,EAAE,CACR,IAAI,WAAW,CAAC;YACd,KAAK;YACL,IAAI,EAAE,qCAAqC,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE;SACjE,CAAC,CACL,CACF,CAAA;QAED,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;QACtB,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,KAAK,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO;QACP,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM;QACpC,MAAM,EAAE,KAAK;QACb,WAAW;KACZ,CAAA;AACH,CAAC,CAAC,EACJ,kBAAkB,CACnB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,30 +1,86 @@
1
1
  {
2
2
  "name": "@livestore/cli",
3
- "version": "0.4.0-dev.8",
3
+ "version": "0.4.0",
4
+ "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/livestorejs/livestore.git"
8
+ },
9
+ "bin": {
10
+ "livestore": "./dist/bin.js"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "package.json",
15
+ "src"
16
+ ],
4
17
  "type": "module",
5
18
  "sideEffects": false,
6
19
  "exports": {
7
20
  ".": "./dist/mod.js"
8
21
  },
9
- "bin": {
10
- "livestore": "./dist/bin.js"
22
+ "publishConfig": {
23
+ "access": "public"
11
24
  },
12
25
  "dependencies": {
13
- "@effect/ai-openai": "0.30.1",
14
- "@livestore/common": "0.4.0-dev.8",
15
- "@livestore/utils": "0.4.0-dev.8"
26
+ "@effect/ai": "0.35.0",
27
+ "@effect/ai-openai": "0.39.0",
28
+ "@effect/experimental": "0.60.0",
29
+ "@effect/opentelemetry": "0.63.0",
30
+ "@effect/platform": "0.96.1",
31
+ "@effect/rpc": "0.75.1",
32
+ "effect": "3.21.2",
33
+ "@livestore/common": "^0.4.0",
34
+ "@livestore/adapter-node": "^0.4.0",
35
+ "@livestore/peer-deps": "^0.4.0",
36
+ "@livestore/utils": "^0.4.0",
37
+ "@livestore/livestore": "^0.4.0"
16
38
  },
17
39
  "devDependencies": {
18
- "@types/node": "24.2.0",
19
- "typescript": "5.9.2"
40
+ "@types/node": "25.3.3",
41
+ "typescript": "5.9.3",
42
+ "vitest": "3.2.4",
43
+ "@livestore/utils-dev": "^0.4.0"
20
44
  },
21
- "files": [
22
- "package.json",
23
- "src",
24
- "dist"
25
- ],
26
- "publishConfig": {
27
- "access": "public"
45
+ "peerDependencies": {
46
+ "@effect/ai": "^0.35.0",
47
+ "@effect/cli": "^0.75.1",
48
+ "@effect/cluster": "^0.58.2",
49
+ "@effect/experimental": "^0.60.0",
50
+ "@effect/opentelemetry": "^0.63.0",
51
+ "@effect/platform": "^0.96.1",
52
+ "@effect/platform-browser": "^0.76.0",
53
+ "@effect/platform-bun": "^0.89.0",
54
+ "@effect/platform-node": "^0.106.0",
55
+ "@effect/printer": "^0.49.0",
56
+ "@effect/printer-ansi": "^0.49.0",
57
+ "@effect/rpc": "^0.75.1",
58
+ "@effect/sql": "^0.51.1",
59
+ "@effect/typeclass": "^0.40.0",
60
+ "@effect/vitest": "^0.29.0",
61
+ "@opentelemetry/api": "^1.9.0",
62
+ "@opentelemetry/resources": "^2.2.0",
63
+ "@standard-schema/spec": "^1.1.0",
64
+ "effect": "^3.21.2"
65
+ },
66
+ "$genie": {
67
+ "source": "package.json.genie.ts",
68
+ "warning": "DO NOT EDIT - changes will be overwritten",
69
+ "workspaceClosureDirs": [
70
+ "packages/@livestore/adapter-node",
71
+ "packages/@livestore/adapter-web",
72
+ "packages/@livestore/cli",
73
+ "packages/@livestore/common",
74
+ "packages/@livestore/common-cf",
75
+ "packages/@livestore/devtools-web-common",
76
+ "packages/@livestore/livestore",
77
+ "packages/@livestore/peer-deps",
78
+ "packages/@livestore/sqlite-wasm",
79
+ "packages/@livestore/utils",
80
+ "packages/@livestore/utils-dev",
81
+ "packages/@livestore/wa-sqlite",
82
+ "packages/@livestore/webmesh"
83
+ ]
28
84
  },
29
85
  "scripts": {
30
86
  "build": "tsc",
@@ -0,0 +1,112 @@
1
+ import path from 'node:path'
2
+ import { fileURLToPath, pathToFileURL } from 'node:url'
3
+
4
+ import { Events, makeSchema, State } from '@livestore/common/schema'
5
+ import type { MockSyncBackend } from '@livestore/common/sync'
6
+ import { EventFactory } from '@livestore/common/testing'
7
+ import { Effect, FileSystem, type Mailbox, Schema } from '@livestore/utils/effect'
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+
11
+ class DynamicImportError extends Schema.TaggedError<DynamicImportError>()('DynamicImportError', {
12
+ cause: Schema.Defect,
13
+ path: Schema.String,
14
+ }) {}
15
+
16
+ // Use package-local temp directory for test config files to ensure proper module resolution
17
+ const tmpDir = path.join(__dirname, '.tmp-test-configs')
18
+
19
+ const items = State.SQLite.table({
20
+ name: 'items',
21
+ columns: {
22
+ id: State.SQLite.text({ primaryKey: true }),
23
+ title: State.SQLite.text({ default: '', nullable: false }),
24
+ },
25
+ })
26
+
27
+ export const events = {
28
+ itemAdded: Events.synced({
29
+ name: 'itemAdded',
30
+ schema: Schema.Struct({ id: Schema.String, title: Schema.String }),
31
+ }),
32
+ }
33
+
34
+ const materializers = State.SQLite.materializers(events, {
35
+ itemAdded: ({ id, title }) => items.insert({ id, title }),
36
+ })
37
+
38
+ const state = State.SQLite.makeState({
39
+ tables: { items },
40
+ materializers,
41
+ })
42
+
43
+ export const schema = makeSchema({ state, events })
44
+
45
+ const schemaModuleUrl = pathToFileURL(path.join(__dirname, 'mock-config.ts')).href
46
+
47
+ /** Generates a per-test config module exporting schema, a mock backend, and connection event taps. */
48
+ const makeTempConfig = () => {
49
+ const moduleSource = `
50
+ import { schema } from ${JSON.stringify(schemaModuleUrl)}
51
+ import { makeMockSyncBackend } from '@livestore/common/sync'
52
+ import { Effect, Mailbox } from '@livestore/utils/effect'
53
+
54
+ export const mockBackend = await Effect.runPromise(Effect.scoped(makeMockSyncBackend({ startConnected: true })))
55
+ export const connectionEvents = await Effect.runPromise(Mailbox.make<'connect' | 'disconnect'>())
56
+
57
+ export { schema }
58
+
59
+ export const syncBackend = (_args) =>
60
+ mockBackend.makeSyncBackend.pipe(
61
+ Effect.tap(() => connectionEvents.offer('connect')),
62
+ Effect.map((backend) => {
63
+ const disconnect = backend.disconnect ?? Effect.void
64
+ return {
65
+ ...backend,
66
+ disconnect: disconnect.pipe(Effect.tap(() => connectionEvents.offer('disconnect'))),
67
+ }
68
+ }),
69
+ )
70
+ `
71
+
72
+ return moduleSource
73
+ }
74
+
75
+ /**
76
+ * Creates a temporary config module (schema + mock backend) and cleans it up afterwards.
77
+ * Returns the module path plus handles to the backend and connection event mailbox, keeping lifecycle assertions local to each test.
78
+ */
79
+ export const useMockConfig = Effect.acquireRelease(
80
+ Effect.gen(function* () {
81
+ const fs = yield* FileSystem.FileSystem
82
+
83
+ yield* fs.makeDirectory(tmpDir, { recursive: true })
84
+
85
+ const tempPath = path.join(tmpDir, `mock-config-${Date.now()}-${Math.random().toString(16).slice(2)}.ts`)
86
+ const moduleSource = makeTempConfig()
87
+
88
+ yield* fs.writeFileString(tempPath, moduleSource)
89
+
90
+ const mod = (yield* Effect.tryPromise({
91
+ try: () => import(pathToFileURL(tempPath).href),
92
+ catch: (cause) => new DynamicImportError({ cause, path: tempPath }),
93
+ })) as {
94
+ mockBackend: MockSyncBackend
95
+ connectionEvents: Mailbox.Mailbox<'connect' | 'disconnect'>
96
+ }
97
+
98
+ return { configPath: tempPath, mockBackend: mod.mockBackend, connectionEvents: mod.connectionEvents }
99
+ }),
100
+ ({ configPath }) =>
101
+ Effect.gen(function* () {
102
+ const fs = yield* FileSystem.FileSystem
103
+ yield* fs.remove(configPath, { recursive: false }).pipe(Effect.catchAll(() => Effect.void))
104
+ }),
105
+ )
106
+
107
+ export const makeEventFactory = () =>
108
+ EventFactory.makeFactory(events)({
109
+ client: EventFactory.clientIdentity('cli-test-client'),
110
+ startSeq: 1,
111
+ initialParent: 'root',
112
+ })
@@ -0,0 +1,232 @@
1
+ import { expect } from 'vitest'
2
+
3
+ import type { LiveStoreEvent } from '@livestore/common/schema'
4
+ import { Vitest } from '@livestore/utils-dev/node-vitest'
5
+ import { Chunk, Effect, FetchHttpClient, Layer, Mailbox, Stream } from '@livestore/utils/effect'
6
+ import { PlatformNode } from '@livestore/utils/node'
7
+
8
+ import { pullEventsFromSyncBackend, pushEventsToSyncBackend } from '../sync-operations.ts'
9
+ import { makeEventFactory, useMockConfig } from './fixtures/mock-config.ts'
10
+
11
+ const baseLayer = Layer.mergeAll(PlatformNode.NodeFileSystem.layer, FetchHttpClient.layer)
12
+ const withTestCtx = Vitest.makeWithTestCtx({ makeLayer: () => baseLayer })
13
+
14
+ /** Each test acquires its own temporary config module via useMockConfig, avoiding shared state. */
15
+ Vitest.describe('sync-operations', { timeout: 10_000 }, () => {
16
+ const storeId = 'test-store'
17
+ const clientId = 'test-client'
18
+
19
+ /** Collects the connect + disconnect lifecycle emitted by the mock sync backend. */
20
+ const expectConnectLifecycle = (
21
+ mailbox: Mailbox.Mailbox<'connect' | 'disconnect'>,
22
+ ): Effect.Effect<ReadonlyArray<'connect' | 'disconnect'>> =>
23
+ Mailbox.toStream(mailbox).pipe(
24
+ Stream.take(2),
25
+ Stream.runCollect,
26
+ Effect.map((chunk) => Chunk.toReadonlyArray(chunk)),
27
+ )
28
+
29
+ Vitest.scopedLive('exports events and releases the backend connection', (test: Vitest.TestContext) =>
30
+ Effect.gen(function* () {
31
+ const { mockBackend, connectionEvents, configPath } = yield* useMockConfig
32
+ const factory = makeEventFactory()
33
+
34
+ const batch = [
35
+ factory.itemAdded.next({ id: 'e1', title: 'First' }),
36
+ factory.itemAdded.next({ id: 'e2', title: 'Second' }),
37
+ ]
38
+
39
+ yield* mockBackend.advance(...batch)
40
+
41
+ const result = yield* pullEventsFromSyncBackend({
42
+ configPath,
43
+ storeId,
44
+ clientId,
45
+ })
46
+
47
+ expect(result.eventCount).toBe(2)
48
+ expect(result.data.events).toHaveLength(2)
49
+
50
+ const lifecycle = yield* expectConnectLifecycle(connectionEvents)
51
+ expect(lifecycle).toEqual(['connect', 'disconnect'])
52
+ }).pipe(withTestCtx(test)),
53
+ )
54
+
55
+ Vitest.scopedLive('fails import when backend is not empty', (test: Vitest.TestContext) =>
56
+ Effect.gen(function* () {
57
+ const { mockBackend, connectionEvents, configPath } = yield* useMockConfig
58
+ const factory = makeEventFactory()
59
+
60
+ yield* mockBackend.advance(factory.itemAdded.next({ id: 'existing', title: 'Present' }))
61
+
62
+ const importBatch = [
63
+ factory.itemAdded.next({ id: 'incoming-1', title: 'Incoming' }),
64
+ factory.itemAdded.next({ id: 'incoming-2', title: 'Incoming 2' }),
65
+ ]
66
+
67
+ const result = yield* pushEventsToSyncBackend({
68
+ configPath,
69
+ storeId,
70
+ clientId,
71
+ data: {
72
+ version: 1,
73
+ storeId,
74
+ exportedAt: new Date().toISOString(),
75
+ eventCount: importBatch.length,
76
+ events: importBatch,
77
+ },
78
+ force: false,
79
+ dryRun: false,
80
+ }).pipe(Effect.either)
81
+
82
+ expect(result._tag).toBe('Left')
83
+ if (result._tag === 'Left') {
84
+ expect(result.left._tag).toBe('ImportError')
85
+ }
86
+
87
+ const lifecycle = yield* expectConnectLifecycle(connectionEvents)
88
+ expect(lifecycle).toEqual(['connect', 'disconnect'])
89
+ }).pipe(withTestCtx(test)),
90
+ )
91
+
92
+ Vitest.scopedLive('supports dry-run import and releases backend', (test: Vitest.TestContext) =>
93
+ Effect.gen(function* () {
94
+ const { configPath, connectionEvents } = yield* useMockConfig
95
+ const factory = makeEventFactory()
96
+ const importBatch = [factory.itemAdded.next({ id: 'dry-run', title: 'Simulated' })]
97
+
98
+ const result = yield* pushEventsToSyncBackend({
99
+ configPath,
100
+ storeId,
101
+ clientId,
102
+ data: {
103
+ version: 1,
104
+ storeId,
105
+ exportedAt: new Date().toISOString(),
106
+ eventCount: importBatch.length,
107
+ events: importBatch,
108
+ },
109
+ force: false,
110
+ dryRun: true,
111
+ })
112
+
113
+ expect(result.dryRun).toBe(true)
114
+ expect(result.eventCount).toBe(importBatch.length)
115
+
116
+ const lifecycle = yield* expectConnectLifecycle(connectionEvents)
117
+ expect(lifecycle).toEqual(['connect', 'disconnect'])
118
+ }).pipe(withTestCtx(test)),
119
+ )
120
+
121
+ Vitest.scopedLive('imports events into empty backend with progress and batching', (test: Vitest.TestContext) =>
122
+ Effect.gen(function* () {
123
+ const { mockBackend, configPath, connectionEvents } = yield* useMockConfig
124
+ const factory = makeEventFactory()
125
+ const importBatch = Array.from({ length: 120 }, (_, idx) =>
126
+ factory.itemAdded.next({ id: `id-${idx + 1}`, title: `Item ${idx + 1}` }),
127
+ )
128
+
129
+ const progress: Array<{ pushed: number; total: number }> = []
130
+
131
+ const result = yield* pushEventsToSyncBackend({
132
+ configPath,
133
+ storeId,
134
+ clientId,
135
+ data: {
136
+ version: 1,
137
+ storeId,
138
+ exportedAt: new Date().toISOString(),
139
+ eventCount: importBatch.length,
140
+ events: importBatch,
141
+ },
142
+ force: false,
143
+ dryRun: false,
144
+ onProgress: (pushed, total) => Effect.sync(() => progress.push({ pushed, total })),
145
+ })
146
+
147
+ expect(result.dryRun).toBe(false)
148
+ expect(result.eventCount).toBe(importBatch.length)
149
+ expect(progress).toEqual([
150
+ { pushed: 100, total: 120 },
151
+ { pushed: 120, total: 120 },
152
+ ])
153
+
154
+ const pushedEvents = yield* mockBackend.pushedEvents.pipe(
155
+ Stream.take(importBatch.length),
156
+ Stream.runCollect,
157
+ Effect.map((chunk: Chunk.Chunk<LiveStoreEvent.Global.Encoded>) => Chunk.toReadonlyArray(chunk)),
158
+ )
159
+ expect(pushedEvents.map((event) => event.seqNum)).toHaveLength(importBatch.length)
160
+
161
+ const lifecycle = yield* expectConnectLifecycle(connectionEvents)
162
+ expect(lifecycle).toEqual(['connect', 'disconnect'])
163
+ }).pipe(withTestCtx(test)),
164
+ )
165
+
166
+ Vitest.scopedLive('allows force import on store ID mismatch', (test: Vitest.TestContext) =>
167
+ Effect.gen(function* () {
168
+ const { mockBackend, configPath, connectionEvents } = yield* useMockConfig
169
+ const factory = makeEventFactory()
170
+ const importBatch = [factory.itemAdded.next({ id: 'force-1', title: 'Force' })]
171
+
172
+ const result = yield* pushEventsToSyncBackend({
173
+ configPath,
174
+ storeId,
175
+ clientId,
176
+ data: {
177
+ version: 1,
178
+ storeId: 'different-store',
179
+ exportedAt: new Date().toISOString(),
180
+ eventCount: importBatch.length,
181
+ events: importBatch,
182
+ },
183
+ force: true,
184
+ dryRun: false,
185
+ })
186
+
187
+ expect(result.dryRun).toBe(false)
188
+ expect(result.eventCount).toBe(importBatch.length)
189
+
190
+ const pushedEvents = yield* mockBackend.pushedEvents.pipe(
191
+ Stream.take(1),
192
+ Stream.runCollect,
193
+ Effect.map((chunk: Chunk.Chunk<LiveStoreEvent.Global.Encoded>) => Chunk.toReadonlyArray(chunk)),
194
+ )
195
+ expect(pushedEvents).toHaveLength(1)
196
+
197
+ const lifecycle = yield* expectConnectLifecycle(connectionEvents)
198
+ expect(lifecycle).toEqual(['connect', 'disconnect'])
199
+ }).pipe(withTestCtx(test)),
200
+ )
201
+
202
+ Vitest.scopedLive('rejects store ID mismatch without force', (test: Vitest.TestContext) =>
203
+ Effect.gen(function* () {
204
+ const { configPath, connectionEvents } = yield* useMockConfig
205
+ const factory = makeEventFactory()
206
+ const importBatch = [factory.itemAdded.next({ id: 'mismatch', title: 'Mismatch' })]
207
+
208
+ const result = yield* pushEventsToSyncBackend({
209
+ configPath,
210
+ storeId,
211
+ clientId,
212
+ data: {
213
+ version: 1,
214
+ storeId: 'other-store',
215
+ exportedAt: new Date().toISOString(),
216
+ eventCount: importBatch.length,
217
+ events: importBatch,
218
+ },
219
+ force: false,
220
+ dryRun: false,
221
+ }).pipe(Effect.either)
222
+
223
+ expect(result._tag).toBe('Left')
224
+ if (result._tag === 'Left') {
225
+ expect(result.left._tag).toBe('ImportError')
226
+ }
227
+
228
+ const lifecycle = yield* expectConnectLifecycle(connectionEvents)
229
+ expect(lifecycle).toEqual(['connect', 'disconnect'])
230
+ }).pipe(withTestCtx(test)),
231
+ )
232
+ })
package/src/bin.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  import { liveStoreVersion } from '@livestore/common'
4
4
  import { Console, Effect, FetchHttpClient, Layer, Logger, LogLevel } from '@livestore/utils/effect'
5
5
  import { Cli, PlatformNode } from '@livestore/utils/node'
6
+
6
7
  import { command } from './cli.ts'
7
8
 
8
9
  const cli = Cli.Command.run(command, {
package/src/cli.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { Cli } from '@livestore/utils/node'
2
+
3
+ import { syncCommand } from './commands/import-export.ts'
2
4
  import { mcpCommand } from './commands/mcp.ts'
3
- import { newProjectCommand } from './commands/new-project.ts'
5
+ import { createCommand } from './commands/new-project.ts'
4
6
 
5
7
  export const command = Cli.Command.make('livestore', {
6
8
  verbose: Cli.Options.boolean('verbose').pipe(Cli.Options.withDefault(false)),
7
- }).pipe(Cli.Command.withSubcommands([mcpCommand, newProjectCommand]))
8
-
9
- if (import.meta.main) {
10
- }
9
+ }).pipe(Cli.Command.withSubcommands([mcpCommand, createCommand, syncCommand]))