@lix-js/sdk 0.4.3 → 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/database/init-db.test.js.map +1 -1
- package/dist/database/nano-id.js +1 -1
- package/dist/database/nano-id.js.map +1 -1
- package/dist/file-queue/file-handlers.d.ts.map +1 -1
- package/dist/file-queue/file-handlers.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 +4 -3
- package/src/change-set/create-change-set.test.ts +64 -0
- package/src/change-set/create-change-set.ts +38 -10
- package/src/database/init-db.test.ts +1 -3
- package/src/database/nano-id.test.ts +1 -1
- package/src/database/nano-id.ts +13 -13
- package/src/file-queue/file-handlers.ts +0 -1
- 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
|
@@ -2,18 +2,18 @@ import { route as newRouteV1 } from "./routes/new-v1.js";
|
|
|
2
2
|
import { route as pushRouteV1 } from "./routes/push-v1.js";
|
|
3
3
|
import { route as pullRouteV1 } from "./routes/pull-v1.js";
|
|
4
4
|
import { route as getRouteV1 } from "./routes/get-v1.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { LspEnvironment } from "./environment/environment.js";
|
|
6
6
|
|
|
7
|
-
export type
|
|
8
|
-
|
|
9
|
-
export type
|
|
7
|
+
export type LixServerProtocolHandler = (request: Request) => Promise<Response>;
|
|
8
|
+
// Keep old name for backward compatibility
|
|
9
|
+
export type LixServerProtocolHandlerContext = {
|
|
10
10
|
request: Request;
|
|
11
|
-
environment:
|
|
11
|
+
environment: LspEnvironment;
|
|
12
12
|
params?: Record<string, string | undefined>;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export type
|
|
16
|
-
context:
|
|
15
|
+
export type LixServerProtocolHandlerRoute = (
|
|
16
|
+
context: LixServerProtocolHandlerContext
|
|
17
17
|
) => Promise<Response>;
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -30,10 +30,10 @@ export type LixServerApiHandlerRoute = (
|
|
|
30
30
|
* // objects will need to be mapped.
|
|
31
31
|
* const app = new Hono();
|
|
32
32
|
*
|
|
33
|
-
* const
|
|
33
|
+
* const lspHandler = createServerProtocolHandler({ storage });
|
|
34
34
|
*
|
|
35
35
|
* app.use('/lsp/*', async (req) => {
|
|
36
|
-
* await
|
|
36
|
+
* await lspHandler(req);
|
|
37
37
|
* });
|
|
38
38
|
* ```
|
|
39
39
|
*
|
|
@@ -41,35 +41,35 @@ export type LixServerApiHandlerRoute = (
|
|
|
41
41
|
* Testing the handler.
|
|
42
42
|
*
|
|
43
43
|
* ```ts
|
|
44
|
-
* const
|
|
44
|
+
* const lspHandler = createServerProtocolHandler({ storage });
|
|
45
45
|
* const request = new Request('/lsp/new', {
|
|
46
46
|
* method: 'POST',
|
|
47
47
|
* body: new Blob(['...']),
|
|
48
48
|
* });
|
|
49
49
|
*
|
|
50
|
-
* const response = await
|
|
50
|
+
* const response = await lspHandler(request);
|
|
51
51
|
*
|
|
52
52
|
* expect(response).to(...);
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
export async function
|
|
56
|
-
environment:
|
|
57
|
-
}): Promise<
|
|
55
|
+
export async function createServerProtocolHandler(args: {
|
|
56
|
+
environment: LspEnvironment;
|
|
57
|
+
}): Promise<LixServerProtocolHandler> {
|
|
58
58
|
const context = { environment: args.environment };
|
|
59
59
|
|
|
60
60
|
return async (request) => {
|
|
61
61
|
try {
|
|
62
62
|
const path = new URL(request.url).pathname;
|
|
63
|
-
if (path === "/
|
|
63
|
+
if (path === "/lsp/get-v1") {
|
|
64
64
|
return await getRouteV1({ ...context, request });
|
|
65
65
|
}
|
|
66
|
-
if (path === "/
|
|
66
|
+
if (path === "/lsp/new-v1") {
|
|
67
67
|
return await newRouteV1({ ...context, request });
|
|
68
68
|
}
|
|
69
|
-
if (path === "/
|
|
69
|
+
if (path === "/lsp/push-v1") {
|
|
70
70
|
return await pushRouteV1({ ...context, request });
|
|
71
71
|
}
|
|
72
|
-
if (path === "/
|
|
72
|
+
if (path === "/lsp/pull-v1") {
|
|
73
73
|
return await pullRouteV1({ ...context, request });
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -82,3 +82,7 @@ export async function createServerApiHandler(args: {
|
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
// Keep old name for backward compatibility
|
|
87
|
+
export const createServerApiHandler: typeof createServerProtocolHandler =
|
|
88
|
+
createServerProtocolHandler;
|
|
@@ -3,14 +3,14 @@ import { closeLix } from "../../lix/close-lix.js";
|
|
|
3
3
|
import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
|
|
4
4
|
import type { Lix } from "../../lix/open-lix.js";
|
|
5
5
|
import { toBlob } from "../../lix/to-blob.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { LspEnvironment } from "./environment.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Create an in-memory storage.
|
|
10
10
|
*
|
|
11
11
|
* Great for testing or quick prototyping.
|
|
12
12
|
*/
|
|
13
|
-
export const
|
|
13
|
+
export const createLspInMemoryEnvironment = (): LspEnvironment => {
|
|
14
14
|
const store = new Map<string, Blob>();
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -113,3 +113,7 @@ export const createLsaInMemoryEnvironment = (): LsaEnvironment => {
|
|
|
113
113
|
},
|
|
114
114
|
};
|
|
115
115
|
};
|
|
116
|
+
|
|
117
|
+
// For backward compatibility
|
|
118
|
+
export const createLsaInMemoryEnvironment: typeof createLspInMemoryEnvironment =
|
|
119
|
+
createLspInMemoryEnvironment;
|
|
@@ -3,7 +3,7 @@ import type { Lix } from "../../lix/open-lix.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Key value storage interface.
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
6
|
+
export type LspEnvironment = {
|
|
7
7
|
get(key: string): Promise<Blob | undefined>;
|
|
8
8
|
set(key: string, value: Blob): Promise<void>;
|
|
9
9
|
has(key: string): Promise<boolean>;
|
|
@@ -41,3 +41,6 @@ export type LsaEnvironment = {
|
|
|
41
41
|
*/
|
|
42
42
|
closeLix(args: { id: string; connectionId: string }): Promise<void>;
|
|
43
43
|
};
|
|
44
|
+
|
|
45
|
+
// For backward compatibility
|
|
46
|
+
export type LsaEnvironment = LspEnvironment;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { test, expect } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { createServerProtocolHandler } from "../create-server-protocol-handler.js";
|
|
3
3
|
import { newLixFile } from "../../lix/new-lix.js";
|
|
4
4
|
import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createLspInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
|
|
6
6
|
import { toBlob } from "../../lix/to-blob.js";
|
|
7
7
|
|
|
8
8
|
test("it should fetch the lix file from the server", async () => {
|
|
@@ -20,20 +20,20 @@ test("it should fetch the lix file from the server", async () => {
|
|
|
20
20
|
.values({ key: "mock_key", value: "hello world" })
|
|
21
21
|
.execute();
|
|
22
22
|
|
|
23
|
-
const environment =
|
|
24
|
-
const
|
|
23
|
+
const environment = createLspInMemoryEnvironment();
|
|
24
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
25
25
|
|
|
26
26
|
// Store the lix file
|
|
27
|
-
await
|
|
28
|
-
new Request("http://localhost:3000/
|
|
27
|
+
await lspHandler(
|
|
28
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
29
29
|
method: "POST",
|
|
30
30
|
body: await toBlob({ lix }),
|
|
31
31
|
})
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
// Fetch the lix file
|
|
35
|
-
const response = await
|
|
36
|
-
new Request("http://localhost:3000/
|
|
35
|
+
const response = await lspHandler(
|
|
36
|
+
new Request("http://localhost:3000/lsp/get-v1", {
|
|
37
37
|
method: "POST",
|
|
38
38
|
headers: {
|
|
39
39
|
"Content-Type": "application/json",
|
|
@@ -64,12 +64,12 @@ test("it should fetch the lix file from the server", async () => {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
test("it should return 404 if the lix file does not exist", async () => {
|
|
67
|
-
const environment =
|
|
67
|
+
const environment = createLspInMemoryEnvironment();
|
|
68
68
|
|
|
69
|
-
const
|
|
69
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
70
70
|
|
|
71
|
-
const response = await
|
|
72
|
-
new Request("http://localhost:3000/
|
|
71
|
+
const response = await lspHandler(
|
|
72
|
+
new Request("http://localhost:3000/lsp/get-v1", {
|
|
73
73
|
method: "POST",
|
|
74
74
|
headers: {
|
|
75
75
|
"Content-Type": "application/json",
|
|
@@ -85,11 +85,11 @@ test("it should return 404 if the lix file does not exist", async () => {
|
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
test("it should return 400 for a request without lix_id", async () => {
|
|
88
|
-
const environment =
|
|
89
|
-
const
|
|
88
|
+
const environment = createLspInMemoryEnvironment();
|
|
89
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
90
90
|
|
|
91
|
-
const response = await
|
|
92
|
-
new Request("http://localhost:3000/
|
|
91
|
+
const response = await lspHandler(
|
|
92
|
+
new Request("http://localhost:3000/lsp/get-v1", {
|
|
93
93
|
method: "POST",
|
|
94
94
|
headers: {
|
|
95
95
|
"Content-Type": "application/json",
|
|
@@ -105,8 +105,8 @@ test("it should return 400 for a request without lix_id", async () => {
|
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
test("lix_sync is set to true", async () => {
|
|
108
|
-
const environment =
|
|
109
|
-
const
|
|
108
|
+
const environment = createLspInMemoryEnvironment();
|
|
109
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
110
110
|
|
|
111
111
|
const lix = await openLixInMemory({
|
|
112
112
|
blob: await newLixFile(),
|
|
@@ -114,8 +114,8 @@ test("lix_sync is set to true", async () => {
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
// Store the lix file
|
|
117
|
-
const response0 = await
|
|
118
|
-
new Request("http://localhost:3000/
|
|
117
|
+
const response0 = await lspHandler(
|
|
118
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
119
119
|
method: "POST",
|
|
120
120
|
body: await toBlob({ lix }),
|
|
121
121
|
})
|
|
@@ -123,8 +123,8 @@ test("lix_sync is set to true", async () => {
|
|
|
123
123
|
|
|
124
124
|
const id = (await response0.json()).id;
|
|
125
125
|
|
|
126
|
-
const response1 = await
|
|
127
|
-
new Request("http://localhost:3000/
|
|
126
|
+
const response1 = await lspHandler(
|
|
127
|
+
new Request("http://localhost:3000/lsp/get-v1", {
|
|
128
128
|
method: "POST",
|
|
129
129
|
headers: {
|
|
130
130
|
"Content-Type": "application/json",
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
createInMemoryDatabase,
|
|
4
4
|
importDatabase,
|
|
5
5
|
} from "sqlite-wasm-kysely";
|
|
6
|
-
import type {
|
|
6
|
+
import type { LixServerProtocolHandlerRoute } from "../create-server-protocol-handler.js";
|
|
7
7
|
|
|
8
|
-
export const route:
|
|
8
|
+
export const route: LixServerProtocolHandlerRoute = async (context) => {
|
|
9
9
|
const { lix_id } = await context.request.json();
|
|
10
10
|
|
|
11
11
|
if (!lix_id) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { test, expect } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { createServerProtocolHandler } from "../create-server-protocol-handler.js";
|
|
3
3
|
import { newLixFile } from "../../lix/new-lix.js";
|
|
4
4
|
import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createLspInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
|
|
6
6
|
import { toBlob } from "../../lix/to-blob.js";
|
|
7
7
|
|
|
8
8
|
test("it should store the lix file", async () => {
|
|
@@ -16,12 +16,12 @@ test("it should store the lix file", async () => {
|
|
|
16
16
|
.selectAll()
|
|
17
17
|
.executeTakeFirstOrThrow();
|
|
18
18
|
|
|
19
|
-
const environment =
|
|
19
|
+
const environment = createLspInMemoryEnvironment();
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
22
22
|
|
|
23
|
-
const response = await
|
|
24
|
-
new Request("http://localhost:3000/
|
|
23
|
+
const response = await lspHandler(
|
|
24
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
25
25
|
method: "POST",
|
|
26
26
|
body: await toBlob({ lix: initLix }),
|
|
27
27
|
})
|
|
@@ -62,12 +62,12 @@ test.skip("it should return 400 for an invalid lix file", async () => {
|
|
|
62
62
|
|
|
63
63
|
console.error = () => {};
|
|
64
64
|
|
|
65
|
-
const environment =
|
|
65
|
+
const environment = createLspInMemoryEnvironment();
|
|
66
66
|
|
|
67
|
-
const
|
|
67
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
68
68
|
|
|
69
|
-
const response = await
|
|
70
|
-
new Request("http://localhost:3000/
|
|
69
|
+
const response = await lspHandler(
|
|
70
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
71
71
|
method: "POST",
|
|
72
72
|
body: invalidLixFile,
|
|
73
73
|
})
|
|
@@ -79,21 +79,21 @@ test.skip("it should return 400 for an invalid lix file", async () => {
|
|
|
79
79
|
test("it should return 409 if the lix file already exists", async () => {
|
|
80
80
|
const lixFile = await newLixFile();
|
|
81
81
|
|
|
82
|
-
const environment =
|
|
82
|
+
const environment = createLspInMemoryEnvironment();
|
|
83
83
|
|
|
84
|
-
const
|
|
84
|
+
const lspHandler = await createServerProtocolHandler({ environment });
|
|
85
85
|
|
|
86
86
|
// First request to store the lix file
|
|
87
|
-
await
|
|
88
|
-
new Request("http://localhost:3000/
|
|
87
|
+
await lspHandler(
|
|
88
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
89
89
|
method: "POST",
|
|
90
90
|
body: lixFile,
|
|
91
91
|
})
|
|
92
92
|
);
|
|
93
93
|
|
|
94
94
|
// Second request to store the same lix file
|
|
95
|
-
const response = await
|
|
96
|
-
new Request("http://localhost:3000/
|
|
95
|
+
const response = await lspHandler(
|
|
96
|
+
new Request("http://localhost:3000/lsp/new-v1", {
|
|
97
97
|
method: "POST",
|
|
98
98
|
body: lixFile,
|
|
99
99
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
|
|
2
2
|
import type { Lix } from "../../lix/open-lix.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { LixServerProtocolHandlerRoute } from "../create-server-protocol-handler.js";
|
|
4
4
|
|
|
5
|
-
export const route:
|
|
5
|
+
export const route: LixServerProtocolHandlerRoute = async (context) => {
|
|
6
6
|
const blob = await context.request.blob();
|
|
7
7
|
|
|
8
8
|
let lix: Lix;
|
|
@@ -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
|
|