@livestore/common 0.4.0 → 0.5.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/ClientSessionLeaderThreadProxy.d.ts +1 -1
- package/dist/ClientSessionLeaderThreadProxy.d.ts.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 +3 -3
- package/dist/WorkerTransportError.d.ts.map +1 -1
- package/dist/WorkerTransportError.js +3 -3
- package/dist/WorkerTransportError.js.map +1 -1
- 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 +29 -57
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +20 -37
- package/dist/adapter-types.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 +28 -41
- 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.js +1 -0
- package/dist/devtools/devtools-compatibility.test.js.map +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +520 -332
- package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-client-session.js +76 -74
- package/dist/devtools/devtools-messages-client-session.js.map +1 -1
- package/dist/devtools/devtools-messages-common.d.ts +27 -27
- package/dist/devtools/devtools-messages-common.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-common.js +5 -5
- package/dist/devtools/devtools-messages-common.js.map +1 -1
- package/dist/devtools/devtools-messages-leader.d.ts +405 -343
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-leader.js +101 -89
- package/dist/devtools/devtools-messages-leader.js.map +1 -1
- package/dist/devtools/devtools-sessioninfo.d.ts +18 -19
- package/dist/devtools/devtools-sessioninfo.d.ts.map +1 -1
- package/dist/devtools/devtools-sessioninfo.js +8 -5
- package/dist/devtools/devtools-sessioninfo.js.map +1 -1
- package/dist/devtools/mod.d.ts +4 -5
- package/dist/devtools/mod.d.ts.map +1 -1
- package/dist/devtools/mod.js +9 -5
- package/dist/devtools/mod.js.map +1 -1
- package/dist/errors.d.ts +45 -69
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +18 -16
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +66 -18
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +519 -461
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/RejectedPushError.d.ts +67 -36
- package/dist/leader-thread/RejectedPushError.d.ts.map +1 -1
- package/dist/leader-thread/RejectedPushError.js +24 -5
- package/dist/leader-thread/RejectedPushError.js.map +1 -1
- 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 +9 -8
- package/dist/leader-thread/connection.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts +4 -4
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +6 -6
- package/dist/leader-thread/eventlog.js.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +33 -17
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +9 -5
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +25 -35
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.test.js +7 -7
- package/dist/leader-thread/make-leader-thread-layer.test.js.map +1 -1
- package/dist/leader-thread/materialize-event.d.ts +2 -1
- package/dist/leader-thread/materialize-event.d.ts.map +1 -1
- package/dist/leader-thread/materialize-event.js +4 -0
- package/dist/leader-thread/materialize-event.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +18 -39
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/shutdown-channel.d.ts +2 -6
- 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 +4 -7
- package/dist/leader-thread/stream-events.d.ts.map +1 -1
- package/dist/leader-thread/stream-events.js +13 -16
- package/dist/leader-thread/stream-events.js.map +1 -1
- package/dist/leader-thread/types.d.ts +32 -69
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/leader-thread/types.js +5 -5
- package/dist/leader-thread/types.js.map +1 -1
- package/dist/logging.d.ts +5 -30
- package/dist/logging.d.ts.map +1 -1
- package/dist/logging.js +1 -32
- package/dist/logging.js.map +1 -1
- package/dist/make-client-session.d.ts +1 -2
- package/dist/make-client-session.d.ts.map +1 -1
- package/dist/make-client-session.js +3 -3
- package/dist/make-client-session.js.map +1 -1
- package/dist/materializer-helper.d.ts +0 -1
- package/dist/materializer-helper.d.ts.map +1 -1
- package/dist/materializer-helper.js +7 -35
- package/dist/materializer-helper.js.map +1 -1
- package/dist/otel.d.ts +2 -3
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +2 -7
- package/dist/otel.js.map +1 -1
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
- package/dist/rematerialize-from-eventlog.js +28 -26
- package/dist/rematerialize-from-eventlog.js.map +1 -1
- package/dist/schema/EventDef/define.d.ts +4 -4
- package/dist/schema/EventDef/define.d.ts.map +1 -1
- package/dist/schema/EventDef/define.js +5 -5
- package/dist/schema/EventDef/define.js.map +1 -1
- 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 +8 -13
- package/dist/schema/EventDef/deprecated.d.ts.map +1 -1
- package/dist/schema/EventDef/deprecated.js +12 -13
- package/dist/schema/EventDef/deprecated.js.map +1 -1
- package/dist/schema/EventDef/deprecated.test.js +1 -1
- package/dist/schema/EventDef/deprecated.test.js.map +1 -1
- package/dist/schema/EventDef/event-def.d.ts +1 -1
- package/dist/schema/EventDef/event-def.d.ts.map +1 -1
- package/dist/schema/EventSequenceNumber/client.d.ts +12 -12
- package/dist/schema/EventSequenceNumber/client.d.ts.map +1 -1
- package/dist/schema/EventSequenceNumber/client.js +8 -9
- package/dist/schema/EventSequenceNumber/client.js.map +1 -1
- package/dist/schema/EventSequenceNumber/global.d.ts +2 -2
- package/dist/schema/EventSequenceNumber/global.d.ts.map +1 -1
- package/dist/schema/EventSequenceNumber/global.js +1 -1
- package/dist/schema/EventSequenceNumber/global.js.map +1 -1
- package/dist/schema/EventSequenceNumber.test.js +5 -5
- package/dist/schema/EventSequenceNumber.test.js.map +1 -1
- package/dist/schema/LiveStoreEvent/client.d.ts +50 -179
- package/dist/schema/LiveStoreEvent/client.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent/client.js +32 -29
- package/dist/schema/LiveStoreEvent/client.js.map +1 -1
- package/dist/schema/LiveStoreEvent/client.test.js +11 -2
- package/dist/schema/LiveStoreEvent/client.test.js.map +1 -1
- package/dist/schema/LiveStoreEvent/for-event-def.d.ts +7 -7
- package/dist/schema/LiveStoreEvent/for-event-def.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent/global.d.ts +6 -6
- package/dist/schema/LiveStoreEvent/global.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent/global.js +1 -1
- package/dist/schema/LiveStoreEvent/global.js.map +1 -1
- package/dist/schema/LiveStoreEvent/input.d.ts +5 -5
- package/dist/schema/LiveStoreEvent/input.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent/input.js +3 -3
- package/dist/schema/LiveStoreEvent/input.js.map +1 -1
- package/dist/schema/mod.d.ts +1 -0
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +1 -0
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +3 -2
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.d.ts +12 -17
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +23 -20
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.test.js +29 -8
- 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 +57 -31
- package/dist/schema/state/sqlite/column-def.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.test.js +118 -72
- package/dist/schema/state/sqlite/column-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-spec.js.map +1 -1
- package/dist/schema/state/sqlite/column-spec.test.js +2 -2
- 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 +13 -4
- 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 +9 -9
- 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 +8 -13
- 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 +27 -16
- 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 +13 -11
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js +5 -3
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -1
- package/dist/schema/state/sqlite/mod.d.ts +1 -3
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.js +1 -1
- 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 +7 -7
- 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 +27 -23
- package/dist/schema/state/sqlite/query-builder/astToSql.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts +3 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.js +16 -14
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +362 -596
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
- package/dist/schema/state/sqlite/schema-helpers.js +1 -1
- package/dist/schema/state/sqlite/schema-helpers.js.map +1 -1
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.d.ts +102 -134
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.d.ts.map +1 -1
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.js +2 -2
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.js.map +1 -1
- package/dist/schema/state/sqlite/system-tables/state-tables.d.ts +328 -106
- package/dist/schema/state/sqlite/system-tables/state-tables.d.ts.map +1 -1
- package/dist/schema/state/sqlite/system-tables/state-tables.js +33 -1
- package/dist/schema/state/sqlite/system-tables/state-tables.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.d.ts +16 -19
- package/dist/schema/state/sqlite/table-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/table-def.js +53 -3
- package/dist/schema/state/sqlite/table-def.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.test.js +153 -36
- package/dist/schema/state/sqlite/table-def.test.js.map +1 -1
- package/dist/schema/unknown-events.d.ts.map +1 -1
- package/dist/schema/unknown-events.js +2 -1
- package/dist/schema/unknown-events.js.map +1 -1
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js +2 -2
- 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 +8 -10
- package/dist/sql-queries/sql-queries.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 +37 -2
- package/dist/sqlite-db-helper.js.map +1 -1
- package/dist/sqlite-types.d.ts +3 -6
- 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 +38 -16
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +196 -66
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/errors.d.ts +12 -18
- package/dist/sync/errors.d.ts.map +1 -1
- package/dist/sync/errors.js +2 -2
- package/dist/sync/errors.js.map +1 -1
- package/dist/sync/mock-sync-backend.d.ts +2 -3
- package/dist/sync/mock-sync-backend.d.ts.map +1 -1
- package/dist/sync/mock-sync-backend.js +54 -33
- 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/history-dag-common.d.ts +4 -0
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +52 -31
- 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 +2 -1
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/next/test/compact-events.calculator.test.js +2 -2
- package/dist/sync/next/test/event-fixtures.d.ts +7 -7
- package/dist/sync/next/test/event-fixtures.js +1 -1
- 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.map +1 -1
- package/dist/sync/sync-backend-kv.js +4 -2
- package/dist/sync/sync-backend-kv.js.map +1 -1
- package/dist/sync/sync-backend.d.ts +15 -15
- package/dist/sync/sync-backend.d.ts.map +1 -1
- package/dist/sync/sync-backend.js +9 -5
- package/dist/sync/sync-backend.js.map +1 -1
- package/dist/sync/sync.d.ts +1 -1
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/syncstate.d.ts +97 -173
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +34 -37
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +100 -61
- package/dist/sync/syncstate.test.js.map +1 -1
- package/dist/sync/transport-chunking.d.ts +15 -16
- package/dist/sync/transport-chunking.d.ts.map +1 -1
- package/dist/sync/transport-chunking.js +23 -32
- package/dist/sync/transport-chunking.js.map +1 -1
- package/dist/util.d.ts +11 -4
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +19 -2
- package/dist/util.js.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +19 -37
- package/src/ClientSessionLeaderThreadProxy.ts +1 -1
- package/src/MaterializationJournal.ts +184 -0
- package/src/StateHead.ts +80 -0
- package/src/WorkerTransportError.ts +4 -4
- package/src/__tests__/fixture.ts +3 -3
- package/src/adapter-types.ts +24 -61
- package/src/debug-info.ts +50 -70
- package/src/defs.ts +2 -2
- package/src/devtools/devtools-compatibility.test.ts +1 -0
- package/src/devtools/devtools-messages-client-session.ts +56 -65
- package/src/devtools/devtools-messages-common.ts +12 -11
- package/src/devtools/devtools-messages-leader.ts +71 -69
- package/src/devtools/devtools-sessioninfo.ts +13 -11
- package/src/devtools/mod.ts +4 -5
- package/src/errors.ts +46 -34
- package/src/index.ts +8 -1
- package/src/leader-thread/LeaderSyncProcessor.ts +794 -691
- package/src/leader-thread/RejectedPushError.ts +40 -27
- package/src/leader-thread/connection.ts +12 -8
- package/src/leader-thread/eventlog.ts +7 -7
- package/src/leader-thread/leader-worker-devtools.ts +37 -19
- package/src/leader-thread/make-leader-thread-layer.test.ts +7 -7
- package/src/leader-thread/make-leader-thread-layer.ts +56 -53
- package/src/leader-thread/materialize-event.ts +13 -8
- package/src/leader-thread/recreate-db.ts +24 -59
- package/src/leader-thread/shutdown-channel.ts +3 -14
- package/src/leader-thread/stream-events.ts +104 -101
- package/src/leader-thread/types.ts +24 -62
- package/src/logging.ts +5 -52
- package/src/make-client-session.ts +6 -6
- package/src/materializer-helper.ts +8 -37
- package/src/otel.ts +5 -14
- package/src/rematerialize-from-eventlog.ts +97 -94
- package/src/schema/EventDef/define.test.ts +28 -0
- package/src/schema/EventDef/define.ts +20 -19
- package/src/schema/EventDef/deprecated.test.ts +1 -8
- package/src/schema/EventDef/deprecated.ts +17 -20
- package/src/schema/EventDef/event-def.ts +2 -4
- package/src/schema/EventSequenceNumber/client.ts +8 -9
- package/src/schema/EventSequenceNumber/global.ts +1 -1
- package/src/schema/EventSequenceNumber.test.ts +5 -5
- package/src/schema/LiveStoreEvent/client.test.ts +17 -4
- package/src/schema/LiveStoreEvent/client.ts +36 -35
- package/src/schema/LiveStoreEvent/for-event-def.ts +7 -7
- package/src/schema/LiveStoreEvent/global.ts +1 -1
- package/src/schema/LiveStoreEvent/input.ts +6 -6
- package/src/schema/mod.ts +1 -0
- package/src/schema/schema.ts +3 -2
- package/src/schema/state/sqlite/client-document-def.test.ts +32 -13
- package/src/schema/state/sqlite/client-document-def.ts +95 -80
- package/src/schema/state/sqlite/column-annotations.test.ts +26 -45
- package/src/schema/state/sqlite/column-annotations.ts +26 -30
- package/src/schema/state/sqlite/column-def.test.ts +132 -77
- package/src/schema/state/sqlite/column-def.ts +72 -37
- package/src/schema/state/sqlite/column-spec.test.ts +2 -2
- package/src/schema/state/sqlite/column-spec.ts +3 -2
- package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +15 -5
- 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 +35 -16
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.ts +25 -31
- package/src/schema/state/sqlite/db-schema/dsl/mod.ts +35 -21
- package/src/schema/state/sqlite/mod.ts +2 -4
- package/src/schema/state/sqlite/persistence.ts +11 -0
- package/src/schema/state/sqlite/query-builder/api.ts +9 -9
- package/src/schema/state/sqlite/query-builder/astToSql.ts +31 -26
- package/src/schema/state/sqlite/query-builder/impl.test.ts +433 -669
- package/src/schema/state/sqlite/query-builder/impl.ts +19 -15
- package/src/schema/state/sqlite/schema-helpers.ts +1 -1
- package/src/schema/state/sqlite/system-tables/eventlog-tables.ts +2 -2
- package/src/schema/state/sqlite/system-tables/state-tables.ts +41 -1
- package/src/schema/state/sqlite/table-def.test.ts +204 -66
- package/src/schema/state/sqlite/table-def.ts +96 -45
- package/src/schema/unknown-events.ts +3 -2
- package/src/schema-management/__tests__/migrations-autoincrement-quoting.test.ts +2 -2
- package/src/session-id-symbol.ts +59 -0
- package/src/sql-queries/sql-queries.ts +8 -12
- package/src/sql-queries/types.ts +6 -7
- package/src/sqlite-db-helper.ts +64 -2
- package/src/sqlite-types.ts +5 -8
- package/src/sync/ClientSessionSyncProcessor.ts +303 -119
- package/src/sync/errors.ts +14 -12
- package/src/sync/mock-sync-backend.test.ts +78 -0
- package/src/sync/mock-sync-backend.ts +93 -47
- package/src/sync/next/history-dag-common.ts +60 -34
- package/src/sync/next/history-dag.ts +4 -1
- package/src/sync/next/test/compact-events.calculator.test.ts +2 -2
- package/src/sync/next/test/event-fixtures.ts +1 -1
- package/src/sync/next/test/history-dag-common.test.ts +87 -0
- package/src/sync/sync-backend-kv.ts +4 -2
- package/src/sync/sync-backend.ts +15 -15
- package/src/sync/sync.ts +1 -1
- package/src/sync/syncstate.test.ts +191 -140
- package/src/sync/syncstate.ts +63 -53
- package/src/sync/transport-chunking.ts +34 -39
- package/src/util.ts +18 -9
- package/src/version.ts +1 -2
- 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/src/sql-queries/misc.ts +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { TestSchema } from 'effect/testing'
|
|
1
2
|
import { assert, describe, expect, it } from 'vitest'
|
|
2
3
|
|
|
3
|
-
import { Schema } from '@livestore/utils/effect'
|
|
4
|
-
import { objectToString } from '@livestore/utils'
|
|
4
|
+
import { Schema, SchemaAST, Struct } from '@livestore/utils/effect'
|
|
5
5
|
|
|
6
6
|
import * as State from '../mod.ts'
|
|
7
7
|
import { withAutoIncrement, withColumnType, withDefault, withPrimaryKey, withUnique } from './column-annotations.ts'
|
|
@@ -14,7 +14,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
it('should map Schema.Number to real column', () => {
|
|
17
|
-
const columnDef = State.SQLite.getColumnDefForSchema(Schema.
|
|
17
|
+
const columnDef = State.SQLite.getColumnDefForSchema(Schema.Finite)
|
|
18
18
|
expect(columnDef.columnType).toBe('real')
|
|
19
19
|
})
|
|
20
20
|
|
|
@@ -26,15 +26,25 @@ describe('getColumnDefForSchema', () => {
|
|
|
26
26
|
it('should map Schema.Date to text column', () => {
|
|
27
27
|
const columnDef = State.SQLite.getColumnDefForSchema(Schema.Date)
|
|
28
28
|
expect(columnDef.columnType).toBe('text')
|
|
29
|
-
expect(Schema.
|
|
30
|
-
expect(
|
|
29
|
+
expect(Schema.toEncoded(columnDef.schema).ast._tag).toBe('String')
|
|
30
|
+
expect(
|
|
31
|
+
SchemaAST.resolveAt<{ readonly id: string }>('representation')(Schema.toType(columnDef.schema).ast)?.id,
|
|
32
|
+
).toBe('effect/schema/Date')
|
|
31
33
|
})
|
|
32
34
|
|
|
33
|
-
it('should map Schema.
|
|
34
|
-
const columnDef = State.SQLite.getColumnDefForSchema(Schema.
|
|
35
|
+
it('should map Schema.DateFromMillis to integer column', () => {
|
|
36
|
+
const columnDef = State.SQLite.getColumnDefForSchema(Schema.DateFromMillis)
|
|
35
37
|
expect(columnDef.columnType).toBe('integer')
|
|
36
|
-
expect(Schema.
|
|
37
|
-
expect(
|
|
38
|
+
expect(Schema.toEncoded(columnDef.schema).ast._tag).toBe('Number')
|
|
39
|
+
expect(
|
|
40
|
+
SchemaAST.resolveAt<{ readonly id: string }>('representation')(Schema.toType(columnDef.schema).ast)?.id,
|
|
41
|
+
).toBe('effect/schema/Date')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('should preserve the Date representation through checks', () => {
|
|
45
|
+
const schema = Schema.DateFromMillis.check(Schema.isGreaterThanDate(new Date(0)))
|
|
46
|
+
|
|
47
|
+
expect(State.SQLite.getColumnDefForSchema(schema).columnType).toBe('integer')
|
|
38
48
|
})
|
|
39
49
|
|
|
40
50
|
it('should map Schema.BigInt to text column', () => {
|
|
@@ -47,17 +57,20 @@ describe('getColumnDefForSchema', () => {
|
|
|
47
57
|
it('should map Schema.Int to integer column', () => {
|
|
48
58
|
const columnDef = State.SQLite.getColumnDefForSchema(Schema.Int)
|
|
49
59
|
expect(columnDef.columnType).toBe('integer')
|
|
60
|
+
|
|
61
|
+
const positiveInt = State.SQLite.getColumnDefForSchema(Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)))
|
|
62
|
+
expect(positiveInt.columnType).toBe('integer')
|
|
50
63
|
})
|
|
51
64
|
|
|
52
65
|
it('should map string refinements to text column', () => {
|
|
53
66
|
const refinements = [
|
|
54
67
|
{ schema: Schema.NonEmptyString, name: 'NonEmptyString' },
|
|
55
68
|
{ schema: Schema.Trim, name: 'Trim' },
|
|
56
|
-
{ schema: Schema.
|
|
57
|
-
{ schema: Schema.
|
|
58
|
-
{ schema: Schema.String.
|
|
69
|
+
{ schema: Schema.String.check(Schema.isUUID()), name: 'UUID' },
|
|
70
|
+
{ schema: Schema.String.check(Schema.isULID()), name: 'ULID' },
|
|
71
|
+
{ schema: Schema.String.check(Schema.isMinLength(5)), name: 'minLength' },
|
|
59
72
|
{
|
|
60
|
-
schema: Schema.String.
|
|
73
|
+
schema: Schema.String.check(Schema.isPattern(/^[A-Z]+$/)),
|
|
61
74
|
name: 'pattern',
|
|
62
75
|
},
|
|
63
76
|
]
|
|
@@ -71,8 +84,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
71
84
|
it('should map number refinements to real column', () => {
|
|
72
85
|
const refinements = [
|
|
73
86
|
{ schema: Schema.Finite, name: 'Finite' },
|
|
74
|
-
{ schema: Schema.
|
|
75
|
-
{ schema: Schema.Number.pipe(Schema.between(0, 100)), name: 'between' },
|
|
87
|
+
{ schema: Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 100 })), name: 'between' },
|
|
76
88
|
]
|
|
77
89
|
|
|
78
90
|
for (const { schema, name } of refinements) {
|
|
@@ -101,12 +113,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
101
113
|
|
|
102
114
|
describe('transformations', () => {
|
|
103
115
|
it('should map transformations based on target type', () => {
|
|
104
|
-
const StringToNumber = Schema.
|
|
105
|
-
Schema.transform(Schema.Number, {
|
|
106
|
-
decode: Number.parseFloat,
|
|
107
|
-
encode: String,
|
|
108
|
-
}),
|
|
109
|
-
)
|
|
116
|
+
const StringToNumber = Schema.FiniteFromString
|
|
110
117
|
|
|
111
118
|
const columnDef = State.SQLite.getColumnDefForSchema(StringToNumber)
|
|
112
119
|
expect(columnDef.columnType).toBe('text') // Based on the encoded type (String)
|
|
@@ -122,7 +129,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
122
129
|
it('should map structs to json column', () => {
|
|
123
130
|
const UserSchema = Schema.Struct({
|
|
124
131
|
name: Schema.String,
|
|
125
|
-
age: Schema.
|
|
132
|
+
age: Schema.Finite,
|
|
126
133
|
})
|
|
127
134
|
|
|
128
135
|
const columnDef = State.SQLite.getColumnDefForSchema(UserSchema)
|
|
@@ -135,22 +142,22 @@ describe('getColumnDefForSchema', () => {
|
|
|
135
142
|
})
|
|
136
143
|
|
|
137
144
|
it('should map records to json column', () => {
|
|
138
|
-
const columnDef = State.SQLite.getColumnDefForSchema(Schema.Record(
|
|
145
|
+
const columnDef = State.SQLite.getColumnDefForSchema(Schema.Record(Schema.String, Schema.Finite))
|
|
139
146
|
expect(columnDef.columnType).toBe('text')
|
|
140
147
|
})
|
|
141
148
|
|
|
142
149
|
it('should map tuples to json column', () => {
|
|
143
|
-
const columnDef = State.SQLite.getColumnDefForSchema(Schema.Tuple(Schema.String, Schema.
|
|
150
|
+
const columnDef = State.SQLite.getColumnDefForSchema(Schema.Tuple([Schema.String, Schema.Finite]))
|
|
144
151
|
expect(columnDef.columnType).toBe('text')
|
|
145
152
|
})
|
|
146
153
|
|
|
147
154
|
it('should map tagged unions to json column', () => {
|
|
148
|
-
const ResultSchema = Schema.Union(
|
|
155
|
+
const ResultSchema = Schema.Union([
|
|
149
156
|
Schema.TaggedStruct('success', {
|
|
150
157
|
value: Schema.String,
|
|
151
158
|
}),
|
|
152
159
|
Schema.TaggedStruct('error', { error: Schema.String }),
|
|
153
|
-
)
|
|
160
|
+
])
|
|
154
161
|
|
|
155
162
|
const columnDef = State.SQLite.getColumnDefForSchema(ResultSchema)
|
|
156
163
|
expect(columnDef.columnType).toBe('text')
|
|
@@ -173,7 +180,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
173
180
|
|
|
174
181
|
it('should handle optional nested schemas', () => {
|
|
175
182
|
const columnDef = State.SQLite.getColumnDefForSchema(
|
|
176
|
-
Schema.Union(Schema.Struct({ name: Schema.String }), Schema.Undefined),
|
|
183
|
+
Schema.Union([Schema.Struct({ name: Schema.String }), Schema.Undefined]),
|
|
177
184
|
)
|
|
178
185
|
expect(columnDef.columnType).toBe('text')
|
|
179
186
|
})
|
|
@@ -198,7 +205,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
198
205
|
|
|
199
206
|
it('should handle never schema', () => {
|
|
200
207
|
// Create a schema that should never validate
|
|
201
|
-
const neverSchema = Schema.String.
|
|
208
|
+
const neverSchema = Schema.String.check(Schema.makeFilter(() => false, { message: 'Always fails' }))
|
|
202
209
|
|
|
203
210
|
const columnDef = State.SQLite.getColumnDefForSchema(neverSchema)
|
|
204
211
|
expect(columnDef.columnType).toBe('text')
|
|
@@ -234,7 +241,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
234
241
|
email: Schema.String,
|
|
235
242
|
})
|
|
236
243
|
|
|
237
|
-
const PickedSchema = UserSchema.
|
|
244
|
+
const PickedSchema = UserSchema.mapFields(Struct.pick(['id', 'name']))
|
|
238
245
|
|
|
239
246
|
const columnDef = State.SQLite.getColumnDefForSchema(PickedSchema)
|
|
240
247
|
expect(columnDef.columnType).toBe('text')
|
|
@@ -247,7 +254,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
247
254
|
password: Schema.String,
|
|
248
255
|
})
|
|
249
256
|
|
|
250
|
-
const PublicUserSchema = UserSchema.
|
|
257
|
+
const PublicUserSchema = UserSchema.mapFields(Struct.omit(['password']))
|
|
251
258
|
|
|
252
259
|
const columnDef = State.SQLite.getColumnDefForSchema(PublicUserSchema)
|
|
253
260
|
expect(columnDef.columnType).toBe('text')
|
|
@@ -256,10 +263,10 @@ describe('getColumnDefForSchema', () => {
|
|
|
256
263
|
|
|
257
264
|
describe('annotations', () => {
|
|
258
265
|
it('should handle schemas with custom annotations', () => {
|
|
259
|
-
const AnnotatedString = Schema.String.
|
|
266
|
+
const AnnotatedString = Schema.String.annotate({
|
|
260
267
|
description: 'A special string',
|
|
261
268
|
})
|
|
262
|
-
const AnnotatedNumber = Schema.
|
|
269
|
+
const AnnotatedNumber = Schema.Finite.annotate({ min: 0, max: 100 })
|
|
263
270
|
|
|
264
271
|
expect(State.SQLite.getColumnDefForSchema(AnnotatedString).columnType).toBe('text')
|
|
265
272
|
expect(State.SQLite.getColumnDefForSchema(AnnotatedNumber).columnType).toBe('real')
|
|
@@ -268,20 +275,20 @@ describe('getColumnDefForSchema', () => {
|
|
|
268
275
|
|
|
269
276
|
describe('enums and literal unions', () => {
|
|
270
277
|
it('should handle enums and literal unions as text', () => {
|
|
271
|
-
const StatusEnum = Schema.
|
|
278
|
+
const StatusEnum = Schema.Enum({
|
|
272
279
|
PENDING: 'pending',
|
|
273
280
|
ACTIVE: 'active',
|
|
274
281
|
INACTIVE: 'inactive',
|
|
275
282
|
})
|
|
276
283
|
|
|
277
|
-
const StatusUnion = Schema.
|
|
284
|
+
const StatusUnion = Schema.Literals(['pending', 'active', 'inactive'])
|
|
278
285
|
|
|
279
286
|
expect(State.SQLite.getColumnDefForSchema(StatusEnum).columnType).toBe('text')
|
|
280
287
|
expect(State.SQLite.getColumnDefForSchema(StatusUnion).columnType).toBe('text')
|
|
281
288
|
})
|
|
282
289
|
|
|
283
290
|
it('should handle unions of numeric literals as integer column', () => {
|
|
284
|
-
const IntervalSchema = Schema.
|
|
291
|
+
const IntervalSchema = Schema.Literals([1, 5, 15, 30])
|
|
285
292
|
|
|
286
293
|
const columnDef = State.SQLite.getColumnDefForSchema(IntervalSchema)
|
|
287
294
|
|
|
@@ -289,7 +296,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
289
296
|
})
|
|
290
297
|
|
|
291
298
|
it('should handle unions of non-integer numeric literals as real column', () => {
|
|
292
|
-
const PercentSchema = Schema.
|
|
299
|
+
const PercentSchema = Schema.Literals([0.1, 0.2, 0.25])
|
|
293
300
|
|
|
294
301
|
const columnDef = State.SQLite.getColumnDefForSchema(PercentSchema)
|
|
295
302
|
|
|
@@ -298,10 +305,25 @@ describe('getColumnDefForSchema', () => {
|
|
|
298
305
|
})
|
|
299
306
|
|
|
300
307
|
describe('binary data', () => {
|
|
301
|
-
it('should handle Uint8Array as blob column', () => {
|
|
308
|
+
it('should handle Uint8Array as blob column', async () => {
|
|
302
309
|
const columnDef = State.SQLite.getColumnDefForSchema(Schema.Uint8Array)
|
|
303
310
|
expect(columnDef.columnType).toBe('blob')
|
|
304
|
-
expect(
|
|
311
|
+
expect(
|
|
312
|
+
SchemaAST.resolveAt<{ readonly id: string }>('representation')(Schema.toType(columnDef.schema).ast)?.id,
|
|
313
|
+
).toBe('effect/schema/Uint8Array')
|
|
314
|
+
|
|
315
|
+
const asserts = new TestSchema.Asserts(columnDef.schema)
|
|
316
|
+
await asserts.decoding().succeed(new Uint8Array([1, 2, 3]))
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
it('should preserve Uint8Array checks on blob columns', () => {
|
|
320
|
+
const schema = Schema.Uint8Array.check(Schema.makeFilter((value) => value.byteLength > 0))
|
|
321
|
+
const columnDef = State.SQLite.getColumnDefForSchema(schema)
|
|
322
|
+
|
|
323
|
+
expect(columnDef.columnType).toBe('blob')
|
|
324
|
+
expect(columnDef.schema).toBe(schema)
|
|
325
|
+
expect(Schema.decodeUnknownSync(columnDef.schema)(new Uint8Array([1]))).toEqual(new Uint8Array([1]))
|
|
326
|
+
expect(() => Schema.decodeUnknownSync(columnDef.schema)(new Uint8Array())).toThrow()
|
|
305
327
|
})
|
|
306
328
|
})
|
|
307
329
|
|
|
@@ -322,12 +344,12 @@ describe('getColumnDefForSchema', () => {
|
|
|
322
344
|
})
|
|
323
345
|
|
|
324
346
|
describe('schema-based table definitions', () => {
|
|
325
|
-
it('should handle optional fields in schema', () => {
|
|
347
|
+
it('should handle optional fields in schema', async () => {
|
|
326
348
|
const UserSchema = Schema.Struct({
|
|
327
349
|
id: Schema.String,
|
|
328
350
|
name: Schema.String,
|
|
329
351
|
email: Schema.optional(Schema.String),
|
|
330
|
-
age: Schema.optional(Schema.
|
|
352
|
+
age: Schema.optional(Schema.Finite),
|
|
331
353
|
})
|
|
332
354
|
|
|
333
355
|
const userTable = State.SQLite.table({
|
|
@@ -343,12 +365,16 @@ describe('getColumnDefForSchema', () => {
|
|
|
343
365
|
expect(userTable.sqliteDef.columns.id.nullable).toBe(false)
|
|
344
366
|
expect(userTable.sqliteDef.columns.name.nullable).toBe(false)
|
|
345
367
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
368
|
+
const asserts = new TestSchema.Asserts(userTable.rowSchema)
|
|
369
|
+
await asserts.decoding().succeed({
|
|
370
|
+
id: 'user-1',
|
|
371
|
+
name: 'Ada',
|
|
372
|
+
email: null,
|
|
373
|
+
age: null,
|
|
374
|
+
})
|
|
349
375
|
})
|
|
350
376
|
|
|
351
|
-
it('should handle optional boolean with proper transformation', () => {
|
|
377
|
+
it('should handle optional boolean with proper transformation', async () => {
|
|
352
378
|
const schema = Schema.Struct({
|
|
353
379
|
id: Schema.String,
|
|
354
380
|
active: Schema.optional(Schema.Boolean),
|
|
@@ -358,11 +384,13 @@ describe('getColumnDefForSchema', () => {
|
|
|
358
384
|
|
|
359
385
|
expect(table.sqliteDef.columns.active.nullable).toBe(true)
|
|
360
386
|
expect(table.sqliteDef.columns.active.columnType).toBe('integer')
|
|
361
|
-
|
|
362
|
-
|
|
387
|
+
const asserts = new TestSchema.Asserts(table.rowSchema)
|
|
388
|
+
await asserts.decoding().succeed({ id: 'row-1', active: 1 }, { id: 'row-1', active: true })
|
|
389
|
+
expect(Schema.encodeSync(table.sqliteDef.columns.active.schema)(false)).toBe(0)
|
|
390
|
+
await asserts.decoding().succeed({ id: 'row-1', active: null })
|
|
363
391
|
})
|
|
364
392
|
|
|
365
|
-
it('should handle optional complex types with JSON encoding', () => {
|
|
393
|
+
it('should handle optional complex types with JSON encoding', async () => {
|
|
366
394
|
const schema = Schema.Struct({
|
|
367
395
|
id: Schema.String,
|
|
368
396
|
metadata: Schema.optional(Schema.Struct({ color: Schema.String })),
|
|
@@ -373,17 +401,27 @@ describe('getColumnDefForSchema', () => {
|
|
|
373
401
|
|
|
374
402
|
expect(table.sqliteDef.columns.metadata.nullable).toBe(true)
|
|
375
403
|
expect(table.sqliteDef.columns.metadata.columnType).toBe('text')
|
|
376
|
-
expect((table.rowSchema as any).fields.metadata.toString()).toBe(
|
|
377
|
-
'(parseJson <-> { readonly color: string }) | null',
|
|
378
|
-
// '(parseJson <-> { readonly color: string } | null)', // not sure yet about which semantics we want here
|
|
379
|
-
)
|
|
380
404
|
|
|
381
405
|
expect(table.sqliteDef.columns.tags.nullable).toBe(true)
|
|
382
406
|
expect(table.sqliteDef.columns.tags.columnType).toBe('text')
|
|
383
|
-
|
|
407
|
+
|
|
408
|
+
const asserts = new TestSchema.Asserts(table.rowSchema)
|
|
409
|
+
await asserts.decoding().succeed(
|
|
410
|
+
{
|
|
411
|
+
id: 'row-1',
|
|
412
|
+
metadata: JSON.stringify({ color: 'red' }),
|
|
413
|
+
tags: JSON.stringify(['urgent', 'local']),
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
id: 'row-1',
|
|
417
|
+
metadata: { color: 'red' },
|
|
418
|
+
tags: ['urgent', 'local'],
|
|
419
|
+
},
|
|
420
|
+
)
|
|
421
|
+
await asserts.decoding().succeed({ id: 'row-1', metadata: null, tags: null })
|
|
384
422
|
})
|
|
385
423
|
|
|
386
|
-
it('should handle Schema.NullOr', () => {
|
|
424
|
+
it('should handle Schema.NullOr', async () => {
|
|
387
425
|
const schema = Schema.Struct({
|
|
388
426
|
id: Schema.String,
|
|
389
427
|
description: Schema.NullOr(Schema.String),
|
|
@@ -395,41 +433,55 @@ describe('getColumnDefForSchema', () => {
|
|
|
395
433
|
expect(table.sqliteDef.columns.description.nullable).toBe(true)
|
|
396
434
|
expect(table.sqliteDef.columns.count.nullable).toBe(true)
|
|
397
435
|
|
|
398
|
-
|
|
399
|
-
|
|
436
|
+
const asserts = new TestSchema.Asserts(table.rowSchema)
|
|
437
|
+
await asserts.decoding().succeed({
|
|
438
|
+
id: 'row-1',
|
|
439
|
+
description: 'ready',
|
|
440
|
+
count: 1,
|
|
441
|
+
})
|
|
442
|
+
await asserts.decoding().succeed({
|
|
443
|
+
id: 'row-1',
|
|
444
|
+
description: null,
|
|
445
|
+
count: null,
|
|
446
|
+
})
|
|
400
447
|
})
|
|
401
448
|
|
|
402
|
-
it('should treat unions of string literals as text columns without JSON parsing', () => {
|
|
449
|
+
it('should treat unions of string literals as text columns without JSON parsing', async () => {
|
|
403
450
|
const schema = Schema.Struct({
|
|
404
451
|
id: Schema.String,
|
|
405
|
-
status: Schema.
|
|
452
|
+
status: Schema.Literals(['idle', 'running', 'stopped']),
|
|
406
453
|
})
|
|
407
454
|
|
|
408
455
|
const table = State.SQLite.table({ name: 'timers', schema })
|
|
409
456
|
|
|
410
457
|
expect(table.sqliteDef.columns.status.columnType).toBe('text')
|
|
411
|
-
expect(
|
|
412
|
-
|
|
458
|
+
expect(Schema.toEncoded(table.sqliteDef.columns.status.schema).ast._tag).toBe('Union')
|
|
459
|
+
|
|
460
|
+
const asserts = new TestSchema.Asserts(table.rowSchema)
|
|
461
|
+
await asserts.decoding().succeed({ id: 'timer-1', status: 'idle' })
|
|
413
462
|
})
|
|
414
463
|
|
|
415
|
-
it('should handle Schema.NullOr with complex types', () => {
|
|
464
|
+
it('should handle Schema.NullOr with complex types', async () => {
|
|
416
465
|
const schema = Schema.Struct({
|
|
417
|
-
data: Schema.NullOr(Schema.Struct({ value: Schema.
|
|
418
|
-
}).
|
|
466
|
+
data: Schema.NullOr(Schema.Struct({ value: Schema.Finite })),
|
|
467
|
+
}).annotate({ title: 'test' })
|
|
419
468
|
|
|
420
469
|
const table = State.SQLite.table({ schema })
|
|
421
470
|
|
|
422
471
|
expect(table.sqliteDef.columns.data.nullable).toBe(true)
|
|
423
472
|
expect(table.sqliteDef.columns.data.columnType).toBe('text')
|
|
424
|
-
|
|
473
|
+
|
|
474
|
+
const asserts = new TestSchema.Asserts(table.rowSchema)
|
|
475
|
+
await asserts.decoding().succeed({ data: JSON.stringify({ value: 42 }) }, { data: { value: 42 } })
|
|
476
|
+
await asserts.decoding().succeed({ data: null })
|
|
425
477
|
})
|
|
426
478
|
|
|
427
|
-
it('should handle mixed nullable and optional fields', () => {
|
|
479
|
+
it('should handle mixed nullable and optional fields', async () => {
|
|
428
480
|
const schema = Schema.Struct({
|
|
429
481
|
nullableText: Schema.NullOr(Schema.String),
|
|
430
482
|
optionalText: Schema.optional(Schema.String),
|
|
431
|
-
optionalJson: Schema.optional(Schema.Struct({ x: Schema.
|
|
432
|
-
}).
|
|
483
|
+
optionalJson: Schema.optional(Schema.Struct({ x: Schema.Finite })),
|
|
484
|
+
}).annotate({ title: 'test' })
|
|
433
485
|
|
|
434
486
|
const table = State.SQLite.table({ schema })
|
|
435
487
|
|
|
@@ -438,12 +490,15 @@ describe('getColumnDefForSchema', () => {
|
|
|
438
490
|
expect(table.sqliteDef.columns.optionalText.nullable).toBe(true)
|
|
439
491
|
expect(table.sqliteDef.columns.optionalJson.nullable).toBe(true)
|
|
440
492
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
)
|
|
493
|
+
const nullableTextAsserts = new TestSchema.Asserts(table.sqliteDef.columns.nullableText.schema)
|
|
494
|
+
const optionalTextAsserts = new TestSchema.Asserts(table.sqliteDef.columns.optionalText.schema)
|
|
495
|
+
const optionalJsonAsserts = new TestSchema.Asserts(table.sqliteDef.columns.optionalJson.schema)
|
|
496
|
+
|
|
497
|
+
await nullableTextAsserts.decoding().succeed('hello')
|
|
498
|
+
await nullableTextAsserts.decoding().succeed(null)
|
|
499
|
+
await optionalTextAsserts.decoding().succeed(null)
|
|
500
|
+
await optionalJsonAsserts.decoding().succeed(JSON.stringify({ x: 1 }), { x: 1 })
|
|
501
|
+
await optionalJsonAsserts.decoding().succeed(null)
|
|
447
502
|
})
|
|
448
503
|
|
|
449
504
|
// TODO bring back some time later
|
|
@@ -452,7 +507,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
452
507
|
// id: Schema.String,
|
|
453
508
|
// lossyText: Schema.optional(Schema.NullOr(Schema.String)),
|
|
454
509
|
// lossyComplex: Schema.optional(Schema.NullOr(Schema.Struct({ value: Schema.Number }))),
|
|
455
|
-
// }).
|
|
510
|
+
// }).annotate({ title: 'lossy_test' })
|
|
456
511
|
|
|
457
512
|
// const table = State.SQLite.table({ schema })
|
|
458
513
|
|
|
@@ -476,7 +531,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
476
531
|
describe('annotations', () => {
|
|
477
532
|
describe('withColumnType', () => {
|
|
478
533
|
it('should respect column type annotation for text', () => {
|
|
479
|
-
const schema = Schema.
|
|
534
|
+
const schema = Schema.Finite.pipe(withColumnType('text'))
|
|
480
535
|
const columnDef = State.SQLite.getColumnDefForSchema(schema)
|
|
481
536
|
expect(columnDef.columnType).toBe('text')
|
|
482
537
|
})
|
|
@@ -501,7 +556,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
501
556
|
|
|
502
557
|
it('should override default type mapping', () => {
|
|
503
558
|
// Number normally maps to real, but we override to text
|
|
504
|
-
const schema = Schema.
|
|
559
|
+
const schema = Schema.Finite.pipe(withColumnType('text'))
|
|
505
560
|
const columnDef = State.SQLite.getColumnDefForSchema(schema)
|
|
506
561
|
expect(columnDef.columnType).toBe('text')
|
|
507
562
|
})
|
|
@@ -540,7 +595,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
540
595
|
it('should throw when primary key is used with optional schema', () => {
|
|
541
596
|
// Note: Schema.optional returns a property signature, not a schema, so we can't pipe it
|
|
542
597
|
// Instead, we use Schema.Union to create an optional schema that can be piped
|
|
543
|
-
const optionalString = Schema.Union(Schema.String, Schema.Undefined)
|
|
598
|
+
const optionalString = Schema.Union([Schema.String, Schema.Undefined])
|
|
544
599
|
const UserSchema = Schema.Struct({
|
|
545
600
|
id: optionalString.pipe(withPrimaryKey),
|
|
546
601
|
name: Schema.String,
|
|
@@ -570,7 +625,7 @@ describe('getColumnDefForSchema', () => {
|
|
|
570
625
|
|
|
571
626
|
it('should work with column type annotation', () => {
|
|
572
627
|
const UserSchema = Schema.Struct({
|
|
573
|
-
id: Schema.
|
|
628
|
+
id: Schema.Finite.pipe(withColumnType('integer'), withPrimaryKey),
|
|
574
629
|
name: Schema.String,
|
|
575
630
|
})
|
|
576
631
|
|