@prisma-next/adapter-postgres 0.4.0-dev.9 → 0.4.2
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/adapter-hNElNHo4.mjs +60 -0
- package/dist/adapter-hNElNHo4.mjs.map +1 -0
- package/dist/adapter.d.mts +2 -8
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/column-types.d.mts.map +1 -1
- package/dist/column-types.mjs +1 -1
- package/dist/column-types.mjs.map +1 -1
- package/dist/control.d.mts +3 -70
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +19 -160
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-DemWrTfB.mjs → descriptor-meta-RTDzyrae.mjs} +33 -9
- package/dist/descriptor-meta-RTDzyrae.mjs.map +1 -0
- package/dist/operation-types.d.mts +21 -0
- package/dist/operation-types.d.mts.map +1 -0
- package/dist/operation-types.mjs +1 -0
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +8 -7
- package/dist/runtime.mjs.map +1 -1
- package/dist/{adapter-7pXt8ej9.mjs → sql-renderer-pEaSP82_.mjs} +102 -101
- package/dist/sql-renderer-pEaSP82_.mjs.map +1 -0
- package/dist/{types-DxaTd7aP.d.mts → types-CfRPdAk8.d.mts} +1 -1
- package/dist/{types-DxaTd7aP.d.mts.map → types-CfRPdAk8.d.mts.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +22 -16
- package/src/core/adapter.ts +4 -626
- package/src/core/control-adapter.ts +21 -47
- package/src/core/descriptor-meta.ts +25 -5
- package/src/core/enum-control-hooks.ts +7 -2
- package/src/core/json-schema-validator.ts +2 -1
- package/src/core/sql-renderer.ts +710 -0
- package/src/exports/column-types.ts +1 -1
- package/src/exports/control.ts +9 -4
- package/src/exports/operation-types.ts +1 -0
- package/src/exports/runtime.ts +5 -4
- package/src/types/operation-types.ts +11 -0
- package/dist/adapter-7pXt8ej9.mjs.map +0 -1
- package/dist/codec-ids-BwjcIf74.mjs +0 -29
- package/dist/codec-ids-BwjcIf74.mjs.map +0 -1
- package/dist/codec-types.d.mts +0 -107
- package/dist/codec-types.d.mts.map +0 -1
- package/dist/codec-types.mjs +0 -3
- package/dist/codecs-C3wlpdV7.mjs +0 -385
- package/dist/codecs-C3wlpdV7.mjs.map +0 -1
- package/dist/descriptor-meta-DemWrTfB.mjs.map +0 -1
- package/dist/sql-utils-CSfAGEwF.mjs +0 -78
- package/dist/sql-utils-CSfAGEwF.mjs.map +0 -1
- package/src/core/codec-ids.ts +0 -30
- package/src/core/codecs.ts +0 -645
- package/src/core/default-normalizer.ts +0 -145
- package/src/core/json-schema-type-expression.ts +0 -131
- package/src/core/sql-utils.ts +0 -111
- package/src/exports/codec-types.ts +0 -44
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
//#region src/core/sql-utils.ts
|
|
2
|
-
/**
|
|
3
|
-
* Shared SQL utility functions for the Postgres adapter.
|
|
4
|
-
*
|
|
5
|
-
* These functions handle safe SQL identifier and literal escaping
|
|
6
|
-
* with security validations to prevent injection and encoding issues.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Error thrown when an invalid SQL identifier or literal is detected.
|
|
10
|
-
* Boundary layers map this to structured envelopes.
|
|
11
|
-
*/
|
|
12
|
-
var SqlEscapeError = class extends Error {
|
|
13
|
-
constructor(message, value, kind) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.value = value;
|
|
16
|
-
this.kind = kind;
|
|
17
|
-
this.name = "SqlEscapeError";
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Maximum length for PostgreSQL identifiers (NAMEDATALEN - 1).
|
|
22
|
-
*/
|
|
23
|
-
const MAX_IDENTIFIER_LENGTH = 63;
|
|
24
|
-
/**
|
|
25
|
-
* Validates and quotes a PostgreSQL identifier (table, column, type, schema names).
|
|
26
|
-
*
|
|
27
|
-
* Security validations:
|
|
28
|
-
* - Rejects null bytes which could cause truncation or unexpected behavior
|
|
29
|
-
* - Rejects empty identifiers
|
|
30
|
-
* - Warns on identifiers exceeding PostgreSQL's 63-character limit
|
|
31
|
-
*
|
|
32
|
-
* @throws {SqlEscapeError} If the identifier contains null bytes or is empty
|
|
33
|
-
*/
|
|
34
|
-
function quoteIdentifier(identifier) {
|
|
35
|
-
if (identifier.length === 0) throw new SqlEscapeError("Identifier cannot be empty", identifier, "identifier");
|
|
36
|
-
if (identifier.includes("\0")) throw new SqlEscapeError("Identifier cannot contain null bytes", identifier.replace(/\0/g, "\\0"), "identifier");
|
|
37
|
-
if (identifier.length > MAX_IDENTIFIER_LENGTH) console.warn(`Identifier "${identifier.slice(0, 20)}..." exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character limit and will be truncated`);
|
|
38
|
-
return `"${identifier.replace(/"/g, "\"\"")}"`;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Escapes a string literal for safe use in SQL statements.
|
|
42
|
-
*
|
|
43
|
-
* Security validations:
|
|
44
|
-
* - Rejects null bytes which could cause truncation or unexpected behavior
|
|
45
|
-
*
|
|
46
|
-
* Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).
|
|
47
|
-
* Backslashes are treated as literal characters, not escape sequences.
|
|
48
|
-
*
|
|
49
|
-
* @throws {SqlEscapeError} If the value contains null bytes
|
|
50
|
-
*/
|
|
51
|
-
function escapeLiteral(value) {
|
|
52
|
-
if (value.includes("\0")) throw new SqlEscapeError("Literal value cannot contain null bytes", value.replace(/\0/g, "\\0"), "literal");
|
|
53
|
-
return value.replace(/'/g, "''");
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Builds a qualified name (schema.object) with proper quoting.
|
|
57
|
-
*/
|
|
58
|
-
function qualifyName(schemaName, objectName) {
|
|
59
|
-
return `${quoteIdentifier(schemaName)}.${quoteIdentifier(objectName)}`;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Validates that an enum value doesn't exceed PostgreSQL's label length limit.
|
|
63
|
-
*
|
|
64
|
-
* PostgreSQL enum labels have a maximum length of NAMEDATALEN-1 (63 bytes by default).
|
|
65
|
-
* Unlike identifiers, enum labels that exceed this limit cause an error rather than
|
|
66
|
-
* silent truncation.
|
|
67
|
-
*
|
|
68
|
-
* @param value - The enum value to validate
|
|
69
|
-
* @param enumTypeName - Name of the enum type (for error messages)
|
|
70
|
-
* @throws {SqlEscapeError} If the value exceeds the maximum length
|
|
71
|
-
*/
|
|
72
|
-
function validateEnumValueLength(value, enumTypeName) {
|
|
73
|
-
if (value.length > MAX_IDENTIFIER_LENGTH) throw new SqlEscapeError(`Enum value "${value.slice(0, 20)}..." for type "${enumTypeName}" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character label limit`, value, "literal");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
//#endregion
|
|
77
|
-
export { validateEnumValueLength as a, quoteIdentifier as i, escapeLiteral as n, qualifyName as r, SqlEscapeError as t };
|
|
78
|
-
//# sourceMappingURL=sql-utils-CSfAGEwF.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sql-utils-CSfAGEwF.mjs","names":["value: string","kind: 'identifier' | 'literal'"],"sources":["../src/core/sql-utils.ts"],"sourcesContent":["/**\n * Shared SQL utility functions for the Postgres adapter.\n *\n * These functions handle safe SQL identifier and literal escaping\n * with security validations to prevent injection and encoding issues.\n */\n\n/**\n * Error thrown when an invalid SQL identifier or literal is detected.\n * Boundary layers map this to structured envelopes.\n */\nexport class SqlEscapeError extends Error {\n constructor(\n message: string,\n public readonly value: string,\n public readonly kind: 'identifier' | 'literal',\n ) {\n super(message);\n this.name = 'SqlEscapeError';\n }\n}\n\n/**\n * Maximum length for PostgreSQL identifiers (NAMEDATALEN - 1).\n */\nconst MAX_IDENTIFIER_LENGTH = 63;\n\n/**\n * Validates and quotes a PostgreSQL identifier (table, column, type, schema names).\n *\n * Security validations:\n * - Rejects null bytes which could cause truncation or unexpected behavior\n * - Rejects empty identifiers\n * - Warns on identifiers exceeding PostgreSQL's 63-character limit\n *\n * @throws {SqlEscapeError} If the identifier contains null bytes or is empty\n */\nexport function quoteIdentifier(identifier: string): string {\n if (identifier.length === 0) {\n throw new SqlEscapeError('Identifier cannot be empty', identifier, 'identifier');\n }\n if (identifier.includes('\\0')) {\n throw new SqlEscapeError(\n 'Identifier cannot contain null bytes',\n identifier.replace(/\\0/g, '\\\\0'),\n 'identifier',\n );\n }\n // PostgreSQL will truncate identifiers longer than 63 characters.\n // We don't throw here because it's not a security issue, but callers should be aware.\n if (identifier.length > MAX_IDENTIFIER_LENGTH) {\n // Log warning in development, but don't fail - PostgreSQL handles truncation\n console.warn(\n `Identifier \"${identifier.slice(0, 20)}...\" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character limit and will be truncated`,\n );\n }\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\n/**\n * Escapes a string literal for safe use in SQL statements.\n *\n * Security validations:\n * - Rejects null bytes which could cause truncation or unexpected behavior\n *\n * Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).\n * Backslashes are treated as literal characters, not escape sequences.\n *\n * @throws {SqlEscapeError} If the value contains null bytes\n */\nexport function escapeLiteral(value: string): string {\n if (value.includes('\\0')) {\n throw new SqlEscapeError(\n 'Literal value cannot contain null bytes',\n value.replace(/\\0/g, '\\\\0'),\n 'literal',\n );\n }\n return value.replace(/'/g, \"''\");\n}\n\n/**\n * Builds a qualified name (schema.object) with proper quoting.\n */\nexport function qualifyName(schemaName: string, objectName: string): string {\n return `${quoteIdentifier(schemaName)}.${quoteIdentifier(objectName)}`;\n}\n\n/**\n * Validates that an enum value doesn't exceed PostgreSQL's label length limit.\n *\n * PostgreSQL enum labels have a maximum length of NAMEDATALEN-1 (63 bytes by default).\n * Unlike identifiers, enum labels that exceed this limit cause an error rather than\n * silent truncation.\n *\n * @param value - The enum value to validate\n * @param enumTypeName - Name of the enum type (for error messages)\n * @throws {SqlEscapeError} If the value exceeds the maximum length\n */\nexport function validateEnumValueLength(value: string, enumTypeName: string): void {\n // PostgreSQL uses byte length, not character length. For simplicity, we use\n // character length as a conservative approximation (multi-byte chars would fail earlier).\n if (value.length > MAX_IDENTIFIER_LENGTH) {\n throw new SqlEscapeError(\n `Enum value \"${value.slice(0, 20)}...\" for type \"${enumTypeName}\" exceeds PostgreSQL's ` +\n `${MAX_IDENTIFIER_LENGTH}-character label limit`,\n value,\n 'literal',\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAWA,IAAa,iBAAb,cAAoC,MAAM;CACxC,YACE,SACA,AAAgBA,OAChB,AAAgBC,MAChB;AACA,QAAM,QAAQ;EAHE;EACA;AAGhB,OAAK,OAAO;;;;;;AAOhB,MAAM,wBAAwB;;;;;;;;;;;AAY9B,SAAgB,gBAAgB,YAA4B;AAC1D,KAAI,WAAW,WAAW,EACxB,OAAM,IAAI,eAAe,8BAA8B,YAAY,aAAa;AAElF,KAAI,WAAW,SAAS,KAAK,CAC3B,OAAM,IAAI,eACR,wCACA,WAAW,QAAQ,OAAO,MAAM,EAChC,aACD;AAIH,KAAI,WAAW,SAAS,sBAEtB,SAAQ,KACN,eAAe,WAAW,MAAM,GAAG,GAAG,CAAC,4BAA4B,sBAAsB,wCAC1F;AAEH,QAAO,IAAI,WAAW,QAAQ,MAAM,OAAK,CAAC;;;;;;;;;;;;;AAc5C,SAAgB,cAAc,OAAuB;AACnD,KAAI,MAAM,SAAS,KAAK,CACtB,OAAM,IAAI,eACR,2CACA,MAAM,QAAQ,OAAO,MAAM,EAC3B,UACD;AAEH,QAAO,MAAM,QAAQ,MAAM,KAAK;;;;;AAMlC,SAAgB,YAAY,YAAoB,YAA4B;AAC1E,QAAO,GAAG,gBAAgB,WAAW,CAAC,GAAG,gBAAgB,WAAW;;;;;;;;;;;;;AActE,SAAgB,wBAAwB,OAAe,cAA4B;AAGjF,KAAI,MAAM,SAAS,sBACjB,OAAM,IAAI,eACR,eAAe,MAAM,MAAM,GAAG,GAAG,CAAC,iBAAiB,aAAa,yBAC3D,sBAAsB,yBAC3B,OACA,UACD"}
|
package/src/core/codec-ids.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
SQL_CHAR_CODEC_ID,
|
|
3
|
-
SQL_FLOAT_CODEC_ID,
|
|
4
|
-
SQL_INT_CODEC_ID,
|
|
5
|
-
SQL_TEXT_CODEC_ID,
|
|
6
|
-
SQL_TIMESTAMP_CODEC_ID,
|
|
7
|
-
SQL_VARCHAR_CODEC_ID,
|
|
8
|
-
} from '@prisma-next/sql-relational-core/ast';
|
|
9
|
-
export const PG_TEXT_CODEC_ID = 'pg/text@1' as const;
|
|
10
|
-
export const PG_ENUM_CODEC_ID = 'pg/enum@1' as const;
|
|
11
|
-
export const PG_CHAR_CODEC_ID = 'pg/char@1' as const;
|
|
12
|
-
export const PG_VARCHAR_CODEC_ID = 'pg/varchar@1' as const;
|
|
13
|
-
export const PG_INT_CODEC_ID = 'pg/int@1' as const;
|
|
14
|
-
export const PG_INT2_CODEC_ID = 'pg/int2@1' as const;
|
|
15
|
-
export const PG_INT4_CODEC_ID = 'pg/int4@1' as const;
|
|
16
|
-
export const PG_INT8_CODEC_ID = 'pg/int8@1' as const;
|
|
17
|
-
export const PG_FLOAT_CODEC_ID = 'pg/float@1' as const;
|
|
18
|
-
export const PG_FLOAT4_CODEC_ID = 'pg/float4@1' as const;
|
|
19
|
-
export const PG_FLOAT8_CODEC_ID = 'pg/float8@1' as const;
|
|
20
|
-
export const PG_NUMERIC_CODEC_ID = 'pg/numeric@1' as const;
|
|
21
|
-
export const PG_BOOL_CODEC_ID = 'pg/bool@1' as const;
|
|
22
|
-
export const PG_BIT_CODEC_ID = 'pg/bit@1' as const;
|
|
23
|
-
export const PG_VARBIT_CODEC_ID = 'pg/varbit@1' as const;
|
|
24
|
-
export const PG_TIMESTAMP_CODEC_ID = 'pg/timestamp@1' as const;
|
|
25
|
-
export const PG_TIMESTAMPTZ_CODEC_ID = 'pg/timestamptz@1' as const;
|
|
26
|
-
export const PG_TIME_CODEC_ID = 'pg/time@1' as const;
|
|
27
|
-
export const PG_TIMETZ_CODEC_ID = 'pg/timetz@1' as const;
|
|
28
|
-
export const PG_INTERVAL_CODEC_ID = 'pg/interval@1' as const;
|
|
29
|
-
export const PG_JSON_CODEC_ID = 'pg/json@1' as const;
|
|
30
|
-
export const PG_JSONB_CODEC_ID = 'pg/jsonb@1' as const;
|