Skip to content
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

Add a way to access available param-matchers from inside a library #12094

Open
LorisSigrist opened this issue Apr 9, 2024 · 1 comment
Open

Comments

@LorisSigrist
Copy link
Contributor

Describe the problem

It's currently not possible to access the param-matcher-functions that are available in an App from inside a library. They need to be passed into the library by reference, one-by-one.

I have a library that requires access to the matcher-functions as it operates on routeIDs.

  • Having to pass matchers to the library one-by-one is cumbersome and error-prone since you're likely to forget to add new matchers
  • vite-glob-imports don't work since they don't respect kit.files.params

As discussed in: https://discord.com/channels/457912077277855764/1226858732223205497/1226858732223205497

Describe the proposed solution

A way to access the matcher-functions that are present in an app. For example an $app/matchers module where we can import the matcher functions from. Given that matchers are already shipped to the client this wouldn't make a meaningful bundle-size difference, it's just about exposing them.

Example:

import * as matchers from "$app/matchers"

matchers.int("123") // true
matchers.float("asd") //false

const availableMatchers = Object.keys(matchers) // ["int", "float", "uuid"]

Alternatives considered

Require library users to pass in matcher-functions one by one. This is awkward since they'er all exported as "match" and the matcher name is implicit from the filename.

import { init } from "some-library"
import { match as int } from "../params/int.js"
import { match as float } from "../params/float.js"

init({ matchers: { int, float }})

Importance

nice to have

Additional Information

No response

@david-plugge
Copy link
Contributor

david-plugge commented Apr 10, 2024

You can use globs here, but not in your library. The lib user has to glob all matchers and pass them into your entry function. Thats what im doing in such cases.
Its not the optimal solution, but still better than manually having to add all matchers one by one.

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

No branches or pull requests

2 participants