@llmops/core 0.4.8-beta.8 → 0.5.0-beta.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/dist/{bun-sqlite-dialect-CZ9G39Hw.cjs → bun-sqlite-dialect-gGK75m-T.cjs} +1 -1
- package/dist/db/index.cjs +2 -5
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +2 -2
- package/dist/{db-Bsofxq5N.cjs → db-B6s2Fj5e.cjs} +18 -286
- package/dist/{db-BFaJfeYI.mjs → db-DdV835WT.mjs} +17 -267
- package/dist/{index-BvU4Gv3C.d.mts → index-BtZBaB4H.d.cts} +3 -39
- package/dist/{index-BYhMgUES.d.cts → index-DkZvY6Q3.d.mts} +3 -39
- package/dist/index.cjs +19 -6
- package/dist/index.d.cts +95 -46
- package/dist/index.d.mts +95 -46
- package/dist/index.mjs +19 -3
- package/dist/{neon-dialect-C0wJAG1X.cjs → neon-dialect-aLfG_zN7.cjs} +1 -1
- package/dist/{neon-dialect-E2P4iCXQ.cjs → neon-dialect-fjqFddrY.cjs} +1 -1
- package/dist/{node-sqlite-dialect-eD-MKapr.cjs → node-sqlite-dialect-DR6hDh7D.cjs} +1 -1
- package/package.json +2 -3
|
@@ -13915,247 +13915,6 @@ const schemas = {
|
|
|
13915
13915
|
llm_requests: llmRequestsSchema
|
|
13916
13916
|
};
|
|
13917
13917
|
|
|
13918
|
-
//#endregion
|
|
13919
|
-
//#region src/db/schema-sql.ts
|
|
13920
|
-
/**
|
|
13921
|
-
* Idempotent SQL Schema Generator
|
|
13922
|
-
*
|
|
13923
|
-
* Generates fully idempotent PostgreSQL schema SQL that can be run on every
|
|
13924
|
-
* server restart. Works in edge environments (no file system access needed).
|
|
13925
|
-
*
|
|
13926
|
-
* This is the programmatic version of the generate-schema-sql.ts script.
|
|
13927
|
-
*/
|
|
13928
|
-
function toSnakeCase(str) {
|
|
13929
|
-
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
13930
|
-
}
|
|
13931
|
-
function getDefaultValue(fieldType, defaultValue) {
|
|
13932
|
-
if (defaultValue === void 0) return null;
|
|
13933
|
-
if (defaultValue === "now()") return "NOW()";
|
|
13934
|
-
if (typeof defaultValue === "boolean") return defaultValue ? "TRUE" : "FALSE";
|
|
13935
|
-
if (typeof defaultValue === "number") return String(defaultValue);
|
|
13936
|
-
if (typeof defaultValue === "string") {
|
|
13937
|
-
if (defaultValue === "{}") return "'{}'::jsonb";
|
|
13938
|
-
return `'${defaultValue}'`;
|
|
13939
|
-
}
|
|
13940
|
-
return null;
|
|
13941
|
-
}
|
|
13942
|
-
const TYPE_MAPPINGS = {
|
|
13943
|
-
uuid: "UUID",
|
|
13944
|
-
text: "TEXT",
|
|
13945
|
-
integer: "INTEGER",
|
|
13946
|
-
boolean: "BOOLEAN",
|
|
13947
|
-
timestamp: "TIMESTAMP WITH TIME ZONE",
|
|
13948
|
-
jsonb: "JSONB"
|
|
13949
|
-
};
|
|
13950
|
-
/**
|
|
13951
|
-
* Generate idempotent PostgreSQL schema SQL
|
|
13952
|
-
*
|
|
13953
|
-
* @param schemaName - Optional PostgreSQL schema name (e.g., 'llmops').
|
|
13954
|
-
* If not provided, tables are created in the current search_path.
|
|
13955
|
-
* @returns SQL string that can be executed to create/update the schema
|
|
13956
|
-
*/
|
|
13957
|
-
function generatePostgresSchemaSQL(schemaName) {
|
|
13958
|
-
const lines = [];
|
|
13959
|
-
const schemaPrefix = schemaName ? `"${schemaName}".` : "";
|
|
13960
|
-
lines.push(`-- LLMOps Database Schema (PostgreSQL)`);
|
|
13961
|
-
lines.push(`-- This SQL is fully idempotent and safe to run on every server restart.`);
|
|
13962
|
-
lines.push("");
|
|
13963
|
-
if (schemaName) {
|
|
13964
|
-
lines.push(`-- Create schema if not exists`);
|
|
13965
|
-
lines.push(`CREATE SCHEMA IF NOT EXISTS "${schemaName}";`);
|
|
13966
|
-
lines.push("");
|
|
13967
|
-
}
|
|
13968
|
-
lines.push(`-- Enable UUID extension`);
|
|
13969
|
-
lines.push(`CREATE EXTENSION IF NOT EXISTS "pgcrypto" SCHEMA public;`);
|
|
13970
|
-
lines.push("");
|
|
13971
|
-
const sortedTables = Object.entries(SCHEMA_METADATA.tables).map(([name, meta$2]) => ({
|
|
13972
|
-
name,
|
|
13973
|
-
meta: meta$2
|
|
13974
|
-
})).sort((a, b) => a.meta.order - b.meta.order);
|
|
13975
|
-
lines.push(`-- STEP 1: Create tables (if not exist)`);
|
|
13976
|
-
for (const { name, meta: meta$2 } of sortedTables) {
|
|
13977
|
-
const fullTableName = schemaPrefix + toSnakeCase(name);
|
|
13978
|
-
if (!Object.entries(meta$2.fields).find(([_, f]) => f.primaryKey)) continue;
|
|
13979
|
-
lines.push(`CREATE TABLE IF NOT EXISTS ${fullTableName} (`);
|
|
13980
|
-
lines.push(` id UUID PRIMARY KEY DEFAULT gen_random_uuid()`);
|
|
13981
|
-
lines.push(`);`);
|
|
13982
|
-
}
|
|
13983
|
-
lines.push("");
|
|
13984
|
-
lines.push(`-- STEP 2: Add columns (if not exist)`);
|
|
13985
|
-
for (const { name, meta: meta$2 } of sortedTables) {
|
|
13986
|
-
const fullTableName = schemaPrefix + toSnakeCase(name);
|
|
13987
|
-
for (const [columnName, field] of Object.entries(meta$2.fields)) {
|
|
13988
|
-
if (field.primaryKey) continue;
|
|
13989
|
-
const snakeColumn = toSnakeCase(columnName);
|
|
13990
|
-
const sqlType = TYPE_MAPPINGS[field.type] || "TEXT";
|
|
13991
|
-
const defaultVal = getDefaultValue(field.type, field.default);
|
|
13992
|
-
let colDef = `${snakeColumn} ${sqlType}`;
|
|
13993
|
-
if (defaultVal) colDef += ` DEFAULT ${defaultVal}`;
|
|
13994
|
-
lines.push(`ALTER TABLE ${fullTableName} ADD COLUMN IF NOT EXISTS ${colDef};`);
|
|
13995
|
-
}
|
|
13996
|
-
}
|
|
13997
|
-
lines.push("");
|
|
13998
|
-
lines.push(`-- STEP 3: Add unique constraints (if not exist)`);
|
|
13999
|
-
for (const { name, meta: meta$2 } of sortedTables) {
|
|
14000
|
-
const snakeTable = toSnakeCase(name);
|
|
14001
|
-
const fullTableName = schemaPrefix + snakeTable;
|
|
14002
|
-
for (const [columnName, field] of Object.entries(meta$2.fields)) if (field.unique) {
|
|
14003
|
-
const snakeColumn = toSnakeCase(columnName);
|
|
14004
|
-
const constraintName = `uq_${snakeTable}_${snakeColumn}`;
|
|
14005
|
-
lines.push(`DO $$`);
|
|
14006
|
-
lines.push(`BEGIN`);
|
|
14007
|
-
lines.push(` IF NOT EXISTS (`);
|
|
14008
|
-
lines.push(` SELECT 1 FROM pg_constraint WHERE conname = '${constraintName}'`);
|
|
14009
|
-
lines.push(` ) THEN`);
|
|
14010
|
-
lines.push(` ALTER TABLE ${fullTableName} ADD CONSTRAINT ${constraintName} UNIQUE (${snakeColumn});`);
|
|
14011
|
-
lines.push(` END IF;`);
|
|
14012
|
-
lines.push(`END $$;`);
|
|
14013
|
-
}
|
|
14014
|
-
if (meta$2.uniqueConstraints) for (const constraint of meta$2.uniqueConstraints) {
|
|
14015
|
-
const cols = constraint.columns.map(toSnakeCase).join(", ");
|
|
14016
|
-
const constraintName = `uq_${snakeTable}_${constraint.columns.map(toSnakeCase).join("_")}`;
|
|
14017
|
-
lines.push(`DO $$`);
|
|
14018
|
-
lines.push(`BEGIN`);
|
|
14019
|
-
lines.push(` IF NOT EXISTS (`);
|
|
14020
|
-
lines.push(` SELECT 1 FROM pg_constraint WHERE conname = '${constraintName}'`);
|
|
14021
|
-
lines.push(` ) THEN`);
|
|
14022
|
-
lines.push(` ALTER TABLE ${fullTableName} ADD CONSTRAINT ${constraintName} UNIQUE (${cols});`);
|
|
14023
|
-
lines.push(` END IF;`);
|
|
14024
|
-
lines.push(`END $$;`);
|
|
14025
|
-
}
|
|
14026
|
-
}
|
|
14027
|
-
lines.push("");
|
|
14028
|
-
lines.push(`-- STEP 4: Add foreign keys (if not exist)`);
|
|
14029
|
-
for (const { name, meta: meta$2 } of sortedTables) {
|
|
14030
|
-
const snakeTable = toSnakeCase(name);
|
|
14031
|
-
const fullTableName = schemaPrefix + snakeTable;
|
|
14032
|
-
for (const [columnName, field] of Object.entries(meta$2.fields)) if (field.references) {
|
|
14033
|
-
const snakeColumn = toSnakeCase(columnName);
|
|
14034
|
-
const refTable = schemaPrefix + toSnakeCase(field.references.table);
|
|
14035
|
-
const refColumn = toSnakeCase(field.references.column);
|
|
14036
|
-
const constraintName = `fk_${snakeTable}_${snakeColumn}`;
|
|
14037
|
-
lines.push(`DO $$`);
|
|
14038
|
-
lines.push(`BEGIN`);
|
|
14039
|
-
lines.push(` IF NOT EXISTS (`);
|
|
14040
|
-
lines.push(` SELECT 1 FROM pg_constraint WHERE conname = '${constraintName}'`);
|
|
14041
|
-
lines.push(` ) THEN`);
|
|
14042
|
-
lines.push(` ALTER TABLE ${fullTableName} ADD CONSTRAINT ${constraintName}`);
|
|
14043
|
-
lines.push(` FOREIGN KEY (${snakeColumn}) REFERENCES ${refTable}(${refColumn}) ON DELETE CASCADE;`);
|
|
14044
|
-
lines.push(` END IF;`);
|
|
14045
|
-
lines.push(`END $$;`);
|
|
14046
|
-
}
|
|
14047
|
-
}
|
|
14048
|
-
lines.push("");
|
|
14049
|
-
lines.push(`-- STEP 5: Create indexes (if not exist)`);
|
|
14050
|
-
for (const { name, meta: meta$2 } of sortedTables) {
|
|
14051
|
-
const snakeTable = toSnakeCase(name);
|
|
14052
|
-
const fullTableName = schemaPrefix + snakeTable;
|
|
14053
|
-
for (const [columnName, field] of Object.entries(meta$2.fields)) if (field.references) {
|
|
14054
|
-
const snakeColumn = toSnakeCase(columnName);
|
|
14055
|
-
lines.push(`CREATE INDEX IF NOT EXISTS idx_${snakeTable}_${snakeColumn} ON ${fullTableName}(${snakeColumn});`);
|
|
14056
|
-
}
|
|
14057
|
-
}
|
|
14058
|
-
lines.push("");
|
|
14059
|
-
lines.push(`-- STEP 6: Create updated_at triggers`);
|
|
14060
|
-
const functionName = `${schemaName ? `"${schemaName}".` : "public."}update_updated_at_column`;
|
|
14061
|
-
lines.push(`CREATE OR REPLACE FUNCTION ${functionName}()`);
|
|
14062
|
-
lines.push(`RETURNS TRIGGER AS $$`);
|
|
14063
|
-
lines.push(`BEGIN`);
|
|
14064
|
-
lines.push(` NEW.updated_at = NOW();`);
|
|
14065
|
-
lines.push(` RETURN NEW;`);
|
|
14066
|
-
lines.push(`END;`);
|
|
14067
|
-
lines.push(`$$ language 'plpgsql';`);
|
|
14068
|
-
for (const { name } of sortedTables) {
|
|
14069
|
-
const snakeTable = toSnakeCase(name);
|
|
14070
|
-
const fullTableName = schemaPrefix + snakeTable;
|
|
14071
|
-
lines.push(`DROP TRIGGER IF EXISTS update_${snakeTable}_updated_at ON ${fullTableName};`);
|
|
14072
|
-
lines.push(`CREATE TRIGGER update_${snakeTable}_updated_at BEFORE UPDATE ON ${fullTableName} FOR EACH ROW EXECUTE FUNCTION ${functionName}();`);
|
|
14073
|
-
}
|
|
14074
|
-
lines.push("");
|
|
14075
|
-
return lines.join("\n");
|
|
14076
|
-
}
|
|
14077
|
-
/**
|
|
14078
|
-
* Execute the schema SQL using a Neon SQL function
|
|
14079
|
-
*
|
|
14080
|
-
* @param sql - Neon sql function (from `neon()` or passed connection)
|
|
14081
|
-
* @param schemaName - Optional PostgreSQL schema name
|
|
14082
|
-
*/
|
|
14083
|
-
async function runSchemaSQL(sql$1, schemaName) {
|
|
14084
|
-
const statements = splitSQLStatements(generatePostgresSchemaSQL(schemaName));
|
|
14085
|
-
for (let i = 0; i < statements.length; i++) {
|
|
14086
|
-
const trimmed = statements[i].trim();
|
|
14087
|
-
if (trimmed && !trimmed.startsWith("--")) try {
|
|
14088
|
-
await sql$1(trimmed);
|
|
14089
|
-
} catch (error$47) {
|
|
14090
|
-
console.error(`[Schema] Failed at statement ${i + 1}/${statements.length}:`);
|
|
14091
|
-
console.error(`[Schema] Statement preview: ${trimmed.slice(0, 100)}...`);
|
|
14092
|
-
throw error$47;
|
|
14093
|
-
}
|
|
14094
|
-
}
|
|
14095
|
-
}
|
|
14096
|
-
/**
|
|
14097
|
-
* Split SQL into individual statements, keeping $$ blocks together
|
|
14098
|
-
* Handles both DO $$ blocks and CREATE FUNCTION ... AS $$ blocks
|
|
14099
|
-
*/
|
|
14100
|
-
function splitSQLStatements(sql$1) {
|
|
14101
|
-
const statements = [];
|
|
14102
|
-
let current = "";
|
|
14103
|
-
let inDollarBlock = false;
|
|
14104
|
-
const lines = sql$1.split("\n");
|
|
14105
|
-
for (const line of lines) {
|
|
14106
|
-
const trimmed = line.trim();
|
|
14107
|
-
if (!trimmed || trimmed.startsWith("--")) continue;
|
|
14108
|
-
if (!inDollarBlock && (trimmed === "DO $$" || trimmed.endsWith("AS $$"))) {
|
|
14109
|
-
inDollarBlock = true;
|
|
14110
|
-
current += line + "\n";
|
|
14111
|
-
continue;
|
|
14112
|
-
}
|
|
14113
|
-
if (inDollarBlock) {
|
|
14114
|
-
current += line + "\n";
|
|
14115
|
-
if (trimmed.startsWith("$$") && trimmed.endsWith(";")) {
|
|
14116
|
-
statements.push(current.trim());
|
|
14117
|
-
current = "";
|
|
14118
|
-
inDollarBlock = false;
|
|
14119
|
-
}
|
|
14120
|
-
continue;
|
|
14121
|
-
}
|
|
14122
|
-
current += line + "\n";
|
|
14123
|
-
if (trimmed.endsWith(";")) {
|
|
14124
|
-
statements.push(current.trim());
|
|
14125
|
-
current = "";
|
|
14126
|
-
}
|
|
14127
|
-
}
|
|
14128
|
-
if (current.trim()) statements.push(current.trim());
|
|
14129
|
-
return statements;
|
|
14130
|
-
}
|
|
14131
|
-
/**
|
|
14132
|
-
* Create a Neon SQL function from various connection types
|
|
14133
|
-
*
|
|
14134
|
-
* The Neon serverless library returns a tagged template function from neon(),
|
|
14135
|
-
* but for conventional string queries we need to use sql.query() instead.
|
|
14136
|
-
* This helper wraps the neon instance to provide a simple query function.
|
|
14137
|
-
*
|
|
14138
|
-
* @param rawConnection - neon() function, connection string, or undefined (uses env vars)
|
|
14139
|
-
* @returns SQL function that can be used with runSchemaSQL, or null if unable to create
|
|
14140
|
-
*/
|
|
14141
|
-
async function createNeonSqlFunction(rawConnection) {
|
|
14142
|
-
const wrapNeonSql = (sql$1) => {
|
|
14143
|
-
return (query) => sql$1.query(query);
|
|
14144
|
-
};
|
|
14145
|
-
if (typeof rawConnection === "function") {
|
|
14146
|
-
if ("query" in rawConnection && typeof rawConnection.query === "function") return wrapNeonSql(rawConnection);
|
|
14147
|
-
return rawConnection;
|
|
14148
|
-
}
|
|
14149
|
-
if (typeof rawConnection === "string" && rawConnection) {
|
|
14150
|
-
const { neon: neon$1 } = await import("@neondatabase/serverless");
|
|
14151
|
-
return wrapNeonSql(neon$1(rawConnection));
|
|
14152
|
-
}
|
|
14153
|
-
const connectionString = process.env.NEON_CONNECTION_STRING || process.env.NEON_PG_URL || process.env.DATABASE_URL || process.env.POSTGRES_URL || "";
|
|
14154
|
-
if (!connectionString) return null;
|
|
14155
|
-
const { neon } = await import("@neondatabase/serverless");
|
|
14156
|
-
return wrapNeonSql(neon(connectionString));
|
|
14157
|
-
}
|
|
14158
|
-
|
|
14159
13918
|
//#endregion
|
|
14160
13919
|
//#region src/db/validation.ts
|
|
14161
13920
|
/**
|
|
@@ -14569,21 +14328,9 @@ function createDatabase(connection) {
|
|
|
14569
14328
|
return new Kysely({ dialect: connection.dialect });
|
|
14570
14329
|
}
|
|
14571
14330
|
/**
|
|
14572
|
-
*
|
|
14573
|
-
*/
|
|
14574
|
-
function isNeonConnectionString(str) {
|
|
14575
|
-
return str.includes(".neon.tech") || str.includes("neon.tech") || str.includes("@neon-");
|
|
14576
|
-
}
|
|
14577
|
-
/**
|
|
14578
|
-
* Auto-detect database type from connection object or string
|
|
14331
|
+
* Auto-detect database type from connection object
|
|
14579
14332
|
*/
|
|
14580
14333
|
function detectDatabaseType(db) {
|
|
14581
|
-
if (typeof db === "string") {
|
|
14582
|
-
if (isNeonConnectionString(db)) return "neon";
|
|
14583
|
-
if (db.startsWith("postgres://") || db.startsWith("postgresql://")) return "postgres";
|
|
14584
|
-
if (db.startsWith("mysql://")) return "mysql";
|
|
14585
|
-
return null;
|
|
14586
|
-
}
|
|
14587
14334
|
if (!db || typeof db !== "object" && typeof db !== "function") return null;
|
|
14588
14335
|
if ("createDriver" in db) {
|
|
14589
14336
|
if (db instanceof SqliteDialect) return "sqlite";
|
|
@@ -14635,20 +14382,23 @@ async function createDatabaseFromConnection(rawConnection, options) {
|
|
|
14635
14382
|
}
|
|
14636
14383
|
});
|
|
14637
14384
|
break;
|
|
14638
|
-
case "neon":
|
|
14639
|
-
if (
|
|
14640
|
-
const {
|
|
14641
|
-
|
|
14642
|
-
|
|
14385
|
+
case "neon":
|
|
14386
|
+
if (schema && schema !== "public") {
|
|
14387
|
+
const { Pool, neonConfig } = await import("@neondatabase/serverless");
|
|
14388
|
+
const { default: ws } = await import("ws");
|
|
14389
|
+
neonConfig.webSocketConstructor = ws;
|
|
14390
|
+
const connectionString = typeof rawConnection === "string" ? rawConnection : process.env.NEON_PG_URL || "";
|
|
14391
|
+
dialect = new PostgresDialect({
|
|
14392
|
+
pool: new Pool({ connectionString: connectionString.includes("currentSchema") ? connectionString.split("currentSchema=")[1].split("&")[0] === "public" ? connectionString.replace(/currentSchema=[^&]*&?/, "") : connectionString : connectionString }),
|
|
14393
|
+
onCreateConnection: async (connection) => {
|
|
14394
|
+
await connection.executeQuery(CompiledQuery.raw(`SET search_path TO "${schema}"`));
|
|
14395
|
+
}
|
|
14396
|
+
});
|
|
14397
|
+
} else {
|
|
14398
|
+
const { createNeonDialect } = await import("./neon-dialect-Hmo08nUq.mjs");
|
|
14399
|
+
dialect = createNeonDialect(rawConnection);
|
|
14643
14400
|
}
|
|
14644
|
-
const connectionString = typeof rawConnection === "string" && rawConnection || process.env.NEON_CONNECTION_STRING || process.env.NEON_PG_URL || process.env.DATABASE_URL || process.env.POSTGRES_URL || "";
|
|
14645
|
-
if (!connectionString) throw new Error("Neon connection string is required. Pass it directly as the database option or set one of: NEON_CONNECTION_STRING, NEON_PG_URL, DATABASE_URL, POSTGRES_URL");
|
|
14646
|
-
const { neon } = await import("@neondatabase/serverless");
|
|
14647
|
-
const sql$1 = neon(connectionString);
|
|
14648
|
-
const { createNeonDialect } = await import("./neon-dialect-Hmo08nUq.mjs");
|
|
14649
|
-
dialect = createNeonDialect(sql$1);
|
|
14650
14401
|
break;
|
|
14651
|
-
}
|
|
14652
14402
|
case "mssql":
|
|
14653
14403
|
if ("createDriver" in rawConnection) dialect = rawConnection;
|
|
14654
14404
|
break;
|
|
@@ -14657,4 +14407,4 @@ async function createDatabaseFromConnection(rawConnection, options) {
|
|
|
14657
14407
|
}
|
|
14658
14408
|
|
|
14659
14409
|
//#endregion
|
|
14660
|
-
export {
|
|
14410
|
+
export { schemas as A, literal as B, llmRequestsSchema as C, playgroundsSchema as D, playgroundRunsSchema as E, zod_default as F, union as G, object as H, _enum as I, unknown as K, any as L, variantVersionsSchema as M, variantsSchema as N, providerConfigsSchema as O, workspaceSettingsSchema as P, array as R, guardrailConfigsSchema as S, playgroundResultsSchema as T, record as U, number$1 as V, string$1 as W, datasetVersionRecordsSchema as _, matchType as a, environmentSecretsSchema as b, logger as c, validatePartialTableData as d, validateTableData as f, datasetRecordsSchema as g, configsSchema as h, getMigrations$1 as i, targetingRulesSchema as j, providerGuardrailOverridesSchema as k, parsePartialTableData as l, configVariantsSchema as m, createDatabaseFromConnection as n, runAutoMigrations as o, SCHEMA_METADATA as p, detectDatabaseType as r, getAuthClientOptions as s, createDatabase as t, parseTableData as u, datasetVersionsSchema as v, playgroundColumnSchema as w, environmentsSchema as x, datasetsSchema as y, boolean$1 as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ColumnType, Dialect, Generated, Kysely, MssqlDialect, MysqlDialect, PostgresDialect, SqliteDialect } from "kysely";
|
|
2
|
-
import { NeonQueryFunction } from "@neondatabase/serverless";
|
|
3
2
|
import * as zod0 from "zod";
|
|
4
3
|
import { z } from "zod";
|
|
4
|
+
import { NeonQueryFunction } from "@neondatabase/serverless";
|
|
5
5
|
|
|
6
6
|
//#region src/db/schema.d.ts
|
|
7
7
|
declare const configsSchema: z.ZodObject<{
|
|
@@ -1900,42 +1900,6 @@ declare const schemas: {
|
|
|
1900
1900
|
}, z.core.$strip>;
|
|
1901
1901
|
};
|
|
1902
1902
|
//#endregion
|
|
1903
|
-
//#region src/db/schema-sql.d.ts
|
|
1904
|
-
/**
|
|
1905
|
-
* Idempotent SQL Schema Generator
|
|
1906
|
-
*
|
|
1907
|
-
* Generates fully idempotent PostgreSQL schema SQL that can be run on every
|
|
1908
|
-
* server restart. Works in edge environments (no file system access needed).
|
|
1909
|
-
*
|
|
1910
|
-
* This is the programmatic version of the generate-schema-sql.ts script.
|
|
1911
|
-
*/
|
|
1912
|
-
/**
|
|
1913
|
-
* Generate idempotent PostgreSQL schema SQL
|
|
1914
|
-
*
|
|
1915
|
-
* @param schemaName - Optional PostgreSQL schema name (e.g., 'llmops').
|
|
1916
|
-
* If not provided, tables are created in the current search_path.
|
|
1917
|
-
* @returns SQL string that can be executed to create/update the schema
|
|
1918
|
-
*/
|
|
1919
|
-
declare function generatePostgresSchemaSQL(schemaName?: string): string;
|
|
1920
|
-
/**
|
|
1921
|
-
* Execute the schema SQL using a Neon SQL function
|
|
1922
|
-
*
|
|
1923
|
-
* @param sql - Neon sql function (from `neon()` or passed connection)
|
|
1924
|
-
* @param schemaName - Optional PostgreSQL schema name
|
|
1925
|
-
*/
|
|
1926
|
-
declare function runSchemaSQL(sql: (query: string) => Promise<unknown>, schemaName?: string): Promise<void>;
|
|
1927
|
-
/**
|
|
1928
|
-
* Create a Neon SQL function from various connection types
|
|
1929
|
-
*
|
|
1930
|
-
* The Neon serverless library returns a tagged template function from neon(),
|
|
1931
|
-
* but for conventional string queries we need to use sql.query() instead.
|
|
1932
|
-
* This helper wraps the neon instance to provide a simple query function.
|
|
1933
|
-
*
|
|
1934
|
-
* @param rawConnection - neon() function, connection string, or undefined (uses env vars)
|
|
1935
|
-
* @returns SQL function that can be used with runSchemaSQL, or null if unable to create
|
|
1936
|
-
*/
|
|
1937
|
-
declare function createNeonSqlFunction(rawConnection: unknown): Promise<((query: string) => Promise<unknown>) | null>;
|
|
1938
|
-
//#endregion
|
|
1939
1903
|
//#region src/db/validation.d.ts
|
|
1940
1904
|
/**
|
|
1941
1905
|
* Validate data against table schema
|
|
@@ -2982,7 +2946,7 @@ type DatabaseConnection = {
|
|
|
2982
2946
|
*/
|
|
2983
2947
|
declare function createDatabase(connection: DatabaseConnection): Kysely<Database>;
|
|
2984
2948
|
/**
|
|
2985
|
-
* Auto-detect database type from connection object
|
|
2949
|
+
* Auto-detect database type from connection object
|
|
2986
2950
|
*/
|
|
2987
2951
|
declare function detectDatabaseType(db: unknown): DatabaseType | null;
|
|
2988
2952
|
/**
|
|
@@ -2993,4 +2957,4 @@ declare function detectDatabaseType(db: unknown): DatabaseType | null;
|
|
|
2993
2957
|
*/
|
|
2994
2958
|
declare function createDatabaseFromConnection(rawConnection: any, options?: DatabaseOptions): Promise<Kysely<Database> | null>;
|
|
2995
2959
|
//#endregion
|
|
2996
|
-
export {
|
|
2960
|
+
export { SCHEMA_METADATA as $, DatasetsTable as A, variantsSchema as At, LLMRequest as B, Dataset as C, playgroundRunsSchema as Ct, DatasetVersionRecord as D, schemas as Dt, DatasetVersion as E, providerGuardrailOverridesSchema as Et, GuardrailConfig as F, PlaygroundResultsTable as G, Playground as H, GuardrailConfigsTable as I, PlaygroundsTable as J, PlaygroundRun as K, GuardrailResult as L, EnvironmentSecret as M, EnvironmentSecretsTable as N, DatasetVersionRecordsTable as O, targetingRulesSchema as Ot, EnvironmentsTable as P, ProviderGuardrailOverridesTable as Q, GuardrailResults as R, Database as S, playgroundResultsSchema as St, DatasetRecordsTable as T, providerConfigsSchema as Tt, PlaygroundColumn as U, LLMRequestsTable as V, PlaygroundResult as W, ProviderConfigsTable as X, ProviderConfig as Y, ProviderGuardrailOverride as Z, validateTableData as _, environmentSecretsSchema as _t, createDatabaseFromConnection as a, Variant as at, ConfigVariantsTable as b, llmRequestsSchema as bt, executeWithSchema as c, VariantsTable as ct, getMigrations as d, configVariantsSchema as dt, Selectable as et, matchType as f, configsSchema as ft, validatePartialTableData as g, datasetsSchema as gt, parseTableData as h, datasetVersionsSchema as ht, createDatabase as i, Updateable as it, Environment as j, workspaceSettingsSchema as jt, DatasetVersionsTable as k, variantVersionsSchema as kt, MigrationOptions as l, WorkspaceSettings as lt, parsePartialTableData as m, datasetVersionRecordsSchema as mt, DatabaseOptions as n, TargetingRule as nt, detectDatabaseType as o, VariantVersion as ot, runAutoMigrations as p, datasetRecordsSchema as pt, PlaygroundRunsTable as q, DatabaseType as r, TargetingRulesTable as rt, createNeonDialect as s, VariantVersionsTable as st, DatabaseConnection as t, TableName as tt, MigrationResult as u, WorkspaceSettingsTable as ut, Config as v, environmentsSchema as vt, DatasetRecord as w, playgroundsSchema as wt, ConfigsTable as x, playgroundColumnSchema as xt, ConfigVariant as y, guardrailConfigsSchema as yt, Insertable as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ColumnType, Dialect, Generated, Kysely, MssqlDialect, MysqlDialect, PostgresDialect, SqliteDialect } from "kysely";
|
|
2
|
+
import { NeonQueryFunction } from "@neondatabase/serverless";
|
|
2
3
|
import * as zod0 from "zod";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
import { NeonQueryFunction } from "@neondatabase/serverless";
|
|
5
5
|
|
|
6
6
|
//#region src/db/schema.d.ts
|
|
7
7
|
declare const configsSchema: z.ZodObject<{
|
|
@@ -1900,42 +1900,6 @@ declare const schemas: {
|
|
|
1900
1900
|
}, z.core.$strip>;
|
|
1901
1901
|
};
|
|
1902
1902
|
//#endregion
|
|
1903
|
-
//#region src/db/schema-sql.d.ts
|
|
1904
|
-
/**
|
|
1905
|
-
* Idempotent SQL Schema Generator
|
|
1906
|
-
*
|
|
1907
|
-
* Generates fully idempotent PostgreSQL schema SQL that can be run on every
|
|
1908
|
-
* server restart. Works in edge environments (no file system access needed).
|
|
1909
|
-
*
|
|
1910
|
-
* This is the programmatic version of the generate-schema-sql.ts script.
|
|
1911
|
-
*/
|
|
1912
|
-
/**
|
|
1913
|
-
* Generate idempotent PostgreSQL schema SQL
|
|
1914
|
-
*
|
|
1915
|
-
* @param schemaName - Optional PostgreSQL schema name (e.g., 'llmops').
|
|
1916
|
-
* If not provided, tables are created in the current search_path.
|
|
1917
|
-
* @returns SQL string that can be executed to create/update the schema
|
|
1918
|
-
*/
|
|
1919
|
-
declare function generatePostgresSchemaSQL(schemaName?: string): string;
|
|
1920
|
-
/**
|
|
1921
|
-
* Execute the schema SQL using a Neon SQL function
|
|
1922
|
-
*
|
|
1923
|
-
* @param sql - Neon sql function (from `neon()` or passed connection)
|
|
1924
|
-
* @param schemaName - Optional PostgreSQL schema name
|
|
1925
|
-
*/
|
|
1926
|
-
declare function runSchemaSQL(sql: (query: string) => Promise<unknown>, schemaName?: string): Promise<void>;
|
|
1927
|
-
/**
|
|
1928
|
-
* Create a Neon SQL function from various connection types
|
|
1929
|
-
*
|
|
1930
|
-
* The Neon serverless library returns a tagged template function from neon(),
|
|
1931
|
-
* but for conventional string queries we need to use sql.query() instead.
|
|
1932
|
-
* This helper wraps the neon instance to provide a simple query function.
|
|
1933
|
-
*
|
|
1934
|
-
* @param rawConnection - neon() function, connection string, or undefined (uses env vars)
|
|
1935
|
-
* @returns SQL function that can be used with runSchemaSQL, or null if unable to create
|
|
1936
|
-
*/
|
|
1937
|
-
declare function createNeonSqlFunction(rawConnection: unknown): Promise<((query: string) => Promise<unknown>) | null>;
|
|
1938
|
-
//#endregion
|
|
1939
1903
|
//#region src/db/validation.d.ts
|
|
1940
1904
|
/**
|
|
1941
1905
|
* Validate data against table schema
|
|
@@ -2982,7 +2946,7 @@ type DatabaseConnection = {
|
|
|
2982
2946
|
*/
|
|
2983
2947
|
declare function createDatabase(connection: DatabaseConnection): Kysely<Database>;
|
|
2984
2948
|
/**
|
|
2985
|
-
* Auto-detect database type from connection object
|
|
2949
|
+
* Auto-detect database type from connection object
|
|
2986
2950
|
*/
|
|
2987
2951
|
declare function detectDatabaseType(db: unknown): DatabaseType | null;
|
|
2988
2952
|
/**
|
|
@@ -2993,4 +2957,4 @@ declare function detectDatabaseType(db: unknown): DatabaseType | null;
|
|
|
2993
2957
|
*/
|
|
2994
2958
|
declare function createDatabaseFromConnection(rawConnection: any, options?: DatabaseOptions): Promise<Kysely<Database> | null>;
|
|
2995
2959
|
//#endregion
|
|
2996
|
-
export {
|
|
2960
|
+
export { SCHEMA_METADATA as $, DatasetsTable as A, variantsSchema as At, LLMRequest as B, Dataset as C, playgroundRunsSchema as Ct, DatasetVersionRecord as D, schemas as Dt, DatasetVersion as E, providerGuardrailOverridesSchema as Et, GuardrailConfig as F, PlaygroundResultsTable as G, Playground as H, GuardrailConfigsTable as I, PlaygroundsTable as J, PlaygroundRun as K, GuardrailResult as L, EnvironmentSecret as M, EnvironmentSecretsTable as N, DatasetVersionRecordsTable as O, targetingRulesSchema as Ot, EnvironmentsTable as P, ProviderGuardrailOverridesTable as Q, GuardrailResults as R, Database as S, playgroundResultsSchema as St, DatasetRecordsTable as T, providerConfigsSchema as Tt, PlaygroundColumn as U, LLMRequestsTable as V, PlaygroundResult as W, ProviderConfigsTable as X, ProviderConfig as Y, ProviderGuardrailOverride as Z, validateTableData as _, environmentSecretsSchema as _t, createDatabaseFromConnection as a, Variant as at, ConfigVariantsTable as b, llmRequestsSchema as bt, executeWithSchema as c, VariantsTable as ct, getMigrations as d, configVariantsSchema as dt, Selectable as et, matchType as f, configsSchema as ft, validatePartialTableData as g, datasetsSchema as gt, parseTableData as h, datasetVersionsSchema as ht, createDatabase as i, Updateable as it, Environment as j, workspaceSettingsSchema as jt, DatasetVersionsTable as k, variantVersionsSchema as kt, MigrationOptions as l, WorkspaceSettings as lt, parsePartialTableData as m, datasetVersionRecordsSchema as mt, DatabaseOptions as n, TargetingRule as nt, detectDatabaseType as o, VariantVersion as ot, runAutoMigrations as p, datasetRecordsSchema as pt, PlaygroundRunsTable as q, DatabaseType as r, TargetingRulesTable as rt, createNeonDialect as s, VariantVersionsTable as st, DatabaseConnection as t, TableName as tt, MigrationResult as u, WorkspaceSettingsTable as ut, Config as v, environmentsSchema as vt, DatasetRecord as w, playgroundsSchema as wt, ConfigsTable as x, playgroundColumnSchema as xt, ConfigVariant as y, guardrailConfigsSchema as yt, Insertable as z };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_db = require('./db-
|
|
2
|
-
const require_neon_dialect = require('./neon-dialect-
|
|
1
|
+
const require_db = require('./db-B6s2Fj5e.cjs');
|
|
2
|
+
const require_neon_dialect = require('./neon-dialect-fjqFddrY.cjs');
|
|
3
3
|
let __llmops_gateway = require("@llmops/gateway");
|
|
4
4
|
__llmops_gateway = require_db.__toESM(__llmops_gateway);
|
|
5
5
|
let kysely = require("kysely");
|
|
@@ -436,10 +436,26 @@ const variantJsonDataSchema = require_db.object({
|
|
|
436
436
|
|
|
437
437
|
//#endregion
|
|
438
438
|
//#region src/schemas/config.ts
|
|
439
|
+
/**
|
|
440
|
+
* Schema for inline provider configuration
|
|
441
|
+
*/
|
|
442
|
+
const inlineProviderConfigSchema = require_db.object({
|
|
443
|
+
provider: require_db.string().min(1, "Provider is required"),
|
|
444
|
+
slug: require_db.string().min(1, "Slug is required"),
|
|
445
|
+
apiKey: require_db.string().optional(),
|
|
446
|
+
customHost: require_db.string().optional(),
|
|
447
|
+
requestTimeout: require_db.number().optional(),
|
|
448
|
+
forwardHeaders: require_db.array(require_db.string()).optional()
|
|
449
|
+
}).passthrough();
|
|
450
|
+
/**
|
|
451
|
+
* Schema for providers array
|
|
452
|
+
*/
|
|
453
|
+
const providersConfigSchema = require_db.array(inlineProviderConfigSchema).optional();
|
|
439
454
|
const llmopsConfigSchema = require_db.object({
|
|
440
455
|
database: require_db.any(),
|
|
441
456
|
basePath: require_db.string().min(1, "Base path is required and cannot be empty").refine((path) => path.startsWith("/"), "Base path must start with a forward slash"),
|
|
442
|
-
schema: require_db.string().optional().default("llmops")
|
|
457
|
+
schema: require_db.string().optional().default("llmops"),
|
|
458
|
+
providers: providersConfigSchema
|
|
443
459
|
});
|
|
444
460
|
function validateLLMOpsConfig(config) {
|
|
445
461
|
const result = llmopsConfigSchema.safeParse(config);
|
|
@@ -3764,7 +3780,6 @@ exports.createEnvironmentSecretDataLayer = createEnvironmentSecretDataLayer;
|
|
|
3764
3780
|
exports.createGuardrailConfigsDataLayer = createGuardrailConfigsDataLayer;
|
|
3765
3781
|
exports.createLLMRequestsDataLayer = createLLMRequestsDataLayer;
|
|
3766
3782
|
exports.createNeonDialect = require_neon_dialect.createNeonDialect;
|
|
3767
|
-
exports.createNeonSqlFunction = require_db.createNeonSqlFunction;
|
|
3768
3783
|
exports.createPlaygroundDataLayer = createPlaygroundDataLayer;
|
|
3769
3784
|
exports.createPlaygroundResultsDataLayer = createPlaygroundResultsDataLayer;
|
|
3770
3785
|
exports.createPlaygroundRunsDataLayer = createPlaygroundRunsDataLayer;
|
|
@@ -3791,7 +3806,6 @@ Object.defineProperty(exports, 'gateway', {
|
|
|
3791
3806
|
}
|
|
3792
3807
|
});
|
|
3793
3808
|
exports.generateId = generateId;
|
|
3794
|
-
exports.generatePostgresSchemaSQL = require_db.generatePostgresSchemaSQL;
|
|
3795
3809
|
exports.getAuthClientOptions = require_db.getAuthClientOptions;
|
|
3796
3810
|
exports.getDefaultPricingProvider = getDefaultPricingProvider;
|
|
3797
3811
|
exports.getMigrations = require_db.getMigrations;
|
|
@@ -3810,7 +3824,6 @@ exports.playgroundsSchema = require_db.playgroundsSchema;
|
|
|
3810
3824
|
exports.providerConfigsSchema = require_db.providerConfigsSchema;
|
|
3811
3825
|
exports.providerGuardrailOverridesSchema = require_db.providerGuardrailOverridesSchema;
|
|
3812
3826
|
exports.runAutoMigrations = require_db.runAutoMigrations;
|
|
3813
|
-
exports.runSchemaSQL = require_db.runSchemaSQL;
|
|
3814
3827
|
exports.schemas = require_db.schemas;
|
|
3815
3828
|
exports.targetingRulesSchema = require_db.targetingRulesSchema;
|
|
3816
3829
|
exports.validateLLMOpsConfig = validateLLMOpsConfig;
|