@lix-js/sdk 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/change-set/create-change-set.d.ts +13 -1
- package/dist/change-set/create-change-set.d.ts.map +1 -1
- package/dist/change-set/create-change-set.js +30 -7
- package/dist/change-set/create-change-set.js.map +1 -1
- package/dist/change-set/create-change-set.test.js +50 -0
- package/dist/change-set/create-change-set.test.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/server-protocol-handler/create-server-protocol-handler.d.ts +49 -0
- package/dist/server-protocol-handler/create-server-protocol-handler.d.ts.map +1 -0
- package/dist/{server-api-handler/create-server-api-handler.js → server-protocol-handler/create-server-protocol-handler.js} +12 -10
- package/dist/server-protocol-handler/create-server-protocol-handler.js.map +1 -0
- package/dist/server-protocol-handler/environment/create-in-memory-environment.d.ts +9 -0
- package/dist/server-protocol-handler/environment/create-in-memory-environment.d.ts.map +1 -0
- package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.js +3 -1
- package/dist/server-protocol-handler/environment/create-in-memory-environment.js.map +1 -0
- package/dist/server-protocol-handler/environment/create-in-memory-environment.test.d.ts.map +1 -0
- package/dist/server-protocol-handler/environment/create-in-memory-environment.test.js.map +1 -0
- package/dist/{server-api-handler → server-protocol-handler}/environment/environment.d.ts +2 -1
- package/dist/server-protocol-handler/environment/environment.d.ts.map +1 -0
- package/dist/server-protocol-handler/environment/environment.js.map +1 -0
- package/dist/server-protocol-handler/index.d.ts +3 -0
- package/dist/server-protocol-handler/index.d.ts.map +1 -0
- package/dist/server-protocol-handler/index.js +3 -0
- package/dist/server-protocol-handler/index.js.map +1 -0
- package/dist/server-protocol-handler/routes/get-v1.d.ts +3 -0
- package/dist/server-protocol-handler/routes/get-v1.d.ts.map +1 -0
- package/dist/server-protocol-handler/routes/get-v1.js.map +1 -0
- package/dist/server-protocol-handler/routes/get-v1.test.d.ts.map +1 -0
- package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.test.js +16 -16
- package/dist/server-protocol-handler/routes/get-v1.test.js.map +1 -0
- package/dist/server-protocol-handler/routes/new-v1.d.ts +3 -0
- package/dist/server-protocol-handler/routes/new-v1.d.ts.map +1 -0
- package/dist/server-protocol-handler/routes/new-v1.js.map +1 -0
- package/dist/server-protocol-handler/routes/new-v1.test.d.ts.map +1 -0
- package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.test.js +12 -12
- package/dist/server-protocol-handler/routes/new-v1.test.js.map +1 -0
- package/dist/server-protocol-handler/routes/pull-v1.d.ts +3 -0
- package/dist/server-protocol-handler/routes/pull-v1.d.ts.map +1 -0
- package/dist/server-protocol-handler/routes/pull-v1.js.map +1 -0
- package/dist/server-protocol-handler/routes/pull-v1.test.d.ts.map +1 -0
- package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.js +12 -13
- package/dist/server-protocol-handler/routes/pull-v1.test.js.map +1 -0
- package/dist/server-protocol-handler/routes/push-v1.d.ts +3 -0
- package/dist/server-protocol-handler/routes/push-v1.d.ts.map +1 -0
- package/dist/server-protocol-handler/routes/push-v1.js.map +1 -0
- package/dist/server-protocol-handler/routes/push-v1.test.d.ts.map +1 -0
- package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.test.js +12 -13
- package/dist/server-protocol-handler/routes/push-v1.test.js.map +1 -0
- package/dist/services/env-variables/index.js +1 -1
- package/dist/sync/pull-from-server.js +1 -2
- package/dist/sync/pull-from-server.js.map +1 -1
- package/dist/sync/pull-from-server.test.js +27 -27
- package/dist/sync/pull-from-server.test.js.map +1 -1
- package/dist/sync/push-to-server.js +1 -1
- package/dist/sync/push-to-server.test.js +18 -18
- package/dist/sync/push-to-server.test.js.map +1 -1
- package/dist/sync/sync-process.js +1 -1
- package/dist/sync/sync-process.js.map +1 -1
- package/dist/sync/sync-process.test.js +13 -13
- package/dist/sync/sync-process.test.js.map +1 -1
- package/package.json +3 -3
- package/src/change-set/create-change-set.test.ts +64 -0
- package/src/change-set/create-change-set.ts +38 -10
- package/src/index.ts +1 -1
- package/src/{server-api-handler/create-server-api-handler.ts → server-protocol-handler/create-server-protocol-handler.ts} +22 -18
- package/src/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.ts +6 -2
- package/src/{server-api-handler → server-protocol-handler}/environment/environment.ts +4 -1
- package/src/server-protocol-handler/index.ts +5 -0
- package/src/{server-api-handler → server-protocol-handler}/routes/get-v1.test.ts +22 -22
- package/src/{server-api-handler → server-protocol-handler}/routes/get-v1.ts +2 -2
- package/src/{server-api-handler → server-protocol-handler}/routes/new-v1.test.ts +16 -16
- package/src/{server-api-handler → server-protocol-handler}/routes/new-v1.ts +2 -2
- package/src/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.ts +16 -16
- package/src/{server-api-handler → server-protocol-handler}/routes/pull-v1.ts +6 -5
- package/src/{server-api-handler → server-protocol-handler}/routes/push-v1.test.ts +18 -18
- package/src/{server-api-handler → server-protocol-handler}/routes/push-v1.ts +6 -5
- package/src/sync/pull-from-server.test.ts +32 -32
- package/src/sync/pull-from-server.ts +5 -5
- package/src/sync/push-to-server.test.ts +22 -22
- package/src/sync/push-to-server.ts +3 -3
- package/src/sync/sync-process.test.ts +18 -18
- package/src/sync/sync-process.ts +1 -1
- package/dist/server-api-handler/create-server-api-handler.d.ts +0 -48
- package/dist/server-api-handler/create-server-api-handler.d.ts.map +0 -1
- package/dist/server-api-handler/create-server-api-handler.js.map +0 -1
- package/dist/server-api-handler/environment/create-in-memory-environment.d.ts +0 -8
- package/dist/server-api-handler/environment/create-in-memory-environment.d.ts.map +0 -1
- package/dist/server-api-handler/environment/create-in-memory-environment.js.map +0 -1
- package/dist/server-api-handler/environment/create-in-memory-environment.test.d.ts.map +0 -1
- package/dist/server-api-handler/environment/create-in-memory-environment.test.js.map +0 -1
- package/dist/server-api-handler/environment/environment.d.ts.map +0 -1
- package/dist/server-api-handler/environment/environment.js.map +0 -1
- package/dist/server-api-handler/index.d.ts +0 -3
- package/dist/server-api-handler/index.d.ts.map +0 -1
- package/dist/server-api-handler/index.js +0 -3
- package/dist/server-api-handler/index.js.map +0 -1
- package/dist/server-api-handler/routes/get-v1.d.ts +0 -3
- package/dist/server-api-handler/routes/get-v1.d.ts.map +0 -1
- package/dist/server-api-handler/routes/get-v1.js.map +0 -1
- package/dist/server-api-handler/routes/get-v1.test.d.ts.map +0 -1
- package/dist/server-api-handler/routes/get-v1.test.js.map +0 -1
- package/dist/server-api-handler/routes/new-v1.d.ts +0 -3
- package/dist/server-api-handler/routes/new-v1.d.ts.map +0 -1
- package/dist/server-api-handler/routes/new-v1.js.map +0 -1
- package/dist/server-api-handler/routes/new-v1.test.d.ts.map +0 -1
- package/dist/server-api-handler/routes/new-v1.test.js.map +0 -1
- package/dist/server-api-handler/routes/pull-v1.d.ts +0 -3
- package/dist/server-api-handler/routes/pull-v1.d.ts.map +0 -1
- package/dist/server-api-handler/routes/pull-v1.js.map +0 -1
- package/dist/server-api-handler/routes/pull-v1.test.d.ts.map +0 -1
- package/dist/server-api-handler/routes/pull-v1.test.js.map +0 -1
- package/dist/server-api-handler/routes/push-v1.d.ts +0 -3
- package/dist/server-api-handler/routes/push-v1.d.ts.map +0 -1
- package/dist/server-api-handler/routes/push-v1.js.map +0 -1
- package/dist/server-api-handler/routes/push-v1.test.d.ts.map +0 -1
- package/dist/server-api-handler/routes/push-v1.test.js.map +0 -1
- package/src/server-api-handler/index.ts +0 -5
- /package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.test.d.ts +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.test.js +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/environment/environment.js +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.js +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.test.d.ts +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.js +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.test.d.ts +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.js +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.d.ts +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.js +0 -0
- /package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.test.d.ts +0 -0
- /package/src/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.test.ts +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { test, expect } from "vitest";
|
|
2
|
-
import * as
|
|
2
|
+
import type * as LixServerProtocol from "@lix-js/server-protocol-schema";
|
|
3
3
|
import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
|
|
4
|
-
import { createServerApiHandler } from "../create-server-
|
|
4
|
+
import { createServerApiHandler } from "../create-server-protocol-handler.js";
|
|
5
5
|
import { mockJsonSnapshot } from "../../snapshot/mock-json-snapshot.js";
|
|
6
6
|
import { mockChange } from "../../change/mock-change.js";
|
|
7
|
-
import {
|
|
7
|
+
import { createLspInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
|
|
8
8
|
import { toBlob } from "../../lix/to-blob.js";
|
|
9
9
|
|
|
10
10
|
type RequestBody =
|
|
11
|
-
|
|
11
|
+
LixServerProtocol.paths["/lsp/pull-v1"]["post"]["requestBody"]["content"]["application/json"];
|
|
12
12
|
|
|
13
13
|
test("it should pull rows successfully", async () => {
|
|
14
14
|
const lix = await openLixInMemory({});
|
|
@@ -26,14 +26,14 @@ test("it should pull rows successfully", async () => {
|
|
|
26
26
|
|
|
27
27
|
await lix.db.insertInto("change").values(mockChanges).execute();
|
|
28
28
|
|
|
29
|
-
const environment =
|
|
29
|
+
const environment = createLspInMemoryEnvironment();
|
|
30
30
|
|
|
31
31
|
await environment.setLix({ id: id.value, blob: await toBlob({ lix }) });
|
|
32
32
|
|
|
33
33
|
const lsaHandler = await createServerApiHandler({ environment });
|
|
34
34
|
|
|
35
35
|
const response = await lsaHandler(
|
|
36
|
-
new Request("http://localhost:3000/
|
|
36
|
+
new Request("http://localhost:3000/lsp/pull-v1", {
|
|
37
37
|
method: "POST",
|
|
38
38
|
body: JSON.stringify({
|
|
39
39
|
lix_id: id.value,
|
|
@@ -48,7 +48,7 @@ test("it should pull rows successfully", async () => {
|
|
|
48
48
|
|
|
49
49
|
expect(response.status).toBe(200);
|
|
50
50
|
const responseJson =
|
|
51
|
-
(await response.json()) as
|
|
51
|
+
(await response.json()) as LixServerProtocol.paths["/lsp/pull-v1"]["post"]["responses"]["200"]["content"]["application/json"];
|
|
52
52
|
|
|
53
53
|
expect(responseJson.data).toBeDefined();
|
|
54
54
|
|
|
@@ -79,13 +79,13 @@ test("it should specifically be able to handle snapshots which use json binary a
|
|
|
79
79
|
.values([{ content: mockSnapshot.content }])
|
|
80
80
|
.execute();
|
|
81
81
|
|
|
82
|
-
const environment =
|
|
82
|
+
const environment = createLspInMemoryEnvironment();
|
|
83
83
|
await environment.setLix({ id, blob: await toBlob({ lix }) });
|
|
84
84
|
|
|
85
85
|
const lsa = await createServerApiHandler({ environment });
|
|
86
86
|
|
|
87
87
|
const response = await lsa(
|
|
88
|
-
new Request("http://localhost:3000/
|
|
88
|
+
new Request("http://localhost:3000/lsp/pull-v1", {
|
|
89
89
|
method: "POST",
|
|
90
90
|
body: JSON.stringify({
|
|
91
91
|
lix_id: id,
|
|
@@ -99,7 +99,7 @@ test("it should specifically be able to handle snapshots which use json binary a
|
|
|
99
99
|
|
|
100
100
|
expect(response.status).toBe(200);
|
|
101
101
|
const responseJson =
|
|
102
|
-
(await response.json()) as
|
|
102
|
+
(await response.json()) as LixServerProtocol.paths["/lsp/pull-v1"]["post"]["responses"]["200"]["content"]["application/json"];
|
|
103
103
|
|
|
104
104
|
expect(responseJson.data).toBeDefined();
|
|
105
105
|
|
|
@@ -119,12 +119,12 @@ test("it should specifically be able to handle snapshots which use json binary a
|
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
test("it should return 404 if the Lix file is not found", async () => {
|
|
122
|
-
const environment =
|
|
122
|
+
const environment = createLspInMemoryEnvironment();
|
|
123
123
|
|
|
124
124
|
const lsa = await createServerApiHandler({ environment });
|
|
125
125
|
|
|
126
126
|
const response = await lsa(
|
|
127
|
-
new Request("http://localhost:3000/
|
|
127
|
+
new Request("http://localhost:3000/lsp/pull-v1", {
|
|
128
128
|
method: "POST",
|
|
129
129
|
body: JSON.stringify({
|
|
130
130
|
lix_id: "nonexistent-id",
|
|
@@ -140,7 +140,7 @@ test("it should return 404 if the Lix file is not found", async () => {
|
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
test("it should return 500 if the Lix file is invalid", async () => {
|
|
143
|
-
const environment =
|
|
143
|
+
const environment = createLspInMemoryEnvironment();
|
|
144
144
|
|
|
145
145
|
await environment.setLix({
|
|
146
146
|
id: "invalid-lix",
|
|
@@ -150,7 +150,7 @@ test("it should return 500 if the Lix file is invalid", async () => {
|
|
|
150
150
|
const lsaHandler = await createServerApiHandler({ environment });
|
|
151
151
|
|
|
152
152
|
const response = await lsaHandler(
|
|
153
|
-
new Request("http://localhost:3000/
|
|
153
|
+
new Request("http://localhost:3000/lsp/pull-v1", {
|
|
154
154
|
method: "POST",
|
|
155
155
|
body: JSON.stringify({
|
|
156
156
|
lix_id: "invalid-lix",
|
|
@@ -172,13 +172,13 @@ test("it should handle empty tables gracefully", async () => {
|
|
|
172
172
|
.selectAll()
|
|
173
173
|
.executeTakeFirstOrThrow();
|
|
174
174
|
|
|
175
|
-
const environment =
|
|
175
|
+
const environment = createLspInMemoryEnvironment();
|
|
176
176
|
await environment.setLix({ id, blob: await toBlob({ lix }) });
|
|
177
177
|
|
|
178
178
|
const lsa = await createServerApiHandler({ environment });
|
|
179
179
|
|
|
180
180
|
const response = await lsa(
|
|
181
|
-
new Request("http://localhost:3000/
|
|
181
|
+
new Request("http://localhost:3000/lsp/pull-v1", {
|
|
182
182
|
method: "POST",
|
|
183
183
|
body: JSON.stringify({
|
|
184
184
|
lix_id: id,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type * as
|
|
2
|
-
import type {
|
|
1
|
+
import type * as LixServerProtocol from "@lix-js/server-protocol-schema";
|
|
2
|
+
import type { LixServerProtocolHandlerRoute } from "../create-server-protocol-handler.js";
|
|
3
3
|
import { getDiffingRows } from "../../sync/get-diffing-rows.js";
|
|
4
4
|
|
|
5
5
|
type RequestBody =
|
|
6
|
-
|
|
6
|
+
LixServerProtocol.paths["/lsp/pull-v1"]["post"]["requestBody"]["content"]["application/json"];
|
|
7
7
|
|
|
8
|
-
type ResponseBody =
|
|
8
|
+
type ResponseBody =
|
|
9
|
+
LixServerProtocol.paths["/lsp/pull-v1"]["post"]["responses"];
|
|
9
10
|
|
|
10
|
-
export const route:
|
|
11
|
+
export const route: LixServerProtocolHandlerRoute = async (context) => {
|
|
11
12
|
const body = (await context.request.json()) as RequestBody;
|
|
12
13
|
const exists = await context.environment.hasLix({ id: body.lix_id });
|
|
13
14
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { test, expect, vi } from "vitest";
|
|
2
|
-
import * as
|
|
2
|
+
import type * as LixServerProtocol from "@lix-js/server-protocol-schema";
|
|
3
3
|
import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
|
|
4
|
-
import { createServerApiHandler } from "../create-server-
|
|
4
|
+
import { createServerApiHandler } from "../create-server-protocol-handler.js";
|
|
5
5
|
import type { Change } from "../../database/schema.js";
|
|
6
6
|
import { mockChange } from "../../change/mock-change.js";
|
|
7
7
|
import { getDiffingRows } from "../../sync/get-diffing-rows.js";
|
|
8
8
|
import { createVersion } from "../../version/create-version.js";
|
|
9
9
|
import { switchVersion } from "../../version/switch-version.js";
|
|
10
10
|
import { pullFromServer } from "../../sync/pull-from-server.js";
|
|
11
|
-
import {
|
|
11
|
+
import { createLspInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
|
|
12
12
|
import { toBlob } from "../../lix/to-blob.js";
|
|
13
13
|
|
|
14
14
|
test("it should push data successfully", async () => {
|
|
@@ -19,7 +19,7 @@ test("it should push data successfully", async () => {
|
|
|
19
19
|
.selectAll()
|
|
20
20
|
.executeTakeFirstOrThrow();
|
|
21
21
|
|
|
22
|
-
const environment =
|
|
22
|
+
const environment = createLspInMemoryEnvironment();
|
|
23
23
|
await environment.setLix({ id, blob: await toBlob({ lix }) });
|
|
24
24
|
|
|
25
25
|
const lsaHandler = await createServerApiHandler({ environment });
|
|
@@ -27,7 +27,7 @@ test("it should push data successfully", async () => {
|
|
|
27
27
|
const mockChange0 = mockChange({ id: "change0" });
|
|
28
28
|
|
|
29
29
|
const response = await lsaHandler(
|
|
30
|
-
new Request("http://localhost:3000/
|
|
30
|
+
new Request("http://localhost:3000/lsp/push-v1", {
|
|
31
31
|
method: "POST",
|
|
32
32
|
body: JSON.stringify({
|
|
33
33
|
lix_id: id,
|
|
@@ -50,7 +50,7 @@ test("it should push data successfully", async () => {
|
|
|
50
50
|
],
|
|
51
51
|
change: [mockChange0] satisfies Change[],
|
|
52
52
|
},
|
|
53
|
-
} satisfies
|
|
53
|
+
} satisfies LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
|
|
54
54
|
headers: {
|
|
55
55
|
"Content-Type": "application/json",
|
|
56
56
|
},
|
|
@@ -73,18 +73,18 @@ test("it should push data successfully", async () => {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
test("it should return 404 if the Lix file is not found", async () => {
|
|
76
|
-
const environment =
|
|
76
|
+
const environment = createLspInMemoryEnvironment();
|
|
77
77
|
|
|
78
78
|
const lsaHandler = await createServerApiHandler({ environment });
|
|
79
79
|
|
|
80
80
|
const response = await lsaHandler(
|
|
81
|
-
new Request("http://localhost:3000/
|
|
81
|
+
new Request("http://localhost:3000/lsp/push-v1", {
|
|
82
82
|
method: "POST",
|
|
83
83
|
body: JSON.stringify({
|
|
84
84
|
lix_id: "nonexistent-id",
|
|
85
85
|
vector_clock: [],
|
|
86
86
|
data: {},
|
|
87
|
-
} satisfies
|
|
87
|
+
} satisfies LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
|
|
88
88
|
headers: {
|
|
89
89
|
"Content-Type": "application/json",
|
|
90
90
|
},
|
|
@@ -95,7 +95,7 @@ test("it should return 404 if the Lix file is not found", async () => {
|
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
test("it should return 500 for an invalid Lix file", async () => {
|
|
98
|
-
const environment =
|
|
98
|
+
const environment = createLspInMemoryEnvironment();
|
|
99
99
|
|
|
100
100
|
await environment.setLix({
|
|
101
101
|
id: `invalid-lix`,
|
|
@@ -105,13 +105,13 @@ test("it should return 500 for an invalid Lix file", async () => {
|
|
|
105
105
|
const lsa = await createServerApiHandler({ environment });
|
|
106
106
|
|
|
107
107
|
const response = await lsa(
|
|
108
|
-
new Request("http://localhost:3000/
|
|
108
|
+
new Request("http://localhost:3000/lsp/push-v1", {
|
|
109
109
|
method: "POST",
|
|
110
110
|
body: JSON.stringify({
|
|
111
111
|
lix_id: "invalid-lix",
|
|
112
112
|
vector_clock: [],
|
|
113
113
|
data: {},
|
|
114
|
-
} satisfies
|
|
114
|
+
} satisfies LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
|
|
115
115
|
headers: {
|
|
116
116
|
"Content-Type": "application/json",
|
|
117
117
|
},
|
|
@@ -129,14 +129,14 @@ test("it should return 400 for a failed insert operation", async () => {
|
|
|
129
129
|
.selectAll()
|
|
130
130
|
.executeTakeFirstOrThrow();
|
|
131
131
|
|
|
132
|
-
const environment =
|
|
132
|
+
const environment = createLspInMemoryEnvironment();
|
|
133
133
|
|
|
134
134
|
environment.setLix({ id, blob: await toBlob({ lix }) });
|
|
135
135
|
|
|
136
136
|
const lsa = await createServerApiHandler({ environment });
|
|
137
137
|
|
|
138
138
|
const response = await lsa(
|
|
139
|
-
new Request("http://localhost:3000/
|
|
139
|
+
new Request("http://localhost:3000/lsp/push-v1", {
|
|
140
140
|
method: "POST",
|
|
141
141
|
body: JSON.stringify({
|
|
142
142
|
lix_id: id,
|
|
@@ -144,7 +144,7 @@ test("it should return 400 for a failed insert operation", async () => {
|
|
|
144
144
|
data: {
|
|
145
145
|
nonexistent_table: [{ key: "test", value: "test value" }],
|
|
146
146
|
},
|
|
147
|
-
} satisfies
|
|
147
|
+
} satisfies LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
|
|
148
148
|
headers: {
|
|
149
149
|
"Content-Type": "application/json",
|
|
150
150
|
},
|
|
@@ -179,7 +179,7 @@ test.skip("it should detect conflicts", async () => {
|
|
|
179
179
|
.selectAll()
|
|
180
180
|
.executeTakeFirstOrThrow();
|
|
181
181
|
|
|
182
|
-
const environment =
|
|
182
|
+
const environment = createLspInMemoryEnvironment();
|
|
183
183
|
|
|
184
184
|
const lsaHandler = await createServerApiHandler({ environment });
|
|
185
185
|
|
|
@@ -208,13 +208,13 @@ test.skip("it should detect conflicts", async () => {
|
|
|
208
208
|
});
|
|
209
209
|
|
|
210
210
|
const response = await lsaHandler(
|
|
211
|
-
new Request("http://localhost:3000/
|
|
211
|
+
new Request("http://localhost:3000/lsp/push-v1", {
|
|
212
212
|
method: "POST",
|
|
213
213
|
body: JSON.stringify({
|
|
214
214
|
lix_id: lixId.value,
|
|
215
215
|
vector_clock: state,
|
|
216
216
|
data: tableRowsToPush,
|
|
217
|
-
} satisfies
|
|
217
|
+
} satisfies LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
|
|
218
218
|
headers: {
|
|
219
219
|
"Content-Type": "application/json",
|
|
220
220
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type * as
|
|
2
|
-
import type {
|
|
1
|
+
import type * as LixServerProtocol from "@lix-js/server-protocol-schema";
|
|
2
|
+
import type { LixServerProtocolHandlerRoute } from "../create-server-protocol-handler.js";
|
|
3
3
|
import { mergeTheirState } from "../../sync/merge-state.js";
|
|
4
4
|
import type { Change } from "../../database/schema.js";
|
|
5
5
|
// import { detectChangeConflicts } from "../../change-conflict/detect-change-conflicts.js";
|
|
@@ -7,11 +7,12 @@ import type { Change } from "../../database/schema.js";
|
|
|
7
7
|
import { CompiledQuery } from "kysely";
|
|
8
8
|
|
|
9
9
|
type RequestBody =
|
|
10
|
-
|
|
10
|
+
LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"];
|
|
11
11
|
|
|
12
|
-
type ResponseBody =
|
|
12
|
+
type ResponseBody =
|
|
13
|
+
LixServerProtocol.paths["/lsp/push-v1"]["post"]["responses"];
|
|
13
14
|
|
|
14
|
-
export const route:
|
|
15
|
+
export const route: LixServerProtocolHandlerRoute = async (context) => {
|
|
15
16
|
const body = (await context.request.json()) as RequestBody;
|
|
16
17
|
const exists = await context.environment.hasLix({ id: body.lix_id });
|
|
17
18
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { expect, test, vi } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { createServerProtocolHandler } from "../server-protocol-handler/create-server-protocol-handler.js";
|
|
3
3
|
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
|
-
import {
|
|
6
|
+
import { createLspInMemoryEnvironment } from "../server-protocol-handler/environment/create-in-memory-environment.js";
|
|
7
7
|
import { toBlob } from "../lix/to-blob.js";
|
|
8
8
|
|
|
9
9
|
test("pull rows of multiple tables from server successfully and applies them", async () => {
|
|
@@ -19,10 +19,10 @@ test("pull rows of multiple tables from server successfully and applies them", a
|
|
|
19
19
|
.selectAll()
|
|
20
20
|
.executeTakeFirstOrThrow();
|
|
21
21
|
|
|
22
|
-
const environment =
|
|
23
|
-
const
|
|
22
|
+
const environment = createLspInMemoryEnvironment();
|
|
23
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
24
24
|
|
|
25
|
-
global.fetch = vi.fn((request) =>
|
|
25
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
26
26
|
|
|
27
27
|
await lixOnServer.db
|
|
28
28
|
.insertInto("account")
|
|
@@ -38,8 +38,8 @@ test("pull rows of multiple tables from server successfully and applies them", a
|
|
|
38
38
|
.execute();
|
|
39
39
|
|
|
40
40
|
// initialize the lix on the server with the mock data
|
|
41
|
-
await
|
|
42
|
-
new Request("http://localhost:3000/
|
|
41
|
+
await lspHandler(
|
|
42
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
43
43
|
method: "POST",
|
|
44
44
|
body: await toBlob({ lix: lixOnServer }),
|
|
45
45
|
headers: {
|
|
@@ -85,10 +85,10 @@ test("it handles snapshot.content being json binary", async () => {
|
|
|
85
85
|
.selectAll()
|
|
86
86
|
.executeTakeFirstOrThrow();
|
|
87
87
|
|
|
88
|
-
const environment =
|
|
89
|
-
const
|
|
88
|
+
const environment = createLspInMemoryEnvironment();
|
|
89
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
90
90
|
|
|
91
|
-
global.fetch = vi.fn((request) =>
|
|
91
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
92
92
|
|
|
93
93
|
const mockSnapshot = mockJsonSnapshot({
|
|
94
94
|
location: "Berlin",
|
|
@@ -103,8 +103,8 @@ test("it handles snapshot.content being json binary", async () => {
|
|
|
103
103
|
.execute();
|
|
104
104
|
|
|
105
105
|
// initialize the lix on the server with the mock data
|
|
106
|
-
await
|
|
107
|
-
new Request("http://localhost:3000/
|
|
106
|
+
await lspHandler(
|
|
107
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
108
108
|
method: "POST",
|
|
109
109
|
body: await toBlob({ lix: lixOnServer }),
|
|
110
110
|
headers: {
|
|
@@ -150,14 +150,14 @@ test("rows changed on the client more recently should not be updated", async ()
|
|
|
150
150
|
blob: await toBlob({ lix: lixOnServer }),
|
|
151
151
|
});
|
|
152
152
|
|
|
153
|
-
const environment =
|
|
154
|
-
const
|
|
153
|
+
const environment = createLspInMemoryEnvironment();
|
|
154
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
155
155
|
|
|
156
|
-
global.fetch = vi.fn((request) =>
|
|
156
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
157
157
|
|
|
158
158
|
// initialize the lix on the server with the mock data
|
|
159
|
-
await
|
|
160
|
-
new Request("http://localhost:3000/
|
|
159
|
+
await lspHandler(
|
|
160
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
161
161
|
method: "POST",
|
|
162
162
|
body: await toBlob({ lix: lixOnServer }),
|
|
163
163
|
headers: {
|
|
@@ -195,10 +195,10 @@ test("rows changed on the client more recently should not be updated", async ()
|
|
|
195
195
|
// the change table now models "change control". no more last edit wins needed
|
|
196
196
|
test.skip("rows changed on the server more recently should be updated on the client", async () => {
|
|
197
197
|
// setup mock server
|
|
198
|
-
const environment =
|
|
199
|
-
const
|
|
198
|
+
const environment = createLspInMemoryEnvironment();
|
|
199
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
200
200
|
|
|
201
|
-
global.fetch = vi.fn((request) =>
|
|
201
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
202
202
|
|
|
203
203
|
// create a lix and clone it for the client - so they share the same lix id
|
|
204
204
|
const remoteLix = await openLixInMemory({});
|
|
@@ -243,8 +243,8 @@ test.skip("rows changed on the server more recently should be updated on the cli
|
|
|
243
243
|
.execute();
|
|
244
244
|
|
|
245
245
|
// initialize the lix on the server with the mock data
|
|
246
|
-
await
|
|
247
|
-
new Request("http://localhost:3000/
|
|
246
|
+
await lspHandler(
|
|
247
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
248
248
|
method: "POST",
|
|
249
249
|
body: await toBlob({ lix: remoteLix }),
|
|
250
250
|
headers: {
|
|
@@ -302,14 +302,14 @@ test.skip("rows changed on the server more recently should be updated on the cli
|
|
|
302
302
|
// .selectAll()
|
|
303
303
|
// .executeTakeFirstOrThrow();
|
|
304
304
|
|
|
305
|
-
// const environment =
|
|
306
|
-
// const
|
|
305
|
+
// const environment = createLspInMemoryEnvironment();
|
|
306
|
+
// const lspHandler = await createServerProtocolHandler({ environment });
|
|
307
307
|
|
|
308
|
-
// global.fetch = vi.fn((request) =>
|
|
308
|
+
// global.fetch = vi.fn((request) => lspHandler(request));
|
|
309
309
|
|
|
310
310
|
// // initialize the lix on the server
|
|
311
|
-
// await
|
|
312
|
-
// new Request("http://localhost:3000/
|
|
311
|
+
// await lspHandler(
|
|
312
|
+
// new Request("http://localhost:3000/lsp/new", {
|
|
313
313
|
// method: "POST",
|
|
314
314
|
// body: await lix.toBlob(),
|
|
315
315
|
// })
|
|
@@ -354,10 +354,10 @@ test("non-conflicting changes from the server should for the same version should
|
|
|
354
354
|
.selectAll()
|
|
355
355
|
.executeTakeFirstOrThrow();
|
|
356
356
|
|
|
357
|
-
const environment =
|
|
358
|
-
const
|
|
357
|
+
const environment = createLspInMemoryEnvironment();
|
|
358
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
359
359
|
|
|
360
|
-
global.fetch = vi.fn((request) =>
|
|
360
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
361
361
|
|
|
362
362
|
const lixOnServer = await openLixInMemory({ blob: await toBlob({ lix }) });
|
|
363
363
|
|
|
@@ -389,8 +389,8 @@ test("non-conflicting changes from the server should for the same version should
|
|
|
389
389
|
])
|
|
390
390
|
);
|
|
391
391
|
|
|
392
|
-
await
|
|
393
|
-
new Request("http://localhost:3000/
|
|
392
|
+
await lspHandler(
|
|
393
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
394
394
|
method: "POST",
|
|
395
395
|
body: await toBlob({ lix: lixOnServer }),
|
|
396
396
|
headers: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Lix } from "../lix/open-lix.js";
|
|
2
|
-
import * as
|
|
2
|
+
import type * as LixServerProtocol from "@lix-js/server-protocol-schema";
|
|
3
3
|
import { mergeTheirState, type VectorClock } from "./merge-state.js";
|
|
4
4
|
import { applyChanges } from "../change/apply-changes.js";
|
|
5
5
|
import type { Change } from "../database/schema.js";
|
|
@@ -21,12 +21,12 @@ export async function pullFromServer(args: {
|
|
|
21
21
|
|
|
22
22
|
// 2. query the state from the server using the clients vector clock
|
|
23
23
|
const response = await fetch(
|
|
24
|
-
new Request(`${args.serverUrl}/
|
|
24
|
+
new Request(`${args.serverUrl}/lsp/pull-v1`, {
|
|
25
25
|
method: "POST",
|
|
26
26
|
body: JSON.stringify({
|
|
27
27
|
lix_id: args.id,
|
|
28
28
|
vector_clock: sessionStatesClient,
|
|
29
|
-
} satisfies
|
|
29
|
+
} satisfies LixServerProtocol.paths["/lsp/pull-v1"]["post"]["requestBody"]["content"]["application/json"]),
|
|
30
30
|
headers: {
|
|
31
31
|
"Content-Type": "application/json",
|
|
32
32
|
},
|
|
@@ -49,11 +49,11 @@ export async function pullFromServer(args: {
|
|
|
49
49
|
// 3. Client receives the data (added/changed rows + vector clock) from the server
|
|
50
50
|
// - client could have moved forward in the meantime!
|
|
51
51
|
const data = (
|
|
52
|
-
body as
|
|
52
|
+
body as LixServerProtocol.paths["/lsp/pull-v1"]["post"]["responses"]["200"]["content"]["application/json"]
|
|
53
53
|
).data;
|
|
54
54
|
|
|
55
55
|
const sessionStateServer = (
|
|
56
|
-
body as
|
|
56
|
+
body as LixServerProtocol.paths["/lsp/pull-v1"]["post"]["responses"]["200"]["content"]["application/json"]
|
|
57
57
|
).vector_clock;
|
|
58
58
|
|
|
59
59
|
const changes = (data["change"] ?? []) as Change[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, test, vi } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { createServerProtocolHandler } from "../server-protocol-handler/create-server-protocol-handler.js";
|
|
3
3
|
import { openLixInMemory } from "../lix/open-lix-in-memory.js";
|
|
4
4
|
import { pushToServer } from "./push-to-server.js";
|
|
5
5
|
import type { LixFile } from "../database/schema.js";
|
|
@@ -8,7 +8,7 @@ import { newLixFile } from "../lix/new-lix.js";
|
|
|
8
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
|
-
import {
|
|
11
|
+
import { createLspInMemoryEnvironment } from "../server-protocol-handler/environment/create-in-memory-environment.js";
|
|
12
12
|
import { toBlob } from "../lix/to-blob.js";
|
|
13
13
|
|
|
14
14
|
test("push rows of multiple tables to server successfully", async () => {
|
|
@@ -22,14 +22,14 @@ test("push rows of multiple tables to server successfully", async () => {
|
|
|
22
22
|
.selectAll()
|
|
23
23
|
.executeTakeFirstOrThrow();
|
|
24
24
|
|
|
25
|
-
const environment =
|
|
26
|
-
const
|
|
25
|
+
const environment = createLspInMemoryEnvironment();
|
|
26
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
27
27
|
|
|
28
|
-
global.fetch = vi.fn((request) =>
|
|
28
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
29
29
|
|
|
30
30
|
// initialize the lix on the server
|
|
31
|
-
await
|
|
32
|
-
new Request("http://localhost:3000/
|
|
31
|
+
await lspHandler(
|
|
32
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
33
33
|
method: "POST",
|
|
34
34
|
body: await toBlob({ lix }),
|
|
35
35
|
})
|
|
@@ -103,14 +103,14 @@ test("push-pull-push with two clients", async () => {
|
|
|
103
103
|
.selectAll()
|
|
104
104
|
.executeTakeFirstOrThrow();
|
|
105
105
|
|
|
106
|
-
const environment =
|
|
107
|
-
const
|
|
106
|
+
const environment = createLspInMemoryEnvironment();
|
|
107
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
108
108
|
|
|
109
|
-
global.fetch = vi.fn((request) =>
|
|
109
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
110
110
|
|
|
111
111
|
// Initialize the lix on the server
|
|
112
|
-
await
|
|
113
|
-
new Request("http://localhost:3000/
|
|
112
|
+
await lspHandler(
|
|
113
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
114
114
|
method: "POST",
|
|
115
115
|
body: await toBlob({ lix: client1 }),
|
|
116
116
|
})
|
|
@@ -286,14 +286,14 @@ test("it should handle snapshots.content json binaries", async () => {
|
|
|
286
286
|
.selectAll()
|
|
287
287
|
.executeTakeFirstOrThrow();
|
|
288
288
|
|
|
289
|
-
const environment =
|
|
290
|
-
const
|
|
289
|
+
const environment = createLspInMemoryEnvironment();
|
|
290
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
291
291
|
|
|
292
|
-
global.fetch = vi.fn((request) =>
|
|
292
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
293
293
|
|
|
294
294
|
// initialize the lix on the server
|
|
295
|
-
await
|
|
296
|
-
new Request("http://localhost:3000/
|
|
295
|
+
await lspHandler(
|
|
296
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
297
297
|
method: "POST",
|
|
298
298
|
body: await toBlob({ lix }),
|
|
299
299
|
})
|
|
@@ -340,14 +340,14 @@ test.todo("it should handle binary values", async () => {
|
|
|
340
340
|
.selectAll()
|
|
341
341
|
.executeTakeFirstOrThrow();
|
|
342
342
|
|
|
343
|
-
const environment =
|
|
344
|
-
const
|
|
343
|
+
const environment = createLspInMemoryEnvironment();
|
|
344
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
345
345
|
|
|
346
|
-
global.fetch = vi.fn((request) =>
|
|
346
|
+
global.fetch = vi.fn((request) => lspHandler(request));
|
|
347
347
|
|
|
348
348
|
// initialize the lix on the server
|
|
349
|
-
await
|
|
350
|
-
new Request("http://localhost:3000/
|
|
349
|
+
await lspHandler(
|
|
350
|
+
new Request("http://localhost:3000/lsp/new", {
|
|
351
351
|
method: "POST",
|
|
352
352
|
body: await toBlob({ lix }),
|
|
353
353
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as LixServerProtocol from "
|
|
1
|
+
import type * as LixServerProtocol from "@lix-js/server-protocol-schema";
|
|
2
2
|
import type { Lix } from "../lix/open-lix.js";
|
|
3
3
|
import type { VectorClock } from "./merge-state.js";
|
|
4
4
|
import { getDiffingRows } from "./get-diffing-rows.js";
|
|
@@ -28,13 +28,13 @@ export async function pushToServer(args: {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const response = await fetch(
|
|
31
|
-
new Request(`${args.serverUrl}/
|
|
31
|
+
new Request(`${args.serverUrl}/lsp/push-v1`, {
|
|
32
32
|
method: "POST",
|
|
33
33
|
body: JSON.stringify({
|
|
34
34
|
lix_id: args.id,
|
|
35
35
|
vector_clock: state,
|
|
36
36
|
data: tableRowsToPush,
|
|
37
|
-
} satisfies LixServerProtocol.paths["/
|
|
37
|
+
} satisfies LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
|
|
38
38
|
headers: {
|
|
39
39
|
"Content-Type": "application/json",
|
|
40
40
|
},
|