rake-db 2.27.22 → 2.27.24

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as pqb from 'pqb';
2
- import { ColumnsShape, Db, TableData, NoPrimaryKeyOption, MaybeArray, ColumnType, RawSQLBase, ColumnDataCheckBase, RecordString, ColumnTypeBase, EnumColumn, EmptyObject, ColumnSchemaConfig, DefaultColumnTypes, DefaultSchemaConfig, QueryLogOptions, AdapterBase, DbResult, MaybePromise, QueryLogObject, TableDataFn, TableDataItem, DbDomainArg, raw, SearchWeight, ColumnsByType, DbStructureDomainsMap, QueryBase } from 'pqb';
2
+ import { ColumnsShape, Db, TableData, NoPrimaryKeyOption, MaybeArray, Column, RawSQLBase, RecordString, EnumColumn, EmptyObject, ColumnSchemaConfig, DefaultColumnTypes, DefaultSchemaConfig, QueryLogOptions, AdapterBase, DbResult, MaybePromise, QueryLogObject, TableDataFn, TableDataItem, DbDomainArg, raw, SearchWeight, ColumnsByType, DbStructureDomainsMap, QueryBase } from 'pqb';
3
3
 
4
4
  interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
5
5
  table: Db<Table, Shape>;
@@ -33,7 +33,7 @@ declare namespace RakeDbAst {
33
33
  namespace ChangeTableItem {
34
34
  interface Column {
35
35
  type: 'add' | 'drop';
36
- item: ColumnType;
36
+ item: Column;
37
37
  dropMode?: DropMode;
38
38
  }
39
39
  interface Change {
@@ -53,7 +53,7 @@ declare namespace RakeDbAst {
53
53
  }
54
54
  }
55
55
  interface ColumnChange {
56
- column?: ColumnType;
56
+ column?: Column;
57
57
  type?: string;
58
58
  collate?: string;
59
59
  default?: unknown | RawSQLBase;
@@ -61,7 +61,7 @@ declare namespace RakeDbAst {
61
61
  comment?: string | null;
62
62
  compression?: string;
63
63
  primaryKey?: boolean;
64
- checks?: ColumnDataCheckBase[];
64
+ checks?: Column.Data.Check[];
65
65
  foreignKeys?: TableData.ColumnReferences[];
66
66
  indexes?: TableData.ColumnIndex[];
67
67
  excludes?: TableData.ColumnExclude[];
@@ -134,7 +134,7 @@ declare namespace RakeDbAst {
134
134
  action: 'create' | 'drop';
135
135
  schema?: string;
136
136
  name: string;
137
- baseType: ColumnType;
137
+ baseType: Column;
138
138
  }
139
139
  interface Collation {
140
140
  type: 'collation';
@@ -198,11 +198,11 @@ declare namespace RakeDbAst {
198
198
  }
199
199
  }
200
200
 
201
- declare function add(item: ColumnType, options?: {
201
+ declare function add(item: Column, options?: {
202
202
  dropMode?: DropMode;
203
203
  }): SpecialChange;
204
204
  declare function add(emptyObject: EmptyObject): SpecialChange;
205
- declare function add(items: Record<string, ColumnType>, options?: {
205
+ declare function add(items: Record<string, Column>, options?: {
206
206
  dropMode?: DropMode;
207
207
  }): Record<string, RakeDbAst.ChangeTableItem.Column>;
208
208
  interface Change extends RakeDbAst.ChangeTableItem.Change, ChangeOptions {
@@ -222,7 +222,7 @@ declare const tableChangeMethods: {
222
222
  name(name: string): any;
223
223
  add: typeof add;
224
224
  drop: typeof add;
225
- change(from: ColumnType | OneWayChange, to: ColumnType | OneWayChange, using?: ChangeOptions): Change;
225
+ change(from: Column | OneWayChange, to: Column | OneWayChange, using?: ChangeOptions): Change;
226
226
  default(value: unknown | RawSQLBase): OneWayChange;
227
227
  nullable(): OneWayChange;
228
228
  nonNullable(): OneWayChange;
@@ -260,13 +260,18 @@ declare const tableChangeMethods: {
260
260
  index(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.OptionsArg | undefined): pqb.NonUniqDataItem;
261
261
  searchIndex(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.TsVectorArg | undefined): pqb.NonUniqDataItem;
262
262
  exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<string>[], options?: TableData.Exclude.Options | undefined): pqb.NonUniqDataItem;
263
- foreignKey<ForeignTable extends string | (() => pqb.ForeignKeyTable), ForeignColumns extends ForeignTable extends () => pqb.ForeignKeyTable ? [pqb.ColumnNameOfTable<ReturnType<ForeignTable>>, ...pqb.ColumnNameOfTable<ReturnType<ForeignTable>>[]] : [string, ...string[]]>(columns: [string, ...string[]], fnOrTable: ForeignTable, foreignColumns: ForeignColumns, options?: TableData.References.Options | undefined): pqb.NonUniqDataItem;
264
- check(check: RawSQLBase<pqb.QueryColumn<unknown, any>, unknown>, name?: string | undefined): pqb.NonUniqDataItem;
263
+ foreignKey<Shape>(columns: [string, ...string[]], fnOrTable: () => new () => {
264
+ columns: {
265
+ shape: Shape;
266
+ };
267
+ }, foreignColumns: [keyof Shape, ...(keyof Shape)[]], options?: TableData.References.Options | undefined): pqb.NonUniqDataItem;
268
+ foreignKey(columns: [string, ...string[]], fnOrTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options | undefined): pqb.NonUniqDataItem;
269
+ check(check: RawSQLBase<Column.Pick.QueryColumn, unknown>, name?: string | undefined): pqb.NonUniqDataItem;
265
270
  sql: pqb.SqlFn;
266
271
  enum(name: string): EnumColumn<pqb.DefaultSchemaConfig, undefined, [string, ...string[]]>;
267
272
  };
268
273
  type TableChanger<CT> = MigrationColumnTypes<CT> & TableChangeMethods;
269
- type TableChangeData = Record<string, RakeDbAst.ChangeTableItem.Column | RakeDbAst.ChangeTableItem.Rename | Change | SpecialChange | ColumnTypeBase>;
274
+ type TableChangeData = Record<string, RakeDbAst.ChangeTableItem.Column | RakeDbAst.ChangeTableItem.Rename | Change | SpecialChange | Column.Pick.Data>;
270
275
 
271
276
  interface RakeDbCtx {
272
277
  migrationsPromise?: Promise<MigrationsSet>;
@@ -492,7 +497,7 @@ interface RakeDbRenameMigrationsInput {
492
497
  map: RakeDbRenameMigrationsMap;
493
498
  }
494
499
  declare const migrationConfigDefaults: RakeDbBaseConfig<ColumnSchemaConfig>;
495
- declare const processRakeDbConfig: <SchemaConfig extends ColumnSchemaConfig<pqb.ColumnTypeBase<pqb.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, pqb.ColumnDataBase>>, CT>(config: InputRakeDbConfig<SchemaConfig, CT>, args?: string[]) => RakeDbConfig<SchemaConfig, CT>;
500
+ declare const processRakeDbConfig: <SchemaConfig extends ColumnSchemaConfig<pqb.Column.Pick.Data>, CT>(config: InputRakeDbConfig<SchemaConfig, CT>, args?: string[]) => RakeDbConfig<SchemaConfig, CT>;
496
501
 
497
502
  type DropMode = 'CASCADE' | 'RESTRICT';
498
503
  type TableOptions = {
@@ -741,7 +746,7 @@ declare class Migration<CT> {
741
746
  * @param columnName - name of the column to add
742
747
  * @param fn - function returning a type of the column
743
748
  */
744
- addColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes<CT>) => ColumnType): Promise<void>;
749
+ addColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes<CT>) => Column): Promise<void>;
745
750
  /**
746
751
  * Drop the schema, create it on rollback. See {@link addColumn}.
747
752
  *
@@ -749,7 +754,7 @@ declare class Migration<CT> {
749
754
  * @param columnName - name of the column to add
750
755
  * @param fn - function returning a type of the column
751
756
  */
752
- dropColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes<CT>) => ColumnType): Promise<void>;
757
+ dropColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes<CT>) => Column): Promise<void>;
753
758
  /**
754
759
  * Add an index to the table on migrating, and remove it on rollback.
755
760
  *
@@ -1497,7 +1502,7 @@ interface RakeDbChangeFnWithPromise<CT> extends RakeDbChangeFn<CT> {
1497
1502
  declare const rakeDbWithAdapters: RakeDbFn<AdapterBase[]>;
1498
1503
  declare const makeChange: (config: RakeDbConfig<ColumnSchemaConfig, unknown>) => (fn: ChangeCallback<unknown>) => MigrationChange;
1499
1504
 
1500
- declare const encodeColumnDefault: (def: unknown, values: unknown[], column?: ColumnTypeBase) => string | null;
1505
+ declare const encodeColumnDefault: (def: unknown, values: unknown[], column?: Column.Pick.Data) => string | null;
1501
1506
  declare const getConstraintName: (table: string, constraint: {
1502
1507
  references?: {
1503
1508
  columns: string[];
@@ -1730,14 +1735,14 @@ interface StructureToAstTableData {
1730
1735
  declare const makeStructureToAstCtx: (config: AnyRakeDbConfig, currentSchema: string) => StructureToAstCtx;
1731
1736
  declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config: AnyRakeDbConfig) => Promise<RakeDbAst[]>;
1732
1737
  declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
1733
- declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => ColumnType<pqb.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any>;
1738
+ declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => Column<pqb.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any>;
1734
1739
  declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: 'create' | 'drop', domains: DbStructureDomainsMap) => RakeDbAst.Table;
1735
1740
  declare const getDbStructureTableData: (data: IntrospectedStructure, { name, schemaName }: DbStructure.Table) => StructureToAstTableData;
1736
1741
  interface ColumnChecks {
1737
1742
  [K: string]: string[];
1738
1743
  }
1739
1744
  declare const getDbTableColumnsChecks: (tableData: StructureToAstTableData) => ColumnChecks;
1740
- declare const dbColumnToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, tableName: string, item: DbStructure.Column, table?: DbStructure.Table, tableData?: StructureToAstTableData, checks?: ColumnChecks) => [key: string, column: ColumnType];
1745
+ declare const dbColumnToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, tableName: string, item: DbStructure.Column, table?: DbStructure.Table, tableData?: StructureToAstTableData, checks?: ColumnChecks) => [key: string, column: Column];
1741
1746
 
1742
1747
  declare const writeMigrationFile: (config: AnyRakeDbConfig, version: string, name: string, migrationCode: string) => Promise<void>;
1743
1748
  declare const makeFileVersion: (ctx: RakeDbCtx, config: AnyRakeDbConfig) => Promise<string>;
@@ -1755,7 +1760,7 @@ declare const makeMigrateAdapter: (config?: Partial<MigrateFnConfig>) => ((adapt
1755
1760
  declare class RakeDbError extends Error {
1756
1761
  }
1757
1762
 
1758
- declare const runCommand: <SchemaConfig extends ColumnSchemaConfig<pqb.ColumnTypeBase<pqb.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, pqb.ColumnDataBase>>, CT>(adapters: AdapterBase[], config: RakeDbConfig<SchemaConfig, CT>, args?: string[]) => Promise<RakeDbResult>;
1763
+ declare const runCommand: <SchemaConfig extends ColumnSchemaConfig<pqb.Column.Pick.Data>, CT>(adapters: AdapterBase[], config: RakeDbConfig<SchemaConfig, CT>, args?: string[]) => Promise<RakeDbResult>;
1759
1764
  interface RakeDbCommand {
1760
1765
  run(adapters: AdapterBase[], config: AnyRakeDbConfig, args: string[]): MaybePromise<unknown>;
1761
1766
  help: string;
package/dist/index.js CHANGED
@@ -623,14 +623,14 @@ const addOrDropChanges = [];
623
623
  function add(item, options) {
624
624
  pqb.consumeColumnName();
625
625
  setName(this, item);
626
- if (item instanceof pqb.ColumnType) {
626
+ if (item instanceof pqb.Column) {
627
627
  const result = addOrDrop("add", item, options);
628
628
  if (result.type === "change") return result;
629
629
  addOrDropChanges.push(result);
630
630
  return addOrDropChanges.length - 1;
631
631
  }
632
632
  for (const key in item) {
633
- if (item[key] instanceof pqb.ColumnTypeBase) {
633
+ if (item[key] instanceof pqb.Column) {
634
634
  const result = {};
635
635
  for (const key2 in item) {
636
636
  result[key2] = {
@@ -649,14 +649,14 @@ function add(item, options) {
649
649
  const drop = function(item, options) {
650
650
  pqb.consumeColumnName();
651
651
  setName(this, item);
652
- if (item instanceof pqb.ColumnType) {
652
+ if (item instanceof pqb.Column) {
653
653
  const result = addOrDrop("drop", item, options);
654
654
  if (result.type === "change") return result;
655
655
  addOrDropChanges.push(result);
656
656
  return addOrDropChanges.length - 1;
657
657
  }
658
658
  for (const key in item) {
659
- if (item[key] instanceof pqb.ColumnTypeBase) {
659
+ if (item[key] instanceof pqb.Column) {
660
660
  const result = {};
661
661
  for (const key2 in item) {
662
662
  result[key2] = {
@@ -698,7 +698,7 @@ const addOrDrop = (type, item, options) => {
698
698
  };
699
699
  };
700
700
  const columnTypeToColumnChange = (item, name) => {
701
- if (item instanceof pqb.ColumnType) {
701
+ if (item instanceof pqb.Column) {
702
702
  let column = item;
703
703
  const foreignKeys = column.data.foreignKeys;
704
704
  if (foreignKeys?.some((it) => "fn" in it)) {
@@ -720,9 +720,9 @@ const setName = (self, item) => {
720
720
  var _a, _b;
721
721
  const name = self[nameKey];
722
722
  if (!name) return;
723
- if ("column" in item && item.column instanceof pqb.ColumnType) {
723
+ if ("column" in item && item.column instanceof pqb.Column) {
724
724
  (_a = item.column.data).name ?? (_a.name = name);
725
- } else if (item instanceof pqb.ColumnType) {
725
+ } else if (item instanceof pqb.Column) {
726
726
  (_b = item.data).name ?? (_b.name = name);
727
727
  } else {
728
728
  item.name ?? (item.name = name);
@@ -823,7 +823,7 @@ const makeAst$1 = (up, name, changeData, changeTableData2, options) => {
823
823
  if (typeof item === "number") {
824
824
  consumedChanges[item] = true;
825
825
  item = addOrDropChanges[item];
826
- } else if (item instanceof pqb.ColumnType) {
826
+ } else if (item instanceof pqb.Column) {
827
827
  item = addOrDrop("add", item);
828
828
  }
829
829
  if ("type" in item) {
@@ -3285,7 +3285,7 @@ const ensureMigrationsPath = (config) => {
3285
3285
  };
3286
3286
  const ensureBasePathAndDbScript = (config, intermediateCallers = 0) => {
3287
3287
  if (config.basePath && config.dbScript) return config;
3288
- let filePath = pqb.getStackTrace()?.[3 + intermediateCallers].getFileName();
3288
+ let filePath = pqb.getStackTrace()?.[3 + intermediateCallers]?.getFileName();
3289
3289
  if (!filePath) {
3290
3290
  throw new Error(
3291
3291
  "Failed to determine path to db script. Please set basePath option of rakeDb"