orchid-orm 1.72.8 → 1.72.10

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
@@ -20,7 +20,7 @@ interface RelationHasOneThroughOptions<Through extends string, Source extends st
20
20
  required?: boolean;
21
21
  }
22
22
  type HasOneOptions<Columns extends Column.Shape.QueryInit = Column.Shape.QueryInit, Related extends ORMTableInput = ORMTableInput, Through extends string = string, Source extends string = string> = RelationRefsOptions<keyof Columns, Related['columns']['shape']> | RelationHasOneThroughOptions<Through, Source>;
23
- type HasOneParams<T extends RelationConfigSelf, Options> = Options extends RelationRefsOptions ? { [Name in Options['columns'][number]]: T['columns']['shape'][Name]['type'] } : Options extends RelationThroughOptions ? RelationConfigParams<T, T['relations'][Options['through']]> : never;
23
+ type HasOneParams<T extends RelationConfigSelf, Options> = Options extends RelationRefsOptions ? { [Name in Options['columns'][number]]: T['columns']['shape'][Name]['__type'] } : Options extends RelationThroughOptions ? RelationConfigParams<T, T['relations'][Options['through']]> : never;
24
24
  type HasOneQueryThrough<Name extends string, TableQuery extends Query> = { [K in keyof TableQuery]: K extends '__selectable' ? SelectableFromShape<TableQuery['shape'], Name> : K extends '__as' ? Name : K extends CreateMethodsNames ? never : TableQuery[K] } & QueryHasWhere & HasRelJoin;
25
25
  type HasOneQuery<T extends RelationConfigSelf, Name extends string, TableQuery extends Query> = T['relations'][Name]['options'] extends RelationRefsOptions ? { [K in keyof TableQuery]: K extends '__defaults' ? { [K in keyof TableQuery['__defaults'] | T['relations'][Name]['options']['references'][number]]: true } : K extends '__selectable' ? SelectableFromShape<TableQuery['shape'], Name> : K extends '__as' ? Name : K extends CreateManyMethodsNames ? never : TableQuery[K] } & QueryHasWhere & HasRelJoin : HasOneQueryThrough<Name, TableQuery>;
26
26
  interface HasOneInfo<T extends RelationConfigSelf, Name extends string, Rel extends HasOne, Q extends Query> extends RelationConfigBase {
@@ -117,7 +117,7 @@ interface BelongsToOptions<Columns extends Column.Shape.QueryInit = Column.Shape
117
117
  foreignKey?: boolean | TableData.References.Options;
118
118
  on?: ColumnsShape.InputPartial<Related['columns']['shape']>;
119
119
  }
120
- type BelongsToParams<T extends RelationConfigSelf, FK extends string> = { [Name in FK]: T['columns']['shape'][Name]['type'] };
120
+ type BelongsToParams<T extends RelationConfigSelf, FK extends string> = { [Name in FK]: T['columns']['shape'][Name]['__type'] };
121
121
  type BelongsToQuery<T extends Query, Name extends string> = { [P in keyof T]: P extends '__selectable' ? SelectableFromShape<T['shape'], Name> : P extends '__as' ? Name : P extends CreateMethodsNames | DeleteMethodsNames ? never : T[P] } & QueryHasWhere & HasRelJoin;
122
122
  interface BelongsToInfo<T extends RelationConfigSelf, Name extends string, FK extends string, Required, Q extends Query> extends RelationConfigBase {
123
123
  returnsOne: true;
@@ -175,7 +175,7 @@ interface HasAndBelongsToManyOptions<Columns extends Column.Shape.QueryInit = Co
175
175
  };
176
176
  on?: ColumnsShape.InputPartial<Related['columns']['shape']>;
177
177
  }
178
- type HasAndBelongsToManyParams<T extends RelationConfigSelf, FK extends string> = { [Name in FK]: T['columns']['shape'][Name]['type'] };
178
+ type HasAndBelongsToManyParams<T extends RelationConfigSelf, FK extends string> = { [Name in FK]: T['columns']['shape'][Name]['__type'] };
179
179
  type HasAndBelongsToManyQuery<Name extends string, TableQuery extends Query> = { [K in keyof TableQuery]: K extends '__selectable' ? SelectableFromShape<TableQuery['shape'], Name> : K extends '__as' ? Name : TableQuery[K] } & QueryHasWhere & HasRelJoin;
180
180
  interface HasAndBelongsToManyInfo<T extends RelationConfigSelf, Name extends string, FK extends string, Q extends Query> extends RelationConfigBase {
181
181
  returnsOne: false;
@@ -562,9 +562,15 @@ interface ORMTableInput extends PickORMTableInputColumnsAndComputed {
562
562
  grants?: readonly Grant.TableClassGrant[];
563
563
  readonly readOnly?: boolean;
564
564
  readonly materialized?: true;
565
+ /**
566
+ * Keep this table-like definition available at runtime, but exclude it from
567
+ * generated migration DDL reconciliation.
568
+ */
569
+ generatorIgnore?: true;
565
570
  table?: string;
566
571
  noPrimaryKey?: boolean;
567
572
  name?: string;
573
+ query?: Query;
568
574
  sql?: string | RawSqlBase;
569
575
  recursive?: boolean;
570
576
  checkOption?: 'LOCAL' | 'CASCADED';
@@ -572,17 +578,17 @@ interface ORMTableInput extends PickORMTableInputColumnsAndComputed {
572
578
  securityInvoker?: boolean;
573
579
  withData?: boolean;
574
580
  }
575
- type Queryable<T extends PickORMTableInputColumns> = ShallowSimplify<{ [K in keyof T['columns']['shape']]?: T['columns']['shape'][K]['queryType'] }>;
581
+ type Queryable<T extends PickORMTableInputColumns> = ShallowSimplify<{ [K in keyof T['columns']['shape']]?: T['columns']['shape'][K]['__queryType'] }>;
576
582
  type DefaultSelect<T extends PickORMTableInputColumns> = ShallowSimplify<ColumnsShape.DefaultOutput<T['columns']['shape']>>;
577
583
  type Selectable<T extends PickORMTableInputColumnsAndComputed> = T['computed'] extends ((t: never) => infer R extends ComputedOptionsConfig) ? ShallowSimplify<ColumnsShape.Output<T['columns']['shape']> & { [K in keyof R]: R[K] extends {
578
584
  result: {
579
585
  value: infer Value extends Column.Pick.QueryColumn;
580
586
  };
581
- } ? Value['outputType'] : R[K] extends (() => {
587
+ } ? Value['__outputType'] : R[K] extends (() => {
582
588
  result: {
583
589
  value: infer Value extends Column.Pick.QueryColumn;
584
590
  };
585
- }) ? Value['outputType'] : never }> : ShallowSimplify<ColumnsShape.Output<T['columns']['shape']>>;
591
+ }) ? Value['__outputType'] : never }> : ShallowSimplify<ColumnsShape.Output<T['columns']['shape']>>;
586
592
  type Insertable<T extends PickORMTableInputColumns> = ShallowSimplify<ColumnsShape.Input<T['columns']['shape']>>;
587
593
  type Updatable<T extends PickORMTableInputColumns> = ShallowSimplify<ColumnsShape.InputPartial<T['columns']['shape']>>;
588
594
  type BeforeHookMethod = (cb: QueryBeforeHook) => void;
@@ -610,6 +616,11 @@ interface BaseTableInstance<ColumnTypes> {
610
616
  q: QueryData;
611
617
  language?: string;
612
618
  filePath: string;
619
+ /**
620
+ * Keep this table-like definition available at runtime, but exclude it from
621
+ * generated migration DDL reconciliation.
622
+ */
623
+ generatorIgnore?: true;
613
624
  result: Column.Shape.QueryInit;
614
625
  clone<T extends IsQuery>(this: T): T;
615
626
  getFilePath(): string;
@@ -819,6 +830,7 @@ interface BaseTableClass<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> {
819
830
  }
820
831
  interface BaseViewInstance<ColumnTypes> extends BaseTableInstance<ColumnTypes> {
821
832
  name: string;
833
+ query?: Query;
822
834
  sql: string | RawSqlBase;
823
835
  readonly readOnly?: boolean;
824
836
  recursive?: boolean;
@@ -828,6 +840,7 @@ interface BaseViewInstance<ColumnTypes> extends BaseTableInstance<ColumnTypes> {
828
840
  }
829
841
  interface BaseMaterializedViewInstance<ColumnTypes> extends BaseTableInstance<ColumnTypes> {
830
842
  name: string;
843
+ query?: Query;
831
844
  sql: string | RawSqlBase;
832
845
  readonly readOnly?: true;
833
846
  readonly materialized: true;
package/dist/index.js CHANGED
@@ -1482,18 +1482,12 @@ const assignTablesToOrm = (isTable, tables, result, adapter, qb, asyncStorage, c
1482
1482
  comment: table.comment,
1483
1483
  readOnly: isTable ? table.readOnly ? true : void 0 : table.materialized || table.readOnly !== false ? true : void 0,
1484
1484
  materialized: !isTable && table.materialized ? true : void 0,
1485
+ generatorIgnore: table.generatorIgnore,
1485
1486
  noPrimaryKey: table.noPrimaryKey || !isTable ? "ignore" : void 0,
1486
1487
  computed: table.computed,
1487
1488
  nowSQL: tableClass.nowSQL
1488
1489
  };
1489
- const dbTable = new pqb.Db(adapter, qb, isTable ? table.table : table.name, table.columns.shape, table.types, asyncStorage, options, table.columns?.data ?? {}, isTable ? void 0 : {
1490
- sql: table.sql,
1491
- recursive: table.recursive,
1492
- checkOption: table.checkOption,
1493
- securityBarrier: table.securityBarrier,
1494
- securityInvoker: table.securityInvoker,
1495
- withData: table.withData
1496
- });
1490
+ const dbTable = new pqb.Db(adapter, qb, isTable ? table.table : table.name, table.columns.shape, table.types, asyncStorage, options, table.columns?.data ?? {}, getViewData(isTable, table));
1497
1491
  dbTable.definedAs = key;
1498
1492
  dbTable.db = result;
1499
1493
  dbTable.filePath = table.filePath;
@@ -1504,6 +1498,18 @@ const assignTablesToOrm = (isTable, tables, result, adapter, qb, asyncStorage, c
1504
1498
  }
1505
1499
  return tableInstances;
1506
1500
  };
1501
+ const getViewData = (isTable, table) => {
1502
+ if (isTable) return;
1503
+ return {
1504
+ query: table.query,
1505
+ sql: table.sql,
1506
+ recursive: table.recursive,
1507
+ checkOption: table.checkOption,
1508
+ securityBarrier: table.securityBarrier,
1509
+ securityInvoker: table.securityInvoker,
1510
+ withData: table.withData
1511
+ };
1512
+ };
1507
1513
  const bundleOrchidORM = ({ tables = {}, views = {} }) => {
1508
1514
  const result = {};
1509
1515
  const bundledViews = {};
@@ -1619,14 +1625,23 @@ const privateOrchidORMWithAdapter = ({ log, logger, autoPreparedStatements, noPr
1619
1625
  ...result.$views
1620
1626
  }, schema);
1621
1627
  setDbAwareInstance?.(result);
1622
- const initItems = [[tableInstances, result], [viewInstances, result.$views]];
1623
- for (const [items, queries] of initItems) {
1628
+ const initItems = [[
1629
+ tableInstances,
1630
+ result,
1631
+ true
1632
+ ], [
1633
+ viewInstances,
1634
+ result.$views,
1635
+ false
1636
+ ]];
1637
+ for (const [items, queries, isTable] of initItems) {
1624
1638
  if (!items) continue;
1625
1639
  for (const key in items) {
1626
1640
  const table = items[key];
1627
1641
  if (table.init) {
1628
1642
  table.init(result);
1629
1643
  Object.assign(queries[key].baseQuery.q, table.q);
1644
+ if (!isTable) queries[key].internal.viewData = getViewData(false, table);
1630
1645
  }
1631
1646
  }
1632
1647
  }