Skip to content

fix: avoid re-stringify per await by single-pass parse#5

Open
bas080 wants to merge 14 commits intomasterfrom
improve-await-parse
Open

fix: avoid re-stringify per await by single-pass parse#5
bas080 wants to merge 14 commits intomasterfrom
improve-await-parse

Conversation

@bas080
Copy link
Copy Markdown
Owner

@bas080 bas080 commented Apr 6, 2026

This PR changes parse.mjs to use a single JSON.parse pass with an explicit await marker. It avoids repeated JSON stringify/parse cycles for awaited sub-programs and keeps plain promise values intact unless explicitly awaited.

bas080 added 14 commits April 6, 2026 01:34
- stringify(program, leafSerializer) accepts custom leaf serialization
- parse(program, leafDeserializer) accepts custom leaf deserialization
- leaf values wrapped as ['leaf', serializedString] nodes
- supports Date, RegExp, BigInt, Set, Map, and undefined via superjson
- preserves undefined in objects using internal sentinel mechanism
- simplify defaultLeafDeserializer to remove unreachable branch
- add test for default deserializer when not provided
- add test for fallback to default deserializer when null passed
- add test to exercise defensive undefined parameter handling
- achieves 100% branch coverage
- remove unused Symbol('replaced') that was vestigial from replacer pattern
- move awaitId tracking into state object passed to transformValue
- reset awaitId per stringify() call for proper isolation
- simplifies code path and removes global mutable state per-call
- JSON.parse reviver can only receive null (not undefined)
- replace isNil(value) with direct null check
- remove unused is-nil import
- document transformValue behavior for stringify
- document resolveAwaitedValues behavior for parse
- document restoreUndefined purpose
- improve code readability through strategic comments
document the leaf (de)serializer API:
- explain default JSON limitation
- show how to extend with superjson
- provide complete example with Date, RegExp, BigInt, Map, Set
- clarify leaf wrapper format for safety
- add test to verify ['leaf', 1, 2, 3] is properly quoted and unquoted
- fix: add 'leaf' to keywords list so it's quoted when appearing as array data
- ensures leaf marker is not confused with actual leaf data
…e coverage

- Added getTypeInfo() helper for better error messages
- Improved assertion messages with type information
- Added property test for type distinctness (different primitives have different serializations)
- Added property test for serialization stability (idempotence)
- Better error handling and reporting in all property tests
- Now running 6 property tests with comprehensive coverage
- All 60 tests passing
- Converted all source files (.mjs) to TypeScript (.ts) in src/ directory
- Converted all test files (.test.mjs) to TypeScript (.test.ts) in test/ directory
- Set up TypeScript build configuration with tsconfig.json
- Added proper types and type safety throughout the codebase
- Updated package.json with TypeScript build scripts
- Configured ES2022 target and ESM module resolution
- All 61 tests passing
- Added type definitions for better IDE support and type checking
- Builds to dist/ directory with declaration files (.d.ts)
- Maintains full backward compatibility with ESM exports
- Ready for publication with TypeScript support
- Removed all old .mjs source and test files (now using TypeScript)
- Updated package.json for proper npm packaging:
  - Added 'bin' entry for CLI tool (sendscript command)
  - Added 'files' field to specify publishable content
  - Added 'engines' field requiring Node >= 18
  - Added 'typescript' keyword
  - Enhanced 'prepublishOnly' to run tests before publishing
  - Added 'test:watch' script for development
- Created .npmignore to exclude source/dev files from npm package
- Made dist/cli.js executable
- Verified all 61 tests passing
- Ready for npm release with proper TypeScript support and CLI entry point
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