@brickkit/core 0.4.2 → 0.6.0

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.
package/dist/index.d.ts CHANGED
@@ -1,465 +1,319 @@
1
- import { $ as ToolConfigWithoutAuthorize, A as ErrorBuilder, At as index, B as Resource, Bt as PluginRouteScope, C as ActionSchema, Ct as secret, D as CacheOptions, Dt as blob, E as BaseContext, Et as SQLiteDatabaseConfig, F as NarrowAuthorizedContext, Ft as text, G as ServiceAuthOptions, Gt as ResourcePluginTypes, H as ResourceIdentity, Ht as ResourcePlugin, I as PreparationContribution, It as uniqueIndex, J as StandardErrorMap, Jt as defineResourcePlugin, K as ServiceOptions, Kt as ServicePlugin, L as ProxyOptions, Lt as PluginEndpointContext, M as InferTableRow, Mt as primaryKey, N as LifecycleOptions, Nt as real, O as CompiledRoutePlan, Ot as createSQLiteDatabase, P as Logger, Pt as sqliteTable, Q as ToolConfigWithAuthorize, R as RateLimitOptions, Rt as PluginRouteMethod, S as ActionExecutionError, St as resolveSecrets, T as BaseActionConfig, Tt as BunSQLiteDatabase, U as ResourceTypeOptions, Ut as ResourcePluginAPI, V as ResourceConfig, Vt as PluginRoutes, W as Service, Wt as ResourcePluginContext, X as Tool, Xt as getPluginActionRoute, Y as TelemetryOptions, Yt as defineServicePlugin, Z as ToolAnnotations, Zt as getPluginEndpoints, _ as ActionConfig, _t as envSource, a as BrickClientOptions, at as EnvInput, b as ActionContext, bt as overrideSecrets, c as InferActionErrorCodes, ct as defineDatabase, d as InferActionOutput, dt as PostgresDatabase, et as ToolOptions, f as createBrickClient, ft as PostgresDatabaseConfig, g as ActionAccessPolicy, gt as SecretSource, h as Action, ht as SecretRef, i as BrickClientAction, it as DatabaseHandle, j as InferTableInsert, jt as integer, k as DefaultServiceContext, kt as foreignKey, l as InferActionFailure, lt as isDatabaseHandle, m as isBrickTransportError, mt as SecretOptions, n as BrickCallOptions, nt as ValidationErrorItem, o as BrickServerError, ot as PostgresDefinition, p as isBrickServerError, pt as createPostgresDatabase, q as ServiceSchema, qt as ServicePluginContext, r as BrickClient, rt as DatabaseDefinition, s as BrickTransportError, st as SQLiteDefinition, t as BrickActionCaller, tt as ValidationError, u as InferActionInput, ut as DatabaseAdapter, v as ActionConfigWithAuthorize, vt as listSecrets, w as ArchitectureSchema, wt as BrickSQLiteDatabase, x as ActionErrorDefinition, xt as resetSecrets, y as ActionConfigWithoutAuthorize, yt as overrideSecret, z as ResilienceOptions, zt as PluginRouteRegistrar } from "./chunks/client.js";
2
- import { Static, TSchema, TSchema as TSchema$1, Type } from "@sinclair/typebox";
3
- import { TypeCheck } from "@sinclair/typebox/compiler";
4
- import { Elysia } from "elysia";
5
- import { Table, and, asc, desc, eq, getTableColumns, getTableName, gt, gte, ilike, inArray, is, isNotNull, isNull, like, lt, lte, ne, not, notInArray, or, relations, sql } from "drizzle-orm";
6
- //#region src/compiler/ir.d.ts
7
- type RouteMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
8
- interface RouteIR {
9
- readonly method: RouteMethod;
10
- readonly path: string;
11
- readonly service: string;
12
- readonly action: string;
13
- readonly kind: "action";
14
- readonly input: boolean;
15
- readonly output: boolean;
16
- readonly context: boolean;
17
- readonly authorize: boolean;
18
- readonly inputPrecedence: readonly ("query" | "params" | "body")[];
19
- readonly coercions: readonly {
20
- readonly key: string;
21
- readonly type: "number" | "boolean";
22
- }[];
23
- /** JSON projection for inspection and stale-artifact detection, not runtime validation. */
24
- readonly inputSchema?: unknown;
25
- readonly outputSchema?: unknown;
26
- }
27
- interface BrickIR {
28
- readonly version: 1;
29
- readonly target: "bun-elysia";
30
- readonly prefix: string;
31
- readonly services: readonly string[];
32
- readonly routes: readonly RouteIR[];
33
- readonly preparations: readonly {
34
- service: string;
35
- name: string;
36
- metadata: unknown;
37
- }[];
38
- readonly diagnostics: readonly string[];
1
+ import { s as errors_d_exports } from "./chunks/errors.js";
2
+ import { Effect, Layer, Scope } from "effect";
3
+ import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
4
+ import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
5
+ import { Rpc, RpcGroup } from "effect/rpc";
6
+ import { McpServer, Tool } from "effect/ai";
7
+ //#region src/native/transports.d.ts
8
+ interface TransportAction extends ActionConstraint {
9
+ readonly rpc: Rpc.Any;
10
+ readonly tool: Tool.Any;
11
+ readonly mcp: boolean;
39
12
  }
13
+ type RpcRequirements<A extends Record<string, TransportAction>> = Exclude<[unknown] extends [Rpc.ServicesServer<A[keyof A]["rpc"]> | Rpc.Middleware<A[keyof A]["rpc"]>] ? never : Rpc.ServicesServer<A[keyof A]["rpc"]> | Rpc.Middleware<A[keyof A]["rpc"]>, Scope.Scope | HttpServerRequest.HttpServerRequest>;
14
+ type McpRequirements<A extends Record<string, TransportAction>> = Exclude<[unknown] extends [Tool.HandlerServices<A[keyof A]["tool"]>] ? never : Tool.HandlerServices<A[keyof A]["tool"]>, Scope.Scope | HttpServerRequest.HttpServerRequest>;
15
+ declare function mcpRoutes<const A extends Record<string, TransportAction>>(actions: A, options: Parameters<typeof McpServer.layerHttp>[0]): Layer.Layer<never, Layer.Error<ReturnType<typeof McpServer.layerHttp>>, HttpRouter.HttpRouter | Requirements<A> | McpRequirements<A>>;
40
16
  //#endregion
41
- //#region src/endpoints.d.ts
42
- type EndpointMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
43
- /** Logger subset handed to endpoint handlers (mirrors action context loggers). */
44
- interface EndpointLogger {
45
- info: (...args: any[]) => void;
46
- warn: (...args: any[]) => void;
47
- error: (...args: any[]) => void;
48
- debug: (...args: any[]) => void;
17
+ //#region src/native/kernel.d.ts
18
+ interface ActionConstraint {
19
+ readonly rpc: Rpc.Any;
20
+ readonly tool: Tool.Any;
21
+ readonly mcp: boolean;
22
+ readonly endpoint: HttpApiEndpoint.Constraint;
23
+ readonly method: string;
24
+ readonly path: `/${string}`;
25
+ readonly handler: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
26
+ readonly httpHandler: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
49
27
  }
50
- /** Context for raw endpoint handlers: Elysia route fields + Brick extras. */
51
- interface EndpointContext {
52
- params: Record<string, string>;
53
- query: Record<string, string | undefined>;
54
- body: unknown;
55
- headers: Record<string, string>;
56
- request: Request;
57
- /** Elysia response setter (status/headers). Mutate like in `app.get`. */
58
- set: {
59
- status?: number;
60
- headers: Record<string, string>;
61
- };
62
- /** Drizzle db from `service` (or first service with one); `undefined` when none. */
63
- db: any;
64
- logger: EndpointLogger;
65
- traceId: string;
66
- requestId: string;
28
+ type Endpoints<A extends Record<string, ActionConstraint>> = A[keyof A]["endpoint"];
29
+ type Requirements<A extends Record<string, ActionConstraint>> = Exclude<Effect.Services<ReturnType<A[keyof A]["handler"]>>, HttpServerRequest.HttpServerRequest | Scope.Scope>;
30
+ type HttpRequirements<A extends Record<string, ActionConstraint>> = { [K in keyof A]: ([unknown] extends [HttpApiEndpoint.ExcludeProvided<A[K]["endpoint"], Effect.Services<ReturnType<A[K]["handler"]>> | HttpApiEndpoint.ServerServices<A[K]["endpoint"]>>] ? Effect.Services<ReturnType<A[K]["handler"]>> : HttpApiEndpoint.ExcludeProvided<A[K]["endpoint"], Effect.Services<ReturnType<A[K]["handler"]>> | HttpApiEndpoint.ServerServices<A[K]["endpoint"]>>) | HttpApiEndpoint.Middleware<A[K]["endpoint"]> | HttpApiEndpoint.MiddlewareServices<A[K]["endpoint"]>; }[keyof A];
31
+ declare const service: <const N extends string, const A extends Record<string, ActionConstraint>>(name: N, options: {
32
+ readonly actions: A;
33
+ }) => Readonly<{
34
+ name: N;
35
+ actions: Readonly<A>;
36
+ group: HttpApiGroup.HttpApiGroup<N, Endpoints<A>>;
37
+ }>;
38
+ declare function compileService<const N extends string, const A extends Record<string, ActionConstraint>>(s: ReturnType<typeof service<N, A>>): Readonly<{
39
+ api: HttpApi.HttpApi<"brick", HttpApiGroup.HttpApiGroup<N, Endpoints<A>, false>>;
40
+ implementation: Layer.Layer<HttpApiGroup.Service<"brick", N>, never, HttpRequirements<A>>;
41
+ }>;
42
+ declare function layer<const N extends string, const A extends Record<string, ActionConstraint>>(s: ReturnType<typeof service<N, A>>): Layer.Layer<never, never, HttpRouter.HttpRouter | Exclude<HttpRequirements<A>, import("effect/http/Etag").Generator | import("effect/FileSystem").FileSystem | import("effect/http/HttpPlatform").HttpPlatform | import("effect/Path").Path> | Exclude<Exclude<HttpApiGroup.ToService<"brick", HttpApiGroup.HttpApiGroup<N, Endpoints<A>, false>>, HttpApiGroup.Service<"brick", N>>, import("effect/http/Etag").Generator | import("effect/FileSystem").FileSystem | import("effect/http/HttpPlatform").HttpPlatform | import("effect/Path").Path>>;
43
+ interface ServiceConstraint {
44
+ readonly name: string;
45
+ readonly actions: Record<string, ActionConstraint>;
46
+ readonly group: HttpApiGroup.Constraint;
67
47
  }
68
- interface EndpointDefinition {
69
- method: EndpointMethod;
70
- /** Elysia-style path, e.g. `/p/:slug`. */
71
- path: string;
72
- handler: (ctx: EndpointContext) => unknown | Promise<unknown>;
73
- /** Db source: instance or registered service name. Defaults to first service with a db. */
74
- service?: Service<any, any> | string;
75
- /** Explicit database handle, independent of a service. */
76
- database?: DatabaseHandle<unknown>;
77
- summary?: string;
78
- description?: string;
79
- tags?: string[];
48
+ type AppGroups<S extends readonly ServiceConstraint[]> = S[number]["group"];
49
+ type AppRequirements<S extends readonly ServiceConstraint[]> = S[number] extends (infer V) ? V extends ServiceConstraint ? HttpRequirements<V["actions"]> : never : never;
50
+ interface Transports {
51
+ readonly rpc?: {
52
+ readonly path: `/${string}`;
53
+ };
54
+ readonly mcp?: Parameters<typeof McpServer.layerHttp>[0];
80
55
  }
81
- /** Resolve the db for an endpoint: explicit service first, else first service holding one. */
82
- export declare function resolveEndpointDb(service: Service<any, any> | string | undefined, services: Service<any, any>[]): any;
83
- /** Wrap a raw handler with trace ids, logger, db, and mesh-consistent error mapping. */
84
- export declare function createEndpointHandler(def: EndpointDefinition, services: Service<any, any>[]): (elysiaCtx: any) => Promise<unknown>;
85
- /** `/p/:slug` → `/p/{slug}` for OpenAPI. */
86
- export declare function toOpenApiPath(elysiaPath: string): string;
87
- /** OpenAPI `paths` fragment for declared endpoints (raw HTML included). */
88
- export declare function endpointPaths(defs: EndpointDefinition[]): Record<string, any>;
89
- /** The app object returned by `brick`: Elysia plus `endpoint()`. */
90
- type BrickApp = Elysia<any, any, any, any, any, any, any> & {
91
- /** Service definitions and prefix selected when this app was constructed. */
92
- readonly definition: {
93
- readonly routes: readonly RouteIR[];
94
- readonly services: readonly Service<any, any>[];
95
- readonly prefix: string;
56
+ type TransportRequirements<S extends readonly ServiceConstraint[], T> = S[number] extends (infer V) ? V extends ServiceConstraint ? (T extends {
57
+ readonly rpc: object;
58
+ } ? Requirements<V["actions"]> | RpcRequirements<V["actions"]> : never) | (T extends {
59
+ readonly mcp: object;
60
+ } ? Requirements<V["actions"]> | McpRequirements<V["actions"]> : never) : never : never;
61
+ /** Compose closed applications. Handler and schema requirements must be supplied. */
62
+ declare function app<const S extends readonly ServiceConstraint[], E, const T extends Transports = {}, RoutesA = never, RoutesE = never, RoutesR = never>(options: {
63
+ readonly services: S;
64
+ readonly layer: Layer.Layer<AppRequirements<S> | TransportRequirements<S, T> | Exclude<RoutesR, HttpRouter.HttpRouter>, E, never>;
65
+ readonly transports?: T;
66
+ readonly routes?: Layer.Layer<RoutesA, RoutesE, RoutesR>;
67
+ readonly docs?: {
68
+ readonly path: `/${string}`;
69
+ };
70
+ readonly client?: {
71
+ readonly module: string;
72
+ readonly exportName?: string;
96
73
  };
97
- /** Register a raw endpoint (outside the JSON action mesh). */
98
- endpoint(def: EndpointDefinition): void;
99
- /** All endpoints registered via `endpoint()` (declaration order). */
100
- listEndpoints(): EndpointDefinition[];
101
- };
74
+ }): Readonly<{
75
+ kind: "brick-native-app";
76
+ services: readonly S[number][];
77
+ client: Readonly<{
78
+ module: string;
79
+ exportName?: string;
80
+ }> | undefined;
81
+ layer: Layer.Layer<never, E | RoutesE | Layer.Error<ReturnType<typeof mcpRoutes>>, HttpRouter.HttpRouter>;
82
+ api: HttpApi.HttpApi<"brick", AppGroups<S>>;
83
+ openApi: () => OpenApi.OpenAPISpec;
84
+ fetch: (request: Request) => Promise<Response>;
85
+ ready: () => Promise<void>;
86
+ dispose: () => Promise<void>;
87
+ }>;
88
+ //#endregion
89
+ //#region src/native/route.d.ts
90
+ type Static<R> = Exclude<R, Scope.Scope | HttpServerRequest.HttpServerRequest | HttpRouter.RouteContext>;
91
+ /** Capture application services once, and use request services at invocation. */
92
+ declare function route<E, R>(method: Parameters<typeof HttpRouter.add>[0], path: `/${string}`, handler: Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>): Layer.Layer<never, never, HttpRouter.HttpRouter | Static<R>>;
102
93
  //#endregion
103
- //#region src/compiler/runtime.d.ts
104
- type CompiledHandler = (context: any) => unknown | Promise<unknown>;
105
- type HandlerFactory = (binding: CompiledRoutePlan, runtime: typeof compilerRuntime) => CompiledHandler;
106
- /** Retains Brick's existing source precedence and treatment of empty bodies. */
107
- declare function mergeInput(first: any, second: any, third: any): any;
108
- declare function checkDepth(value: unknown, action: string): void;
109
- declare function validate(check: NonNullable<CompiledRoutePlan["inputChecker"]>, value: unknown, action: string, stage: "input" | "output"): void;
110
- declare function mapError(err: unknown, set: any, options: {
111
- logger: Logger;
112
- requestId: string;
113
- }): ErrorEnvelope;
114
- export declare const compilerRuntime: Readonly<{
115
- emptyServices: Readonly<{}>;
116
- defaultRequest: Request;
117
- nextSequence: () => string;
118
- mergeInput: typeof mergeInput;
119
- checkDepth: typeof checkDepth;
120
- validate: typeof validate;
121
- mapError: typeof mapError;
122
- isThenable: (value: any) => boolean;
123
- deny: (action: string, user: unknown) => never;
94
+ //#region src/native/index.d.ts
95
+ /** Effect-native contracts and scoped HTTP applications. */
96
+ export declare const Brick: Readonly<{
97
+ action: <const N extends string, I extends import("effect/Schema").Top, O extends import("effect/Schema").Top, const Errors extends readonly import("effect/Schema").Top[]>(name: N, path: `/${string}`, schemas: {
98
+ input: I;
99
+ output: O;
100
+ errors: Errors;
101
+ mcp?: boolean;
102
+ description?: string;
103
+ title?: string;
104
+ tool?: {
105
+ readonly readOnly?: boolean;
106
+ readonly destructive?: boolean;
107
+ readonly idempotent?: boolean;
108
+ readonly openWorld?: boolean;
109
+ };
110
+ }) => (<Failure extends Errors[number]["Type"], R>(handler: (input: I["Type"]) => import("effect/Effect").Effect<O["Type"], Failure, R>) => Readonly<{
111
+ handler: (input: I["Type"]) => import("effect/Effect").Effect<O["Type"], Failure, Exclude<R, import("effect/Tracer").ParentSpan>>;
112
+ httpHandler: ({ payload }: {
113
+ payload: I["Type"];
114
+ }) => import("effect/Effect").Effect<O["Type"], Failure, Exclude<R, import("effect/Tracer").ParentSpan>>;
115
+ name: N;
116
+ endpoint: import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<N, "POST", `/${string}`, never, never, [I extends import("effect/Schema").Struct.Fields ? import("effect/Schema").Struct<I> : I extends readonly import("effect/Schema").Constraint[] ? I[number] : I] extends [never] ? never : [I extends import("effect/Schema").Struct.Fields ? import("effect/Schema").Struct<I> : I extends readonly import("effect/Schema").Constraint[] ? I[number] : I] extends [import("effect/Schema").Constraint] ? import("effect/Schema").toCodecJson<import("effect/Schema").Constraint & (I extends import("effect/Schema").Struct.Fields ? import("effect/Schema").Struct<I> : I extends readonly import("effect/Schema").Constraint[] ? I[number] : I)> : never, never, [Exclude<Extract<O extends readonly (infer A)[] ? A : O, import("effect/Schema").Top>, import("effect/http-api/HttpApiSchema").WithHeaders<import("effect/Schema").Top, import("effect/Schema").Top> | import("effect/http-api/HttpApiSchema").StreamSchema>] extends [never] ? ((O extends readonly (infer A)[] ? A : O) extends (infer Success) ? Success extends import("effect/http-api/HttpApiSchema").StreamSchema ? Success : never : never) | ((O extends readonly (infer A)[] ? A : O) extends (infer Success_1) ? Success_1 extends import("effect/http-api/HttpApiSchema").WithHeaders<infer _Inner extends import("effect/Schema").Top, infer _Headers extends import("effect/Schema").Top> ? import("effect/http-api/HttpApiSchema").WithHeaders<_Inner extends import("effect/http-api/HttpApiSchema").StreamSchema ? _Inner : import("effect/Schema").toCodecJson<_Inner>, import("effect/Schema").toCodecStringTree<_Headers>> : never : never) : ((O extends readonly (infer A)[] ? A : O) extends (infer Success) ? Success extends import("effect/http-api/HttpApiSchema").StreamSchema ? Success : never : never) | ((O extends readonly (infer A)[] ? A : O) extends (infer Success_1) ? Success_1 extends import("effect/http-api/HttpApiSchema").WithHeaders<infer _Inner extends import("effect/Schema").Top, infer _Headers extends import("effect/Schema").Top> ? import("effect/http-api/HttpApiSchema").WithHeaders<_Inner extends import("effect/http-api/HttpApiSchema").StreamSchema ? _Inner : import("effect/Schema").toCodecJson<_Inner>, import("effect/Schema").toCodecStringTree<_Headers>> : never : never) | import("effect/Schema").toCodecJson<Exclude<Extract<O extends readonly (infer A)[] ? A : O, import("effect/Schema").Top>, import("effect/http-api/HttpApiSchema").WithHeaders<import("effect/Schema").Top, import("effect/Schema").Top> | import("effect/http-api/HttpApiSchema").StreamSchema>>, [import("effect/Schema").Union<readonly [import("effect/Schema").Union<Errors>]>] extends [import("effect/Schema").Constraint] ? import("effect/Schema").toCodecJson<import("effect/Schema").Constraint & import("effect/Schema").Union<readonly [import("effect/Schema").Union<Errors>]>> : never, never, never>;
117
+ method: import("effect/http/HttpMethod").HttpMethod;
118
+ path: `/${string}`;
119
+ rpc: import("effect/rpc/Rpc").Rpc<N, I extends import("effect/Schema").Struct.Fields ? import("effect/Schema").Struct<I> : I, O, import("effect/Schema").Union<Errors>, never, never>;
120
+ tool: import("effect/ai/Tool").Tool<N, {
121
+ readonly parameters: I;
122
+ readonly success: O;
123
+ readonly failure: import("effect/Schema").Union<Errors>;
124
+ readonly failureMode: "error";
125
+ }, never>;
126
+ mcp: boolean;
127
+ }>) & Readonly<{
128
+ name: N;
129
+ endpoint: import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<N, "POST", `/${string}`, never, never, [I extends import("effect/Schema").Struct.Fields ? import("effect/Schema").Struct<I> : I extends readonly import("effect/Schema").Constraint[] ? I[number] : I] extends [never] ? never : [I extends import("effect/Schema").Struct.Fields ? import("effect/Schema").Struct<I> : I extends readonly import("effect/Schema").Constraint[] ? I[number] : I] extends [import("effect/Schema").Constraint] ? import("effect/Schema").toCodecJson<import("effect/Schema").Constraint & (I extends import("effect/Schema").Struct.Fields ? import("effect/Schema").Struct<I> : I extends readonly import("effect/Schema").Constraint[] ? I[number] : I)> : never, never, [Exclude<Extract<O extends readonly (infer A)[] ? A : O, import("effect/Schema").Top>, import("effect/http-api/HttpApiSchema").WithHeaders<import("effect/Schema").Top, import("effect/Schema").Top> | import("effect/http-api/HttpApiSchema").StreamSchema>] extends [never] ? ((O extends readonly (infer A)[] ? A : O) extends (infer Success) ? Success extends import("effect/http-api/HttpApiSchema").StreamSchema ? Success : never : never) | ((O extends readonly (infer A)[] ? A : O) extends (infer Success_1) ? Success_1 extends import("effect/http-api/HttpApiSchema").WithHeaders<infer _Inner extends import("effect/Schema").Top, infer _Headers extends import("effect/Schema").Top> ? import("effect/http-api/HttpApiSchema").WithHeaders<_Inner extends import("effect/http-api/HttpApiSchema").StreamSchema ? _Inner : import("effect/Schema").toCodecJson<_Inner>, import("effect/Schema").toCodecStringTree<_Headers>> : never : never) : ((O extends readonly (infer A)[] ? A : O) extends (infer Success) ? Success extends import("effect/http-api/HttpApiSchema").StreamSchema ? Success : never : never) | ((O extends readonly (infer A)[] ? A : O) extends (infer Success_1) ? Success_1 extends import("effect/http-api/HttpApiSchema").WithHeaders<infer _Inner extends import("effect/Schema").Top, infer _Headers extends import("effect/Schema").Top> ? import("effect/http-api/HttpApiSchema").WithHeaders<_Inner extends import("effect/http-api/HttpApiSchema").StreamSchema ? _Inner : import("effect/Schema").toCodecJson<_Inner>, import("effect/Schema").toCodecStringTree<_Headers>> : never : never) | import("effect/Schema").toCodecJson<Exclude<Extract<O extends readonly (infer A)[] ? A : O, import("effect/Schema").Top>, import("effect/http-api/HttpApiSchema").WithHeaders<import("effect/Schema").Top, import("effect/Schema").Top> | import("effect/http-api/HttpApiSchema").StreamSchema>>, [import("effect/Schema").Union<readonly [import("effect/Schema").Union<Errors>]>] extends [import("effect/Schema").Constraint] ? import("effect/Schema").toCodecJson<import("effect/Schema").Constraint & import("effect/Schema").Union<readonly [import("effect/Schema").Union<Errors>]>> : never, never, never>;
130
+ method: import("effect/http/HttpMethod").HttpMethod;
131
+ path: `/${string}`;
132
+ rpc: import("effect/rpc/Rpc").Rpc<N, I extends import("effect/Schema").Struct.Fields ? import("effect/Schema").Struct<I> : I, O, import("effect/Schema").Union<Errors>, never, never>;
133
+ tool: import("effect/ai/Tool").Tool<N, {
134
+ readonly parameters: I;
135
+ readonly success: O;
136
+ readonly failure: import("effect/Schema").Union<Errors>;
137
+ readonly failureMode: "error";
138
+ }, never>;
139
+ mcp: boolean;
140
+ }>;
141
+ endpoint: <const N extends string, const M extends import("effect/http/HttpMethod").HttpMethod, const I extends Record<string, import("effect/Schema").Top>, O extends import("effect/Schema").Top, const Errors extends readonly import("effect/Schema").Top[]>(name: N, method: M, path: `/${string}`, schemas: {
142
+ readonly input: I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
143
+ readonly payload?: never;
144
+ } : unknown);
145
+ readonly output: O;
146
+ readonly errors: Errors;
147
+ readonly mcp?: boolean;
148
+ readonly description?: string;
149
+ readonly title?: string;
150
+ }) => (<Failure extends Errors[number]["Type"], R>(handler: (input: import("effect/Schema").Struct.View<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
151
+ readonly payload?: never;
152
+ } : unknown), "Type", import("effect/Schema").Struct.TypeOptionalKeys<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
153
+ readonly payload?: never;
154
+ } : unknown)>, import("effect/Schema").Struct.TypeMutableKeys<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
155
+ readonly payload?: never;
156
+ } : unknown)>>) => import("effect/Effect").Effect<O["Type"], Failure, R>) => Readonly<{
157
+ method: import("effect/http/HttpMethod").HttpMethod;
158
+ endpoint: import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<N, M, `/${string}`, ["params" extends (infer T) ? T extends "params" ? T extends keyof I ? I[T] : never : never : never] extends [never] ? never : ("params" extends (infer T_1) ? T_1 extends "params" ? T_1 extends keyof I ? I[T_1] : never : never : never) extends (infer T_2) ? T_2 extends ("params" extends (infer T_3) ? T_3 extends "params" ? T_3 extends keyof I ? I[T_3] : never : never : never) ? T_2 extends import("effect/Schema").Top ? import("effect/Schema").toCodecStringTree<T_2> : never : never : never, ["query" extends (infer T_4) ? T_4 extends "query" ? T_4 extends keyof I ? I[T_4] : never : never : never] extends [never] ? never : ("query" extends (infer T_5) ? T_5 extends "query" ? T_5 extends keyof I ? I[T_5] : never : never : never) extends (infer T_6) ? T_6 extends ("query" extends (infer T_7) ? T_7 extends "query" ? T_7 extends keyof I ? I[T_7] : never : never : never) ? T_6 extends import("effect/Schema").Top ? import("effect/Schema").toCodecStringTree<T_6> : never : never : never, ["payload" extends (infer T_8) ? T_8 extends "payload" ? T_8 extends keyof I ? I[T_8] : never : never : never] extends [never] ? never : ("payload" extends (infer T_9) ? T_9 extends "payload" ? T_9 extends keyof I ? I[T_9] : never : never : never) extends (infer T_10) ? T_10 extends ("payload" extends (infer T_11) ? T_11 extends "payload" ? T_11 extends keyof I ? I[T_11] : never : never : never) ? T_10 extends import("effect/Schema").Top ? import("effect/Schema").toCodecJson<T_10> : never : never : never, ["headers" extends (infer T_12) ? T_12 extends "headers" ? T_12 extends keyof I ? I[T_12] : never : never : never] extends [never] ? never : ("headers" extends (infer T_13) ? T_13 extends "headers" ? T_13 extends keyof I ? I[T_13] : never : never : never) extends (infer T_14) ? T_14 extends ("headers" extends (infer T_15) ? T_15 extends "headers" ? T_15 extends keyof I ? I[T_15] : never : never : never) ? T_14 extends import("effect/Schema").Top ? import("effect/Schema").toCodecStringTree<T_14> : never : never : never, [O] extends [never] ? import("effect/http-api/HttpApiSchema").NoContent : O extends import("effect/Schema").Top ? import("effect/Schema").toCodecJson<O> : never, [Errors] extends [never] ? never : import("effect/Schema").toCodecJson<import("effect/Schema").Union<[import("effect/Schema").Union<Errors>]>>, never, never>;
159
+ httpHandler: (input: import("effect/Schema").Struct.View<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
160
+ readonly payload?: never;
161
+ } : unknown), "Type", import("effect/Schema").Struct.TypeOptionalKeys<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
162
+ readonly payload?: never;
163
+ } : unknown)>, import("effect/Schema").Struct.TypeMutableKeys<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
164
+ readonly payload?: never;
165
+ } : unknown)>>) => import("effect/Effect").Effect<O["Type"], Failure, Exclude<R, import("effect/Tracer").ParentSpan>>;
166
+ handler: (input: import("effect/Schema").Struct.View<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
167
+ readonly payload?: never;
168
+ } : unknown), "Type", import("effect/Schema").Struct.TypeOptionalKeys<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
169
+ readonly payload?: never;
170
+ } : unknown)>, import("effect/Schema").Struct.TypeMutableKeys<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
171
+ readonly payload?: never;
172
+ } : unknown)>>) => import("effect/Effect").Effect<O["Type"], Failure, Exclude<R, import("effect/Tracer").ParentSpan>>;
173
+ name: N;
174
+ path: `/${string}`;
175
+ rpc: import("effect/rpc/Rpc").Rpc<N, import("effect/Schema").Struct<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
176
+ readonly payload?: never;
177
+ } : unknown)>, O, import("effect/Schema").Union<Errors>, never, never>;
178
+ tool: import("effect/ai/Tool").Tool<N, {
179
+ readonly parameters: import("effect/Schema").Struct<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
180
+ readonly payload?: never;
181
+ } : unknown)>;
182
+ readonly success: O;
183
+ readonly failure: import("effect/Schema").Union<Errors>;
184
+ readonly failureMode: "error";
185
+ }, never>;
186
+ mcp: boolean;
187
+ }>) & {
188
+ name: N;
189
+ method: import("effect/http/HttpMethod").HttpMethod;
190
+ endpoint: import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<N, M, `/${string}`, ["params" extends (infer T) ? T extends "params" ? T extends keyof I ? I[T] : never : never : never] extends [never] ? never : ("params" extends (infer T_1) ? T_1 extends "params" ? T_1 extends keyof I ? I[T_1] : never : never : never) extends (infer T_2) ? T_2 extends ("params" extends (infer T_3) ? T_3 extends "params" ? T_3 extends keyof I ? I[T_3] : never : never : never) ? T_2 extends import("effect/Schema").Top ? import("effect/Schema").toCodecStringTree<T_2> : never : never : never, ["query" extends (infer T_4) ? T_4 extends "query" ? T_4 extends keyof I ? I[T_4] : never : never : never] extends [never] ? never : ("query" extends (infer T_5) ? T_5 extends "query" ? T_5 extends keyof I ? I[T_5] : never : never : never) extends (infer T_6) ? T_6 extends ("query" extends (infer T_7) ? T_7 extends "query" ? T_7 extends keyof I ? I[T_7] : never : never : never) ? T_6 extends import("effect/Schema").Top ? import("effect/Schema").toCodecStringTree<T_6> : never : never : never, ["payload" extends (infer T_8) ? T_8 extends "payload" ? T_8 extends keyof I ? I[T_8] : never : never : never] extends [never] ? never : ("payload" extends (infer T_9) ? T_9 extends "payload" ? T_9 extends keyof I ? I[T_9] : never : never : never) extends (infer T_10) ? T_10 extends ("payload" extends (infer T_11) ? T_11 extends "payload" ? T_11 extends keyof I ? I[T_11] : never : never : never) ? T_10 extends import("effect/Schema").Top ? import("effect/Schema").toCodecJson<T_10> : never : never : never, ["headers" extends (infer T_12) ? T_12 extends "headers" ? T_12 extends keyof I ? I[T_12] : never : never : never] extends [never] ? never : ("headers" extends (infer T_13) ? T_13 extends "headers" ? T_13 extends keyof I ? I[T_13] : never : never : never) extends (infer T_14) ? T_14 extends ("headers" extends (infer T_15) ? T_15 extends "headers" ? T_15 extends keyof I ? I[T_15] : never : never : never) ? T_14 extends import("effect/Schema").Top ? import("effect/Schema").toCodecStringTree<T_14> : never : never : never, [O] extends [never] ? import("effect/http-api/HttpApiSchema").NoContent : O extends import("effect/Schema").Top ? import("effect/Schema").toCodecJson<O> : never, [Errors] extends [never] ? never : import("effect/Schema").toCodecJson<import("effect/Schema").Union<[import("effect/Schema").Union<Errors>]>>, never, never>;
191
+ path: `/${string}`;
192
+ rpc: import("effect/rpc/Rpc").Rpc<N, import("effect/Schema").Struct<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
193
+ readonly payload?: never;
194
+ } : unknown)>, O, import("effect/Schema").Union<Errors>, never, never>;
195
+ tool: import("effect/ai/Tool").Tool<N, {
196
+ readonly parameters: import("effect/Schema").Struct<I & Record<Exclude<keyof I, "payload" | "params" | "query" | "headers">, never> & (M extends import("effect/http/HttpMethod").HttpMethod.NoBody ? {
197
+ readonly payload?: never;
198
+ } : unknown)>;
199
+ readonly success: O;
200
+ readonly failure: import("effect/Schema").Union<Errors>;
201
+ readonly failureMode: "error";
202
+ }, never>;
203
+ mcp: boolean;
204
+ };
205
+ service: <const N extends string, const A extends Record<string, ActionConstraint>>(name: N, options: {
206
+ readonly actions: A;
207
+ }) => Readonly<{
208
+ name: N;
209
+ actions: Readonly<A>;
210
+ group: import("effect/http-api/HttpApiGroup").HttpApiGroup<N, A[keyof A]["endpoint"]>;
211
+ }>;
212
+ app: typeof app;
213
+ compileService: typeof compileService;
214
+ layer: typeof layer;
215
+ mount: <A, E>(routes: import("effect/Layer").Layer<A, E, import("effect/http/HttpRouter").HttpRouter>) => Readonly<{
216
+ fetch: (request: Request) => Promise<Response>;
217
+ ready: () => Promise<void>;
218
+ dispose: () => Promise<void>;
219
+ }>;
220
+ errors: typeof errors_d_exports;
221
+ rpcGroup: <const A extends Record<string, {
222
+ readonly rpc: import("effect/rpc/Rpc").Any;
223
+ }>>(actions: A) => import("effect/rpc/RpcGroup").RpcGroup<A[keyof A]["rpc"]>;
224
+ route: typeof route;
124
225
  }>;
125
226
  //#endregion
126
- //#region src/compiler.d.ts
127
- type ApplicationBinder = (services: Service<any, any>[]) => CompiledApplication;
128
- /** Build artifact bootstrap: bind generated handlers while evaluating the original app. */
129
- export declare function loadCompiledBrickApp(load: () => Promise<{
130
- default: unknown;
131
- }>, ir: BrickIR, bind: ApplicationBinder): Promise<BrickApp>;
132
- interface CompiledRoute {
133
- readonly ir: RouteIR;
134
- readonly handler: CompiledHandler;
135
- }
136
- interface CompiledApplication {
137
- readonly ir: BrickIR;
138
- readonly routes: readonly CompiledRoute[];
139
- }
140
- /** Startup compiler: analyzes once, then binds live callbacks. */
141
- export declare function compileBrickApplication(options: {
142
- services: Service<any, any>[];
143
- prefix?: string;
144
- mode?: "specialized" | "generic";
145
- }): CompiledApplication;
146
- /** Build artifact binder: consumes emitted functions, with no runtime handler code generation. */
147
- export declare function bindCompiledApplication(ir: BrickIR, services: Service<any, any>[], factories: readonly HandlerFactory[]): CompiledApplication;
227
+ //#region src/native-app-entry.d.ts
228
+ type NativeBrickApp = ReturnType<typeof app>;
229
+ export declare function isNativeBrickApp(value: unknown): value is NativeBrickApp;
148
230
  //#endregion
149
- //#region src/request-logger.d.ts
150
- interface RequestLoggingOptions {
151
- enabled?: boolean;
152
- logger?: (msg: string) => void;
153
- }
231
+ //#region src/secrets.d.ts
154
232
  /**
155
- * Elysia plugin that logs each request as `METHOD path → status (elapsedms)`.
156
- * Timing is tracked per-Request via a WeakMap. The onError hook only logs and
157
- * returns undefined so existing error mapping is preserved. Logging only —
158
- * no CORS headers are set here.
233
+ * Type-safe secrets & environment variables.
234
+ *
235
+ * Declare each secret once at module scope instead of scattering untyped
236
+ * `process.env.FOO` reads:
237
+ *
238
+ * const port = secret("PORT").default("3333").transform(Number).require();
239
+ * const baseUrl = secret("BASE_URL").url().require();
240
+ * const key = secret("STRIPE_KEY").validate((v) =>
241
+ * v.startsWith("sk_") || "must start with sk_"
242
+ * ).require();
243
+ *
244
+ * Values resolve from the environment (Bun populates `process.env` from
245
+ * `.env` locally; in prod the same env source applies — a future
246
+ * `SecretSource` such as AWS can slot in without touching call sites).
159
247
  *
160
- * Hooks are registered with the "global" scope so they propagate to the
161
- * parent app when mounted via `app.use(...)` — Elysia scopes plain instance
162
- * hooks to the plugin's own routes. Timing is captured in beforeHandle
163
- * because request hooks are not propagated from a
164
- * used instance. Unmatched routes (no beforeHandle) fall back to Date.now().
248
+ * Resolution order per secret: test/session override → source (`process.env`
249
+ * by default) → declared `default`. `resolveSecrets()` validates every
250
+ * registered secret at boot and throws listing all missing required ones.
165
251
  */
166
- export declare function requestLoggingPlugin(opts?: RequestLoggingOptions): Elysia;
167
- //#endregion
168
- //#region src/docs.d.ts
169
- interface ReferenceOptions {
170
- path?: string;
171
- title?: string;
172
- specUrl?: string;
252
+ interface SecretSource {
253
+ get(name: string): string | undefined;
173
254
  }
174
- /** Renders the Scalar API reference page for the given OpenAPI URL. */
175
- export declare function scalarDocsHTML(specUrl: string, title: string): string;
176
- /** Standalone Elysia plugin serving GET <path> with the Scalar HTML page. */
177
- export declare function referencePlugin(opts?: ReferenceOptions): Elysia;
178
- /** Mounts the Scalar reference route onto an existing app. */
179
- export declare function registerReferenceRoute(app: Elysia, opts?: ReferenceOptions): Elysia;
180
- /** Renders the Swagger UI page. */
181
- export declare function swaggerDocsHTML(specUrl: string, title: string): string;
182
- //#endregion
183
- //#region src/action-handler.d.ts
184
- export declare function compileRoutePlan(service: Service, action: Action, routePath: string, method?: string): CompiledRoutePlan;
185
- export declare function executeCompiledRoute(plan: CompiledRoutePlan, elysiaCtx: any): Promise<any>;
186
- export declare function createActionHandler(service: Service, action: Action, routePath: string, method?: string): (elysiaCtx: any) => Promise<any>;
187
- //#endregion
188
- //#region src/server.d.ts
189
- interface CreateServerOptions {
190
- port?: number;
191
- /** Generate specialized handlers once at startup (default true). */
192
- compiler?: boolean;
193
- /** Ahead-of-time handlers already bound to the supplied services. */
194
- compilation?: CompiledApplication;
195
- services?: Service<any, any>[];
196
- prefix?: string;
197
- title?: string;
198
- version?: string;
199
- description?: string;
200
- docs?: boolean;
201
- openApiPath?: string;
202
- docsPath?: string;
203
- swaggerPath?: string;
204
- requestLogging?: boolean | RequestLoggingOptions;
205
- reference?: boolean | ReferenceOptions;
206
- secrets?: {
207
- source?: SecretSource;
208
- validate?: boolean;
209
- };
210
- /** Raw endpoints (outside the JSON action mesh), mounted at startup. */
211
- endpoints?: EndpointDefinition[];
255
+ /** Default source: `process.env` (Bun loads `.env` into it automatically). */
256
+ export declare const envSource: SecretSource;
257
+ interface SecretOptions {
258
+ /** Fallback when the source has no value. Secrets without a default are required. */
259
+ default?: string;
212
260
  }
213
- export declare function brick(options?: CreateServerOptions): BrickApp;
214
- //#endregion
215
- //#region src/app-entry.d.ts
216
- export declare function isBrickApp(app: unknown): app is BrickApp;
217
- export declare function requireBrickApp(app: unknown): BrickApp;
218
- //#endregion
219
- //#region src/compiler/emit.d.ts
220
- /** Emits framework code only. User callbacks remain closures bound separately. */
221
- export declare function emitHandlerFactory(route: RouteIR): string;
222
- //#endregion
223
- //#region src/db/index.d.ts
224
- export interface DatabaseConfig<TSchema extends Record<string, unknown> = Record<string, unknown>> extends Omit<SQLiteDatabaseConfig<TSchema>, "client">, Omit<PostgresDatabaseConfig<TSchema>, "client"> {
225
- client?: SQLiteDatabaseConfig<TSchema>["client"] | PostgresDatabaseConfig<TSchema>["client"];
226
- /** Database engine. Default: 'sqlite' */
227
- engine?: "sqlite" | "postgres" | "clickhouse";
228
- /** Optional service name associated with this database */
229
- name?: string;
230
- }
231
- export type BrickDatabase<TSchema extends Record<string, unknown> = Record<string, unknown>> = BunSQLiteDatabase<TSchema> | PostgresDatabase<TSchema>;
232
- /**
233
- * Creates a database instance based on the provided configuration.
234
- * Zero-config: calling `createDatabase()` returns an ultra-fast Bun-native SQLite
235
- * database in `:memory:` mode wrapped with Drizzle ORM.
236
- */
237
- export declare function createDatabase<TSchema extends Record<string, unknown> = Record<string, unknown>>(config?: DatabaseConfig<TSchema>): BunSQLiteDatabase<TSchema> | PostgresDatabase<TSchema>;
238
- /** Attach a defined database. Schema changes remain the caller's responsibility. */
239
- export declare function attachDatabase<TDb>(service: Service<TDb, any>, database: DatabaseHandle<TDb>): TDb;
240
- /**
241
- * Generates an idempotent SQLite CREATE TABLE IF NOT EXISTS definition
242
- * directly from a Drizzle table schema.
243
- */
244
- export declare function generateSQLiteTableDdl(table: any): string;
245
- /**
246
- * Generates idempotent secondary index DDL for a Drizzle table.
247
- * Covers owner scoping, sort columns, and exact-match filters.
248
- * UNIQUE columns already carry an implicit index — skipped here.
249
- * FTS/trigram indexes are handled separately by the search layer.
250
- */
251
- export declare function generateSQLiteIndexDdl(table: any, opts?: {
252
- ownerField?: string;
253
- sortFields?: string[];
254
- }): string[];
255
- /**
256
- * Ensures secondary indexes exist for a resource table.
257
- * SQLite: B-tree indexes for owner scope + sort + composite hot path.
258
- * Postgres: same B-trees plus pg_trgm GIN indexes for substring search.
259
- * Best-effort: failures warn and continue (e.g. read-only replicas).
260
- */
261
- export declare function ensureResourceIndexes(db: any, table: any, opts?: {
262
- ownerField?: string;
263
- sortFields?: string[];
264
- searchFields?: string[];
265
- }): void;
266
- /**
267
- * Creates the FTS5 sidecar table + sync triggers + backfills existing rows.
268
- * Idempotent; safe to call on every resource registration.
269
- * No-op on Postgres (relies on pg_trgm instead) and when searchCols is empty.
270
- */
271
- export declare function ensureSQLiteFts(db: any, table: any, searchCols: string[]): void;
272
- /**
273
- * Builds an FTS5 MATCH condition for a resource search term.
274
- * Returns null when the term has no usable tokens or FTS errors.
275
- * Caller falls back to LIKE in that case.
276
- */
277
- export declare function buildFtsMatchQuery(search: string): string | null;
278
- /**
279
- * Explicit SQLite development/test schema preparation helper.
280
- * Never called by services, resources, auth, or server startup.
281
- * Not a migration runner; PostgreSQL schema management is caller-owned.
282
- */
283
- export declare function syncSchema(tablesOrService: Map<string, any> | any[] | Record<string, any> | Service, dbInstance?: any): Promise<void> | void;
284
- //#endregion
285
- //#region src/service.d.ts
286
- export declare class ServiceImpl<TDb = BunSQLiteDatabase<Record<string, unknown>>, TServiceContext extends Record<string, any> = Record<string, any>> implements Service<TDb, TServiceContext> {
261
+ /** A validator: return `true`/`void` when ok, `false`/reason/`throw` when not. */
262
+ type SecretValidator<T> = (value: T) => void | boolean | string;
263
+ export declare class SecretRef<T = string> {
287
264
  readonly name: string;
288
- readonly options: ServiceOptions<TServiceContext, TDb>;
289
- readonly actions: Map<string, Action<any, any, any, any>>;
290
- readonly tools: Map<string, Tool<any, any, any, any>>;
291
- readonly tables: Map<string, any>;
292
- readonly resources: Map<string, Resource<any, BaseContext<TDb> & TServiceContext, {}>>;
293
- readonly preparations: Map<string, PreparationContribution>;
294
- private database?;
295
- private _isBuilt;
296
- constructor(name: string, options?: ServiceOptions<TServiceContext, TDb>);
297
- use<A>(plugin: ServicePlugin<this, A>): A;
298
- get db(): TDb | undefined;
299
- get isBuilt(): boolean;
300
- /**
301
- * Closes declarations after plugins have registered their actions and preparations.
302
- */
303
- build(): this;
304
- contributePreparation(contribution: PreparationContribution): void;
305
- listPreparations(): PreparationContribution[];
306
- prepareContributions(): void;
307
- registerTable(table: any): this;
308
- resource: Service<TDb, TServiceContext>["resource"];
309
- getResource(name: string): Resource<any, BaseContext<TDb> & TServiceContext> | undefined;
310
- listResources(): Resource<any, BaseContext<TDb> & TServiceContext>[];
311
- action<TIn extends TSchema$1 | undefined = undefined, TOut extends TSchema$1 | undefined = undefined, TErr extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>>(action: Action<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>): this;
312
- action<TIn extends TSchema$1 | undefined = undefined, TOut extends TSchema$1 | undefined = undefined, TErr extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>>(config: ActionConfigWithAuthorize<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>): Action<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>;
313
- action<TIn extends TSchema$1 | undefined = undefined, TOut extends TSchema$1 | undefined = undefined, TErr extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>>(config: ActionConfigWithoutAuthorize<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>): Action<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>;
314
- tool<TIn extends TSchema$1 | undefined = undefined, TOut extends TSchema$1 | undefined = undefined, TErr extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>>(action: Tool<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>): this;
315
- tool<TIn extends TSchema$1 | undefined = undefined, TOut extends TSchema$1 | undefined = undefined, TErr extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>>(config: ToolConfigWithAuthorize<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>): Tool<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>;
316
- tool<TIn extends TSchema$1 | undefined = undefined, TOut extends TSchema$1 | undefined = undefined, TErr extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>>(config: ToolConfigWithoutAuthorize<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>): Tool<TIn, TOut, TErr, BaseContext<TDb> & TServiceContext>;
317
- getTool(name: string): Tool<any, any, any, any> | undefined;
318
- listTools(): Tool<any, any, any, any>[];
319
- getAction(name: string): Action<any, any, any, any> | undefined;
320
- listActions(): Action<any, any, any, any>[];
321
- getDb(): TDb | undefined;
322
- setDb(database: DatabaseHandle<TDb>): void;
265
+ readonly options: SecretOptions;
266
+ private transformFn?;
267
+ private validators;
268
+ constructor(name: string, options?: SecretOptions);
269
+ /** True when a default was declared (i.e. the secret is optional). */
270
+ get hasDefault(): boolean;
271
+ /** Fallback used when the source has no value. Makes the secret optional. */
272
+ default(value: string): this;
323
273
  /**
324
- * Resolves the complete service execution context once per incoming request.
325
- * Merges framework BaseContext with the service's custom context hook.
326
- * Always rebuilds context for this service to prevent caller context from overriding.
274
+ * Convert the raw string (e.g. `Number`, `JSON.parse`, `v === "true"`).
275
+ * Runs before validators; a throwing transform fails resolution.
327
276
  */
328
- resolveContext(callCtx?: Partial<BaseContext<TDb> & TServiceContext>): Promise<BaseContext<TDb> & TServiceContext>;
329
- private _resolveContextSlow;
330
- introspect(): ServiceSchema;
331
- }
332
- export declare function defineService<TDb = BunSQLiteDatabase<Record<string, unknown>>, TServiceContext extends Record<string, any> = Record<string, any>>(name: string, options?: ServiceOptions<TServiceContext, TDb>): Service<TDb, TServiceContext>;
333
- //#endregion
334
- //#region src/access.d.ts
335
- interface ActionAccessInfo {
336
- hasAuthorize: boolean;
337
- hasScope: boolean;
338
- policy: ActionAccessPolicy;
277
+ transform<U>(fn: (raw: string) => U): SecretRef<U>;
278
+ /** Run a custom check on the (transformed) value at every resolution. */
279
+ validate(fn: SecretValidator<T>): this;
280
+ /** Shorthand validator: value must parse as a URL. String refs only. */
281
+ url(this: SecretRef<string>): SecretRef<string>;
282
+ private resolveRaw;
283
+ private coerce;
284
+ /** Resolved (transformed, validated) value or `undefined`. Never throws on missing. */
285
+ value(source?: SecretSource): T | undefined;
286
+ /** Resolved value, or throws naming the missing/invalid secret. */
287
+ require(source?: SecretSource): T;
288
+ /** True when a value would resolve (override, source, or default). */
289
+ isSet(source?: SecretSource): boolean;
339
290
  }
340
291
  /**
341
- * Cross-copy access metadata protocol. CRUD enforces its access policy
342
- * inside `execute`, so `config.authorize` is absent and introspection
343
- * can't see it. The plugin stamps each action under this process-global
344
- * symbol; introspection and OpenAPI read it back. Uses `Symbol.for` so
345
- * the binding survives a second copy of core (bundler SSR, Vitest),
346
- * same as the plugin action-binding key.
292
+ * Declare a secret. Idempotent: re-declaring the same name returns the
293
+ * original ref (first declaration wins) so module re-evaluation is safe.
347
294
  */
348
- export declare const ACTION_ACCESS_KEY: unique symbol;
349
- export declare function setActionAccess(action: object, info: ActionAccessInfo): void;
350
- export declare function getActionAccess(action: Action | object): ActionAccessInfo;
351
- //#endregion
352
- //#region src/action.d.ts
353
- export declare function buildErrorHelpers<TErrors extends Record<string, ActionErrorDefinition>>(errorsDef?: TErrors): ErrorBuilder<TErrors>;
354
- export declare function defineAction<TInputSchema extends TSchema$1 | undefined = undefined, TOutputSchema extends TSchema$1 | undefined = undefined, TErrors extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>, TContext extends ActionContext = ActionContext>(config: ActionConfigWithAuthorize<TInputSchema, TOutputSchema, TErrors, TContext>): Action<TInputSchema, TOutputSchema, TErrors, TContext>;
355
- export declare function defineAction<TInputSchema extends TSchema$1 | undefined = undefined, TOutputSchema extends TSchema$1 | undefined = undefined, TErrors extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>, TContext extends ActionContext = ActionContext>(config: ActionConfigWithoutAuthorize<TInputSchema, TOutputSchema, TErrors, TContext>): Action<TInputSchema, TOutputSchema, TErrors, TContext>;
356
- //#endregion
357
- //#region src/resource.d.ts
358
- /** Declares a plugin host without registering actions or changing the schema. */
359
- export declare function defineResource<TTable = any, TCtx extends ActionContext = ActionContext, const O extends ResourceTypeOptions = ResourceTypeOptions>(service: Service<any, any>, config: ResourceConfig<TTable, TCtx> & O): Resource<TTable, TCtx, ResourceIdentity<TTable, O>>;
360
- //#endregion
361
- //#region src/rpc.d.ts
362
- export declare function createServiceProxy<T extends Record<string, any>>(serviceName: string, options?: ProxyOptions): T;
363
- //#endregion
364
- //#region src/registry.d.ts
365
- interface ArchitectureApplication {
366
- services: readonly Service[];
367
- routes: readonly RouteIR[];
368
- }
369
- export declare class ServiceRegistry {
370
- private _revision;
371
- /** Definition revision for invalidating serialized architecture snapshots. */
372
- get revision(): number;
373
- touch(): void;
374
- private services;
375
- private routes;
376
- /** Remember the actual registered routes for subsequent registry exports. */
377
- setApplicationRoutes(application: ArchitectureApplication): void;
378
- register(service: Service): void;
379
- get(name: string): Service | undefined;
380
- has(name: string): boolean;
381
- list(): Service[];
382
- clear(): void;
383
- exportArchitecture(application?: ArchitectureApplication): ArchitectureSchema;
384
- }
385
- export declare function getGlobalRegistry(): ServiceRegistry;
386
- export declare function resetGlobalRegistry(): void;
387
- //#endregion
388
- //#region src/typebox.d.ts
389
- export declare function getCompiledCheck<T extends TSchema>(schema: T): TypeCheck<T>;
390
- export declare function validateWithSchema<T extends TSchema>(schema: T | undefined, value: unknown): {
391
- success: true;
392
- data: Static<T>;
393
- } | {
394
- success: false;
395
- errors: ValidationErrorItem[];
396
- };
397
- //#endregion
398
- //#region src/openapi.d.ts
399
- interface OpenApiGeneratorOptions {
400
- title?: string;
401
- version?: string;
402
- description?: string;
403
- prefix?: string;
404
- services?: Service<any, any>[];
405
- registry?: ServiceRegistry;
406
- }
407
- export declare function generateOpenApiSpec(options?: OpenApiGeneratorOptions): Record<string, any>;
408
- //#endregion
409
- //#region src/tool.d.ts
410
- export declare function defineTool<TInputSchema extends TSchema$1 | undefined = undefined, TOutputSchema extends TSchema$1 | undefined = undefined, TErrors extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>, TContext extends ActionContext = ActionContext>(config: ToolConfigWithAuthorize<TInputSchema, TOutputSchema, TErrors, TContext>): Tool<TInputSchema, TOutputSchema, TErrors, TContext>;
411
- export declare function defineTool<TInputSchema extends TSchema$1 | undefined = undefined, TOutputSchema extends TSchema$1 | undefined = undefined, TErrors extends Record<string, ActionErrorDefinition> = Record<string, ActionErrorDefinition>, TContext extends ActionContext = ActionContext>(config: ToolConfigWithoutAuthorize<TInputSchema, TOutputSchema, TErrors, TContext>): Tool<TInputSchema, TOutputSchema, TErrors, TContext>;
412
- export declare function isTool(value: unknown): value is Tool<any, any, any, any>;
413
- //#endregion
414
- //#region src/mcp.d.ts
415
- interface McpToolDefinition {
416
- name: string;
417
- title?: string;
418
- description: string;
419
- inputSchema: unknown;
420
- annotations: ToolAnnotations;
421
- }
422
- interface McpRegistryOptions {
423
- services?: readonly Pick<Service<any, any>, "listTools">[];
424
- tools?: readonly Tool<any, any, any, any>[];
425
- }
426
- interface McpRegistry {
427
- listTools(): McpToolDefinition[];
428
- callTool(name: string, args?: Record<string, unknown>, ctx?: Partial<ActionContext>): Promise<unknown>;
429
- }
430
- export declare class UnknownToolError extends Error {
431
- constructor(name: string);
432
- }
433
- /** Collect only explicitly defined tools, without exposing ordinary actions. */
434
- export declare function createMcpRegistry(options: McpRegistryOptions): McpRegistry;
435
- interface McpHandlerOptions {
436
- registry: McpRegistry;
437
- serverInfo: {
438
- name: string;
439
- version: string;
440
- title?: string;
441
- };
442
- /** Versions supported by this transport, newest first. */
443
- protocolVersions?: readonly string[];
444
- }
445
- /** Stateless MCP JSON-RPC POST handler. Wrap with the app's authentication. */
446
- export declare function createMcpHandler(options: McpHandlerOptions): (request: Request, ctx?: Partial<ActionContext>) => Promise<Response>;
447
- //#endregion
448
- //#region src/error-response.d.ts
449
- interface ErrorEnvelope {
295
+ export declare function secret(name: string, options?: SecretOptions): SecretRef<string>;
296
+ /**
297
+ * Validate every registered secret at boot. Throws a single error listing
298
+ * all missing required secrets. Returns the resolved values.
299
+ */
300
+ export declare function resolveSecrets(opts?: {
301
+ source?: SecretSource;
302
+ }): Record<string, unknown>;
303
+ /** Metadata for introspection (values never exposed — future dashboard use). */
304
+ export declare function listSecrets(opts?: {
305
+ source?: SecretSource;
306
+ }): Array<{
450
307
  name: string;
451
- code: string;
452
- message: string;
453
- status: number;
454
- requestId: string;
455
- details?: unknown;
456
- errors?: ValidationError["errors"];
457
- }
458
- type ErrorContext = {
459
- logger: Pick<Logger, "error">;
460
- requestId: string;
461
- };
462
- export declare function toErrorResponse(err: unknown, context: ErrorContext): ErrorEnvelope;
308
+ hasDefault: boolean;
309
+ isSet: boolean;
310
+ }>;
311
+ /** Test/session override for one secret (`undefined` clears the override). */
312
+ export declare function overrideSecret(name: string, value: string | undefined): void;
313
+ /** Bulk overrides (test/session scoped). */
314
+ export declare function overrideSecrets(values: Record<string, string | undefined>): void;
315
+ /** Clear registry and overrides. Test-only. */
316
+ export declare function resetSecrets(): void;
463
317
  //#endregion
464
- export { Action, type ActionAccessInfo, ActionAccessPolicy, ActionConfig, ActionConfigWithAuthorize, ActionConfigWithoutAuthorize, ActionContext, ActionErrorDefinition, ActionExecutionError, ActionSchema, ArchitectureSchema, BaseActionConfig, BaseContext, type BrickActionCaller, type BrickApp, type BrickCallOptions, type BrickClient, type BrickClientAction, type BrickClientOptions, type BrickIR, BrickSQLiteDatabase, BrickServerError, BrickTransportError, type BunSQLiteDatabase, CacheOptions, type CompiledApplication, type CompiledHandler, type CompiledRoute, CompiledRoutePlan, type CreateServerOptions, DatabaseAdapter, DatabaseDefinition, DatabaseHandle, DefaultServiceContext, type EndpointContext, type EndpointDefinition, type EndpointLogger, type EndpointMethod, EnvInput, ErrorBuilder, type ErrorEnvelope, type HandlerFactory, type InferActionErrorCodes, type InferActionFailure, type InferActionInput, type InferActionOutput, InferTableInsert, InferTableRow, LifecycleOptions, Logger, type McpHandlerOptions, type McpRegistry, type McpRegistryOptions, type McpToolDefinition, NarrowAuthorizedContext, type OpenApiGeneratorOptions, type PluginEndpointContext, type PluginRouteMethod, type PluginRouteRegistrar, type PluginRouteScope, type PluginRoutes, PostgresDatabase, PostgresDatabaseConfig, PostgresDefinition, PreparationContribution, ProxyOptions, RateLimitOptions, type ReferenceOptions, type RequestLoggingOptions, ResilienceOptions, Resource, ResourceConfig, ResourceIdentity, type ResourcePlugin, type ResourcePluginAPI, type ResourcePluginContext, type ResourcePluginTypes, ResourceTypeOptions, type RouteIR, type RouteMethod, SQLiteDatabaseConfig, SQLiteDefinition, type SecretOptions, SecretRef, type SecretSource, Service, ServiceAuthOptions, ServiceOptions, type ServicePlugin, type ServicePluginContext, ServiceSchema, StandardErrorMap, type Static, type TSchema, Table, TelemetryOptions, Tool, ToolAnnotations, ToolConfigWithAuthorize, ToolConfigWithoutAuthorize, ToolOptions, Type, Type as t, ValidationError, ValidationErrorItem, and, asc, blob, createBrickClient, createPostgresDatabase, createSQLiteDatabase, defineDatabase, defineResourcePlugin, defineServicePlugin, desc, envSource, eq, foreignKey, getPluginActionRoute, getPluginEndpoints, getTableColumns, getTableName, gt, gte, ilike, inArray, index, integer, is, isBrickServerError, isBrickTransportError, isDatabaseHandle, isNotNull, isNull, like, listSecrets, lt, lte, ne, not, notInArray, or, overrideSecret, overrideSecrets, primaryKey, real, relations, resetSecrets, resolveSecrets, secret, sql, sqliteTable, text, uniqueIndex };
318
+ export type { NativeBrickApp, SecretOptions, SecretSource };
465
319
  //# sourceMappingURL=index.d.ts.map