@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.
Files changed (132) 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/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/server-protocol-handler/create-server-protocol-handler.d.ts +49 -0
  12. package/dist/server-protocol-handler/create-server-protocol-handler.d.ts.map +1 -0
  13. package/dist/{server-api-handler/create-server-api-handler.js → server-protocol-handler/create-server-protocol-handler.js} +12 -10
  14. package/dist/server-protocol-handler/create-server-protocol-handler.js.map +1 -0
  15. package/dist/server-protocol-handler/environment/create-in-memory-environment.d.ts +9 -0
  16. package/dist/server-protocol-handler/environment/create-in-memory-environment.d.ts.map +1 -0
  17. package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.js +3 -1
  18. package/dist/server-protocol-handler/environment/create-in-memory-environment.js.map +1 -0
  19. package/dist/server-protocol-handler/environment/create-in-memory-environment.test.d.ts.map +1 -0
  20. package/dist/server-protocol-handler/environment/create-in-memory-environment.test.js.map +1 -0
  21. package/dist/{server-api-handler → server-protocol-handler}/environment/environment.d.ts +2 -1
  22. package/dist/server-protocol-handler/environment/environment.d.ts.map +1 -0
  23. package/dist/server-protocol-handler/environment/environment.js.map +1 -0
  24. package/dist/server-protocol-handler/index.d.ts +3 -0
  25. package/dist/server-protocol-handler/index.d.ts.map +1 -0
  26. package/dist/server-protocol-handler/index.js +3 -0
  27. package/dist/server-protocol-handler/index.js.map +1 -0
  28. package/dist/server-protocol-handler/routes/get-v1.d.ts +3 -0
  29. package/dist/server-protocol-handler/routes/get-v1.d.ts.map +1 -0
  30. package/dist/server-protocol-handler/routes/get-v1.js.map +1 -0
  31. package/dist/server-protocol-handler/routes/get-v1.test.d.ts.map +1 -0
  32. package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.test.js +16 -16
  33. package/dist/server-protocol-handler/routes/get-v1.test.js.map +1 -0
  34. package/dist/server-protocol-handler/routes/new-v1.d.ts +3 -0
  35. package/dist/server-protocol-handler/routes/new-v1.d.ts.map +1 -0
  36. package/dist/server-protocol-handler/routes/new-v1.js.map +1 -0
  37. package/dist/server-protocol-handler/routes/new-v1.test.d.ts.map +1 -0
  38. package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.test.js +12 -12
  39. package/dist/server-protocol-handler/routes/new-v1.test.js.map +1 -0
  40. package/dist/server-protocol-handler/routes/pull-v1.d.ts +3 -0
  41. package/dist/server-protocol-handler/routes/pull-v1.d.ts.map +1 -0
  42. package/dist/server-protocol-handler/routes/pull-v1.js.map +1 -0
  43. package/dist/server-protocol-handler/routes/pull-v1.test.d.ts.map +1 -0
  44. package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.js +12 -13
  45. package/dist/server-protocol-handler/routes/pull-v1.test.js.map +1 -0
  46. package/dist/server-protocol-handler/routes/push-v1.d.ts +3 -0
  47. package/dist/server-protocol-handler/routes/push-v1.d.ts.map +1 -0
  48. package/dist/server-protocol-handler/routes/push-v1.js.map +1 -0
  49. package/dist/server-protocol-handler/routes/push-v1.test.d.ts.map +1 -0
  50. package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.test.js +12 -13
  51. package/dist/server-protocol-handler/routes/push-v1.test.js.map +1 -0
  52. package/dist/services/env-variables/index.js +1 -1
  53. package/dist/sync/pull-from-server.js +1 -2
  54. package/dist/sync/pull-from-server.js.map +1 -1
  55. package/dist/sync/pull-from-server.test.js +27 -27
  56. package/dist/sync/pull-from-server.test.js.map +1 -1
  57. package/dist/sync/push-to-server.js +1 -1
  58. package/dist/sync/push-to-server.test.js +18 -18
  59. package/dist/sync/push-to-server.test.js.map +1 -1
  60. package/dist/sync/sync-process.js +1 -1
  61. package/dist/sync/sync-process.js.map +1 -1
  62. package/dist/sync/sync-process.test.js +13 -13
  63. package/dist/sync/sync-process.test.js.map +1 -1
  64. package/package.json +3 -3
  65. package/src/change-set/create-change-set.test.ts +64 -0
  66. package/src/change-set/create-change-set.ts +38 -10
  67. package/src/index.ts +1 -1
  68. package/src/{server-api-handler/create-server-api-handler.ts → server-protocol-handler/create-server-protocol-handler.ts} +22 -18
  69. package/src/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.ts +6 -2
  70. package/src/{server-api-handler → server-protocol-handler}/environment/environment.ts +4 -1
  71. package/src/server-protocol-handler/index.ts +5 -0
  72. package/src/{server-api-handler → server-protocol-handler}/routes/get-v1.test.ts +22 -22
  73. package/src/{server-api-handler → server-protocol-handler}/routes/get-v1.ts +2 -2
  74. package/src/{server-api-handler → server-protocol-handler}/routes/new-v1.test.ts +16 -16
  75. package/src/{server-api-handler → server-protocol-handler}/routes/new-v1.ts +2 -2
  76. package/src/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.ts +16 -16
  77. package/src/{server-api-handler → server-protocol-handler}/routes/pull-v1.ts +6 -5
  78. package/src/{server-api-handler → server-protocol-handler}/routes/push-v1.test.ts +18 -18
  79. package/src/{server-api-handler → server-protocol-handler}/routes/push-v1.ts +6 -5
  80. package/src/sync/pull-from-server.test.ts +32 -32
  81. package/src/sync/pull-from-server.ts +5 -5
  82. package/src/sync/push-to-server.test.ts +22 -22
  83. package/src/sync/push-to-server.ts +3 -3
  84. package/src/sync/sync-process.test.ts +18 -18
  85. package/src/sync/sync-process.ts +1 -1
  86. package/dist/server-api-handler/create-server-api-handler.d.ts +0 -48
  87. package/dist/server-api-handler/create-server-api-handler.d.ts.map +0 -1
  88. package/dist/server-api-handler/create-server-api-handler.js.map +0 -1
  89. package/dist/server-api-handler/environment/create-in-memory-environment.d.ts +0 -8
  90. package/dist/server-api-handler/environment/create-in-memory-environment.d.ts.map +0 -1
  91. package/dist/server-api-handler/environment/create-in-memory-environment.js.map +0 -1
  92. package/dist/server-api-handler/environment/create-in-memory-environment.test.d.ts.map +0 -1
  93. package/dist/server-api-handler/environment/create-in-memory-environment.test.js.map +0 -1
  94. package/dist/server-api-handler/environment/environment.d.ts.map +0 -1
  95. package/dist/server-api-handler/environment/environment.js.map +0 -1
  96. package/dist/server-api-handler/index.d.ts +0 -3
  97. package/dist/server-api-handler/index.d.ts.map +0 -1
  98. package/dist/server-api-handler/index.js +0 -3
  99. package/dist/server-api-handler/index.js.map +0 -1
  100. package/dist/server-api-handler/routes/get-v1.d.ts +0 -3
  101. package/dist/server-api-handler/routes/get-v1.d.ts.map +0 -1
  102. package/dist/server-api-handler/routes/get-v1.js.map +0 -1
  103. package/dist/server-api-handler/routes/get-v1.test.d.ts.map +0 -1
  104. package/dist/server-api-handler/routes/get-v1.test.js.map +0 -1
  105. package/dist/server-api-handler/routes/new-v1.d.ts +0 -3
  106. package/dist/server-api-handler/routes/new-v1.d.ts.map +0 -1
  107. package/dist/server-api-handler/routes/new-v1.js.map +0 -1
  108. package/dist/server-api-handler/routes/new-v1.test.d.ts.map +0 -1
  109. package/dist/server-api-handler/routes/new-v1.test.js.map +0 -1
  110. package/dist/server-api-handler/routes/pull-v1.d.ts +0 -3
  111. package/dist/server-api-handler/routes/pull-v1.d.ts.map +0 -1
  112. package/dist/server-api-handler/routes/pull-v1.js.map +0 -1
  113. package/dist/server-api-handler/routes/pull-v1.test.d.ts.map +0 -1
  114. package/dist/server-api-handler/routes/pull-v1.test.js.map +0 -1
  115. package/dist/server-api-handler/routes/push-v1.d.ts +0 -3
  116. package/dist/server-api-handler/routes/push-v1.d.ts.map +0 -1
  117. package/dist/server-api-handler/routes/push-v1.js.map +0 -1
  118. package/dist/server-api-handler/routes/push-v1.test.d.ts.map +0 -1
  119. package/dist/server-api-handler/routes/push-v1.test.js.map +0 -1
  120. package/src/server-api-handler/index.ts +0 -5
  121. /package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.test.d.ts +0 -0
  122. /package/dist/{server-api-handler → server-protocol-handler}/environment/create-in-memory-environment.test.js +0 -0
  123. /package/dist/{server-api-handler → server-protocol-handler}/environment/environment.js +0 -0
  124. /package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.js +0 -0
  125. /package/dist/{server-api-handler → server-protocol-handler}/routes/get-v1.test.d.ts +0 -0
  126. /package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.js +0 -0
  127. /package/dist/{server-api-handler → server-protocol-handler}/routes/new-v1.test.d.ts +0 -0
  128. /package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.js +0 -0
  129. /package/dist/{server-api-handler → server-protocol-handler}/routes/pull-v1.test.d.ts +0 -0
  130. /package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.js +0 -0
  131. /package/dist/{server-api-handler → server-protocol-handler}/routes/push-v1.test.d.ts +0 -0
  132. /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 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
 
@@ -1,9 +1,9 @@
1
1
  import { expect, test, vi } from "vitest";
2
- import { createServerApiHandler } from "../server-api-handler/create-server-api-handler.js";
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 { createLsaInMemoryEnvironment } from "../server-api-handler/environment/create-in-memory-environment.js";
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 = createLsaInMemoryEnvironment();
23
- const lsaHandler = await createServerApiHandler({ environment });
22
+ const environment = createLspInMemoryEnvironment();
23
+ const lspHandler = await createServerProtocolHandler({ environment });
24
24
 
25
- global.fetch = vi.fn((request) => lsaHandler(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 lsaHandler(
42
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
89
- const lsaHandler = await createServerApiHandler({ environment });
88
+ const environment = createLspInMemoryEnvironment();
89
+ const lspHandler = await createServerProtocolHandler({ environment });
90
90
 
91
- global.fetch = vi.fn((request) => lsaHandler(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 lsaHandler(
107
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
154
- const lsaHandler = await createServerApiHandler({ environment });
153
+ const environment = createLspInMemoryEnvironment();
154
+ const lspHandler = await createServerProtocolHandler({ environment });
155
155
 
156
- global.fetch = vi.fn((request) => lsaHandler(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 lsaHandler(
160
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
199
- const lsaHandler = await createServerApiHandler({ environment });
198
+ const environment = createLspInMemoryEnvironment();
199
+ const lspHandler = await createServerProtocolHandler({ environment });
200
200
 
201
- global.fetch = vi.fn((request) => lsaHandler(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 lsaHandler(
247
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
306
- // const lsaHandler = await createServerApiHandler({ environment });
305
+ // const environment = createLspInMemoryEnvironment();
306
+ // const lspHandler = await createServerProtocolHandler({ environment });
307
307
 
308
- // global.fetch = vi.fn((request) => lsaHandler(request));
308
+ // global.fetch = vi.fn((request) => lspHandler(request));
309
309
 
310
310
  // // initialize the lix on the server
311
- // await lsaHandler(
312
- // new Request("http://localhost:3000/lsa/new", {
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 = createLsaInMemoryEnvironment();
358
- const lsaHandler = await createServerApiHandler({ environment });
357
+ const environment = createLspInMemoryEnvironment();
358
+ const lspHandler = await createServerProtocolHandler({ environment });
359
359
 
360
- global.fetch = vi.fn((request) => lsaHandler(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 lsaHandler(
393
- new Request("http://localhost:3000/lsa/new-v1", {
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 LixServerApi from "@lix-js/server-api-schema";
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}/lsa/pull-v1`, {
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 LixServerApi.paths["/lsa/pull-v1"]["post"]["requestBody"]["content"]["application/json"]),
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 LixServerApi.paths["/lsa/pull-v1"]["post"]["responses"]["200"]["content"]["application/json"]
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 LixServerApi.paths["/lsa/pull-v1"]["post"]["responses"]["200"]["content"]["application/json"]
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 { createServerApiHandler } from "../server-api-handler/create-server-api-handler.js";
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 { createLsaInMemoryEnvironment } from "../server-api-handler/environment/create-in-memory-environment.js";
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 = createLsaInMemoryEnvironment();
26
- const lsaHandler = await createServerApiHandler({ environment });
25
+ const environment = createLspInMemoryEnvironment();
26
+ const lspHandler = await createServerProtocolHandler({ environment });
27
27
 
28
- global.fetch = vi.fn((request) => lsaHandler(request));
28
+ global.fetch = vi.fn((request) => lspHandler(request));
29
29
 
30
30
  // initialize the lix on the server
31
- await lsaHandler(
32
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
107
- const lsaHandler = await createServerApiHandler({ environment });
106
+ const environment = createLspInMemoryEnvironment();
107
+ const lspHandler = await createServerProtocolHandler({ environment });
108
108
 
109
- global.fetch = vi.fn((request) => lsaHandler(request));
109
+ global.fetch = vi.fn((request) => lspHandler(request));
110
110
 
111
111
  // Initialize the lix on the server
112
- await lsaHandler(
113
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
290
- const lsaHandler = await createServerApiHandler({ environment });
289
+ const environment = createLspInMemoryEnvironment();
290
+ const lspHandler = await createServerProtocolHandler({ environment });
291
291
 
292
- global.fetch = vi.fn((request) => lsaHandler(request));
292
+ global.fetch = vi.fn((request) => lspHandler(request));
293
293
 
294
294
  // initialize the lix on the server
295
- await lsaHandler(
296
- new Request("http://localhost:3000/lsa/new-v1", {
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 = createLsaInMemoryEnvironment();
344
- const lsaHandler = await createServerApiHandler({ environment });
343
+ const environment = createLspInMemoryEnvironment();
344
+ const lspHandler = await createServerProtocolHandler({ environment });
345
345
 
346
- global.fetch = vi.fn((request) => lsaHandler(request));
346
+ global.fetch = vi.fn((request) => lspHandler(request));
347
347
 
348
348
  // initialize the lix on the server
349
- await lsaHandler(
350
- new Request("http://localhost:3000/lsa/new", {
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 "../../../lix-server-api-schema/dist/schema.js";
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}/lsa/push-v1`, {
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["/lsa/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
37
+ } satisfies LixServerProtocol.paths["/lsp/push-v1"]["post"]["requestBody"]["content"]["application/json"]),
38
38
  headers: {
39
39
  "Content-Type": "application/json",
40
40
  },