@livestore/common 0.3.0-dev.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/__tests__/fixture.d.ts +83 -221
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +33 -11
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/adapter-types.d.ts +120 -64
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +39 -8
- package/dist/adapter-types.js.map +1 -1
- package/dist/bounded-collections.d.ts.map +1 -1
- package/dist/debug-info.d.ts +1 -1
- package/dist/debug-info.d.ts.map +1 -1
- package/dist/debug-info.js +1 -0
- package/dist/debug-info.js.map +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +390 -0
- package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -0
- package/dist/devtools/devtools-messages-client-session.js +97 -0
- package/dist/devtools/devtools-messages-client-session.js.map +1 -0
- package/dist/devtools/devtools-messages-common.d.ts +68 -0
- package/dist/devtools/devtools-messages-common.d.ts.map +1 -0
- package/dist/devtools/devtools-messages-common.js +60 -0
- package/dist/devtools/devtools-messages-common.js.map +1 -0
- package/dist/devtools/devtools-messages-leader.d.ts +394 -0
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -0
- package/dist/devtools/devtools-messages-leader.js +147 -0
- package/dist/devtools/devtools-messages-leader.js.map +1 -0
- package/dist/devtools/devtools-messages.d.ts +3 -580
- package/dist/devtools/devtools-messages.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.js +3 -174
- package/dist/devtools/devtools-messages.js.map +1 -1
- package/dist/devtools/devtools-sessioninfo.d.ts +32 -0
- package/dist/devtools/devtools-sessioninfo.d.ts.map +1 -0
- package/dist/devtools/devtools-sessioninfo.js +36 -0
- package/dist/devtools/devtools-sessioninfo.js.map +1 -0
- package/dist/devtools/mod.d.ts +55 -0
- package/dist/devtools/mod.d.ts.map +1 -0
- package/dist/devtools/mod.js +33 -0
- package/dist/devtools/mod.js.map +1 -0
- package/dist/index.d.ts +7 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -9
- package/dist/index.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +36 -11
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +426 -252
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/connection.d.ts +34 -6
- package/dist/leader-thread/connection.d.ts.map +1 -1
- package/dist/leader-thread/connection.js +22 -7
- package/dist/leader-thread/connection.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts +27 -0
- package/dist/leader-thread/eventlog.d.ts.map +1 -0
- package/dist/leader-thread/eventlog.js +119 -0
- package/dist/leader-thread/eventlog.js.map +1 -0
- package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +155 -80
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +22 -9
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +67 -45
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/materialize-event.d.ts +16 -0
- package/dist/leader-thread/materialize-event.d.ts.map +1 -0
- package/dist/leader-thread/materialize-event.js +109 -0
- package/dist/leader-thread/materialize-event.js.map +1 -0
- package/dist/leader-thread/mod.d.ts +1 -1
- package/dist/leader-thread/mod.d.ts.map +1 -1
- package/dist/leader-thread/mod.js +1 -1
- package/dist/leader-thread/mod.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts +4 -2
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +28 -32
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/shutdown-channel.d.ts +2 -5
- package/dist/leader-thread/shutdown-channel.d.ts.map +1 -1
- package/dist/leader-thread/shutdown-channel.js +2 -4
- package/dist/leader-thread/shutdown-channel.js.map +1 -1
- package/dist/leader-thread/types.d.ts +79 -38
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/leader-thread/types.js +1 -3
- package/dist/leader-thread/types.js.map +1 -1
- package/dist/make-client-session.d.ts +23 -0
- package/dist/make-client-session.d.ts.map +1 -0
- package/dist/make-client-session.js +57 -0
- package/dist/make-client-session.js.map +1 -0
- package/dist/materializer-helper.d.ts +23 -0
- package/dist/materializer-helper.d.ts.map +1 -0
- package/dist/materializer-helper.js +86 -0
- package/dist/materializer-helper.js.map +1 -0
- package/dist/otel.d.ts +2 -0
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +5 -0
- package/dist/otel.js.map +1 -1
- package/dist/rematerialize-from-eventlog.d.ts +14 -0
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -0
- package/dist/rematerialize-from-eventlog.js +64 -0
- package/dist/rematerialize-from-eventlog.js.map +1 -0
- package/dist/schema/EventDef.d.ts +146 -0
- package/dist/schema/EventDef.d.ts.map +1 -0
- package/dist/schema/EventDef.js +58 -0
- package/dist/schema/EventDef.js.map +1 -0
- package/dist/schema/EventSequenceNumber.d.ts +57 -0
- package/dist/schema/EventSequenceNumber.d.ts.map +1 -0
- package/dist/schema/EventSequenceNumber.js +82 -0
- package/dist/schema/EventSequenceNumber.js.map +1 -0
- package/dist/schema/EventSequenceNumber.test.d.ts +2 -0
- package/dist/schema/EventSequenceNumber.test.d.ts.map +1 -0
- package/dist/schema/EventSequenceNumber.test.js +11 -0
- package/dist/schema/EventSequenceNumber.test.js.map +1 -0
- package/dist/schema/LiveStoreEvent.d.ts +257 -0
- package/dist/schema/LiveStoreEvent.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent.js +117 -0
- package/dist/schema/LiveStoreEvent.js.map +1 -0
- package/dist/schema/events.d.ts +2 -0
- package/dist/schema/events.d.ts.map +1 -0
- package/dist/schema/events.js +2 -0
- package/dist/schema/events.js.map +1 -0
- package/dist/schema/mod.d.ts +8 -6
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +8 -6
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts +50 -32
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +36 -43
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/mod.d.ts +3 -0
- package/dist/schema/state/mod.d.ts.map +1 -0
- package/dist/schema/state/mod.js +3 -0
- package/dist/schema/state/mod.js.map +1 -0
- package/dist/schema/state/sqlite/client-document-def.d.ts +223 -0
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -0
- package/dist/schema/state/sqlite/client-document-def.js +170 -0
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -0
- package/dist/schema/state/sqlite/client-document-def.test.d.ts +2 -0
- package/dist/schema/state/sqlite/client-document-def.test.d.ts.map +1 -0
- package/dist/schema/state/sqlite/client-document-def.test.js +201 -0
- package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts +69 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +71 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts +3 -0
- package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/validate.js +12 -0
- package/dist/schema/state/sqlite/db-schema/ast/validate.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts +90 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js +87 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.d.ts +2 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js +29 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +90 -0
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js +41 -0
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/hash.d.ts +2 -0
- package/dist/schema/state/sqlite/db-schema/hash.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/hash.js +14 -0
- package/dist/schema/state/sqlite/db-schema/hash.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/mod.d.ts +3 -0
- package/dist/schema/state/sqlite/db-schema/mod.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/mod.js +3 -0
- package/dist/schema/state/sqlite/db-schema/mod.js.map +1 -0
- package/dist/schema/state/sqlite/mod.d.ts +17 -0
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -0
- package/dist/schema/state/sqlite/mod.js +41 -0
- package/dist/schema/state/sqlite/mod.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/api.d.ts +294 -0
- package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/api.js +6 -0
- package/dist/schema/state/sqlite/query-builder/api.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/astToSql.d.ts +7 -0
- package/dist/schema/state/sqlite/query-builder/astToSql.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/astToSql.js +190 -0
- package/dist/schema/state/sqlite/query-builder/astToSql.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/impl.d.ts +7 -0
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/impl.js +286 -0
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.d.ts +87 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.js +563 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -0
- package/dist/{query-builder → schema/state/sqlite/query-builder}/mod.d.ts +7 -0
- package/dist/schema/state/sqlite/query-builder/mod.d.ts.map +1 -0
- package/dist/{query-builder → schema/state/sqlite/query-builder}/mod.js +7 -0
- package/dist/schema/state/sqlite/query-builder/mod.js.map +1 -0
- package/dist/schema/state/sqlite/schema-helpers.d.ts.map +1 -0
- package/dist/schema/{schema-helpers.js → state/sqlite/schema-helpers.js} +1 -1
- package/dist/schema/state/sqlite/schema-helpers.js.map +1 -0
- package/dist/schema/state/sqlite/system-tables.d.ts +574 -0
- package/dist/schema/state/sqlite/system-tables.d.ts.map +1 -0
- package/dist/schema/state/sqlite/system-tables.js +88 -0
- package/dist/schema/state/sqlite/system-tables.js.map +1 -0
- package/dist/schema/state/sqlite/table-def.d.ts +84 -0
- package/dist/schema/state/sqlite/table-def.d.ts.map +1 -0
- package/dist/schema/state/sqlite/table-def.js +36 -0
- package/dist/schema/state/sqlite/table-def.js.map +1 -0
- package/dist/schema-management/common.d.ts +7 -7
- package/dist/schema-management/common.d.ts.map +1 -1
- package/dist/schema-management/common.js.map +1 -1
- package/dist/schema-management/migrations.d.ts +6 -6
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +27 -18
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/schema-management/validate-schema.d.ts +8 -0
- package/dist/schema-management/validate-schema.d.ts.map +1 -0
- package/dist/schema-management/validate-schema.js +39 -0
- package/dist/schema-management/validate-schema.js.map +1 -0
- package/dist/sql-queries/misc.d.ts.map +1 -1
- package/dist/sql-queries/sql-queries.d.ts +1 -1
- package/dist/sql-queries/sql-queries.d.ts.map +1 -1
- package/dist/sql-queries/sql-queries.js.map +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts.map +1 -1
- package/dist/sql-queries/sql-query-builder.js.map +1 -1
- package/dist/sql-queries/types.d.ts +2 -1
- package/dist/sql-queries/types.d.ts.map +1 -1
- package/dist/sql-queries/types.js.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.d.ts +40 -19
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +149 -73
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/next/compact-events.d.ts.map +1 -1
- package/dist/sync/next/compact-events.js +38 -35
- package/dist/sync/next/compact-events.js.map +1 -1
- package/dist/sync/next/facts.d.ts +21 -21
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js +11 -11
- package/dist/sync/next/facts.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts +9 -7
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +10 -5
- package/dist/sync/next/history-dag-common.js.map +1 -1
- package/dist/sync/next/history-dag.d.ts +0 -2
- package/dist/sync/next/history-dag.d.ts.map +1 -1
- package/dist/sync/next/history-dag.js +16 -14
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/next/rebase-events.d.ts +10 -8
- package/dist/sync/next/rebase-events.d.ts.map +1 -1
- package/dist/sync/next/rebase-events.js +18 -10
- package/dist/sync/next/rebase-events.js.map +1 -1
- package/dist/sync/next/test/compact-events.calculator.test.js +39 -34
- package/dist/sync/next/test/compact-events.calculator.test.js.map +1 -1
- package/dist/sync/next/test/compact-events.test.js +77 -77
- package/dist/sync/next/test/compact-events.test.js.map +1 -1
- package/dist/sync/next/test/{mutation-fixtures.d.ts → event-fixtures.d.ts} +35 -25
- package/dist/sync/next/test/event-fixtures.d.ts.map +1 -0
- package/dist/sync/next/test/{mutation-fixtures.js → event-fixtures.js} +81 -38
- package/dist/sync/next/test/event-fixtures.js.map +1 -0
- package/dist/sync/next/test/mod.d.ts +1 -1
- package/dist/sync/next/test/mod.d.ts.map +1 -1
- package/dist/sync/next/test/mod.js +1 -1
- package/dist/sync/next/test/mod.js.map +1 -1
- package/dist/sync/sync.d.ts +46 -21
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/sync.js +10 -6
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/syncstate.d.ts +193 -84
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +305 -151
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +267 -303
- package/dist/sync/syncstate.test.js.map +1 -1
- package/dist/sync/validate-push-payload.d.ts +2 -2
- package/dist/sync/validate-push-payload.d.ts.map +1 -1
- package/dist/sync/validate-push-payload.js +4 -4
- package/dist/sync/validate-push-payload.js.map +1 -1
- package/dist/util.d.ts +2 -2
- package/dist/util.d.ts.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +10 -4
- package/src/__tests__/fixture.ts +36 -15
- package/src/adapter-types.ts +107 -68
- package/src/debug-info.ts +1 -0
- package/src/devtools/devtools-messages-client-session.ts +142 -0
- package/src/devtools/devtools-messages-common.ts +115 -0
- package/src/devtools/devtools-messages-leader.ts +191 -0
- package/src/devtools/devtools-messages.ts +3 -246
- package/src/devtools/devtools-sessioninfo.ts +101 -0
- package/src/devtools/mod.ts +59 -0
- package/src/index.ts +7 -9
- package/src/leader-thread/LeaderSyncProcessor.ts +664 -394
- package/src/leader-thread/connection.ts +54 -9
- package/src/leader-thread/eventlog.ts +199 -0
- package/src/leader-thread/leader-worker-devtools.ts +227 -104
- package/src/leader-thread/make-leader-thread-layer.ts +121 -72
- package/src/leader-thread/materialize-event.ts +173 -0
- package/src/leader-thread/mod.ts +1 -1
- package/src/leader-thread/recreate-db.ts +33 -38
- package/src/leader-thread/shutdown-channel.ts +2 -4
- package/src/leader-thread/types.ts +84 -46
- package/src/make-client-session.ts +136 -0
- package/src/materializer-helper.ts +138 -0
- package/src/otel.ts +8 -0
- package/src/rematerialize-from-eventlog.ts +117 -0
- package/src/schema/EventDef.ts +227 -0
- package/src/schema/EventSequenceNumber.test.ts +12 -0
- package/src/schema/EventSequenceNumber.ts +121 -0
- package/src/schema/LiveStoreEvent.ts +240 -0
- package/src/schema/events.ts +1 -0
- package/src/schema/mod.ts +8 -6
- package/src/schema/schema.ts +88 -84
- package/src/schema/state/mod.ts +2 -0
- package/src/schema/state/sqlite/client-document-def.test.ts +238 -0
- package/src/schema/state/sqlite/client-document-def.ts +444 -0
- package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +142 -0
- package/src/schema/state/sqlite/db-schema/ast/validate.ts +13 -0
- package/src/schema/state/sqlite/db-schema/dsl/__snapshots__/field-defs.test.ts.snap +206 -0
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.test.ts +35 -0
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.ts +242 -0
- package/src/schema/state/sqlite/db-schema/dsl/mod.ts +222 -0
- package/src/schema/state/sqlite/db-schema/hash.ts +14 -0
- package/src/schema/state/sqlite/db-schema/mod.ts +2 -0
- package/src/schema/state/sqlite/mod.ts +73 -0
- package/src/schema/state/sqlite/query-builder/api.ts +440 -0
- package/src/schema/state/sqlite/query-builder/astToSql.ts +232 -0
- package/src/schema/state/sqlite/query-builder/impl.test.ts +617 -0
- package/src/schema/state/sqlite/query-builder/impl.ts +351 -0
- package/src/{query-builder → schema/state/sqlite/query-builder}/mod.ts +7 -0
- package/src/schema/{schema-helpers.ts → state/sqlite/schema-helpers.ts} +1 -1
- package/src/schema/state/sqlite/system-tables.ts +117 -0
- package/src/schema/state/sqlite/table-def.ts +197 -0
- package/src/schema-management/common.ts +7 -7
- package/src/schema-management/migrations.ts +37 -31
- package/src/schema-management/validate-schema.ts +61 -0
- package/src/sql-queries/sql-queries.ts +1 -1
- package/src/sql-queries/sql-query-builder.ts +1 -2
- package/src/sql-queries/types.ts +3 -1
- package/src/sync/ClientSessionSyncProcessor.ts +218 -94
- package/src/sync/next/compact-events.ts +38 -35
- package/src/sync/next/facts.ts +43 -41
- package/src/sync/next/history-dag-common.ts +17 -10
- package/src/sync/next/history-dag.ts +16 -17
- package/src/sync/next/rebase-events.ts +29 -17
- package/src/sync/next/test/compact-events.calculator.test.ts +46 -46
- package/src/sync/next/test/compact-events.test.ts +79 -79
- package/src/sync/next/test/event-fixtures.ts +226 -0
- package/src/sync/next/test/mod.ts +1 -1
- package/src/sync/sync.ts +46 -21
- package/src/sync/syncstate.test.ts +312 -345
- package/src/sync/syncstate.ts +414 -224
- package/src/sync/validate-push-payload.ts +6 -6
- package/src/version.ts +2 -2
- package/dist/derived-mutations.d.ts +0 -109
- package/dist/derived-mutations.d.ts.map +0 -1
- package/dist/derived-mutations.js +0 -54
- package/dist/derived-mutations.js.map +0 -1
- package/dist/derived-mutations.test.d.ts +0 -2
- package/dist/derived-mutations.test.d.ts.map +0 -1
- package/dist/derived-mutations.test.js +0 -93
- package/dist/derived-mutations.test.js.map +0 -1
- package/dist/devtools/devtools-bridge.d.ts +0 -13
- package/dist/devtools/devtools-bridge.d.ts.map +0 -1
- package/dist/devtools/devtools-bridge.js +0 -2
- package/dist/devtools/devtools-bridge.js.map +0 -1
- package/dist/devtools/devtools-window-message.d.ts +0 -29
- package/dist/devtools/devtools-window-message.d.ts.map +0 -1
- package/dist/devtools/devtools-window-message.js +0 -33
- package/dist/devtools/devtools-window-message.js.map +0 -1
- package/dist/devtools/index.d.ts +0 -42
- package/dist/devtools/index.d.ts.map +0 -1
- package/dist/devtools/index.js +0 -48
- package/dist/devtools/index.js.map +0 -1
- package/dist/init-singleton-tables.d.ts +0 -4
- package/dist/init-singleton-tables.d.ts.map +0 -1
- package/dist/init-singleton-tables.js +0 -16
- package/dist/init-singleton-tables.js.map +0 -1
- package/dist/leader-thread/apply-mutation.d.ts +0 -11
- package/dist/leader-thread/apply-mutation.d.ts.map +0 -1
- package/dist/leader-thread/apply-mutation.js +0 -107
- package/dist/leader-thread/apply-mutation.js.map +0 -1
- package/dist/leader-thread/leader-sync-processor.d.ts +0 -47
- package/dist/leader-thread/leader-sync-processor.d.ts.map +0 -1
- package/dist/leader-thread/leader-sync-processor.js +0 -430
- package/dist/leader-thread/leader-sync-processor.js.map +0 -1
- package/dist/leader-thread/mutationlog.d.ts +0 -10
- package/dist/leader-thread/mutationlog.d.ts.map +0 -1
- package/dist/leader-thread/mutationlog.js +0 -28
- package/dist/leader-thread/mutationlog.js.map +0 -1
- package/dist/leader-thread/pull-queue-set.d.ts +0 -7
- package/dist/leader-thread/pull-queue-set.d.ts.map +0 -1
- package/dist/leader-thread/pull-queue-set.js +0 -39
- package/dist/leader-thread/pull-queue-set.js.map +0 -1
- package/dist/mutation.d.ts +0 -20
- package/dist/mutation.d.ts.map +0 -1
- package/dist/mutation.js +0 -57
- package/dist/mutation.js.map +0 -1
- package/dist/query-builder/api.d.ts +0 -190
- package/dist/query-builder/api.d.ts.map +0 -1
- package/dist/query-builder/api.js +0 -8
- package/dist/query-builder/api.js.map +0 -1
- package/dist/query-builder/impl.d.ts +0 -12
- package/dist/query-builder/impl.d.ts.map +0 -1
- package/dist/query-builder/impl.js +0 -244
- package/dist/query-builder/impl.js.map +0 -1
- package/dist/query-builder/impl.test.d.ts +0 -2
- package/dist/query-builder/impl.test.d.ts.map +0 -1
- package/dist/query-builder/impl.test.js +0 -212
- package/dist/query-builder/impl.test.js.map +0 -1
- package/dist/query-builder/mod.d.ts.map +0 -1
- package/dist/query-builder/mod.js.map +0 -1
- package/dist/query-info.d.ts +0 -38
- package/dist/query-info.d.ts.map +0 -1
- package/dist/query-info.js +0 -7
- package/dist/query-info.js.map +0 -1
- package/dist/rehydrate-from-mutationlog.d.ts +0 -14
- package/dist/rehydrate-from-mutationlog.d.ts.map +0 -1
- package/dist/rehydrate-from-mutationlog.js +0 -66
- package/dist/rehydrate-from-mutationlog.js.map +0 -1
- package/dist/schema/EventId.d.ts +0 -39
- package/dist/schema/EventId.d.ts.map +0 -1
- package/dist/schema/EventId.js +0 -38
- package/dist/schema/EventId.js.map +0 -1
- package/dist/schema/EventId.test.d.ts +0 -2
- package/dist/schema/EventId.test.d.ts.map +0 -1
- package/dist/schema/EventId.test.js +0 -11
- package/dist/schema/EventId.test.js.map +0 -1
- package/dist/schema/MutationEvent.d.ts +0 -167
- package/dist/schema/MutationEvent.d.ts.map +0 -1
- package/dist/schema/MutationEvent.js +0 -72
- package/dist/schema/MutationEvent.js.map +0 -1
- package/dist/schema/MutationEvent.test.d.ts +0 -2
- package/dist/schema/MutationEvent.test.d.ts.map +0 -1
- package/dist/schema/MutationEvent.test.js +0 -2
- package/dist/schema/MutationEvent.test.js.map +0 -1
- package/dist/schema/mutations.d.ts +0 -107
- package/dist/schema/mutations.d.ts.map +0 -1
- package/dist/schema/mutations.js +0 -42
- package/dist/schema/mutations.js.map +0 -1
- package/dist/schema/schema-helpers.d.ts.map +0 -1
- package/dist/schema/schema-helpers.js.map +0 -1
- package/dist/schema/system-tables.d.ts +0 -399
- package/dist/schema/system-tables.d.ts.map +0 -1
- package/dist/schema/system-tables.js +0 -59
- package/dist/schema/system-tables.js.map +0 -1
- package/dist/schema/table-def.d.ts +0 -156
- package/dist/schema/table-def.d.ts.map +0 -1
- package/dist/schema/table-def.js +0 -79
- package/dist/schema/table-def.js.map +0 -1
- package/dist/schema-management/validate-mutation-defs.d.ts +0 -8
- package/dist/schema-management/validate-mutation-defs.d.ts.map +0 -1
- package/dist/schema-management/validate-mutation-defs.js +0 -39
- package/dist/schema-management/validate-mutation-defs.js.map +0 -1
- package/dist/sync/client-session-sync-processor.d.ts +0 -45
- package/dist/sync/client-session-sync-processor.d.ts.map +0 -1
- package/dist/sync/client-session-sync-processor.js +0 -131
- package/dist/sync/client-session-sync-processor.js.map +0 -1
- package/dist/sync/next/test/mutation-fixtures.d.ts.map +0 -1
- package/dist/sync/next/test/mutation-fixtures.js.map +0 -1
- package/src/derived-mutations.test.ts +0 -101
- package/src/derived-mutations.ts +0 -170
- package/src/devtools/devtools-bridge.ts +0 -14
- package/src/devtools/devtools-window-message.ts +0 -27
- package/src/devtools/index.ts +0 -48
- package/src/init-singleton-tables.ts +0 -24
- package/src/leader-thread/apply-mutation.ts +0 -161
- package/src/leader-thread/mutationlog.ts +0 -46
- package/src/leader-thread/pull-queue-set.ts +0 -58
- package/src/mutation.ts +0 -91
- package/src/query-builder/api.ts +0 -289
- package/src/query-builder/impl.test.ts +0 -239
- package/src/query-builder/impl.ts +0 -285
- package/src/query-info.ts +0 -78
- package/src/rehydrate-from-mutationlog.ts +0 -119
- package/src/schema/EventId.test.ts +0 -12
- package/src/schema/EventId.ts +0 -60
- package/src/schema/MutationEvent.ts +0 -185
- package/src/schema/mutations.ts +0 -192
- package/src/schema/system-tables.ts +0 -105
- package/src/schema/table-def.ts +0 -343
- package/src/schema-management/validate-mutation-defs.ts +0 -63
- package/src/sync/next/test/mutation-fixtures.ts +0 -224
- package/tsconfig.json +0 -11
- /package/dist/schema/{schema-helpers.d.ts → state/sqlite/schema-helpers.d.ts} +0 -0
@@ -1,27 +0,0 @@
|
|
1
|
-
import { Schema, Transferable } from '@livestore/utils/effect'
|
2
|
-
|
3
|
-
const appHostId = Schema.String
|
4
|
-
|
5
|
-
export namespace DevtoolsWindowMessage {
|
6
|
-
/** Message is being created in contentscript-iframe, sent to contentscript and then sent to Store */
|
7
|
-
export class MessagePortReady extends Schema.TaggedStruct('LSD.WindowMessage.MessagePortReady', {
|
8
|
-
port: Transferable.MessagePort,
|
9
|
-
appHostId,
|
10
|
-
}) {}
|
11
|
-
|
12
|
-
export class ContentscriptListening extends Schema.TaggedStruct('LSD.WindowMessage.ContentscriptListening', {}) {}
|
13
|
-
|
14
|
-
// export class ContentscriptReady extends Schema.TaggedStruct('LSD.WindowMessage.ContentscriptReady', {
|
15
|
-
// appHostId,
|
16
|
-
// }) {}
|
17
|
-
|
18
|
-
export class LoadIframe extends Schema.TaggedStruct('LSD.WindowMessage.LoadIframe', {}) {}
|
19
|
-
|
20
|
-
export class StoreReady extends Schema.TaggedStruct('LSD.WindowMessage.StoreReady', {
|
21
|
-
appHostId,
|
22
|
-
}) {}
|
23
|
-
|
24
|
-
export class MessageForStore extends Schema.Union(MessagePortReady, ContentscriptListening) {}
|
25
|
-
|
26
|
-
export class MessageForContentscript extends Schema.Union(StoreReady, LoadIframe) {}
|
27
|
-
}
|
package/src/devtools/index.ts
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
import type { Effect, Scope } from '@livestore/utils/effect'
|
2
|
-
import { Schema, WebChannel } from '@livestore/utils/effect'
|
3
|
-
|
4
|
-
export * from './devtools-messages.js'
|
5
|
-
export * from './devtools-window-message.js'
|
6
|
-
export * from './devtools-bridge.js'
|
7
|
-
|
8
|
-
export namespace WebBridge {
|
9
|
-
export class AppHostReady extends Schema.TaggedStruct('LSD.WebBridge.AppHostReady', {
|
10
|
-
appHostId: Schema.String,
|
11
|
-
// storeId: Schema.String,
|
12
|
-
isLeader: Schema.Boolean,
|
13
|
-
}) {}
|
14
|
-
|
15
|
-
export class DevtoolsReady extends Schema.TaggedStruct('LSD.WebBridge.DevtoolsReady', {
|
16
|
-
devtoolsId: Schema.String,
|
17
|
-
}) {}
|
18
|
-
|
19
|
-
export class ConnectToDevtools extends Schema.TaggedStruct('LSD.WebBridge.ConnectToDevtools', {
|
20
|
-
devtoolsId: Schema.String,
|
21
|
-
appHostId: Schema.String,
|
22
|
-
/**
|
23
|
-
* Given the m:n relationship between devtools and app hosts and the fact that appHostIds are usually
|
24
|
-
* sticky, we generate a new unique id for the lifetime of the web bridge.
|
25
|
-
*/
|
26
|
-
webBridgeId: Schema.String,
|
27
|
-
isLeader: Schema.Boolean,
|
28
|
-
storeId: Schema.String,
|
29
|
-
}) {}
|
30
|
-
|
31
|
-
export class AppHostWillDisconnect extends Schema.TaggedStruct('LSD.WebBridge.AppHostWillDisconnect', {
|
32
|
-
appHostId: Schema.String,
|
33
|
-
}) {}
|
34
|
-
|
35
|
-
// export class DevtoolsWillDisconnect extends Schema.TaggedStruct('LSD.WebBridge.DevtoolsWillDisconnect', {
|
36
|
-
// appHostId: Schema.String,
|
37
|
-
// }) {}
|
38
|
-
|
39
|
-
export class All extends Schema.Union(AppHostReady, DevtoolsReady, ConnectToDevtools, AppHostWillDisconnect) {}
|
40
|
-
|
41
|
-
export const makeBroadcastChannel = (
|
42
|
-
key?: string,
|
43
|
-
): Effect.Effect<WebChannel.WebChannel<typeof All.Type, typeof All.Type>, never, Scope.Scope> =>
|
44
|
-
WebChannel.broadcastChannel({
|
45
|
-
channelName: `livestore-web-bridge-devtools${key ? `-${key}` : ''}`,
|
46
|
-
schema: All,
|
47
|
-
})
|
48
|
-
}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import type { SynchronousDatabase } from './adapter-types.js'
|
2
|
-
import type { LiveStoreSchema } from './schema/mod.js'
|
3
|
-
import { getDefaultValuesEncoded } from './schema/schema-helpers.js'
|
4
|
-
import { prepareBindValues, sql } from './util.js'
|
5
|
-
|
6
|
-
export const initializeSingletonTables = (schema: LiveStoreSchema, db: SynchronousDatabase) => {
|
7
|
-
for (const [, tableDef] of schema.tables) {
|
8
|
-
if (tableDef.options.isSingleton) {
|
9
|
-
const defaultValues = getDefaultValuesEncoded(tableDef, undefined)
|
10
|
-
|
11
|
-
const defaultColumnNames = [...Object.keys(defaultValues), 'id']
|
12
|
-
const columnValues = defaultColumnNames.map((name) => `$${name}`).join(', ')
|
13
|
-
|
14
|
-
const tableName = tableDef.sqliteDef.name
|
15
|
-
const insertQuery = sql`insert into ${tableName} (${defaultColumnNames.join(
|
16
|
-
', ',
|
17
|
-
)}) select ${columnValues} where not exists(select 1 from ${tableName} where id = 'singleton')`
|
18
|
-
|
19
|
-
const bindValues = prepareBindValues({ ...defaultValues, id: 'singleton' }, insertQuery)
|
20
|
-
|
21
|
-
db.execute(insertQuery, bindValues)
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
@@ -1,161 +0,0 @@
|
|
1
|
-
import { memoizeByRef, shouldNeverHappen } from '@livestore/utils'
|
2
|
-
import type { Scope } from '@livestore/utils/effect'
|
3
|
-
import { Effect, Option, Schema } from '@livestore/utils/effect'
|
4
|
-
|
5
|
-
import type { SqliteError, SynchronousDatabase, UnexpectedError } from '../index.js'
|
6
|
-
import { getExecArgsFromMutation } from '../mutation.js'
|
7
|
-
import {
|
8
|
-
type LiveStoreSchema,
|
9
|
-
MUTATION_LOG_META_TABLE,
|
10
|
-
type MutationEvent,
|
11
|
-
mutationLogMetaTable,
|
12
|
-
SESSION_CHANGESET_META_TABLE,
|
13
|
-
sessionChangesetMetaTable,
|
14
|
-
} from '../schema/mod.js'
|
15
|
-
import { insertRow } from '../sql-queries/index.js'
|
16
|
-
import { execSql, execSqlPrepared } from './connection.js'
|
17
|
-
import { LeaderThreadCtx } from './types.js'
|
18
|
-
|
19
|
-
export type ApplyMutation = (
|
20
|
-
mutationEventEncoded: MutationEvent.AnyEncoded,
|
21
|
-
options?: {
|
22
|
-
/** Needed for rehydrateFromMutationLog */
|
23
|
-
skipMutationLog?: boolean
|
24
|
-
},
|
25
|
-
) => Effect.Effect<void, SqliteError | UnexpectedError>
|
26
|
-
|
27
|
-
export const makeApplyMutation: Effect.Effect<ApplyMutation, never, Scope.Scope | LeaderThreadCtx> = Effect.gen(
|
28
|
-
function* () {
|
29
|
-
const leaderThreadCtx = yield* LeaderThreadCtx
|
30
|
-
const shouldExcludeMutationFromLog = makeShouldExcludeMutationFromLog(leaderThreadCtx.schema)
|
31
|
-
|
32
|
-
const mutationDefSchemaHashMap = new Map(
|
33
|
-
// TODO Running `Schema.hash` can be a bottleneck for larger schemas. There is an opportunity to run this
|
34
|
-
// at build time and lookup the pre-computed hash at runtime.
|
35
|
-
// Also see https://github.com/Effect-TS/effect/issues/2719
|
36
|
-
[...leaderThreadCtx.schema.mutations.entries()].map(([k, v]) => [k, Schema.hash(v.schema)] as const),
|
37
|
-
)
|
38
|
-
|
39
|
-
return (mutationEventEncoded, options) =>
|
40
|
-
Effect.gen(function* () {
|
41
|
-
const { schema, db, dbLog } = leaderThreadCtx
|
42
|
-
const skipMutationLog = options?.skipMutationLog ?? false
|
43
|
-
|
44
|
-
const mutationName = mutationEventEncoded.mutation
|
45
|
-
const mutationDef = schema.mutations.get(mutationName) ?? shouldNeverHappen(`Unknown mutation: ${mutationName}`)
|
46
|
-
|
47
|
-
const execArgsArr = getExecArgsFromMutation({
|
48
|
-
mutationDef,
|
49
|
-
mutationEvent: { decoded: undefined, encoded: mutationEventEncoded },
|
50
|
-
})
|
51
|
-
|
52
|
-
// NOTE we might want to bring this back if we want to debug no-op mutations
|
53
|
-
// const makeExecuteOptions = (statementSql: string, bindValues: any) => ({
|
54
|
-
// onRowsChanged: (rowsChanged: number) => {
|
55
|
-
// if (rowsChanged === 0) {
|
56
|
-
// console.warn(`Mutation "${mutationDef.name}" did not affect any rows:`, statementSql, bindValues)
|
57
|
-
// }
|
58
|
-
// },
|
59
|
-
// })
|
60
|
-
|
61
|
-
// console.group('[@livestore/common:leader-thread:applyMutation]', { mutationName })
|
62
|
-
|
63
|
-
const session = db.session()
|
64
|
-
|
65
|
-
for (const { statementSql, bindValues } of execArgsArr) {
|
66
|
-
// console.debug(mutationName, statementSql, bindValues)
|
67
|
-
// TODO use cached prepared statements instead of exec
|
68
|
-
yield* execSqlPrepared(db, statementSql, bindValues)
|
69
|
-
}
|
70
|
-
|
71
|
-
const changeset = session.changeset()
|
72
|
-
session.finish()
|
73
|
-
|
74
|
-
// TODO use prepared statements
|
75
|
-
yield* execSql(
|
76
|
-
db,
|
77
|
-
...insertRow({
|
78
|
-
tableName: SESSION_CHANGESET_META_TABLE,
|
79
|
-
columns: sessionChangesetMetaTable.sqliteDef.columns,
|
80
|
-
values: {
|
81
|
-
idGlobal: mutationEventEncoded.id.global,
|
82
|
-
idLocal: mutationEventEncoded.id.local,
|
83
|
-
// NOTE the changeset will be empty (i.e. null) for no-op mutations
|
84
|
-
changeset: changeset ?? null,
|
85
|
-
debug: execArgsArr,
|
86
|
-
},
|
87
|
-
}),
|
88
|
-
)
|
89
|
-
|
90
|
-
// console.groupEnd()
|
91
|
-
|
92
|
-
// write to mutation_log
|
93
|
-
const excludeFromMutationLog = shouldExcludeMutationFromLog(mutationName, mutationEventEncoded)
|
94
|
-
if (skipMutationLog === false && excludeFromMutationLog === false) {
|
95
|
-
yield* insertIntoMutationLog(mutationEventEncoded, dbLog, mutationDefSchemaHashMap)
|
96
|
-
} else {
|
97
|
-
// console.debug('[@livestore/common:leader-thread] skipping mutation log write', mutation, statementSql, bindValues)
|
98
|
-
}
|
99
|
-
}).pipe(
|
100
|
-
Effect.withSpan(`@livestore/common:leader-thread:applyMutation`, {
|
101
|
-
attributes: {
|
102
|
-
mutationName: mutationEventEncoded.mutation,
|
103
|
-
mutationId: mutationEventEncoded.id,
|
104
|
-
'span.label': `(${mutationEventEncoded.id.global},${mutationEventEncoded.id.local}) ${mutationEventEncoded.mutation}`,
|
105
|
-
},
|
106
|
-
}),
|
107
|
-
// Effect.logDuration('@livestore/common:leader-thread:applyMutation'),
|
108
|
-
)
|
109
|
-
},
|
110
|
-
)
|
111
|
-
|
112
|
-
const insertIntoMutationLog = (
|
113
|
-
mutationEventEncoded: MutationEvent.AnyEncoded,
|
114
|
-
dbLog: SynchronousDatabase,
|
115
|
-
mutationDefSchemaHashMap: Map<string, number>,
|
116
|
-
) =>
|
117
|
-
Effect.gen(function* () {
|
118
|
-
const mutationName = mutationEventEncoded.mutation
|
119
|
-
const mutationDefSchemaHash =
|
120
|
-
mutationDefSchemaHashMap.get(mutationName) ?? shouldNeverHappen(`Unknown mutation: ${mutationName}`)
|
121
|
-
|
122
|
-
// TODO use prepared statements
|
123
|
-
yield* execSql(
|
124
|
-
dbLog,
|
125
|
-
...insertRow({
|
126
|
-
tableName: MUTATION_LOG_META_TABLE,
|
127
|
-
columns: mutationLogMetaTable.sqliteDef.columns,
|
128
|
-
values: {
|
129
|
-
idGlobal: mutationEventEncoded.id.global,
|
130
|
-
idLocal: mutationEventEncoded.id.local,
|
131
|
-
parentIdGlobal: mutationEventEncoded.parentId.global,
|
132
|
-
parentIdLocal: mutationEventEncoded.parentId.local,
|
133
|
-
mutation: mutationEventEncoded.mutation,
|
134
|
-
argsJson: mutationEventEncoded.args ?? {},
|
135
|
-
schemaHash: mutationDefSchemaHash,
|
136
|
-
syncMetadataJson: Option.none(),
|
137
|
-
},
|
138
|
-
}),
|
139
|
-
)
|
140
|
-
})
|
141
|
-
|
142
|
-
// TODO let's consider removing this "should exclude" mechanism in favour of log compaction etc
|
143
|
-
const makeShouldExcludeMutationFromLog = memoizeByRef((schema: LiveStoreSchema) => {
|
144
|
-
const migrationOptions = schema.migrationOptions
|
145
|
-
const mutationLogExclude =
|
146
|
-
migrationOptions.strategy === 'from-mutation-log'
|
147
|
-
? (migrationOptions.excludeMutations ?? new Set(['livestore.RawSql']))
|
148
|
-
: new Set(['livestore.RawSql'])
|
149
|
-
|
150
|
-
return (mutationName: string, mutationEventEncoded: MutationEvent.AnyEncoded): boolean => {
|
151
|
-
if (mutationLogExclude.has(mutationName)) return true
|
152
|
-
|
153
|
-
const mutationDef = schema.mutations.get(mutationName) ?? shouldNeverHappen(`Unknown mutation: ${mutationName}`)
|
154
|
-
const execArgsArr = getExecArgsFromMutation({
|
155
|
-
mutationDef,
|
156
|
-
mutationEvent: { decoded: undefined, encoded: mutationEventEncoded },
|
157
|
-
})
|
158
|
-
|
159
|
-
return execArgsArr.some((_) => _.statementSql.includes('__livestore'))
|
160
|
-
}
|
161
|
-
})
|
@@ -1,46 +0,0 @@
|
|
1
|
-
import { Effect, Schema } from '@livestore/utils/effect'
|
2
|
-
|
3
|
-
import type { SynchronousDatabase } from '../adapter-types.js'
|
4
|
-
import * as EventId from '../schema/EventId.js'
|
5
|
-
import type * as MutationEvent from '../schema/MutationEvent.js'
|
6
|
-
import { MUTATION_LOG_META_TABLE, mutationLogMetaTable, SYNC_STATUS_TABLE } from '../schema/system-tables.js'
|
7
|
-
import { prepareBindValues, sql } from '../util.js'
|
8
|
-
import { LeaderThreadCtx } from './types.js'
|
9
|
-
|
10
|
-
export const getMutationEventsSince = (
|
11
|
-
since: EventId.EventId,
|
12
|
-
): Effect.Effect<ReadonlyArray<MutationEvent.AnyEncoded>, never, LeaderThreadCtx> =>
|
13
|
-
Effect.gen(function* () {
|
14
|
-
const { dbLog } = yield* LeaderThreadCtx
|
15
|
-
|
16
|
-
const query = mutationLogMetaTable.query.where('idGlobal', '>=', since.global).asSql()
|
17
|
-
const pendingMutationEventsRaw = dbLog.select(query.query, prepareBindValues(query.bindValues, query.query))
|
18
|
-
const pendingMutationEvents = Schema.decodeUnknownSync(mutationLogMetaTable.schema.pipe(Schema.Array))(
|
19
|
-
pendingMutationEventsRaw,
|
20
|
-
)
|
21
|
-
|
22
|
-
return pendingMutationEvents
|
23
|
-
.map((_) => ({
|
24
|
-
mutation: _.mutation,
|
25
|
-
args: _.argsJson,
|
26
|
-
id: { global: _.idGlobal, local: _.idLocal },
|
27
|
-
parentId: { global: _.parentIdGlobal, local: _.parentIdLocal },
|
28
|
-
}))
|
29
|
-
.filter((_) => EventId.compare(_.id, since) > 0)
|
30
|
-
})
|
31
|
-
|
32
|
-
export const getLocalHeadFromDb = (dbLog: SynchronousDatabase): EventId.EventId => {
|
33
|
-
const res = dbLog.select<{ idGlobal: EventId.GlobalEventId; idLocal: EventId.LocalEventId }>(
|
34
|
-
sql`select idGlobal, idLocal from ${MUTATION_LOG_META_TABLE} order by idGlobal DESC, idLocal DESC limit 1`,
|
35
|
-
)[0]
|
36
|
-
|
37
|
-
return res ? { global: res.idGlobal, local: res.idLocal } : EventId.ROOT
|
38
|
-
}
|
39
|
-
|
40
|
-
export const getBackendHeadFromDb = (dbLog: SynchronousDatabase): EventId.GlobalEventId =>
|
41
|
-
dbLog.select<{ head: EventId.GlobalEventId }>(sql`select head from ${SYNC_STATUS_TABLE}`)[0]?.head ??
|
42
|
-
EventId.ROOT.global
|
43
|
-
|
44
|
-
// TODO use prepared statements
|
45
|
-
export const updateBackendHead = (dbLog: SynchronousDatabase, head: EventId.EventId) =>
|
46
|
-
dbLog.execute(sql`UPDATE ${SYNC_STATUS_TABLE} SET head = ${head.global}`)
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import { Effect, Queue } from '@livestore/utils/effect'
|
2
|
-
|
3
|
-
import * as MutationEvent from '../schema/MutationEvent.js'
|
4
|
-
import { getMutationEventsSince } from './mutationlog.js'
|
5
|
-
import { type PullQueueItem, type PullQueueSet } from './types.js'
|
6
|
-
|
7
|
-
export const makePullQueueSet = Effect.gen(function* () {
|
8
|
-
const set = new Set<Queue.Queue<PullQueueItem>>()
|
9
|
-
|
10
|
-
yield* Effect.addFinalizer(() =>
|
11
|
-
Effect.gen(function* () {
|
12
|
-
for (const queue of set) {
|
13
|
-
yield* Queue.shutdown(queue)
|
14
|
-
}
|
15
|
-
|
16
|
-
set.clear()
|
17
|
-
}),
|
18
|
-
)
|
19
|
-
|
20
|
-
const makeQueue: PullQueueSet['makeQueue'] = (since) =>
|
21
|
-
Effect.gen(function* () {
|
22
|
-
const queue = yield* Queue.unbounded<PullQueueItem>().pipe(Effect.acquireRelease(Queue.shutdown))
|
23
|
-
|
24
|
-
yield* Effect.addFinalizer(() => Effect.sync(() => set.delete(queue)))
|
25
|
-
|
26
|
-
const mutationEvents = yield* getMutationEventsSince(since)
|
27
|
-
|
28
|
-
if (mutationEvents.length > 0) {
|
29
|
-
const newEvents = mutationEvents.map((mutationEvent) => new MutationEvent.EncodedWithMeta(mutationEvent))
|
30
|
-
yield* queue.offer({ payload: { _tag: 'upstream-advance', newEvents }, remaining: 0 })
|
31
|
-
}
|
32
|
-
|
33
|
-
set.add(queue)
|
34
|
-
|
35
|
-
return queue
|
36
|
-
})
|
37
|
-
|
38
|
-
const offer: PullQueueSet['offer'] = (item) =>
|
39
|
-
Effect.gen(function* () {
|
40
|
-
// Short-circuit if the payload is an empty upstream advance
|
41
|
-
if (
|
42
|
-
item.payload._tag === 'upstream-advance' &&
|
43
|
-
item.payload.newEvents.length === 0 &&
|
44
|
-
item.payload.trimRollbackUntil === undefined
|
45
|
-
) {
|
46
|
-
return
|
47
|
-
}
|
48
|
-
|
49
|
-
for (const queue of set) {
|
50
|
-
yield* Queue.offer(queue, item)
|
51
|
-
}
|
52
|
-
})
|
53
|
-
|
54
|
-
return {
|
55
|
-
makeQueue,
|
56
|
-
offer,
|
57
|
-
}
|
58
|
-
})
|
package/src/mutation.ts
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
import { Schema } from '@livestore/utils/effect'
|
2
|
-
|
3
|
-
import { SessionIdSymbol } from './adapter-types.js'
|
4
|
-
import type * as MutationEvent from './schema/MutationEvent.js'
|
5
|
-
import type { MutationDef } from './schema/mutations.js'
|
6
|
-
import type { PreparedBindValues } from './util.js'
|
7
|
-
import { prepareBindValues } from './util.js'
|
8
|
-
|
9
|
-
export const getExecArgsFromMutation = ({
|
10
|
-
mutationDef,
|
11
|
-
mutationEvent,
|
12
|
-
}: {
|
13
|
-
mutationDef: MutationDef.Any
|
14
|
-
/** Both encoded and decoded mutation events are supported to reduce the number of times we need to decode/encode */
|
15
|
-
mutationEvent:
|
16
|
-
| {
|
17
|
-
decoded: MutationEvent.AnyDecoded | MutationEvent.PartialAnyDecoded
|
18
|
-
encoded: undefined
|
19
|
-
}
|
20
|
-
| {
|
21
|
-
decoded: undefined
|
22
|
-
encoded: MutationEvent.AnyEncoded | MutationEvent.PartialAnyEncoded
|
23
|
-
}
|
24
|
-
}): ReadonlyArray<{
|
25
|
-
statementSql: string
|
26
|
-
bindValues: PreparedBindValues
|
27
|
-
writeTables: ReadonlySet<string> | undefined
|
28
|
-
}> => {
|
29
|
-
let statementRes: ReadonlyArray<
|
30
|
-
string | { sql: string; bindValues: Record<string, unknown>; writeTables?: ReadonlySet<string> }
|
31
|
-
>
|
32
|
-
|
33
|
-
switch (typeof mutationDef.sql) {
|
34
|
-
case 'function': {
|
35
|
-
const mutationArgsDecoded =
|
36
|
-
mutationEvent.decoded?.args ?? Schema.decodeUnknownSync(mutationDef.schema)(mutationEvent.encoded!.args)
|
37
|
-
const res = mutationDef.sql(mutationArgsDecoded)
|
38
|
-
statementRes = Array.isArray(res) ? res : [res]
|
39
|
-
break
|
40
|
-
}
|
41
|
-
case 'string': {
|
42
|
-
statementRes = [mutationDef.sql]
|
43
|
-
break
|
44
|
-
}
|
45
|
-
default: {
|
46
|
-
statementRes = mutationDef.sql
|
47
|
-
break
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
return statementRes.map((statementRes) => {
|
52
|
-
const statementSql = typeof statementRes === 'string' ? statementRes : statementRes.sql
|
53
|
-
|
54
|
-
const mutationArgsEncoded =
|
55
|
-
mutationEvent.encoded?.args ?? Schema.encodeUnknownSync(mutationDef.schema)(mutationEvent.decoded!.args)
|
56
|
-
const bindValues = typeof statementRes === 'string' ? mutationArgsEncoded : statementRes.bindValues
|
57
|
-
|
58
|
-
const writeTables = typeof statementRes === 'string' ? undefined : statementRes.writeTables
|
59
|
-
|
60
|
-
return { statementSql, bindValues: prepareBindValues(bindValues ?? {}, statementSql), writeTables }
|
61
|
-
})
|
62
|
-
}
|
63
|
-
|
64
|
-
// NOTE we should explore whether there is a more elegant solution
|
65
|
-
// e.g. by leveraging the schema to replace the sessionIdSymbol
|
66
|
-
export const replaceSessionIdSymbol = (
|
67
|
-
bindValues: Record<string, unknown> | ReadonlyArray<unknown>,
|
68
|
-
sessionId: string,
|
69
|
-
) => {
|
70
|
-
deepReplaceValue(bindValues, SessionIdSymbol, sessionId)
|
71
|
-
}
|
72
|
-
|
73
|
-
const deepReplaceValue = <S, R>(input: any, searchValue: S, replaceValue: R): void => {
|
74
|
-
if (Array.isArray(input)) {
|
75
|
-
for (const i in input) {
|
76
|
-
if (input[i] === searchValue) {
|
77
|
-
input[i] = replaceValue
|
78
|
-
} else {
|
79
|
-
deepReplaceValue(input[i], searchValue, replaceValue)
|
80
|
-
}
|
81
|
-
}
|
82
|
-
} else if (typeof input === 'object' && input !== null) {
|
83
|
-
for (const key in input) {
|
84
|
-
if (input[key] === searchValue) {
|
85
|
-
input[key] = replaceValue
|
86
|
-
} else {
|
87
|
-
deepReplaceValue(input[key], searchValue, replaceValue)
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|