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.
Files changed (84) hide show
  1. package/dist/cjs/cli/commands/add.cjs +252 -12
  2. package/dist/cjs/cli/commands/commit.cjs +12 -1
  3. package/dist/cjs/cli/commands/export.cjs +25 -19
  4. package/dist/cjs/cli/commands/import.cjs +219 -100
  5. package/dist/cjs/cli/commands/init.cjs +86 -14
  6. package/dist/cjs/cli/commands/pull.cjs +104 -23
  7. package/dist/cjs/cli/commands/push.cjs +38 -3
  8. package/dist/cjs/cli/index.cjs +9 -1
  9. package/dist/cjs/cli/utils/ast/codegen/builder.cjs +297 -0
  10. package/dist/cjs/cli/utils/ast/codegen/constraints.cjs +185 -0
  11. package/dist/cjs/cli/utils/ast/codegen/defaults.cjs +311 -0
  12. package/dist/cjs/cli/utils/ast/codegen/index.cjs +24 -0
  13. package/dist/cjs/cli/utils/ast/codegen/type-map.cjs +116 -0
  14. package/dist/cjs/cli/utils/ast/codegen/utils.cjs +69 -0
  15. package/dist/cjs/cli/utils/ast/index.cjs +19 -0
  16. package/dist/cjs/cli/utils/ast/transformer/helpers.cjs +154 -0
  17. package/dist/cjs/cli/utils/ast/transformer/index.cjs +25 -0
  18. package/dist/cjs/cli/utils/ast/types.cjs +2 -0
  19. package/dist/cjs/cli/utils/ast-codegen.cjs +949 -0
  20. package/dist/cjs/cli/utils/ast-transformer.cjs +916 -0
  21. package/dist/cjs/cli/utils/change-tracker.cjs +50 -1
  22. package/dist/cjs/cli/utils/cli-utils.cjs +151 -0
  23. package/dist/cjs/cli/utils/fast-introspect.cjs +149 -23
  24. package/dist/cjs/cli/utils/pg-parser.cjs +1 -0
  25. package/dist/cjs/cli/utils/repo-manager.cjs +121 -4
  26. package/dist/cjs/cli/utils/schema-comparator.cjs +98 -14
  27. package/dist/cjs/cli/utils/schema-introspect.cjs +56 -19
  28. package/dist/cjs/cli/utils/snapshot-manager.cjs +0 -1
  29. package/dist/cjs/cli/utils/sql-generator.cjs +353 -64
  30. package/dist/cjs/cli/utils/type-generator.cjs +114 -15
  31. package/dist/cjs/core/relq-client.cjs +22 -6
  32. package/dist/cjs/schema-definition/column-types.cjs +149 -13
  33. package/dist/cjs/schema-definition/defaults.cjs +72 -0
  34. package/dist/cjs/schema-definition/index.cjs +15 -1
  35. package/dist/cjs/schema-definition/introspection.cjs +7 -3
  36. package/dist/cjs/schema-definition/pg-relations.cjs +169 -0
  37. package/dist/cjs/schema-definition/pg-view.cjs +30 -0
  38. package/dist/cjs/schema-definition/table-definition.cjs +110 -4
  39. package/dist/cjs/types/config-types.cjs +13 -4
  40. package/dist/cjs/utils/aws-dsql.cjs +177 -0
  41. package/dist/config.d.ts +146 -1
  42. package/dist/esm/cli/commands/add.js +250 -13
  43. package/dist/esm/cli/commands/commit.js +12 -1
  44. package/dist/esm/cli/commands/export.js +25 -19
  45. package/dist/esm/cli/commands/import.js +221 -102
  46. package/dist/esm/cli/commands/init.js +86 -14
  47. package/dist/esm/cli/commands/pull.js +106 -25
  48. package/dist/esm/cli/commands/push.js +39 -4
  49. package/dist/esm/cli/index.js +9 -1
  50. package/dist/esm/cli/utils/ast/codegen/builder.js +291 -0
  51. package/dist/esm/cli/utils/ast/codegen/constraints.js +176 -0
  52. package/dist/esm/cli/utils/ast/codegen/defaults.js +305 -0
  53. package/dist/esm/cli/utils/ast/codegen/index.js +6 -0
  54. package/dist/esm/cli/utils/ast/codegen/type-map.js +111 -0
  55. package/dist/esm/cli/utils/ast/codegen/utils.js +60 -0
  56. package/dist/esm/cli/utils/ast/index.js +3 -0
  57. package/dist/esm/cli/utils/ast/transformer/helpers.js +141 -0
  58. package/dist/esm/cli/utils/ast/transformer/index.js +2 -0
  59. package/dist/esm/cli/utils/ast/types.js +1 -0
  60. package/dist/esm/cli/utils/ast-codegen.js +945 -0
  61. package/dist/esm/cli/utils/ast-transformer.js +907 -0
  62. package/dist/esm/cli/utils/change-tracker.js +50 -1
  63. package/dist/esm/cli/utils/cli-utils.js +147 -0
  64. package/dist/esm/cli/utils/fast-introspect.js +149 -23
  65. package/dist/esm/cli/utils/pg-parser.js +1 -0
  66. package/dist/esm/cli/utils/repo-manager.js +114 -4
  67. package/dist/esm/cli/utils/schema-comparator.js +98 -14
  68. package/dist/esm/cli/utils/schema-introspect.js +56 -19
  69. package/dist/esm/cli/utils/snapshot-manager.js +0 -1
  70. package/dist/esm/cli/utils/sql-generator.js +353 -64
  71. package/dist/esm/cli/utils/type-generator.js +114 -15
  72. package/dist/esm/core/relq-client.js +23 -7
  73. package/dist/esm/schema-definition/column-types.js +146 -12
  74. package/dist/esm/schema-definition/defaults.js +69 -0
  75. package/dist/esm/schema-definition/index.js +3 -0
  76. package/dist/esm/schema-definition/introspection.js +7 -3
  77. package/dist/esm/schema-definition/pg-relations.js +161 -0
  78. package/dist/esm/schema-definition/pg-view.js +24 -0
  79. package/dist/esm/schema-definition/table-definition.js +110 -4
  80. package/dist/esm/types/config-types.js +12 -4
  81. package/dist/esm/utils/aws-dsql.js +139 -0
  82. package/dist/index.d.ts +159 -1
  83. package/dist/schema-builder.d.ts +1314 -32
  84. 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