@livestore/common 0.4.0-dev.21 → 0.4.0-dev.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/ClientSessionLeaderThreadProxy.d.ts +16 -9
- package/dist/ClientSessionLeaderThreadProxy.d.ts.map +1 -1
- package/dist/ClientSessionLeaderThreadProxy.js.map +1 -1
- package/dist/WorkerTransportError.d.ts +11 -0
- package/dist/WorkerTransportError.d.ts.map +1 -0
- package/dist/WorkerTransportError.js +11 -0
- package/dist/WorkerTransportError.js.map +1 -0
- package/dist/adapter-types.d.ts +26 -3
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +27 -1
- package/dist/adapter-types.js.map +1 -1
- package/dist/bounded-collections.d.ts.map +1 -1
- package/dist/bounded-collections.js +6 -4
- package/dist/bounded-collections.js.map +1 -1
- package/dist/debug-info.js +4 -4
- package/dist/debug-info.js.map +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +42 -22
- package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-client-session.js +12 -1
- package/dist/devtools/devtools-messages-client-session.js.map +1 -1
- package/dist/devtools/devtools-messages-common.d.ts +12 -6
- package/dist/devtools/devtools-messages-common.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-common.js +8 -3
- package/dist/devtools/devtools-messages-common.js.map +1 -1
- package/dist/devtools/devtools-messages-leader.d.ts +45 -25
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-leader.js +12 -1
- package/dist/devtools/devtools-messages-leader.js.map +1 -1
- package/dist/devtools/mod.js +1 -1
- package/dist/devtools/mod.js.map +1 -1
- package/dist/errors.d.ts +15 -15
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +11 -11
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +20 -6
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +283 -253
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/RejectedPushError.d.ts +107 -0
- package/dist/leader-thread/RejectedPushError.d.ts.map +1 -0
- package/dist/leader-thread/RejectedPushError.js +78 -0
- package/dist/leader-thread/RejectedPushError.js.map +1 -0
- package/dist/leader-thread/connection.js +1 -1
- package/dist/leader-thread/connection.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +12 -11
- package/dist/leader-thread/eventlog.js.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts +1 -2
- package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +34 -14
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +12 -5
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +12 -11
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.test.js +1 -1
- package/dist/leader-thread/make-leader-thread-layer.test.js.map +1 -1
- package/dist/leader-thread/materialize-event.d.ts.map +1 -1
- package/dist/leader-thread/materialize-event.js +7 -4
- package/dist/leader-thread/materialize-event.js.map +1 -1
- package/dist/leader-thread/recreate-db.js +1 -1
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/shutdown-channel.d.ts +2 -2
- package/dist/leader-thread/shutdown-channel.d.ts.map +1 -1
- package/dist/leader-thread/shutdown-channel.js +2 -2
- package/dist/leader-thread/shutdown-channel.js.map +1 -1
- package/dist/leader-thread/stream-events.d.ts.map +1 -1
- package/dist/leader-thread/stream-events.js +4 -3
- package/dist/leader-thread/stream-events.js.map +1 -1
- package/dist/leader-thread/types.d.ts +7 -6
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/leader-thread/types.js.map +1 -1
- package/dist/logging.js +4 -4
- package/dist/logging.js.map +1 -1
- package/dist/make-client-session.js +2 -2
- package/dist/make-client-session.js.map +1 -1
- package/dist/materializer-helper.js +6 -6
- package/dist/materializer-helper.js.map +1 -1
- package/dist/otel.d.ts +1 -1
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +2 -2
- package/dist/otel.js.map +1 -1
- package/dist/rematerialize-from-eventlog.d.ts +1 -1
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
- package/dist/rematerialize-from-eventlog.js +11 -9
- package/dist/rematerialize-from-eventlog.js.map +1 -1
- package/dist/schema/EventDef/define.d.ts +16 -2
- package/dist/schema/EventDef/define.d.ts.map +1 -1
- package/dist/schema/EventDef/define.js +5 -4
- package/dist/schema/EventDef/define.js.map +1 -1
- package/dist/schema/EventDef/deprecated.d.ts +99 -0
- package/dist/schema/EventDef/deprecated.d.ts.map +1 -0
- package/dist/schema/EventDef/deprecated.js +144 -0
- package/dist/schema/EventDef/deprecated.js.map +1 -0
- package/dist/schema/EventDef/deprecated.test.d.ts +2 -0
- package/dist/schema/EventDef/deprecated.test.d.ts.map +1 -0
- package/dist/schema/EventDef/deprecated.test.js +95 -0
- package/dist/schema/EventDef/deprecated.test.js.map +1 -0
- package/dist/schema/EventDef/event-def.d.ts +4 -0
- package/dist/schema/EventDef/event-def.d.ts.map +1 -1
- package/dist/schema/EventDef/mod.d.ts +1 -0
- package/dist/schema/EventDef/mod.d.ts.map +1 -1
- package/dist/schema/EventDef/mod.js +1 -0
- package/dist/schema/EventDef/mod.js.map +1 -1
- package/dist/schema/EventSequenceNumber/client.d.ts.map +1 -1
- package/dist/schema/EventSequenceNumber/client.js +11 -11
- package/dist/schema/EventSequenceNumber/client.js.map +1 -1
- package/dist/schema/EventSequenceNumber.test.js +1 -1
- package/dist/schema/EventSequenceNumber.test.js.map +1 -1
- package/dist/schema/LiveStoreEvent/client.d.ts +6 -6
- package/dist/schema/LiveStoreEvent/client.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent/client.js +6 -3
- package/dist/schema/LiveStoreEvent/client.js.map +1 -1
- package/dist/schema/LiveStoreEvent/client.test.d.ts +2 -0
- package/dist/schema/LiveStoreEvent/client.test.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/client.test.js +83 -0
- package/dist/schema/LiveStoreEvent/client.test.js.map +1 -0
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +7 -4
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.d.ts +1 -0
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +34 -13
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.test.js +121 -2
- package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-annotations.d.ts.map +1 -1
- package/dist/schema/state/sqlite/column-annotations.js +1 -1
- package/dist/schema/state/sqlite/column-annotations.js.map +1 -1
- package/dist/schema/state/sqlite/column-annotations.test.js +1 -1
- package/dist/schema/state/sqlite/column-annotations.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/column-def.js +36 -34
- package/dist/schema/state/sqlite/column-def.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.test.js +7 -6
- package/dist/schema/state/sqlite/column-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-spec.d.ts.map +1 -1
- package/dist/schema/state/sqlite/column-spec.js +8 -8
- package/dist/schema/state/sqlite/column-spec.js.map +1 -1
- package/dist/schema/state/sqlite/column-spec.test.js +1 -1
- package/dist/schema/state/sqlite/column-spec.test.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +2 -2
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts +2 -2
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js +11 -2
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -1
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.js +3 -5
- package/dist/schema/state/sqlite/mod.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/api.d.ts +37 -13
- package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/astToSql.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/astToSql.js +77 -7
- package/dist/schema/state/sqlite/query-builder/astToSql.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.js +28 -14
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +112 -3
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
- package/dist/schema/state/sqlite/schema-helpers.js +2 -2
- package/dist/schema/state/sqlite/schema-helpers.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.d.ts +5 -3
- package/dist/schema/state/sqlite/table-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/table-def.js +1 -1
- package/dist/schema/state/sqlite/table-def.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.test.js +57 -4
- package/dist/schema/state/sqlite/table-def.test.js.map +1 -1
- package/dist/schema/unknown-events.d.ts +1 -1
- package/dist/schema/unknown-events.d.ts.map +1 -1
- package/dist/schema/unknown-events.js +1 -1
- package/dist/schema/unknown-events.js.map +1 -1
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js +1 -1
- package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js.map +1 -1
- package/dist/schema-management/common.js +2 -2
- package/dist/schema-management/common.js.map +1 -1
- package/dist/schema-management/migrations.js +1 -1
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/sql-queries/sql-queries.js +8 -6
- package/dist/sql-queries/sql-queries.js.map +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts.map +1 -1
- package/dist/sql-queries/sql-query-builder.js.map +1 -1
- package/dist/sqlite-db-helper.js +3 -3
- package/dist/sqlite-db-helper.js.map +1 -1
- package/dist/sqlite-types.d.ts +2 -2
- package/dist/sqlite-types.d.ts.map +1 -1
- package/dist/sqlite-types.js.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.d.ts +8 -9
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +93 -107
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/errors.d.ts +0 -38
- package/dist/sync/errors.d.ts.map +1 -1
- package/dist/sync/errors.js +3 -20
- package/dist/sync/errors.js.map +1 -1
- package/dist/sync/mock-sync-backend.d.ts +5 -3
- package/dist/sync/mock-sync-backend.d.ts.map +1 -1
- package/dist/sync/mock-sync-backend.js +70 -68
- package/dist/sync/mock-sync-backend.js.map +1 -1
- package/dist/sync/next/compact-events.js +6 -6
- package/dist/sync/next/compact-events.js.map +1 -1
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js +6 -6
- package/dist/sync/next/facts.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +6 -6
- package/dist/sync/next/history-dag-common.js.map +1 -1
- package/dist/sync/next/history-dag.js +3 -3
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/next/rebase-events.js +1 -1
- package/dist/sync/next/rebase-events.js.map +1 -1
- package/dist/sync/next/test/compact-events.calculator.test.js +2 -2
- package/dist/sync/next/test/compact-events.calculator.test.js.map +1 -1
- package/dist/sync/next/test/compact-events.test.d.ts.map +1 -1
- package/dist/sync/next/test/compact-events.test.js +2 -2
- package/dist/sync/next/test/compact-events.test.js.map +1 -1
- package/dist/sync/next/test/event-fixtures.d.ts.map +1 -1
- package/dist/sync/next/test/event-fixtures.js +2 -2
- package/dist/sync/next/test/event-fixtures.js.map +1 -1
- package/dist/sync/sync-backend-kv.d.ts.map +1 -1
- package/dist/sync/sync-backend-kv.js.map +1 -1
- package/dist/sync/sync-backend.d.ts +3 -3
- package/dist/sync/sync-backend.d.ts.map +1 -1
- package/dist/sync/sync-backend.js +1 -1
- package/dist/sync/sync-backend.js.map +1 -1
- package/dist/sync/sync.d.ts +20 -0
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/syncstate.d.ts +4 -17
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +51 -74
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +112 -96
- package/dist/sync/syncstate.test.js.map +1 -1
- package/dist/sync/transport-chunking.js +3 -3
- package/dist/sync/transport-chunking.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 -6
- package/dist/sync/validate-push-payload.js.map +1 -1
- package/dist/util.js +2 -2
- package/dist/util.js.map +1 -1
- package/dist/version.d.ts +7 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +8 -4
- package/dist/version.js.map +1 -1
- package/package.json +66 -12
- package/src/ClientSessionLeaderThreadProxy.ts +16 -9
- package/src/WorkerTransportError.ts +12 -0
- package/src/adapter-types.ts +39 -3
- package/src/bounded-collections.ts +6 -5
- package/src/debug-info.ts +4 -4
- package/src/devtools/devtools-messages-client-session.ts +12 -0
- package/src/devtools/devtools-messages-common.ts +8 -4
- package/src/devtools/devtools-messages-leader.ts +12 -0
- package/src/devtools/mod.ts +1 -1
- package/src/errors.ts +18 -17
- package/src/index.ts +2 -0
- package/src/leader-thread/LeaderSyncProcessor.ts +417 -347
- package/src/leader-thread/RejectedPushError.ts +106 -0
- package/src/leader-thread/connection.ts +1 -1
- package/src/leader-thread/eventlog.ts +16 -14
- package/src/leader-thread/leader-worker-devtools.ts +107 -66
- package/src/leader-thread/make-leader-thread-layer.test.ts +1 -1
- package/src/leader-thread/make-leader-thread-layer.ts +41 -31
- package/src/leader-thread/materialize-event.ts +8 -4
- package/src/leader-thread/recreate-db.ts +1 -1
- package/src/leader-thread/shutdown-channel.ts +2 -6
- package/src/leader-thread/stream-events.ts +10 -5
- package/src/leader-thread/types.ts +7 -6
- package/src/logging.ts +4 -4
- package/src/make-client-session.ts +2 -2
- package/src/materializer-helper.ts +9 -9
- package/src/otel.ts +3 -2
- package/src/rematerialize-from-eventlog.ts +60 -60
- package/src/schema/EventDef/define.ts +22 -6
- package/src/schema/EventDef/deprecated.test.ts +129 -0
- package/src/schema/EventDef/deprecated.ts +175 -0
- package/src/schema/EventDef/event-def.ts +5 -0
- package/src/schema/EventDef/mod.ts +1 -0
- package/src/schema/EventSequenceNumber/client.ts +11 -11
- package/src/schema/EventSequenceNumber.test.ts +2 -1
- package/src/schema/LiveStoreEvent/client.test.ts +97 -0
- package/src/schema/LiveStoreEvent/client.ts +6 -3
- package/src/schema/schema.ts +9 -4
- package/src/schema/state/sqlite/client-document-def.test.ts +142 -3
- package/src/schema/state/sqlite/client-document-def.ts +37 -14
- package/src/schema/state/sqlite/column-annotations.test.ts +2 -1
- package/src/schema/state/sqlite/column-annotations.ts +2 -1
- package/src/schema/state/sqlite/column-def.test.ts +8 -6
- package/src/schema/state/sqlite/column-def.ts +41 -36
- package/src/schema/state/sqlite/column-spec.test.ts +3 -1
- package/src/schema/state/sqlite/column-spec.ts +9 -8
- package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +2 -2
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.test.ts +2 -1
- package/src/schema/state/sqlite/db-schema/dsl/field-defs.ts +13 -4
- package/src/schema/state/sqlite/db-schema/dsl/mod.ts +3 -3
- package/src/schema/state/sqlite/mod.ts +4 -5
- package/src/schema/state/sqlite/query-builder/api.ts +37 -8
- package/src/schema/state/sqlite/query-builder/astToSql.ts +87 -7
- package/src/schema/state/sqlite/query-builder/impl.test.ts +145 -3
- package/src/schema/state/sqlite/query-builder/impl.ts +26 -12
- package/src/schema/state/sqlite/schema-helpers.ts +2 -2
- package/src/schema/state/sqlite/table-def.test.ts +67 -4
- package/src/schema/state/sqlite/table-def.ts +8 -15
- package/src/schema/unknown-events.ts +2 -2
- package/src/schema-management/__tests__/migrations-autoincrement-quoting.test.ts +3 -1
- package/src/schema-management/common.ts +2 -2
- package/src/schema-management/migrations.ts +1 -1
- package/src/sql-queries/sql-queries.ts +10 -6
- package/src/sql-queries/sql-query-builder.ts +1 -0
- package/src/sqlite-db-helper.ts +3 -3
- package/src/sqlite-types.ts +3 -2
- package/src/sync/ClientSessionSyncProcessor.ts +142 -133
- package/src/sync/errors.ts +10 -22
- package/src/sync/mock-sync-backend.ts +139 -97
- package/src/sync/next/compact-events.ts +5 -5
- package/src/sync/next/facts.ts +7 -6
- package/src/sync/next/history-dag-common.ts +9 -6
- package/src/sync/next/history-dag.ts +3 -3
- package/src/sync/next/rebase-events.ts +1 -1
- package/src/sync/next/test/compact-events.calculator.test.ts +3 -2
- package/src/sync/next/test/compact-events.test.ts +4 -3
- package/src/sync/next/test/event-fixtures.ts +2 -2
- package/src/sync/sync-backend-kv.ts +1 -0
- package/src/sync/sync-backend.ts +5 -4
- package/src/sync/sync.ts +21 -0
- package/src/sync/syncstate.test.ts +513 -435
- package/src/sync/syncstate.ts +80 -86
- package/src/sync/transport-chunking.ts +3 -3
- package/src/sync/validate-push-payload.ts +4 -6
- package/src/util.ts +2 -2
- package/src/version.ts +8 -4
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { objectToString } from '@livestore/utils'
|
|
2
|
+
|
|
1
3
|
import { Schema } from '@livestore/utils/effect'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { describe, expect, expectTypeOf, it } from 'vitest'
|
|
5
|
+
|
|
3
6
|
import { State } from '../../mod.ts'
|
|
4
7
|
|
|
5
8
|
describe('table function overloads', () => {
|
|
@@ -79,11 +82,11 @@ describe('table function overloads', () => {
|
|
|
79
82
|
expect(todosTable.sqliteDef.columns).toHaveProperty('optionalComplex')
|
|
80
83
|
|
|
81
84
|
expect(todosTable.sqliteDef.columns.optionalBoolean.nullable).toBe(true)
|
|
82
|
-
expect(todosTable.sqliteDef.columns.optionalBoolean.schema
|
|
85
|
+
expect(objectToString(todosTable.sqliteDef.columns.optionalBoolean.schema)).toBe('(number <-> boolean) | null')
|
|
83
86
|
expect((todosTable.rowSchema as any).fields.optionalBoolean.toString()).toBe('(number <-> boolean) | null')
|
|
84
87
|
|
|
85
88
|
expect(todosTable.sqliteDef.columns.optionalComplex.nullable).toBe(true)
|
|
86
|
-
expect(todosTable.sqliteDef.columns.optionalComplex.schema
|
|
89
|
+
expect(objectToString(todosTable.sqliteDef.columns.optionalComplex.schema)).toBe(
|
|
87
90
|
'(parseJson <-> { readonly color: string } | undefined) | null',
|
|
88
91
|
)
|
|
89
92
|
expect((todosTable.rowSchema as any).fields.optionalComplex.toString()).toBe(
|
|
@@ -91,6 +94,22 @@ describe('table function overloads', () => {
|
|
|
91
94
|
)
|
|
92
95
|
})
|
|
93
96
|
|
|
97
|
+
it('should allow explicit first two generic arguments without options generic', () => {
|
|
98
|
+
const columns = {
|
|
99
|
+
id: State.SQLite.text({ primaryKey: true }),
|
|
100
|
+
text: State.SQLite.text({ default: '' }),
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const todosTable = State.SQLite.table<'todos', typeof columns>({
|
|
104
|
+
name: 'todos',
|
|
105
|
+
columns,
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
expect(todosTable.sqliteDef.name).toBe('todos')
|
|
109
|
+
expect(todosTable.sqliteDef.columns).toHaveProperty('id')
|
|
110
|
+
expect(todosTable.sqliteDef.columns).toHaveProperty('text')
|
|
111
|
+
})
|
|
112
|
+
|
|
94
113
|
it('should work with schema parameter', () => {
|
|
95
114
|
const TodoSchema = Schema.Struct({
|
|
96
115
|
id: Schema.String,
|
|
@@ -301,6 +320,50 @@ describe('table function overloads', () => {
|
|
|
301
320
|
expect(userTable.sqliteDef.columns.metadata.nullable).toBe(true)
|
|
302
321
|
})
|
|
303
322
|
|
|
323
|
+
it('should allow omitting nullable fields in insert()', () => {
|
|
324
|
+
const UserSchema = Schema.Struct({
|
|
325
|
+
id: Schema.String.pipe(State.SQLite.withPrimaryKey),
|
|
326
|
+
undefined: Schema.Undefined,
|
|
327
|
+
null: Schema.Null,
|
|
328
|
+
undefinedOrString: Schema.UndefinedOr(Schema.String),
|
|
329
|
+
nullOrString: Schema.NullOr(Schema.String),
|
|
330
|
+
optionalString: Schema.optional(Schema.String),
|
|
331
|
+
optionalNullOrString: Schema.optional(Schema.NullOr(Schema.String)),
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
const usersTable = State.SQLite.table({
|
|
335
|
+
name: 'users',
|
|
336
|
+
schema: UserSchema,
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
// Non-nullable fields (id) are required — omitting id should be rejected
|
|
340
|
+
expectTypeOf<{ undefined: undefined }>().not.toExtend<Parameters<typeof usersTable.insert>[0]>()
|
|
341
|
+
|
|
342
|
+
// Nullable fields (NullOr, optional+NullOr) are omittable — SQL defaults to NULL
|
|
343
|
+
expectTypeOf(usersTable.insert)
|
|
344
|
+
.toBeCallableWith({ id: '1' })
|
|
345
|
+
.toBeCallableWith({ id: '1', undefined: undefined })
|
|
346
|
+
.toBeCallableWith({ id: '1', undefined: undefined, null: null })
|
|
347
|
+
.toBeCallableWith({ id: '1', undefined: undefined, null: null, undefinedOrString: undefined })
|
|
348
|
+
.toBeCallableWith({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string' })
|
|
349
|
+
.toBeCallableWith({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: null })
|
|
350
|
+
.toBeCallableWith({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: 'string' })
|
|
351
|
+
.toBeCallableWith({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: 'string', optionalString: 'string' })
|
|
352
|
+
.toBeCallableWith({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: 'string', optionalString: 'string', optionalNullOrString: null })
|
|
353
|
+
.toBeCallableWith({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: 'string', optionalString: 'string', optionalNullOrString: 'string' })
|
|
354
|
+
|
|
355
|
+
expect(() => usersTable.insert({ id: '1' }).asSql()).not.toThrow()
|
|
356
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined }).asSql()).not.toThrow()
|
|
357
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined, null: null }).asSql()).not.toThrow()
|
|
358
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined, null: null, undefinedOrString: undefined }).asSql()).not.toThrow()
|
|
359
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string' }).asSql()).not.toThrow()
|
|
360
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: null }).asSql()).not.toThrow()
|
|
361
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: 'string' }).asSql()).not.toThrow()
|
|
362
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: 'string', optionalString: 'string' }).asSql()).not.toThrow()
|
|
363
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: 'string', optionalString: 'string', optionalNullOrString: null }).asSql()).not.toThrow()
|
|
364
|
+
expect(() => usersTable.insert({ id: '1', undefined: undefined, null: null, undefinedOrString: 'string', nullOrString: 'string', optionalString: 'string', optionalNullOrString: 'string' }).asSql()).not.toThrow()
|
|
365
|
+
})
|
|
366
|
+
|
|
304
367
|
it('supports discriminated unions with parsed JSON payloads', () => {
|
|
305
368
|
const CircleDataSchema = Schema.Struct({
|
|
306
369
|
radius: Schema.Number,
|
|
@@ -327,7 +390,7 @@ describe('table function overloads', () => {
|
|
|
327
390
|
|
|
328
391
|
expect(shapes.sqliteDef.columns.kind.columnType).toBe('text')
|
|
329
392
|
|
|
330
|
-
const kindSchema = shapes.sqliteDef.columns.kind.schema
|
|
393
|
+
const kindSchema = objectToString(shapes.sqliteDef.columns.kind.schema)
|
|
331
394
|
expect(kindSchema).toContain('"circle" | "square"')
|
|
332
395
|
|
|
333
396
|
expect(() =>
|
|
@@ -168,10 +168,7 @@ export function table<
|
|
|
168
168
|
name: TName
|
|
169
169
|
schema: TSchema
|
|
170
170
|
} & Partial<TOptionsInput>,
|
|
171
|
-
): TableDef<
|
|
172
|
-
SqliteTableDefForSchemaInput<TName, Schema.Schema.Type<TSchema>, Schema.Schema.Encoded<TSchema>, TSchema>,
|
|
173
|
-
TableOptions
|
|
174
|
-
>
|
|
171
|
+
): TableDef<SqliteTableDefForSchemaInput<TName, Schema.Schema.Type<TSchema>, Schema.Schema.Encoded<TSchema>, TSchema>>
|
|
175
172
|
|
|
176
173
|
// Overload 3: With schema and no name (uses schema annotations)
|
|
177
174
|
export function table<
|
|
@@ -181,10 +178,7 @@ export function table<
|
|
|
181
178
|
args: {
|
|
182
179
|
schema: TSchema
|
|
183
180
|
} & Partial<TOptionsInput>,
|
|
184
|
-
): TableDef<
|
|
185
|
-
SqliteTableDefForSchemaInput<string, Schema.Schema.Type<TSchema>, Schema.Schema.Encoded<TSchema>, TSchema>,
|
|
186
|
-
TableOptions
|
|
187
|
-
>
|
|
181
|
+
): TableDef<SqliteTableDefForSchemaInput<string, Schema.Schema.Type<TSchema>, Schema.Schema.Encoded<TSchema>, TSchema>>
|
|
188
182
|
|
|
189
183
|
// Implementation
|
|
190
184
|
export function table<
|
|
@@ -216,9 +210,7 @@ export function table<
|
|
|
216
210
|
if ('columns' in args) {
|
|
217
211
|
tableName = args.name
|
|
218
212
|
const columnOrColumns = args.columns
|
|
219
|
-
columns = (
|
|
220
|
-
SqliteDsl.isColumnDefinition(columnOrColumns) ? { value: columnOrColumns } : columnOrColumns
|
|
221
|
-
) as SqliteDsl.Columns
|
|
213
|
+
columns = SqliteDsl.isColumnDefinition(columnOrColumns) === true ? { value: columnOrColumns } : columnOrColumns
|
|
222
214
|
additionalIndexes = []
|
|
223
215
|
} else if ('schema' in args) {
|
|
224
216
|
const result = schemaFieldsToColumns(Schema.getResolvedPropertySignatures(args.schema))
|
|
@@ -377,15 +369,16 @@ export type ToColumns<TColumns extends SqliteDsl.Columns | SqliteDsl.ColumnDefin
|
|
|
377
369
|
: never
|
|
378
370
|
|
|
379
371
|
export declare namespace SchemaToColumns {
|
|
372
|
+
/** Checks if `null` or `undefined` is assignable to `T`, matching the runtime nullable detection. */
|
|
373
|
+
type IsNullable<T> = null extends T ? true : undefined extends T ? true : false
|
|
374
|
+
|
|
380
375
|
// Type helper to create column definition with proper schema
|
|
381
|
-
export type ColumnDefForType<TEncoded, TType> = SqliteDsl.ColumnDefinition<TEncoded, TType
|
|
376
|
+
export type ColumnDefForType<TEncoded, TType> = SqliteDsl.ColumnDefinition<TEncoded, TType, IsNullable<TEncoded>>
|
|
382
377
|
|
|
383
|
-
// Create columns type from schema Type and Encoded
|
|
384
378
|
export type FromTypes<TType, TEncoded> =
|
|
385
379
|
TEncoded extends Record<string, any>
|
|
386
380
|
? {
|
|
387
|
-
[K in keyof TEncoded]-?: ColumnDefForType<
|
|
388
|
-
TEncoded[K],
|
|
381
|
+
[K in keyof TEncoded]-?: ColumnDefForType<TEncoded[K],
|
|
389
382
|
TType extends Record<string, any> ? (K extends keyof TType ? TType[K] : TEncoded[K]) : TEncoded[K]
|
|
390
383
|
>
|
|
391
384
|
}
|
|
@@ -17,7 +17,7 @@ export namespace UnknownEvents {
|
|
|
17
17
|
export type Callback = (
|
|
18
18
|
context: UnknownEventContext,
|
|
19
19
|
error: UnknownEventError,
|
|
20
|
-
) => Effect.SyncOrPromiseOrEffect<void, unknown
|
|
20
|
+
) => Effect.SyncOrPromiseOrEffect<void, unknown>
|
|
21
21
|
|
|
22
22
|
export type HandlingConfig =
|
|
23
23
|
| { readonly strategy: 'warn' }
|
|
@@ -60,7 +60,7 @@ const handleUnknownEvent = ({
|
|
|
60
60
|
|
|
61
61
|
switch (config.strategy) {
|
|
62
62
|
case 'fail': {
|
|
63
|
-
return yield*
|
|
63
|
+
return yield* error
|
|
64
64
|
}
|
|
65
65
|
case 'warn': {
|
|
66
66
|
yield* Effect.logWarning('@livestore/common:schema:unknown-event', context)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Effect, Option, Schema } from '@livestore/utils/effect'
|
|
2
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { Effect, Option, Schema } from '@livestore/utils/effect'
|
|
4
|
+
|
|
3
5
|
import { SqliteAst } from '../../schema/state/sqlite/db-schema/mod.ts'
|
|
4
6
|
import type { PreparedStatement, SqliteDb } from '../../sqlite-types.ts'
|
|
5
7
|
import type { PreparedBindValues } from '../../util.ts'
|
|
@@ -13,7 +13,7 @@ export const dbExecute = (db: SqliteDb, queryStr: string, bindValues?: ParamsObj
|
|
|
13
13
|
// cachedStmts.set(queryStr, stmt)
|
|
14
14
|
// }
|
|
15
15
|
|
|
16
|
-
const preparedBindValues = bindValues ? prepareBindValues(bindValues, queryStr) : undefined
|
|
16
|
+
const preparedBindValues = bindValues !== undefined ? prepareBindValues(bindValues, queryStr) : undefined
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
19
|
stmt.execute(preparedBindValues)
|
|
@@ -34,7 +34,7 @@ export const dbSelect = <T>(db: SqliteDb, queryStr: string, bindValues?: ParamsO
|
|
|
34
34
|
// cachedStmts.set(queryStr, stmt)
|
|
35
35
|
// }
|
|
36
36
|
|
|
37
|
-
const res = stmt.select<T>(bindValues ? prepareBindValues(bindValues, queryStr) : undefined)
|
|
37
|
+
const res = stmt.select<T>(bindValues !== undefined ? prepareBindValues(bindValues, queryStr) : undefined)
|
|
38
38
|
stmt.finalize()
|
|
39
39
|
return res
|
|
40
40
|
}
|
|
@@ -200,7 +200,7 @@ export const migrateTable = ({
|
|
|
200
200
|
)
|
|
201
201
|
|
|
202
202
|
const createIndexFromDefinition = (tableName: string, index: SqliteAst.Index) => {
|
|
203
|
-
const uniqueStr = index.unique ? 'UNIQUE' : ''
|
|
203
|
+
const uniqueStr = index.unique === true ? 'UNIQUE' : ''
|
|
204
204
|
return sql`create ${uniqueStr} index if not exists "${index.name}" on "${tableName}" (${index.columns
|
|
205
205
|
.map((col) => `"${col}"`)
|
|
206
206
|
.join(', ')})`
|
|
@@ -23,7 +23,7 @@ export const findManyRows = <TColumns extends SqliteDsl.Columns>({
|
|
|
23
23
|
}): [string, BindValues] => {
|
|
24
24
|
const whereSql = buildWhereSql({ where })
|
|
25
25
|
const whereModifier = whereSql === '' ? '' : `WHERE ${whereSql}`
|
|
26
|
-
const limitModifier = limit ? `LIMIT ${limit}` : ''
|
|
26
|
+
const limitModifier = limit !== undefined ? `LIMIT ${limit}` : ''
|
|
27
27
|
|
|
28
28
|
const whereBindValues = makeBindValues({ columns, values: where, variablePrefix: 'where_', skipNil: true })
|
|
29
29
|
|
|
@@ -80,7 +80,7 @@ export const insertRowPrepared = <TColumns extends SqliteDsl.Columns>({
|
|
|
80
80
|
const keysStr = keys.join(', ')
|
|
81
81
|
const valuesStr = keys.map((key) => `$${key}`).join(', ')
|
|
82
82
|
|
|
83
|
-
return sql`INSERT ${options.orReplace ? 'OR REPLACE ' : ''}INTO ${tableName} (${keysStr}) VALUES (${valuesStr})`
|
|
83
|
+
return sql`INSERT ${options.orReplace === true ? 'OR REPLACE ' : ''}INTO ${tableName} (${keysStr}) VALUES (${valuesStr})`
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export const insertRows = <TColumns extends SqliteDsl.Columns>({
|
|
@@ -134,7 +134,7 @@ export const insertOrIgnoreRow = <TColumns extends SqliteDsl.Columns>({
|
|
|
134
134
|
.join(', ')
|
|
135
135
|
|
|
136
136
|
const bindValues = makeBindValues({ columns, values })
|
|
137
|
-
const returningStmt = returnRow ? 'RETURNING *' : ''
|
|
137
|
+
const returningStmt = returnRow === true ? 'RETURNING *' : ''
|
|
138
138
|
|
|
139
139
|
return [sql`INSERT OR IGNORE INTO ${tableName} (${keysStr}) VALUES (${valuesStr}) ${returningStmt}`, bindValues]
|
|
140
140
|
}
|
|
@@ -251,7 +251,7 @@ export const createTable = ({
|
|
|
251
251
|
if (columnDef.default._tag === 'None') return ''
|
|
252
252
|
const defaultValue = columnDef.default.value
|
|
253
253
|
if (typeof defaultValue === 'function') return ''
|
|
254
|
-
if (defaultValue && typeof defaultValue === 'object' && 'sql' in defaultValue) {
|
|
254
|
+
if (defaultValue !== undefined && typeof defaultValue === 'object' && 'sql' in defaultValue) {
|
|
255
255
|
return `DEFAULT ${defaultValue.sql}`
|
|
256
256
|
}
|
|
257
257
|
return `DEFAULT ${defaultValue}`
|
|
@@ -301,7 +301,7 @@ Error: ${parseErrorStr}
|
|
|
301
301
|
Value:`,
|
|
302
302
|
value,
|
|
303
303
|
)
|
|
304
|
-
//
|
|
304
|
+
// oxlint-disable-next-line eslint(no-debugger) -- intentional breakpoint for SQL decode errors
|
|
305
305
|
debugger
|
|
306
306
|
throw res.left
|
|
307
307
|
} else {
|
|
@@ -349,7 +349,11 @@ const buildWhereSql = <TColumns extends SqliteDsl.Columns>({
|
|
|
349
349
|
const getWhereOp = (columnName: string, value: ClientTypes.WhereValueForDecoded<any>) => {
|
|
350
350
|
if (value === null) {
|
|
351
351
|
return `IS NULL`
|
|
352
|
-
} else if (
|
|
352
|
+
} else if (
|
|
353
|
+
typeof value === 'object' &&
|
|
354
|
+
typeof value.op === 'string' &&
|
|
355
|
+
ClientTypes.isValidWhereOp(value.op) === true
|
|
356
|
+
) {
|
|
353
357
|
return `${value.op} $where_${columnName}`
|
|
354
358
|
} else if (typeof value === 'object' && typeof value.op === 'string' && value.op === 'in') {
|
|
355
359
|
return `in (${value.val.map((_: any, i: number) => `$where_${columnName}_${i}`).join(', ')})`
|
package/src/sqlite-db-helper.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const makeExecute = (
|
|
|
14
14
|
return (...args: any[]) => {
|
|
15
15
|
const [queryStrOrQueryBuilder, bindValuesOrOptions, maybeOptions] = args
|
|
16
16
|
|
|
17
|
-
if (isQueryBuilder(queryStrOrQueryBuilder)) {
|
|
17
|
+
if (isQueryBuilder(queryStrOrQueryBuilder) === true) {
|
|
18
18
|
const { query, bindValues } = queryStrOrQueryBuilder.asSql()
|
|
19
19
|
return execute(query, bindValues as unknown as PreparedBindValues, bindValuesOrOptions)
|
|
20
20
|
} else {
|
|
@@ -29,7 +29,7 @@ export const makeSelect = <T>(
|
|
|
29
29
|
return (...args: any[]) => {
|
|
30
30
|
const [queryStrOrQueryBuilder, maybeBindValues] = args
|
|
31
31
|
|
|
32
|
-
if (isQueryBuilder(queryStrOrQueryBuilder)) {
|
|
32
|
+
if (isQueryBuilder(queryStrOrQueryBuilder) === true) {
|
|
33
33
|
const { query, bindValues } = queryStrOrQueryBuilder.asSql()
|
|
34
34
|
const resultSchema = getResultSchema(queryStrOrQueryBuilder)
|
|
35
35
|
const results = select(query, bindValues as unknown as PreparedBindValues)
|
|
@@ -44,7 +44,7 @@ export const validateSnapshot = (snapshot: Uint8Array) => {
|
|
|
44
44
|
const headerBytes = new TextDecoder().decode(snapshot.slice(0, 16))
|
|
45
45
|
const hasValidHeader = headerBytes.startsWith('SQLite format 3')
|
|
46
46
|
|
|
47
|
-
if (
|
|
47
|
+
if (hasValidHeader === false) {
|
|
48
48
|
throw new SqliteError({
|
|
49
49
|
cause: 'Invalid SQLite header',
|
|
50
50
|
note: `Expected header to start with 'SQLite format 3', but got: ${headerBytes}`,
|
package/src/sqlite-types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Effect, Schema } from '@livestore/utils/effect'
|
|
2
|
+
|
|
2
3
|
import type { SqliteError, UnknownError } from './errors.ts'
|
|
3
4
|
import type { EventSequenceNumber } from './schema/mod.ts'
|
|
4
5
|
import type { QueryBuilder } from './schema/state/sqlite/query-builder/api.ts'
|
|
@@ -17,12 +18,12 @@ export interface SqliteDb<TReq = any, TMetadata extends TReq = TReq> {
|
|
|
17
18
|
prepare(queryStr: string): PreparedStatement
|
|
18
19
|
execute(
|
|
19
20
|
queryStr: string,
|
|
20
|
-
bindValues?: PreparedBindValues
|
|
21
|
+
bindValues?: PreparedBindValues ,
|
|
21
22
|
options?: { onRowsChanged?: (rowsChanged: number) => void },
|
|
22
23
|
): void
|
|
23
24
|
execute(queryBuilder: QueryBuilder.Any, options?: { onRowsChanged?: (rowsChanged: number) => void }): void
|
|
24
25
|
|
|
25
|
-
select<T>(queryStr: string, bindValues?: PreparedBindValues
|
|
26
|
+
select<T>(queryStr: string, bindValues?: PreparedBindValues ): ReadonlyArray<T>
|
|
26
27
|
select<T>(queryBuilder: QueryBuilder<T, any, any>): T
|
|
27
28
|
|
|
28
29
|
export(): Uint8Array<ArrayBuffer>
|