@nifrajs/core 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -0
  3. package/dist/errors.d.ts +21 -0
  4. package/dist/errors.d.ts.map +1 -0
  5. package/dist/errors.js +26 -0
  6. package/dist/errors.js.map +1 -0
  7. package/dist/index.d.ts +26 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +21 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/internal/brand.d.ts +11 -0
  12. package/dist/internal/brand.d.ts.map +1 -0
  13. package/dist/internal/brand.js +10 -0
  14. package/dist/internal/brand.js.map +1 -0
  15. package/dist/internal/secret.d.ts +9 -0
  16. package/dist/internal/secret.d.ts.map +1 -0
  17. package/dist/internal/secret.js +19 -0
  18. package/dist/internal/secret.js.map +1 -0
  19. package/dist/router/router.d.ts +61 -0
  20. package/dist/router/router.d.ts.map +1 -0
  21. package/dist/router/router.js +324 -0
  22. package/dist/router/router.js.map +1 -0
  23. package/dist/schema/standard.d.ts +46 -0
  24. package/dist/schema/standard.d.ts.map +1 -0
  25. package/dist/schema/standard.js +20 -0
  26. package/dist/schema/standard.js.map +1 -0
  27. package/dist/seo.d.ts +48 -0
  28. package/dist/seo.d.ts.map +1 -0
  29. package/dist/seo.js +109 -0
  30. package/dist/seo.js.map +1 -0
  31. package/dist/server/body.d.ts +39 -0
  32. package/dist/server/body.d.ts.map +1 -0
  33. package/dist/server/body.js +85 -0
  34. package/dist/server/body.js.map +1 -0
  35. package/dist/server/context.d.ts +111 -0
  36. package/dist/server/context.d.ts.map +1 -0
  37. package/dist/server/context.js +2 -0
  38. package/dist/server/context.js.map +1 -0
  39. package/dist/server/contract.d.ts +142 -0
  40. package/dist/server/contract.d.ts.map +1 -0
  41. package/dist/server/contract.js +59 -0
  42. package/dist/server/contract.js.map +1 -0
  43. package/dist/server/cookies.d.ts +41 -0
  44. package/dist/server/cookies.d.ts.map +1 -0
  45. package/dist/server/cookies.js +181 -0
  46. package/dist/server/cookies.js.map +1 -0
  47. package/dist/server/logger.d.ts +49 -0
  48. package/dist/server/logger.d.ts.map +1 -0
  49. package/dist/server/logger.js +125 -0
  50. package/dist/server/logger.js.map +1 -0
  51. package/dist/server/registry.d.ts +46 -0
  52. package/dist/server/registry.d.ts.map +1 -0
  53. package/dist/server/registry.js +2 -0
  54. package/dist/server/registry.js.map +1 -0
  55. package/dist/server/server.d.ts +528 -0
  56. package/dist/server/server.d.ts.map +1 -0
  57. package/dist/server/server.js +1660 -0
  58. package/dist/server/server.js.map +1 -0
  59. package/dist/server/sse.d.ts +54 -0
  60. package/dist/server/sse.d.ts.map +1 -0
  61. package/dist/server/sse.js +126 -0
  62. package/dist/server/sse.js.map +1 -0
  63. package/dist/server/webhook.d.ts +42 -0
  64. package/dist/server/webhook.d.ts.map +1 -0
  65. package/dist/server/webhook.js +149 -0
  66. package/dist/server/webhook.js.map +1 -0
  67. package/dist/server/websocket.d.ts +152 -0
  68. package/dist/server/websocket.d.ts.map +1 -0
  69. package/dist/server/websocket.js +178 -0
  70. package/dist/server/websocket.js.map +1 -0
  71. package/dist/server/ws-bun.d.ts +27 -0
  72. package/dist/server/ws-bun.d.ts.map +1 -0
  73. package/dist/server/ws-bun.js +82 -0
  74. package/dist/server/ws-bun.js.map +1 -0
  75. package/dist/server/ws-hook.d.ts +36 -0
  76. package/dist/server/ws-hook.d.ts.map +1 -0
  77. package/dist/server/ws-hook.js +18 -0
  78. package/dist/server/ws-hook.js.map +1 -0
  79. package/dist/ws.d.ts +19 -0
  80. package/dist/ws.d.ts.map +1 -0
  81. package/dist/ws.js +26 -0
  82. package/dist/ws.js.map +1 -0
  83. package/package.json +63 -0
  84. package/src/errors.ts +41 -0
  85. package/src/index.ts +115 -0
  86. package/src/internal/brand.ts +11 -0
  87. package/src/internal/secret.ts +24 -0
  88. package/src/router/router.ts +429 -0
  89. package/src/schema/standard.ts +76 -0
  90. package/src/seo.ts +155 -0
  91. package/src/server/body.ts +89 -0
  92. package/src/server/context.ts +124 -0
  93. package/src/server/contract.ts +209 -0
  94. package/src/server/cookies.ts +198 -0
  95. package/src/server/logger.ts +167 -0
  96. package/src/server/registry.ts +63 -0
  97. package/src/server/server.ts +2479 -0
  98. package/src/server/sse.ts +161 -0
  99. package/src/server/webhook.ts +207 -0
  100. package/src/server/websocket.ts +308 -0
  101. package/src/server/ws-bun.ts +106 -0
  102. package/src/server/ws-hook.ts +53 -0
  103. package/src/ws.ts +40 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/server/logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,MAAM,QAAQ,GAAG,YAAY,CAAA;AAE7B;;;GAGG;AACH,MAAM,mBAAmB,GAA0B;IACjD,eAAe;IACf,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,SAAS;IACT,SAAS;IACT,YAAY;IACZ,KAAK;CACN,CAAA;AAiBD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0B;IACzD,iCAAiC,EAAE,gCAAgC;IACnE,sDAAsD,EAAE,iCAAiC;IACzF,qDAAqD,EAAE,QAAQ;IAC/D,0CAA0C,EAAE,sCAAsC;IAClF,+BAA+B,EAAE,uCAAuC;IACxE,uBAAuB,EAAE,oBAAoB;CAC9C,CAAA;AAQD,6FAA6F;AAC7F,kGAAkG;AAClG,MAAM,YAAY,GAAG,CAAC,EAAU,EAAU,EAAE,CAC1C,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,CAAA;AAErE,SAAS,WAAW,CAAC,OAAuB;IAC1C,MAAM,KAAK,GAAG,O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M,KAAK,SAAS;YAClB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAE,WAAW,CAAC,MAAM,EAAE,IAAI,OAAO,EAAE,EAAE,MAAM,CAA6B,CAAA;QAC7E,KAAK,CAAC,KAAK,GAAG,KAAK,CAAA;QACnB,KAAK,CAAC,OAAO,GAAG,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA,CAAC,qDAAqD;QACnG,KAAK,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;QACrC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9B,CAAC,CAAA;IACD,OAAO;QACL,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC;QAC1D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;QACxD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;QACxD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC;KAC3D,CAAA;AACH,CAAC;AAED,MAAM,IAAI,GAAG,GAAS,EAAE,CAAC,SAAS,CAAA;AAElC,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAW;IAClC,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;CACZ,CAAA"}
@@ -0,0 +1,46 @@
1
+ import type { InferOutput, StandardSchemaV1 } from "../schema/standard.js";
2
+ import type { Params, RouteSchema } from "./context.js";
3
+ /**
4
+ * One route's input/output shape as the **client** will consume it. `query`/`body`
5
+ * are `never` when the route declares no schema for them, so the client can detect
6
+ * "this route takes no body" via `[body] extends [never]`. `output` is the
7
+ * handler's raw return type (the client applies `Jsonify` when reading it).
8
+ */
9
+ export interface RouteInfo {
10
+ readonly params: object;
11
+ readonly query: unknown;
12
+ readonly body: unknown;
13
+ readonly output: unknown;
14
+ }
15
+ /** The accumulated, type-level map of every route on a Server: path → method → RouteInfo. */
16
+ export type Registry = Record<string, Record<string, RouteInfo>>;
17
+ /** The empty registry (no routes). `NonNullable<unknown>` is `{}` without tripping noBannedTypes. */
18
+ export type EmptyRegistry = NonNullable<unknown>;
19
+ type RegistryBody<S extends RouteSchema> = S extends {
20
+ body: infer B extends StandardSchemaV1;
21
+ } ? InferOutput<B> : never;
22
+ type RegistryQuery<S extends RouteSchema> = S extends {
23
+ query: infer Q extends StandardSchemaV1;
24
+ } ? InferOutput<Q> : never;
25
+ /** The client-visible output: the declared `response` contract when present (so the client sees the
26
+ * contract, not the handler's incidental return), otherwise the inferred handler output. */
27
+ type RegistryOutput<S extends RouteSchema, Output> = S extends {
28
+ response: infer R extends StandardSchemaV1;
29
+ } ? InferOutput<R> : Output;
30
+ /** Build a {@link RouteInfo} from a route's path, schema, and handler output type. */
31
+ export type RouteInfoFor<Path extends string, S extends RouteSchema, Output> = {
32
+ readonly params: Params<Path>;
33
+ readonly query: RegistryQuery<S>;
34
+ readonly body: RegistryBody<S>;
35
+ readonly output: RegistryOutput<S, Output>;
36
+ };
37
+ /** The client-visible output of a handler: its awaited return, minus raw `Response`. */
38
+ export type OutputOf<H extends (...args: never[]) => unknown> = Exclude<Awaited<ReturnType<H>>, Response>;
39
+ /** Merge a new route into the registry, combining methods that share a path. */
40
+ export type AddRoute<R extends Registry, Method extends string, Path extends string, Info extends RouteInfo> = R & {
41
+ [P in Path]: {
42
+ [M in Method]: Info;
43
+ };
44
+ };
45
+ export {};
46
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot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CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IAChC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;IAC9B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;CAC3C,CAAA;AAED,wFAAwF;AACxF,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,IAAI,OAAO,CACrE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACtB,QAAQ,CACT,CAAA;AAED,gFAAgF;AAChF,MAAM,MAAM,QAAQ,CAClB,CAAC,SAAS,QAAQ,EAClB,MAAM,SAAS,MAAM,EACrB,IAAI,SAAS,MAAM,EACnB,IAAI,SAAS,SAAS,IACpB,CAAC,GAAG;KAAG,CAAC,IAAI,IAAI,GAAG;SAAG,CAAC,IAAI,MAAM,GAAG,IAAI;KAAE;CAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/server/registry.ts"],"names":[],"mappings":""}
@@ -0,0 +1,528 @@
1
+ import { type Method } from "../router/router.js";
2
+ import type { InferOutput, StandardSchemaV1 } from "../schema/standard.js";
3
+ import type { Context, Platform, RouteSchema } from "./context.js";
4
+ import { type Logger } from "./logger.js";
5
+ import type { AddRoute, EmptyRegistry, OutputOf, Registry, RouteInfoFor } from "./registry.js";
6
+ import type { WebSocketHandler, WebSocketUpgradeOutcome } from "./websocket.js";
7
+ type MaybePromise<T> = T | Promise<T>;
8
+ /**
9
+ * Internal request view. A real Web `Request` already satisfies this shape, so Web/edge runtimes pass
10
+ * their `Request` **directly** (zero wrapper allocation on the hot path — `request` is simply absent and
11
+ * {@link requestOf} returns the source itself). Node's adapter passes a *lazy* source whose `request`
12
+ * getter builds an undici `Request` only when user code reads `c.req`, an onRequest/onResponse hook
13
+ * needs it, or a body helper consumes it — so the common Node request never pays for a `Request` build.
14
+ */
15
+ export interface RequestSource {
16
+ readonly method: string;
17
+ readonly url: string;
18
+ readonly headers: Headers;
19
+ header?(name: string): string | null;
20
+ readonly body: ReadableStream<Uint8Array> | null;
21
+ arrayBuffer(): Promise<ArrayBuffer>;
22
+ json(): Promise<unknown>;
23
+ /** Present only when materializing a `Request` is non-trivial (the Node lazy source); for a real
24
+ * `Request` passed as the source it's absent and {@link requestOf} returns the source itself. */
25
+ readonly request?: Request;
26
+ }
27
+ /** The empty context extension. `NonNullable<unknown>` is `{}` without tripping noBannedTypes. */
28
+ type EmptyContext = NonNullable<unknown>;
29
+ /**
30
+ * Extracts the app's platform `Env` from its context `Ctx`. `server<Env>()` seeds `Ctx` with
31
+ * `{ env: Env }`, so this pulls that back out to type `fetch`/`toFetchHandler`'s `env` argument
32
+ * against the app's declared bindings. Defaults to `unknown` when no env was declared.
33
+ */
34
+ type EnvOf<Ctx> = Ctx extends {
35
+ readonly env: infer E;
36
+ } ? E : unknown;
37
+ /** A handler returns a `Response` (used as-is) or any value (serialized to JSON). */
38
+ type HandlerResult = Response | unknown;
39
+ export type OnRequestResult = Response | Request | undefined;
40
+ /** The handler's permitted return type. When the route declares a `response` schema, the return is
41
+ * constrained to the contract's type (or a raw `Response`) — so the implementation can't drift from the
42
+ * declared contract. Without a `response` schema it's unconstrained (`HandlerResult`), exactly as before. */
43
+ type ResponseOf<S extends RouteSchema> = S extends {
44
+ response: infer R extends StandardSchemaV1;
45
+ } ? InferOutput<R> | Response : HandlerResult;
46
+ /**
47
+ * Public handler shape: context typed from the path, the (optional) schema, and
48
+ * any accumulated middleware context `Ctx` (from `derive`/`decorate`).
49
+ */
50
+ export type Handler<Path extends string, S extends RouteSchema = RouteSchema, Ctx = EmptyContext> = (ctx: Context<Path, S> & Ctx) => MaybePromise<ResponseOf<S>>;
51
+ export interface ServerOptions {
52
+ /**
53
+ * Max request body size (bytes), enforced **only when a route declares a body schema** — the cap
54
+ * lives in the schema-validated read path. Default 1_000_000.
55
+ *
56
+ * A route WITHOUT a body schema (raw body, file upload, BYO-validation) that reads `c.req` directly
57
+ * is not auto-bounded — use **`c.boundedBody(maxBytes?)`** / **`c.boundedJson(maxBytes?)`**, which
58
+ * apply this same cap (override per route by passing `maxBytes` — larger for an upload endpoint,
59
+ * smaller to tighten one).
60
+ */
61
+ readonly maxBodyBytes?: number;
62
+ /** Per-request timeout (ms): a slower request gets a 503 and `ctx.signal` aborts. 0 disables (default). */
63
+ readonly requestTimeoutMs?: number;
64
+ /** When `listen()`ing, install SIGTERM/SIGINT handlers that gracefully `stop()`. Default false. */
65
+ readonly gracefulSignals?: boolean;
66
+ /** Structured logger for framework events (redacts secrets). Default: JSON to stderr. */
67
+ readonly logger?: Logger;
68
+ }
69
+ /**
70
+ * A registered route's public descriptor — method, path, and input schemas. The
71
+ * router trie discards the original patterns, so this flat list is what lets tools
72
+ * (e.g. `toOpenAPI`) enumerate routes after registration.
73
+ */
74
+ export interface RouteDescriptor {
75
+ readonly method: Method;
76
+ readonly path: string;
77
+ readonly schema: RouteSchema | undefined;
78
+ }
79
+ /**
80
+ * The handle `listen()` returns — the slice of Bun's server nifra holds and exposes.
81
+ * Declared explicitly (rather than `ReturnType<typeof Bun.serve>`) so the public type
82
+ * surface doesn't leak the ambient `Bun` global into consumers' `.d.ts` resolution.
83
+ */
84
+ export interface RunningServer {
85
+ readonly port: number;
86
+ readonly hostname: string;
87
+ readonly pendingRequests: number;
88
+ stop(closeActiveConnections?: boolean): void;
89
+ }
90
+ /**
91
+ * A bundle of lifecycle hooks applied together via {@link Server.use} — the unit
92
+ * `@nifrajs/middleware` ships (cors, security headers, rate-limit). Every hook is
93
+ * optional and wired to its lifecycle point. Middleware is context-agnostic (sees
94
+ * the base `Context`); `use` does no context-type merging — the full type-merging
95
+ * plugin system is deferred, and `.use` is reserved as its future entry point.
96
+ */
97
+ export interface Middleware {
98
+ readonly name?: string;
99
+ readonly onRequest?: (req: Request) => MaybePromise<OnRequestResult>;
100
+ readonly around?: <T>(context: Context, next: () => MaybePromise<T>) => MaybePromise<T>;
101
+ readonly beforeHandle?: (context: Context) => MaybePromise<unknown>;
102
+ readonly afterHandle?: (result: unknown, context: Context) => MaybePromise<unknown>;
103
+ readonly onResponse?: (response: Response, req: Request) => MaybePromise<Response>;
104
+ readonly onError?: (error: unknown, context: Context) => MaybePromise<unknown>;
105
+ }
106
+ export type AnyServer = Server<any, any>;
107
+ /**
108
+ * A nifra **plugin**: a function that augments an app — calling `use`/`derive`/`decorate` and/or
109
+ * registering routes — and returns it. Because `derive`/`decorate` are type-threaded, an **inline**
110
+ * `app.use((a) => a.derive(...).decorate(...))` carries the added context to handlers defined after
111
+ * it (the `use` overload is generic over the concrete `this`). Wrap with {@link definePlugin} to
112
+ * attach a name for idempotent dedupe (applying the same named plugin twice — e.g. transitively — is
113
+ * a no-op).
114
+ */
115
+ export type NifraPlugin<In extends AnyServer = AnyServer, Out extends AnyServer = In> = ((app: In) => Out) & {
116
+ readonly pluginName?: string;
117
+ };
118
+ /**
119
+ * A named type-identity plugin built with {@link defineIdentityPlugin}. It returns the same concrete
120
+ * server type it receives, preserving the caller's typed registry and context across `.use()` while
121
+ * still allowing the plugin to register runtime hooks or handlers.
122
+ */
123
+ export type IdentityPlugin = (<S extends AnyServer>(app: S) => S) & {
124
+ readonly pluginName?: string;
125
+ };
126
+ /**
127
+ * Name + ergonomics for a plugin. `app.use(myPlugin)` applies it once; a second `use` of the same
128
+ * name is skipped (idempotent), so plugins can depend on each other without double-registering hooks.
129
+ *
130
+ * ```ts
131
+ * export const requestId = definePlugin("requestId", (app) => app.derive(() => ({ requestId: uuid() })))
132
+ * app.use(requestId) // downstream handlers see c.requestId
133
+ * ```
134
+ */
135
+ export declare function definePlugin<In extends AnyServer, Out extends AnyServer>(name: string, apply: (app: In) => Out): NifraPlugin<In, Out>;
136
+ /**
137
+ * Define a type-**identity** plugin: it registers routes/hooks as a side effect but returns the app with
138
+ * its `Registry` + `Context` UNCHANGED. Use this (not {@link definePlugin}) for any plugin that doesn't
139
+ * add context types — e.g. one mounting an auth handler. It threads the caller's *concrete* server type
140
+ * through `use`, so routes declared after `app.use(plugin)` keep their types.
141
+ *
142
+ * Why a dedicated helper: `definePlugin((app) => app)` infers `app: Server<any, any>`, so `use` returns
143
+ * `Server<any, any>` and the whole typed client collapses to `any`. The explicit generic return type here
144
+ * (which a plain `Object.assign` can't preserve) is what keeps `use` returning the precise server type.
145
+ *
146
+ * ```ts
147
+ * export const audit = defineIdentityPlugin("audit", (app) => app.onResponse(logResponse))
148
+ * const api = server().get("/a", h).use(audit).get("/b", h) // /a AND /b stay typed
149
+ * ```
150
+ */
151
+ export declare function defineIdentityPlugin(name: string, apply: <S extends AnyServer>(app: S) => S): IdentityPlugin;
152
+ interface UrlParts {
153
+ readonly pathname: string;
154
+ readonly search: string;
155
+ }
156
+ export declare function urlPartsOf(url: string): UrlParts;
157
+ export declare function pathnameOf(url: string): string;
158
+ export declare function searchOf(url: string): string;
159
+ /** A query value: a single occurrence is a string; a repeated key promotes to a string[] so an
160
+ * array query schema (`t.array(t.string())`) can validate `?tag=a&tag=b` — last-wins silently
161
+ * dropped values before (audit 2026-06). Single-occurrence keys stay plain strings, so existing
162
+ * `t.string()` schemas are untouched; a repeated key against a string schema now FAILS validation
163
+ * (an explicit 400 beats silently picking one). */
164
+ export type QueryValue = string | string[];
165
+ export declare function queryObjectOf(search: string): Record<string, QueryValue>;
166
+ /**
167
+ * What {@link Server.resolveNode} returns: either a plain-data render the `@nifrajs/node` adapter writes
168
+ * to the socket directly (`kind: "json"` — status + headers + cookies + a pre-stringified body, **no**
169
+ * undici `Response` built or drained), a marked buffered response body (`kind: "body"` — e.g.
170
+ * @nifrajs/web's non-deferred SSR HTML), or a `Response` (`kind: "response"`) for everything else
171
+ * (redirects, 404/405/errors, unmarked or streaming bodies). Internal to the nifra↔node bridge.
172
+ */
173
+ export type NodeServeOutcome = {
174
+ readonly kind: "response";
175
+ readonly response: Response;
176
+ } | {
177
+ readonly kind: "json";
178
+ readonly status: number;
179
+ /** `c.set.headers` backing, or `undefined` when the handler never set a header. */
180
+ readonly headers: Readonly<Record<string, string>> | undefined;
181
+ /** Queued `Set-Cookie` lines, or `undefined`; the adapter emits one header line each. */
182
+ readonly cookies: readonly string[] | undefined;
183
+ /** The JSON body already stringified, or `null` for an empty (204) response. */
184
+ readonly body: string | null;
185
+ } | {
186
+ readonly kind: "body";
187
+ readonly status: number;
188
+ readonly headers: Readonly<Record<string, string | readonly string[]>> | undefined;
189
+ readonly body: string | Uint8Array;
190
+ };
191
+ /**
192
+ * The inline server. Routes are chainable and fully type-inferred. `derive`/
193
+ * `decorate` extend the handler context (`Ctx`) for routes defined *after* them,
194
+ * with full types; `Ctx` is server-only and never touches the client registry.
195
+ *
196
+ * app.decorate("db", db).derive((c) => ({ user: auth(c) }))
197
+ * .get("/me", (c) => c.user) // c.user + c.db are typed
198
+ */
199
+ export declare class Server<R extends Registry = EmptyRegistry, Ctx = EmptyContext> {
200
+ private readonly router;
201
+ /** WebSocket routes, matched separately at upgrade time (a GET + `Upgrade: websocket`). */
202
+ private readonly wsRouter;
203
+ private wsRouteCount;
204
+ /** In-process pub/sub backing `ws.subscribe(topic)` + `app.publish(topic, data)` (single-instance).
205
+ * Created by the first `app.ws()` via the `@nifrajs/core/ws` runtime — `undefined` until then, so a
206
+ * no-WebSocket app never constructs (or bundles) it. */
207
+ private topics;
208
+ private readonly routeList;
209
+ private readonly maxBodyBytes;
210
+ private readonly requestTimeoutMs;
211
+ private readonly gracefulSignals;
212
+ private readonly logger;
213
+ private bunServer;
214
+ private readonly derives;
215
+ private readonly decorations;
216
+ private readonly beforeHandleHooks;
217
+ private readonly afterHandleHooks;
218
+ private readonly onErrorHooks;
219
+ private readonly aroundHooks;
220
+ private readonly onRequestHooks;
221
+ private readonly onResponseHooks;
222
+ private readonly responseRequests;
223
+ /** Names of plugins/middleware already applied via `use` — for idempotent dedupe. */
224
+ private readonly appliedPlugins;
225
+ constructor(options?: ServerOptions);
226
+ /** Add a per-request, computed context extension for subsequent routes. */
227
+ derive<D extends object>(fn: (context: Context & Ctx) => MaybePromise<D>): Server<R, Ctx & D>;
228
+ /** Add a static context value for subsequent routes. */
229
+ decorate<const K extends string, V>(key: K, value: V): Server<R, Ctx & Record<K, V>>;
230
+ /**
231
+ * Run before routing on the raw request. Return a `Response` to short-circuit, or a replacement
232
+ * `Request` to continue routing with a rewritten method/URL/headers. Global.
233
+ */
234
+ onRequest(fn: (req: Request) => MaybePromise<OnRequestResult>): this;
235
+ /** Run after validation, before the handler; a non-`undefined` return short-circuits. Order-scoped. */
236
+ beforeHandle(fn: (context: Context & Ctx) => MaybePromise<unknown>): this;
237
+ /**
238
+ * Wrap the matched route lifecycle for subsequent routes. This is intentionally generic over the
239
+ * route output, so wrappers like async context storage do not force Node's direct JSON path through
240
+ * a Web `Response`. The first registered wrapper is outermost.
241
+ */
242
+ around(fn: <T>(context: Context & Ctx, next: () => MaybePromise<T>) => MaybePromise<T>): this;
243
+ /** Transform the handler's result before it is serialized. Order-scoped. */
244
+ afterHandle(fn: (result: unknown, context: Context & Ctx) => MaybePromise<unknown>): this;
245
+ /** Handle a thrown error; a non-`undefined` return becomes the response (else the default 500). Order-scoped. */
246
+ onError(fn: (error: unknown, context: Context & Ctx) => MaybePromise<unknown>): this;
247
+ /** Transform every outgoing response — success, error, 404, 405, short-circuit. Global. */
248
+ onResponse(fn: (response: Response, req: Request) => MaybePromise<Response>): this;
249
+ /**
250
+ * Apply a type-**identity** plugin ({@link IdentityPlugin}, from {@link defineIdentityPlugin}) — it
251
+ * registers routes/hooks but doesn't change the types, so this returns `this` with the route registry
252
+ * and context fully intact. This overload exists specifically so a *named* identity plugin (e.g.
253
+ * `@nifrajs/better-auth`) threads the registry: its `& { pluginName }` intersection would otherwise
254
+ * defeat the generic inference of the transforming overload below and collapse the result to `any`.
255
+ */
256
+ use(plugin: IdentityPlugin): this;
257
+ /**
258
+ * Apply a **plugin function** — `(app) => app`, typically built with {@link definePlugin}. It's
259
+ * called with `this` and its result is returned, so an inline plugin's `derive`/`decorate` thread
260
+ * the added context to handlers defined after `use` (the overload is generic over the concrete
261
+ * `this`). A named plugin already applied is skipped (idempotent dedupe).
262
+ */
263
+ use<Out extends AnyServer>(plugin: (app: this) => Out): Out;
264
+ /**
265
+ * Apply a {@link Middleware} bundle — wire each hook it provides to its lifecycle point. Returns
266
+ * `this` (no context-type merging); call it before the routes its `beforeHandle`/`afterHandle`
267
+ * should cover (those are order-scoped; `onRequest`/`onResponse` are global). A named bundle already
268
+ * applied is skipped (idempotent).
269
+ */
270
+ use(mw: Middleware): this;
271
+ get<Path extends string, S extends RouteSchema, H extends Handler<Path, S, Ctx>>(path: Path, schema: S, handler: H): Server<AddRoute<R, "GET", Path, RouteInfoFor<Path, S, OutputOf<H>>>, Ctx>;
272
+ get<Path extends string, H extends Handler<Path, RouteSchema, Ctx>>(path: Path, handler: H): Server<AddRoute<R, "GET", Path, RouteInfoFor<Path, Record<never, never>, OutputOf<H>>>, Ctx>;
273
+ post<Path extends string, S extends RouteSchema, H extends Handler<Path, S, Ctx>>(path: Path, schema: S, handler: H): Server<AddRoute<R, "POST", Path, RouteInfoFor<Path, S, OutputOf<H>>>, Ctx>;
274
+ post<Path extends string, H extends Handler<Path, RouteSchema, Ctx>>(path: Path, handler: H): Server<AddRoute<R, "POST", Path, RouteInfoFor<Path, Record<never, never>, OutputOf<H>>>, Ctx>;
275
+ put<Path extends string, S extends RouteSchema, H extends Handler<Path, S, Ctx>>(path: Path, schema: S, handler: H): Server<AddRoute<R, "PUT", Path, RouteInfoFor<Path, S, OutputOf<H>>>, Ctx>;
276
+ put<Path extends string, H extends Handler<Path, RouteSchema, Ctx>>(path: Path, handler: H): Server<AddRoute<R, "PUT", Path, RouteInfoFor<Path, Record<never, never>, OutputOf<H>>>, Ctx>;
277
+ patch<Path extends string, S extends RouteSchema, H extends Handler<Path, S, Ctx>>(path: Path, schema: S, handler: H): Server<AddRoute<R, "PATCH", Path, RouteInfoFor<Path, S, OutputOf<H>>>, Ctx>;
278
+ patch<Path extends string, H extends Handler<Path, RouteSchema, Ctx>>(path: Path, handler: H): Server<AddRoute<R, "PATCH", Path, RouteInfoFor<Path, Record<never, never>, OutputOf<H>>>, Ctx>;
279
+ delete<Path extends string, S extends RouteSchema, H extends Handler<Path, S, Ctx>>(path: Path, schema: S, handler: H): Server<AddRoute<R, "DELETE", Path, RouteInfoFor<Path, S, OutputOf<H>>>, Ctx>;
280
+ delete<Path extends string, H extends Handler<Path, RouteSchema, Ctx>>(path: Path, handler: H): Server<AddRoute<R, "DELETE", Path, RouteInfoFor<Path, Record<never, never>, OutputOf<H>>>, Ctx>;
281
+ /**
282
+ * Register a **WebSocket** route. The connection upgrades on a `GET` to `path` carrying
283
+ * `Upgrade: websocket`; the optional `handler.upgrade(c)` runs in the request context first and may
284
+ * reject (return a `Response`) or seed per-connection `ws.data`. WebSockets are served by the
285
+ * adapter (`listen()`, `@nifrajs/node`, `@nifrajs/deno`, `toFetchHandler`) — not by bare `app.fetch`, which
286
+ * has no socket (a WS path through `app.fetch` is a normal HTTP response).
287
+ *
288
+ * app.ws("/chat", { open: (ws) => ws.send("hi"), message: (ws, data) => ws.send(data) })
289
+ */
290
+ ws<Data = unknown, Schema extends StandardSchemaV1 | undefined = undefined>(path: string, handler: WebSocketHandler<Data, EnvOf<Ctx>, Schema>): this;
291
+ /**
292
+ * Broadcast `data` to every WebSocket connection subscribed to `topic` (via `ws.subscribe(topic)`).
293
+ * In-process and **single-instance** (see {@link TopicRegistry}) — a multi-instance deploy must bridge
294
+ * an external fan-out (Redis, a Durable Object) to this. A no-op when nobody is subscribed.
295
+ */
296
+ publish(topic: string, data: string | ArrayBufferView | ArrayBuffer): void;
297
+ private route;
298
+ /**
299
+ * Low-level route registration shared by the inline builder and `implement()`.
300
+ * Captures the server's current `derive`/`decorate` chain into the route — this
301
+ * is the "compiled", order-scoped per-route chain.
302
+ */
303
+ register(method: Method, path: string, schema: RouteSchema | undefined, handler: (context: never) => unknown): void;
304
+ /**
305
+ * Enumerate the registered routes (method, path, input schemas), in registration
306
+ * order. Powers `toOpenAPI` and other introspection; the router trie itself no
307
+ * longer holds the original patterns.
308
+ */
309
+ routes(): ReadonlyArray<RouteDescriptor>;
310
+ /**
311
+ * Resolve a `Request` to a `Response` — the whole lifecycle, testable without a port. The
312
+ * optional `platform` carries edge inputs (`env`, `waitUntil`); edge adapters pass it, and
313
+ * Bun/Node/Deno omit it (then `c.env` is `undefined` and `c.waitUntil` runs fire-and-forget).
314
+ */
315
+ fetch(req: Request, platform?: Platform<EnvOf<Ctx>>): MaybePromise<Response>;
316
+ private fetchSource;
317
+ /**
318
+ * Like {@link fetch}, but renders a plain-data result **without** building a Web `Response` — the
319
+ * `@nifrajs/node` adapter serializes the returned primitives straight to the socket, skipping the undici
320
+ * `Response` build + body drain (the bulk of the Node bridge cost, measured ≈4µs/req). A handler that
321
+ * returns a `Response`, an error/short-circuit, or any registered `onResponse` hook falls back to the
322
+ * full Web path (`{ kind: "response" }`), so behavior is identical — only the common JSON-data case is
323
+ * faster. Same lifecycle as {@link fetch} (body cap, validation, hooks all run); only the final
324
+ * render differs.
325
+ */
326
+ resolveNode(req: Request, platform?: Platform<EnvOf<Ctx>>): MaybePromise<NodeServeOutcome>;
327
+ resolveNodeSource(source: RequestSource, platform?: Platform<EnvOf<Ctx>>): MaybePromise<NodeServeOutcome>;
328
+ /**
329
+ * Resolve a WebSocket upgrade — the seam every serving adapter uses. Returns `pass` (not a WS
330
+ * upgrade for a registered route → handle as normal HTTP), `reject` (a WS route matched but
331
+ * `upgrade()` rejected, or the path was malformed → return `response`), or `upgrade` (perform the
332
+ * runtime upgrade, then dispatch the native socket's events to `handler`, seeding `ws.data` with
333
+ * `data`). Runs the route's `upgrade(c)` guard in a real request context. Synchronous unless
334
+ * `upgrade()` is async; a throw rejects with a flat 500 (no detail leaked).
335
+ */
336
+ resolveWebSocketUpgrade(req: Request, platform?: Platform<EnvOf<Ctx>>): MaybePromise<WebSocketUpgradeOutcome>;
337
+ /** Bun `fetch` when WS routes exist: try a WS upgrade first, else run the normal HTTP lifecycle.
338
+ * `undefined` ⇒ Bun owns the upgraded socket; a `Response` ⇒ a normal reply or a rejected upgrade.
339
+ * (The socket dispatch itself lives in `ws-bun.ts`, loaded via `@nifrajs/core/ws`.) */
340
+ private bunFetchWithWebSocket;
341
+ /**
342
+ * The shared lifecycle, generic over how the final value is rendered: `finalize` turns a handler's
343
+ * result + `set` into the output `T` (`toResponse` → a Web `Response`; `toNodeOutcome` → node-direct
344
+ * primitives), `wrapResponse` lifts an early/error `Response` into that same `T`, and `onTimeout`
345
+ * produces the 503. The Web `fetch` and `resolveNode` are thin callers over this one routing +
346
+ * context + lifecycle implementation — no duplication across the trust boundary.
347
+ */
348
+ private dispatch;
349
+ /**
350
+ * onRequest short-circuit path. Synchronous as long as every hook returns synchronously (the
351
+ * common case — e.g. CORS returning `undefined` for a non-preflight request): an `async` version
352
+ * here put EVERY request of any app with one onRequest hook onto the promise machinery, profiled
353
+ * at ~13% of a realistic request. The first hook that returns a Promise hands the REMAINING
354
+ * hooks to the async continuation; behavior is identical.
355
+ */
356
+ private runWithOnRequest;
357
+ /** Async tail of {@link runWithOnRequest}: applies the first awaited hook's outcome, then runs
358
+ * the remaining hooks (awaiting freely — we're already async here). */
359
+ private continueOnRequest;
360
+ private takeResponseRequest;
361
+ /**
362
+ * Route → build context → run. Synchronous through to the handler for a **bare** route
363
+ * ({@link RouteEntry.bare}), so a sync handler produces its result with zero promise allocations;
364
+ * routes with validation/hooks keep the full async {@link runLifecycle}, unchanged.
365
+ */
366
+ private routeAndRun;
367
+ /** The narrowest bare route: a syntactic `() => ...` handler cannot observe the context argument, so
368
+ * successful requests can skip allocating `RequestContext`. Errors still allocate one for logging. */
369
+ private runContextlessBare;
370
+ private contextlessBareError;
371
+ /**
372
+ * The synchronous fast path for a {@link RouteEntry.bare} route: apply static decorations, call the
373
+ * handler, render the result — **no `await`** unless the handler itself returns a promise. It mirrors
374
+ * the bare slice of {@link runLifecycle} (which a bare route would otherwise no-op through) and shares
375
+ * {@link logRequestError}; a bare route has no `onError` hooks, so error handling is fully synchronous
376
+ * (a thrown `Response` is control flow; anything else is a logged flat 500). This is where nifra skips
377
+ * the per-request async-frame tax — the same win codegen routers get, but without `eval`.
378
+ */
379
+ private runBare;
380
+ /** Bare-route error rendering — identical to {@link runLifecycle}'s catch minus the (absent) onError
381
+ * loop: a thrown `Response` is returned as deliberate control flow; anything else is logged + 500. */
382
+ /**
383
+ * Build a route's fused Web lane (see {@link RouteEntry.fusedWeb}). Composition happens once at
384
+ * registration; the returned closure is what every request to the route runs. Behavior is
385
+ * byte-identical to the generic `runBare`/`runContextlessBare` + `toResponse` pair — same
386
+ * decoration order, same error routing (thrown `Response` = control flow; anything else logs and
387
+ * 500s), same respond semantics (the lifecycle parity suite pins it).
388
+ */
389
+ private buildFusedWeb;
390
+ private bareError;
391
+ private runWithAround;
392
+ private runAround;
393
+ private runBodyOnly;
394
+ /** Validate + run the handler for the bodyOnly path — shared by the inline fast path and the
395
+ * streaming fallback. A method (not per-request closures) so the hot path allocates nothing
396
+ * beyond the one `.then` continuation. */
397
+ private finishBodyOnly;
398
+ private applyBodyValidation;
399
+ private runQueryOnly;
400
+ /** Validate-result → set `ctx.query` → run handler. A method (not a per-request closure), the
401
+ * query analogue of {@link applyBodyValidation}. */
402
+ private applyQueryValidation;
403
+ /**
404
+ * Thread the response through each global `onResponse` hook. Stays SYNCHRONOUS until a hook
405
+ * actually returns a Promise — an `async` version forced a promise + microtask on EVERY response
406
+ * of any app with an onResponse hook (cors/securityHeaders/etag/timing all use onResponse), the
407
+ * same ~13%/req tax the onRequest walk was de-async'd to avoid. The first async hook hands the
408
+ * rest to {@link continueOnResponse}.
409
+ */
410
+ private applyOnResponse;
411
+ /** Async tail of {@link applyOnResponse}: runs the remaining hooks once one has gone async. */
412
+ private continueOnResponse;
413
+ /**
414
+ * Bound the response time. On timeout we abort `ctx.signal` (so cancellation-aware
415
+ * handlers can bail) and return 503; the in-flight work keeps running but its
416
+ * result is discarded — JS can't forcibly cancel a promise.
417
+ */
418
+ private withTimeout;
419
+ /**
420
+ * The post-match lifecycle: validate → derive → beforeHandle → handler → afterHandle, with onError.
421
+ * Generic over the render: a success value goes through `finalize(result, set)` (a Web `Response`, or
422
+ * node-direct primitives); an early/error `Response` (validation, thrown, 500) through `wrapResponse`.
423
+ */
424
+ private runLifecycle;
425
+ private handleLifecycleError;
426
+ /** Log an unhandled request error to the (redacting) logger — shared by {@link runLifecycle} and the
427
+ * bare fast path ({@link bareError}) so both record the same fields. Never throws; never leaks. */
428
+ private logRequestError;
429
+ private readAndValidateBody;
430
+ /**
431
+ * Read the body as text, capped at `maxBodyBytes`. Rejects (`null`) on a
432
+ * `Content-Length` over the cap *before* buffering, and aborts mid-stream once the
433
+ * running byte count exceeds it — so a lying or absent length can't force us to
434
+ * buffer an oversized payload.
435
+ *
436
+ * Fast path: when a non-chunked request carries a `Content-Length` within the cap,
437
+ * a native `req.json()` is already bounded — under HTTP/1.1 + HTTP/2 framing the
438
+ * runtime delivers at most `Content-Length` bytes — so we skip the manual stream
439
+ * loop and a separate text decode. It trusts the wire
440
+ * *framing*, not the header value: nifra only ever receives framed Requests from the
441
+ * runtime's HTTP server, never a hand-built one with a mismatched length. Chunked or
442
+ * length-less bodies fall through to the streaming byte-cap guard below.
443
+ */
444
+ private readBoundedJson;
445
+ /**
446
+ * Start a `Bun.serve` instance bound to `port` (use `0` for an ephemeral port).
447
+ *
448
+ * `reusePort` sets `SO_REUSEPORT` so **multiple processes can bind the same port** and the kernel
449
+ * load-balances connections across them — the standard way to use every core (Bun is
450
+ * single-threaded per process). Spawn one process per core, each calling
451
+ * `app.listen(PORT, { reusePort: true })`; see `examples/cluster.ts`. Every process must opt in,
452
+ * and all of them must be the same app. Linux balances ~evenly; macOS accepts the flag but may
453
+ * favor one socket (fine for dev, measure on Linux for production numbers).
454
+ */
455
+ listen(port: number, options?: {
456
+ readonly reusePort?: boolean;
457
+ }): RunningServer;
458
+ /**
459
+ * Gracefully stop: wait for in-flight requests to finish (up to `drainMs`), then
460
+ * issue a single terminal stop — graceful if everything drained, forced if
461
+ * stragglers remain. Safe to call when not listening.
462
+ *
463
+ * The Bun semantics: poll `pendingRequests` (awaiting
464
+ * `stop()`'s promise drops in-flight requests), and decide graceful-vs-forced in
465
+ * ONE call (Bun can't escalate an already-graceful `stop()` to a forced close).
466
+ * New connections may be accepted during the drain window; in a real deploy the
467
+ * load balancer has already stopped routing here, and `drainMs` bounds it.
468
+ */
469
+ stop({ drainMs }?: {
470
+ drainMs?: number;
471
+ }): Promise<void>;
472
+ private installSignalHandlers;
473
+ }
474
+ /**
475
+ * Create a new {@link Server}. Pass an `Env` to type the platform bindings — `server<Env>()` makes
476
+ * `c.env: Env` in every handler + middleware, and types the `env` argument of `app.fetch` /
477
+ * `toFetchHandler`. Omit it and `c.env` is `unknown` (validate/cast before use).
478
+ */
479
+ export declare function server<Env = unknown>(options?: ServerOptions): Server<EmptyRegistry, {
480
+ readonly env: Env;
481
+ }>;
482
+ /** A Cloudflare Workers-style execution context (the `fetch` 3rd arg). Structural — only
483
+ * `waitUntil` is used; declared here so `@nifrajs/core` needs no Workers type dependency. */
484
+ export interface ExecutionContext {
485
+ waitUntil(promise: Promise<unknown>): void;
486
+ }
487
+ /** A Cloudflare Workers-style scheduled (cron) controller. Structural — no Workers type dependency. */
488
+ export interface ScheduledController {
489
+ /** Epoch ms the run was scheduled for. */
490
+ readonly scheduledTime: number;
491
+ /** The matching cron expression from `wrangler.toml` `[triggers]`. */
492
+ readonly cron: string;
493
+ /** Tell the platform not to retry this run on failure. */
494
+ noRetry(): void;
495
+ }
496
+ /** A nifra cron handler: the platform controller + the same typed `env`/`waitUntil` nifra threads into
497
+ * request handlers. Schedule background work with `waitUntil` so it outlives the trigger. */
498
+ export type ScheduledHandler<Env = unknown> = (controller: ScheduledController, context: {
499
+ readonly env: Env;
500
+ waitUntil(promise: Promise<unknown>): void;
501
+ }) => MaybePromise<void>;
502
+ /** Structural view of a Cloudflare Durable Object namespace binding — keeps `@cloudflare/workers-types`
503
+ * out of `@nifrajs/core`. The real `DurableObjectNamespace` satisfies it. */
504
+ export interface DurableObjectNamespaceLike {
505
+ idFromName(name: string): unknown;
506
+ get(id: unknown): {
507
+ fetch(request: Request): Promise<Response>;
508
+ };
509
+ }
510
+ export declare function toFetchHandler<Env = unknown>(app: {
511
+ fetch(request: Request, platform?: Platform<Env>): MaybePromise<Response>;
512
+ resolveWebSocketUpgrade?(request: Request, platform?: Platform<Env>): MaybePromise<WebSocketUpgradeOutcome>;
513
+ }, options?: {
514
+ scheduled?: ScheduledHandler<Env>;
515
+ /**
516
+ * Route WebSocket upgrades to a Durable Object that holds the connections and runs the app's
517
+ * pub/sub — enabling cross-connection broadcast (`app.publish`) on Cloudflare Workers, where a
518
+ * stateless isolate can't. Pass the DO namespace binding from `env`; pair with `@nifrajs/workers`'
519
+ * `createWebSocketHub(app)` (the DO class) + a `wrangler.toml` binding. Without this, WS upgrades use
520
+ * a per-connection `WebSocketPair` (no broadcast).
521
+ */
522
+ webSocketHub?: (env: Env) => DurableObjectNamespaceLike;
523
+ }): {
524
+ fetch(request: Request, env: Env, ctx: ExecutionContext): MaybePromise<Response>;
525
+ scheduled?(controller: ScheduledController, env: Env, ctx: ExecutionContext): MaybePromise<void>;
526
+ };
527
+ export {};
528
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,MAAM,EAAU,MAAM,qBAAqB,CAAA;AACvE,OAAO,KAAK,EACV,WAAW,EAGX,gBAAgB,EACjB,MAAM,uBAA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