@brickkit/core 0.9.0 → 0.10.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 +105 -2
- package/dist/chunks/client.d.ts.map +1 -1
- package/dist/chunks/client.js +221 -1
- package/dist/chunks/client.js.map +1 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/index.d.ts +32 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +318 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as isBrickTransportError, i as isBrickServerError,
|
|
1
|
+
import { a as isBrickTransportError, c as SOCKET_MAX_BYTES, d as ActionExecutionError, f as ValidationError, i as isBrickServerError, l as isSocketEnvelope, n as BrickTransportError, r as createBrickClient, s as SOCKET_BUFFER_BYTES, t as BrickServerError, u as serializeSocketSchema } from "./chunks/client.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
|
|
4
4
|
import { Type, Type as t } from "@sinclair/typebox";
|
|
@@ -8,9 +8,11 @@ import { Elysia } from "elysia";
|
|
|
8
8
|
import { Table, and, and as and$1, asc, asc as asc$1, desc, eq, eq as eq$1, getTableColumns, getTableColumns as getTableColumns$1, getTableName, getTableName as getTableName$1, gt, gte, ilike, inArray, inArray as inArray$1, is, isNotNull, isNull, like, lt, lt as lt$1, lte, lte as lte$1, ne, not, notInArray, or, or as or$1, relations, sql, sql as sql$1 } from "drizzle-orm";
|
|
9
9
|
import { bigserial, index as index$1, integer as integer$1, jsonb, pgTable, text as text$1, timestamp } from "drizzle-orm/pg-core";
|
|
10
10
|
import { blob, foreignKey, index, index as index$2, integer, integer as integer$2, primaryKey, real, sqliteTable, sqliteTable as sqliteTable$1, text, text as text$2, uniqueIndex } from "drizzle-orm/sqlite-core";
|
|
11
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
12
|
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
12
13
|
import { dirname, join, resolve } from "node:path";
|
|
13
14
|
import { pathToFileURL } from "node:url";
|
|
15
|
+
import { websocket } from "elysia/websocket";
|
|
14
16
|
import postgres from "postgres";
|
|
15
17
|
import { drizzle } from "drizzle-orm/postgres-js";
|
|
16
18
|
//#region \0rolldown/runtime.js
|
|
@@ -173,6 +175,7 @@ var ServiceRegistry = class {
|
|
|
173
175
|
const schema = service.introspect();
|
|
174
176
|
return {
|
|
175
177
|
...schema,
|
|
178
|
+
...application?.sockets ? { sockets: application.sockets.filter((socket) => socket.service === service.name) } : {},
|
|
176
179
|
actions: schema.actions.map((action) => {
|
|
177
180
|
const route = byAction.get(action.name);
|
|
178
181
|
return route ? {
|
|
@@ -2284,16 +2287,44 @@ function outboxEngine(table) {
|
|
|
2284
2287
|
//#endregion
|
|
2285
2288
|
//#region src/events/transaction.ts
|
|
2286
2289
|
const sqliteQueues = /* @__PURE__ */ new WeakMap();
|
|
2290
|
+
const active = new AsyncLocalStorage();
|
|
2291
|
+
function joined(db) {
|
|
2292
|
+
const open = active.getStore();
|
|
2293
|
+
return open?.open && open.handles.has(db) ? open : void 0;
|
|
2294
|
+
}
|
|
2287
2295
|
function isSqliteDatabase(db) {
|
|
2288
2296
|
return typeof db?.$client?.prepare === "function" && typeof db?.$client?.run === "function";
|
|
2289
2297
|
}
|
|
2290
|
-
function rollbackQuietly(db) {
|
|
2298
|
+
function rollbackQuietly(db, statement = "ROLLBACK") {
|
|
2291
2299
|
try {
|
|
2292
|
-
db.$client.run(
|
|
2300
|
+
db.$client.run(statement);
|
|
2293
2301
|
} catch {
|
|
2294
2302
|
return;
|
|
2295
2303
|
}
|
|
2296
2304
|
}
|
|
2305
|
+
async function nested(db, open, fn) {
|
|
2306
|
+
const commits = open.commits.length;
|
|
2307
|
+
try {
|
|
2308
|
+
if (!isSqliteDatabase(db)) return await db.transaction((tx) => {
|
|
2309
|
+
open.handles.add(tx);
|
|
2310
|
+
return fn(tx);
|
|
2311
|
+
});
|
|
2312
|
+
const name = `brick_${++open.savepoints}`;
|
|
2313
|
+
db.$client.run(`SAVEPOINT ${name}`);
|
|
2314
|
+
try {
|
|
2315
|
+
const result = await fn(db);
|
|
2316
|
+
db.$client.run(`RELEASE ${name}`);
|
|
2317
|
+
return result;
|
|
2318
|
+
} catch (error) {
|
|
2319
|
+
rollbackQuietly(db, `ROLLBACK TO ${name}`);
|
|
2320
|
+
rollbackQuietly(db, `RELEASE ${name}`);
|
|
2321
|
+
throw error;
|
|
2322
|
+
}
|
|
2323
|
+
} catch (error) {
|
|
2324
|
+
open.commits.length = commits;
|
|
2325
|
+
throw error;
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2297
2328
|
/**
|
|
2298
2329
|
* Run `fn` in a database transaction: everything it writes through the `tx` it is
|
|
2299
2330
|
* given is committed together when it returns, or undone if it throws.
|
|
@@ -2305,13 +2336,40 @@ function rollbackQuietly(db) {
|
|
|
2305
2336
|
* A write made elsewhere in the process during that time, outside this helper,
|
|
2306
2337
|
* would join the transaction; use Postgres where that matters.
|
|
2307
2338
|
*
|
|
2339
|
+
* A call made inside `fn` with the `tx` it was given (on SQLite, the database
|
|
2340
|
+
* itself) joins the open transaction as a savepoint instead of waiting for it: a
|
|
2341
|
+
* nested failure undoes only the nested work, and the outer transaction decides
|
|
2342
|
+
* the commit. Nested calls must run one at a time.
|
|
2343
|
+
*
|
|
2308
2344
|
* @param db - A Drizzle database, from `service.getDb()`.
|
|
2309
2345
|
* @param fn - Receives the transaction handle to run queries on.
|
|
2310
2346
|
* @returns What `fn` returned.
|
|
2311
2347
|
* @throws What `fn` threw, after rolling back.
|
|
2312
2348
|
*/
|
|
2313
2349
|
async function runInTransaction(db, fn) {
|
|
2314
|
-
|
|
2350
|
+
const outer = joined(db);
|
|
2351
|
+
if (outer) return nested(db, outer, fn);
|
|
2352
|
+
const open = {
|
|
2353
|
+
handles: /* @__PURE__ */ new Set(),
|
|
2354
|
+
commits: [],
|
|
2355
|
+
open: true,
|
|
2356
|
+
savepoints: 0
|
|
2357
|
+
};
|
|
2358
|
+
let result;
|
|
2359
|
+
try {
|
|
2360
|
+
result = await active.run(open, () => begin(db, open, fn));
|
|
2361
|
+
} finally {
|
|
2362
|
+
open.open = false;
|
|
2363
|
+
}
|
|
2364
|
+
for (const commit of open.commits) await commit();
|
|
2365
|
+
return result;
|
|
2366
|
+
}
|
|
2367
|
+
async function begin(db, open, fn) {
|
|
2368
|
+
if (!isSqliteDatabase(db)) return db.transaction((tx) => {
|
|
2369
|
+
open.handles.add(tx);
|
|
2370
|
+
return fn(tx);
|
|
2371
|
+
});
|
|
2372
|
+
open.handles.add(db);
|
|
2315
2373
|
const previous = sqliteQueues.get(db) ?? Promise.resolve();
|
|
2316
2374
|
let release;
|
|
2317
2375
|
const turn = new Promise((resolve) => {
|
|
@@ -2333,6 +2391,20 @@ async function runInTransaction(db, fn) {
|
|
|
2333
2391
|
release();
|
|
2334
2392
|
}
|
|
2335
2393
|
}
|
|
2394
|
+
/**
|
|
2395
|
+
* Run `fn` once the transaction that `db` belongs to has committed, or now when
|
|
2396
|
+
* `db` is not in one opened by `runInTransaction`. It never runs when that
|
|
2397
|
+
* transaction, or the savepoint it was queued in, rolls back. An error it throws
|
|
2398
|
+
* reaches the caller of the outermost `runInTransaction`, after the commit.
|
|
2399
|
+
*
|
|
2400
|
+
* @param db - The handle the work ran on: a `tx`, or a database.
|
|
2401
|
+
* @param fn - The side effect, such as clearing a cache.
|
|
2402
|
+
*/
|
|
2403
|
+
async function onTransactionCommit(db, fn) {
|
|
2404
|
+
const open = joined(db);
|
|
2405
|
+
if (open) open.commits.push(fn);
|
|
2406
|
+
else await fn();
|
|
2407
|
+
}
|
|
2336
2408
|
//#endregion
|
|
2337
2409
|
//#region src/events/dispatcher.ts
|
|
2338
2410
|
function resolveDispatchOptions(options = {}) {
|
|
@@ -3013,6 +3085,217 @@ var EventsHub = class {
|
|
|
3013
3085
|
}
|
|
3014
3086
|
};
|
|
3015
3087
|
//#endregion
|
|
3088
|
+
//#region src/socket.ts
|
|
3089
|
+
var SocketDenied = class extends Error {};
|
|
3090
|
+
function defineServiceSocket(config, resolve) {
|
|
3091
|
+
if (!config.name || config.name.split(".").some((part) => !/^[a-zA-Z_][\w-]*$/.test(part))) throw new Error("Invalid socket name");
|
|
3092
|
+
if (config.path !== void 0 && (!config.path.startsWith("/") || /[?#*]/.test(config.path) || config.path.split("/").some((segment) => segment.startsWith(":")))) throw new Error("Socket path must be a static absolute route without a query or fragment");
|
|
3093
|
+
const input = Object.freeze({ ...config.input });
|
|
3094
|
+
const output = Object.freeze({ ...config.output });
|
|
3095
|
+
const handlers = { ...config.handlers };
|
|
3096
|
+
if (Object.keys(input).length !== Object.keys(handlers).length || Object.keys(input).some((key) => !Object.hasOwn(handlers, key) || typeof handlers[key] !== "function")) throw new Error("Every socket input event needs exactly one handler");
|
|
3097
|
+
for (const schema of [...Object.values(input), ...Object.values(output)]) {
|
|
3098
|
+
serializeSocketSchema(schema);
|
|
3099
|
+
getCompiledCheck(schema);
|
|
3100
|
+
}
|
|
3101
|
+
const typed = (socket) => socket;
|
|
3102
|
+
const context = async (request) => {
|
|
3103
|
+
const ctx = await resolve(request);
|
|
3104
|
+
if (config.authorize && !await config.authorize({ ctx })) throw new SocketDenied();
|
|
3105
|
+
return ctx;
|
|
3106
|
+
};
|
|
3107
|
+
return {
|
|
3108
|
+
schema: {
|
|
3109
|
+
name: config.name,
|
|
3110
|
+
path: config.path,
|
|
3111
|
+
description: config.description,
|
|
3112
|
+
input: Object.keys(input),
|
|
3113
|
+
output: Object.keys(output),
|
|
3114
|
+
hasAuthorize: !!config.authorize
|
|
3115
|
+
},
|
|
3116
|
+
input,
|
|
3117
|
+
output,
|
|
3118
|
+
allowedOrigins: config.allowedOrigins ? [...config.allowedOrigins] : void 0,
|
|
3119
|
+
allowMissingOrigin: config.allowMissingOrigin,
|
|
3120
|
+
async connect(request) {
|
|
3121
|
+
const initial = await context(request);
|
|
3122
|
+
return {
|
|
3123
|
+
async open(socket) {
|
|
3124
|
+
await config.open?.({
|
|
3125
|
+
ctx: initial,
|
|
3126
|
+
socket: typed(socket)
|
|
3127
|
+
});
|
|
3128
|
+
},
|
|
3129
|
+
async message(event, data, socket) {
|
|
3130
|
+
const schema = Object.hasOwn(input, event) ? input[event] : void 0;
|
|
3131
|
+
if (!schema || !getCompiledCheck(schema).Check(data)) throw new SocketDenied();
|
|
3132
|
+
const ctx = await context(request);
|
|
3133
|
+
if (!socket.isOpen) return;
|
|
3134
|
+
const handler = handlers[event];
|
|
3135
|
+
await handler({
|
|
3136
|
+
input: data,
|
|
3137
|
+
ctx,
|
|
3138
|
+
socket: typed(socket)
|
|
3139
|
+
});
|
|
3140
|
+
},
|
|
3141
|
+
async close(socket, code, reason) {
|
|
3142
|
+
await config.close?.({
|
|
3143
|
+
ctx: initial,
|
|
3144
|
+
socket: typed(socket),
|
|
3145
|
+
code,
|
|
3146
|
+
reason
|
|
3147
|
+
});
|
|
3148
|
+
}
|
|
3149
|
+
};
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3152
|
+
}
|
|
3153
|
+
function socketPath(prefix, service, socket) {
|
|
3154
|
+
return socket.schema.path ?? `${prefix.replace(/\/$/, "")}/${service}/${socket.schema.name}`;
|
|
3155
|
+
}
|
|
3156
|
+
/** The origin a browser saw, so TLS-terminating proxies still pass the same-origin check. */
|
|
3157
|
+
function publicOrigin(request) {
|
|
3158
|
+
const forwarded = (name) => request.headers.get(name)?.split(",")[0]?.trim() || void 0;
|
|
3159
|
+
const url = new URL(request.url);
|
|
3160
|
+
const proto = forwarded("x-forwarded-proto");
|
|
3161
|
+
return `${proto ? `${proto}:` : url.protocol}//${forwarded("x-forwarded-host") ?? url.host}`;
|
|
3162
|
+
}
|
|
3163
|
+
/** Mounts native adapters. Each connection owns its queue and service session. */
|
|
3164
|
+
function mountSockets(app, sockets) {
|
|
3165
|
+
if (!sockets.length) return;
|
|
3166
|
+
app.use(websocket({
|
|
3167
|
+
maxPayloadLength: SOCKET_MAX_BYTES,
|
|
3168
|
+
backpressureLimit: SOCKET_BUFFER_BYTES,
|
|
3169
|
+
closeOnBackpressureLimit: true
|
|
3170
|
+
}));
|
|
3171
|
+
for (const { service, path, definition } of sockets) {
|
|
3172
|
+
const logger = createLogger(`[Brick socket ${service}.${definition.schema.name}]`);
|
|
3173
|
+
const sessions = /* @__PURE__ */ new WeakMap();
|
|
3174
|
+
const connections = /* @__PURE__ */ new WeakMap();
|
|
3175
|
+
const fail = (ws, error) => {
|
|
3176
|
+
if (!(error instanceof SocketDenied)) logger.error({
|
|
3177
|
+
error,
|
|
3178
|
+
service,
|
|
3179
|
+
socket: definition.schema.name
|
|
3180
|
+
});
|
|
3181
|
+
if (ws.readyState !== 1) return;
|
|
3182
|
+
ws.close(error instanceof SocketDenied ? 1008 : 1011, error instanceof SocketDenied ? "Message refused" : "Socket handler failed");
|
|
3183
|
+
};
|
|
3184
|
+
app.ws(path, {
|
|
3185
|
+
async beforeHandle({ request }) {
|
|
3186
|
+
if (sessions.has(request)) return;
|
|
3187
|
+
const origin = request.headers.get("origin");
|
|
3188
|
+
if (origin ? !(definition.allowedOrigins ?? [publicOrigin(request)]).includes(origin) : !definition.allowMissingOrigin) return new Response("Socket origin refused", { status: 403 });
|
|
3189
|
+
try {
|
|
3190
|
+
sessions.set(request, await definition.connect(request));
|
|
3191
|
+
} catch (error) {
|
|
3192
|
+
if (!(error instanceof SocketDenied)) logger.error({
|
|
3193
|
+
error,
|
|
3194
|
+
service,
|
|
3195
|
+
socket: definition.schema.name
|
|
3196
|
+
});
|
|
3197
|
+
return new Response("Socket connection refused", { status: error instanceof SocketDenied ? 403 : 500 });
|
|
3198
|
+
}
|
|
3199
|
+
},
|
|
3200
|
+
async open(ws) {
|
|
3201
|
+
const session = sessions.get(ws.request);
|
|
3202
|
+
if (!session) {
|
|
3203
|
+
ws.close(1011, "Missing socket session");
|
|
3204
|
+
return;
|
|
3205
|
+
}
|
|
3206
|
+
const sender = {
|
|
3207
|
+
get isOpen() {
|
|
3208
|
+
return !state.closed && ws.readyState === 1;
|
|
3209
|
+
},
|
|
3210
|
+
close() {
|
|
3211
|
+
ws.close(1e3, "");
|
|
3212
|
+
},
|
|
3213
|
+
send(event, data) {
|
|
3214
|
+
if (!sender.isOpen) throw new Error("Socket is closed");
|
|
3215
|
+
const schema = Object.hasOwn(definition.output, event) ? definition.output[event] : void 0;
|
|
3216
|
+
if (!schema || !getCompiledCheck(schema).Check(data)) throw new Error("Invalid socket output");
|
|
3217
|
+
const frame = JSON.stringify({
|
|
3218
|
+
event,
|
|
3219
|
+
data
|
|
3220
|
+
});
|
|
3221
|
+
if (new TextEncoder().encode(frame).byteLength > 65536) throw new Error("Socket output too large");
|
|
3222
|
+
if (!getCompiledCheck(schema).Check(JSON.parse(frame).data)) throw new Error("Socket output is not JSON-compatible");
|
|
3223
|
+
if (ws.send(frame) === 0) {
|
|
3224
|
+
ws.close(1013, "Socket buffer full");
|
|
3225
|
+
throw new Error("Socket buffer full");
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
};
|
|
3229
|
+
const state = {
|
|
3230
|
+
session,
|
|
3231
|
+
sender,
|
|
3232
|
+
tail: Promise.resolve(),
|
|
3233
|
+
pending: 0,
|
|
3234
|
+
bytes: 0,
|
|
3235
|
+
closed: false
|
|
3236
|
+
};
|
|
3237
|
+
connections.set(ws.request, state);
|
|
3238
|
+
try {
|
|
3239
|
+
await session.open(sender);
|
|
3240
|
+
} catch (error) {
|
|
3241
|
+
fail(ws, error);
|
|
3242
|
+
}
|
|
3243
|
+
},
|
|
3244
|
+
message(ws, value) {
|
|
3245
|
+
const state = connections.get(ws.request);
|
|
3246
|
+
if (!state || state.closed || ws.readyState !== 1) return;
|
|
3247
|
+
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
|
|
3248
|
+
ws.close(1003, "Only JSON text is supported");
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
3251
|
+
if (typeof value === "string") {
|
|
3252
|
+
ws.close(1007, "Expected JSON envelope");
|
|
3253
|
+
return;
|
|
3254
|
+
}
|
|
3255
|
+
if (!isSocketEnvelope(value)) {
|
|
3256
|
+
ws.close(1008, "Invalid socket envelope");
|
|
3257
|
+
return;
|
|
3258
|
+
}
|
|
3259
|
+
const size = new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
3260
|
+
if (size > 65536) {
|
|
3261
|
+
ws.close(1009, "Message too large");
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
if (state.pending >= 32 || state.bytes + size > 1048576) {
|
|
3265
|
+
ws.close(1013, "Socket queue full");
|
|
3266
|
+
return;
|
|
3267
|
+
}
|
|
3268
|
+
state.pending++;
|
|
3269
|
+
state.bytes += size;
|
|
3270
|
+
state.tail = state.tail.then(async () => {
|
|
3271
|
+
if (state.closed || ws.readyState !== 1) return;
|
|
3272
|
+
await state.session.message(value.event, value.data, state.sender);
|
|
3273
|
+
}).catch((error) => fail(ws, error)).finally(() => {
|
|
3274
|
+
state.pending--;
|
|
3275
|
+
state.bytes -= size;
|
|
3276
|
+
});
|
|
3277
|
+
},
|
|
3278
|
+
async close(ws, code = 1006, reason = "") {
|
|
3279
|
+
const state = connections.get(ws.request);
|
|
3280
|
+
sessions.delete(ws.request);
|
|
3281
|
+
if (!state || state.closed) return;
|
|
3282
|
+
state.closed = true;
|
|
3283
|
+
try {
|
|
3284
|
+
await state.session.close(state.sender, code, reason);
|
|
3285
|
+
} catch (error) {
|
|
3286
|
+
logger.error({
|
|
3287
|
+
error,
|
|
3288
|
+
service,
|
|
3289
|
+
socket: definition.schema.name,
|
|
3290
|
+
phase: "cleanup"
|
|
3291
|
+
});
|
|
3292
|
+
}
|
|
3293
|
+
connections.delete(ws.request);
|
|
3294
|
+
}
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
//#endregion
|
|
3016
3299
|
//#region src/server.ts
|
|
3017
3300
|
/**
|
|
3018
3301
|
* Create the HTTP application: an Elysia app that serves every service's
|
|
@@ -3129,8 +3412,20 @@ function brick(options = {}) {
|
|
|
3129
3412
|
swaggerPath
|
|
3130
3413
|
]) registeredRoutes.set(routeKey("GET", path), false);
|
|
3131
3414
|
if (referencePath !== void 0) registeredRoutes.set(routeKey("GET", referencePath), false);
|
|
3415
|
+
const sockets = services.flatMap((service) => service.listSockets().map((definition) => ({
|
|
3416
|
+
service: service.name,
|
|
3417
|
+
path: socketPath(prefix, service.name, definition),
|
|
3418
|
+
definition
|
|
3419
|
+
})));
|
|
3420
|
+
const socketRoutes = /* @__PURE__ */ new Set();
|
|
3421
|
+
for (const socket of sockets) {
|
|
3422
|
+
const key = routeKey("GET", socket.path);
|
|
3423
|
+
if (registeredRoutes.has(key) || socketRoutes.has(key)) throw new Error(`Brick: duplicate socket route '${socket.path}'`);
|
|
3424
|
+
socketRoutes.add(key);
|
|
3425
|
+
}
|
|
3132
3426
|
const mountRoute = (method, path, handler, plugin = false) => {
|
|
3133
3427
|
const key = routeKey(method, path);
|
|
3428
|
+
if (socketRoutes.has(key)) throw new Error(`Brick: route '${method} ${path}' conflicts with a socket`);
|
|
3134
3429
|
if (registeredRoutes.has(key)) {
|
|
3135
3430
|
if (plugin || registeredRoutes.get(key)) throw new Error(`Brick: duplicate plugin route '${method} ${path}'`);
|
|
3136
3431
|
return false;
|
|
@@ -3200,10 +3495,16 @@ function brick(options = {}) {
|
|
|
3200
3495
|
};
|
|
3201
3496
|
if (mountRoute(route.ir.method, route.ir.path, telemetry ? (context) => traceHttpRequest(context, route.ir.method, route.ir.path, () => invoke(context)) : invoke, getPluginActionRoute(action, prefix) !== void 0)) mountedRoutes.push(route.ir);
|
|
3202
3497
|
}
|
|
3498
|
+
mountSockets(app, sockets);
|
|
3203
3499
|
const definition = Object.freeze({
|
|
3204
3500
|
services: Object.freeze([...services]),
|
|
3205
3501
|
prefix,
|
|
3206
3502
|
routes: Object.freeze(mountedRoutes),
|
|
3503
|
+
sockets: Object.freeze(sockets.map(({ service, path, definition }) => ({
|
|
3504
|
+
...definition.schema,
|
|
3505
|
+
service,
|
|
3506
|
+
path
|
|
3507
|
+
}))),
|
|
3207
3508
|
telemetry,
|
|
3208
3509
|
documentation: normalizeDocumentation(options.documentation),
|
|
3209
3510
|
dashboard,
|
|
@@ -3735,6 +4036,7 @@ var ServiceImpl = class {
|
|
|
3735
4036
|
actions = /* @__PURE__ */ new Map();
|
|
3736
4037
|
tools = /* @__PURE__ */ new Map();
|
|
3737
4038
|
tables = /* @__PURE__ */ new Map();
|
|
4039
|
+
sockets = /* @__PURE__ */ new Map();
|
|
3738
4040
|
resources = /* @__PURE__ */ new Map();
|
|
3739
4041
|
preparations = /* @__PURE__ */ new Map();
|
|
3740
4042
|
database;
|
|
@@ -3827,6 +4129,16 @@ var ServiceImpl = class {
|
|
|
3827
4129
|
getTool(name) {
|
|
3828
4130
|
return this.tools.get(name);
|
|
3829
4131
|
}
|
|
4132
|
+
socket(config) {
|
|
4133
|
+
if (this._isBuilt) throw new Error("Sockets must be declared before service build");
|
|
4134
|
+
if (this.sockets.has(config.name)) throw new Error(`Duplicate socket: ${config.name}`);
|
|
4135
|
+
this.sockets.set(config.name, defineServiceSocket(config, (request) => resolveServiceContext(this, { request })));
|
|
4136
|
+
getGlobalRegistry().touch();
|
|
4137
|
+
return this;
|
|
4138
|
+
}
|
|
4139
|
+
listSockets() {
|
|
4140
|
+
return [...this.sockets.values()];
|
|
4141
|
+
}
|
|
3830
4142
|
listTools() {
|
|
3831
4143
|
return Array.from(this.tools.values());
|
|
3832
4144
|
}
|
|
@@ -3872,6 +4184,7 @@ var ServiceImpl = class {
|
|
|
3872
4184
|
name: this.name,
|
|
3873
4185
|
options,
|
|
3874
4186
|
hasDatabase: Boolean(this.database),
|
|
4187
|
+
sockets: this.listSockets().map((socket) => socket.schema),
|
|
3875
4188
|
databaseConfig,
|
|
3876
4189
|
actions: this.listActions().map((act) => {
|
|
3877
4190
|
const access = getActionAccess(act);
|
|
@@ -4243,6 +4556,6 @@ function createMcpHandler(options) {
|
|
|
4243
4556
|
};
|
|
4244
4557
|
}
|
|
4245
4558
|
//#endregion
|
|
4246
|
-
export { ACTION_ACCESS_KEY, ActionExecutionError, BrickServerError, BrickTransportError, Dispatcher, EventsHub, SecretRef, ServiceImpl, ServiceRegistry, Table, Type, UnknownToolError, ValidationError, and, asc, attachDatabase, bindCompiledApplication, blob, brick, buildErrorHelpers, buildFtsMatchQuery, compileBrickApplication, compileRoutePlan, compilerRuntime, createActionHandler, createBrickClient, createDatabase, createEndpointHandler, createMcpHandler, createMcpRegistry, createPostgresDatabase, createSQLiteDatabase, createServiceProxy, defineAction, defineDatabase, defineListener, defineResource, defineResourcePlugin, defineService, defineServicePlugin, defineTool, desc, emitEvent, emitHandlerFactory, endpointPaths, ensureResourceIndexes, ensureSQLiteFts, envSource, eq, executeCompiledRoute, foreignKey, generateOpenApiSpec, generateSQLiteIndexDdl, generateSQLiteTableDdl, getActionAccess, getCompiledCheck, getGlobalRegistry, getPluginActionRoute, getPluginEndpoints, getTableColumns, getTableName, gt, gte, hoistAnchoredSchemas, ilike, inArray, index, integer, is, isBrickApp, isBrickServerError, isBrickTransportError, isDatabaseHandle, isNotNull, isNull, isOutboxTable, isTool, like, listSecrets, loadCompiledBrickApp, lt, lte, ne, not, notInArray, or, outboxTable, overrideSecret, overrideSecrets, primaryKey, real, referencePlugin, registerReferenceRoute, relations, requestLoggingPlugin, requireBrickApp, resetGlobalRegistry, resetSecrets, resolveEndpointDb, resolveSecrets, resolveWorkflowPaths, runInTransaction, scalarDocsHTML, secret, setActionAccess, sql, sqliteTable, stopAllEvents, swaggerDocsHTML, syncSchema, t, text, toErrorResponse, toOpenApiPath, traceRoute, uniqueIndex, validateWithSchema };
|
|
4559
|
+
export { ACTION_ACCESS_KEY, ActionExecutionError, BrickServerError, BrickTransportError, Dispatcher, EventsHub, SecretRef, ServiceImpl, ServiceRegistry, Table, Type, UnknownToolError, ValidationError, and, asc, attachDatabase, bindCompiledApplication, blob, brick, buildErrorHelpers, buildFtsMatchQuery, compileBrickApplication, compileRoutePlan, compilerRuntime, createActionHandler, createBrickClient, createDatabase, createEndpointHandler, createMcpHandler, createMcpRegistry, createPostgresDatabase, createSQLiteDatabase, createServiceProxy, defineAction, defineDatabase, defineListener, defineResource, defineResourcePlugin, defineService, defineServicePlugin, defineTool, desc, emitEvent, emitHandlerFactory, endpointPaths, ensureResourceIndexes, ensureSQLiteFts, envSource, eq, executeCompiledRoute, foreignKey, generateOpenApiSpec, generateSQLiteIndexDdl, generateSQLiteTableDdl, getActionAccess, getCompiledCheck, getGlobalRegistry, getPluginActionRoute, getPluginEndpoints, getTableColumns, getTableName, gt, gte, hoistAnchoredSchemas, ilike, inArray, index, integer, is, isBrickApp, isBrickServerError, isBrickTransportError, isDatabaseHandle, isNotNull, isNull, isOutboxTable, isTool, like, listSecrets, loadCompiledBrickApp, lt, lte, ne, not, notInArray, onTransactionCommit, or, outboxTable, overrideSecret, overrideSecrets, primaryKey, real, referencePlugin, registerReferenceRoute, relations, requestLoggingPlugin, requireBrickApp, resetGlobalRegistry, resetSecrets, resolveEndpointDb, resolveSecrets, resolveWorkflowPaths, runInTransaction, scalarDocsHTML, secret, serializeSocketSchema, setActionAccess, sql, sqliteTable, stopAllEvents, swaggerDocsHTML, syncSchema, t, text, toErrorResponse, toOpenApiPath, traceRoute, uniqueIndex, validateWithSchema };
|
|
4247
4560
|
|
|
4248
4561
|
//# sourceMappingURL=index.js.map
|