@tstdl/base 0.92.48 → 0.92.49

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.
@@ -10,7 +10,7 @@ import { BadRequestError } from '../../../errors/index.js';
10
10
  import { getMimeType, getMimeTypeExtensions } from '../../../file/index.js';
11
11
  import { Singleton, inject, injectArgument, provide, resolveArgumentType } from '../../../injector/index.js';
12
12
  import { ObjectStorage } from '../../../object-storage/index.js';
13
- import { DATABASE_CONFIG, EntityRepositoryConfig, injectRepository } from '../../../orm/server/index.js';
13
+ import { DatabaseConfig, EntityRepositoryConfig, injectRepository } from '../../../orm/server/index.js';
14
14
  import { toArray } from '../../../utils/array/index.js';
15
15
  import { assertDefinedPass, compareByValueSelectionToOrder, currentTimestamp, digest, isBoolean, isDefined, isNotNull, isNull, isNumber, isString, isUint8Array, millisecondsPerMinute } from '../../../utils/index.js';
16
16
  import { groupToMap } from '../../../utils/iterable-helpers/index.js';
@@ -354,7 +354,7 @@ DocumentManagementService = __decorate([
354
354
  Singleton({
355
355
  providers: [
356
356
  provide(EntityRepositoryConfig, { useValue: { schema: 'document_management' } }),
357
- { provide: DATABASE_CONFIG, useFactory: (_, context) => context.resolve(DocumentManagementConfig).database }
357
+ { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(DocumentManagementConfig).database }
358
358
  ]
359
359
  })
360
360
  ], DocumentManagementService);
@@ -1,6 +1,7 @@
1
1
  import { NodePgDatabase } from 'drizzle-orm/node-postgres';
2
+ import type { PoolConfig } from 'pg';
2
3
  import type { Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
3
- import type { DatabaseArgument } from './module.js';
4
+ export type DatabaseArgument = string | PoolConfig;
4
5
  export declare class Database extends NodePgDatabase<any> implements Resolvable<DatabaseArgument> {
5
6
  readonly [resolveArgumentType]?: DatabaseArgument;
6
7
  }
@@ -4,11 +4,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { NodePgDatabase } from 'drizzle-orm/node-postgres';
8
- import { ReplaceClass } from '../../injector/decorators.js';
7
+ import { drizzle, NodePgDatabase } from 'drizzle-orm/node-postgres';
8
+ import { inject, Injector, ReplaceClass } from '../../injector/index.js';
9
+ import { isUndefined } from '../../utils/type-guards.js';
10
+ import { DatabaseConfig } from './module.js';
9
11
  let Database = class Database extends NodePgDatabase {
10
12
  };
11
13
  Database = __decorate([
12
14
  ReplaceClass(NodePgDatabase)
13
15
  ], Database);
14
16
  export { Database };
17
+ Injector.registerSingleton(Database, {
18
+ useFactory: (argument) => {
19
+ const connection = argument ?? inject(DatabaseConfig, undefined, { optional: true })?.connection;
20
+ if (isUndefined(connection)) {
21
+ throw new Error('Missing postgres connection. Provide it either via injection argument or provider.');
22
+ }
23
+ return drizzle({ connection });
24
+ }
25
+ });
@@ -1,6 +1,10 @@
1
1
  import type { PoolConfig } from 'pg';
2
- export type DatabaseConfig = {
3
- connection: DatabaseArgument;
2
+ import { EntityRepositoryConfig } from './repository.js';
3
+ export declare class DatabaseConfig {
4
+ connection?: string | PoolConfig;
5
+ }
6
+ export type OrmModuleOptions = {
7
+ connection?: string | PoolConfig;
8
+ repositoryConfig?: EntityRepositoryConfig;
4
9
  };
5
- export type DatabaseArgument = string | PoolConfig;
6
- export declare const DATABASE_CONFIG: import("../../injector/index.js").InjectionToken<DatabaseConfig, never>;
10
+ export declare function configureOrm(options: OrmModuleOptions): void;
@@ -1,15 +1,14 @@
1
- import { drizzle } from 'drizzle-orm/node-postgres';
2
- import { inject, injectionToken } from '../../injector/index.js';
3
1
  import { Injector } from '../../injector/injector.js';
4
- import { isUndefined } from '../../utils/type-guards.js';
5
- import { Database } from './database.js';
6
- export const DATABASE_CONFIG = injectionToken('EntityRepositoryConfig');
7
- Injector.registerSingleton(Database, {
8
- useFactory: (argument) => {
9
- const connection = argument ?? inject(DATABASE_CONFIG, undefined, { optional: true })?.connection;
10
- if (isUndefined(connection)) {
11
- throw new Error('Missing postgres connection. Provide it either via injection argument or provider.');
12
- }
13
- return drizzle({ connection });
2
+ import { isDefined } from '../../utils/type-guards.js';
3
+ import { EntityRepositoryConfig } from './repository.js';
4
+ export class DatabaseConfig {
5
+ connection;
6
+ }
7
+ export function configureOrm(options) {
8
+ if (isDefined(options.connection)) {
9
+ Injector.register(DatabaseConfig, { useValue: { connection: options.connection } });
14
10
  }
15
- });
11
+ if (isDefined(options.repositoryConfig)) {
12
+ Injector.register(EntityRepositoryConfig, { useValue: options.repositoryConfig });
13
+ }
14
+ }
@@ -390,7 +390,7 @@ let EntityRepository = class EntityRepository {
390
390
  ...mappedUpdate,
391
391
  attributes: this.getAttributesUpdate(update.metadata?.attributes),
392
392
  revision: sql `${this.table.revision} + 1`,
393
- revisionTimestamp: sql `transaction_timestamp()`
393
+ revisionTimestamp: TRANSACTION_TIMESTAMP
394
394
  };
395
395
  }
396
396
  getIdLimitQuery(query) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.48",
3
+ "version": "0.92.49",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"