| 265 | * @category tags |
| 266 | */ |
| 267 | export const Tag = <Self>(): < |
| 268 | const Name extends string, |
| 269 | const Options extends { |
| 270 | readonly optional?: boolean |
| 271 | readonly failure?: Schema.Schema.All |
| 272 | readonly provides?: Context.Tag<any, any> |
| 273 | readonly security?: Record<string, HttpApiSecurity.HttpApiSecurity> |
| 274 | } |
| 275 | >( |
| 276 | id: Name, |
| 277 | options?: Options | undefined |
| 278 | ) => TagClass<Self, Name, Options> => |
| 279 | ( |
| 280 | id: string, |
| 281 | options?: { |
| 282 | readonly optional?: boolean |
| 283 | readonly security?: Record<string, HttpApiSecurity.HttpApiSecurity> |
| 284 | readonly failure?: Schema.Schema.All |
| 285 | readonly provides?: Context.Tag<any, any> |
| 286 | } |
| 287 | ) => { |
| 288 | const Err = globalThis.Error as any |
| 289 | const limit = Err.stackTraceLimit |
| 290 | Err.stackTraceLimit = 2 |
| 291 | const creationError = new Err() |
| 292 | Err.stackTraceLimit = limit |
| 293 | |
| 294 | function TagClass() {} |
| 295 | const TagClass_ = TagClass as any as Mutable<TagClassSecurityAny> |
| 296 | Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.GenericTag<Self, any>(id))) |
| 297 | TagClass.key = id |
| 298 | Object.defineProperty(TagClass, "stack", { |
| 299 | get() { |
| 300 | return creationError.stack |
| 301 | } |
| 302 | }) |
| 303 | TagClass_[TypeId] = TypeId |
| 304 | TagClass_.failure = options?.optional === true || options?.failure === undefined ? Schema.Never : options.failure |
| 305 | if (options?.provides) { |
| 306 | TagClass_.provides = options.provides |
| 307 | } |
| 308 | TagClass_.optional = options?.optional ?? false |
| 309 | if (options?.security) { |
| 310 | if (Object.keys(options.security).length === 0) { |
| 311 | throw new Error("HttpApiMiddleware.Tag: security object must not be empty") |
| 312 | } |
| 313 | TagClass_[SecurityTypeId] = SecurityTypeId |
| 314 | TagClass_.security = options.security |
| 315 | } |
| 316 | return TagClass as any |
| 317 | } |