@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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ENV_VARIABLES } from "../env-variables/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* List of telemetry events for typesafety.
|
|
5
|
+
*
|
|
6
|
+
* - prefix with `SDK` to avoid collisions with other apps
|
|
7
|
+
* - use past tense to indicate that the event is completed
|
|
8
|
+
*/
|
|
9
|
+
type TelemetryEvent = "LIX-SDK lix opened";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Capture an event.
|
|
13
|
+
*
|
|
14
|
+
* - manually calling the PostHog API because the SDKs were not platform angostic (and generally bloated)
|
|
15
|
+
*/
|
|
16
|
+
export const capture = async (
|
|
17
|
+
event: TelemetryEvent,
|
|
18
|
+
args: {
|
|
19
|
+
lixId: string;
|
|
20
|
+
accountId: string;
|
|
21
|
+
/**
|
|
22
|
+
* The value of the telemetry key-value pair.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const telemetryKeyValue = await lix.db.selectFrom("key_value").select("value").where("key", "=", "lix_telemetry").executeTakeFirstOrThrow();
|
|
26
|
+
* await capture("LIX-SDK opened lix", { lixId: "test", accountId: "test", telemetryKeyValue: telemetryKeyValue.value, properties: {} });
|
|
27
|
+
*/
|
|
28
|
+
telemetryKeyValue: string;
|
|
29
|
+
/**
|
|
30
|
+
* Please use snake_case for property names.
|
|
31
|
+
*/
|
|
32
|
+
properties: Record<string, any>;
|
|
33
|
+
}
|
|
34
|
+
): Promise<void> => {
|
|
35
|
+
if (ENV_VARIABLES.LIX_SDK_POSTHOG_TOKEN === undefined) {
|
|
36
|
+
return;
|
|
37
|
+
} else if (args.telemetryKeyValue === "off") {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await fetch("https://eu.posthog.com/capture/", {
|
|
42
|
+
method: "POST",
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
api_key: ENV_VARIABLES.LIX_SDK_POSTHOG_TOKEN,
|
|
45
|
+
event,
|
|
46
|
+
distinct_id: args.accountId,
|
|
47
|
+
properties: {
|
|
48
|
+
$groups: { lix_id: args.lixId },
|
|
49
|
+
...args.properties,
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
await identifyLix({
|
|
54
|
+
lixId: args.lixId,
|
|
55
|
+
accountId: args.accountId,
|
|
56
|
+
// using the id for now as a name but can be changed in the future
|
|
57
|
+
// we need at least one property to make a project visible in the dashboard
|
|
58
|
+
properties: { name: args.lixId },
|
|
59
|
+
});
|
|
60
|
+
} catch {
|
|
61
|
+
//
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Identifying a project is needed.
|
|
67
|
+
*
|
|
68
|
+
* Otherwise, the project will not be visible in the PostHog dashboard.
|
|
69
|
+
*/
|
|
70
|
+
const identifyLix = async (args: {
|
|
71
|
+
lixId: string;
|
|
72
|
+
accountId: string;
|
|
73
|
+
properties: Record<string, string>;
|
|
74
|
+
}) => {
|
|
75
|
+
// do not send events if the token is not set
|
|
76
|
+
// (assuming this eases testing)
|
|
77
|
+
if (ENV_VARIABLES.LIX_SDK_POSTHOG_TOKEN === undefined) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
await fetch("https://eu.posthog.com/capture/", {
|
|
82
|
+
method: "POST",
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
api_key: ENV_VARIABLES.LIX_SDK_POSTHOG_TOKEN,
|
|
85
|
+
event: "$groupidentify",
|
|
86
|
+
distinct_id: args.accountId,
|
|
87
|
+
properties: {
|
|
88
|
+
$group_type: "lix",
|
|
89
|
+
$group_key: args.lixId,
|
|
90
|
+
$group_set: {
|
|
91
|
+
...args.properties,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
});
|
|
96
|
+
} catch {
|
|
97
|
+
//
|
|
98
|
+
}
|
|
99
|
+
};
|
|
@@ -4,11 +4,14 @@ import { openLixInMemory } from "../lix/open-lix-in-memory.js";
|
|
|
4
4
|
import { pullFromServer } from "./pull-from-server.js";
|
|
5
5
|
import { mockJsonSnapshot } from "../snapshot/mock-json-snapshot.js";
|
|
6
6
|
import { createLsaInMemoryEnvironment } from "../server-api-handler/environment/create-in-memory-environment.js";
|
|
7
|
+
import { toBlob } from "../lix/to-blob.js";
|
|
7
8
|
|
|
8
9
|
test("pull rows of multiple tables from server successfully and applies them", async () => {
|
|
9
10
|
const lixOnServer = await openLixInMemory({});
|
|
10
11
|
|
|
11
|
-
const lix = await openLixInMemory({
|
|
12
|
+
const lix = await openLixInMemory({
|
|
13
|
+
blob: await toBlob({ lix: lixOnServer }),
|
|
14
|
+
});
|
|
12
15
|
|
|
13
16
|
const { value: id } = await lixOnServer.db
|
|
14
17
|
.selectFrom("key_value")
|
|
@@ -38,7 +41,7 @@ test("pull rows of multiple tables from server successfully and applies them", a
|
|
|
38
41
|
await lsaHandler(
|
|
39
42
|
new Request("http://localhost:3000/lsa/new-v1", {
|
|
40
43
|
method: "POST",
|
|
41
|
-
body: await
|
|
44
|
+
body: await toBlob({ lix: lixOnServer }),
|
|
42
45
|
headers: {
|
|
43
46
|
"Content-Type": "application/json",
|
|
44
47
|
},
|
|
@@ -66,13 +69,15 @@ test("pull rows of multiple tables from server successfully and applies them", a
|
|
|
66
69
|
.executeTakeFirstOrThrow();
|
|
67
70
|
|
|
68
71
|
expect(account).toEqual({ id: "account0", name: "test account" });
|
|
69
|
-
expect(mockKey).
|
|
72
|
+
expect(mockKey).toMatchObject({ key: "mock-key", value: "mock-value" });
|
|
70
73
|
});
|
|
71
74
|
|
|
72
75
|
test("it handles snapshot.content being json binary", async () => {
|
|
73
76
|
const lixOnServer = await openLixInMemory({});
|
|
74
77
|
|
|
75
|
-
const lix = await openLixInMemory({
|
|
78
|
+
const lix = await openLixInMemory({
|
|
79
|
+
blob: await toBlob({ lix: lixOnServer }),
|
|
80
|
+
});
|
|
76
81
|
|
|
77
82
|
const { value: id } = await lixOnServer.db
|
|
78
83
|
.selectFrom("key_value")
|
|
@@ -101,7 +106,7 @@ test("it handles snapshot.content being json binary", async () => {
|
|
|
101
106
|
await lsaHandler(
|
|
102
107
|
new Request("http://localhost:3000/lsa/new-v1", {
|
|
103
108
|
method: "POST",
|
|
104
|
-
body: await
|
|
109
|
+
body: await toBlob({ lix: lixOnServer }),
|
|
105
110
|
headers: {
|
|
106
111
|
"Content-Type": "application/json",
|
|
107
112
|
},
|
|
@@ -141,7 +146,9 @@ test("rows changed on the client more recently should not be updated", async ()
|
|
|
141
146
|
})
|
|
142
147
|
.executeTakeFirstOrThrow();
|
|
143
148
|
|
|
144
|
-
const lix = await openLixInMemory({
|
|
149
|
+
const lix = await openLixInMemory({
|
|
150
|
+
blob: await toBlob({ lix: lixOnServer }),
|
|
151
|
+
});
|
|
145
152
|
|
|
146
153
|
const environment = createLsaInMemoryEnvironment();
|
|
147
154
|
const lsaHandler = await createServerApiHandler({ environment });
|
|
@@ -152,7 +159,7 @@ test("rows changed on the client more recently should not be updated", async ()
|
|
|
152
159
|
await lsaHandler(
|
|
153
160
|
new Request("http://localhost:3000/lsa/new-v1", {
|
|
154
161
|
method: "POST",
|
|
155
|
-
body: await
|
|
162
|
+
body: await toBlob({ lix: lixOnServer }),
|
|
156
163
|
headers: {
|
|
157
164
|
"Content-Type": "application/json",
|
|
158
165
|
},
|
|
@@ -179,7 +186,10 @@ test("rows changed on the client more recently should not be updated", async ()
|
|
|
179
186
|
.selectAll()
|
|
180
187
|
.executeTakeFirstOrThrow();
|
|
181
188
|
|
|
182
|
-
expect(mockKey).
|
|
189
|
+
expect(mockKey).toMatchObject({
|
|
190
|
+
key: "mock-key",
|
|
191
|
+
value: "mock-value-updated",
|
|
192
|
+
});
|
|
183
193
|
});
|
|
184
194
|
|
|
185
195
|
// the change table now models "change control". no more last edit wins needed
|
|
@@ -192,7 +202,9 @@ test.skip("rows changed on the server more recently should be updated on the cli
|
|
|
192
202
|
|
|
193
203
|
// create a lix and clone it for the client - so they share the same lix id
|
|
194
204
|
const remoteLix = await openLixInMemory({});
|
|
195
|
-
const localLix = await openLixInMemory({
|
|
205
|
+
const localLix = await openLixInMemory({
|
|
206
|
+
blob: await toBlob({ lix: remoteLix }),
|
|
207
|
+
});
|
|
196
208
|
|
|
197
209
|
// insert mock data into server lix
|
|
198
210
|
await remoteLix.db
|
|
@@ -234,7 +246,7 @@ test.skip("rows changed on the server more recently should be updated on the cli
|
|
|
234
246
|
await lsaHandler(
|
|
235
247
|
new Request("http://localhost:3000/lsa/new-v1", {
|
|
236
248
|
method: "POST",
|
|
237
|
-
body: await
|
|
249
|
+
body: await toBlob({ lix: remoteLix }),
|
|
238
250
|
headers: {
|
|
239
251
|
"Content-Type": "application/json",
|
|
240
252
|
},
|
|
@@ -347,7 +359,7 @@ test("non-conflicting changes from the server should for the same version should
|
|
|
347
359
|
|
|
348
360
|
global.fetch = vi.fn((request) => lsaHandler(request));
|
|
349
361
|
|
|
350
|
-
const lixOnServer = await openLixInMemory({ blob: await
|
|
362
|
+
const lixOnServer = await openLixInMemory({ blob: await toBlob({ lix }) });
|
|
351
363
|
|
|
352
364
|
// insert data on the server that the client does not have yet
|
|
353
365
|
await lixOnServer.db
|
|
@@ -369,7 +381,10 @@ test("non-conflicting changes from the server should for the same version should
|
|
|
369
381
|
expect.arrayContaining([
|
|
370
382
|
expect.objectContaining({
|
|
371
383
|
version_id: currentVersion.id,
|
|
372
|
-
content: {
|
|
384
|
+
content: expect.objectContaining({
|
|
385
|
+
key: "mock-key",
|
|
386
|
+
value: "mock-value",
|
|
387
|
+
}),
|
|
373
388
|
}),
|
|
374
389
|
])
|
|
375
390
|
);
|
|
@@ -377,7 +392,7 @@ test("non-conflicting changes from the server should for the same version should
|
|
|
377
392
|
await lsaHandler(
|
|
378
393
|
new Request("http://localhost:3000/lsa/new-v1", {
|
|
379
394
|
method: "POST",
|
|
380
|
-
body: await
|
|
395
|
+
body: await toBlob({ lix: lixOnServer }),
|
|
381
396
|
headers: {
|
|
382
397
|
"Content-Type": "application/json",
|
|
383
398
|
},
|
|
@@ -405,6 +420,6 @@ test("non-conflicting changes from the server should for the same version should
|
|
|
405
420
|
.select("snapshot.content as content")
|
|
406
421
|
.execute();
|
|
407
422
|
|
|
408
|
-
expect(mockKey).
|
|
423
|
+
expect(mockKey).toMatchObject({ key: "mock-key", value: "mock-value" });
|
|
409
424
|
expect(versionChanges).toEqual(expect.arrayContaining(serverVersionChanges));
|
|
410
425
|
});
|
|
@@ -133,8 +133,6 @@ export async function pullFromServer(args: {
|
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
if (changesToApply.length > 0) {
|
|
136
|
-
// the changes already exists hence prevent own change control
|
|
137
|
-
// from creating new changes for the applied changes
|
|
138
136
|
await applyChanges({
|
|
139
137
|
lix: { ...args.lix, db: trx },
|
|
140
138
|
changes: changesToApply,
|
|
@@ -5,10 +5,11 @@ import { pushToServer } from "./push-to-server.js";
|
|
|
5
5
|
import type { LixFile } from "../database/schema.js";
|
|
6
6
|
import type { Account } from "../account/database-schema.js";
|
|
7
7
|
import { newLixFile } from "../lix/new-lix.js";
|
|
8
|
-
import type {
|
|
8
|
+
import type { NewKeyValue } from "../key-value/database-schema.js";
|
|
9
9
|
import { mockJsonSnapshot } from "../snapshot/mock-json-snapshot.js";
|
|
10
10
|
import { pullFromServer } from "./pull-from-server.js";
|
|
11
11
|
import { createLsaInMemoryEnvironment } from "../server-api-handler/environment/create-in-memory-environment.js";
|
|
12
|
+
import { toBlob } from "../lix/to-blob.js";
|
|
12
13
|
|
|
13
14
|
test("push rows of multiple tables to server successfully", async () => {
|
|
14
15
|
const lixBlob = await newLixFile();
|
|
@@ -30,7 +31,7 @@ test("push rows of multiple tables to server successfully", async () => {
|
|
|
30
31
|
await lsaHandler(
|
|
31
32
|
new Request("http://localhost:3000/lsa/new-v1", {
|
|
32
33
|
method: "POST",
|
|
33
|
-
body: await
|
|
34
|
+
body: await toBlob({ lix }),
|
|
34
35
|
})
|
|
35
36
|
);
|
|
36
37
|
|
|
@@ -83,11 +84,11 @@ test("push rows of multiple tables to server successfully", async () => {
|
|
|
83
84
|
{ id: "account0", name: "some account" } satisfies Account,
|
|
84
85
|
]);
|
|
85
86
|
expect(keyValueChangesOnServer.map((c) => c.content)).toEqual([
|
|
86
|
-
{
|
|
87
|
+
expect.objectContaining({
|
|
87
88
|
key: "mock-key",
|
|
88
89
|
value: "mock-value",
|
|
89
|
-
},
|
|
90
|
-
] satisfies
|
|
90
|
+
}),
|
|
91
|
+
] satisfies NewKeyValue[]);
|
|
91
92
|
});
|
|
92
93
|
|
|
93
94
|
test("push-pull-push with two clients", async () => {
|
|
@@ -111,7 +112,7 @@ test("push-pull-push with two clients", async () => {
|
|
|
111
112
|
await lsaHandler(
|
|
112
113
|
new Request("http://localhost:3000/lsa/new-v1", {
|
|
113
114
|
method: "POST",
|
|
114
|
-
body: await
|
|
115
|
+
body: await toBlob({ lix: client1 }),
|
|
115
116
|
})
|
|
116
117
|
);
|
|
117
118
|
|
|
@@ -165,10 +166,10 @@ test("push-pull-push with two clients", async () => {
|
|
|
165
166
|
|
|
166
167
|
expect(client2KeyValueAfterPull).toEqual(
|
|
167
168
|
expect.arrayContaining([
|
|
168
|
-
{
|
|
169
|
+
expect.objectContaining({
|
|
169
170
|
key: "mock-key",
|
|
170
171
|
value: "mock-value from client 1",
|
|
171
|
-
} satisfies
|
|
172
|
+
} satisfies NewKeyValue),
|
|
172
173
|
])
|
|
173
174
|
);
|
|
174
175
|
|
|
@@ -260,15 +261,18 @@ test("push-pull-push with two clients", async () => {
|
|
|
260
261
|
|
|
261
262
|
expect(keyValueChangesOnServer.map((c) => c.content)).toEqual(
|
|
262
263
|
expect.arrayContaining([
|
|
263
|
-
{
|
|
264
|
+
expect.objectContaining({
|
|
264
265
|
key: "mock-key",
|
|
265
266
|
value: "mock-value from client 1",
|
|
266
|
-
},
|
|
267
|
-
{
|
|
267
|
+
}),
|
|
268
|
+
expect.objectContaining({
|
|
268
269
|
key: "mock-key",
|
|
269
270
|
value: "mock-value from client 1 - updated by client 2",
|
|
270
|
-
},
|
|
271
|
-
{
|
|
271
|
+
}),
|
|
272
|
+
expect.objectContaining({
|
|
273
|
+
key: "mock-key-2",
|
|
274
|
+
value: "mock-value from client 2",
|
|
275
|
+
}),
|
|
272
276
|
])
|
|
273
277
|
);
|
|
274
278
|
});
|
|
@@ -291,7 +295,7 @@ test("it should handle snapshots.content json binaries", async () => {
|
|
|
291
295
|
await lsaHandler(
|
|
292
296
|
new Request("http://localhost:3000/lsa/new-v1", {
|
|
293
297
|
method: "POST",
|
|
294
|
-
body: await
|
|
298
|
+
body: await toBlob({ lix }),
|
|
295
299
|
})
|
|
296
300
|
);
|
|
297
301
|
|
|
@@ -345,7 +349,7 @@ test.todo("it should handle binary values", async () => {
|
|
|
345
349
|
await lsaHandler(
|
|
346
350
|
new Request("http://localhost:3000/lsa/new", {
|
|
347
351
|
method: "POST",
|
|
348
|
-
body: await
|
|
352
|
+
body: await toBlob({ lix }),
|
|
349
353
|
})
|
|
350
354
|
);
|
|
351
355
|
|
|
@@ -8,6 +8,7 @@ import { createVersion } from "../version/create-version.js";
|
|
|
8
8
|
import { switchVersion } from "../version/switch-version.js";
|
|
9
9
|
import type { Version } from "../database/schema.js";
|
|
10
10
|
import { executeSync } from "../database/execute-sync.js";
|
|
11
|
+
import { toBlob } from "../lix/to-blob.js";
|
|
11
12
|
|
|
12
13
|
test("versions should be synced", async () => {
|
|
13
14
|
const environment = createLsaInMemoryEnvironment();
|
|
@@ -16,7 +17,7 @@ test("versions should be synced", async () => {
|
|
|
16
17
|
global.fetch = vi.fn((request) => lsaHandler(request));
|
|
17
18
|
|
|
18
19
|
const lix0 = await openLixInMemory({
|
|
19
|
-
keyValues: [{ key: "
|
|
20
|
+
keyValues: [{ key: "lix_server_url", value: "http://mock.com" }],
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
// @ts-expect-error - eases debugging
|
|
@@ -32,32 +33,26 @@ test("versions should be synced", async () => {
|
|
|
32
33
|
await lsaHandler(
|
|
33
34
|
new Request("http://mock.com/lsa/new-v1", {
|
|
34
35
|
method: "POST",
|
|
35
|
-
body: await
|
|
36
|
+
body: await toBlob({ lix: lix0 }),
|
|
36
37
|
})
|
|
37
38
|
);
|
|
38
39
|
|
|
39
40
|
// create a second client
|
|
40
41
|
const lix1 = await openLixInMemory({
|
|
41
|
-
blob: await
|
|
42
|
-
keyValues: [{ key: "
|
|
42
|
+
blob: await toBlob({ lix: lix0 }),
|
|
43
|
+
keyValues: [{ key: "lix_sync", value: "true" }],
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
// start syncing
|
|
46
|
-
await
|
|
47
|
-
.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.insertInto("key_value")
|
|
56
|
-
.values({
|
|
57
|
-
key: "lix_server_url",
|
|
58
|
-
value: "http://mock.com",
|
|
59
|
-
})
|
|
60
|
-
.execute();
|
|
47
|
+
await Promise.all(
|
|
48
|
+
[lix0, lix1].map((lix) =>
|
|
49
|
+
lix.db
|
|
50
|
+
.updateTable("key_value")
|
|
51
|
+
.where("key", "=", "lix_sync")
|
|
52
|
+
.set({ value: "true" })
|
|
53
|
+
.execute()
|
|
54
|
+
)
|
|
55
|
+
);
|
|
61
56
|
|
|
62
57
|
// @ts-expect-error - eases debugging
|
|
63
58
|
lix1.db.__name = "lix1";
|
|
@@ -74,7 +69,7 @@ test("versions should be synced", async () => {
|
|
|
74
69
|
.executeTakeFirstOrThrow();
|
|
75
70
|
version0 = await createVersion({
|
|
76
71
|
lix: { ...lix0, db: trx },
|
|
77
|
-
|
|
72
|
+
from: currentVersion,
|
|
78
73
|
name: "version0",
|
|
79
74
|
});
|
|
80
75
|
await switchVersion({ lix: { ...lix0, db: trx }, to: version0 });
|
|
@@ -113,17 +108,16 @@ test("versions should be synced", async () => {
|
|
|
113
108
|
expect(lix0Versions).toEqual(lix1Versions);
|
|
114
109
|
|
|
115
110
|
// expecting both lix0 and lix1 to have the same version changes
|
|
116
|
-
const lix0VersionChanges = await
|
|
117
|
-
.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
.execute();
|
|
111
|
+
const [lix0VersionChanges, lix1VersionChanges] = await Promise.all(
|
|
112
|
+
[lix0, lix1].map((lix) =>
|
|
113
|
+
lix.db
|
|
114
|
+
.selectFrom("version_change")
|
|
115
|
+
.orderBy("change_id", "desc")
|
|
116
|
+
.orderBy("version_id", "desc")
|
|
117
|
+
.selectAll()
|
|
118
|
+
.execute()
|
|
119
|
+
)
|
|
120
|
+
);
|
|
127
121
|
|
|
128
122
|
expect(lix0VersionChanges).toEqual(lix1VersionChanges);
|
|
129
123
|
});
|
|
@@ -137,7 +131,7 @@ test("switching synced versions should work", async () => {
|
|
|
137
131
|
global.executeSync = executeSync;
|
|
138
132
|
|
|
139
133
|
const lix0 = await openLixInMemory({
|
|
140
|
-
keyValues: [{ key: "
|
|
134
|
+
keyValues: [{ key: "lix_sync", value: "true" }],
|
|
141
135
|
});
|
|
142
136
|
// @ts-expect-error - eases debugging
|
|
143
137
|
lix0.db.__name = "lix0";
|
|
@@ -154,7 +148,7 @@ test("switching synced versions should work", async () => {
|
|
|
154
148
|
await lsaHandler(
|
|
155
149
|
new Request("http://mock.com/lsa/new-v1", {
|
|
156
150
|
method: "POST",
|
|
157
|
-
body: await
|
|
151
|
+
body: await toBlob({ lix: lix0 }),
|
|
158
152
|
})
|
|
159
153
|
);
|
|
160
154
|
|
|
@@ -169,8 +163,8 @@ test("switching synced versions should work", async () => {
|
|
|
169
163
|
|
|
170
164
|
// create a second client
|
|
171
165
|
const lix1 = await openLixInMemory({
|
|
172
|
-
blob: await
|
|
173
|
-
keyValues: [{ key: "
|
|
166
|
+
blob: await toBlob({ lix: lix0 }),
|
|
167
|
+
keyValues: [{ key: "lix_sync", value: "true" }],
|
|
174
168
|
});
|
|
175
169
|
|
|
176
170
|
// @ts-expect-error - eases debugging
|
|
@@ -187,7 +181,7 @@ test("switching synced versions should work", async () => {
|
|
|
187
181
|
const version0 = await createVersion({
|
|
188
182
|
lix: lix0,
|
|
189
183
|
name: "version0",
|
|
190
|
-
|
|
184
|
+
from: currentVersion,
|
|
191
185
|
});
|
|
192
186
|
|
|
193
187
|
await switchVersion({ lix: lix0, to: version0 });
|
|
@@ -239,13 +233,13 @@ test("switching synced versions should work", async () => {
|
|
|
239
233
|
.selectAll()
|
|
240
234
|
.executeTakeFirst();
|
|
241
235
|
|
|
242
|
-
expect(keyValue).
|
|
236
|
+
expect(keyValue).toMatchObject({
|
|
243
237
|
key: "mock-key",
|
|
244
238
|
value: "mock",
|
|
245
239
|
});
|
|
246
240
|
});
|
|
247
241
|
|
|
248
|
-
test("doesnt sync if
|
|
242
|
+
test("doesnt sync if lix_sync is not true", async () => {
|
|
249
243
|
const environment = createLsaInMemoryEnvironment();
|
|
250
244
|
const lsaHandler = await createServerApiHandler({ environment });
|
|
251
245
|
global.fetch = vi.fn((request) => lsaHandler(request));
|
|
@@ -262,14 +256,14 @@ test("doesnt sync if #lix_sync is not true", async () => {
|
|
|
262
256
|
await lsaHandler(
|
|
263
257
|
new Request("http://mock.com/lsa/new-v1", {
|
|
264
258
|
method: "POST",
|
|
265
|
-
body: await
|
|
259
|
+
body: await toBlob({ lix }),
|
|
266
260
|
})
|
|
267
261
|
);
|
|
268
262
|
|
|
269
263
|
await lix.db
|
|
270
264
|
.updateTable("key_value")
|
|
271
265
|
.set({ value: "false" })
|
|
272
|
-
.where("key", "=", "
|
|
266
|
+
.where("key", "=", "lix_sync")
|
|
273
267
|
.execute();
|
|
274
268
|
|
|
275
269
|
await lix.db
|
|
@@ -301,7 +295,7 @@ test("doesnt sync if #lix_sync is not true", async () => {
|
|
|
301
295
|
await lix.db
|
|
302
296
|
.updateTable("key_value")
|
|
303
297
|
.set({ value: "true" })
|
|
304
|
-
.where("key", "=", "
|
|
298
|
+
.where("key", "=", "lix_sync")
|
|
305
299
|
.execute();
|
|
306
300
|
|
|
307
301
|
await new Promise((resolve) => setTimeout(resolve, 1010));
|
|
@@ -317,10 +311,10 @@ test("doesnt sync if #lix_sync is not true", async () => {
|
|
|
317
311
|
expect(keyValueChangesOnServerAfterSync).toEqual(
|
|
318
312
|
expect.arrayContaining([
|
|
319
313
|
expect.objectContaining({
|
|
320
|
-
content: {
|
|
314
|
+
content: expect.objectContaining({
|
|
321
315
|
key: "foo",
|
|
322
316
|
value: "bar",
|
|
323
|
-
},
|
|
317
|
+
}),
|
|
324
318
|
}),
|
|
325
319
|
])
|
|
326
320
|
);
|
package/src/sync/sync-process.ts
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
import type { Lix } from "../lix/open-lix.js";
|
|
2
2
|
import { pushToServer } from "./push-to-server.js";
|
|
3
3
|
import { pullFromServer } from "./pull-from-server.js";
|
|
4
|
+
import { toBlob } from "../lix/to-blob.js";
|
|
4
5
|
|
|
5
6
|
export async function initSyncProcess(args: {
|
|
6
|
-
lix: Pick<Lix, "db" | "plugin" | "
|
|
7
|
-
}): Promise<
|
|
8
|
-
| {
|
|
9
|
-
stop: () => void;
|
|
10
|
-
}
|
|
11
|
-
| undefined
|
|
12
|
-
> {
|
|
7
|
+
lix: Pick<Lix, "db" | "plugin" | "sqlite">;
|
|
8
|
+
}): Promise<void> {
|
|
13
9
|
const lixId = await args.lix.db
|
|
14
10
|
.selectFrom("key_value")
|
|
15
11
|
.where("key", "=", "lix_id")
|
|
16
12
|
.select("value")
|
|
17
13
|
.executeTakeFirstOrThrow();
|
|
18
14
|
|
|
19
|
-
let stoped = false;
|
|
20
|
-
|
|
21
15
|
const pullAndPush = async () => {
|
|
22
16
|
const shouldSync = await args.lix.db
|
|
23
17
|
.selectFrom("key_value")
|
|
24
|
-
.where("key", "=", "
|
|
18
|
+
.where("key", "=", "lix_sync")
|
|
25
19
|
.select("value")
|
|
26
20
|
.executeTakeFirst();
|
|
27
21
|
|
|
@@ -40,7 +34,6 @@ export async function initSyncProcess(args: {
|
|
|
40
34
|
if (!url) {
|
|
41
35
|
return;
|
|
42
36
|
}
|
|
43
|
-
|
|
44
37
|
try {
|
|
45
38
|
// console.log("----------- PULL FROM SERVER -------------");
|
|
46
39
|
const serverState = await pullFromServer({
|
|
@@ -64,7 +57,7 @@ export async function initSyncProcess(args: {
|
|
|
64
57
|
const response = await fetch(
|
|
65
58
|
new Request(url.value + "/lsa/new-v1", {
|
|
66
59
|
method: "POST",
|
|
67
|
-
body: await args.lix
|
|
60
|
+
body: await toBlob({ lix: args.lix }),
|
|
68
61
|
})
|
|
69
62
|
);
|
|
70
63
|
if (!response.ok && response.status !== 409) {
|
|
@@ -77,21 +70,21 @@ export async function initSyncProcess(args: {
|
|
|
77
70
|
// naive implementation that syncs every second
|
|
78
71
|
|
|
79
72
|
function schedulePullAndPush() {
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
console.error("Error in sync process", e);
|
|
83
|
-
});
|
|
73
|
+
if (args.lix.sqlite.isOpen() === false) {
|
|
74
|
+
return;
|
|
84
75
|
}
|
|
76
|
+
pullAndPush().catch((e) => {
|
|
77
|
+
if (e instanceof Error && e.message.includes("DB has been closed.")) {
|
|
78
|
+
// stop the syncing process, the database has been closed.
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
console.error("Error in sync process", e);
|
|
82
|
+
});
|
|
83
|
+
// schedule next sync
|
|
85
84
|
setTimeout(() => {
|
|
86
85
|
schedulePullAndPush();
|
|
87
|
-
},
|
|
86
|
+
}, 750);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
schedulePullAndPush();
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
stop: () => {
|
|
94
|
-
stoped = true;
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
90
|
}
|
|
@@ -42,7 +42,7 @@ test("it should copy the changes from the parent version", async () => {
|
|
|
42
42
|
|
|
43
43
|
const version1 = await createVersion({
|
|
44
44
|
lix,
|
|
45
|
-
|
|
45
|
+
from: version0,
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
const changesInversion0 = await lix.db
|
|
@@ -132,7 +132,7 @@ test("it should copy change conflict pointers from the parent version", async ()
|
|
|
132
132
|
|
|
133
133
|
const version1 = await createVersion({
|
|
134
134
|
lix,
|
|
135
|
-
|
|
135
|
+
from: version0,
|
|
136
136
|
name: "version1",
|
|
137
137
|
});
|
|
138
138
|
|