relq 1.0.5 → 1.0.6
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/cjs/cli/commands/add.cjs +252 -12
- package/dist/cjs/cli/commands/commit.cjs +12 -1
- package/dist/cjs/cli/commands/export.cjs +25 -19
- package/dist/cjs/cli/commands/import.cjs +219 -100
- package/dist/cjs/cli/commands/init.cjs +86 -14
- package/dist/cjs/cli/commands/pull.cjs +104 -23
- package/dist/cjs/cli/commands/push.cjs +38 -3
- package/dist/cjs/cli/index.cjs +9 -1
- package/dist/cjs/cli/utils/ast/codegen/builder.cjs +297 -0
- package/dist/cjs/cli/utils/ast/codegen/constraints.cjs +185 -0
- package/dist/cjs/cli/utils/ast/codegen/defaults.cjs +311 -0
- package/dist/cjs/cli/utils/ast/codegen/index.cjs +24 -0
- package/dist/cjs/cli/utils/ast/codegen/type-map.cjs +116 -0
- package/dist/cjs/cli/utils/ast/codegen/utils.cjs +69 -0
- package/dist/cjs/cli/utils/ast/index.cjs +19 -0
- package/dist/cjs/cli/utils/ast/transformer/helpers.cjs +154 -0
- package/dist/cjs/cli/utils/ast/transformer/index.cjs +25 -0
- package/dist/cjs/cli/utils/ast/types.cjs +2 -0
- package/dist/cjs/cli/utils/ast-codegen.cjs +949 -0
- package/dist/cjs/cli/utils/ast-transformer.cjs +916 -0
- package/dist/cjs/cli/utils/change-tracker.cjs +50 -1
- package/dist/cjs/cli/utils/cli-utils.cjs +151 -0
- package/dist/cjs/cli/utils/fast-introspect.cjs +149 -23
- package/dist/cjs/cli/utils/pg-parser.cjs +1 -0
- package/dist/cjs/cli/utils/repo-manager.cjs +121 -4
- package/dist/cjs/cli/utils/schema-comparator.cjs +98 -14
- package/dist/cjs/cli/utils/schema-introspect.cjs +56 -19
- package/dist/cjs/cli/utils/snapshot-manager.cjs +0 -1
- package/dist/cjs/cli/utils/sql-generator.cjs +353 -64
- package/dist/cjs/cli/utils/type-generator.cjs +114 -15
- package/dist/cjs/core/relq-client.cjs +22 -6
- package/dist/cjs/schema-definition/column-types.cjs +149 -13
- package/dist/cjs/schema-definition/defaults.cjs +72 -0
- package/dist/cjs/schema-definition/index.cjs +15 -1
- package/dist/cjs/schema-definition/introspection.cjs +7 -3
- package/dist/cjs/schema-definition/pg-relations.cjs +169 -0
- package/dist/cjs/schema-definition/pg-view.cjs +30 -0
- package/dist/cjs/schema-definition/table-definition.cjs +110 -4
- package/dist/cjs/types/config-types.cjs +13 -4
- package/dist/cjs/utils/aws-dsql.cjs +177 -0
- package/dist/config.d.ts +146 -1
- package/dist/esm/cli/commands/add.js +250 -13
- package/dist/esm/cli/commands/commit.js +12 -1
- package/dist/esm/cli/commands/export.js +25 -19
- package/dist/esm/cli/commands/import.js +221 -102
- package/dist/esm/cli/commands/init.js +86 -14
- package/dist/esm/cli/commands/pull.js +106 -25
- package/dist/esm/cli/commands/push.js +39 -4
- package/dist/esm/cli/index.js +9 -1
- package/dist/esm/cli/utils/ast/codegen/builder.js +291 -0
- package/dist/esm/cli/utils/ast/codegen/constraints.js +176 -0
- package/dist/esm/cli/utils/ast/codegen/defaults.js +305 -0
- package/dist/esm/cli/utils/ast/codegen/index.js +6 -0
- package/dist/esm/cli/utils/ast/codegen/type-map.js +111 -0
- package/dist/esm/cli/utils/ast/codegen/utils.js +60 -0
- package/dist/esm/cli/utils/ast/index.js +3 -0
- package/dist/esm/cli/utils/ast/transformer/helpers.js +141 -0
- package/dist/esm/cli/utils/ast/transformer/index.js +2 -0
- package/dist/esm/cli/utils/ast/types.js +1 -0
- package/dist/esm/cli/utils/ast-codegen.js +945 -0
- package/dist/esm/cli/utils/ast-transformer.js +907 -0
- package/dist/esm/cli/utils/change-tracker.js +50 -1
- package/dist/esm/cli/utils/cli-utils.js +147 -0
- package/dist/esm/cli/utils/fast-introspect.js +149 -23
- package/dist/esm/cli/utils/pg-parser.js +1 -0
- package/dist/esm/cli/utils/repo-manager.js +114 -4
- package/dist/esm/cli/utils/schema-comparator.js +98 -14
- package/dist/esm/cli/utils/schema-introspect.js +56 -19
- package/dist/esm/cli/utils/snapshot-manager.js +0 -1
- package/dist/esm/cli/utils/sql-generator.js +353 -64
- package/dist/esm/cli/utils/type-generator.js +114 -15
- package/dist/esm/core/relq-client.js +23 -7
- package/dist/esm/schema-definition/column-types.js +146 -12
- package/dist/esm/schema-definition/defaults.js +69 -0
- package/dist/esm/schema-definition/index.js +3 -0
- package/dist/esm/schema-definition/introspection.js +7 -3
- package/dist/esm/schema-definition/pg-relations.js +161 -0
- package/dist/esm/schema-definition/pg-view.js +24 -0
- package/dist/esm/schema-definition/table-definition.js +110 -4
- package/dist/esm/types/config-types.js +12 -4
- package/dist/esm/utils/aws-dsql.js +139 -0
- package/dist/index.d.ts +159 -1
- package/dist/schema-builder.d.ts +1314 -32
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -191,6 +191,14 @@ export type IsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE
|
|
|
191
191
|
* Transaction access modes
|
|
192
192
|
*/
|
|
193
193
|
export type TransactionMode = "READ WRITE" | "READ ONLY";
|
|
194
|
+
/**
|
|
195
|
+
* Type-safe PostgreSQL DEFAULT value helpers
|
|
196
|
+
* Covers all PostgreSQL default value types with 100% typed output
|
|
197
|
+
*/
|
|
198
|
+
export interface DefaultValue {
|
|
199
|
+
readonly $sql: string;
|
|
200
|
+
readonly $isDefault: true;
|
|
201
|
+
}
|
|
194
202
|
declare const EMPTY_OBJECT: unique symbol;
|
|
195
203
|
declare const EMPTY_ARRAY: unique symbol;
|
|
196
204
|
export interface ColumnConfig<T = unknown> {
|
|
@@ -198,7 +206,7 @@ export interface ColumnConfig<T = unknown> {
|
|
|
198
206
|
$sqlType?: string;
|
|
199
207
|
$tsType?: T;
|
|
200
208
|
$nullable?: boolean;
|
|
201
|
-
$default?: T | (() => T) | string | object | typeof EMPTY_OBJECT | typeof EMPTY_ARRAY;
|
|
209
|
+
$default?: T | (() => T) | string | object | typeof EMPTY_OBJECT | typeof EMPTY_ARRAY | DefaultValue;
|
|
202
210
|
$primaryKey?: boolean;
|
|
203
211
|
$unique?: boolean;
|
|
204
212
|
$references?: {
|
|
@@ -220,6 +228,7 @@ export interface ColumnConfig<T = unknown> {
|
|
|
220
228
|
$scale?: number;
|
|
221
229
|
$withTimezone?: boolean;
|
|
222
230
|
$columnName?: string;
|
|
231
|
+
$trackingId?: string;
|
|
223
232
|
}
|
|
224
233
|
/**
|
|
225
234
|
* Partition Types and Builders
|
|
@@ -270,6 +279,58 @@ export interface IndexDefinition {
|
|
|
270
279
|
include?: string[];
|
|
271
280
|
/** Expression for expression-based indexes */
|
|
272
281
|
expression?: string;
|
|
282
|
+
/**
|
|
283
|
+
* Generate CREATE INDEX IF NOT EXISTS instead of CREATE INDEX.
|
|
284
|
+
*
|
|
285
|
+
* When true, the generated SQL will be:
|
|
286
|
+
* `CREATE INDEX IF NOT EXISTS index_name ON table_name (...)`
|
|
287
|
+
*
|
|
288
|
+
* This makes index creation idempotent - if the index already exists,
|
|
289
|
+
* PostgreSQL will skip creation instead of throwing an error.
|
|
290
|
+
*
|
|
291
|
+
* Use cases:
|
|
292
|
+
* - Idempotent migrations that can be run multiple times safely
|
|
293
|
+
* - Manual schema management where you want to avoid errors on re-runs
|
|
294
|
+
* - Incremental schema updates in development environments
|
|
295
|
+
* - CI/CD pipelines where schema might already exist
|
|
296
|
+
*
|
|
297
|
+
* @default false
|
|
298
|
+
*/
|
|
299
|
+
ifNotExists?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Use ON ONLY clause for partitioned tables.
|
|
302
|
+
*
|
|
303
|
+
* When true, the generated SQL will be:
|
|
304
|
+
* `CREATE INDEX index_name ON ONLY table_name (...)`
|
|
305
|
+
*
|
|
306
|
+
* This creates an index on the parent partitioned table only, without
|
|
307
|
+
* automatically creating matching indexes on child partitions. Each
|
|
308
|
+
* partition must have its own index created separately.
|
|
309
|
+
*
|
|
310
|
+
* Use cases:
|
|
311
|
+
* - When you want different index configurations per partition
|
|
312
|
+
* - When partitions have different access patterns
|
|
313
|
+
* - When you want to control index creation timing per partition
|
|
314
|
+
* - For declarative partitioning with custom index strategies
|
|
315
|
+
* - When some partitions don't need certain indexes (e.g., archive partitions)
|
|
316
|
+
*
|
|
317
|
+
* @default false
|
|
318
|
+
* @see https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE-MAINTENANCE
|
|
319
|
+
*/
|
|
320
|
+
tableOnly?: boolean;
|
|
321
|
+
/** Index comment/description */
|
|
322
|
+
comment?: string;
|
|
323
|
+
/** Tracking ID for rename detection */
|
|
324
|
+
trackingId?: string;
|
|
325
|
+
}
|
|
326
|
+
/** Constraint definition result */
|
|
327
|
+
export interface ConstraintDef {
|
|
328
|
+
readonly $type: "PRIMARY KEY" | "UNIQUE" | "EXCLUDE";
|
|
329
|
+
readonly $name: string;
|
|
330
|
+
readonly $columns: string[];
|
|
331
|
+
readonly $expression?: string;
|
|
332
|
+
/** Tracking ID for rename detection */
|
|
333
|
+
readonly $trackingId?: string;
|
|
273
334
|
}
|
|
274
335
|
export type IsSerialType<T extends string> = T extends "SERIAL" | "BIGSERIAL" | "SMALLSERIAL" | "SERIAL4" | "SERIAL2" | "SERIAL8" ? true : false;
|
|
275
336
|
export type HasDefault<C> = C extends {
|
|
@@ -355,6 +416,8 @@ export interface TableDefinition<T extends Record<string, ColumnConfig>> {
|
|
|
355
416
|
expression: string;
|
|
356
417
|
name?: string;
|
|
357
418
|
}>;
|
|
419
|
+
/** Table-level constraints (composite PKs, etc.) */
|
|
420
|
+
$constraints?: ConstraintDef[];
|
|
358
421
|
$foreignKeys?: Array<{
|
|
359
422
|
columns: string[];
|
|
360
423
|
references: {
|
|
@@ -364,12 +427,18 @@ export interface TableDefinition<T extends Record<string, ColumnConfig>> {
|
|
|
364
427
|
onDelete?: string;
|
|
365
428
|
onUpdate?: string;
|
|
366
429
|
name?: string;
|
|
430
|
+
/** Tracking ID for rename detection */
|
|
431
|
+
trackingId?: string;
|
|
367
432
|
}>;
|
|
368
433
|
$indexes?: IndexDefinition[];
|
|
369
434
|
$inherits?: string[];
|
|
370
435
|
$partitionBy?: PartitionStrategyDef;
|
|
371
436
|
$tablespace?: string;
|
|
372
437
|
$withOptions?: Record<string, unknown>;
|
|
438
|
+
/** Whether to use CREATE TABLE IF NOT EXISTS */
|
|
439
|
+
$ifNotExists?: boolean;
|
|
440
|
+
/** Tracking ID for rename detection */
|
|
441
|
+
$trackingId?: string;
|
|
373
442
|
$inferSelect: BuildSelectType<T>;
|
|
374
443
|
$inferInsert: BuildInsertType<T>;
|
|
375
444
|
toSQL(): string;
|
|
@@ -5006,6 +5075,76 @@ export interface QueryResultRow {
|
|
|
5006
5075
|
export interface QueryResult<R extends QueryResultRow = any> extends QueryResultBase {
|
|
5007
5076
|
rows: R[];
|
|
5008
5077
|
}
|
|
5078
|
+
/**
|
|
5079
|
+
* AWS regions with autocomplete support
|
|
5080
|
+
* Includes all standard AWS regions that may support DSQL
|
|
5081
|
+
*/
|
|
5082
|
+
export type AwsRegion = "us-east-1" | "us-east-2" | "us-west-1" | "us-west-2" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "eu-central-1" | "eu-central-2" | "eu-north-1" | "eu-south-1" | "eu-south-2" | "ap-east-1" | "ap-south-1" | "ap-south-2" | "ap-northeast-1" | "ap-northeast-2" | "ap-northeast-3" | "ap-southeast-1" | "ap-southeast-2" | "ap-southeast-3" | "ap-southeast-4" | "me-south-1" | "me-central-1" | "af-south-1" | "il-central-1" | "sa-east-1" | "ca-central-1" | "ca-west-1" | "us-gov-east-1" | "us-gov-west-1" | (string & {});
|
|
5083
|
+
/**
|
|
5084
|
+
* AWS DSQL (Aurora Serverless) configuration
|
|
5085
|
+
* When provided, Relq automatically handles IAM token generation and caching
|
|
5086
|
+
*
|
|
5087
|
+
* @example
|
|
5088
|
+
* ```typescript
|
|
5089
|
+
* const db = new Relq(schema, {
|
|
5090
|
+
* database: 'postgres',
|
|
5091
|
+
* aws: {
|
|
5092
|
+
* hostname: 'abc123.dsql.us-east-1.on.aws',
|
|
5093
|
+
* region: 'us-east-1', // Autocomplete supported!
|
|
5094
|
+
* accessKeyId: 'AKIA...',
|
|
5095
|
+
* secretAccessKey: '...'
|
|
5096
|
+
* }
|
|
5097
|
+
* });
|
|
5098
|
+
* ```
|
|
5099
|
+
*/
|
|
5100
|
+
export interface AwsDbConfig {
|
|
5101
|
+
/**
|
|
5102
|
+
* DSQL cluster hostname
|
|
5103
|
+
* @example "7btnrhwkzis7lsxg24cqdyzsm4.dsql.us-east-1.on.aws"
|
|
5104
|
+
*/
|
|
5105
|
+
hostname: string;
|
|
5106
|
+
/**
|
|
5107
|
+
* AWS region with autocomplete support
|
|
5108
|
+
* @example "us-east-1"
|
|
5109
|
+
*/
|
|
5110
|
+
region: AwsRegion;
|
|
5111
|
+
/**
|
|
5112
|
+
* AWS Access Key ID
|
|
5113
|
+
* Required unless useDefaultCredentials is true
|
|
5114
|
+
*/
|
|
5115
|
+
accessKeyId?: string;
|
|
5116
|
+
/**
|
|
5117
|
+
* AWS Secret Access Key
|
|
5118
|
+
* Required unless useDefaultCredentials is true
|
|
5119
|
+
*/
|
|
5120
|
+
secretAccessKey?: string;
|
|
5121
|
+
/**
|
|
5122
|
+
* Database port (inherited from root config if not specified)
|
|
5123
|
+
* @default 5432
|
|
5124
|
+
*/
|
|
5125
|
+
port?: number;
|
|
5126
|
+
/**
|
|
5127
|
+
* Database user (inherited from root config if not specified)
|
|
5128
|
+
* @default 'admin'
|
|
5129
|
+
*/
|
|
5130
|
+
user?: string;
|
|
5131
|
+
/**
|
|
5132
|
+
* Enable SSL/TLS for connection
|
|
5133
|
+
* @default true (DSQL typically requires SSL)
|
|
5134
|
+
*/
|
|
5135
|
+
ssl?: boolean;
|
|
5136
|
+
/**
|
|
5137
|
+
* Use AWS default credential provider chain
|
|
5138
|
+
* (env vars, IAM role, ~/.aws/credentials)
|
|
5139
|
+
* @default false
|
|
5140
|
+
*/
|
|
5141
|
+
useDefaultCredentials?: boolean;
|
|
5142
|
+
/**
|
|
5143
|
+
* Token expiration time in seconds
|
|
5144
|
+
* @default 604800 (7 days)
|
|
5145
|
+
*/
|
|
5146
|
+
tokenExpiresIn?: number;
|
|
5147
|
+
}
|
|
5009
5148
|
/**
|
|
5010
5149
|
* Relq database configuration
|
|
5011
5150
|
* Supports both pooled and single connection modes
|
|
@@ -5204,6 +5343,25 @@ export interface RelqConfig {
|
|
|
5204
5343
|
* @default 1000
|
|
5205
5344
|
*/
|
|
5206
5345
|
commitLimit?: number;
|
|
5346
|
+
/**
|
|
5347
|
+
* AWS DSQL configuration
|
|
5348
|
+
* When provided, enables first-class AWS Aurora DSQL support
|
|
5349
|
+
* with automatic IAM token generation and caching
|
|
5350
|
+
*
|
|
5351
|
+
* @example
|
|
5352
|
+
* ```typescript
|
|
5353
|
+
* const db = new Relq(schema, {
|
|
5354
|
+
* database: 'postgres',
|
|
5355
|
+
* aws: {
|
|
5356
|
+
* hostname: 'abc123.dsql.us-east-1.on.aws',
|
|
5357
|
+
* region: 'us-east-1', // Autocomplete!
|
|
5358
|
+
* accessKeyId: 'AKIA...',
|
|
5359
|
+
* secretAccessKey: '...'
|
|
5360
|
+
* }
|
|
5361
|
+
* });
|
|
5362
|
+
* ```
|
|
5363
|
+
*/
|
|
5364
|
+
aws?: AwsDbConfig;
|
|
5207
5365
|
}
|
|
5208
5366
|
/**
|
|
5209
5367
|
* Metadata returned with all database operations
|