@vibeorm/sql 2.3.0 → 2.3.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 +1 @@
1
- {"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/dialects/mysql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,eAAO,MAAM,YAAY,EAAE,UA4F1B,CAAC"}
1
+ {"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/dialects/mysql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD,eAAO,MAAM,YAAY,EAAE,UA4F1B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/dialects/postgres.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,eAAO,MAAM,eAAe,EAAE,UA0F7B,CAAC"}
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/dialects/postgres.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD,eAAO,MAAM,eAAe,EAAE,UA0F7B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/dialects/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,eAAO,MAAM,aAAa,EAAE,UAuF3B,CAAC"}
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/dialects/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD,eAAO,MAAM,aAAa,EAAE,UAuF3B,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Identifier hygiene shared by every dialect's `quoteIdent`.
3
+ *
4
+ * Quoting doubles the quote character, which is the whole grammar for every
5
+ * other byte — except NUL: C-string servers stop reading an identifier at the
6
+ * first NUL, so `"users\0x"` would address `users`, and a quoted identifier
7
+ * containing one is not an identifier at all. Refused at render time, the
8
+ * earliest point every path (IR, raw `sql.ident`, extension DDL) shares.
9
+ */
10
+ /** Return `name` unchanged, or throw `VIBE_VALIDATION` when it contains a NUL. */
11
+ export declare function assertNoNul(params: {
12
+ name: string;
13
+ }): string;
14
+ //# sourceMappingURL=identifiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAS5D"}
package/dist/index.js CHANGED
@@ -1188,6 +1188,19 @@ import {
1188
1188
  MYSQL_CAPABILITIES
1189
1189
  } from "@vibeorm/schema";
1190
1190
 
1191
+ // packages/sql/src/identifiers.ts
1192
+ import { VibeError as VibeError6 } from "@vibeorm/schema";
1193
+ function assertNoNul(params) {
1194
+ if (params.name.includes("\x00")) {
1195
+ throw new VibeError6({
1196
+ code: "VIBE_VALIDATION",
1197
+ message: "an SQL identifier cannot contain a NUL character \u2014 the server would stop reading it there and address a different object",
1198
+ meta: { name: params.name.replaceAll("\x00", "\\0") }
1199
+ });
1200
+ }
1201
+ return params.name;
1202
+ }
1203
+
1191
1204
  // packages/sql/src/dialects/postgres.ts
1192
1205
  var postgresDialect = {
1193
1206
  name: "postgres",
@@ -1243,7 +1256,7 @@ var postgresDialect = {
1243
1256
  paramBudget: 30000,
1244
1257
  booleanLiteral: { true: "true", false: "false" },
1245
1258
  quoteIdent({ name }) {
1246
- return `"${name.replaceAll('"', '""')}"`;
1259
+ return `"${assertNoNul({ name }).replaceAll('"', '""')}"`;
1247
1260
  },
1248
1261
  quoteStringLiteral({ value }) {
1249
1262
  return `'${value.replaceAll("'", "''")}'`;
@@ -1294,7 +1307,7 @@ var sqliteDialect = {
1294
1307
  paramBudget: 900,
1295
1308
  booleanLiteral: { true: "1", false: "0" },
1296
1309
  quoteIdent({ name }) {
1297
- return `"${name.replaceAll('"', '""')}"`;
1310
+ return `"${assertNoNul({ name }).replaceAll('"', '""')}"`;
1298
1311
  },
1299
1312
  quoteStringLiteral({ value }) {
1300
1313
  return `'${value.replaceAll("'", "''")}'`;
@@ -1349,7 +1362,7 @@ var mysqlDialect = {
1349
1362
  paramBudget: 1e4,
1350
1363
  booleanLiteral: { true: "1", false: "0" },
1351
1364
  quoteIdent({ name }) {
1352
- return `\`${name.replaceAll("`", "``")}\``;
1365
+ return `\`${assertNoNul({ name }).replaceAll("`", "``")}\``;
1353
1366
  },
1354
1367
  quoteStringLiteral({ value }) {
1355
1368
  return `'${value.replaceAll("\\", "\\\\").replaceAll("'", "''")}'`;
@@ -1390,7 +1403,7 @@ function isFixedDiagnostic(params) {
1390
1403
  }
1391
1404
 
1392
1405
  // packages/sql/src/dialects/postgres-diagnostics.ts
1393
- import { VibeError as VibeError6, unsupportedCapability as unsupportedCapability6 } from "@vibeorm/schema";
1406
+ import { VibeError as VibeError7, unsupportedCapability as unsupportedCapability6 } from "@vibeorm/schema";
1394
1407
  function renderPostgresExplain(params) {
1395
1408
  const { dialect, query, options } = params;
1396
1409
  requirePostgres({ dialect, feature: "query plan inspection (EXPLAIN)" });
@@ -1443,7 +1456,7 @@ function renderPostgresWorkload(params) {
1443
1456
  if (query === "statementSnapshot") {
1444
1457
  const bounded = limit ?? 20;
1445
1458
  if (!Number.isInteger(bounded) || bounded < POSTGRES_WORKLOAD_LIMITS.minLimit || bounded > POSTGRES_WORKLOAD_LIMITS.maxLimit) {
1446
- throw new VibeError6({
1459
+ throw new VibeError7({
1447
1460
  code: "VIBE_CONFIG",
1448
1461
  message: `workload snapshot limit must be an integer between ${POSTGRES_WORKLOAD_LIMITS.minLimit} and ${POSTGRES_WORKLOAD_LIMITS.maxLimit}, got ${String(limit)}`,
1449
1462
  meta: { limit }
@@ -1462,7 +1475,7 @@ function renderPostgresWorkload(params) {
1462
1475
  function requireArg(params) {
1463
1476
  const { value, name, query } = params;
1464
1477
  if (value === undefined || value.length === 0) {
1465
- throw new VibeError6({
1478
+ throw new VibeError7({
1466
1479
  code: "VIBE_CONFIG",
1467
1480
  message: `the "${query}" diagnostic read requires a ${name}`,
1468
1481
  meta: { query, argument: name }
@@ -1475,7 +1488,7 @@ function requireArg(params) {
1475
1488
  import { unsupportedCapability as unsupportedCapability8 } from "@vibeorm/schema";
1476
1489
 
1477
1490
  // packages/sql/src/dialects/postgres-rls.ts
1478
- import { RlsContextError, VibeError as VibeError7, assertValidSchemaIR, unsupportedCapability as unsupportedCapability7, validateRlsContextIR } from "@vibeorm/schema";
1491
+ import { RlsContextError, VibeError as VibeError8, assertValidSchemaIR, unsupportedCapability as unsupportedCapability7, validateRlsContextIR } from "@vibeorm/schema";
1479
1492
  var NATIVE_RLS = Object.freeze({ policyName: "vibeorm_managed", tableSchema: "public", settingPrefix: "vibeorm.", parentAlias: "parent" });
1480
1493
  var COLUMN_TYPES = {
1481
1494
  String: { default: "text", native: { text: "text", varchar: "varchar", charactervarying: "varchar", uuid: "uuid" } },
@@ -1493,7 +1506,7 @@ function requireRls(params) {
1493
1506
  }
1494
1507
  function identifier2(params) {
1495
1508
  if (typeof params.name !== "string" || params.name.length === 0 || params.name.includes("\x00") || new TextEncoder().encode(params.name).length > 63) {
1496
- throw new VibeError7({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS identifiers must be nonempty PostgreSQL identifiers of at most 63 bytes" });
1509
+ throw new VibeError8({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS identifiers must be nonempty PostgreSQL identifiers of at most 63 bytes" });
1497
1510
  }
1498
1511
  return params.dialect.quoteIdent({ name: params.name });
1499
1512
  }
@@ -1547,7 +1560,7 @@ function protectedModel(params) {
1547
1560
  assertValidSchemaIR({ schema: params.schema });
1548
1561
  const model = params.schema.models.find((entry) => entry.name === params.model);
1549
1562
  if (model === undefined || model.rls === undefined || model.rls === "unprotected") {
1550
- throw new VibeError7({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS policy rendering requires a protected model", meta: { model: params.model } });
1563
+ throw new VibeError8({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS policy rendering requires a protected model", meta: { model: params.model } });
1551
1564
  }
1552
1565
  return model;
1553
1566
  }
@@ -1580,7 +1593,7 @@ function predicate(params) {
1580
1593
  }).join(" AND ");
1581
1594
  return `EXISTS (SELECT 1 FROM ${tableRef({ dialect, table: parent.dbName ?? parent.name })} AS ${alias} WHERE ${join})`;
1582
1595
  }
1583
- throw new VibeError7({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS requires a protected policy rule" });
1596
+ throw new VibeError8({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS requires a protected policy rule" });
1584
1597
  }
1585
1598
  function renderRlsPolicy(params) {
1586
1599
  const model = protectedModel(params);
@@ -1614,7 +1627,7 @@ function renderRlsContext(params) {
1614
1627
  function renderRlsRole(params) {
1615
1628
  requireRls(params);
1616
1629
  if (typeof params.role !== "string" || params.role.trim().length === 0 || params.role.includes("\x00")) {
1617
- throw new VibeError7({ code: "VIBE_CONFIG", message: "PGlite native RLS requires a trusted nonempty runtime role name" });
1630
+ throw new VibeError8({ code: "VIBE_CONFIG", message: "PGlite native RLS requires a trusted nonempty runtime role name" });
1618
1631
  }
1619
1632
  const collector = new ParamCollector(params.dialect);
1620
1633
  return query({ text: `SELECT set_config('role', ${collector.add(params.role)}, true)`, values: collector.values });
@@ -2121,7 +2134,7 @@ function jsonPathString(path) {
2121
2134
  } else if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(segment)) {
2122
2135
  out += `.${segment}`;
2123
2136
  } else {
2124
- out += `."${segment.replaceAll('"', "\\\"")}"`;
2137
+ out += `."${segment.replaceAll("\\", "\\\\").replaceAll('"', "\\\"")}"`;
2125
2138
  }
2126
2139
  }
2127
2140
  return out;
@@ -2623,7 +2636,7 @@ function renderDelete(params) {
2623
2636
  return { text: text + returning.suffix, values: collector.values, returning: returning.status };
2624
2637
  }
2625
2638
  // packages/sql/src/dialects/sqlite-table-definition.ts
2626
- import { VibeError as VibeError8 } from "@vibeorm/schema";
2639
+ import { VibeError as VibeError9 } from "@vibeorm/schema";
2627
2640
  function tableDefinitionParts(params) {
2628
2641
  const sql = params.sql;
2629
2642
  if (!/^\s*CREATE\s+(?:TEMP(?:ORARY)?\s+)?TABLE\b/i.test(sql))
@@ -2684,7 +2697,7 @@ function tableDefinitionParts(params) {
2684
2697
  throw unavailable();
2685
2698
  }
2686
2699
  function unavailable() {
2687
- return new VibeError8({ code: "VIBE_MIGRATION", message: "Cannot preserve table definition", meta: { reason: "table-definition-unavailable" } });
2700
+ return new VibeError9({ code: "VIBE_MIGRATION", message: "Cannot preserve table definition", meta: { reason: "table-definition-unavailable" } });
2688
2701
  }
2689
2702
  function sqliteColumnClauses(params) {
2690
2703
  const columns = [];
@@ -3108,7 +3121,7 @@ function renderCheckProbe(params) {
3108
3121
  return { text: `ALTER TABLE ${q(params.table.namespace)}.${q(params.table.name)} ADD CONSTRAINT ${q(params.name)} CHECK (${params.expression}) NOT VALID`, values: [], returning: "none" };
3109
3122
  }
3110
3123
  // packages/sql/src/dialects/postgres-migration.ts
3111
- import { VibeError as VibeError9, unsupportedCapability as unsupportedCapability17 } from "@vibeorm/schema";
3124
+ import { VibeError as VibeError10, unsupportedCapability as unsupportedCapability17 } from "@vibeorm/schema";
3112
3125
  var SETTING_VALUE = /^[0-9]+(?:\.[0-9]+)?\s*(?:us|ms|s|min|h|d)?$/;
3113
3126
  function requirePostgres2(params) {
3114
3127
  if (params.dialect.name !== "postgres") {
@@ -3127,7 +3140,7 @@ function renderMigrationSessionSet(params) {
3127
3140
  requirePostgres2({ dialect: params.dialect, feature: "migrationSessionSettings" });
3128
3141
  const { milliseconds, setting } = params;
3129
3142
  if (!Number.isSafeInteger(milliseconds) || milliseconds < 0) {
3130
- throw new VibeError9({
3143
+ throw new VibeError10({
3131
3144
  code: "VIBE_MIGRATION",
3132
3145
  message: `${setting} must be a non-negative integer number of milliseconds (got ${String(milliseconds)})`,
3133
3146
  meta: { reason: "execution-metadata-invalid", setting, value: milliseconds }
@@ -3333,4 +3346,4 @@ export {
3333
3346
  toPgArrayLiteral
3334
3347
  };
3335
3348
 
3336
- //# debugId=E08264A778510D8664756E2164756E21
3349
+ //# debugId=C1F0ADA45113049064756E2164756E21