@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.
Files changed (141) hide show
  1. package/dist/change-set/create-change-set.d.ts +13 -1
  2. package/dist/change-set/create-change-set.d.ts.map +1 -1
  3. package/dist/change-set/create-change-set.js +30 -7
  4. package/dist/change-set/create-change-set.js.map +1 -1
  5. package/dist/change-set/create-change-set.test.js +50 -0
  6. package/dist/change-set/create-change-set.test.js.map +1 -1
  7. package/dist/database/init-db.test.js.map +1 -1
  8. package/dist/database/nano-id.js +1 -1
  9. package/dist/database/nano-id.js.map +1 -1
  10. package/dist/file-queue/file-handlers.d.ts.map +1 -1
  11. package/dist/file-queue/file-handlers.js.map +1 -1
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/server-protocol-handler/create-server-protocol-handler.d.ts +49 -0
  17. package/dist/server-protocol-handler/create-server-protocol-handler.d.ts.map +1 -0
  18. package/dist/{server-api-handler/create-server-api-handler.js → server-protocol-handler/create-server-protocol-handler.js} +12 -10
  19. package/dist/server-protocol-handler/create-server-protocol-handler.js.map +1 -0
  20. package/dist/server-protocol-handler/environment/create-in-memory-environment.d.ts +9 -0
  21. package/dist/server-protocol-handler/environment/create-in-memory-environment.d.ts.map +1 -0
  22. package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.js +3 -1
  23. package/dist/server-protocol-handler/environment/create-in-memory-environment.js.map +1 -0
  24. package/dist/server-protocol-handler/environment/create-in-memory-environment.test.d.ts.map +1 -0
  25. package/dist/server-protocol-handler/environment/create-in-memory-environment.test.js.map +1 -0
  26. package/dist/{server-api-handler → server-protocol-handler}/environment/environment.d.ts +2 -1
  27. package/dist/server-protocol-handler/environment/environment.d.ts.map +1 -0
  28. package/dist/server-protocol-handler/environment/environment.js.map +1 -0
  29. package/dist/server-protocol-handler/index.d.ts +3 -0
  30. package/dist/server-protocol-handler/index.d.ts.map +1 -0
  31. package/dist/server-protocol-handler/index.js +3 -0
  32. package/dist/server-protocol-handler/index.js.map +1 -0
  33. package/dist/server-protocol-handler/routes/get-v1.d.ts +3 -0
  34. package/dist/server-protocol-handler/routes/get-v1.d.ts.map +1 -0
  35. package/dist/server-protocol-handler/routes/get-v1.js.map +1 -0
  36. package/dist/server-protocol-handler/routes/get-v1.test.d.ts.map +1 -0
  37. package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.test.js +16 -16
  38. package/dist/server-protocol-handler/routes/get-v1.test.js.map +1 -0
  39. package/dist/server-protocol-handler/routes/new-v1.d.ts +3 -0
  40. package/dist/server-protocol-handler/routes/new-v1.d.ts.map +1 -0
  41. package/dist/server-protocol-handler/routes/new-v1.js.map +1 -0
  42. package/dist/server-protocol-handler/routes/new-v1.test.d.ts.map +1 -0
  43. package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.test.js +12 -12
  44. package/dist/server-protocol-handler/routes/new-v1.test.js.map +1 -0
  45. package/dist/server-protocol-handler/routes/pull-v1.d.ts +3 -0
  46. package/dist/server-protocol-handler/routes/pull-v1.d.ts.map +1 -0
  47. package/dist/server-protocol-handler/routes/pull-v1.js.map +1 -0
  48. package/dist/server-protocol-handler/routes/pull-v1.test.d.ts.map +1 -0
  49. package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.js +12 -13
  50. package/dist/server-protocol-handler/routes/pull-v1.test.js.map +1 -0
  51. package/dist/server-protocol-handler/routes/push-v1.d.ts +3 -0
  52. package/dist/server-protocol-handler/routes/push-v1.d.ts.map +1 -0
  53. package/dist/server-protocol-handler/routes/push-v1.js.map +1 -0
  54. package/dist/server-protocol-handler/routes/push-v1.test.d.ts.map +1 -0
  55. package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.test.js +12 -13
  56. package/dist/server-protocol-handler/routes/push-v1.test.js.map +1 -0
  57. package/dist/services/env-variables/index.js +1 -1
  58. package/dist/sync/pull-from-server.js +1 -2
  59. package/dist/sync/pull-from-server.js.map +1 -1
  60. package/dist/sync/pull-from-server.test.js +27 -27
  61. package/dist/sync/pull-from-server.test.js.map +1 -1
  62. package/dist/sync/push-to-server.js +1 -1
  63. package/dist/sync/push-to-server.test.js +18 -18
  64. package/dist/sync/push-to-server.test.js.map +1 -1
  65. package/dist/sync/sync-process.js +1 -1
  66. package/dist/sync/sync-process.js.map +1 -1
  67. package/dist/sync/sync-process.test.js +13 -13
  68. package/dist/sync/sync-process.test.js.map +1 -1
  69. package/package.json +4 -3
  70. package/src/change-set/create-change-set.test.ts +64 -0
  71. package/src/change-set/create-change-set.ts +38 -10
  72. package/src/database/init-db.test.ts +1 -3
  73. package/src/database/nano-id.test.ts +1 -1
  74. package/src/database/nano-id.ts +13 -13
  75. package/src/file-queue/file-handlers.ts +0 -1
  76. package/src/index.ts +1 -1
  77. package/src/{server-api-handler/create-server-api-handler.ts → server-protocol-handler/create-server-protocol-handler.ts} +22 -18
  78. package/src/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.ts +6 -2
  79. package/src/{server-api-handler → server-protocol-handler}/environment/environment.ts +4 -1
  80. package/src/server-protocol-handler/index.ts +5 -0
  81. package/src/{server-api-handler → server-protocol-handler}/routes/get-v1.test.ts +22 -22
  82. package/src/{server-api-handler → server-protocol-handler}/routes/get-v1.ts +2 -2
  83. package/src/{server-api-handler → server-protocol-handler}/routes/new-v1.test.ts +16 -16
  84. package/src/{server-api-handler → server-protocol-handler}/routes/new-v1.ts +2 -2
  85. package/src/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.ts +16 -16
  86. package/src/{server-api-handler → server-protocol-handler}/routes/pull-v1.ts +6 -5
  87. package/src/{server-api-handler → server-protocol-handler}/routes/push-v1.test.ts +18 -18
  88. package/src/{server-api-handler → server-protocol-handler}/routes/push-v1.ts +6 -5
  89. package/src/sync/pull-from-server.test.ts +32 -32
  90. package/src/sync/pull-from-server.ts +5 -5
  91. package/src/sync/push-to-server.test.ts +22 -22
  92. package/src/sync/push-to-server.ts +3 -3
  93. package/src/sync/sync-process.test.ts +18 -18
  94. package/src/sync/sync-process.ts +1 -1
  95. package/dist/server-api-handler/create-server-api-handler.d.ts +0 -48
  96. package/dist/server-api-handler/create-server-api-handler.d.ts.map +0 -1
  97. package/dist/server-api-handler/create-server-api-handler.js.map +0 -1
  98. package/dist/server-api-handler/environment/create-in-memory-environment.d.ts +0 -8
  99. package/dist/server-api-handler/environment/create-in-memory-environment.d.ts.map +0 -1
  100. package/dist/server-api-handler/environment/create-in-memory-environment.js.map +0 -1
  101. package/dist/server-api-handler/environment/create-in-memory-environment.test.d.ts.map +0 -1
  102. package/dist/server-api-handler/environment/create-in-memory-environment.test.js.map +0 -1
  103. package/dist/server-api-handler/environment/environment.d.ts.map +0 -1
  104. package/dist/server-api-handler/environment/environment.js.map +0 -1
  105. package/dist/server-api-handler/index.d.ts +0 -3
  106. package/dist/server-api-handler/index.d.ts.map +0 -1
  107. package/dist/server-api-handler/index.js +0 -3
  108. package/dist/server-api-handler/index.js.map +0 -1
  109. package/dist/server-api-handler/routes/get-v1.d.ts +0 -3
  110. package/dist/server-api-handler/routes/get-v1.d.ts.map +0 -1
  111. package/dist/server-api-handler/routes/get-v1.js.map +0 -1
  112. package/dist/server-api-handler/routes/get-v1.test.d.ts.map +0 -1
  113. package/dist/server-api-handler/routes/get-v1.test.js.map +0 -1
  114. package/dist/server-api-handler/routes/new-v1.d.ts +0 -3
  115. package/dist/server-api-handler/routes/new-v1.d.ts.map +0 -1
  116. package/dist/server-api-handler/routes/new-v1.js.map +0 -1
  117. package/dist/server-api-handler/routes/new-v1.test.d.ts.map +0 -1
  118. package/dist/server-api-handler/routes/new-v1.test.js.map +0 -1
  119. package/dist/server-api-handler/routes/pull-v1.d.ts +0 -3
  120. package/dist/server-api-handler/routes/pull-v1.d.ts.map +0 -1
  121. package/dist/server-api-handler/routes/pull-v1.js.map +0 -1
  122. package/dist/server-api-handler/routes/pull-v1.test.d.ts.map +0 -1
  123. package/dist/server-api-handler/routes/pull-v1.test.js.map +0 -1
  124. package/dist/server-api-handler/routes/push-v1.d.ts +0 -3
  125. package/dist/server-api-handler/routes/push-v1.d.ts.map +0 -1
  126. package/dist/server-api-handler/routes/push-v1.js.map +0 -1
  127. package/dist/server-api-handler/routes/push-v1.test.d.ts.map +0 -1
  128. package/dist/server-api-handler/routes/push-v1.test.js.map +0 -1
  129. package/src/server-api-handler/index.ts +0 -5
  130. /package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.test.d.ts +0 -0
  131. /package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.test.js +0 -0
  132. /package/dist/{server-api-handler → server-protocol-handler}/environment/environment.js +0 -0
  133. /package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.js +0 -0
  134. /package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.test.d.ts +0 -0
  135. /package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.js +0 -0
  136. /package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.test.d.ts +0 -0
  137. /package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.js +0 -0
  138. /package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.d.ts +0 -0
  139. /package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.js +0 -0
  140. /package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.test.d.ts +0 -0
  141. /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 { LsaEnvironment } from "./environment/environment.js";
5
+ import type { LspEnvironment } from "./environment/environment.js";
6
6
 
7
- export type LixServerApiHandler = (request: Request) => Promise<Response>;
8
-
9
- export type LixServerApiHandlerContext = {
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: LsaEnvironment;
11
+ environment: LspEnvironment;
12
12
  params?: Record<string, string | undefined>;
13
13
  };
14
14
 
15
- export type LixServerApiHandlerRoute = (
16
- context: LixServerApiHandlerContext
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 lsaHandler = createServerApiHandler({ storage });
33
+ * const lspHandler = createServerProtocolHandler({ storage });
34
34
  *
35
35
  * app.use('/lsp/*', async (req) => {
36
- * await lsaHandler(req);
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 lsaHandler = createServerApiHandler({ storage });
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 lsaHandler(request);
50
+ * const response = await lspHandler(request);
51
51
  *
52
52
  * expect(response).to(...);
53
53
  * ```
54
54
  */
55
- export async function createServerApiHandler(args: {
56
- environment: LsaEnvironment;
57
- }): Promise<LixServerApiHandler> {
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 === "/lsa/get-v1") {
63
+ if (path === "/lsp/get-v1") {
64
64
  return await getRouteV1({ ...context, request });
65
65
  }
66
- if (path === "/lsa/new-v1") {
66
+ if (path === "/lsp/new-v1") {
67
67
  return await newRouteV1({ ...context, request });
68
68
  }
69
- if (path === "/lsa/push-v1") {
69
+ if (path === "/lsp/push-v1") {
70
70
  return await pushRouteV1({ ...context, request });
71
71
  }
72
- if (path === "/lsa/pull-v1") {
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 { LsaEnvironment } from "./environment.js";
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 createLsaInMemoryEnvironment = (): LsaEnvironment => {
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 LsaEnvironment = {
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;
@@ -0,0 +1,5 @@
1
+ export {
2
+ createServerProtocolHandler,
3
+ type LixServerProtocolHandlerContext,
4
+ } from "./create-server-protocol-handler.js";
5
+ export { createLspInMemoryEnvironment } from "./environment/create-in-memory-environment.js";
@@ -1,8 +1,8 @@
1
1
  import { test, expect } from "vitest";
2
- import { createServerApiHandler } from "../create-server-api-handler.js";
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 { createLsaInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
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 = createLsaInMemoryEnvironment();
24
- const lsaHandler = await createServerApiHandler({ environment });
23
+ const environment = createLspInMemoryEnvironment();
24
+ const lspHandler = await createServerProtocolHandler({ environment });
25
25
 
26
26
  // Store the lix file
27
- await lsaHandler(
28
- new Request("http://localhost:3000/lsa/new-v1", {
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 lsaHandler(
36
- new Request("http://localhost:3000/lsa/get-v1", {
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 = createLsaInMemoryEnvironment();
67
+ const environment = createLspInMemoryEnvironment();
68
68
 
69
- const lsaHandler = await createServerApiHandler({ environment });
69
+ const lspHandler = await createServerProtocolHandler({ environment });
70
70
 
71
- const response = await lsaHandler(
72
- new Request("http://localhost:3000/lsa/get-v1", {
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 = createLsaInMemoryEnvironment();
89
- const lsaHandler = await createServerApiHandler({ environment });
88
+ const environment = createLspInMemoryEnvironment();
89
+ const lspHandler = await createServerProtocolHandler({ environment });
90
90
 
91
- const response = await lsaHandler(
92
- new Request("http://localhost:3000/lsa/get-v1", {
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 = createLsaInMemoryEnvironment();
109
- const lsaHandler = await createServerApiHandler({ environment });
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 lsaHandler(
118
- new Request("http://localhost:3000/lsa/new-v1", {
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 lsaHandler(
127
- new Request("http://localhost:3000/lsa/get-v1", {
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 { LixServerApiHandlerRoute } from "../create-server-api-handler.js";
6
+ import type { LixServerProtocolHandlerRoute } from "../create-server-protocol-handler.js";
7
7
 
8
- export const route: LixServerApiHandlerRoute = async (context) => {
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 { createServerApiHandler } from "../create-server-api-handler.js";
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 { createLsaInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
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 = createLsaInMemoryEnvironment();
19
+ const environment = createLspInMemoryEnvironment();
20
20
 
21
- const lsaHandler = await createServerApiHandler({ environment });
21
+ const lspHandler = await createServerProtocolHandler({ environment });
22
22
 
23
- const response = await lsaHandler(
24
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
65
+ const environment = createLspInMemoryEnvironment();
66
66
 
67
- const lsaHandler = await createServerApiHandler({ environment });
67
+ const lspHandler = await createServerProtocolHandler({ environment });
68
68
 
69
- const response = await lsaHandler(
70
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
82
+ const environment = createLspInMemoryEnvironment();
83
83
 
84
- const lsaHandler = await createServerApiHandler({ environment });
84
+ const lspHandler = await createServerProtocolHandler({ environment });
85
85
 
86
86
  // First request to store the lix file
87
- await lsaHandler(
88
- new Request("http://localhost:3000/lsa/new-v1", {
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 lsaHandler(
96
- new Request("http://localhost:3000/lsa/new-v1", {
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 { LixServerApiHandlerRoute } from "../create-server-api-handler.js";
3
+ import type { LixServerProtocolHandlerRoute } from "../create-server-protocol-handler.js";
4
4
 
5
- export const route: LixServerApiHandlerRoute = async (context) => {
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 LixServerApi from "@lix-js/server-api-schema";
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-api-handler.js";
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 { createLsaInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
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
- LixServerApi.paths["/lsa/pull-v1"]["post"]["requestBody"]["content"]["application/json"];
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 = createLsaInMemoryEnvironment();
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/lsa/pull-v1", {
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 LixServerApi.paths["/lsa/pull-v1"]["post"]["responses"]["200"]["content"]["application/json"];
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 = createLsaInMemoryEnvironment();
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/lsa/pull-v1", {
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 LixServerApi.paths["/lsa/pull-v1"]["post"]["responses"]["200"]["content"]["application/json"];
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 = createLsaInMemoryEnvironment();
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/lsa/pull-v1", {
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 = createLsaInMemoryEnvironment();
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/lsa/pull-v1", {
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 = createLsaInMemoryEnvironment();
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/lsa/pull-v1", {
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 LixServerApi from "@lix-js/server-api-schema";
2
- import type { LixServerApiHandlerRoute } from "../create-server-api-handler.js";
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
- LixServerApi.paths["/lsa/pull-v1"]["post"]["requestBody"]["content"]["application/json"];
6
+ LixServerProtocol.paths["/lsp/pull-v1"]["post"]["requestBody"]["content"]["application/json"];
7
7
 
8
- type ResponseBody = LixServerApi.paths["/lsa/pull-v1"]["post"]["responses"];
8
+ type ResponseBody =
9
+ LixServerProtocol.paths["/lsp/pull-v1"]["post"]["responses"];
9
10
 
10
- export const route: LixServerApiHandlerRoute = async (context) => {
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 LixServerApi from "@lix-js/server-api-schema";
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-api-handler.js";
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 { createLsaInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
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 = createLsaInMemoryEnvironment();
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/lsa/push-v1", {
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 LixServerApi.paths["/lsa/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
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 = createLsaInMemoryEnvironment();
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/lsa/push-v1", {
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 LixServerApi.paths["/lsa/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
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 = createLsaInMemoryEnvironment();
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/lsa/push-v1", {
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 LixServerApi.paths["/lsa/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
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 = createLsaInMemoryEnvironment();
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/lsa/push-v1", {
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 LixServerApi.paths["/lsa/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
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 = createLsaInMemoryEnvironment();
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/lsa/push-v1", {
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 LixServerApi.paths["/lsa/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
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 LixServerApi from "@lix-js/server-api-schema";
2
- import type { LixServerApiHandlerRoute } from "../create-server-api-handler.js";
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
- LixServerApi.paths["/lsa/push-v1"]["post"]["requestBody"]["content"]["application/json"];
10
+ LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"];
11
11
 
12
- type ResponseBody = LixServerApi.paths["/lsa/push-v1"]["post"]["responses"];
12
+ type ResponseBody =
13
+ LixServerProtocol.paths["/lsp/push-v1"]["post"]["responses"];
13
14
 
14
- export const route: LixServerApiHandlerRoute = async (context) => {
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