@tstdl/base 0.93.46 → 0.93.48

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.
@@ -1,10 +1,10 @@
1
1
  import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js';
2
- import type { AiServiceOptions } from './ai.service.js';
2
+ import { AiModuleOptions } from './module.js';
3
3
  import { type FileContentPart, type FileInput } from './types.js';
4
4
  /**
5
5
  * Options for {@link AiFileService}.
6
6
  */
7
- export type AiFileServiceOptions = Pick<AiServiceOptions, 'apiKey' | 'keyFile' | 'vertex'>;
7
+ export type AiFileServiceOptions = Pick<AiModuleOptions, 'apiKey' | 'keyFile' | 'vertex'>;
8
8
  export type AiFileServiceArgument = AiFileServiceOptions;
9
9
  type File = {
10
10
  id: string;
@@ -21,13 +21,14 @@ import { backoffGenerator } from '../utils/backoff.js';
21
21
  import { formatBytes } from '../utils/format.js';
22
22
  import { readBinaryStream } from '../utils/stream/stream-reader.js';
23
23
  import { assertDefinedPass, isBlob, isDefined, isUndefined } from '../utils/type-guards.js';
24
+ import { AiModuleOptions } from './module.js';
24
25
  import { isPathFileInput } from './types.js';
25
26
  /**
26
27
  * Manages file uploads and state for use with AI models.
27
28
  * Handles both Google Generative AI File API and Google Cloud Storage for Vertex AI.
28
29
  */
29
30
  let AiFileService = class AiFileService {
30
- #options = injectArgument(this);
31
+ #options = injectArgument(this, { optional: true }) ?? inject(AiModuleOptions);
31
32
  #genAI = new GoogleGenAI({
32
33
  vertexai: isDefined(this.#options.vertex?.project),
33
34
  project: this.#options.vertex?.project,
@@ -2,6 +2,7 @@ import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js'
2
2
  import { type SchemaTestable } from '../schema/index.js';
3
3
  import type { Enumeration as EnumerationType, EnumerationValue } from '../types/index.js';
4
4
  import { AiSession } from './ai-session.js';
5
+ import { AiModuleOptions } from './module.js';
5
6
  import { type AiModel, type FileContentPart, type FileInput, type GenerationOptions, type GenerationRequest, type GenerationResult, type SchemaFunctionDeclarations, type SchemaFunctionDeclarationsResult } from './types.js';
6
7
  /**
7
8
  * A generation result that includes a specialized, typed result alongside the raw generation data.
@@ -20,27 +21,7 @@ export type SpecializedGenerationResult<T> = {
20
21
  export type SpecializedGenerationResultGenerator<T> = AsyncGenerator<T> & {
21
22
  raw: Promise<GenerationResult>;
22
23
  };
23
- /**
24
- * Options for configuring the {@link AiService}.
25
- */
26
- export declare class AiServiceOptions {
27
- /** Google AI API key. */
28
- apiKey?: string;
29
- /** Path to the Google Cloud credentials file. */
30
- keyFile?: string;
31
- /** Vertex AI specific options. If provided, the service will use Vertex AI endpoints. */
32
- vertex?: {
33
- project: string;
34
- location: string;
35
- bucket?: string;
36
- };
37
- /**
38
- * The default model to use for generation requests.
39
- * @default 'small'
40
- */
41
- defaultModel?: AiModel;
42
- }
43
- export type AiServiceArgument = AiServiceOptions;
24
+ export type AiServiceArgument = AiModuleOptions;
44
25
  export type ClassificationResult<T extends EnumerationType> = {
45
26
  types: {
46
27
  type: EnumerationValue<T>;
package/ai/ai.service.js CHANGED
@@ -27,24 +27,8 @@ import { assertDefinedPass, isDefined, isError, isNotNull, isNull, isUndefined }
27
27
  import { resolveValueOrAsyncProvider } from '../utils/value-or-provider.js';
28
28
  import { AiFileService } from './ai-file.service.js';
29
29
  import { AiSession } from './ai-session.js';
30
+ import { AiModuleOptions } from './module.js';
30
31
  import { isSchemaFunctionDeclarationWithHandler } from './types.js';
31
- /**
32
- * Options for configuring the {@link AiService}.
33
- */
34
- export class AiServiceOptions {
35
- /** Google AI API key. */
36
- apiKey;
37
- /** Path to the Google Cloud credentials file. */
38
- keyFile;
39
- /** Vertex AI specific options. If provided, the service will use Vertex AI endpoints. */
40
- vertex;
41
- /**
42
- * The default model to use for generation requests.
43
- * @default 'small'
44
- */
45
- defaultModel;
46
- }
47
- ;
48
32
  const functionCallingModeMap = {
49
33
  auto: GoogleFunctionCallingMode.AUTO,
50
34
  force: GoogleFunctionCallingMode.ANY,
@@ -58,7 +42,7 @@ let generationCounter = 0;
58
42
  * supporting both standard Google AI and Vertex AI endpoints.
59
43
  */
60
44
  let AiService = AiService_1 = class AiService {
61
- #options = injectArgument(this, { optional: true }) ?? inject(AiServiceOptions);
45
+ #options = injectArgument(this, { optional: true }) ?? inject(AiModuleOptions);
62
46
  #fileService = inject(AiFileService, this.#options);
63
47
  #logger = inject(Logger, AiService_1.name);
64
48
  #cancellationSignal = inject(CancellationSignal);
@@ -81,7 +65,7 @@ let AiService = AiService_1 = class AiService {
81
65
  /**
82
66
  * The default AI model to use for requests if not specified otherwise.
83
67
  */
84
- defaultModel = this.#options.defaultModel ?? 'gemini-flash-lite-latest';
68
+ defaultModel = this.#options.defaultModel ?? 'gemini-2.5-flash-lite';
85
69
  /**
86
70
  * Creates a new {@link AiSession} for managing conversational history.
87
71
  */
@@ -437,8 +421,8 @@ let AiService = AiService_1 = class AiService {
437
421
  }
438
422
  mapModel(model) {
439
423
  return match(model)
440
- .with('small', () => 'gemini-flash-lite-latest')
441
- .with('medium', () => 'gemini-flash-latest')
424
+ .with('small', () => 'gemini-2.5-flash-lite')
425
+ .with('medium', () => 'gemini-2.5-flash')
442
426
  .with('large', () => 'gemini-2.5-pro')
443
427
  .otherwise(() => model ?? this.defaultModel);
444
428
  }
package/ai/module.d.ts CHANGED
@@ -1,11 +1,26 @@
1
- import { AiServiceOptions } from './ai.service.js';
1
+ import type { AiModel } from './types.js';
2
2
  /**
3
- * Options for configuring the AI module.
4
- * @see {@link AiServiceOptions}
3
+ * Options for configuring the AI Module.
5
4
  */
6
- export type ApiModuleOptions = AiServiceOptions;
5
+ export declare class AiModuleOptions {
6
+ /** Google AI API key. */
7
+ apiKey?: string;
8
+ /** Path to the Google Cloud credentials file. */
9
+ keyFile?: string;
10
+ /** Vertex AI specific options. If provided, the service will use Vertex AI endpoints. */
11
+ vertex?: {
12
+ project: string;
13
+ location: string;
14
+ bucket?: string;
15
+ };
16
+ /**
17
+ * The default model to use for generation requests.
18
+ * @default 'small'
19
+ */
20
+ defaultModel?: AiModel;
21
+ }
7
22
  /**
8
23
  * Configures the {@link AiService}.
9
24
  * @param options The configuration options for the AI services.
10
25
  */
11
- export declare function configureAiService(options: ApiModuleOptions): void;
26
+ export declare function configureAiService(options: AiModuleOptions): void;
package/ai/module.js CHANGED
@@ -1,9 +1,25 @@
1
1
  import { Injector } from '../injector/injector.js';
2
- import { AiServiceOptions } from './ai.service.js';
2
+ /**
3
+ * Options for configuring the AI Module.
4
+ */
5
+ export class AiModuleOptions {
6
+ /** Google AI API key. */
7
+ apiKey;
8
+ /** Path to the Google Cloud credentials file. */
9
+ keyFile;
10
+ /** Vertex AI specific options. If provided, the service will use Vertex AI endpoints. */
11
+ vertex;
12
+ /**
13
+ * The default model to use for generation requests.
14
+ * @default 'small'
15
+ */
16
+ defaultModel;
17
+ }
18
+ ;
3
19
  /**
4
20
  * Configures the {@link AiService}.
5
21
  * @param options The configuration options for the AI services.
6
22
  */
7
23
  export function configureAiService(options) {
8
- Injector.register(AiServiceOptions, { useValue: options });
24
+ Injector.register(AiModuleOptions, { useValue: options });
9
25
  }
package/orm/sqls.d.ts CHANGED
@@ -62,13 +62,12 @@ export type TsHeadlineOptions = {
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.
65
+ * Generates a SQL condition that ensures exactly one of the specified columns is non-null and optional custom conditions.
67
66
  * @param enumeration The enumeration object
68
67
  * @param discriminator The column used to discriminate between different enumeration values
69
68
  * @param conditionMapping An object mapping enumeration values to columns and conditions
70
69
  */
71
- export declare function exclusiveReference<T extends EnumerationObject>(enumeration: T, discriminator: Column, conditionMapping: Record<EnumerationValue<T>, Column | [Column, condition: boolean | SQL]>): SQL;
70
+ export declare function exclusiveReference<T extends EnumerationObject>(enumeration: T, discriminator: Column, conditionMapping: Record<EnumerationValue<T>, Column | [Column, condition: boolean | SQL] | null>): SQL;
72
71
  export declare function exclusiveNotNull(...columns: Column[]): SQL;
73
72
  /**
74
73
  * Generates a SQL `CASE ... WHEN ... END` statement for dynamic condition mapping based on an enumeration.
package/orm/sqls.js CHANGED
@@ -7,7 +7,7 @@
7
7
  import { and, Column, eq, sql, isNotNull as sqlIsNotNull, Table } from 'drizzle-orm';
8
8
  import { match, P } from 'ts-pattern';
9
9
  import { mapObjectValues, objectEntries, objectValues } from '../utils/object/object.js';
10
- import { assertDefined, isDefined, isInstanceOf, isNull, isNumber, isString } from '../utils/type-guards.js';
10
+ import { assertDefined, isDefined, isInstanceOf, isNotNull, isNull, isNumber, isString } from '../utils/type-guards.js';
11
11
  import { getEnumName } from './enums.js';
12
12
  /** Drizzle SQL helper for getting the current transaction's timestamp. Returns a Date object. */
13
13
  export const TRANSACTION_TIMESTAMP = sql `transaction_timestamp()`;
@@ -25,18 +25,20 @@ export function enumValue(enumeration, dbEnum, value) {
25
25
  return sql `'${sql.raw(String(value))}'::${enumType}`;
26
26
  }
27
27
  /**
28
- *
29
- * Generates a SQL condition that ensures exactly one of the specified columns is non-null and allows for custom conditions.
28
+ * Generates a SQL condition that ensures exactly one of the specified columns is non-null and optional custom conditions.
30
29
  * @param enumeration The enumeration object
31
30
  * @param discriminator The column used to discriminate between different enumeration values
32
31
  * @param conditionMapping An object mapping enumeration values to columns and conditions
33
32
  */
34
33
  export function exclusiveReference(enumeration, discriminator, conditionMapping) {
35
- const columns = objectValues(conditionMapping).map((value) => isInstanceOf(value, Column) ? value : value[0]);
34
+ const columns = objectValues(conditionMapping).filter(isNotNull).map((value) => isInstanceOf(value, Column) ? value : value[0]);
36
35
  const mapping = mapObjectValues(conditionMapping, (value) => {
37
36
  if (isInstanceOf(value, Column)) {
38
37
  return value;
39
38
  }
39
+ if (isNull(value)) {
40
+ return sql `FALSE`;
41
+ }
40
42
  return value[1];
41
43
  });
42
44
  return and(exclusiveNotNull(...columns), enumerationCaseWhen(enumeration, discriminator, mapping));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.46",
3
+ "version": "0.93.48",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"