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