@tstdl/base 0.92.94 → 0.92.96

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.
@@ -8,7 +8,7 @@ type ConverterContext = {
8
8
  };
9
9
  export declare const getDrizzleTableFromType: typeof _getDrizzleTableFromType;
10
10
  export declare function getColumnDefinitions(table: PgTableWithColumns<any>): ColumnDefinition[];
11
- export declare function _getDrizzleTableFromType<T extends EntityType, S extends string>(type: T, schemaName?: S): PgTableFromType<T, S>;
11
+ export declare function _getDrizzleTableFromType<T extends EntityType, S extends string>(type: T, fallbackSchemaName?: S): PgTableFromType<T, S>;
12
12
  export declare function registerEnum(enumeration: Enumeration, name: string): void;
13
13
  export declare function getPgEnum(schema: string | PgSchema, enumeration: Enumeration, context?: ConverterContext): PgEnum<[string, ...string[]]>;
14
14
  export {};
@@ -25,7 +25,7 @@ const columnDefinitionsSymbol = Symbol('columnDefinitions');
25
25
  export function getColumnDefinitions(table) {
26
26
  return table[columnDefinitionsSymbol];
27
27
  }
28
- export function _getDrizzleTableFromType(type, schemaName) {
28
+ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
29
29
  const metadata = reflectionRegistry.getMetadata(type);
30
30
  assertDefined(metadata, `Type ${type.name} does not have reflection metadata.`);
31
31
  const tableReflectionDatas = [];
@@ -36,7 +36,7 @@ export function _getDrizzleTableFromType(type, schemaName) {
36
36
  }
37
37
  }
38
38
  const tableReflectionData = tableReflectionDatas[0];
39
- const schema = assertDefinedPass(schemaName ?? tableReflectionData?.schema, 'Table schema not provided');
39
+ const schema = assertDefinedPass(tableReflectionData?.schema ?? fallbackSchemaName, 'Table schema not provided');
40
40
  const tableName = tableReflectionData?.name ?? getDefaultTableName(type);
41
41
  const dbSchema = getDbSchema(schema);
42
42
  const columnDefinitions = getPostgresColumnEntries(type, dbSchema, tableName);
@@ -168,7 +168,7 @@ function getPostgresColumn(tableName, columnName, dbSchema, propertySchema, refl
168
168
  column = column.primaryKey();
169
169
  }
170
170
  if (isDefined(reflectionData.references)) {
171
- column = column.references(() => getDrizzleTableFromType(reflectionData.references()).id);
171
+ column = column.references(() => getDrizzleTableFromType(reflectionData.references(), dbSchema.schemaName).id);
172
172
  }
173
173
  return column;
174
174
  }
@@ -76,7 +76,7 @@ export declare class EntityRepository<T extends Entity | EntityWithoutMetadata =
76
76
  hardDeleteMany(ids: string[]): Promise<T[]>;
77
77
  hardDeleteManyByQuery(query: Query<T>): Promise<T[]>;
78
78
  getColumn(pathOrColumn: Paths<UntaggedDeep<T>> | ColumnDefinition): PgColumn;
79
- convertOrderBy(orderBy: Order<T>): SQL<unknown>[];
79
+ convertOrderBy(order: Order<T>): SQL[];
80
80
  convertQuery(query: Query<T>): SQL;
81
81
  mapManyToEntity(columns: InferSelect[]): Promise<T[]>;
82
82
  mapToEntity(columns: InferSelect): Promise<T>;
@@ -434,9 +434,9 @@ let EntityRepository = class EntityRepository {
434
434
  }
435
435
  return this.#table[pathOrColumn.name];
436
436
  }
437
- convertOrderBy(orderBy) {
438
- if (isArray(orderBy)) {
439
- return orderBy.map((item) => {
437
+ convertOrderBy(order) {
438
+ if (isArray(order)) {
439
+ return order.map((item) => {
440
440
  const itemIsArray = isArray(item);
441
441
  const target = itemIsArray ? item[0] : item;
442
442
  const column = isSQLWrapper(target) ? target : this.getColumn(target);
@@ -444,8 +444,11 @@ let EntityRepository = class EntityRepository {
444
444
  return direction == 'asc' ? asc(column) : desc(column);
445
445
  });
446
446
  }
447
- return objectEntries(orderBy)
448
- .map(([path, direction]) => {
447
+ if (isString(order)) {
448
+ const column = this.getColumn(order);
449
+ return [asc(column)];
450
+ }
451
+ return objectEntries(order).map(([path, direction]) => {
449
452
  const column = this.getColumn(path);
450
453
  return direction == 'asc' ? asc(column) : desc(column);
451
454
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.94",
3
+ "version": "0.92.96",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"