orchid-orm 1.58.1 → 1.58.3

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,7 +1,5 @@
1
- import { TableData, Query, SelectableFromShape, CreateManyMethodsNames, CreateData, CreateBelongsToData, AddQueryDefaults, QueryTake, QueryTakeOptional, UpdateData, WhereArg, CreateMethodsNames, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, FromArg, FromResult, DbSharedOptions, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, ComputedOptionsConfig, QueryData, TableDataFn, DbTableOptionScopes, RawSQL, DynamicRawSQL, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHookInternal, QueryAfterHook, AfterHook, WhereResult, MergeQuery } from 'pqb';
1
+ import { ColumnsShapeBase, TableData, ColumnShapeInputPartial, Query, SelectableFromShape, CreateManyMethodsNames, CreateData, AddQueryDefaults, RelationConfigBase, QueryTake, QueryTakeOptional, EmptyObject, UpdateData, WhereArg, CreateMethodsNames, MaybeArray, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, AfterCommitStandaloneHook, AdapterBase, FromArg, FromResult, DbSharedOptions, RelationsBase, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, RecordUnknown, ShallowSimplify, ColumnShapeOutput, DefaultSelectColumns, ComputedOptionsConfig, QueryOrExpression, QueryColumn, ColumnShapeInput, QueryData, IsQuery, TableDataFn, DbTableOptionScopes, CoreQueryScopes, ColumnSchemaConfig, StaticSQLArgs, RawSQL, DynamicSQLArg, DynamicRawSQL, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHookInternal, QueryAfterHook, QueryColumns, AfterHook, WhereResult, MergeQuery, QueryReturnType } from 'pqb';
2
2
  export * from 'pqb';
3
- import { ColumnsShapeBase, ColumnShapeInputPartial, RelationConfigBase, EmptyObject, MaybeArray, AfterCommitStandaloneHook, AdapterBase, RelationsBase, RecordUnknown, ShallowSimplify, ColumnShapeOutput, DefaultSelectColumns, QueryOrExpression, QueryColumn, ColumnShapeInput, IsQuery, CoreQueryScopes, ColumnSchemaConfig, StaticSQLArgs, DynamicSQLArg, QueryColumns, QueryReturnType } from 'orchid-core';
4
- export * from 'orchid-core';
5
3
 
6
4
  interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends ColumnsShapeBase = ColumnsShapeBase> {
7
5
  required?: boolean;
@@ -43,7 +41,7 @@ type HasOneQuery<T extends RelationConfigSelf, Name extends string, TableQuery e
43
41
  selectable: SelectableFromShape<TableQuery['shape'], Name>;
44
42
  } : K extends 'join' ? RelJoin : K extends CreateManyMethodsNames ? never : TableQuery[K];
45
43
  };
46
- interface HasOneInfo<T extends RelationConfigSelf, Name extends string, Rel extends HasOne, Q extends Query, CD = T['relations'][Name]['options'] extends RelationThroughOptions ? CreateData<Q, CreateBelongsToData<Q>> : CreateData<AddQueryDefaults<Q, HasOnePopulate<T, Name>>, CreateBelongsToData<Q>>> extends RelationConfigBase {
44
+ interface HasOneInfo<T extends RelationConfigSelf, Name extends string, Rel extends HasOne, Q extends Query, CD = T['relations'][Name]['options'] extends RelationThroughOptions ? CreateData<Q> : CreateData<AddQueryDefaults<Q, HasOnePopulate<T, Name>>>> extends RelationConfigBase {
47
45
  returnsOne: true;
48
46
  query: Q;
49
47
  params: HasOneParams<T, Rel>;
@@ -182,7 +180,7 @@ interface BelongsToInfo<T extends RelationConfigSelf, Name extends string, Rel e
182
180
  } | {
183
181
  update: UpdateData<Q>;
184
182
  } | {
185
- create: CreateData<Q, CreateBelongsToData<Q>>;
183
+ create: CreateData<Q>;
186
184
  };
187
185
  dataForUpdateOne: {
188
186
  disconnect: boolean;
@@ -193,11 +191,11 @@ interface BelongsToInfo<T extends RelationConfigSelf, Name extends string, Rel e
193
191
  } | {
194
192
  update: UpdateData<Q>;
195
193
  } | {
196
- create: CreateData<Q, CreateBelongsToData<Q>>;
194
+ create: CreateData<Q>;
197
195
  } | {
198
196
  upsert: {
199
197
  update: UpdateData<Q>;
200
- create: CreateData<Q, CreateBelongsToData<Q>> | (() => CreateData<Q, CreateBelongsToData<Q>>);
198
+ create: CreateData<Q> | (() => CreateData<Q>);
201
199
  };
202
200
  };
203
201
  }
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var pqb = require('pqb');
4
- var orchidCore = require('orchid-core');
5
4
  var node_async_hooks = require('node:async_hooks');
6
5
 
7
6
  function createBaseTable({
@@ -16,11 +15,11 @@ function createBaseTable({
16
15
  } = {}) {
17
16
  var _a;
18
17
  const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(pqb.makeColumnTypes(schemaConfig)) : columnTypesArg || pqb.makeColumnTypes(schemaConfig);
19
- const filePathOrStack = filePathArg || orchidCore.getStackTrace();
18
+ const filePathOrStack = filePathArg || pqb.getStackTrace();
20
19
  let filePath;
21
20
  const defaultColumns = {
22
- shape: orchidCore.emptyObject,
23
- data: orchidCore.emptyArray
21
+ shape: pqb.emptyObject,
22
+ data: pqb.emptyArray
24
23
  };
25
24
  const base = (_a = class {
26
25
  constructor() {
@@ -64,7 +63,7 @@ function createBaseTable({
64
63
  if (typeof filePathOrStack === "string") {
65
64
  return filePath = filePathOrStack;
66
65
  }
67
- filePath = orchidCore.getCallerFilePath(filePathOrStack);
66
+ filePath = pqb.getCallerFilePath(filePathOrStack);
68
67
  if (filePath) return filePath;
69
68
  throw new Error(
70
69
  `Failed to determine file path of a base table. Please set the \`filePath\` option of \`createBaseTable\` manually.`
@@ -80,21 +79,21 @@ function createBaseTable({
80
79
  if (this.filePath) return this.filePath;
81
80
  if (typeof filePathOrStack === "string")
82
81
  return this.filePath = filePathOrStack;
83
- const filePath2 = orchidCore.getCallerFilePath(filePathOrStack);
82
+ const filePath2 = pqb.getCallerFilePath(filePathOrStack);
84
83
  if (filePath2) return this.filePath = filePath2;
85
84
  throw new Error(
86
85
  `Failed to determine file path for table ${this.constructor.name}. Please set \`filePath\` property manually`
87
86
  );
88
87
  }
89
88
  setColumns(fn, dataFn) {
90
- columnTypes[orchidCore.snakeCaseKey] = this.snakeCase;
89
+ columnTypes[pqb.snakeCaseKey] = this.snakeCase;
91
90
  const shape = pqb.getColumnTypes(columnTypes, fn, nowSQL, this.language);
92
91
  const tableData = pqb.parseTableData(dataFn);
93
92
  if (this.snakeCase) {
94
93
  for (const key in shape) {
95
94
  const column = shape[key];
96
95
  if (column.data.name) continue;
97
- const snakeName = orchidCore.toSnakeCase(key);
96
+ const snakeName = pqb.toSnakeCase(key);
98
97
  if (snakeName !== key) {
99
98
  column.data.name = snakeName;
100
99
  }
@@ -140,7 +139,7 @@ function createBaseTable({
140
139
  };
141
140
  }
142
141
  }, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a.columnTypes = columnTypes, _a);
143
- orchidCore.applyMixins(base, [pqb.QueryHooks]);
142
+ pqb.applyMixins(base, [pqb.QueryHooks]);
144
143
  base.prototype.types = columnTypes;
145
144
  base.prototype.snakeCase = snakeCase;
146
145
  base.prototype.autoForeignKeys = autoForeignKeys === true ? {} : autoForeignKeys || void 0;
@@ -239,7 +238,7 @@ const addAutoForeignKey = (tableConfig, from, to, primaryKeys, foreignKeys, opti
239
238
  let fkeyOptions = options.foreignKey !== void 0 ? options.foreignKey : tableConfig.autoForeignKeys;
240
239
  if (!fkeyOptions) return;
241
240
  if (fkeyOptions === true) {
242
- fkeyOptions = tableConfig.autoForeignKeys || orchidCore.emptyObject;
241
+ fkeyOptions = tableConfig.autoForeignKeys || pqb.emptyObject;
243
242
  }
244
243
  if (foreignKeys.length === 1) {
245
244
  const column = from.shape[foreignKeys[0]];
@@ -306,7 +305,7 @@ const joinQueryChainHOF = (relPKeys, reverseJoin, joinQuery) => (joiningQuery, b
306
305
  useWhereExist = jq.q.order.every((o) => {
307
306
  if (typeof o === "string") {
308
307
  return isOwnColumn(prefix, o);
309
- } else if (orchidCore.isExpression(o)) {
308
+ } else if (pqb.isExpression(o)) {
310
309
  return false;
311
310
  } else {
312
311
  for (const key in o) {
@@ -323,7 +322,7 @@ const joinQueryChainHOF = (relPKeys, reverseJoin, joinQuery) => (joiningQuery, b
323
322
  useWhereExist = jq.q.select.every((s) => {
324
323
  if (typeof s === "string") {
325
324
  return isOwnColumn(prefix, s);
326
- } else if (orchidCore.isExpression(s)) {
325
+ } else if (pqb.isExpression(s)) {
327
326
  return false;
328
327
  } else if (!s) {
329
328
  return false;
@@ -378,7 +377,7 @@ const combineOrdering = (result, joined) => {
378
377
  if (order) {
379
378
  const as = pqb.getQueryAs(joined);
380
379
  const add = order.map(
381
- (o) => typeof o === "string" ? `${as}.${o}` : orchidCore.isExpression(o) ? o : Object.fromEntries(
380
+ (o) => typeof o === "string" ? `${as}.${o}` : pqb.isExpression(o) ? o : Object.fromEntries(
382
381
  Object.entries(o).map(([key, value]) => [`${as}.${key}`, value])
383
382
  )
384
383
  );
@@ -428,7 +427,7 @@ class BelongsToVirtualColumn extends pqb.VirtualColumn {
428
427
  const relationData = [values];
429
428
  store.belongsTo[key] = relationData;
430
429
  q.q.wrapInTransaction = true;
431
- orchidCore.pushQueryValueImmutable(q, "beforeCreate", async (q2) => {
430
+ pqb.pushQueryValueImmutable(q, "beforeCreate", async (q2) => {
432
431
  const inserted = await this.nestedInsert(
433
432
  q2,
434
433
  relationData.map(([, , data]) => data)
@@ -505,7 +504,7 @@ const makeBelongsToMethod = (tableConfig, table, relation, relationName, query)
505
504
  state
506
505
  ),
507
506
  joinQuery: joinQueryChainHOF(
508
- orchidCore.getPrimaryKeys(query),
507
+ pqb.getPrimaryKeys(query),
509
508
  reverseJoin,
510
509
  (joiningQuery, baseQuery) => join(
511
510
  baseQuery,
@@ -543,7 +542,7 @@ const nestedInsert$3 = ({ query, primaryKeys, on }) => {
543
542
  }
544
543
  connectOrCreated = await Promise.all(items);
545
544
  } else {
546
- connectOrCreated = orchidCore.emptyArray;
545
+ connectOrCreated = pqb.emptyArray;
547
546
  }
548
547
  let connectOrCreatedI = 0;
549
548
  items.length = 0;
@@ -564,7 +563,7 @@ const nestedInsert$3 = ({ query, primaryKeys, on }) => {
564
563
  items
565
564
  );
566
565
  } else {
567
- created = orchidCore.emptyArray;
566
+ created = pqb.emptyArray;
568
567
  }
569
568
  items.length = 0;
570
569
  for (const item of data) {
@@ -581,7 +580,7 @@ const nestedInsert$3 = ({ query, primaryKeys, on }) => {
581
580
  }
582
581
  connected = await Promise.all(items);
583
582
  } else {
584
- connected = orchidCore.emptyArray;
583
+ connected = pqb.emptyArray;
585
584
  }
586
585
  let createdI = 0;
587
586
  let connectedI = 0;
@@ -636,7 +635,7 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
636
635
  } else if (params.delete) {
637
636
  const selectQuery = q2.clone();
638
637
  selectQuery.q.type = void 0;
639
- selectQuery.q.distinct = orchidCore.emptyArray;
638
+ selectQuery.q.distinct = pqb.emptyArray;
640
639
  selectIfNotSelected(selectQuery, foreignKeys);
641
640
  idsForDelete = await pqb._queryRows(selectQuery);
642
641
  for (const foreignKey of foreignKeys) {
@@ -682,7 +681,7 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
682
681
  } else if (params.delete || params.update) {
683
682
  pqb._queryHookAfterUpdate(
684
683
  q,
685
- params.update ? foreignKeys : orchidCore.emptyArray,
684
+ params.update ? foreignKeys : pqb.emptyArray,
686
685
  async (data) => {
687
686
  let ids;
688
687
  if (params.delete) {
@@ -754,7 +753,7 @@ class HasOneVirtualColumn extends pqb.VirtualColumn {
754
753
  }
755
754
  }
756
755
  const makeHasOneMethod = (tableConfig, table, relation, relationName, query) => {
757
- const relPKeys = orchidCore.getPrimaryKeys(query);
756
+ const relPKeys = pqb.getPrimaryKeys(query);
758
757
  if ("through" in relation.options) {
759
758
  const { through, source } = relation.options;
760
759
  const throughRelation = getThroughRelation(table, through);
@@ -1029,7 +1028,7 @@ class HasManyVirtualColumn extends pqb.VirtualColumn {
1029
1028
  }
1030
1029
  }
1031
1030
  const makeHasManyMethod = (tableConfig, table, relation, relationName, query) => {
1032
- const relPKeys = orchidCore.getPrimaryKeys(query);
1031
+ const relPKeys = pqb.getPrimaryKeys(query);
1033
1032
  if ("through" in relation.options) {
1034
1033
  const { through, source } = relation.options;
1035
1034
  const throughRelation = getThroughRelation(table, through);
@@ -1148,7 +1147,7 @@ const getWhereForNestedUpdate = (t, data, params, primaryKeys, foreignKeys) => {
1148
1147
  columns: foreignKeys,
1149
1148
  values: data.map((item) => primaryKeys.map((key) => item[key]))
1150
1149
  },
1151
- OR: params ? orchidCore.toArray(params) : void 0
1150
+ OR: params ? pqb.toArray(params) : void 0
1152
1151
  });
1153
1152
  };
1154
1153
  const nestedInsert$1 = ({ query, primaryKeys, foreignKeys }) => {
@@ -1268,7 +1267,7 @@ const nestedUpdate$1 = ({ query, primaryKeys, foreignKeys }) => {
1268
1267
  }
1269
1268
  if (params.add) {
1270
1269
  if (data.length > 1) {
1271
- throw new orchidCore.OrchidOrmInternalError(
1270
+ throw new pqb.OrchidOrmInternalError(
1272
1271
  query,
1273
1272
  "`connect` is not available when updating multiple records, it is only applicable for a single record update"
1274
1273
  );
@@ -1277,13 +1276,13 @@ const nestedUpdate$1 = ({ query, primaryKeys, foreignKeys }) => {
1277
1276
  for (let i = 0; i < len; i++) {
1278
1277
  obj[foreignKeys[i]] = data[0][primaryKeys[i]];
1279
1278
  }
1280
- const relatedWheres = orchidCore.toArray(params.add);
1279
+ const relatedWheres = pqb.toArray(params.add);
1281
1280
  const count = await pqb._queryUpdate(
1282
1281
  t.where({ OR: relatedWheres }),
1283
1282
  obj
1284
1283
  );
1285
1284
  if (count < relatedWheres.length) {
1286
- throw new orchidCore.OrchidOrmInternalError(
1285
+ throw new pqb.OrchidOrmInternalError(
1287
1286
  query,
1288
1287
  `Expected to find at least ${relatedWheres.length} record(s) based on \`add\` conditions, but found ${count}`
1289
1288
  );
@@ -1294,7 +1293,7 @@ const nestedUpdate$1 = ({ query, primaryKeys, foreignKeys }) => {
1294
1293
  for (const foreignKey of foreignKeys) {
1295
1294
  obj[foreignKey] = null;
1296
1295
  }
1297
- const setConditions = params.set && (Array.isArray(params.set) ? params.set.length : orchidCore.objectHasValues(params.set)) && (Array.isArray(params.set) ? {
1296
+ const setConditions = params.set && (Array.isArray(params.set) ? params.set.length : pqb.objectHasValues(params.set)) && (Array.isArray(params.set) ? {
1298
1297
  OR: params.set
1299
1298
  } : params.set);
1300
1299
  let queryToDisconnect = getWhereForNestedUpdate(
@@ -1388,11 +1387,11 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
1388
1387
  pqb._queryDefaults(query, on);
1389
1388
  }
1390
1389
  const foreignKeysFull = foreignKeys.map((key, i) => {
1391
- if (snakeCase) key = foreignKeys[i] = orchidCore.toSnakeCase(key);
1390
+ if (snakeCase) key = foreignKeys[i] = pqb.toSnakeCase(key);
1392
1391
  return `${joinTable}.${key}`;
1393
1392
  });
1394
1393
  const throughForeignKeysFull = throughForeignKeys.map((key, i) => {
1395
- if (snakeCase) key = throughForeignKeys[i] = orchidCore.toSnakeCase(key);
1394
+ if (snakeCase) key = throughForeignKeys[i] = pqb.toSnakeCase(key);
1396
1395
  return `${joinTable}.${key}`;
1397
1396
  });
1398
1397
  const foreignTable = pqb.getQueryAs(query);
@@ -1514,7 +1513,7 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
1514
1513
  state
1515
1514
  ),
1516
1515
  joinQuery: joinQueryChainHOF(
1517
- orchidCore.getPrimaryKeys(query),
1516
+ pqb.getPrimaryKeys(query),
1518
1517
  reverseJoin,
1519
1518
  (joiningQuery, baseQuery2) => joinQuery(
1520
1519
  joiningQuery,
@@ -1548,7 +1547,7 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
1548
1547
  data
1549
1548
  );
1550
1549
  if (createdCount === 0) {
1551
- throw new orchidCore.NotFoundError(baseQuery2);
1550
+ throw new pqb.NotFoundError(baseQuery2);
1552
1551
  }
1553
1552
  }
1554
1553
  );
@@ -1812,7 +1811,7 @@ const nestedUpdate = (state) => {
1812
1811
  }
1813
1812
  if (params.add) {
1814
1813
  const as = query.table;
1815
- const relatedWheres = orchidCore.toArray(params.add);
1814
+ const relatedWheres = pqb.toArray(params.add);
1816
1815
  const joinTableColumns = [
1817
1816
  ...state.foreignKeys,
1818
1817
  ...state.throughForeignKeys
@@ -1841,18 +1840,18 @@ const nestedUpdate = (state) => {
1841
1840
  state.primaryKeysShape[key]
1842
1841
  ])
1843
1842
  ),
1844
- data.map((x) => orchidCore.pick(x, state.primaryKeys))
1843
+ data.map((x) => pqb.pick(x, state.primaryKeys))
1845
1844
  )
1846
1845
  ).onConflict(joinTableColumns).merge([state.foreignKeys[0]]);
1847
1846
  if (count < data.length * relatedWheres.length) {
1848
- throw new orchidCore.OrchidOrmInternalError(
1847
+ throw new pqb.OrchidOrmInternalError(
1849
1848
  query,
1850
1849
  `Expected to find at least ${relatedWheres.length} record(s) based on \`add\` conditions, but found ${count / data.length}`
1851
1850
  );
1852
1851
  }
1853
1852
  } catch (err) {
1854
1853
  if (err.code === "42P10") {
1855
- throw new orchidCore.OrchidOrmInternalError(
1854
+ throw new pqb.OrchidOrmInternalError(
1856
1855
  query,
1857
1856
  `"${state.joinTableQuery.table}" must have a primary key or a unique index on columns (${joinTableColumns.join(
1858
1857
  ", "
@@ -1884,7 +1883,7 @@ const nestedUpdate = (state) => {
1884
1883
  if (params.set) {
1885
1884
  const j = queryJoinTable(state, data);
1886
1885
  await pqb._queryDelete(j);
1887
- if (Array.isArray(params.set) ? params.set.length : orchidCore.objectHasValues(params.set)) {
1886
+ if (Array.isArray(params.set) ? params.set.length : pqb.objectHasValues(params.set)) {
1888
1887
  const idsRows = await pqb._queryRows(
1889
1888
  pqb._querySelect(
1890
1889
  state.relatedTableQuery.where(
@@ -2208,10 +2207,4 @@ Object.keys(pqb).forEach(function (k) {
2208
2207
  get: function () { return pqb[k]; }
2209
2208
  });
2210
2209
  });
2211
- Object.keys(orchidCore).forEach(function (k) {
2212
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2213
- enumerable: true,
2214
- get: function () { return orchidCore[k]; }
2215
- });
2216
- });
2217
2210
  //# sourceMappingURL=index.js.map