@tstdl/base 0.92.43 → 0.92.44
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/orm/decorators.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export declare function References(type: () => EntityType): PropertyDecorator;
|
|
|
47
47
|
export declare function Embedded(type: AbstractConstructor, options?: TypedOmit<NonNullable<OrmColumnReflectionData['embedded']>, 'type'>): PropertyDecorator;
|
|
48
48
|
export declare function Unique(name?: string, options?: UniqueReflectionData['options']): PropertyDecorator;
|
|
49
49
|
export declare function Unique(name: string | undefined, columns: [string, ...string[]], options?: UniqueReflectionData['options']): ClassDecorator;
|
|
50
|
+
export declare function Unique(columns: [string, ...string[]], options?: UniqueReflectionData['options']): ClassDecorator;
|
|
50
51
|
export declare function Index(name?: string, options?: IndexReflectionData['options']): PropertyDecorator;
|
|
51
52
|
export declare function Index(name: string | undefined, columns: [string, ...string[]], options?: IndexReflectionData['options']): ClassDecorator;
|
|
53
|
+
export declare function Index(columns: [string, ...string[]], options?: IndexReflectionData['options']): ClassDecorator;
|
|
52
54
|
export {};
|
package/orm/decorators.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/utils.js';
|
|
2
2
|
import { Property } from '../schema/index.js';
|
|
3
|
-
import { isArray } from '../utils/type-guards.js';
|
|
3
|
+
import { assertNotArrayPass, isArray } from '../utils/type-guards.js';
|
|
4
4
|
export function createTableDecorator(data) {
|
|
5
5
|
return createClassDecorator({ data: { orm: data }, mergeData: true });
|
|
6
6
|
}
|
|
@@ -24,15 +24,21 @@ export function Embedded(type, options) {
|
|
|
24
24
|
include: [Property(type), createColumnDecorator({ embedded: { type, ...options } })]
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
export function Unique(
|
|
27
|
+
export function Unique(nameOrColumns, columnsOrOptions, options) {
|
|
28
|
+
if (isArray(nameOrColumns)) {
|
|
29
|
+
return createTableDecorator({ unique: [{ columns: nameOrColumns, options: assertNotArrayPass(columnsOrOptions) }] });
|
|
30
|
+
}
|
|
28
31
|
if (isArray(columnsOrOptions)) {
|
|
29
|
-
return createTableDecorator({ unique: [{ name, columns: columnsOrOptions, options }] });
|
|
32
|
+
return createTableDecorator({ unique: [{ name: nameOrColumns, columns: columnsOrOptions, options }] });
|
|
30
33
|
}
|
|
31
|
-
return createColumnDecorator({ unique: { name, options: columnsOrOptions ?? options } });
|
|
34
|
+
return createColumnDecorator({ unique: { name: nameOrColumns, options: columnsOrOptions ?? options } });
|
|
32
35
|
}
|
|
33
|
-
export function Index(
|
|
36
|
+
export function Index(nameOrColumns, columnsOrOptions, options) {
|
|
37
|
+
if (isArray(nameOrColumns)) {
|
|
38
|
+
return createTableDecorator({ index: [{ columns: nameOrColumns, options: assertNotArrayPass(columnsOrOptions) }] });
|
|
39
|
+
}
|
|
34
40
|
if (isArray(columnsOrOptions)) {
|
|
35
|
-
return createTableDecorator({ index: [{ name, columns: columnsOrOptions, options }] });
|
|
41
|
+
return createTableDecorator({ index: [{ name: nameOrColumns, columns: columnsOrOptions, options }] });
|
|
36
42
|
}
|
|
37
|
-
return createColumnDecorator({ index: { name, options: columnsOrOptions ?? options } });
|
|
43
|
+
return createColumnDecorator({ index: { name: nameOrColumns, options: columnsOrOptions ?? options } });
|
|
38
44
|
}
|
|
@@ -46,7 +46,7 @@ export function _getDrizzleTableFromType(type, schemaName, tableName = getDefaul
|
|
|
46
46
|
return column;
|
|
47
47
|
});
|
|
48
48
|
const indexFn = (data.options?.unique == true) ? uniqueIndex : index;
|
|
49
|
-
return indexFn().using(data.options?.using ?? 'btree', ...columns);
|
|
49
|
+
return indexFn(data.name).using(data.options?.using ?? 'btree', ...columns);
|
|
50
50
|
}
|
|
51
51
|
const columnEntries = columnDefinitions.map((entry) => [entry.name, entry.type]);
|
|
52
52
|
const drizzleSchema = dbSchema.table(tableName, fromEntries(columnEntries), (table) => [
|