@tstdl/base 0.93.44 → 0.93.46
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.
|
@@ -97,6 +97,9 @@ let DocumentManagementAiService = DocumentManagementAiService_1 = class Document
|
|
|
97
97
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
98
98
|
try {
|
|
99
99
|
const document = await this.#documentRepository.loadByQuery({ tenantId, id: documentId });
|
|
100
|
+
if (isNotNull(document.typeId)) {
|
|
101
|
+
return document.typeId;
|
|
102
|
+
}
|
|
100
103
|
const fileContentStream = this.#documentFileService.getContentStream(document);
|
|
101
104
|
const tmpFile = __addDisposableResource(env_1, await TemporaryFile.from(fileContentStream), true);
|
|
102
105
|
const filePart = await this.#aiService.processFile({ path: tmpFile.path, mimeType: document.mimeType });
|
package/orm/sqls.d.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* simplifying common SQL operations like generating UUIDs, working with intervals,
|
|
5
5
|
* and aggregating data.
|
|
6
6
|
*/
|
|
7
|
-
import type
|
|
8
|
-
import { type AnyColumn, type Column, type SQL, type SQLChunk } from 'drizzle-orm';
|
|
7
|
+
import { Column, type AnyColumn, type SQL, type SQLChunk } from 'drizzle-orm';
|
|
9
8
|
import type { GetSelectTableSelection, SelectResultField, TableLike } from 'drizzle-orm/query-builders/select.types';
|
|
9
|
+
import type { EnumerationObject, EnumerationValue } from '../types/types.js';
|
|
10
10
|
import { type PgEnumFromEnumeration } from './enums.js';
|
|
11
11
|
import type { TsVectorWeight } from './query/index.js';
|
|
12
12
|
import type { Uuid } from './types.js';
|
|
@@ -61,7 +61,38 @@ export type TsHeadlineOptions = {
|
|
|
61
61
|
fragmentDelimiter?: string;
|
|
62
62
|
};
|
|
63
63
|
export declare function enumValue<T extends EnumerationObject>(enumeration: T, dbEnum: PgEnumFromEnumeration<T> | string | null, value: EnumerationValue<T>): SQL<string>;
|
|
64
|
-
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* Generates a SQL condition that ensures exactly one of the specified columns is non-null and allows for custom conditions.
|
|
67
|
+
* @param enumeration The enumeration object
|
|
68
|
+
* @param discriminator The column used to discriminate between different enumeration values
|
|
69
|
+
* @param conditionMapping An object mapping enumeration values to columns and conditions
|
|
70
|
+
*/
|
|
71
|
+
export declare function exclusiveReference<T extends EnumerationObject>(enumeration: T, discriminator: Column, conditionMapping: Record<EnumerationValue<T>, Column | [Column, condition: boolean | SQL]>): SQL;
|
|
72
|
+
export declare function exclusiveNotNull(...columns: Column[]): SQL;
|
|
73
|
+
/**
|
|
74
|
+
* Generates a SQL `CASE ... WHEN ... END` statement for dynamic condition mapping based on an enumeration.
|
|
75
|
+
*
|
|
76
|
+
* This function is particularly useful for scenarios where you need to apply different logical
|
|
77
|
+
* conditions based on the value of a "type" or "status" column (the discriminator). The resulting
|
|
78
|
+
* `CASE` statement returns a boolean value (`TRUE` or `FALSE`).
|
|
79
|
+
*
|
|
80
|
+
* @param enumeration - The enumeration object
|
|
81
|
+
*
|
|
82
|
+
* @param discriminator - The column whose value is being evaluated in the `CASE` statement (e.g., the `status` column).
|
|
83
|
+
*
|
|
84
|
+
* @param conditionMapping - An object that maps
|
|
85
|
+
* each enumeration key to the condition that should be applied when the discriminator matches that key's value.
|
|
86
|
+
* The value can be:
|
|
87
|
+
* - `boolean`: Directly results in `THEN TRUE` or `THEN FALSE`.
|
|
88
|
+
* - `Column`: A reference to another column. The condition applied to it is determined by `defaultColumnCondition`.
|
|
89
|
+
* - `SQL`: A raw SQL chunk for a custom, complex condition.
|
|
90
|
+
*
|
|
91
|
+
* @param defaultColumnCondition - An optional function
|
|
92
|
+
* that defines the default condition to apply when a `Column` is provided in `conditionMapping`.
|
|
93
|
+
* By default, it generates an `IS NOT NULL` check.
|
|
94
|
+
*/
|
|
95
|
+
export declare function enumerationCaseWhen<T extends EnumerationObject>(enumeration: T, discriminator: Column, conditionMapping: Record<EnumerationValue<T>, Column | boolean | SQL>, defaultColumnCondition?: (column: Column) => SQL<unknown>): SQL;
|
|
65
96
|
export declare function array<T>(values: SQL<T>[]): SQL<T[]>;
|
|
66
97
|
export declare function array<T = unknown>(values: SQLChunk[]): SQL<T[]>;
|
|
67
98
|
export declare function autoAlias<T>(column: AnyColumn<{
|
package/orm/sqls.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Provides utility SQL functions and constants for use with Drizzle ORM,
|
|
4
|
+
* simplifying common SQL operations like generating UUIDs, working with intervals,
|
|
5
|
+
* and aggregating data.
|
|
6
|
+
*/
|
|
7
|
+
import { and, Column, eq, sql, isNotNull as sqlIsNotNull, Table } from 'drizzle-orm';
|
|
8
|
+
import { match, P } from 'ts-pattern';
|
|
9
|
+
import { mapObjectValues, objectEntries, objectValues } from '../utils/object/object.js';
|
|
10
|
+
import { assertDefined, isDefined, isInstanceOf, isNull, isNumber, isString } from '../utils/type-guards.js';
|
|
4
11
|
import { getEnumName } from './enums.js';
|
|
5
12
|
/** Drizzle SQL helper for getting the current transaction's timestamp. Returns a Date object. */
|
|
6
13
|
export const TRANSACTION_TIMESTAMP = sql `transaction_timestamp()`;
|
|
@@ -17,18 +24,62 @@ export function enumValue(enumeration, dbEnum, value) {
|
|
|
17
24
|
const enumType = isString(dbEnum) ? sql `"${sql.raw(dbEnum)}"` : dbEnum;
|
|
18
25
|
return sql `'${sql.raw(String(value))}'::${enumType}`;
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* Generates a SQL condition that ensures exactly one of the specified columns is non-null and allows for custom conditions.
|
|
30
|
+
* @param enumeration The enumeration object
|
|
31
|
+
* @param discriminator The column used to discriminate between different enumeration values
|
|
32
|
+
* @param conditionMapping An object mapping enumeration values to columns and conditions
|
|
33
|
+
*/
|
|
34
|
+
export function exclusiveReference(enumeration, discriminator, conditionMapping) {
|
|
35
|
+
const columns = objectValues(conditionMapping).map((value) => isInstanceOf(value, Column) ? value : value[0]);
|
|
36
|
+
const mapping = mapObjectValues(conditionMapping, (value) => {
|
|
37
|
+
if (isInstanceOf(value, Column)) {
|
|
38
|
+
return value;
|
|
25
39
|
}
|
|
40
|
+
return value[1];
|
|
41
|
+
});
|
|
42
|
+
return and(exclusiveNotNull(...columns), enumerationCaseWhen(enumeration, discriminator, mapping));
|
|
43
|
+
}
|
|
44
|
+
export function exclusiveNotNull(...columns) {
|
|
45
|
+
return eq(numNonNulls(...columns), sql.raw('1'));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generates a SQL `CASE ... WHEN ... END` statement for dynamic condition mapping based on an enumeration.
|
|
49
|
+
*
|
|
50
|
+
* This function is particularly useful for scenarios where you need to apply different logical
|
|
51
|
+
* conditions based on the value of a "type" or "status" column (the discriminator). The resulting
|
|
52
|
+
* `CASE` statement returns a boolean value (`TRUE` or `FALSE`).
|
|
53
|
+
*
|
|
54
|
+
* @param enumeration - The enumeration object
|
|
55
|
+
*
|
|
56
|
+
* @param discriminator - The column whose value is being evaluated in the `CASE` statement (e.g., the `status` column).
|
|
57
|
+
*
|
|
58
|
+
* @param conditionMapping - An object that maps
|
|
59
|
+
* each enumeration key to the condition that should be applied when the discriminator matches that key's value.
|
|
60
|
+
* The value can be:
|
|
61
|
+
* - `boolean`: Directly results in `THEN TRUE` or `THEN FALSE`.
|
|
62
|
+
* - `Column`: A reference to another column. The condition applied to it is determined by `defaultColumnCondition`.
|
|
63
|
+
* - `SQL`: A raw SQL chunk for a custom, complex condition.
|
|
64
|
+
*
|
|
65
|
+
* @param defaultColumnCondition - An optional function
|
|
66
|
+
* that defines the default condition to apply when a `Column` is provided in `conditionMapping`.
|
|
67
|
+
* By default, it generates an `IS NOT NULL` check.
|
|
68
|
+
*/
|
|
69
|
+
export function enumerationCaseWhen(enumeration, discriminator, conditionMapping, defaultColumnCondition = (column) => sqlIsNotNull(column)) {
|
|
70
|
+
const whens = [];
|
|
71
|
+
for (const [key, value] of objectEntries(conditionMapping)) {
|
|
72
|
+
const condition = match(value)
|
|
73
|
+
.with(P.boolean, (bool) => bool ? sql `TRUE` : sql `FALSE`)
|
|
74
|
+
.when((value) => isInstanceOf(value, Column), (col) => defaultColumnCondition(col))
|
|
75
|
+
.otherwise((rawSql) => rawSql);
|
|
76
|
+
whens.push(sql ` WHEN ${enumValue(enumeration, null, key)} THEN ${condition}`);
|
|
26
77
|
}
|
|
27
|
-
return
|
|
78
|
+
return sql `
|
|
28
79
|
CASE ${discriminator}
|
|
29
80
|
${sql.join(whens, sql `\n`)}
|
|
30
81
|
ELSE FALSE
|
|
31
|
-
END
|
|
82
|
+
END`;
|
|
32
83
|
}
|
|
33
84
|
export function array(values) {
|
|
34
85
|
const valueString = sql.join(values, sql.raw(', '));
|
package/package.json
CHANGED
package/utils/type-guards.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractConstructor, BinaryData, JsonPrimitive, PascalCase, Primitive, Type, TypedArray } from '../types/index.js';
|
|
1
|
+
import type { AbstractConstructor, AbstractType, BinaryData, JsonPrimitive, PascalCase, Primitive, Type, TypedArray } from '../types/index.js';
|
|
2
2
|
export type AssertionMessage = string | (() => string);
|
|
3
3
|
export type IsFunction<T> = <U extends T = T>(value: any) => value is U;
|
|
4
4
|
export type IsNotFunction<T> = <V>(value: V) => value is Exclude<V, T>;
|
|
@@ -269,9 +269,9 @@ export declare const assertReadableStream: <T = any>(value: any, message?: Asser
|
|
|
269
269
|
export declare const assertNotReadableStream: AssertNotFunction<ReadableStream>;
|
|
270
270
|
export declare const assertReadableStreamPass: <T = any>(value: any, message?: AssertionMessage) => ReadableStream<T>;
|
|
271
271
|
export declare const assertNotReadableStreamPass: AssertNotPassFunction<ReadableStream>;
|
|
272
|
-
export declare const isInstanceOf: <T>(value: any, type:
|
|
273
|
-
export declare const isNotInstanceOf: <V, T>(value: V, type:
|
|
274
|
-
export declare const assertInstanceOf: <T>(value: any, type:
|
|
275
|
-
export declare const assertNotInstanceOf: <V, T>(value: V, type:
|
|
276
|
-
export declare const assertInstanceOfPass: <T>(value: any, type:
|
|
272
|
+
export declare const isInstanceOf: <T>(value: any, type: AbstractType<T>) => value is T;
|
|
273
|
+
export declare const isNotInstanceOf: <V, T>(value: V, type: AbstractType<T>) => value is Exclude<V, T>;
|
|
274
|
+
export declare const assertInstanceOf: <T>(value: any, type: AbstractType<T>, message?: AssertionMessage) => asserts value is T;
|
|
275
|
+
export declare const assertNotInstanceOf: <V, T>(value: V, type: AbstractType<T>, message?: AssertionMessage) => asserts value is Exclude<V, T>;
|
|
276
|
+
export declare const assertInstanceOfPass: <T>(value: any, type: AbstractType<T>, message?: AssertionMessage) => T;
|
|
277
277
|
export declare const assertNotInstanceOfPass: <V, T>(value: V, type: Type<T>, message?: AssertionMessage) => Exclude<V, T>;
|