@livestore/common 0.4.0-dev.9 → 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/ClientSessionLeaderThreadProxy.d.ts +27 -12
- package/dist/ClientSessionLeaderThreadProxy.d.ts.map +1 -1
- package/dist/ClientSessionLeaderThreadProxy.js.map +1 -1
- package/dist/MaterializationJournal.d.ts +44 -0
- package/dist/MaterializationJournal.d.ts.map +1 -0
- package/dist/MaterializationJournal.js +112 -0
- package/dist/MaterializationJournal.js.map +1 -0
- package/dist/StateHead.d.ts +26 -0
- package/dist/StateHead.d.ts.map +1 -0
- package/dist/StateHead.js +50 -0
- package/dist/StateHead.js.map +1 -0
- package/dist/WorkerTransportError.d.ts +11 -0
- package/dist/WorkerTransportError.d.ts.map +1 -0
- package/dist/WorkerTransportError.js +11 -0
- package/dist/WorkerTransportError.js.map +1 -0
- package/dist/__tests__/fixture.d.ts +1 -1
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +3 -3
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/adapter-types.d.ts +59 -57
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +31 -22
- package/dist/adapter-types.js.map +1 -1
- package/dist/bounded-collections.d.ts.map +1 -1
- package/dist/bounded-collections.js +6 -4
- package/dist/bounded-collections.js.map +1 -1
- package/dist/debug-info.d.ts +56 -56
- package/dist/debug-info.d.ts.map +1 -1
- package/dist/debug-info.js +46 -32
- package/dist/debug-info.js.map +1 -1
- package/dist/defs.d.ts +9 -9
- package/dist/defs.js +2 -2
- package/dist/devtools/devtools-compatibility.test.d.ts +2 -0
- package/dist/devtools/devtools-compatibility.test.d.ts.map +1 -0
- package/dist/devtools/devtools-compatibility.test.js +16 -0
- package/dist/devtools/devtools-compatibility.test.js.map +1 -0
- package/dist/devtools/devtools-messages-client-session.d.ts +531 -312
- package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-client-session.js +86 -67
- package/dist/devtools/devtools-messages-client-session.js.map +1 -1
- package/dist/devtools/devtools-messages-common.d.ts +32 -35
- package/dist/devtools/devtools-messages-common.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-common.js +12 -14
- package/dist/devtools/devtools-messages-common.js.map +1 -1
- package/dist/devtools/devtools-messages-leader.d.ts +417 -320
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-leader.js +117 -87
- package/dist/devtools/devtools-messages-leader.js.map +1 -1
- package/dist/devtools/devtools-sessioninfo.d.ts +28 -17
- package/dist/devtools/devtools-sessioninfo.d.ts.map +1 -1
- package/dist/devtools/devtools-sessioninfo.js +12 -6
- package/dist/devtools/devtools-sessioninfo.js.map +1 -1
- package/dist/devtools/mod.d.ts +17 -7
- package/dist/devtools/mod.d.ts.map +1 -1
- package/dist/devtools/mod.js +19 -8
- package/dist/devtools/mod.js.map +1 -1
- package/dist/errors.d.ts +52 -46
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +31 -21
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +116 -21
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +596 -470
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/RejectedPushError.d.ts +138 -0
- package/dist/leader-thread/RejectedPushError.d.ts.map +1 -0
- package/dist/leader-thread/RejectedPushError.js +97 -0
- package/dist/leader-thread/RejectedPushError.js.map +1 -0
- package/dist/leader-thread/connection.d.ts +1 -0
- package/dist/leader-thread/connection.d.ts.map +1 -1
- package/dist/leader-thread/connection.js +10 -9
- package/dist/leader-thread/connection.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts +20 -15
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +80 -20
- package/dist/leader-thread/eventlog.js.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts +1 -2
- package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +110 -62
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +19 -7
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +67 -45
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.test.d.ts +2 -0
- package/dist/leader-thread/make-leader-thread-layer.test.d.ts.map +1 -0
- package/dist/leader-thread/make-leader-thread-layer.test.js +32 -0
- package/dist/leader-thread/make-leader-thread-layer.test.js.map +1 -0
- package/dist/leader-thread/materialize-event.d.ts +3 -2
- package/dist/leader-thread/materialize-event.d.ts.map +1 -1
- package/dist/leader-thread/materialize-event.js +32 -9
- package/dist/leader-thread/materialize-event.js.map +1 -1
- package/dist/leader-thread/mod.d.ts +1 -0
- package/dist/leader-thread/mod.d.ts.map +1 -1
- package/dist/leader-thread/mod.js +1 -0
- package/dist/leader-thread/mod.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts +2 -2
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +19 -40
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/shutdown-channel.d.ts +3 -7
- package/dist/leader-thread/shutdown-channel.d.ts.map +1 -1
- package/dist/leader-thread/shutdown-channel.js +2 -3
- package/dist/leader-thread/shutdown-channel.js.map +1 -1
- package/dist/leader-thread/stream-events.d.ts +53 -0
- package/dist/leader-thread/stream-events.d.ts.map +1 -0
- package/dist/leader-thread/stream-events.js +164 -0
- package/dist/leader-thread/stream-events.js.map +1 -0
- package/dist/leader-thread/types.d.ts +92 -51
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/leader-thread/types.js +17 -4
- package/dist/leader-thread/types.js.map +1 -1
- package/dist/logging.d.ts +15 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +2 -0
- package/dist/logging.js.map +1 -0
- package/dist/make-client-session.d.ts +6 -5
- package/dist/make-client-session.d.ts.map +1 -1
- package/dist/make-client-session.js +10 -7
- package/dist/make-client-session.js.map +1 -1
- package/dist/materializer-helper.d.ts +6 -7
- package/dist/materializer-helper.d.ts.map +1 -1
- package/dist/materializer-helper.js +22 -40
- package/dist/materializer-helper.js.map +1 -1
- package/dist/otel.d.ts +4 -4
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +8 -8
- package/dist/otel.js.map +1 -1
- package/dist/rematerialize-from-eventlog.d.ts +3 -3
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
- package/dist/rematerialize-from-eventlog.js +52 -39
- package/dist/rematerialize-from-eventlog.js.map +1 -1
- package/dist/schema/EventDef/define.d.ts +161 -0
- package/dist/schema/EventDef/define.d.ts.map +1 -0
- package/dist/schema/EventDef/define.js +140 -0
- package/dist/schema/EventDef/define.js.map +1 -0
- package/dist/schema/EventDef/define.test.d.ts +2 -0
- package/dist/schema/EventDef/define.test.d.ts.map +1 -0
- package/dist/schema/EventDef/define.test.js +23 -0
- package/dist/schema/EventDef/define.test.js.map +1 -0
- package/dist/schema/EventDef/deprecated.d.ts +94 -0
- package/dist/schema/EventDef/deprecated.d.ts.map +1 -0
- package/dist/schema/EventDef/deprecated.js +143 -0
- package/dist/schema/EventDef/deprecated.js.map +1 -0
- package/dist/schema/EventDef/deprecated.test.d.ts +2 -0
- package/dist/schema/EventDef/deprecated.test.d.ts.map +1 -0
- package/dist/schema/EventDef/deprecated.test.js +95 -0
- package/dist/schema/EventDef/deprecated.test.js.map +1 -0
- package/dist/schema/EventDef/event-def.d.ts +110 -0
- package/dist/schema/EventDef/event-def.d.ts.map +1 -0
- package/dist/schema/EventDef/event-def.js +2 -0
- package/dist/schema/EventDef/event-def.js.map +1 -0
- package/dist/schema/EventDef/facts.d.ts +118 -0
- package/dist/schema/EventDef/facts.d.ts.map +1 -0
- package/dist/schema/EventDef/facts.js +53 -0
- package/dist/schema/EventDef/facts.js.map +1 -0
- package/dist/schema/EventDef/materializer.d.ts +155 -0
- package/dist/schema/EventDef/materializer.d.ts.map +1 -0
- package/dist/schema/EventDef/materializer.js +83 -0
- package/dist/schema/EventDef/materializer.js.map +1 -0
- package/dist/schema/EventDef/mod.d.ts +6 -0
- package/dist/schema/EventDef/mod.d.ts.map +1 -0
- package/dist/schema/EventDef/mod.js +6 -0
- package/dist/schema/EventDef/mod.js.map +1 -0
- package/dist/schema/EventSequenceNumber/client.d.ts +136 -0
- package/dist/schema/EventSequenceNumber/client.d.ts.map +1 -0
- package/dist/schema/EventSequenceNumber/client.js +192 -0
- package/dist/schema/EventSequenceNumber/client.js.map +1 -0
- package/dist/schema/EventSequenceNumber/global.d.ts +15 -0
- package/dist/schema/EventSequenceNumber/global.d.ts.map +1 -0
- package/dist/schema/EventSequenceNumber/global.js +14 -0
- package/dist/schema/EventSequenceNumber/global.js.map +1 -0
- package/dist/schema/EventSequenceNumber/mod.d.ts +37 -0
- package/dist/schema/EventSequenceNumber/mod.d.ts.map +1 -0
- package/dist/schema/EventSequenceNumber/mod.js +37 -0
- package/dist/schema/EventSequenceNumber/mod.js.map +1 -0
- package/dist/schema/EventSequenceNumber.test.js +44 -44
- package/dist/schema/EventSequenceNumber.test.js.map +1 -1
- package/dist/schema/LiveStoreEvent/client.d.ts +168 -0
- package/dist/schema/LiveStoreEvent/client.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/client.js +179 -0
- package/dist/schema/LiveStoreEvent/client.js.map +1 -0
- package/dist/schema/LiveStoreEvent/client.test.d.ts +2 -0
- package/dist/schema/LiveStoreEvent/client.test.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/client.test.js +120 -0
- package/dist/schema/LiveStoreEvent/client.test.js.map +1 -0
- package/dist/schema/LiveStoreEvent/for-event-def.d.ts +52 -0
- package/dist/schema/LiveStoreEvent/for-event-def.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/for-event-def.js +2 -0
- package/dist/schema/LiveStoreEvent/for-event-def.js.map +1 -0
- package/dist/schema/LiveStoreEvent/global.d.ts +36 -0
- package/dist/schema/LiveStoreEvent/global.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/global.js +31 -0
- package/dist/schema/LiveStoreEvent/global.js.map +1 -0
- package/dist/schema/LiveStoreEvent/input.d.ts +46 -0
- package/dist/schema/LiveStoreEvent/input.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/input.js +26 -0
- package/dist/schema/LiveStoreEvent/input.js.map +1 -0
- package/dist/schema/LiveStoreEvent/mod.d.ts +5 -0
- package/dist/schema/LiveStoreEvent/mod.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/mod.js +5 -0
- package/dist/schema/LiveStoreEvent/mod.js.map +1 -0
- package/dist/schema/events.d.ts +1 -1
- package/dist/schema/events.d.ts.map +1 -1
- package/dist/schema/events.js +1 -1
- package/dist/schema/events.js.map +1 -1
- package/dist/schema/mod.d.ts +7 -4
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +6 -4
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts +16 -1
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +34 -5
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.d.ts +14 -18
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +54 -30
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.test.js +146 -6
- package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-annotations.d.ts +13 -13
- package/dist/schema/state/sqlite/column-annotations.d.ts.map +1 -1
- package/dist/schema/state/sqlite/column-annotations.js +13 -15
- package/dist/schema/state/sqlite/column-annotations.js.map +1 -1
- package/dist/schema/state/sqlite/column-annotations.test.js +19 -43
- package/dist/schema/state/sqlite/column-annotations.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.d.ts +1 -1
- package/dist/schema/state/sqlite/column-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/column-def.js +132 -57
- package/dist/schema/state/sqlite/column-def.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.test.js +155 -70
- package/dist/schema/state/sqlite/column-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-spec.d.ts.map +1 -1
- package/dist/schema/state/sqlite/column-spec.js +30 -12
- package/dist/schema/state/sqlite/column-spec.js.map +1 -1
- package/dist/schema/state/sqlite/column-spec.test.js +26 -17
- package/dist/schema/state/sqlite/column-spec.test.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts +2 -2
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +15 -6
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts +25 -19
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js +22 -16
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js +28 -17
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +14 -12
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js +6 -4
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -1
- package/dist/schema/state/sqlite/mod.d.ts +3 -5
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.js +6 -8
- package/dist/schema/state/sqlite/mod.js.map +1 -1
- package/dist/schema/state/sqlite/persistence.d.ts +11 -0
- package/dist/schema/state/sqlite/persistence.d.ts.map +1 -0
- package/dist/schema/state/sqlite/persistence.js +10 -0
- package/dist/schema/state/sqlite/persistence.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/api.d.ts +58 -29
- package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/astToSql.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/astToSql.js +105 -24
- package/dist/schema/state/sqlite/query-builder/astToSql.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts +4 -2
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.js +42 -27
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +402 -498
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
- package/dist/schema/state/sqlite/schema-helpers.d.ts +2 -2
- package/dist/schema/state/sqlite/schema-helpers.d.ts.map +1 -1
- package/dist/schema/state/sqlite/schema-helpers.js +24 -14
- package/dist/schema/state/sqlite/schema-helpers.js.map +1 -1
- package/dist/schema/state/sqlite/schema-helpers.test.d.ts +2 -0
- package/dist/schema/state/sqlite/schema-helpers.test.d.ts.map +1 -0
- package/dist/schema/state/sqlite/schema-helpers.test.js +36 -0
- package/dist/schema/state/sqlite/schema-helpers.test.js.map +1 -0
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.d.ts +515 -0
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.d.ts.map +1 -0
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.js +54 -0
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.js.map +1 -0
- package/dist/schema/state/sqlite/system-tables/mod.d.ts +3 -0
- package/dist/schema/state/sqlite/system-tables/mod.d.ts.map +1 -0
- package/dist/schema/state/sqlite/system-tables/mod.js +3 -0
- package/dist/schema/state/sqlite/system-tables/mod.js.map +1 -0
- package/dist/schema/state/sqlite/system-tables/state-tables.d.ts +678 -0
- package/dist/schema/state/sqlite/system-tables/state-tables.d.ts.map +1 -0
- package/dist/schema/state/sqlite/system-tables/state-tables.js +87 -0
- package/dist/schema/state/sqlite/system-tables/state-tables.js.map +1 -0
- package/dist/schema/state/sqlite/table-def.d.ts +19 -20
- package/dist/schema/state/sqlite/table-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/table-def.js +54 -4
- package/dist/schema/state/sqlite/table-def.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.test.js +226 -20
- package/dist/schema/state/sqlite/table-def.test.js.map +1 -1
- package/dist/schema/unknown-events.d.ts +47 -0
- package/dist/schema/unknown-events.d.ts.map +1 -0
- package/dist/schema/unknown-events.js +70 -0
- package/dist/schema/unknown-events.js.map +1 -0
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.d.ts +2 -0
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.d.ts.map +1 -0
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js +73 -0
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js.map +1 -0
- package/dist/schema-management/common.js +2 -2
- package/dist/schema-management/common.js.map +1 -1
- package/dist/schema-management/migrations.d.ts +32 -2
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +38 -6
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/schema-management/validate-schema.d.ts +3 -3
- package/dist/schema-management/validate-schema.d.ts.map +1 -1
- package/dist/schema-management/validate-schema.js +2 -2
- package/dist/schema-management/validate-schema.js.map +1 -1
- package/dist/session-id-symbol.d.ts +29 -0
- package/dist/session-id-symbol.d.ts.map +1 -0
- package/dist/session-id-symbol.js +44 -0
- package/dist/session-id-symbol.js.map +1 -0
- package/dist/sql-queries/sql-queries.d.ts.map +1 -1
- package/dist/sql-queries/sql-queries.js +26 -16
- package/dist/sql-queries/sql-queries.js.map +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts.map +1 -1
- package/dist/sql-queries/sql-query-builder.js.map +1 -1
- package/dist/sql-queries/types.d.ts +6 -7
- package/dist/sql-queries/types.d.ts.map +1 -1
- package/dist/sql-queries/types.js.map +1 -1
- package/dist/sqlite-db-helper.d.ts +21 -1
- package/dist/sqlite-db-helper.d.ts.map +1 -1
- package/dist/sqlite-db-helper.js +40 -5
- package/dist/sqlite-db-helper.js.map +1 -1
- package/dist/sqlite-types.d.ts +8 -11
- package/dist/sqlite-types.d.ts.map +1 -1
- package/dist/sqlite-types.js +3 -3
- package/dist/sqlite-types.js.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.d.ts +47 -25
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +269 -154
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/errors.d.ts +12 -51
- package/dist/sync/errors.d.ts.map +1 -1
- package/dist/sync/errors.js +7 -24
- package/dist/sync/errors.js.map +1 -1
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +2 -0
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/mock-sync-backend.d.ts +11 -10
- package/dist/sync/mock-sync-backend.d.ts.map +1 -1
- package/dist/sync/mock-sync-backend.js +97 -74
- package/dist/sync/mock-sync-backend.js.map +1 -1
- package/dist/sync/mock-sync-backend.test.d.ts +2 -0
- package/dist/sync/mock-sync-backend.test.d.ts.map +1 -0
- package/dist/sync/mock-sync-backend.test.js +49 -0
- package/dist/sync/mock-sync-backend.test.js.map +1 -0
- package/dist/sync/next/compact-events.d.ts.map +1 -1
- package/dist/sync/next/compact-events.js +11 -12
- package/dist/sync/next/compact-events.js.map +1 -1
- package/dist/sync/next/facts.d.ts +5 -5
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js +7 -8
- package/dist/sync/next/facts.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts +58 -15
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +219 -9
- package/dist/sync/next/history-dag-common.js.map +1 -1
- package/dist/sync/next/history-dag.d.ts.map +1 -1
- package/dist/sync/next/history-dag.js +12 -11
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/next/rebase-events.d.ts +5 -5
- package/dist/sync/next/rebase-events.d.ts.map +1 -1
- package/dist/sync/next/rebase-events.js +6 -6
- package/dist/sync/next/rebase-events.js.map +1 -1
- package/dist/sync/next/test/compact-events.calculator.test.js +4 -4
- package/dist/sync/next/test/compact-events.calculator.test.js.map +1 -1
- package/dist/sync/next/test/compact-events.test.d.ts.map +1 -1
- package/dist/sync/next/test/compact-events.test.js +2 -2
- package/dist/sync/next/test/compact-events.test.js.map +1 -1
- package/dist/sync/next/test/event-fixtures.d.ts +9 -9
- package/dist/sync/next/test/event-fixtures.d.ts.map +1 -1
- package/dist/sync/next/test/event-fixtures.js +12 -12
- package/dist/sync/next/test/event-fixtures.js.map +1 -1
- package/dist/sync/next/test/history-dag-common.test.d.ts +2 -0
- package/dist/sync/next/test/history-dag-common.test.d.ts.map +1 -0
- package/dist/sync/next/test/history-dag-common.test.js +73 -0
- package/dist/sync/next/test/history-dag-common.test.js.map +1 -0
- package/dist/sync/sync-backend-kv.d.ts +3 -3
- package/dist/sync/sync-backend-kv.d.ts.map +1 -1
- package/dist/sync/sync-backend-kv.js +6 -4
- package/dist/sync/sync-backend-kv.js.map +1 -1
- package/dist/sync/sync-backend.d.ts +41 -21
- package/dist/sync/sync-backend.d.ts.map +1 -1
- package/dist/sync/sync-backend.js +45 -4
- package/dist/sync/sync-backend.js.map +1 -1
- package/dist/sync/sync.d.ts +23 -2
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/syncstate.d.ts +115 -191
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +108 -129
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +289 -161
- package/dist/sync/syncstate.test.js.map +1 -1
- package/dist/sync/transport-chunking.d.ts +35 -0
- package/dist/sync/transport-chunking.d.ts.map +1 -0
- package/dist/sync/transport-chunking.js +47 -0
- package/dist/sync/transport-chunking.js.map +1 -0
- package/dist/sync/validate-push-payload.d.ts +2 -2
- package/dist/sync/validate-push-payload.d.ts.map +1 -1
- package/dist/sync/validate-push-payload.js +4 -6
- package/dist/sync/validate-push-payload.js.map +1 -1
- package/dist/testing/event-factory.d.ts +3 -3
- package/dist/testing/event-factory.d.ts.map +1 -1
- package/dist/testing/event-factory.js +5 -7
- package/dist/testing/event-factory.js.map +1 -1
- package/dist/util.d.ts +11 -4
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +21 -4
- package/dist/util.js.map +1 -1
- package/dist/version.d.ts +24 -5
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +25 -8
- package/dist/version.js.map +1 -1
- package/package.json +50 -16
- package/src/ClientSessionLeaderThreadProxy.ts +27 -12
- package/src/MaterializationJournal.ts +184 -0
- package/src/StateHead.ts +80 -0
- package/src/WorkerTransportError.ts +12 -0
- package/src/__tests__/fixture.ts +3 -3
- package/src/adapter-types.ts +62 -56
- package/src/bounded-collections.ts +6 -5
- package/src/debug-info.ts +54 -43
- package/src/defs.ts +2 -2
- package/src/devtools/devtools-compatibility.test.ts +19 -0
- package/src/devtools/devtools-messages-client-session.ts +72 -63
- package/src/devtools/devtools-messages-common.ts +18 -22
- package/src/devtools/devtools-messages-leader.ts +89 -68
- package/src/devtools/devtools-sessioninfo.ts +17 -12
- package/src/devtools/mod.ts +15 -7
- package/src/errors.ts +58 -38
- package/src/index.ts +11 -1
- package/src/leader-thread/LeaderSyncProcessor.ts +927 -674
- package/src/leader-thread/RejectedPushError.ts +119 -0
- package/src/leader-thread/connection.ts +13 -9
- package/src/leader-thread/eventlog.ts +114 -41
- package/src/leader-thread/leader-worker-devtools.ts +223 -124
- package/src/leader-thread/make-leader-thread-layer.test.ts +44 -0
- package/src/leader-thread/make-leader-thread-layer.ts +170 -82
- package/src/leader-thread/materialize-event.ts +51 -16
- package/src/leader-thread/mod.ts +1 -0
- package/src/leader-thread/recreate-db.ts +26 -61
- package/src/leader-thread/shutdown-channel.ts +3 -18
- package/src/leader-thread/stream-events.ts +209 -0
- package/src/leader-thread/types.ts +77 -65
- package/src/logging.ts +15 -0
- package/src/make-client-session.ts +16 -10
- package/src/materializer-helper.ts +31 -49
- package/src/otel.ts +15 -13
- package/src/rematerialize-from-eventlog.ts +106 -93
- package/src/schema/EventDef/define.test.ts +28 -0
- package/src/schema/EventDef/define.ts +218 -0
- package/src/schema/EventDef/deprecated.test.ts +122 -0
- package/src/schema/EventDef/deprecated.ts +172 -0
- package/src/schema/EventDef/event-def.ts +123 -0
- package/src/schema/EventDef/facts.ts +135 -0
- package/src/schema/EventDef/materializer.ts +172 -0
- package/src/schema/EventDef/mod.ts +5 -0
- package/src/schema/EventSequenceNumber/client.ts +256 -0
- package/src/schema/EventSequenceNumber/global.ts +19 -0
- package/src/schema/EventSequenceNumber/mod.ts +37 -0
- package/src/schema/EventSequenceNumber.test.ts +72 -53
- package/src/schema/LiveStoreEvent/client.test.ts +142 -0
- package/src/schema/LiveStoreEvent/client.ts +236 -0
- package/src/schema/LiveStoreEvent/for-event-def.ts +60 -0
- package/src/schema/LiveStoreEvent/global.ts +45 -0
- package/src/schema/LiveStoreEvent/input.ts +63 -0
- package/src/schema/LiveStoreEvent/mod.ts +4 -0
- package/src/schema/events.ts +1 -1
- package/src/schema/mod.ts +7 -4
- package/src/schema/schema.ts +48 -6
- package/src/schema/state/sqlite/client-document-def.test.ts +172 -14
- package/src/schema/state/sqlite/client-document-def.ts +126 -98
- package/src/schema/state/sqlite/column-annotations.test.ts +27 -45
- package/src/schema/state/sqlite/column-annotations.ts +27 -30
- package/src/schema/state/sqlite/column-def.test.ts +186 -77
- package/src/schema/state/sqlite/column-def.ts +169 -62
- package/src/schema/state/sqlite/column-spec.test.ts +34 -19
- package/src/schema/state/sqlite/column-spec.ts +38 -11
- package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +17 -7
- package/src/schema/state/sqlite/db-schema/dsl/__snapshots__/field-defs.test.ts.snap +123 -63
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.test.ts +37 -17
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.ts +65 -45
- package/src/schema/state/sqlite/db-schema/dsl/mod.ts +48 -40
- package/src/schema/state/sqlite/mod.ts +9 -12
- package/src/schema/state/sqlite/persistence.ts +11 -0
- package/src/schema/state/sqlite/query-builder/api.ts +61 -23
- package/src/schema/state/sqlite/query-builder/astToSql.ts +117 -23
- package/src/schema/state/sqlite/query-builder/impl.test.ts +489 -551
- package/src/schema/state/sqlite/query-builder/impl.ts +43 -26
- package/src/schema/state/sqlite/schema-helpers.test.ts +44 -0
- package/src/schema/state/sqlite/schema-helpers.ts +30 -22
- package/src/schema/state/sqlite/system-tables/eventlog-tables.ts +64 -0
- package/src/schema/state/sqlite/system-tables/mod.ts +2 -0
- package/src/schema/state/sqlite/system-tables/state-tables.ts +109 -0
- package/src/schema/state/sqlite/table-def.test.ts +295 -46
- package/src/schema/state/sqlite/table-def.ts +109 -64
- package/src/schema/unknown-events.ts +132 -0
- package/src/schema-management/__tests__/migrations-autoincrement-quoting.test.ts +88 -0
- package/src/schema-management/common.ts +2 -2
- package/src/schema-management/migrations.ts +42 -9
- package/src/schema-management/validate-schema.ts +3 -3
- package/src/session-id-symbol.ts +59 -0
- package/src/sql-queries/sql-queries.ts +26 -18
- package/src/sql-queries/sql-query-builder.ts +1 -0
- package/src/sql-queries/types.ts +6 -7
- package/src/sqlite-db-helper.ts +67 -5
- package/src/sqlite-types.ts +9 -11
- package/src/sync/ClientSessionSyncProcessor.ts +388 -194
- package/src/sync/errors.ts +18 -28
- package/src/sync/index.ts +2 -0
- package/src/sync/mock-sync-backend.test.ts +78 -0
- package/src/sync/mock-sync-backend.ts +196 -108
- package/src/sync/next/compact-events.ts +10 -11
- package/src/sync/next/facts.ts +13 -14
- package/src/sync/next/history-dag-common.ts +306 -26
- package/src/sync/next/history-dag.ts +20 -13
- package/src/sync/next/rebase-events.ts +12 -12
- package/src/sync/next/test/compact-events.calculator.test.ts +5 -4
- package/src/sync/next/test/compact-events.test.ts +4 -3
- package/src/sync/next/test/event-fixtures.ts +14 -14
- package/src/sync/next/test/history-dag-common.test.ts +87 -0
- package/src/sync/sync-backend-kv.ts +7 -4
- package/src/sync/sync-backend.ts +75 -26
- package/src/sync/sync.ts +24 -2
- package/src/sync/syncstate.test.ts +657 -442
- package/src/sync/syncstate.ts +175 -160
- package/src/sync/transport-chunking.ts +85 -0
- package/src/sync/validate-push-payload.ts +6 -8
- package/src/testing/event-factory.ts +10 -12
- package/src/util.ts +20 -11
- package/src/version.ts +32 -8
- package/dist/schema/EventDef.d.ts +0 -126
- package/dist/schema/EventDef.d.ts.map +0 -1
- package/dist/schema/EventDef.js +0 -46
- package/dist/schema/EventDef.js.map +0 -1
- package/dist/schema/EventSequenceNumber.d.ts +0 -80
- package/dist/schema/EventSequenceNumber.d.ts.map +0 -1
- package/dist/schema/EventSequenceNumber.js +0 -139
- package/dist/schema/EventSequenceNumber.js.map +0 -1
- package/dist/schema/LiveStoreEvent.d.ts +0 -306
- package/dist/schema/LiveStoreEvent.d.ts.map +0 -1
- package/dist/schema/LiveStoreEvent.js +0 -147
- package/dist/schema/LiveStoreEvent.js.map +0 -1
- package/dist/schema/state/sqlite/system-tables.d.ts +0 -976
- package/dist/schema/state/sqlite/system-tables.d.ts.map +0 -1
- package/dist/schema/state/sqlite/system-tables.js +0 -81
- package/dist/schema/state/sqlite/system-tables.js.map +0 -1
- package/dist/sql-queries/misc.d.ts +0 -2
- package/dist/sql-queries/misc.d.ts.map +0 -1
- package/dist/sql-queries/misc.js +0 -2
- package/dist/sql-queries/misc.js.map +0 -1
- package/dist/sync/next/graphology.d.ts +0 -8
- package/dist/sync/next/graphology.d.ts.map +0 -1
- package/dist/sync/next/graphology.js +0 -30
- package/dist/sync/next/graphology.js.map +0 -1
- package/dist/sync/next/graphology_.d.ts +0 -3
- package/dist/sync/next/graphology_.d.ts.map +0 -1
- package/dist/sync/next/graphology_.js +0 -3
- package/dist/sync/next/graphology_.js.map +0 -1
- package/src/schema/EventDef.ts +0 -222
- package/src/schema/EventSequenceNumber.ts +0 -199
- package/src/schema/LiveStoreEvent.ts +0 -286
- package/src/schema/state/sqlite/system-tables.ts +0 -106
- package/src/sql-queries/misc.ts +0 -2
- package/src/sync/next/ambient.d.ts +0 -3
- package/src/sync/next/graphology.ts +0 -41
- package/src/sync/next/graphology_.ts +0 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Nullable, shouldNeverHappen } from '@livestore/utils'
|
|
2
|
-
import {
|
|
2
|
+
import type { Schema } from '@livestore/utils/effect'
|
|
3
|
+
import { SchemaAST, type Types } from '@livestore/utils/effect'
|
|
3
4
|
|
|
4
5
|
import { getColumnDefForSchema, schemaFieldsToColumns } from './column-def.ts'
|
|
5
6
|
import { SqliteDsl } from './db-schema/mod.ts'
|
|
@@ -38,29 +39,17 @@ export type TableDef<
|
|
|
38
39
|
// https://github.com/livestorejs/livestore/issues/382
|
|
39
40
|
TSqliteDef extends DefaultSqliteTableDef = DefaultSqliteTableDefConstrained,
|
|
40
41
|
TOptions extends TableOptions = TableOptions,
|
|
41
|
-
|
|
42
|
-
// as we don't want the alias type for users to show up, so we're redefining it here
|
|
43
|
-
// TODO adjust this to `TSchema = Schema.TypeLiteral<` but requires some advance type-level work
|
|
44
|
-
TSchema = Schema.Schema<
|
|
45
|
-
SqliteDsl.AnyIfConstained<
|
|
46
|
-
TSqliteDef['columns'],
|
|
47
|
-
{ readonly [K in keyof TSqliteDef['columns']]: TSqliteDef['columns'][K]['schema']['Type'] }
|
|
48
|
-
>,
|
|
49
|
-
SqliteDsl.AnyIfConstained<
|
|
50
|
-
TSqliteDef['columns'],
|
|
51
|
-
{ readonly [K in keyof TSqliteDef['columns']]: TSqliteDef['columns'][K]['schema']['Encoded'] }
|
|
52
|
-
>
|
|
53
|
-
>,
|
|
42
|
+
TSchema extends Schema.Top = Schema.Struct<SqliteDsl.StructFieldsForColumns<TSqliteDef['columns']>>,
|
|
54
43
|
> = {
|
|
55
44
|
sqliteDef: TSqliteDef
|
|
56
45
|
options: TOptions
|
|
57
46
|
// Derived from `sqliteDef`, so only exposed for convenience
|
|
58
47
|
rowSchema: TSchema
|
|
59
48
|
insertSchema: SqliteDsl.InsertStructSchemaForColumns<TSqliteDef['columns']>
|
|
60
|
-
// query: QueryBuilder<ReadonlyArray<
|
|
61
|
-
readonly Type:
|
|
62
|
-
readonly Encoded:
|
|
63
|
-
} & QueryBuilder<ReadonlyArray<
|
|
49
|
+
// query: QueryBuilder<ReadonlyArray<TSchema['Type']>>, TableDefBase<TSqliteDef & {}, TOptions>>
|
|
50
|
+
readonly Type: TSchema['Type']
|
|
51
|
+
readonly Encoded: TSchema['Encoded']
|
|
52
|
+
} & QueryBuilder<ReadonlyArray<TSchema['Type']>, TableDefBase<TSqliteDef & {}, TOptions>>
|
|
64
53
|
|
|
65
54
|
export type TableOptionsInput = Partial<{
|
|
66
55
|
indexes: SqliteDsl.Index[]
|
|
@@ -114,7 +103,7 @@ export type TableOptions = {
|
|
|
114
103
|
* })
|
|
115
104
|
*
|
|
116
105
|
* // Option 2: With name from schema annotation (title or identifier)
|
|
117
|
-
* const AnnotatedUserSchema = UserSchema.
|
|
106
|
+
* const AnnotatedUserSchema = UserSchema.annotate({ title: 'users' })
|
|
118
107
|
* const usersTable2 = State.SQLite.table({
|
|
119
108
|
* schema: AnnotatedUserSchema,
|
|
120
109
|
* })
|
|
@@ -127,7 +116,7 @@ export type TableOptions = {
|
|
|
127
116
|
* title: Schema.String,
|
|
128
117
|
* authorId: Schema.String,
|
|
129
118
|
* createdAt: Schema.Date,
|
|
130
|
-
* }).
|
|
119
|
+
* }).annotate({ identifier: 'posts' })
|
|
131
120
|
*
|
|
132
121
|
* const postsTable = State.SQLite.table({
|
|
133
122
|
* schema: PostSchema,
|
|
@@ -161,30 +150,21 @@ export function table<
|
|
|
161
150
|
// Overload 2: With schema and explicit name
|
|
162
151
|
export function table<
|
|
163
152
|
TName extends string,
|
|
164
|
-
TSchema extends Schema.
|
|
153
|
+
TSchema extends Schema.Top,
|
|
165
154
|
const TOptionsInput extends TableOptionsInput = TableOptionsInput,
|
|
166
155
|
>(
|
|
167
156
|
args: {
|
|
168
157
|
name: TName
|
|
169
158
|
schema: TSchema
|
|
170
159
|
} & Partial<TOptionsInput>,
|
|
171
|
-
): TableDef<
|
|
172
|
-
SqliteTableDefForSchemaInput<TName, Schema.Schema.Type<TSchema>, Schema.Schema.Encoded<TSchema>, TSchema>,
|
|
173
|
-
TableOptions
|
|
174
|
-
>
|
|
160
|
+
): TableDef<SqliteTableDefForSchemaInput<TName, TSchema['Type'], TSchema['Encoded'], TSchema>>
|
|
175
161
|
|
|
176
162
|
// Overload 3: With schema and no name (uses schema annotations)
|
|
177
|
-
export function table<
|
|
178
|
-
TSchema extends Schema.Schema.AnyNoContext,
|
|
179
|
-
const TOptionsInput extends TableOptionsInput = TableOptionsInput,
|
|
180
|
-
>(
|
|
163
|
+
export function table<TSchema extends Schema.Top, const TOptionsInput extends TableOptionsInput = TableOptionsInput>(
|
|
181
164
|
args: {
|
|
182
165
|
schema: TSchema
|
|
183
166
|
} & Partial<TOptionsInput>,
|
|
184
|
-
): TableDef<
|
|
185
|
-
SqliteTableDefForSchemaInput<string, Schema.Schema.Type<TSchema>, Schema.Schema.Encoded<TSchema>, TSchema>,
|
|
186
|
-
TableOptions
|
|
187
|
-
>
|
|
167
|
+
): TableDef<SqliteTableDefForSchemaInput<string, TSchema['Type'], TSchema['Encoded'], TSchema>>
|
|
188
168
|
|
|
189
169
|
// Implementation
|
|
190
170
|
export function table<
|
|
@@ -199,10 +179,10 @@ export function table<
|
|
|
199
179
|
}
|
|
200
180
|
| {
|
|
201
181
|
name: TName
|
|
202
|
-
schema: Schema.
|
|
182
|
+
schema: Schema.Top
|
|
203
183
|
}
|
|
204
184
|
| {
|
|
205
|
-
schema: Schema.
|
|
185
|
+
schema: Schema.Top
|
|
206
186
|
}
|
|
207
187
|
) &
|
|
208
188
|
Partial<TOptionsInput>,
|
|
@@ -216,12 +196,10 @@ export function table<
|
|
|
216
196
|
if ('columns' in args) {
|
|
217
197
|
tableName = args.name
|
|
218
198
|
const columnOrColumns = args.columns
|
|
219
|
-
columns = (
|
|
220
|
-
SqliteDsl.isColumnDefinition(columnOrColumns) ? { value: columnOrColumns } : columnOrColumns
|
|
221
|
-
) as SqliteDsl.Columns
|
|
199
|
+
columns = SqliteDsl.isColumnDefinition(columnOrColumns) === true ? { value: columnOrColumns } : columnOrColumns
|
|
222
200
|
additionalIndexes = []
|
|
223
201
|
} else if ('schema' in args) {
|
|
224
|
-
const result =
|
|
202
|
+
const result = args.schema.pipe(getSqlitePropertySignatures, schemaFieldsToColumns)
|
|
225
203
|
columns = result.columns
|
|
226
204
|
|
|
227
205
|
// We'll set tableName first, then use it for index names
|
|
@@ -232,14 +210,12 @@ export function table<
|
|
|
232
210
|
tempTableName = args.name
|
|
233
211
|
} else {
|
|
234
212
|
// Use title or identifier, with preference for title
|
|
235
|
-
tempTableName =
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
),
|
|
242
|
-
)
|
|
213
|
+
tempTableName =
|
|
214
|
+
SchemaAST.resolveTitle(args.schema.ast) ??
|
|
215
|
+
SchemaAST.resolveIdentifier(args.schema.ast) ??
|
|
216
|
+
shouldNeverHappen(
|
|
217
|
+
'When using schema without explicit name, the schema must have a title or identifier annotation',
|
|
218
|
+
)
|
|
243
219
|
}
|
|
244
220
|
|
|
245
221
|
tableName = tempTableName
|
|
@@ -289,6 +265,74 @@ export function table<
|
|
|
289
265
|
return tableDef as any
|
|
290
266
|
}
|
|
291
267
|
|
|
268
|
+
const getSqlitePropertySignatures = (schema: Schema.Top): ReadonlyArray<SchemaAST.PropertySignature> => {
|
|
269
|
+
const encodedPropertySignatures = getPropertySignatures(SchemaAST.toEncoded(schema.ast))
|
|
270
|
+
const typePropertySignatures = getPropertySignatures(SchemaAST.toType(schema.ast))
|
|
271
|
+
|
|
272
|
+
return encodedPropertySignatures.map((encodedPropertySignature) => {
|
|
273
|
+
const typePropertySignature = typePropertySignatures.find(
|
|
274
|
+
(propertySignature) => propertySignature.name === encodedPropertySignature.name,
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
if (typePropertySignature === undefined || hasLiveStoreSqliteAnnotation(encodedPropertySignature.type) === true) {
|
|
278
|
+
return encodedPropertySignature
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return new SchemaAST.PropertySignature(encodedPropertySignature.name, typePropertySignature.type)
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const getPropertySignatures = (ast: SchemaAST.AST): ReadonlyArray<SchemaAST.PropertySignature> => {
|
|
286
|
+
if (SchemaAST.isObjects(ast) === true) return ast.propertySignatures
|
|
287
|
+
|
|
288
|
+
if (SchemaAST.isUnion(ast) === true) {
|
|
289
|
+
const members = ast.types.map(getPropertySignatures)
|
|
290
|
+
const [head, ...tail] = members
|
|
291
|
+
if (head === undefined) return []
|
|
292
|
+
|
|
293
|
+
return head.flatMap((propertySignature) => {
|
|
294
|
+
const matchingPropertySignatures: Array<SchemaAST.PropertySignature> = []
|
|
295
|
+
for (const propertySignatures of tail) {
|
|
296
|
+
const matchingPropertySignature = propertySignatures.find(
|
|
297
|
+
(memberPropertySignature) => memberPropertySignature.name === propertySignature.name,
|
|
298
|
+
)
|
|
299
|
+
if (matchingPropertySignature === undefined) {
|
|
300
|
+
return []
|
|
301
|
+
}
|
|
302
|
+
matchingPropertySignatures.push(matchingPropertySignature)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const propertySignatures = [propertySignature, ...matchingPropertySignatures]
|
|
306
|
+
/**
|
|
307
|
+
* `SchemaAST.optionalKey` became internal in Effect rc.109, so the optional-key marker is
|
|
308
|
+
* applied by constructing the union with an optional `Context`. Equivalent here because the
|
|
309
|
+
* union is freshly built and therefore carries no encoding chain to propagate the marker to.
|
|
310
|
+
*/
|
|
311
|
+
const hasOptionalMember =
|
|
312
|
+
propertySignatures.some((memberPropertySignature) => SchemaAST.isOptional(memberPropertySignature.type)) ===
|
|
313
|
+
true
|
|
314
|
+
const keyContext = hasOptionalMember === true ? new SchemaAST.Context(true, false) : undefined
|
|
315
|
+
const union = new SchemaAST.Union(
|
|
316
|
+
propertySignatures.map((memberPropertySignature) => memberPropertySignature.type),
|
|
317
|
+
ast.mode,
|
|
318
|
+
undefined,
|
|
319
|
+
undefined,
|
|
320
|
+
undefined,
|
|
321
|
+
keyContext,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
return [new SchemaAST.PropertySignature(propertySignature.name, union)]
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return []
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const hasLiveStoreSqliteAnnotation = (ast: SchemaAST.AST): boolean => {
|
|
332
|
+
const annotationKeys = [...Object.keys(ast.annotations ?? {}), ...Object.keys(ast.context?.annotations ?? {})]
|
|
333
|
+
return annotationKeys.some((key) => key.startsWith('livestore/state/sqlite/annotations/'))
|
|
334
|
+
}
|
|
335
|
+
|
|
292
336
|
export namespace FromTable {
|
|
293
337
|
// TODO this sometimes doesn't preserve the order of columns
|
|
294
338
|
export type RowDecoded<TTableDef extends TableDefBase> = Types.Simplify<
|
|
@@ -305,9 +349,7 @@ export namespace FromTable {
|
|
|
305
349
|
}
|
|
306
350
|
|
|
307
351
|
export type RowEncodeNonNullable<TTableDef extends TableDefBase> = {
|
|
308
|
-
[K in keyof TTableDef['sqliteDef']['columns']]:
|
|
309
|
-
TTableDef['sqliteDef']['columns'][K]['schema']
|
|
310
|
-
>
|
|
352
|
+
[K in keyof TTableDef['sqliteDef']['columns']]: TTableDef['sqliteDef']['columns'][K]['schema']['Encoded']
|
|
311
353
|
}
|
|
312
354
|
|
|
313
355
|
export type RowEncoded<TTableDef extends TableDefBase> = Types.Simplify<
|
|
@@ -316,7 +358,7 @@ export namespace FromTable {
|
|
|
316
358
|
>
|
|
317
359
|
|
|
318
360
|
export type RowDecodedAll<TTableDef extends TableDefBase> = {
|
|
319
|
-
[K in keyof TTableDef['sqliteDef']['columns']]:
|
|
361
|
+
[K in keyof TTableDef['sqliteDef']['columns']]: TTableDef['sqliteDef']['columns'][K]['schema']['Type']
|
|
320
362
|
}
|
|
321
363
|
}
|
|
322
364
|
|
|
@@ -328,7 +370,7 @@ export namespace FromColumns {
|
|
|
328
370
|
>
|
|
329
371
|
|
|
330
372
|
export type RowDecodedAll<TColumns extends SqliteDsl.Columns> = {
|
|
331
|
-
[K in keyof TColumns]:
|
|
373
|
+
[K in keyof TColumns]: TColumns[K]['schema']['Type']
|
|
332
374
|
}
|
|
333
375
|
|
|
334
376
|
export type RowEncoded<TColumns extends SqliteDsl.Columns> = Types.Simplify<
|
|
@@ -337,7 +379,7 @@ export namespace FromColumns {
|
|
|
337
379
|
>
|
|
338
380
|
|
|
339
381
|
export type RowEncodeNonNullable<TColumns extends SqliteDsl.Columns> = {
|
|
340
|
-
[K in keyof TColumns]:
|
|
382
|
+
[K in keyof TColumns]: TColumns[K]['schema']['Encoded']
|
|
341
383
|
}
|
|
342
384
|
|
|
343
385
|
export type NullableColumnNames<TColumns extends SqliteDsl.Columns> = keyof {
|
|
@@ -377,18 +419,21 @@ export type ToColumns<TColumns extends SqliteDsl.Columns | SqliteDsl.ColumnDefin
|
|
|
377
419
|
: never
|
|
378
420
|
|
|
379
421
|
export declare namespace SchemaToColumns {
|
|
422
|
+
/** Checks if `null` or `undefined` is assignable to `T`, matching the runtime nullable detection. */
|
|
423
|
+
type IsNullable<T> = null extends T ? true : undefined extends T ? true : false
|
|
424
|
+
|
|
380
425
|
// Type helper to create column definition with proper schema
|
|
381
|
-
export type ColumnDefForType<TEncoded, TType> = SqliteDsl.ColumnDefinition<TEncoded, TType
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
426
|
+
export type ColumnDefForType<TEncoded, TType> = SqliteDsl.ColumnDefinition<TEncoded, TType, IsNullable<TEncoded>>
|
|
427
|
+
|
|
428
|
+
export type FromTypes<TType, TEncoded> =
|
|
429
|
+
TEncoded extends Record<string, any>
|
|
430
|
+
? {
|
|
431
|
+
[K in keyof TEncoded]-?: ColumnDefForType<
|
|
432
|
+
TEncoded[K],
|
|
433
|
+
TType extends Record<string, any> ? (K extends keyof TType ? TType[K] : TEncoded[K]) : TEncoded[K]
|
|
434
|
+
>
|
|
435
|
+
}
|
|
436
|
+
: SqliteDsl.Columns
|
|
392
437
|
}
|
|
393
438
|
|
|
394
439
|
export declare namespace TableDefInput {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Effect } from '@livestore/utils/effect'
|
|
2
|
+
|
|
3
|
+
import { UnknownEventError } from '../errors.ts'
|
|
4
|
+
import type { EventDef, Materializer } from './EventDef/mod.ts'
|
|
5
|
+
import type * as LiveStoreEvent from './LiveStoreEvent/mod.ts'
|
|
6
|
+
import type { LiveStoreSchema } from './schema.ts'
|
|
7
|
+
|
|
8
|
+
export type UnknownEventContext = {
|
|
9
|
+
readonly event: Pick<LiveStoreEvent.Client.Encoded, 'name' | 'args' | 'seqNum' | 'clientId' | 'sessionId'>
|
|
10
|
+
readonly reason: 'event-definition-missing' | 'materializer-missing'
|
|
11
|
+
readonly operation: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export namespace UnknownEvents {
|
|
15
|
+
export type HandlingStrategy = 'warn' | 'fail' | 'ignore' | 'callback'
|
|
16
|
+
|
|
17
|
+
export type Callback = (
|
|
18
|
+
context: UnknownEventContext,
|
|
19
|
+
error: UnknownEventError,
|
|
20
|
+
) => Effect.SyncOrPromiseOrEffect<void, unknown>
|
|
21
|
+
|
|
22
|
+
export type HandlingConfig =
|
|
23
|
+
| { readonly strategy: 'warn' }
|
|
24
|
+
| { readonly strategy: 'ignore' }
|
|
25
|
+
| { readonly strategy: 'fail' }
|
|
26
|
+
| { readonly strategy: 'callback'; readonly onUnknownEvent: Callback }
|
|
27
|
+
|
|
28
|
+
export type Reason = UnknownEventContext['reason']
|
|
29
|
+
|
|
30
|
+
export type ResolveContext = Omit<UnknownEventContext, 'reason'>
|
|
31
|
+
|
|
32
|
+
export type Resolved =
|
|
33
|
+
| {
|
|
34
|
+
readonly _tag: 'known'
|
|
35
|
+
readonly eventDef: EventDef.AnyWithoutFn
|
|
36
|
+
readonly materializer: Materializer
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
readonly _tag: 'unknown'
|
|
40
|
+
readonly reason: Reason
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const DEFAULT_UNKNOWN_EVENT_HANDLING: UnknownEvents.HandlingConfig = { strategy: 'warn' }
|
|
45
|
+
|
|
46
|
+
export const normalizeUnknownEventHandling = (
|
|
47
|
+
input: UnknownEvents.HandlingConfig | undefined,
|
|
48
|
+
): UnknownEvents.HandlingConfig => input ?? DEFAULT_UNKNOWN_EVENT_HANDLING
|
|
49
|
+
|
|
50
|
+
const handleUnknownEvent = ({
|
|
51
|
+
schema,
|
|
52
|
+
context,
|
|
53
|
+
}: {
|
|
54
|
+
schema: LiveStoreSchema
|
|
55
|
+
context: UnknownEventContext
|
|
56
|
+
}): Effect.Effect<void, UnknownEventError> =>
|
|
57
|
+
Effect.gen(function* () {
|
|
58
|
+
const config = schema.unknownEventHandling
|
|
59
|
+
const error = new UnknownEventError(context)
|
|
60
|
+
|
|
61
|
+
switch (config.strategy) {
|
|
62
|
+
case 'fail': {
|
|
63
|
+
return yield* error
|
|
64
|
+
}
|
|
65
|
+
case 'warn': {
|
|
66
|
+
yield* Effect.logWarning('@livestore/common:schema:unknown-event', context)
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
case 'ignore': {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
case 'callback': {
|
|
73
|
+
const callback = config.onUnknownEvent
|
|
74
|
+
|
|
75
|
+
// @effect-diagnostics-next-line anyUnknownInErrorContext:off -- user callback errors are immediately handled and logged below
|
|
76
|
+
yield* Effect.trySyncOrPromiseOrEffect(() => callback(context, error)).pipe(
|
|
77
|
+
Effect.catch((cause) =>
|
|
78
|
+
Effect.logWarning('@livestore/common:schema:unknown-event:callback-error', {
|
|
79
|
+
event: context.event,
|
|
80
|
+
reason: context.reason,
|
|
81
|
+
operation: context.operation,
|
|
82
|
+
cause,
|
|
83
|
+
}),
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Resolves the runtime event definition + materializer for a given event name.
|
|
93
|
+
*
|
|
94
|
+
* Behaviour is intentionally split across the result and error channels:
|
|
95
|
+
* - For `'fail'` handling, we surface an `UnknownEventError` via the failure channel so
|
|
96
|
+
* callers can convert it into the appropriate domain error (for example `MaterializeError`).
|
|
97
|
+
* - For all other strategies (`warn`, `ignore`, `callback`) we succeed with an
|
|
98
|
+
* `{ _tag: 'unknown' }` value, signalling that the caller should skip the event while
|
|
99
|
+
* continuing normal processing.
|
|
100
|
+
*/
|
|
101
|
+
export const resolveEventDef = (
|
|
102
|
+
schema: LiveStoreSchema,
|
|
103
|
+
context: UnknownEvents.ResolveContext,
|
|
104
|
+
): Effect.Effect<UnknownEvents.Resolved, UnknownEventError> =>
|
|
105
|
+
Effect.gen(function* () {
|
|
106
|
+
const eventName = context.event.name
|
|
107
|
+
const eventDef = schema.eventsDefsMap.get(eventName)
|
|
108
|
+
if (eventDef === undefined) {
|
|
109
|
+
yield* handleUnknownEvent({
|
|
110
|
+
schema,
|
|
111
|
+
context: {
|
|
112
|
+
event: context.event,
|
|
113
|
+
reason: 'event-definition-missing',
|
|
114
|
+
operation: context.operation,
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
return { _tag: 'unknown', reason: 'event-definition-missing' }
|
|
118
|
+
}
|
|
119
|
+
const materializer = schema.state.materializers.get(eventName)
|
|
120
|
+
if (materializer === undefined) {
|
|
121
|
+
yield* handleUnknownEvent({
|
|
122
|
+
schema,
|
|
123
|
+
context: {
|
|
124
|
+
event: context.event,
|
|
125
|
+
reason: 'materializer-missing',
|
|
126
|
+
operation: context.operation,
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
return { _tag: 'unknown', reason: 'materializer-missing' }
|
|
130
|
+
}
|
|
131
|
+
return { _tag: 'known', eventDef, materializer }
|
|
132
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { Effect, Option, Schema } from '@livestore/utils/effect'
|
|
4
|
+
|
|
5
|
+
import { SqliteAst } from '../../schema/state/sqlite/db-schema/mod.ts'
|
|
6
|
+
import type { PreparedStatement, SqliteDb } from '../../sqlite-types.ts'
|
|
7
|
+
import type { PreparedBindValues } from '../../util.ts'
|
|
8
|
+
import { migrateTable } from '../migrations.ts'
|
|
9
|
+
|
|
10
|
+
const makeStubDb = () => {
|
|
11
|
+
const executed: string[] = []
|
|
12
|
+
|
|
13
|
+
const db: SqliteDb = {
|
|
14
|
+
_tag: 'SqliteDb',
|
|
15
|
+
metadata: { dbPointer: 0, persistenceInfo: { fileName: ':memory:' } } as any,
|
|
16
|
+
debug: { head: 0 as any },
|
|
17
|
+
prepare: (queryStr: string): PreparedStatement => ({
|
|
18
|
+
sql: queryStr,
|
|
19
|
+
execute: (_bind: PreparedBindValues | undefined) => {
|
|
20
|
+
executed.push(queryStr)
|
|
21
|
+
},
|
|
22
|
+
select: <T>(_bind: PreparedBindValues | undefined) => [] as unknown as ReadonlyArray<T>,
|
|
23
|
+
finalize: () => {},
|
|
24
|
+
}),
|
|
25
|
+
execute: () => {},
|
|
26
|
+
select: () => [],
|
|
27
|
+
export: () => new Uint8Array(),
|
|
28
|
+
import: () => {},
|
|
29
|
+
close: () => {},
|
|
30
|
+
destroy: () => {},
|
|
31
|
+
session: () => ({ changeset: () => undefined, finish: () => {} }),
|
|
32
|
+
makeChangeset: () => ({ invert: () => ({ invert: () => ({}) as any, apply: () => {} }) as any, apply: () => {} }),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { db, executed }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('migrateTable - quoting and autoincrement', () => {
|
|
39
|
+
it('creates valid CREATE TABLE with inline INTEGER PRIMARY KEY AUTOINCREMENT and double-quoted identifiers', () => {
|
|
40
|
+
const { db, executed } = makeStubDb()
|
|
41
|
+
|
|
42
|
+
const table = SqliteAst.table(
|
|
43
|
+
'todos',
|
|
44
|
+
[
|
|
45
|
+
SqliteAst.column({
|
|
46
|
+
name: 'id',
|
|
47
|
+
type: { _tag: 'integer' },
|
|
48
|
+
nullable: false,
|
|
49
|
+
primaryKey: true,
|
|
50
|
+
autoIncrement: true,
|
|
51
|
+
default: Option.none(),
|
|
52
|
+
schema: Schema.Finite,
|
|
53
|
+
}),
|
|
54
|
+
SqliteAst.column({
|
|
55
|
+
name: 'text',
|
|
56
|
+
type: { _tag: 'text' },
|
|
57
|
+
nullable: false,
|
|
58
|
+
primaryKey: false,
|
|
59
|
+
autoIncrement: false,
|
|
60
|
+
default: Option.some(''),
|
|
61
|
+
schema: Schema.String,
|
|
62
|
+
}),
|
|
63
|
+
SqliteAst.column({
|
|
64
|
+
name: 'completed',
|
|
65
|
+
type: { _tag: 'integer' },
|
|
66
|
+
nullable: false,
|
|
67
|
+
primaryKey: false,
|
|
68
|
+
autoIncrement: false,
|
|
69
|
+
default: Option.some(0),
|
|
70
|
+
schema: Schema.Finite,
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
[],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
migrateTable({ db, tableAst: table, behaviour: 'create-if-not-exists', skipMetaTable: true }).pipe(Effect.runSync)
|
|
77
|
+
|
|
78
|
+
const createStmt = executed.find((s) => /create table if not exists/i.test(s))
|
|
79
|
+
expect(createStmt).toBeDefined()
|
|
80
|
+
|
|
81
|
+
// Identifiers must be double-quoted, not single-quoted
|
|
82
|
+
expect(createStmt!).toContain('create table if not exists "todos"')
|
|
83
|
+
expect(createStmt!).toContain('"id" integer primary key autoincrement')
|
|
84
|
+
expect(createStmt!).toContain(" default ''")
|
|
85
|
+
expect(createStmt!).not.toContain("PRIMARY KEY ('id')")
|
|
86
|
+
expect(createStmt!).not.toMatch(/'todos'|'id'|'text'/)
|
|
87
|
+
})
|
|
88
|
+
})
|
|
@@ -13,7 +13,7 @@ export const dbExecute = (db: SqliteDb, queryStr: string, bindValues?: ParamsObj
|
|
|
13
13
|
// cachedStmts.set(queryStr, stmt)
|
|
14
14
|
// }
|
|
15
15
|
|
|
16
|
-
const preparedBindValues = bindValues ? prepareBindValues(bindValues, queryStr) : undefined
|
|
16
|
+
const preparedBindValues = bindValues !== undefined ? prepareBindValues(bindValues, queryStr) : undefined
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
19
|
stmt.execute(preparedBindValues)
|
|
@@ -34,7 +34,7 @@ export const dbSelect = <T>(db: SqliteDb, queryStr: string, bindValues?: ParamsO
|
|
|
34
34
|
// cachedStmts.set(queryStr, stmt)
|
|
35
35
|
// }
|
|
36
36
|
|
|
37
|
-
const res = stmt.select<T>(bindValues ? prepareBindValues(bindValues, queryStr) : undefined)
|
|
37
|
+
const res = stmt.select<T>(bindValues !== undefined ? prepareBindValues(bindValues, queryStr) : undefined)
|
|
38
38
|
stmt.finalize()
|
|
39
39
|
return res
|
|
40
40
|
}
|
|
@@ -1,20 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTOMATIC HASH-BASED SCHEMA MIGRATIONS
|
|
3
|
+
*
|
|
4
|
+
* This module implements automatic schema versioning using hash-based change detection.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ CRITICAL DISTINCTION:
|
|
7
|
+
* - STATE TABLES (safe to modify): Changes trigger rematerialization from eventlog
|
|
8
|
+
* - EVENTLOG TABLES (NEVER modify): Changes cause data loss - need manual versioning!
|
|
9
|
+
*
|
|
10
|
+
* How it works:
|
|
11
|
+
* 1. Each table's schema is hashed using SqliteAst.hash()
|
|
12
|
+
* 2. Hashes are stored in SCHEMA_META_TABLE after successful migrations
|
|
13
|
+
* 3. On app start, current schema hashes are compared with stored hashes
|
|
14
|
+
* 4. Mismatches trigger migrations:
|
|
15
|
+
* - State tables: Recreated and repopulated from eventlog (safe, no data loss)
|
|
16
|
+
* - Eventlog tables: Uses 'create-if-not-exists' (UNSAFE - causes data loss!)
|
|
17
|
+
*
|
|
18
|
+
* State Table Changes (SAFE):
|
|
19
|
+
* - User-defined tables are rebuilt from eventlog
|
|
20
|
+
* - System tables (schemaMetaTable, etc.) are recreated
|
|
21
|
+
* - Data preserved through rematerializeFromEventlog()
|
|
22
|
+
*
|
|
23
|
+
* Eventlog Table Changes (UNSAFE):
|
|
24
|
+
* - eventlogMetaTable, syncStatusTable changes cause "soft reset"
|
|
25
|
+
* - Old table becomes inaccessible (but remains in DB)
|
|
26
|
+
* - No automatic migration - effectively data loss
|
|
27
|
+
* - TODO: Implement proper EVENTLOG_PERSISTENCE_FORMAT_VERSION system
|
|
28
|
+
*
|
|
29
|
+
* See system-tables/state-tables.ts and system-tables/eventlog-tables.ts for detailed documentation on each table type.
|
|
30
|
+
*/
|
|
31
|
+
|
|
1
32
|
import { memoizeByStringifyArgs } from '@livestore/utils'
|
|
2
33
|
import { Effect } from '@livestore/utils/effect'
|
|
3
34
|
|
|
4
35
|
import type { SqliteDb } from '../adapter-types.ts'
|
|
5
36
|
import type { MigrationsReport, MigrationsReportEntry } from '../defs.ts'
|
|
6
|
-
import type {
|
|
37
|
+
import type { UnknownError } from '../errors.ts'
|
|
7
38
|
import type { LiveStoreSchema } from '../schema/mod.ts'
|
|
8
39
|
import { makeColumnSpec } from '../schema/state/sqlite/column-spec.ts'
|
|
9
40
|
import { SqliteAst } from '../schema/state/sqlite/db-schema/mod.ts'
|
|
10
|
-
import type { SchemaEventDefsMetaRow, SchemaMetaRow } from '../schema/state/sqlite/system-tables.ts'
|
|
41
|
+
import type { SchemaEventDefsMetaRow, SchemaMetaRow } from '../schema/state/sqlite/system-tables/state-tables.ts'
|
|
11
42
|
import {
|
|
12
43
|
isStateSystemTable,
|
|
13
44
|
SCHEMA_EVENT_DEFS_META_TABLE,
|
|
14
45
|
SCHEMA_META_TABLE,
|
|
15
46
|
schemaEventDefsMetaTable,
|
|
16
47
|
stateSystemTables,
|
|
17
|
-
} from '../schema/state/sqlite/system-tables.ts'
|
|
48
|
+
} from '../schema/state/sqlite/system-tables/state-tables.ts'
|
|
18
49
|
import { sql } from '../util.ts'
|
|
19
50
|
import type { SchemaManager } from './common.ts'
|
|
20
51
|
import { dbExecute, dbSelect } from './common.ts'
|
|
@@ -56,7 +87,7 @@ export const migrateDb = ({
|
|
|
56
87
|
db: SqliteDb
|
|
57
88
|
schema: LiveStoreSchema
|
|
58
89
|
onProgress?: (opts: { done: number; total: number }) => Effect.Effect<void>
|
|
59
|
-
}): Effect.Effect<MigrationsReport,
|
|
90
|
+
}): Effect.Effect<MigrationsReport, UnknownError> =>
|
|
60
91
|
Effect.gen(function* () {
|
|
61
92
|
for (const tableDef of stateSystemTables) {
|
|
62
93
|
yield* migrateTable({
|
|
@@ -137,10 +168,10 @@ export const migrateTable = ({
|
|
|
137
168
|
|
|
138
169
|
if (behaviour === 'drop-and-recreate') {
|
|
139
170
|
// TODO need to possibly handle cascading deletes due to foreign keys
|
|
140
|
-
dbExecute(db, sql`drop table if exists
|
|
141
|
-
dbExecute(db, sql`create table if not exists
|
|
171
|
+
dbExecute(db, sql`drop table if exists "${tableName}"`)
|
|
172
|
+
dbExecute(db, sql`create table if not exists "${tableName}" (${columnSpec}) strict`)
|
|
142
173
|
} else if (behaviour === 'create-if-not-exists') {
|
|
143
|
-
dbExecute(db, sql`create table if not exists
|
|
174
|
+
dbExecute(db, sql`create table if not exists "${tableName}" (${columnSpec}) strict`)
|
|
144
175
|
}
|
|
145
176
|
|
|
146
177
|
for (const index of tableAst.indexes) {
|
|
@@ -169,6 +200,8 @@ export const migrateTable = ({
|
|
|
169
200
|
)
|
|
170
201
|
|
|
171
202
|
const createIndexFromDefinition = (tableName: string, index: SqliteAst.Index) => {
|
|
172
|
-
const uniqueStr = index.unique ? 'UNIQUE' : ''
|
|
173
|
-
return sql`create ${uniqueStr} index if not exists
|
|
203
|
+
const uniqueStr = index.unique === true ? 'UNIQUE' : ''
|
|
204
|
+
return sql`create ${uniqueStr} index if not exists "${index.name}" on "${tableName}" (${index.columns
|
|
205
|
+
.map((col) => `"${col}"`)
|
|
206
|
+
.join(', ')})`
|
|
174
207
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from '@livestore/utils/effect'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import type { EventDef } from '../schema/EventDef.ts'
|
|
3
|
+
import { UnknownError } from '../adapter-types.ts'
|
|
4
|
+
import type { EventDef } from '../schema/EventDef/mod.ts'
|
|
5
5
|
import type { LiveStoreSchema } from '../schema/mod.ts'
|
|
6
6
|
import type { EventDefInfo, SchemaManager } from './common.ts'
|
|
7
7
|
|
|
@@ -15,7 +15,7 @@ export const validateSchema = (schema: LiveStoreSchema, schemaManager: SchemaMan
|
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
if (missingEventDefs.length > 0) {
|
|
18
|
-
return yield* new
|
|
18
|
+
return yield* new UnknownError({
|
|
19
19
|
cause: `Missing mutation definitions: ${missingEventDefs.map((info) => info.eventName).join(', ')}`,
|
|
20
20
|
})
|
|
21
21
|
}
|