@databricks/appkit 0.75.0 → 0.75.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/CLAUDE.md +1 -1
- package/dist/appkit/package.js +1 -1
- package/dist/beta.d.ts +1 -1
- package/dist/beta.js +2 -1
- package/dist/cache/index.js +2 -2
- package/dist/cache/storage/persistent.js +1 -1
- package/dist/connectors/index.js +1 -1
- package/dist/connectors/jobs/client.js +1 -1
- package/dist/connectors/lakebase/index.d.ts +2 -2
- package/dist/connectors/lakebase/index.d.ts.map +1 -1
- package/dist/connectors/lakebase/index.js +25 -2
- package/dist/connectors/lakebase/index.js.map +1 -1
- package/dist/connectors/mcp/client.js +1 -1
- package/dist/connectors/sql-warehouse/client.js +1 -1
- package/dist/context/service-context.js +1 -1
- package/dist/core/appkit.js +1 -1
- package/dist/database/errors.js +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/dev-reader.js +1 -1
- package/dist/plugin/interceptors/retry.js +1 -1
- package/dist/plugin/plugin.js +1 -1
- package/dist/plugins/analytics/analytics.js +1 -1
- package/dist/plugins/analytics/result-delivery.js +1 -1
- package/dist/plugins/beta-exports.generated.d.ts +1 -3
- package/dist/plugins/beta-exports.generated.js +0 -2
- package/dist/plugins/database/config.js +14 -0
- package/dist/plugins/database/config.js.map +1 -0
- package/dist/plugins/database/database.d.ts +22 -5
- package/dist/plugins/database/database.d.ts.map +1 -1
- package/dist/plugins/database/database.js +23 -8
- package/dist/plugins/database/database.js.map +1 -1
- package/dist/plugins/database/lifecycle.js +3 -3
- package/dist/plugins/database/lifecycle.js.map +1 -1
- package/dist/plugins/database/load-schema.js +40 -0
- package/dist/plugins/database/load-schema.js.map +1 -0
- package/dist/plugins/database/manifest.js +1 -1
- package/dist/plugins/database/types.d.ts +12 -3
- package/dist/plugins/database/types.d.ts.map +1 -1
- package/dist/plugins/files/plugin.js +1 -1
- package/dist/plugins/jobs/plugin.js +1 -1
- package/dist/plugins/lakebase/lakebase.js +1 -1
- package/dist/plugins/server/index.js +3 -3
- package/dist/plugins/server/index.js.map +1 -1
- package/dist/plugins/server/remote-tunnel/remote-tunnel-manager.js +3 -3
- package/dist/plugins/server/remote-tunnel/remote-tunnel-manager.js.map +1 -1
- package/dist/plugins/server/static-server.js +3 -3
- package/dist/plugins/server/static-server.js.map +1 -1
- package/dist/plugins/server/utils.js +3 -3
- package/dist/plugins/server/utils.js.map +1 -1
- package/dist/plugins/server/vite-dev-server.js +5 -5
- package/dist/plugins/server/vite-dev-server.js.map +1 -1
- package/dist/registry/manifest-loader.js +1 -1
- package/dist/registry/resource-registry.js +1 -1
- package/dist/stream/arrow-stream-processor.js +1 -1
- package/dist/stream/stream-manager.js +1 -1
- package/dist/type-generator/database/generate.js +3 -3
- package/dist/type-generator/database/generate.js.map +1 -1
- package/dist/type-generator/migration.js +2 -2
- package/dist/type-generator/migration.js.map +1 -1
- package/dist/type-generator/serving/server-file-extractor.js +3 -3
- package/dist/type-generator/serving/server-file-extractor.js.map +1 -1
- package/docs/api/appkit/Function.database.md +30 -29
- package/docs/api/appkit/TypeAlias.IDatabaseConfig.md +8 -6
- package/docs/api/appkit.md +1 -1
- package/docs/plugins/database.md +46 -18
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/sbom.cdx.json +1 -1
package/CLAUDE.md
CHANGED
|
@@ -97,7 +97,7 @@ npx @databricks/appkit docs <query>
|
|
|
97
97
|
- [Function: createLakebasePool()](./docs/api/appkit/Function.createLakebasePool.md): Create a Lakebase pool with appkit's logger integration.
|
|
98
98
|
- [Function: createLakebasePoolManager()](./docs/api/appkit/Function.createLakebasePoolManager.md): Create a pool manager that maintains per-key Lakebase connection pools.
|
|
99
99
|
- [Function: createWorkspaceClient()](./docs/api/appkit/Function.createWorkspaceClient.md): Construct an AppKit workspace client.
|
|
100
|
-
- [Function: database()](./docs/api/appkit/Function.database.md):
|
|
100
|
+
- [Function: database()](./docs/api/appkit/Function.database.md): Call Signature
|
|
101
101
|
- [Function: defineEval()](./docs/api/appkit/Function.defineEval.md): Define an agent eval. Default-export the result from a
|
|
102
102
|
- [Function: defineEvalConfig()](./docs/api/appkit/Function.defineEvalConfig.md): Define per-directory eval config. Default-export from evals.config.ts.
|
|
103
103
|
- [Function: defineManifest()](./docs/api/appkit/Function.defineManifest.md): Validates a raw manifest (typically a manifest.json import) against the
|
package/dist/appkit/package.js
CHANGED
package/dist/beta.d.ts
CHANGED
|
@@ -34,10 +34,10 @@ import { agents } from "./plugins/agents/agents.js";
|
|
|
34
34
|
import "./plugins/agents/index.js";
|
|
35
35
|
import { IAiSearchConfig, IndexConfig, RerankerConfig, SearchFilters, SearchRequest, SearchResponse, SearchResult } from "./plugins/ai-search/types.js";
|
|
36
36
|
import { aiSearch } from "./plugins/ai-search/ai-search.js";
|
|
37
|
+
import "./plugins/beta-exports.generated.js";
|
|
37
38
|
import { DatabaseExports, TransactionClient } from "./plugins/database/entity-types.js";
|
|
38
39
|
import { EntityMutationHooks, HookApp, HookContext } from "./plugins/database/hooks.js";
|
|
39
40
|
import { DatabaseApiConfig, DatabaseApiWriteOperation, DatabaseApiWritesConfig, EntityHooks, IDatabaseConfig, ReadSerializer, ReadSerializerContext } from "./plugins/database/types.js";
|
|
40
41
|
import { database } from "./plugins/database/database.js";
|
|
41
42
|
import "./plugins/database/index.js";
|
|
42
|
-
import "./plugins/beta-exports.generated.js";
|
|
43
43
|
export { type AgentAdapter, type AgentDefinition, type AgentEvent, type AgentInput, type AgentRunContext, type AgentTool, type AgentToolDefinition, type AgentTools, type AgentToolsFn, type AgentsPluginConfig, AppKitMcpClient, AssertionHandle, AssertionResult, Assessment, type AutoInheritToolsConfig, type BaseSystemPromptOption, CustomJudgeSpec, type DatabaseApiConfig, type DatabaseApiWriteOperation, type DatabaseApiWritesConfig, type DatabaseExports, DatabricksAdapter, DatabricksAuth, DatasetRow, DiscoveredEval, DiscoveredEvalConfig, DriveResult, type EntityHooks, type EntityMutationHooks, EvalDefinition, EvalDriver, EvalProgress, EvalResult, EvalRunSummary, EvalSummary, EvalWebServer, type FunctionTool, type GenerationParams, type HookApp, type HookContext, type HostedSupervisorTool, type HostedTool, HttpDriverOptions, type IAiSearchConfig, type IDatabaseConfig, type IndexConfig, JudgeConfig, JudgeScore, MatchResult, Matcher, type McpConnectAllResult, type Message, MlflowClient, type PluginToolkitProvider, type Plugins, PostResult, type PromptContext, ReadEvalDatasetOptions, type ReadSerializer, type ReadSerializerContext, type RegisteredAgent, ReportOutcome, type RerankerConfig, ResolveDatabricksAuthOptions, type ResolvedToolEntry, type RunAgentInput, type RunAgentResult, RunEvalOptions, RunEvalsOptions, SUPERVISOR_EXTENSION_KEY, type Schema, type SearchFilters, type SearchRequest, type SearchResponse, type SearchResult, Severity, SupervisorApiAdapter, type SupervisorApiAdapterOptions, type SupervisorExtension, type SupervisorTool, TestContext, type Thread, type ThreadStore, type ToolAnnotations, type ToolConfig, type ToolEntry, type ToolProvider, type ToolRegistry, type ToolkitEntry, type ToolkitOptions, type TransactionClient, type WorkspaceClientLike, agentIdFromMarkdownPath, agents, aiSearch, bigid, bigint, boolean, buildAssessments, configureJudge, createAgent, createHttpDriver, database, defineEval, defineEvalConfig, defineSchema, defineTool, discoverEvalConfigs, discoverEvalFiles, enumColumn, equals, evalGlyph, executeFromRegistry, findRootEvalConfig, fk, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatResultsJUnit, formatResultsJson, formatSummaryLine, fromSupervisorApi, functionToolToDefinition, id, includes, integer, isFunctionTool, isHostedTool, isJudgeConfigured, isSupervisorTool, isToolkitEntry, jsonb, loadAgentFromFile, loadAgentsFromDir, loadRootEvalConfig, matches, mcpServer, normalizeHost, parseTextToolCalls, readEvalDataset, reportToMlflow, resolveDatabricksAuth, resolveHostedTools, resolveWorkspaceClient, runAgent, runEval, runEvalsInDir, runWithRetries, summarize, supervisorTools, text, timestamp, tool, toolsFromRegistry, userTurns, uuid, varchar };
|
package/dist/beta.js
CHANGED
|
@@ -30,7 +30,8 @@ import { agentIdFromMarkdownPath, loadAgentFromFile, loadAgentsFromDir } from ".
|
|
|
30
30
|
import { agents } from "./plugins/agents/agents.js";
|
|
31
31
|
import "./plugins/agents/index.js";
|
|
32
32
|
import { aiSearch } from "./plugins/ai-search/ai-search.js";
|
|
33
|
-
import { database } from "./plugins/database/database.js";
|
|
34
33
|
import "./plugins/beta-exports.generated.js";
|
|
34
|
+
import { database } from "./plugins/database/database.js";
|
|
35
|
+
import "./plugins/database/index.js";
|
|
35
36
|
|
|
36
37
|
export { AppKitMcpClient, DatabricksAdapter, MlflowClient, SUPERVISOR_EXTENSION_KEY, SupervisorApiAdapter, agentIdFromMarkdownPath, agents, aiSearch, bigid, bigint, boolean, buildAssessments, configureJudge, createAgent, createHttpDriver, database, defineEval, defineEvalConfig, defineSchema, defineTool, discoverEvalConfigs, discoverEvalFiles, enumColumn, equals, evalGlyph, executeFromRegistry, findRootEvalConfig, fk, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatResultsJUnit, formatResultsJson, formatSummaryLine, fromSupervisorApi, functionToolToDefinition, id, includes, integer, isFunctionTool, isHostedTool, isJudgeConfigured, isSupervisorTool, isToolkitEntry, jsonb, loadAgentFromFile, loadAgentsFromDir, loadRootEvalConfig, matches, mcpServer, normalizeHost, parseTextToolCalls, readEvalDataset, reportToMlflow, resolveDatabricksAuth, resolveHostedTools, resolveWorkspaceClient, runAgent, runEval, runEvalsInDir, runWithRetries, summarize, supervisorTools, text, timestamp, tool, toolsFromRegistry, userTurns, uuid, varchar };
|
package/dist/cache/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ApiError } from "../shared/src/workspace-client/errors.js";
|
|
2
2
|
import { createWorkspaceClient } from "../shared/src/workspace-client/factory.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getClientOptions } from "../context/client-options.js";
|
|
4
4
|
import { AppKitError } from "../errors/base.js";
|
|
5
5
|
import { ExecutionError } from "../errors/execution.js";
|
|
6
6
|
import { InitializationError } from "../errors/initialization.js";
|
|
7
7
|
import "../errors/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { createLogger } from "../logging/logger.js";
|
|
9
9
|
import { createLakebasePool } from "../connectors/lakebase/index.js";
|
|
10
10
|
import { TelemetryManager } from "../telemetry/telemetry-manager.js";
|
|
11
11
|
import { SpanStatusCode } from "../telemetry/index.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createLogger } from "../../logging/logger.js";
|
|
2
1
|
import { InitializationError } from "../../errors/initialization.js";
|
|
3
2
|
import { ValidationError } from "../../errors/validation.js";
|
|
4
3
|
import "../../errors/index.js";
|
|
4
|
+
import { createLogger } from "../../logging/logger.js";
|
|
5
5
|
import { lakebaseStorageDefaults } from "./defaults.js";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
|
package/dist/connectors/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createLakebasePoolManager } from "./lakebase/pool-manager.js";
|
|
2
2
|
import { RoutingPool } from "./lakebase/routing-pool.js";
|
|
3
|
-
import { RequestedClaimsPermissionSet, createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup, getWorkspaceClient } from "./lakebase/index.js";
|
|
3
|
+
import { RequestedClaimsPermissionSet, createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup, getWorkspaceClient, initializeLakebasePool } from "./lakebase/index.js";
|
|
4
4
|
import { AiSearchConnector } from "./ai-search/client.js";
|
|
5
5
|
import "./ai-search/index.js";
|
|
6
6
|
import { FILES_MAX_READ_SIZE, SAFE_INLINE_CONTENT_TYPES, contentTypeFromPath, isSafeInlineContentType, isTextContentType, validateCustomContentTypes } from "./files/defaults.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Context } from "../../shared/src/workspace-client/legacy.js";
|
|
2
|
-
import { createLogger } from "../../logging/logger.js";
|
|
3
2
|
import { AppKitError } from "../../errors/base.js";
|
|
4
3
|
import { ExecutionError } from "../../errors/execution.js";
|
|
5
4
|
import "../../errors/index.js";
|
|
5
|
+
import { createLogger } from "../../logging/logger.js";
|
|
6
6
|
import { TelemetryManager } from "../../telemetry/telemetry-manager.js";
|
|
7
7
|
import { SpanKind, SpanStatusCode } from "../../telemetry/index.js";
|
|
8
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LakebasePoolManager, createLakebasePoolManager } from "./pool-manager.js";
|
|
2
2
|
import { LakebasePool } from "./routing-pool.js";
|
|
3
|
-
import { DatabaseCredential, GenerateDatabaseCredentialRequest, LakebasePoolConfig, LakebasePoolConfig as LakebasePoolConfig$1, RequestedClaims, RequestedClaimsPermissionSet, RequestedResource, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup, getWorkspaceClient } from "@databricks/lakebase";
|
|
3
|
+
import { DatabaseCredential, GenerateDatabaseCredentialRequest, LakebasePoolConfig, LakebasePoolConfig as LakebasePoolConfig$1, RequestedClaims, RequestedClaimsPermissionSet, RequestedResource, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup as getUsernameWithApiLookup$1, getWorkspaceClient } from "@databricks/lakebase";
|
|
4
4
|
import { Pool } from "pg";
|
|
5
5
|
|
|
6
6
|
//#region src/connectors/lakebase/index.d.ts
|
|
@@ -13,5 +13,5 @@ import { Pool } from "pg";
|
|
|
13
13
|
*/
|
|
14
14
|
declare function createLakebasePool$1(config?: Partial<LakebasePoolConfig>): Pool;
|
|
15
15
|
//#endregion
|
|
16
|
-
export { type DatabaseCredential, type GenerateDatabaseCredentialRequest, type LakebasePoolConfig$1 as LakebasePoolConfig, type RequestedClaims, RequestedClaimsPermissionSet, type RequestedResource, createLakebasePool$1 as createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup, getWorkspaceClient };
|
|
16
|
+
export { type DatabaseCredential, type GenerateDatabaseCredentialRequest, type LakebasePoolConfig$1 as LakebasePoolConfig, type RequestedClaims, RequestedClaimsPermissionSet, type RequestedResource, createLakebasePool$1 as createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup$1 as getUsernameWithApiLookup, getWorkspaceClient };
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/connectors/lakebase/index.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/connectors/lakebase/index.ts"],"mappings":";;;;;;;;;;AAoBA;;;iBAAgB,oBAAA,CAAmB,MAAA,GAAS,OAAA,CAAQ,kBAAA,IAAsB,IAAA"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { createWorkspaceClient } from "../../shared/src/workspace-client/factory.js";
|
|
2
|
+
import { getClientOptions } from "../../context/client-options.js";
|
|
3
|
+
import { ConfigurationError } from "../../errors/configuration.js";
|
|
4
|
+
import "../../errors/index.js";
|
|
5
|
+
import { ServiceContext } from "../../context/service-context.js";
|
|
1
6
|
import { createLogger } from "../../logging/logger.js";
|
|
2
7
|
import { createLakebasePoolManager } from "./pool-manager.js";
|
|
3
8
|
import { RoutingPool } from "./routing-pool.js";
|
|
4
|
-
import { RequestedClaimsPermissionSet, createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup, getWorkspaceClient } from "@databricks/lakebase";
|
|
9
|
+
import { RequestedClaimsPermissionSet, createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup, getUsernameWithApiLookup as getUsernameWithApiLookup$1, getWorkspaceClient } from "@databricks/lakebase";
|
|
5
10
|
|
|
6
11
|
//#region src/connectors/lakebase/index.ts
|
|
7
12
|
/**
|
|
@@ -17,7 +22,25 @@ function createLakebasePool$1(config) {
|
|
|
17
22
|
...config
|
|
18
23
|
});
|
|
19
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the startup identity and create a pool through the existing Lakebase
|
|
27
|
+
* connector. Explicit clients win over the app's service client; request/OBO
|
|
28
|
+
* context is never selected implicitly. The pool connects lazily on first use.
|
|
29
|
+
*
|
|
30
|
+
* Keep createLakebasePool synchronous for existing callers and OBO pool caches.
|
|
31
|
+
*/
|
|
32
|
+
async function initializeLakebasePool(config = {}) {
|
|
33
|
+
const resolved = { ...config };
|
|
34
|
+
const needsClient = config.password === void 0 || !(config.user || process.env.PGUSER || process.env.DATABRICKS_CLIENT_ID);
|
|
35
|
+
if (!resolved.workspaceClient && needsClient) resolved.workspaceClient = (ServiceContext.isInitialized() ? ServiceContext.get().client : createWorkspaceClient({ clientOptions: getClientOptions() })).toLegacyWorkspaceClient();
|
|
36
|
+
const user = await getUsernameWithApiLookup(resolved);
|
|
37
|
+
if (!user) throw ConfigurationError.invalidConnection("Lakebase", "Could not determine the PostgreSQL user from the current Databricks credentials. Check your authentication or set PGUSER explicitly.");
|
|
38
|
+
return createLakebasePool$1({
|
|
39
|
+
...resolved,
|
|
40
|
+
user
|
|
41
|
+
});
|
|
42
|
+
}
|
|
20
43
|
|
|
21
44
|
//#endregion
|
|
22
|
-
export { RequestedClaimsPermissionSet, createLakebasePool$1 as createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup, getWorkspaceClient };
|
|
45
|
+
export { RequestedClaimsPermissionSet, createLakebasePool$1 as createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup$1 as getUsernameWithApiLookup, getWorkspaceClient, initializeLakebasePool };
|
|
23
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createLakebasePool","createLakebasePoolBase"],"sources":["../../../src/connectors/lakebase/index.ts"],"sourcesContent":["import {\n createLakebasePool as createLakebasePoolBase,\n type LakebasePoolConfig,\n} from \"@databricks/lakebase\";\nimport type { Pool } from \"pg\";\n\nimport { createLogger } from \"../../logging/logger\";\n\n/**\n * Create a Lakebase pool with appkit's logger integration.\n * Telemetry automatically uses appkit's OpenTelemetry configuration via global registry.\n *\n * @param config - Lakebase pool configuration\n * @returns PostgreSQL pool with appkit integration\n */\nexport function createLakebasePool(config?: Partial<LakebasePoolConfig>): Pool {\n return createLakebasePoolBase({\n logger: createLogger(\"connectors:lakebase\"),\n ...config,\n });\n}\n\n// Re-export everything else from lakebase\nexport {\n type DatabaseCredential,\n type GenerateDatabaseCredentialRequest,\n generateDatabaseCredential,\n getLakebaseOrmConfig,\n getLakebasePgConfig,\n getUsernameWithApiLookup,\n getWorkspaceClient,\n type LakebasePoolConfig,\n type RequestedClaims,\n RequestedClaimsPermissionSet,\n type RequestedResource,\n} from \"@databricks/lakebase\";\n\nexport {\n createLakebasePoolManager,\n type LakebasePoolManager,\n} from \"./pool-manager\";\n\nexport { type LakebasePool, RoutingPool } from \"./routing-pool\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["createLakebasePool","createLakebasePoolBase"],"sources":["../../../src/connectors/lakebase/index.ts"],"sourcesContent":["import {\n createLakebasePool as createLakebasePoolBase,\n getUsernameWithApiLookup,\n type LakebasePoolConfig,\n} from \"@databricks/lakebase\";\nimport type { Pool } from \"pg\";\n\nimport { getClientOptions } from \"../../context/client-options\";\nimport { ServiceContext } from \"../../context/service-context\";\nimport { ConfigurationError } from \"../../errors\";\nimport { createLogger } from \"../../logging/logger\";\nimport { createWorkspaceClient } from \"../../workspace-client\";\n\n/**\n * Create a Lakebase pool with appkit's logger integration.\n * Telemetry automatically uses appkit's OpenTelemetry configuration via global registry.\n *\n * @param config - Lakebase pool configuration\n * @returns PostgreSQL pool with appkit integration\n */\nexport function createLakebasePool(config?: Partial<LakebasePoolConfig>): Pool {\n return createLakebasePoolBase({\n logger: createLogger(\"connectors:lakebase\"),\n ...config,\n });\n}\n\n/**\n * Resolve the startup identity and create a pool through the existing Lakebase\n * connector. Explicit clients win over the app's service client; request/OBO\n * context is never selected implicitly. The pool connects lazily on first use.\n *\n * Keep createLakebasePool synchronous for existing callers and OBO pool caches.\n */\nexport async function initializeLakebasePool(\n config: Partial<LakebasePoolConfig> = {},\n): Promise<Pool> {\n const resolved = { ...config };\n // Native password auth with an explicit/environment user needs no Databricks\n // client. Otherwise use one client for both identity lookup and token refresh.\n const needsClient =\n config.password === undefined ||\n !(config.user || process.env.PGUSER || process.env.DATABRICKS_CLIENT_ID);\n if (!resolved.workspaceClient && needsClient) {\n const client = ServiceContext.isInitialized()\n ? ServiceContext.get().client\n : createWorkspaceClient({ clientOptions: getClientOptions() });\n resolved.workspaceClient = client.toLegacyWorkspaceClient();\n }\n const user = await getUsernameWithApiLookup(resolved);\n if (!user) {\n throw ConfigurationError.invalidConnection(\n \"Lakebase\",\n \"Could not determine the PostgreSQL user from the current Databricks credentials. Check your authentication or set PGUSER explicitly.\",\n );\n }\n return createLakebasePool({ ...resolved, user });\n}\n\n// Re-export everything else from lakebase\nexport {\n type DatabaseCredential,\n type GenerateDatabaseCredentialRequest,\n generateDatabaseCredential,\n getLakebaseOrmConfig,\n getLakebasePgConfig,\n getUsernameWithApiLookup,\n getWorkspaceClient,\n type LakebasePoolConfig,\n type RequestedClaims,\n RequestedClaimsPermissionSet,\n type RequestedResource,\n} from \"@databricks/lakebase\";\n\nexport {\n createLakebasePoolManager,\n type LakebasePoolManager,\n} from \"./pool-manager\";\n\nexport { type LakebasePool, RoutingPool } from \"./routing-pool\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,SAAgBA,qBAAmB,QAA4C;AAC7E,QAAOC,mBAAuB;EAC5B,QAAQ,aAAa,sBAAsB;EAC3C,GAAG;EACJ,CAAC;;;;;;;;;AAUJ,eAAsB,uBACpB,SAAsC,EAAE,EACzB;CACf,MAAM,WAAW,EAAE,GAAG,QAAQ;CAG9B,MAAM,cACJ,OAAO,aAAa,UACpB,EAAE,OAAO,QAAQ,QAAQ,IAAI,UAAU,QAAQ,IAAI;AACrD,KAAI,CAAC,SAAS,mBAAmB,YAI/B,UAAS,mBAHM,eAAe,eAAe,GACzC,eAAe,KAAK,CAAC,SACrB,sBAAsB,EAAE,eAAe,kBAAkB,EAAE,CAAC,EAC9B,yBAAyB;CAE7D,MAAM,OAAO,MAAM,yBAAyB,SAAS;AACrD,KAAI,CAAC,KACH,OAAM,mBAAmB,kBACvB,YACA,uIACD;AAEH,QAAOD,qBAAmB;EAAE,GAAG;EAAU;EAAM,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createLogger } from "../../logging/logger.js";
|
|
2
1
|
import { APPKIT_USER_AGENT } from "../../context/client-options.js";
|
|
2
|
+
import { createLogger } from "../../logging/logger.js";
|
|
3
3
|
import { assertResolvedHostSafe, checkMcpUrl } from "./host-policy.js";
|
|
4
4
|
|
|
5
5
|
//#region src/connectors/mcp/client.ts
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Context } from "../../shared/src/workspace-client/legacy.js";
|
|
2
|
-
import { createLogger } from "../../logging/logger.js";
|
|
3
2
|
import { AppKitError } from "../../errors/base.js";
|
|
4
3
|
import { ConfigurationError } from "../../errors/configuration.js";
|
|
5
4
|
import { ConnectionError } from "../../errors/connection.js";
|
|
6
5
|
import { ExecutionError } from "../../errors/execution.js";
|
|
7
6
|
import { ValidationError } from "../../errors/validation.js";
|
|
8
7
|
import "../../errors/index.js";
|
|
8
|
+
import { createLogger } from "../../logging/logger.js";
|
|
9
9
|
import { TelemetryManager } from "../../telemetry/telemetry-manager.js";
|
|
10
10
|
import { SpanKind, SpanStatusCode } from "../../telemetry/index.js";
|
|
11
11
|
import { ArrowStreamProcessor } from "../../stream/arrow-stream-processor.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ConfigError } from "../shared/src/workspace-client/legacy.js";
|
|
2
2
|
import { createWorkspaceClient } from "../shared/src/workspace-client/factory.js";
|
|
3
|
+
import { getClientOptions } from "./client-options.js";
|
|
3
4
|
import { AuthenticationError } from "../errors/authentication.js";
|
|
4
5
|
import { ConfigurationError } from "../errors/configuration.js";
|
|
5
6
|
import { InitializationError } from "../errors/initialization.js";
|
|
6
7
|
import "../errors/index.js";
|
|
7
|
-
import { getClientOptions } from "./client-options.js";
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
|
|
10
10
|
//#region src/context/service-context.ts
|
package/dist/core/appkit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createLogger } from "../logging/logger.js";
|
|
2
1
|
import { version } from "../appkit/package.js";
|
|
3
2
|
import { ServiceContext } from "../context/service-context.js";
|
|
3
|
+
import { createLogger } from "../logging/logger.js";
|
|
4
4
|
import { TelemetryManager } from "../telemetry/telemetry-manager.js";
|
|
5
5
|
import "../telemetry/index.js";
|
|
6
6
|
import { CacheManager } from "../cache/index.js";
|
package/dist/database/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createLogger } from "../logging/logger.js";
|
|
2
1
|
import { AppKitError } from "../errors/base.js";
|
|
3
2
|
import "../errors/index.js";
|
|
3
|
+
import { createLogger } from "../logging/logger.js";
|
|
4
4
|
|
|
5
5
|
//#region src/database/errors.ts
|
|
6
6
|
const logger = createLogger("database");
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isSQLTypeMarker, sql } from "./shared/src/sql/helpers.js";
|
|
2
2
|
import { ApiError } from "./shared/src/workspace-client/errors.js";
|
|
3
3
|
import { createWorkspaceClient } from "./shared/src/workspace-client/factory.js";
|
|
4
|
-
import { createLakebasePoolManager } from "./connectors/lakebase/pool-manager.js";
|
|
5
4
|
import { AppKitError } from "./errors/base.js";
|
|
6
5
|
import { AuthenticationError } from "./errors/authentication.js";
|
|
7
6
|
import { ConfigurationError } from "./errors/configuration.js";
|
|
@@ -13,6 +12,7 @@ import { ServerError } from "./errors/server.js";
|
|
|
13
12
|
import { TunnelError } from "./errors/tunnel.js";
|
|
14
13
|
import { ValidationError } from "./errors/validation.js";
|
|
15
14
|
import "./errors/index.js";
|
|
15
|
+
import { createLakebasePoolManager } from "./connectors/lakebase/pool-manager.js";
|
|
16
16
|
import { getExecutionContext } from "./context/execution-context.js";
|
|
17
17
|
import { RequestedClaimsPermissionSet, createLakebasePool, generateDatabaseCredential, getLakebaseOrmConfig, getLakebasePgConfig, getUsernameWithApiLookup, getWorkspaceClient } from "./connectors/lakebase/index.js";
|
|
18
18
|
import { SeverityNumber, SpanStatusCode } from "./telemetry/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createLogger } from "../logging/logger.js";
|
|
2
1
|
import { TunnelError } from "../errors/tunnel.js";
|
|
3
2
|
import "../errors/index.js";
|
|
3
|
+
import { createLogger } from "../logging/logger.js";
|
|
4
4
|
import { isRemoteTunnelAllowedByEnv } from "../plugins/server/remote-tunnel/gate.js";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
|
package/dist/plugin/plugin.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { camelToKebab } from "../shared/src/naming.js";
|
|
2
|
-
import { createLogger } from "../logging/logger.js";
|
|
3
2
|
import { AppKitError } from "../errors/base.js";
|
|
4
3
|
import { AuthenticationError } from "../errors/authentication.js";
|
|
5
4
|
import "../errors/index.js";
|
|
6
5
|
import { ServiceContext } from "../context/service-context.js";
|
|
6
|
+
import { createLogger } from "../logging/logger.js";
|
|
7
7
|
import { getCurrentUserId, runInUserContext } from "../context/execution-context.js";
|
|
8
8
|
import { normalizeTelemetryOptions } from "../telemetry/config.js";
|
|
9
9
|
import { TelemetryManager } from "../telemetry/telemetry-manager.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { makeResultMessage } from "../../shared/src/sse/analytics.js";
|
|
2
|
-
import { createLogger } from "../../logging/logger.js";
|
|
3
2
|
import { AppKitError } from "../../errors/base.js";
|
|
4
3
|
import { ExecutionError } from "../../errors/execution.js";
|
|
5
4
|
import "../../errors/index.js";
|
|
5
|
+
import { createLogger } from "../../logging/logger.js";
|
|
6
6
|
import { getWarehouseId, getWorkspaceClient } from "../../context/execution-context.js";
|
|
7
7
|
import "../../context/index.js";
|
|
8
8
|
import { Plugin } from "../../plugin/plugin.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createLogger } from "../../logging/logger.js";
|
|
2
1
|
import { ExecutionError } from "../../errors/execution.js";
|
|
3
2
|
import "../../errors/index.js";
|
|
3
|
+
import { createLogger } from "../../logging/logger.js";
|
|
4
4
|
import { Type, tableFromIPC } from "apache-arrow";
|
|
5
5
|
|
|
6
6
|
//#region src/plugins/analytics/result-delivery.ts
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { agents } from "./agents/agents.js";
|
|
2
2
|
import "./agents/index.js";
|
|
3
3
|
import { aiSearch } from "./ai-search/ai-search.js";
|
|
4
|
-
import "./ai-search/index.js";
|
|
5
|
-
import { database } from "./database/database.js";
|
|
6
|
-
import "./database/index.js";
|
|
4
|
+
import "./ai-search/index.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { databaseSetupFailed } from "../../database/errors.js";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/database/config.ts
|
|
4
|
+
/** Reject invalid arguments instead of turning them into the default API. */
|
|
5
|
+
function assertDatabaseConfig(config) {
|
|
6
|
+
if (typeof config !== "object" || config === null || Array.isArray(config)) throw databaseSetupFailed("Expected a database configuration object or no argument.");
|
|
7
|
+
const prototype = Object.getPrototypeOf(config);
|
|
8
|
+
if (prototype !== Object.prototype && prototype !== null) throw databaseSetupFailed("Expected a plain database configuration object.");
|
|
9
|
+
if ("crudRoutes" in config) throw databaseSetupFailed("\"crudRoutes\" was renamed to \"api\". Use api: false to disable generated routes or api: { writes: false } for reads only.");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { assertDatabaseConfig };
|
|
14
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../../../src/plugins/database/config.ts"],"sourcesContent":["import { databaseSetupFailed } from \"../../database/errors\";\n\n/** Reject invalid arguments instead of turning them into the default API. */\nexport function assertDatabaseConfig(config: unknown): void {\n if (typeof config !== \"object\" || config === null || Array.isArray(config)) {\n throw databaseSetupFailed(\n \"Expected a database configuration object or no argument.\",\n );\n }\n const prototype = Object.getPrototypeOf(config);\n if (prototype !== Object.prototype && prototype !== null) {\n throw databaseSetupFailed(\n \"Expected a plain database configuration object.\",\n );\n }\n // Do not silently turn a previous opt-out into the default full API.\n if (\"crudRoutes\" in config) {\n throw databaseSetupFailed(\n '\"crudRoutes\" was renamed to \"api\". Use api: false to disable generated routes or api: { writes: false } for reads only.',\n );\n }\n}\n"],"mappings":";;;;AAGA,SAAgB,qBAAqB,QAAuB;AAC1D,KAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,MAAM,QAAQ,OAAO,CACxE,OAAM,oBACJ,2DACD;CAEH,MAAM,YAAY,OAAO,eAAe,OAAO;AAC/C,KAAI,cAAc,OAAO,aAAa,cAAc,KAClD,OAAM,oBACJ,kDACD;AAGH,KAAI,gBAAgB,OAClB,OAAM,oBACJ,8HACD"}
|
|
@@ -6,12 +6,12 @@ import "../../plugin/index.js";
|
|
|
6
6
|
import { PluginManifest } from "../../registry/types.js";
|
|
7
7
|
import "../../registry/index.js";
|
|
8
8
|
import { DatabaseExports } from "./entity-types.js";
|
|
9
|
-
import { IDatabaseConfig } from "./types.js";
|
|
9
|
+
import { DefaultDatabaseSchema, IDatabaseConfig } from "./types.js";
|
|
10
10
|
import express from "express";
|
|
11
11
|
|
|
12
12
|
//#region src/plugins/database/database.d.ts
|
|
13
13
|
/** Schema-driven database plugin */
|
|
14
|
-
declare class DatabasePlugin<TSchema extends Schema> extends Plugin<IDatabaseConfig<TSchema>> {
|
|
14
|
+
declare class DatabasePlugin<TSchema extends Schema = DefaultDatabaseSchema> extends Plugin<IDatabaseConfig<TSchema>> {
|
|
15
15
|
/** Plugin metadata and required PostgreSQL resource. */
|
|
16
16
|
static manifest: PluginManifest<"database">;
|
|
17
17
|
protected config: IDatabaseConfig<TSchema>;
|
|
@@ -20,7 +20,8 @@ declare class DatabasePlugin<TSchema extends Schema> extends Plugin<IDatabaseCon
|
|
|
20
20
|
private draining;
|
|
21
21
|
private shutdownPromise;
|
|
22
22
|
private exposure;
|
|
23
|
-
|
|
23
|
+
private resolvedSchema;
|
|
24
|
+
constructor(config?: IDatabaseConfig<TSchema>);
|
|
24
25
|
/** Build and verify one candidate state before publishing its exports. */
|
|
25
26
|
setup(): Promise<void>;
|
|
26
27
|
/** Register generated CRUD, subject to the configured table and write restrictions. */
|
|
@@ -34,12 +35,28 @@ declare class DatabasePlugin<TSchema extends Schema> extends Plugin<IDatabaseCon
|
|
|
34
35
|
/** Trace one generated route with allowlisted, low-cardinality attributes. */
|
|
35
36
|
private runRouteSpan;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
declare function database<TSchema extends Schema>(config: IDatabaseConfig<TSchema>): {
|
|
38
|
+
type DatabaseRegistration<TSchema extends Schema> = {
|
|
39
39
|
plugin: PluginConstructor<BasePluginConfig, DatabasePlugin<TSchema>>;
|
|
40
40
|
config: IDatabaseConfig<TSchema>;
|
|
41
41
|
name: "database";
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Create the database plugin. Omit configuration to load
|
|
45
|
+
* `config/database/schema.ts`, or supply a typed schema override.
|
|
46
|
+
*/
|
|
47
|
+
declare function database<TSchema extends Schema>(config: IDatabaseConfig<TSchema> & {
|
|
48
|
+
readonly schema: TSchema;
|
|
49
|
+
}): DatabaseRegistration<TSchema> & {
|
|
50
|
+
config: IDatabaseConfig<TSchema> & {
|
|
51
|
+
readonly schema: TSchema;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Register the database plugin with opinionated defaults and full HTTP CRUD.
|
|
56
|
+
* By default, setup loads the named `schema` export from the application's
|
|
57
|
+
* `config/database/schema.ts`. Registration itself performs no file or database I/O.
|
|
58
|
+
*/
|
|
59
|
+
declare function database<TSchema extends Schema = DefaultDatabaseSchema>(config?: IDatabaseConfig<TSchema>): DatabaseRegistration<TSchema>;
|
|
43
60
|
//#endregion
|
|
44
61
|
export { database };
|
|
45
62
|
//# sourceMappingURL=database.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","names":[],"sources":["../../../src/plugins/database/database.ts"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"database.d.ts","names":[],"sources":["../../../src/plugins/database/database.ts"],"mappings":";;;;;;;;;;;;;cAoCa,cAAA,iBACK,MAAA,GAAS,qBAAA,UACjB,MAAA,CAAO,eAAA,CAAgB,OAAA;;SAExB,QAAA,EAAuB,cAAA;EAAA,UACZ,MAAA,EAAQ,eAAA,CAAgB,OAAA;EAAA,QAClC,KAAA;EAAA,QACA,YAAA;EAAA,QACA,QAAA;EAAA,QACA,eAAA;EAAA,QACA,QAAA;EAAA,QACA,cAAA;cAEI,MAAA,GAAQ,eAAA,CAAgB,OAAA;EATN;EAoBxB,KAAA,CAAA,GAAS,OAAA;EAnBW;EAoE1B,YAAA,CAAa,MAAA,EAAQ,OAAA,CAAQ,MAAA;EA5DT;EAAA,QA6HZ,KAAA;EAjEa;EAsErB,OAAA,CAAA,GAOO,eAAA;EAIW;EAAZ,QAAA,CAAA,GAAY,OAAA;EAxJJ;EAAA,QA4KN,YAAA;AAAA;AAAA,KA8BL,oBAAA,iBAAqC,MAAA;EACxC,MAAA,EAAQ,iBAAA,CAAkB,gBAAA,EAAkB,cAAA,CAAe,OAAA;EAC3D,MAAA,EAAQ,eAAA,CAAgB,OAAA;EACxB,IAAA;AAAA;;;;;iBAOc,QAAA,iBAAyB,MAAA,CAAA,CACvC,MAAA,EAAQ,eAAA,CAAgB,OAAA;EAAA,SAAsB,MAAA,EAAQ,OAAA;AAAA,IACrD,oBAAA,CAAqB,OAAA;EACtB,MAAA,EAAQ,eAAA,CAAgB,OAAA;IAAA,SAAsB,MAAA,EAAQ,OAAA;EAAA;AAAA;;;;;;iBAOxC,QAAA,iBAAyB,MAAA,GAAS,qBAAA,CAAA,CAChD,MAAA,GAAS,eAAA,CAAgB,OAAA,IACxB,oBAAA,CAAqB,OAAA"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Plugin } from "../../plugin/plugin.js";
|
|
2
2
|
import "../../plugin/index.js";
|
|
3
|
+
import { assertFinalizedSchema } from "../../database/schema-builder/define-schema.js";
|
|
3
4
|
import { DatabasePluginError, databaseSetupFailed } from "../../database/errors.js";
|
|
5
|
+
import { assertDatabaseConfig } from "./config.js";
|
|
4
6
|
import { compileCrudTables } from "./crud/contract.js";
|
|
5
7
|
import { resolveCrudExposure } from "./crud/exposure.js";
|
|
6
8
|
import { routeOutcome } from "./crud/response.js";
|
|
7
9
|
import { createCreateHandler, createDeleteHandler, createDetailHandler, createListHandler, createUpdateHandler } from "./crud/routes.js";
|
|
8
10
|
import { createDatabaseState } from "./lifecycle.js";
|
|
11
|
+
import { loadDefaultDatabaseSchema } from "./load-schema.js";
|
|
9
12
|
import manifest_default from "./manifest.js";
|
|
10
13
|
|
|
11
14
|
//#region src/plugins/database/database.ts
|
|
@@ -21,9 +24,10 @@ var DatabasePlugin = class extends Plugin {
|
|
|
21
24
|
tables: [],
|
|
22
25
|
writes: /* @__PURE__ */ new Map()
|
|
23
26
|
};
|
|
24
|
-
|
|
27
|
+
resolvedSchema = null;
|
|
28
|
+
constructor(config = {}) {
|
|
29
|
+
assertDatabaseConfig(config);
|
|
25
30
|
super({ schema: config.schema });
|
|
26
|
-
if ("crudRoutes" in config) throw databaseSetupFailed("\"crudRoutes\" was renamed to \"api\". Use api: false to disable generated routes or api: { writes: false } for reads only.");
|
|
27
31
|
this.config = {
|
|
28
32
|
schema: config.schema,
|
|
29
33
|
api: config.api,
|
|
@@ -34,14 +38,23 @@ var DatabasePlugin = class extends Plugin {
|
|
|
34
38
|
async setup() {
|
|
35
39
|
if (this.draining || this.state) throw databaseSetupFailed();
|
|
36
40
|
if (!this.setupPromise) this.setupPromise = (async () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
const schema = this.config.schema === void 0 ? await loadDefaultDatabaseSchema() : this.config.schema;
|
|
42
|
+
try {
|
|
43
|
+
assertFinalizedSchema(schema);
|
|
44
|
+
} catch {
|
|
45
|
+
throw databaseSetupFailed("schema must be a finalized AppKit schema created with defineSchema().");
|
|
46
|
+
}
|
|
47
|
+
if (this.draining) throw databaseSetupFailed();
|
|
48
|
+
const exposure = resolveCrudExposure(this.config.api, Object.keys(schema.$tables));
|
|
49
|
+
for (const name of Object.keys(this.hooks() ?? {})) if (!Object.hasOwn(schema.$tables, name)) throw databaseSetupFailed(`hooks names undeclared table ${JSON.stringify(name)}. Use a table declared in schema.`);
|
|
50
|
+
const candidate = await createDatabaseState(schema, (operation, options) => this.execute(operation, options), this.hooks());
|
|
40
51
|
if (this.draining) {
|
|
41
52
|
candidate.deactivate();
|
|
42
53
|
await candidate.pool.end().catch(() => void 0);
|
|
43
54
|
throw databaseSetupFailed();
|
|
44
55
|
}
|
|
56
|
+
this.resolvedSchema = schema;
|
|
57
|
+
this.exposure = exposure;
|
|
45
58
|
this.state = candidate;
|
|
46
59
|
})();
|
|
47
60
|
return this.setupPromise;
|
|
@@ -49,7 +62,9 @@ var DatabasePlugin = class extends Plugin {
|
|
|
49
62
|
/** Register generated CRUD, subject to the configured table and write restrictions. */
|
|
50
63
|
injectRoutes(router) {
|
|
51
64
|
if (this.exposure.tables.length === 0) return;
|
|
52
|
-
const
|
|
65
|
+
const schema = this.resolvedSchema;
|
|
66
|
+
if (!schema) throw databaseSetupFailed();
|
|
67
|
+
const tables = compileCrudTables(Object.fromEntries(this.exposure.tables.map((name) => [name, schema.$tables[name]])));
|
|
53
68
|
const hooks = this.hooks();
|
|
54
69
|
const entities = () => this.exports();
|
|
55
70
|
for (const table of tables.values()) {
|
|
@@ -138,8 +153,8 @@ var DatabasePlugin = class extends Plugin {
|
|
|
138
153
|
});
|
|
139
154
|
}
|
|
140
155
|
};
|
|
141
|
-
|
|
142
|
-
|
|
156
|
+
function database(config = {}) {
|
|
157
|
+
assertDatabaseConfig(config);
|
|
143
158
|
return {
|
|
144
159
|
plugin: DatabasePlugin,
|
|
145
160
|
config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","names":["manifest"],"sources":["../../../src/plugins/database/database.ts"],"sourcesContent":["import type express from \"express\";\nimport type { BasePluginConfig, PluginConstructor } from \"shared\";\n\nimport {\n DatabasePluginError,\n databaseSetupFailed,\n} from \"../../database/errors\";\nimport type { Schema } from \"../../database/schema-builder\";\nimport { Plugin } from \"../../plugin\";\nimport type { PluginManifest } from \"../../registry\";\nimport { compileCrudTables } from \"./crud/contract\";\nimport { type CrudExposure, resolveCrudExposure } from \"./crud/exposure\";\nimport { routeOutcome } from \"./crud/response\";\nimport {\n type CrudEntity,\n type CrudOperation,\n type CrudRouteDeps,\n createCreateHandler,\n createDeleteHandler,\n createDetailHandler,\n createListHandler,\n createUpdateHandler,\n} from \"./crud/routes\";\nimport type { DatabaseExports } from \"./entity-types\";\nimport { createDatabaseState, type DatabaseState } from \"./lifecycle\";\nimport manifest from \"./manifest.json\";\nimport type { DatabaseHooks, IDatabaseConfig } from \"./types\";\n\n/** Schema-driven database plugin */\nexport class DatabasePlugin<TSchema extends Schema> extends Plugin<\n IDatabaseConfig<TSchema>\n> {\n /** Plugin metadata and required PostgreSQL resource. */\n static manifest = manifest as PluginManifest<\"database\">;\n declare protected config: IDatabaseConfig<TSchema>;\n private state: DatabaseState | null = null;\n private setupPromise: Promise<void> | null = null;\n private draining = false;\n private shutdownPromise: Promise<void> | null = null;\n private exposure: CrudExposure = { tables: [], writes: new Map() };\n\n constructor(config: IDatabaseConfig<TSchema>) {\n super({ schema: config.schema });\n // Do not silently turn a previous opt-out into the default full API.\n if (\"crudRoutes\" in config) {\n throw databaseSetupFailed(\n '\"crudRoutes\" was renamed to \"api\". Use api: false to disable generated routes or api: { writes: false } for reads only.',\n );\n }\n this.config = {\n schema: config.schema,\n api: config.api,\n hooks: config.hooks,\n };\n }\n\n /** Build and verify one candidate state before publishing its exports. */\n async setup(): Promise<void> {\n if (this.draining || this.state) throw databaseSetupFailed();\n if (!this.setupPromise) {\n const attempt = (async () => {\n this.exposure = resolveCrudExposure(\n this.config.api,\n Object.keys(this.config.schema.$tables),\n );\n // A hook key naming no declared table would silently never run.\n for (const name of Object.keys(this.hooks() ?? {})) {\n if (!Object.hasOwn(this.config.schema.$tables, name)) {\n throw databaseSetupFailed(\n `hooks names undeclared table ${JSON.stringify(name)}. Use a table declared in schema.`,\n );\n }\n }\n const candidate = await createDatabaseState(\n this.config.schema,\n (operation, options) => this.execute(operation, options),\n this.hooks(),\n );\n if (this.draining) {\n // Setup may finish while shutdown is waiting; never publish that state.\n candidate.deactivate();\n await candidate.pool.end().catch(() => undefined);\n throw databaseSetupFailed();\n }\n this.state = candidate;\n })();\n this.setupPromise = attempt;\n }\n return this.setupPromise;\n }\n\n /** Register generated CRUD, subject to the configured table and write restrictions. */\n injectRoutes(router: express.Router): void {\n if (this.exposure.tables.length === 0) return;\n const tables = compileCrudTables(\n Object.fromEntries(\n this.exposure.tables.map((name) => [\n name,\n this.config.schema.$tables[name],\n ]),\n ),\n );\n const hooks = this.hooks();\n // Every exposed name is a declared table, so its export is an entity client.\n const entities = () =>\n this.exports() as unknown as Record<string, CrudEntity>;\n\n for (const table of tables.values()) {\n const deps: CrudRouteDeps = {\n table,\n entity: () => entities()[table.name],\n serialize: hooks?.[table.name]?.serialize,\n runRouteSpan: (operation, route, run) =>\n this.runRouteSpan(table.name, operation, route, run),\n };\n this.route(router, {\n name: `${table.name}.list`,\n method: \"get\",\n path: `/${table.name}`,\n handler: createListHandler(deps),\n });\n const writes = this.exposure.writes.get(table.name);\n if (writes?.has(\"create\")) {\n this.route(router, {\n name: `${table.name}.create`,\n method: \"post\",\n path: `/${table.name}`,\n handler: createCreateHandler(deps),\n });\n }\n // Addressing one row needs a public key.\n if (!table.primaryKey) continue;\n this.route(router, {\n name: `${table.name}.detail`,\n method: \"get\",\n path: `/${table.name}/:id`,\n handler: createDetailHandler(deps),\n });\n if (writes?.has(\"update\")) {\n this.route(router, {\n name: `${table.name}.update`,\n method: \"patch\",\n path: `/${table.name}/:id`,\n handler: createUpdateHandler(deps),\n });\n }\n if (writes?.has(\"delete\")) {\n this.route(router, {\n name: `${table.name}.delete`,\n method: \"delete\",\n path: `/${table.name}/:id`,\n handler: createDeleteHandler(deps),\n });\n }\n }\n }\n\n /** Typed hook keys are schema table names, which routing addresses at runtime. */\n private hooks(): DatabaseHooks | undefined {\n return this.config.hooks as DatabaseHooks | undefined;\n }\n\n /** Return the typed database API only while the plugin is active. */\n exports() {\n if (!this.state || this.draining)\n throw new DatabasePluginError(\"INTERNAL\", \"read\");\n // AppKit binds exported functions onto this object on every access.\n return Object.assign(\n Object.create(null),\n this.state.exports,\n ) as DatabaseExports;\n }\n\n /** Stop new work, wait for setup, and close the owned pool exactly once. */\n async shutdown(): Promise<void> {\n if (this.shutdownPromise) return this.shutdownPromise;\n this.draining = true;\n this.shutdownPromise = (async () => {\n await this.setupPromise?.catch(() => undefined);\n const state = this.state;\n state?.deactivate();\n this.state = null;\n if (state) {\n try {\n await state.pool.end();\n } catch {\n throw new DatabasePluginError(\"INTERNAL\", \"shutdown\");\n }\n }\n })();\n return this.shutdownPromise;\n }\n\n /** Trace one generated route with allowlisted, low-cardinality attributes. */\n private runRouteSpan(\n table: string,\n operation: CrudOperation,\n route: string,\n run: () => Promise<void>,\n ): Promise<void> {\n return this.telemetry.startActiveSpan(\n \"database.crud.route\",\n {\n attributes: {\n table_name: table,\n operation,\n \"http.route\": `/api/${this.name}${route}`,\n },\n },\n async (span) => {\n try {\n await run();\n span.setAttribute(\"outcome\", \"success\");\n } catch (error) {\n span.setAttribute(\"outcome\", routeOutcome(error));\n throw error;\n } finally {\n span.end();\n }\n },\n );\n }\n}\n\n/** Create a typed database plugin registration for a finalized schema. */\nexport function database<TSchema extends Schema>(\n config: IDatabaseConfig<TSchema>,\n) {\n return {\n plugin: DatabasePlugin as unknown as PluginConstructor<\n BasePluginConfig,\n DatabasePlugin<TSchema>\n >,\n config,\n name: \"database\" as const,\n };\n}\n"],"mappings":";;;;;;;;;;;;AA6BA,IAAa,iBAAb,cAA4D,OAE1D;;CAEA,OAAO,WAAWA;CAElB,AAAQ,QAA8B;CACtC,AAAQ,eAAqC;CAC7C,AAAQ,WAAW;CACnB,AAAQ,kBAAwC;CAChD,AAAQ,WAAyB;EAAE,QAAQ,EAAE;EAAE,wBAAQ,IAAI,KAAK;EAAE;CAElE,YAAY,QAAkC;AAC5C,QAAM,EAAE,QAAQ,OAAO,QAAQ,CAAC;AAEhC,MAAI,gBAAgB,OAClB,OAAM,oBACJ,8HACD;AAEH,OAAK,SAAS;GACZ,QAAQ,OAAO;GACf,KAAK,OAAO;GACZ,OAAO,OAAO;GACf;;;CAIH,MAAM,QAAuB;AAC3B,MAAI,KAAK,YAAY,KAAK,MAAO,OAAM,qBAAqB;AAC5D,MAAI,CAAC,KAAK,aA2BR,MAAK,gBA1BY,YAAY;AAC3B,QAAK,WAAW,oBACd,KAAK,OAAO,KACZ,OAAO,KAAK,KAAK,OAAO,OAAO,QAAQ,CACxC;AAED,QAAK,MAAM,QAAQ,OAAO,KAAK,KAAK,OAAO,IAAI,EAAE,CAAC,CAChD,KAAI,CAAC,OAAO,OAAO,KAAK,OAAO,OAAO,SAAS,KAAK,CAClD,OAAM,oBACJ,gCAAgC,KAAK,UAAU,KAAK,CAAC,mCACtD;GAGL,MAAM,YAAY,MAAM,oBACtB,KAAK,OAAO,SAC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.js","names":["manifest"],"sources":["../../../src/plugins/database/database.ts"],"sourcesContent":["import type express from \"express\";\nimport type { BasePluginConfig, PluginConstructor } from \"shared\";\n\nimport {\n DatabasePluginError,\n databaseSetupFailed,\n} from \"../../database/errors\";\nimport type { Schema } from \"../../database/schema-builder\";\nimport { assertFinalizedSchema } from \"../../database/schema-builder/define-schema\";\nimport { Plugin } from \"../../plugin\";\nimport type { PluginManifest } from \"../../registry\";\nimport { assertDatabaseConfig } from \"./config\";\nimport { compileCrudTables } from \"./crud/contract\";\nimport { type CrudExposure, resolveCrudExposure } from \"./crud/exposure\";\nimport { routeOutcome } from \"./crud/response\";\nimport {\n type CrudEntity,\n type CrudOperation,\n type CrudRouteDeps,\n createCreateHandler,\n createDeleteHandler,\n createDetailHandler,\n createListHandler,\n createUpdateHandler,\n} from \"./crud/routes\";\nimport type { DatabaseExports } from \"./entity-types\";\nimport { createDatabaseState, type DatabaseState } from \"./lifecycle\";\nimport { loadDefaultDatabaseSchema } from \"./load-schema\";\nimport manifest from \"./manifest.json\";\nimport type {\n DatabaseHooks,\n DefaultDatabaseSchema,\n IDatabaseConfig,\n} from \"./types\";\n\n/** Schema-driven database plugin */\nexport class DatabasePlugin<\n TSchema extends Schema = DefaultDatabaseSchema,\n> extends Plugin<IDatabaseConfig<TSchema>> {\n /** Plugin metadata and required PostgreSQL resource. */\n static manifest = manifest as PluginManifest<\"database\">;\n declare protected config: IDatabaseConfig<TSchema>;\n private state: DatabaseState | null = null;\n private setupPromise: Promise<void> | null = null;\n private draining = false;\n private shutdownPromise: Promise<void> | null = null;\n private exposure: CrudExposure = { tables: [], writes: new Map() };\n private resolvedSchema: Schema | null = null;\n\n constructor(config: IDatabaseConfig<TSchema> = {}) {\n assertDatabaseConfig(config);\n super({ schema: config.schema });\n this.config = {\n schema: config.schema,\n api: config.api,\n hooks: config.hooks,\n };\n }\n\n /** Build and verify one candidate state before publishing its exports. */\n async setup(): Promise<void> {\n if (this.draining || this.state) throw databaseSetupFailed();\n if (!this.setupPromise) {\n const attempt = (async () => {\n const schema =\n this.config.schema === undefined\n ? await loadDefaultDatabaseSchema()\n : this.config.schema;\n try {\n assertFinalizedSchema(schema);\n } catch {\n throw databaseSetupFailed(\n \"schema must be a finalized AppKit schema created with defineSchema().\",\n );\n }\n if (this.draining) throw databaseSetupFailed();\n const exposure = resolveCrudExposure(\n this.config.api,\n Object.keys(schema.$tables),\n );\n // A hook key naming no declared table would silently never run.\n for (const name of Object.keys(this.hooks() ?? {})) {\n if (!Object.hasOwn(schema.$tables, name)) {\n throw databaseSetupFailed(\n `hooks names undeclared table ${JSON.stringify(name)}. Use a table declared in schema.`,\n );\n }\n }\n const candidate = await createDatabaseState(\n schema,\n (operation, options) => this.execute(operation, options),\n this.hooks(),\n );\n if (this.draining) {\n // Setup may finish while shutdown is waiting; never publish that state.\n candidate.deactivate();\n await candidate.pool.end().catch(() => undefined);\n throw databaseSetupFailed();\n }\n this.resolvedSchema = schema;\n this.exposure = exposure;\n this.state = candidate;\n })();\n this.setupPromise = attempt;\n }\n return this.setupPromise;\n }\n\n /** Register generated CRUD, subject to the configured table and write restrictions. */\n injectRoutes(router: express.Router): void {\n if (this.exposure.tables.length === 0) return;\n const schema = this.resolvedSchema;\n if (!schema) throw databaseSetupFailed();\n const tables = compileCrudTables(\n Object.fromEntries(\n this.exposure.tables.map((name) => [name, schema.$tables[name]]),\n ),\n );\n const hooks = this.hooks();\n // Every exposed name is a declared table, so its export is an entity client.\n const entities = () =>\n this.exports() as unknown as Record<string, CrudEntity>;\n\n for (const table of tables.values()) {\n const deps: CrudRouteDeps = {\n table,\n entity: () => entities()[table.name],\n serialize: hooks?.[table.name]?.serialize,\n runRouteSpan: (operation, route, run) =>\n this.runRouteSpan(table.name, operation, route, run),\n };\n this.route(router, {\n name: `${table.name}.list`,\n method: \"get\",\n path: `/${table.name}`,\n handler: createListHandler(deps),\n });\n const writes = this.exposure.writes.get(table.name);\n if (writes?.has(\"create\")) {\n this.route(router, {\n name: `${table.name}.create`,\n method: \"post\",\n path: `/${table.name}`,\n handler: createCreateHandler(deps),\n });\n }\n // Addressing one row needs a public key.\n if (!table.primaryKey) continue;\n this.route(router, {\n name: `${table.name}.detail`,\n method: \"get\",\n path: `/${table.name}/:id`,\n handler: createDetailHandler(deps),\n });\n if (writes?.has(\"update\")) {\n this.route(router, {\n name: `${table.name}.update`,\n method: \"patch\",\n path: `/${table.name}/:id`,\n handler: createUpdateHandler(deps),\n });\n }\n if (writes?.has(\"delete\")) {\n this.route(router, {\n name: `${table.name}.delete`,\n method: \"delete\",\n path: `/${table.name}/:id`,\n handler: createDeleteHandler(deps),\n });\n }\n }\n }\n\n /** Typed hook keys are schema table names, which routing addresses at runtime. */\n private hooks(): DatabaseHooks | undefined {\n return this.config.hooks as DatabaseHooks | undefined;\n }\n\n /** Return the typed database API only while the plugin is active. */\n exports() {\n if (!this.state || this.draining)\n throw new DatabasePluginError(\"INTERNAL\", \"read\");\n // AppKit binds exported functions onto this object on every access.\n return Object.assign(\n Object.create(null),\n this.state.exports,\n ) as DatabaseExports;\n }\n\n /** Stop new work, wait for setup, and close the owned pool exactly once. */\n async shutdown(): Promise<void> {\n if (this.shutdownPromise) return this.shutdownPromise;\n this.draining = true;\n this.shutdownPromise = (async () => {\n await this.setupPromise?.catch(() => undefined);\n const state = this.state;\n state?.deactivate();\n this.state = null;\n if (state) {\n try {\n await state.pool.end();\n } catch {\n throw new DatabasePluginError(\"INTERNAL\", \"shutdown\");\n }\n }\n })();\n return this.shutdownPromise;\n }\n\n /** Trace one generated route with allowlisted, low-cardinality attributes. */\n private runRouteSpan(\n table: string,\n operation: CrudOperation,\n route: string,\n run: () => Promise<void>,\n ): Promise<void> {\n return this.telemetry.startActiveSpan(\n \"database.crud.route\",\n {\n attributes: {\n table_name: table,\n operation,\n \"http.route\": `/api/${this.name}${route}`,\n },\n },\n async (span) => {\n try {\n await run();\n span.setAttribute(\"outcome\", \"success\");\n } catch (error) {\n span.setAttribute(\"outcome\", routeOutcome(error));\n throw error;\n } finally {\n span.end();\n }\n },\n );\n }\n}\n\ntype DatabaseRegistration<TSchema extends Schema> = {\n plugin: PluginConstructor<BasePluginConfig, DatabasePlugin<TSchema>>;\n config: IDatabaseConfig<TSchema>;\n name: \"database\";\n};\n\n/**\n * Create the database plugin. Omit configuration to load\n * `config/database/schema.ts`, or supply a typed schema override.\n */\nexport function database<TSchema extends Schema>(\n config: IDatabaseConfig<TSchema> & { readonly schema: TSchema },\n): DatabaseRegistration<TSchema> & {\n config: IDatabaseConfig<TSchema> & { readonly schema: TSchema };\n};\n/**\n * Register the database plugin with opinionated defaults and full HTTP CRUD.\n * By default, setup loads the named `schema` export from the application's\n * `config/database/schema.ts`. Registration itself performs no file or database I/O.\n */\nexport function database<TSchema extends Schema = DefaultDatabaseSchema>(\n config?: IDatabaseConfig<TSchema>,\n): DatabaseRegistration<TSchema>;\nexport function database<TSchema extends Schema = DefaultDatabaseSchema>(\n config: IDatabaseConfig<TSchema> = {},\n): DatabaseRegistration<TSchema> {\n assertDatabaseConfig(config);\n return {\n plugin: DatabasePlugin as unknown as PluginConstructor<\n BasePluginConfig,\n DatabasePlugin<TSchema>\n >,\n config,\n name: \"database\" as const,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoCA,IAAa,iBAAb,cAEU,OAAiC;;CAEzC,OAAO,WAAWA;CAElB,AAAQ,QAA8B;CACtC,AAAQ,eAAqC;CAC7C,AAAQ,WAAW;CACnB,AAAQ,kBAAwC;CAChD,AAAQ,WAAyB;EAAE,QAAQ,EAAE;EAAE,wBAAQ,IAAI,KAAK;EAAE;CAClE,AAAQ,iBAAgC;CAExC,YAAY,SAAmC,EAAE,EAAE;AACjD,uBAAqB,OAAO;AAC5B,QAAM,EAAE,QAAQ,OAAO,QAAQ,CAAC;AAChC,OAAK,SAAS;GACZ,QAAQ,OAAO;GACf,KAAK,OAAO;GACZ,OAAO,OAAO;GACf;;;CAIH,MAAM,QAAuB;AAC3B,MAAI,KAAK,YAAY,K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AAClC,SAAM,KAAK,cAAc,YAAY,OAAU;GAC/C,MAAM,QAAQ,KAAK;AACnB,UAAO,YAAY;AACnB,QAAK,QAAQ;AACb,OAAI,MACF,KAAI;AACF,UAAM,MAAM,KAAK,KAAK;WAChB;AACN,UAAM,IAAI,oBAAoB,YAAY,WAAW;;MAGvD;AACJ,SAAO,KAAK;;;CAId,AAAQ,aACN,OACA,WACA,OACA,KACe;AACf,SAAO,KAAK,UAAU,gBACpB,uBACA,EACE,YAAY;GACV,YAAY;GACZ;GACA,cAAc,QAAQ,KAAK,OAAO;GACnC,EACF,EACD,OAAO,SAAS;AACd,OAAI;AACF,UAAM,KAAK;AACX,SAAK,aAAa,WAAW,UAAU;YAChC,OAAO;AACd,SAAK,aAAa,WAAW,aAAa,MAAM,CAAC;AACjD,UAAM;aACE;AACR,SAAK,KAAK;;IAGf;;;AA2BL,SAAgB,SACd,SAAmC,EAAE,EACN;AAC/B,sBAAqB,OAAO;AAC5B,QAAO;EACL,QAAQ;EAIR;EACA,MAAM;EACP"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createLogger } from "../../logging/logger.js";
|
|
2
1
|
import { DatabaseValidationError } from "../../errors/database-validation.js";
|
|
3
2
|
import "../../errors/index.js";
|
|
4
|
-
import {
|
|
3
|
+
import { createLogger } from "../../logging/logger.js";
|
|
4
|
+
import { initializeLakebasePool } from "../../connectors/lakebase/index.js";
|
|
5
5
|
import { assertFinalizedSchema } from "../../database/schema-builder/define-schema.js";
|
|
6
6
|
import { DatabasePluginError, classifyDatabaseError } from "../../database/errors.js";
|
|
7
7
|
import { IDLE_IN_TRANSACTION_TIMEOUT_MS, STATEMENT_TIMEOUT_MS, TRANSACTION_TIMEOUT_MS } from "./defaults.js";
|
|
@@ -112,7 +112,7 @@ async function createDatabaseState(schema, execute, hooks) {
|
|
|
112
112
|
if (!active) throw new DatabasePluginError("INTERNAL", "runtime");
|
|
113
113
|
};
|
|
114
114
|
try {
|
|
115
|
-
pool =
|
|
115
|
+
pool = await initializeLakebasePool({
|
|
116
116
|
statement_timeout: STATEMENT_TIMEOUT_MS,
|
|
117
117
|
idle_in_transaction_session_timeout: IDLE_IN_TRANSACTION_TIMEOUT_MS
|
|
118
118
|
});
|