| 450 | */ |
| 451 | // deno-lint-ignore no-explicit-any |
| 452 | export class Application<AS extends State = Record<string, any>> |
| 453 | extends EventTarget { |
| 454 | #composedMiddleware?: (context: Context<AS, AS>) => Promise<unknown>; |
| 455 | #contextOptions: Pick< |
| 456 | ApplicationOptions<AS, ServerRequest>, |
| 457 | "jsonBodyReplacer" | "jsonBodyReviver" |
| 458 | >; |
| 459 | #contextState: "clone" | "prototype" | "alias" | "empty"; |
| 460 | #keys?: KeyStack; |
| 461 | #middleware: MiddlewareOrMiddlewareObject<State, Context<State, AS>>[] = []; |
| 462 | #serverConstructor: ServerConstructor<ServerRequest> | undefined; |
| 463 | |
| 464 | /** A set of keys, or an instance of `KeyStack` which will be used to sign |
| 465 | * cookies read and set by the application to avoid tampering with the |
| 466 | * cookies. */ |
| 467 | get keys(): KeyStack | Key[] | undefined { |
| 468 | return this.#keys; |
| 469 | } |
| 470 | |
| 471 | set keys(keys: KeyStack | Key[] | undefined) { |
| 472 | if (!keys) { |
| 473 | this.#keys = undefined; |
| 474 | return; |
| 475 | } else if (Array.isArray(keys)) { |
| 476 | this.#keys = new KeyStack(keys); |
| 477 | } else { |
| 478 | this.#keys = keys; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | /** If `true`, proxy headers will be trusted when processing requests. This |
| 483 | * defaults to `false`. */ |
| 484 | proxy: boolean; |
| 485 | |
| 486 | /** Generic state of the application, which can be specified by passing the |
| 487 | * generic argument when constructing: |
| 488 | * |
| 489 | * const app = new Application<{ foo: string }>(); |
| 490 | * |
| 491 | * Or can be contextually inferred based on setting an initial state object: |
| 492 | * |
| 493 | * const app = new Application({ state: { foo: "bar" } }); |
| 494 | * |
| 495 | * When a new context is created, the application's state is cloned and the |
| 496 | * state is unique to that request/response. Changes can be made to the |
| 497 | * application state that will be shared with all contexts. |
| 498 | */ |
| 499 | state: AS; |
| 500 | |
| 501 | constructor(options: ApplicationOptions<AS, ServerRequest> = {}) { |
| 502 | super(); |
| 503 | const { |
| 504 | state, |
| 505 | keys, |
| 506 | proxy, |
| 507 | serverConstructor, |
| 508 | contextState = "clone", |
| 509 | logErrors = true, |
nothing calls this directly
no test coverage detected