| 37 | } |
| 38 | |
| 39 | export class Builder< |
| 40 | TInitialContext extends Context, |
| 41 | TCurrentContext extends Context, |
| 42 | TInputSchema extends AnySchema, |
| 43 | TOutputSchema extends AnySchema, |
| 44 | TErrorMap extends ErrorMap, |
| 45 | TMeta extends Meta, |
| 46 | > { |
| 47 | /** |
| 48 | * This property holds the defined options. |
| 49 | */ |
| 50 | '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> |
| 51 | |
| 52 | constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>) { |
| 53 | this['~orpc'] = def |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Sets or overrides the config. |
| 58 | * |
| 59 | * @see {@link https://orpc.dev/docs/client/server-side#middlewares-order Middlewares Order Docs} |
| 60 | * @see {@link https://orpc.dev/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs} |
| 61 | */ |
| 62 | $config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> { |
| 63 | const inputValidationCount = this['~orpc'].inputValidationIndex - fallbackConfig('initialInputValidationIndex', this['~orpc'].config.initialInputValidationIndex) |
| 64 | const outputValidationCount = this['~orpc'].outputValidationIndex - fallbackConfig('initialOutputValidationIndex', this['~orpc'].config.initialOutputValidationIndex) |
| 65 | |
| 66 | return new Builder({ |
| 67 | ...this['~orpc'], |
| 68 | config, |
| 69 | dedupeLeadingMiddlewares: fallbackConfig('dedupeLeadingMiddlewares', config.dedupeLeadingMiddlewares), |
| 70 | inputValidationIndex: fallbackConfig('initialInputValidationIndex', config.initialInputValidationIndex) + inputValidationCount, |
| 71 | outputValidationIndex: fallbackConfig('initialOutputValidationIndex', config.initialOutputValidationIndex) + outputValidationCount, |
| 72 | }) |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Set or override the initial context. |
| 77 | * |
| 78 | * @see {@link https://orpc.dev/docs/context Context Docs} |
| 79 | */ |
| 80 | $context<U extends Context>(): Builder<U & Record<never, never>, U, TInputSchema, TOutputSchema, TErrorMap, TMeta> { |
| 81 | /** |
| 82 | * We need `& Record<never, never>` to deal with `has no properties in common with type` error |
| 83 | */ |
| 84 | |
| 85 | return new Builder({ |
| 86 | ...this['~orpc'], |
| 87 | middlewares: [], |
| 88 | inputValidationIndex: fallbackConfig('initialInputValidationIndex', this['~orpc'].config.initialInputValidationIndex), |
| 89 | outputValidationIndex: fallbackConfig('initialOutputValidationIndex', this['~orpc'].config.initialOutputValidationIndex), |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Sets or overrides the initial meta. |
| 95 | * |
| 96 | * @see {@link https://orpc.dev/docs/metadata Metadata Docs} |
nothing calls this directly
no outgoing calls
no test coverage detected