@tstdl/base 0.92.85 → 0.92.87
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/ai/ai.service.d.ts +4 -4
- package/ai/ai.service.js +27 -14
- package/ai/types.d.ts +5 -4
- package/api/server/gateway.js +1 -1
- package/authentication/authentication.api.d.ts +9 -9
- package/authentication/models/schemas.d.ts +2 -2
- package/authentication/server/authentication-ancillary.service.d.ts +6 -4
- package/authentication/server/authentication-ancillary.service.js +5 -5
- package/cancellation/token.d.ts +1 -1
- package/context/context.d.ts +1 -9
- package/context/context.js +8 -5
- package/document-management/api/document-management.api.d.ts +142 -110
- package/document-management/models/document-category.model.d.ts +1 -0
- package/document-management/models/document-category.model.js +2 -0
- package/document-management/models/document-collection-document.model.js +7 -3
- package/document-management/models/document-property-value.model.d.ts +13 -14
- package/document-management/models/document-property-value.model.js +60 -27
- package/document-management/models/document-property.model.d.ts +2 -0
- package/document-management/models/document-property.model.js +4 -1
- package/document-management/models/document-request-assignment-task-collection.model.d.ts +7 -0
- package/document-management/models/document-request-assignment-task-collection.model.js +32 -0
- package/document-management/models/document-request-assignment-task.model.d.ts +14 -0
- package/document-management/models/document-request-assignment-task.model.js +72 -0
- package/document-management/models/document-request-collection.model.d.ts +1 -0
- package/document-management/models/document-request-collection.model.js +7 -3
- package/document-management/models/document-request-file.model.d.ts +7 -2
- package/document-management/models/document-request-file.model.js +29 -4
- package/document-management/models/document-request.model.d.ts +1 -0
- package/document-management/models/document-requests-template.js +2 -0
- package/document-management/models/document-type-property.model.js +7 -3
- package/document-management/models/document-type.model.d.ts +1 -0
- package/document-management/models/document-type.model.js +7 -3
- package/document-management/models/document.model.d.ts +5 -2
- package/document-management/models/document.model.js +21 -6
- package/document-management/models/index.d.ts +2 -0
- package/document-management/models/index.js +2 -0
- package/document-management/models/service-models/document.service-model.d.ts +84 -65
- package/document-management/models/service-models/document.service-model.js +11 -6
- package/document-management/models/service-models/document.view-model.d.ts +1 -1
- package/document-management/models/service-models/document.view-model.js +2 -2
- package/document-management/server/drizzle/{0000_sloppy_fenris.sql → 0000_cool_victor_mancha.sql} +99 -43
- package/document-management/server/drizzle/meta/0000_snapshot.json +518 -130
- package/document-management/server/drizzle/meta/_journal.json +2 -2
- package/document-management/server/drizzle.config.js +1 -1
- package/document-management/server/module.d.ts +3 -2
- package/document-management/server/module.js +4 -2
- package/document-management/server/schemas.d.ts +36 -0
- package/document-management/server/schemas.js +37 -0
- package/document-management/server/services/document-management-ancillary.service.d.ts +4 -0
- package/document-management/server/services/document-management-ancillary.service.js +13 -0
- package/document-management/server/services/document-management.service.d.ts +71 -22
- package/document-management/server/services/document-management.service.js +528 -81
- package/document-management/server/services/index.d.ts +1 -0
- package/document-management/server/services/index.js +1 -0
- package/eslint.config.js +1 -0
- package/examples/document-management/main.d.ts +5 -0
- package/examples/document-management/main.js +20 -2
- package/examples/orm/schemas.d.ts +1 -1
- package/file/index.d.ts +1 -0
- package/file/index.js +1 -0
- package/file/temporary-file.d.ts +17 -0
- package/file/temporary-file.js +49 -0
- package/http/server/http-server-response.d.ts +2 -0
- package/http/server/http-server-response.js +13 -0
- package/injector/index.d.ts +1 -0
- package/injector/index.js +1 -0
- package/injector/injector.js +19 -7
- package/injector/interfaces.d.ts +1 -1
- package/injector/interfaces.js +1 -1
- package/injector/resolution.d.ts +15 -0
- package/injector/resolution.js +6 -0
- package/logger/console/logger.d.ts +1 -1
- package/logger/logger.d.ts +1 -1
- package/mail/drizzle.config.js +1 -1
- package/mail/models/schemas.d.ts +1 -1
- package/object-storage/object-storage.d.ts +5 -7
- package/object-storage/s3/s3.object-storage.d.ts +0 -1
- package/object-storage/s3/s3.object-storage.js +0 -3
- package/orm/{server/data-types → data-types}/numeric-date.js +2 -3
- package/orm/decorators.d.ts +17 -8
- package/orm/decorators.js +13 -7
- package/orm/entity.d.ts +5 -7
- package/orm/entity.js +11 -7
- package/orm/index.d.ts +2 -0
- package/orm/index.js +2 -0
- package/orm/query.d.ts +1 -3
- package/orm/query.js +0 -1
- package/orm/repository.types.d.ts +32 -0
- package/orm/repository.types.js +1 -0
- package/orm/server/database-schema.d.ts +4 -4
- package/orm/server/drizzle/schema-converter.d.ts +1 -1
- package/orm/server/drizzle/schema-converter.js +48 -19
- package/orm/server/index.d.ts +1 -0
- package/orm/server/index.js +1 -0
- package/orm/server/query-converter.d.ts +1 -2
- package/orm/server/query-converter.js +66 -61
- package/orm/server/repository.d.ts +80 -43
- package/orm/server/repository.js +219 -112
- package/orm/server/sqls.d.ts +15 -0
- package/orm/server/sqls.js +19 -0
- package/orm/server/types.d.ts +3 -3
- package/orm/types.d.ts +4 -4
- package/orm/utils.d.ts +3 -0
- package/orm/utils.js +6 -0
- package/package.json +23 -19
- package/pdf/pdf.service.d.ts +0 -1
- package/pdf/pdf.service.js +1 -95
- package/pdf/utils.d.ts +3 -1
- package/pdf/utils.js +129 -4
- package/promise/lazy-promise.d.ts +3 -3
- package/queue/enqueue-batch.d.ts +1 -0
- package/queue/enqueue-batch.js +1 -1
- package/queue/mongo/queue.d.ts +9 -4
- package/queue/mongo/queue.js +5 -6
- package/queue/postgres/drizzle/0000_zippy_moondragon.sql +11 -0
- package/queue/postgres/drizzle/meta/0000_snapshot.json +90 -0
- package/queue/postgres/drizzle/meta/_journal.json +13 -0
- package/queue/postgres/drizzle.config.d.ts +2 -0
- package/queue/postgres/drizzle.config.js +11 -0
- package/queue/postgres/index.d.ts +4 -0
- package/queue/postgres/index.js +4 -0
- package/queue/postgres/job.model.d.ts +13 -0
- package/queue/postgres/job.model.js +55 -0
- package/queue/postgres/module.d.ts +9 -0
- package/queue/postgres/module.js +29 -0
- package/queue/postgres/queue.d.ts +28 -0
- package/queue/postgres/queue.js +147 -0
- package/queue/postgres/queue.provider.d.ts +7 -0
- package/queue/postgres/queue.provider.js +21 -0
- package/queue/postgres/schemas.d.ts +3 -0
- package/queue/postgres/schemas.js +4 -0
- package/queue/provider.d.ts +2 -1
- package/queue/queue.d.ts +32 -6
- package/queue/queue.js +43 -0
- package/schema/schemas/object.d.ts +1 -1
- package/utils/date-time.d.ts +4 -2
- package/utils/date-time.js +10 -3
- package/utils/format-error.js +0 -1
- package/utils/object/lazy-property.js +0 -1
- package/utils/timing.d.ts +4 -3
- package/utils/timing.js +3 -1
- package/utils/try-ignore.d.ts +9 -2
- package/utils/try-ignore.js +30 -6
- package/document-management/models/schemas.d.ts +0 -33
- package/document-management/models/schemas.js +0 -34
- /package/orm/{server/data-types → data-types}/bytea.d.ts +0 -0
- /package/orm/{server/data-types → data-types}/bytea.js +0 -0
- /package/orm/{server/data-types → data-types}/index.d.ts +0 -0
- /package/orm/{server/data-types → data-types}/index.js +0 -0
- /package/orm/{server/data-types → data-types}/numeric-date.d.ts +0 -0
- /package/orm/{server/data-types → data-types}/timestamp.d.ts +0 -0
- /package/orm/{server/data-types → data-types}/timestamp.js +0 -0
package/orm/query.js
CHANGED
|
@@ -2,6 +2,5 @@ export const allLogicalQueryTypes = ['$and', '$or', '$nor'];
|
|
|
2
2
|
export const allComparisonQueryTypes = ['$all', '$not', '$eq', '$exists', '$gt', '$gte', '$in', '$item', '$lt', '$lte', '$neq', '$nin', '$regex', '$text', '$geoDistance', '$geoShape'];
|
|
3
3
|
export const allSpecialQueryTypes = ['$textSpan'];
|
|
4
4
|
export const allQueryTypes = [...allLogicalQueryTypes, ...allComparisonQueryTypes, ...allSpecialQueryTypes];
|
|
5
|
-
export const allOrders = ['asc', 'desc'];
|
|
6
5
|
export const allOperators = ['and', 'or'];
|
|
7
6
|
export const allTextSpanQueryModes = ['best', 'most', 'cross'];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Paths, Record, TypedOmit } from '../types.js';
|
|
2
|
+
import type { UntaggedDeep } from '../types/tagged.js';
|
|
3
|
+
import type { SQL, SQLWrapper } from 'drizzle-orm';
|
|
4
|
+
import type { PartialDeep } from 'type-fest';
|
|
5
|
+
import type { Entity, EntityMetadata, EntityWithoutMetadata } from './entity.js';
|
|
6
|
+
type WithSql<T> = {
|
|
7
|
+
[P in keyof T]: T[P] extends Record ? WithSql<T[P]> : (T[P] | SQL);
|
|
8
|
+
};
|
|
9
|
+
export type OrderDirection = 'asc' | 'desc';
|
|
10
|
+
export type OrderTarget<T extends EntityWithoutMetadata> = Paths<UntaggedDeep<T>> | SQLWrapper;
|
|
11
|
+
export type Order<T extends EntityWithoutMetadata> = OrderTarget<T> | (OrderTarget<T> | [OrderTarget<T>, OrderDirection])[] | Partial<Record<Exclude<OrderTarget<T>, SQLWrapper>, OrderDirection>>;
|
|
12
|
+
export type OrderOptions<T extends EntityWithoutMetadata> = {
|
|
13
|
+
order?: Order<T>;
|
|
14
|
+
};
|
|
15
|
+
export type LoadOptions<T extends EntityWithoutMetadata> = OrderOptions<T> & {
|
|
16
|
+
offset?: number;
|
|
17
|
+
};
|
|
18
|
+
export type LoadManyOptions<T extends EntityWithoutMetadata> = LoadOptions<T> & {
|
|
19
|
+
limit?: number;
|
|
20
|
+
};
|
|
21
|
+
export type UpdateOptions<T extends EntityWithoutMetadata> = LoadOptions<T>;
|
|
22
|
+
export type EntityMetadataUpdate = WithSql<Partial<UntaggedDeep<Pick<EntityMetadata, 'attributes'>>>>;
|
|
23
|
+
export type NewEntity<T extends Entity | EntityWithoutMetadata> = T extends Entity ? WithSql<UntaggedDeep<TypedOmit<T, 'id' | 'metadata'> & {
|
|
24
|
+
id?: string;
|
|
25
|
+
metadata?: Partial<Pick<EntityMetadata, 'attributes'>>;
|
|
26
|
+
}>> : WithSql<UntaggedDeep<TypedOmit<T, 'id'> & {
|
|
27
|
+
id?: string;
|
|
28
|
+
}>>;
|
|
29
|
+
export type EntityUpdate<T extends EntityWithoutMetadata> = T extends Entity ? WithSql<PartialDeep<UntaggedDeep<TypedOmit<T, 'metadata'>>>> & {
|
|
30
|
+
metadata?: EntityMetadataUpdate;
|
|
31
|
+
} : WithSql<PartialDeep<UntaggedDeep<T>>>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,10 +2,10 @@ import type { PgEnum } from 'drizzle-orm/pg-core';
|
|
|
2
2
|
import type { Enumeration, EnumerationValue, UnionToTuple } from '../../types.js';
|
|
3
3
|
import type { EntityType } from '../entity.js';
|
|
4
4
|
import type { PgTableFromType } from './types.js';
|
|
5
|
-
export declare class DatabaseSchema<
|
|
6
|
-
readonly name:
|
|
7
|
-
constructor(name:
|
|
8
|
-
getTable<T extends EntityType>(type: T): PgTableFromType<
|
|
5
|
+
export declare class DatabaseSchema<SchemaName extends string> {
|
|
6
|
+
readonly name: SchemaName;
|
|
7
|
+
constructor(name: SchemaName);
|
|
8
|
+
getTable<T extends EntityType>(type: T): PgTableFromType<T, SchemaName>;
|
|
9
9
|
getEnum<T extends Enumeration>(enumeration: T, name?: string): PgEnum<UnionToTuple<`${EnumerationValue<T>}`> extends [string, ...string[]] ? UnionToTuple<`${EnumerationValue<T>}`> : never>;
|
|
10
10
|
}
|
|
11
11
|
export declare function databaseSchema<Name extends string>(name: Name): DatabaseSchema<Name>;
|
|
@@ -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<
|
|
11
|
+
export declare function _getDrizzleTableFromType<T extends EntityType, S extends string>(type: T, schemaName?: 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 {};
|
|
@@ -12,12 +12,12 @@ import { enumValues } from '../../../utils/enum.js';
|
|
|
12
12
|
import { memoize, memoizeSingle } from '../../../utils/function/memoize.js';
|
|
13
13
|
import { compileDereferencer } from '../../../utils/object/dereference.js';
|
|
14
14
|
import { fromEntries, objectEntries } from '../../../utils/object/object.js';
|
|
15
|
-
import { assertDefined, assertDefinedPass, isArray, isDefined, isNull, isString, isUndefined } from '../../../utils/type-guards.js';
|
|
15
|
+
import { assertDefined, assertDefinedPass, isArray, isDefined, isNotNullOrUndefined, isNull, isString, isUndefined } from '../../../utils/type-guards.js';
|
|
16
|
+
import { bytea, numericDate, timestamp } from '../../data-types/index.js';
|
|
16
17
|
import { JsonSchema } from '../../schemas/json.js';
|
|
17
18
|
import { NumericDateSchema } from '../../schemas/numeric-date.js';
|
|
18
19
|
import { TimestampSchema } from '../../schemas/timestamp.js';
|
|
19
20
|
import { UuidSchema } from '../../schemas/uuid.js';
|
|
20
|
-
import { bytea, numericDate, timestamp } from '../data-types/index.js';
|
|
21
21
|
import { decryptBytes, encryptBytes } from '../encryption.js';
|
|
22
22
|
const getDbSchema = memoizeSingle(pgSchema);
|
|
23
23
|
export const getDrizzleTableFromType = memoize(_getDrizzleTableFromType);
|
|
@@ -28,11 +28,18 @@ export function getColumnDefinitions(table) {
|
|
|
28
28
|
export function _getDrizzleTableFromType(type, schemaName) {
|
|
29
29
|
const metadata = reflectionRegistry.getMetadata(type);
|
|
30
30
|
assertDefined(metadata, `Type ${type.name} does not have reflection metadata.`);
|
|
31
|
-
const
|
|
31
|
+
const tableReflectionDatas = [];
|
|
32
|
+
for (let currentMetadata = metadata; isNotNullOrUndefined(currentMetadata?.parent); currentMetadata = reflectionRegistry.getMetadata(currentMetadata.parent)) {
|
|
33
|
+
const tableReflectionData = currentMetadata.data.tryGet('orm');
|
|
34
|
+
if (isDefined(tableReflectionData)) {
|
|
35
|
+
tableReflectionDatas.push(tableReflectionData);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const tableReflectionData = tableReflectionDatas[0];
|
|
32
39
|
const schema = assertDefinedPass(schemaName ?? tableReflectionData?.schema, 'Table schema not provided');
|
|
33
40
|
const tableName = tableReflectionData?.name ?? getDefaultTableName(type);
|
|
34
41
|
const dbSchema = getDbSchema(schema);
|
|
35
|
-
const columnDefinitions = getPostgresColumnEntries(type,
|
|
42
|
+
const columnDefinitions = getPostgresColumnEntries(type, dbSchema, tableName);
|
|
36
43
|
function getColumn(table, propertyName) {
|
|
37
44
|
return assertDefinedPass(table[propertyName], `Property "${propertyName}" does not exist on ${type.name}`);
|
|
38
45
|
}
|
|
@@ -52,14 +59,21 @@ export function _getDrizzleTableFromType(type, schemaName) {
|
|
|
52
59
|
return column;
|
|
53
60
|
});
|
|
54
61
|
const indexFn = (data.options?.unique == true) ? uniqueIndex : index;
|
|
55
|
-
return indexFn(data.name).using(data.options?.using ?? 'btree', ...columns);
|
|
62
|
+
return indexFn(data.name ?? getIndexName(tableName, columns, { naming: data.options?.naming })).using(data.options?.using ?? 'btree', ...columns);
|
|
56
63
|
}
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
function buildPrimaryKey(table) {
|
|
65
|
+
const columns = primaryKeyColumnDefinitions.map((columnDefinition) => getColumn(table, columnDefinition.name));
|
|
66
|
+
return primaryKey({
|
|
67
|
+
name: tableReflectionData?.compundPrimaryKeyName ?? getPrimaryKeyName(tableName, columns, { naming: tableReflectionData?.compundPrimaryKeyNaming }),
|
|
68
|
+
columns
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const primaryKeyColumnDefinitions = columnDefinitions.filter((columnDefinition) => columnDefinition.reflectionData?.primaryKey == true);
|
|
72
|
+
const skipPrimaryKey = primaryKeyColumnDefinitions.length > 1;
|
|
59
73
|
const columnEntries = columnDefinitions.map((entry) => [entry.name, entry.buildType({ skipPrimaryKey })]);
|
|
60
74
|
const drizzleSchema = dbSchema.table(tableName, fromEntries(columnEntries), (table) => [
|
|
61
|
-
...((
|
|
62
|
-
? [
|
|
75
|
+
...((primaryKeyColumnDefinitions.length > 1)
|
|
76
|
+
? [buildPrimaryKey(table)]
|
|
63
77
|
: []),
|
|
64
78
|
...(columnDefinitions.map((columnDefinition) => {
|
|
65
79
|
const indexData = columnDefinition.reflectionData?.index;
|
|
@@ -68,21 +82,21 @@ export function _getDrizzleTableFromType(type, schemaName) {
|
|
|
68
82
|
}
|
|
69
83
|
return buildIndex(table, indexData, columnDefinition.name);
|
|
70
84
|
}).filter(isDefined)),
|
|
71
|
-
...(tableReflectionData
|
|
85
|
+
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.unique).filter(isDefined).map((data) => {
|
|
72
86
|
const columns = data.columns?.map((column) => getColumn(table, column));
|
|
73
|
-
let constraint = unique(
|
|
87
|
+
let constraint = unique(data.name ?? getUniqueName(tableName, columns, { naming: data.options?.naming })).on(...columns);
|
|
74
88
|
if (data.options?.nulls == 'not distinct') {
|
|
75
89
|
constraint = constraint.nullsNotDistinct();
|
|
76
90
|
}
|
|
77
91
|
return constraint;
|
|
78
|
-
})
|
|
79
|
-
...(tableReflectionData
|
|
80
|
-
...(tableReflectionData
|
|
92
|
+
}),
|
|
93
|
+
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.index).filter(isDefined).map((data) => buildIndex(table, data)),
|
|
94
|
+
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.checks).filter(isDefined).map((data) => check(data.name, data.builder(table)))
|
|
81
95
|
]);
|
|
82
96
|
drizzleSchema[columnDefinitionsSymbol] = columnDefinitions;
|
|
83
97
|
return drizzleSchema;
|
|
84
98
|
}
|
|
85
|
-
function getPostgresColumnEntries(type,
|
|
99
|
+
function getPostgresColumnEntries(type, dbSchema, tableName, path = new JsonPath({ dollar: false }), prefix = '') {
|
|
86
100
|
const metadata = reflectionRegistry.getMetadata(type);
|
|
87
101
|
assertDefined(metadata, `Type ${type.name} does not have reflection metadata (path: ${path.toString()}).`);
|
|
88
102
|
const objectSchema = getObjectSchema(type);
|
|
@@ -94,7 +108,7 @@ function getPostgresColumnEntries(type, tableName, dbSchema, path = new JsonPath
|
|
|
94
108
|
assertDefined(propertyMetadata, `Property "${property}" of type "${type.name}" does not have reflection metadata (path: ${path.toString()}).`);
|
|
95
109
|
const propertyPrefix = columnReflectionData?.embedded?.prefix;
|
|
96
110
|
const nestedPrefix = [prefix, isNull(propertyPrefix) ? '' : propertyPrefix ?? `${columnName}_`].join('');
|
|
97
|
-
return getPostgresColumnEntries(columnReflectionData?.embedded?.type ?? propertyMetadata.type,
|
|
111
|
+
return getPostgresColumnEntries(columnReflectionData?.embedded?.type ?? propertyMetadata.type, dbSchema, tableName, path.add(property), nestedPrefix);
|
|
98
112
|
}
|
|
99
113
|
const objectPath = path.add(property);
|
|
100
114
|
const encrypted = columnReflectionData?.encrypted == true;
|
|
@@ -115,7 +129,7 @@ function getPostgresColumnEntries(type, tableName, dbSchema, path = new JsonPath
|
|
|
115
129
|
name: toCamelCase(prefixedColumnName),
|
|
116
130
|
objectPath,
|
|
117
131
|
reflectionData: columnReflectionData,
|
|
118
|
-
buildType: (options) => getPostgresColumn(toSnakeCase(prefixedColumnName), dbSchema, schema, columnReflectionData ?? {}, options, { type, property }),
|
|
132
|
+
buildType: (options) => getPostgresColumn(tableName, toSnakeCase(prefixedColumnName), dbSchema, schema, columnReflectionData ?? {}, options, { type, property }),
|
|
119
133
|
dereferenceObjectPath: compileDereferencer(objectPath, { optional: true }),
|
|
120
134
|
toDatabase,
|
|
121
135
|
fromDatabase
|
|
@@ -123,7 +137,7 @@ function getPostgresColumnEntries(type, tableName, dbSchema, path = new JsonPath
|
|
|
123
137
|
});
|
|
124
138
|
return entries;
|
|
125
139
|
}
|
|
126
|
-
function getPostgresColumn(columnName, dbSchema, propertySchema, reflectionData, options, context) {
|
|
140
|
+
function getPostgresColumn(tableName, columnName, dbSchema, propertySchema, reflectionData, options, context) {
|
|
127
141
|
let nullable = false;
|
|
128
142
|
let array = false;
|
|
129
143
|
let baseSchema = propertySchema;
|
|
@@ -148,7 +162,7 @@ function getPostgresColumn(columnName, dbSchema, propertySchema, reflectionData,
|
|
|
148
162
|
column = column.notNull();
|
|
149
163
|
}
|
|
150
164
|
if (isDefined(reflectionData.unique)) {
|
|
151
|
-
column = column.unique(reflectionData.unique.name, isString(reflectionData.unique.options?.nulls) ? { nulls: reflectionData.unique.options.nulls } : undefined);
|
|
165
|
+
column = column.unique(reflectionData.unique.name ?? getUniqueName(tableName, [columnName], { naming: reflectionData.unique.options?.naming }), isString(reflectionData.unique.options?.nulls) ? { nulls: reflectionData.unique.options.nulls } : undefined);
|
|
152
166
|
}
|
|
153
167
|
if ((reflectionData.primaryKey == true) && (options.skipPrimaryKey != true)) {
|
|
154
168
|
column = column.primaryKey();
|
|
@@ -227,3 +241,18 @@ export function getPgEnum(schema, enumeration, context) {
|
|
|
227
241
|
function getDefaultTableName(type) {
|
|
228
242
|
return toSnakeCase(isString(type.entityName) ? type.entityName : type.name.replace(/\d+$/u, ''));
|
|
229
243
|
}
|
|
244
|
+
function getPrimaryKeyName(tableName, columns, options) {
|
|
245
|
+
return `${getTablePrefix(tableName, options?.naming)}_${getColumnNames(columns).join('_')}_pk`;
|
|
246
|
+
}
|
|
247
|
+
function getIndexName(tableName, columns, options) {
|
|
248
|
+
return `${getTablePrefix(tableName, options?.naming)}_${getColumnNames(columns).join('_')}_idx`;
|
|
249
|
+
}
|
|
250
|
+
function getUniqueName(tableName, columns, options) {
|
|
251
|
+
return `${getTablePrefix(tableName, options?.naming)}_${getColumnNames(columns).join('_')}_unique`;
|
|
252
|
+
}
|
|
253
|
+
function getTablePrefix(tableName, naming) {
|
|
254
|
+
return (naming == 'abbreviated-table') ? tableName.split('_').map((part) => part[0]).join('') : tableName;
|
|
255
|
+
}
|
|
256
|
+
function getColumnNames(columns) {
|
|
257
|
+
return columns.map((column) => isString(column) ? column : column.name);
|
|
258
|
+
}
|
package/orm/server/index.d.ts
CHANGED
package/orm/server/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SQL } from 'drizzle-orm';
|
|
2
|
-
import type { EntityType } from '../entity.js';
|
|
3
2
|
import type { Query } from '../query.js';
|
|
4
3
|
import type { ColumnDefinition, PgTableFromType } from './types.js';
|
|
5
|
-
export declare function convertQuery(query: Query, table: PgTableFromType
|
|
4
|
+
export declare function convertQuery(query: Query, table: PgTableFromType, columnDefinitionsMap: Map<string, ColumnDefinition>): SQL;
|
|
@@ -14,8 +14,8 @@ export function convertQuery(query, table, columnDefinitionsMap) {
|
|
|
14
14
|
if (queryEntries.length == 0) {
|
|
15
15
|
return sqlTrue;
|
|
16
16
|
}
|
|
17
|
+
const conditions = [];
|
|
17
18
|
for (const [property, value] of queryEntries) {
|
|
18
|
-
const isPrimitiveValue = isPrimitive(value);
|
|
19
19
|
if (property == '$and') {
|
|
20
20
|
if (queryEntries.length > 1) {
|
|
21
21
|
throw new Error('only one logical operator per level allowed');
|
|
@@ -48,66 +48,71 @@ export function convertQuery(query, table, columnDefinitionsMap) {
|
|
|
48
48
|
}
|
|
49
49
|
const columnDef = assertDefinedPass(columnDefinitionsMap.get(property), `Could not map property ${property} to column.`);
|
|
50
50
|
const column = table[columnDef.name];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const queryValue = value.$in;
|
|
70
|
-
return inArray(column, queryValue);
|
|
71
|
-
}
|
|
72
|
-
if (hasOwnProperty(value, '$nin')) {
|
|
73
|
-
const queryValue = value.$nin;
|
|
74
|
-
return notInArray(column, queryValue);
|
|
75
|
-
}
|
|
76
|
-
if (hasOwnProperty(value, '$lt')) {
|
|
77
|
-
const queryValue = value.$lt;
|
|
78
|
-
return lt(column, queryValue);
|
|
79
|
-
}
|
|
80
|
-
if (hasOwnProperty(value, '$lte')) {
|
|
81
|
-
const queryValue = value.$lte;
|
|
82
|
-
return lte(column, queryValue);
|
|
83
|
-
}
|
|
84
|
-
if (hasOwnProperty(value, '$gt')) {
|
|
85
|
-
const queryValue = value.$gt;
|
|
86
|
-
return gt(column, queryValue);
|
|
87
|
-
}
|
|
88
|
-
if (hasOwnProperty(value, '$gte')) {
|
|
89
|
-
const queryValue = value.$gte;
|
|
90
|
-
return gte(column, queryValue);
|
|
91
|
-
}
|
|
92
|
-
if (hasOwnProperty(value, '$regex')) {
|
|
93
|
-
const queryValue = value.$regex;
|
|
94
|
-
const regexp = isString(queryValue)
|
|
95
|
-
? ({ value: queryValue })
|
|
96
|
-
: isRegExp(queryValue)
|
|
97
|
-
? ({ flags: queryValue.flags, value: queryValue.source })
|
|
98
|
-
: ({ flags: queryValue.flags, value: queryValue.pattern });
|
|
99
|
-
return sql `regexp_like(${column}, ${regexp.value}, ${regexp.flags})`;
|
|
100
|
-
}
|
|
101
|
-
if (hasOwnProperty(value, '$text')) {
|
|
102
|
-
throw new NotSupportedError('$text is not supported.');
|
|
103
|
-
}
|
|
104
|
-
if (hasOwnProperty(value, '$geoShape')) {
|
|
105
|
-
throw new NotSupportedError('$geoShape is not supported.');
|
|
106
|
-
}
|
|
107
|
-
if (hasOwnProperty(value, '$geoDistance')) {
|
|
108
|
-
throw new NotSupportedError('$geoDistance is not supported.');
|
|
51
|
+
const condition = getCondition(property, value, column);
|
|
52
|
+
conditions.push(condition);
|
|
53
|
+
}
|
|
54
|
+
return and(...conditions);
|
|
55
|
+
}
|
|
56
|
+
function getCondition(property, value, column) {
|
|
57
|
+
const isPrimitiveValue = isPrimitive(value);
|
|
58
|
+
if (isPrimitiveValue || hasOwnProperty(value, '$eq')) {
|
|
59
|
+
const queryValue = isPrimitiveValue ? value : value.$eq;
|
|
60
|
+
if (queryValue === null) {
|
|
61
|
+
return isNull(column);
|
|
62
|
+
}
|
|
63
|
+
return eq(column, queryValue);
|
|
64
|
+
}
|
|
65
|
+
if (hasOwnProperty(value, '$neq')) {
|
|
66
|
+
const queryValue = value.$neq;
|
|
67
|
+
if (queryValue === null) {
|
|
68
|
+
return isNotNull(column);
|
|
109
69
|
}
|
|
110
|
-
|
|
70
|
+
return ne(column, queryValue);
|
|
71
|
+
}
|
|
72
|
+
if (hasOwnProperty(value, '$exists')) {
|
|
73
|
+
throw new NotSupportedError('$exists is not supported.');
|
|
74
|
+
}
|
|
75
|
+
if (hasOwnProperty(value, '$in')) {
|
|
76
|
+
const queryValue = value.$in;
|
|
77
|
+
return inArray(column, queryValue);
|
|
78
|
+
}
|
|
79
|
+
if (hasOwnProperty(value, '$nin')) {
|
|
80
|
+
const queryValue = value.$nin;
|
|
81
|
+
return notInArray(column, queryValue);
|
|
82
|
+
}
|
|
83
|
+
if (hasOwnProperty(value, '$lt')) {
|
|
84
|
+
const queryValue = value.$lt;
|
|
85
|
+
return lt(column, queryValue);
|
|
86
|
+
}
|
|
87
|
+
if (hasOwnProperty(value, '$lte')) {
|
|
88
|
+
const queryValue = value.$lte;
|
|
89
|
+
return lte(column, queryValue);
|
|
90
|
+
}
|
|
91
|
+
if (hasOwnProperty(value, '$gt')) {
|
|
92
|
+
const queryValue = value.$gt;
|
|
93
|
+
return gt(column, queryValue);
|
|
94
|
+
}
|
|
95
|
+
if (hasOwnProperty(value, '$gte')) {
|
|
96
|
+
const queryValue = value.$gte;
|
|
97
|
+
return gte(column, queryValue);
|
|
98
|
+
}
|
|
99
|
+
if (hasOwnProperty(value, '$regex')) {
|
|
100
|
+
const queryValue = value.$regex;
|
|
101
|
+
const regexp = isString(queryValue)
|
|
102
|
+
? ({ value: queryValue })
|
|
103
|
+
: isRegExp(queryValue)
|
|
104
|
+
? ({ flags: queryValue.flags, value: queryValue.source })
|
|
105
|
+
: ({ flags: queryValue.flags, value: queryValue.pattern });
|
|
106
|
+
return sql `regexp_like(${column}, ${regexp.value}, ${regexp.flags})`;
|
|
107
|
+
}
|
|
108
|
+
if (hasOwnProperty(value, '$text')) {
|
|
109
|
+
throw new NotSupportedError('$text is not supported.');
|
|
110
|
+
}
|
|
111
|
+
if (hasOwnProperty(value, '$geoShape')) {
|
|
112
|
+
throw new NotSupportedError('$geoShape is not supported.');
|
|
113
|
+
}
|
|
114
|
+
if (hasOwnProperty(value, '$geoDistance')) {
|
|
115
|
+
throw new NotSupportedError('$geoDistance is not supported.');
|
|
111
116
|
}
|
|
112
|
-
throw new Error(
|
|
117
|
+
throw new Error(`Unsupported query type "${property}".`);
|
|
113
118
|
}
|
|
@@ -1,44 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SQL } from 'drizzle-orm';
|
|
2
2
|
import { PgTransaction as DrizzlePgTransaction, type PgColumn, type PgInsertValue, type PgQueryResultHKT, type PgUpdateSetSource } from 'drizzle-orm/pg-core';
|
|
3
|
-
import type { PartialDeep } from 'type-fest';
|
|
4
3
|
import { type Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
|
|
5
|
-
import type { DeepPartial, OneOrMany, Paths, Record, Type
|
|
4
|
+
import type { DeepPartial, OneOrMany, Paths, Record, Type } from '../../types.js';
|
|
6
5
|
import type { UntaggedDeep } from '../../types/index.js';
|
|
7
|
-
import
|
|
6
|
+
import { Entity, type EntityMetadataAttributes, type EntityType, type EntityWithoutMetadata } from '../entity.js';
|
|
8
7
|
import type { Query } from '../query.js';
|
|
8
|
+
import type { EntityMetadataUpdate, EntityUpdate, LoadManyOptions, LoadOptions, NewEntity, Order } from '../repository.types.js';
|
|
9
9
|
import { Database } from './database.js';
|
|
10
10
|
import { type Transaction, type TransactionConfig } from './transaction.js';
|
|
11
11
|
import type { ColumnDefinition, PgTableFromType, TransformContext } from './types.js';
|
|
12
12
|
type PgTransaction = DrizzlePgTransaction<PgQueryResultHKT, Record, Record>;
|
|
13
13
|
export declare const repositoryType: unique symbol;
|
|
14
|
-
export type OrderOptions<T extends Entity> = {
|
|
15
|
-
order?: Partial<Record<Paths<UntaggedDeep<T>>, 1 | -1 | 'asc' | 'desc'>>;
|
|
16
|
-
};
|
|
17
|
-
export type LoadOptions<T extends Entity> = OrderOptions<T> & {
|
|
18
|
-
offset?: number;
|
|
19
|
-
withDeleted?: boolean;
|
|
20
|
-
};
|
|
21
|
-
export type LoadManyOptions<T extends Entity> = LoadOptions<T> & {
|
|
22
|
-
limit?: number;
|
|
23
|
-
};
|
|
24
|
-
export type UpdateOptions<T extends Entity> = LoadOptions<T>;
|
|
25
|
-
export type EntityMetadataUpdate = Partial<UntaggedDeep<Pick<EntityMetadata, 'attributes'>>>;
|
|
26
|
-
export type EntityUpdate<T extends Entity> = PartialDeep<UntaggedDeep<TypedOmit<T, 'metadata'> & {
|
|
27
|
-
metadata: EntityMetadataUpdate;
|
|
28
|
-
}>>;
|
|
29
14
|
export declare class EntityRepositoryConfig {
|
|
30
15
|
schema: string;
|
|
31
16
|
}
|
|
32
|
-
export type TransactionHandler<T extends
|
|
33
|
-
export declare class EntityRepository<T extends Entity =
|
|
17
|
+
export type TransactionHandler<T extends EntityWithoutMetadata, R> = (repository: EntityRepository<T>, transaction: Transaction) => Promise<R>;
|
|
18
|
+
export declare class EntityRepository<T extends Entity | EntityWithoutMetadata = EntityWithoutMetadata> implements Resolvable<EntityType<T>> {
|
|
34
19
|
#private;
|
|
35
20
|
readonly type: EntityType<T>;
|
|
36
|
-
readonly
|
|
37
|
-
readonly columnDefinitions: ColumnDefinition[];
|
|
38
|
-
readonly columnDefinitionsMap: Map<string, ColumnDefinition>;
|
|
21
|
+
readonly typeName: string;
|
|
39
22
|
readonly session: Database | PgTransaction;
|
|
40
23
|
readonly isInTransaction: boolean;
|
|
24
|
+
readonly hasMetadata: boolean;
|
|
25
|
+
get table(): PgTableFromType<EntityType<T>>;
|
|
41
26
|
readonly [resolveArgumentType]: EntityType<T>;
|
|
27
|
+
readonly _anyInferSelect: PgTableFromType<EntityType<Entity>>['$inferSelect'];
|
|
28
|
+
readonly _inferSelect: PgTableFromType<EntityType<T>>['$inferSelect'];
|
|
42
29
|
constructor();
|
|
43
30
|
withOptionalTransaction(transaction: Transaction | undefined): EntityRepository<T>;
|
|
44
31
|
withTransaction(transaction: Transaction): EntityRepository<T>;
|
|
@@ -69,7 +56,7 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
|
|
|
69
56
|
insert(entity: NewEntity<T>): Promise<T>;
|
|
70
57
|
insertMany(entities: NewEntity<T>[]): Promise<T[]>;
|
|
71
58
|
upsert(target: OneOrMany<Paths<UntaggedDeep<T>>>, entity: NewEntity<T>, update?: EntityUpdate<T>): Promise<T>;
|
|
72
|
-
upsertMany(target: OneOrMany<Paths<UntaggedDeep<T>>>, entities: NewEntity<T>[], update
|
|
59
|
+
upsertMany(target: OneOrMany<Paths<UntaggedDeep<T>>>, entities: NewEntity<T>[], update?: EntityUpdate<T>): Promise<T[]>;
|
|
73
60
|
update(id: string, update: EntityUpdate<T>): Promise<T>;
|
|
74
61
|
tryUpdate(id: string, update: EntityUpdate<T>): Promise<T | undefined>;
|
|
75
62
|
updateByQuery(query: Query<T>, update: EntityUpdate<T>): Promise<T>;
|
|
@@ -82,21 +69,23 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
|
|
|
82
69
|
tryDeleteByQuery(query: Query<T>, metadataUpdate?: EntityMetadataUpdate): Promise<T | undefined>;
|
|
83
70
|
deleteMany(ids: string[], metadataUpdate?: EntityMetadataUpdate): Promise<T[]>;
|
|
84
71
|
deleteManyByQuery(query: Query<T>, metadataUpdate?: EntityMetadataUpdate): Promise<T[]>;
|
|
85
|
-
hardDelete(id: string): Promise<
|
|
86
|
-
tryHardDelete(id: string): Promise<
|
|
87
|
-
hardDeleteByQuery(query: Query<T>): Promise<
|
|
88
|
-
tryHardDeleteByQuery(query: Query<T>): Promise<
|
|
89
|
-
hardDeleteMany(ids: string[]): Promise<
|
|
90
|
-
hardDeleteManyByQuery(query: Query<T>): Promise<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
72
|
+
hardDelete(id: string): Promise<T>;
|
|
73
|
+
tryHardDelete(id: string): Promise<T | undefined>;
|
|
74
|
+
hardDeleteByQuery(query: Query<T>): Promise<T>;
|
|
75
|
+
tryHardDeleteByQuery(query: Query<T>): Promise<T | undefined>;
|
|
76
|
+
hardDeleteMany(ids: string[]): Promise<T[]>;
|
|
77
|
+
hardDeleteManyByQuery(query: Query<T>): Promise<T[]>;
|
|
78
|
+
$getColumn(pathOrColumn: Paths<UntaggedDeep<T>> | ColumnDefinition): PgColumn;
|
|
79
|
+
$convertOrderBy(orderBy: Order<T>): SQL<unknown>[];
|
|
80
|
+
$convertQuery(query: Query<T>): SQL;
|
|
81
|
+
$mapManyToEntity(columns: this['_inferSelect'][]): Promise<T[]>;
|
|
82
|
+
$mapToEntity(columns: this['_inferSelect']): Promise<T>;
|
|
83
|
+
$mapManyToColumns(objects: (DeepPartial<T> | NewEntity<T>)[]): Promise<PgInsertValue<PgTableFromType>[]>;
|
|
84
|
+
$mapToColumns(obj: DeepPartial<T> | NewEntity<T>): Promise<PgInsertValue<PgTableFromType>>;
|
|
85
|
+
$mapManyToInsertColumns(objects: (DeepPartial<T> | NewEntity<T>)[]): Promise<PgInsertValue<PgTableFromType>[]>;
|
|
86
|
+
$mapToInsertColumns(obj: DeepPartial<T> | NewEntity<T>): Promise<PgInsertValue<PgTableFromType>>;
|
|
87
|
+
$mapUpdate(update: EntityUpdate<T>): Promise<PgUpdateSetSource<PgTableFromType>>;
|
|
88
|
+
$getIdLimitQuery(query: Query<T>): Omit<import("drizzle-orm/pg-core").PgSelectBase<string, {
|
|
100
89
|
id: PgColumn<{
|
|
101
90
|
name: string;
|
|
102
91
|
tableName: string;
|
|
@@ -135,9 +124,57 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
|
|
|
135
124
|
generated: undefined;
|
|
136
125
|
}, {}, {}>;
|
|
137
126
|
}>, "where" | "limit">;
|
|
138
|
-
|
|
127
|
+
$getAttributesUpdate(attributes: SQL | EntityMetadataAttributes | undefined): SQL<unknown> | undefined;
|
|
128
|
+
protected mapManyToEntity(columns: this['_anyInferSelect'][], transformContext: TransformContext): Promise<T[]>;
|
|
129
|
+
protected mapToEntity(columns: this['_anyInferSelect'], transformContext: TransformContext): Promise<T>;
|
|
130
|
+
protected mapManyToColumns(objects: (DeepPartial<T> | NewEntity<T>)[], transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType>[]>;
|
|
131
|
+
protected mapToColumns(obj: DeepPartial<T> | NewEntity<T>, transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType>>;
|
|
132
|
+
protected mapManyToInsertColumns(objects: (DeepPartial<T> | NewEntity<T>)[], transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType>[]>;
|
|
133
|
+
protected mapToInsertColumns(obj: DeepPartial<T> | NewEntity<T>, transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType>>;
|
|
134
|
+
protected mapUpdate(update: EntityUpdate<T>, transformContext: TransformContext): Promise<PgUpdateSetSource<PgTableFromType>>;
|
|
135
|
+
protected getMetadataUpdate(update?: EntityUpdate<T>): PgUpdateSetSource<PgTableFromType<EntityType<Entity>>> | undefined;
|
|
136
|
+
protected getIdLimitSelect(query: Query<T>): Omit<import("drizzle-orm/pg-core").PgSelectBase<string, {
|
|
137
|
+
id: PgColumn<{
|
|
138
|
+
name: string;
|
|
139
|
+
tableName: string;
|
|
140
|
+
dataType: "string";
|
|
141
|
+
columnType: "PgUUID";
|
|
142
|
+
data: string;
|
|
143
|
+
driverParam: string;
|
|
144
|
+
notNull: true;
|
|
145
|
+
hasDefault: true;
|
|
146
|
+
isPrimaryKey: true;
|
|
147
|
+
isAutoincrement: false;
|
|
148
|
+
hasRuntimeDefault: false;
|
|
149
|
+
enumValues: undefined;
|
|
150
|
+
baseColumn: never;
|
|
151
|
+
identity: undefined;
|
|
152
|
+
generated: undefined;
|
|
153
|
+
}, {}, {}>;
|
|
154
|
+
}, "partial", globalThis.Record<string, "not-null">, false, "where" | "limit", {
|
|
155
|
+
id: string;
|
|
156
|
+
}[], {
|
|
157
|
+
id: PgColumn<{
|
|
158
|
+
name: string;
|
|
159
|
+
tableName: string;
|
|
160
|
+
dataType: "string";
|
|
161
|
+
columnType: "PgUUID";
|
|
162
|
+
data: string;
|
|
163
|
+
driverParam: string;
|
|
164
|
+
notNull: true;
|
|
165
|
+
hasDefault: true;
|
|
166
|
+
isPrimaryKey: true;
|
|
167
|
+
isAutoincrement: false;
|
|
168
|
+
hasRuntimeDefault: false;
|
|
169
|
+
enumValues: undefined;
|
|
170
|
+
baseColumn: never;
|
|
171
|
+
identity: undefined;
|
|
172
|
+
generated: undefined;
|
|
173
|
+
}, {}, {}>;
|
|
174
|
+
}>, "where" | "limit">;
|
|
175
|
+
protected getAttributesUpdate(attributes: SQL | EntityMetadataAttributes | undefined): SQL<unknown> | undefined;
|
|
139
176
|
protected getTransformContext(): Promise<TransformContext>;
|
|
140
177
|
}
|
|
141
|
-
export declare function injectRepository<T extends Entity>(type: EntityType<T>): EntityRepository<T>;
|
|
142
|
-
export declare function getRepository<T extends Entity>(type: EntityType<T>): Type<EntityRepository<T>>;
|
|
178
|
+
export declare function injectRepository<T extends Entity | EntityWithoutMetadata>(type: EntityType<T>): EntityRepository<T>;
|
|
179
|
+
export declare function getRepository<T extends Entity | EntityWithoutMetadata>(type: EntityType<T>): Type<EntityRepository<T>>;
|
|
143
180
|
export {};
|