feat(stax-xml): add synchronous cursor reader API#3
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 100f47e99f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| name, | ||
| localName: typedInfo.localName, | ||
| prefix: typedInfo.prefix, |
There was a problem hiding this comment.
Derive cursor attribute fields from qualified name
When AttrStore.fromEvent reads event.attributesWithPrefix, it assumes each value already contains localName and that the entry key is the full attribute name. For StartElementEvents produced by the existing async parser, the map is keyed by local name and values do not include localName, so XmlCursorEvent ends up with CursorAttribute.localName as undefined and drops prefixes from name (for example, a:id becomes id), which also breaks getAttributeValue('a:id') lookups when wrapping those events.
Useful? React with 👍 / 👎.
Motivation
read()/hasNext()control over the existing iterable parser.StaxXmlParserSyncimplementation to avoid changing existing parser constructors or behavior.Description
StaxXmlCursorReaderSyncwith a factorycreateStaxXmlCursorReaderSyncthat wrapsStaxXmlParserSyncand exposeshasNext(),read(),getEvent(), andrequireEvent()methods (packages/stax-xml/src/StaxXmlCursorReaderSync.ts).XmlCursorEventand internalAttrStoremodules to provide cursor-friendly accessors for event fields and attributes (packages/stax-xml/src/XmlCursorEvent.ts,packages/stax-xml/src/AttrStore.ts).CursorXmlEventType,CursorAttribute,XmlCursorEventLike, andXmlCursorReaderSyncLike(packages/stax-xml/src/types.ts).packages/stax-xml/src/index.ts).packages/stax-xml/test/cursor-reader-sync.test.ts,README.md,packages/stax-xml/README.md).Testing
tsc -p packages/stax-xml/tsconfig.json --noEmit, which completed successfully. ✅vitestfor the new cursor tests via./node_modules/.bin/vitest run packages/stax-xml/test/cursor-reader-sync.test.ts, which passed (2 tests). ✅./node_modules/.bin/vitest run packages/stax-xml/test/parser-sync.test.ts, which passed (29 tests). ✅pnpm --filter=stax-xml testfailed due to environment network/corepack fetch error; this is unrelated to the code changes.Codex Task