fix: resolve build errors in metadata and client-react packages#642
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Fix TS6133 unused 'type' param in MetadataManager.validate()
- Fix TS2416 watch() signature conflict with IMetadataService contract
- Fix PaginatedResult property references (count→total, value→records)
- Fix getObject→getItem('object', name) in metadata-hooks
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes TypeScript build errors across @objectstack/metadata and @objectstack/client-react by aligning method names with contract types and updating client-side pagination/metadata access to match the current @objectstack/client response shapes.
Changes:
- Update
MetadataManagerinternals to avoid a type conflict with theIMetadataService.watch?contract and fix an unused parameter warning. - Update React client hooks to use the current pagination fields (
total,records) and metadata fetch API (getItem). - Adjust metadata tests to use the renamed internal watch-callback helpers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/metadata/src/metadata.test.ts | Updates watch/unwatch tests to call the renamed internal watch-callback helpers. |
| packages/metadata/src/metadata-manager.ts | Renames internal watch/unwatch helpers and silences an unused validate parameter warning. |
| packages/client-react/src/metadata-hooks.tsx | Switches object fetch to client.meta.getItem('object', name) for the non-cached path. |
| packages/client-react/src/data-hooks.tsx | Updates pagination field usage to total/records to match PaginatedResult. |
| @@ -623,7 +623,7 @@ export class MetadataManager implements IMetadataService { | |||
| * Validate a metadata item against its type schema. | |||
There was a problem hiding this comment.
validate() JSDoc says it validates “against its type schema”, but the implementation doesn’t use type at all (now _type) and only performs basic structural checks. Either implement type-based validation (e.g., via the registered type registry) or update the comment/parameter name to avoid implying schema validation.
| * Validate a metadata item against its type schema. | |
| * Perform basic structural validation for a metadata item. | |
| * Ensures the payload is a non-null object with a name field and optional label. |
| // Determine if there's a next page | ||
| const fetchedCount = result.value?.length ?? 0; | ||
| const fetchedCount = result.records?.length ?? 0; | ||
| const hasMore = fetchedCount === pageSize; |
There was a problem hiding this comment.
useInfiniteQuery computes hasMore purely from records.length === pageSize, but PaginatedResult also supports a server-provided hasMore flag. If the backend returns hasMore: false while still returning a full page, this hook will incorrectly keep enabling “load more”. Prefer honoring result.hasMore when present (fallback to the length check otherwise).
| const hasMore = fetchedCount === pageSize; | |
| const hasMore = | |
| typeof result.hasMore === 'boolean' ? result.hasMore : fetchedCount === pageSize; |
| @@ -207,8 +207,8 @@ describe('MetadataManager', () => { | |||
|
|
|||
| it('should unwatch callback', () => { | |||
| const callback = vi.fn(); | |||
| manager.watch('object', callback); | |||
| manager.unwatch('object', callback); | |||
| (manager as any).addWatchCallback('object', callback); | |||
| (manager as any).removeWatchCallback('object', callback); | |||
There was a problem hiding this comment.
This test suite is still labeled "watch / unwatch" but it now exercises addWatchCallback / removeWatchCallback. Renaming the describe/it titles to match the current API will keep test intent clear (especially since watch/unwatch no longer exist on MetadataManager).
DTS build fails in
@objectstack/metadataand@objectstack/client-reactdue to type mismatches against updated spec contracts.@objectstack/metadatatypeparam invalidate()→_typewatch(type, callback: WatchCallback): voidconflicts withIMetadataService.watch?which expectsMetadataWatchCallback → MetadataWatchHandle. Renamed internal methods toaddWatchCallback/removeWatchCallback(protected) to eliminate the signature clash.watchService()already implements the contract correctly and now calls the renamed internals.@objectstack/client-reactPaginatedResult<T>was refactored to userecords/totalbutdata-hooks.tsxstill referenced oldvalue/countpropertiesmetadata-hooks.tsxcalled non-existentclient.meta.getObject()→client.meta.getItem('object', name)💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.