Skip to content

Commit

Permalink
Merge pull request #3059 from opral/samuel/fix-old-neu
Browse files Browse the repository at this point in the history
fix: old neu file passing
  • Loading branch information
janfjohannes committed Aug 13, 2024
2 parents 1a9b96b + 476fd8e commit 59ce2ed
Show file tree
Hide file tree
Showing 8 changed files with 1,813 additions and 867 deletions.
2 changes: 1 addition & 1 deletion inlang/source-code/fink2/src/components/VariantHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const VariantHistory = (props: { variantId: string }) => {
<div className="flex items-center text-zinc-400 text-sm!">
{latestCommit?.user_id && (
<p>
by {latestCommit?.user_id} | {timeAgo(latestCommit?.zoned_date_time)}
by {latestCommit?.user_id} | {timeAgo(latestCommit?.created)}
</p>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const VariantHistoryList = (props: {
changed variant
</h3>
<p className="text-[16px] text-zinc-700">
{timeAgo(change.zoned_date_time)}
{timeAgo(change.created)}
</p>
</div>
<div className="flex gap-2 mt-1">
Expand All @@ -95,9 +95,9 @@ const VariantHistoryList = (props: {
variant="default"
size="medium"
className="mt-4 ml-auto"
loading={loading === change.zoned_date_time}
loading={loading === change.created}
onClick={() =>
handleRollback(change.value, change.zoned_date_time)
handleRollback(change.value, change.created)
}
>
Rollback
Expand Down
2 changes: 1 addition & 1 deletion inlang/source-code/sdk2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@inlang/json-types": "workspace:*",
"@types/debug": "^4.1.12",
"@types/murmurhash3js": "^3.0.7",
"@vitest/coverage-v8": "^0.33.0",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/web-worker": "^1.6.0",
"jsdom": "22.1.0",
"memfs": "4.6.0",
Expand Down
32 changes: 32 additions & 0 deletions inlang/source-code/sdk2/src/lix-plugin/inlangLixPluginV1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,38 @@ describe("plugin.diff.file", () => {
} satisfies DiffReport,
]);
});

// https://github.com/opral/lix-sdk/issues/33
test("it should generate changes after the first change", async () => {
const project = await loadProjectInMemory({ blob: await newProject() });

const initialChanges = await project.lix.db
.selectFrom("change")
.selectAll()
.execute();
expect(initialChanges.length).toEqual(0);

await project.db
.insertInto("bundle")
.values({
id: "1",
// @ts-expect-error - database expects stringified json
alias: JSON.stringify({}),
})
.execute();

// workaround until await lix.settled() is implemented
await new Promise((resolve) => setTimeout(resolve, 500));

const changes = await project.lix.db
.selectFrom("change")
.selectAll()
.execute();

expect(changes.length).toBe(1);
expect(changes[0]?.value?.id).toBe("1");
expect(changes[0]?.operation).toBe("create");
});
});

describe("plugin.diff.variant", () => {
Expand Down
2 changes: 2 additions & 0 deletions inlang/source-code/sdk2/src/lix-plugin/inlangLixPluginV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ export const inlangLixPluginV1: LixPlugin<{
sqlite: await loadDatabaseInMemory(neu.data),
})
: undefined;

const newProjectBundles = await newDb
?.selectFrom("bundle")
.selectAll()
.execute();

const newProjectMessages = await newDb
?.selectFrom("message")
.selectAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ export async function initHandleSaveToLixOnChange(args: {
arity: 0,
// @ts-expect-error - dynamic function
xFunc: () => {
const data = contentFromDatabase(args.sqlite);
args.lix.db
.updateTable("file")
.set("data", data)
.where("path", "=", "/db.sqlite")
.execute();
(async () => {
await new Promise((resolve) => setTimeout(resolve, 100));
const data = contentFromDatabase(args.sqlite);
await args.lix.db
.updateTable("file")
.set("data", data)
.where("path", "=", "/db.sqlite")
.execute();
})();
return;
},
});

Expand Down
9 changes: 6 additions & 3 deletions lix/packages/sdk/src/open/openLix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function openLix(args: {
await sql`
CREATE TEMP TRIGGER file_modified AFTER UPDATE ON file
BEGIN
SELECT handle_file_change(NEW.id, NEW.path, NEW.data, OLD.id, OLD.path, OLD.data);
SELECT handle_file_change(OLD.id, OLD.path, OLD.data, NEW.id, NEW.path, NEW.data);
END;
`.execute(db);

Expand Down Expand Up @@ -187,8 +187,11 @@ async function getChangeHistory({
.selectFrom("commit")
.selectAll()
.where("id", "=", nextCommitId)
.executeTakeFirstOrThrow();
.executeTakeFirst();

if (!commit) {
break;
}
nextCommitId = commit.parent_id;

firstChange = await db
Expand Down Expand Up @@ -267,10 +270,10 @@ async function handleFileChange(args: {
type: diff.type,
file_id: fileId,
operation: diff.operation,
parent_id: parent?.id,
plugin_key: plugin.key,
// @ts-expect-error - database expects stringified json
value: JSON.stringify(value),
parent_id: parent?.id,
meta: JSON.stringify(diff.meta),
})
.execute();
Expand Down
Loading

0 comments on commit 59ce2ed

Please sign in to comment.