Skip to content

Add dynamic param suport for .prefix #914

Description

@dinwwwh

Describe the feature

Current limitations for generating specs and accessing dynamic parameters:

  1. For generating specs: Instead of requiring dynamic parameters to exist in the .input schema, we can assume they expect a string type when we cannot infer it from the .input schema.

  2. For accessing parameters: We can inject them into the context and access them through a unique symbol:

const router = os.prefix('/{organizationId}').use(({ next, context }) => {
    const organizationId: string | undefined = getDynamicParams(context).organizationId
    return next()
}).router({
    // ...
})

Warning

This draft is still missing some important things:

  • How RPC stubs works (because RPC has no definitions for params) from client to server
  • How client works? where to define there params when invoke?
  • Because .prefix only effect procedure with defined paths inside .route, how does it work in this case?
  • ... Personally, I think this shouldn't be implemented in oRPC. If you require parameters for the entire router, why not put them in the headers? If you still need this kind of feature, you can combine it with a third-party router like Hono for the dynamic params part.

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions