orchid-orm 1.9.10 → 1.9.12

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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { columnTypes, getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSqlCacheKey, NotFoundError, relationQueryKey, Adapter, Db, anyShape, getClonedQueryData, columnsShapeToCode, ColumnType, primaryKeyToCode, indexToCode, constraintToCode, columnIndexesToCode, columnForeignKeysToCode, columnCheckToCode, identityToCode } from 'pqb';
2
2
  export { OrchidOrmError, OrchidOrmInternalError, columnTypes } from 'pqb';
3
- import { getCallerFilePath, snakeCaseKey, toSnakeCase, emptyObject, pathToLog, toCamelCase, toPascalCase, getImportPath, singleQuote, codeToString, quoteObjectKey, addCode, columnDefaultArgumentToCode, deepCompare } from 'orchid-core';
3
+ import { getCallerFilePath, snakeCaseKey, toSnakeCase, pathToLog, toCamelCase, toPascalCase, getImportPath, singleQuote, codeToString, quoteObjectKey, addCode, columnDefaultArgumentToCode, deepCompare } from 'orchid-core';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
5
5
  import * as path from 'path';
6
6
  import path__default from 'path';
@@ -99,8 +99,8 @@ const create = (columnTypes, filePath, snakeCase) => {
99
99
  };
100
100
 
101
101
  class BelongsToVirtualColumn extends VirtualColumn {
102
- constructor(types, key, state) {
103
- super(types);
102
+ constructor(key, state) {
103
+ super();
104
104
  this.key = key;
105
105
  this.state = state;
106
106
  this.nestedInsert = nestedInsert$3(this.state);
@@ -153,7 +153,7 @@ const makeBelongsToMethod = (relation, relationName, query) => {
153
153
  method: (params) => {
154
154
  return query.findBy({ [primaryKey]: params[foreignKey] });
155
155
  },
156
- virtualColumn: new BelongsToVirtualColumn(emptyObject, relationName, state),
156
+ virtualColumn: new BelongsToVirtualColumn(relationName, state),
157
157
  joinQuery(fromQuery, toQuery) {
158
158
  return addQueryOn(toQuery, fromQuery, toQuery, primaryKey, foreignKey);
159
159
  },
@@ -354,8 +354,8 @@ var __spreadValues$7 = (a, b) => {
354
354
  };
355
355
  var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
356
356
  class HasOneVirtualColumn extends VirtualColumn {
357
- constructor(types, key, state) {
358
- super(types);
357
+ constructor(key, state) {
358
+ super();
359
359
  this.key = key;
360
360
  this.state = state;
361
361
  this.nestedInsert = nestedInsert$2(state);
@@ -440,7 +440,7 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
440
440
  const values = { [foreignKey]: params[primaryKey] };
441
441
  return query.where(values)._defaults(values);
442
442
  },
443
- virtualColumn: new HasOneVirtualColumn(emptyObject, relationName, state),
443
+ virtualColumn: new HasOneVirtualColumn(relationName, state),
444
444
  joinQuery(fromQuery, toQuery) {
445
445
  return addQueryOn(toQuery, fromQuery, toQuery, foreignKey, primaryKey);
446
446
  },
@@ -551,8 +551,8 @@ var __spreadValues$6 = (a, b) => {
551
551
  };
552
552
  var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
553
553
  class HasManyVirtualColumn extends VirtualColumn {
554
- constructor(types, key, state) {
555
- super(types);
554
+ constructor(key, state) {
555
+ super();
556
556
  this.key = key;
557
557
  this.state = state;
558
558
  this.nestedInsert = nestedInsert$1(state);
@@ -636,7 +636,7 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
636
636
  const values = { [foreignKey]: params[primaryKey] };
637
637
  return query.where(values)._defaults(values);
638
638
  },
639
- virtualColumn: new HasManyVirtualColumn(emptyObject, relationName, state),
639
+ virtualColumn: new HasManyVirtualColumn(relationName, state),
640
640
  joinQuery(fromQuery, toQuery) {
641
641
  return addQueryOn(toQuery, fromQuery, toQuery, foreignKey, primaryKey);
642
642
  },
@@ -800,8 +800,8 @@ var __spreadValues$5 = (a, b) => {
800
800
  };
801
801
  var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
802
802
  class HasAndBelongsToManyVirtualColumn extends VirtualColumn {
803
- constructor(types, key, state) {
804
- super(types);
803
+ constructor(key, state) {
804
+ super();
805
805
  this.key = key;
806
806
  this.state = state;
807
807
  this.nestedInsert = nestedInsert(state);
@@ -879,11 +879,7 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
879
879
  })
880
880
  );
881
881
  },
882
- virtualColumn: new HasAndBelongsToManyVirtualColumn(
883
- emptyObject,
884
- relationName,
885
- state
886
- ),
882
+ virtualColumn: new HasAndBelongsToManyVirtualColumn(relationName, state),
887
883
  // joinQuery can be a property of RelationQuery and be used by whereExists and other stuff which needs it
888
884
  // and the chained query itself may be a query around this joinQuery
889
885
  joinQuery(fromQuery, toQuery) {
@@ -1210,7 +1206,9 @@ const delayRelation = (delayedRelations, table, relationName, data) => {
1210
1206
  };
1211
1207
  const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, delayedRelations) => {
1212
1208
  var _a;
1213
- const query = (relation.options.scope ? relation.options.scope(otherDbTable) : otherDbTable).as(relationName);
1209
+ const baseQuery = Object.create(otherDbTable);
1210
+ baseQuery.baseQuery = baseQuery;
1211
+ const query = (relation.options.scope ? relation.options.scope(baseQuery) : baseQuery).as(relationName);
1214
1212
  const definedAs = query.definedAs;
1215
1213
  if (!definedAs) {
1216
1214
  throw new Error(
@@ -1243,6 +1241,7 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
1243
1241
  dbTable.shape[relationName] = dbTable.query.shape[relationName] = data.virtualColumn;
1244
1242
  }
1245
1243
  makeRelationQuery(dbTable, definedAs, relationName, data);
1244
+ baseQuery.joinQuery = data.joinQuery;
1246
1245
  dbTable.relations[relationName] = {
1247
1246
  type,
1248
1247
  key: relationName,
@@ -1252,6 +1251,7 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
1252
1251
  primaryKey: data.primaryKey,
1253
1252
  options: relation.options
1254
1253
  };
1254
+ dbTable.relationsQueries[relationName] = query;
1255
1255
  const tableRelations = delayedRelations.get(dbTable);
1256
1256
  if (!tableRelations)
1257
1257
  return;