@lix-js/sdk 0.0.1 → 0.1.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/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 +85 -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 +373 -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 +3 -5
- package/dist/lix/open-lix.d.ts.map +1 -1
- package/dist/lix/open-lix.js +4 -18
- package/dist/lix/open-lix.js.map +1 -1
- package/dist/lix/open-lix.test.js +16 -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/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 +4 -9
- 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/node_modules/@lix-js/server-api-schema/CHANGELOG.md +9 -0
- package/node_modules/@lix-js/server-api-schema/LICENSE +21 -0
- package/node_modules/@lix-js/server-api-schema/dist/schema.js +0 -0
- package/node_modules/@lix-js/server-api-schema/package.json +2 -2
- package/node_modules/sqlite-wasm-kysely/LICENSE +21 -0
- package/package.json +4 -4
- 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} +24 -24
- package/src/{change-queue/init-change-queue.ts → file-queue/file-queue-process.ts} +18 -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 +19 -7
- package/src/lix/open-lix.ts +7 -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/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 +6 -18
- 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/dist/schema.d.ts +0 -384
- 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
|
@@ -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
|
|
@@ -4,6 +4,7 @@ import type { VersionChange } from "../database/schema.js";
|
|
|
4
4
|
import { mockChange } from "../change/mock-change.js";
|
|
5
5
|
import { createVersion } from "../version/create-version.js";
|
|
6
6
|
import { versionChangeInDifference } from "./version-change-in-difference.js";
|
|
7
|
+
import { updateChangesInVersion } from "../version/update-changes-in-version.js";
|
|
7
8
|
|
|
8
9
|
test("should return the difference between two versions", async () => {
|
|
9
10
|
const lix = await openLixInMemory({});
|
|
@@ -11,42 +12,42 @@ test("should return the difference between two versions", async () => {
|
|
|
11
12
|
const versionA = await createVersion({ lix });
|
|
12
13
|
const versionB = await createVersion({ lix });
|
|
13
14
|
|
|
15
|
+
const mockChanges = [
|
|
16
|
+
mockChange({ id: "change0", entity_id: "entity0" }),
|
|
17
|
+
mockChange({ id: "change1", entity_id: "entity1" }),
|
|
18
|
+
mockChange({ id: "change2", entity_id: "entity2" }),
|
|
19
|
+
mockChange({ id: "change3", entity_id: "entity3" }),
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
14
22
|
await lix.db
|
|
15
23
|
.insertInto("change")
|
|
16
|
-
.values(
|
|
17
|
-
mockChange({ id: "change1" }),
|
|
18
|
-
mockChange({ id: "change2" }),
|
|
19
|
-
mockChange({ id: "change3" }),
|
|
20
|
-
mockChange({ id: "change4" }),
|
|
21
|
-
])
|
|
24
|
+
.values(mockChanges)
|
|
22
25
|
.returningAll()
|
|
23
26
|
.execute();
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const changesB: VersionChange[] = [
|
|
31
|
-
{ version_id: versionB.id, change_id: "change2" },
|
|
32
|
-
{ version_id: versionB.id, change_id: "change3" },
|
|
33
|
-
];
|
|
28
|
+
await updateChangesInVersion({
|
|
29
|
+
lix,
|
|
30
|
+
version: versionA,
|
|
31
|
+
changes: [mockChanges[0], mockChanges[1]],
|
|
32
|
+
});
|
|
34
33
|
|
|
35
|
-
await
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
await updateChangesInVersion({
|
|
35
|
+
lix,
|
|
36
|
+
version: versionB,
|
|
37
|
+
changes: [mockChanges[1], mockChanges[2]],
|
|
38
|
+
});
|
|
39
39
|
|
|
40
40
|
const result = await lix.db
|
|
41
41
|
.selectFrom("version_change")
|
|
42
42
|
.where(versionChangeInDifference(versionA, versionB))
|
|
43
|
-
.
|
|
43
|
+
.select("version_id")
|
|
44
|
+
.select("change_id")
|
|
44
45
|
.execute();
|
|
45
46
|
|
|
46
47
|
expect(result).toEqual([
|
|
47
|
-
//
|
|
48
|
-
{ version_id: versionA.id, change_id: "
|
|
49
|
-
] satisfies VersionChange[]);
|
|
48
|
+
// change0 is in A but not in B
|
|
49
|
+
expect.objectContaining({ version_id: versionA.id, change_id: "change0" }),
|
|
50
|
+
] satisfies Partial<VersionChange>[]);
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
test("should return an empty array if there are no differences", async () => {
|
|
@@ -55,20 +56,28 @@ test("should return an empty array if there are no differences", async () => {
|
|
|
55
56
|
const versionA = await createVersion({ lix });
|
|
56
57
|
const versionB = await createVersion({ lix });
|
|
57
58
|
|
|
59
|
+
const mockChanges = [
|
|
60
|
+
mockChange({ id: "change0" }),
|
|
61
|
+
mockChange({ id: "change1" }),
|
|
62
|
+
];
|
|
63
|
+
|
|
58
64
|
await lix.db
|
|
59
65
|
.insertInto("change")
|
|
60
|
-
.values(
|
|
66
|
+
.values(mockChanges)
|
|
61
67
|
.returningAll()
|
|
62
68
|
.execute();
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
await updateChangesInVersion({
|
|
71
|
+
lix,
|
|
72
|
+
version: versionA,
|
|
73
|
+
changes: mockChanges,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await updateChangesInVersion({
|
|
77
|
+
lix,
|
|
78
|
+
version: versionB,
|
|
79
|
+
changes: mockChanges,
|
|
80
|
+
});
|
|
72
81
|
|
|
73
82
|
const result = await lix.db
|
|
74
83
|
.selectFrom("version_change")
|
|
@@ -4,6 +4,7 @@ import type { VersionChange } from "../database/schema.js";
|
|
|
4
4
|
import { mockChange } from "../change/mock-change.js";
|
|
5
5
|
import { createVersion } from "../version/create-version.js";
|
|
6
6
|
import { versionChangeInSymmetricDifference } from "./version-change-in-symmetric-difference.js";
|
|
7
|
+
import { updateChangesInVersion } from "../version/update-changes-in-version.js";
|
|
7
8
|
|
|
8
9
|
test("should return the symmetric difference between two versions", async () => {
|
|
9
10
|
const lix = await openLixInMemory({});
|
|
@@ -11,31 +12,26 @@ test("should return the symmetric difference between two versions", async () =>
|
|
|
11
12
|
const versionA = await createVersion({ lix });
|
|
12
13
|
const versionB = await createVersion({ lix });
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
mockChange({ id: "change4" }),
|
|
21
|
-
])
|
|
22
|
-
.returningAll()
|
|
23
|
-
.execute();
|
|
15
|
+
const mockChanges = [
|
|
16
|
+
mockChange({ id: "change0", entity_id: "entity0" }),
|
|
17
|
+
mockChange({ id: "change1", entity_id: "entity1" }),
|
|
18
|
+
mockChange({ id: "change2", entity_id: "entity2" }),
|
|
19
|
+
mockChange({ id: "change3", entity_id: "entity3" }),
|
|
20
|
+
] as const;
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
{ version_id: versionA.id, change_id: "change1" },
|
|
27
|
-
{ version_id: versionA.id, change_id: "change2" },
|
|
28
|
-
];
|
|
22
|
+
await lix.db.insertInto("change").values(mockChanges).execute();
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
await updateChangesInVersion({
|
|
25
|
+
lix,
|
|
26
|
+
version: versionA,
|
|
27
|
+
changes: [mockChanges[0], mockChanges[1]],
|
|
28
|
+
});
|
|
34
29
|
|
|
35
|
-
await
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
await updateChangesInVersion({
|
|
31
|
+
lix,
|
|
32
|
+
version: versionB,
|
|
33
|
+
changes: [mockChanges[1], mockChanges[2]],
|
|
34
|
+
});
|
|
39
35
|
|
|
40
36
|
const result = await lix.db
|
|
41
37
|
.selectFrom("version_change")
|
|
@@ -44,13 +40,13 @@ test("should return the symmetric difference between two versions", async () =>
|
|
|
44
40
|
.execute();
|
|
45
41
|
|
|
46
42
|
expect(result).toEqual([
|
|
47
|
-
// change
|
|
48
|
-
{ version_id: versionA.id, change_id: "
|
|
49
|
-
// change
|
|
50
|
-
{ version_id: versionB.id, change_id: "
|
|
51
|
-
// change
|
|
43
|
+
// change 0 is in A but not in B
|
|
44
|
+
expect.objectContaining({ version_id: versionA.id, change_id: "change0" }),
|
|
45
|
+
// change 2 is in B but not in A
|
|
46
|
+
expect.objectContaining({ version_id: versionB.id, change_id: "change2" }),
|
|
47
|
+
// change 3 is in neither A nor B
|
|
52
48
|
// hence not in the symmetric difference
|
|
53
|
-
] satisfies VersionChange[]);
|
|
49
|
+
] satisfies Partial<VersionChange>[]);
|
|
54
50
|
});
|
|
55
51
|
|
|
56
52
|
test("should return an empty array if there are no differences", async () => {
|
|
@@ -59,25 +55,28 @@ test("should return an empty array if there are no differences", async () => {
|
|
|
59
55
|
const versionA = await createVersion({ lix });
|
|
60
56
|
const versionB = await createVersion({ lix });
|
|
61
57
|
|
|
58
|
+
const mockChanges = [
|
|
59
|
+
mockChange({ id: "change0", entity_id: "entity0" }),
|
|
60
|
+
mockChange({ id: "change1", entity_id: "entity1" }),
|
|
61
|
+
] as const;
|
|
62
|
+
|
|
62
63
|
await lix.db
|
|
63
64
|
.insertInto("change")
|
|
64
|
-
.values(
|
|
65
|
-
mockChange({ id: "change1" }),
|
|
66
|
-
mockChange({ id: "change2" }),
|
|
67
|
-
mockChange({ id: "change3" }),
|
|
68
|
-
mockChange({ id: "change4" }),
|
|
69
|
-
])
|
|
65
|
+
.values(mockChanges)
|
|
70
66
|
.returningAll()
|
|
71
67
|
.execute();
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
await updateChangesInVersion({
|
|
70
|
+
lix,
|
|
71
|
+
version: versionA,
|
|
72
|
+
changes: [mockChanges[0], mockChanges[1]],
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
await updateChangesInVersion({
|
|
76
|
+
lix,
|
|
77
|
+
version: versionB,
|
|
78
|
+
changes: [mockChanges[0], mockChanges[1]],
|
|
79
|
+
});
|
|
81
80
|
|
|
82
81
|
const result = await lix.db
|
|
83
82
|
.selectFrom("version_change")
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { test, expect } from "vitest";
|
|
2
2
|
import { createLsaInMemoryEnvironment } from "./create-in-memory-environment.js";
|
|
3
3
|
import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
|
|
4
|
+
import { toBlob } from "../../lix/to-blob.js";
|
|
4
5
|
|
|
5
6
|
test("opening a lix works", async () => {
|
|
6
7
|
const environment = createLsaInMemoryEnvironment();
|
|
@@ -14,7 +15,7 @@ test("opening a lix works", async () => {
|
|
|
14
15
|
.executeTakeFirstOrThrow();
|
|
15
16
|
|
|
16
17
|
// initialize the env with the lix file
|
|
17
|
-
environment.setLix({ id: lixId, blob: await
|
|
18
|
+
environment.setLix({ id: lixId, blob: await toBlob({ lix: mockLix }) });
|
|
18
19
|
|
|
19
20
|
const open0 = await environment.openLix({ id: lixId });
|
|
20
21
|
|
|
@@ -24,7 +25,7 @@ test("opening a lix works", async () => {
|
|
|
24
25
|
.returningAll()
|
|
25
26
|
.executeTakeFirstOrThrow();
|
|
26
27
|
|
|
27
|
-
expect(mockInsert).
|
|
28
|
+
expect(mockInsert).toMatchObject({
|
|
28
29
|
key: "foo",
|
|
29
30
|
value: "bar",
|
|
30
31
|
});
|
|
@@ -44,7 +45,7 @@ test("opening a lix works", async () => {
|
|
|
44
45
|
.selectAll()
|
|
45
46
|
.executeTakeFirstOrThrow();
|
|
46
47
|
|
|
47
|
-
expect(mockSelect).
|
|
48
|
+
expect(mockSelect).toMatchObject({ key: "foo", value: "bar" });
|
|
48
49
|
|
|
49
50
|
await environment.closeLix({ id: lixId, connectionId: open1.connectionId });
|
|
50
51
|
});
|
|
@@ -61,7 +62,7 @@ test("it handles concurrent connections", async () => {
|
|
|
61
62
|
.executeTakeFirstOrThrow();
|
|
62
63
|
|
|
63
64
|
// initialize the env with the lix file
|
|
64
|
-
environment.setLix({ id: lixId, blob: await
|
|
65
|
+
environment.setLix({ id: lixId, blob: await toBlob({ lix: mockLix }) });
|
|
65
66
|
|
|
66
67
|
const open0 = await environment.openLix({ id: lixId });
|
|
67
68
|
const open1 = await environment.openLix({ id: lixId });
|
|
@@ -72,7 +73,7 @@ test("it handles concurrent connections", async () => {
|
|
|
72
73
|
.returningAll()
|
|
73
74
|
.executeTakeFirstOrThrow();
|
|
74
75
|
|
|
75
|
-
expect(mockInsert).
|
|
76
|
+
expect(mockInsert).toMatchObject({
|
|
76
77
|
key: "foo",
|
|
77
78
|
value: "bar",
|
|
78
79
|
});
|
|
@@ -83,7 +84,7 @@ test("it handles concurrent connections", async () => {
|
|
|
83
84
|
.selectAll()
|
|
84
85
|
.executeTakeFirstOrThrow();
|
|
85
86
|
|
|
86
|
-
expect(mockSelect).
|
|
87
|
+
expect(mockSelect).toMatchObject({ key: "foo", value: "bar" });
|
|
87
88
|
|
|
88
89
|
// test both writing at the same time
|
|
89
90
|
|
|
@@ -124,7 +125,7 @@ test("it handles concurrent connections", async () => {
|
|
|
124
125
|
.selectAll()
|
|
125
126
|
.executeTakeFirstOrThrow();
|
|
126
127
|
|
|
127
|
-
expect(mockSelect2).
|
|
128
|
+
expect(mockSelect2).toMatchObject({ key: "foo", value: "bar3" });
|
|
128
129
|
|
|
129
130
|
await environment.closeLix({ id: lixId, connectionId: open2.connectionId });
|
|
130
131
|
});
|