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

Bug: JSON-patches do not comply with the RFC-6902 standard #1077

Open
2 tasks done
Black1358 opened this issue Dec 12, 2024 · 2 comments
Open
2 tasks done

Bug: JSON-patches do not comply with the RFC-6902 standard #1077

Black1358 opened this issue Dec 12, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@Black1358
Copy link

Black1358 commented Dec 12, 2024

Describe the bug

https://surrealdb.com/docs/surrealdb/integration/rpc#live-
RFC-6902 does not contain "change" patches.

12-12-2024 (21:39:05.971) [SDB]: 🔍 {
  result: {
    action: "UPDATE",
    id: "cd80a055-cbde-47f0-b581-959b443b1481",
    record: "category:f46wmdv0vqy0f50d7bqb",
    result: [
      {
        op: "change",
        path: "/title",
        value: "@@ -1,7 +1,7 @@\n-ABC %D0%90%D0%91%D0%A1\n+%D0%90%D0%91%D0%A1 ABC\n"
      }
    ]
  }
}

Steps to reproduce

  1. Use the RPC protocol
  2. Subscribe to any table
  3. Change some string field in the record

Expected behaviour

Implementaion RFC-6902
https://datatracker.ietf.org/doc/html/rfc6902

SurrealDB version

surrealdb-2.1.2

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Black1358 Black1358 added the bug Something isn't working label Dec 12, 2024
@kearfy kearfy transferred this issue from surrealdb/surrealdb Dec 17, 2024
@kearfy
Copy link
Member

kearfy commented Dec 17, 2024

Hey @Black1358, we have some custom formatted messages in addition to the standard. We should introduce a page in the documentation describing all formats, instead of linking to the official spec to clarify that 👍

List of all operations can be found here, where the enum variant is translated into the "op" property as lowercase: https://github.com/surrealdb/surrealdb/blob/main/crates/core/src/sql/operation.rs

@kearfy kearfy added documentation Improvements or additions to documentation good first issue Good for newcomers and removed bug Something isn't working labels Dec 17, 2024
@Black1358
Copy link
Author

Hello @kearfy!
Existing libraries rely on this standard to work with JSON-patch. I was forced to write my own because of this deviation from the standard. In addition, the diff-text format requires the presence of the previous value for correct implementation, which is very annoying.

import DiffMatchPatch from "diff-match-patch";

const changeToReplacePatch = (text: string, patch: JiffChangePatch) => {
	(patch as unknown as JiffReplacePatch).op = "replace";
	const result = applyTextPatch(text, patch.value);
	patch.value = result;
};

//...
	case CHANGE:
		changeToReplacePatch(cursor[target], patch);
		cursor[target] = patch.value;
		break;
//...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants