Skip to content

Enable full keypath support for write operations#132

Merged
gohabereg merged 21 commits intomainfrom
feature/keypath-support
May 7, 2026
Merged

Enable full keypath support for write operations#132
gohabereg merged 21 commits intomainfrom
feature/keypath-support

Conversation

@gohabereg
Copy link
Copy Markdown
Member

All BlockNode operations now support keypath:

blockNode.insertText('compound.key.path', 'text') // serialized value gonna look like { compound: { key: { path: 'text' } }

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

⏭️ No files to mutate for ./packages/dom-adapters

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Coverage report for ./packages/dom-adapters

St.
Category Percentage Covered / Total
🟢 Statements 96.43% 27/28
🟢 Branches 86.96% 20/23
🟢 Functions 100% 5/5
🟢 Lines 96.43% 27/28

Test suite run success

11 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from 454927d

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

⏭️ No files to mutate for ./packages/core

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Coverage report for ./packages/model

St.
Category Percentage Covered / Total
🟢 Statements
99.79% (-0.21% 🔻)
937/939
🟢 Branches
98.95% (-0.67% 🔻)
284/287
🟢 Functions
97.78% (+0.03% 🔼)
220/225
🟢 Lines
99.78% (-0.22% 🔻)
901/903
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / AlreadyExistingKeyError.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 utils/keypath.ts
95.74% (-4.26% 🔻)
93.1% (-6.9% 🔻)
100%
95.74% (-4.26% 🔻)

Test suite run success

512 tests passing in 25 suites.

Report generated by 🧪jest coverage report action from 454927d

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Coverage report for ./packages/ot-server

St.
Category Percentage Covered / Total
🟡 Statements 70.97% 22/31
🔴 Branches 20% 1/5
🟡 Functions 75% 6/8
🟡 Lines 68.97% 20/29

Test suite run success

4 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 454927d

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Coverage report for ./packages/collaboration-manager

St.
Category Percentage Covered / Total
🟢 Statements 92.51% 358/387
🟢 Branches 85.51% 118/138
🟢 Functions 98.15% 53/54
🟢 Lines 92.41% 353/382

Test suite run success

117 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 454927d

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Coverage report for ./packages/core

St.
Category Percentage Covered / Total
🟢 Statements 100% 129/129
🟢 Branches 100% 46/46
🟢 Functions 100% 27/27
🟢 Lines 100% 120/120

Test suite run success

74 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 454927d

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

⏭️ No files to mutate for ./packages/model

…taNode

- Add insert() to keypath utils: splices a value into an array at the
  given index, shifting existing elements right (symmetric with remove())
- Update BlockNode.createDataNode to detect the parent container type:
  * Array parent → insert() (splice in, no duplicate guard)
  * Object parent → existing has() guard + set() semantics
- Add tests for insert() in keypath.spec.ts (8 cases)
- Add tests for array-insert behavior in BlockNode.spec.ts (3 cases)
Base automatically changed from fix/inputs-registration to main May 5, 2026 00:21
Comment thread packages/model/src/entities/BlockNode/BlockNode.spec.ts
Comment thread packages/model/src/entities/BlockNode/BlockNode.spec.ts Outdated
Comment thread packages/model/src/entities/BlockNode/BlockNode.spec.ts Outdated
Comment thread packages/model/src/entities/BlockNode/BlockNode.spec.ts
Comment thread packages/model/src/entities/BlockNode/BlockNode.spec.ts
Comment thread packages/model/src/entities/BlockNode/BlockNode.spec.ts
@gohabereg gohabereg requested a review from Copilot May 5, 2026 19:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the model’s “keypath” support so BlockNode write operations can target nested paths (e.g. meta.url, items.0.content) and array indexes, aligning write behavior with existing keypath-based reads.

Changes:

  • Expanded keypath utilities to support array insertion (insert) and keypath deletion (remove), and broadened set typing to support recursion through arrays/objects.
  • Updated BlockNode write paths to use keypath-aware operations (set, insert, remove) and introduced an error for duplicate key creation.
  • Added/updated unit tests to cover nested object paths, array index paths, and event emission behavior; added root build/test workspace scripts.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/model/src/utils/keypath.ts Adds insert/remove helpers and updates set typing to support keypath writes into nested structures/arrays.
packages/model/src/utils/keypath.spec.ts Adds tests for insert/remove and updates imports; adjusts test coverage around keypath behavior.
packages/model/src/entities/BlockNode/index.ts Switches write operations to keypath-aware utils and throws on duplicate key creation for non-array parents.
packages/model/src/entities/BlockNode/errors/AlreadyExistingKeyError.ts Introduces a dedicated error type for duplicate createDataNode keys.
packages/model/src/entities/BlockNode/BlockNode.spec.ts Adds tests for nested keypaths, array index paths, and expected event behavior/error throwing.
packages/core/src/components/BlockRenderer.ts Adds a TODO note related to adapter memory cleanup.
package.json Adds root build and test scripts for all workspaces.
Comments suppressed due to low confidence (1)

packages/model/src/utils/keypath.spec.ts:76

  • This describe('remove()') block contains set() tests (calls set(...) throughout). It looks like the suite name was accidentally changed from set() to remove(), which makes the test output misleading and duplicates the real remove() suite later in the file.
  describe('remove()', () => {
    it('should do nothing if no key passed', () => {
      const object = {};

      set(object, [], value);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +75 to +84
const lastKey = parsedKeys.pop()!;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- unknown can't be used as data parameter is used for recursion
const parent = get<any[]>(data, parsedKeys);

if (!Array.isArray(parent)) {
return;
}

parent.splice(Number(lastKey), 0, value);
}
Comment on lines +102 to +113
const lastKey = parsedKeys.pop()!;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- unknown can't be used as data parameter is used for recursion
const parent = get<Record<string | number, any>>(data, parsedKeys);

if (parent === undefined || parent === null) {
return;
}

if (Array.isArray(parent)) {
parent.splice(Number(lastKey), 1);
} else {
delete parent[lastKey];
* @param key - data key existing node
*/
constructor(key: DataKey) {
super(`BlockNode: data with key "${key}" already not exists`);
Copy link
Copy Markdown
Member

@ilyamore88 ilyamore88 left a comment

Choose a reason for hiding this comment

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

Two minor requests. But I’m fine to approve it.

Comment on lines +3 to +5
/**
*
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doc

});
});

describe('remove()', () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You created remove() block twice

@gohabereg gohabereg requested review from e11sy and neSpecc May 7, 2026 16:35
@gohabereg gohabereg added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit 7478236 May 7, 2026
24 checks passed
@gohabereg gohabereg deleted the feature/keypath-support branch May 7, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants