@livestore/cli 0.4.0 → 0.5.0-dev.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/dist/.tsbuildinfo +1 -1
- package/dist/__tests__/fixtures/mock-config.d.ts +7 -9
- package/dist/__tests__/fixtures/mock-config.d.ts.map +1 -1
- package/dist/__tests__/fixtures/mock-config.js +6 -6
- package/dist/__tests__/fixtures/mock-config.js.map +1 -1
- package/dist/__tests__/sync-operations.test.js +20 -20
- package/dist/__tests__/sync-operations.test.js.map +1 -1
- package/dist/bin.js +6 -5
- package/dist/bin.js.map +1 -1
- package/dist/cli.d.ts +2 -23
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/__fixtures__/mcp-protocol-server.d.ts +2 -0
- package/dist/commands/__fixtures__/mcp-protocol-server.d.ts.map +1 -0
- package/dist/commands/__fixtures__/mcp-protocol-server.js +10 -0
- package/dist/commands/__fixtures__/mcp-protocol-server.js.map +1 -0
- package/dist/commands/import-export.d.ts +5 -19
- package/dist/commands/import-export.d.ts.map +1 -1
- package/dist/commands/import-export.js +12 -12
- package/dist/commands/import-export.js.map +1 -1
- package/dist/commands/mcp-coach.d.ts +8 -7
- package/dist/commands/mcp-coach.d.ts.map +1 -1
- package/dist/commands/mcp-coach.js +10 -10
- package/dist/commands/mcp-coach.js.map +1 -1
- package/dist/commands/mcp-protocols.d.ts +7 -0
- package/dist/commands/mcp-protocols.d.ts.map +1 -0
- package/dist/commands/mcp-protocols.js +12 -0
- package/dist/commands/mcp-protocols.js.map +1 -0
- package/dist/commands/mcp-protocols.test.d.ts +2 -0
- package/dist/commands/mcp-protocols.test.d.ts.map +1 -0
- package/dist/commands/mcp-protocols.test.js +60 -0
- package/dist/commands/mcp-protocols.test.js.map +1 -0
- package/dist/commands/mcp-stdio.test.d.ts +2 -0
- package/dist/commands/mcp-stdio.test.d.ts.map +1 -0
- package/dist/commands/mcp-stdio.test.js +79 -0
- package/dist/commands/mcp-stdio.test.js.map +1 -0
- package/dist/commands/mcp-tool-handlers.d.ts +1 -1
- package/dist/commands/mcp-tool-handlers.d.ts.map +1 -1
- package/dist/commands/mcp-tool-handlers.js +1 -0
- package/dist/commands/mcp-tool-handlers.js.map +1 -1
- package/dist/commands/mcp-tools-defs.d.ts +65 -64
- package/dist/commands/mcp-tools-defs.d.ts.map +1 -1
- package/dist/commands/mcp-tools-defs.js +59 -52
- package/dist/commands/mcp-tools-defs.js.map +1 -1
- package/dist/commands/mcp-tools-defs.test.d.ts +2 -0
- package/dist/commands/mcp-tools-defs.test.d.ts.map +1 -0
- package/dist/commands/mcp-tools-defs.test.js +11 -0
- package/dist/commands/mcp-tools-defs.test.js.map +1 -0
- package/dist/commands/mcp.d.ts +1 -3
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +5 -4
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/new-project.d.ts +19 -27
- package/dist/commands/new-project.d.ts.map +1 -1
- package/dist/commands/new-project.js +17 -16
- package/dist/commands/new-project.js.map +1 -1
- package/dist/mcp-content/architecture.d.ts +1 -1
- package/dist/mcp-content/architecture.d.ts.map +1 -1
- package/dist/mcp-content/architecture.js +3 -3
- package/dist/mcp-content/features.d.ts +1 -1
- package/dist/mcp-content/features.d.ts.map +1 -1
- package/dist/mcp-content/features.js +1 -1
- package/dist/mcp-content/getting-started.d.ts +1 -1
- package/dist/mcp-content/getting-started.d.ts.map +1 -1
- package/dist/mcp-content/getting-started.js +37 -37
- package/dist/mcp-content/overview.d.ts +1 -1
- package/dist/mcp-content/overview.d.ts.map +1 -1
- package/dist/mcp-content/overview.js +6 -6
- package/dist/mcp-content/schemas/blog.d.ts +1 -1
- package/dist/mcp-content/schemas/blog.d.ts.map +1 -1
- package/dist/mcp-content/schemas/blog.js +25 -25
- package/dist/mcp-content/schemas/ecommerce.d.ts +1 -1
- package/dist/mcp-content/schemas/ecommerce.d.ts.map +1 -1
- package/dist/mcp-content/schemas/ecommerce.js +67 -67
- package/dist/mcp-content/schemas/social.d.ts +1 -1
- package/dist/mcp-content/schemas/social.d.ts.map +1 -1
- package/dist/mcp-content/schemas/social.js +48 -48
- package/dist/mcp-content/schemas/todo.d.ts +1 -1
- package/dist/mcp-content/schemas/todo.d.ts.map +1 -1
- package/dist/mcp-content/schemas/todo.js +35 -35
- package/dist/mcp-runtime/runtime.d.ts +2 -2
- package/dist/mcp-runtime/runtime.d.ts.map +1 -1
- package/dist/mcp-runtime/runtime.js +4 -4
- package/dist/mcp-runtime/runtime.js.map +1 -1
- package/dist/module-loader.d.ts +2 -2
- package/dist/module-loader.d.ts.map +1 -1
- package/dist/module-loader.js +6 -6
- package/dist/module-loader.js.map +1 -1
- package/dist/sync-operations.d.ts +24 -30
- package/dist/sync-operations.d.ts.map +1 -1
- package/dist/sync-operations.js +10 -12
- package/dist/sync-operations.js.map +1 -1
- package/package.json +30 -44
- package/src/__tests__/fixtures/mock-config.ts +8 -8
- package/src/__tests__/sync-operations.test.ts +21 -35
- package/src/bin.ts +7 -6
- package/src/cli.ts +1 -1
- package/src/commands/__fixtures__/mcp-protocol-server.ts +12 -0
- package/src/commands/import-export.ts +29 -29
- package/src/commands/mcp-coach.ts +12 -11
- package/src/commands/mcp-protocols.test.ts +76 -0
- package/src/commands/mcp-protocols.ts +12 -0
- package/src/commands/mcp-stdio.test.ts +93 -0
- package/src/commands/mcp-tool-handlers.ts +11 -8
- package/src/commands/mcp-tools-defs.test.ts +13 -0
- package/src/commands/mcp-tools-defs.ts +53 -51
- package/src/commands/mcp.ts +7 -4
- package/src/commands/new-project.ts +49 -36
- package/src/mcp-content/architecture.ts +3 -3
- package/src/mcp-content/features.ts +1 -1
- package/src/mcp-content/getting-started.ts +37 -37
- package/src/mcp-content/overview.ts +6 -6
- package/src/mcp-content/schemas/blog.ts +25 -25
- package/src/mcp-content/schemas/ecommerce.ts +67 -67
- package/src/mcp-content/schemas/social.ts +48 -48
- package/src/mcp-content/schemas/todo.ts +35 -35
- package/src/mcp-runtime/runtime.ts +7 -7
- package/src/module-loader.ts +10 -10
- package/src/sync-operations.ts +16 -16
|
@@ -34,8 +34,8 @@ export const tables = {
|
|
|
34
34
|
// Client-only state for UI (not synced)
|
|
35
35
|
uiState: State.SQLite.clientDocument({
|
|
36
36
|
name: 'uiState',
|
|
37
|
-
schema: Schema.Struct({
|
|
38
|
-
newTodoText: Schema.String,
|
|
37
|
+
schema: Schema.Struct({
|
|
38
|
+
newTodoText: Schema.String,
|
|
39
39
|
filter: Schema.Literal('all', 'active', 'completed'),
|
|
40
40
|
selectedTags: Schema.Array(Schema.String)
|
|
41
41
|
}),
|
|
@@ -48,8 +48,8 @@ export const events = {
|
|
|
48
48
|
// Todo events
|
|
49
49
|
todoCreated: Events.synced({
|
|
50
50
|
name: 'v1.TodoCreated',
|
|
51
|
-
schema: Schema.Struct({
|
|
52
|
-
id: Schema.String,
|
|
51
|
+
schema: Schema.Struct({
|
|
52
|
+
id: Schema.String,
|
|
53
53
|
title: Schema.String,
|
|
54
54
|
createdAt: Schema.Date,
|
|
55
55
|
position: Schema.Number
|
|
@@ -60,7 +60,7 @@ export const events = {
|
|
|
60
60
|
schema: Schema.Struct({ id: Schema.String }),
|
|
61
61
|
}),
|
|
62
62
|
todoUncompleted: Events.synced({
|
|
63
|
-
name: 'v1.TodoUncompleted',
|
|
63
|
+
name: 'v1.TodoUncompleted',
|
|
64
64
|
schema: Schema.Struct({ id: Schema.String }),
|
|
65
65
|
}),
|
|
66
66
|
todoTitleChanged: Events.synced({
|
|
@@ -76,16 +76,16 @@ export const events = {
|
|
|
76
76
|
schema: Schema.Struct({ id: Schema.String, deletedAt: Schema.Date }),
|
|
77
77
|
}),
|
|
78
78
|
todosCleared: Events.synced({
|
|
79
|
-
name: 'v1.TodosCleared',
|
|
79
|
+
name: 'v1.TodosCleared',
|
|
80
80
|
schema: Schema.Struct({ deletedAt: Schema.Date }),
|
|
81
81
|
}),
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
// Tag events
|
|
84
84
|
tagCreated: Events.synced({
|
|
85
85
|
name: 'v1.TagCreated',
|
|
86
|
-
schema: Schema.Struct({
|
|
87
|
-
id: Schema.String,
|
|
88
|
-
name: Schema.String,
|
|
86
|
+
schema: Schema.Struct({
|
|
87
|
+
id: Schema.String,
|
|
88
|
+
name: Schema.String,
|
|
89
89
|
color: Schema.NullOr(Schema.String),
|
|
90
90
|
createdAt: Schema.Date
|
|
91
91
|
}),
|
|
@@ -94,7 +94,7 @@ export const events = {
|
|
|
94
94
|
name: 'v1.TagDeleted',
|
|
95
95
|
schema: Schema.Struct({ id: Schema.String, deletedAt: Schema.Date }),
|
|
96
96
|
}),
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
// Todo-Tag relationship events
|
|
99
99
|
todoTagged: Events.synced({
|
|
100
100
|
name: 'v1.TodoTagged',
|
|
@@ -104,7 +104,7 @@ export const events = {
|
|
|
104
104
|
name: 'v1.TodoUntagged',
|
|
105
105
|
schema: Schema.Struct({ todoId: Schema.String, tagId: Schema.String }),
|
|
106
106
|
}),
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
// UI state events (local only)
|
|
109
109
|
uiStateSet: tables.uiState.set,
|
|
110
110
|
}
|
|
@@ -112,39 +112,39 @@ export const events = {
|
|
|
112
112
|
// Materializers - Map events to state changes with conflict-free semantics
|
|
113
113
|
const materializers = State.SQLite.materializers(events, {
|
|
114
114
|
// Todo materializers
|
|
115
|
-
'v1.TodoCreated': ({ id, title, createdAt, position }) =>
|
|
115
|
+
'v1.TodoCreated': ({ id, title, createdAt, position }) =>
|
|
116
116
|
tables.todos.insert({ id, title, completed: false, createdAt, position }),
|
|
117
|
-
|
|
118
|
-
'v1.TodoCompleted': ({ id }) =>
|
|
117
|
+
|
|
118
|
+
'v1.TodoCompleted': ({ id }) =>
|
|
119
119
|
tables.todos.update({ completed: true }).where({ id }),
|
|
120
|
-
|
|
121
|
-
'v1.TodoUncompleted': ({ id }) =>
|
|
120
|
+
|
|
121
|
+
'v1.TodoUncompleted': ({ id }) =>
|
|
122
122
|
tables.todos.update({ completed: false }).where({ id }),
|
|
123
|
-
|
|
124
|
-
'v1.TodoTitleChanged': ({ id, title }) =>
|
|
123
|
+
|
|
124
|
+
'v1.TodoTitleChanged': ({ id, title }) =>
|
|
125
125
|
tables.todos.update({ title }).where({ id }),
|
|
126
|
-
|
|
127
|
-
'v1.TodoReordered': ({ id, position }) =>
|
|
126
|
+
|
|
127
|
+
'v1.TodoReordered': ({ id, position }) =>
|
|
128
128
|
tables.todos.update({ position }).where({ id }),
|
|
129
|
-
|
|
130
|
-
'v1.TodoDeleted': ({ id, deletedAt }) =>
|
|
129
|
+
|
|
130
|
+
'v1.TodoDeleted': ({ id, deletedAt }) =>
|
|
131
131
|
tables.todos.update({ deletedAt }).where({ id }),
|
|
132
|
-
|
|
133
|
-
'v1.TodosCleared': ({ deletedAt }) =>
|
|
132
|
+
|
|
133
|
+
'v1.TodosCleared': ({ deletedAt }) =>
|
|
134
134
|
tables.todos.update({ deletedAt }).where({ completed: true, deletedAt: null }),
|
|
135
|
-
|
|
136
|
-
// Tag materializers
|
|
137
|
-
'v1.TagCreated': ({ id, name, color, createdAt }) =>
|
|
135
|
+
|
|
136
|
+
// Tag materializers
|
|
137
|
+
'v1.TagCreated': ({ id, name, color, createdAt }) =>
|
|
138
138
|
tables.tags.insert({ id, name, color, createdAt }),
|
|
139
|
-
|
|
140
|
-
'v1.TagDeleted': ({ id, deletedAt }) =>
|
|
139
|
+
|
|
140
|
+
'v1.TagDeleted': ({ id, deletedAt }) =>
|
|
141
141
|
tables.tags.update({ deletedAt }).where({ id }),
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
// Todo-Tag relationship materializers
|
|
144
|
-
'v1.TodoTagged': ({ todoId, tagId, createdAt }) =>
|
|
144
|
+
'v1.TodoTagged': ({ todoId, tagId, createdAt }) =>
|
|
145
145
|
tables.todoTags.insert({ todoId, tagId, createdAt }),
|
|
146
|
-
|
|
147
|
-
'v1.TodoUntagged': ({ todoId, tagId }) =>
|
|
146
|
+
|
|
147
|
+
'v1.TodoUntagged': ({ todoId, tagId }) =>
|
|
148
148
|
tables.todoTags.delete().where({ todoId, tagId }),
|
|
149
149
|
})
|
|
150
150
|
|
|
@@ -153,7 +153,7 @@ const state = State.SQLite.makeState({ tables, materializers })
|
|
|
153
153
|
export const schema = makeSchema({ events, state })
|
|
154
154
|
|
|
155
155
|
// Example usage:
|
|
156
|
-
//
|
|
156
|
+
//
|
|
157
157
|
// import { queryDb, dispatchEvent } from '@livestore/livestore'
|
|
158
158
|
// import { schema, events, tables } from './schema.js'
|
|
159
159
|
//
|
|
@@ -55,7 +55,7 @@ export const init = ({
|
|
|
55
55
|
storeId,
|
|
56
56
|
adapter,
|
|
57
57
|
disableDevtools: true,
|
|
58
|
-
syncPayload,
|
|
58
|
+
...(syncPayload !== undefined ? { syncPayload } : {}),
|
|
59
59
|
syncPayloadSchema,
|
|
60
60
|
}),
|
|
61
61
|
)
|
|
@@ -73,7 +73,7 @@ export const init = ({
|
|
|
73
73
|
return store
|
|
74
74
|
}).pipe(Effect.provide(ModuleLoaderLayer), Effect.withSpan('mcp-runtime:init'))
|
|
75
75
|
|
|
76
|
-
export const getStore = Effect.sync(() => Option.
|
|
76
|
+
export const getStore = Effect.sync(() => Option.fromNullishOr(store))
|
|
77
77
|
|
|
78
78
|
export const status = Effect.gen(function* () {
|
|
79
79
|
const opt = yield* getStore
|
|
@@ -111,26 +111,26 @@ export const query = Effect.fn('mcp-runtime:query')(function* ({
|
|
|
111
111
|
}) {
|
|
112
112
|
const opt = yield* getStore
|
|
113
113
|
if (opt._tag === 'None') {
|
|
114
|
-
return yield* Effect.
|
|
114
|
+
return yield* Effect.die(new Error('LiveStore not connected. Call livestore_instance_connect first.'))
|
|
115
115
|
}
|
|
116
116
|
const s = opt.value
|
|
117
117
|
|
|
118
118
|
const rows = s.query<Array<Record<string, unknown>>>({ query: sql, bindValues: (bindValues as any) ?? [] })
|
|
119
|
-
const jsonRows = rows.map((r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, v as Schema.
|
|
119
|
+
const jsonRows = rows.map((r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, v as Schema.Json])))
|
|
120
120
|
return { rows: jsonRows, rowCount: jsonRows.length }
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
export const commit = Effect.fn('mcp-runtime:commit')(function* ({
|
|
124
124
|
events,
|
|
125
125
|
}: {
|
|
126
|
-
events: ReadonlyArray<{ name: string; args: Schema.
|
|
126
|
+
events: ReadonlyArray<{ name: string; args: Schema.Json }>
|
|
127
127
|
}) {
|
|
128
128
|
const opt = yield* getStore
|
|
129
129
|
if (opt._tag === 'None') {
|
|
130
|
-
return yield* Effect.
|
|
130
|
+
return yield* Effect.die(new Error('LiveStore not connected. Call livestore_instance_connect first.'))
|
|
131
131
|
}
|
|
132
132
|
const s = opt.value
|
|
133
|
-
const InputEventSchema = LiveStoreEvent.Input.makeSchema(s.schema) as Schema.
|
|
133
|
+
const InputEventSchema = LiveStoreEvent.Input.makeSchema(s.schema) as Schema.Codec<any>
|
|
134
134
|
const decoded = events.map((e) => Schema.decodeSync(InputEventSchema)(e))
|
|
135
135
|
s.commit(...decoded)
|
|
136
136
|
return { committed: decoded.length }
|
package/src/module-loader.ts
CHANGED
|
@@ -14,8 +14,8 @@ import { Effect, FileSystem, Schema } from '@livestore/utils/effect'
|
|
|
14
14
|
export interface ModuleConfig {
|
|
15
15
|
schema: LiveStoreSchema
|
|
16
16
|
syncBackendConstructor: SyncBackend.SyncBackendConstructor
|
|
17
|
-
syncPayloadSchema: Schema.Schema
|
|
18
|
-
syncPayload:
|
|
17
|
+
syncPayloadSchema: Schema.Codec<Schema.Json, Schema.Json>
|
|
18
|
+
syncPayload: Schema.Json | undefined
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -52,7 +52,7 @@ export const loadModuleConfig = ({
|
|
|
52
52
|
}),
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
const schema =
|
|
55
|
+
const schema = mod?.schema
|
|
56
56
|
if (isLiveStoreSchema(schema) === false) {
|
|
57
57
|
return yield* UnknownError.make({
|
|
58
58
|
cause: `Module at ${abs} must export a valid LiveStore 'schema'`,
|
|
@@ -60,7 +60,7 @@ export const loadModuleConfig = ({
|
|
|
60
60
|
})
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const syncBackendConstructor =
|
|
63
|
+
const syncBackendConstructor = mod?.syncBackend
|
|
64
64
|
if (typeof syncBackendConstructor !== 'function') {
|
|
65
65
|
return yield* UnknownError.make({
|
|
66
66
|
cause: `Module at ${abs} must export a 'syncBackend' constructor`,
|
|
@@ -68,21 +68,21 @@ export const loadModuleConfig = ({
|
|
|
68
68
|
})
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
const syncPayloadSchemaExport =
|
|
71
|
+
const syncPayloadSchemaExport = mod?.syncPayloadSchema
|
|
72
72
|
const syncPayloadSchema =
|
|
73
73
|
syncPayloadSchemaExport === undefined
|
|
74
|
-
? Schema.
|
|
74
|
+
? Schema.Json
|
|
75
75
|
: Schema.isSchema(syncPayloadSchemaExport) === true
|
|
76
|
-
? (syncPayloadSchemaExport as Schema.Schema
|
|
76
|
+
? (syncPayloadSchemaExport as Schema.Codec<Schema.Json, Schema.Json>)
|
|
77
77
|
: shouldNeverHappen(
|
|
78
78
|
`Exported 'syncPayloadSchema' from ${abs} must be an Effect Schema (received ${typeof syncPayloadSchemaExport}).`,
|
|
79
79
|
)
|
|
80
80
|
|
|
81
|
-
const syncPayloadExport =
|
|
81
|
+
const syncPayloadExport = mod?.syncPayload
|
|
82
82
|
const syncPayload = yield* (
|
|
83
83
|
syncPayloadExport === undefined
|
|
84
|
-
? Effect.succeed<
|
|
85
|
-
: Schema.
|
|
84
|
+
? Effect.succeed<Schema.Json | undefined>(undefined)
|
|
85
|
+
: Schema.decodeUnknownEffect(syncPayloadSchema)(syncPayloadExport)
|
|
86
86
|
).pipe(UnknownError.mapToUnknownError)
|
|
87
87
|
|
|
88
88
|
return {
|
package/src/sync-operations.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { UnknownError } from '@livestore/common'
|
|
|
7
7
|
import { LiveStoreEvent } from '@livestore/common/schema'
|
|
8
8
|
import {
|
|
9
9
|
Cause,
|
|
10
|
-
Chunk,
|
|
11
10
|
Effect,
|
|
12
11
|
type FileSystem,
|
|
13
12
|
type HttpClient,
|
|
@@ -43,18 +42,21 @@ export const ExportFileSchema = Schema.Struct({
|
|
|
43
42
|
|
|
44
43
|
export type ExportFile = typeof ExportFileSchema.Type
|
|
45
44
|
|
|
46
|
-
export class ConnectionError extends Schema.TaggedError<ConnectionError>('~@livestore/cli/ConnectionError')(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
export class ConnectionError extends Schema.TaggedError<ConnectionError>('~@livestore/cli/ConnectionError')(
|
|
46
|
+
'ConnectionError',
|
|
47
|
+
{
|
|
48
|
+
cause: Schema.Defect(),
|
|
49
|
+
note: Schema.String,
|
|
50
|
+
},
|
|
51
|
+
) {}
|
|
50
52
|
|
|
51
53
|
export class ExportError extends Schema.TaggedError<ExportError>('~@livestore/cli/ExportError')('ExportError', {
|
|
52
|
-
cause: Schema.Defect,
|
|
54
|
+
cause: Schema.Defect(),
|
|
53
55
|
note: Schema.String,
|
|
54
56
|
}) {}
|
|
55
57
|
|
|
56
58
|
export class ImportError extends Schema.TaggedError<ImportError>('~@livestore/cli/ImportError')('ImportError', {
|
|
57
|
-
cause: Schema.Defect,
|
|
59
|
+
cause: Schema.Defect(),
|
|
58
60
|
note: Schema.String,
|
|
59
61
|
}) {}
|
|
60
62
|
|
|
@@ -85,7 +87,7 @@ export const makeSyncBackend = ({
|
|
|
85
87
|
storeId,
|
|
86
88
|
clientId,
|
|
87
89
|
/** syncPayload is validated against syncPayloadSchema by loadModuleConfig */
|
|
88
|
-
payload: syncPayload as Schema.
|
|
90
|
+
payload: syncPayload as Schema.Json | undefined,
|
|
89
91
|
}).pipe(Effect.provide(KeyValueStore.layerMemory), UnknownError.mapToUnknownError)
|
|
90
92
|
|
|
91
93
|
/** Connect to the sync backend */
|
|
@@ -102,8 +104,8 @@ export const makeSyncBackend = ({
|
|
|
102
104
|
/** Verify connectivity with a ping (with timeout) */
|
|
103
105
|
yield* syncBackend.ping.pipe(
|
|
104
106
|
Effect.timeout(CONNECTION_TIMEOUT_MS),
|
|
105
|
-
Effect.
|
|
106
|
-
if (Cause.
|
|
107
|
+
Effect.catch((cause) => {
|
|
108
|
+
if (Cause.isTimeoutError(cause) === true) {
|
|
107
109
|
return Effect.fail(
|
|
108
110
|
new ConnectionError({
|
|
109
111
|
cause,
|
|
@@ -126,7 +128,7 @@ export const makeSyncBackend = ({
|
|
|
126
128
|
const releaseSyncBackend = (syncBackend: SyncBackend.SyncBackend): Effect.Effect<void> => {
|
|
127
129
|
const maybeDisconnect = (syncBackend as { disconnect?: Effect.Effect<void> }).disconnect
|
|
128
130
|
const releaseEffect = maybeDisconnect ?? SubscriptionRef.set(syncBackend.isConnected, false)
|
|
129
|
-
return releaseEffect.pipe(Effect.
|
|
131
|
+
return releaseEffect.pipe(Effect.catch(() => Effect.void))
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
export interface ExportResult {
|
|
@@ -173,9 +175,7 @@ export const pullEventsFromSyncBackend = ({
|
|
|
173
175
|
),
|
|
174
176
|
)
|
|
175
177
|
|
|
176
|
-
const events =
|
|
177
|
-
.flatMap((item) => item.batch)
|
|
178
|
-
.map((item) => item.eventEncoded)
|
|
178
|
+
const events = batchesChunk.flatMap((item) => item.batch).map((item) => item.eventEncoded)
|
|
179
179
|
|
|
180
180
|
const exportedAt = new Date().toISOString()
|
|
181
181
|
const exportData: ExportFile = {
|
|
@@ -224,7 +224,7 @@ export const validateExportData = ({
|
|
|
224
224
|
targetStoreId: string
|
|
225
225
|
}): Effect.Effect<ImportValidationResult, ImportError> =>
|
|
226
226
|
Effect.gen(function* () {
|
|
227
|
-
const exportData = yield* Schema.
|
|
227
|
+
const exportData = yield* Schema.decodeUnknownEffect(ExportFileSchema)(data).pipe(
|
|
228
228
|
Effect.mapError(
|
|
229
229
|
(cause) =>
|
|
230
230
|
new ImportError({
|
|
@@ -272,7 +272,7 @@ export const pushEventsToSyncBackend = ({
|
|
|
272
272
|
makeSyncBackend({ configPath, storeId, clientId }),
|
|
273
273
|
(syncBackend) =>
|
|
274
274
|
Effect.gen(function* () {
|
|
275
|
-
const exportData = yield* Schema.
|
|
275
|
+
const exportData = yield* Schema.decodeUnknownEffect(ExportFileSchema)(data).pipe(
|
|
276
276
|
Effect.mapError(
|
|
277
277
|
(cause) =>
|
|
278
278
|
new ImportError({
|