@tstdl/base 0.92.79 → 0.92.80
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
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
import type { SQL } from 'drizzle-orm';
|
|
1
2
|
import type { LiteralUnion } from 'type-fest';
|
|
2
3
|
import type { AbstractConstructor, TypedOmit } from '../types.js';
|
|
3
|
-
import type { EntityType } from './entity.js';
|
|
4
|
+
import type { Entity, EntityType } from './entity.js';
|
|
5
|
+
import type { PgTableFromType } from './server/types.js';
|
|
4
6
|
type IndexMethod = LiteralUnion<'hash' | 'btree' | 'gist' | 'spgist' | 'gin' | 'brin' | 'hnsw' | 'ivfflat', string>;
|
|
7
|
+
export type CheckBuilder<T extends Entity = any> = (table: PgTableFromType<string, EntityType<T>>) => SQL;
|
|
5
8
|
export type OrmTableReflectionData = {
|
|
6
9
|
name?: string;
|
|
7
10
|
schema?: string;
|
|
8
11
|
unique?: UniqueReflectionData[];
|
|
9
12
|
index?: IndexReflectionData[];
|
|
13
|
+
checks?: {
|
|
14
|
+
name: string;
|
|
15
|
+
builder: CheckBuilder;
|
|
16
|
+
}[];
|
|
10
17
|
};
|
|
11
18
|
export type OrmColumnReflectionData = {
|
|
12
19
|
name?: string;
|
|
@@ -46,6 +53,7 @@ export declare function createTableAndColumnDecorator(data?: OrmColumnReflection
|
|
|
46
53
|
export declare function Column(options: OrmColumnReflectionData): PropertyDecorator;
|
|
47
54
|
export declare function PrimaryKey(): PropertyDecorator;
|
|
48
55
|
export declare function References(type: () => EntityType): PropertyDecorator;
|
|
56
|
+
export declare function Check<T extends Entity>(name: string, builder: CheckBuilder<T>): ClassDecorator;
|
|
49
57
|
export declare function Encrypted(): PropertyDecorator;
|
|
50
58
|
export declare function Embedded(type: AbstractConstructor, options?: TypedOmit<NonNullable<OrmColumnReflectionData['embedded']>, 'type'>): PropertyDecorator;
|
|
51
59
|
type TableOptions = Partial<Pick<OrmTableReflectionData, 'name' | 'schema'>>;
|
package/orm/decorators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/
|
|
1
|
+
import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/index.js';
|
|
2
2
|
import { Property } from '../schema/index.js';
|
|
3
3
|
import { assertNotArrayPass, isArray, isString } from '../utils/type-guards.js';
|
|
4
4
|
export function createTableDecorator(data) {
|
|
@@ -19,6 +19,15 @@ export function PrimaryKey() {
|
|
|
19
19
|
export function References(type) {
|
|
20
20
|
return createColumnDecorator({ references: type });
|
|
21
21
|
}
|
|
22
|
+
export function Check(name, builder) {
|
|
23
|
+
return createClassDecorator({
|
|
24
|
+
handler: (_, metadata) => {
|
|
25
|
+
const checks = metadata.data.tryGet('orm')?.checks ?? [];
|
|
26
|
+
checks.push({ name, builder });
|
|
27
|
+
metadata.data.set('orm', { checks }, true);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
22
31
|
export function Encrypted() {
|
|
23
32
|
return createColumnDecorator({ encrypted: true });
|
|
24
33
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toCamelCase, toSnakeCase } from 'drizzle-orm/casing';
|
|
2
|
-
import { boolean, doublePrecision, index, integer, jsonb, pgSchema, primaryKey, text, unique, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { boolean, check, doublePrecision, index, integer, jsonb, pgSchema, primaryKey, text, unique, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
|
|
3
3
|
import { MultiKeyMap } from '../../../data-structures/multi-key-map.js';
|
|
4
4
|
import { tryGetEnumName } from '../../../enumeration/enumeration.js';
|
|
5
5
|
import { NotSupportedError } from '../../../errors/not-supported.error.js';
|
|
@@ -76,7 +76,8 @@ export function _getDrizzleTableFromType(type, schemaName) {
|
|
|
76
76
|
}
|
|
77
77
|
return constraint;
|
|
78
78
|
}) ?? []),
|
|
79
|
-
...(tableReflectionData?.index?.map((data) => buildIndex(table, data)) ?? [])
|
|
79
|
+
...(tableReflectionData?.index?.map((data) => buildIndex(table, data)) ?? []),
|
|
80
|
+
...(tableReflectionData?.checks?.map((data) => check(data.name, data.builder(table))) ?? [])
|
|
80
81
|
]);
|
|
81
82
|
drizzleSchema[columnDefinitionsSymbol] = columnDefinitions;
|
|
82
83
|
return drizzleSchema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.92.
|
|
3
|
+
"version": "0.92.80",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"@types/node": "22",
|
|
146
146
|
"@types/nodemailer": "6.4",
|
|
147
147
|
"@types/pg": "8.11",
|
|
148
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
148
|
+
"@typescript-eslint/eslint-plugin": "8.25",
|
|
149
149
|
"concurrently": "9.1",
|
|
150
150
|
"drizzle-kit": "0.30",
|
|
151
151
|
"eslint": "9.21",
|
package/reflection/utils.js
CHANGED
|
@@ -3,9 +3,7 @@ import { noop } from '../utils/noop.js';
|
|
|
3
3
|
import { assert, isDefined, isFunction, isSymbol } from '../utils/type-guards.js';
|
|
4
4
|
import { getDecoratorData } from './decorator-data.js';
|
|
5
5
|
import { reflectionRegistry } from './registry.js';
|
|
6
|
-
// eslint-disable-next-line max-lines-per-function
|
|
7
6
|
export function createDecorator(options, handler = noop) {
|
|
8
|
-
// eslint-disable-next-line max-statements, max-lines-per-function
|
|
9
7
|
function decoratorWrapper(...args) {
|
|
10
8
|
const data = getDecoratorData(...args);
|
|
11
9
|
const optionsType = (data.type == 'constructor-parameter') ? 'constructorParameter'
|