@brickkit/core 0.2.0 → 0.2.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 +11 -5
- package/dist/chunks/client.d.ts +28 -16
- package/dist/chunks/client.d.ts.map +1 -1
- package/dist/chunks/client.js +30 -24
- package/dist/chunks/client.js.map +1 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +35 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as ServiceAuthOptions, A as ErrorBuilder, At as resolveSecrets, B as ResourceActions, Bt as primaryKey, C as ActionSchema, Ct as SecretRef, D as CacheOptions, Dt as overrideSecret, E as BaseContext, Et as listSecrets, F as NarrowAuthorizedContext, Ft as blob, G as ResourceListInput, H as ResourceCreateInput, Ht as sqliteTable, I as ProxyOptions, It as createSQLiteDatabase, J as ResourcePlan, K as ResourceListResult, L as RateLimitOptions, Lt as foreignKey, M as InferTableRow, Mt as BrickSQLiteDatabase, N as LifecycleOptions, Nt as BunSQLiteDatabase, O as CompiledRoutePlan, Ot as overrideSecrets, P as Logger, Pt as SQLiteDatabaseConfig, Q as Service, R as ResilienceOptions, Rt as index, S as ActionExecutionError, St as SecretOptions, T as BaseActionConfig, Tt as envSource, U as ResourceHooks, Ut as text, V as ResourceConfig, Vt as real, W as ResourceIdInput, Wt as uniqueIndex, X as ResourceTypeOptions, Y as ResourceRow, Z as ResourceUpdateInput, _ as ActionConfig, _t as isDatabaseHandle, a as
|
|
1
|
+
import { $ as ServiceAuthOptions, A as ErrorBuilder, At as resolveSecrets, B as ResourceActions, Bt as primaryKey, C as ActionSchema, Ct as SecretRef, D as CacheOptions, Dt as overrideSecret, E as BaseContext, Et as listSecrets, F as NarrowAuthorizedContext, Ft as blob, G as ResourceListInput, H as ResourceCreateInput, Ht as sqliteTable, I as ProxyOptions, It as createSQLiteDatabase, J as ResourcePlan, K as ResourceListResult, L as RateLimitOptions, Lt as foreignKey, M as InferTableRow, Mt as BrickSQLiteDatabase, N as LifecycleOptions, Nt as BunSQLiteDatabase, O as CompiledRoutePlan, Ot as overrideSecrets, P as Logger, Pt as SQLiteDatabaseConfig, Q as Service, R as ResilienceOptions, Rt as index, S as ActionExecutionError, St as SecretOptions, T as BaseActionConfig, Tt as envSource, U as ResourceHooks, Ut as text, V as ResourceConfig, Vt as real, W as ResourceIdInput, Wt as uniqueIndex, X as ResourceTypeOptions, Y as ResourceRow, Z as ResourceUpdateInput, _ as ActionConfig, _t as isDatabaseHandle, a as BrickClientOptions, at as ToolAnnotations, b as ActionContext, bt as PostgresDatabaseConfig, c as BrickTransportError, ct as ToolOptions, d as InferActionInput, dt as DatabaseDefinition, et as ServiceOptions, f as InferActionOutput, ft as DatabaseHandle, g as Action, gt as defineDatabase, h as isBrickTransportError, ht as SQLiteDefinition, i as BrickClientAction, it as Tool, j as InferTableInsert, jt as secret, k as DefaultServiceContext, kt as resetSecrets, l as InferActionErrorCodes, lt as ValidationError, m as isBrickServerError, mt as PostgresDefinition, n as BrickCallOptions, nt as StandardErrorMap, o as BrickResourceClient, ot as ToolConfigWithAuthorize, p as createBrickClient, pt as EnvInput, q as ResourceOperationsConfig, r as BrickClient, rt as TelemetryOptions, s as BrickServerError, st as ToolConfigWithoutAuthorize, t as BrickActionCaller, tt as ServiceSchema, u as InferActionFailure, ut as ValidationErrorItem, v as ActionConfigWithAuthorize, vt as DatabaseAdapter, w as ArchitectureSchema, wt as SecretSource, x as ActionErrorDefinition, xt as createPostgresDatabase, y as ActionConfigWithoutAuthorize, yt as PostgresDatabase, z as Resource, zt as integer } from "./chunks/client.js";
|
|
2
2
|
import { Static, TSchema, TSchema as TSchema$1, Type } from "@sinclair/typebox";
|
|
3
3
|
import { TypeCheck } from "@sinclair/typebox/compiler";
|
|
4
4
|
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";
|
|
@@ -216,5 +216,5 @@ interface McpHandlerOptions {
|
|
|
216
216
|
/** Stateless MCP JSON-RPC POST handler. Wrap with the app's authentication. */
|
|
217
217
|
export declare function createMcpHandler(options: McpHandlerOptions): (request: Request, ctx?: Partial<ActionContext>) => Promise<Response>;
|
|
218
218
|
//#endregion
|
|
219
|
-
export { Action, ActionConfig, ActionConfigWithAuthorize, ActionConfigWithoutAuthorize, ActionContext, ActionErrorDefinition, ActionExecutionError, ActionSchema, ArchitectureSchema, BaseActionConfig, BaseContext, type BrickActionCaller, type BrickCallOptions, type BrickClient, type BrickClientOptions, type BrickResourceClient, BrickSQLiteDatabase, BrickServerError, BrickTransportError, type BunSQLiteDatabase, CacheOptions, CompiledRoutePlan, DatabaseAdapter, DatabaseDefinition, DatabaseHandle, DefaultServiceContext, EnvInput, ErrorBuilder, type InferActionErrorCodes, type InferActionFailure, type InferActionInput, type InferActionOutput, InferTableInsert, InferTableRow, LifecycleOptions, Logger, type McpHandlerOptions, type McpRegistry, type McpRegistryOptions, type McpToolDefinition, NarrowAuthorizedContext, type OpenApiGeneratorOptions, PostgresDatabase, PostgresDatabaseConfig, PostgresDefinition, ProxyOptions, RateLimitOptions, ResilienceOptions, Resource, ResourceActions, ResourceConfig, ResourceCreateInput, ResourceHooks, ResourceIdInput, ResourceListInput, ResourceListResult, ResourceOperationsConfig, ResourcePlan, type ResourceReadQueries, ResourceRow, ResourceTypeOptions, ResourceUpdateInput, SQLiteDatabaseConfig, SQLiteDefinition, type SecretOptions, SecretRef, type SecretSource, Service, ServiceAuthOptions, ServiceOptions, ServiceSchema, StandardErrorMap, type Static, type TSchema, Table, TelemetryOptions, Tool, ToolAnnotations, ToolConfigWithAuthorize, ToolConfigWithoutAuthorize, ToolOptions, Type, Type as t, ValidationError, ValidationErrorItem, and, asc, blob, createBrickClient, createPostgresDatabase, createSQLiteDatabase,
|
|
219
|
+
export { Action, ActionConfig, ActionConfigWithAuthorize, ActionConfigWithoutAuthorize, ActionContext, ActionErrorDefinition, ActionExecutionError, ActionSchema, ArchitectureSchema, BaseActionConfig, BaseContext, type BrickActionCaller, type BrickCallOptions, type BrickClient, type BrickClientAction, type BrickClientOptions, type BrickResourceClient, BrickSQLiteDatabase, BrickServerError, BrickTransportError, type BunSQLiteDatabase, CacheOptions, CompiledRoutePlan, DatabaseAdapter, DatabaseDefinition, DatabaseHandle, DefaultServiceContext, EnvInput, ErrorBuilder, type InferActionErrorCodes, type InferActionFailure, type InferActionInput, type InferActionOutput, InferTableInsert, InferTableRow, LifecycleOptions, Logger, type McpHandlerOptions, type McpRegistry, type McpRegistryOptions, type McpToolDefinition, NarrowAuthorizedContext, type OpenApiGeneratorOptions, PostgresDatabase, PostgresDatabaseConfig, PostgresDefinition, ProxyOptions, RateLimitOptions, ResilienceOptions, Resource, ResourceActions, ResourceConfig, ResourceCreateInput, ResourceHooks, ResourceIdInput, ResourceListInput, ResourceListResult, ResourceOperationsConfig, ResourcePlan, type ResourceReadQueries, ResourceRow, ResourceTypeOptions, ResourceUpdateInput, SQLiteDatabaseConfig, SQLiteDefinition, type SecretOptions, SecretRef, type SecretSource, Service, ServiceAuthOptions, ServiceOptions, ServiceSchema, StandardErrorMap, type Static, type TSchema, Table, TelemetryOptions, Tool, ToolAnnotations, ToolConfigWithAuthorize, ToolConfigWithoutAuthorize, ToolOptions, Type, Type as t, ValidationError, ValidationErrorItem, and, asc, blob, createBrickClient, createPostgresDatabase, createSQLiteDatabase, defineDatabase, desc, envSource, eq, foreignKey, getTableColumns, getTableName, gt, gte, ilike, inArray, index, integer, is, isBrickServerError, isBrickTransportError, isDatabaseHandle, isNotNull, isNull, like, listSecrets, lt, lte, ne, not, notInArray, or, overrideSecret, overrideSecrets, primaryKey, real, relations, resetSecrets, resolveSecrets, secret, sql, sqliteTable, text, uniqueIndex };
|
|
220
220
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as isBrickTransportError, i as isBrickServerError, n as BrickTransportError, o as ActionExecutionError, r as createBrickClient, s as ValidationError, t as BrickServerError } from "./chunks/client.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { Type } from "@sinclair/typebox";
|
|
4
4
|
import { TypeCompiler } from "@sinclair/typebox/compiler";
|
|
@@ -1892,9 +1892,12 @@ function generateOpenApiSpec(options = {}) {
|
|
|
1892
1892
|
for (const service of services) {
|
|
1893
1893
|
tagsSet.add(service.name);
|
|
1894
1894
|
for (const action of service.listActions()) {
|
|
1895
|
-
const
|
|
1895
|
+
const routePath = action.config.path ?? `${prefix}/${service.name}/${action.name}`;
|
|
1896
|
+
const method = (action.config.method ?? "POST").toLowerCase();
|
|
1897
|
+
const pathParams = [...routePath.matchAll(/:([^/]+)/g)].map((match) => match[1]);
|
|
1898
|
+
const actionPath = routePath.replace(/:([^/]+)/g, "{$1}");
|
|
1896
1899
|
if (!paths[actionPath]) paths[actionPath] = {};
|
|
1897
|
-
|
|
1900
|
+
if (paths[actionPath][method]) continue;
|
|
1898
1901
|
const hasAuth = Boolean(action.config.authorize);
|
|
1899
1902
|
if (hasAuth) hasAnyAuthorizedAction = true;
|
|
1900
1903
|
const responses = {};
|
|
@@ -1954,44 +1957,41 @@ function generateOpenApiSpec(options = {}) {
|
|
|
1954
1957
|
};
|
|
1955
1958
|
}
|
|
1956
1959
|
responses["500"] = { description: "Internal server error" };
|
|
1957
|
-
const
|
|
1958
|
-
operationId: `${service.name}_${action.name}
|
|
1960
|
+
const operation = {
|
|
1961
|
+
operationId: `${service.name}_${action.name}_${method}`,
|
|
1959
1962
|
summary: `${service.name}.${action.name}`,
|
|
1960
1963
|
description: action.config.description ?? `Execute action '${action.name}' on service '${service.name}'`,
|
|
1961
1964
|
tags: action.config.tags && action.config.tags.length > 0 ? action.config.tags : [service.name],
|
|
1962
1965
|
responses
|
|
1963
1966
|
};
|
|
1964
|
-
|
|
1967
|
+
const inputSchema = action.config.input;
|
|
1968
|
+
const properties = inputSchema?.properties ?? {};
|
|
1969
|
+
const parameters = [...new Set(pathParams)].map((key) => ({
|
|
1970
|
+
name: key,
|
|
1971
|
+
in: "path",
|
|
1965
1972
|
required: true,
|
|
1966
|
-
|
|
1967
|
-
};
|
|
1968
|
-
if (
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
responses
|
|
1977
|
-
};
|
|
1978
|
-
if (action.config.input && typeof action.config.input === "object") {
|
|
1979
|
-
const inputSchema = action.config.input;
|
|
1980
|
-
if (inputSchema.properties) {
|
|
1981
|
-
const parameters = [];
|
|
1982
|
-
const requiredFields = inputSchema.required || [];
|
|
1983
|
-
for (const [key, propSchema] of Object.entries(inputSchema.properties)) parameters.push({
|
|
1984
|
-
name: key,
|
|
1985
|
-
in: "query",
|
|
1986
|
-
required: requiredFields.includes(key),
|
|
1987
|
-
schema: propSchema
|
|
1988
|
-
});
|
|
1989
|
-
if (parameters.length > 0) getOperation.parameters = parameters;
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
if (hasAuth) getOperation.security = [{ bearerAuth: [] }];
|
|
1993
|
-
paths[actionPath].get = getOperation;
|
|
1973
|
+
schema: properties[key] ?? { type: "string" }
|
|
1974
|
+
}));
|
|
1975
|
+
if (method === "get" || method === "delete") for (const [key, schema] of Object.entries(properties)) {
|
|
1976
|
+
if (pathParams.includes(key)) continue;
|
|
1977
|
+
parameters.push({
|
|
1978
|
+
name: key,
|
|
1979
|
+
in: "query",
|
|
1980
|
+
required: inputSchema?.required?.includes(key) ?? false,
|
|
1981
|
+
schema
|
|
1982
|
+
});
|
|
1994
1983
|
}
|
|
1984
|
+
else if (inputSchema) operation.requestBody = {
|
|
1985
|
+
required: true,
|
|
1986
|
+
content: { "application/json": { schema: pathParams.length && inputSchema.properties ? {
|
|
1987
|
+
...inputSchema,
|
|
1988
|
+
properties: Object.fromEntries(Object.entries(properties).filter(([key]) => !pathParams.includes(key))),
|
|
1989
|
+
required: (inputSchema.required ?? []).filter((key) => !pathParams.includes(key))
|
|
1990
|
+
} : inputSchema } }
|
|
1991
|
+
};
|
|
1992
|
+
if (parameters.length) operation.parameters = parameters;
|
|
1993
|
+
if (hasAuth) operation.security = [{ bearerAuth: [] }];
|
|
1994
|
+
paths[actionPath][method] = operation;
|
|
1995
1995
|
}
|
|
1996
1996
|
}
|
|
1997
1997
|
const spec = {
|
|
@@ -2137,6 +2137,6 @@ function createMcpHandler(options) {
|
|
|
2137
2137
|
};
|
|
2138
2138
|
}
|
|
2139
2139
|
//#endregion
|
|
2140
|
-
export { ActionExecutionError, BrickServerError, BrickTransportError, SecretRef, ServiceImpl, ServiceRegistry, Table, Type, Type as t, UnknownToolError, ValidationError, and, asc, attachDatabase, blob, buildErrorHelpers, buildFtsMatchQuery, buildResourcePlan, createBrickClient, createDatabase, createMcpHandler, createMcpRegistry, createPostgresDatabase, createSQLiteDatabase, createServiceProxy, defineAction,
|
|
2140
|
+
export { ActionExecutionError, BrickServerError, BrickTransportError, SecretRef, ServiceImpl, ServiceRegistry, Table, Type, Type as t, UnknownToolError, ValidationError, and, asc, attachDatabase, blob, buildErrorHelpers, buildFtsMatchQuery, buildResourcePlan, createBrickClient, createDatabase, createMcpHandler, createMcpRegistry, createPostgresDatabase, createSQLiteDatabase, createServiceProxy, defineAction, defineDatabase, defineResource, defineService, defineTool, desc, describeResourceReads, ensureResourceIndexes, ensureSQLiteFts, envSource, eq, foreignKey, generateOpenApiSpec, generateSQLiteIndexDdl, generateSQLiteTableDdl, getCompiledCheck, getGlobalRegistry, getTableColumns, getTableName, gt, gte, ilike, inArray, index, integer, is, isBrickServerError, isBrickTransportError, isDatabaseHandle, isNotNull, isNull, isTool, like, listSecrets, lt, lte, ne, not, notInArray, or, overrideSecret, overrideSecrets, prepareResourceReads, prepareResourceWrites, primaryKey, real, relations, resetGlobalRegistry, resetSecrets, resolveSecrets, secret, sql, sqliteTable, syncSchema, text, uniqueIndex, validateWithSchema };
|
|
2141
2141
|
|
|
2142
2142
|
//# sourceMappingURL=index.js.map
|