Skip to content

enhance(rest): Support wildcard path params as arrays for path-to-regexp v8#3771

Merged
ntucker merged 2 commits into
masterfrom
path-to-regexp-v8-types
Mar 6, 2026
Merged

enhance(rest): Support wildcard path params as arrays for path-to-regexp v8#3771
ntucker merged 2 commits into
masterfrom
path-to-regexp-v8-types

Conversation

@ntucker
Copy link
Copy Markdown
Collaborator

@ntucker ntucker commented Mar 6, 2026

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/rest did not account for this — wildcards were typed as string | number and the runtime url() method stringified all values, breaking array params.

Solution

Types (pathTypes.ts): Simplified from 14 to 11 type helpers by unifying ParamSplits/WildcardSplits into a single Splits<S, M> generic. Wildcard keys are tagged with * prefix internally, which KeyVal uses to determine string[] vs string | number, and KeyName strips 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 calling String() on them, passing them through to compile() as path-to-regexp v8 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 in types.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.path with path-to-regexp v8 semantics, notably making *wildcard path params compile from string[] (including optional wildcards) and updating shortenPath() to strip the last :param or *wildcard when 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.

…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
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 6, 2026

⚠️ No Changeset found

Latest commit: 9a8bfe0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 3 packages
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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

Size Change: +32 B (+0.04%)

Total Size: 80.4 kB

Filename Size Change
examples/test-bundlesize/dist/rdcEndpoint.js 6.33 kB +32 B (+0.51%)
ℹ️ View Unchanged
Filename Size
examples/test-bundlesize/dist/App.js 3.18 kB
examples/test-bundlesize/dist/polyfill.js 307 B
examples/test-bundlesize/dist/rdcClient.js 10.2 kB
examples/test-bundlesize/dist/react.js 59.7 kB
examples/test-bundlesize/dist/webpack-runtime.js 726 B

compressed-size-action

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.05%. Comparing base (48c1fb4) to head (9a8bfe0).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/rest/src/pathTypes.ts
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
@ntucker ntucker merged commit b22fcd3 into master Mar 6, 2026
24 checks passed
@ntucker ntucker deleted the path-to-regexp-v8-types branch March 6, 2026 15:34
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