(
self: HttpApi<Id, Groups>,
options: {
readonly predicate?:
| Predicate.Predicate<{
readonly endpoint: HttpApiEndpoint.Top
readonly group: HttpApiGroup.Top
}>
| undefined
readonly onGroup: (options: {
readonly group: HttpApiGroup.Top
readonly mergedAnnotations: Context.Context<never>
}) => void
readonly onEndpoint: (options: {
readonly group: HttpApiGroup.Top
readonly endpoint: HttpApiEndpoint.Top
readonly mergedAnnotations: Context.Context<never>
readonly middleware: ReadonlySet<HttpApiMiddleware.AnyService>
readonly successes: ReadonlyMap<number, readonly [Schema.Top, ...Array<Schema.Top>]>
readonly errors: ReadonlyMap<number, readonly [Schema.Top, ...Array<Schema.Top>]>
}) => void
}
)
| 244 | * @since 4.0.0 |
| 245 | */ |
| 246 | export const reflect = <Id extends string, Groups extends HttpApiGroup.Constraint>( |
| 247 | self: HttpApi<Id, Groups>, |
| 248 | options: { |
| 249 | readonly predicate?: |
| 250 | | Predicate.Predicate<{ |
| 251 | readonly endpoint: HttpApiEndpoint.Top |
| 252 | readonly group: HttpApiGroup.Top |
| 253 | }> |
| 254 | | undefined |
| 255 | readonly onGroup: (options: { |
| 256 | readonly group: HttpApiGroup.Top |
| 257 | readonly mergedAnnotations: Context.Context<never> |
| 258 | }) => void |
| 259 | readonly onEndpoint: (options: { |
| 260 | readonly group: HttpApiGroup.Top |
| 261 | readonly endpoint: HttpApiEndpoint.Top |
| 262 | readonly mergedAnnotations: Context.Context<never> |
| 263 | readonly middleware: ReadonlySet<HttpApiMiddleware.AnyService> |
| 264 | readonly successes: ReadonlyMap<number, readonly [Schema.Top, ...Array<Schema.Top>]> |
| 265 | readonly errors: ReadonlyMap<number, readonly [Schema.Top, ...Array<Schema.Top>]> |
| 266 | }) => void |
| 267 | } |
| 268 | ) => { |
| 269 | const groups = Object.values(self.groups) as any as Array<HttpApiGroup.Top> |
| 270 | for (const group of groups) { |
| 271 | const groupAnnotations = Context.merge(self.annotations, group.annotations) |
| 272 | options.onGroup({ |
| 273 | group, |
| 274 | mergedAnnotations: groupAnnotations |
| 275 | }) |
| 276 | const endpoints = Object.values(group.endpoints) as Iterable<HttpApiEndpoint.Top> |
| 277 | for (const endpoint of endpoints) { |
| 278 | if ( |
| 279 | options.predicate && !options.predicate({ |
| 280 | endpoint, |
| 281 | group |
| 282 | } as any) |
| 283 | ) continue |
| 284 | |
| 285 | options.onEndpoint({ |
| 286 | group, |
| 287 | endpoint, |
| 288 | middleware: endpoint.middlewares as any, |
| 289 | mergedAnnotations: Context.merge(groupAnnotations, endpoint.annotations), |
| 290 | successes: extractResponseContent( |
| 291 | HttpApiEndpoint.getSuccessSchemas(endpoint), |
| 292 | HttpApiSchema.getStatusSuccessSchema |
| 293 | ), |
| 294 | errors: extractResponseContent( |
| 295 | HttpApiEndpoint.getErrorSchemas(endpoint), |
| 296 | HttpApiSchema.getStatusErrorSchema |
| 297 | ) |
| 298 | }) |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | // ------------------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected