@tstdl/base 0.92.78 → 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/ai/ai.service.js CHANGED
@@ -339,27 +339,29 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
339
339
  convertGoogleContent(content) {
340
340
  return {
341
341
  role: content.role,
342
- parts: content.parts
343
- .map((part) => {
344
- if (isDefined(part.text)) {
345
- if (part.text.length == 0) {
346
- return null;
342
+ parts: isUndefined(content.parts)
343
+ ? []
344
+ : content.parts
345
+ .map((part) => {
346
+ if (isDefined(part.text)) {
347
+ if (part.text.length == 0) {
348
+ return null;
349
+ }
350
+ return { text: part.text };
347
351
  }
348
- return { text: part.text };
349
- }
350
- if (isDefined(part.fileData)) {
351
- const file = assertDefinedPass(this.#fileService.getFileByUri(part.fileData.fileUri), 'File not found.');
352
- return { file: file.id };
353
- }
354
- if (isDefined(part.functionResponse)) {
355
- return { functionResult: { name: part.functionResponse.name, value: part.functionResponse.response } };
356
- }
357
- if (isDefined(part.functionCall)) {
358
- return { functionCall: { name: part.functionCall.name, parameters: part.functionCall.args } };
359
- }
360
- throw new NotSupportedError('Unsupported content part.');
361
- })
362
- .filter(isNotNull)
352
+ if (isDefined(part.fileData)) {
353
+ const file = assertDefinedPass(this.#fileService.getFileByUri(part.fileData.fileUri), 'File not found.');
354
+ return { file: file.id };
355
+ }
356
+ if (isDefined(part.functionResponse)) {
357
+ return { functionResult: { name: part.functionResponse.name, value: part.functionResponse.response } };
358
+ }
359
+ if (isDefined(part.functionCall)) {
360
+ return { functionCall: { name: part.functionCall.name, parameters: part.functionCall.args } };
361
+ }
362
+ throw new NotSupportedError('Unsupported content part.');
363
+ })
364
+ .filter(isNotNull)
363
365
  };
364
366
  }
365
367
  getModel(model) {
@@ -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/utils.js';
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.78",
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.24",
148
+ "@typescript-eslint/eslint-plugin": "8.25",
149
149
  "concurrently": "9.1",
150
150
  "drizzle-kit": "0.30",
151
151
  "eslint": "9.21",
@@ -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'