@brickkit/core 0.7.4 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -80
- package/dist/chunks/client.d.ts +122 -3
- package/dist/chunks/client.d.ts.map +1 -1
- package/dist/chunks/client.js +264 -0
- package/dist/chunks/client.js.map +1 -0
- package/dist/client.js +1 -206
- package/dist/index.d.ts +902 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3284 -4
- package/dist/index.js.map +1 -1
- package/dist/tanstack-query.js +1 -1
- package/package.json +5 -6
- package/dist/chunks/effect.d.ts +0 -583
- package/dist/chunks/effect.d.ts.map +0 -1
- package/dist/chunks/effect.js +0 -2965
- package/dist/chunks/effect.js.map +0 -1
- package/dist/chunks/types.js +0 -46
- package/dist/chunks/types.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/effect.d.ts +0 -3
- package/dist/effect.js +0 -1
package/README.md
CHANGED
|
@@ -117,94 +117,48 @@ The registry accepts `services` and/or an explicit `tools` array, rejects duplic
|
|
|
117
117
|
|
|
118
118
|
Source: <https://github.com/Chandraprakash-Darji/brick>.
|
|
119
119
|
|
|
120
|
-
##
|
|
120
|
+
## Tracing
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
plugin setup stay synchronous so the compiler can inspect them and plugin
|
|
126
|
-
installation can roll back failed declarations.
|
|
122
|
+
Brick records HTTP, action, and RPC spans through `@opentelemetry/api`. Tracing
|
|
123
|
+
is off by default. Turn it on per app with the `telemetry` option, and register
|
|
124
|
+
an OpenTelemetry tracer provider so the spans have somewhere to go:
|
|
127
125
|
|
|
128
126
|
```ts
|
|
129
|
-
import {
|
|
130
|
-
import { brick, defineService, t } from "@brickkit/core/effect";
|
|
131
|
-
|
|
132
|
-
class Greeting extends Context.Service<Greeting, { text: string }>()(
|
|
133
|
-
"Greeting",
|
|
134
|
-
) {}
|
|
135
|
-
|
|
136
|
-
const service = defineService("greetings", {
|
|
137
|
-
context: () => Effect.map(Greeting, ({ text }) => ({ greeting: text })),
|
|
138
|
-
lifecycle: {
|
|
139
|
-
onInit: () => Effect.void,
|
|
140
|
-
onDestroy: () => Effect.void,
|
|
141
|
-
},
|
|
142
|
-
});
|
|
127
|
+
import { brick } from "@brickkit/core";
|
|
143
128
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
output: t.String(),
|
|
147
|
-
authorize: () => Effect.succeed(true),
|
|
148
|
-
execute: ({ ctx }) => Effect.succeed(ctx.greeting),
|
|
149
|
-
});
|
|
129
|
+
const app = brick({ services: [pagesService], telemetry: true });
|
|
130
|
+
```
|
|
150
131
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
132
|
+
Each request becomes a server span. Each action, remote call, and SQL statement
|
|
133
|
+
made during it becomes a child span. SQLite statements are timed at the
|
|
134
|
+
`bun:sqlite` driver, and postgres.js statements at the query itself. Failures
|
|
135
|
+
are recorded on the span that produced them: server faults (5xx) mark the span
|
|
136
|
+
as errored with an exception event, while client errors (4xx) only add
|
|
137
|
+
`brick.error.code`. Without a registered provider the spans are no-ops.
|
|
138
|
+
|
|
139
|
+
With a W3C trace context propagator registered, requests continue a caller's
|
|
140
|
+
trace from its `traceparent` header, and the response carries `traceparent`
|
|
141
|
+
back. Without an `x-trace-id` header, Brick returns the request's trace id as
|
|
142
|
+
`x-trace-id`. Statement text is recorded as `db.statement`; bound parameter
|
|
143
|
+
values are not.
|
|
144
|
+
|
|
145
|
+
Routes registered directly on the app, such as an auth handler mounted with
|
|
146
|
+
`app.all()`, sit outside actions and endpoints. Wrap their handlers with
|
|
147
|
+
`traceRoute(route, handler)` to give them a server span. The handler receives
|
|
148
|
+
`request`, `headers`, `set`, `params`, and `query`; read the body from
|
|
149
|
+
`request`. `traceRoute` records whenever a tracer provider is registered.
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { traceRoute } from "@brickkit/core";
|
|
162
153
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
154
|
+
app.all(
|
|
155
|
+
"/api/auth/*",
|
|
156
|
+
traceRoute("/api/auth/*", ({ request }) => auth.handler(request)),
|
|
157
|
+
);
|
|
167
158
|
```
|
|
168
159
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
before the first HTTP request or server startup. `initialize()` also lets scripts
|
|
172
|
-
initialize explicitly before direct action or tool calls. `dispose()` runs service
|
|
173
|
-
destruction hooks, releases the Layer, and releases database handles — closing
|
|
174
|
-
the ones no remaining app uses. Injected database clients remain owned by their
|
|
175
|
-
callers. Services may be shared across apps; the newest live binding wins for
|
|
176
|
-
direct calls, and disposing an app restores the previous binding.
|
|
177
|
-
|
|
178
|
-
The app exposes `initializeEffect`, `disposeEffect`, `handleEffect(request)`, and
|
|
179
|
-
`listenEffect(port)` for Effect composition. The normal `.handle()`, `.listen()`,
|
|
180
|
-
and `.stop()` methods remain available. HTTP request cancellation interrupts
|
|
181
|
-
native callbacks and runs their finalizers.
|
|
182
|
-
|
|
183
|
-
Actions and tools expose lazy `executeEffect(params)`, including context
|
|
184
|
-
resolution, input validation, authorization, execution, and output validation.
|
|
185
|
-
Calling an action, `.run`, or `.execute` returns a Promise. Native action
|
|
186
|
-
requirements remain in the Effect type; provide dependencies with `Effect.provide`
|
|
187
|
-
when composing outside an app. Service context resolution also exposes
|
|
188
|
-
`resolveContextEffect`. Resource plugin and CRUD callbacks inherit that caller's
|
|
189
|
-
runtime across the Promise-based database code.
|
|
190
|
-
|
|
191
|
-
Use `service.tool` for native tools. `createMcpRegistry` retains the MCP Promise
|
|
192
|
-
interface and adds `callToolEffect`. `createServiceProxy` returns Effects for local
|
|
193
|
-
RPC calls and preserves the caller's Layer. Remote dispatch is not implemented.
|
|
194
|
-
|
|
195
|
-
Use `defineServicePlugin` and `defineResourcePlugin` from the Effect entrypoint
|
|
196
|
-
for native `routes.action` and `routes.endpoint` callbacks. `defineResource` and
|
|
197
|
-
`service.resource` share the existing resource identity and plugin host.
|
|
198
|
-
For CRUD policies, hooks, SQL scopes, and field scrubbers, use `crud` from
|
|
199
|
-
`@brickkit/crud/effect`.
|
|
200
|
-
|
|
201
|
-
`Effect.fail` preserves failure values at the Promise boundary. Use
|
|
202
|
-
`ActionExecutionError` for a specific HTTP status. Throwing `error` helpers also
|
|
203
|
-
work. Action errors include framework validation and context errors; service,
|
|
204
|
-
CRUD, and dynamic MCP failure types remain broad because plugins and providers
|
|
205
|
-
can reject arbitrary values. Dynamic registration does not prove at compile time
|
|
206
|
-
that an application's Layer supplies every registered callback's dependencies.
|
|
207
|
-
The framework uses Effect 4.
|
|
160
|
+
`brick dev` registers a provider and sends the spans to its dashboard, so apps
|
|
161
|
+
there need `telemetry: true` too.
|
|
208
162
|
|
|
209
163
|
## TanStack Query options
|
|
210
164
|
|
package/dist/chunks/client.d.ts
CHANGED
|
@@ -83,12 +83,64 @@ interface ResourcePlugin<S extends Service<any, any>, R extends Resource<any, an
|
|
|
83
83
|
readonly routes?: PluginRoutes;
|
|
84
84
|
readonly setup: (context: ResourcePluginContext<S, R>) => A;
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Define a plugin that installs onto a service with `service.use(plugin)`. Its
|
|
88
|
+
* `setup` receives the service and a `routes` registrar for adding actions and
|
|
89
|
+
* raw HTTP endpoints, and returns the typed API that `service.use` hands back.
|
|
90
|
+
*
|
|
91
|
+
* @param definition - A unique `name`, optional `routes` controls that let the
|
|
92
|
+
* user move or switch off the plugin's routes, and `setup`, which must be
|
|
93
|
+
* synchronous.
|
|
94
|
+
* @returns The plugin descriptor, frozen.
|
|
95
|
+
* @throws When the name is empty or has surrounding whitespace.
|
|
96
|
+
* @example
|
|
97
|
+
* import { defineServicePlugin, t } from "@brickkit/core";
|
|
98
|
+
*
|
|
99
|
+
* export const greeting = (salutation = "Hello") =>
|
|
100
|
+
* defineServicePlugin({
|
|
101
|
+
* name: "example/greeting",
|
|
102
|
+
* setup({ routes }) {
|
|
103
|
+
* const hello = routes.action({
|
|
104
|
+
* name: "hello",
|
|
105
|
+
* input: t.Object({ name: t.String() }),
|
|
106
|
+
* output: t.String(),
|
|
107
|
+
* execute: ({ input }) => `${salutation}, ${input.name}!`,
|
|
108
|
+
* });
|
|
109
|
+
* return { hello };
|
|
110
|
+
* },
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* const api = greeterService.use(greeting("Welcome"));
|
|
114
|
+
* await api.hello({ input: { name: "Ada" } });
|
|
115
|
+
*/
|
|
86
116
|
declare function defineServicePlugin<S extends Service<any, any> = Service<any, any>, A = unknown>(definition: Omit<ServicePlugin<S, A>, typeof pluginKind> & {
|
|
87
117
|
setup: (context: ServicePluginContext<S>) => A & (A extends PromiseLike<unknown> ? never : unknown);
|
|
88
118
|
}): ServicePlugin<S, A>;
|
|
119
|
+
/**
|
|
120
|
+
* Define a plugin that installs onto a resource (a table and its entity) with
|
|
121
|
+
* `resource.use(plugin)`. Its `setup` receives the service, the resource, and a
|
|
122
|
+
* `routes` registrar, whose routes are scoped under the resource's name, and
|
|
123
|
+
* returns the typed API that `resource.use` hands back. `crud` is built this way.
|
|
124
|
+
*
|
|
125
|
+
* @param definition - A unique `name`, optional `routes` controls, and `setup`,
|
|
126
|
+
* which must be synchronous.
|
|
127
|
+
* @returns The plugin descriptor, frozen.
|
|
128
|
+
* @throws When the name is empty or has surrounding whitespace.
|
|
129
|
+
*/
|
|
89
130
|
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 pluginKind> & {
|
|
90
131
|
setup: (context: ResourcePluginContext<S, R>) => A & (A extends PromiseLike<unknown> ? never : unknown);
|
|
91
132
|
}): ResourcePlugin<S, R, A>;
|
|
133
|
+
/**
|
|
134
|
+
* Where a plugin mounted an action over HTTP, for the OpenAPI generator, the
|
|
135
|
+
* compiler, and the typed client.
|
|
136
|
+
*
|
|
137
|
+
* @param action - An action.
|
|
138
|
+
* @param prefix - The application's route prefix (default `/api`).
|
|
139
|
+
* @returns `undefined` when no plugin bound the action (it uses its own route),
|
|
140
|
+
* `false` when the plugin's route was switched off, otherwise the route's
|
|
141
|
+
* `path` and `method`, the `clientPath` the typed client uses, and the owning
|
|
142
|
+
* `plugin` and `resource`.
|
|
143
|
+
*/
|
|
92
144
|
declare function getPluginActionRoute(action: Action<any, any, any, any>, prefix?: string): false | {
|
|
93
145
|
path: string;
|
|
94
146
|
method: PluginRouteMethod;
|
|
@@ -96,6 +148,15 @@ declare function getPluginActionRoute(action: Action<any, any, any, any>, prefix
|
|
|
96
148
|
plugin: string;
|
|
97
149
|
resource: string | undefined;
|
|
98
150
|
} | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* The raw HTTP endpoints plugins registered on a service, ready to mount on the
|
|
153
|
+
* application. Each handler resolves the service's context before it runs.
|
|
154
|
+
*
|
|
155
|
+
* @param service - The service plugins were installed on.
|
|
156
|
+
* @param prefix - The application's route prefix (default `/api`).
|
|
157
|
+
* @returns The enabled endpoints: `path`, `method`, `handler`, and the
|
|
158
|
+
* `summary`, `description`, and `tags` for OpenAPI.
|
|
159
|
+
*/
|
|
99
160
|
declare function getPluginEndpoints(service: Service<any, any>, prefix?: string): {
|
|
100
161
|
path: string;
|
|
101
162
|
method: PluginRouteMethod;
|
|
@@ -292,13 +353,51 @@ interface DatabaseHandle<TDb, TSchema extends Record<string, unknown> = Record<s
|
|
|
292
353
|
getDb(): TDb;
|
|
293
354
|
close?(): void | Promise<void>;
|
|
294
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Whether a value is a database handle made by `defineDatabase`.
|
|
358
|
+
*
|
|
359
|
+
* @param value - Anything.
|
|
360
|
+
* @returns `true` for a handle, narrowing its type.
|
|
361
|
+
*/
|
|
295
362
|
declare function isDatabaseHandle(value: unknown): value is DatabaseHandle<unknown>;
|
|
363
|
+
/**
|
|
364
|
+
* Declare a service's database: its engine, its Drizzle tables, and how to
|
|
365
|
+
* reach it. Nothing connects until the handle is used (`getDb()`), so defining
|
|
366
|
+
* one has no side effects.
|
|
367
|
+
*
|
|
368
|
+
* SQLite is the default and needs no options. Pass `engine: "postgres"` with a
|
|
369
|
+
* `url` for Postgres. Options that belong to the other engine (such as `url` for
|
|
370
|
+
* SQLite, or `path` for Postgres) are refused.
|
|
371
|
+
*
|
|
372
|
+
* @param options - `engine` (`"sqlite"` or `"postgres"`), `tables`, an optional
|
|
373
|
+
* `name`, and the engine's connection settings.
|
|
374
|
+
* @returns A handle to give to `defineService({ database })`. `getDb()` returns
|
|
375
|
+
* the Drizzle database.
|
|
376
|
+
* @throws When the engine is unsupported, or an option does not suit the engine.
|
|
377
|
+
* @example
|
|
378
|
+
* import { defineDatabase } from "@brickkit/core";
|
|
379
|
+
* import { sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
380
|
+
*
|
|
381
|
+
* const pages = sqliteTable("pages", {
|
|
382
|
+
* id: text("id").primaryKey(),
|
|
383
|
+
* title: text("title").notNull(),
|
|
384
|
+
* });
|
|
385
|
+
*
|
|
386
|
+
* export const database = defineDatabase({ tables: { pages } });
|
|
387
|
+
*/
|
|
296
388
|
declare function defineDatabase<TSchema extends Record<string, unknown> = Record<string, unknown>>(options?: SQLiteDefinition<TSchema>): DatabaseHandle<BunSQLiteDatabase$1<TSchema>, TSchema>;
|
|
297
389
|
declare function defineDatabase<TSchema extends Record<string, unknown> = Record<string, unknown>>(options: PostgresDefinition<TSchema>): DatabaseHandle<PostgresJsDatabase<TSchema> & {
|
|
298
390
|
$client: Sql;
|
|
299
391
|
}, TSchema>;
|
|
300
392
|
//#endregion
|
|
301
393
|
//#region src/types.d.ts
|
|
394
|
+
/**
|
|
395
|
+
* The logger on action, tool, and endpoint contexts. While a dashboard is on
|
|
396
|
+
* (`brick dev`, or `brick start` with the `dashboard` option) a line logged
|
|
397
|
+
* during a traced request appears in the dashboard with that request, instead
|
|
398
|
+
* of on the console (as does a plain `console.log`); anywhere else it prints
|
|
399
|
+
* to the console.
|
|
400
|
+
*/
|
|
302
401
|
interface Logger {
|
|
303
402
|
info: (...args: any[]) => void;
|
|
304
403
|
warn: (...args: any[]) => void;
|
|
@@ -604,7 +703,8 @@ interface ActionSchema {
|
|
|
604
703
|
}
|
|
605
704
|
interface ServiceSchema {
|
|
606
705
|
name: string;
|
|
607
|
-
options:
|
|
706
|
+
/** The service options as JSON: functions, such as `context` and hooks, are left out. */
|
|
707
|
+
options: Record<string, unknown>;
|
|
608
708
|
hasDatabase: boolean;
|
|
609
709
|
databaseConfig?: {
|
|
610
710
|
name?: string;
|
|
@@ -612,6 +712,10 @@ interface ServiceSchema {
|
|
|
612
712
|
tables: string[];
|
|
613
713
|
};
|
|
614
714
|
actions: ActionSchema[];
|
|
715
|
+
/** MCP tools. A tool with an HTTP route is also listed under `actions`. */
|
|
716
|
+
tools?: {
|
|
717
|
+
name: string;
|
|
718
|
+
}[];
|
|
615
719
|
resources?: {
|
|
616
720
|
name: string;
|
|
617
721
|
}[];
|
|
@@ -646,6 +750,7 @@ interface CompiledRoutePlan {
|
|
|
646
750
|
key: string;
|
|
647
751
|
isNumber: boolean;
|
|
648
752
|
isBoolean: boolean;
|
|
753
|
+
isArray?: boolean;
|
|
649
754
|
}>;
|
|
650
755
|
logger: Logger;
|
|
651
756
|
errorBuilder: any;
|
|
@@ -682,8 +787,6 @@ interface Service<TDb = BunSQLiteDatabase$1<Record<string, unknown>>, TServiceCo
|
|
|
682
787
|
listResources(): Resource<any, BaseContext<TDb> & TServiceContext>[];
|
|
683
788
|
getDb(): TDb | undefined;
|
|
684
789
|
setDb(database: DatabaseHandle<TDb>): void;
|
|
685
|
-
/** The live handle, reflecting setDb swaps (options.database stays declared). */
|
|
686
|
-
getDatabaseHandle(): DatabaseHandle<TDb> | undefined;
|
|
687
790
|
resolveContext(callCtx?: Partial<BaseContext<TDb> & TServiceContext>): Promise<BaseContext<TDb> & TServiceContext>;
|
|
688
791
|
introspect(): ServiceSchema;
|
|
689
792
|
}
|
|
@@ -838,7 +941,23 @@ declare class BrickServerError extends Error {
|
|
|
838
941
|
body: unknown;
|
|
839
942
|
});
|
|
840
943
|
}
|
|
944
|
+
/**
|
|
945
|
+
* Whether an error from the typed client is a `BrickTransportError`: the request
|
|
946
|
+
* got no meaningful answer from the server (a network failure, a body that was
|
|
947
|
+
* not JSON, or a 4xx outside the declared contract).
|
|
948
|
+
*
|
|
949
|
+
* @param err - What a client call threw.
|
|
950
|
+
* @returns `true` for a transport error, narrowing its type.
|
|
951
|
+
*/
|
|
841
952
|
declare function isBrickTransportError(err: unknown): err is BrickTransportError;
|
|
953
|
+
/**
|
|
954
|
+
* Whether an error from the typed client is a `BrickServerError`: the server
|
|
955
|
+
* answered with a 5xx that is not one of the contract's declared errors, and the
|
|
956
|
+
* error carries its `status`, `url`, and `body`.
|
|
957
|
+
*
|
|
958
|
+
* @param err - What a client call threw.
|
|
959
|
+
* @returns `true` for a server error, narrowing its type.
|
|
960
|
+
*/
|
|
842
961
|
declare function isBrickServerError(err: unknown): err is BrickServerError;
|
|
843
962
|
/** Static input type from the schema, with a fallback for structural actions. */
|
|
844
963
|
type InferActionInput<A> = A extends BrickClientAction<infer I, any, any> ? I : A extends {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","names":["BunSQLiteDatabase","_$__plugin0.ResourcePluginAPI","BunSQLiteDatabase"],"sources":["../../src/plugin.ts","../../src/db/sqlite.ts","../../src/secrets.ts","../../src/db/postgres.ts","../../src/db/define.ts","../../src/types.ts","../../src/client.ts"],"mappings":";;;;;;;;KAcY;KACA;KACA,aAAa,UAAU,mBAAmB,4BAElD,SAAS;EAAyB;EAAe,QAAQ;;KAExD,UAAU,KACb,UAAU,cAAc,SAAS,KAAK,YAAY,KAAK;UAExC,sBACf,UAAU,gBAAgB;EAE1B,QAAQ;EACR,OAAO;EACP;EACA,SAAS;EACT,SAAS;EACT;IAAO;IAAiB,SAAS;;EACjC,KAAK;;UAGU,qBACf,UAAU,gBAAgB,eAC1B,UAAU,mBAAmB;EAE7B,OACE,UAAU,iCACV,UAAU,iCACV,UAAU,eAAe,yBAAyB,eAEhD,wBAGF,QAAQ,0BAA0B,GAAG,GAAG,GAAG;IACzC;IACA,QAAQ;IACR,QAAQ;MAET,OAAO,GAAG,GAAG,GAAG;EACnB,OACE,UAAU,iCACV,UAAU,iCACV,UAAU,eAAe,yBAAyB,eAEhD,wBAGF,QAAQ,6BAA6B,GAAG,GAAG,GAAG;IAC5C;IACA,QAAQ;IACR,QAAQ;MAET,OAAO,GAAG,GAAG,GAAG;EACnB,SAAS;IACP;IACA;IACA,QAAQ;IACR,QAAQ;IACR,UAAU,SAAS,sBAAsB,iBAAiB;IAC1D;IACA;IACA;;;UAIa,qBACf,UAAU,oBAAoB;EAE9B,SAAS;EACT,QAAQ,qBAAqB,UAAU;;UAExB,sBACf,UAAU,oBAAoB,mBAC9B,UAAU,0BAA0B,cAAc,UAAU;EAE5D,SAAS;EACT,UAAU;EACV,QAAQ,qBAAqB,UAAU;;;UAIxB;WACN;WACA;WACA;WACA;;KAEC,kBAAkB,GAAG,GAAG,GAAG,eAAe;WAC3C,aAAa,UAAU;KAE7B;WACU,OAAO;WACP,SAAS;WACT,UAAU;YAErB,UAAU,+BAA+B,KACvC;cAIA;UACW,cAAc,UAAU,mBAAmB;YAChD;WACD;WACA,SAAS;WACT,QAAQ,SAAS,qBAAqB,OAAO;;UAEvC,eACf,UAAU,mBACV,UAAU,yBACV;YAEU;WACD;WACA,SAAS;WACT,QAAQ,SAAS,sBAAsB,GAAG,OAAO
|
|
1
|
+
{"version":3,"file":"client.d.ts","names":["BunSQLiteDatabase","_$__plugin0.ResourcePluginAPI","BunSQLiteDatabase"],"sources":["../../src/plugin.ts","../../src/db/sqlite.ts","../../src/secrets.ts","../../src/db/postgres.ts","../../src/db/define.ts","../../src/types.ts","../../src/client.ts"],"mappings":";;;;;;;;KAcY;KACA;KACA,aAAa,UAAU,mBAAmB,4BAElD,SAAS;EAAyB;EAAe,QAAQ;;KAExD,UAAU,KACb,UAAU,cAAc,SAAS,KAAK,YAAY,KAAK;UAExC,sBACf,UAAU,gBAAgB;EAE1B,QAAQ;EACR,OAAO;EACP;EACA,SAAS;EACT,SAAS;EACT;IAAO;IAAiB,SAAS;;EACjC,KAAK;;UAGU,qBACf,UAAU,gBAAgB,eAC1B,UAAU,mBAAmB;EAE7B,OACE,UAAU,iCACV,UAAU,iCACV,UAAU,eAAe,yBAAyB,eAEhD,wBAGF,QAAQ,0BAA0B,GAAG,GAAG,GAAG;IACzC;IACA,QAAQ;IACR,QAAQ;MAET,OAAO,GAAG,GAAG,GAAG;EACnB,OACE,UAAU,iCACV,UAAU,iCACV,UAAU,eAAe,yBAAyB,eAEhD,wBAGF,QAAQ,6BAA6B,GAAG,GAAG,GAAG;IAC5C;IACA,QAAQ;IACR,QAAQ;MAET,OAAO,GAAG,GAAG,GAAG;EACnB,SAAS;IACP;IACA;IACA,QAAQ;IACR,QAAQ;IACR,UAAU,SAAS,sBAAsB,iBAAiB;IAC1D;IACA;IACA;;;UAIa,qBACf,UAAU,oBAAoB;EAE9B,SAAS;EACT,QAAQ,qBAAqB,UAAU;;UAExB,sBACf,UAAU,oBAAoB,mBAC9B,UAAU,0BAA0B,cAAc,UAAU;EAE5D,SAAS;EACT,UAAU;EACV,QAAQ,qBAAqB,UAAU;;;UAIxB;WACN;WACA;WACA;WACA;;KAEC,kBAAkB,GAAG,GAAG,GAAG,eAAe;WAC3C,aAAa,UAAU;KAE7B;WACU,OAAO;WACP,SAAS;WACT,UAAU;YAErB,UAAU,+BAA+B,KACvC;cAIA;UACW,cAAc,UAAU,mBAAmB;YAChD;WACD;WACA,SAAS;WACT,QAAQ,SAAS,qBAAqB,OAAO;;UAEvC,eACf,UAAU,mBACV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,qBAC7C,SAAS;EAAuB,UAAU;IACzC,YAAY;iBACC,kBAAkB,aAAa,qBAC7C,SAAS,qBACR,YAAY"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
var ValidationError = class extends Error {
|
|
3
|
+
code = "VALIDATION_FAILED";
|
|
4
|
+
status;
|
|
5
|
+
errors;
|
|
6
|
+
constructor(message, errors = [], status = 400) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "ValidationError";
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.errors = errors;
|
|
11
|
+
}
|
|
12
|
+
toJSON() {
|
|
13
|
+
return {
|
|
14
|
+
name: this.name,
|
|
15
|
+
code: this.code,
|
|
16
|
+
message: this.message,
|
|
17
|
+
status: this.status,
|
|
18
|
+
errors: this.errors
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var ActionExecutionError = class extends Error {
|
|
23
|
+
code;
|
|
24
|
+
status;
|
|
25
|
+
details;
|
|
26
|
+
constructor(code, message, status = 400, details, options) {
|
|
27
|
+
super(message, options);
|
|
28
|
+
this.name = "ActionExecutionError";
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.details = details;
|
|
32
|
+
}
|
|
33
|
+
toJSON() {
|
|
34
|
+
return {
|
|
35
|
+
name: this.name,
|
|
36
|
+
code: this.code,
|
|
37
|
+
message: this.message,
|
|
38
|
+
status: this.status,
|
|
39
|
+
details: this.details
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/client.ts
|
|
45
|
+
/**
|
|
46
|
+
* The request never received a meaningful server answer: DNS / connection
|
|
47
|
+
* failure, a malformed body, or a 4xx response outside the declared contract
|
|
48
|
+
* (no `code` and no `ValidationError` shape).
|
|
49
|
+
*/
|
|
50
|
+
var BrickTransportError = class extends Error {
|
|
51
|
+
kind = "transport";
|
|
52
|
+
status;
|
|
53
|
+
url;
|
|
54
|
+
body;
|
|
55
|
+
cause;
|
|
56
|
+
constructor(message, opts) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = "BrickTransportError";
|
|
59
|
+
this.status = opts.status;
|
|
60
|
+
this.url = opts.url;
|
|
61
|
+
this.body = opts.body;
|
|
62
|
+
this.cause = opts.cause;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The server answered 5xx without a declared `code` / `ValidationError` shape,
|
|
67
|
+
* i.e. an unexpected failure rather than a modelled domain error.
|
|
68
|
+
*/
|
|
69
|
+
var BrickServerError = class extends Error {
|
|
70
|
+
kind = "server";
|
|
71
|
+
status;
|
|
72
|
+
url;
|
|
73
|
+
body;
|
|
74
|
+
constructor(message, opts) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.name = "BrickServerError";
|
|
77
|
+
this.status = opts.status;
|
|
78
|
+
this.url = opts.url;
|
|
79
|
+
this.body = opts.body;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Whether an error from the typed client is a `BrickTransportError`: the request
|
|
84
|
+
* got no meaningful answer from the server (a network failure, a body that was
|
|
85
|
+
* not JSON, or a 4xx outside the declared contract).
|
|
86
|
+
*
|
|
87
|
+
* @param err - What a client call threw.
|
|
88
|
+
* @returns `true` for a transport error, narrowing its type.
|
|
89
|
+
*/
|
|
90
|
+
function isBrickTransportError(err) {
|
|
91
|
+
return err instanceof BrickTransportError;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Whether an error from the typed client is a `BrickServerError`: the server
|
|
95
|
+
* answered with a 5xx that is not one of the contract's declared errors, and the
|
|
96
|
+
* error carries its `status`, `url`, and `body`.
|
|
97
|
+
*
|
|
98
|
+
* @param err - What a client call threw.
|
|
99
|
+
* @returns `true` for a server error, narrowing its type.
|
|
100
|
+
*/
|
|
101
|
+
function isBrickServerError(err) {
|
|
102
|
+
return err instanceof BrickServerError;
|
|
103
|
+
}
|
|
104
|
+
function normalizeBaseUrl(baseUrl) {
|
|
105
|
+
const trimmed = baseUrl.replace(/\/+$/, "");
|
|
106
|
+
if (!trimmed) throw new Error("[Brick-TS client] `baseUrl` must not be empty.");
|
|
107
|
+
return trimmed;
|
|
108
|
+
}
|
|
109
|
+
function normalizePrefix(prefix) {
|
|
110
|
+
if (!prefix) return "/api";
|
|
111
|
+
const withLeading = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
112
|
+
return withLeading.length > 1 ? withLeading.replace(/\/+$/, "") : withLeading;
|
|
113
|
+
}
|
|
114
|
+
function toQueryString(input) {
|
|
115
|
+
if (input == null || typeof input !== "object") return "";
|
|
116
|
+
const params = new URLSearchParams();
|
|
117
|
+
for (const [key, value] of Object.entries(input)) {
|
|
118
|
+
if (value === void 0 || value === null) continue;
|
|
119
|
+
if (Array.isArray(value)) for (const item of value) {
|
|
120
|
+
if (item === void 0 || item === null) continue;
|
|
121
|
+
params.append(key, typeof item === "object" ? JSON.stringify(item) : String(item));
|
|
122
|
+
}
|
|
123
|
+
else if (typeof value === "object") params.append(key, JSON.stringify(value));
|
|
124
|
+
else params.append(key, String(value));
|
|
125
|
+
}
|
|
126
|
+
const qs = params.toString();
|
|
127
|
+
return qs ? `?${qs}` : "";
|
|
128
|
+
}
|
|
129
|
+
function isActionValue(value) {
|
|
130
|
+
return typeof value === "function" && !!value.config && typeof value.config.execute === "function";
|
|
131
|
+
}
|
|
132
|
+
function isClientAction(value) {
|
|
133
|
+
return !!value && typeof value === "object" && value.kind === "action";
|
|
134
|
+
}
|
|
135
|
+
function planRequest(path, target, input, baseUrl, prefix) {
|
|
136
|
+
if (path.length === 0) throw new Error("[Brick-TS client] No action selected: call a leaf such as `api.page.list(input)`.");
|
|
137
|
+
const actionTarget = isActionValue(target) || isClientAction(target) ? target : void 0;
|
|
138
|
+
const actionConfig = actionTarget?.config;
|
|
139
|
+
if (path.length < 2) throw new Error(`[Brick-TS client] Cannot address '${path.join(".")}': custom actions need a service segment, e.g. \`api.${path[0]}.<action>(input)\`.`);
|
|
140
|
+
const service = typeof actionTarget?.serviceName === "string" && actionTarget.serviceName ? actionTarget.serviceName : path[0];
|
|
141
|
+
const action = typeof actionTarget?.name === "string" && actionTarget.name ? actionTarget.name : path.slice(1).join(".");
|
|
142
|
+
const method = actionConfig?.method ?? "POST";
|
|
143
|
+
const configuredPath = actionConfig?.path;
|
|
144
|
+
let actionPath = configuredPath ?? `${prefix}/${encodeURIComponent(service)}/${action.split(".").map(encodeURIComponent).join(".")}`;
|
|
145
|
+
let remaining = input;
|
|
146
|
+
if (configuredPath !== void 0) {
|
|
147
|
+
if (!configuredPath.startsWith("/")) throw new Error("[Brick-TS client] Action paths must start with '/'.");
|
|
148
|
+
const source = { ...input ?? {} };
|
|
149
|
+
const record = { ...source };
|
|
150
|
+
actionPath = actionPath.replace(/:([^/]+)/g, (_match, key) => {
|
|
151
|
+
const value = Object.hasOwn(source, key) ? source[key] : void 0;
|
|
152
|
+
if (value === void 0 || value === null || value === "") throw new Error(`[Brick-TS client] Missing path parameter '${key}'.`);
|
|
153
|
+
delete record[key];
|
|
154
|
+
return encodeURIComponent(String(value));
|
|
155
|
+
});
|
|
156
|
+
remaining = input === void 0 ? void 0 : record;
|
|
157
|
+
}
|
|
158
|
+
const queryOnly = method === "GET" || method === "DELETE";
|
|
159
|
+
return {
|
|
160
|
+
method,
|
|
161
|
+
url: `${baseUrl}${actionPath}${queryOnly ? toQueryString(remaining) : ""}`,
|
|
162
|
+
body: queryOnly ? void 0 : remaining,
|
|
163
|
+
hasBody: !queryOnly && remaining !== void 0
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function toActionError(status, body, url) {
|
|
167
|
+
if (body !== null && typeof body === "object") {
|
|
168
|
+
const record = body;
|
|
169
|
+
if (record.name === "ValidationError") return new ValidationError(typeof record.message === "string" ? record.message : "Validation failed", Array.isArray(record.errors) ? record.errors : [], typeof record.status === "number" ? record.status : status);
|
|
170
|
+
if (typeof record.code === "string") return new ActionExecutionError(record.code, typeof record.message === "string" ? record.message : record.code, typeof record.status === "number" ? record.status : status, record.details ?? void 0);
|
|
171
|
+
}
|
|
172
|
+
if (status >= 500) return new BrickServerError(`Unexpected server error (status ${status}) for ${url}.`, {
|
|
173
|
+
status,
|
|
174
|
+
url,
|
|
175
|
+
body
|
|
176
|
+
});
|
|
177
|
+
return new BrickTransportError(`Request failed with status ${status} for ${url}.`, {
|
|
178
|
+
status,
|
|
179
|
+
url,
|
|
180
|
+
body
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async function dispatch(resolved, path, target, input, callOptions) {
|
|
184
|
+
const { method, url, body, hasBody } = planRequest(path, target, input, resolved.baseUrl, resolved.prefix);
|
|
185
|
+
const headers = {
|
|
186
|
+
accept: "application/json",
|
|
187
|
+
...typeof resolved.headers === "function" ? await resolved.headers() : resolved.headers ?? {},
|
|
188
|
+
...callOptions?.headers
|
|
189
|
+
};
|
|
190
|
+
let payload;
|
|
191
|
+
if (hasBody) {
|
|
192
|
+
headers["content-type"] = "application/json";
|
|
193
|
+
payload = JSON.stringify(body ?? null);
|
|
194
|
+
}
|
|
195
|
+
const timeoutMs = callOptions?.timeoutMs ?? resolved.timeoutMs;
|
|
196
|
+
let timeoutSignal;
|
|
197
|
+
if (timeoutMs !== void 0) timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
198
|
+
const signals = [callOptions?.signal ?? resolved.signal, timeoutSignal].filter((value) => value !== void 0);
|
|
199
|
+
const signal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
200
|
+
let response;
|
|
201
|
+
try {
|
|
202
|
+
response = await resolved.fetch(url, {
|
|
203
|
+
method,
|
|
204
|
+
headers,
|
|
205
|
+
body: payload,
|
|
206
|
+
signal
|
|
207
|
+
});
|
|
208
|
+
} catch (err) {
|
|
209
|
+
if (err instanceof Error && err.name === "AbortError") throw err;
|
|
210
|
+
throw new BrickTransportError(`Network request failed for ${url}: ${err instanceof Error ? err.message : String(err)}`, {
|
|
211
|
+
url,
|
|
212
|
+
cause: err
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
let parsed;
|
|
216
|
+
const text = await response.text();
|
|
217
|
+
if (response.headers.get("content-type")?.includes("text/plain")) parsed = text;
|
|
218
|
+
else if (text) try {
|
|
219
|
+
parsed = JSON.parse(text);
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (!response.headers.has("content-type")) parsed = text;
|
|
222
|
+
else throw new BrickTransportError(`Unparsable response body for ${url}.`, {
|
|
223
|
+
status: response.status,
|
|
224
|
+
url,
|
|
225
|
+
cause: err
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (response.ok) return parsed;
|
|
229
|
+
throw toActionError(response.status, parsed, url);
|
|
230
|
+
}
|
|
231
|
+
function childNode(node, prop) {
|
|
232
|
+
if (node != null && (typeof node === "object" || typeof node === "function")) return node[prop];
|
|
233
|
+
}
|
|
234
|
+
function createNamespace(resolved, path, node) {
|
|
235
|
+
const callable = async (input, options) => dispatch(resolved, path, node, input, options);
|
|
236
|
+
return new Proxy(callable, {
|
|
237
|
+
get(target, prop, receiver) {
|
|
238
|
+
if (typeof prop !== "string") return Reflect.get(target, prop, receiver);
|
|
239
|
+
if (prop === "then" || prop === "catch" || prop === "finally") return void 0;
|
|
240
|
+
return createNamespace(resolved, [...path, prop], childNode(node, prop));
|
|
241
|
+
},
|
|
242
|
+
apply(_target, _thisArg, args) {
|
|
243
|
+
const [input, options] = args;
|
|
244
|
+
return dispatch(resolved, path, node, input, options);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function createBrickClient(options) {
|
|
249
|
+
if (!options?.baseUrl) throw new Error("[Brick-TS client] `baseUrl` is required, e.g. `{ baseUrl: \"http://localhost:4000\" }`.");
|
|
250
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
251
|
+
if (typeof fetchImpl !== "function") throw new Error("[Brick-TS client] No `fetch` implementation available: pass `fetch` explicitly.");
|
|
252
|
+
return createNamespace({
|
|
253
|
+
baseUrl: normalizeBaseUrl(options.baseUrl),
|
|
254
|
+
prefix: normalizePrefix(options.prefix),
|
|
255
|
+
headers: options.headers,
|
|
256
|
+
fetch: fetchImpl,
|
|
257
|
+
signal: options.signal,
|
|
258
|
+
timeoutMs: options.timeoutMs
|
|
259
|
+
}, [], options.contract);
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
export { isBrickTransportError as a, isBrickServerError as i, BrickTransportError as n, ActionExecutionError as o, createBrickClient as r, ValidationError as s, BrickServerError as t };
|
|
263
|
+
|
|
264
|
+
//# sourceMappingURL=client.js.map
|