create-monolayer-app 0.1.2 → 0.2.0

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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/template/_gitignore +5 -0
  3. package/template/lib/db/client.ts +30 -0
  4. package/template/lib/db/db.ts +4 -0
  5. package/template/oxlint.config.ts +11 -0
  6. package/template/package.json +23 -3
  7. package/template/tsconfig.json +3 -2
  8. package/template/vendor/kysely-dsql/dsql/adapter.ts +15 -0
  9. package/template/vendor/kysely-dsql/dsql/alter-column-builder.ts +105 -0
  10. package/template/vendor/kysely-dsql/dsql/alter-table-builders.ts +195 -0
  11. package/template/vendor/kysely-dsql/dsql/compatibility-rules.ts +235 -0
  12. package/template/vendor/kysely-dsql/dsql/create-column-builder.ts +187 -0
  13. package/template/vendor/kysely-dsql/dsql/create-table-builder.ts +115 -0
  14. package/template/vendor/kysely-dsql/dsql/dialect.ts +41 -0
  15. package/template/vendor/kysely-dsql/dsql/dsql-kysely.ts +93 -0
  16. package/template/vendor/kysely-dsql/dsql/dsql-token.ts +29 -0
  17. package/template/vendor/kysely-dsql/dsql/index-view-builders.ts +206 -0
  18. package/template/vendor/kysely-dsql/dsql/pool.ts +40 -0
  19. package/template/vendor/kysely-dsql/dsql/query-compiler-error.ts +18 -0
  20. package/template/vendor/kysely-dsql/dsql/query-compiler.test.ts +765 -0
  21. package/template/vendor/kysely-dsql/dsql/query-compiler.ts +259 -0
  22. package/template/vendor/kysely-dsql/dsql/query-validation.test.ts +518 -0
  23. package/template/vendor/kysely-dsql/dsql/query-validation.ts +128 -0
  24. package/template/vendor/kysely-dsql/dsql/raw-statement.test.ts +167 -0
  25. package/template/vendor/kysely-dsql/dsql/raw-statement.ts +51 -0
  26. package/template/vendor/kysely-dsql/dsql/schema-module.ts +167 -0
  27. package/template/vendor/kysely-dsql/dsql/types.ts +4 -0
  28. package/template/vendor/kysely-dsql/generator/create-migration.ts +86 -0
  29. package/template/vendor/kysely-dsql/generator/generate-types-from-pglite.ts +40 -0
  30. package/template/vendor/kysely-dsql/generator/generated-types-writer.ts +73 -0
  31. package/template/vendor/kysely-dsql/generator/migration-file.ts +73 -0
  32. package/template/vendor/kysely-dsql/generator/type-generator.ts +330 -0
  33. package/template/vendor/kysely-dsql/plugins/auto-updated-at.plugin.ts +139 -0
  34. package/template/vendor/kysely-dsql/plugins/index.ts +10 -0
  35. package/template/vendor/kysely-dsql/plugins/soft-delete.plugin.ts +217 -0
  36. package/template/vitest.config.ts +23 -0
@@ -0,0 +1,235 @@
1
+ import type { DSQLValidationCode } from "./query-validation.js";
2
+
3
+ export interface CompatibilityRule {
4
+ readonly code: DSQLValidationCode;
5
+ readonly feature: string;
6
+ readonly message: string;
7
+ readonly documentationUrl: string;
8
+ readonly check: (normalizedSql: string) => boolean;
9
+ }
10
+
11
+ const DOC_BASE = "https://docs.aws.amazon.com/aurora-dsql/latest/userguide";
12
+ const DOC_FEATURES = `${DOC_BASE}/working-with-postgresql-compatibility-supported-sql-features.html`;
13
+ const DOC_CREATE_TABLE = `${DOC_BASE}/create-table-syntax-support.html`;
14
+ const DOC_ALTER_TABLE = `${DOC_BASE}/alter-table-syntax-support.html`;
15
+ const DOC_INDEX = `${DOC_BASE}/working-with-create-index-async.html`;
16
+
17
+ const isSynchronousIndex = (sql: string): boolean => {
18
+ if (!/\bcreate\s+(?:unique\s+)?index\b/u.test(sql)) {
19
+ return false;
20
+ }
21
+ return !/\bcreate\s+(?:unique\s+)?index\s+(?:if\s+not\s+exists\s+async|async(?:\s+if\s+not\s+exists)?)\b/u.test(
22
+ sql
23
+ );
24
+ };
25
+
26
+ const hasUnsupportedIndexClause = (sql: string): boolean => {
27
+ if (!/\bcreate\s+(?:unique\s+)?index\b/u.test(sql)) {
28
+ return false;
29
+ }
30
+ return /\busing\s+\w+|\bwhere\s+|\([^)]*\b(?:asc|desc)\b|\bnulls\s+(?:first|last)\b/u.test(
31
+ sql
32
+ );
33
+ };
34
+
35
+ const isAlterAddColumnWithConstraint = (sql: string): boolean => {
36
+ if (!/\balter\s+table\b/u.test(sql)) {
37
+ return false;
38
+ }
39
+ if (
40
+ /\balter\s+table\s+\S+\s+add\s+column\s+(?:if\s+not\s+exists\s+)?\S+\s+\S+\s+(?:default\b|not\s+null\b|primary\s+key\b|unique\b|references\b|check\b|generated\b)/u.test(
41
+ sql
42
+ )
43
+ ) {
44
+ return true;
45
+ }
46
+ return /\balter\s+table\s+\S+\s+add\s+(?!column\b|constraint\b|check\b|primary\s+key\b|unique\b|foreign\s+key\b)(?:if\s+not\s+exists\s+)?\S+\s+\S+\s+(?:default\b|not\s+null\b|primary\s+key\b|unique\b|references\b|check\b|generated\b)/u.test(
47
+ sql
48
+ );
49
+ };
50
+
51
+ const isCreateTableAs = (sql: string): boolean => {
52
+ if (/\bcreate\s+table\s+\S+\s+as\b/u.test(sql)) {
53
+ return true;
54
+ }
55
+ return /\bselect\s+.*\binto\s+(?:temporary\s+|temp\s+|unlogged\s+)?(?:table\s+)?\S+\s+from\b/u.test(
56
+ sql
57
+ );
58
+ };
59
+
60
+ export const COMPATIBILITY_RULES: readonly CompatibilityRule[] = [
61
+ {
62
+ code: "foreign_key",
63
+ feature: "Foreign key constraints",
64
+ message: "Aurora DSQL does not support foreign key constraints.",
65
+ documentationUrl: DOC_CREATE_TABLE,
66
+ check: (sql) => /\bforeign\s+key\b|\breferences\b/u.test(sql),
67
+ },
68
+ {
69
+ code: "trigger",
70
+ feature: "Triggers",
71
+ message: "Aurora DSQL does not support triggers.",
72
+ documentationUrl: DOC_FEATURES,
73
+ check: (sql) =>
74
+ /\b(?:create|alter|drop)\s+(?:or\s+replace\s+)?trigger\b/u.test(sql),
75
+ },
76
+ {
77
+ code: "function_language",
78
+ feature: "User-defined functions",
79
+ message:
80
+ "Aurora DSQL does not support user-defined functions or procedural languages.",
81
+ documentationUrl: DOC_FEATURES,
82
+ check: (sql) =>
83
+ /\b(?:create|alter|drop)\s+(?:or\s+replace\s+)?function\b/u.test(sql),
84
+ },
85
+ {
86
+ code: "procedure",
87
+ feature: "Stored procedures",
88
+ message: "Aurora DSQL does not support stored procedures.",
89
+ documentationUrl: DOC_FEATURES,
90
+ check: (sql) =>
91
+ /\b(?:create|alter|drop)\s+(?:or\s+replace\s+)?procedure\b/u.test(sql),
92
+ },
93
+ {
94
+ code: "truncate",
95
+ feature: "Table truncation",
96
+ message: "Aurora DSQL does not support TRUNCATE. Use DELETE FROM instead.",
97
+ documentationUrl: DOC_FEATURES,
98
+ check: (sql) => /\btruncate\b/u.test(sql),
99
+ },
100
+ {
101
+ code: "listen_notify",
102
+ feature: "LISTEN and NOTIFY",
103
+ message: "Aurora DSQL does not support LISTEN, NOTIFY, or UNLISTEN.",
104
+ documentationUrl: DOC_FEATURES,
105
+ check: (sql) => /\b(?:listen|notify|unlisten)\b/u.test(sql),
106
+ },
107
+ {
108
+ code: "extension",
109
+ feature: "PostgreSQL extensions",
110
+ message: "Aurora DSQL does not support CREATE EXTENSION or DROP EXTENSION.",
111
+ documentationUrl: DOC_FEATURES,
112
+ check: (sql) => /\b(?:create|drop)\s+extension\b/u.test(sql),
113
+ },
114
+ {
115
+ code: "postgres_type",
116
+ feature: "User-defined types and domains",
117
+ message: "Aurora DSQL does not support user-defined types or domains.",
118
+ documentationUrl: DOC_FEATURES,
119
+ check: (sql) => /\b(?:create|alter|drop)\s+(?:type|domain)\b/u.test(sql),
120
+ },
121
+ {
122
+ code: "temporary_object",
123
+ feature: "Temporary and unlogged objects",
124
+ message:
125
+ "Aurora DSQL does not support temporary or unlogged tables, views, or sequences.",
126
+ documentationUrl: DOC_FEATURES,
127
+ check: (sql) =>
128
+ /\bcreate\s+(?:global\s+|local\s+)?(?:temporary|temp|unlogged)\b|\b(?:temporary|temp|unlogged)\s+(?:table|view|sequence)\b/u.test(
129
+ sql
130
+ ),
131
+ },
132
+ {
133
+ code: "materialized_view",
134
+ feature: "Materialized views",
135
+ message: "Aurora DSQL does not support materialized views.",
136
+ documentationUrl: DOC_FEATURES,
137
+ check: (sql) => /\bmaterialized\s+view\b/u.test(sql),
138
+ },
139
+ {
140
+ code: "row_level_security",
141
+ feature: "Row-level security",
142
+ message:
143
+ "Aurora DSQL does not support row-level security or security policies.",
144
+ documentationUrl: DOC_FEATURES,
145
+ check: (sql) =>
146
+ /\brow\s+level\s+security\b|\b(?:create|alter|drop)\s+policy\b/u.test(
147
+ sql
148
+ ),
149
+ },
150
+ {
151
+ code: "database_or_tablespace",
152
+ feature: "Database and tablespace management",
153
+ message:
154
+ "Aurora DSQL does not support database or tablespace management statements.",
155
+ documentationUrl: DOC_FEATURES,
156
+ check: (sql) =>
157
+ /\b(?:create|alter|drop)\s+(?:database|tablespace)\b/u.test(sql),
158
+ },
159
+ {
160
+ code: "synchronous_index",
161
+ feature: "Synchronous index creation",
162
+ message:
163
+ "Aurora DSQL requires CREATE INDEX ASYNC for all index creation statements.",
164
+ documentationUrl: DOC_INDEX,
165
+ check: isSynchronousIndex,
166
+ },
167
+ {
168
+ code: "unsupported_index_clause",
169
+ feature: "Unsupported index clauses",
170
+ message:
171
+ "Aurora DSQL indexes do not support USING clauses, WHERE predicates, expressions, or sort ordering.",
172
+ documentationUrl: DOC_INDEX,
173
+ check: hasUnsupportedIndexClause,
174
+ },
175
+ {
176
+ code: "alter_column_type",
177
+ feature: "Altering column types",
178
+ message: "Aurora DSQL does not support altering column types.",
179
+ documentationUrl: DOC_ALTER_TABLE,
180
+ check: (sql) =>
181
+ /\balter\s+table\b.*\balter\s+(?:column\s+)?\S+\s+(?:set\s+data\s+)?type\b|\balter\s+column\s+\S+\s+(?:set\s+data\s+)?type\b/u.test(
182
+ sql
183
+ ),
184
+ },
185
+ {
186
+ code: "alter_column_set_not_null",
187
+ feature: "Setting NOT NULL on existing columns",
188
+ message: "Aurora DSQL does not support ALTER COLUMN SET NOT NULL.",
189
+ documentationUrl: DOC_ALTER_TABLE,
190
+ check: (sql) =>
191
+ /\balter\s+table\b.*\balter\s+(?:column\s+)?\S+\s+set\s+not\s+null\b|\balter\s+column\s+\S+\s+set\s+not\s+null\b/u.test(
192
+ sql
193
+ ),
194
+ },
195
+ {
196
+ code: "alter_add_column_constraint",
197
+ feature: "Adding column constraints during ALTER TABLE",
198
+ message:
199
+ "Aurora DSQL does not support inline constraints, defaults, or generated expressions when adding columns.",
200
+ documentationUrl: DOC_ALTER_TABLE,
201
+ check: isAlterAddColumnWithConstraint,
202
+ },
203
+ {
204
+ code: "create_table_as",
205
+ feature: "CREATE TABLE AS",
206
+ message: "Aurora DSQL does not support CREATE TABLE AS or SELECT INTO.",
207
+ documentationUrl: DOC_CREATE_TABLE,
208
+ check: isCreateTableAs,
209
+ },
210
+ {
211
+ code: "merge",
212
+ feature: "MERGE statements",
213
+ message:
214
+ "Aurora DSQL does not support MERGE statements. Use INSERT ... ON CONFLICT instead.",
215
+ documentationUrl: DOC_FEATURES,
216
+ check: (sql) => /\bmerge\b/u.test(sql),
217
+ },
218
+ {
219
+ code: "collation",
220
+ feature: "Collations",
221
+ message:
222
+ "Aurora DSQL does not support custom collations or COLLATE clauses.",
223
+ documentationUrl: DOC_FEATURES,
224
+ check: (sql) =>
225
+ /\bcollate\b|\b(?:create|alter|drop)\s+collation\b/u.test(sql),
226
+ },
227
+ {
228
+ code: "vacuum",
229
+ feature: "VACUUM and ANALYZE",
230
+ message:
231
+ "Aurora DSQL manages storage automatically and does not support VACUUM or ANALYZE statements.",
232
+ documentationUrl: DOC_FEATURES,
233
+ check: (sql) => /\bvacuum\b|\banalyze\b/u.test(sql),
234
+ },
235
+ ];
@@ -0,0 +1,187 @@
1
+ import { ColumnDefinitionBuilder } from "kysely";
2
+
3
+ /**
4
+ * Lists the Kysely data type strings that Aurora DSQL accepts for new columns.
5
+ *
6
+ * The TypeScript compiler accepts supported type names and parameter syntax.
7
+ * Numeric bounds are outside the type contract.
8
+ * Aurora DSQL supports precision up to 38 and scale up to 37.
9
+ * Aurora DSQL applies stored-value limits during `INSERT` and `UPDATE`.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const columnType: DSQLColumnDataType = "numeric(38, 37)";
14
+ * ```
15
+ */
16
+ export type DSQLColumnDataType =
17
+ | "bigint"
18
+ | "boolean"
19
+ | "bytea"
20
+ | "char"
21
+ | `char(${number})`
22
+ | "date"
23
+ | "decimal"
24
+ | `decimal(${number}, ${number})`
25
+ | "double precision"
26
+ | "float4"
27
+ | "float8"
28
+ | "int2"
29
+ | "int4"
30
+ | "int8"
31
+ | "integer"
32
+ | "json"
33
+ | "jsonb"
34
+ | "numeric"
35
+ | `numeric(${number}, ${number})`
36
+ | "real"
37
+ | "smallint"
38
+ | "text"
39
+ | "time"
40
+ | `time(${number})`
41
+ | "timestamp"
42
+ | `timestamp(${number})`
43
+ | "timestamptz"
44
+ | `timestamptz(${number})`
45
+ | "timetz"
46
+ | `timetz(${number})`
47
+ | "uuid"
48
+ | "varchar"
49
+ | `varchar(${number})`;
50
+
51
+ /**
52
+ * Restricts index column names to reject sort direction suffixes.
53
+ */
54
+ export type DSQLIndexColumnName<C extends string> = C extends `${string} ${
55
+ | "asc"
56
+ | "desc"
57
+ | "ASC"
58
+ | "DESC"}`
59
+ ? never
60
+ : C;
61
+
62
+ /**
63
+ * Restricts column definition options during table creation in Aurora DSQL.
64
+ *
65
+ * This class adds type declarations only. Kysely supplies all runtime behavior.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * db.schema.createTable("person").addColumn("id", "uuid", (col) => col.primaryKey());
70
+ * ```
71
+ */
72
+ // The contract requires related public type-only builder classes in one module.
73
+ // eslint-disable-next-line max-classes-per-file
74
+ export class DSQLCreateColumnDefinitionBuilder extends ColumnDefinitionBuilder {
75
+ /**
76
+ * Makes the column the primary key.
77
+ *
78
+ * @returns The restricted column definition builder.
79
+ */
80
+ declare primaryKey: () => DSQLCreateColumnDefinitionBuilder;
81
+
82
+ /**
83
+ * Adds a unique constraint for the column.
84
+ *
85
+ * @returns The restricted column definition builder.
86
+ */
87
+ declare unique: () => DSQLCreateColumnDefinitionBuilder;
88
+
89
+ /**
90
+ * Adds the NULLS NOT DISTINCT specifier.
91
+ *
92
+ * @returns The restricted column definition builder.
93
+ */
94
+ declare nullsNotDistinct: () => DSQLCreateColumnDefinitionBuilder;
95
+
96
+ /**
97
+ * Adds a NOT NULL constraint for the column.
98
+ *
99
+ * @returns The restricted column definition builder.
100
+ */
101
+ declare notNull: () => DSQLCreateColumnDefinitionBuilder;
102
+
103
+ /**
104
+ * Adds a default value expression for the column.
105
+ *
106
+ * @param args - The default value arguments.
107
+ * @returns The restricted column definition builder.
108
+ */
109
+ declare defaultTo: (
110
+ ...args: Parameters<ColumnDefinitionBuilder["defaultTo"]>
111
+ ) => DSQLCreateColumnDefinitionBuilder;
112
+
113
+ /**
114
+ * Adds a check constraint for the column.
115
+ *
116
+ * @param args - The check constraint arguments.
117
+ * @returns The restricted column definition builder.
118
+ */
119
+ declare check: (
120
+ ...args: Parameters<ColumnDefinitionBuilder["check"]>
121
+ ) => DSQLCreateColumnDefinitionBuilder;
122
+
123
+ /**
124
+ * Makes the column a generated column using GENERATED ALWAYS AS.
125
+ *
126
+ * @param args - The generated column arguments.
127
+ * @returns The restricted column definition builder.
128
+ */
129
+ declare generatedAlwaysAs: (
130
+ ...args: Parameters<ColumnDefinitionBuilder["generatedAlwaysAs"]>
131
+ ) => DSQLCreateColumnDefinitionBuilder;
132
+
133
+ /**
134
+ * Makes a generated column stored.
135
+ *
136
+ * @returns The restricted column definition builder.
137
+ */
138
+ declare stored: () => DSQLCreateColumnDefinitionBuilder;
139
+
140
+ /**
141
+ * Adds SQL modifiers directly after the column data type.
142
+ *
143
+ * @param args - The modifier arguments.
144
+ * @returns The restricted column definition builder.
145
+ */
146
+ declare modifyFront: (
147
+ ...args: Parameters<ColumnDefinitionBuilder["modifyFront"]>
148
+ ) => DSQLCreateColumnDefinitionBuilder;
149
+
150
+ /**
151
+ * Adds SQL modifiers at the end of the column definition.
152
+ *
153
+ * @param args - The modifier arguments.
154
+ * @returns The restricted column definition builder.
155
+ */
156
+ declare modifyEnd: (
157
+ ...args: Parameters<ColumnDefinitionBuilder["modifyEnd"]>
158
+ ) => DSQLCreateColumnDefinitionBuilder;
159
+
160
+ /**
161
+ * Calls a custom transformation function.
162
+ *
163
+ * @param func - The transformation callback.
164
+ * @returns The callback result.
165
+ */
166
+ declare $call: <T>(func: (qb: this) => T) => T;
167
+
168
+ declare references: (this: never, ...args: never[]) => never;
169
+ declare onDelete: (this: never, ...args: never[]) => never;
170
+ declare onUpdate: (this: never, ...args: never[]) => never;
171
+ declare autoIncrement: (this: never, ...args: never[]) => never;
172
+ declare identity: (this: never, ...args: never[]) => never;
173
+ declare unsigned: (this: never, ...args: never[]) => never;
174
+ declare generatedAlwaysAsIdentity: (this: never, ...args: never[]) => never;
175
+ declare generatedByDefaultAsIdentity: (
176
+ this: never,
177
+ ...args: never[]
178
+ ) => never;
179
+ declare ifNotExists: (this: never, ...args: never[]) => never;
180
+ }
181
+
182
+ /**
183
+ * Callback function to configure a column definition during table creation.
184
+ */
185
+ export type DSQLCreateColumnDefinitionBuilderCallback = (
186
+ builder: DSQLCreateColumnDefinitionBuilder
187
+ ) => DSQLCreateColumnDefinitionBuilder;
@@ -0,0 +1,115 @@
1
+ import { CreateTableBuilder } from "kysely";
2
+
3
+ import type {
4
+ DSQLColumnDataType,
5
+ DSQLCreateColumnDefinitionBuilderCallback,
6
+ } from "./create-column-builder.js";
7
+
8
+ /**
9
+ * Restricts table creation builders for Aurora DSQL.
10
+ *
11
+ * @template TB - The table name.
12
+ * @template C - The column names in the builder.
13
+ * @example
14
+ * ```ts
15
+ * db.schema.createTable("person").addColumn("id", "uuid");
16
+ * ```
17
+ */
18
+ // eslint-disable-next-line max-classes-per-file
19
+ export class DSQLCreateTableBuilder<
20
+ TB extends string,
21
+ C extends string = never,
22
+ > extends CreateTableBuilder<TB, C> {
23
+ /**
24
+ * Adds a column with an Aurora DSQL data type.
25
+ *
26
+ * @param columnName - The column name.
27
+ * @param dataType - The Aurora DSQL data type.
28
+ * @param build - The optional column builder callback.
29
+ * @returns A restricted builder with the new column name.
30
+ * @example
31
+ * ```ts
32
+ * builder.addColumn("id", "uuid");
33
+ * ```
34
+ */
35
+ declare addColumn: <CN extends string>(
36
+ columnName: CN,
37
+ dataType: DSQLColumnDataType,
38
+ build?: DSQLCreateColumnDefinitionBuilderCallback
39
+ ) => DSQLCreateTableBuilder<TB, C | CN>;
40
+
41
+ /**
42
+ * Adds a check constraint and keeps the restricted builder.
43
+ *
44
+ * @param args - The Kysely check constraint arguments.
45
+ * @returns The restricted table builder.
46
+ */
47
+ declare addCheckConstraint: (
48
+ ...args: Parameters<CreateTableBuilder<TB, C>["addCheckConstraint"]>
49
+ ) => DSQLCreateTableBuilder<TB, C>;
50
+
51
+ /**
52
+ * Adds a primary key constraint and keeps the restricted builder.
53
+ *
54
+ * @param args - The Kysely primary key constraint arguments.
55
+ * @returns The restricted table builder.
56
+ */
57
+ declare addPrimaryKeyConstraint: (
58
+ ...args: Parameters<CreateTableBuilder<TB, C>["addPrimaryKeyConstraint"]>
59
+ ) => DSQLCreateTableBuilder<TB, C>;
60
+
61
+ /**
62
+ * Adds a unique constraint and keeps the restricted builder.
63
+ *
64
+ * @param args - The Kysely unique constraint arguments.
65
+ * @returns The restricted table builder.
66
+ */
67
+ declare addUniqueConstraint: (
68
+ ...args: Parameters<CreateTableBuilder<TB, C>["addUniqueConstraint"]>
69
+ ) => DSQLCreateTableBuilder<TB, C>;
70
+
71
+ /**
72
+ * Adds the missing-table condition and keeps the restricted builder.
73
+ *
74
+ * @returns The restricted table builder.
75
+ * @example
76
+ * ```ts
77
+ * builder.ifNotExists();
78
+ * ```
79
+ */
80
+ declare ifNotExists: () => DSQLCreateTableBuilder<TB, C>;
81
+
82
+ /**
83
+ * Adds SQL at the front and keeps the restricted builder.
84
+ *
85
+ * @param args - The modifier arguments.
86
+ * @returns The restricted table builder.
87
+ */
88
+ declare modifyFront: (
89
+ ...args: Parameters<CreateTableBuilder<TB, C>["modifyFront"]>
90
+ ) => DSQLCreateTableBuilder<TB, C>;
91
+
92
+ /**
93
+ * Adds SQL at the end and keeps the restricted builder.
94
+ *
95
+ * @param args - The modifier arguments.
96
+ * @returns The restricted table builder.
97
+ */
98
+ declare modifyEnd: (
99
+ ...args: Parameters<CreateTableBuilder<TB, C>["modifyEnd"]>
100
+ ) => DSQLCreateTableBuilder<TB, C>;
101
+
102
+ /**
103
+ * Calls a custom transformation function.
104
+ *
105
+ * @param func - The transformation callback.
106
+ * @returns The callback result.
107
+ */
108
+ declare $call: <T>(func: (qb: this) => T) => T;
109
+
110
+ declare temporary: (this: never, ...args: never[]) => never;
111
+ declare onCommit: (this: never, ...args: never[]) => never;
112
+ declare as: (this: never, ...args: never[]) => never;
113
+ declare addIndex: (this: never, ...args: never[]) => never;
114
+ declare addForeignKeyConstraint: (this: never, ...args: never[]) => never;
115
+ }
@@ -0,0 +1,41 @@
1
+ // oxlint-disable max-classes-per-file typescript/no-explicit-any
2
+ import { PostgresDriver, PostgresIntrospector } from "kysely";
3
+ import type {
4
+ DatabaseIntrospector,
5
+ Dialect,
6
+ DialectAdapter,
7
+ Driver,
8
+ Kysely,
9
+ PostgresDialectConfig,
10
+ QueryCompiler,
11
+ } from "kysely";
12
+
13
+ import { DQSLAdapter } from "./adapter.js";
14
+ import { DSQLQueryCompiler } from "./query-compiler.js";
15
+
16
+ export class DSQLDialect implements Dialect {
17
+ readonly #config: PostgresDialectConfig;
18
+
19
+ constructor(config: PostgresDialectConfig) {
20
+ this.#config = config;
21
+ }
22
+
23
+ createDriver(): Driver {
24
+ return new PostgresDriver(this.#config);
25
+ }
26
+
27
+ // oxlint-disable-next-line class-methods-use-this
28
+ createQueryCompiler(): QueryCompiler {
29
+ return new DSQLQueryCompiler();
30
+ }
31
+
32
+ // oxlint-disable-next-line class-methods-use-this
33
+ createAdapter(): DialectAdapter {
34
+ return new DQSLAdapter();
35
+ }
36
+
37
+ // oxlint-disable-next-line class-methods-use-this
38
+ createIntrospector(db: Kysely<any>): DatabaseIntrospector {
39
+ return new PostgresIntrospector(db);
40
+ }
41
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Supplies a Kysely client with the restricted Aurora DSQL schema module.
3
+ *
4
+ * @template DB - The database shape.
5
+ * @example
6
+ * ```ts
7
+ * const client = new DSQLKysely<Database>({ dialect });
8
+ * ```
9
+ */
10
+
11
+ import { Kysely, type KyselyConfig } from "kysely";
12
+
13
+ import { DSQLSchemaModule } from "./schema-module";
14
+
15
+ // eslint-disable-next-line max-classes-per-file
16
+ export class DSQLKysely<DB> extends Kysely<DB> {
17
+ /**
18
+ * Adds a plugin and keeps the restricted client.
19
+ *
20
+ * @param plugin - The Kysely plugin.
21
+ * @returns A restricted client with the plugin.
22
+ * @example
23
+ * ```ts
24
+ * const client = db.withPlugin(plugin);
25
+ * ```
26
+ */
27
+ // @ts-expect-error DSQLKysely restricts the schema surface for Aurora DSQL.
28
+ override withPlugin(plugin: KyselyPlugin): DSQLKysely<DB> {
29
+ // SAFETY: The subclass changes types only and adds no runtime state.
30
+ return super.withPlugin(plugin) as DSQLKysely<DB>;
31
+ }
32
+
33
+ /**
34
+ * Removes all plugins and keeps the restricted client.
35
+ *
36
+ * @returns A restricted client without plugins.
37
+ * @example
38
+ * ```ts
39
+ * const client = db.withoutPlugins();
40
+ * ```
41
+ */
42
+ // @ts-expect-error DSQLKysely restricts the schema surface for Aurora DSQL.
43
+ override withoutPlugins(): DSQLKysely<DB> {
44
+ // SAFETY: The subclass changes types only and adds no runtime state.
45
+ return super.withoutPlugins() as DSQLKysely<DB>;
46
+ }
47
+
48
+ /**
49
+ * Selects a schema and keeps the restricted client.
50
+ *
51
+ * @param schema - The schema name.
52
+ * @returns A restricted client for the schema.
53
+ * @example
54
+ * ```ts
55
+ * const client = db.withSchema("public");
56
+ * ```
57
+ */
58
+ // @ts-expect-error DSQLKysely restricts the schema surface for Aurora DSQL.
59
+ override withSchema(schema: string): DSQLKysely<DB> {
60
+ // SAFETY: The subclass changes types only and adds no runtime state.
61
+ return super.withSchema(schema) as DSQLKysely<DB>;
62
+ }
63
+
64
+ /**
65
+ * Creates a restricted Aurora DSQL client.
66
+ *
67
+ * @param config - The Kysely client configuration.
68
+ * @example
69
+ * ```ts
70
+ * const client = new DSQLKysely<Database>({ dialect });
71
+ * ```
72
+ */
73
+ // The explicit constructor documents the public configuration contract.
74
+ // eslint-disable-next-line no-useless-constructor
75
+ constructor(config: KyselyConfig) {
76
+ super(config);
77
+ }
78
+
79
+ /**
80
+ * Gets the restricted Aurora DSQL schema module.
81
+ *
82
+ * @returns The schema module for this client.
83
+ * @example
84
+ * ```ts
85
+ * const schema = db.schema;
86
+ * ```
87
+ */
88
+ // @ts-expect-error DSQLKysely restricts the schema surface for Aurora DSQL.
89
+ override get schema(): DSQLSchemaModule {
90
+ // SAFETY: DSQLSchemaModule is an exact subtype extending SchemaModule.
91
+ return new DSQLSchemaModule(this.getExecutor());
92
+ }
93
+ }
@@ -0,0 +1,29 @@
1
+ import assert from "node:assert";
2
+
3
+ // oxlint-disable func-style
4
+ import { DsqlSigner } from "@aws-sdk/dsql-signer";
5
+
6
+ async function getToken(clusterEndpoint: string, region: string) {
7
+ const signer = new DsqlSigner({
8
+ hostname: clusterEndpoint,
9
+ expiresIn: 60_000,
10
+ region,
11
+ });
12
+ return await signer.getDbConnectAdminAuthToken();
13
+ }
14
+ async function main() {
15
+ const clusterEndpoint = process.env.CLUSTER_ENDPOINT;
16
+ assert.ok(clusterEndpoint);
17
+ const user = process.env.CLUSTER_USER;
18
+ assert.ok(user);
19
+ const region = process.env.AWS_REGION;
20
+ assert.ok(region);
21
+ const token = await getToken(clusterEndpoint, region);
22
+ console.log({
23
+ token,
24
+ encodedToken: encodeURIComponent(token),
25
+ connectionString: `postgresql://admin:${encodeURIComponent(token)}@${clusterEndpoint}:5432/postgres?sslmode=true`,
26
+ });
27
+ }
28
+
29
+ main();