@livestore/common 0.4.0 → 0.5.0-dev.1
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 +8 -8
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +4 -4
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/adapter-types.d.ts +33 -57
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +24 -41
- package/dist/adapter-types.js.map +1 -1
- package/dist/bounded-collections.d.ts.map +1 -1
- 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 +32 -44
- 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 +2 -1
- package/dist/devtools/devtools-compatibility.test.js.map +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +522 -334
- package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-client-session.js +80 -78
- 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 +6 -6
- package/dist/devtools/devtools-messages-common.js.map +1 -1
- package/dist/devtools/devtools-messages-leader.d.ts +410 -348
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-leader.js +105 -93
- package/dist/devtools/devtools-messages-leader.js.map +1 -1
- package/dist/devtools/devtools-messages.js +3 -3
- 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 +12 -8
- 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 +19 -17
- 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 +22 -19
- package/dist/index.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +87 -18
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +548 -480
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/RejectedPushError.d.ts +72 -41
- package/dist/leader-thread/RejectedPushError.d.ts.map +1 -1
- package/dist/leader-thread/RejectedPushError.js +25 -6
- 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 +11 -10
- package/dist/leader-thread/connection.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts +15 -5
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +19 -19
- 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 +36 -20
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +15 -5
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +62 -58
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.test.js +9 -9
- 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 +12 -8
- package/dist/leader-thread/materialize-event.js.map +1 -1
- package/dist/leader-thread/mod.js +9 -9
- package/dist/leader-thread/recreate-db.d.ts +5 -1
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +34 -59
- 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 +16 -21
- package/dist/leader-thread/stream-events.js.map +1 -1
- package/dist/leader-thread/types.d.ts +38 -73
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/leader-thread/types.js +10 -6
- 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 +2 -3
- package/dist/make-client-session.d.ts.map +1 -1
- package/dist/make-client-session.js +5 -5
- 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 +9 -37
- 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 +3 -1
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
- package/dist/rematerialize-from-eventlog.js +42 -33
- package/dist/rematerialize-from-eventlog.js.map +1 -1
- package/dist/schema/EventDef/define.d.ts +6 -6
- 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 +3 -3
- 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/EventDef/facts.d.ts.map +1 -1
- package/dist/schema/EventDef/materializer.d.ts +2 -2
- package/dist/schema/EventDef/materializer.d.ts.map +1 -1
- package/dist/schema/EventDef/mod.js +5 -5
- package/dist/schema/EventSequenceNumber/client.d.ts +12 -17
- package/dist/schema/EventSequenceNumber/client.d.ts.map +1 -1
- package/dist/schema/EventSequenceNumber/client.js +20 -24
- 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/mod.js +2 -2
- package/dist/schema/EventSequenceNumber.test.js +6 -6
- package/dist/schema/EventSequenceNumber.test.js.map +1 -1
- package/dist/schema/LiveStoreEvent/client.d.ts +58 -187
- package/dist/schema/LiveStoreEvent/client.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent/client.js +33 -30
- package/dist/schema/LiveStoreEvent/client.js.map +1 -1
- package/dist/schema/LiveStoreEvent/client.test.js +13 -4
- 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 +2 -2
- package/dist/schema/LiveStoreEvent/global.js.map +1 -1
- package/dist/schema/LiveStoreEvent/input.d.ts +6 -6
- 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/LiveStoreEvent/mod.js +4 -4
- package/dist/schema/events.js +1 -1
- package/dist/schema/mod.d.ts +1 -0
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +11 -10
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts +1 -1
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +6 -5
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/mod.js +2 -2
- package/dist/schema/state/sqlite/client-document-def.d.ts +13 -18
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +30 -27
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.test.js +53 -18
- 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 +73 -33
- package/dist/schema/state/sqlite/column-def.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.test.js +176 -75
- 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 +1 -1
- package/dist/schema/state/sqlite/column-spec.js.map +1 -1
- package/dist/schema/state/sqlite/column-spec.test.js +4 -4
- package/dist/schema/state/sqlite/column-spec.test.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint-digest.d.ts +3 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint-digest.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint-digest.js +5 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint-digest.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint.d.ts +5 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint.js +183 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint.test.d.ts +2 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint.test.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint.test.js +142 -0
- package/dist/schema/state/sqlite/db-schema/ast/fingerprint.test.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts +3 -8
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +1 -73
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts.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 +9 -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 +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 +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 +6 -4
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/has-json-string-encoding.d.ts +3 -0
- package/dist/schema/state/sqlite/db-schema/has-json-string-encoding.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/has-json-string-encoding.js +6 -0
- package/dist/schema/state/sqlite/db-schema/has-json-string-encoding.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/mod.js +2 -2
- 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 +11 -10
- 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 +22 -23
- package/dist/schema/state/sqlite/query-builder/astToSql.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.js +18 -16
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +364 -598
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/mod.js +2 -2
- package/dist/schema/state/sqlite/schema-helpers.d.ts.map +1 -1
- package/dist/schema/state/sqlite/schema-helpers.js +2 -2
- package/dist/schema/state/sqlite/schema-helpers.js.map +1 -1
- package/dist/schema/state/sqlite/schema-helpers.test.js +2 -2
- 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 +5 -5
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.js.map +1 -1
- package/dist/schema/state/sqlite/system-tables/mod.js +2 -2
- package/dist/schema/state/sqlite/system-tables/state-tables.d.ts +380 -115
- package/dist/schema/state/sqlite/system-tables/state-tables.d.ts.map +1 -1
- package/dist/schema/state/sqlite/system-tables/state-tables.js +47 -6
- package/dist/schema/state/sqlite/system-tables/state-tables.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.d.ts +17 -20
- package/dist/schema/state/sqlite/table-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/table-def.js +72 -6
- package/dist/schema/state/sqlite/table-def.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.test.js +207 -37
- 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 +3 -2
- package/dist/schema/unknown-events.js.map +1 -1
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js +28 -6
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js.map +1 -1
- package/dist/schema-management/common.d.ts.map +1 -1
- package/dist/schema-management/common.js +2 -2
- package/dist/schema-management/migrations.d.ts +4 -4
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +9 -9
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/schema-management/validate-schema.d.ts.map +1 -1
- package/dist/schema-management/validate-schema.js +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/index.js +3 -3
- package/dist/sql-queries/sql-queries.d.ts.map +1 -1
- package/dist/sql-queries/sql-queries.js +11 -13
- 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 +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 +23 -3
- package/dist/sqlite-db-helper.d.ts.map +1 -1
- package/dist/sqlite-db-helper.js +39 -4
- 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 +41 -19
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +200 -70
- 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 +3 -3
- package/dist/sync/errors.js.map +1 -1
- package/dist/sync/index.js +6 -6
- 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 +58 -37
- 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 +3 -3
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js +1 -1
- package/dist/sync/next/history-dag-common.d.ts +5 -1
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +53 -32
- 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 +5 -4
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/next/mod.js +5 -5
- package/dist/sync/next/rebase-events.d.ts.map +1 -1
- package/dist/sync/next/rebase-events.js +2 -2
- package/dist/sync/next/test/compact-events.calculator.test.js +6 -6
- package/dist/sync/next/test/compact-events.test.js +4 -4
- package/dist/sync/next/test/event-fixtures.d.ts +8 -8
- package/dist/sync/next/test/event-fixtures.d.ts.map +1 -1
- package/dist/sync/next/test/event-fixtures.js +6 -6
- 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/next/test/mod.js +1 -1
- package/dist/sync/sync-backend-kv.d.ts.map +1 -1
- package/dist/sync/sync-backend-kv.js +5 -3
- 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 +10 -6
- 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/sync.js +2 -2
- package/dist/sync/syncstate.d.ts +100 -176
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +36 -39
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +103 -64
- 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/sync/validate-push-payload.d.ts.map +1 -1
- package/dist/sync/validate-push-payload.js +2 -2
- package/dist/testing/event-factory.d.ts.map +1 -1
- package/dist/testing/event-factory.js +2 -2
- package/dist/testing/event-factory.js.map +1 -1
- package/dist/testing/mod.js +1 -1
- package/dist/util.d.ts +11 -4
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +20 -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 +40 -57
- 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 +28 -61
- package/src/debug-info.ts +53 -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 +777 -650
- package/src/leader-thread/RejectedPushError.ts +40 -27
- package/src/leader-thread/connection.ts +12 -8
- package/src/leader-thread/eventlog.ts +20 -12
- package/src/leader-thread/leader-worker-devtools.ts +38 -20
- package/src/leader-thread/make-leader-thread-layer.test.ts +7 -7
- package/src/leader-thread/make-leader-thread-layer.ts +100 -71
- package/src/leader-thread/materialize-event.ts +13 -8
- package/src/leader-thread/recreate-db.ts +41 -75
- package/src/leader-thread/shutdown-channel.ts +3 -14
- package/src/leader-thread/stream-events.ts +102 -101
- package/src/leader-thread/types.ts +29 -62
- package/src/logging.ts +5 -52
- package/src/make-client-session.ts +6 -6
- package/src/materializer-helper.ts +7 -36
- package/src/otel.ts +5 -14
- package/src/rematerialize-from-eventlog.ts +116 -98
- 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 +20 -24
- 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 +4 -3
- package/src/schema/state/sqlite/client-document-def.test.ts +55 -20
- 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 +213 -77
- package/src/schema/state/sqlite/column-def.ts +87 -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/fingerprint-digest.ts +6 -0
- package/src/schema/state/sqlite/db-schema/ast/fingerprint.test.ts +209 -0
- package/src/schema/state/sqlite/db-schema/ast/fingerprint.ts +225 -0
- package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +2 -81
- 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 +26 -31
- package/src/schema/state/sqlite/db-schema/dsl/mod.ts +35 -21
- package/src/schema/state/sqlite/db-schema/has-json-string-encoding.ts +9 -0
- package/src/schema/state/sqlite/mod.ts +4 -5
- 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 +24 -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 +54 -3
- package/src/schema/state/sqlite/table-def.test.ts +270 -66
- package/src/schema/state/sqlite/table-def.ts +112 -45
- package/src/schema/unknown-events.ts +3 -2
- package/src/schema-management/__tests__/migrations-autoincrement-quoting.test.ts +35 -4
- package/src/schema-management/migrations.ts +7 -6
- package/src/session-id-symbol.ts +59 -0
- package/src/sql-queries/sql-queries.ts +9 -13
- 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 +19 -9
- package/src/version.ts +1 -2
- package/dist/schema/state/sqlite/db-schema/hash.d.ts +0 -2
- package/dist/schema/state/sqlite/db-schema/hash.d.ts.map +0 -1
- package/dist/schema/state/sqlite/db-schema/hash.js +0 -15
- package/dist/schema/state/sqlite/db-schema/hash.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/src/schema/state/sqlite/db-schema/hash.ts +0 -13
- package/src/sql-queries/misc.ts +0 -2
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Predicate, ReadonlyArray, Schema } from '@livestore/utils/effect'
|
|
2
|
+
|
|
3
|
+
import { SqliteError, type SqliteDb } from './adapter-types.ts'
|
|
4
|
+
import { execSql, execSqlPrepared } from './leader-thread/connection.ts'
|
|
5
|
+
import * as EventSequenceNumber from './schema/EventSequenceNumber/mod.ts'
|
|
6
|
+
import { SystemTables } from './schema/mod.ts'
|
|
7
|
+
import { findManyRows, insertRow } from './sql-queries/index.ts'
|
|
8
|
+
import * as SqliteDbHelper from './sqlite-db-helper.ts'
|
|
9
|
+
import { prepareBindValues, sql } from './util.ts'
|
|
10
|
+
|
|
11
|
+
export const TypeId = '~@livestore/common/MaterializationJournal' as const
|
|
12
|
+
export type TypeId = typeof TypeId
|
|
13
|
+
|
|
14
|
+
export const MaterializationJournalErrorTypeId = '~@livestore/common/MaterializationJournalError' as const
|
|
15
|
+
|
|
16
|
+
export const isMaterializationJournalError = (u: unknown): u is MaterializationJournalError =>
|
|
17
|
+
Predicate.hasProperty(u, MaterializationJournalErrorTypeId)
|
|
18
|
+
|
|
19
|
+
export class MaterializationJournalError extends Schema.TaggedError<MaterializationJournalError>(
|
|
20
|
+
MaterializationJournalErrorTypeId,
|
|
21
|
+
)('MaterializationJournalError', {
|
|
22
|
+
method: Schema.Literals(['record', 'rollback', 'discardUpTo']),
|
|
23
|
+
cause: Schema.Defect(),
|
|
24
|
+
}) {
|
|
25
|
+
readonly [MaterializationJournalErrorTypeId] = MaterializationJournalErrorTypeId
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type MaterializationChangeset = { _tag: 'changeset'; data: Uint8Array<ArrayBuffer> } | { _tag: 'no-op' }
|
|
29
|
+
|
|
30
|
+
export type MaterializationRecord = {
|
|
31
|
+
key: EventSequenceNumber.Client.Composite
|
|
32
|
+
changeset: MaterializationChangeset
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface Service {
|
|
36
|
+
readonly [TypeId]: TypeId
|
|
37
|
+
/** Stores a materialization record, replacing any record at the same key. */
|
|
38
|
+
record: (record: MaterializationRecord) => Effect.Effect<void, MaterializationJournalError>
|
|
39
|
+
/** Reverts the keyed materializations in reverse order, then discards their records. */
|
|
40
|
+
rollback: (
|
|
41
|
+
keys: ReadonlyArray<EventSequenceNumber.Client.Composite>,
|
|
42
|
+
) => Effect.Effect<void, MaterializationJournalError>
|
|
43
|
+
/** Discards records whose key is less than or equal to `key`, ignoring rebase generation. */
|
|
44
|
+
discardUpTo: (key: EventSequenceNumber.Client.Composite) => Effect.Effect<void, MaterializationJournalError>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class MaterializationJournal extends Context.Service<MaterializationJournal, Service>()(
|
|
48
|
+
'@livestore/common/MaterializationJournal',
|
|
49
|
+
) {}
|
|
50
|
+
|
|
51
|
+
interface Options {
|
|
52
|
+
readonly dbState: SqliteDb
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const make = ({ dbState }: Options) => {
|
|
56
|
+
const deleteByKeys = Effect.fnUntraced(function* (keys: ReadonlyArray<EventSequenceNumber.Client.Composite>) {
|
|
57
|
+
// Keep DELETE statements below SQLite's bound-parameter limit.
|
|
58
|
+
const keyChunks = ReadonlyArray.chunksOf(100)(keys)
|
|
59
|
+
|
|
60
|
+
for (const keyChunk of keyChunks) {
|
|
61
|
+
const placeholders = keyChunk.map(() => '(?, ?, ?)').join(', ')
|
|
62
|
+
const bindValues = keyChunk.flatMap((key) => [key.global, key.client, key.rebaseGeneration])
|
|
63
|
+
const statement = sql`DELETE FROM ${SystemTables.MATERIALIZATION_JOURNAL_META_TABLE}
|
|
64
|
+
WHERE (seqNumGlobal, seqNumClient, seqNumRebaseGeneration) IN (${placeholders})`
|
|
65
|
+
|
|
66
|
+
yield* execSqlPrepared(dbState, statement, prepareBindValues(bindValues, statement))
|
|
67
|
+
}
|
|
68
|
+
}, SqliteDbHelper.withSavepoint(dbState))
|
|
69
|
+
|
|
70
|
+
return MaterializationJournal.of({
|
|
71
|
+
[TypeId]: TypeId,
|
|
72
|
+
record: Effect.fnUntraced(
|
|
73
|
+
function* (record: MaterializationRecord) {
|
|
74
|
+
yield* deleteByKeys([record.key])
|
|
75
|
+
|
|
76
|
+
// Generate the parameterized INSERT statement
|
|
77
|
+
const [statement, bindValues] = insertRow({
|
|
78
|
+
tableName: SystemTables.MATERIALIZATION_JOURNAL_META_TABLE,
|
|
79
|
+
columns: SystemTables.materializationJournalMetaTable.sqliteDef.columns,
|
|
80
|
+
values: {
|
|
81
|
+
seqNumGlobal: record.key.global,
|
|
82
|
+
seqNumClient: record.key.client,
|
|
83
|
+
seqNumRebaseGeneration: record.key.rebaseGeneration,
|
|
84
|
+
changeset: record.changeset._tag === 'changeset' ? record.changeset.data : null,
|
|
85
|
+
// Legacy processors still expose this column for development diagnostics.
|
|
86
|
+
debug: null,
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
yield* execSqlPrepared(dbState, statement, prepareBindValues(bindValues, statement))
|
|
91
|
+
},
|
|
92
|
+
SqliteDbHelper.withSavepoint(dbState),
|
|
93
|
+
Effect.mapError((cause) => new MaterializationJournalError({ method: 'record', cause })),
|
|
94
|
+
),
|
|
95
|
+
rollback: Effect.fnUntraced(
|
|
96
|
+
function* (keys: ReadonlyArray<EventSequenceNumber.Client.Composite>) {
|
|
97
|
+
const sortedKeys = keys.toSorted((a, b) => EventSequenceNumber.Client.compare(b, a))
|
|
98
|
+
const rollbackRecords = yield* Effect.forEach(
|
|
99
|
+
sortedKeys,
|
|
100
|
+
Effect.fnUntraced(function* (key) {
|
|
101
|
+
const [statement, bindValues] = findManyRows({
|
|
102
|
+
tableName: SystemTables.MATERIALIZATION_JOURNAL_META_TABLE,
|
|
103
|
+
columns: SystemTables.materializationJournalMetaTable.sqliteDef.columns,
|
|
104
|
+
where: {
|
|
105
|
+
seqNumGlobal: key.global,
|
|
106
|
+
seqNumClient: key.client,
|
|
107
|
+
seqNumRebaseGeneration: key.rebaseGeneration,
|
|
108
|
+
},
|
|
109
|
+
limit: 1,
|
|
110
|
+
})
|
|
111
|
+
const preparedBindValues = prepareBindValues(bindValues, statement)
|
|
112
|
+
const row = yield* Effect.try({
|
|
113
|
+
try: () => dbState.select<SystemTables.MaterializationJournalMetaRow>(statement, preparedBindValues)[0],
|
|
114
|
+
catch: (cause) => new SqliteError({ cause, query: { sql: statement, bindValues: preparedBindValues } }),
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
if (row === undefined) {
|
|
118
|
+
return yield* new MaterializationJournalError({
|
|
119
|
+
method: 'rollback',
|
|
120
|
+
cause: new Error(
|
|
121
|
+
`Missing materialization journal record for ${EventSequenceNumber.Client.toString(key)}`,
|
|
122
|
+
),
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
key,
|
|
128
|
+
changeset:
|
|
129
|
+
row.changeset === null
|
|
130
|
+
? { _tag: 'no-op' as const }
|
|
131
|
+
: { _tag: 'changeset' as const, data: row.changeset },
|
|
132
|
+
}
|
|
133
|
+
}),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
for (const record of rollbackRecords) {
|
|
137
|
+
if (record.changeset._tag === 'changeset') {
|
|
138
|
+
const data = record.changeset.data
|
|
139
|
+
yield* Effect.try({
|
|
140
|
+
try: () => dbState.makeChangeset(data).invert().apply(),
|
|
141
|
+
catch: (cause) => new SqliteError({ cause }),
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
yield* deleteByKeys(sortedKeys)
|
|
147
|
+
},
|
|
148
|
+
SqliteDbHelper.withSavepoint(dbState),
|
|
149
|
+
Effect.mapError((cause) =>
|
|
150
|
+
isMaterializationJournalError(cause) === true
|
|
151
|
+
? cause
|
|
152
|
+
: new MaterializationJournalError({ method: 'rollback', cause }),
|
|
153
|
+
),
|
|
154
|
+
),
|
|
155
|
+
discardUpTo: Effect.fnUntraced(
|
|
156
|
+
function* (key: EventSequenceNumber.Client.Composite) {
|
|
157
|
+
yield* execSql(
|
|
158
|
+
dbState,
|
|
159
|
+
sql`DELETE FROM ${SystemTables.MATERIALIZATION_JOURNAL_META_TABLE}
|
|
160
|
+
WHERE seqNumGlobal < ${key.global}
|
|
161
|
+
OR (
|
|
162
|
+
seqNumGlobal = ${key.global}
|
|
163
|
+
AND seqNumClient <= ${key.client}
|
|
164
|
+
)`,
|
|
165
|
+
{},
|
|
166
|
+
)
|
|
167
|
+
},
|
|
168
|
+
SqliteDbHelper.withSavepoint(dbState),
|
|
169
|
+
Effect.mapError((cause) => new MaterializationJournalError({ method: 'discardUpTo', cause })),
|
|
170
|
+
),
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export const layer = (options: Options) => Layer.succeed(MaterializationJournal, make(options))
|
|
175
|
+
|
|
176
|
+
export const layerTest = Layer.succeed(
|
|
177
|
+
MaterializationJournal,
|
|
178
|
+
MaterializationJournal.of({
|
|
179
|
+
[TypeId]: TypeId,
|
|
180
|
+
record: () => Effect.void,
|
|
181
|
+
rollback: () => Effect.void,
|
|
182
|
+
discardUpTo: () => Effect.void,
|
|
183
|
+
}),
|
|
184
|
+
)
|
package/src/StateHead.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from '@livestore/utils/effect'
|
|
2
|
+
|
|
3
|
+
import type { SqliteDb, SqliteError } from './adapter-types.ts'
|
|
4
|
+
import { execSql, selectSql } from './leader-thread/connection.ts'
|
|
5
|
+
import * as EventSequenceNumber from './schema/EventSequenceNumber/mod.ts'
|
|
6
|
+
import { SystemTables } from './schema/mod.ts'
|
|
7
|
+
import { findManyRows, insertRow } from './sql-queries/index.ts'
|
|
8
|
+
|
|
9
|
+
export const TypeId = '~@livestore/common/StateHead' as const
|
|
10
|
+
export type TypeId = typeof TypeId
|
|
11
|
+
|
|
12
|
+
const STATE_HEAD_ROW_ID = 1
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Persists and reads the latest event sequence number reflected by the state database.
|
|
16
|
+
*/
|
|
17
|
+
export interface Service {
|
|
18
|
+
readonly [TypeId]: TypeId
|
|
19
|
+
/** Persists the latest event sequence number reflected by the state database. */
|
|
20
|
+
set: (head: EventSequenceNumber.Client.Composite) => Effect.Effect<void, SqliteError>
|
|
21
|
+
/** Returns the persisted head, or the root when the current-schema table has no row. */
|
|
22
|
+
get: Effect.Effect<EventSequenceNumber.Client.Composite, SqliteError>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class StateHead extends Context.Service<StateHead, Service>()('@livestore/common/StateHead') {}
|
|
26
|
+
|
|
27
|
+
interface Options {
|
|
28
|
+
readonly dbState: SqliteDb
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const make = ({ dbState }: Options) => {
|
|
32
|
+
return StateHead.of({
|
|
33
|
+
[TypeId]: TypeId,
|
|
34
|
+
set: (head) => {
|
|
35
|
+
const [statement, bindValues] = insertRow({
|
|
36
|
+
tableName: SystemTables.STATE_HEAD_META_TABLE,
|
|
37
|
+
columns: SystemTables.stateHeadMetaTable.sqliteDef.columns,
|
|
38
|
+
values: {
|
|
39
|
+
id: STATE_HEAD_ROW_ID,
|
|
40
|
+
seqNumGlobal: head.global,
|
|
41
|
+
seqNumClient: head.client,
|
|
42
|
+
seqNumRebaseGeneration: head.rebaseGeneration,
|
|
43
|
+
},
|
|
44
|
+
options: { orReplace: true },
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return execSql(dbState, statement, bindValues)
|
|
48
|
+
},
|
|
49
|
+
get: Effect.suspend(() => {
|
|
50
|
+
const [statement, bindValues] = findManyRows({
|
|
51
|
+
tableName: SystemTables.STATE_HEAD_META_TABLE,
|
|
52
|
+
columns: SystemTables.stateHeadMetaTable.sqliteDef.columns,
|
|
53
|
+
where: { id: STATE_HEAD_ROW_ID },
|
|
54
|
+
limit: 1,
|
|
55
|
+
})
|
|
56
|
+
return selectSql<SystemTables.StateHeadMetaRow>(dbState, statement, bindValues).pipe(
|
|
57
|
+
Effect.map(([row]) =>
|
|
58
|
+
row === undefined
|
|
59
|
+
? EventSequenceNumber.Client.ROOT
|
|
60
|
+
: EventSequenceNumber.Client.Composite.make({
|
|
61
|
+
global: row.seqNumGlobal,
|
|
62
|
+
client: row.seqNumClient,
|
|
63
|
+
rebaseGeneration: row.seqNumRebaseGeneration,
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
}),
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const layer = (options: Options) => Layer.succeed(StateHead, make(options))
|
|
72
|
+
|
|
73
|
+
export const layerTest = Layer.succeed(
|
|
74
|
+
StateHead,
|
|
75
|
+
StateHead.of({
|
|
76
|
+
[TypeId]: TypeId,
|
|
77
|
+
set: () => Effect.void,
|
|
78
|
+
get: Effect.succeed(EventSequenceNumber.Client.ROOT),
|
|
79
|
+
}),
|
|
80
|
+
)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema, WorkerError } from '@livestore/utils/effect'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Type guard that identifies infrastructure errors from the Effect Worker transport layer.
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
7
|
*
|
|
8
|
-
* These errors ({@link WorkerError.WorkerError}, {@link
|
|
8
|
+
* These errors ({@link WorkerError.WorkerError}, {@link Schema.SchemaError}) represent communication failures between
|
|
9
9
|
* threads/processes — not application-level failures.
|
|
10
10
|
*/
|
|
11
|
-
export const isWorkerTransportError = (e: unknown): e is WorkerError.WorkerError |
|
|
12
|
-
|
|
11
|
+
export const isWorkerTransportError = (e: unknown): e is WorkerError.WorkerError | Schema.SchemaError =>
|
|
12
|
+
Schema.isSchemaError(e) || WorkerError.isWorkerError(e)
|
package/src/__tests__/fixture.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
|
2
2
|
|
|
3
|
-
import { SessionIdSymbol } from '../adapter-types.ts'
|
|
4
3
|
import { makeSchema, State } from '../schema/mod.ts'
|
|
4
|
+
import { SessionIdSymbol } from '../session-id-symbol.ts'
|
|
5
5
|
|
|
6
6
|
export const UiState = State.SQLite.clientDocument({
|
|
7
7
|
name: 'UiState',
|
|
@@ -14,8 +14,8 @@ export const UiState = State.SQLite.clientDocument({
|
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
const Config = Schema.Struct({
|
|
17
|
-
fontSize: Schema.
|
|
18
|
-
theme: Schema.
|
|
17
|
+
fontSize: Schema.Finite,
|
|
18
|
+
theme: Schema.Literals(['light', 'dark']),
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
export const appConfig = State.SQLite.clientDocument({
|
package/src/adapter-types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
type Effect,
|
|
3
3
|
type Exit,
|
|
4
4
|
type Queue,
|
|
5
|
+
type Latch,
|
|
5
6
|
Schema,
|
|
6
7
|
type Scope,
|
|
7
8
|
type SubscriptionRef,
|
|
@@ -28,16 +29,13 @@ export * from './sqlite-types.ts'
|
|
|
28
29
|
export interface ClientSession {
|
|
29
30
|
/** SQLite database with synchronous API running in the same thread (usually in-memory) */
|
|
30
31
|
sqliteDb: SqliteDb
|
|
31
|
-
devtools: { enabled: false } | { enabled: true; pullLatch:
|
|
32
|
+
devtools: { enabled: false } | { enabled: true; pullLatch: Latch.Latch; pushLatch: Latch.Latch }
|
|
32
33
|
clientId: string
|
|
33
34
|
sessionId: string
|
|
34
35
|
/** Status info whether current session is leader or not */
|
|
35
36
|
lockStatus: SubscriptionRef.SubscriptionRef<LockStatus>
|
|
36
37
|
shutdown: (
|
|
37
|
-
cause: Exit.Exit<
|
|
38
|
-
IntentionalShutdownCause,
|
|
39
|
-
UnknownError | MaterializeError | BackendIdMismatchError
|
|
40
|
-
>,
|
|
38
|
+
cause: Exit.Exit<IntentionalShutdownCause, UnknownError | MaterializeError | BackendIdMismatchError>,
|
|
41
39
|
) => Effect.Effect<void>
|
|
42
40
|
/** A proxy API to communicate with the leader thread */
|
|
43
41
|
leaderThread: ClientSessionLeaderThreadProxy
|
|
@@ -48,8 +46,8 @@ export interface ClientSession {
|
|
|
48
46
|
export type ResetMode = 'all-data' | 'only-app-db'
|
|
49
47
|
|
|
50
48
|
export const BootStateProgress = Schema.Struct({
|
|
51
|
-
done: Schema.
|
|
52
|
-
total: Schema.
|
|
49
|
+
done: Schema.Finite,
|
|
50
|
+
total: Schema.Finite,
|
|
53
51
|
})
|
|
54
52
|
|
|
55
53
|
/**
|
|
@@ -60,7 +58,7 @@ export const BootStateProgress = Schema.Struct({
|
|
|
60
58
|
* - `storage-unavailable`: OPFS access denied for other reasons (permissions, quota)
|
|
61
59
|
* - `unknown`: Unexpected error during storage initialization
|
|
62
60
|
*/
|
|
63
|
-
export const BootWarningReason = Schema.
|
|
61
|
+
export const BootWarningReason = Schema.Literals(['private-browsing', 'storage-unavailable', 'unknown'])
|
|
64
62
|
export type BootWarningReason = typeof BootWarningReason.Type
|
|
65
63
|
|
|
66
64
|
/**
|
|
@@ -70,10 +68,10 @@ export type BootWarningReason = typeof BootWarningReason.Type
|
|
|
70
68
|
* - `persisted`: Data is persisted to disk (e.g., via OPFS)
|
|
71
69
|
* - `in-memory`: Data is only stored in memory and will be lost on page refresh
|
|
72
70
|
*/
|
|
73
|
-
export const StorageMode = Schema.
|
|
71
|
+
export const StorageMode = Schema.Literals(['persisted', 'in-memory'])
|
|
74
72
|
export type StorageMode = typeof StorageMode.Type
|
|
75
73
|
|
|
76
|
-
export const BootStatus = Schema.Union(
|
|
74
|
+
export const BootStatus = Schema.Union([
|
|
77
75
|
Schema.Struct({ stage: Schema.Literal('loading') }),
|
|
78
76
|
Schema.Struct({ stage: Schema.Literal('migrating'), progress: BootStateProgress }),
|
|
79
77
|
Schema.Struct({ stage: Schema.Literal('rehydrating'), progress: BootStateProgress }),
|
|
@@ -88,67 +86,35 @@ export const BootStatus = Schema.Union(
|
|
|
88
86
|
reason: BootWarningReason,
|
|
89
87
|
message: Schema.String,
|
|
90
88
|
}),
|
|
91
|
-
).
|
|
89
|
+
]).annotate({ title: 'BootStatus' })
|
|
92
90
|
|
|
93
91
|
export type BootStatus = typeof BootStatus.Type
|
|
94
92
|
|
|
95
|
-
/**
|
|
96
|
-
* Can be used in queries to refer to the current session id.
|
|
97
|
-
* Will be replaced with the actual session id at runtime
|
|
98
|
-
*
|
|
99
|
-
* In client document table:
|
|
100
|
-
* ```ts
|
|
101
|
-
* const uiState = State.SQLite.clientDocument({
|
|
102
|
-
* name: 'ui_state',
|
|
103
|
-
* schema: Schema.Struct({
|
|
104
|
-
* theme: Schema.Literal('dark', 'light', 'system'),
|
|
105
|
-
* user: Schema.String,
|
|
106
|
-
* showToolbar: Schema.Boolean,
|
|
107
|
-
* }),
|
|
108
|
-
* default: { value: defaultFrontendState, id: SessionIdSymbol },
|
|
109
|
-
* })
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* Or in a client document query:
|
|
113
|
-
* ```ts
|
|
114
|
-
* const query$ = queryDb(tables.uiState.get(SessionIdSymbol))
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
export const SessionIdSymbol = Symbol.for('@livestore/session-id')
|
|
118
|
-
export type SessionIdSymbol = typeof SessionIdSymbol
|
|
119
|
-
|
|
120
93
|
export type LockStatus = 'has-lock' | 'no-lock'
|
|
121
94
|
|
|
122
|
-
// TODO possibly allow a combination of these options
|
|
123
95
|
// TODO allow a way to stream the migration progress back to the app
|
|
124
|
-
export type MigrationOptions =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
| {
|
|
133
|
-
strategy: 'manual'
|
|
134
|
-
migrate: (
|
|
135
|
-
oldDb: Uint8Array<ArrayBuffer>,
|
|
136
|
-
) => Uint8Array<ArrayBuffer> | Promise<Uint8Array<ArrayBuffer>> | Effect.Effect<Uint8Array<ArrayBuffer>, unknown>
|
|
137
|
-
}
|
|
96
|
+
export type MigrationOptions = {
|
|
97
|
+
hooks?: Partial<MigrationHooks>
|
|
98
|
+
logging?: {
|
|
99
|
+
excludeAffectedRows?: (sqlStmt: string) => boolean
|
|
100
|
+
}
|
|
101
|
+
}
|
|
138
102
|
|
|
139
103
|
export type MigrationHooks = {
|
|
140
104
|
/** Runs on the empty in-memory database with no database schemas applied yet */
|
|
141
105
|
init: MigrationHook
|
|
142
|
-
/** Runs
|
|
106
|
+
/** Runs after table schemas and singleton rows are created, but before rematerializing state from the eventlog */
|
|
143
107
|
pre: MigrationHook
|
|
144
|
-
/** Runs after
|
|
108
|
+
/** Runs after rematerializing state from the eventlog */
|
|
145
109
|
post: MigrationHook
|
|
146
110
|
}
|
|
147
111
|
|
|
148
112
|
export type MigrationHook = (db: SqliteDb) => void | Promise<void> | Effect.Effect<void, unknown>
|
|
149
113
|
|
|
150
|
-
export interface ClientSessionDevtoolsChannel
|
|
151
|
-
|
|
114
|
+
export interface ClientSessionDevtoolsChannel extends WebChannel.WebChannel<
|
|
115
|
+
Devtools.ClientSession.MessageToApp,
|
|
116
|
+
Devtools.ClientSession.MessageFromApp
|
|
117
|
+
> {}
|
|
152
118
|
|
|
153
119
|
export type ConnectDevtoolsToStore = (
|
|
154
120
|
storeDevtoolsChannel: ClientSessionDevtoolsChannel,
|
|
@@ -159,14 +125,15 @@ export type Adapter = (args: AdapterArgs) => Effect.Effect<ClientSession, Unknow
|
|
|
159
125
|
export interface AdapterArgs {
|
|
160
126
|
schema: LiveStoreSchema
|
|
161
127
|
storeId: string
|
|
128
|
+
/** Runtime parameters resolved by `createStore` before the adapter is invoked. */
|
|
129
|
+
params: {
|
|
130
|
+
stateRebuildBatchSize: number
|
|
131
|
+
}
|
|
162
132
|
devtoolsEnabled: boolean
|
|
163
133
|
debugInstanceId: string
|
|
164
134
|
bootStatusQueue: Queue.Queue<BootStatus>
|
|
165
135
|
shutdown: (
|
|
166
|
-
exit: Exit.Exit<
|
|
167
|
-
IntentionalShutdownCause,
|
|
168
|
-
UnknownError | MaterializeError | BackendIdMismatchError
|
|
169
|
-
>,
|
|
136
|
+
exit: Exit.Exit<IntentionalShutdownCause, UnknownError | MaterializeError | BackendIdMismatchError>,
|
|
170
137
|
) => Effect.Effect<void>
|
|
171
138
|
connectDevtoolsToStore: ConnectDevtoolsToStore
|
|
172
139
|
/**
|
|
@@ -174,7 +141,7 @@ export interface AdapterArgs {
|
|
|
174
141
|
*
|
|
175
142
|
* @default undefined
|
|
176
143
|
*/
|
|
177
|
-
syncPayloadSchema: Schema.Schema
|
|
144
|
+
syncPayloadSchema: Schema.Decoder<Schema.Json> | undefined
|
|
178
145
|
/** Encoded representation of the sync payload matching `syncPayloadSchema`. */
|
|
179
|
-
syncPayloadEncoded: Schema.
|
|
146
|
+
syncPayloadEncoded: Schema.Json | undefined
|
|
180
147
|
}
|
package/src/debug-info.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import {
|
|
2
|
+
import { Schema, SchemaGetter, Struct } from '@livestore/utils/effect'
|
|
3
3
|
|
|
4
4
|
import { BoundArray } from './bounded-collections.ts'
|
|
5
5
|
import { PreparedBindValues } from './util.ts'
|
|
@@ -16,93 +16,76 @@ export type SlowQueryInfo = {
|
|
|
16
16
|
export const SlowQueryInfo = Schema.Struct({
|
|
17
17
|
queryStr: Schema.String,
|
|
18
18
|
bindValues: Schema.UndefinedOr(PreparedBindValues),
|
|
19
|
-
durationMs: Schema.
|
|
20
|
-
rowsCount: Schema.UndefinedOr(Schema.
|
|
19
|
+
durationMs: Schema.Finite,
|
|
20
|
+
rowsCount: Schema.UndefinedOr(Schema.Finite),
|
|
21
21
|
queriedTables: Schema.ReadonlySet(Schema.String),
|
|
22
|
-
startTimePerfNow: Schema.
|
|
22
|
+
startTimePerfNow: Schema.Finite,
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
typeof (value as { sizeLimit?: number }).sizeLimit === 'number'
|
|
27
|
-
? (value as { sizeLimit: number }).sizeLimit
|
|
28
|
-
: Number.POSITIVE_INFINITY
|
|
25
|
+
const isBoundArrayLike = <A>(value: unknown): value is BoundArray<A> => value instanceof BoundArray
|
|
29
26
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
const BoundArraySchemaFromSelf = <A, I, RD, RE>(
|
|
28
|
+
item: Schema.Codec<A, I, RD, RE>,
|
|
29
|
+
): Schema.Codec<BoundArray<A>, BoundArray<A>> =>
|
|
30
|
+
Schema.declare<BoundArray<A>>(isBoundArrayLike, {
|
|
31
|
+
identifier: 'BoundArray',
|
|
32
|
+
expected: 'BoundArray',
|
|
33
|
+
description: 'Bounded array',
|
|
34
|
+
toFormatter: () => (_) => `BoundArray(${_.length})`,
|
|
35
|
+
toCodecArbitrary: () =>
|
|
36
|
+
Schema.link<BoundArray<A>>()(
|
|
37
|
+
Schema.Struct({
|
|
38
|
+
size: Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 100 })),
|
|
39
|
+
items: Schema.Array(item).check(Schema.isMaxLength(100)),
|
|
40
|
+
}),
|
|
41
|
+
{
|
|
42
|
+
decode: SchemaGetter.transform(({ size, items }) => BoundArray.make(size, items)),
|
|
43
|
+
encode: SchemaGetter.forbiddenEncoding,
|
|
44
|
+
},
|
|
45
|
+
),
|
|
46
|
+
toEquivalence: () => {
|
|
47
|
+
const elementEquivalence = Schema.toEquivalence(item)
|
|
48
|
+
return (a, b) => {
|
|
49
|
+
if (a === b) {
|
|
50
|
+
return true
|
|
44
51
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
encode: (item) => (input, parseOptions, ast) => {
|
|
48
|
-
if (isBoundArrayLike(input) === true) {
|
|
49
|
-
const items = [...input]
|
|
50
|
-
const elements = ParseResult.encodeUnknown(Schema.Array(item))(items, parseOptions)
|
|
51
|
-
return ParseResult.map(elements, (is): BoundArray<I> => BoundArray.make(getSizeLimit(input), is))
|
|
52
|
+
if (isBoundArrayLike(a) === false || isBoundArrayLike(b) === false) {
|
|
53
|
+
return false
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
equivalence: () => {
|
|
61
|
-
const elementEquivalence = Schema.equivalence(item)
|
|
62
|
-
return (a: unknown, b: unknown) => {
|
|
63
|
-
if (a === b) {
|
|
64
|
-
return true
|
|
65
|
-
}
|
|
66
|
-
if (isBoundArrayLike(a) === false || isBoundArrayLike(b) === false) {
|
|
67
|
-
return false
|
|
68
|
-
}
|
|
69
|
-
if (getSizeLimit(a) !== getSizeLimit(b) || a.length !== b.length) {
|
|
55
|
+
if (a.sizeLimit !== b.sizeLimit || a.length !== b.length) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
const itemsA = [...a]
|
|
59
|
+
const itemsB = [...b]
|
|
60
|
+
for (let i = 0; i < itemsA.length; i++) {
|
|
61
|
+
if (elementEquivalence(itemsA[i]!, itemsB[i]!) === false) {
|
|
70
62
|
return false
|
|
71
63
|
}
|
|
72
|
-
const itemsA = [...a]
|
|
73
|
-
const itemsB = [...b]
|
|
74
|
-
for (let i = 0; i < itemsA.length; i++) {
|
|
75
|
-
if (elementEquivalence(itemsA[i] as any, itemsB[i] as any) === false) {
|
|
76
|
-
return false
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return true
|
|
80
64
|
}
|
|
81
|
-
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
82
67
|
},
|
|
83
|
-
)
|
|
68
|
+
})
|
|
84
69
|
|
|
85
|
-
export const BoundArraySchema = <ItemDecoded, ItemEncoded>(elSchema: Schema.
|
|
86
|
-
Schema.
|
|
87
|
-
Schema.
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
export const BoundArraySchema = <ItemDecoded, ItemEncoded>(elSchema: Schema.Codec<ItemDecoded, ItemEncoded>) =>
|
|
71
|
+
Schema.Struct({
|
|
72
|
+
size: Schema.Finite,
|
|
73
|
+
items: Schema.Array(elSchema),
|
|
74
|
+
}).pipe(
|
|
75
|
+
Schema.decodeTo(BoundArraySchemaFromSelf(Schema.toType(elSchema)), {
|
|
76
|
+
decode: SchemaGetter.transform((_) => BoundArray.make(_.size, _.items)),
|
|
77
|
+
encode: SchemaGetter.transform((_) => ({ size: _.sizeLimit, items: [..._] })),
|
|
90
78
|
}),
|
|
91
|
-
BoundArraySchemaFromSelf(Schema.typeSchema(elSchema)),
|
|
92
|
-
{
|
|
93
|
-
encode: (_) => ({ size: _.sizeLimit, items: [..._] }),
|
|
94
|
-
decode: (_) => BoundArray.make(_.size, _.items),
|
|
95
|
-
},
|
|
96
79
|
)
|
|
97
80
|
|
|
98
81
|
export const DebugInfo = Schema.Struct({
|
|
99
82
|
slowQueries: BoundArraySchema(SlowQueryInfo),
|
|
100
|
-
queryFrameDuration: Schema.
|
|
101
|
-
queryFrameCount: Schema.
|
|
102
|
-
events: BoundArraySchema(Schema.Tuple(Schema.String, Schema.Any)),
|
|
83
|
+
queryFrameDuration: Schema.Finite,
|
|
84
|
+
queryFrameCount: Schema.Finite,
|
|
85
|
+
events: BoundArraySchema(Schema.Tuple([Schema.String, Schema.Any])),
|
|
103
86
|
})
|
|
104
87
|
|
|
105
88
|
export type DebugInfo = typeof DebugInfo.Type
|
|
106
89
|
|
|
107
|
-
export const MutableDebugInfo = Schema.
|
|
90
|
+
export const MutableDebugInfo = DebugInfo.mapFields(Struct.map(Schema.mutableKey))
|
|
108
91
|
export type MutableDebugInfo = typeof MutableDebugInfo.Type
|
package/src/defs.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { Schema } from '@livestore/utils/effect'
|
|
|
3
3
|
export const MigrationsReportEntry = Schema.Struct({
|
|
4
4
|
tableName: Schema.String,
|
|
5
5
|
hashes: Schema.Struct({
|
|
6
|
-
expected: Schema.
|
|
7
|
-
actual: Schema.optional(Schema.
|
|
6
|
+
expected: Schema.String,
|
|
7
|
+
actual: Schema.optional(Schema.String),
|
|
8
8
|
}),
|
|
9
9
|
})
|
|
10
10
|
|
|
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
|
|
|
2
2
|
|
|
3
3
|
import { isDevtoolsProtocolVersionSupported, resolveDevtoolsProtocolVersion } from '../version.ts'
|
|
4
4
|
|
|
5
|
+
/** Verifies: LS.SYS.DT-R02, LS.SYS.VER.PROTO-R01 */
|
|
5
6
|
describe('DevTools protocol compatibility', () => {
|
|
6
7
|
it('treats legacy pings without a protocol version as protocol 1', () => {
|
|
7
8
|
expect(resolveDevtoolsProtocolVersion(undefined)).toBe(1)
|