Enable full keypath support for write operations#132
Conversation
…nputs-registration
…nputs-registration
|
⏭️ No files to mutate for |
Coverage report for
|
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
|
⏭️ No files to mutate for |
Coverage report for
|
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
Coverage report for
|
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
Coverage report for
|
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
Coverage report for
|
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
|
⏭️ No files to mutate for |
…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)
…re/keypath-support
There was a problem hiding this comment.
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
keypathutilities to support array insertion (insert) and keypath deletion (remove), and broadenedsettyping to support recursion through arrays/objects. - Updated
BlockNodewrite 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/testworkspace 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 containsset()tests (callsset(...)throughout). It looks like the suite name was accidentally changed fromset()toremove(), which makes the test output misleading and duplicates the realremove()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.
| 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); | ||
| } |
| 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`); |
ilyamore88
left a comment
There was a problem hiding this comment.
Two minor requests. But I’m fine to approve it.
| /** | ||
| * | ||
| */ |
| }); | ||
| }); | ||
|
|
||
| describe('remove()', () => { |
There was a problem hiding this comment.
You created remove() block twice
All BlockNode operations now support keypath: