create-monolayer-app 0.1.2 → 0.2.1
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/package.json +1 -1
- package/template/_gitignore +5 -0
- package/template/lib/db/client.ts +30 -0
- package/template/lib/db/db.ts +4 -0
- package/template/oxlint.config.ts +11 -0
- package/template/package.json +23 -3
- package/template/tsconfig.json +3 -2
- package/template/vendor/kysely-dsql/dsql/adapter.ts +15 -0
- package/template/vendor/kysely-dsql/dsql/alter-column-builder.ts +105 -0
- package/template/vendor/kysely-dsql/dsql/alter-table-builders.ts +195 -0
- package/template/vendor/kysely-dsql/dsql/compatibility-rules.ts +235 -0
- package/template/vendor/kysely-dsql/dsql/create-column-builder.ts +187 -0
- package/template/vendor/kysely-dsql/dsql/create-table-builder.ts +115 -0
- package/template/vendor/kysely-dsql/dsql/dialect.ts +41 -0
- package/template/vendor/kysely-dsql/dsql/dsql-kysely.ts +93 -0
- package/template/vendor/kysely-dsql/dsql/dsql-token.ts +29 -0
- package/template/vendor/kysely-dsql/dsql/index-view-builders.ts +206 -0
- package/template/vendor/kysely-dsql/dsql/pool.ts +40 -0
- package/template/vendor/kysely-dsql/dsql/query-compiler-error.ts +18 -0
- package/template/vendor/kysely-dsql/dsql/query-compiler.test.ts +765 -0
- package/template/vendor/kysely-dsql/dsql/query-compiler.ts +259 -0
- package/template/vendor/kysely-dsql/dsql/query-validation.test.ts +518 -0
- package/template/vendor/kysely-dsql/dsql/query-validation.ts +128 -0
- package/template/vendor/kysely-dsql/dsql/raw-statement.test.ts +167 -0
- package/template/vendor/kysely-dsql/dsql/raw-statement.ts +51 -0
- package/template/vendor/kysely-dsql/dsql/schema-module.ts +167 -0
- package/template/vendor/kysely-dsql/dsql/types.ts +4 -0
- package/template/vendor/kysely-dsql/generator/create-migration.ts +86 -0
- package/template/vendor/kysely-dsql/generator/generate-types-from-pglite.ts +40 -0
- package/template/vendor/kysely-dsql/generator/generated-types-writer.ts +73 -0
- package/template/vendor/kysely-dsql/generator/migration-file.ts +73 -0
- package/template/vendor/kysely-dsql/generator/type-generator.ts +330 -0
- package/template/vendor/kysely-dsql/plugins/auto-updated-at.plugin.ts +139 -0
- package/template/vendor/kysely-dsql/plugins/index.ts +10 -0
- package/template/vendor/kysely-dsql/plugins/soft-delete.plugin.ts +217 -0
- package/template/vitest.config.ts +23 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// oxlint-disable-next-line max-classes-per-file
|
|
2
|
+
import {
|
|
3
|
+
CreateIndexBuilder,
|
|
4
|
+
CreateViewBuilder,
|
|
5
|
+
DropIndexBuilder,
|
|
6
|
+
DropTableBuilder,
|
|
7
|
+
} from "kysely";
|
|
8
|
+
import type { RawBuilder, SelectQueryBuilder } from "kysely";
|
|
9
|
+
|
|
10
|
+
import type { DSQLIndexColumnName } from "./create-column-builder.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Restricts index creation options for Aurora DSQL.
|
|
14
|
+
*
|
|
15
|
+
* Aurora DSQL requires asynchronous index creation and rejects WHERE, USING, and sort directions.
|
|
16
|
+
*
|
|
17
|
+
* @template C - The indexed column names.
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line max-classes-per-file
|
|
20
|
+
export class DSQLCreateIndexBuilder<C = never> extends CreateIndexBuilder<C> {
|
|
21
|
+
/**
|
|
22
|
+
* Adds the IF NOT EXISTS clause.
|
|
23
|
+
*
|
|
24
|
+
* @returns The restricted index builder.
|
|
25
|
+
*/
|
|
26
|
+
// @ts-expect-error DSQLCreateIndexBuilder restricts index column names and expressions for Aurora DSQL.
|
|
27
|
+
declare ifNotExists: () => DSQLCreateIndexBuilder<C>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Makes the index unique.
|
|
31
|
+
*
|
|
32
|
+
* @returns The restricted index builder.
|
|
33
|
+
*/
|
|
34
|
+
// @ts-expect-error DSQLCreateIndexBuilder restricts index column names and expressions for Aurora DSQL.
|
|
35
|
+
declare unique: () => DSQLCreateIndexBuilder<C>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Adds the NULLS NOT DISTINCT specifier.
|
|
39
|
+
*
|
|
40
|
+
* @returns The restricted index builder.
|
|
41
|
+
*/
|
|
42
|
+
// @ts-expect-error DSQLCreateIndexBuilder restricts index column names and expressions for Aurora DSQL.
|
|
43
|
+
declare nullsNotDistinct: () => DSQLCreateIndexBuilder<C>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Specifies the target table for the index.
|
|
47
|
+
*
|
|
48
|
+
* @param table - The table name.
|
|
49
|
+
* @returns The restricted index builder.
|
|
50
|
+
*/
|
|
51
|
+
// @ts-expect-error DSQLCreateIndexBuilder restricts index column names and expressions for Aurora DSQL.
|
|
52
|
+
declare on: (table: string) => DSQLCreateIndexBuilder<C>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Adds a column name to the index.
|
|
56
|
+
*
|
|
57
|
+
* @param column - The column name without sort direction.
|
|
58
|
+
* @returns The restricted index builder with the new column.
|
|
59
|
+
*/
|
|
60
|
+
// @ts-expect-error DSQLCreateIndexBuilder restricts index column names and expressions for Aurora DSQL.
|
|
61
|
+
declare column: <CL extends string>(
|
|
62
|
+
column: DSQLIndexColumnName<CL>
|
|
63
|
+
) => DSQLCreateIndexBuilder<C | CL>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Adds multiple column names to the index.
|
|
67
|
+
*
|
|
68
|
+
* @param columns - The array of column names without sort directions.
|
|
69
|
+
* @returns The restricted index builder with the added columns.
|
|
70
|
+
*/
|
|
71
|
+
// @ts-expect-error DSQLCreateIndexBuilder restricts index column names and expressions for Aurora DSQL.
|
|
72
|
+
declare columns: <CL extends string>(
|
|
73
|
+
columns: DSQLIndexColumnName<CL>[]
|
|
74
|
+
) => DSQLCreateIndexBuilder<C | CL>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Calls a custom transformation function.
|
|
78
|
+
*
|
|
79
|
+
* @param func - The transformation callback.
|
|
80
|
+
* @returns The callback result.
|
|
81
|
+
*/
|
|
82
|
+
declare $call: <T>(func: (qb: this) => T) => T;
|
|
83
|
+
|
|
84
|
+
declare where: (this: never, ...args: never[]) => never;
|
|
85
|
+
declare using: (this: never, ...args: never[]) => never;
|
|
86
|
+
declare expression: (this: never, ...args: never[]) => never;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Restricts view creation options for Aurora DSQL.
|
|
91
|
+
*
|
|
92
|
+
* Aurora DSQL supports CREATE VIEW and CREATE OR REPLACE VIEW.
|
|
93
|
+
*/
|
|
94
|
+
// eslint-disable-next-line max-classes-per-file
|
|
95
|
+
export class DSQLCreateViewBuilder extends CreateViewBuilder {
|
|
96
|
+
/**
|
|
97
|
+
* Adds the OR REPLACE clause.
|
|
98
|
+
*
|
|
99
|
+
* @returns The restricted view builder.
|
|
100
|
+
*/
|
|
101
|
+
declare orReplace: () => DSQLCreateViewBuilder;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Specifies column names for the view.
|
|
105
|
+
*
|
|
106
|
+
* @param columns - The list of view column names.
|
|
107
|
+
* @returns The restricted view builder.
|
|
108
|
+
*/
|
|
109
|
+
declare columns: (columns: string[]) => DSQLCreateViewBuilder;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Specifies the underlying query that creates the view.
|
|
113
|
+
*
|
|
114
|
+
* @param query - The select query or raw SQL expression.
|
|
115
|
+
* @returns The restricted view builder.
|
|
116
|
+
*/
|
|
117
|
+
declare as: (
|
|
118
|
+
// SAFETY: Universal query types accept any select or raw query shape.
|
|
119
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
120
|
+
query: SelectQueryBuilder<any, any, any> | RawBuilder<any>
|
|
121
|
+
) => DSQLCreateViewBuilder;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Calls a custom transformation function.
|
|
125
|
+
*
|
|
126
|
+
* @param func - The transformation callback.
|
|
127
|
+
* @returns The callback result.
|
|
128
|
+
*/
|
|
129
|
+
declare $call: <T>(func: (qb: this) => T) => T;
|
|
130
|
+
|
|
131
|
+
declare temporary: (this: never, ...args: never[]) => never;
|
|
132
|
+
declare materialized: (this: never, ...args: never[]) => never;
|
|
133
|
+
declare ifNotExists: (this: never, ...args: never[]) => never;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Restricts drop index options for Aurora DSQL.
|
|
138
|
+
*/
|
|
139
|
+
// eslint-disable-next-line max-classes-per-file
|
|
140
|
+
export class DSQLDropIndexBuilder extends DropIndexBuilder {
|
|
141
|
+
/**
|
|
142
|
+
* Adds the IF EXISTS clause.
|
|
143
|
+
*
|
|
144
|
+
* @returns The restricted drop index builder.
|
|
145
|
+
*/
|
|
146
|
+
declare ifExists: () => DSQLDropIndexBuilder;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Adds the CASCADE clause.
|
|
150
|
+
*
|
|
151
|
+
* @returns The restricted drop index builder.
|
|
152
|
+
*/
|
|
153
|
+
declare cascade: () => DSQLDropIndexBuilder;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Calls a custom transformation function.
|
|
157
|
+
*
|
|
158
|
+
* @param func - The transformation callback.
|
|
159
|
+
* @returns The callback result.
|
|
160
|
+
*/
|
|
161
|
+
declare $call: <T>(func: (qb: this) => T) => T;
|
|
162
|
+
|
|
163
|
+
declare on: (this: never, ...args: never[]) => never;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Restricts drop table options for Aurora DSQL.
|
|
168
|
+
*/
|
|
169
|
+
// eslint-disable-next-line max-classes-per-file
|
|
170
|
+
export class DSQLDropTableBuilder extends DropTableBuilder {
|
|
171
|
+
/**
|
|
172
|
+
* Adds the IF EXISTS clause.
|
|
173
|
+
*
|
|
174
|
+
* @returns The restricted drop table builder.
|
|
175
|
+
*/
|
|
176
|
+
declare ifExists: () => DSQLDropTableBuilder;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Adds the CASCADE clause.
|
|
180
|
+
*
|
|
181
|
+
* @returns The restricted drop table builder.
|
|
182
|
+
*/
|
|
183
|
+
declare cascade: () => DSQLDropTableBuilder;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Calls a custom transformation function.
|
|
187
|
+
*
|
|
188
|
+
* @param func - The transformation callback.
|
|
189
|
+
* @returns The callback result.
|
|
190
|
+
*/
|
|
191
|
+
declare $call: <T>(func: (qb: this) => T) => T;
|
|
192
|
+
|
|
193
|
+
declare temporary: (this: never, ...args: never[]) => never;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Restricts table creation builders for Aurora DSQL.
|
|
198
|
+
*
|
|
199
|
+
* @template TB - The table name.
|
|
200
|
+
* @template C - The column names in the builder.
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* db.schema.createTable("person").addColumn("id", "uuid");
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
// eslint-disable-next-line max-classes-per-file
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuroraDSQLPool,
|
|
3
|
+
type AuroraDSQLPoolConfig,
|
|
4
|
+
} from "@aws/aurora-dsql-node-postgres-connector";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for creating an Aurora DSQL Kysely client.
|
|
8
|
+
*/
|
|
9
|
+
export interface CreateDSQLKyselyOptions {
|
|
10
|
+
/** The Aurora DSQL cluster endpoint (host). */
|
|
11
|
+
readonly clusterEndpoint: string;
|
|
12
|
+
/** Optional Aurora DSQL client options. */
|
|
13
|
+
readonly clientOptions?:
|
|
14
|
+
| {
|
|
15
|
+
/**
|
|
16
|
+
* The caller-supplied AWS credential identity or provider for a production connection.
|
|
17
|
+
* The caller selects the AWS profile and creates the provider.
|
|
18
|
+
*/
|
|
19
|
+
readonly credentialsProvider?: AuroraDSQLPoolConfig["customCredentialsProvider"];
|
|
20
|
+
readonly region?: string | undefined;
|
|
21
|
+
readonly role?: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
| undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const createDSQLPool = (
|
|
27
|
+
clusterEndpoint: string,
|
|
28
|
+
clientOptions?: CreateDSQLKyselyOptions["clientOptions"]
|
|
29
|
+
): AuroraDSQLPool =>
|
|
30
|
+
new AuroraDSQLPool({
|
|
31
|
+
// SAFETY: An undefined value keeps the connector default credential chain.
|
|
32
|
+
customCredentialsProvider:
|
|
33
|
+
clientOptions?.credentialsProvider as NonNullable<
|
|
34
|
+
AuroraDSQLPoolConfig["customCredentialsProvider"]
|
|
35
|
+
>,
|
|
36
|
+
host: clusterEndpoint,
|
|
37
|
+
user: clientOptions?.role ?? "admin",
|
|
38
|
+
max: 3,
|
|
39
|
+
idleTimeoutMillis: 60_000,
|
|
40
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DSQLValidationIssue } from "./query-validation.js";
|
|
2
|
+
|
|
3
|
+
const formatIssueMessage = (issues: readonly DSQLValidationIssue[]): string =>
|
|
4
|
+
issues.map((issue) => `[${issue.code}] ${issue.message}`).join("; ");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when a SQL query or operation node violates Amazon Aurora DSQL compatibility rules.
|
|
8
|
+
*/
|
|
9
|
+
export class DSQLQueryCompilerError extends Error {
|
|
10
|
+
readonly issues: readonly DSQLValidationIssue[];
|
|
11
|
+
|
|
12
|
+
constructor(issues: readonly DSQLValidationIssue[]) {
|
|
13
|
+
const summary = formatIssueMessage(issues);
|
|
14
|
+
super(`Aurora DSQL query compilation failed: ${summary}`);
|
|
15
|
+
this.name = "DSQLQueryCompilerError";
|
|
16
|
+
this.issues = issues;
|
|
17
|
+
}
|
|
18
|
+
}
|