MCPcopy Create free account
hub / github.com/middleapi/orpc / populateContractRouterPaths

Function populateContractRouterPaths

packages/contract/src/router-utils.ts:126–154  ·  view source on GitHub ↗
(router: T, options: PopulateContractRouterPathsOptions = {})

Source from the content-addressed store, hash-verified

124 * @see {@link https://orpc.dev/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
125 */
126export function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options: PopulateContractRouterPathsOptions = {}): PopulatedContractRouterPaths<T> {
127 const path = toArray(options.path)
128
129 if (isContractProcedure(router)) {
130 if (router['~orpc'].route.path === undefined) {
131 return new ContractProcedure({
132 ...router['~orpc'],
133 route: {
134 ...router['~orpc'].route,
135 path: toHttpPath(path),
136 },
137 }) as any
138 }
139
140 return router as any
141 }
142
143 if (typeof router !== 'object' || router === null) {
144 return router as any
145 }
146
147 const populated: Record<string, any> = {}
148
149 for (const key in router) {
150 populated[key] = populateContractRouterPaths(router[key]!, { ...options, path: [...path, key] })
151 }
152
153 return populated as any
154}

Callers 1

Calls 3

toArrayFunction · 0.90
isContractProcedureFunction · 0.90
toHttpPathFunction · 0.90

Tested by

no test coverage detected