@palbase/backend 24.0.0 → 24.0.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.
@@ -1,4 +1,4 @@
1
- export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EmbeddingModelRef, f as EnvServiceDatabase, E as EnvTypedDatabase, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RawConstraintDef, n as RowShape, S as SchemaDef, o as SchemaInput, T as TableDef, p as TableInput, q as TxPlan, r as TxTables, s as TypedDB, t as TypedTable, u as TypedTx, v as bigint, w as boolean, x as defineSchema, y as enumType, z as integer, A as isPalbaseExtension, B as jsonb, D as makeTypedDB, G as openai, H as policy, J as raw, K as text, L as timestamp, M as uuid, N as vector } from '../index-D-4-PNuQ.cjs';
1
+ export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EmbeddingModelRef, f as EnvServiceDatabase, E as EnvTypedDatabase, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RawConstraintDef, n as RowShape, S as SchemaDef, o as SchemaInput, T as TableDef, p as TableInput, q as TxPlan, r as TxTables, s as TypedDB, t as TypedTable, u as TypedTx, v as bigint, w as boolean, x as defineSchema, y as enumType, z as integer, A as isPalbaseExtension, B as jsonb, D as makeTypedDB, G as openai, H as policy, J as raw, K as text, L as timestamp, M as uuid, N as vector } from '../index-MoQ31B6M.cjs';
2
2
  export { M as Materialized, b1 as Ref, b3 as TxColumnExpr, b4 as TxInsertShape, b6 as TxNow, T as TxPlanBody, b7 as TxPlanError, b8 as TxPlanHandle, b9 as TxPlanOpResult, ba as TxPlanRejection, g as TxPlanResponse, bb as TxRefError, bc as TxRow, bd as TxRows, be as TxSelectOptions, bf as TxSetShape, bh as TxTable, bi as TxWhere, bs as dec, bu as inc, bv as now } from '../endpoint-CcQ1a36a.cjs';
3
3
  import './env.cjs';
4
4
  import '../stack.cjs';
@@ -1,4 +1,4 @@
1
- export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EmbeddingModelRef, f as EnvServiceDatabase, E as EnvTypedDatabase, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RawConstraintDef, n as RowShape, S as SchemaDef, o as SchemaInput, T as TableDef, p as TableInput, q as TxPlan, r as TxTables, s as TypedDB, t as TypedTable, u as TypedTx, v as bigint, w as boolean, x as defineSchema, y as enumType, z as integer, A as isPalbaseExtension, B as jsonb, D as makeTypedDB, G as openai, H as policy, J as raw, K as text, L as timestamp, M as uuid, N as vector } from '../index-CJiJU9ux.js';
1
+ export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EmbeddingModelRef, f as EnvServiceDatabase, E as EnvTypedDatabase, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RawConstraintDef, n as RowShape, S as SchemaDef, o as SchemaInput, T as TableDef, p as TableInput, q as TxPlan, r as TxTables, s as TypedDB, t as TypedTable, u as TypedTx, v as bigint, w as boolean, x as defineSchema, y as enumType, z as integer, A as isPalbaseExtension, B as jsonb, D as makeTypedDB, G as openai, H as policy, J as raw, K as text, L as timestamp, M as uuid, N as vector } from '../index-BOS_rFBO.js';
2
2
  export { M as Materialized, b1 as Ref, b3 as TxColumnExpr, b4 as TxInsertShape, b6 as TxNow, T as TxPlanBody, b7 as TxPlanError, b8 as TxPlanHandle, b9 as TxPlanOpResult, ba as TxPlanRejection, g as TxPlanResponse, bb as TxRefError, bc as TxRow, bd as TxRows, be as TxSelectOptions, bf as TxSetShape, bh as TxTable, bi as TxWhere, bs as dec, bu as inc, bv as now } from '../endpoint-0_DGBajf.js';
3
3
  import './env.js';
4
4
  import '../stack.js';
package/dist/db/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  timestamp,
18
18
  uuid,
19
19
  vector
20
- } from "../chunk-ZUGY7RGS.js";
20
+ } from "../chunk-LCL7TUAI.js";
21
21
  import {
22
22
  TxPlanError,
23
23
  TxRefError,
@@ -1408,11 +1408,17 @@ function offsetClause(offset, limit) {
1408
1408
  }
1409
1409
  function compileWhere(table, colSet, where, add, caller = "search") {
1410
1410
  const parts = [];
1411
+ const transforms = transformsOf(currentSchema, table);
1412
+ const bindFor = (col) => {
1413
+ const t = transforms.get(col);
1414
+ return t?.toDb === void 0 ? add : (v) => add(v === null || v === void 0 ? v : t.toDb(v));
1415
+ };
1411
1416
  for (const [col, cond] of Object.entries(where)) {
1412
1417
  if (colSet !== null && !colSet.has(col)) {
1413
1418
  throw new Error(`${caller}(${table}): where kolonu "${col}" tabloda yok (FR-016)`);
1414
1419
  }
1415
1420
  const q = `t.${quoteIdent(col)}`;
1421
+ const bind = bindFor(col);
1416
1422
  if (cond !== null && typeof cond === "object" && !Array.isArray(cond)) {
1417
1423
  for (const [op, v] of Object.entries(cond)) {
1418
1424
  if (op === "in") {
@@ -1421,15 +1427,15 @@ function compileWhere(table, colSet, where, add, caller = "search") {
1421
1427
  parts.push("false");
1422
1428
  continue;
1423
1429
  }
1424
- parts.push(`${q} IN (${v.map((x) => add(x)).join(", ")})`);
1430
+ parts.push(`${q} IN (${v.map((x) => bind(x)).join(", ")})`);
1425
1431
  } else if (op in WHERE_OPS) {
1426
- parts.push(`${q} ${WHERE_OPS[op]} ${add(v)}`);
1432
+ parts.push(`${q} ${WHERE_OPS[op]} ${bind(v)}`);
1427
1433
  } else {
1428
1434
  throw new Error(`${caller}(${table}): where.${col} bilinmeyen operat\xF6r "${op}" (gt/gte/lt/lte/neq/in)`);
1429
1435
  }
1430
1436
  }
1431
1437
  } else {
1432
- parts.push(`${q} = ${add(cond)}`);
1438
+ parts.push(`${q} = ${bind(cond)}`);
1433
1439
  }
1434
1440
  }
1435
1441
  return parts.length === 0 ? "" : ` AND ${parts.join(" AND ")}`;
@@ -1628,10 +1634,9 @@ function createOps(tx) {
1628
1634
  */
1629
1635
  async updateMany(table, where, set) {
1630
1636
  const cols = Object.keys(set);
1631
- if (cols.length === 0) return [];
1632
- if (Object.keys(where).length === 0) {
1637
+ if (cols.length === 0) {
1633
1638
  throw new Error(
1634
- `updateMany(${table}): bo\u015F filtre T\xDCM sat\u0131rlar\u0131 g\xFCncellerdi \u2014 bir filtre verin, ya da her sat\u0131ra uyan bir ko\u015Ful yaz\u0131n`
1639
+ `updateMany(${table}): nothing to set. An update with no columns is not a no-op worth pretending happened \u2014 pass the columns to write.`
1635
1640
  );
1636
1641
  }
1637
1642
  const params = [];
@@ -1642,6 +1647,7 @@ function createOps(tx) {
1642
1647
  const assignments = cols.map((c) => `${quoteIdent(c)} = ${add(asBindParams(table, [c], set)[0])}`).join(", ");
1643
1648
  const known = schemaColumns(table);
1644
1649
  const whereSql = compileWhere(table, known, where, add, "updateMany");
1650
+ assertHasPredicate(whereSql, "updateMany", table);
1645
1651
  const sql = `UPDATE ${quoteIdent(table)} AS t SET ${assignments} WHERE true${whereSql} RETURNING *`;
1646
1652
  return asTableRows(table, await (await at()).unsafe(sql, params));
1647
1653
  },
@@ -1651,11 +1657,6 @@ function createOps(tx) {
1651
1657
  * {@link updateMany} — and here the accident is worse.
1652
1658
  */
1653
1659
  async deleteMany(table, where) {
1654
- if (Object.keys(where).length === 0) {
1655
- throw new Error(
1656
- `deleteMany(${table}): bo\u015F filtre T\xDCM sat\u0131rlar\u0131 silerdi \u2014 bir filtre verin, ya da her sat\u0131ra uyan bir ko\u015Ful yaz\u0131n`
1657
- );
1658
- }
1659
1660
  const params = [];
1660
1661
  const add = (v) => {
1661
1662
  params.push(v);
@@ -1663,6 +1664,7 @@ function createOps(tx) {
1663
1664
  };
1664
1665
  const known = schemaColumns(table);
1665
1666
  const whereSql = compileWhere(table, known, where, add, "deleteMany");
1667
+ assertHasPredicate(whereSql, "deleteMany", table);
1666
1668
  const sql = `DELETE FROM ${quoteIdent(table)} AS t WHERE true${whereSql} RETURNING 1`;
1667
1669
  const rows = await (await at()).unsafe(sql, params);
1668
1670
  return rows.length;
@@ -2213,6 +2215,12 @@ function isAbortedTransaction(e) {
2213
2215
  const message = String(e?.message ?? "");
2214
2216
  return sqlstateOf(e) === "25P02" || /current transaction is aborted/i.test(message);
2215
2217
  }
2218
+ function assertHasPredicate(whereSql, op, table) {
2219
+ if (whereSql.trim().length > 0) return;
2220
+ throw new Error(
2221
+ `${op}(${table}): the filter compiled to no condition, so this would have written EVERY row. An empty filter \u2014 or an operator object with no operators in it, like { col: {} } \u2014 is refused. Name a condition.`
2222
+ );
2223
+ }
2216
2224
  function sqlstateOf(e) {
2217
2225
  const err = e;
2218
2226
  const isState = (v) => typeof v === "string" && /^[0-9A-Z]{5}$/.test(v);