@lix-js/sdk 0.3.0 → 0.3.2
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/services/env-variables/index.d.ts +1 -1
- package/dist/services/env-variables/index.js +2 -2
- package/dist/services/env-variables/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/change-queue/change-queue-settled.d.ts +0 -13
- package/dist/change-queue/change-queue-settled.d.ts.map +0 -1
- package/dist/change-queue/change-queue-settled.js +0 -25
- package/dist/change-queue/change-queue-settled.js.map +0 -1
- package/dist/change-queue/change-queue-settled.test.d.ts +0 -2
- package/dist/change-queue/change-queue-settled.test.d.ts.map +0 -1
- package/dist/change-queue/change-queue-settled.test.js +0 -47
- package/dist/change-queue/change-queue-settled.test.js.map +0 -1
- package/dist/change-queue/file-handlers.d.ts +0 -24
- package/dist/change-queue/file-handlers.d.ts.map +0 -1
- package/dist/change-queue/file-handlers.js +0 -209
- package/dist/change-queue/file-handlers.js.map +0 -1
- package/dist/change-queue/index.d.ts +0 -2
- package/dist/change-queue/index.d.ts.map +0 -1
- package/dist/change-queue/index.js +0 -2
- package/dist/change-queue/index.js.map +0 -1
- package/dist/change-queue/init-change-queue.d.ts +0 -7
- package/dist/change-queue/init-change-queue.d.ts.map +0 -1
- package/dist/change-queue/init-change-queue.js +0 -80
- package/dist/change-queue/init-change-queue.js.map +0 -1
- package/dist/change-queue/init-change-queue.test.d.ts +0 -2
- package/dist/change-queue/init-change-queue.test.d.ts.map +0 -1
- package/dist/change-queue/init-change-queue.test.js +0 -373
- package/dist/change-queue/init-change-queue.test.js.map +0 -1
- package/dist/change-queue/with-skip-change-queue.d.ts +0 -3
- package/dist/change-queue/with-skip-change-queue.d.ts.map +0 -1
- package/dist/change-queue/with-skip-change-queue.js +0 -26
- package/dist/change-queue/with-skip-change-queue.js.map +0 -1
- package/dist/change-queue/with-skip-change-queue.test.d.ts +0 -2
- package/dist/change-queue/with-skip-change-queue.test.d.ts.map +0 -1
- package/dist/change-queue/with-skip-change-queue.test.js +0 -138
- package/dist/change-queue/with-skip-change-queue.test.js.map +0 -1
- package/dist/own-entity-change-control/apply-own-entity-change.d.ts +0 -10
- package/dist/own-entity-change-control/apply-own-entity-change.d.ts.map +0 -1
- package/dist/own-entity-change-control/apply-own-entity-change.js +0 -69
- package/dist/own-entity-change-control/apply-own-entity-change.js.map +0 -1
- package/dist/own-entity-change-control/apply-own-entity-change.test.d.ts +0 -2
- package/dist/own-entity-change-control/apply-own-entity-change.test.d.ts.map +0 -1
- package/dist/own-entity-change-control/apply-own-entity-change.test.js +0 -297
- package/dist/own-entity-change-control/apply-own-entity-change.test.js.map +0 -1
- package/dist/own-entity-change-control/change-controlled-tables.d.ts +0 -61
- package/dist/own-entity-change-control/change-controlled-tables.d.ts.map +0 -1
- package/dist/own-entity-change-control/change-controlled-tables.js +0 -71
- package/dist/own-entity-change-control/change-controlled-tables.js.map +0 -1
- package/dist/own-entity-change-control/change-controlled-tables.test.d.ts +0 -2
- package/dist/own-entity-change-control/change-controlled-tables.test.d.ts.map +0 -1
- package/dist/own-entity-change-control/change-controlled-tables.test.js +0 -48
- package/dist/own-entity-change-control/change-controlled-tables.test.js.map +0 -1
- package/dist/own-entity-change-control/database-triggers.d.ts +0 -5
- package/dist/own-entity-change-control/database-triggers.d.ts.map +0 -1
- package/dist/own-entity-change-control/database-triggers.js +0 -135
- package/dist/own-entity-change-control/database-triggers.js.map +0 -1
- package/dist/own-entity-change-control/database-triggers.test.d.ts +0 -2
- package/dist/own-entity-change-control/database-triggers.test.d.ts.map +0 -1
- package/dist/own-entity-change-control/database-triggers.test.js +0 -214
- package/dist/own-entity-change-control/database-triggers.test.js.map +0 -1
- package/dist/own-entity-change-control/index.d.ts +0 -2
- package/dist/own-entity-change-control/index.d.ts.map +0 -1
- package/dist/own-entity-change-control/index.js +0 -2
- package/dist/own-entity-change-control/index.js.map +0 -1
- package/dist/own-entity-change-control/with-skip-own-change-control.d.ts +0 -3
- package/dist/own-entity-change-control/with-skip-own-change-control.d.ts.map +0 -1
- package/dist/own-entity-change-control/with-skip-own-change-control.js +0 -24
- package/dist/own-entity-change-control/with-skip-own-change-control.js.map +0 -1
- package/dist/own-entity-change-control/with-skip-own-change-control.test.d.ts +0 -2
- package/dist/own-entity-change-control/with-skip-own-change-control.test.d.ts.map +0 -1
- package/dist/own-entity-change-control/with-skip-own-change-control.test.js +0 -49
- package/dist/own-entity-change-control/with-skip-own-change-control.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/env-variables/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/env-variables/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,qBAAqB,EAAE,iDAAiD;IACzE,eAAe,EAAE,OAAO;CACxB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lix-js/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/index.js"
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"js-sha256": "^0.11.0",
|
|
23
23
|
"kysely": "^0.27.4",
|
|
24
24
|
"uuid": "^10.0.0",
|
|
25
|
-
"sqlite-wasm-kysely": "0.1.1"
|
|
25
|
+
"sqlite-wasm-kysely": "0.1.1",
|
|
26
|
+
"@lix-js/server-api-schema": "0.1.1"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@eslint/js": "^9.12.0",
|
|
@@ -33,8 +34,7 @@
|
|
|
33
34
|
"prettier": "^3.3.3",
|
|
34
35
|
"typescript": "^5.5.4",
|
|
35
36
|
"typescript-eslint": "^8.9.0",
|
|
36
|
-
"vitest": "2.0.5"
|
|
37
|
-
"@lix-js/server-api-schema": "0.1.1"
|
|
37
|
+
"vitest": "2.0.5"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"prebuild": "npm run env-variables",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Lix } from "../lix/open-lix.js";
|
|
2
|
-
/**
|
|
3
|
-
* Waits until the change queue is settled.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* await changeQueueSettled({ lix });
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
export declare function changeQueueSettled(args: {
|
|
11
|
-
lix: Pick<Lix, "db">;
|
|
12
|
-
}): Promise<void>;
|
|
13
|
-
//# sourceMappingURL=change-queue-settled.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"change-queue-settled.d.ts","sourceRoot":"","sources":["../../src/change-queue/change-queue-settled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAC9C,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBhB"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Waits until the change queue is settled.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* await changeQueueSettled({ lix });
|
|
7
|
-
* ```
|
|
8
|
-
*/
|
|
9
|
-
export async function changeQueueSettled(args) {
|
|
10
|
-
let hasEntries = true;
|
|
11
|
-
while (hasEntries) {
|
|
12
|
-
const entries = await args.lix.db
|
|
13
|
-
.selectFrom("change_queue")
|
|
14
|
-
.selectAll()
|
|
15
|
-
.limit(1)
|
|
16
|
-
.execute();
|
|
17
|
-
hasEntries = entries.length > 0;
|
|
18
|
-
if (hasEntries) {
|
|
19
|
-
// poll again in 50ms. This is a workaround until subscriptions
|
|
20
|
-
// or another mechanism is implemented to notify when the queue is settled
|
|
21
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=change-queue-settled.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"change-queue-settled.js","sourceRoot":"","sources":["../../src/change-queue/change-queue-settled.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAExC;IACA,IAAI,UAAU,GAAG,IAAI,CAAC;IAEtB,OAAO,UAAU,EAAE,CAAC;QACnB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;aAC/B,UAAU,CAAC,cAAc,CAAC;aAC1B,SAAS,EAAE;aACX,KAAK,CAAC,CAAC,CAAC;aACR,OAAO,EAAE,CAAC;QAEZ,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QAEhC,IAAI,UAAU,EAAE,CAAC;YAChB,+DAA+D;YAC/D,0EAA0E;YAC1E,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"change-queue-settled.test.d.ts","sourceRoot":"","sources":["../../src/change-queue/change-queue-settled.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "vitest";
|
|
2
|
-
import { openLixInMemory } from "../lix/open-lix-in-memory.js";
|
|
3
|
-
import { changeQueueSettled } from "./change-queue-settled.js";
|
|
4
|
-
test("should wait until the change queue is settled", async () => {
|
|
5
|
-
const lix = await openLixInMemory({});
|
|
6
|
-
await lix.db
|
|
7
|
-
.insertInto("change_queue")
|
|
8
|
-
.values([
|
|
9
|
-
{
|
|
10
|
-
id: 1,
|
|
11
|
-
file_id: "file1",
|
|
12
|
-
path_after: "path1",
|
|
13
|
-
data_after: new TextEncoder().encode("data1"),
|
|
14
|
-
metadata_after: null,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
id: 2,
|
|
18
|
-
file_id: "file2",
|
|
19
|
-
path_after: "path2",
|
|
20
|
-
data_after: new TextEncoder().encode("data2"),
|
|
21
|
-
metadata_after: null,
|
|
22
|
-
},
|
|
23
|
-
])
|
|
24
|
-
.execute();
|
|
25
|
-
// Start a background task to remove entries from the change_queue after a delay
|
|
26
|
-
setTimeout(async () => {
|
|
27
|
-
await lix.db.deleteFrom("change_queue").where("id", "=", 1).execute();
|
|
28
|
-
await lix.db.deleteFrom("change_queue").where("id", "=", 2).execute();
|
|
29
|
-
}, 110);
|
|
30
|
-
await changeQueueSettled({ lix });
|
|
31
|
-
const remainingEntries = await lix.db
|
|
32
|
-
.selectFrom("change_queue")
|
|
33
|
-
.selectAll()
|
|
34
|
-
.execute();
|
|
35
|
-
expect(remainingEntries).toEqual([]);
|
|
36
|
-
});
|
|
37
|
-
test("should return immediately if the change queue is already empty", async () => {
|
|
38
|
-
const lix = await openLixInMemory({});
|
|
39
|
-
await lix.db.deleteFrom("change_queue").execute();
|
|
40
|
-
await changeQueueSettled({ lix });
|
|
41
|
-
const remainingEntries = await lix.db
|
|
42
|
-
.selectFrom("change_queue")
|
|
43
|
-
.selectAll()
|
|
44
|
-
.execute();
|
|
45
|
-
expect(remainingEntries).toEqual([]);
|
|
46
|
-
});
|
|
47
|
-
//# sourceMappingURL=change-queue-settled.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"change-queue-settled.test.js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,GAAG,MAAM,GAAG,CAAC,EAAE;SACnC,UAAU,CAAC,cAAc,CAAC;SAC1B,SAAS,EAAE;SACX,OAAO,EAAE,CAAC;IAEZ,MAAM,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;IACjF,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,EAAE,CAAC,CAAC;IAEtC,MAAM,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;IAElD,MAAM,kBAAkB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAElC,MAAM,gBAAgB,GAAG,MAAM,GAAG,CAAC,EAAE;SACnC,UAAU,CAAC,cAAc,CAAC;SAC1B,SAAS,EAAE;SACX,OAAO,EAAE,CAAC;IACZ,MAAM,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ChangeQueueEntry } from "../database/schema.js";
|
|
2
|
-
import type { Lix } from "../lix/open-lix.js";
|
|
3
|
-
export declare function handleFileInsert(args: {
|
|
4
|
-
lix: Pick<Lix, "db" | "plugin" | "sqlite">;
|
|
5
|
-
changeQueueEntry: ChangeQueueEntry;
|
|
6
|
-
}): Promise<void>;
|
|
7
|
-
export declare function handleFileUpdate(args: {
|
|
8
|
-
lix: Pick<Lix, "db" | "plugin" | "sqlite">;
|
|
9
|
-
changeQueueEntry: ChangeQueueEntry;
|
|
10
|
-
}): Promise<void>;
|
|
11
|
-
/**
|
|
12
|
-
* File deletions don't need to invoke a plugin to detect changes.
|
|
13
|
-
*
|
|
14
|
-
* Instead, we can simply query the database for all changes that are related to the file
|
|
15
|
-
* and create the corresponding deletion changes for the current version.
|
|
16
|
-
*
|
|
17
|
-
* - simpler plugin API (because deletions don't need to be accounted for)
|
|
18
|
-
* - faster file deletion (because we don't need to invoke plugins)
|
|
19
|
-
*/
|
|
20
|
-
export declare function handleFileDelete(args: {
|
|
21
|
-
lix: Pick<Lix, "db" | "plugin" | "sqlite">;
|
|
22
|
-
changeQueueEntry: ChangeQueueEntry;
|
|
23
|
-
}): Promise<void>;
|
|
24
|
-
//# sourceMappingURL=file-handlers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-handlers.d.ts","sourceRoot":"","sources":["../../src/change-queue/file-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AA6B9C,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC5C,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;IAC3C,gBAAgB,EAAE,gBAAgB,CAAC;CACnC,GAAG,OAAO,CAAC,IAAI,CAAC,CAwFhB;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC5C,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;IAC3C,gBAAgB,EAAE,gBAAgB,CAAC;CACnC,GAAG,OAAO,CAAC,IAAI,CAAC,CAyFhB;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC5C,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;IAC3C,gBAAgB,EAAE,gBAAgB,CAAC;CACnC,GAAG,OAAO,CAAC,IAAI,CAAC,CA0ChB"}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { sql } from "kysely";
|
|
2
|
-
import { createChange } from "../change/create-change.js";
|
|
3
|
-
import { changeIsLeafInVersion } from "../query-filter/change-is-leaf-in-version.js";
|
|
4
|
-
// start a new normalize path function that has the absolute minimum implementation.
|
|
5
|
-
function normalizePath(path) {
|
|
6
|
-
if (!path.startsWith("/")) {
|
|
7
|
-
return "/" + path;
|
|
8
|
-
}
|
|
9
|
-
return path;
|
|
10
|
-
}
|
|
11
|
-
async function glob(args) {
|
|
12
|
-
const result = await sql `SELECT CASE WHEN ${args.path} GLOB ${args.glob} THEN 1 ELSE 0 END AS matches`.execute(args.lix.db);
|
|
13
|
-
// Extract the result from the response
|
|
14
|
-
return result.rows[0]?.matches === 1;
|
|
15
|
-
}
|
|
16
|
-
// creates initial changes for new files
|
|
17
|
-
export async function handleFileInsert(args) {
|
|
18
|
-
const detectedChanges = [];
|
|
19
|
-
const plugins = await args.lix.plugin.getAll();
|
|
20
|
-
// the path of the file is either the after path or the before path
|
|
21
|
-
// depending on whether the file was deleted, updated, or created
|
|
22
|
-
const path = args.changeQueueEntry.path_after ?? args.changeQueueEntry.path_before;
|
|
23
|
-
if (path === null) {
|
|
24
|
-
throw new Error("Both before and after paths are null");
|
|
25
|
-
}
|
|
26
|
-
for (const plugin of plugins) {
|
|
27
|
-
// glob expressions are expressed relative without leading / but path has leading /
|
|
28
|
-
if (!(await glob({
|
|
29
|
-
lix: args.lix,
|
|
30
|
-
path: normalizePath(path),
|
|
31
|
-
glob: "/" + plugin.detectChangesGlob,
|
|
32
|
-
}))) {
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
if (plugin.detectChanges === undefined) {
|
|
36
|
-
const error = new Error("Plugin does not support detecting changes even though the glob matches.");
|
|
37
|
-
// https://linear.app/opral/issue/LIXDK-195/await-change-queue-to-log-errors
|
|
38
|
-
console.error(error);
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
if (args.changeQueueEntry.data_after === null) {
|
|
42
|
-
throw new Error("Data after is null");
|
|
43
|
-
}
|
|
44
|
-
for (const change of await plugin.detectChanges({
|
|
45
|
-
lix: args.lix,
|
|
46
|
-
before: undefined,
|
|
47
|
-
after: {
|
|
48
|
-
id: args.changeQueueEntry.file_id,
|
|
49
|
-
path,
|
|
50
|
-
metadata: args.changeQueueEntry.metadata_after,
|
|
51
|
-
data: args.changeQueueEntry.data_after,
|
|
52
|
-
},
|
|
53
|
-
})) {
|
|
54
|
-
detectedChanges.push({
|
|
55
|
-
...change,
|
|
56
|
-
pluginKey: plugin.key,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
await args.lix.db.transaction().execute(async (trx) => {
|
|
61
|
-
const currentAuthors = await trx
|
|
62
|
-
.selectFrom("active_account")
|
|
63
|
-
.selectAll()
|
|
64
|
-
.execute();
|
|
65
|
-
const currentVersion = await trx
|
|
66
|
-
.selectFrom("current_version")
|
|
67
|
-
.innerJoin("version", "current_version.id", "version.id")
|
|
68
|
-
.selectAll()
|
|
69
|
-
.executeTakeFirstOrThrow();
|
|
70
|
-
await Promise.all(detectedChanges.map(async (detectedChange) => {
|
|
71
|
-
await createChange({
|
|
72
|
-
lix: { ...args.lix, db: trx },
|
|
73
|
-
authors: currentAuthors,
|
|
74
|
-
version: currentVersion,
|
|
75
|
-
entityId: detectedChange.entity_id,
|
|
76
|
-
fileId: args.changeQueueEntry.file_id,
|
|
77
|
-
pluginKey: detectedChange.pluginKey,
|
|
78
|
-
schemaKey: detectedChange.schema.key,
|
|
79
|
-
snapshotContent: detectedChange.snapshot,
|
|
80
|
-
});
|
|
81
|
-
}));
|
|
82
|
-
await trx
|
|
83
|
-
.deleteFrom("change_queue")
|
|
84
|
-
.where("id", "=", args.changeQueueEntry.id)
|
|
85
|
-
.execute();
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
export async function handleFileUpdate(args) {
|
|
89
|
-
const detectedChanges = [];
|
|
90
|
-
const plugins = await args.lix.plugin.getAll();
|
|
91
|
-
// the path of the file is either the after path or the before path
|
|
92
|
-
// depending on whether the file was deleted, updated, or created
|
|
93
|
-
const path = args.changeQueueEntry.path_after ?? args.changeQueueEntry.path_before;
|
|
94
|
-
if (path === null) {
|
|
95
|
-
throw new Error("Both before and after paths are null");
|
|
96
|
-
}
|
|
97
|
-
for (const plugin of plugins) {
|
|
98
|
-
// glob expressions are expressed relative without leading / but path has leading /
|
|
99
|
-
if (!(await glob({
|
|
100
|
-
lix: args.lix,
|
|
101
|
-
path: normalizePath(path),
|
|
102
|
-
glob: "/" + plugin.detectChangesGlob,
|
|
103
|
-
}))) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
if (plugin.detectChanges === undefined) {
|
|
107
|
-
const error = new Error("Plugin does not support detecting changes even though the glob matches.");
|
|
108
|
-
// https://linear.app/opral/issue/LIXDK-195/await-change-queue-to-log-errors
|
|
109
|
-
console.error(error);
|
|
110
|
-
throw error;
|
|
111
|
-
}
|
|
112
|
-
for (const change of await plugin.detectChanges({
|
|
113
|
-
lix: args.lix,
|
|
114
|
-
before: args.changeQueueEntry.data_before
|
|
115
|
-
? {
|
|
116
|
-
id: args.changeQueueEntry.file_id,
|
|
117
|
-
path: path,
|
|
118
|
-
metadata: args.changeQueueEntry.metadata_before,
|
|
119
|
-
data: args.changeQueueEntry.data_before,
|
|
120
|
-
}
|
|
121
|
-
: undefined,
|
|
122
|
-
after: {
|
|
123
|
-
id: args.changeQueueEntry.file_id,
|
|
124
|
-
path,
|
|
125
|
-
metadata: args.changeQueueEntry.metadata_after,
|
|
126
|
-
data: args.changeQueueEntry.data_after,
|
|
127
|
-
},
|
|
128
|
-
})) {
|
|
129
|
-
detectedChanges.push({
|
|
130
|
-
...change,
|
|
131
|
-
pluginKey: plugin.key,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
await args.lix.db.transaction().execute(async (trx) => {
|
|
136
|
-
const currentAuthors = await trx
|
|
137
|
-
.selectFrom("active_account")
|
|
138
|
-
.selectAll()
|
|
139
|
-
.execute();
|
|
140
|
-
const currentVersion = await trx
|
|
141
|
-
.selectFrom("current_version")
|
|
142
|
-
.innerJoin("version", "current_version.id", "version.id")
|
|
143
|
-
.selectAll()
|
|
144
|
-
.executeTakeFirstOrThrow();
|
|
145
|
-
await Promise.all(detectedChanges.map(async (detectedChange) => {
|
|
146
|
-
await createChange({
|
|
147
|
-
lix: { ...args.lix, db: trx },
|
|
148
|
-
authors: currentAuthors,
|
|
149
|
-
version: currentVersion,
|
|
150
|
-
entityId: detectedChange.entity_id,
|
|
151
|
-
fileId: args.changeQueueEntry.file_id,
|
|
152
|
-
pluginKey: detectedChange.pluginKey,
|
|
153
|
-
schemaKey: detectedChange.schema.key,
|
|
154
|
-
snapshotContent: detectedChange.snapshot,
|
|
155
|
-
});
|
|
156
|
-
}));
|
|
157
|
-
await trx
|
|
158
|
-
.deleteFrom("change_queue")
|
|
159
|
-
.where("id", "=", args.changeQueueEntry.id)
|
|
160
|
-
.execute();
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* File deletions don't need to invoke a plugin to detect changes.
|
|
165
|
-
*
|
|
166
|
-
* Instead, we can simply query the database for all changes that are related to the file
|
|
167
|
-
* and create the corresponding deletion changes for the current version.
|
|
168
|
-
*
|
|
169
|
-
* - simpler plugin API (because deletions don't need to be accounted for)
|
|
170
|
-
* - faster file deletion (because we don't need to invoke plugins)
|
|
171
|
-
*/
|
|
172
|
-
export async function handleFileDelete(args) {
|
|
173
|
-
await args.lix.db.transaction().execute(async (trx) => {
|
|
174
|
-
const currentVersion = await trx
|
|
175
|
-
.selectFrom("current_version")
|
|
176
|
-
.innerJoin("version", "current_version.id", "version.id")
|
|
177
|
-
.selectAll()
|
|
178
|
-
.executeTakeFirstOrThrow();
|
|
179
|
-
const toBeDeletedEntities = await trx
|
|
180
|
-
.selectFrom("change")
|
|
181
|
-
.where("file_id", "=", args.changeQueueEntry.file_id)
|
|
182
|
-
.where(changeIsLeafInVersion(currentVersion))
|
|
183
|
-
.select("entity_id")
|
|
184
|
-
.select("schema_key")
|
|
185
|
-
.select("plugin_key")
|
|
186
|
-
.execute();
|
|
187
|
-
const currentAuthors = await trx
|
|
188
|
-
.selectFrom("active_account")
|
|
189
|
-
.selectAll()
|
|
190
|
-
.execute();
|
|
191
|
-
await Promise.all(toBeDeletedEntities.map(async (change) => {
|
|
192
|
-
await createChange({
|
|
193
|
-
lix: { ...args.lix, db: trx },
|
|
194
|
-
authors: currentAuthors,
|
|
195
|
-
version: currentVersion,
|
|
196
|
-
entityId: change.entity_id,
|
|
197
|
-
fileId: args.changeQueueEntry.file_id,
|
|
198
|
-
pluginKey: change.plugin_key,
|
|
199
|
-
schemaKey: change.schema_key,
|
|
200
|
-
snapshotContent: null, // Snapshot is null for deletions
|
|
201
|
-
});
|
|
202
|
-
}));
|
|
203
|
-
await trx
|
|
204
|
-
.deleteFrom("change_queue")
|
|
205
|
-
.where("id", "=", args.changeQueueEntry.id)
|
|
206
|
-
.execute();
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
//# sourceMappingURL=file-handlers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-handlers.js","sourceRoot":"","sources":["../../src/change-queue/file-handlers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAErF,oFAAoF;AACpF,SAAS,aAAa,CAAC,IAAY;IAClC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,OAAO,GAAG,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,KAAK,UAAU,IAAI,CAAC,IAInB;IACA,MAAM,MAAM,GACX,MAAM,GAAG,CAAA,oBAAoB,IAAI,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI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,MAAM,cAAc,GAAG,MAAM,GAAG;aAC9B,UAAU,CAAC,gBAAgB,CAAC;aAC5B,SAAS,EAAE;aACX,OAAO,EAAE,CAAC;QAEZ,MAAM,OAAO,CAAC,GAAG,CAChB,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YACxC,MAAM,YAAY,CAAC;gBAClB,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE;gBAC7B,OAAO,EAAE,cAAc;gBACvB,OAAO,EAAE,cAAc;gBACvB,QAAQ,EAAE,MAAM,CAAC,SAAS;gBAC1B,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,OAAO;gBACrC,SAAS,EAAE,MAAM,CAAC,UAAU;gBAC5B,SAAS,EAAE,MAAM,CAAC,UAAU;gBAC5B,eAAe,EAAE,IAAI,EAAE,iCAAiC;aACxD,CAAC,CAAC;QACJ,CAAC,CAAC,CACF,CAAC;QAEF,MAAM,GAAG;aACP,UAAU,CAAC,cAAc,CAAC;aAC1B,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC;aAC1C,OAAO,EAAE,CAAC;IACb,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/change-queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/change-queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { SqliteDatabase } from "sqlite-wasm-kysely";
|
|
2
|
-
import type { Lix } from "../lix/open-lix.js";
|
|
3
|
-
export declare function initChangeQueue(args: {
|
|
4
|
-
lix: Pick<Lix, "db" | "plugin" | "sqlite">;
|
|
5
|
-
rawDatabase: SqliteDatabase;
|
|
6
|
-
}): Promise<void>;
|
|
7
|
-
//# sourceMappingURL=init-change-queue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init-change-queue.d.ts","sourceRoot":"","sources":["../../src/change-queue/init-change-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAMzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAE9C,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC3C,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;IAC3C,WAAW,EAAE,cAAc,CAAC;CAC5B,GAAG,OAAO,CAAC,IAAI,CAAC,CAuFhB"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { handleFileUpdate, handleFileInsert, handleFileDelete, } from "./file-handlers.js";
|
|
2
|
-
export async function initChangeQueue(args) {
|
|
3
|
-
args.rawDatabase.createFunction({
|
|
4
|
-
name: "triggerChangeQueue",
|
|
5
|
-
arity: 0,
|
|
6
|
-
// @ts-expect-error - dynamic function
|
|
7
|
-
xFunc: () => {
|
|
8
|
-
// TODO: abort current running queue?
|
|
9
|
-
queueWorker();
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
let pending;
|
|
13
|
-
let resolve;
|
|
14
|
-
// run number counts the worker runs in a current batch and is used to prevent race conditions where a trigger is missed because a previous run is just about to reset the hasMoreEntriesSince flag
|
|
15
|
-
let runNumber = 1;
|
|
16
|
-
// If a queue trigger happens during an existing queue run we might miss updates and use hasMoreEntriesSince to make sure there is always a final immediate queue worker execution
|
|
17
|
-
let hasMoreEntriesSince = undefined;
|
|
18
|
-
async function queueWorker(trail = false) {
|
|
19
|
-
try {
|
|
20
|
-
if (pending && !trail) {
|
|
21
|
-
hasMoreEntriesSince = runNumber;
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
runNumber++;
|
|
25
|
-
if (!pending) {
|
|
26
|
-
pending = new Promise((res) => {
|
|
27
|
-
resolve = res;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
const entry = await args.lix.db
|
|
31
|
-
.selectFrom("change_queue")
|
|
32
|
-
.selectAll()
|
|
33
|
-
.orderBy("id asc")
|
|
34
|
-
.limit(1)
|
|
35
|
-
.executeTakeFirst();
|
|
36
|
-
if (entry) {
|
|
37
|
-
if (entry.data_before && entry.data_after) {
|
|
38
|
-
await handleFileUpdate({
|
|
39
|
-
changeQueueEntry: entry,
|
|
40
|
-
lix: args.lix,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
else if (!entry.data_before && entry.data_after) {
|
|
44
|
-
await handleFileInsert({
|
|
45
|
-
changeQueueEntry: entry,
|
|
46
|
-
lix: args.lix,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
await handleFileDelete({
|
|
51
|
-
changeQueueEntry: entry,
|
|
52
|
-
lix: args.lix,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// console.log("getrting { numEntries }");
|
|
57
|
-
const { numEntries } = await args.lix.db
|
|
58
|
-
.selectFrom("change_queue")
|
|
59
|
-
.select((eb) => eb.fn.count("id").as("numEntries"))
|
|
60
|
-
.executeTakeFirstOrThrow();
|
|
61
|
-
// console.log({ numEntries });
|
|
62
|
-
if (!hasMoreEntriesSince ||
|
|
63
|
-
(numEntries === 0 && hasMoreEntriesSince < runNumber)) {
|
|
64
|
-
resolve(); // TODO: fix type
|
|
65
|
-
hasMoreEntriesSince = undefined;
|
|
66
|
-
pending = undefined;
|
|
67
|
-
// console.log("resolving");
|
|
68
|
-
}
|
|
69
|
-
// TODO: handle endless tries on failing quee entries
|
|
70
|
-
// we either execute the queue immediately if we know there is more work or fall back to polling
|
|
71
|
-
setTimeout(() => queueWorker(true), hasMoreEntriesSince ? 0 : 1000);
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
console.error("change queue failed ", e);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// start a worker in case there are entries
|
|
78
|
-
return queueWorker();
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=init-change-queue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init-change-queue.js","sourceRoot":"","sources":["../../src/change-queue/init-change-queue.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAGrC;IACA,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;QAC/B,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,CAAC;QACR,sCAAsC;QACtC,KAAK,EAAE,GAAG,EAAE;YACX,qCAAqC;YACrC,WAAW,EAAE,CAAC;QACf,CAAC;KACD,CAAC,CAAC;IAEH,IAAI,OAAkC,CAAC;IAEvC,IAAI,OAAmB,CAAC;IACxB,mMAAmM;IACnM,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,kLAAkL;IAClL,IAAI,mBAAmB,GAAuB,SAAS,CAAC;IAExD,KAAK,UAAU,WAAW,CAAC,KAAK,GAAG,KAAK;QACvC,IAAI,CAAC;YACJ,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;gBACvB,mBAAmB,GAAG,SAAS,CAAC;gBAChC,OAAO;YACR,CAAC;YACD,SAAS,EAAE,CAAC;YAEZ,IAAI,CAAC,OAAO,EAAE,CAAC;gBACd,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;oBAC7B,OAAO,GAAG,GAAG,CAAC;gBACf,CAAC,CAAC,CAAC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mB,GAAG,SAAS,CAAC;gBAChC,OAAO,GAAG,SAAS,CAAC;gBACpB,4BAA4B;YAC7B,CAAC;YAED,qDAAqD;YACrD,gGAAgG;YAChG,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACrE,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC;QAC1C,CAAC;IACF,CAAC;IACD,2CAA2C;IAC3C,OAAO,WAAW,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init-change-queue.test.d.ts","sourceRoot":"","sources":["../../src/change-queue/init-change-queue.test.ts"],"names":[],"mappings":""}
|