feat(resource): implement defineResource API (A2)#16
Merged
Conversation
…nt generation - Add defineResource<T, TQuery>(config) function - Implement comprehensive config validation (name, routes, methods) - Generate typed client methods (list, get, create, update, remove) - Add path interpolation for :id/:slug patterns - Generate store keys and cache key functions - Add 70 unit tests (29 interpolation + 41 defineResource) - Export resource system from kernel package - Add tsconfig.tests.json for test file type checking - Add typecheck:tests script and pre-commit hook Tests: 153 passing Build: ✓ TypeScript compilation successful Lint: ✓ ESLint passing TypeCheck: ✓ Source and test files Implements issue #2 (A2: defineResource Public API) Depends on #1 (A1: Result Types & Errors)
Contributor
There was a problem hiding this comment.
Pull Request Overview
Implements the A2: defineResource Public API as a core building block for the WP Kernel resource system. This adds comprehensive resource definition capabilities with type safety, validation, and automatic client generation for REST endpoints.
Key changes include:
- Core defineResource function with TypeScript generics for type-safe resource definitions
- Complete configuration validation using the KernelError system from A1
- Automatic generation of typed client methods (list, get, create, update, remove) based on configured routes
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/kernel/src/resource/types.ts | Complete TypeScript type definitions for resource system including config interfaces, client methods, and response types |
| packages/kernel/src/resource/interpolate.ts | REST path interpolation utilities for handling :id/:slug patterns with validation |
| packages/kernel/src/resource/defineResource.ts | Core defineResource function with config validation and client method generation |
| packages/kernel/src/resource/index.ts | Module exports for the resource system |
| packages/kernel/src/resource/tests/interpolate.test.ts | Comprehensive tests for path interpolation (29 tests) |
| packages/kernel/src/resource/tests/defineResource.test.ts | Extensive tests for resource definition and validation (41 tests) |
| packages/kernel/src/index.ts | Adds resource system exports to main kernel module |
| packages/kernel/tsconfig.tests.json | TypeScript configuration for test files |
| packages/kernel/package.json | Adds typecheck:tests script |
| package.json | Adds root-level typecheck:tests script |
| .husky/pre-commit | Updates pre-commit hook to include test file type checking |
| .changeset/define-resource-api.md | Changeset documenting the new feature |
| * @param config - Resource configuration to validate | ||
| * @throws DeveloperError if configuration is invalid | ||
| */ | ||
| function validateConfig<T, TQuery>(config: ResourceConfig<T, TQuery>): void { |
There was a problem hiding this comment.
[nitpick] The validateConfig function performs extensive validation on every defineResource call. Consider memoizing validation results for identical configurations or moving some checks to build time to improve runtime performance.
- Add detailed configuration reference (name, routes, cacheKeys) - Document generated client methods with examples - Explain TypeScript generics (T, TQuery) - Add validation & error handling section - Document path interpolation patterns - Add advanced patterns (nested resources, custom cache keys) - Include best practices & current limitations - Add cross-references to related docs
pipewrk
added a commit
that referenced
this pull request
Nov 8, 2025
feat(resource): implement defineResource API (A2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements A2: defineResource Public API with comprehensive resource definition, config validation, and typed client method generation.
Features
gk/{resourceName})Files Added
packages/kernel/src/resource/types.ts- Type definitions for resource systempackages/kernel/src/resource/interpolate.ts- Path parameter interpolationpackages/kernel/src/resource/defineResource.ts- Core defineResource functionpackages/kernel/src/resource/index.ts- Module exportspackages/kernel/src/resource/__tests__/interpolate.test.ts- 29 testspackages/kernel/src/resource/__tests__/defineResource.test.ts- 41 testspackages/kernel/tsconfig.tests.json- TypeScript config for test files.husky/pre-commit- Updated with test typecheckTests
Verification
Dependencies
Next Steps
After merge, continue to A3: Store Factory (issue #3)
Note
Client methods currently throw NotImplementedError - transport integration will be added in A3.
Closes #2