Skip to content

fix(util): make objectOfArraysAsArrayOfObjects work with native array methods#610

Merged
sroussey merged 1 commit into
mainfrom
fix/object-of-arrays-proxy-has-trap
Jul 3, 2026
Merged

fix(util): make objectOfArraysAsArrayOfObjects work with native array methods#610
sroussey merged 1 commit into
mainfrom
fix/object-of-arrays-proxy-has-trap

Conversation

@sroussey

@sroussey sroussey commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Problem

The objectOfArraysAsArrayOfObjects proxy backs onto an empty [], so HasProperty for a numeric index returned false. Native array methods that probe presence (slice, concat, at, flat, …) therefore treated every row as an absent hole and silently dropped the data:

const p = objectOfArraysAsArrayOfObjects({ a: [1,2,3,4], b: ["w","x","y","z"] });
p.slice(0, 2)        // -> [ 2 x empty items ]  (sparse!)
[...p.slice(0, 2)]   // -> [ undefined, undefined ]
p.map(r => r.a)      // -> [1,2,3,4]  (map is explicitly implemented, so it worked)

This surfaced downstream in @workglow/sec, where StoreSubmissionFilingsTask sliced the proxy to batch filings and then spread the result into a bulk insert — every filing became an undefined row and the insert crashed, storing zero filings. (That caller has its own fix; this is the root cause.)

Fix

  • Add a has trap that reports in-range numeric indices (and length) as present, so native methods that rely on HasProperty see real rows.
  • Implement slice explicitly, mirroring the file's other materializing methods (map/filter/forEach/…) and guarding the exact method that regressed.

Test

Regression cases (slice returns dense rows, the in operator, at/concat) added to the existing proxy suite in the dedicated @workglow/test package (packages/test/src/test/util/arrayAsObjectProxy.test.ts) — 14 pass against a freshly built @workglow/util.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BNNJyBunCkJhiUhdM9ys7V

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 62.83% 25680 / 40872
🔵 Statements 62.66% 26569 / 42400
🔵 Functions 64.03% 4874 / 7612
🔵 Branches 51.56% 12590 / 24416
File CoverageNo changed files found.
Generated in workflow #2647 for commit e84daf2 by the Vitest Coverage Report Action

… methods

The proxy backs onto an empty `[]`, so `HasProperty` for a numeric index
returned false. Native array methods that probe presence (`slice`, `concat`,
`at`, `flat`, ...) therefore treated every row as an absent hole and silently
dropped the data — e.g. `proxy.slice(0, 2)` returned a sparse array whose
spread became `[undefined, undefined]`.

Add a `has` trap that reports in-range indices (and `length`) as present, and
implement `slice` explicitly to mirror the existing materializing methods.
Regression cases (slice, the `in` operator, at/concat) added to the existing
proxy suite in @workglow/test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BNNJyBunCkJhiUhdM9ys7V
@sroussey sroussey force-pushed the fix/object-of-arrays-proxy-has-trap branch from ba333e7 to e84daf2 Compare July 3, 2026 05:20
@sroussey sroussey merged commit f863734 into main Jul 3, 2026
12 checks passed
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.

1 participant