@nextlyhq/adapter-drizzle 0.0.2-alpha.7 → 0.0.2-alpha.71
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/README.md +25 -1
- package/dist/adapter-BypoOEEN.d.cts +1166 -0
- package/dist/adapter-CSP-Ek-L.d.ts +1166 -0
- package/dist/index-BYb6cDli.d.ts +1168 -0
- package/dist/index-C4HJsfwA.d.cts +1168 -0
- package/dist/index.cjs +2302 -1085
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -9
- package/dist/index.d.ts +5 -9
- package/dist/index.mjs +2301 -1083
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.cjs +345 -146
- package/dist/migrations.cjs.map +1 -1
- package/dist/migrations.d.cts +93 -109
- package/dist/migrations.d.ts +93 -109
- package/dist/migrations.mjs +344 -144
- package/dist/migrations.mjs.map +1 -1
- package/dist/schema/index.cjs +21 -6
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +5 -116
- package/dist/schema/index.d.ts +5 -116
- package/dist/schema/index.mjs +20 -4
- package/dist/schema/index.mjs.map +1 -1
- package/dist/schema-Bkkr3JMC.d.cts +264 -0
- package/dist/schema-Bkkr3JMC.d.ts +264 -0
- package/dist/schema-name.cjs +42 -0
- package/dist/schema-name.cjs.map +1 -0
- package/dist/schema-name.d.cts +12 -0
- package/dist/schema-name.d.ts +12 -0
- package/dist/schema-name.mjs +40 -0
- package/dist/schema-name.mjs.map +1 -0
- package/dist/text-match.cjs +50 -0
- package/dist/text-match.cjs.map +1 -0
- package/dist/text-match.d.cts +32 -0
- package/dist/text-match.d.ts +32 -0
- package/dist/text-match.mjs +48 -0
- package/dist/text-match.mjs.map +1 -0
- package/dist/types/index.cjs +8 -24
- package/dist/types/index.d.cts +3 -210
- package/dist/types/index.d.ts +3 -210
- package/dist/types/index.mjs +1 -21
- package/dist/types-CNyA1oIm.cjs +185 -0
- package/dist/types-CNyA1oIm.cjs.map +1 -0
- package/dist/types-CaF_5jNk.mjs +150 -0
- package/dist/types-CaF_5jNk.mjs.map +1 -0
- package/dist/version-check.cjs +119 -127
- package/dist/version-check.cjs.map +1 -1
- package/dist/version-check.d.cts +54 -39
- package/dist/version-check.d.ts +54 -39
- package/dist/version-check.mjs +117 -125
- package/dist/version-check.mjs.map +1 -1
- package/package.json +23 -17
- package/dist/adapter-BxJVtttb.d.ts +0 -592
- package/dist/adapter-nvlxFkF-.d.cts +0 -592
- package/dist/core-CVO7WYDj.d.cts +0 -74
- package/dist/core-CVO7WYDj.d.ts +0 -74
- package/dist/error-um1d_3Uo.d.cts +0 -105
- package/dist/error-um1d_3Uo.d.ts +0 -105
- package/dist/migration-BbO5meEV.d.cts +0 -622
- package/dist/migration-Qe70wDOC.d.ts +0 -622
- package/dist/schema-BDn8WfSL.d.cts +0 -200
- package/dist/schema-BIQ0YQZ_.d.ts +0 -200
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.mjs.map +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/types/query.ts
|
|
2
|
+
/**
|
|
3
|
+
* Every WHERE clause operator this package DECLARES, as a value.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Declared, not guaranteed executable. Membership here means a `WhereCondition`
|
|
7
|
+
* carrying the operator type-checks — it does NOT mean the adapter can run it.
|
|
8
|
+
* `OVERLAPS` is declared and unimplemented, and throws at build time, so a
|
|
9
|
+
* validator written against this list will admit input the query layer then
|
|
10
|
+
* rejects. Validate against it to catch a misspelled operator; do not read
|
|
11
|
+
* acceptance here as a capability.
|
|
12
|
+
*
|
|
13
|
+
* - Standard comparison: =, !=, <, >, <=, >=
|
|
14
|
+
* - Set operations: IN, NOT IN
|
|
15
|
+
* - Pattern matching: LIKE, ILIKE (case-insensitive, PostgreSQL/emulated)
|
|
16
|
+
* - NULL checks: IS NULL, IS NOT NULL
|
|
17
|
+
* - Range: BETWEEN, NOT BETWEEN
|
|
18
|
+
* - Substring: CONTAINS — a LITERAL match on a TEXT column; see below
|
|
19
|
+
* - Declared but NOT implemented: OVERLAPS, which throws
|
|
20
|
+
*
|
|
21
|
+
* This list is the source of truth and {@link WhereOperator} is derived from it,
|
|
22
|
+
* rather than the two being written out separately. A guard that has to enumerate
|
|
23
|
+
* the operators — a validator over caller input, or a test asserting the builder
|
|
24
|
+
* handles or refuses each one — can only do that from a runtime value, and a
|
|
25
|
+
* hand-kept copy of the union would agree with it on the day it was written and
|
|
26
|
+
* silently stop agreeing the next time a member is added.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
const WHERE_OPERATORS = [
|
|
31
|
+
"=",
|
|
32
|
+
"!=",
|
|
33
|
+
"<",
|
|
34
|
+
">",
|
|
35
|
+
"<=",
|
|
36
|
+
">=",
|
|
37
|
+
"IN",
|
|
38
|
+
"NOT IN",
|
|
39
|
+
"LIKE",
|
|
40
|
+
"ILIKE",
|
|
41
|
+
"IS NULL",
|
|
42
|
+
"IS NOT NULL",
|
|
43
|
+
"BETWEEN",
|
|
44
|
+
"NOT BETWEEN",
|
|
45
|
+
"CONTAINS",
|
|
46
|
+
"ICONTAINS",
|
|
47
|
+
"OVERLAPS"
|
|
48
|
+
];
|
|
49
|
+
// src/types/error.ts
|
|
50
|
+
/**
|
|
51
|
+
* Type guard for DatabaseError.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Checks if an error is a DatabaseError with proper typing.
|
|
55
|
+
*
|
|
56
|
+
* @param error - Error to check
|
|
57
|
+
* @returns True if error is a DatabaseError
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
function isDatabaseError(error) {
|
|
62
|
+
return typeof error === "object" && error !== null && "kind" in error && typeof error.kind === "string";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The brand every Nextly application error carries.
|
|
66
|
+
*
|
|
67
|
+
* Read through the global symbol registry rather than imported, because the
|
|
68
|
+
* adapters must not depend on the package that defines the error: `Symbol.for`
|
|
69
|
+
* resolves to the same symbol in every module instance, which is why the brand
|
|
70
|
+
* exists in that form to begin with.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
const APPLICATION_ERROR_BRAND = Symbol.for("nextly/NextlyError");
|
|
75
|
+
/**
|
|
76
|
+
* Whether an error is the application's verdict rather than the database's
|
|
77
|
+
* failure.
|
|
78
|
+
*
|
|
79
|
+
* Work running inside a transaction may throw to roll the write back — a
|
|
80
|
+
* refused value, a permission denial — and such an error is not something the
|
|
81
|
+
* driver produced. Classifying it as a database error replaces its code and its
|
|
82
|
+
* payload with a generic one, so a caller that asked for a refusal is handed an
|
|
83
|
+
* unexplained failure instead, and per-field validation detail is lost on the
|
|
84
|
+
* way out.
|
|
85
|
+
*
|
|
86
|
+
* @param error - Error to check
|
|
87
|
+
* @returns True if the error was raised by application code
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
function isApplicationError(error) {
|
|
92
|
+
if (error === null || typeof error !== "object" && typeof error !== "function") return false;
|
|
93
|
+
return error[APPLICATION_ERROR_BRAND] === true;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create a DatabaseError instance.
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* Helper function to create properly structured DatabaseError objects.
|
|
100
|
+
*
|
|
101
|
+
* @param options - Error options
|
|
102
|
+
* @returns DatabaseError instance
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
function createDatabaseError(options) {
|
|
107
|
+
const error = new Error(options.message);
|
|
108
|
+
error.name = "DatabaseError";
|
|
109
|
+
error.kind = options.kind;
|
|
110
|
+
if (options.code !== void 0) error.code = options.code;
|
|
111
|
+
if (options.constraint !== void 0) error.constraint = options.constraint;
|
|
112
|
+
if (options.table !== void 0) error.table = options.table;
|
|
113
|
+
if (options.column !== void 0) error.column = options.column;
|
|
114
|
+
if (options.detail !== void 0) error.detail = options.detail;
|
|
115
|
+
if (options.hint !== void 0) error.hint = options.hint;
|
|
116
|
+
if (options.cause !== void 0) error.cause = options.cause;
|
|
117
|
+
return error;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The code an adapter gives the error it raises when a request has waited
|
|
121
|
+
* longer than `pool.connectionTimeoutMs` for a database connection.
|
|
122
|
+
*
|
|
123
|
+
* A code of the adapters' own rather than the driver's wording, because the
|
|
124
|
+
* drivers disagree: pg-pool raises a plain `Error` with no code, mysql2 has no
|
|
125
|
+
* such wait to time out, and better-sqlite3 has no pool. Core reads this one
|
|
126
|
+
* code to answer with its retryable "database busy" error.
|
|
127
|
+
*
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
const POOL_WAIT_TIMEOUT_CODE = "NEXTLY_POOL_WAIT_TIMEOUT";
|
|
131
|
+
/**
|
|
132
|
+
* The error for a request that waited `boundMs` for a database connection and
|
|
133
|
+
* was given none.
|
|
134
|
+
*
|
|
135
|
+
* @param boundMs - The bound it waited, `pool.connectionTimeoutMs`
|
|
136
|
+
* @param cause - The driver's own error, when the driver raised one
|
|
137
|
+
*
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
function poolWaitTimeoutError(boundMs, cause) {
|
|
141
|
+
return createDatabaseError({
|
|
142
|
+
kind: "timeout",
|
|
143
|
+
code: POOL_WAIT_TIMEOUT_CODE,
|
|
144
|
+
message: `Waited ${boundMs} ms for a database connection, and none was free`,
|
|
145
|
+
cause
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
export { poolWaitTimeoutError as a, isDatabaseError as i, createDatabaseError as n, WHERE_OPERATORS as o, isApplicationError as r, POOL_WAIT_TIMEOUT_CODE as t };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=types-CaF_5jNk.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CaF_5jNk.mjs","names":[],"sources":["../src/types/query.ts","../src/types/error.ts"],"sourcesContent":["/**\n * Query building type definitions for database-agnostic queries.\n *\n * @packageDocumentation\n */\n\nimport type { SqlParam } from \"./core\";\n\n/**\n * Every WHERE clause operator this package DECLARES, as a value.\n *\n * @remarks\n * Declared, not guaranteed executable. Membership here means a `WhereCondition`\n * carrying the operator type-checks — it does NOT mean the adapter can run it.\n * `OVERLAPS` is declared and unimplemented, and throws at build time, so a\n * validator written against this list will admit input the query layer then\n * rejects. Validate against it to catch a misspelled operator; do not read\n * acceptance here as a capability.\n *\n * - Standard comparison: =, !=, <, >, <=, >=\n * - Set operations: IN, NOT IN\n * - Pattern matching: LIKE, ILIKE (case-insensitive, PostgreSQL/emulated)\n * - NULL checks: IS NULL, IS NOT NULL\n * - Range: BETWEEN, NOT BETWEEN\n * - Substring: CONTAINS — a LITERAL match on a TEXT column; see below\n * - Declared but NOT implemented: OVERLAPS, which throws\n *\n * This list is the source of truth and {@link WhereOperator} is derived from it,\n * rather than the two being written out separately. A guard that has to enumerate\n * the operators — a validator over caller input, or a test asserting the builder\n * handles or refuses each one — can only do that from a runtime value, and a\n * hand-kept copy of the union would agree with it on the day it was written and\n * silently stop agreeing the next time a member is added.\n *\n * @public\n */\nexport const WHERE_OPERATORS = [\n \"=\",\n \"!=\",\n \"<\",\n \">\",\n \"<=\",\n \">=\",\n \"IN\",\n \"NOT IN\",\n \"LIKE\",\n \"ILIKE\",\n \"IS NULL\",\n \"IS NOT NULL\",\n \"BETWEEN\",\n \"NOT BETWEEN\",\n // Substring match on a TEXT column, with the value taken literally. Despite the name it is\n // not JSON containment, and it is not safe to point at a JSON column: the builder emits a\n // bare `LIKE` with no cast, so on PostgreSQL a `json`/`jsonb` column has no matching operator\n // and the statement ERRORS (`operator does not exist: jsonb ~~ text`). MySQL and SQLite\n // coerce, and there it searches the serialized text — which hits a key name as readily as a\n // value. Text columns only, and a search rather than a containment check.\n \"CONTAINS\",\n // CONTAINS without regard to case: a substring match on a TEXT column with the value taken\n // literally (`%` and `_` are characters to find, not wildcards), ignoring case on every\n // dialect even where the column's collation is case-sensitive. Which letters fold is the\n // database's `lower()` under the column's collation: the collation's Unicode version on\n // MySQL; non-ASCII too under a linguistic PostgreSQL collation; ASCII letters only on\n // SQLite and under PostgreSQL's `C` or `POSIX`.\n \"ICONTAINS\",\n // Declared, never implemented — the builder throws `Unsupported operator: OVERLAPS`. Kept in\n // the union because removing it would be a breaking change to a published type; the refusal\n // is pinned by a test so implementing it has to come through here.\n \"OVERLAPS\",\n] as const;\n\n/**\n * Every WHERE clause operator this package declares. Derived from\n * {@link WHERE_OPERATORS}, and carrying the same caveat: a value of this type\n * type-checks, which is not the same as the adapter being able to execute it.\n *\n * @public\n */\nexport type WhereOperator = (typeof WHERE_OPERATORS)[number];\n\n/**\n * Individual WHERE condition.\n *\n * @remarks\n * Represents a single condition in a WHERE clause. For IS NULL and IS NOT NULL\n * operators, the value field is optional.\n *\n * @public\n */\nexport interface WhereCondition {\n /** Column name to filter on */\n column: string;\n\n /** Comparison operator */\n op: WhereOperator;\n\n /** Value(s) to compare against (optional for IS NULL/IS NOT NULL) */\n value?: SqlParam | SqlParam[];\n\n /** Second value for BETWEEN operator */\n valueTo?: SqlParam;\n}\n\n/**\n * Complex WHERE clause with logical operators.\n *\n * @remarks\n * Supports nested conditions with AND, OR, and NOT logical operators.\n * Can be recursively nested for complex queries.\n *\n * @example\n * ```typescript\n * const where: WhereClause = {\n * and: [\n * { column: \"status\", op: \"=\", value: \"published\" },\n * {\n * or: [\n * { column: \"author\", op: \"=\", value: \"john\" },\n * { column: \"author\", op: \"=\", value: \"jane\" }\n * ]\n * }\n * ]\n * };\n * ```\n *\n * @public\n */\nexport interface WhereClause {\n /** All conditions must be true (AND) */\n and?: (WhereCondition | WhereClause)[];\n\n /** At least one condition must be true (OR) */\n or?: (WhereCondition | WhereClause)[];\n\n /** Negate a condition (NOT) */\n not?: WhereCondition | WhereClause;\n}\n\n/**\n * ORDER BY specification for query results.\n *\n * @remarks\n * Controls the sorting of query results. NULL handling varies by database\n * but can be explicitly controlled with the nulls field.\n *\n * @public\n */\nexport interface OrderBySpec {\n /** Column name to sort by */\n column: string;\n\n /** Sort direction (default: asc) */\n direction?: \"asc\" | \"desc\";\n\n /** NULL value ordering (database-specific defaults vary) */\n nulls?: \"first\" | \"last\";\n}\n\n/**\n * JOIN specification for table joins.\n *\n * @remarks\n * Supports different types of JOINs. Note that complex joins may require\n * dialect-specific handling.\n *\n * @public\n */\nexport interface JoinSpec {\n /** Type of join */\n type: \"inner\" | \"left\" | \"right\" | \"full\";\n\n /** Table name to join */\n table: string;\n\n /** Join condition */\n on: {\n /** Column from the left table */\n leftColumn: string;\n /** Column from the right table */\n rightColumn: string;\n };\n\n /** Optional alias for the joined table */\n alias?: string;\n}\n","/**\n * Database error type definitions.\n *\n * @packageDocumentation\n */\n\n/**\n * Database error classification.\n *\n * @remarks\n * Categorizes database errors for consistent error handling across adapters.\n * Each adapter translates database-specific error codes to these kinds.\n *\n * @public\n */\nexport type DatabaseErrorKind =\n | \"connection\" // Connection/network errors\n | \"query\" // Syntax or execution errors\n | \"constraint\" // Generic constraint violation\n | \"unique_violation\" // Unique constraint violation\n | \"foreign_key_violation\" // Foreign key constraint violation\n | \"check_violation\" // Check constraint violation\n | \"not_null_violation\" // NOT NULL constraint violation\n | \"deadlock\" // Transaction deadlock\n | \"timeout\" // Query or connection timeout\n | \"serialization_failure\" // Serializable transaction conflict\n | \"unsupported_version\" // F17: DB version below minimum or unparseable at connect\n | \"unknown\"; // Unclassified error\n\n/**\n * Enhanced database error interface.\n *\n * @remarks\n * Extends the standard Error interface with database-specific context.\n * Adapters should throw errors implementing this interface for consistent\n * error handling.\n *\n * @example\n * ```typescript\n * try {\n * await adapter.insert('users', { email: 'duplicate@example.com' });\n * } catch (error) {\n * if (isDatabaseError(error) && error.kind === 'unique_violation') {\n * console.log(`Duplicate ${error.column} in ${error.table}`);\n * }\n * }\n * ```\n *\n * @public\n */\nexport interface DatabaseError extends Error {\n /** Error classification */\n kind: DatabaseErrorKind;\n\n /** Database-specific error code (e.g., \"23505\" for PostgreSQL unique violation) */\n code?: string;\n\n /** Constraint name that was violated (if applicable) */\n constraint?: string;\n\n /** Table name involved in the error */\n table?: string;\n\n /** Column name involved in the error */\n column?: string;\n\n /** Detailed error description from the database */\n detail?: string;\n\n /** Hint for resolving the error */\n hint?: string;\n\n /** Original error from the database driver */\n cause?: Error;\n}\n\n/**\n * Type guard for DatabaseError.\n *\n * @remarks\n * Checks if an error is a DatabaseError with proper typing.\n *\n * @param error - Error to check\n * @returns True if error is a DatabaseError\n *\n * @public\n */\nexport function isDatabaseError(error: unknown): error is DatabaseError {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"kind\" in error &&\n typeof (error as DatabaseError).kind === \"string\"\n );\n}\n\n/**\n * The brand every Nextly application error carries.\n *\n * Read through the global symbol registry rather than imported, because the\n * adapters must not depend on the package that defines the error: `Symbol.for`\n * resolves to the same symbol in every module instance, which is why the brand\n * exists in that form to begin with.\n *\n * @internal\n */\nconst APPLICATION_ERROR_BRAND: unique symbol = Symbol.for(\"nextly/NextlyError\");\n\n/**\n * Whether an error is the application's verdict rather than the database's\n * failure.\n *\n * Work running inside a transaction may throw to roll the write back — a\n * refused value, a permission denial — and such an error is not something the\n * driver produced. Classifying it as a database error replaces its code and its\n * payload with a generic one, so a caller that asked for a refusal is handed an\n * unexplained failure instead, and per-field validation detail is lost on the\n * way out.\n *\n * @param error - Error to check\n * @returns True if the error was raised by application code\n *\n * @public\n */\nexport function isApplicationError(error: unknown): boolean {\n if (\n error === null ||\n (typeof error !== \"object\" && typeof error !== \"function\")\n ) {\n return false;\n }\n return (error as Record<symbol, unknown>)[APPLICATION_ERROR_BRAND] === true;\n}\n\n/**\n * Database error constructor options.\n *\n * @public\n */\nexport interface DatabaseErrorOptions {\n /** Error classification */\n kind: DatabaseErrorKind;\n\n /** Error message */\n message: string;\n\n /** Database-specific error code */\n code?: string;\n\n /** Constraint name */\n constraint?: string;\n\n /** Table name */\n table?: string;\n\n /** Column name */\n column?: string;\n\n /** Detailed description */\n detail?: string;\n\n /** Resolution hint */\n hint?: string;\n\n /** Original error */\n cause?: Error;\n}\n\n/**\n * Create a DatabaseError instance.\n *\n * @remarks\n * Helper function to create properly structured DatabaseError objects.\n *\n * @param options - Error options\n * @returns DatabaseError instance\n *\n * @public\n */\nexport function createDatabaseError(\n options: DatabaseErrorOptions\n): DatabaseError {\n const error = new Error(options.message) as DatabaseError;\n error.name = \"DatabaseError\";\n error.kind = options.kind;\n\n if (options.code !== undefined) error.code = options.code;\n if (options.constraint !== undefined) error.constraint = options.constraint;\n if (options.table !== undefined) error.table = options.table;\n if (options.column !== undefined) error.column = options.column;\n if (options.detail !== undefined) error.detail = options.detail;\n if (options.hint !== undefined) error.hint = options.hint;\n if (options.cause !== undefined) error.cause = options.cause;\n\n return error;\n}\n\n/**\n * The code an adapter gives the error it raises when a request has waited\n * longer than `pool.connectionTimeoutMs` for a database connection.\n *\n * A code of the adapters' own rather than the driver's wording, because the\n * drivers disagree: pg-pool raises a plain `Error` with no code, mysql2 has no\n * such wait to time out, and better-sqlite3 has no pool. Core reads this one\n * code to answer with its retryable \"database busy\" error.\n *\n * @public\n */\nexport const POOL_WAIT_TIMEOUT_CODE = \"NEXTLY_POOL_WAIT_TIMEOUT\";\n\n/**\n * The error for a request that waited `boundMs` for a database connection and\n * was given none.\n *\n * @param boundMs - The bound it waited, `pool.connectionTimeoutMs`\n * @param cause - The driver's own error, when the driver raised one\n *\n * @public\n */\nexport function poolWaitTimeoutError(\n boundMs: number,\n cause?: Error\n): DatabaseError {\n return createDatabaseError({\n kind: \"timeout\",\n code: POOL_WAIT_TIMEOUT_CODE,\n message: `Waited ${boundMs} ms for a database connection, and none was free`,\n cause,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const NEXTLY_MIN_DB_VERSIONS = {
|
|
4
|
+
postgresql: {
|
|
5
|
+
major: 15,
|
|
6
|
+
minor: 0
|
|
7
|
+
},
|
|
8
|
+
mysql: {
|
|
9
|
+
major: 8,
|
|
10
|
+
minor: 0
|
|
11
|
+
},
|
|
12
|
+
sqlite: {
|
|
13
|
+
major: 3,
|
|
14
|
+
minor: 38
|
|
15
|
+
}
|
|
8
16
|
};
|
|
9
17
|
var UnsupportedDialectVersionError = class extends Error {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
kind = "unsupported_version";
|
|
19
|
+
dialect;
|
|
20
|
+
detectedVersion;
|
|
21
|
+
requiredVersion;
|
|
22
|
+
cause;
|
|
23
|
+
constructor(args) {
|
|
24
|
+
super(args.message);
|
|
25
|
+
this.name = "UnsupportedDialectVersionError";
|
|
26
|
+
this.dialect = args.dialect;
|
|
27
|
+
this.detectedVersion = args.detectedVersion;
|
|
28
|
+
this.requiredVersion = args.requiredVersion;
|
|
29
|
+
this.cause = args.cause;
|
|
30
|
+
}
|
|
23
31
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
const DOCS_URL = "https://nextlyhq.com/docs/database/support";
|
|
33
|
+
const VARIANT_TOKENS = [
|
|
34
|
+
"mariadb",
|
|
35
|
+
"tidb",
|
|
36
|
+
"aurora",
|
|
37
|
+
"planetscale",
|
|
38
|
+
"vitess"
|
|
31
39
|
];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
const VARIANTS_WITHOUT_FOR_SHARE = /* @__PURE__ */ new Set(["mariadb", "tidb"]);
|
|
41
|
+
/**
|
|
42
|
+
* Whether a MySQL-dialect server accepts `SELECT ... FOR SHARE`: true for
|
|
43
|
+
* MySQL itself and the variants that do, false for MariaDB and TiDB.
|
|
44
|
+
*/
|
|
45
|
+
function acceptsForShare(variant) {
|
|
46
|
+
return variant === null || !VARIANTS_WITHOUT_FOR_SHARE.has(variant);
|
|
47
|
+
}
|
|
48
|
+
const POSTGRES_REGEX = /^PostgreSQL (\d+)\.(\d+)/;
|
|
49
|
+
const MYSQL_REGEX = /^(\d+)\.(\d+)\.(\d+)/;
|
|
50
|
+
const SQLITE_REGEX = /^(\d+)\.(\d+)\.(\d+)/;
|
|
35
51
|
function parsePostgres(raw) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
const match = POSTGRES_REGEX.exec(raw);
|
|
53
|
+
if (!match) return null;
|
|
54
|
+
return {
|
|
55
|
+
major: Number(match[1]),
|
|
56
|
+
minor: Number(match[2])
|
|
57
|
+
};
|
|
39
58
|
}
|
|
40
59
|
function parseMySQL(raw) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
const match = MYSQL_REGEX.exec(raw);
|
|
61
|
+
if (!match) return null;
|
|
62
|
+
return {
|
|
63
|
+
major: Number(match[1]),
|
|
64
|
+
minor: Number(match[2])
|
|
65
|
+
};
|
|
44
66
|
}
|
|
45
67
|
function parseSQLite(raw) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
68
|
+
const match = SQLITE_REGEX.exec(raw);
|
|
69
|
+
if (!match) return null;
|
|
70
|
+
return {
|
|
71
|
+
major: Number(match[1]),
|
|
72
|
+
minor: Number(match[2])
|
|
73
|
+
};
|
|
49
74
|
}
|
|
50
75
|
function detectVariant(raw) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
76
|
+
const lower = raw.toLowerCase();
|
|
77
|
+
for (const token of VARIANT_TOKENS) if (lower.includes(token)) return token;
|
|
78
|
+
return null;
|
|
56
79
|
}
|
|
57
80
|
function meetsMinimum(detected, required) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
if (detected.major > required.major) return true;
|
|
82
|
+
if (detected.major < required.major) return false;
|
|
83
|
+
return detected.minor >= required.minor;
|
|
61
84
|
}
|
|
62
85
|
async function checkDialectVersion(client, dialect, options) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
throw new UnsupportedDialectVersionError({
|
|
98
|
-
dialect,
|
|
99
|
-
detectedVersion: `${parsed.major}.${parsed.minor}`,
|
|
100
|
-
requiredVersion: requiredStr,
|
|
101
|
-
message: `${labels[dialect]} ${requiredStr} required; detected ${parsed.major}.${parsed.minor}. See ${DOCS_URL}.`
|
|
102
|
-
});
|
|
103
|
-
}
|
|
86
|
+
const required = NEXTLY_MIN_DB_VERSIONS[dialect];
|
|
87
|
+
const requiredStr = `${required.major}.${required.minor}+`;
|
|
88
|
+
let raw;
|
|
89
|
+
if (dialect === "sqlite") raw = await querySqliteVersion(client);
|
|
90
|
+
else if (dialect === "postgresql") raw = await queryPostgresVersion(client);
|
|
91
|
+
else raw = await queryMysqlVersion(client);
|
|
92
|
+
const variant = dialect === "mysql" ? detectVariant(raw) : null;
|
|
93
|
+
if (variant) {
|
|
94
|
+
const warning = `Detected ${variant} ('${raw}'). Nextly is regression-tested against real MySQL 8.0+ only; this MySQL-compatible variant is not officially supported in v1 but most operations should work. See ${DOCS_URL}.`;
|
|
95
|
+
if (options?.onWarning) options.onWarning(warning);
|
|
96
|
+
return { variant };
|
|
97
|
+
}
|
|
98
|
+
let parsed;
|
|
99
|
+
if (dialect === "postgresql") parsed = parsePostgres(raw);
|
|
100
|
+
else if (dialect === "mysql") parsed = parseMySQL(raw);
|
|
101
|
+
else parsed = parseSQLite(raw);
|
|
102
|
+
if (!parsed) throw new UnsupportedDialectVersionError({
|
|
103
|
+
dialect,
|
|
104
|
+
detectedVersion: raw,
|
|
105
|
+
requiredVersion: requiredStr,
|
|
106
|
+
message: `Could not parse ${dialect} version from '${raw}'. Nextly requires ${dialect} ${requiredStr}. If you are on a known MySQL-compatible variant we did not detect, please file an issue. See ${DOCS_URL}.`
|
|
107
|
+
});
|
|
108
|
+
if (!meetsMinimum(parsed, required)) throw new UnsupportedDialectVersionError({
|
|
109
|
+
dialect,
|
|
110
|
+
detectedVersion: `${parsed.major}.${parsed.minor}`,
|
|
111
|
+
requiredVersion: requiredStr,
|
|
112
|
+
message: `${{
|
|
113
|
+
postgresql: "PostgreSQL",
|
|
114
|
+
mysql: "MySQL",
|
|
115
|
+
sqlite: "SQLite"
|
|
116
|
+
}[dialect]} ${requiredStr} required; detected ${parsed.major}.${parsed.minor}. See ${DOCS_URL}.`
|
|
117
|
+
});
|
|
118
|
+
return { variant: null };
|
|
104
119
|
}
|
|
105
120
|
async function queryPostgresVersion(client) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const version = row?.version;
|
|
112
|
-
if (typeof version !== "string") {
|
|
113
|
-
throw new Error(
|
|
114
|
-
`Unexpected response shape from SELECT version(): ${JSON.stringify(result)}`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
return version;
|
|
121
|
+
if (!client.query) throw new Error("PostgreSQL client missing query() method");
|
|
122
|
+
const result = await client.query("SELECT version()");
|
|
123
|
+
const version = (result.rows?.[0])?.version;
|
|
124
|
+
if (typeof version !== "string") throw new Error(`Unexpected response shape from SELECT version(): ${JSON.stringify(result)}`);
|
|
125
|
+
return version;
|
|
118
126
|
}
|
|
119
127
|
async function queryMysqlVersion(client) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const version = row?.version;
|
|
126
|
-
if (typeof version !== "string") {
|
|
127
|
-
throw new Error(
|
|
128
|
-
`Unexpected response shape from SELECT VERSION(): ${JSON.stringify(result)}`
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
return version;
|
|
128
|
+
if (!client.query) throw new Error("MySQL client missing query() method");
|
|
129
|
+
const result = await client.query("SELECT VERSION() AS version");
|
|
130
|
+
const version = (result?.[0]?.[0])?.version;
|
|
131
|
+
if (typeof version !== "string") throw new Error(`Unexpected response shape from SELECT VERSION(): ${JSON.stringify(result)}`);
|
|
132
|
+
return version;
|
|
132
133
|
}
|
|
133
134
|
function querySqliteVersion(client) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const version = row?.version;
|
|
140
|
-
if (typeof version !== "string") {
|
|
141
|
-
return Promise.reject(
|
|
142
|
-
new Error(
|
|
143
|
-
`Unexpected response shape from SELECT sqlite_version(): ${JSON.stringify(row)}`
|
|
144
|
-
)
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
return Promise.resolve(version);
|
|
135
|
+
if (!client.prepare) return Promise.reject(/* @__PURE__ */ new Error("SQLite client missing prepare() method"));
|
|
136
|
+
const row = client.prepare("SELECT sqlite_version() AS version").get();
|
|
137
|
+
const version = row?.version;
|
|
138
|
+
if (typeof version !== "string") return Promise.reject(/* @__PURE__ */ new Error(`Unexpected response shape from SELECT sqlite_version(): ${JSON.stringify(row)}`));
|
|
139
|
+
return Promise.resolve(version);
|
|
148
140
|
}
|
|
149
|
-
|
|
150
141
|
exports.NEXTLY_MIN_DB_VERSIONS = NEXTLY_MIN_DB_VERSIONS;
|
|
151
142
|
exports.UnsupportedDialectVersionError = UnsupportedDialectVersionError;
|
|
143
|
+
exports.acceptsForShare = acceptsForShare;
|
|
152
144
|
exports.checkDialectVersion = checkDialectVersion;
|
|
153
|
-
|
|
145
|
+
|
|
154
146
|
//# sourceMappingURL=version-check.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version-check.ts"],"names":[],"mappings":";;;AAmBO,IAAM,sBAAA,GAAyB;AAAA,EACpC,UAAA,EAAY,EAAE,KAAA,EAAO,EAAA,EAAI,OAAO,CAAA,EAAE;AAAA,EAClC,KAAA,EAAO,EAAE,KAAA,EAAO,CAAA,EAAG,OAAO,CAAA,EAAE;AAAA,EAC5B,MAAA,EAAQ,EAAE,KAAA,EAAO,CAAA,EAAG,OAAO,EAAA;AAC7B;AAQO,IAAM,8BAAA,GAAN,cACG,KAAA,CAEV;AAAA,EACkB,IAAA,GAAO,qBAAA;AAAA,EACP,OAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACS,KAAA;AAAA,EAEzB,YAAY,IAAA,EAMT;AACD,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,gCAAA;AACZ,IAAA,IAAA,CAAK,UAAU,IAAA,CAAK,OAAA;AACpB,IAAA,IAAA,CAAK,kBAAkB,IAAA,CAAK,eAAA;AAC5B,IAAA,IAAA,CAAK,kBAAkB,IAAA,CAAK,eAAA;AAC5B,IAAA,IAAA,CAAK,QAAQ,IAAA,CAAK,KAAA;AAAA,EACpB;AACF;AAwBA,IAAM,QAAA,GAAW,4CAAA;AAWjB,IAAM,cAAA,GAAiB;AAAA,EACrB,SAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,aAAA;AAAA,EACA;AACF,CAAA;AAEA,IAAM,cAAA,GAAiB,0BAAA;AACvB,IAA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SAAA,CAAU,GAAG,CAAC,CAAA;AAAA;AAChF,KACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA,CAAQ,QAAQ,OAAO,CAAA;AAChC","file":"version-check.cjs","sourcesContent":["// What: shared connect-time DB version check.\n// Why: each dialect has version-dependent capabilities (RENAME COLUMN on\n// SQLite 3.25+, transactional DDL on MySQL 8+, etc). This helper hard-fails\n// at connect on real dialects below minimum, lets recognized cloud variants\n// (MariaDB, TiDB, Aurora, PlanetScale, Vitess) proceed with a warning, and\n// hard-fails on completely unparseable strings. F17 in the schema\n// architecture plan.\n\n// Why local imports only: adapter-drizzle is upstream of nextly\n// in the dep graph. Importing from nextly here would create a\n// circular dependency. SupportedDialect and DatabaseError already exist\n// in adapter-drizzle's own type system.\nimport type { SupportedDialect } from \"./types\";\nimport type { DatabaseError } from \"./types/error\";\n\n// Why these minimums: PG 15 ships native MERGE + nbtree dedup needed for\n// our schema rename pipeline. MySQL 8.0 ships native RENAME COLUMN.\n// SQLite 3.38 ships strict tables + native unixepoch(). Older versions\n// would force fallback paths that v1 explicitly does not implement.\nexport const NEXTLY_MIN_DB_VERSIONS = {\n postgresql: { major: 15, minor: 0 },\n mysql: { major: 8, minor: 0 },\n sqlite: { major: 3, minor: 38 },\n} as const;\n\n// What: typed error thrown when a real DB version is below minimum or a\n// version string cannot be parsed.\n// Why: implements adapter-drizzle's DatabaseError interface so existing\n// isDatabaseError() type guards work. Stores dialect + detected/required\n// versions on the instance so callers can build upgrade-guidance UI from\n// the error fields without parsing the message.\nexport class UnsupportedDialectVersionError\n extends Error\n implements DatabaseError\n{\n public readonly kind = \"unsupported_version\" as const;\n public readonly dialect: SupportedDialect;\n public readonly detectedVersion: string;\n public readonly requiredVersion: string;\n public override readonly cause?: Error;\n\n constructor(args: {\n dialect: SupportedDialect;\n detectedVersion: string;\n requiredVersion: string;\n message: string;\n cause?: Error;\n }) {\n super(args.message);\n this.name = \"UnsupportedDialectVersionError\";\n this.dialect = args.dialect;\n this.detectedVersion = args.detectedVersion;\n this.requiredVersion = args.requiredVersion;\n this.cause = args.cause;\n }\n}\n\n// What: minimal duck-typed query interface so this helper does not pull in\n// pg / mysql2 / better-sqlite3 types directly.\n// Why: keeps adapter-drizzle dependency-free of the per-dialect drivers.\n// query() returns unknown because Promise<unknown> is already a subtype of\n// unknown; the helper awaits at the call site, which works for both sync\n// and async return shapes.\nexport interface VersionQueryClient {\n query?: (sql: string) => unknown;\n prepare?: (sql: string) => { get: () => unknown };\n}\n\n// What: optional callback so adapters can route the variant warning through\n// their own logger.\n// Why: the helper itself does not depend on a logger module; the adapter\n// owns logger config and is the right place to surface the warning.\nexport interface CheckDialectVersionOptions {\n onWarning?: (message: string) => void;\n}\n\n// What: doc URL embedded in error messages.\n// Why: gives users a single landing page with upgrade instructions per\n// dialect + cloud provider. Filled in PR-2.\nconst DOCS_URL = \"https://nextlyhq.com/docs/database/support\";\n\n// What: recognized MySQL-protocol-compatible variants. Detection of any of\n// these tokens in the version string causes a warning instead of a hard-\n// fail.\n// Why: these databases speak the MySQL wire protocol but use their own\n// version schemes (MariaDB 10.x, TiDB 6.x advertising MySQL 5.7, Aurora's\n// custom suffix). Hard-failing them would lock out a large fraction of\n// real cloud users on first install. We warn so the user knows we have not\n// regression-tested against their variant; we proceed because the wire\n// protocol is compatible enough that most operations work.\nconst VARIANT_TOKENS = [\n \"mariadb\",\n \"tidb\",\n \"aurora\",\n \"planetscale\",\n \"vitess\",\n] as const;\n\nconst POSTGRES_REGEX = /^PostgreSQL (\\d+)\\.(\\d+)/;\nconst MYSQL_REGEX = /^(\\d+)\\.(\\d+)\\.(\\d+)/;\nconst SQLITE_REGEX = /^(\\d+)\\.(\\d+)\\.(\\d+)/;\n\ninterface ParsedVersion {\n major: number;\n minor: number;\n}\n\nfunction parsePostgres(raw: string): ParsedVersion | null {\n const match = POSTGRES_REGEX.exec(raw);\n if (!match) return null;\n return { major: Number(match[1]), minor: Number(match[2]) };\n}\n\nfunction parseMySQL(raw: string): ParsedVersion | null {\n const match = MYSQL_REGEX.exec(raw);\n if (!match) return null;\n return { major: Number(match[1]), minor: Number(match[2]) };\n}\n\nfunction parseSQLite(raw: string): ParsedVersion | null {\n const match = SQLITE_REGEX.exec(raw);\n if (!match) return null;\n return { major: Number(match[1]), minor: Number(match[2]) };\n}\n\nfunction detectVariant(raw: string): string | null {\n const lower = raw.toLowerCase();\n for (const token of VARIANT_TOKENS) {\n if (lower.includes(token)) return token;\n }\n return null;\n}\n\n// What: compares detected version to required minimum.\n// Why: simple major-minor comparison is sufficient; we do not gate on patch.\nfunction meetsMinimum(\n detected: ParsedVersion,\n required: { major: number; minor: number }\n): boolean {\n if (detected.major > required.major) return true;\n if (detected.major < required.major) return false;\n return detected.minor >= required.minor;\n}\n\n// What: queries the DB for its version string and validates it under the\n// hybrid policy.\n// Why: called as the first DB-content step inside each adapter's connect()\n// method.\n//\n// Decision tree:\n// 1. Variant token present (MariaDB/TiDB/Aurora/PlanetScale/Vitess)?\n// -> emit warning via options.onWarning, return successfully.\n// 2. Strict regex matches and version >= minimum?\n// -> return successfully.\n// 3. Strict regex matches but version < minimum?\n// -> throw UnsupportedDialectVersionError (real-DB-too-old path).\n// 4. Strict regex does not match AND no variant token detected?\n// -> throw UnsupportedDialectVersionError (truly unparseable path).\nexport async function checkDialectVersion(\n client: VersionQueryClient,\n dialect: SupportedDialect,\n options?: CheckDialectVersionOptions\n): Promise<void> {\n const required = NEXTLY_MIN_DB_VERSIONS[dialect];\n const requiredStr = `${required.major}.${required.minor}+`;\n\n let raw: string;\n if (dialect === \"sqlite\") {\n raw = await querySqliteVersion(client);\n } else if (dialect === \"postgresql\") {\n raw = await queryPostgresVersion(client);\n } else {\n raw = await queryMysqlVersion(client);\n }\n\n // Step 1: variant check. Only meaningful for MySQL — Postgres-flavored\n // services (Neon, Supabase, RDS PG, Aurora PG) all return canonical\n // \"PostgreSQL X.Y...\" strings and pass the strict regex naturally.\n const variant = dialect === \"mysql\" ? detectVariant(raw) : null;\n if (variant) {\n const warning =\n `Detected ${variant} ('${raw}'). Nextly is regression-tested ` +\n `against real MySQL 8.0+ only; this MySQL-compatible variant is not ` +\n `officially supported in v1 but most operations should work. ` +\n `See ${DOCS_URL}.`;\n if (options?.onWarning) options.onWarning(warning);\n return;\n }\n\n // Step 2/3: strict regex parse for real dialects.\n let parsed: ParsedVersion | null;\n if (dialect === \"postgresql\") parsed = parsePostgres(raw);\n else if (dialect === \"mysql\") parsed = parseMySQL(raw);\n else parsed = parseSQLite(raw);\n\n if (!parsed) {\n // Step 4: truly unparseable. Hard-fail so we surface the issue at boot\n // rather than silently letting the user proceed and hit cryptic errors\n // later.\n throw new UnsupportedDialectVersionError({\n dialect,\n detectedVersion: raw,\n requiredVersion: requiredStr,\n message:\n `Could not parse ${dialect} version from '${raw}'. ` +\n `Nextly requires ${dialect} ${requiredStr}. ` +\n `If you are on a known MySQL-compatible variant we did not detect, ` +\n `please file an issue. See ${DOCS_URL}.`,\n });\n }\n\n if (!meetsMinimum(parsed, required)) {\n const labels: Record<SupportedDialect, string> = {\n postgresql: \"PostgreSQL\",\n mysql: \"MySQL\",\n sqlite: \"SQLite\",\n };\n throw new UnsupportedDialectVersionError({\n dialect,\n detectedVersion: `${parsed.major}.${parsed.minor}`,\n requiredVersion: requiredStr,\n message:\n `${labels[dialect]} ${requiredStr} required; detected ` +\n `${parsed.major}.${parsed.minor}. See ${DOCS_URL}.`,\n });\n }\n}\n\n// What: PG version query.\n// Why: pg's Client/PoolClient.query() returns { rows: [{ version: \"...\" }] }.\nasync function queryPostgresVersion(\n client: VersionQueryClient\n): Promise<string> {\n if (!client.query) {\n throw new Error(\"PostgreSQL client missing query() method\");\n }\n const result = (await client.query(\"SELECT version()\")) as {\n rows?: Array<{ version?: unknown }>;\n };\n const row = result.rows?.[0];\n const version = row?.version;\n if (typeof version !== \"string\") {\n throw new Error(\n `Unexpected response shape from SELECT version(): ${JSON.stringify(result)}`\n );\n }\n return version;\n}\n\n// What: MySQL version query.\n// Why: mysql2's Connection.query() returns [rows, fields] where rows[0]\n// has the column aliased as 'version'.\nasync function queryMysqlVersion(client: VersionQueryClient): Promise<string> {\n if (!client.query) {\n throw new Error(\"MySQL client missing query() method\");\n }\n const result = (await client.query(\"SELECT VERSION() AS version\")) as Array<\n Array<{ version?: unknown }>\n >;\n const row = result?.[0]?.[0];\n const version = row?.version;\n if (typeof version !== \"string\") {\n throw new Error(\n `Unexpected response shape from SELECT VERSION(): ${JSON.stringify(result)}`\n );\n }\n return version;\n}\n\n// What: SQLite version query via better-sqlite3's prepare/get.\n// Why: better-sqlite3 is synchronous, so this is a plain function returning\n// a resolved Promise. The helper awaits it uniformly with PG/MySQL paths.\nfunction querySqliteVersion(client: VersionQueryClient): Promise<string> {\n if (!client.prepare) {\n return Promise.reject(new Error(\"SQLite client missing prepare() method\"));\n }\n const stmt = client.prepare(\"SELECT sqlite_version() AS version\");\n const row = stmt.get() as { version?: unknown } | undefined;\n const version = row?.version;\n if (typeof version !== \"string\") {\n return Promise.reject(\n new Error(\n `Unexpected response shape from SELECT sqlite_version(): ${JSON.stringify(row)}`\n )\n );\n }\n return Promise.resolve(version);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"version-check.cjs","names":[],"sources":["../src/version-check.ts"],"sourcesContent":["// What: shared connect-time DB version check.\n// Why: each dialect has version-dependent capabilities (RENAME COLUMN on\n// SQLite 3.25+, transactional DDL on MySQL 8+, etc). This helper hard-fails\n// at connect on real dialects below minimum, lets recognized cloud variants\n// (MariaDB, TiDB, Aurora, PlanetScale, Vitess) proceed with a warning, and\n// hard-fails on completely unparseable strings. F17 in the schema\n// architecture plan.\n\n// Why local imports only: adapter-drizzle is upstream of nextly\n// in the dep graph. Importing from nextly here would create a\n// circular dependency. SupportedDialect and DatabaseError already exist\n// in adapter-drizzle's own type system.\nimport type { SupportedDialect } from \"./types\";\nimport type { DatabaseError } from \"./types/error\";\n\n// Why these minimums: PG 15 ships native MERGE + nbtree dedup needed for\n// our schema rename pipeline. MySQL 8.0 ships native RENAME COLUMN.\n// SQLite 3.38 ships strict tables + native unixepoch(). Older versions\n// would force fallback paths that v1 explicitly does not implement.\nexport const NEXTLY_MIN_DB_VERSIONS = {\n postgresql: { major: 15, minor: 0 },\n mysql: { major: 8, minor: 0 },\n sqlite: { major: 3, minor: 38 },\n} as const;\n\n// What: typed error thrown when a real DB version is below minimum or a\n// version string cannot be parsed.\n// Why: implements adapter-drizzle's DatabaseError interface so existing\n// isDatabaseError() type guards work. Stores dialect + detected/required\n// versions on the instance so callers can build upgrade-guidance UI from\n// the error fields without parsing the message.\nexport class UnsupportedDialectVersionError\n extends Error\n implements DatabaseError\n{\n public readonly kind = \"unsupported_version\" as const;\n public readonly dialect: SupportedDialect;\n public readonly detectedVersion: string;\n public readonly requiredVersion: string;\n public override readonly cause?: Error;\n\n constructor(args: {\n dialect: SupportedDialect;\n detectedVersion: string;\n requiredVersion: string;\n message: string;\n cause?: Error;\n }) {\n super(args.message);\n this.name = \"UnsupportedDialectVersionError\";\n this.dialect = args.dialect;\n this.detectedVersion = args.detectedVersion;\n this.requiredVersion = args.requiredVersion;\n this.cause = args.cause;\n }\n}\n\n// What: minimal duck-typed query interface so this helper does not pull in\n// pg / mysql2 / better-sqlite3 types directly.\n// Why: keeps adapter-drizzle dependency-free of the per-dialect drivers.\n// query() returns unknown because Promise<unknown> is already a subtype of\n// unknown; the helper awaits at the call site, which works for both sync\n// and async return shapes.\nexport interface VersionQueryClient {\n query?: (sql: string) => unknown;\n prepare?: (sql: string) => { get: () => unknown };\n}\n\n// What: optional callback so adapters can route the variant warning through\n// their own logger.\n// Why: the helper itself does not depend on a logger module; the adapter\n// owns logger config and is the right place to surface the warning.\nexport interface CheckDialectVersionOptions {\n onWarning?: (message: string) => void;\n}\n\n// What: doc URL embedded in error messages.\n// Why: gives users a single landing page with upgrade instructions per\n// dialect + cloud provider. Filled in PR-2.\nconst DOCS_URL = \"https://nextlyhq.com/docs/database/support\";\n\n// What: recognized MySQL-protocol-compatible variants. Detection of any of\n// these tokens in the version string causes a warning instead of a hard-\n// fail.\n// Why: these databases speak the MySQL wire protocol but use their own\n// version schemes (MariaDB 10.x, TiDB 6.x advertising MySQL 5.7, Aurora's\n// custom suffix). Hard-failing them would lock out a large fraction of\n// real cloud users on first install. We warn so the user knows we have not\n// regression-tested against their variant; we proceed because the wire\n// protocol is compatible enough that most operations work.\nconst VARIANT_TOKENS = [\n \"mariadb\",\n \"tidb\",\n \"aurora\",\n \"planetscale\",\n \"vitess\",\n] as const;\n\n/** A MySQL-compatible server the version string names. */\nexport type DialectVariant = (typeof VARIANT_TOKENS)[number];\n\n/** What the version check learned about the server it connected to. */\nexport interface DialectVersionInfo {\n /**\n * The MySQL-compatible variant the version string names, or null for the\n * dialect's own server (and always null on PostgreSQL and SQLite).\n */\n variant: DialectVariant | null;\n}\n\n// What: the variants that reject `SELECT ... FOR SHARE` as a syntax error.\n// Why: MariaDB spells the shared lock `LOCK IN SHARE MODE` only, and TiDB\n// refuses both spellings unless its no-op functions are switched on. MySQL\n// 8, Aurora MySQL and Vitess/PlanetScale accept `FOR SHARE`.\nconst VARIANTS_WITHOUT_FOR_SHARE: ReadonlySet<DialectVariant> = new Set([\n \"mariadb\",\n \"tidb\",\n]);\n\n/**\n * Whether a MySQL-dialect server accepts `SELECT ... FOR SHARE`: true for\n * MySQL itself and the variants that do, false for MariaDB and TiDB.\n */\nexport function acceptsForShare(variant: DialectVariant | null): boolean {\n return variant === null || !VARIANTS_WITHOUT_FOR_SHARE.has(variant);\n}\n\nconst POSTGRES_REGEX = /^PostgreSQL (\\d+)\\.(\\d+)/;\nconst MYSQL_REGEX = /^(\\d+)\\.(\\d+)\\.(\\d+)/;\nconst SQLITE_REGEX = /^(\\d+)\\.(\\d+)\\.(\\d+)/;\n\ninterface ParsedVersion {\n major: number;\n minor: number;\n}\n\nfunction parsePostgres(raw: string): ParsedVersion | null {\n const match = POSTGRES_REGEX.exec(raw);\n if (!match) return null;\n return { major: Number(match[1]), minor: Number(match[2]) };\n}\n\nfunction parseMySQL(raw: string): ParsedVersion | null {\n const match = MYSQL_REGEX.exec(raw);\n if (!match) return null;\n return { major: Number(match[1]), minor: Number(match[2]) };\n}\n\nfunction parseSQLite(raw: string): ParsedVersion | null {\n const match = SQLITE_REGEX.exec(raw);\n if (!match) return null;\n return { major: Number(match[1]), minor: Number(match[2]) };\n}\n\nfunction detectVariant(raw: string): DialectVariant | null {\n const lower = raw.toLowerCase();\n for (const token of VARIANT_TOKENS) {\n if (lower.includes(token)) return token;\n }\n return null;\n}\n\n// What: compares detected version to required minimum.\n// Why: simple major-minor comparison is sufficient; we do not gate on patch.\nfunction meetsMinimum(\n detected: ParsedVersion,\n required: { major: number; minor: number }\n): boolean {\n if (detected.major > required.major) return true;\n if (detected.major < required.major) return false;\n return detected.minor >= required.minor;\n}\n\n// What: queries the DB for its version string and validates it under the\n// hybrid policy.\n// Why: called as the first DB-content step inside each adapter's connect()\n// method.\n//\n// Decision tree:\n// 1. Variant token present (MariaDB/TiDB/Aurora/PlanetScale/Vitess)?\n// -> emit warning via options.onWarning, return the variant.\n// 2. Strict regex matches and version >= minimum?\n// -> return successfully.\n// 3. Strict regex matches but version < minimum?\n// -> throw UnsupportedDialectVersionError (real-DB-too-old path).\n// 4. Strict regex does not match AND no variant token detected?\n// -> throw UnsupportedDialectVersionError (truly unparseable path).\nexport async function checkDialectVersion(\n client: VersionQueryClient,\n dialect: SupportedDialect,\n options?: CheckDialectVersionOptions\n): Promise<DialectVersionInfo> {\n const required = NEXTLY_MIN_DB_VERSIONS[dialect];\n const requiredStr = `${required.major}.${required.minor}+`;\n\n let raw: string;\n if (dialect === \"sqlite\") {\n raw = await querySqliteVersion(client);\n } else if (dialect === \"postgresql\") {\n raw = await queryPostgresVersion(client);\n } else {\n raw = await queryMysqlVersion(client);\n }\n\n // Step 1: variant check. Only meaningful for MySQL — Postgres-flavored\n // services (Neon, Supabase, RDS PG, Aurora PG) all return canonical\n // \"PostgreSQL X.Y...\" strings and pass the strict regex naturally.\n const variant = dialect === \"mysql\" ? detectVariant(raw) : null;\n if (variant) {\n const warning =\n `Detected ${variant} ('${raw}'). Nextly is regression-tested ` +\n `against real MySQL 8.0+ only; this MySQL-compatible variant is not ` +\n `officially supported in v1 but most operations should work. ` +\n `See ${DOCS_URL}.`;\n if (options?.onWarning) options.onWarning(warning);\n return { variant };\n }\n\n // Step 2/3: strict regex parse for real dialects.\n let parsed: ParsedVersion | null;\n if (dialect === \"postgresql\") parsed = parsePostgres(raw);\n else if (dialect === \"mysql\") parsed = parseMySQL(raw);\n else parsed = parseSQLite(raw);\n\n if (!parsed) {\n // Step 4: truly unparseable. Hard-fail so we surface the issue at boot\n // rather than silently letting the user proceed and hit cryptic errors\n // later.\n throw new UnsupportedDialectVersionError({\n dialect,\n detectedVersion: raw,\n requiredVersion: requiredStr,\n message:\n `Could not parse ${dialect} version from '${raw}'. ` +\n `Nextly requires ${dialect} ${requiredStr}. ` +\n `If you are on a known MySQL-compatible variant we did not detect, ` +\n `please file an issue. See ${DOCS_URL}.`,\n });\n }\n\n if (!meetsMinimum(parsed, required)) {\n const labels: Record<SupportedDialect, string> = {\n postgresql: \"PostgreSQL\",\n mysql: \"MySQL\",\n sqlite: \"SQLite\",\n };\n throw new UnsupportedDialectVersionError({\n dialect,\n detectedVersion: `${parsed.major}.${parsed.minor}`,\n requiredVersion: requiredStr,\n message:\n `${labels[dialect]} ${requiredStr} required; detected ` +\n `${parsed.major}.${parsed.minor}. See ${DOCS_URL}.`,\n });\n }\n return { variant: null };\n}\n\n// What: PG version query.\n// Why: pg's Client/PoolClient.query() returns { rows: [{ version: \"...\" }] }.\nasync function queryPostgresVersion(\n client: VersionQueryClient\n): Promise<string> {\n if (!client.query) {\n throw new Error(\"PostgreSQL client missing query() method\");\n }\n const result = (await client.query(\"SELECT version()\")) as {\n rows?: Array<{ version?: unknown }>;\n };\n const row = result.rows?.[0];\n const version = row?.version;\n if (typeof version !== \"string\") {\n throw new Error(\n `Unexpected response shape from SELECT version(): ${JSON.stringify(result)}`\n );\n }\n return version;\n}\n\n// What: MySQL version query.\n// Why: mysql2's Connection.query() returns [rows, fields] where rows[0]\n// has the column aliased as 'version'.\nasync function queryMysqlVersion(client: VersionQueryClient): Promise<string> {\n if (!client.query) {\n throw new Error(\"MySQL client missing query() method\");\n }\n const result = (await client.query(\"SELECT VERSION() AS version\")) as Array<\n Array<{ version?: unknown }>\n >;\n const row = result?.[0]?.[0];\n const version = row?.version;\n if (typeof version !== \"string\") {\n throw new Error(\n `Unexpected response shape from SELECT VERSION(): ${JSON.stringify(result)}`\n );\n }\n return version;\n}\n\n// What: SQLite version query via better-sqlite3's prepare/get.\n// Why: better-sqlite3 is synchronous, so this is a plain function returning\n// a resolved Promise. The helper awaits it uniformly with PG/MySQL paths.\nfunction querySqliteVersion(client: VersionQueryClient): Promise<string> {\n if (!client.prepare) {\n return Promise.reject(new Error(\"SQLite client missing prepare() method\"));\n }\n const stmt = client.prepare(\"SELECT sqlite_version() AS version\");\n const row = stmt.get() as { version?: unknown } | undefined;\n const version = row?.version;\n if (typeof version !== \"string\") {\n return Promise.reject(\n new Error(\n `Unexpected response shape from SELECT sqlite_version(): ${JSON.stringify(row)}`\n )\n );\n }\n return Promise.resolve(version);\n}\n"],"mappings":";;AAmBA,MAAa,yBAAyB;CACpC,YAAY;EAAE,OAAO;EAAI,OAAO;CAAE;CAClC,OAAO;EAAE,OAAO;EAAG,OAAO;CAAE;CAC5B,QAAQ;EAAE,OAAO;EAAG,OAAO;CAAG;AAChC;AAQA,IAAa,iCAAb,cACU,MAEV;CACE,OAAuB;CACvB;CACA;CACA;CACA;CAEA,YAAY,MAMT;EACD,MAAM,KAAK,OAAO;EAClB,KAAK,OAAO;EACZ,KAAK,UAAU,KAAK;EACpB,KAAK,kBAAkB,KAAK;EAC5B,KAAK,kBAAkB,KAAK;EAC5B,KAAK,QAAQ,KAAK;CACpB;AACF;AAwBA,MAAM,WAAW;AAWjB,MAAM,iBAAiB;CACrB;CACA;CACA;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qC;CAEvD,MAAM,SAAU,MAAM,OAAO,MAAM,6BAA6B;CAIhE,MAAM,WADM,SAAS,EAAE,GAAG,GAAA,EACL;CACrB,IAAI,OAAO,YAAY,UACrB,MAAM,IAAI,MACR,oDAAoD,KAAK,UAAU,MAAM,GAC3E;CAEF,OAAO;AACT;AAKA,SAAS,mBAAmB,QAA6C;CACvE,IAAI,CAAC,OAAO,SACV,OAAO,QAAQ,uBAAO,IAAI,MAAM,wCAAwC,CAAC;CAG3E,MAAM,MADO,OAAO,QAAQ,oCACb,CAAC,CAAC,IAAI;CACrB,MAAM,UAAU,KAAK;CACrB,IAAI,OAAO,YAAY,UACrB,OAAO,QAAQ,uBACb,IAAI,MACF,2DAA2D,KAAK,UAAU,GAAG,GAC/E,CACF;CAEF,OAAO,QAAQ,QAAQ,OAAO;AAChC"}
|
package/dist/version-check.d.cts
CHANGED
|
@@ -1,43 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
readonly
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
readonly
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
readonly
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
1
|
+
import { p as SupportedDialect } from "./schema-Bkkr3JMC.cjs";
|
|
2
|
+
import { c as DatabaseError } from "./index-C4HJsfwA.cjs";
|
|
3
|
+
export declare const NEXTLY_MIN_DB_VERSIONS: {
|
|
4
|
+
readonly postgresql: {
|
|
5
|
+
readonly major: 15;
|
|
6
|
+
readonly minor: 0;
|
|
7
|
+
};
|
|
8
|
+
readonly mysql: {
|
|
9
|
+
readonly major: 8;
|
|
10
|
+
readonly minor: 0;
|
|
11
|
+
};
|
|
12
|
+
readonly sqlite: {
|
|
13
|
+
readonly major: 3;
|
|
14
|
+
readonly minor: 38;
|
|
15
|
+
};
|
|
17
16
|
};
|
|
18
|
-
declare class UnsupportedDialectVersionError extends Error implements DatabaseError {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
export declare class UnsupportedDialectVersionError extends Error implements DatabaseError {
|
|
18
|
+
readonly kind: "unsupported_version";
|
|
19
|
+
readonly dialect: SupportedDialect;
|
|
20
|
+
readonly detectedVersion: string;
|
|
21
|
+
readonly requiredVersion: string;
|
|
22
|
+
override readonly cause?: Error;
|
|
23
|
+
constructor(args: {
|
|
24
|
+
dialect: SupportedDialect;
|
|
25
|
+
detectedVersion: string;
|
|
26
|
+
requiredVersion: string;
|
|
27
|
+
message: string;
|
|
28
|
+
cause?: Error;
|
|
29
|
+
});
|
|
31
30
|
}
|
|
32
|
-
interface VersionQueryClient {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
export interface VersionQueryClient {
|
|
32
|
+
query?: (sql: string) => unknown;
|
|
33
|
+
prepare?: (sql: string) => {
|
|
34
|
+
get: () => unknown;
|
|
35
|
+
};
|
|
37
36
|
}
|
|
38
|
-
interface CheckDialectVersionOptions {
|
|
39
|
-
|
|
37
|
+
export interface CheckDialectVersionOptions {
|
|
38
|
+
onWarning?: (message: string) => void;
|
|
40
39
|
}
|
|
41
|
-
declare
|
|
42
|
-
|
|
43
|
-
export
|
|
40
|
+
declare const VARIANT_TOKENS: readonly ["mariadb", "tidb", "aurora", "planetscale", "vitess"];
|
|
41
|
+
/** A MySQL-compatible server the version string names. */
|
|
42
|
+
export type DialectVariant = (typeof VARIANT_TOKENS)[number];
|
|
43
|
+
/** What the version check learned about the server it connected to. */
|
|
44
|
+
export interface DialectVersionInfo {
|
|
45
|
+
/**
|
|
46
|
+
* The MySQL-compatible variant the version string names, or null for the
|
|
47
|
+
* dialect's own server (and always null on PostgreSQL and SQLite).
|
|
48
|
+
*/
|
|
49
|
+
variant: DialectVariant | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether a MySQL-dialect server accepts `SELECT ... FOR SHARE`: true for
|
|
53
|
+
* MySQL itself and the variants that do, false for MariaDB and TiDB.
|
|
54
|
+
*/
|
|
55
|
+
export declare function acceptsForShare(variant: DialectVariant | null): boolean;
|
|
56
|
+
export declare function checkDialectVersion(client: VersionQueryClient, dialect: SupportedDialect, options?: CheckDialectVersionOptions): Promise<DialectVersionInfo>;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=version-check.d.cts.map
|