@prisma-next/target-postgres 0.3.0-dev.162 → 0.3.0-dev.163
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/control.mjs +76 -76
- package/dist/control.mjs.map +1 -1
- package/package.json +17 -17
package/dist/control.mjs
CHANGED
|
@@ -14,6 +14,82 @@ import { invariant } from "@prisma-next/utils/assertions";
|
|
|
14
14
|
import { readMarker } from "@prisma-next/family-sql/verify";
|
|
15
15
|
import { SqlQueryError } from "@prisma-next/sql-errors";
|
|
16
16
|
|
|
17
|
+
//#region ../../6-adapters/postgres/dist/sql-utils-CSfAGEwF.mjs
|
|
18
|
+
/**
|
|
19
|
+
* Shared SQL utility functions for the Postgres adapter.
|
|
20
|
+
*
|
|
21
|
+
* These functions handle safe SQL identifier and literal escaping
|
|
22
|
+
* with security validations to prevent injection and encoding issues.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Error thrown when an invalid SQL identifier or literal is detected.
|
|
26
|
+
* Boundary layers map this to structured envelopes.
|
|
27
|
+
*/
|
|
28
|
+
var SqlEscapeError = class extends Error {
|
|
29
|
+
constructor(message, value, kind) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.value = value;
|
|
32
|
+
this.kind = kind;
|
|
33
|
+
this.name = "SqlEscapeError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Maximum length for PostgreSQL identifiers (NAMEDATALEN - 1).
|
|
38
|
+
*/
|
|
39
|
+
const MAX_IDENTIFIER_LENGTH$1 = 63;
|
|
40
|
+
/**
|
|
41
|
+
* Validates and quotes a PostgreSQL identifier (table, column, type, schema names).
|
|
42
|
+
*
|
|
43
|
+
* Security validations:
|
|
44
|
+
* - Rejects null bytes which could cause truncation or unexpected behavior
|
|
45
|
+
* - Rejects empty identifiers
|
|
46
|
+
* - Warns on identifiers exceeding PostgreSQL's 63-character limit
|
|
47
|
+
*
|
|
48
|
+
* @throws {SqlEscapeError} If the identifier contains null bytes or is empty
|
|
49
|
+
*/
|
|
50
|
+
function quoteIdentifier(identifier) {
|
|
51
|
+
if (identifier.length === 0) throw new SqlEscapeError("Identifier cannot be empty", identifier, "identifier");
|
|
52
|
+
if (identifier.includes("\0")) throw new SqlEscapeError("Identifier cannot contain null bytes", identifier.replace(/\0/g, "\\0"), "identifier");
|
|
53
|
+
if (identifier.length > MAX_IDENTIFIER_LENGTH$1) console.warn(`Identifier "${identifier.slice(0, 20)}..." exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH$1}-character limit and will be truncated`);
|
|
54
|
+
return `"${identifier.replace(/"/g, "\"\"")}"`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Escapes a string literal for safe use in SQL statements.
|
|
58
|
+
*
|
|
59
|
+
* Security validations:
|
|
60
|
+
* - Rejects null bytes which could cause truncation or unexpected behavior
|
|
61
|
+
*
|
|
62
|
+
* Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).
|
|
63
|
+
* Backslashes are treated as literal characters, not escape sequences.
|
|
64
|
+
*
|
|
65
|
+
* @throws {SqlEscapeError} If the value contains null bytes
|
|
66
|
+
*/
|
|
67
|
+
function escapeLiteral(value) {
|
|
68
|
+
if (value.includes("\0")) throw new SqlEscapeError("Literal value cannot contain null bytes", value.replace(/\0/g, "\\0"), "literal");
|
|
69
|
+
return value.replace(/'/g, "''");
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Builds a qualified name (schema.object) with proper quoting.
|
|
73
|
+
*/
|
|
74
|
+
function qualifyName(schemaName, objectName) {
|
|
75
|
+
return `${quoteIdentifier(schemaName)}.${quoteIdentifier(objectName)}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Validates that an enum value doesn't exceed PostgreSQL's label length limit.
|
|
79
|
+
*
|
|
80
|
+
* PostgreSQL enum labels have a maximum length of NAMEDATALEN-1 (63 bytes by default).
|
|
81
|
+
* Unlike identifiers, enum labels that exceed this limit cause an error rather than
|
|
82
|
+
* silent truncation.
|
|
83
|
+
*
|
|
84
|
+
* @param value - The enum value to validate
|
|
85
|
+
* @param enumTypeName - Name of the enum type (for error messages)
|
|
86
|
+
* @throws {SqlEscapeError} If the value exceeds the maximum length
|
|
87
|
+
*/
|
|
88
|
+
function validateEnumValueLength(value, enumTypeName) {
|
|
89
|
+
if (value.length > MAX_IDENTIFIER_LENGTH$1) throw new SqlEscapeError(`Enum value "${value.slice(0, 20)}..." for type "${enumTypeName}" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH$1}-character label limit`, value, "literal");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
17
93
|
//#region ../../6-adapters/postgres/dist/codec-ids-BwjcIf74.mjs
|
|
18
94
|
const PG_TEXT_CODEC_ID = "pg/text@1";
|
|
19
95
|
const PG_ENUM_CODEC_ID = "pg/enum@1";
|
|
@@ -413,82 +489,6 @@ const codecs = defineCodecs().add("char", sqlCharCodec).add("varchar", sqlVarcha
|
|
|
413
489
|
const codecDefinitions = codecs.codecDefinitions;
|
|
414
490
|
const dataTypes = codecs.dataTypes;
|
|
415
491
|
|
|
416
|
-
//#endregion
|
|
417
|
-
//#region ../../6-adapters/postgres/dist/sql-utils-CSfAGEwF.mjs
|
|
418
|
-
/**
|
|
419
|
-
* Shared SQL utility functions for the Postgres adapter.
|
|
420
|
-
*
|
|
421
|
-
* These functions handle safe SQL identifier and literal escaping
|
|
422
|
-
* with security validations to prevent injection and encoding issues.
|
|
423
|
-
*/
|
|
424
|
-
/**
|
|
425
|
-
* Error thrown when an invalid SQL identifier or literal is detected.
|
|
426
|
-
* Boundary layers map this to structured envelopes.
|
|
427
|
-
*/
|
|
428
|
-
var SqlEscapeError = class extends Error {
|
|
429
|
-
constructor(message, value, kind) {
|
|
430
|
-
super(message);
|
|
431
|
-
this.value = value;
|
|
432
|
-
this.kind = kind;
|
|
433
|
-
this.name = "SqlEscapeError";
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
/**
|
|
437
|
-
* Maximum length for PostgreSQL identifiers (NAMEDATALEN - 1).
|
|
438
|
-
*/
|
|
439
|
-
const MAX_IDENTIFIER_LENGTH$1 = 63;
|
|
440
|
-
/**
|
|
441
|
-
* Validates and quotes a PostgreSQL identifier (table, column, type, schema names).
|
|
442
|
-
*
|
|
443
|
-
* Security validations:
|
|
444
|
-
* - Rejects null bytes which could cause truncation or unexpected behavior
|
|
445
|
-
* - Rejects empty identifiers
|
|
446
|
-
* - Warns on identifiers exceeding PostgreSQL's 63-character limit
|
|
447
|
-
*
|
|
448
|
-
* @throws {SqlEscapeError} If the identifier contains null bytes or is empty
|
|
449
|
-
*/
|
|
450
|
-
function quoteIdentifier(identifier) {
|
|
451
|
-
if (identifier.length === 0) throw new SqlEscapeError("Identifier cannot be empty", identifier, "identifier");
|
|
452
|
-
if (identifier.includes("\0")) throw new SqlEscapeError("Identifier cannot contain null bytes", identifier.replace(/\0/g, "\\0"), "identifier");
|
|
453
|
-
if (identifier.length > MAX_IDENTIFIER_LENGTH$1) console.warn(`Identifier "${identifier.slice(0, 20)}..." exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH$1}-character limit and will be truncated`);
|
|
454
|
-
return `"${identifier.replace(/"/g, "\"\"")}"`;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Escapes a string literal for safe use in SQL statements.
|
|
458
|
-
*
|
|
459
|
-
* Security validations:
|
|
460
|
-
* - Rejects null bytes which could cause truncation or unexpected behavior
|
|
461
|
-
*
|
|
462
|
-
* Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).
|
|
463
|
-
* Backslashes are treated as literal characters, not escape sequences.
|
|
464
|
-
*
|
|
465
|
-
* @throws {SqlEscapeError} If the value contains null bytes
|
|
466
|
-
*/
|
|
467
|
-
function escapeLiteral(value) {
|
|
468
|
-
if (value.includes("\0")) throw new SqlEscapeError("Literal value cannot contain null bytes", value.replace(/\0/g, "\\0"), "literal");
|
|
469
|
-
return value.replace(/'/g, "''");
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Builds a qualified name (schema.object) with proper quoting.
|
|
473
|
-
*/
|
|
474
|
-
function qualifyName(schemaName, objectName) {
|
|
475
|
-
return `${quoteIdentifier(schemaName)}.${quoteIdentifier(objectName)}`;
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Validates that an enum value doesn't exceed PostgreSQL's label length limit.
|
|
479
|
-
*
|
|
480
|
-
* PostgreSQL enum labels have a maximum length of NAMEDATALEN-1 (63 bytes by default).
|
|
481
|
-
* Unlike identifiers, enum labels that exceed this limit cause an error rather than
|
|
482
|
-
* silent truncation.
|
|
483
|
-
*
|
|
484
|
-
* @param value - The enum value to validate
|
|
485
|
-
* @param enumTypeName - Name of the enum type (for error messages)
|
|
486
|
-
* @throws {SqlEscapeError} If the value exceeds the maximum length
|
|
487
|
-
*/
|
|
488
|
-
function validateEnumValueLength(value, enumTypeName) {
|
|
489
|
-
if (value.length > MAX_IDENTIFIER_LENGTH$1) throw new SqlEscapeError(`Enum value "${value.slice(0, 20)}..." for type "${enumTypeName}" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH$1}-character label limit`, value, "literal");
|
|
490
|
-
}
|
|
491
|
-
|
|
492
492
|
//#endregion
|
|
493
493
|
//#region ../../6-adapters/postgres/dist/descriptor-meta-DemWrTfB.mjs
|
|
494
494
|
const ENUM_INTROSPECT_QUERY = `
|