@nextlyhq/adapter-drizzle 0.0.2-alpha.67 → 0.0.2-alpha.69
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-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 +2258 -2183
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -10
- package/dist/index.d.ts +5 -10
- package/dist/index.mjs +2257 -2181
- 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 -110
- package/dist/migrations.d.ts +93 -110
- 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 +34 -12
- package/dist/schema-name.cjs.map +1 -1
- package/dist/schema-name.d.cts +3 -15
- package/dist/schema-name.d.ts +3 -15
- package/dist/schema-name.mjs +33 -10
- package/dist/schema-name.mjs.map +1 -1
- package/dist/text-match.cjs +42 -8
- package/dist/text-match.cjs.map +1 -1
- package/dist/text-match.d.cts +4 -16
- package/dist/text-match.d.ts +4 -16
- package/dist/text-match.mjs +41 -6
- package/dist/text-match.mjs.map +1 -1
- package/dist/types/index.cjs +8 -69
- package/dist/types/index.d.cts +3 -225
- package/dist/types/index.d.ts +3 -225
- package/dist/types/index.mjs +1 -64
- 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 +116 -133
- package/dist/version-check.cjs.map +1 -1
- package/dist/version-check.d.cts +46 -47
- package/dist/version-check.d.ts +46 -47
- package/dist/version-check.mjs +115 -131
- package/dist/version-check.mjs.map +1 -1
- package/package.json +12 -16
- package/dist/adapter-bUAaPzjV.d.cts +0 -1143
- package/dist/adapter-iJ5hbUvL.d.ts +0 -1143
- package/dist/core-CVO7WYDj.d.cts +0 -74
- package/dist/core-CVO7WYDj.d.ts +0 -74
- package/dist/error-BrdknH2s.d.cts +0 -122
- package/dist/error-BrdknH2s.d.ts +0 -122
- package/dist/migration-BqHebSwM.d.ts +0 -831
- package/dist/migration-Bu0WLdX4.d.cts +0 -831
- 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,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the Nextly database adapter system.
|
|
3
|
+
*
|
|
4
|
+
* These types are the foundation for all database operations and are designed
|
|
5
|
+
* to be database-agnostic while supporting dialect-specific features.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Supported database dialects.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* These are the database systems that Nextly officially supports through
|
|
14
|
+
* dedicated adapter packages.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
type SupportedDialect = "postgresql" | "mysql" | "sqlite";
|
|
19
|
+
/**
|
|
20
|
+
* SQL parameter types that are safe to use across all database dialects.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* - `undefined` is included for optional parameters
|
|
24
|
+
* - `Date` objects will be converted to appropriate format per dialect
|
|
25
|
+
* - `null` represents SQL NULL
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
type SqlParam = string | number | boolean | Date | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* JSON value types that can be stored in JSON/JSONB columns.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Represents the valid JSON value types as defined by the JSON specification.
|
|
35
|
+
* This is a recursive type to support nested objects and arrays.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
40
|
+
[key: string]: JsonValue;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* JSON object type for structured data.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* Useful for typed JSON column data where the structure is known.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
type JsonObject = {
|
|
51
|
+
[key: string]: JsonValue;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* JSON array type.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
type JsonArray = JsonValue[];
|
|
59
|
+
/**
|
|
60
|
+
* Interface for resolving table names to Drizzle table objects.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* When a TableResolver is set on the adapter via `setTableResolver()`,
|
|
64
|
+
* CRUD methods will use Drizzle's query API instead of raw SQL string building.
|
|
65
|
+
* The nextly SchemaRegistry implements this interface.
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
interface TableResolver {
|
|
70
|
+
/** Look up a Drizzle table object by table name. Returns null if not found. */
|
|
71
|
+
getTable(tableName: string): unknown;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Column definition for schema operations.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Defines the structure of a database column in a database-agnostic way.
|
|
78
|
+
* Adapters translate these definitions to dialect-specific DDL.
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
interface ColumnDefinition {
|
|
83
|
+
/** Column name */
|
|
84
|
+
name: string;
|
|
85
|
+
/**
|
|
86
|
+
* Column data type.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* Common types across databases:
|
|
90
|
+
* - Text: varchar(n), text, char(n)
|
|
91
|
+
* - Numbers: int, bigint, decimal, numeric
|
|
92
|
+
* - Boolean: boolean
|
|
93
|
+
* - Date/Time: timestamp, date, time
|
|
94
|
+
* - JSON: json, jsonb (PostgreSQL)
|
|
95
|
+
* - UUID: uuid (PostgreSQL), char(36) (MySQL/SQLite)
|
|
96
|
+
*
|
|
97
|
+
* Adapters handle dialect-specific type mapping.
|
|
98
|
+
*/
|
|
99
|
+
type: string;
|
|
100
|
+
/** Allow NULL values (default: true) */
|
|
101
|
+
nullable?: boolean;
|
|
102
|
+
/** Primary key column */
|
|
103
|
+
primaryKey?: boolean;
|
|
104
|
+
/** Unique constraint */
|
|
105
|
+
unique?: boolean;
|
|
106
|
+
/** Default value (literal or SQL expression) */
|
|
107
|
+
default?: SqlParam | {
|
|
108
|
+
sql: string;
|
|
109
|
+
};
|
|
110
|
+
/** Foreign key reference */
|
|
111
|
+
references?: {
|
|
112
|
+
/** Referenced table name */
|
|
113
|
+
table: string;
|
|
114
|
+
/** Referenced column name */
|
|
115
|
+
column: string;
|
|
116
|
+
/** Action on DELETE */
|
|
117
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
118
|
+
/** Action on UPDATE */
|
|
119
|
+
onUpdate?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
120
|
+
};
|
|
121
|
+
/** Check constraint expression */
|
|
122
|
+
check?: string;
|
|
123
|
+
/** Generated column definition (computed column) */
|
|
124
|
+
generated?: {
|
|
125
|
+
/** SQL expression to generate the value */
|
|
126
|
+
as: string;
|
|
127
|
+
/** Store the value (true) or compute on-the-fly (false) */
|
|
128
|
+
stored?: boolean;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Index definition for schema operations.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* Defines database indexes for performance optimization.
|
|
136
|
+
*
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
interface IndexDefinition {
|
|
140
|
+
/** Index name */
|
|
141
|
+
name: string;
|
|
142
|
+
/** Columns included in the index */
|
|
143
|
+
columns: string[];
|
|
144
|
+
/** Unique index (enforces uniqueness) */
|
|
145
|
+
unique?: boolean;
|
|
146
|
+
/** Partial index condition (WHERE clause) */
|
|
147
|
+
where?: string;
|
|
148
|
+
/** Index type (database-specific) */
|
|
149
|
+
using?: "btree" | "hash" | "gin" | "gist" | "brin";
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Table constraint definition.
|
|
153
|
+
*
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
interface TableConstraint {
|
|
157
|
+
/** Constraint name */
|
|
158
|
+
name: string;
|
|
159
|
+
/** Constraint type */
|
|
160
|
+
type: "unique" | "check" | "foreign_key" | "primary_key";
|
|
161
|
+
/** Columns involved in the constraint */
|
|
162
|
+
columns?: string[];
|
|
163
|
+
/** Check constraint expression */
|
|
164
|
+
expression?: string;
|
|
165
|
+
/** Foreign key reference (for foreign_key type) */
|
|
166
|
+
references?: {
|
|
167
|
+
/** Referenced table name */
|
|
168
|
+
table: string;
|
|
169
|
+
/** Referenced columns */
|
|
170
|
+
columns: string[];
|
|
171
|
+
/** Action on DELETE */
|
|
172
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
173
|
+
/** Action on UPDATE */
|
|
174
|
+
onUpdate?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Complete table definition.
|
|
179
|
+
*
|
|
180
|
+
* @remarks
|
|
181
|
+
* Defines the complete structure of a database table including columns,
|
|
182
|
+
* indexes, and constraints.
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
interface TableDefinition {
|
|
187
|
+
/** Table name */
|
|
188
|
+
name: string;
|
|
189
|
+
/** Column definitions */
|
|
190
|
+
columns: ColumnDefinition[];
|
|
191
|
+
/** Composite primary key (if not defined at column level) */
|
|
192
|
+
primaryKey?: string[];
|
|
193
|
+
/** Index definitions */
|
|
194
|
+
indexes?: IndexDefinition[];
|
|
195
|
+
/** Table-level constraints */
|
|
196
|
+
constraints?: TableConstraint[];
|
|
197
|
+
/** Table comment/description */
|
|
198
|
+
comment?: string;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Options for table creation.
|
|
202
|
+
*
|
|
203
|
+
* @public
|
|
204
|
+
*/
|
|
205
|
+
interface CreateTableOptions {
|
|
206
|
+
/** Don't throw error if table exists */
|
|
207
|
+
ifNotExists?: boolean;
|
|
208
|
+
/** Temporary table (session-scoped) */
|
|
209
|
+
temporary?: boolean;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Options for table dropping.
|
|
213
|
+
*
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
216
|
+
interface DropTableOptions {
|
|
217
|
+
/** Don't throw error if table doesn't exist */
|
|
218
|
+
ifExists?: boolean;
|
|
219
|
+
/** Drop dependent objects (CASCADE) */
|
|
220
|
+
cascade?: boolean;
|
|
221
|
+
/** Restrict drop if dependencies exist (default) */
|
|
222
|
+
restrict?: boolean;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Options for table alteration.
|
|
226
|
+
*
|
|
227
|
+
* @public
|
|
228
|
+
*/
|
|
229
|
+
interface AlterTableOptions {
|
|
230
|
+
/** Validation mode for constraints */
|
|
231
|
+
validate?: boolean;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Table alteration operations.
|
|
235
|
+
*
|
|
236
|
+
* @remarks
|
|
237
|
+
* Defines the types of operations that can be performed when altering a table.
|
|
238
|
+
*
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
type AlterTableOperation = {
|
|
242
|
+
kind: "add_column";
|
|
243
|
+
column: ColumnDefinition;
|
|
244
|
+
} | {
|
|
245
|
+
kind: "drop_column";
|
|
246
|
+
columnName: string;
|
|
247
|
+
cascade?: boolean;
|
|
248
|
+
} | {
|
|
249
|
+
kind: "rename_column";
|
|
250
|
+
from: string;
|
|
251
|
+
to: string;
|
|
252
|
+
} | {
|
|
253
|
+
kind: "modify_column";
|
|
254
|
+
column: ColumnDefinition;
|
|
255
|
+
} | {
|
|
256
|
+
kind: "add_constraint";
|
|
257
|
+
constraint: TableConstraint;
|
|
258
|
+
} | {
|
|
259
|
+
kind: "drop_constraint";
|
|
260
|
+
constraintName: string;
|
|
261
|
+
cascade?: boolean;
|
|
262
|
+
};
|
|
263
|
+
export { DropTableOptions as a, TableDefinition as c, JsonValue as d, SqlParam as f, CreateTableOptions as i, JsonArray as l, TableResolver as m, AlterTableOptions as n, IndexDefinition as o, SupportedDialect as p, ColumnDefinition as r, TableConstraint as s, AlterTableOperation as t, JsonObject as u };
|
|
264
|
+
//# sourceMappingURL=schema-Bkkr3JMC.d.ts.map
|
package/dist/schema-name.cjs
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
2
|
// src/schema-name.ts
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The one rule for a PostgreSQL schema name.
|
|
5
|
+
*
|
|
6
|
+
* Lives in the adapter package because both sides need it and neither may
|
|
7
|
+
* import the other: `nextly` validates the configured value at boot so the
|
|
8
|
+
* error names the setting, and the Postgres adapter validates again at the
|
|
9
|
+
* point of interpolation, because that is where a bad value becomes SQL.
|
|
10
|
+
*
|
|
11
|
+
* @module schema-name
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* A plain, lower-case identifier.
|
|
16
|
+
*
|
|
17
|
+
* Checked rather than quoted because the value is interpolated into
|
|
18
|
+
* `search_path` and `CREATE SCHEMA`, where a quoted-but-hostile name is still
|
|
19
|
+
* a name somebody else chose. Refusing the shapes that need quoting costs
|
|
20
|
+
* nothing real and removes the question entirely.
|
|
21
|
+
*/
|
|
22
|
+
const IDENTIFIER = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
23
|
+
/** Whether this is a name the adapter will interpolate. */
|
|
5
24
|
function isValidSchemaName(name) {
|
|
6
|
-
|
|
25
|
+
return IDENTIFIER.test(name) && !name.startsWith("pg_");
|
|
7
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Return the name, or throw rather than interpolate something unchecked.
|
|
29
|
+
*
|
|
30
|
+
* The adapter throws a plain Error: it has no access to the config path that
|
|
31
|
+
* produced the value, and `nextly` already refuses the same shapes at boot
|
|
32
|
+
* with a message that names `db.postgres.schema`. This is the backstop for a
|
|
33
|
+
* caller that constructed the adapter directly.
|
|
34
|
+
*/
|
|
8
35
|
function assertSchemaName(name) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`Invalid PostgreSQL schema name "${name}". Use lower-case letters, digits and underscores, starting with a letter or underscore (max 63 characters), and not beginning with "pg_".`
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
return name;
|
|
36
|
+
if (!isValidSchemaName(name)) throw new Error(`Invalid PostgreSQL schema name "${name}". Use lower-case letters, digits and underscores, starting with a letter or underscore (max 63 characters), and not beginning with "pg_".`);
|
|
37
|
+
return name;
|
|
15
38
|
}
|
|
16
|
-
|
|
17
39
|
exports.assertSchemaName = assertSchemaName;
|
|
18
40
|
exports.isValidSchemaName = isValidSchemaName;
|
|
19
|
-
|
|
41
|
+
|
|
20
42
|
//# sourceMappingURL=schema-name.cjs.map
|
package/dist/schema-name.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"schema-name.cjs","names":[],"sources":["../src/schema-name.ts"],"sourcesContent":["/**\n * The one rule for a PostgreSQL schema name.\n *\n * Lives in the adapter package because both sides need it and neither may\n * import the other: `nextly` validates the configured value at boot so the\n * error names the setting, and the Postgres adapter validates again at the\n * point of interpolation, because that is where a bad value becomes SQL.\n *\n * @module schema-name\n * @since 1.0.0\n */\n\n/**\n * A plain, lower-case identifier.\n *\n * Checked rather than quoted because the value is interpolated into\n * `search_path` and `CREATE SCHEMA`, where a quoted-but-hostile name is still\n * a name somebody else chose. Refusing the shapes that need quoting costs\n * nothing real and removes the question entirely.\n */\nconst IDENTIFIER = /^[a-z_][a-z0-9_]{0,62}$/;\n\n/** Whether this is a name the adapter will interpolate. */\nexport function isValidSchemaName(name: string): boolean {\n // `pg_` is PostgreSQL's reserved prefix for system catalogs.\n return IDENTIFIER.test(name) && !name.startsWith(\"pg_\");\n}\n\n/**\n * Return the name, or throw rather than interpolate something unchecked.\n *\n * The adapter throws a plain Error: it has no access to the config path that\n * produced the value, and `nextly` already refuses the same shapes at boot\n * with a message that names `db.postgres.schema`. This is the backstop for a\n * caller that constructed the adapter directly.\n */\nexport function assertSchemaName(name: string): string {\n if (!isValidSchemaName(name)) {\n throw new Error(\n `Invalid PostgreSQL schema name \"${name}\". Use lower-case letters, digits and underscores, starting with a letter or underscore (max 63 characters), and not beginning with \"pg_\".`\n );\n }\n return name;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,aAAa;;AAGnB,SAAgB,kBAAkB,MAAuB;CAEvD,OAAO,WAAW,KAAK,IAAI,KAAK,CAAC,KAAK,WAAW,KAAK;AACxD;;;;;;;;;AAUA,SAAgB,iBAAiB,MAAsB;CACrD,IAAI,CAAC,kBAAkB,IAAI,GACzB,MAAM,IAAI,MACR,mCAAmC,KAAK,2IAC1C;CAEF,OAAO;AACT"}
|
package/dist/schema-name.d.cts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The one rule for a PostgreSQL schema name.
|
|
3
|
-
*
|
|
4
|
-
* Lives in the adapter package because both sides need it and neither may
|
|
5
|
-
* import the other: `nextly` validates the configured value at boot so the
|
|
6
|
-
* error names the setting, and the Postgres adapter validates again at the
|
|
7
|
-
* point of interpolation, because that is where a bad value becomes SQL.
|
|
8
|
-
*
|
|
9
|
-
* @module schema-name
|
|
10
|
-
* @since 1.0.0
|
|
11
|
-
*/
|
|
12
1
|
/** Whether this is a name the adapter will interpolate. */
|
|
13
|
-
declare function isValidSchemaName(name: string): boolean;
|
|
2
|
+
export declare function isValidSchemaName(name: string): boolean;
|
|
14
3
|
/**
|
|
15
4
|
* Return the name, or throw rather than interpolate something unchecked.
|
|
16
5
|
*
|
|
@@ -19,6 +8,5 @@ declare function isValidSchemaName(name: string): boolean;
|
|
|
19
8
|
* with a message that names `db.postgres.schema`. This is the backstop for a
|
|
20
9
|
* caller that constructed the adapter directly.
|
|
21
10
|
*/
|
|
22
|
-
declare function assertSchemaName(name: string): string;
|
|
23
|
-
|
|
24
|
-
export { assertSchemaName, isValidSchemaName };
|
|
11
|
+
export declare function assertSchemaName(name: string): string;
|
|
12
|
+
//# sourceMappingURL=schema-name.d.cts.map
|
package/dist/schema-name.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The one rule for a PostgreSQL schema name.
|
|
3
|
-
*
|
|
4
|
-
* Lives in the adapter package because both sides need it and neither may
|
|
5
|
-
* import the other: `nextly` validates the configured value at boot so the
|
|
6
|
-
* error names the setting, and the Postgres adapter validates again at the
|
|
7
|
-
* point of interpolation, because that is where a bad value becomes SQL.
|
|
8
|
-
*
|
|
9
|
-
* @module schema-name
|
|
10
|
-
* @since 1.0.0
|
|
11
|
-
*/
|
|
12
1
|
/** Whether this is a name the adapter will interpolate. */
|
|
13
|
-
declare function isValidSchemaName(name: string): boolean;
|
|
2
|
+
export declare function isValidSchemaName(name: string): boolean;
|
|
14
3
|
/**
|
|
15
4
|
* Return the name, or throw rather than interpolate something unchecked.
|
|
16
5
|
*
|
|
@@ -19,6 +8,5 @@ declare function isValidSchemaName(name: string): boolean;
|
|
|
19
8
|
* with a message that names `db.postgres.schema`. This is the backstop for a
|
|
20
9
|
* caller that constructed the adapter directly.
|
|
21
10
|
*/
|
|
22
|
-
declare function assertSchemaName(name: string): string;
|
|
23
|
-
|
|
24
|
-
export { assertSchemaName, isValidSchemaName };
|
|
11
|
+
export declare function assertSchemaName(name: string): string;
|
|
12
|
+
//# sourceMappingURL=schema-name.d.ts.map
|
package/dist/schema-name.mjs
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
// src/schema-name.ts
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The one rule for a PostgreSQL schema name.
|
|
4
|
+
*
|
|
5
|
+
* Lives in the adapter package because both sides need it and neither may
|
|
6
|
+
* import the other: `nextly` validates the configured value at boot so the
|
|
7
|
+
* error names the setting, and the Postgres adapter validates again at the
|
|
8
|
+
* point of interpolation, because that is where a bad value becomes SQL.
|
|
9
|
+
*
|
|
10
|
+
* @module schema-name
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* A plain, lower-case identifier.
|
|
15
|
+
*
|
|
16
|
+
* Checked rather than quoted because the value is interpolated into
|
|
17
|
+
* `search_path` and `CREATE SCHEMA`, where a quoted-but-hostile name is still
|
|
18
|
+
* a name somebody else chose. Refusing the shapes that need quoting costs
|
|
19
|
+
* nothing real and removes the question entirely.
|
|
20
|
+
*/
|
|
21
|
+
const IDENTIFIER = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
22
|
+
/** Whether this is a name the adapter will interpolate. */
|
|
3
23
|
function isValidSchemaName(name) {
|
|
4
|
-
|
|
24
|
+
return IDENTIFIER.test(name) && !name.startsWith("pg_");
|
|
5
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Return the name, or throw rather than interpolate something unchecked.
|
|
28
|
+
*
|
|
29
|
+
* The adapter throws a plain Error: it has no access to the config path that
|
|
30
|
+
* produced the value, and `nextly` already refuses the same shapes at boot
|
|
31
|
+
* with a message that names `db.postgres.schema`. This is the backstop for a
|
|
32
|
+
* caller that constructed the adapter directly.
|
|
33
|
+
*/
|
|
6
34
|
function assertSchemaName(name) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`Invalid PostgreSQL schema name "${name}". Use lower-case letters, digits and underscores, starting with a letter or underscore (max 63 characters), and not beginning with "pg_".`
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
return name;
|
|
35
|
+
if (!isValidSchemaName(name)) throw new Error(`Invalid PostgreSQL schema name "${name}". Use lower-case letters, digits and underscores, starting with a letter or underscore (max 63 characters), and not beginning with "pg_".`);
|
|
36
|
+
return name;
|
|
13
37
|
}
|
|
14
|
-
|
|
15
38
|
export { assertSchemaName, isValidSchemaName };
|
|
16
|
-
|
|
39
|
+
|
|
17
40
|
//# sourceMappingURL=schema-name.mjs.map
|
package/dist/schema-name.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"schema-name.mjs","names":[],"sources":["../src/schema-name.ts"],"sourcesContent":["/**\n * The one rule for a PostgreSQL schema name.\n *\n * Lives in the adapter package because both sides need it and neither may\n * import the other: `nextly` validates the configured value at boot so the\n * error names the setting, and the Postgres adapter validates again at the\n * point of interpolation, because that is where a bad value becomes SQL.\n *\n * @module schema-name\n * @since 1.0.0\n */\n\n/**\n * A plain, lower-case identifier.\n *\n * Checked rather than quoted because the value is interpolated into\n * `search_path` and `CREATE SCHEMA`, where a quoted-but-hostile name is still\n * a name somebody else chose. Refusing the shapes that need quoting costs\n * nothing real and removes the question entirely.\n */\nconst IDENTIFIER = /^[a-z_][a-z0-9_]{0,62}$/;\n\n/** Whether this is a name the adapter will interpolate. */\nexport function isValidSchemaName(name: string): boolean {\n // `pg_` is PostgreSQL's reserved prefix for system catalogs.\n return IDENTIFIER.test(name) && !name.startsWith(\"pg_\");\n}\n\n/**\n * Return the name, or throw rather than interpolate something unchecked.\n *\n * The adapter throws a plain Error: it has no access to the config path that\n * produced the value, and `nextly` already refuses the same shapes at boot\n * with a message that names `db.postgres.schema`. This is the backstop for a\n * caller that constructed the adapter directly.\n */\nexport function assertSchemaName(name: string): string {\n if (!isValidSchemaName(name)) {\n throw new Error(\n `Invalid PostgreSQL schema name \"${name}\". Use lower-case letters, digits and underscores, starting with a letter or underscore (max 63 characters), and not beginning with \"pg_\".`\n );\n }\n return name;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,aAAa;;AAGnB,SAAgB,kBAAkB,MAAuB;CAEvD,OAAO,WAAW,KAAK,IAAI,KAAK,CAAC,KAAK,WAAW,KAAK;AACxD;;;;;;;;;AAUA,SAAgB,iBAAiB,MAAsB;CACrD,IAAI,CAAC,kBAAkB,IAAI,GACzB,MAAM,IAAI,MACR,mCAAmC,KAAK,2IAC1C;CAEF,OAAO;AACT"}
|
package/dist/text-match.cjs
CHANGED
|
@@ -1,16 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var drizzleOrm = require('drizzle-orm');
|
|
4
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let drizzle_orm = require("drizzle-orm");
|
|
5
3
|
// src/text-match.ts
|
|
4
|
+
/**
|
|
5
|
+
* Case-insensitive, literal substring matching: the one rule for "does this text contain that,
|
|
6
|
+
* ignoring case" on every dialect.
|
|
7
|
+
*
|
|
8
|
+
* The where builder's `ICONTAINS` compiles through it, and so does any caller that builds its own
|
|
9
|
+
* SQL against a column, such as a collection's search, so the rule cannot be spelled two ways.
|
|
10
|
+
*
|
|
11
|
+
* @module text-match
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Wraps a value in `%…%` for a substring match, escaping the LIKE metacharacters inside it so
|
|
15
|
+
* the value matches literally.
|
|
16
|
+
*
|
|
17
|
+
* `!` is the escape character rather than the more usual backslash, and it has to be, because
|
|
18
|
+
* this builder emits one statement for every dialect. SQLite gives LIKE no default escape
|
|
19
|
+
* character at all, so a backslash there is just a backslash; declaring `ESCAPE '\'` instead
|
|
20
|
+
* runs into MySQL, where the backslash also escapes inside the string literal and the clause
|
|
21
|
+
* would have to be spelled differently per dialect. `ESCAPE '!'` parses identically on
|
|
22
|
+
* PostgreSQL, MySQL and SQLite, and needs no per-dialect branch to stay correct.
|
|
23
|
+
*
|
|
24
|
+
* The escape character is escaped FIRST by including it in the character class, so a literal
|
|
25
|
+
* `!` in the value cannot be produced by escaping something else afterwards.
|
|
26
|
+
*/
|
|
6
27
|
function containsPattern(value) {
|
|
7
|
-
|
|
28
|
+
return `%${value.replace(/[!%_]/g, (character) => `!${character}`)}%`;
|
|
8
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* `column` contains `value`, without regard to case, on PostgreSQL, MySQL and SQLite, even where
|
|
32
|
+
* the column's collation is case-sensitive: both sides lower-cased, `value` matched literally
|
|
33
|
+
* (its `%` and `_` are characters to find, not wildcards).
|
|
34
|
+
*
|
|
35
|
+
* Which letters fold is the database's own `lower()` under the column's collation: MySQL by its
|
|
36
|
+
* collation's Unicode version, PostgreSQL's non-ASCII letters too under a linguistic collation,
|
|
37
|
+
* and ASCII letters only on SQLite and under PostgreSQL's `C` or `POSIX`.
|
|
38
|
+
*
|
|
39
|
+
* @experimental
|
|
40
|
+
* @param column - The column, or any SQL expression yielding text
|
|
41
|
+
* @param value - The text to find, as the person typed it
|
|
42
|
+
* @returns The condition
|
|
43
|
+
*/
|
|
9
44
|
function caseInsensitiveContains(column, value) {
|
|
10
|
-
|
|
45
|
+
return drizzle_orm.sql`lower(${column}) like lower(${containsPattern(value)}) escape '!'`;
|
|
11
46
|
}
|
|
12
|
-
|
|
13
47
|
exports.caseInsensitiveContains = caseInsensitiveContains;
|
|
14
48
|
exports.containsPattern = containsPattern;
|
|
15
|
-
|
|
49
|
+
|
|
16
50
|
//# sourceMappingURL=text-match.cjs.map
|
package/dist/text-match.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"text-match.cjs","names":[],"sources":["../src/text-match.ts"],"sourcesContent":["/**\n * Case-insensitive, literal substring matching: the one rule for \"does this text contain that,\n * ignoring case\" on every dialect.\n *\n * The where builder's `ICONTAINS` compiles through it, and so does any caller that builds its own\n * SQL against a column, such as a collection's search, so the rule cannot be spelled two ways.\n *\n * @module text-match\n */\nimport { sql, type SQL, type SQLWrapper } from \"drizzle-orm\";\n\n/**\n * Wraps a value in `%…%` for a substring match, escaping the LIKE metacharacters inside it so\n * the value matches literally.\n *\n * `!` is the escape character rather than the more usual backslash, and it has to be, because\n * this builder emits one statement for every dialect. SQLite gives LIKE no default escape\n * character at all, so a backslash there is just a backslash; declaring `ESCAPE '\\'` instead\n * runs into MySQL, where the backslash also escapes inside the string literal and the clause\n * would have to be spelled differently per dialect. `ESCAPE '!'` parses identically on\n * PostgreSQL, MySQL and SQLite, and needs no per-dialect branch to stay correct.\n *\n * The escape character is escaped FIRST by including it in the character class, so a literal\n * `!` in the value cannot be produced by escaping something else afterwards.\n */\nexport function containsPattern(value: string): string {\n return `%${value.replace(/[!%_]/g, character => `!${character}`)}%`;\n}\n\n/**\n * `column` contains `value`, without regard to case, on PostgreSQL, MySQL and SQLite, even where\n * the column's collation is case-sensitive: both sides lower-cased, `value` matched literally\n * (its `%` and `_` are characters to find, not wildcards).\n *\n * Which letters fold is the database's own `lower()` under the column's collation: MySQL by its\n * collation's Unicode version, PostgreSQL's non-ASCII letters too under a linguistic collation,\n * and ASCII letters only on SQLite and under PostgreSQL's `C` or `POSIX`.\n *\n * @experimental\n * @param column - The column, or any SQL expression yielding text\n * @param value - The text to find, as the person typed it\n * @returns The condition\n */\nexport function caseInsensitiveContains(\n column: SQLWrapper,\n value: string\n): SQL {\n return sql`lower(${column}) like lower(${containsPattern(value)}) escape '!'`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,gBAAgB,OAAuB;CACrD,OAAO,IAAI,MAAM,QAAQ,WAAU,cAAa,IAAI,WAAW,EAAE;AACnE;;;;;;;;;;;;;;;AAgBA,SAAgB,wBACd,QACA,OACK;CACL,OAAO,YAAA,GAAG,SAAS,OAAO,eAAe,gBAAgB,KAAK,EAAE;AAClE"}
|
package/dist/text-match.d.cts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Case-insensitive, literal substring matching: the one rule for "does this text contain that,
|
|
5
|
-
* ignoring case" on every dialect.
|
|
6
|
-
*
|
|
7
|
-
* The where builder's `ICONTAINS` compiles through it, and so does any caller that builds its own
|
|
8
|
-
* SQL against a column, such as a collection's search, so the rule cannot be spelled two ways.
|
|
9
|
-
*
|
|
10
|
-
* @module text-match
|
|
11
|
-
*/
|
|
12
|
-
|
|
1
|
+
import { SQL, SQLWrapper } from "drizzle-orm";
|
|
13
2
|
/**
|
|
14
3
|
* Wraps a value in `%…%` for a substring match, escaping the LIKE metacharacters inside it so
|
|
15
4
|
* the value matches literally.
|
|
@@ -24,7 +13,7 @@ import { SQLWrapper, SQL } from 'drizzle-orm';
|
|
|
24
13
|
* The escape character is escaped FIRST by including it in the character class, so a literal
|
|
25
14
|
* `!` in the value cannot be produced by escaping something else afterwards.
|
|
26
15
|
*/
|
|
27
|
-
declare function containsPattern(value: string): string;
|
|
16
|
+
export declare function containsPattern(value: string): string;
|
|
28
17
|
/**
|
|
29
18
|
* `column` contains `value`, without regard to case, on PostgreSQL, MySQL and SQLite, even where
|
|
30
19
|
* the column's collation is case-sensitive: both sides lower-cased, `value` matched literally
|
|
@@ -39,6 +28,5 @@ declare function containsPattern(value: string): string;
|
|
|
39
28
|
* @param value - The text to find, as the person typed it
|
|
40
29
|
* @returns The condition
|
|
41
30
|
*/
|
|
42
|
-
declare function caseInsensitiveContains(column: SQLWrapper, value: string): SQL;
|
|
43
|
-
|
|
44
|
-
export { caseInsensitiveContains, containsPattern };
|
|
31
|
+
export declare function caseInsensitiveContains(column: SQLWrapper, value: string): SQL;
|
|
32
|
+
//# sourceMappingURL=text-match.d.cts.map
|
package/dist/text-match.d.ts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Case-insensitive, literal substring matching: the one rule for "does this text contain that,
|
|
5
|
-
* ignoring case" on every dialect.
|
|
6
|
-
*
|
|
7
|
-
* The where builder's `ICONTAINS` compiles through it, and so does any caller that builds its own
|
|
8
|
-
* SQL against a column, such as a collection's search, so the rule cannot be spelled two ways.
|
|
9
|
-
*
|
|
10
|
-
* @module text-match
|
|
11
|
-
*/
|
|
12
|
-
|
|
1
|
+
import { SQL, SQLWrapper } from "drizzle-orm";
|
|
13
2
|
/**
|
|
14
3
|
* Wraps a value in `%…%` for a substring match, escaping the LIKE metacharacters inside it so
|
|
15
4
|
* the value matches literally.
|
|
@@ -24,7 +13,7 @@ import { SQLWrapper, SQL } from 'drizzle-orm';
|
|
|
24
13
|
* The escape character is escaped FIRST by including it in the character class, so a literal
|
|
25
14
|
* `!` in the value cannot be produced by escaping something else afterwards.
|
|
26
15
|
*/
|
|
27
|
-
declare function containsPattern(value: string): string;
|
|
16
|
+
export declare function containsPattern(value: string): string;
|
|
28
17
|
/**
|
|
29
18
|
* `column` contains `value`, without regard to case, on PostgreSQL, MySQL and SQLite, even where
|
|
30
19
|
* the column's collation is case-sensitive: both sides lower-cased, `value` matched literally
|
|
@@ -39,6 +28,5 @@ declare function containsPattern(value: string): string;
|
|
|
39
28
|
* @param value - The text to find, as the person typed it
|
|
40
29
|
* @returns The condition
|
|
41
30
|
*/
|
|
42
|
-
declare function caseInsensitiveContains(column: SQLWrapper, value: string): SQL;
|
|
43
|
-
|
|
44
|
-
export { caseInsensitiveContains, containsPattern };
|
|
31
|
+
export declare function caseInsensitiveContains(column: SQLWrapper, value: string): SQL;
|
|
32
|
+
//# sourceMappingURL=text-match.d.ts.map
|
package/dist/text-match.mjs
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
import { sql } from
|
|
2
|
-
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
3
2
|
// src/text-match.ts
|
|
3
|
+
/**
|
|
4
|
+
* Case-insensitive, literal substring matching: the one rule for "does this text contain that,
|
|
5
|
+
* ignoring case" on every dialect.
|
|
6
|
+
*
|
|
7
|
+
* The where builder's `ICONTAINS` compiles through it, and so does any caller that builds its own
|
|
8
|
+
* SQL against a column, such as a collection's search, so the rule cannot be spelled two ways.
|
|
9
|
+
*
|
|
10
|
+
* @module text-match
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Wraps a value in `%…%` for a substring match, escaping the LIKE metacharacters inside it so
|
|
14
|
+
* the value matches literally.
|
|
15
|
+
*
|
|
16
|
+
* `!` is the escape character rather than the more usual backslash, and it has to be, because
|
|
17
|
+
* this builder emits one statement for every dialect. SQLite gives LIKE no default escape
|
|
18
|
+
* character at all, so a backslash there is just a backslash; declaring `ESCAPE '\'` instead
|
|
19
|
+
* runs into MySQL, where the backslash also escapes inside the string literal and the clause
|
|
20
|
+
* would have to be spelled differently per dialect. `ESCAPE '!'` parses identically on
|
|
21
|
+
* PostgreSQL, MySQL and SQLite, and needs no per-dialect branch to stay correct.
|
|
22
|
+
*
|
|
23
|
+
* The escape character is escaped FIRST by including it in the character class, so a literal
|
|
24
|
+
* `!` in the value cannot be produced by escaping something else afterwards.
|
|
25
|
+
*/
|
|
4
26
|
function containsPattern(value) {
|
|
5
|
-
|
|
27
|
+
return `%${value.replace(/[!%_]/g, (character) => `!${character}`)}%`;
|
|
6
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* `column` contains `value`, without regard to case, on PostgreSQL, MySQL and SQLite, even where
|
|
31
|
+
* the column's collation is case-sensitive: both sides lower-cased, `value` matched literally
|
|
32
|
+
* (its `%` and `_` are characters to find, not wildcards).
|
|
33
|
+
*
|
|
34
|
+
* Which letters fold is the database's own `lower()` under the column's collation: MySQL by its
|
|
35
|
+
* collation's Unicode version, PostgreSQL's non-ASCII letters too under a linguistic collation,
|
|
36
|
+
* and ASCII letters only on SQLite and under PostgreSQL's `C` or `POSIX`.
|
|
37
|
+
*
|
|
38
|
+
* @experimental
|
|
39
|
+
* @param column - The column, or any SQL expression yielding text
|
|
40
|
+
* @param value - The text to find, as the person typed it
|
|
41
|
+
* @returns The condition
|
|
42
|
+
*/
|
|
7
43
|
function caseInsensitiveContains(column, value) {
|
|
8
|
-
|
|
44
|
+
return sql`lower(${column}) like lower(${containsPattern(value)}) escape '!'`;
|
|
9
45
|
}
|
|
10
|
-
|
|
11
46
|
export { caseInsensitiveContains, containsPattern };
|
|
12
|
-
|
|
47
|
+
|
|
13
48
|
//# sourceMappingURL=text-match.mjs.map
|
package/dist/text-match.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"text-match.mjs","names":[],"sources":["../src/text-match.ts"],"sourcesContent":["/**\n * Case-insensitive, literal substring matching: the one rule for \"does this text contain that,\n * ignoring case\" on every dialect.\n *\n * The where builder's `ICONTAINS` compiles through it, and so does any caller that builds its own\n * SQL against a column, such as a collection's search, so the rule cannot be spelled two ways.\n *\n * @module text-match\n */\nimport { sql, type SQL, type SQLWrapper } from \"drizzle-orm\";\n\n/**\n * Wraps a value in `%…%` for a substring match, escaping the LIKE metacharacters inside it so\n * the value matches literally.\n *\n * `!` is the escape character rather than the more usual backslash, and it has to be, because\n * this builder emits one statement for every dialect. SQLite gives LIKE no default escape\n * character at all, so a backslash there is just a backslash; declaring `ESCAPE '\\'` instead\n * runs into MySQL, where the backslash also escapes inside the string literal and the clause\n * would have to be spelled differently per dialect. `ESCAPE '!'` parses identically on\n * PostgreSQL, MySQL and SQLite, and needs no per-dialect branch to stay correct.\n *\n * The escape character is escaped FIRST by including it in the character class, so a literal\n * `!` in the value cannot be produced by escaping something else afterwards.\n */\nexport function containsPattern(value: string): string {\n return `%${value.replace(/[!%_]/g, character => `!${character}`)}%`;\n}\n\n/**\n * `column` contains `value`, without regard to case, on PostgreSQL, MySQL and SQLite, even where\n * the column's collation is case-sensitive: both sides lower-cased, `value` matched literally\n * (its `%` and `_` are characters to find, not wildcards).\n *\n * Which letters fold is the database's own `lower()` under the column's collation: MySQL by its\n * collation's Unicode version, PostgreSQL's non-ASCII letters too under a linguistic collation,\n * and ASCII letters only on SQLite and under PostgreSQL's `C` or `POSIX`.\n *\n * @experimental\n * @param column - The column, or any SQL expression yielding text\n * @param value - The text to find, as the person typed it\n * @returns The condition\n */\nexport function caseInsensitiveContains(\n column: SQLWrapper,\n value: string\n): SQL {\n return sql`lower(${column}) like lower(${containsPattern(value)}) escape '!'`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,gBAAgB,OAAuB;CACrD,OAAO,IAAI,MAAM,QAAQ,WAAU,cAAa,IAAI,WAAW,EAAE;AACnE;;;;;;;;;;;;;;;AAgBA,SAAgB,wBACd,QACA,OACK;CACL,OAAO,GAAG,SAAS,OAAO,eAAe,gBAAgB,KAAK,EAAE;AAClE"}
|