enhance(rest): Support wildcard path params as arrays for path-to-regexp v8#3771
Conversation
…exp v8 Wildcard `*name` params now correctly typed as `string[]` and handled at runtime. Simplifies path type helpers from 14 to 11 types using unified `Splits<S, M>` generic with `KeyName`/`KeyVal` helpers. Made-with: Cursor
|
| Name | Type |
|---|---|
| @data-client/rest | Minor |
| test-bundlesize | Patch |
| coinbase-lite | Patch |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
|
Size Change: +32 B (+0.04%) Total Size: 80.4 kB
ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3771 +/- ##
=======================================
Coverage 98.05% 98.05%
=======================================
Files 151 151
Lines 2831 2832 +1
Branches 554 554
=======================================
+ Hits 2776 2777 +1
Misses 11 11
Partials 44 44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
ShortenPath type and runtime shortenPath now handle *wildcard as the last token, so resource() correctly strips wildcards for getList/create paths. Updated docs for RestEndpoint, resource, hookifyResource, blog post, and changeset to document string[] typing for wildcard params. Made-with: Cursor
Motivation
path-to-regexp v8 changed repeating/wildcard params (
*name) to require array values instead of strings. The existing type system and runtime code in@data-client/restdid not account for this — wildcards were typed asstring | numberand the runtimeurl()method stringified all values, breaking array params.Solution
Types (
pathTypes.ts): Simplified from 14 to 11 type helpers by unifyingParamSplits/WildcardSplitsinto a singleSplits<S, M>generic. Wildcard keys are tagged with*prefix internally, whichKeyValuses to determinestring[]vsstring | number, andKeyNamestrips for the final property name. Correctly handles required vs optional wildcards, quoted params, escaped characters, and adjacency edge cases.Runtime (
RestEndpoint.js):url()now preserves array values for wildcard params instead of callingString()on them, passing them through tocompile()aspath-to-regexpv8 expects.Tests: Added 4 runtime tests for wildcard URL generation (required, mixed with params, optional, optional with required param). Updated type tests with comprehensive wildcard/v8 assertions (214 type assertions in
pathTypes.test.ts, 182 new lines intypes.test.ts).Open questions
N/A
Made with Cursor
Note
Medium Risk
Touches core URL construction and type inference for
RestEndpoint.path/resource()paths, which can break existing wildcard usage and path-templating edge cases. Risk is mitigated by expanded runtime and TypeScript test coverage.Overview
Aligns
RestEndpoint.path/Resource.pathwithpath-to-regexpv8 semantics, notably making*wildcardpath params compile fromstring[](including optional wildcards) and updatingshortenPath()to strip the last:paramor*wildcardwhen deriving list/create paths.Updates the path type-level parser (
PathKeys/PathArgs/PathArgsAndSearch) to correctly infer wildcard arrays, optional groups, quoted names, escapes, and adjacency edge cases, and adds/updates runtime + TS tests plus migration/docs notes (changeset, REST docs, and release blog) to reflect the new v8 syntax and escaping rules.Written by Cursor Bugbot for commit 9a8bfe0. This will update automatically on new commits. Configure here.