@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
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
|
|
|
@@ -64,7 +58,7 @@ export async function initSyncProcess(args: {
|
|
|
64
58
|
const response = await fetch(
|
|
65
59
|
new Request(url.value + "/lsa/new-v1", {
|
|
66
60
|
method: "POST",
|
|
67
|
-
body: await args.lix
|
|
61
|
+
body: await toBlob({ lix: args.lix }),
|
|
68
62
|
})
|
|
69
63
|
);
|
|
70
64
|
if (!response.ok && response.status !== 409) {
|
|
@@ -77,7 +71,7 @@ export async function initSyncProcess(args: {
|
|
|
77
71
|
// naive implementation that syncs every second
|
|
78
72
|
|
|
79
73
|
function schedulePullAndPush() {
|
|
80
|
-
if (
|
|
74
|
+
if (args.lix.sqlite.isOpen()) {
|
|
81
75
|
pullAndPush().catch((e) => {
|
|
82
76
|
console.error("Error in sync process", e);
|
|
83
77
|
});
|
|
@@ -88,10 +82,4 @@ export async function initSyncProcess(args: {
|
|
|
88
82
|
}
|
|
89
83
|
|
|
90
84
|
schedulePullAndPush();
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
stop: () => {
|
|
94
|
-
stoped = true;
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
85
|
}
|
|
@@ -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
|
|
|
@@ -4,25 +4,25 @@ import type { Lix } from "../lix/open-lix.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a new Version.
|
|
6
6
|
*
|
|
7
|
-
* If
|
|
7
|
+
* If `from` is provided, the new version will be identical to the from version.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* _Without
|
|
10
|
+
* _Without from_
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const version = await createVersion({ lix });
|
|
14
14
|
* ```
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
|
-
* _With
|
|
17
|
+
* _With from_
|
|
18
18
|
*
|
|
19
19
|
* ```ts
|
|
20
|
-
* const version = await createVersion({ lix,
|
|
20
|
+
* const version = await createVersion({ lix, from: otherVersion });
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export async function createVersion(args: {
|
|
24
24
|
lix: Pick<Lix, "db">;
|
|
25
|
-
|
|
25
|
+
from?: Pick<Version, "id">;
|
|
26
26
|
name?: Version["name"];
|
|
27
27
|
}): Promise<Version> {
|
|
28
28
|
const executeInTransaction = async (trx: Lix["db"]) => {
|
|
@@ -36,20 +36,32 @@ export async function createVersion(args: {
|
|
|
36
36
|
|
|
37
37
|
const newVersion = await query.executeTakeFirstOrThrow();
|
|
38
38
|
|
|
39
|
-
// copy the change pointers from the
|
|
40
|
-
if (args.
|
|
39
|
+
// copy the change pointers from the from Version
|
|
40
|
+
if (args.from) {
|
|
41
41
|
await trx
|
|
42
42
|
.insertInto("version_change")
|
|
43
|
-
.columns([
|
|
43
|
+
.columns([
|
|
44
|
+
"version_id",
|
|
45
|
+
"change_id",
|
|
46
|
+
"entity_id",
|
|
47
|
+
"schema_key",
|
|
48
|
+
"file_id",
|
|
49
|
+
])
|
|
44
50
|
.expression((eb) =>
|
|
45
51
|
eb
|
|
46
52
|
.selectFrom("version_change")
|
|
47
|
-
.select([
|
|
48
|
-
|
|
53
|
+
.select([
|
|
54
|
+
eb.val(newVersion.id).as("version_id"),
|
|
55
|
+
"change_id",
|
|
56
|
+
"entity_id",
|
|
57
|
+
"schema_key",
|
|
58
|
+
"file_id",
|
|
59
|
+
])
|
|
60
|
+
.where("version_id", "=", args.from!.id)
|
|
49
61
|
)
|
|
50
62
|
.execute();
|
|
51
63
|
|
|
52
|
-
// copy the change conflicts from the
|
|
64
|
+
// copy the change conflicts from the from Version
|
|
53
65
|
await trx
|
|
54
66
|
.insertInto("version_change_conflict")
|
|
55
67
|
.columns(["version_id", "change_conflict_id"])
|
|
@@ -60,7 +72,7 @@ export async function createVersion(args: {
|
|
|
60
72
|
eb.val(newVersion.id).as("version_id"),
|
|
61
73
|
"change_conflict_id",
|
|
62
74
|
])
|
|
63
|
-
.where("version_id", "=", args.
|
|
75
|
+
.where("version_id", "=", args.from!.id)
|
|
64
76
|
)
|
|
65
77
|
.execute();
|
|
66
78
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createChangeConflict } from "../change-conflict/create-change-conflict.js";
|
|
2
2
|
import { detectChangeConflicts } from "../change-conflict/detect-change-conflicts.js";
|
|
3
3
|
import { applyChanges } from "../change/apply-changes.js";
|
|
4
|
-
import type { Version } from "../database/schema.js";
|
|
4
|
+
import type { Version, VersionChange } from "../database/schema.js";
|
|
5
5
|
import type { Lix } from "../lix/open-lix.js";
|
|
6
6
|
import { versionChangeInSymmetricDifference } from "../query-filter/version-change-in-symmetric-difference.js";
|
|
7
7
|
|
|
@@ -33,42 +33,34 @@ export async function mergeVersion(args: {
|
|
|
33
33
|
conflict.conflictingChangeIds.has(change.id)
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
const
|
|
37
|
-
.
|
|
38
|
-
|
|
36
|
+
const versionChange: VersionChange = {
|
|
37
|
+
version_id: args.targetVersion.id,
|
|
38
|
+
change_id: change.id,
|
|
39
|
+
entity_id: change.entity_id,
|
|
40
|
+
schema_key: change.schema_key,
|
|
41
|
+
file_id: change.file_id,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const existingTargetVersionChange = await trx
|
|
45
|
+
.selectFrom("version_change")
|
|
39
46
|
.where("version_change.version_id", "=", args.targetVersion.id)
|
|
40
47
|
.where("file_id", "=", change.file_id)
|
|
41
48
|
.where("entity_id", "=", change.entity_id)
|
|
42
49
|
.where("schema_key", "=", change.schema_key)
|
|
43
|
-
.select("
|
|
50
|
+
.select("change_id")
|
|
44
51
|
.executeTakeFirst();
|
|
45
52
|
|
|
46
53
|
// shouldn't update the pointer if there is a conflict
|
|
47
54
|
// and the change pointer already exists
|
|
48
|
-
if (hasConflict &&
|
|
55
|
+
if (hasConflict && existingTargetVersionChange) {
|
|
49
56
|
continue;
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
change_id: change.id,
|
|
58
|
-
})
|
|
59
|
-
.where("change_id", "=", existingTargetChange.id)
|
|
60
|
-
.where("version_id", "=", args.targetVersion.id)
|
|
61
|
-
.execute();
|
|
62
|
-
} else {
|
|
63
|
-
// insert the new change pointer
|
|
64
|
-
await trx
|
|
65
|
-
.insertInto("version_change")
|
|
66
|
-
.values({
|
|
67
|
-
version_id: args.targetVersion.id,
|
|
68
|
-
change_id: change.id,
|
|
69
|
-
})
|
|
70
|
-
.execute();
|
|
71
|
-
}
|
|
59
|
+
await trx
|
|
60
|
+
.insertInto("version_change")
|
|
61
|
+
.values(versionChange)
|
|
62
|
+
.onConflict((oc) => oc.doUpdateSet(versionChange))
|
|
63
|
+
.execute();
|
|
72
64
|
}
|
|
73
65
|
|
|
74
66
|
// insert the detected conflicts
|
|
@@ -4,7 +4,7 @@ import { switchVersion } from "./switch-version.js";
|
|
|
4
4
|
import { createVersion } from "./create-version.js";
|
|
5
5
|
import { createChange } from "../change/create-change.js";
|
|
6
6
|
import type { LixPlugin } from "../plugin/lix-plugin.js";
|
|
7
|
-
import {
|
|
7
|
+
import { fileQueueSettled } from "../file-queue/file-queue-settled.js";
|
|
8
8
|
|
|
9
9
|
test("switching versiones should update the current_version", async () => {
|
|
10
10
|
const lix = await openLixInMemory({});
|
|
@@ -18,7 +18,7 @@ test("switching versiones should update the current_version", async () => {
|
|
|
18
18
|
const newVersion = await lix.db.transaction().execute(async (trx) => {
|
|
19
19
|
const newVersion = await createVersion({
|
|
20
20
|
lix: { db: trx },
|
|
21
|
-
|
|
21
|
+
from: currentVersion,
|
|
22
22
|
});
|
|
23
23
|
await switchVersion({ lix: { ...lix, db: trx }, to: newVersion });
|
|
24
24
|
return newVersion;
|
|
@@ -60,7 +60,7 @@ test("switching a version does not lead to duplicate changes", async () => {
|
|
|
60
60
|
|
|
61
61
|
const newVersion = await createVersion({
|
|
62
62
|
lix: lix,
|
|
63
|
-
|
|
63
|
+
from: currentVersion,
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
const changesBefore = await lix.db.selectFrom("change").selectAll().execute();
|
|
@@ -95,7 +95,7 @@ test("switch version applies the changes of the switched to version", async () =
|
|
|
95
95
|
.selectAll()
|
|
96
96
|
.execute();
|
|
97
97
|
|
|
98
|
-
expect(keyValues).
|
|
98
|
+
expect(keyValues).toMatchObject([{ key: "foo", value: "bar" }]);
|
|
99
99
|
|
|
100
100
|
await switchVersion({ lix, to: versionB });
|
|
101
101
|
|
|
@@ -123,7 +123,7 @@ test("switch version applies the changes of the switched to version", async () =
|
|
|
123
123
|
.execute();
|
|
124
124
|
|
|
125
125
|
// expecting to see the value from version A again
|
|
126
|
-
expect(keyValues).
|
|
126
|
+
expect(keyValues).toMatchObject([{ key: "foo", value: "bar" }]);
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
// https://github.com/opral/lix-sdk/issues/209
|
|
@@ -177,11 +177,11 @@ test("a deleted file in one version does not impact a version which did not dele
|
|
|
177
177
|
})
|
|
178
178
|
.execute();
|
|
179
179
|
|
|
180
|
-
await
|
|
180
|
+
await fileQueueSettled({ lix });
|
|
181
181
|
|
|
182
182
|
expect(mockTxtPlugin.detectChanges).toHaveBeenCalledTimes(1);
|
|
183
183
|
|
|
184
|
-
const versionB = await createVersion({ lix,
|
|
184
|
+
const versionB = await createVersion({ lix, from: versionA });
|
|
185
185
|
|
|
186
186
|
await switchVersion({ lix, to: versionB });
|
|
187
187
|
|
|
@@ -191,7 +191,7 @@ test("a deleted file in one version does not impact a version which did not dele
|
|
|
191
191
|
// deleting the file in version B
|
|
192
192
|
await lix.db.deleteFrom("file").where("id", "=", "file0").execute();
|
|
193
193
|
|
|
194
|
-
await
|
|
194
|
+
await fileQueueSettled({ lix });
|
|
195
195
|
|
|
196
196
|
// lix own change control handles file deletions
|
|
197
197
|
// expecting the plugin.detectChanges to not be invoked
|
|
@@ -231,7 +231,7 @@ test("a deleted file in one version does not impact a version which did not dele
|
|
|
231
231
|
expect(fileAfterSwitch).toBeUndefined();
|
|
232
232
|
});
|
|
233
233
|
|
|
234
|
-
test("doesn't trigger the
|
|
234
|
+
test("doesn't trigger the file queue when switching versions which would lead to duplicate changes", async () => {
|
|
235
235
|
const mockTxtPlugin: LixPlugin = {
|
|
236
236
|
key: "mock_txt_plugin",
|
|
237
237
|
detectChangesGlob: "*.txt",
|
|
@@ -282,14 +282,11 @@ test("doesn't trigger the change queue when switching versions which would lead
|
|
|
282
282
|
})
|
|
283
283
|
.execute();
|
|
284
284
|
|
|
285
|
-
await
|
|
285
|
+
await fileQueueSettled({ lix });
|
|
286
286
|
|
|
287
287
|
await switchVersion({ lix, to: versionB });
|
|
288
288
|
|
|
289
|
-
const
|
|
290
|
-
.selectFrom("change_queue")
|
|
291
|
-
.selectAll()
|
|
292
|
-
.execute();
|
|
289
|
+
const fileQueue = await lix.db.selectFrom("file_queue").selectAll().execute();
|
|
293
290
|
|
|
294
|
-
expect(
|
|
291
|
+
expect(fileQueue).toHaveLength(0);
|
|
295
292
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withSkipFileQueue } from "../file-queue/with-skip-file-queue.js";
|
|
2
2
|
import { applyChanges } from "../change/apply-changes.js";
|
|
3
3
|
import type { Change, Version } from "../database/schema.js";
|
|
4
4
|
import type { Lix } from "../lix/open-lix.js";
|
|
@@ -29,7 +29,7 @@ export async function switchVersion(args: {
|
|
|
29
29
|
to: Pick<Version, "id">;
|
|
30
30
|
}): Promise<void> {
|
|
31
31
|
const executeInTransaction = async (trx: Lix["db"]) => {
|
|
32
|
-
await
|
|
32
|
+
await withSkipFileQueue(trx, async (trx) => {
|
|
33
33
|
const sourceVersion = await trx
|
|
34
34
|
.selectFrom("current_version")
|
|
35
35
|
.selectAll()
|
|
@@ -75,7 +75,7 @@ export async function switchVersion(args: {
|
|
|
75
75
|
// need to remove the entity when switching the version
|
|
76
76
|
else {
|
|
77
77
|
if (
|
|
78
|
-
change.plugin_key === "
|
|
78
|
+
change.plugin_key === "lix_own_change_control" &&
|
|
79
79
|
(change.schema_key === "lix_account_table" ||
|
|
80
80
|
change.schema_key === "lix_version_table")
|
|
81
81
|
) {
|
|
@@ -13,41 +13,22 @@ export async function updateChangesInVersion(args: {
|
|
|
13
13
|
changes: Change[];
|
|
14
14
|
}): Promise<void> {
|
|
15
15
|
// const executeInTransaction = async (trx: Lix["db"]) => {
|
|
16
|
-
|
|
17
16
|
for (const change of args.changes ?? []) {
|
|
18
|
-
|
|
19
|
-
const existingEntityChange = executeSync({
|
|
17
|
+
executeSync({
|
|
20
18
|
lix: args.lix,
|
|
21
19
|
query: args.lix.db
|
|
22
|
-
.
|
|
23
|
-
.
|
|
24
|
-
.where("version_change.version_id", "=", args.version.id)
|
|
25
|
-
.where("change.schema_key", "=", change.schema_key)
|
|
26
|
-
.where("change.entity_id", "=", change.entity_id)
|
|
27
|
-
.where("change.file_id", "=", change.file_id)
|
|
28
|
-
.selectAll(),
|
|
29
|
-
})[0];
|
|
30
|
-
|
|
31
|
-
if (existingEntityChange) {
|
|
32
|
-
// update the existing pointer
|
|
33
|
-
executeSync({
|
|
34
|
-
lix: args.lix,
|
|
35
|
-
query: args.lix.db
|
|
36
|
-
.updateTable("version_change")
|
|
37
|
-
.set("change_id", change.id)
|
|
38
|
-
.where("change_id", "=", existingEntityChange.id)
|
|
39
|
-
.where("version_id", "=", args.version.id),
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
// create a new pointer
|
|
43
|
-
executeSync({
|
|
44
|
-
lix: args.lix,
|
|
45
|
-
query: args.lix.db.insertInto("version_change").values({
|
|
20
|
+
.insertInto("version_change")
|
|
21
|
+
.values({
|
|
46
22
|
version_id: args.version.id,
|
|
47
23
|
change_id: change.id,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
entity_id: change.entity_id,
|
|
25
|
+
schema_key: change.schema_key,
|
|
26
|
+
file_id: change.file_id,
|
|
27
|
+
})
|
|
28
|
+
.onConflict((oc) =>
|
|
29
|
+
oc.doUpdateSet((eb) => ({ change_id: eb.ref("excluded.change_id") }))
|
|
30
|
+
),
|
|
31
|
+
});
|
|
51
32
|
}
|
|
52
33
|
|
|
53
34
|
// await updateChangeConflicts({
|