-
Notifications
You must be signed in to change notification settings - Fork 4
Midnight v1 – 03 Auto Simple View Rendering #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: midnight/02-ingestion
Are you sure you want to change the base?
Conversation
…atibility - Patch @midnight-ntwrk/compact-runtime for Node.js polyfills - Patch @midnight-ntwrk/midnight-js-indexer-public-data-provider for Apollo Client ESM, cross-fetch, and Network ID module singleton - Patch @midnight-ntwrk/midnight-js-network-id for peer dependency - Patch @midnight-ntwrk/midnight-js-types for peer dependency - Patch @midnight-ntwrk/midnight-js-utils for peer dependency - Add tsup.config.ts external WASM packages configuration - Add comprehensive documentation in MIDNIGHT-SDK-PATCHES.md
…tion validation - Move getWalletConfigIfAvailable to configuration module for proper alignment - Consolidate provider configuration logic in query handler - Add view function validation (isViewFunction check) and early address validation - Implement RPC endpoint precedence: user override > wallet config > network config - Add network ID handling with numeric mapping support - Add derivation logic for indexer URIs from RPC endpoints as fallback - Update network config type to include networkId enum value - Align query handler pattern with EVM and Stellar adapters This completes Phase 5 (US3) for auto-rendering simple view functions with proper validation and wallet privacy preference integration.
… functions Add 56 unit tests covering Phase 5 (US3) - Auto Simple View Rendering: - View Function Validation (12 tests) ✓ Identifies read-only vs state-modifying functions ✓ Handles parameter-less and parameterized views ✓ Detects edge cases (empty functions, complex types, options) - Query Handler Input Validation (8 tests) ✓ Validates contract schema structure ✓ Verifies address format detection ✓ Tests function existence checks and view-only enforcement - Output Formatter (36 tests) ✓ Primitives (numbers, strings, booleans) display without quotes ✓ BigInt values formatted correctly ✓ Null/undefined handling ✓ Complex types (arrays, objects, nested structures) ✓ Error handling and edge cases All tests follow Vitest patterns and align with existing test infrastructure. Addresses Phase 5 requirements for defense-in-depth validation, view-function enforcement, and consistent output formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 48 out of 49 changed files in this pull request and generated 7 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
patches/@midnight-ntwrk__midnight-js-indexer-public-data-provider@2.0.2.patch
Outdated
Show resolved
Hide resolved
patches/@midnight-ntwrk__midnight-js-indexer-public-data-provider@2.0.2.patch
Outdated
Show resolved
Hide resolved
…[email protected] Co-authored-by: Copilot <[email protected]>
…[email protected] Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
… dangerous globals
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 48 out of 49 changed files in this pull request and generated 9 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
patches/@midnight-ntwrk__midnight-js-indexer-public-data-provider@2.0.2.patch
Show resolved
Hide resolved
…formatting, validation
Midnight Adapter: Auto Simple View Rendering
Overview
This PR implements Phase 5 (US3): Auto Simple View Rendering for the Midnight adapter, completing the core functionality for automatically rendering and querying read-only contract functions in the UI Builder.
Key Features
✅ View Function Validation
isMidnightViewFunction()checkqueryMidnightViewFunction()handler✅ Query Execution
ledger()function from compiled module✅ Output Formatting
✅ Configuration Management
getWalletConfigIfAvailable()relocated tosrc/configuration/provider.ts✅ Comprehensive Testing
Technical Highlights
Browser Compatibility
Module Resolution
NetworkIdoverride for module singleton workaroundnew Function()Validation Strategy
Files Changed
New Files
src/configuration/provider.ts- Wallet configuration retrievalsrc/validation/address.ts- Address validation logicsrc/validation/index.ts- Validation module barrelsrc/query/__tests__/view-checker.test.ts- View function tests (12 tests)src/query/__tests__/handler.test.ts- Handler validation tests (8 tests)src/transform/__tests__/output-formatter.test.ts- Output formatting tests (36 tests)Modified Files
src/adapter.ts- Updated to pass contract module to query handlersrc/query/handler.ts- Implemented complete query orchestration with provider setupsrc/query/executor.ts- Added ledger function dynamic loadingsrc/transform/output-formatter.ts- Centralized result formatting logicsrc/networks/testnet.ts- Added networkId configurationsrc/utils/index.ts- Removed address validation exportssrc/query/index.ts- Made executor/provider internaltsup.config.ts- External WASM packages configurationpackages/types/src/networks/config.ts- Extended MidnightNetworkConfig typeDeleted Files
src/query/provider.ts- Logic moved to handlersrc/utils/address-validation.ts- Moved to validation/address.tssrc/utils/__tests__/address-validation.test.ts- Moved to validation testsTesting
All 56 tests pass:
Commits
ad54ceea- test(adapter-midnight): add comprehensive Phase 5 unit tests for view functionsf0fe2a9b- chore(deps): update pnpm lock file6e313ad7- feat(adapter-midnight): consolidate provider config and add view function validation470202db- fix(adapter-midnight): add pnpm patches for Midnight SDK browser compatibilityRelated Issues
Closes #4 (Add Midnight Adapter)
Migration Notes
No breaking changes for consumers. The Phase 4 foundation is fully compatible with Phase 5 additions.
Next Steps