@brickkit/core 0.10.0 → 0.12.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/README.md +1 -1
- package/dist/chunks/client.d.ts +13 -1862
- package/dist/chunks/client.js +328 -83
- package/dist/chunks/client.js.map +1 -1
- package/dist/chunks/index.d.ts +1106 -0
- package/dist/chunks/server.js +4624 -0
- package/dist/chunks/server.js.map +1 -0
- package/dist/chunks/types.d.ts +2701 -0
- package/dist/chunks/workflow.d.ts +74 -0
- package/dist/client.d.ts +3 -2
- package/dist/index.d.ts +5 -1076
- package/dist/index.js +756 -3726
- package/dist/index.js.map +1 -1
- package/dist/pg.d.ts +0 -2
- package/dist/tanstack-query.d.ts +2 -3
- package/dist/tanstack-query.js +1 -2
- package/dist/testing.d.ts +31 -0
- package/dist/testing.js +47 -0
- package/dist/testing.js.map +1 -0
- package/dist/workflow.d.ts +2 -0
- package/dist/workflow.js +93 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +32 -18
- package/dist/chunks/client.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/pg.d.ts.map +0 -1
- package/dist/tanstack-query.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,1076 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
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";
|
|
7
|
-
//#region src/compiler/ir.d.ts
|
|
8
|
-
type RouteMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
9
|
-
interface RouteIR {
|
|
10
|
-
readonly method: RouteMethod;
|
|
11
|
-
readonly path: string;
|
|
12
|
-
readonly service: string;
|
|
13
|
-
readonly action: string;
|
|
14
|
-
readonly kind: "action";
|
|
15
|
-
readonly input: boolean;
|
|
16
|
-
readonly output: boolean;
|
|
17
|
-
readonly context: boolean;
|
|
18
|
-
readonly authorize: boolean;
|
|
19
|
-
readonly inputPrecedence: readonly ("query" | "params" | "body")[];
|
|
20
|
-
readonly coercions: readonly {
|
|
21
|
-
readonly key: string;
|
|
22
|
-
readonly type: "number" | "boolean" | "array";
|
|
23
|
-
}[];
|
|
24
|
-
/** JSON projection for inspection and stale-artifact detection, not runtime validation. */
|
|
25
|
-
readonly inputSchema?: unknown;
|
|
26
|
-
readonly outputSchema?: unknown;
|
|
27
|
-
}
|
|
28
|
-
interface BrickIR {
|
|
29
|
-
readonly version: 1;
|
|
30
|
-
readonly target: "bun-elysia";
|
|
31
|
-
readonly prefix: string;
|
|
32
|
-
readonly services: readonly string[];
|
|
33
|
-
readonly routes: readonly RouteIR[];
|
|
34
|
-
readonly preparations: readonly {
|
|
35
|
-
service: string;
|
|
36
|
-
name: string;
|
|
37
|
-
metadata: unknown;
|
|
38
|
-
}[];
|
|
39
|
-
readonly diagnostics: readonly string[];
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/docs.d.ts
|
|
43
|
-
/** An OpenAPI document as plain JSON. */
|
|
44
|
-
type OpenApiDocument = Record<string, unknown>;
|
|
45
|
-
/** An extra OpenAPI document for the API reference, such as Better Auth's. */
|
|
46
|
-
interface ReferenceDocument {
|
|
47
|
-
/** Name in the reference's list of documents. */
|
|
48
|
-
title: string;
|
|
49
|
-
/** The document, or a function returning it; called each time the app starts. */
|
|
50
|
-
document: OpenApiDocument | (() => OpenApiDocument | Promise<OpenApiDocument>);
|
|
51
|
-
}
|
|
52
|
-
/** A named OpenAPI document ready to render. */
|
|
53
|
-
interface ApiDocument {
|
|
54
|
-
title: string;
|
|
55
|
-
document: OpenApiDocument;
|
|
56
|
-
}
|
|
57
|
-
/** Developer documentation for the `brick dev` dashboard. */
|
|
58
|
-
interface DocumentationOptions {
|
|
59
|
-
/**
|
|
60
|
-
* Folder of `.md`/`.mdx` pages. A relative path starts at the folder of the
|
|
61
|
-
* app entry, as it reads in the file that sets it.
|
|
62
|
-
*/
|
|
63
|
-
dir: string;
|
|
64
|
-
/**
|
|
65
|
-
* Module whose exports are React components for MDX, added to the built-in
|
|
66
|
-
* ones; a relative path starts where `dir` does. A default export or a
|
|
67
|
-
* `components` export holds the name-to-component map. The dashboard bundles
|
|
68
|
-
* it, so it may import anything the project has.
|
|
69
|
-
*/
|
|
70
|
-
components?: string;
|
|
71
|
-
}
|
|
72
|
-
interface ReferenceOptions {
|
|
73
|
-
/** Also serve a standalone Scalar page here. Without a path, no page is served. */
|
|
74
|
-
path?: string;
|
|
75
|
-
title?: string;
|
|
76
|
-
specUrl?: string;
|
|
77
|
-
/** More OpenAPI documents for the `brick dev` dashboard's APIs view. */
|
|
78
|
-
documents?: ReferenceDocument[];
|
|
79
|
-
}
|
|
80
|
-
/** Renders the Scalar API reference page for the given OpenAPI URL. */
|
|
81
|
-
export declare function scalarDocsHTML(specUrl: string, title: string): string;
|
|
82
|
-
/** Standalone Elysia plugin serving GET <path> with the Scalar HTML page. */
|
|
83
|
-
export declare function referencePlugin(opts?: ReferenceOptions): Elysia;
|
|
84
|
-
/** Mounts the Scalar reference route onto an existing app. */
|
|
85
|
-
export declare function registerReferenceRoute(app: Elysia, opts?: ReferenceOptions): Elysia;
|
|
86
|
-
/** Renders the Swagger UI page. */
|
|
87
|
-
export declare function swaggerDocsHTML(specUrl: string, title: string): string;
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/dashboard.d.ts
|
|
90
|
-
/** Who may open the dashboard that `brick start` serves for monitoring. */
|
|
91
|
-
interface DashboardAuth {
|
|
92
|
-
/**
|
|
93
|
-
* Secrets that let a request in. A browser asks for one in its sign-in
|
|
94
|
-
* prompt (any user name, the secret as the password), and monitors and
|
|
95
|
-
* scripts send `Authorization: Bearer <secret>`. Give several to rotate one
|
|
96
|
-
* while the other still works. Each is at least 16 characters long;
|
|
97
|
-
* `openssl rand -base64 32` makes a good one.
|
|
98
|
-
*/
|
|
99
|
-
token?: string | readonly string[];
|
|
100
|
-
/**
|
|
101
|
-
* Your own check, to sign people in with the auth the app already has: read
|
|
102
|
-
* a session cookie, verify a Better Auth or Clerk session, look at a header
|
|
103
|
-
* a proxy adds. It receives the request (method, URL, and headers; no body)
|
|
104
|
-
* and returns `true` to let it in, `false` to refuse it with 401, or a
|
|
105
|
-
* `Response` to send instead, such as a redirect to your login page. If it
|
|
106
|
-
* throws or takes longer than five seconds, the request is refused with 503.
|
|
107
|
-
*
|
|
108
|
-
* A request is let in when it carries a valid `token`, or when this
|
|
109
|
-
* returns `true`; give both to let monitors in by token and people in by
|
|
110
|
-
* sign-in.
|
|
111
|
-
*/
|
|
112
|
-
authorize?: (request: Request) => boolean | Response | Promise<boolean | Response>;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* The monitoring dashboard `brick start` serves beside the app, on a port of
|
|
116
|
-
* its own: live requests, logs, errors, and the shape of the service, so it
|
|
117
|
-
* stays reachable when the app's own routes are not. `brick dev` has its own
|
|
118
|
-
* dashboard, set by command line options, and ignores this.
|
|
119
|
-
*
|
|
120
|
-
* Setting it turns on `telemetry`, since the dashboard shows what is traced.
|
|
121
|
-
* While it is on, `ctx.logger` and `console` lines written during a request
|
|
122
|
-
* go to the dashboard instead of the console.
|
|
123
|
-
*/
|
|
124
|
-
interface DashboardOptions {
|
|
125
|
-
/** Default 9400. */
|
|
126
|
-
port?: number;
|
|
127
|
-
/**
|
|
128
|
-
* The address to listen on. Default `127.0.0.1`, reachable only from the same
|
|
129
|
-
* machine. In a container use `0.0.0.0`, which needs `auth`: the dashboard
|
|
130
|
-
* will not start on any other address without it.
|
|
131
|
-
*/
|
|
132
|
-
host?: string;
|
|
133
|
-
auth?: DashboardAuth;
|
|
134
|
-
/**
|
|
135
|
-
* Days of finished requests to keep on disk, in `.brick/` of the working
|
|
136
|
-
* folder. Default 0: only what happened since the process started, which is
|
|
137
|
-
* lost when it restarts. Needs a folder that outlives the container.
|
|
138
|
-
*/
|
|
139
|
-
historyDays?: number;
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/endpoints.d.ts
|
|
143
|
-
type EndpointMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
144
|
-
/** Logger subset handed to endpoint handlers (mirrors action context loggers). */
|
|
145
|
-
interface EndpointLogger {
|
|
146
|
-
info: (...args: any[]) => void;
|
|
147
|
-
warn: (...args: any[]) => void;
|
|
148
|
-
error: (...args: any[]) => void;
|
|
149
|
-
debug: (...args: any[]) => void;
|
|
150
|
-
}
|
|
151
|
-
/** Context for raw endpoint handlers: Elysia route fields + Brick extras. */
|
|
152
|
-
interface EndpointContext {
|
|
153
|
-
params: Record<string, string>;
|
|
154
|
-
query: Record<string, string | undefined>;
|
|
155
|
-
body: unknown;
|
|
156
|
-
headers: Record<string, string>;
|
|
157
|
-
request: Request;
|
|
158
|
-
/** Elysia response setter (status/headers). Mutate like in `app.get`. */
|
|
159
|
-
set: {
|
|
160
|
-
status?: number;
|
|
161
|
-
headers: Record<string, string>;
|
|
162
|
-
};
|
|
163
|
-
/** Drizzle db from `service` (or first service with one); `undefined` when none. */
|
|
164
|
-
db: any;
|
|
165
|
-
logger: EndpointLogger;
|
|
166
|
-
traceId: string;
|
|
167
|
-
requestId: string;
|
|
168
|
-
}
|
|
169
|
-
interface EndpointDefinition {
|
|
170
|
-
method: EndpointMethod;
|
|
171
|
-
/** Elysia-style path, e.g. `/p/:slug`. */
|
|
172
|
-
path: string;
|
|
173
|
-
handler: (ctx: EndpointContext) => unknown | Promise<unknown>;
|
|
174
|
-
/** Db source: instance or registered service name. Defaults to first service with a db. */
|
|
175
|
-
service?: Service<any, any> | string;
|
|
176
|
-
/** Explicit database handle, independent of a service. */
|
|
177
|
-
database?: DatabaseHandle<unknown>;
|
|
178
|
-
summary?: string;
|
|
179
|
-
description?: string;
|
|
180
|
-
tags?: string[];
|
|
181
|
-
}
|
|
182
|
-
/** Resolve the db for an endpoint: explicit service first, else first service holding one. */
|
|
183
|
-
export declare function resolveEndpointDb(service: Service<any, any> | string | undefined, services: Service<any, any>[]): any;
|
|
184
|
-
/** Wrap a raw handler with trace ids, logger, db, and mesh-consistent error mapping. */
|
|
185
|
-
export declare function createEndpointHandler(def: EndpointDefinition, services: Service<any, any>[]): (elysiaCtx: any) => Promise<unknown>;
|
|
186
|
-
/** `/p/:slug` → `/p/{slug}` for OpenAPI. */
|
|
187
|
-
export declare function toOpenApiPath(elysiaPath: string): string;
|
|
188
|
-
/** OpenAPI `paths` fragment for declared endpoints (raw HTML included). */
|
|
189
|
-
export declare function endpointPaths(defs: EndpointDefinition[]): Record<string, any>;
|
|
190
|
-
/** The app object returned by `brick`: Elysia plus `endpoint()`. */
|
|
191
|
-
type BrickApp = Elysia<any, any, any, any, any, any, any> & {
|
|
192
|
-
/** Service definitions, prefix, and telemetry setting chosen at construction. */
|
|
193
|
-
readonly definition: {
|
|
194
|
-
readonly routes: readonly RouteIR[];
|
|
195
|
-
readonly sockets: readonly (BrickSocketSchema & {
|
|
196
|
-
service: string;
|
|
197
|
-
path: string;
|
|
198
|
-
})[];
|
|
199
|
-
readonly services: readonly Service<any, any>[];
|
|
200
|
-
readonly prefix: string;
|
|
201
|
-
readonly telemetry: boolean;
|
|
202
|
-
readonly documentation?: DocumentationOptions;
|
|
203
|
-
/** What `brick start` serves for monitoring; its `auth` is not enumerable. */
|
|
204
|
-
readonly dashboard?: DashboardOptions;
|
|
205
|
-
/** The listeners and settings of `events`, as plain data. */
|
|
206
|
-
readonly events?: EventsDefinition;
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* The events of this app, when `events` is set: start and stop delivery, drain
|
|
210
|
-
* what is due, and see or retry what is parked. `brick dev` and `brick start`
|
|
211
|
-
* start it for you.
|
|
212
|
-
*/
|
|
213
|
-
readonly events?: EventsHub;
|
|
214
|
-
/** Register a raw endpoint (outside the JSON action mesh). */
|
|
215
|
-
endpoint(def: EndpointDefinition): void;
|
|
216
|
-
/**
|
|
217
|
-
* The OpenAPI documents behind the dashboard's APIs view: this app's own
|
|
218
|
-
* unless `docs` is false, then those from `reference.documents`.
|
|
219
|
-
*/
|
|
220
|
-
referenceDocuments(): Promise<ApiDocument[]>;
|
|
221
|
-
/** All endpoints registered via `endpoint()` (declaration order). */
|
|
222
|
-
listEndpoints(): EndpointDefinition[];
|
|
223
|
-
};
|
|
224
|
-
//#endregion
|
|
225
|
-
//#region src/compiler/runtime.d.ts
|
|
226
|
-
type CompiledHandler = (context: any) => unknown | Promise<unknown>;
|
|
227
|
-
type HandlerFactory = (binding: CompiledRoutePlan, runtime: typeof compilerRuntime) => CompiledHandler;
|
|
228
|
-
/** Retains Brick's existing source precedence and treatment of empty bodies. */
|
|
229
|
-
declare function mergeInput(first: any, second: any, third: any): any;
|
|
230
|
-
declare function checkDepth(value: unknown, action: string): void;
|
|
231
|
-
declare function validate(check: NonNullable<CompiledRoutePlan["inputChecker"]>, value: unknown, action: string, stage: "input" | "output"): void;
|
|
232
|
-
declare function mapError(err: unknown, set: any, options: {
|
|
233
|
-
logger: Logger;
|
|
234
|
-
requestId: string;
|
|
235
|
-
}): ErrorEnvelope;
|
|
236
|
-
export declare const compilerRuntime: Readonly<{
|
|
237
|
-
emptyServices: Readonly<{}>;
|
|
238
|
-
defaultRequest: Request;
|
|
239
|
-
nextSequence: () => string;
|
|
240
|
-
mergeInput: typeof mergeInput;
|
|
241
|
-
checkDepth: typeof checkDepth;
|
|
242
|
-
validate: typeof validate;
|
|
243
|
-
mapError: typeof mapError;
|
|
244
|
-
isThenable: (value: any) => boolean;
|
|
245
|
-
deny: (action: string, user: unknown) => never;
|
|
246
|
-
}>;
|
|
247
|
-
//#endregion
|
|
248
|
-
//#region src/compiler.d.ts
|
|
249
|
-
type ApplicationBinder = (services: Service<any, any>[]) => CompiledApplication;
|
|
250
|
-
/** Build artifact bootstrap: bind generated handlers while evaluating the original app. */
|
|
251
|
-
export declare function loadCompiledBrickApp(load: () => Promise<{
|
|
252
|
-
default: unknown;
|
|
253
|
-
}>, ir: BrickIR, bind: ApplicationBinder): Promise<BrickApp>;
|
|
254
|
-
interface CompiledRoute {
|
|
255
|
-
readonly ir: RouteIR;
|
|
256
|
-
readonly handler: CompiledHandler;
|
|
257
|
-
}
|
|
258
|
-
interface CompiledApplication {
|
|
259
|
-
readonly ir: BrickIR;
|
|
260
|
-
readonly routes: readonly CompiledRoute[];
|
|
261
|
-
}
|
|
262
|
-
/** Startup compiler: analyzes once, then binds live callbacks. */
|
|
263
|
-
export declare function compileBrickApplication(options: {
|
|
264
|
-
services: Service<any, any>[];
|
|
265
|
-
prefix?: string;
|
|
266
|
-
mode?: "specialized" | "generic";
|
|
267
|
-
}): CompiledApplication;
|
|
268
|
-
/** Build artifact binder: consumes emitted functions, with no runtime handler code generation. */
|
|
269
|
-
export declare function bindCompiledApplication(ir: BrickIR, services: Service<any, any>[], factories: readonly HandlerFactory[]): CompiledApplication;
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region src/request-logger.d.ts
|
|
272
|
-
interface RequestLoggingOptions {
|
|
273
|
-
enabled?: boolean;
|
|
274
|
-
logger?: (msg: string) => void;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Elysia plugin that logs each request as `METHOD path → status (elapsedms)`.
|
|
278
|
-
* Timing is tracked per-Request via a WeakMap. The onError hook only logs and
|
|
279
|
-
* returns undefined so existing error mapping is preserved. Logging only —
|
|
280
|
-
* no CORS headers are set here.
|
|
281
|
-
*
|
|
282
|
-
* Hooks are registered with the "global" scope so they propagate to the
|
|
283
|
-
* parent app when mounted via `app.use(...)` — Elysia scopes plain instance
|
|
284
|
-
* hooks to the plugin's own routes. Timing is captured in beforeHandle
|
|
285
|
-
* because request hooks are not propagated from a
|
|
286
|
-
* used instance. Unmatched routes (no beforeHandle) fall back to Date.now().
|
|
287
|
-
*/
|
|
288
|
-
export declare function requestLoggingPlugin(opts?: RequestLoggingOptions): Elysia;
|
|
289
|
-
//#endregion
|
|
290
|
-
//#region src/action-handler.d.ts
|
|
291
|
-
/**
|
|
292
|
-
* Work out, once at startup, everything an action's route needs to answer a
|
|
293
|
-
* request: where its input comes from (body, query, or path), the validators,
|
|
294
|
-
* the authorization and execute functions, and its logger. Low level: `brick()`
|
|
295
|
-
* does this for every route.
|
|
296
|
-
*
|
|
297
|
-
* @param service - The service the action belongs to.
|
|
298
|
-
* @param action - The action.
|
|
299
|
-
* @param routePath - The route's path.
|
|
300
|
-
* @param method - The HTTP method (POST by default).
|
|
301
|
-
* @returns The plan `executeCompiledRoute` runs.
|
|
302
|
-
*/
|
|
303
|
-
export declare function compileRoutePlan(service: Service, action: Action, routePath: string, method?: string): CompiledRoutePlan;
|
|
304
|
-
/**
|
|
305
|
-
* Answer one request for a compiled route: read the input, run the action, and
|
|
306
|
-
* return its output or the error response, with the `x-trace-id` and
|
|
307
|
-
* `x-request-id` headers set. Low level: `brick()` mounts this for every route.
|
|
308
|
-
*
|
|
309
|
-
* @param plan - From `compileRoutePlan`.
|
|
310
|
-
* @param elysiaCtx - The Elysia request context: `params`, `body`, `query`,
|
|
311
|
-
* `headers`, `request`, and `set`.
|
|
312
|
-
* @returns The action's output, or an error envelope with the status set on `set`.
|
|
313
|
-
*/
|
|
314
|
-
export declare function executeCompiledRoute(plan: CompiledRoutePlan, elysiaCtx: any): Promise<any>;
|
|
315
|
-
/**
|
|
316
|
-
* An Elysia handler for one action: `compileRoutePlan` and
|
|
317
|
-
* `executeCompiledRoute` together. Use it to mount an action on your own
|
|
318
|
-
* Elysia app; `brick()` does it for you.
|
|
319
|
-
*
|
|
320
|
-
* @param service - The service the action belongs to.
|
|
321
|
-
* @param action - The action.
|
|
322
|
-
* @param routePath - The route's path.
|
|
323
|
-
* @param method - The HTTP method (POST by default).
|
|
324
|
-
* @returns A function from the Elysia context to the response.
|
|
325
|
-
*/
|
|
326
|
-
export declare function createActionHandler(service: Service, action: Action, routePath: string, method?: string): (elysiaCtx: any) => Promise<any>;
|
|
327
|
-
//#endregion
|
|
328
|
-
//#region src/server.d.ts
|
|
329
|
-
interface CreateServerOptions {
|
|
330
|
-
port?: number;
|
|
331
|
-
/** Generate specialized handlers once at startup (default true). */
|
|
332
|
-
compiler?: boolean;
|
|
333
|
-
/** Ahead-of-time handlers already bound to the supplied services. */
|
|
334
|
-
compilation?: CompiledApplication;
|
|
335
|
-
services?: Service<any, any>[];
|
|
336
|
-
prefix?: string;
|
|
337
|
-
title?: string;
|
|
338
|
-
version?: string;
|
|
339
|
-
description?: string;
|
|
340
|
-
docs?: boolean;
|
|
341
|
-
openApiPath?: string;
|
|
342
|
-
docsPath?: string;
|
|
343
|
-
swaggerPath?: string;
|
|
344
|
-
requestLogging?: boolean | RequestLoggingOptions;
|
|
345
|
-
/**
|
|
346
|
-
* `true` serves a Scalar page at /reference. Options serve one only with a
|
|
347
|
-
* `path`; `documents` adds OpenAPI documents to the dashboard's APIs view.
|
|
348
|
-
*/
|
|
349
|
-
reference?: boolean | ReferenceOptions;
|
|
350
|
-
secrets?: {
|
|
351
|
-
source?: SecretSource;
|
|
352
|
-
validate?: boolean;
|
|
353
|
-
};
|
|
354
|
-
/** Raw endpoints (outside the JSON action mesh), mounted at startup. */
|
|
355
|
-
endpoints?: EndpointDefinition[];
|
|
356
|
-
/**
|
|
357
|
-
* Record request, action, and RPC spans with OpenTelemetry (default false).
|
|
358
|
-
* Spans go to the globally registered tracer provider; without one they are
|
|
359
|
-
* no-ops. `brick dev` shows them in its dashboard.
|
|
360
|
-
*/
|
|
361
|
-
telemetry?: boolean;
|
|
362
|
-
/**
|
|
363
|
-
* Developer documentation for the `brick dev` dashboard (its Docs tab): a
|
|
364
|
-
* folder of `.md`/`.mdx` pages in Fumadocs' layout, with frontmatter and
|
|
365
|
-
* `meta.json` for ordering. A string is the folder. Relative paths start at
|
|
366
|
-
* the folder of the app entry, as they read in the file that sets them (from
|
|
367
|
-
* `src/app.ts`, `"../docs"` is `docs/` at the project root). Needs
|
|
368
|
-
* `fumadocs-core` and `@mdx-js/mdx` installed.
|
|
369
|
-
*/
|
|
370
|
-
documentation?: string | DocumentationOptions;
|
|
371
|
-
/**
|
|
372
|
-
* Monitoring dashboard for `brick start`, on a port of its own and behind
|
|
373
|
-
* `auth`. Setting it turns on `telemetry`. See `DashboardOptions`.
|
|
374
|
-
*/
|
|
375
|
-
dashboard?: DashboardOptions;
|
|
376
|
-
/**
|
|
377
|
-
* Record events in the same database transaction as the writes that cause them,
|
|
378
|
-
* and deliver them to listeners after the commit. Generated CRUD writes emit
|
|
379
|
-
* `<resource>.create`, `<resource>.update` and `<resource>.delete`. A service
|
|
380
|
-
* records events once its database holds an `outboxTable()`. Reads emit nothing,
|
|
381
|
-
* and an app without this option behaves exactly as before. See `EventsOptions`.
|
|
382
|
-
*/
|
|
383
|
-
events?: EventsOptions;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Create the HTTP application: an Elysia app that serves every service's
|
|
387
|
-
* actions (and the tools that opt in with `http: true`) as routes, with
|
|
388
|
-
* `/_health`, an OpenAPI document at `/openapi.json`, Scalar at `/docs`,
|
|
389
|
-
* Swagger UI at `/swagger`, and the shape of the services at `/_brick/services`.
|
|
390
|
-
*
|
|
391
|
-
* Services come from the global registry unless `services` is given. The app
|
|
392
|
-
* does not listen by itself: export it from your entry file, where `brick dev`,
|
|
393
|
-
* `brick start`, and the Vite plugin load it, or call `app.listen(port)` in your
|
|
394
|
-
* own server bootstrap.
|
|
395
|
-
*
|
|
396
|
-
* @param options - `prefix` for action routes (default `/api`), `services`,
|
|
397
|
-
* `title`, `version`, and `description` for the OpenAPI document, `docs` and the
|
|
398
|
-
* paths of its pages, `requestLogging`, `reference`, `endpoints`, `secrets`,
|
|
399
|
-
* `telemetry`, `documentation`, and `dashboard`. See `CreateServerOptions`.
|
|
400
|
-
* @returns The app, with `definition` (its services, prefix, and routes),
|
|
401
|
-
* `endpoint()` to add raw routes, and `listEndpoints()` to list them.
|
|
402
|
-
* @throws When a required secret is missing, or `documentation` or `dashboard`
|
|
403
|
-
* is invalid.
|
|
404
|
-
* @example
|
|
405
|
-
* import { brick } from "@brickkit/core";
|
|
406
|
-
* import { pagesService } from "./services/pages";
|
|
407
|
-
*
|
|
408
|
-
* export default brick({
|
|
409
|
-
* services: [pagesService],
|
|
410
|
-
* title: "Pages API",
|
|
411
|
-
* telemetry: true,
|
|
412
|
-
* });
|
|
413
|
-
*/
|
|
414
|
-
export declare function brick(options?: CreateServerOptions): BrickApp;
|
|
415
|
-
//#endregion
|
|
416
|
-
//#region src/app-entry.d.ts
|
|
417
|
-
/**
|
|
418
|
-
* Whether a value is an application made by `brick()`. It checks for the
|
|
419
|
-
* methods and `definition` a `BrickApp` has, so it also recognizes one built by
|
|
420
|
-
* another copy of the package.
|
|
421
|
-
*
|
|
422
|
-
* @param app - Anything, such as the default export of an entry file.
|
|
423
|
-
* @returns `true` for a `BrickApp`, narrowing its type.
|
|
424
|
-
*/
|
|
425
|
-
export declare function isBrickApp(app: unknown): app is BrickApp;
|
|
426
|
-
/**
|
|
427
|
-
* Check that a module's default export is an application ready to be served,
|
|
428
|
-
* for tools that load an entry file.
|
|
429
|
-
*
|
|
430
|
-
* @param app - The default export of an entry file.
|
|
431
|
-
* @returns The app.
|
|
432
|
-
* @throws When it is not a `BrickApp`, or it already called `.listen()`: the
|
|
433
|
-
* entry must only build the app, and leave listening to the server bootstrap.
|
|
434
|
-
*/
|
|
435
|
-
export declare function requireBrickApp(app: unknown): BrickApp;
|
|
436
|
-
//#endregion
|
|
437
|
-
//#region src/telemetry.d.ts
|
|
438
|
-
/** What a raw route handler receives from `traceRoute`. Read the body from `request`. */
|
|
439
|
-
interface RawRouteContext {
|
|
440
|
-
request: Request;
|
|
441
|
-
headers: Record<string, string | undefined>;
|
|
442
|
-
set: {
|
|
443
|
-
status?: unknown;
|
|
444
|
-
headers?: Record<string, unknown>;
|
|
445
|
-
};
|
|
446
|
-
params: Record<string, string>;
|
|
447
|
-
query: Record<string, string | undefined>;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Wrap a raw route handler so each of its requests gets a server span. Use it
|
|
451
|
-
* for routes registered directly on the app, outside actions and endpoints,
|
|
452
|
-
* such as auth or webhook routes. Spans are recorded whenever a tracer provider
|
|
453
|
-
* is registered; `brick({ telemetry })` does not apply to these routes.
|
|
454
|
-
*
|
|
455
|
-
* The wrapper forwards only the fields listed in `RawRouteContext`. Elysia
|
|
456
|
-
* decides what to parse from the handler's destructuring, and forwarding the
|
|
457
|
-
* whole context would parse the body and leave `request.json()` with nothing.
|
|
458
|
-
*/
|
|
459
|
-
export declare function traceRoute<T>(route: string, handler: (context: RawRouteContext) => T): (context: RawRouteContext) => T;
|
|
460
|
-
//#endregion
|
|
461
|
-
//#region src/compiler/emit.d.ts
|
|
462
|
-
/** Emits framework code only. User callbacks remain closures bound separately. */
|
|
463
|
-
export declare function emitHandlerFactory(route: RouteIR): string;
|
|
464
|
-
//#endregion
|
|
465
|
-
//#region src/db/index.d.ts
|
|
466
|
-
export interface DatabaseConfig<TSchema extends Record<string, unknown> = Record<string, unknown>> extends Omit<SQLiteDatabaseConfig<TSchema>, "client">, Omit<PostgresDatabaseConfig<TSchema>, "client"> {
|
|
467
|
-
client?: SQLiteDatabaseConfig<TSchema>["client"] | PostgresDatabaseConfig<TSchema>["client"];
|
|
468
|
-
/** Database engine. Default: 'sqlite' */
|
|
469
|
-
engine?: "sqlite" | "postgres" | "clickhouse";
|
|
470
|
-
/** Optional service name associated with this database */
|
|
471
|
-
name?: string;
|
|
472
|
-
}
|
|
473
|
-
export type BrickDatabase<TSchema extends Record<string, unknown> = Record<string, unknown>> = BunSQLiteDatabase<TSchema> | PostgresDatabase<TSchema>;
|
|
474
|
-
/**
|
|
475
|
-
* Creates a database instance based on the provided configuration.
|
|
476
|
-
* Zero-config: calling `createDatabase()` returns an ultra-fast Bun-native SQLite
|
|
477
|
-
* database in `:memory:` mode wrapped with Drizzle ORM.
|
|
478
|
-
*/
|
|
479
|
-
export declare function createDatabase<TSchema extends Record<string, unknown> = Record<string, unknown>>(config?: DatabaseConfig<TSchema>): BunSQLiteDatabase<TSchema> | PostgresDatabase<TSchema>;
|
|
480
|
-
/** Attach a defined database. Schema changes remain the caller's responsibility. */
|
|
481
|
-
export declare function attachDatabase<TDb>(service: Service<TDb, any>, database: DatabaseHandle<TDb>): TDb;
|
|
482
|
-
/**
|
|
483
|
-
* Generates an idempotent SQLite CREATE TABLE IF NOT EXISTS definition
|
|
484
|
-
* directly from a Drizzle table schema.
|
|
485
|
-
*/
|
|
486
|
-
export declare function generateSQLiteTableDdl(table: any): string;
|
|
487
|
-
/**
|
|
488
|
-
* Generates idempotent secondary index DDL for a Drizzle table.
|
|
489
|
-
* Covers owner scoping, sort columns, and exact-match filters.
|
|
490
|
-
* UNIQUE columns already carry an implicit index — skipped here.
|
|
491
|
-
* FTS/trigram indexes are handled separately by the search layer.
|
|
492
|
-
*/
|
|
493
|
-
export declare function generateSQLiteIndexDdl(table: any, opts?: {
|
|
494
|
-
ownerField?: string;
|
|
495
|
-
sortFields?: string[];
|
|
496
|
-
}): string[];
|
|
497
|
-
/**
|
|
498
|
-
* Ensures secondary indexes exist for a resource table.
|
|
499
|
-
* SQLite: B-tree indexes for owner scope + sort + composite hot path.
|
|
500
|
-
* Postgres: same B-trees plus pg_trgm GIN indexes for substring search.
|
|
501
|
-
* Best-effort: failures warn and continue (e.g. read-only replicas).
|
|
502
|
-
*/
|
|
503
|
-
export declare function ensureResourceIndexes(db: any, table: any, opts?: {
|
|
504
|
-
ownerField?: string;
|
|
505
|
-
sortFields?: string[];
|
|
506
|
-
searchFields?: string[];
|
|
507
|
-
}): void;
|
|
508
|
-
/**
|
|
509
|
-
* Creates the FTS5 sidecar table + sync triggers + backfills existing rows.
|
|
510
|
-
* Idempotent; safe to call on every resource registration.
|
|
511
|
-
* No-op on Postgres (relies on pg_trgm instead) and when searchCols is empty.
|
|
512
|
-
*/
|
|
513
|
-
export declare function ensureSQLiteFts(db: any, table: any, searchCols: string[]): void;
|
|
514
|
-
/**
|
|
515
|
-
* Builds an FTS5 MATCH condition for a resource search term.
|
|
516
|
-
* Returns null when the term has no usable tokens or FTS errors.
|
|
517
|
-
* Caller falls back to LIKE in that case.
|
|
518
|
-
*/
|
|
519
|
-
export declare function buildFtsMatchQuery(search: string): string | null;
|
|
520
|
-
/**
|
|
521
|
-
* Explicit SQLite development/test schema preparation helper.
|
|
522
|
-
* Never called by services, resources, auth, or server startup.
|
|
523
|
-
* Not a migration runner; PostgreSQL schema management is caller-owned.
|
|
524
|
-
*/
|
|
525
|
-
export declare function syncSchema(tablesOrService: Map<string, any> | any[] | Record<string, any> | Service, dbInstance?: any): Promise<void> | void;
|
|
526
|
-
//#endregion
|
|
527
|
-
//#region src/service.d.ts
|
|
528
|
-
export declare class ServiceImpl<TDb = BunSQLiteDatabase<Record<string, unknown>>, TServiceContext extends Record<string, any> = Record<string, any>> implements Service<TDb, TServiceContext> {
|
|
529
|
-
readonly name: string;
|
|
530
|
-
readonly options: ServiceOptions<TServiceContext, TDb>;
|
|
531
|
-
readonly actions: Map<string, Action<any, any, any, any>>;
|
|
532
|
-
readonly tools: Map<string, Tool<any, any, any, any>>;
|
|
533
|
-
readonly tables: Map<string, any>;
|
|
534
|
-
private readonly sockets;
|
|
535
|
-
readonly resources: Map<string, Resource<any, BaseContext<TDb> & TServiceContext, {}>>;
|
|
536
|
-
readonly preparations: Map<string, PreparationContribution>;
|
|
537
|
-
private database?;
|
|
538
|
-
private _isBuilt;
|
|
539
|
-
constructor(name: string, options?: ServiceOptions<TServiceContext, TDb>);
|
|
540
|
-
use<A>(plugin: ServicePlugin<this, A>): A;
|
|
541
|
-
get db(): TDb | undefined;
|
|
542
|
-
get isBuilt(): boolean;
|
|
543
|
-
/**
|
|
544
|
-
* Closes declarations after plugins have registered their actions and preparations.
|
|
545
|
-
*/
|
|
546
|
-
build(): this;
|
|
547
|
-
contributePreparation(contribution: PreparationContribution): void;
|
|
548
|
-
listPreparations(): PreparationContribution[];
|
|
549
|
-
prepareContributions(): void;
|
|
550
|
-
registerTable(table: any): this;
|
|
551
|
-
resource: <TTable = any, const TOptions extends ResourceTypeOptions = ResourceTypeOptions>(config: ResourceConfig<TTable, BaseContext<TDb> & TServiceContext> & TOptions & Record<Exclude<keyof TOptions, keyof ResourceConfig>, never>) => Resource<TTable, BaseContext<TDb> & TServiceContext, ResourceIdentity<TTable, TOptions>>;
|
|
552
|
-
getResource(name: string): Resource<any, BaseContext<TDb> & TServiceContext> | undefined;
|
|
553
|
-
listResources(): Resource<any, BaseContext<TDb> & TServiceContext>[];
|
|
554
|
-
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;
|
|
555
|
-
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>;
|
|
556
|
-
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>;
|
|
557
|
-
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;
|
|
558
|
-
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>;
|
|
559
|
-
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>;
|
|
560
|
-
getTool(name: string): Tool<any, any, any, any> | undefined;
|
|
561
|
-
socket<const I extends SocketSchemas, const O extends SocketSchemas>(config: BrickSocketConfig<I, O, BaseContext<TDb> & TServiceContext>): this;
|
|
562
|
-
listSockets(): RegisteredSocket[];
|
|
563
|
-
listTools(): Tool<any, any, any, any>[];
|
|
564
|
-
getAction(name: string): Action<any, any, any, any> | undefined;
|
|
565
|
-
listActions(): Action<any, any, any, any>[];
|
|
566
|
-
getDb(): TDb | undefined;
|
|
567
|
-
/** What a write needs to record events. Set by `brick({ events })`. */
|
|
568
|
-
events?: ServiceEvents;
|
|
569
|
-
getOutbox(): OutboxTable | undefined;
|
|
570
|
-
setEvents(events: ServiceEvents | undefined): void;
|
|
571
|
-
setDb(database: DatabaseHandle<TDb>): void;
|
|
572
|
-
/**
|
|
573
|
-
* Resolves the complete service execution context once per incoming request.
|
|
574
|
-
* Merges framework BaseContext with the service's custom context hook.
|
|
575
|
-
* Always rebuilds context for this service to prevent caller context from overriding.
|
|
576
|
-
*/
|
|
577
|
-
resolveContext(callCtx?: Partial<BaseContext<TDb> & TServiceContext>): Promise<BaseContext<TDb> & TServiceContext>;
|
|
578
|
-
introspect(): ServiceSchema;
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* Declare a service: a named group of actions, tools, and resources with its own
|
|
582
|
-
* database and request context. It is registered globally, so `brick()`, the
|
|
583
|
-
* OpenAPI generator, and `createServiceProxy` find it by name.
|
|
584
|
-
*
|
|
585
|
-
* Add actions with `service.action(...)`, tools with `service.tool(...)`,
|
|
586
|
-
* resources with `service.resource(...)`, and plugins with `service.use(...)`.
|
|
587
|
-
*
|
|
588
|
-
* @param name - Unique name. It is the service's segment of every action route
|
|
589
|
-
* (`/api/<name>/<action>`) and appears in OpenAPI and the dashboard. Defining a
|
|
590
|
-
* second service with the same name replaces the first and logs a warning.
|
|
591
|
-
* @param options - `database` (a handle from `defineDatabase`), `context` (adds
|
|
592
|
-
* fields such as the signed-in user to every action's `ctx`), and `auth`,
|
|
593
|
-
* `rateLimit`, `cache`, `resilience`, `telemetry`, and `lifecycle`.
|
|
594
|
-
* @returns The service.
|
|
595
|
-
* @example
|
|
596
|
-
* import { defineDatabase, defineService, t } from "@brickkit/core";
|
|
597
|
-
*
|
|
598
|
-
* const database = defineDatabase({ tables: { pages } });
|
|
599
|
-
*
|
|
600
|
-
* export const pagesService = defineService("pages", {
|
|
601
|
-
* database,
|
|
602
|
-
* // Added to `ctx` in every action of this service.
|
|
603
|
-
* context: async ({ request }) => ({ user: await readUser(request) }),
|
|
604
|
-
* });
|
|
605
|
-
*
|
|
606
|
-
* pagesService.action({
|
|
607
|
-
* name: "list",
|
|
608
|
-
* input: t.Object({ limit: t.Optional(t.Number()) }),
|
|
609
|
-
* output: t.Array(t.Object({ id: t.String(), title: t.String() })),
|
|
610
|
-
* execute: ({ input, ctx }) =>
|
|
611
|
-
* ctx.db.select().from(pages).limit(input.limit ?? 20),
|
|
612
|
-
* });
|
|
613
|
-
*/
|
|
614
|
-
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>;
|
|
615
|
-
//#endregion
|
|
616
|
-
//#region src/socket-schema.d.ts
|
|
617
|
-
/** Keep validators browser-safe and reject schemas whose behavior cannot cross JSON. */
|
|
618
|
-
export declare function serializeSocketSchema(schema: TSchema$1): unknown;
|
|
619
|
-
//#endregion
|
|
620
|
-
//#region src/access.d.ts
|
|
621
|
-
interface ActionAccessInfo {
|
|
622
|
-
hasAuthorize: boolean;
|
|
623
|
-
hasScope: boolean;
|
|
624
|
-
policy: ActionAccessPolicy;
|
|
625
|
-
}
|
|
626
|
-
/**
|
|
627
|
-
* Cross-copy access metadata protocol. CRUD enforces its access policy
|
|
628
|
-
* inside `execute`, so `config.authorize` is absent and introspection
|
|
629
|
-
* can't see it. The plugin stamps each action under this process-global
|
|
630
|
-
* symbol; introspection and OpenAPI read it back. Uses `Symbol.for` so
|
|
631
|
-
* the binding survives a second copy of core (bundler SSR, Vitest),
|
|
632
|
-
* same as the plugin action-binding key.
|
|
633
|
-
*/
|
|
634
|
-
export declare const ACTION_ACCESS_KEY: unique symbol;
|
|
635
|
-
/**
|
|
636
|
-
* Record how an action is protected, for tools that cannot read it from the
|
|
637
|
-
* configuration: plugins such as `crud` enforce access inside `execute`, so the
|
|
638
|
-
* action has no `authorize` to find. Introspection, OpenAPI, and the dashboard
|
|
639
|
-
* read what is recorded here.
|
|
640
|
-
*
|
|
641
|
-
* @param action - The action to describe.
|
|
642
|
-
* @param info - Whether it checks authorization and whether it scopes queries,
|
|
643
|
-
* and the resulting policy.
|
|
644
|
-
*/
|
|
645
|
-
export declare function setActionAccess(action: object, info: ActionAccessInfo): void;
|
|
646
|
-
/**
|
|
647
|
-
* How an action is protected: `"public"` when nothing checks the caller,
|
|
648
|
-
* `"authorized"` when an `authorize` does, and `"scoped"` when the action also
|
|
649
|
-
* limits what rows the caller can reach. It reads what a plugin recorded with
|
|
650
|
-
* `setActionAccess`, else the action's own `authorize`, and keeps the policy
|
|
651
|
-
* consistent with the flags.
|
|
652
|
-
*
|
|
653
|
-
* @param action - An action, or any object a plugin described.
|
|
654
|
-
* @returns `hasAuthorize`, `hasScope`, and `policy`.
|
|
655
|
-
*/
|
|
656
|
-
export declare function getActionAccess(action: Action | object): ActionAccessInfo;
|
|
657
|
-
//#endregion
|
|
658
|
-
//#region src/action.d.ts
|
|
659
|
-
/**
|
|
660
|
-
* The `error` helpers an action receives: one function per error code that
|
|
661
|
-
* throws an `ActionExecutionError` with that code and status. The standard HTTP
|
|
662
|
-
* codes (`BAD_REQUEST`, `UNAUTHORIZED`, `FORBIDDEN`, `NOT_FOUND`, `CONFLICT`,
|
|
663
|
-
* `INTERNAL_SERVER_ERROR`) are always there; the action's own `errors` add to
|
|
664
|
-
* them or replace one.
|
|
665
|
-
*
|
|
666
|
-
* @param errorsDef - The action's `errors`: for each code, its `message` and
|
|
667
|
-
* `status` (default 400).
|
|
668
|
-
* @returns Helpers that take an optional message, `details`, and `ErrorOptions`,
|
|
669
|
-
* and always throw.
|
|
670
|
-
*/
|
|
671
|
-
export declare function buildErrorHelpers<TErrors extends Record<string, ActionErrorDefinition>>(errorsDef?: TErrors): ErrorBuilder<TErrors>;
|
|
672
|
-
/**
|
|
673
|
-
* Define an action: a typed, validated function that Brick serves over HTTP,
|
|
674
|
-
* runs in-process, and exposes to the typed client and OpenAPI.
|
|
675
|
-
*
|
|
676
|
-
* A call runs in order: the input is validated against `input` (an invalid one
|
|
677
|
-
* is a `VALIDATION_FAILED` error, HTTP 400); `authorize` runs, if there is one;
|
|
678
|
-
* `execute` runs; and its result is validated against `output` (a mismatch is a
|
|
679
|
-
* server error, HTTP 500). Throw `error.CODE(...)` from `execute` for a declared
|
|
680
|
-
* failure or a standard one such as `error.NOT_FOUND()`. Any other thrown value
|
|
681
|
-
* becomes `INTERNAL_SERVER_ERROR` (500), with the cause kept out of the response
|
|
682
|
-
* and in the log.
|
|
683
|
-
*
|
|
684
|
-
* `authorize` returns `false` to refuse: the call fails with `UNAUTHORIZED`
|
|
685
|
-
* (401) when there is no `ctx.user`, and `FORBIDDEN` (403) when there is one.
|
|
686
|
-
* Where it is given, `execute` can rely on what it checked.
|
|
687
|
-
*
|
|
688
|
-
* @param config - `name`, `execute`, and optionally `description`, `input` and
|
|
689
|
-
* `output` (TypeBox schemas), `errors`, `authorize`, `method` and `path` to
|
|
690
|
-
* change the route (POST by default), `tags`, and `emits`.
|
|
691
|
-
* @returns The action. Register it with `service.action(action)`; call it
|
|
692
|
-
* directly with `action.run(input, ctx)`.
|
|
693
|
-
* @example
|
|
694
|
-
* import { defineAction, t } from "@brickkit/core";
|
|
695
|
-
*
|
|
696
|
-
* export const getPage = defineAction({
|
|
697
|
-
* name: "get",
|
|
698
|
-
* method: "GET",
|
|
699
|
-
* input: t.Object({ id: t.String() }),
|
|
700
|
-
* output: t.Object({ id: t.String(), title: t.String() }),
|
|
701
|
-
* errors: { PAGE_GONE: { message: "That page was removed", status: 410 } },
|
|
702
|
-
* authorize: ({ user }) => user != null,
|
|
703
|
-
* execute: async ({ input, ctx, error }) => {
|
|
704
|
-
* const page = await findPage(ctx.db, input.id);
|
|
705
|
-
* if (!page) throw error.NOT_FOUND("No such page");
|
|
706
|
-
* return page;
|
|
707
|
-
* },
|
|
708
|
-
* });
|
|
709
|
-
*/
|
|
710
|
-
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>;
|
|
711
|
-
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>;
|
|
712
|
-
//#endregion
|
|
713
|
-
//#region src/resource.d.ts
|
|
714
|
-
/** Declares a plugin host without registering actions or changing the schema. */
|
|
715
|
-
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>>;
|
|
716
|
-
//#endregion
|
|
717
|
-
//#region src/rpc.d.ts
|
|
718
|
-
/**
|
|
719
|
-
* A typed way to call another service's actions in-process. Each property of
|
|
720
|
-
* the proxy is an action of that service: call it with the action's input, and
|
|
721
|
-
* optionally a call context.
|
|
722
|
-
*
|
|
723
|
-
* The call runs through the target's own validation and authorization, with the
|
|
724
|
-
* target's database and context (never the caller's), and shows as an `rpc`
|
|
725
|
-
* span in the trace. Only in-process dispatch exists: with `isMonolith: false`
|
|
726
|
-
* a call throws. Use the typed client to call a service over HTTP.
|
|
727
|
-
*
|
|
728
|
-
* @param serviceName - The registered name of the service to call.
|
|
729
|
-
* @param options - `from` (the calling service's name, which becomes `ctx.caller`
|
|
730
|
-
* in the target and cannot be spoofed), `context` (defaults for every call), and
|
|
731
|
-
* `isMonolith`.
|
|
732
|
-
* @returns A proxy typed as `T`, usually the target's actions.
|
|
733
|
-
* @throws On a call, when the service or the action is not registered.
|
|
734
|
-
* @example
|
|
735
|
-
* import { createServiceProxy } from "@brickkit/core";
|
|
736
|
-
*
|
|
737
|
-
* const pages = createServiceProxy<{ get(input: { id: string }): Promise<Page> }>(
|
|
738
|
-
* "pages",
|
|
739
|
-
* { from: "billing" },
|
|
740
|
-
* );
|
|
741
|
-
* const page = await pages.get({ id: "p_1" });
|
|
742
|
-
*/
|
|
743
|
-
export declare function createServiceProxy<T extends Record<string, any>>(serviceName: string, options?: ProxyOptions): T;
|
|
744
|
-
//#endregion
|
|
745
|
-
//#region src/events/listener.d.ts
|
|
746
|
-
type ListenerConfig<TPayload> = {
|
|
747
|
-
name: string;
|
|
748
|
-
on: string | readonly string[];
|
|
749
|
-
maxAttempts?: number;
|
|
750
|
-
} & ({
|
|
751
|
-
run: (delivery: EventDelivery<TPayload>) => void | Promise<void>;
|
|
752
|
-
workflow?: never;
|
|
753
|
-
} | {
|
|
754
|
-
workflow: EventWorkflow<TPayload>;
|
|
755
|
-
run?: never;
|
|
756
|
-
});
|
|
757
|
-
/**
|
|
758
|
-
* Define a listener: code that runs for each event it listens for, after the write
|
|
759
|
-
* that caused the event has been committed. Pass it to `brick({ events: {
|
|
760
|
-
* listeners } })`.
|
|
761
|
-
*
|
|
762
|
-
* It either runs a handler (`run`) in the process that delivers events, or starts
|
|
763
|
-
* a durable workflow (`workflow`) on the app's `events.world`. Delivery is at
|
|
764
|
-
* least once. A handler that throws is retried later with a growing delay, then
|
|
765
|
-
* parked as dead, so it can run again for the same event: use
|
|
766
|
-
* `delivery.deliveryId` to make its work idempotent. A workflow needs no such
|
|
767
|
-
* care: a delivery starts one run however often it is tried, and the workflow
|
|
768
|
-
* retries its own steps.
|
|
769
|
-
*
|
|
770
|
-
* @param config - `name` (unique; it is part of each delivery's id), `on` (an
|
|
771
|
-
* event name or a list of them; a trailing `*` matches a prefix, as in
|
|
772
|
-
* `user.*`), `run` or `workflow`, and optionally `maxAttempts`.
|
|
773
|
-
* @returns The listener.
|
|
774
|
-
* @throws When the name is empty or contains `:`, `on` is empty, or the listener
|
|
775
|
-
* has both or neither of `run` and `workflow`.
|
|
776
|
-
* @example
|
|
777
|
-
* import { brick, defineListener } from "@brickkit/core";
|
|
778
|
-
*
|
|
779
|
-
* const welcome = defineListener({
|
|
780
|
-
* name: "welcome-email",
|
|
781
|
-
* on: "user.create",
|
|
782
|
-
* run: async ({ payload, deliveryId }) => {
|
|
783
|
-
* await mailer.sendWelcome(payload.row.email, { idempotencyKey: deliveryId });
|
|
784
|
-
* },
|
|
785
|
-
* });
|
|
786
|
-
*
|
|
787
|
-
* export default brick({ services, events: { listeners: [welcome] } });
|
|
788
|
-
* @example
|
|
789
|
-
* // src/workflows/onboard.ts
|
|
790
|
-
* export async function onboard(event: WorkflowEvent<CrudEventPayload>) {
|
|
791
|
-
* "use workflow";
|
|
792
|
-
* await sendWelcome(event.payload.row.email);
|
|
793
|
-
* }
|
|
794
|
-
*
|
|
795
|
-
* defineListener({ name: "onboard", on: "user.create", workflow: onboard });
|
|
796
|
-
*/
|
|
797
|
-
export declare function defineListener<TPayload = any>(config: ListenerConfig<TPayload>): EventListener<TPayload>;
|
|
798
|
-
//#endregion
|
|
799
|
-
//#region src/events/emit.d.ts
|
|
800
|
-
/**
|
|
801
|
-
* Record an event of your own from an action, a tool or a hook. Listeners get it
|
|
802
|
-
* as they get a generated CRUD event, with the payload you give.
|
|
803
|
-
*
|
|
804
|
-
* By default the event is committed in a transaction of its own. Pass the `tx`
|
|
805
|
-
* of a transaction you have open to commit it with your writes instead: then it
|
|
806
|
-
* is delivered at the dispatcher's next poll, because Brick does not see your
|
|
807
|
-
* commit. Nothing is recorded when no listener wants the event.
|
|
808
|
-
*
|
|
809
|
-
* @param ctx - The action context: its `db` finds the service's outbox, and its
|
|
810
|
-
* `traceId` follows the event to its listeners.
|
|
811
|
-
* @param name - The event name, such as `order.refunded`.
|
|
812
|
-
* @param payload - JSON data for the listeners.
|
|
813
|
-
* @param options - `tx`: an open transaction on the service's database. `source`:
|
|
814
|
-
* what emitted it, shown to listeners.
|
|
815
|
-
* @throws When the context's database has no outbox table, or the app has no
|
|
816
|
-
* `events`.
|
|
817
|
-
* @example
|
|
818
|
-
* refund: service.action({
|
|
819
|
-
* name: "refund",
|
|
820
|
-
* execute: async ({ ctx, input }) => {
|
|
821
|
-
* await ctx.db.update(orders).set({ status: "refunded" }).where(eq(orders.id, input.id));
|
|
822
|
-
* await emitEvent(ctx, "order.refunded", { id: input.id });
|
|
823
|
-
* },
|
|
824
|
-
* });
|
|
825
|
-
*/
|
|
826
|
-
export declare function emitEvent(ctx: {
|
|
827
|
-
db?: unknown;
|
|
828
|
-
traceId?: string;
|
|
829
|
-
}, name: string, payload: unknown, options?: {
|
|
830
|
-
tx?: unknown;
|
|
831
|
-
source?: string;
|
|
832
|
-
}): Promise<void>;
|
|
833
|
-
//#endregion
|
|
834
|
-
//#region src/events/transaction.d.ts
|
|
835
|
-
/**
|
|
836
|
-
* Run `fn` in a database transaction: everything it writes through the `tx` it is
|
|
837
|
-
* given is committed together when it returns, or undone if it throws.
|
|
838
|
-
*
|
|
839
|
-
* Postgres uses a real transaction on one connection. SQLite has one connection
|
|
840
|
-
* and a synchronous driver, which Drizzle's own `transaction` cannot use with an
|
|
841
|
-
* async callback (it would commit before the callback finished). So transactions
|
|
842
|
-
* on one SQLite database take turns, each between `BEGIN IMMEDIATE` and `COMMIT`.
|
|
843
|
-
* A write made elsewhere in the process during that time, outside this helper,
|
|
844
|
-
* would join the transaction; use Postgres where that matters.
|
|
845
|
-
*
|
|
846
|
-
* A call made inside `fn` with the `tx` it was given (on SQLite, the database
|
|
847
|
-
* itself) joins the open transaction as a savepoint instead of waiting for it: a
|
|
848
|
-
* nested failure undoes only the nested work, and the outer transaction decides
|
|
849
|
-
* the commit. Nested calls must run one at a time.
|
|
850
|
-
*
|
|
851
|
-
* @param db - A Drizzle database, from `service.getDb()`.
|
|
852
|
-
* @param fn - Receives the transaction handle to run queries on.
|
|
853
|
-
* @returns What `fn` returned.
|
|
854
|
-
* @throws What `fn` threw, after rolling back.
|
|
855
|
-
*/
|
|
856
|
-
export declare function runInTransaction<T>(db: any, fn: (tx: any) => Promise<T>): Promise<T>;
|
|
857
|
-
/**
|
|
858
|
-
* Run `fn` once the transaction that `db` belongs to has committed, or now when
|
|
859
|
-
* `db` is not in one opened by `runInTransaction`. It never runs when that
|
|
860
|
-
* transaction, or the savepoint it was queued in, rolls back. An error it throws
|
|
861
|
-
* reaches the caller of the outermost `runInTransaction`, after the commit.
|
|
862
|
-
*
|
|
863
|
-
* @param db - The handle the work ran on: a `tx`, or a database.
|
|
864
|
-
* @param fn - The side effect, such as clearing a cache.
|
|
865
|
-
*/
|
|
866
|
-
export declare function onTransactionCommit(db: unknown, fn: () => unknown): Promise<void>;
|
|
867
|
-
//#endregion
|
|
868
|
-
//#region src/events/workflows.d.ts
|
|
869
|
-
/**
|
|
870
|
-
* Where the workflow bundle is read from, and the project it is built from.
|
|
871
|
-
*
|
|
872
|
-
* @param options - The `events.workflows` option.
|
|
873
|
-
* @returns Absolute `root` and `dir`. The bundle cannot live elsewhere: the
|
|
874
|
-
* builder finds the SDK from where it writes, and skips only this directory when it
|
|
875
|
-
* looks for workflows.
|
|
876
|
-
*/
|
|
877
|
-
export declare function resolveWorkflowPaths(options?: WorkflowsOptions): {
|
|
878
|
-
root: string;
|
|
879
|
-
dir: string;
|
|
880
|
-
};
|
|
881
|
-
//#endregion
|
|
882
|
-
//#region src/registry.d.ts
|
|
883
|
-
interface ArchitectureApplication {
|
|
884
|
-
services: readonly Service[];
|
|
885
|
-
routes: readonly RouteIR[];
|
|
886
|
-
events?: EventsDefinition;
|
|
887
|
-
sockets?: readonly (BrickSocketSchema & {
|
|
888
|
-
service: string;
|
|
889
|
-
path: string;
|
|
890
|
-
})[];
|
|
891
|
-
}
|
|
892
|
-
export declare class ServiceRegistry {
|
|
893
|
-
private _revision;
|
|
894
|
-
/** Definition revision for invalidating serialized architecture snapshots. */
|
|
895
|
-
get revision(): number;
|
|
896
|
-
touch(): void;
|
|
897
|
-
private services;
|
|
898
|
-
private routes;
|
|
899
|
-
/** Remember the actual registered routes for subsequent registry exports. */
|
|
900
|
-
setApplicationRoutes(application: ArchitectureApplication): void;
|
|
901
|
-
register(service: Service): void;
|
|
902
|
-
get(name: string): Service | undefined;
|
|
903
|
-
has(name: string): boolean;
|
|
904
|
-
list(): Service[];
|
|
905
|
-
clear(): void;
|
|
906
|
-
exportArchitecture(application?: ArchitectureApplication): ArchitectureSchema;
|
|
907
|
-
}
|
|
908
|
-
/**
|
|
909
|
-
* The registry every `defineService` adds to: it is how `brick()`, the OpenAPI
|
|
910
|
-
* generator, `createServiceProxy`, and the dashboard find services by name.
|
|
911
|
-
*
|
|
912
|
-
* @returns The current global registry.
|
|
913
|
-
*/
|
|
914
|
-
export declare function getGlobalRegistry(): ServiceRegistry;
|
|
915
|
-
/**
|
|
916
|
-
* Start over with an empty global registry. For tests, which define the same
|
|
917
|
-
* services again in each case; an application never needs it.
|
|
918
|
-
*/
|
|
919
|
-
export declare function resetGlobalRegistry(): void;
|
|
920
|
-
//#endregion
|
|
921
|
-
//#region src/typebox.d.ts
|
|
922
|
-
/**
|
|
923
|
-
* The compiled validator for a TypeBox schema. Compiling is slow and checking
|
|
924
|
-
* is fast, so each schema is compiled once and kept for as long as the schema
|
|
925
|
-
* object lives.
|
|
926
|
-
*
|
|
927
|
-
* @param schema - A TypeBox schema.
|
|
928
|
-
* @returns Its `TypeCheck`, with `Check(value)` and `Errors(value)`.
|
|
929
|
-
*/
|
|
930
|
-
export declare function getCompiledCheck<T extends TSchema>(schema: T): TypeCheck<T>;
|
|
931
|
-
/**
|
|
932
|
-
* Check a value against a schema, the way actions check their input and output.
|
|
933
|
-
*
|
|
934
|
-
* @param schema - A TypeBox schema, or `undefined` to accept anything.
|
|
935
|
-
* @param value - The value to check.
|
|
936
|
-
* @returns `{ success: true, data }`, or `{ success: false, errors }` with a
|
|
937
|
-
* `path`, `message`, `type`, and the offending `value` for each problem.
|
|
938
|
-
*/
|
|
939
|
-
export declare function validateWithSchema<T extends TSchema>(schema: T | undefined, value: unknown): {
|
|
940
|
-
success: true;
|
|
941
|
-
data: Static<T>;
|
|
942
|
-
} | {
|
|
943
|
-
success: false;
|
|
944
|
-
errors: ValidationErrorItem[];
|
|
945
|
-
};
|
|
946
|
-
//#endregion
|
|
947
|
-
//#region src/openapi.d.ts
|
|
948
|
-
interface OpenApiGeneratorOptions {
|
|
949
|
-
title?: string;
|
|
950
|
-
version?: string;
|
|
951
|
-
description?: string;
|
|
952
|
-
prefix?: string;
|
|
953
|
-
services?: Service<any, any>[];
|
|
954
|
-
registry?: ServiceRegistry;
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* TypeBox expresses recursive schemas with bare `$id`/`$ref` anchors
|
|
958
|
-
* (`{ $id: "T0", ..., { $ref: "T0" } }`). OpenAPI interprets a bare `$ref`
|
|
959
|
-
* as an external file reference, so downstream tooling tries to load a
|
|
960
|
-
* file named `T0` and fails. Hoist every anchored subschema into
|
|
961
|
-
* `#/components/schemas/` and rewrite the refs to local pointers.
|
|
962
|
-
* First definition wins when one `$id` is declared twice.
|
|
963
|
-
*/
|
|
964
|
-
export declare function hoistAnchoredSchemas(spec: Record<string, any>): string[];
|
|
965
|
-
/**
|
|
966
|
-
* Build the OpenAPI 3.1 document for the services: one path per action route,
|
|
967
|
-
* with request and response schemas from the actions' TypeBox schemas, their
|
|
968
|
-
* declared errors, tags by service, and a bearer security scheme where any
|
|
969
|
-
* action needs authorization.
|
|
970
|
-
*
|
|
971
|
-
* `brick()` calls this for `/openapi.json`; call it yourself to write the
|
|
972
|
-
* document to a file or feed another tool.
|
|
973
|
-
*
|
|
974
|
-
* @param options - `title`, `version`, and `description` for the `info` block,
|
|
975
|
-
* `prefix` (default `/api`), and the `services` or `registry` to describe
|
|
976
|
-
* (the global registry by default).
|
|
977
|
-
* @returns The document as a plain object.
|
|
978
|
-
*/
|
|
979
|
-
export declare function generateOpenApiSpec(options?: OpenApiGeneratorOptions): Record<string, any>;
|
|
980
|
-
//#endregion
|
|
981
|
-
//#region src/tool.d.ts
|
|
982
|
-
/**
|
|
983
|
-
* Define a tool: an action that AI agents can call through MCP. It takes the
|
|
984
|
-
* same configuration as `defineAction` (validation, `authorize`, errors), plus
|
|
985
|
-
* `title`, `annotations` (the MCP hints about what the tool does), and `http`
|
|
986
|
-
* to also serve it over HTTP and in OpenAPI (off by default).
|
|
987
|
-
*
|
|
988
|
-
* @param config - An action configuration and tool options. `input` must be an
|
|
989
|
-
* object schema, since MCP passes arguments by name.
|
|
990
|
-
* @returns The tool, which is also an action. Register it with `service.tool(tool)`.
|
|
991
|
-
* @throws When `input` is not an object schema.
|
|
992
|
-
* @example
|
|
993
|
-
* import { defineTool, t } from "@brickkit/core";
|
|
994
|
-
*
|
|
995
|
-
* export const echoTool = defineTool({
|
|
996
|
-
* name: "echo",
|
|
997
|
-
* title: "Echo a message",
|
|
998
|
-
* description: "Returns the message it is given.",
|
|
999
|
-
* input: t.Object({ message: t.String() }),
|
|
1000
|
-
* output: t.String(),
|
|
1001
|
-
* execute: ({ input }) => `Echo: ${input.message}`,
|
|
1002
|
-
* });
|
|
1003
|
-
*/
|
|
1004
|
-
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>;
|
|
1005
|
-
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>;
|
|
1006
|
-
/**
|
|
1007
|
-
* Whether a value was made with `defineTool`, as opposed to `defineAction`.
|
|
1008
|
-
*
|
|
1009
|
-
* @param value - Anything.
|
|
1010
|
-
* @returns `true` for a tool, narrowing its type.
|
|
1011
|
-
*/
|
|
1012
|
-
export declare function isTool(value: unknown): value is Tool<any, any, any, any>;
|
|
1013
|
-
//#endregion
|
|
1014
|
-
//#region src/mcp.d.ts
|
|
1015
|
-
interface McpToolDefinition {
|
|
1016
|
-
name: string;
|
|
1017
|
-
title?: string;
|
|
1018
|
-
description: string;
|
|
1019
|
-
inputSchema: unknown;
|
|
1020
|
-
annotations: ToolAnnotations;
|
|
1021
|
-
}
|
|
1022
|
-
interface McpRegistryOptions {
|
|
1023
|
-
services?: readonly Pick<Service<any, any>, "listTools">[];
|
|
1024
|
-
tools?: readonly Tool<any, any, any, any>[];
|
|
1025
|
-
}
|
|
1026
|
-
interface McpRegistry {
|
|
1027
|
-
listTools(): McpToolDefinition[];
|
|
1028
|
-
callTool(name: string, args?: Record<string, unknown>, ctx?: Partial<ActionContext>): Promise<unknown>;
|
|
1029
|
-
}
|
|
1030
|
-
export declare class UnknownToolError extends Error {
|
|
1031
|
-
constructor(name: string);
|
|
1032
|
-
}
|
|
1033
|
-
/** Collect only explicitly defined tools, without exposing ordinary actions. */
|
|
1034
|
-
export declare function createMcpRegistry(options: McpRegistryOptions): McpRegistry;
|
|
1035
|
-
interface McpHandlerOptions {
|
|
1036
|
-
registry: McpRegistry;
|
|
1037
|
-
serverInfo: {
|
|
1038
|
-
name: string;
|
|
1039
|
-
version: string;
|
|
1040
|
-
title?: string;
|
|
1041
|
-
};
|
|
1042
|
-
/** Versions supported by this transport, newest first. */
|
|
1043
|
-
protocolVersions?: readonly string[];
|
|
1044
|
-
}
|
|
1045
|
-
/** Stateless MCP JSON-RPC POST handler. Wrap with the app's authentication. */
|
|
1046
|
-
export declare function createMcpHandler(options: McpHandlerOptions): (request: Request, ctx?: Partial<ActionContext>) => Promise<Response>;
|
|
1047
|
-
//#endregion
|
|
1048
|
-
//#region src/error-response.d.ts
|
|
1049
|
-
interface ErrorEnvelope {
|
|
1050
|
-
name: string;
|
|
1051
|
-
code: string;
|
|
1052
|
-
message: string;
|
|
1053
|
-
status: number;
|
|
1054
|
-
requestId: string;
|
|
1055
|
-
details?: unknown;
|
|
1056
|
-
errors?: ValidationError["errors"];
|
|
1057
|
-
}
|
|
1058
|
-
type ErrorContext = {
|
|
1059
|
-
logger: Pick<Logger, "error">;
|
|
1060
|
-
requestId: string;
|
|
1061
|
-
};
|
|
1062
|
-
/**
|
|
1063
|
-
* Turn what an action threw into the JSON body of its HTTP response, and record
|
|
1064
|
-
* the failure on the active trace. Declared failures and validation errors keep
|
|
1065
|
-
* their code, status, and details; anything else is logged and answered as a
|
|
1066
|
-
* generic `INTERNAL_SERVER_ERROR` (500) so internals are never exposed.
|
|
1067
|
-
*
|
|
1068
|
-
* @param err - Whatever was thrown.
|
|
1069
|
-
* @param context - A `logger` with `error()`, and the `requestId` to put in the body.
|
|
1070
|
-
* @returns The envelope: `name`, `code`, `message`, `status`, `requestId`, and
|
|
1071
|
-
* `details` or `errors` when there are any.
|
|
1072
|
-
*/
|
|
1073
|
-
export declare function toErrorResponse(err: unknown, context: ErrorContext): ErrorEnvelope;
|
|
1074
|
-
//#endregion
|
|
1075
|
-
export { Action, type ActionAccessInfo, ActionAccessPolicy, ActionConfig, ActionConfigWithAuthorize, ActionConfigWithoutAuthorize, ActionContext, ActionErrorDefinition, ActionExecutionError, ActionSchema, type ApiDocument, ArchitectureSchema, BaseActionConfig, BaseContext, type BrickActionCaller, type BrickApp, type BrickCallOptions, type BrickClient, type BrickClientAction, type BrickClientOptions, type BrickIR, BrickSQLiteDatabase, BrickServerError, type BrickSocketConfig, type BrickSocketSchema, type BrickSocketSender, BrickTransportError, type BunSQLiteDatabase, CacheOptions, type CompiledApplication, type CompiledHandler, type CompiledRoute, CompiledRoutePlan, type CreateServerOptions, type CrudEventPayload, type DashboardAuth, type DashboardOptions, DatabaseAdapter, DatabaseDefinition, DatabaseHandle, DefaultServiceContext, type DispatchOptions, Dispatcher, type DocumentationOptions, type EndpointContext, type EndpointDefinition, type EndpointLogger, type EndpointMethod, EnvInput, ErrorBuilder, type ErrorEnvelope, type EventDelivery, type EventEnvelope, type EventListener, type EventRecorder, type EventWorkflow, type EventsDefinition, EventsHub, type EventsOptions, type EventsWorld, type HandlerFactory, type InferActionErrorCodes, type InferActionFailure, type InferActionInput, type InferActionOutput, InferTableInsert, InferTableRow, LifecycleOptions, Logger, type McpHandlerOptions, type McpRegistry, type McpRegistryOptions, type McpToolDefinition, NarrowAuthorizedContext, type OpenApiDocument, type OpenApiGeneratorOptions, type OutboxCounts, type OutboxStatus, type OutboxTable, type PluginEndpointContext, type PluginRouteMethod, type PluginRouteRegistrar, type PluginRouteScope, type PluginRoutes, PostgresDatabase, PostgresDatabaseConfig, PostgresDefinition, type PostgresOutboxTable, PreparationContribution, ProxyOptions, RateLimitOptions, type ReferenceDocument, type ReferenceOptions, type RequestLoggingOptions, ResilienceOptions, Resource, ResourceConfig, ResourceIdentity, type ResourcePlugin, type ResourcePluginAPI, type ResourcePluginContext, type ResourcePluginTypes, ResourceTypeOptions, type RouteIR, type RouteMethod, SQLiteDatabaseConfig, SQLiteDefinition, type SQLiteOutboxTable, type SecretOptions, SecretRef, type SecretSource, Service, ServiceAuthOptions, type ServiceEvents, ServiceOptions, type ServicePlugin, type ServicePluginContext, ServiceSchema, type SocketEventArgs, type SocketPayloads, type SocketSchemas, StandardErrorMap, type Static, type TSchema, Table, TelemetryOptions, Tool, ToolAnnotations, ToolConfigWithAuthorize, ToolConfigWithoutAuthorize, ToolOptions, Type, Type as t, ValidationError, ValidationErrorItem, type WorkflowEvent, type WorkflowsOptions, 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, isOutboxTable, like, listSecrets, lt, lte, ne, not, notInArray, or, outboxTable, overrideSecret, overrideSecrets, primaryKey, real, relations, resetSecrets, resolveSecrets, secret, sql, sqliteTable, stopAllEvents, text, uniqueIndex };
|
|
1076
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { $n as WorkflowEvent, $t as getPluginEndpoints, A as Resource, An as satisfiesRange, At as createSQLiteDatabase, B as ServiceSchema, Bn as resolveSecrets, Bt as PluginRouteMethod, C as ErrorDetails, Cn as PluginManifest, Ct as PostgresDatabase, D as NarrowAuthorizedContext, Dn as brickVersion, Dt as BunSQLiteDatabase, E as Logger, En as PluginTableBuilders, Et as BrickSQLiteDatabase, F as ResourceConfig, Fn as envSource, Ft as real, G as ToolConfigWithoutAuthorize, Gn as EventListener, Gt as ResourcePluginAPI, H as Tool, Hn as DispatchOptions, Ht as PluginRouteScope, I as ResourceIdentity, In as listSecrets, It as sqliteTable, J as ValidationErrorItem, Jn as EventsOptions, Jt as ServicePlugin, K as ToolOptions, Kn as EventRecorder, Kt as ResourcePluginContext, L as ResourceTypeOptions, Ln as overrideSecret, Lt as text, M as ResourceActionConfig, Mn as SecretRef, Mt as index, N as ResourceActionInput, Nn as SecretSource, Nt as integer, O as PreparationContribution, On as definePlugin, Ot as SQLiteDatabaseConfig, P as ResourceChild, Pn as defineSecret, Pt as primaryKey, Q as BrickSocketConfig, Qn as ServiceEvents, Qt as getPluginActionRoute, R as Service, Rn as overrideSecrets, Rt as uniqueIndex, S as ErrorBuilder, Sn as PluginLifecycleContext, St as DatabaseAdapter, T as InferTableRow, Tn as PluginSetupContext, Tt as createPostgresDatabase, U as ToolAnnotations, Un as EventDelivery, Ut as PluginRoutes, V as StandardErrorMap, Vn as CrudEventPayload, Vt as PluginRouteRegistrar, W as ToolConfigWithAuthorize, Wn as EventEnvelope, Wt as ResourcePlugin, Xn as ListenerFailure, Xt as defineResourcePlugin, Yn as EventsWorld, Yt as ServicePluginContext, Zn as RetryDecision, Zt as defineServicePlugin, _ as CommandDecision, _n as PluginFactory, _t as EnvInput, a as ActionConfigWithoutAuthorize, an as OutboxCounts, ar as DepsOf, at as BrickSocketSender, b as CompiledRoutePlan, bn as PluginInstallOptions, bt as defineDatabase, c as ActionExecutionError, cn as PostgresOutboxTable, cr as port, ct as SocketBrokerMessage, d as BaseActionConfig, dn as outboxTable, dt as SocketEventArgs, en as resolveWorkflowPaths, er as WorkflowsOptions, f as BaseContext, fn as emitEvent, ft as SocketPayloads, g as CommandConfig, gn as PluginContext, gt as DatabaseHandle, h as CommandChildren, hn as PluginAppContext, ht as DatabaseDefinition, i as ActionConfigWithAuthorize, in as Dispatcher, ir as isEventRef, it as BrickSocketSchema, j as ResourceActionAccess, jn as SecretOptions, jt as foreignKey, k as ProxyOptions, kn as isPluginInstance, kt as blob, l as ActionSchema, ln as SQLiteOutboxTable, lr as useDeps, lt as SocketEmitArgs, m as Command, mn as InstalledPlugin, mt as SocketSchemas, n as ActionAccessPolicy, nn as EventsHub, nr as EventRef, o as ActionContext, on as OutboxStatus, or as Port, p as ChildChanges, pn as defineListener, pt as SocketReplay, q as ValidationError, qn as EventWorkflow, qt as ResourcePluginTypes, r as ActionConfig, rn as stopAllEvents, rr as EventRefs, s as ActionErrorDefinition, sn as OutboxTable, sr as Ports, st as SocketBroker, t as Action, tn as EventsDefinition, tr as EventCatalog, tt as BrickSocketHandle, u as ArchitectureSchema, un as isOutboxTable, ut as SocketEmitOptions, v as CommandErrors, vn as PluginHooks, vt as PostgresDefinition, w as InferTableInsert, wn as PluginServiceContext, wt as PostgresDatabaseConfig, x as DefaultServiceContext, xn as PluginInstance, xt as isDatabaseHandle, y as CommandRow, yn as PluginInfo, yt as SQLiteDefinition, z as ServiceOptions, zn as resetSecrets, zt as PluginEndpointContext } from "./chunks/types.js";
|
|
2
|
+
import { $ as desc, $t as endpointPaths, A as defineAction, At as CreateServerOptions, B as defineService, Bt as CompiledRoute, C as defineResource, Ct as relations, D as getActionRoute, Dt as traceRoute, E as ResourceActionInfo, Et as emitHandlerFactory, F as setActionAccess, Ft as CorsOptions, G as BrickDatabase, Gt as HandlerFactory, H as ServiceClient, Ht as compileBrickApplication, I as RedisBrokerOptions, It as CorsOrigin, J as and, Jt as EndpointContext, K as DatabaseConfig, Kt as compilerRuntime, L as redisBroker, Lt as RequestLoggingOptions, M as ACTION_ACCESS_KEY, Mt as compileRoutePlan, N as ActionAccessInfo, Nt as createActionHandler, O as kebabCase, Ot as isBrickApp, P as getActionAccess, Pt as executeCompiledRoute, Q as createDatabase, Qt as createEndpointHandler, R as serializeSocketSchema, Rt as requestLoggingPlugin, S as resetGlobalRegistry, St as or, T as ActionRoute, Tt as syncSchema, U as UntypedServiceClient, Ut as loadCompiledBrickApp, V as ServiceActionCaller, Vt as bindCompiledApplication, W as useService, Wt as CompiledHandler, X as attachDatabase, Xt as EndpointLogger, Y as asc, Yt as EndpointDefinition, Z as buildFtsMatchQuery, Zt as EndpointMethod, _ as Type, _n as runInTransaction, _t as lte, a as McpRegistryOptions, an as DocumentationOptions, at as generateSQLiteTableDdl, b as ServiceRegistry, bt as not, c as createMcpHandler, cn as ReferenceOptions, ct as gt, d as isTool, dn as scalarDocsHTML, dt as inArray, en as resolveEndpointDb, et as drizzleSchema, f as OpenApiGeneratorOptions, fn as swaggerDocsHTML, ft as is, g as TSchema, gn as onTransactionCommit, gt as lt, h as Static, hn as RouteMethod, ht as like, i as McpRegistry, in as ApiDocument, it as generateSQLiteIndexDdl, j as errorsOf, jt as brick, k as buildErrorHelpers, kt as requireBrickApp, l as createMcpRegistry, ln as referencePlugin, lt as gte, m as hoistAnchoredSchemas, mn as RouteIR, mt as isNull, n as toErrorResponse, nn as DashboardAuth, nt as ensureSQLiteFts, o as McpToolDefinition, on as OpenApiDocument, ot as getTableColumns, p as generateOpenApiSpec, pn as BrickIR, pt as isNotNull, q as Table, qt as BrickApp, r as McpHandlerOptions, rn as DashboardOptions, rt as eq, s as UnknownToolError, sn as ReferenceDocument, st as getTableName, t as ErrorEnvelope, tn as toOpenApiPath, tt as ensureResourceIndexes, u as defineTool, un as registerReferenceRoute, ut as ilike, v as getCompiledCheck, vt as migrateDatabase, w as loadRecord, wt as sql, x as getGlobalRegistry, xt as notInArray, y as validateWithSchema, yt as ne, z as ServiceImpl, zt as CompiledApplication } from "./chunks/index.js";
|
|
3
|
+
import { a as BrickClientOptions, c as BrickTransportError, d as InferActionInput, f as InferActionOutput, h as isBrickTransportError, i as BrickClientAction, l as InferActionErrorCodes, m as isBrickServerError, n as BrickCallOptions, o as BrickServerError, p as createBrickClient, r as BrickClient, s as BrickServices, t as BrickActionCaller, u as InferActionFailure } from "./chunks/client.js";
|
|
4
|
+
import { i as stepFailure, n as defineError, r as stepErrors, t as StepErrorBuilder } from "./chunks/workflow.js";
|
|
5
|
+
export { ACTION_ACCESS_KEY, Action, type ActionAccessInfo, ActionAccessPolicy, ActionConfig, ActionConfigWithAuthorize, ActionConfigWithoutAuthorize, ActionContext, ActionErrorDefinition, ActionExecutionError, type ActionRoute, ActionSchema, type ApiDocument, ArchitectureSchema, BaseActionConfig, BaseContext, type BrickActionCaller, type BrickApp, type BrickCallOptions, type BrickClient, type BrickClientAction, type BrickClientOptions, BrickDatabase, type BrickIR, BrickSQLiteDatabase, BrickServerError, type BrickServices, type BrickSocketConfig, type BrickSocketHandle, type BrickSocketSchema, type BrickSocketSender, BrickTransportError, type BunSQLiteDatabase, ChildChanges, Command, CommandChildren, CommandConfig, CommandDecision, CommandErrors, CommandRow, type CompiledApplication, type CompiledHandler, type CompiledRoute, CompiledRoutePlan, type CorsOptions, type CorsOrigin, type CreateServerOptions, type CrudEventPayload, type DashboardAuth, type DashboardOptions, DatabaseAdapter, DatabaseConfig, DatabaseDefinition, DatabaseHandle, DefaultServiceContext, type DepsOf, type DispatchOptions, Dispatcher, type DocumentationOptions, type EndpointContext, type EndpointDefinition, type EndpointLogger, type EndpointMethod, EnvInput, ErrorBuilder, ErrorDetails, type ErrorEnvelope, type EventCatalog, type EventDelivery, type EventEnvelope, type EventListener, type EventRecorder, type EventRef, type EventRefs, type EventWorkflow, type EventsDefinition, EventsHub, type EventsOptions, type EventsWorld, type HandlerFactory, type InferActionErrorCodes, type InferActionFailure, type InferActionInput, type InferActionOutput, InferTableInsert, InferTableRow, type InstalledPlugin, type ListenerFailure, Logger, type McpHandlerOptions, type McpRegistry, type McpRegistryOptions, type McpToolDefinition, NarrowAuthorizedContext, type OpenApiDocument, type OpenApiGeneratorOptions, type OutboxCounts, type OutboxStatus, type OutboxTable, type PluginAppContext, type PluginContext, type PluginEndpointContext, type PluginFactory, type PluginHooks, type PluginInfo, type PluginInstallOptions, type PluginInstance, type PluginLifecycleContext, type PluginManifest, type PluginRouteMethod, type PluginRouteRegistrar, type PluginRouteScope, type PluginRoutes, type PluginServiceContext, type PluginSetupContext, type PluginTableBuilders, type Port, type Ports, PostgresDatabase, PostgresDatabaseConfig, PostgresDefinition, type PostgresOutboxTable, PreparationContribution, ProxyOptions, type RedisBrokerOptions, type ReferenceDocument, type ReferenceOptions, type RequestLoggingOptions, Resource, ResourceActionAccess, ResourceActionConfig, type ResourceActionInfo, ResourceActionInput, ResourceChild, ResourceConfig, ResourceIdentity, type ResourcePlugin, type ResourcePluginAPI, type ResourcePluginContext, type ResourcePluginTypes, ResourceTypeOptions, type RetryDecision, type RouteIR, type RouteMethod, SQLiteDatabaseConfig, SQLiteDefinition, type SQLiteOutboxTable, type SecretOptions, SecretRef, type SecretSource, Service, type ServiceActionCaller, type ServiceClient, type ServiceEvents, ServiceImpl, ServiceOptions, type ServicePlugin, type ServicePluginContext, ServiceRegistry, ServiceSchema, type SocketBroker, type SocketBrokerMessage, type SocketEmitArgs, type SocketEmitOptions, type SocketEventArgs, type SocketPayloads, type SocketReplay, type SocketSchemas, StandardErrorMap, type Static, type StepErrorBuilder, type TSchema, type Table, Tool, ToolAnnotations, ToolConfigWithAuthorize, ToolConfigWithoutAuthorize, ToolOptions, Type, Type as t, UnknownToolError, type UntypedServiceClient, ValidationError, ValidationErrorItem, type WorkflowEvent, type WorkflowsOptions, and, asc, attachDatabase, bindCompiledApplication, blob, brick, brickVersion, buildErrorHelpers, buildFtsMatchQuery, compileBrickApplication, compileRoutePlan, compilerRuntime, createActionHandler, createBrickClient, createDatabase, createEndpointHandler, createMcpHandler, createMcpRegistry, createPostgresDatabase, createSQLiteDatabase, defineAction, defineDatabase, defineError, defineListener, definePlugin, defineResource, defineResourcePlugin, defineSecret, defineService, defineServicePlugin, defineTool, desc, drizzleSchema, emitEvent, emitHandlerFactory, endpointPaths, ensureResourceIndexes, ensureSQLiteFts, envSource, eq, errorsOf, executeCompiledRoute, foreignKey, generateOpenApiSpec, generateSQLiteIndexDdl, generateSQLiteTableDdl, getActionAccess, getActionRoute, getCompiledCheck, getGlobalRegistry, getPluginActionRoute, getPluginEndpoints, getTableColumns, getTableName, gt, gte, hoistAnchoredSchemas, ilike, inArray, index, integer, is, isBrickApp, isBrickServerError, isBrickTransportError, isDatabaseHandle, isEventRef, isNotNull, isNull, isOutboxTable, isPluginInstance, isTool, kebabCase, like, listSecrets, loadCompiledBrickApp, loadRecord, lt, lte, migrateDatabase, ne, not, notInArray, onTransactionCommit, or, outboxTable, overrideSecret, overrideSecrets, port, primaryKey, real, redisBroker, referencePlugin, registerReferenceRoute, relations, requestLoggingPlugin, requireBrickApp, resetGlobalRegistry, resetSecrets, resolveEndpointDb, resolveSecrets, resolveWorkflowPaths, runInTransaction, satisfiesRange, scalarDocsHTML, serializeSocketSchema, setActionAccess, sql, sqliteTable, stepErrors, stepFailure, stopAllEvents, swaggerDocsHTML, syncSchema, text, toErrorResponse, toOpenApiPath, traceRoute, uniqueIndex, useDeps, useService, validateWithSchema };
|