@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,11 +1,10 @@
|
|
|
1
1
|
import { shouldNeverHappen } from '@livestore/utils'
|
|
2
|
-
import type
|
|
3
|
-
import { Schema } from '@livestore/utils/effect'
|
|
2
|
+
import { type Option, type Types, Schema, SchemaGetter, Struct } from '@livestore/utils/effect'
|
|
4
3
|
|
|
5
|
-
import { SessionIdSymbol } from '../../../
|
|
4
|
+
import { SessionIdSymbol } from '../../../session-id-symbol.ts'
|
|
6
5
|
import { sql } from '../../../util.ts'
|
|
7
|
-
import type { EventDef, Materializer } from '../../EventDef.ts'
|
|
8
|
-
import { defineEvent, defineMaterializer } from '../../EventDef.ts'
|
|
6
|
+
import type { EventDef, Materializer } from '../../EventDef/mod.ts'
|
|
7
|
+
import { defineEvent, defineMaterializer } from '../../EventDef/mod.ts'
|
|
9
8
|
import { SqliteDsl } from './db-schema/mod.ts'
|
|
10
9
|
import type { QueryBuilder, QueryBuilderAst } from './query-builder/mod.ts'
|
|
11
10
|
import { QueryBuilderAstSymbol, QueryBuilderTypeId } from './query-builder/mod.ts'
|
|
@@ -47,7 +46,7 @@ export const clientDocument = <
|
|
|
47
46
|
...inputOptions
|
|
48
47
|
}: {
|
|
49
48
|
name: TName
|
|
50
|
-
schema: Schema.
|
|
49
|
+
schema: Schema.Codec<TType, TEncoded>
|
|
51
50
|
} & TOptions): ClientDocumentTableDef<
|
|
52
51
|
TName,
|
|
53
52
|
TType,
|
|
@@ -61,6 +60,7 @@ export const clientDocument = <
|
|
|
61
60
|
value: inputOptions.default.value,
|
|
62
61
|
},
|
|
63
62
|
} satisfies ClientDocumentTableOptions<TType>
|
|
63
|
+
const canPartialSet = options.partialSet === true && Schema.getResolvedPropertySignatures(valueSchema).length > 0
|
|
64
64
|
|
|
65
65
|
// Column needs optimistic schema to read historical data formats
|
|
66
66
|
const optimisticColumnSchema = createOptimisticEventSchema({
|
|
@@ -83,7 +83,7 @@ export const clientDocument = <
|
|
|
83
83
|
name,
|
|
84
84
|
valueSchema,
|
|
85
85
|
defaultValue: options.default.value,
|
|
86
|
-
partialSet:
|
|
86
|
+
partialSet: canPartialSet,
|
|
87
87
|
})
|
|
88
88
|
|
|
89
89
|
const setEventDef = (...args: any[]) => {
|
|
@@ -95,10 +95,12 @@ export const clientDocument = <
|
|
|
95
95
|
Object.defineProperty(setEventDef, 'schema', {
|
|
96
96
|
value: Schema.Struct({
|
|
97
97
|
id: Schema.String,
|
|
98
|
-
value:
|
|
99
|
-
}).
|
|
98
|
+
value: canPartialSet === true ? partialStructSchema(valueSchema) : valueSchema,
|
|
99
|
+
}).annotate({ title: `${name}Set:Args` }) as Schema.Codec<any, any>,
|
|
100
|
+
})
|
|
101
|
+
Object.defineProperty(setEventDef, 'options', {
|
|
102
|
+
value: { derived: true, clientOnly: true, facts: undefined, deprecated: undefined },
|
|
100
103
|
})
|
|
101
|
-
Object.defineProperty(setEventDef, 'options', { value: { derived: true, clientOnly: true, facts: undefined } })
|
|
102
104
|
|
|
103
105
|
const clientDocumentTableDefTrait: ClientDocumentTableDef.Trait<
|
|
104
106
|
TName,
|
|
@@ -106,20 +108,26 @@ export const clientDocument = <
|
|
|
106
108
|
TEncoded,
|
|
107
109
|
ClientDocumentTableOptions<TType>
|
|
108
110
|
> = {
|
|
111
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- dynamic table def composition; type safety ensured by ClientDocumentTableDef.Trait
|
|
109
112
|
get: makeGetQueryBuilder(() => clientDocumentTableDef) as any,
|
|
113
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- dynamic table def composition; type safety ensured by SetEventDefLike signature
|
|
110
114
|
set: setEventDef as any,
|
|
115
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- phantom type field for generic inference only
|
|
111
116
|
Value: 'only-for-type-inference' as any,
|
|
112
117
|
default: options.default,
|
|
113
118
|
valueSchema,
|
|
114
119
|
[ClientDocumentTableDefSymbol]: {
|
|
115
120
|
derived: {
|
|
121
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- dynamic event def composition; type checked at usage sites
|
|
116
122
|
setEventDef: derivedSetEventDef as any,
|
|
123
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- dynamic materializer composition; type checked at usage sites
|
|
117
124
|
setMaterializer: derivedSetMaterializer as any,
|
|
118
125
|
},
|
|
119
126
|
options,
|
|
120
127
|
},
|
|
121
128
|
}
|
|
122
129
|
|
|
130
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- composing tableDef + clientDocumentTableDefTrait into final type; validated by satisfies above
|
|
123
131
|
const clientDocumentTableDef = {
|
|
124
132
|
...tableDef,
|
|
125
133
|
...clientDocumentTableDefTrait,
|
|
@@ -139,14 +147,30 @@ export const mergeDefaultValues = <T>(defaultValues: T, explicitDefaultValues: T
|
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
// Get all unique keys from both objects
|
|
150
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- Object.keys requires indexable type; T is constrained to object by preceding typeof checks
|
|
142
151
|
const allKeys = new Set([...Object.keys(defaultValues as any), ...Object.keys(explicitDefaultValues as any)])
|
|
143
152
|
|
|
144
153
|
return Array.from(allKeys).reduce((acc, key) => {
|
|
154
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- dynamic key access on generic object; keys validated from Object.keys above
|
|
145
155
|
acc[key] = (explicitDefaultValues as any)[key] ?? (defaultValues as any)[key]
|
|
146
156
|
return acc
|
|
157
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- reduce accumulator type; result type is T
|
|
147
158
|
}, {} as any)
|
|
148
159
|
}
|
|
149
160
|
|
|
161
|
+
const partialStructSchema = (schema: Schema.Codec<any, any>): Schema.Codec<any, any> =>
|
|
162
|
+
(schema as unknown as Schema.Struct<Schema.Struct.Fields>).mapFields(
|
|
163
|
+
Struct.map(Schema.optional),
|
|
164
|
+
) as unknown as Schema.Codec<any, any>
|
|
165
|
+
|
|
166
|
+
const pickStructSchema = (
|
|
167
|
+
schema: Schema.Codec<any, any>,
|
|
168
|
+
keys: ReadonlyArray<string>,
|
|
169
|
+
): Schema.Codec<Record<string, unknown>, Record<string, unknown>> =>
|
|
170
|
+
(schema as unknown as Schema.Struct<Schema.Struct.Fields>).mapFields(
|
|
171
|
+
Struct.pick(keys as readonly any[]),
|
|
172
|
+
) as unknown as Schema.Codec<Record<string, unknown>, Record<string, unknown>>
|
|
173
|
+
|
|
150
174
|
/**
|
|
151
175
|
* Creates an optimistic schema that accepts historical event formats
|
|
152
176
|
* and transforms them to the current schema, preserving data and intent.
|
|
@@ -171,79 +195,90 @@ export const createOptimisticEventSchema = ({
|
|
|
171
195
|
defaultValue,
|
|
172
196
|
partialSet,
|
|
173
197
|
}: {
|
|
174
|
-
valueSchema: Schema.
|
|
198
|
+
valueSchema: Schema.Codec<any, any>
|
|
175
199
|
defaultValue: any
|
|
176
200
|
partialSet: boolean
|
|
177
|
-
}) => {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
201
|
+
}): Schema.Codec<any, unknown> => {
|
|
202
|
+
const canPartialSet = partialSet === true && Schema.getResolvedPropertySignatures(valueSchema).length > 0
|
|
203
|
+
const targetSchema = canPartialSet === true ? partialStructSchema(valueSchema) : valueSchema
|
|
204
|
+
// The transform decode must yield values in the target schema's ENCODED shape.
|
|
205
|
+
// This keeps JSON columns consistent when Encoded != Type (e.g. Option).
|
|
206
|
+
const encodeTarget = Schema.encodeSync(targetSchema)
|
|
207
|
+
|
|
208
|
+
return Schema.Unknown.pipe(
|
|
209
|
+
Schema.decodeTo(
|
|
210
|
+
targetSchema, // Output current schema
|
|
211
|
+
{
|
|
212
|
+
decode: SchemaGetter.transform((eventValue) => {
|
|
213
|
+
// Try direct decode first (for current schema events)
|
|
214
|
+
try {
|
|
215
|
+
const decoded = Schema.decodeUnknownSync(targetSchema)(eventValue)
|
|
216
|
+
// Re-encode so downstream parseJson/column decoding sees encoded values.
|
|
217
|
+
return encodeTarget(decoded)
|
|
218
|
+
} catch {
|
|
219
|
+
// Optimistic decoding for historical events
|
|
220
|
+
|
|
221
|
+
// Handle null/undefined/non-object cases
|
|
222
|
+
if (typeof eventValue !== 'object' || eventValue === null) {
|
|
223
|
+
console.warn(
|
|
224
|
+
`Client document: Non-object event value, using ${canPartialSet === true ? 'empty partial' : 'defaults'}`,
|
|
225
|
+
)
|
|
226
|
+
return encodeTarget(canPartialSet === true ? {} : defaultValue)
|
|
227
|
+
}
|
|
196
228
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
229
|
+
if (canPartialSet === true) {
|
|
230
|
+
// For partial sets: only preserve fields that exist in new schema
|
|
231
|
+
const partialResult: Record<string, unknown> = {}
|
|
232
|
+
let hasValidFields = false
|
|
233
|
+
|
|
234
|
+
for (const [key, value] of Object.entries(eventValue as Record<string, unknown>)) {
|
|
235
|
+
if (key in defaultValue) {
|
|
236
|
+
partialResult[key] = value
|
|
237
|
+
hasValidFields = true
|
|
238
|
+
}
|
|
239
|
+
// Drop fields that don't exist in new schema
|
|
240
|
+
}
|
|
201
241
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
242
|
+
if (hasValidFields === true) {
|
|
243
|
+
try {
|
|
244
|
+
const decoded = Schema.decodeUnknownSync(targetSchema)(partialResult)
|
|
245
|
+
return encodeTarget(decoded)
|
|
246
|
+
} catch {
|
|
247
|
+
// Even filtered fields don't match schema
|
|
248
|
+
console.warn('Client document: Partial fields incompatible, returning empty partial')
|
|
249
|
+
return encodeTarget({})
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return encodeTarget({})
|
|
253
|
+
} else {
|
|
254
|
+
// Full set: merge old data with new defaults
|
|
255
|
+
const merged: Record<string, unknown> = { ...defaultValue }
|
|
256
|
+
|
|
257
|
+
// Override defaults with valid fields from old event
|
|
258
|
+
for (const [key, value] of Object.entries(eventValue as Record<string, unknown>)) {
|
|
259
|
+
if (key in defaultValue) {
|
|
260
|
+
merged[key] = value
|
|
261
|
+
}
|
|
262
|
+
// Drop fields that don't exist in new schema
|
|
206
263
|
}
|
|
207
|
-
// Drop fields that don't exist in new schema
|
|
208
|
-
}
|
|
209
264
|
|
|
210
|
-
|
|
265
|
+
// Try to decode the merged value
|
|
211
266
|
try {
|
|
212
|
-
|
|
267
|
+
const decoded = Schema.decodeUnknownSync(valueSchema)(merged)
|
|
268
|
+
return encodeTarget(decoded)
|
|
213
269
|
} catch {
|
|
214
|
-
//
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
return {}
|
|
220
|
-
} else {
|
|
221
|
-
// Full set: merge old data with new defaults
|
|
222
|
-
const merged: Record<string, unknown> = { ...defaultValue }
|
|
223
|
-
|
|
224
|
-
// Override defaults with valid fields from old event
|
|
225
|
-
for (const [key, value] of Object.entries(eventValue as Record<string, unknown>)) {
|
|
226
|
-
if (key in defaultValue) {
|
|
227
|
-
merged[key] = value
|
|
270
|
+
// Merged value still doesn't match (e.g., type changes)
|
|
271
|
+
// Fall back to pure defaults
|
|
272
|
+
console.warn('Client document: Could not preserve event data, using defaults')
|
|
273
|
+
return encodeTarget(defaultValue)
|
|
228
274
|
}
|
|
229
|
-
// Drop fields that don't exist in new schema
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Try to decode the merged value
|
|
233
|
-
try {
|
|
234
|
-
return Schema.decodeUnknownSync(valueSchema)(merged)
|
|
235
|
-
} catch {
|
|
236
|
-
// Merged value still doesn't match (e.g., type changes)
|
|
237
|
-
// Fall back to pure defaults
|
|
238
|
-
console.warn('Client document: Could not preserve event data, using defaults')
|
|
239
|
-
return defaultValue
|
|
240
275
|
}
|
|
241
276
|
}
|
|
242
|
-
}
|
|
277
|
+
}),
|
|
278
|
+
encode: SchemaGetter.passthroughSubtype(),
|
|
243
279
|
},
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
)
|
|
280
|
+
),
|
|
281
|
+
) as Schema.Codec<any, unknown>
|
|
247
282
|
}
|
|
248
283
|
|
|
249
284
|
export const deriveEventAndMaterializer = ({
|
|
@@ -253,16 +288,16 @@ export const deriveEventAndMaterializer = ({
|
|
|
253
288
|
partialSet,
|
|
254
289
|
}: {
|
|
255
290
|
name: string
|
|
256
|
-
valueSchema: Schema.
|
|
291
|
+
valueSchema: Schema.Codec<any, any>
|
|
257
292
|
defaultValue: any
|
|
258
293
|
partialSet: boolean
|
|
259
294
|
}) => {
|
|
260
295
|
const derivedSetEventDef = defineEvent({
|
|
261
296
|
name: `${name}Set`,
|
|
262
297
|
schema: Schema.Struct({
|
|
263
|
-
id: Schema.Union(Schema.String, Schema.
|
|
298
|
+
id: Schema.Union([Schema.String, Schema.UniqueSymbol(SessionIdSymbol)]),
|
|
264
299
|
value: createOptimisticEventSchema({ valueSchema, defaultValue, partialSet }),
|
|
265
|
-
}).
|
|
300
|
+
}).annotate({ title: `${name}Set:Args` }),
|
|
266
301
|
clientOnly: true,
|
|
267
302
|
derived: true,
|
|
268
303
|
})
|
|
@@ -275,7 +310,7 @@ export const deriveEventAndMaterializer = ({
|
|
|
275
310
|
// Override the full value if it's not an object or no partial set is allowed
|
|
276
311
|
const schemaProps = Schema.getResolvedPropertySignatures(valueSchema)
|
|
277
312
|
if (schemaProps.length === 0 || partialSet === false) {
|
|
278
|
-
const valueColJsonSchema = Schema.
|
|
313
|
+
const valueColJsonSchema = Schema.fromJsonString(valueSchema) as Schema.Codec<any, string>
|
|
279
314
|
const encodedInsertValue = Schema.encodeSyncDebug(valueColJsonSchema)(value ?? defaultValue)
|
|
280
315
|
const encodedUpdateValue = Schema.encodeSyncDebug(valueColJsonSchema)(value)
|
|
281
316
|
|
|
@@ -285,7 +320,7 @@ export const deriveEventAndMaterializer = ({
|
|
|
285
320
|
writeTables: new Set([name]),
|
|
286
321
|
}
|
|
287
322
|
} else {
|
|
288
|
-
const valueColJsonSchema = Schema.
|
|
323
|
+
const valueColJsonSchema = Schema.fromJsonString(partialStructSchema(valueSchema)) as Schema.Codec<any, string>
|
|
289
324
|
|
|
290
325
|
const encodedInsertValue = Schema.encodeSyncDebug(valueColJsonSchema)(mergeDefaultValues(defaultValue, value))
|
|
291
326
|
|
|
@@ -293,7 +328,7 @@ export const deriveEventAndMaterializer = ({
|
|
|
293
328
|
const setBindValues: unknown[] = []
|
|
294
329
|
|
|
295
330
|
const keys = Object.keys(value)
|
|
296
|
-
const partialUpdateSchema = valueSchema
|
|
331
|
+
const partialUpdateSchema = pickStructSchema(valueSchema, keys)
|
|
297
332
|
const encodedPartialUpdate = Schema.encodeSyncDebug(partialUpdateSchema)(value)
|
|
298
333
|
|
|
299
334
|
for (const key in encodedPartialUpdate) {
|
|
@@ -357,11 +392,14 @@ const makeGetQueryBuilder = <TTableDef extends ClientDocumentTableDef<any, any,
|
|
|
357
392
|
return {
|
|
358
393
|
[QueryBuilderTypeId]: QueryBuilderTypeId,
|
|
359
394
|
[QueryBuilderAstSymbol]: ast,
|
|
395
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- phantom type field for generic inference only
|
|
360
396
|
ResultType: 'only-for-type-inference' as any,
|
|
361
397
|
asSql: () => ({ query, bindValues: [id] }),
|
|
362
398
|
toString: () => query.toString(),
|
|
399
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- spreading empty object to satisfy QueryBuilder interface requirements
|
|
363
400
|
...({} as any), // Needed for type cast
|
|
364
401
|
}
|
|
402
|
+
// oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- makeGetQueryBuilder return type uses complex conditional generics
|
|
365
403
|
}) as any
|
|
366
404
|
}
|
|
367
405
|
|
|
@@ -502,7 +540,7 @@ export namespace ClientDocumentTableDef {
|
|
|
502
540
|
*/
|
|
503
541
|
readonly set: SetEventDefLike<TName, TType, TOptions>
|
|
504
542
|
readonly Value: TType
|
|
505
|
-
readonly valueSchema: Schema.
|
|
543
|
+
readonly valueSchema: Schema.Codec<TType, TEncoded>
|
|
506
544
|
readonly default: TOptions['default']
|
|
507
545
|
readonly [ClientDocumentTableDefSymbol]: {
|
|
508
546
|
readonly options: TOptions
|
|
@@ -513,27 +551,17 @@ export namespace ClientDocumentTableDef {
|
|
|
513
551
|
}
|
|
514
552
|
}
|
|
515
553
|
|
|
516
|
-
export type GetOptions<TTableDef extends TraitAny> =
|
|
517
|
-
any,
|
|
518
|
-
any,
|
|
519
|
-
any,
|
|
520
|
-
infer TOptions
|
|
521
|
-
>
|
|
522
|
-
? TOptions
|
|
523
|
-
: never
|
|
554
|
+
export type GetOptions<TTableDef extends TraitAny> =
|
|
555
|
+
TTableDef extends ClientDocumentTableDef.Trait<any, any, any, infer TOptions> ? TOptions : never
|
|
524
556
|
|
|
525
557
|
export type TraitAny = Trait<any, any, any, any>
|
|
526
558
|
|
|
527
|
-
export type DefaultIdType<TTableDef extends TraitAny> =
|
|
528
|
-
any,
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
>
|
|
533
|
-
? TOptions['default']['id'] extends SessionIdSymbol | string
|
|
534
|
-
? TOptions['default']['id']
|
|
559
|
+
export type DefaultIdType<TTableDef extends TraitAny> =
|
|
560
|
+
TTableDef extends ClientDocumentTableDef.Trait<any, any, any, infer TOptions>
|
|
561
|
+
? TOptions['default']['id'] extends SessionIdSymbol | string
|
|
562
|
+
? TOptions['default']['id']
|
|
563
|
+
: never
|
|
535
564
|
: never
|
|
536
|
-
: never
|
|
537
565
|
|
|
538
566
|
export type SetEventDefLike<
|
|
539
567
|
TName extends string,
|
|
@@ -549,12 +577,12 @@ export namespace ClientDocumentTableDef {
|
|
|
549
577
|
id?: string | SessionIdSymbol,
|
|
550
578
|
) => { name: `${TName}Set`; args: { id: string; value: TType } }) & {
|
|
551
579
|
readonly name: `${TName}Set`
|
|
552
|
-
readonly schema: Schema.
|
|
580
|
+
readonly schema: Schema.Codec<any, any>
|
|
553
581
|
readonly Event: {
|
|
554
582
|
readonly name: `${TName}Set`
|
|
555
583
|
readonly args: { id: string; value: TType }
|
|
556
584
|
}
|
|
557
|
-
readonly options: { derived: true; clientOnly: true; facts: undefined }
|
|
585
|
+
readonly options: { derived: true; clientOnly: true; facts: undefined; deprecated: undefined }
|
|
558
586
|
}
|
|
559
587
|
|
|
560
588
|
export type SetEventDef<TName extends string, TType, TOptions extends ClientDocumentTableOptions<TType>> = EventDef<
|
|
@@ -579,5 +607,5 @@ export namespace ClientDocumentTableDef {
|
|
|
579
607
|
) => QueryBuilder<TType, ClientDocumentTableDef.TableDefBase_<TName, TType>, QueryBuilder.ApiFeature>
|
|
580
608
|
}
|
|
581
609
|
|
|
582
|
-
export const ClientDocumentTableDefSymbol = Symbol('ClientDocumentTableDef')
|
|
610
|
+
export const ClientDocumentTableDefSymbol = Symbol.for('livestore.ClientDocumentTableDef')
|
|
583
611
|
export type ClientDocumentTableDefSymbol = typeof ClientDocumentTableDefSymbol
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Schema, SchemaAST } from '@livestore/utils/effect'
|
|
2
1
|
import { describe, expect, test } from 'vitest'
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { Schema, SchemaAST, SchemaTransformation } from '@livestore/utils/effect'
|
|
4
|
+
|
|
5
|
+
import { ColumnType, PrimaryKeyId, withColumnType, withPrimaryKey } from './column-annotations.ts'
|
|
5
6
|
|
|
6
7
|
describe.concurrent('annotations', () => {
|
|
7
8
|
describe('withPrimaryKey', () => {
|
|
@@ -9,16 +10,8 @@ describe.concurrent('annotations', () => {
|
|
|
9
10
|
const schema = Schema.String
|
|
10
11
|
const result = withPrimaryKey(schema)
|
|
11
12
|
|
|
12
|
-
expect(SchemaAST.
|
|
13
|
-
|
|
14
|
-
"_tag": "StringKeyword",
|
|
15
|
-
"annotations": {
|
|
16
|
-
"Symbol(effect/annotation/Description)": "a string",
|
|
17
|
-
"Symbol(effect/annotation/Title)": "string",
|
|
18
|
-
"Symbol(livestore/state/sqlite/annotations/primary-key)": true,
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
`)
|
|
13
|
+
expect(SchemaAST.isString(result.ast)).toBe(true)
|
|
14
|
+
expect(Schema.resolveAnnotations(result)?.[PrimaryKeyId]).toBe(true)
|
|
22
15
|
})
|
|
23
16
|
})
|
|
24
17
|
|
|
@@ -29,19 +22,19 @@ describe.concurrent('annotations', () => {
|
|
|
29
22
|
})
|
|
30
23
|
|
|
31
24
|
test('Schema.Number with integer column type', () => {
|
|
32
|
-
expect(() => withColumnType(Schema.
|
|
25
|
+
expect(() => withColumnType(Schema.Finite, 'integer')).not.toThrow()
|
|
33
26
|
})
|
|
34
27
|
|
|
35
28
|
test('Schema.Number with real column type', () => {
|
|
36
|
-
expect(() => withColumnType(Schema.
|
|
29
|
+
expect(() => withColumnType(Schema.Finite, 'real')).not.toThrow()
|
|
37
30
|
})
|
|
38
31
|
|
|
39
32
|
test('Schema.Boolean with integer column type', () => {
|
|
40
33
|
expect(() => withColumnType(Schema.Boolean, 'integer')).not.toThrow()
|
|
41
34
|
})
|
|
42
35
|
|
|
43
|
-
test('Schema.
|
|
44
|
-
expect(() => withColumnType(Schema.
|
|
36
|
+
test('Schema.Uint8Array with blob column type', () => {
|
|
37
|
+
expect(() => withColumnType(Schema.Uint8Array, 'blob')).not.toThrow()
|
|
45
38
|
})
|
|
46
39
|
|
|
47
40
|
test('Schema.Date with text column type', () => {
|
|
@@ -65,15 +58,20 @@ describe.concurrent('annotations', () => {
|
|
|
65
58
|
})
|
|
66
59
|
|
|
67
60
|
test('Union of same type with compatible column type', () => {
|
|
68
|
-
const unionSchema = Schema.
|
|
61
|
+
const unionSchema = Schema.Literals(['a', 'b'])
|
|
69
62
|
expect(() => withColumnType(unionSchema, 'text')).not.toThrow()
|
|
70
63
|
})
|
|
71
64
|
|
|
72
65
|
test('Transformation schema with compatible base type', () => {
|
|
73
|
-
const transformSchema = Schema.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
const transformSchema = Schema.String.pipe(
|
|
67
|
+
Schema.decodeTo(
|
|
68
|
+
Schema.String,
|
|
69
|
+
SchemaTransformation.transform({
|
|
70
|
+
decode: (s) => s.toUpperCase(),
|
|
71
|
+
encode: (s) => s.toLowerCase(),
|
|
72
|
+
}),
|
|
73
|
+
),
|
|
74
|
+
)
|
|
77
75
|
expect(() => withColumnType(transformSchema, 'text')).not.toThrow()
|
|
78
76
|
})
|
|
79
77
|
})
|
|
@@ -128,8 +126,8 @@ describe.concurrent('annotations', () => {
|
|
|
128
126
|
// )
|
|
129
127
|
// })
|
|
130
128
|
|
|
131
|
-
// test('Schema.
|
|
132
|
-
// expect(() => withColumnType(Schema.
|
|
129
|
+
// test('Schema.Uint8Array with text column type should throw', () => {
|
|
130
|
+
// expect(() => withColumnType(Schema.Uint8Array, 'text')).toThrow(
|
|
133
131
|
// "Schema type 'uint8array' is incompatible with column type 'text'",
|
|
134
132
|
// )
|
|
135
133
|
// })
|
|
@@ -155,7 +153,7 @@ describe.concurrent('annotations', () => {
|
|
|
155
153
|
|
|
156
154
|
describe('complex schemas', () => {
|
|
157
155
|
test('should allow complex schemas that cannot be determined', () => {
|
|
158
|
-
const complexSchema = Schema.Struct({ name: Schema.String, age: Schema.
|
|
156
|
+
const complexSchema = Schema.Struct({ name: Schema.String, age: Schema.Finite })
|
|
159
157
|
expect(() => withColumnType(complexSchema, 'text')).not.toThrow()
|
|
160
158
|
})
|
|
161
159
|
|
|
@@ -179,33 +177,17 @@ describe.concurrent('annotations', () => {
|
|
|
179
177
|
const schema = Schema.String
|
|
180
178
|
const result = withColumnType(schema, 'text')
|
|
181
179
|
|
|
182
|
-
expect(SchemaAST.
|
|
183
|
-
|
|
184
|
-
"_tag": "StringKeyword",
|
|
185
|
-
"annotations": {
|
|
186
|
-
"Symbol(effect/annotation/Description)": "a string",
|
|
187
|
-
"Symbol(effect/annotation/Title)": "string",
|
|
188
|
-
"Symbol(livestore/state/sqlite/annotations/column-type)": "text",
|
|
189
|
-
},
|
|
190
|
-
}
|
|
191
|
-
`)
|
|
180
|
+
expect(SchemaAST.isString(result.ast)).toBe(true)
|
|
181
|
+
expect(Schema.resolveAnnotations(result)?.[ColumnType]).toBe('text')
|
|
192
182
|
})
|
|
193
183
|
|
|
194
184
|
test('should preserve existing annotations', () => {
|
|
195
185
|
const schema = withPrimaryKey(Schema.String)
|
|
196
186
|
const result = withColumnType(schema, 'text')
|
|
197
187
|
|
|
198
|
-
expect(SchemaAST.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
"annotations": {
|
|
202
|
-
"Symbol(effect/annotation/Description)": "a string",
|
|
203
|
-
"Symbol(effect/annotation/Title)": "string",
|
|
204
|
-
"Symbol(livestore/state/sqlite/annotations/column-type)": "text",
|
|
205
|
-
"Symbol(livestore/state/sqlite/annotations/primary-key)": true,
|
|
206
|
-
},
|
|
207
|
-
}
|
|
208
|
-
`)
|
|
188
|
+
expect(SchemaAST.isString(result.ast)).toBe(true)
|
|
189
|
+
expect(Schema.resolveAnnotations(result)?.[ColumnType]).toBe('text')
|
|
190
|
+
expect(Schema.resolveAnnotations(result)?.[PrimaryKeyId]).toBe(true)
|
|
209
191
|
})
|
|
210
192
|
})
|
|
211
193
|
})
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import { type Schema, Function, SchemaAST } from '@livestore/utils/effect'
|
|
2
|
+
|
|
3
3
|
import type { SqliteDsl } from './db-schema/mod.ts'
|
|
4
4
|
|
|
5
|
-
export const PrimaryKeyId =
|
|
5
|
+
export const PrimaryKeyId = 'livestore/state/sqlite/annotations/primary-key'
|
|
6
6
|
|
|
7
|
-
export const ColumnType =
|
|
7
|
+
export const ColumnType = 'livestore/state/sqlite/annotations/column-type'
|
|
8
8
|
|
|
9
|
-
export const Default =
|
|
9
|
+
export const Default = 'livestore/state/sqlite/annotations/default'
|
|
10
10
|
|
|
11
|
-
export const AutoIncrement =
|
|
11
|
+
export const AutoIncrement = 'livestore/state/sqlite/annotations/auto-increment'
|
|
12
12
|
|
|
13
|
-
export const Unique =
|
|
13
|
+
export const Unique = 'livestore/state/sqlite/annotations/unique'
|
|
14
14
|
|
|
15
|
-
// export const Check =
|
|
15
|
+
// export const Check = 'livestore/state/sqlite/annotations/check'
|
|
16
16
|
|
|
17
17
|
/*
|
|
18
18
|
Here are the knobs you can turn per-column when you CREATE TABLE (or ALTER TABLE … ADD COLUMN) in SQLite:
|
|
@@ -25,23 +25,22 @@ Here are the knobs you can turn per-column when you CREATE TABLE (or ALTER TABLE
|
|
|
25
25
|
• COLLATE <name> – per-column collation sequence for text comparison. 
|
|
26
26
|
• REFERENCES tbl(col) [ON UPDATE/DELETE …] – column-local foreign key with its own cascade / restrict / set-null rules. 
|
|
27
27
|
• GENERATED ALWAYS AS (<expr>) [VIRTUAL | STORED] – computed columns (since 3.31). 
|
|
28
|
-
• CONSTRAINT name … – optional label in front of any of the above so you can refer to it in error messages or when dropping/recreating schemas.
|
|
28
|
+
• CONSTRAINT name … – optional label in front of any of the above so you can refer to it in error messages or when dropping/recreating schemas.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Adds a primary key annotation to a schema.
|
|
33
33
|
*/
|
|
34
|
-
export const withPrimaryKey = <T extends Schema.
|
|
35
|
-
applyAnnotations(schema, { [PrimaryKeyId]: true })
|
|
34
|
+
export const withPrimaryKey = <T extends Schema.Top>(schema: T) => applyAnnotations(schema, { [PrimaryKeyId]: true })
|
|
36
35
|
|
|
37
36
|
/**
|
|
38
37
|
* Adds a column type annotation to a schema.
|
|
39
38
|
*/
|
|
40
39
|
export const withColumnType: {
|
|
41
|
-
(type: SqliteDsl.FieldColumnType): <T extends Schema.
|
|
40
|
+
(type: SqliteDsl.FieldColumnType): <T extends Schema.Top>(schema: T) => T
|
|
42
41
|
// TODO make type safe
|
|
43
|
-
<T extends Schema.
|
|
44
|
-
} = dual(2, <T extends Schema.
|
|
42
|
+
<T extends Schema.Top>(schema: T, type: SqliteDsl.FieldColumnType): T
|
|
43
|
+
} = Function.dual(2, <T extends Schema.Top>(schema: T, type: SqliteDsl.FieldColumnType) => {
|
|
45
44
|
validateSchemaColumnTypeCompatibility(schema, type)
|
|
46
45
|
return applyAnnotations(schema, { [ColumnType]: type })
|
|
47
46
|
})
|
|
@@ -49,39 +48,37 @@ export const withColumnType: {
|
|
|
49
48
|
/**
|
|
50
49
|
* Adds an auto-increment annotation to a schema.
|
|
51
50
|
*/
|
|
52
|
-
export const withAutoIncrement = <T extends Schema.
|
|
51
|
+
export const withAutoIncrement = <T extends Schema.Top>(schema: T) =>
|
|
53
52
|
applyAnnotations(schema, { [AutoIncrement]: true })
|
|
54
53
|
|
|
55
54
|
/**
|
|
56
55
|
* Adds a unique constraint annotation to a schema.
|
|
57
56
|
*/
|
|
58
|
-
export const withUnique = <T extends Schema.
|
|
57
|
+
export const withUnique = <T extends Schema.Top>(schema: T) => applyAnnotations(schema, { [Unique]: true })
|
|
59
58
|
|
|
60
59
|
/**
|
|
61
60
|
* Adds a default value annotation to a schema.
|
|
62
61
|
*/
|
|
63
62
|
export const withDefault: {
|
|
64
63
|
// TODO make type safe
|
|
65
|
-
<T extends Schema.
|
|
66
|
-
(value: unknown): <T extends Schema.
|
|
67
|
-
} = dual(2, <T extends Schema.
|
|
64
|
+
<T extends Schema.Top>(schema: T, value: unknown): T
|
|
65
|
+
(value: unknown): <T extends Schema.Top>(schema: T) => T
|
|
66
|
+
} = Function.dual(2, <T extends Schema.Top>(schema: T, value: unknown) =>
|
|
67
|
+
applyAnnotations(schema, { [Default]: value }),
|
|
68
|
+
)
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
71
|
* Validates that a schema is compatible with the specified SQLite column type
|
|
71
72
|
*/
|
|
72
|
-
const validateSchemaColumnTypeCompatibility = (
|
|
73
|
-
_schema: Schema.Schema.All,
|
|
74
|
-
_columnType: SqliteDsl.FieldColumnType,
|
|
75
|
-
): void => {
|
|
73
|
+
const validateSchemaColumnTypeCompatibility = (_schema: Schema.Top, _columnType: SqliteDsl.FieldColumnType): void => {
|
|
76
74
|
// TODO actually implement this
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
const applyAnnotations = <T extends Schema.
|
|
80
|
-
const identifier = SchemaAST.
|
|
81
|
-
const shouldPreserveIdentifier =
|
|
82
|
-
const annotations: Record<
|
|
83
|
-
? { ...overrides,
|
|
84
|
-
: overrides
|
|
77
|
+
const applyAnnotations = <T extends Schema.Top>(schema: T, overrides: Record<string, unknown>): T => {
|
|
78
|
+
const identifier = SchemaAST.resolveIdentifier(schema.ast)
|
|
79
|
+
const shouldPreserveIdentifier = identifier !== undefined && !('identifier' in overrides)
|
|
80
|
+
const annotations: Record<string, unknown> =
|
|
81
|
+
shouldPreserveIdentifier === true ? { ...overrides, identifier } : overrides
|
|
85
82
|
|
|
86
|
-
return schema.
|
|
83
|
+
return schema.annotate(annotations) as T
|
|
87
84
|
}
|