@livestore/common 0.3.0-dev.4 → 0.3.0-dev.40
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 +132 -75
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +36 -7
- 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 -592
- package/dist/devtools/devtools-messages.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.js +3 -171
- 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 -13
- 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 +62 -0
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -0
- package/dist/leader-thread/LeaderSyncProcessor.js +593 -0
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -0
- 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 +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +165 -134
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +26 -12
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +76 -48
- 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 +105 -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 +33 -31
- 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 +89 -40
- 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 +21 -0
- package/dist/make-client-session.d.ts.map +1 -0
- package/dist/make-client-session.js +51 -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 +84 -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/EventId.d.ts +35 -15
- package/dist/schema/EventId.d.ts.map +1 -1
- package/dist/schema/EventId.js +57 -11
- package/dist/schema/EventId.js.map +1 -1
- package/dist/schema/EventId.test.d.ts +2 -0
- package/dist/schema/EventId.test.d.ts.map +1 -0
- package/dist/schema/EventId.test.js +11 -0
- package/dist/schema/EventId.test.js.map +1 -0
- package/dist/schema/LiveStoreEvent.d.ts +255 -0
- package/dist/schema/LiveStoreEvent.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent.js +118 -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 +7 -5
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +7 -5
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts +48 -30
- 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 +554 -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 +87 -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 +33 -24
- 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 +66 -0
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -0
- package/dist/sync/ClientSessionSyncProcessor.js +209 -0
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -0
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +1 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/next/compact-events.d.ts.map +1 -1
- package/dist/sync/next/facts.d.ts +19 -19
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js +3 -3
- package/dist/sync/next/facts.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts +6 -7
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +4 -2
- package/dist/sync/next/history-dag-common.js.map +1 -1
- package/dist/sync/next/history-dag.d.ts.map +1 -1
- package/dist/sync/next/history-dag.js +2 -2
- 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 +11 -8
- package/dist/sync/next/rebase-events.js.map +1 -1
- package/dist/sync/next/test/compact-events.calculator.test.js +38 -33
- package/dist/sync/next/test/compact-events.calculator.test.js.map +1 -1
- package/dist/sync/next/test/compact-events.test.js +76 -76
- 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} +25 -25
- package/dist/sync/next/test/event-fixtures.d.ts.map +1 -0
- package/dist/sync/next/test/{mutation-fixtures.js → event-fixtures.js} +67 -36
- 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 +55 -20
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/sync.js +7 -3
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/syncstate.d.ts +213 -82
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +319 -120
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +295 -275
- 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 +2 -2
- 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 +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +13 -6
- package/src/__tests__/fixture.ts +36 -15
- package/src/adapter-types.ts +116 -83
- 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 -243
- package/src/devtools/devtools-sessioninfo.ts +101 -0
- package/src/devtools/mod.ts +59 -0
- package/src/index.ts +7 -15
- package/src/leader-thread/LeaderSyncProcessor.ts +933 -0
- package/src/leader-thread/connection.ts +54 -9
- package/src/leader-thread/eventlog.ts +194 -0
- package/src/leader-thread/leader-worker-devtools.ts +235 -191
- package/src/leader-thread/make-leader-thread-layer.ts +138 -78
- package/src/leader-thread/materialize-event.ts +169 -0
- package/src/leader-thread/mod.ts +1 -1
- package/src/leader-thread/recreate-db.ts +38 -39
- package/src/leader-thread/shutdown-channel.ts +2 -4
- package/src/leader-thread/types.ts +98 -53
- package/src/make-client-session.ts +119 -0
- package/src/materializer-helper.ts +135 -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/EventId.test.ts +12 -0
- package/src/schema/EventId.ts +75 -15
- package/src/schema/LiveStoreEvent.ts +239 -0
- package/src/schema/events.ts +1 -0
- package/src/schema/mod.ts +7 -5
- package/src/schema/schema.ts +85 -81
- 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 +608 -0
- package/src/schema/state/sqlite/query-builder/impl.ts +350 -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 +116 -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 +43 -37
- 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 +332 -0
- package/src/sync/index.ts +1 -1
- package/src/sync/next/facts.ts +32 -33
- package/src/sync/next/history-dag-common.ts +9 -5
- package/src/sync/next/history-dag.ts +2 -2
- package/src/sync/next/rebase-events.ts +22 -16
- package/src/sync/next/test/compact-events.calculator.test.ts +45 -45
- package/src/sync/next/test/compact-events.test.ts +78 -78
- package/src/sync/next/test/event-fixtures.ts +219 -0
- package/src/sync/next/test/mod.ts +1 -1
- package/src/sync/sync.ts +51 -19
- package/src/sync/syncstate.test.ts +335 -308
- package/src/sync/syncstate.ts +394 -212
- package/src/sync/validate-push-payload.ts +7 -4
- package/src/version.ts +1 -1
- 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 -12
- 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 -8
- package/dist/leader-thread/apply-mutation.d.ts.map +0 -1
- package/dist/leader-thread/apply-mutation.js +0 -95
- 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 -422
- package/dist/leader-thread/leader-sync-processor.js.map +0 -1
- package/dist/leader-thread/mutationlog.d.ts +0 -23
- package/dist/leader-thread/mutationlog.d.ts.map +0 -1
- package/dist/leader-thread/mutationlog.js +0 -27
- 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 -13
- 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 -72
- package/dist/rehydrate-from-mutationlog.js.map +0 -1
- package/dist/schema/MutationEvent.d.ts +0 -191
- package/dist/schema/MutationEvent.d.ts.map +0 -1
- package/dist/schema/MutationEvent.js +0 -56
- package/dist/schema/MutationEvent.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 -51
- 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 -166
- package/src/devtools/devtools-bridge.ts +0 -13
- 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 -143
- package/src/leader-thread/leader-sync-processor.ts +0 -666
- package/src/leader-thread/mutationlog.ts +0 -42
- package/src/leader-thread/pull-queue-set.ts +0 -58
- package/src/mutation.ts +0 -81
- 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 -127
- package/src/schema/MutationEvent.ts +0 -161
- package/src/schema/mutations.ts +0 -192
- package/src/schema/system-tables.ts +0 -97
- package/src/schema/table-def.ts +0 -343
- package/src/schema-management/validate-mutation-defs.ts +0 -63
- package/src/sync/client-session-sync-processor.ts +0 -207
- package/src/sync/next/test/mutation-fixtures.ts +0 -231
- package/tsconfig.json +0 -11
- /package/dist/schema/{schema-helpers.d.ts → state/sqlite/schema-helpers.d.ts} +0 -0
@@ -0,0 +1,227 @@
|
|
1
|
+
import type { SingleOrReadonlyArray } from '@livestore/utils'
|
2
|
+
import { shouldNeverHappen } from '@livestore/utils'
|
3
|
+
import { Schema } from '@livestore/utils/effect'
|
4
|
+
|
5
|
+
import type { BindValues } from '../sql-queries/sql-queries.js'
|
6
|
+
import type { ParamsObject } from '../util.js'
|
7
|
+
import type { QueryBuilder } from './state/sqlite/query-builder/mod.js'
|
8
|
+
|
9
|
+
export type EventDefMap = {
|
10
|
+
map: Map<string | 'livestore.RawSql', EventDef.Any>
|
11
|
+
}
|
12
|
+
export type EventDefRecord = {
|
13
|
+
'livestore.RawSql': RawSqlEvent
|
14
|
+
[name: string]: EventDef.Any
|
15
|
+
}
|
16
|
+
|
17
|
+
export type EventDef<TName extends string, TType, TEncoded = TType, TDerived extends boolean = false> = {
|
18
|
+
name: TName
|
19
|
+
schema: Schema.Schema<TType, TEncoded>
|
20
|
+
options: {
|
21
|
+
/**
|
22
|
+
* When set to true, the mutation won't be synced across clients but
|
23
|
+
*/
|
24
|
+
clientOnly: boolean
|
25
|
+
/** Warning: This feature is not fully implemented yet */
|
26
|
+
facts: FactsCallback<TType> | undefined
|
27
|
+
derived: TDerived
|
28
|
+
}
|
29
|
+
|
30
|
+
/** Helper function to construct a partial mutation event */
|
31
|
+
(args: TType): {
|
32
|
+
name: TName
|
33
|
+
args: TType
|
34
|
+
}
|
35
|
+
|
36
|
+
readonly Event: {
|
37
|
+
name: TName
|
38
|
+
args: TType
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
export type FactsCallback<TTo> = (
|
43
|
+
args: TTo,
|
44
|
+
currentFacts: EventDefFacts,
|
45
|
+
) => {
|
46
|
+
modify: {
|
47
|
+
set: Iterable<EventDefFactInput>
|
48
|
+
unset: Iterable<EventDefFactInput>
|
49
|
+
}
|
50
|
+
require: Iterable<EventDefFactInput>
|
51
|
+
}
|
52
|
+
|
53
|
+
export namespace EventDef {
|
54
|
+
export type Any = EventDef<string, any, any, boolean>
|
55
|
+
|
56
|
+
export type AnyWithoutFn = Pick<Any, 'name' | 'schema' | 'options'>
|
57
|
+
}
|
58
|
+
|
59
|
+
export type EventDefKey = string
|
60
|
+
export type EventDefFact = string
|
61
|
+
export type EventDefFacts = ReadonlyMap<string, any>
|
62
|
+
|
63
|
+
export type EventDefFactsGroup = {
|
64
|
+
modifySet: EventDefFacts
|
65
|
+
modifyUnset: EventDefFacts
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Events on independent "dependency" branches are commutative which can facilitate more prioritized syncing
|
69
|
+
*/
|
70
|
+
depRequire: EventDefFacts
|
71
|
+
depRead: EventDefFacts
|
72
|
+
}
|
73
|
+
|
74
|
+
export type EventDefFactsSnapshot = Map<string, any>
|
75
|
+
|
76
|
+
export type EventDefFactInput = string | readonly [string, any]
|
77
|
+
|
78
|
+
export const defineFacts = <
|
79
|
+
TRecord extends Record<string, EventDefFactInput | ((...args: any[]) => EventDefFactInput)>,
|
80
|
+
>(
|
81
|
+
record: TRecord,
|
82
|
+
): TRecord => record
|
83
|
+
|
84
|
+
export type DefineEventOptions<TTo, TDerived extends boolean = false> = {
|
85
|
+
// TODO actually implement this
|
86
|
+
// onError?: (error: any) => void
|
87
|
+
/** Warning: This feature is not fully implemented yet */
|
88
|
+
facts?: (
|
89
|
+
args: TTo,
|
90
|
+
currentFacts: EventDefFacts,
|
91
|
+
) => {
|
92
|
+
modify?: {
|
93
|
+
set?: Iterable<EventDefFactInput>
|
94
|
+
unset?: Iterable<EventDefFactInput>
|
95
|
+
}
|
96
|
+
/**
|
97
|
+
* Two purposes: constrain history and constrain compaction
|
98
|
+
*/
|
99
|
+
require?: Iterable<EventDefFactInput>
|
100
|
+
}
|
101
|
+
/**
|
102
|
+
* When set to true, the event won't be synced over the network
|
103
|
+
*/
|
104
|
+
clientOnly?: boolean
|
105
|
+
derived?: TDerived
|
106
|
+
}
|
107
|
+
|
108
|
+
export const defineEvent = <TName extends string, TType, TEncoded = TType, TDerived extends boolean = false>(
|
109
|
+
args: {
|
110
|
+
name: TName
|
111
|
+
schema: Schema.Schema<TType, TEncoded>
|
112
|
+
} & DefineEventOptions<TType, TDerived>,
|
113
|
+
): EventDef<TName, TType, TEncoded, TDerived> => {
|
114
|
+
const { name, schema, ...options } = args
|
115
|
+
|
116
|
+
const makePartialEvent = (args: TType) => {
|
117
|
+
const res = Schema.validateEither(schema)(args)
|
118
|
+
if (res._tag === 'Left') {
|
119
|
+
shouldNeverHappen(`Invalid event args for event '${name}':`, res.left.message, '\n')
|
120
|
+
}
|
121
|
+
return { name: name, args }
|
122
|
+
}
|
123
|
+
|
124
|
+
Object.defineProperty(makePartialEvent, 'name', { value: name })
|
125
|
+
Object.defineProperty(makePartialEvent, 'schema', { value: schema })
|
126
|
+
Object.defineProperty(makePartialEvent, 'options', {
|
127
|
+
value: {
|
128
|
+
clientOnly: options?.clientOnly ?? false,
|
129
|
+
facts: options?.facts
|
130
|
+
? (args, currentFacts) => {
|
131
|
+
const res = options.facts!(args, currentFacts)
|
132
|
+
return {
|
133
|
+
modify: {
|
134
|
+
set: res.modify?.set ? new Set(res.modify.set) : new Set(),
|
135
|
+
unset: res.modify?.unset ? new Set(res.modify.unset) : new Set(),
|
136
|
+
},
|
137
|
+
require: res.require ? new Set(res.require) : new Set(),
|
138
|
+
}
|
139
|
+
}
|
140
|
+
: undefined,
|
141
|
+
derived: options?.derived ?? false,
|
142
|
+
} satisfies EventDef.Any['options'],
|
143
|
+
})
|
144
|
+
|
145
|
+
return makePartialEvent as EventDef<TName, TType, TEncoded, TDerived>
|
146
|
+
}
|
147
|
+
|
148
|
+
export const synced = <TName extends string, TType, TEncoded = TType>(
|
149
|
+
args: {
|
150
|
+
name: TName
|
151
|
+
schema: Schema.Schema<TType, TEncoded>
|
152
|
+
} & Omit<DefineEventOptions<TType, false>, 'derived' | 'clientOnly'>,
|
153
|
+
): EventDef<TName, TType, TEncoded> => defineEvent({ ...args, clientOnly: false })
|
154
|
+
|
155
|
+
export const clientOnly = <TName extends string, TType, TEncoded = TType>(
|
156
|
+
args: {
|
157
|
+
name: TName
|
158
|
+
schema: Schema.Schema<TType, TEncoded>
|
159
|
+
} & Omit<DefineEventOptions<TType, false>, 'derived' | 'clientOnly'>,
|
160
|
+
): EventDef<TName, TType, TEncoded> => defineEvent({ ...args, clientOnly: true })
|
161
|
+
|
162
|
+
export type MaterializerResult =
|
163
|
+
| {
|
164
|
+
sql: string
|
165
|
+
bindValues: BindValues
|
166
|
+
writeTables?: ReadonlySet<string>
|
167
|
+
}
|
168
|
+
| QueryBuilder.Any
|
169
|
+
| string
|
170
|
+
|
171
|
+
export type MaterializerContextQuery = {
|
172
|
+
(args: { query: string; bindValues: ParamsObject }): ReadonlyArray<unknown>
|
173
|
+
<TResult>(qb: QueryBuilder<TResult, any, any>): TResult
|
174
|
+
}
|
175
|
+
|
176
|
+
export type Materializer<TEventDef extends EventDef.AnyWithoutFn = EventDef.AnyWithoutFn> = (
|
177
|
+
event: TEventDef['schema']['Type'],
|
178
|
+
context: {
|
179
|
+
currentFacts: EventDefFacts
|
180
|
+
eventDef: TEventDef
|
181
|
+
/** Can be used to query the current state */
|
182
|
+
query: MaterializerContextQuery
|
183
|
+
},
|
184
|
+
) => SingleOrReadonlyArray<MaterializerResult>
|
185
|
+
|
186
|
+
export const defineMaterializer = <TEventDef extends EventDef.AnyWithoutFn>(
|
187
|
+
eventDef: TEventDef,
|
188
|
+
materializer: Materializer<TEventDef>,
|
189
|
+
): Materializer<TEventDef> => {
|
190
|
+
return materializer
|
191
|
+
}
|
192
|
+
|
193
|
+
export const materializers = <TInputRecord extends Record<string, EventDef.AnyWithoutFn>>(
|
194
|
+
eventDefRecord: TInputRecord,
|
195
|
+
handlers: {
|
196
|
+
[TEventName in TInputRecord[keyof TInputRecord]['name'] as Extract<
|
197
|
+
TInputRecord[keyof TInputRecord],
|
198
|
+
{ name: TEventName }
|
199
|
+
>['options']['derived'] extends true
|
200
|
+
? never
|
201
|
+
: TEventName]: Materializer<Extract<TInputRecord[keyof TInputRecord], { name: TEventName }>>
|
202
|
+
// [K in TInputRecord[keyof TInputRecord]['name']]: Materializer<
|
203
|
+
// Extract<TInputRecord[keyof TInputRecord], { name: K }>
|
204
|
+
// >
|
205
|
+
},
|
206
|
+
) => {
|
207
|
+
return handlers
|
208
|
+
}
|
209
|
+
|
210
|
+
export const rawSqlEvent = defineEvent({
|
211
|
+
name: 'livestore.RawSql',
|
212
|
+
schema: Schema.Struct({
|
213
|
+
sql: Schema.String,
|
214
|
+
bindValues: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
215
|
+
writeTables: Schema.optional(Schema.ReadonlySet(Schema.String)),
|
216
|
+
}),
|
217
|
+
clientOnly: true,
|
218
|
+
derived: true,
|
219
|
+
})
|
220
|
+
|
221
|
+
export const rawSqlMaterializer = defineMaterializer(rawSqlEvent, ({ sql, bindValues, writeTables }) => ({
|
222
|
+
sql,
|
223
|
+
bindValues: bindValues ?? {},
|
224
|
+
writeTables,
|
225
|
+
}))
|
226
|
+
|
227
|
+
export type RawSqlEvent = typeof rawSqlEvent
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Vitest } from '@livestore/utils-dev/node-vitest'
|
2
|
+
import { expect } from 'vitest'
|
3
|
+
|
4
|
+
import { EventId } from './mod.js'
|
5
|
+
|
6
|
+
Vitest.describe('EventId', () => {
|
7
|
+
Vitest.test('nextPair', () => {
|
8
|
+
const e_0_0 = EventId.make({ global: 0, client: 0 })
|
9
|
+
expect(EventId.nextPair(e_0_0, false).id).toStrictEqual({ global: 1, client: 0 })
|
10
|
+
expect(EventId.nextPair(e_0_0, true).id).toStrictEqual({ global: 0, client: 1 })
|
11
|
+
})
|
12
|
+
})
|
package/src/schema/EventId.ts
CHANGED
@@ -1,16 +1,41 @@
|
|
1
|
-
import { Schema } from '@livestore/utils/effect'
|
1
|
+
import { Brand, Schema } from '@livestore/utils/effect'
|
2
|
+
|
3
|
+
export type ClientEventId = Brand.Branded<number, 'ClientEventId'>
|
4
|
+
export const localEventId = Brand.nominal<ClientEventId>()
|
5
|
+
export const ClientEventId = Schema.fromBrand(localEventId)(Schema.Int)
|
6
|
+
|
7
|
+
export type GlobalEventId = Brand.Branded<number, 'GlobalEventId'>
|
8
|
+
export const globalEventId = Brand.nominal<GlobalEventId>()
|
9
|
+
export const GlobalEventId = Schema.fromBrand(globalEventId)(Schema.Int)
|
10
|
+
|
11
|
+
export const clientDefault = 0 as any as ClientEventId
|
2
12
|
|
3
13
|
/**
|
4
14
|
* LiveStore event id value consisting of a globally unique event sequence number
|
5
|
-
* and a
|
15
|
+
* and a client sequence number.
|
6
16
|
*
|
7
|
-
* The
|
17
|
+
* The client sequence number is only used for clientOnly events and starts from 0 for each global sequence number.
|
8
18
|
*/
|
9
|
-
export type EventId = { global:
|
19
|
+
export type EventId = { global: GlobalEventId; client: ClientEventId }
|
20
|
+
|
21
|
+
// export const EventSequenceNumber = Schema.Struct({})
|
22
|
+
// export const EventNumber = Schema.Struct({})
|
23
|
+
// export const ClientEventNumber = Schema.Struct({})
|
24
|
+
// export const GlobalEventNumber = Schema.Struct({})
|
10
25
|
|
26
|
+
/**
|
27
|
+
* NOTE: Client mutation events with a non-0 client id, won't be synced to the sync backend.
|
28
|
+
*/
|
11
29
|
export const EventId = Schema.Struct({
|
12
|
-
global:
|
13
|
-
|
30
|
+
global: GlobalEventId,
|
31
|
+
/** Only increments for clientOnly events */
|
32
|
+
client: ClientEventId,
|
33
|
+
|
34
|
+
// TODO also provide a way to see "confirmation level" of event (e.g. confirmed by leader/sync backend)
|
35
|
+
|
36
|
+
// TODO: actually add this field
|
37
|
+
// Client only
|
38
|
+
// generation: Schema.Number.pipe(Schema.optional),
|
14
39
|
}).annotations({ title: 'LiveStore.EventId' })
|
15
40
|
|
16
41
|
/**
|
@@ -20,27 +45,62 @@ export const compare = (a: EventId, b: EventId) => {
|
|
20
45
|
if (a.global !== b.global) {
|
21
46
|
return a.global - b.global
|
22
47
|
}
|
23
|
-
return a.
|
48
|
+
return a.client - b.client
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Convert an event id to a string representation.
|
53
|
+
*/
|
54
|
+
export const toString = (id: EventId) => (id.client === 0 ? `e${id.global}` : `e${id.global}+${id.client}`)
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Convert a string representation of an event id to an event id.
|
58
|
+
*/
|
59
|
+
export const fromString = (str: string): EventId => {
|
60
|
+
const [global, client] = str.slice(1, -1).split(',').map(Number)
|
61
|
+
if (global === undefined || client === undefined) {
|
62
|
+
throw new Error('Invalid event id string')
|
63
|
+
}
|
64
|
+
return { global, client } as EventId
|
24
65
|
}
|
25
66
|
|
26
|
-
export const isEqual = (a: EventId, b: EventId) => a.global === b.global && a.
|
67
|
+
export const isEqual = (a: EventId, b: EventId) => a.global === b.global && a.client === b.client
|
27
68
|
|
28
69
|
export type EventIdPair = { id: EventId; parentId: EventId }
|
29
70
|
|
30
|
-
export const ROOT = { global:
|
71
|
+
export const ROOT = { global: 0 as any as GlobalEventId, client: clientDefault } satisfies EventId
|
31
72
|
|
32
73
|
export const isGreaterThan = (a: EventId, b: EventId) => {
|
33
|
-
return a.global > b.global || (a.global === b.global && a.
|
74
|
+
return a.global > b.global || (a.global === b.global && a.client > b.client)
|
75
|
+
}
|
76
|
+
|
77
|
+
export const isGreaterThanOrEqual = (a: EventId, b: EventId) => {
|
78
|
+
return a.global > b.global || (a.global === b.global && a.client >= b.client)
|
79
|
+
}
|
80
|
+
|
81
|
+
export const max = (a: EventId, b: EventId) => {
|
82
|
+
return a.global > b.global || (a.global === b.global && a.client > b.client) ? a : b
|
83
|
+
}
|
84
|
+
|
85
|
+
export const diff = (a: EventId, b: EventId) => {
|
86
|
+
return {
|
87
|
+
global: a.global - b.global,
|
88
|
+
client: a.client - b.client,
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
export const make = (id: EventId | typeof EventId.Encoded): EventId => {
|
93
|
+
return Schema.is(EventId)(id) ? id : Schema.decodeSync(EventId)(id)
|
34
94
|
}
|
35
95
|
|
36
|
-
export const nextPair = (id: EventId, isLocal: boolean) => {
|
96
|
+
export const nextPair = (id: EventId, isLocal: boolean): EventIdPair => {
|
37
97
|
if (isLocal) {
|
38
|
-
return { id: { global: id.global,
|
98
|
+
return { id: { global: id.global, client: (id.client + 1) as any as ClientEventId }, parentId: id }
|
39
99
|
}
|
40
100
|
|
41
101
|
return {
|
42
|
-
id: { global: id.global + 1,
|
43
|
-
// NOTE we always point to `
|
44
|
-
parentId: { global: id.global,
|
102
|
+
id: { global: (id.global + 1) as any as GlobalEventId, client: clientDefault },
|
103
|
+
// NOTE we always point to `client: 0` for non-clientOnly events
|
104
|
+
parentId: { global: id.global, client: clientDefault },
|
45
105
|
}
|
46
106
|
}
|
@@ -0,0 +1,239 @@
|
|
1
|
+
import { memoizeByRef } from '@livestore/utils'
|
2
|
+
import { Option, Schema } from '@livestore/utils/effect'
|
3
|
+
|
4
|
+
import type { EventDef, EventDefRecord } from './EventDef.js'
|
5
|
+
import * as EventId from './EventId.js'
|
6
|
+
import type { LiveStoreSchema } from './schema.js'
|
7
|
+
|
8
|
+
export type EventDefPartial<TEventDef extends EventDef.Any> = {
|
9
|
+
name: TEventDef['name']
|
10
|
+
args: Schema.Schema.Type<TEventDef['schema']>
|
11
|
+
}
|
12
|
+
|
13
|
+
export type PartialEncoded<TEventDef extends EventDef.Any> = {
|
14
|
+
name: TEventDef['name']
|
15
|
+
args: Schema.Schema.Encoded<TEventDef['schema']>
|
16
|
+
}
|
17
|
+
|
18
|
+
export type ForEventDef<TEventDef extends EventDef.Any> = {
|
19
|
+
name: TEventDef['name']
|
20
|
+
args: Schema.Schema.Type<TEventDef['schema']>
|
21
|
+
id: EventId.EventId
|
22
|
+
parentId: EventId.EventId
|
23
|
+
clientId: string
|
24
|
+
sessionId: string
|
25
|
+
}
|
26
|
+
|
27
|
+
export type EventDefEncoded<TEventDef extends EventDef.Any> = {
|
28
|
+
name: TEventDef['name']
|
29
|
+
args: Schema.Schema.Encoded<TEventDef['schema']>
|
30
|
+
id: EventId.EventId
|
31
|
+
parentId: EventId.EventId
|
32
|
+
clientId: string
|
33
|
+
sessionId: string
|
34
|
+
}
|
35
|
+
|
36
|
+
export type AnyDecoded = ForEventDef<EventDef.Any>
|
37
|
+
export const AnyDecoded = Schema.Struct({
|
38
|
+
name: Schema.String,
|
39
|
+
args: Schema.Any,
|
40
|
+
id: EventId.EventId,
|
41
|
+
parentId: EventId.EventId,
|
42
|
+
clientId: Schema.String,
|
43
|
+
sessionId: Schema.String,
|
44
|
+
}).annotations({ title: 'LiveStoreEvent.AnyDecoded' })
|
45
|
+
|
46
|
+
export type AnyEncoded = EventDefEncoded<EventDef.Any>
|
47
|
+
export const AnyEncoded = Schema.Struct({
|
48
|
+
name: Schema.String,
|
49
|
+
args: Schema.Any,
|
50
|
+
id: EventId.EventId,
|
51
|
+
parentId: EventId.EventId,
|
52
|
+
clientId: Schema.String,
|
53
|
+
sessionId: Schema.String,
|
54
|
+
}).annotations({ title: 'LiveStoreEvent.AnyEncoded' })
|
55
|
+
|
56
|
+
export const AnyEncodedGlobal = Schema.Struct({
|
57
|
+
name: Schema.String,
|
58
|
+
args: Schema.Any,
|
59
|
+
id: EventId.GlobalEventId,
|
60
|
+
parentId: EventId.GlobalEventId,
|
61
|
+
clientId: Schema.String,
|
62
|
+
sessionId: Schema.String,
|
63
|
+
}).annotations({ title: 'LiveStoreEvent.AnyEncodedGlobal' })
|
64
|
+
export type AnyEncodedGlobal = typeof AnyEncodedGlobal.Type
|
65
|
+
|
66
|
+
export type PartialAnyDecoded = EventDefPartial<EventDef.Any>
|
67
|
+
export type PartialAnyEncoded = PartialEncoded<EventDef.Any>
|
68
|
+
|
69
|
+
export const PartialAnyEncoded = Schema.Struct({
|
70
|
+
name: Schema.String,
|
71
|
+
args: Schema.Any,
|
72
|
+
})
|
73
|
+
|
74
|
+
export type PartialForSchema<TSchema extends LiveStoreSchema> = {
|
75
|
+
[K in keyof TSchema['_EventDefMapType']]: EventDefPartial<TSchema['_EventDefMapType'][K]>
|
76
|
+
}[keyof TSchema['_EventDefMapType']]
|
77
|
+
|
78
|
+
export type ForSchema<TSchema extends LiveStoreSchema> = {
|
79
|
+
[K in keyof TSchema['_EventDefMapType']]: ForEventDef<TSchema['_EventDefMapType'][K]>
|
80
|
+
}[keyof TSchema['_EventDefMapType']]
|
81
|
+
|
82
|
+
export const isPartialEventDef = (event: AnyDecoded | PartialAnyDecoded): event is PartialAnyDecoded =>
|
83
|
+
'id' in event === false && 'parentId' in event === false
|
84
|
+
|
85
|
+
export type ForEventDefRecord<TEventDefRecord extends EventDefRecord> = Schema.Schema<
|
86
|
+
{
|
87
|
+
[K in keyof TEventDefRecord]: {
|
88
|
+
name: K
|
89
|
+
args: Schema.Schema.Type<TEventDefRecord[K]['schema']>
|
90
|
+
id: EventId.EventId
|
91
|
+
parentId: EventId.EventId
|
92
|
+
clientId: string
|
93
|
+
sessionId: string
|
94
|
+
}
|
95
|
+
}[keyof TEventDefRecord],
|
96
|
+
{
|
97
|
+
[K in keyof TEventDefRecord]: {
|
98
|
+
name: K
|
99
|
+
args: Schema.Schema.Encoded<TEventDefRecord[K]['schema']>
|
100
|
+
id: EventId.EventId
|
101
|
+
parentId: EventId.EventId
|
102
|
+
clientId: string
|
103
|
+
sessionId: string
|
104
|
+
}
|
105
|
+
}[keyof TEventDefRecord]
|
106
|
+
>
|
107
|
+
|
108
|
+
export type EventDefPartialSchema<TEventDefRecord extends EventDefRecord> = Schema.Schema<
|
109
|
+
{
|
110
|
+
[K in keyof TEventDefRecord]: {
|
111
|
+
name: K
|
112
|
+
args: Schema.Schema.Type<TEventDefRecord[K]['schema']>
|
113
|
+
}
|
114
|
+
}[keyof TEventDefRecord],
|
115
|
+
{
|
116
|
+
[K in keyof TEventDefRecord]: {
|
117
|
+
name: K
|
118
|
+
args: Schema.Schema.Encoded<TEventDefRecord[K]['schema']>
|
119
|
+
}
|
120
|
+
}[keyof TEventDefRecord]
|
121
|
+
>
|
122
|
+
|
123
|
+
export const makeEventDefSchema = <TSchema extends LiveStoreSchema>(
|
124
|
+
schema: TSchema,
|
125
|
+
): ForEventDefRecord<TSchema['_EventDefMapType']> =>
|
126
|
+
Schema.Union(
|
127
|
+
...[...schema.eventsDefsMap.values()].map((def) =>
|
128
|
+
Schema.Struct({
|
129
|
+
name: Schema.Literal(def.name),
|
130
|
+
args: def.schema,
|
131
|
+
id: EventId.EventId,
|
132
|
+
parentId: EventId.EventId,
|
133
|
+
clientId: Schema.String,
|
134
|
+
sessionId: Schema.String,
|
135
|
+
}),
|
136
|
+
),
|
137
|
+
).annotations({ title: 'EventDef' }) as any
|
138
|
+
|
139
|
+
export const makeEventDefPartialSchema = <TSchema extends LiveStoreSchema>(
|
140
|
+
schema: TSchema,
|
141
|
+
): EventDefPartialSchema<TSchema['_EventDefMapType']> =>
|
142
|
+
Schema.Union(
|
143
|
+
...[...schema.eventsDefsMap.values()].map((def) =>
|
144
|
+
Schema.Struct({
|
145
|
+
name: Schema.Literal(def.name),
|
146
|
+
args: def.schema,
|
147
|
+
}),
|
148
|
+
),
|
149
|
+
).annotations({ title: 'EventDefPartial' }) as any
|
150
|
+
|
151
|
+
export const makeEventDefSchemaMemo = memoizeByRef(makeEventDefSchema)
|
152
|
+
|
153
|
+
/** Equivalent to AnyEncoded but with a meta field and some convenience methods */
|
154
|
+
export class EncodedWithMeta extends Schema.Class<EncodedWithMeta>('LiveStoreEvent.EncodedWithMeta')({
|
155
|
+
name: Schema.String,
|
156
|
+
args: Schema.Any,
|
157
|
+
// TODO rename to `.num` / `.parentNum`
|
158
|
+
id: EventId.EventId,
|
159
|
+
parentId: EventId.EventId,
|
160
|
+
clientId: Schema.String,
|
161
|
+
sessionId: Schema.String,
|
162
|
+
// TODO get rid of `meta` again by cleaning up the usage implementations
|
163
|
+
meta: Schema.Struct({
|
164
|
+
sessionChangeset: Schema.Union(
|
165
|
+
Schema.TaggedStruct('sessionChangeset', {
|
166
|
+
data: Schema.Uint8Array,
|
167
|
+
debug: Schema.Any.pipe(Schema.optional),
|
168
|
+
}),
|
169
|
+
Schema.TaggedStruct('no-op', {}),
|
170
|
+
Schema.TaggedStruct('unset', {}),
|
171
|
+
),
|
172
|
+
syncMetadata: Schema.Option(Schema.JsonValue),
|
173
|
+
}).pipe(
|
174
|
+
Schema.mutable,
|
175
|
+
Schema.optional,
|
176
|
+
Schema.withDefaults({
|
177
|
+
constructor: () => ({ sessionChangeset: { _tag: 'unset' as const }, syncMetadata: Option.none() }),
|
178
|
+
decoding: () => ({ sessionChangeset: { _tag: 'unset' as const }, syncMetadata: Option.none() }),
|
179
|
+
}),
|
180
|
+
),
|
181
|
+
}) {
|
182
|
+
toJSON = (): any => {
|
183
|
+
// Only used for logging/debugging
|
184
|
+
// - More readable way to print the id + parentId
|
185
|
+
// - not including `meta`, `clientId`, `sessionId`
|
186
|
+
return {
|
187
|
+
id: `${EventId.toString(this.id)} → ${EventId.toString(this.parentId)} (${this.clientId}, ${this.sessionId})`,
|
188
|
+
name: this.name,
|
189
|
+
args: this.args,
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Example: (global event)
|
195
|
+
* For event id e2 → e1 which should be rebased on event id e3 → e2
|
196
|
+
* the resulting event id will be e4 → e3
|
197
|
+
*
|
198
|
+
* Example: (client event)
|
199
|
+
* For event id e2+1 → e2 which should be rebased on event id e3 → e2
|
200
|
+
* the resulting event id will be e3+1 → e3
|
201
|
+
*
|
202
|
+
* Syntax: e2+2 → e2+1
|
203
|
+
* ^ ^ ^ ^
|
204
|
+
* | | | +- client parent id
|
205
|
+
* | | +--- global parent id
|
206
|
+
* | +-- client id
|
207
|
+
* +---- global id
|
208
|
+
* Client id is ommitted for global events
|
209
|
+
*/
|
210
|
+
rebase = (parentId: EventId.EventId, isClient: boolean) =>
|
211
|
+
new EncodedWithMeta({
|
212
|
+
...this,
|
213
|
+
...EventId.nextPair(parentId, isClient),
|
214
|
+
})
|
215
|
+
|
216
|
+
static fromGlobal = (event: AnyEncodedGlobal, syncMetadata: Option.Option<Schema.JsonValue>) =>
|
217
|
+
new EncodedWithMeta({
|
218
|
+
...event,
|
219
|
+
id: { global: event.id, client: EventId.clientDefault },
|
220
|
+
parentId: { global: event.parentId, client: EventId.clientDefault },
|
221
|
+
meta: { sessionChangeset: { _tag: 'unset' as const }, syncMetadata },
|
222
|
+
})
|
223
|
+
|
224
|
+
toGlobal = (): AnyEncodedGlobal => ({
|
225
|
+
...this,
|
226
|
+
id: this.id.global,
|
227
|
+
parentId: this.parentId.global,
|
228
|
+
})
|
229
|
+
}
|
230
|
+
|
231
|
+
/** NOTE `meta` is not considered for equality */
|
232
|
+
export const isEqualEncoded = (a: AnyEncoded, b: AnyEncoded) =>
|
233
|
+
a.id.global === b.id.global &&
|
234
|
+
a.id.client === b.id.client &&
|
235
|
+
a.name === b.name &&
|
236
|
+
a.clientId === b.clientId &&
|
237
|
+
a.sessionId === b.sessionId &&
|
238
|
+
// TODO use schema equality here
|
239
|
+
JSON.stringify(a.args) === JSON.stringify(b.args)
|
@@ -0,0 +1 @@
|
|
1
|
+
export { defineEvent, synced, clientOnly } from './EventDef.js'
|
package/src/schema/mod.ts
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
export * from './system-tables.js'
|
2
|
-
export
|
3
|
-
export * from './
|
4
|
-
export * from './schema-helpers.js'
|
1
|
+
export * as SystemTables from './state/sqlite/system-tables.js'
|
2
|
+
export { SqliteAst, SqliteDsl } from './state/sqlite/db-schema/mod.js'
|
3
|
+
export * from './EventDef.js'
|
4
|
+
export * from './state/sqlite/schema-helpers.js'
|
5
5
|
export * from './schema.js'
|
6
|
-
export * as
|
6
|
+
export * as State from './state/mod.js'
|
7
|
+
export * as LiveStoreEvent from './LiveStoreEvent.js'
|
7
8
|
export * as EventId from './EventId.js'
|
9
|
+
export * as Events from './events.js'
|