Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolveConflict() api #3073

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lix/packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
},
"dependencies": {
"kysely": "^0.27.4",
"lodash-es": "^4.17.21",
"minimatch": "^10.0.1",
"prettier": "^3.3.3",
"sqlite-wasm-kysely": "workspace: *",
"uuid": "^10.0.0"
},
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/papaparse": "^5.3.14",
"@types/uuid": "^10.0.0",
"@vitest/coverage-v8": "^2.0.5",
Expand Down
4 changes: 3 additions & 1 deletion lix/packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export * from "./schema.js";
export { jsonObjectFrom, jsonArrayFrom } from "kysely/helpers/sqlite";
export { v4 as uuidv4 } from "uuid";
export * from "./types.js";
export * from "./query-utilities/index.js";
export * from "./resolve-conflict/errors.js";
export { merge } from "./merge/merge.js";
export * from "./query-utilities/index.js";
export { resolveConflict } from "./resolve-conflict/resolve-conflict.js";
1 change: 1 addition & 0 deletions lix/packages/sdk/src/newLix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function newLixFile(): Promise<Blob> {
conflicting_change_id TEXT NOT NULL,
reason TEXT,
meta TEXT,
resolved_with_change_id TEXT,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used as marker if a conflict has been resolved.

PRIMARY KEY (change_id, conflicting_change_id)
) strict;

Expand Down
33 changes: 33 additions & 0 deletions lix/packages/sdk/src/resolve-conflict/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export class ResolveConflictError extends Error {
constructor(message: string) {
super(message);
this.name = "ResolveConflictError";
}
}

export class ChangeDoesNotBelongToFileError extends ResolveConflictError {
constructor() {
super(
"The to be resolved change does not belong to the same file as the conflicting changes.",
);
this.name = "ChangeDoesNotBelongToFileError";
}
}

export class ChangeNotDirectChildOfConflictError extends ResolveConflictError {
constructor() {
super(
"The to be resolved change is not a direct child of the conflicting changes. The parent_id of the resolveWithChange must be the id of the conflict or the conflicting change.",
);
this.name = "ChangeNotDirectChildOfConflictError";
}
}

export class ChangeHasBeenMutatedError extends ResolveConflictError {
constructor() {
super(
"The to be resolved change already exists in the database and is not equal to the provided change. Changes are immutable. If you want to resolve a conflict by updating a change, create a new change.",
);
this.name = "ChangeHasBeenMutatedError";
}
}
samuelstroschein marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading