@lix-js/sdk 0.0.1 → 0.2.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/LICENSE +21 -0
- package/dist/account/database-schema.d.ts.map +1 -1
- package/dist/account/database-schema.js +2 -6
- package/dist/account/database-schema.js.map +1 -1
- package/dist/account/database-schema.test.js +4 -8
- package/dist/account/database-schema.test.js.map +1 -1
- package/dist/change/apply-changes.js +9 -9
- package/dist/change/apply-changes.js.map +1 -1
- package/dist/change/apply-changes.test.js +5 -5
- package/dist/change/apply-changes.test.js.map +1 -1
- package/dist/database/apply-schema.d.ts.map +1 -1
- package/dist/database/apply-schema.js +20 -72
- package/dist/database/apply-schema.js.map +1 -1
- package/dist/database/execute-sync.test.js +3 -3
- package/dist/database/execute-sync.test.js.map +1 -1
- package/dist/database/init-db.d.ts.map +1 -1
- package/dist/database/init-db.js +18 -3
- package/dist/database/init-db.js.map +1 -1
- package/dist/database/init-db.test.js +128 -17
- package/dist/database/init-db.test.js.map +1 -1
- package/dist/database/kysely-plugin/parse-jsonb-plugin-v1.d.ts.map +1 -1
- package/dist/database/kysely-plugin/parse-jsonb-plugin-v1.js +5 -2
- package/dist/database/kysely-plugin/parse-jsonb-plugin-v1.js.map +1 -1
- package/dist/database/mutation-log/database-schema.d.ts.map +1 -1
- package/dist/database/mutation-log/database-schema.js +1 -3
- package/dist/database/mutation-log/database-schema.js.map +1 -1
- package/dist/database/nano-id.d.ts +21 -0
- package/dist/database/nano-id.d.ts.map +1 -0
- package/dist/database/nano-id.js +58 -0
- package/dist/database/nano-id.js.map +1 -0
- package/dist/database/nano-id.test.d.ts +2 -0
- package/dist/database/nano-id.test.d.ts.map +1 -0
- package/dist/database/nano-id.test.js +13 -0
- package/dist/database/nano-id.test.js.map +1 -0
- package/dist/database/schema.d.ts +15 -23
- package/dist/database/schema.d.ts.map +1 -1
- package/dist/discussion/create-comment.d.ts +0 -2
- package/dist/discussion/create-comment.d.ts.map +1 -1
- package/dist/discussion/create-comment.js +0 -1
- package/dist/discussion/create-comment.js.map +1 -1
- package/dist/discussion/create-discussion.d.ts +3 -5
- package/dist/discussion/create-discussion.d.ts.map +1 -1
- package/dist/discussion/create-discussion.js +4 -5
- package/dist/discussion/create-discussion.js.map +1 -1
- package/dist/discussion/create-discussion.test.js +8 -34
- package/dist/discussion/create-discussion.test.js.map +1 -1
- package/dist/file-queue/file-handlers.d.ts +24 -0
- package/dist/file-queue/file-handlers.d.ts.map +1 -0
- package/dist/file-queue/file-handlers.js +209 -0
- package/dist/file-queue/file-handlers.js.map +1 -0
- package/dist/file-queue/file-queue-process.d.ts +5 -0
- package/dist/file-queue/file-queue-process.d.ts.map +1 -0
- package/dist/file-queue/file-queue-process.js +88 -0
- package/dist/file-queue/file-queue-process.js.map +1 -0
- package/dist/file-queue/file-queue-process.test.d.ts +2 -0
- package/dist/file-queue/file-queue-process.test.d.ts.map +1 -0
- package/dist/file-queue/file-queue-process.test.js +372 -0
- package/dist/file-queue/file-queue-process.test.js.map +1 -0
- package/dist/file-queue/file-queue-settled.d.ts +13 -0
- package/dist/file-queue/file-queue-settled.d.ts.map +1 -0
- package/dist/file-queue/file-queue-settled.js +25 -0
- package/dist/file-queue/file-queue-settled.js.map +1 -0
- package/dist/file-queue/file-queue-settled.test.d.ts +2 -0
- package/dist/file-queue/file-queue-settled.test.d.ts.map +1 -0
- package/dist/file-queue/file-queue-settled.test.js +47 -0
- package/dist/file-queue/file-queue-settled.test.js.map +1 -0
- package/dist/file-queue/index.d.ts +2 -0
- package/dist/file-queue/index.d.ts.map +1 -0
- package/dist/file-queue/index.js +2 -0
- package/dist/file-queue/index.js.map +1 -0
- package/dist/file-queue/with-skip-file-queue.d.ts +3 -0
- package/dist/file-queue/with-skip-file-queue.d.ts.map +1 -0
- package/dist/file-queue/with-skip-file-queue.js +26 -0
- package/dist/file-queue/with-skip-file-queue.js.map +1 -0
- package/dist/file-queue/with-skip-file-queue.test.d.ts +2 -0
- package/dist/file-queue/with-skip-file-queue.test.d.ts.map +1 -0
- package/dist/file-queue/with-skip-file-queue.test.js +138 -0
- package/dist/file-queue/with-skip-file-queue.test.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/key-value/database-schema.d.ts +11 -2
- package/dist/key-value/database-schema.d.ts.map +1 -1
- package/dist/key-value/database-schema.js +7 -4
- package/dist/key-value/database-schema.js.map +1 -1
- package/dist/key-value/database-schema.test.js +21 -5
- package/dist/key-value/database-schema.test.js.map +1 -1
- package/dist/lix/close-lix.d.ts +8 -0
- package/dist/lix/close-lix.d.ts.map +1 -0
- package/dist/lix/close-lix.js +7 -0
- package/dist/lix/close-lix.js.map +1 -0
- package/dist/lix/index.d.ts +1 -0
- package/dist/lix/index.d.ts.map +1 -1
- package/dist/lix/index.js +1 -0
- package/dist/lix/index.js.map +1 -1
- package/dist/lix/merge.js +3 -3
- package/dist/lix/merge.js.map +1 -1
- package/dist/lix/merge.test.js +7 -18
- package/dist/lix/merge.test.js.map +1 -1
- package/dist/lix/new-lix.d.ts.map +1 -1
- package/dist/lix/new-lix.js +2 -3
- package/dist/lix/new-lix.js.map +1 -1
- package/dist/lix/open-lix-in-memory.test.js +2 -1
- package/dist/lix/open-lix-in-memory.test.js.map +1 -1
- package/dist/lix/open-lix.d.ts +19 -6
- package/dist/lix/open-lix.d.ts.map +1 -1
- package/dist/lix/open-lix.js +80 -18
- package/dist/lix/open-lix.js.map +1 -1
- package/dist/lix/open-lix.test.js +70 -7
- package/dist/lix/open-lix.test.js.map +1 -1
- package/dist/lix/to-blob.d.ts +11 -0
- package/dist/lix/to-blob.d.ts.map +1 -0
- package/dist/lix/to-blob.js +11 -0
- package/dist/lix/to-blob.js.map +1 -0
- package/dist/own-change-control/apply-own-change.d.ts +10 -0
- package/dist/own-change-control/apply-own-change.d.ts.map +1 -0
- package/dist/own-change-control/apply-own-change.js +69 -0
- package/dist/own-change-control/apply-own-change.js.map +1 -0
- package/dist/own-change-control/apply-own-change.test.d.ts +2 -0
- package/dist/own-change-control/apply-own-change.test.d.ts.map +1 -0
- package/dist/own-change-control/apply-own-change.test.js +297 -0
- package/dist/own-change-control/apply-own-change.test.js.map +1 -0
- package/dist/own-change-control/change-controlled-tables.d.ts +60 -0
- package/dist/own-change-control/change-controlled-tables.d.ts.map +1 -0
- package/dist/own-change-control/change-controlled-tables.js +70 -0
- package/dist/own-change-control/change-controlled-tables.js.map +1 -0
- package/dist/own-change-control/change-controlled-tables.test.d.ts +2 -0
- package/dist/own-change-control/change-controlled-tables.test.d.ts.map +1 -0
- package/dist/own-change-control/change-controlled-tables.test.js +48 -0
- package/dist/own-change-control/change-controlled-tables.test.js.map +1 -0
- package/dist/own-change-control/database-triggers.d.ts +5 -0
- package/dist/own-change-control/database-triggers.d.ts.map +1 -0
- package/dist/own-change-control/database-triggers.js +135 -0
- package/dist/own-change-control/database-triggers.js.map +1 -0
- package/dist/own-change-control/database-triggers.test.d.ts +2 -0
- package/dist/own-change-control/database-triggers.test.d.ts.map +1 -0
- package/dist/own-change-control/database-triggers.test.js +214 -0
- package/dist/own-change-control/database-triggers.test.js.map +1 -0
- package/dist/own-change-control/index.d.ts +2 -0
- package/dist/own-change-control/index.d.ts.map +1 -0
- package/dist/own-change-control/index.js +2 -0
- package/dist/own-change-control/index.js.map +1 -0
- package/dist/own-change-control/with-skip-own-change-control.d.ts +3 -0
- package/dist/own-change-control/with-skip-own-change-control.d.ts.map +1 -0
- package/dist/own-change-control/with-skip-own-change-control.js +28 -0
- package/dist/own-change-control/with-skip-own-change-control.js.map +1 -0
- package/dist/own-change-control/with-skip-own-change-control.test.d.ts +2 -0
- package/dist/own-change-control/with-skip-own-change-control.test.d.ts.map +1 -0
- package/dist/own-change-control/with-skip-own-change-control.test.js +49 -0
- package/dist/own-change-control/with-skip-own-change-control.test.js.map +1 -0
- package/dist/own-entity-change-control/apply-own-entity-change.js +2 -2
- package/dist/own-entity-change-control/apply-own-entity-change.js.map +1 -1
- package/dist/own-entity-change-control/apply-own-entity-change.test.js +9 -9
- package/dist/own-entity-change-control/apply-own-entity-change.test.js.map +1 -1
- package/dist/own-entity-change-control/database-triggers.js +6 -6
- package/dist/own-entity-change-control/database-triggers.js.map +1 -1
- package/dist/own-entity-change-control/database-triggers.test.js +1 -1
- package/dist/own-entity-change-control/database-triggers.test.js.map +1 -1
- package/dist/query-filter/version-change-in-difference.test.js +37 -29
- package/dist/query-filter/version-change-in-difference.test.js.map +1 -1
- package/dist/query-filter/version-change-in-symmetric-difference.test.js +37 -39
- package/dist/query-filter/version-change-in-symmetric-difference.test.js.map +1 -1
- package/dist/server-api-handler/environment/create-in-memory-environment.d.ts.map +1 -1
- package/dist/server-api-handler/environment/create-in-memory-environment.js +7 -3
- package/dist/server-api-handler/environment/create-in-memory-environment.js.map +1 -1
- package/dist/server-api-handler/environment/create-in-memory-environment.test.js +8 -7
- package/dist/server-api-handler/environment/create-in-memory-environment.test.js.map +1 -1
- package/dist/server-api-handler/routes/get-v1.d.ts.map +1 -1
- package/dist/server-api-handler/routes/get-v1.js +1 -2
- package/dist/server-api-handler/routes/get-v1.js.map +1 -1
- package/dist/server-api-handler/routes/get-v1.test.js +6 -5
- package/dist/server-api-handler/routes/get-v1.test.js.map +1 -1
- package/dist/server-api-handler/routes/new-v1.d.ts.map +1 -1
- package/dist/server-api-handler/routes/new-v1.js +3 -1
- package/dist/server-api-handler/routes/new-v1.js.map +1 -1
- package/dist/server-api-handler/routes/new-v1.test.js +2 -1
- package/dist/server-api-handler/routes/new-v1.test.js.map +1 -1
- package/dist/server-api-handler/routes/pull-v1.test.js +4 -3
- package/dist/server-api-handler/routes/pull-v1.test.js.map +1 -1
- package/dist/server-api-handler/routes/push-v1.test.js +5 -4
- package/dist/server-api-handler/routes/push-v1.test.js.map +1 -1
- package/dist/services/env-variables/index.d.ts +5 -0
- package/dist/services/env-variables/index.d.ts.map +1 -0
- package/dist/services/env-variables/index.js +5 -0
- package/dist/services/env-variables/index.js.map +1 -0
- package/dist/services/telemetry/capture.d.ts +30 -0
- package/dist/services/telemetry/capture.d.ts.map +1 -0
- package/dist/services/telemetry/capture.js +71 -0
- package/dist/services/telemetry/capture.js.map +1 -0
- package/dist/services/telemetry/capture.test.d.ts +2 -0
- package/dist/services/telemetry/capture.test.d.ts.map +1 -0
- package/dist/services/telemetry/capture.test.js +37 -0
- package/dist/services/telemetry/capture.test.js.map +1 -0
- package/dist/sync/pull-from-server.d.ts.map +1 -1
- package/dist/sync/pull-from-server.js +0 -2
- package/dist/sync/pull-from-server.js.map +1 -1
- package/dist/sync/pull-from-server.test.js +29 -14
- package/dist/sync/pull-from-server.test.js.map +1 -1
- package/dist/sync/push-to-server.test.js +17 -13
- package/dist/sync/push-to-server.test.js.map +1 -1
- package/dist/sync/sync-process.d.ts +2 -4
- package/dist/sync/sync-process.d.ts.map +1 -1
- package/dist/sync/sync-process.js +14 -13
- package/dist/sync/sync-process.js.map +1 -1
- package/dist/sync/sync-process.test.js +26 -38
- package/dist/sync/sync-process.test.js.map +1 -1
- package/dist/version/create-version.d.ts +5 -5
- package/dist/version/create-version.d.ts.map +1 -1
- package/dist/version/create-version.js +23 -11
- package/dist/version/create-version.js.map +1 -1
- package/dist/version/create-version.test.js +2 -2
- package/dist/version/create-version.test.js.map +1 -1
- package/dist/version/merge-version.d.ts.map +1 -1
- package/dist/version/merge-version.js +16 -26
- package/dist/version/merge-version.js.map +1 -1
- package/dist/version/switch-version.js +3 -3
- package/dist/version/switch-version.js.map +1 -1
- package/dist/version/switch-version.test.js +12 -15
- package/dist/version/switch-version.test.js.map +1 -1
- package/dist/version/update-changes-in-version.d.ts.map +1 -1
- package/dist/version/update-changes-in-version.js +11 -31
- package/dist/version/update-changes-in-version.js.map +1 -1
- package/package.json +7 -9
- package/src/account/database-schema.test.ts +6 -9
- package/src/account/database-schema.ts +2 -6
- package/src/change/apply-changes.test.ts +7 -7
- package/src/change/apply-changes.ts +9 -9
- package/src/database/apply-schema.ts +20 -73
- package/src/database/execute-sync.test.ts +3 -3
- package/src/database/init-db.test.ts +163 -19
- package/src/database/init-db.ts +20 -3
- package/src/database/kysely-plugin/parse-jsonb-plugin-v1.ts +9 -2
- package/src/database/mutation-log/database-schema.ts +1 -3
- package/src/database/nano-id.test.ts +15 -0
- package/src/database/nano-id.ts +72 -0
- package/src/database/schema.ts +15 -24
- package/src/discussion/create-comment.ts +0 -3
- package/src/discussion/create-discussion.test.ts +8 -39
- package/src/discussion/create-discussion.ts +6 -9
- package/src/{change-queue → file-queue}/file-handlers.ts +27 -27
- package/src/{change-queue/init-change-queue.test.ts → file-queue/file-queue-process.test.ts} +28 -29
- package/src/{change-queue/init-change-queue.ts → file-queue/file-queue-process.ts} +21 -16
- package/src/{change-queue/change-queue-settled.test.ts → file-queue/file-queue-settled.test.ts} +12 -12
- package/src/{change-queue/change-queue-settled.ts → file-queue/file-queue-settled.ts} +4 -4
- package/src/file-queue/index.ts +1 -0
- package/src/{change-queue/with-skip-change-queue.test.ts → file-queue/with-skip-file-queue.test.ts} +9 -9
- package/src/{change-queue/with-skip-change-queue.ts → file-queue/with-skip-file-queue.ts} +3 -3
- package/src/index.ts +2 -2
- package/src/key-value/database-schema.test.ts +26 -5
- package/src/key-value/database-schema.ts +18 -6
- package/src/lix/close-lix.ts +8 -0
- package/src/lix/index.ts +1 -0
- package/src/lix/merge.test.ts +7 -19
- package/src/lix/merge.ts +4 -4
- package/src/lix/new-lix.ts +2 -3
- package/src/lix/open-lix-in-memory.test.ts +5 -1
- package/src/lix/open-lix.test.ts +82 -7
- package/src/lix/open-lix.ts +104 -24
- package/src/lix/to-blob.ts +14 -0
- package/src/{own-entity-change-control/apply-own-entity-change.test.ts → own-change-control/apply-own-change.test.ts} +27 -31
- package/src/{own-entity-change-control/apply-own-entity-change.ts → own-change-control/apply-own-change.ts} +3 -3
- package/src/{own-entity-change-control → own-change-control}/change-controlled-tables.ts +0 -1
- package/src/{own-entity-change-control → own-change-control}/database-triggers.test.ts +7 -7
- package/src/{own-entity-change-control → own-change-control}/database-triggers.ts +11 -11
- package/src/{own-entity-change-control → own-change-control}/with-skip-own-change-control.ts +6 -2
- package/src/query-filter/version-change-in-difference.test.ts +41 -32
- package/src/query-filter/version-change-in-symmetric-difference.test.ts +41 -42
- package/src/server-api-handler/environment/create-in-memory-environment.test.ts +8 -7
- package/src/server-api-handler/environment/create-in-memory-environment.ts +7 -3
- package/src/server-api-handler/routes/get-v1.test.ts +6 -5
- package/src/server-api-handler/routes/get-v1.ts +1 -3
- package/src/server-api-handler/routes/new-v1.test.ts +2 -1
- package/src/server-api-handler/routes/new-v1.ts +3 -1
- package/src/server-api-handler/routes/pull-v1.test.ts +4 -3
- package/src/server-api-handler/routes/push-v1.test.ts +5 -4
- package/src/services/env-variables/create-index-file.js +35 -0
- package/src/services/env-variables/index.d.ts +15 -0
- package/src/services/telemetry/capture.test.ts +44 -0
- package/src/services/telemetry/capture.ts +99 -0
- package/src/sync/pull-from-server.test.ts +29 -14
- package/src/sync/pull-from-server.ts +0 -2
- package/src/sync/push-to-server.test.ts +19 -15
- package/src/sync/sync-process.test.ts +37 -43
- package/src/sync/sync-process.ts +16 -23
- package/src/version/create-version.test.ts +2 -2
- package/src/version/create-version.ts +24 -12
- package/src/version/merge-version.ts +18 -26
- package/src/version/switch-version.test.ts +12 -15
- package/src/version/switch-version.ts +3 -3
- package/src/version/update-changes-in-version.ts +11 -30
- package/node_modules/@lix-js/server-api-schema/.prettierrc.json +0 -3
- package/node_modules/@lix-js/server-api-schema/.vscode/extensions.json +0 -3
- package/node_modules/@lix-js/server-api-schema/dist/schema.d.ts +0 -384
- package/node_modules/@lix-js/server-api-schema/package.json +0 -21
- package/node_modules/@lix-js/server-api-schema/src/schema.yaml +0 -290
- package/node_modules/@lix-js/server-api-schema/tsconfig.json +0 -20
- package/node_modules/sqlite-wasm-kysely/README.md +0 -11
- package/node_modules/sqlite-wasm-kysely/dist/dialect.d.ts +0 -11
- package/node_modules/sqlite-wasm-kysely/dist/dialect.js +0 -13
- package/node_modules/sqlite-wasm-kysely/dist/dialect.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/index.d.ts +0 -2
- package/node_modules/sqlite-wasm-kysely/dist/index.js +0 -3
- package/node_modules/sqlite-wasm-kysely/dist/index.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.d.ts +0 -5
- package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.js +0 -34
- package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.d.ts +0 -8
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.js +0 -57
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.d.ts +0 -18
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.js +0 -2
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.d.ts +0 -13
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.js +0 -57
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/index.d.ts +0 -4
- package/node_modules/sqlite-wasm-kysely/dist/kysely/index.js +0 -4
- package/node_modules/sqlite-wasm-kysely/dist/kysely/index.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.d.ts +0 -3
- package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.js +0 -5
- package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.d.ts +0 -9
- package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.js +0 -12
- package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.d.ts +0 -3
- package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.js +0 -22
- package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.d.ts +0 -7
- package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.js +0 -15
- package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/index.d.ts +0 -5
- package/node_modules/sqlite-wasm-kysely/dist/util/index.js +0 -5
- package/node_modules/sqlite-wasm-kysely/dist/util/index.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.d.ts +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.js +0 -13
- package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.d.ts +0 -7
- package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.js +0 -17
- package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/package.json +0 -34
- package/node_modules/sqlite-wasm-kysely/src/dialect.ts +0 -15
- package/node_modules/sqlite-wasm-kysely/src/index.ts +0 -2
- package/node_modules/sqlite-wasm-kysely/src/kysely/ConnectionMutex.ts +0 -23
- package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmConnection.ts +0 -57
- package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmDialectConfig.ts +0 -19
- package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmDriver.ts +0 -58
- package/node_modules/sqlite-wasm-kysely/src/kysely/index.ts +0 -4
- package/node_modules/sqlite-wasm-kysely/src/kysely/sqliteModule.ts +0 -7
- package/node_modules/sqlite-wasm-kysely/src/util/contentFromDatabase.ts +0 -13
- package/node_modules/sqlite-wasm-kysely/src/util/createInMemoryDatabase.ts +0 -30
- package/node_modules/sqlite-wasm-kysely/src/util/importDatabase.ts +0 -34
- package/node_modules/sqlite-wasm-kysely/src/util/index.ts +0 -5
- package/node_modules/sqlite-wasm-kysely/src/util/loadDatabaseInMemory.ts +0 -13
- package/node_modules/sqlite-wasm-kysely/src/util/sqliteWasmBinary.ts +0 -20
- package/src/change-queue/index.ts +0 -1
- /package/src/{own-entity-change-control → own-change-control}/change-controlled-tables.test.ts +0 -0
- /package/src/{own-entity-change-control → own-change-control}/index.ts +0 -0
- /package/src/{own-entity-change-control → own-change-control}/with-skip-own-change-control.test.ts +0 -0
package/src/lix/open-lix.test.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { expect, test } from "vitest";
|
|
|
2
2
|
import { openLixInMemory } from "./open-lix-in-memory.js";
|
|
3
3
|
import { newLixFile } from "./new-lix.js";
|
|
4
4
|
import type { LixPlugin } from "../plugin/lix-plugin.js";
|
|
5
|
+
import { toBlob } from "./to-blob.js";
|
|
6
|
+
import { usedFileExtensions } from "./open-lix.js";
|
|
5
7
|
|
|
6
8
|
test("providing plugins should be possible", async () => {
|
|
7
9
|
const mockPlugin: LixPlugin = {
|
|
@@ -17,17 +19,90 @@ test("providing plugins should be possible", async () => {
|
|
|
17
19
|
test("providing key values should be possible", async () => {
|
|
18
20
|
const lix = await openLixInMemory({
|
|
19
21
|
blob: await newLixFile(),
|
|
20
|
-
keyValues: [{ key: "
|
|
22
|
+
keyValues: [{ key: "mock_key", value: "value" }],
|
|
21
23
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
|
|
25
|
+
const value = await lix.db
|
|
26
|
+
.selectFrom("key_value")
|
|
27
|
+
.selectAll()
|
|
28
|
+
.where("key", "=", "mock_key")
|
|
29
|
+
.executeTakeFirstOrThrow();
|
|
30
|
+
|
|
31
|
+
expect(value).toMatchObject({ key: "mock_key", value: "value" });
|
|
24
32
|
|
|
25
33
|
// testing overwriting key values
|
|
26
34
|
const lix1 = await openLixInMemory({
|
|
27
|
-
blob: await
|
|
28
|
-
keyValues: [{ key: "
|
|
35
|
+
blob: await toBlob({ lix }),
|
|
36
|
+
keyValues: [{ key: "mock_key", value: "value2" }],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const value1 = await lix1.db
|
|
40
|
+
.selectFrom("key_value")
|
|
41
|
+
.selectAll()
|
|
42
|
+
.where("key", "=", "mock_key")
|
|
43
|
+
|
|
44
|
+
.executeTakeFirstOrThrow();
|
|
45
|
+
expect(value1).toMatchObject({ key: "mock_key", value: "value2" });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("providing an account should be possible", async () => {
|
|
49
|
+
const mockAccount = {
|
|
50
|
+
id: "mock-account",
|
|
51
|
+
name: "peter",
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const lix = await openLixInMemory({
|
|
55
|
+
account: mockAccount,
|
|
56
|
+
blob: await newLixFile(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const accounts = await lix.db
|
|
60
|
+
.selectFrom("active_account")
|
|
61
|
+
.selectAll()
|
|
62
|
+
.execute();
|
|
63
|
+
|
|
64
|
+
expect(accounts, "to be the provided account").toContainEqual(mockAccount);
|
|
65
|
+
expect(accounts, "no other active account is inserted").lengthOf(1);
|
|
66
|
+
|
|
67
|
+
await lix.db
|
|
68
|
+
.insertInto("key_value")
|
|
69
|
+
.values([{ key: "mock_key", value: "something" }])
|
|
70
|
+
.execute();
|
|
71
|
+
|
|
72
|
+
// lix automatically handles inserting the active account into the account table
|
|
73
|
+
const change = await lix.db
|
|
74
|
+
.selectFrom("change")
|
|
75
|
+
.innerJoin("change_author", "change_author.change_id", "change.id")
|
|
76
|
+
.where("schema_key", "=", "lix_key_value_table")
|
|
77
|
+
.where("entity_id", "=", "mock_key")
|
|
78
|
+
.select("change_author.account_id")
|
|
79
|
+
.executeTakeFirstOrThrow();
|
|
80
|
+
|
|
81
|
+
expect(change.account_id).toBe(mockAccount.id);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("usedFileExtensions", async () => {
|
|
85
|
+
const lix = await openLixInMemory({
|
|
86
|
+
blob: await newLixFile(),
|
|
29
87
|
});
|
|
88
|
+
await lix.db
|
|
89
|
+
.insertInto("file")
|
|
90
|
+
.values([
|
|
91
|
+
{
|
|
92
|
+
path: "/test.txt",
|
|
93
|
+
data: new Uint8Array(),
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
path: "/test2.txt",
|
|
97
|
+
data: new Uint8Array(),
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
path: "/folder/folderwithdot./doc.pdf",
|
|
101
|
+
data: new Uint8Array(),
|
|
102
|
+
},
|
|
103
|
+
])
|
|
104
|
+
.execute();
|
|
30
105
|
|
|
31
|
-
const
|
|
32
|
-
expect(
|
|
106
|
+
const extensions = await usedFileExtensions(lix.db);
|
|
107
|
+
expect(new Set(extensions)).toEqual(new Set(["txt", "pdf"]));
|
|
33
108
|
});
|
package/src/lix/open-lix.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { LixPlugin } from "../plugin/lix-plugin.js";
|
|
2
2
|
import { loadPlugins } from "../plugin/load-plugin.js";
|
|
3
|
-
import {
|
|
3
|
+
import { type SqliteDatabase } from "sqlite-wasm-kysely";
|
|
4
4
|
import { initDb } from "../database/init-db.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import type { Kysely } from "kysely";
|
|
5
|
+
import { initFileQueueProcess } from "../file-queue/file-queue-process.js";
|
|
6
|
+
import { sql, type Kysely } from "kysely";
|
|
8
7
|
import type { LixDatabaseSchema } from "../database/schema.js";
|
|
9
8
|
import { initSyncProcess } from "../sync/sync-process.js";
|
|
10
|
-
import type {
|
|
9
|
+
import type { NewKeyValue } from "../key-value/database-schema.js";
|
|
10
|
+
import { capture } from "../services/telemetry/capture.js";
|
|
11
|
+
import { ENV_VARIABLES } from "../services/env-variables/index.js";
|
|
12
|
+
import type { Account } from "../account/database-schema.js";
|
|
11
13
|
|
|
12
14
|
export type Lix = {
|
|
13
15
|
/**
|
|
@@ -22,17 +24,25 @@ export type Lix = {
|
|
|
22
24
|
*/
|
|
23
25
|
sqlite: SqliteDatabase;
|
|
24
26
|
db: Kysely<LixDatabaseSchema>;
|
|
25
|
-
toBlob: () => Promise<Blob>;
|
|
26
27
|
plugin: {
|
|
27
28
|
getAll: () => Promise<LixPlugin[]>;
|
|
28
29
|
};
|
|
29
|
-
close: () => Promise<void>;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Common setup between different lix environments.
|
|
34
34
|
*/
|
|
35
35
|
export async function openLix(args: {
|
|
36
|
+
/**
|
|
37
|
+
* The account that is opening this lix.
|
|
38
|
+
*
|
|
39
|
+
* Lix will automatically set the active account to the provided account.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const account = localStorage.getItem("account")
|
|
43
|
+
* const lix = await openLix({ account })
|
|
44
|
+
*/
|
|
45
|
+
account?: Account;
|
|
36
46
|
database: SqliteDatabase;
|
|
37
47
|
/**
|
|
38
48
|
* Usecase are lix apps that define their own file format,
|
|
@@ -52,9 +62,9 @@ export async function openLix(args: {
|
|
|
52
62
|
* Set the key values when opening the lix.
|
|
53
63
|
*
|
|
54
64
|
* @example
|
|
55
|
-
* const lix = await openLix({ keyValues: [{ key: "
|
|
65
|
+
* const lix = await openLix({ keyValues: [{ key: "lix_sync", value: "false" }] })
|
|
56
66
|
*/
|
|
57
|
-
keyValues?:
|
|
67
|
+
keyValues?: NewKeyValue[];
|
|
58
68
|
}): Promise<Lix> {
|
|
59
69
|
const db = initDb({ sqlite: args.database });
|
|
60
70
|
|
|
@@ -68,6 +78,18 @@ export async function openLix(args: {
|
|
|
68
78
|
.execute();
|
|
69
79
|
}
|
|
70
80
|
|
|
81
|
+
if (args.account) {
|
|
82
|
+
await db.transaction().execute(async (trx) => {
|
|
83
|
+
// delete the default inserted active account from `initDb`
|
|
84
|
+
await trx.deleteFrom("active_account").execute();
|
|
85
|
+
await trx
|
|
86
|
+
.insertInto("active_account")
|
|
87
|
+
.values(args.account!)
|
|
88
|
+
.onConflict((oc) => oc.doUpdateSet(() => ({ ...args.account })))
|
|
89
|
+
.execute();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
71
93
|
const plugins = await loadPlugins(db);
|
|
72
94
|
if (args.providePlugins && args.providePlugins.length > 0) {
|
|
73
95
|
plugins.push(...args.providePlugins);
|
|
@@ -77,27 +99,85 @@ export async function openLix(args: {
|
|
|
77
99
|
getAll: async () => plugins,
|
|
78
100
|
};
|
|
79
101
|
|
|
80
|
-
|
|
81
|
-
await changeQueueSettled({ lix: { db } });
|
|
82
|
-
return new Blob([contentFromDatabase(args.database)]);
|
|
83
|
-
};
|
|
102
|
+
initFileQueueProcess({ lix: { db, plugin, sqlite: args.database } });
|
|
84
103
|
|
|
85
|
-
|
|
86
|
-
lix: { db, plugin, sqlite: args.database },
|
|
87
|
-
rawDatabase: args.database,
|
|
88
|
-
});
|
|
104
|
+
initSyncProcess({ lix: { db, plugin, sqlite: args.database } });
|
|
89
105
|
|
|
90
|
-
|
|
106
|
+
captureOpened({ db });
|
|
91
107
|
|
|
92
108
|
return {
|
|
93
109
|
db,
|
|
94
110
|
sqlite: args.database,
|
|
95
|
-
toBlob,
|
|
96
111
|
plugin,
|
|
97
|
-
close: async () => {
|
|
98
|
-
await changeQueueSettled({ lix: { db } });
|
|
99
|
-
// args.database.close();
|
|
100
|
-
// await db.destroy();
|
|
101
|
-
},
|
|
102
112
|
};
|
|
103
113
|
}
|
|
114
|
+
|
|
115
|
+
async function captureOpened(args: { db: Kysely<LixDatabaseSchema> }) {
|
|
116
|
+
try {
|
|
117
|
+
const telemetry = await args.db
|
|
118
|
+
.selectFrom("key_value")
|
|
119
|
+
.select("value")
|
|
120
|
+
.where("key", "=", "lix_telemetry")
|
|
121
|
+
.executeTakeFirst();
|
|
122
|
+
|
|
123
|
+
if (telemetry?.value === "off") {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const activeAccount = await args.db
|
|
128
|
+
.selectFrom("active_account")
|
|
129
|
+
.select("id")
|
|
130
|
+
.executeTakeFirstOrThrow();
|
|
131
|
+
|
|
132
|
+
const lixId = await args.db
|
|
133
|
+
.selectFrom("key_value")
|
|
134
|
+
.select("value")
|
|
135
|
+
.where("key", "=", "lix_id")
|
|
136
|
+
.executeTakeFirstOrThrow();
|
|
137
|
+
|
|
138
|
+
const fileExtensions = await usedFileExtensions(args.db);
|
|
139
|
+
|
|
140
|
+
await capture("LIX-SDK lix opened", {
|
|
141
|
+
accountId: activeAccount.id,
|
|
142
|
+
lixId: lixId.value,
|
|
143
|
+
telemetryKeyValue: telemetry?.value ?? "on",
|
|
144
|
+
properties: {
|
|
145
|
+
lix_sdk_version: ENV_VARIABLES.LIX_SDK_VERSION,
|
|
146
|
+
stored_file_extensions: fileExtensions,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
} catch {
|
|
150
|
+
// ignore
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get all used file extensions.
|
|
156
|
+
*/
|
|
157
|
+
export async function usedFileExtensions(
|
|
158
|
+
db: Kysely<LixDatabaseSchema>
|
|
159
|
+
): Promise<any> {
|
|
160
|
+
const result = await sql`
|
|
161
|
+
WITH RECURSIVE numbers(i) AS (
|
|
162
|
+
SELECT 1
|
|
163
|
+
UNION ALL
|
|
164
|
+
SELECT i + 1 FROM numbers WHERE i < 1000 -- Limit to 1000 characters for path length
|
|
165
|
+
),
|
|
166
|
+
REVERSED AS (
|
|
167
|
+
SELECT id,
|
|
168
|
+
GROUP_CONCAT(SUBSTR(path, LENGTH(path) - i + 1, 1), '') AS reversed_path
|
|
169
|
+
FROM file, numbers
|
|
170
|
+
WHERE i <= LENGTH(path)
|
|
171
|
+
GROUP BY id, path
|
|
172
|
+
),
|
|
173
|
+
EXTENSIONS AS (
|
|
174
|
+
SELECT DISTINCT SUBSTR(path, LENGTH(path) - INSTR(reversed_path, '.') + 2) AS extension
|
|
175
|
+
FROM file
|
|
176
|
+
JOIN REVERSED ON file.id = REVERSED.id
|
|
177
|
+
WHERE INSTR(reversed_path, '.') > 0
|
|
178
|
+
)
|
|
179
|
+
SELECT extension FROM EXTENSIONS;
|
|
180
|
+
`.execute(db);
|
|
181
|
+
|
|
182
|
+
return result.rows.map((row) => (row as any).extension);
|
|
183
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { contentFromDatabase } from "sqlite-wasm-kysely";
|
|
2
|
+
import type { Lix } from "./open-lix.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert the lix to a blob.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const blob = await toBlob({ lix })
|
|
9
|
+
*/
|
|
10
|
+
export async function toBlob(args: {
|
|
11
|
+
lix: Pick<Lix, "db" | "sqlite">;
|
|
12
|
+
}): Promise<Blob> {
|
|
13
|
+
return new Blob([contentFromDatabase(args.lix.sqlite)]);
|
|
14
|
+
}
|
|
@@ -5,9 +5,9 @@ import type {
|
|
|
5
5
|
ChangeSet,
|
|
6
6
|
ChangeSetElement,
|
|
7
7
|
} from "../database/schema.js";
|
|
8
|
-
import {
|
|
8
|
+
import { applyOwnChanges } from "./apply-own-change.js";
|
|
9
9
|
import { mockJsonSnapshot } from "../snapshot/mock-json-snapshot.js";
|
|
10
|
-
import { type
|
|
10
|
+
import { type NewKeyValue } from "../key-value/database-schema.js";
|
|
11
11
|
|
|
12
12
|
test("it should apply insert changes correctly", async () => {
|
|
13
13
|
const lix = await openLixInMemory({});
|
|
@@ -21,8 +21,8 @@ test("it should apply insert changes correctly", async () => {
|
|
|
21
21
|
id: "change1",
|
|
22
22
|
entity_id: "key1",
|
|
23
23
|
schema_key: "lix_key_value_table",
|
|
24
|
-
plugin_key: "
|
|
25
|
-
file_id: "
|
|
24
|
+
plugin_key: "lix_own_change_control",
|
|
25
|
+
file_id: "lix_own_change_control",
|
|
26
26
|
snapshot_id: snapshot.id,
|
|
27
27
|
created_at: "2021-01-01T00:00:00.000Z",
|
|
28
28
|
};
|
|
@@ -32,7 +32,7 @@ test("it should apply insert changes correctly", async () => {
|
|
|
32
32
|
.values({ content: snapshot.content })
|
|
33
33
|
.execute();
|
|
34
34
|
|
|
35
|
-
await
|
|
35
|
+
await applyOwnChanges({ lix, changes: [change] });
|
|
36
36
|
|
|
37
37
|
const result = await lix.db
|
|
38
38
|
.selectFrom("key_value")
|
|
@@ -40,7 +40,7 @@ test("it should apply insert changes correctly", async () => {
|
|
|
40
40
|
.selectAll()
|
|
41
41
|
.executeTakeFirst();
|
|
42
42
|
|
|
43
|
-
expect(result).
|
|
43
|
+
expect(result).toMatchObject({ key: "key1", value: "value1" });
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
test("it should apply update changes correctly", async () => {
|
|
@@ -60,9 +60,9 @@ test("it should apply update changes correctly", async () => {
|
|
|
60
60
|
id: "change1",
|
|
61
61
|
schema_key: "lix_key_value_table",
|
|
62
62
|
entity_id: "key1",
|
|
63
|
-
file_id: "
|
|
63
|
+
file_id: "lix_own_change_control",
|
|
64
64
|
created_at: "2021-01-01T00:00:00.000Z",
|
|
65
|
-
plugin_key: "
|
|
65
|
+
plugin_key: "lix_own_change_control",
|
|
66
66
|
snapshot_id: snapshot.id,
|
|
67
67
|
};
|
|
68
68
|
|
|
@@ -73,7 +73,7 @@ test("it should apply update changes correctly", async () => {
|
|
|
73
73
|
})
|
|
74
74
|
.execute();
|
|
75
75
|
|
|
76
|
-
await
|
|
76
|
+
await applyOwnChanges({ lix, changes: [change] });
|
|
77
77
|
|
|
78
78
|
const result = await lix.db
|
|
79
79
|
.selectFrom("key_value")
|
|
@@ -81,7 +81,7 @@ test("it should apply update changes correctly", async () => {
|
|
|
81
81
|
.selectAll()
|
|
82
82
|
.executeTakeFirst();
|
|
83
83
|
|
|
84
|
-
expect(result).
|
|
84
|
+
expect(result).toMatchObject({ key: "key1", value: "new_value" });
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
test("it should apply delete changes correctly", async () => {
|
|
@@ -95,14 +95,14 @@ test("it should apply delete changes correctly", async () => {
|
|
|
95
95
|
const change: Change = {
|
|
96
96
|
id: "change1",
|
|
97
97
|
schema_key: "lix_key_value_table",
|
|
98
|
-
file_id: "
|
|
98
|
+
file_id: "lix_own_change_control",
|
|
99
99
|
created_at: "2021-01-01T00:00:00.000Z",
|
|
100
100
|
entity_id: "key1",
|
|
101
|
-
plugin_key: "
|
|
101
|
+
plugin_key: "lix_own_change_control",
|
|
102
102
|
snapshot_id: "no-content",
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
await
|
|
105
|
+
await applyOwnChanges({ lix, changes: [change] });
|
|
106
106
|
|
|
107
107
|
const result = await lix.db
|
|
108
108
|
.selectFrom("key_value")
|
|
@@ -120,7 +120,7 @@ test("it should throw an error for invalid plugin key", async () => {
|
|
|
120
120
|
id: "change1",
|
|
121
121
|
schema_key: "lix_key_value_table",
|
|
122
122
|
entity_id: "key1",
|
|
123
|
-
file_id: "
|
|
123
|
+
file_id: "lix_own_change_control",
|
|
124
124
|
created_at: "2021-01-01T00:00:00.000Z",
|
|
125
125
|
plugin_key: "invalid-plugin",
|
|
126
126
|
snapshot_id: "snapshot1",
|
|
@@ -138,10 +138,8 @@ test("it should throw an error for invalid plugin key", async () => {
|
|
|
138
138
|
})
|
|
139
139
|
.execute();
|
|
140
140
|
|
|
141
|
-
await expect(
|
|
142
|
-
|
|
143
|
-
).rejects.toThrow(
|
|
144
|
-
"Expected 'lix_own_entity' as plugin key but received invalid-plugin"
|
|
141
|
+
await expect(applyOwnChanges({ lix, changes: [change] })).rejects.toThrow(
|
|
142
|
+
"Expected 'lix_own_change_control' as plugin key but received invalid-plugin"
|
|
145
143
|
);
|
|
146
144
|
});
|
|
147
145
|
|
|
@@ -189,13 +187,13 @@ test("file.data is not changed by applyOwnEntityChanges", async () => {
|
|
|
189
187
|
id: "change1",
|
|
190
188
|
entity_id: file.id,
|
|
191
189
|
schema_key: "lix_file_table",
|
|
192
|
-
plugin_key: "
|
|
190
|
+
plugin_key: "lix_own_change_control",
|
|
193
191
|
file_id: "null",
|
|
194
192
|
snapshot_id: snapshot.id,
|
|
195
193
|
created_at: "2021-01-01T00:00:00.000Z",
|
|
196
194
|
};
|
|
197
195
|
|
|
198
|
-
await
|
|
196
|
+
await applyOwnChanges({ lix, changes: [mockChange] });
|
|
199
197
|
|
|
200
198
|
const result = await lix.db
|
|
201
199
|
.selectFrom("file")
|
|
@@ -230,7 +228,7 @@ test("foreign key constraints are deferred to make the order of applying changes
|
|
|
230
228
|
id: "change2",
|
|
231
229
|
entity_id: "change-set-1,change0",
|
|
232
230
|
schema_key: "lix_change_set_element_table",
|
|
233
|
-
plugin_key: "
|
|
231
|
+
plugin_key: "lix_own_change_control",
|
|
234
232
|
file_id: "null",
|
|
235
233
|
snapshot_id: snapshots[1].id,
|
|
236
234
|
created_at: "2021-01-01T00:00:00.000Z",
|
|
@@ -239,7 +237,7 @@ test("foreign key constraints are deferred to make the order of applying changes
|
|
|
239
237
|
id: "change1",
|
|
240
238
|
entity_id: "change-set-1",
|
|
241
239
|
schema_key: "lix_change_set_table",
|
|
242
|
-
plugin_key: "
|
|
240
|
+
plugin_key: "lix_own_change_control",
|
|
243
241
|
file_id: "null",
|
|
244
242
|
snapshot_id: snapshots[0].id,
|
|
245
243
|
created_at: "2021-01-01T00:00:00.000Z",
|
|
@@ -270,7 +268,7 @@ test("foreign key constraints are deferred to make the order of applying changes
|
|
|
270
268
|
.execute();
|
|
271
269
|
|
|
272
270
|
await expect(
|
|
273
|
-
|
|
271
|
+
applyOwnChanges({ lix, changes: mockChanges })
|
|
274
272
|
).resolves.toBeUndefined();
|
|
275
273
|
});
|
|
276
274
|
|
|
@@ -291,8 +289,8 @@ test("foreign key constraints are obeyed", async () => {
|
|
|
291
289
|
// the change set for this change does not exist
|
|
292
290
|
entity_id: "change-set-1,change0",
|
|
293
291
|
schema_key: "lix_change_set_element_table",
|
|
294
|
-
plugin_key: "
|
|
295
|
-
file_id: "
|
|
292
|
+
plugin_key: "lix_own_change_control",
|
|
293
|
+
file_id: "lix_own_change_control",
|
|
296
294
|
snapshot_id: snapshots[0].id,
|
|
297
295
|
created_at: "2021-01-01T00:00:00.000Z",
|
|
298
296
|
},
|
|
@@ -321,9 +319,7 @@ test("foreign key constraints are obeyed", async () => {
|
|
|
321
319
|
})
|
|
322
320
|
.execute();
|
|
323
321
|
|
|
324
|
-
expect(
|
|
325
|
-
applyOwnEntityChanges({ lix, changes: mockChanges })
|
|
326
|
-
).rejects.toThrow();
|
|
322
|
+
expect(applyOwnChanges({ lix, changes: mockChanges })).rejects.toThrow();
|
|
327
323
|
});
|
|
328
324
|
|
|
329
325
|
// https://github.com/opral/lix-sdk/issues/185
|
|
@@ -333,7 +329,7 @@ test("applying own entity changes doesn't lead to the creation of new changes",
|
|
|
333
329
|
const snapshot = mockJsonSnapshot({
|
|
334
330
|
key: "mock-key",
|
|
335
331
|
value: "1+1=2",
|
|
336
|
-
} satisfies
|
|
332
|
+
} satisfies NewKeyValue);
|
|
337
333
|
|
|
338
334
|
await lix.db
|
|
339
335
|
.insertInto("snapshot")
|
|
@@ -344,14 +340,14 @@ test("applying own entity changes doesn't lead to the creation of new changes",
|
|
|
344
340
|
|
|
345
341
|
const changesBefore = await lix.db.selectFrom("change").selectAll().execute();
|
|
346
342
|
|
|
347
|
-
await
|
|
343
|
+
await applyOwnChanges({
|
|
348
344
|
lix,
|
|
349
345
|
changes: [
|
|
350
346
|
{
|
|
351
347
|
id: "change0",
|
|
352
348
|
entity_id: "mock-key",
|
|
353
349
|
file_id: "null",
|
|
354
|
-
plugin_key: "
|
|
350
|
+
plugin_key: "lix_own_change_control",
|
|
355
351
|
schema_key: "lix_key_value_table",
|
|
356
352
|
snapshot_id: snapshot.id,
|
|
357
353
|
created_at: "2021-01-01T00:00:00Z",
|
|
@@ -16,7 +16,7 @@ import { withSkipOwnChangeControl } from "./with-skip-own-change-control.js";
|
|
|
16
16
|
/**
|
|
17
17
|
* Applies own changes to lix itself.
|
|
18
18
|
*/
|
|
19
|
-
export async function
|
|
19
|
+
export async function applyOwnChanges(args: {
|
|
20
20
|
lix: Pick<Lix, "db">;
|
|
21
21
|
changes: Change[];
|
|
22
22
|
}): Promise<void> {
|
|
@@ -31,9 +31,9 @@ export async function applyOwnEntityChanges(args: {
|
|
|
31
31
|
|
|
32
32
|
await Promise.all(
|
|
33
33
|
args.changes.map(async (change) => {
|
|
34
|
-
if (change.plugin_key !== "
|
|
34
|
+
if (change.plugin_key !== "lix_own_change_control") {
|
|
35
35
|
throw new Error(
|
|
36
|
-
"Expected '
|
|
36
|
+
"Expected 'lix_own_change_control' as plugin key but received " +
|
|
37
37
|
change.plugin_key
|
|
38
38
|
);
|
|
39
39
|
}
|
|
@@ -5,7 +5,6 @@ export const changeControlledTableIds = {
|
|
|
5
5
|
change_author: ["change_id", "account_id"],
|
|
6
6
|
change_set_element: ["change_set_id", "change_id"],
|
|
7
7
|
change_set_label: ["label_id", "change_set_id"],
|
|
8
|
-
change_set_label_author: ["label_id", "change_set_id", "account_id"],
|
|
9
8
|
discussion: ["id"],
|
|
10
9
|
file: ["id"],
|
|
11
10
|
key_value: ["key"],
|
|
@@ -35,12 +35,12 @@ test("it works for inserts, updates and deletions", async () => {
|
|
|
35
35
|
|
|
36
36
|
for (const change of changes) {
|
|
37
37
|
expect(change.entity_id).toBe("key1");
|
|
38
|
-
expect(change.file_id).toBe("
|
|
39
|
-
expect(change.plugin_key).toBe("
|
|
38
|
+
expect(change.file_id).toBe("lix_own_change_control");
|
|
39
|
+
expect(change.plugin_key).toBe("lix_own_change_control");
|
|
40
40
|
expect(change.schema_key).toBe("lix_key_value_table");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
expect(snapshots).
|
|
43
|
+
expect(snapshots).toMatchObject([
|
|
44
44
|
// insert
|
|
45
45
|
{ key: "key1", value: "value1" },
|
|
46
46
|
// update
|
|
@@ -125,23 +125,23 @@ test("if the trigger throws, the transaction is rolled back", async () => {
|
|
|
125
125
|
expect(deleteChange).toBeUndefined();
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
-
test("skips change control of key values if
|
|
128
|
+
test("skips change control of key values if `skip_change_control` is set to true", async () => {
|
|
129
129
|
const lix = await openLixInMemory({});
|
|
130
130
|
|
|
131
131
|
await lix.db
|
|
132
132
|
.insertInto("key_value")
|
|
133
|
-
.values({ key: "
|
|
133
|
+
.values({ key: "key1", value: "value1", skip_change_control: true })
|
|
134
134
|
.execute();
|
|
135
135
|
|
|
136
136
|
const key1 = await lix.db
|
|
137
137
|
.selectFrom("key_value")
|
|
138
|
-
.where("key", "=", "
|
|
138
|
+
.where("key", "=", "key1")
|
|
139
139
|
.selectAll()
|
|
140
140
|
.executeTakeFirst();
|
|
141
141
|
|
|
142
142
|
const key1Change = await lix.db
|
|
143
143
|
.selectFrom("change")
|
|
144
|
-
.where("entity_id", "=", "
|
|
144
|
+
.where("entity_id", "=", "key1")
|
|
145
145
|
.selectAll()
|
|
146
146
|
.executeTakeFirst();
|
|
147
147
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { createChange } from "../change/create-change.js";
|
|
10
10
|
import { executeSync } from "../database/execute-sync.js";
|
|
11
11
|
|
|
12
|
-
export function
|
|
12
|
+
export function applyOwnChangeControlTriggers(
|
|
13
13
|
sqlite: SqliteDatabase,
|
|
14
14
|
db: Kysely<LixDatabaseSchema>
|
|
15
15
|
): void {
|
|
@@ -24,7 +24,7 @@ export function applyOwnEntityChangeControlTriggers(
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
sqlite.createFunction({
|
|
27
|
-
name: "
|
|
27
|
+
name: "handle_lix_own_change_control",
|
|
28
28
|
arity: -1,
|
|
29
29
|
// @ts-expect-error - dynamic function
|
|
30
30
|
xFunc: (
|
|
@@ -51,7 +51,7 @@ export function applyOwnEntityChangeControlTriggers(
|
|
|
51
51
|
CREATE TEMP TRIGGER IF NOT EXISTS ${table}_change_control_insert
|
|
52
52
|
AFTER INSERT ON ${table}
|
|
53
53
|
BEGIN
|
|
54
|
-
SELECT
|
|
54
|
+
SELECT handle_lix_own_change_control('${table}', 'insert', ${tableInfo.map((c) => "NEW." + c.name).join(", ")});
|
|
55
55
|
END;
|
|
56
56
|
|
|
57
57
|
CREATE TEMP TRIGGER IF NOT EXISTS ${table}_change_control_update
|
|
@@ -69,13 +69,13 @@ export function applyOwnEntityChangeControlTriggers(
|
|
|
69
69
|
: ""
|
|
70
70
|
}
|
|
71
71
|
BEGIN
|
|
72
|
-
SELECT
|
|
72
|
+
SELECT handle_lix_own_change_control('${table}', 'update', ${tableInfo.map((c) => "NEW." + c.name).join(", ")});
|
|
73
73
|
END;
|
|
74
74
|
|
|
75
75
|
CREATE TEMP TRIGGER IF NOT EXISTS ${table}_change_control_delete
|
|
76
76
|
AFTER DELETE ON ${table}
|
|
77
77
|
BEGIN
|
|
78
|
-
SELECT
|
|
78
|
+
SELECT handle_lix_own_change_control('${table}', 'delete', ${tableInfo.map((c) => "OLD." + c.name).join(", ")});
|
|
79
79
|
END;
|
|
80
80
|
`;
|
|
81
81
|
|
|
@@ -93,8 +93,8 @@ function handleLixOwnEntityChange(
|
|
|
93
93
|
): void {
|
|
94
94
|
const lix = { db, sqlite };
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
if (tableName === "key_value" && values[
|
|
96
|
+
// key values that have skip_change_control set to true should not be change controlled
|
|
97
|
+
if (tableName === "key_value" && values[2]) {
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -103,7 +103,7 @@ function handleLixOwnEntityChange(
|
|
|
103
103
|
lix,
|
|
104
104
|
query: db
|
|
105
105
|
.selectFrom("key_value")
|
|
106
|
-
.where("key", "=", "
|
|
106
|
+
.where("key", "=", "lix_skip_own_change_control")
|
|
107
107
|
.select("value"),
|
|
108
108
|
})[0]?.value === "true";
|
|
109
109
|
|
|
@@ -120,7 +120,7 @@ function handleLixOwnEntityChange(
|
|
|
120
120
|
.select("plugin_key"),
|
|
121
121
|
})[0];
|
|
122
122
|
|
|
123
|
-
if (change?.plugin_key === "
|
|
123
|
+
if (change?.plugin_key === "lix_own_change_control") {
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -177,8 +177,8 @@ function handleLixOwnEntityChange(
|
|
|
177
177
|
authors: authors,
|
|
178
178
|
version: currentVersion,
|
|
179
179
|
entityId,
|
|
180
|
-
fileId: "
|
|
181
|
-
pluginKey: "
|
|
180
|
+
fileId: "lix_own_change_control",
|
|
181
|
+
pluginKey: "lix_own_change_control",
|
|
182
182
|
schemaKey: `lix_${tableName}_table`,
|
|
183
183
|
snapshotContent,
|
|
184
184
|
},
|
package/src/{own-entity-change-control → own-change-control}/with-skip-own-change-control.ts
RENAMED
|
@@ -7,7 +7,11 @@ export async function withSkipOwnChangeControl<T>(
|
|
|
7
7
|
const executeInTransaction = async (trx: Lix["db"]) => {
|
|
8
8
|
await trx
|
|
9
9
|
.insertInto("key_value")
|
|
10
|
-
.values({
|
|
10
|
+
.values({
|
|
11
|
+
key: "lix_skip_own_change_control",
|
|
12
|
+
value: "true",
|
|
13
|
+
skip_change_control: true,
|
|
14
|
+
})
|
|
11
15
|
.onConflict((oc) => oc.doUpdateSet({ value: "true" }))
|
|
12
16
|
.execute();
|
|
13
17
|
|
|
@@ -16,7 +20,7 @@ export async function withSkipOwnChangeControl<T>(
|
|
|
16
20
|
|
|
17
21
|
await trx
|
|
18
22
|
.deleteFrom("key_value")
|
|
19
|
-
.where("key", "=", "
|
|
23
|
+
.where("key", "=", "lix_skip_own_change_control")
|
|
20
24
|
.execute();
|
|
21
25
|
|
|
22
26
|
// Return the result of the operation
|