@tstdl/base 0.92.48 → 0.92.50

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
+ }
@@ -12,7 +12,7 @@ import { type Transaction, type TransactionConfig } from './transaction.js';
12
12
  type PgTransaction = DrizzlePgTransaction<PgQueryResultHKT, Record, Record>;
13
13
  export declare const repositoryType: unique symbol;
14
14
  export type OrderOptions<T extends Entity> = {
15
- order?: Partial<Record<Paths<T>, 1 | -1 | 'asc' | 'desc'>>;
15
+ order?: Partial<Record<Paths<UntaggedDeep<T>>, 1 | -1 | 'asc' | 'desc'>>;
16
16
  };
17
17
  export type LoadOptions<T extends Entity> = OrderOptions<T> & {
18
18
  offset?: number;
@@ -63,8 +63,8 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
63
63
  hasAll(ids: string[]): Promise<boolean>;
64
64
  insert(entity: NewEntity<T>): Promise<T>;
65
65
  insertMany(entities: NewEntity<T>[]): Promise<T[]>;
66
- upsert(target: OneOrMany<Extract<keyof T, string>>, entity: NewEntity<T>, update?: EntityUpdate<T>): Promise<T>;
67
- upsertMany(target: OneOrMany<Extract<keyof T, string>>, entities: NewEntity<T>[], update: EntityUpdate<T>): Promise<T[]>;
66
+ upsert(target: OneOrMany<Paths<UntaggedDeep<T>>>, entity: NewEntity<T>, update?: EntityUpdate<T>): Promise<T>;
67
+ upsertMany(target: OneOrMany<Paths<UntaggedDeep<T>>>, entities: NewEntity<T>[], update: EntityUpdate<T>): Promise<T[]>;
68
68
  update(id: string, update: EntityUpdate<T>): Promise<T>;
69
69
  tryUpdate(id: string, update: EntityUpdate<T>): Promise<T | undefined>;
70
70
  updateByQuery(query: Query<T>, update: EntityUpdate<T>): Promise<T>;
@@ -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.50",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/types/tagged.d.ts CHANGED
@@ -11,6 +11,6 @@ export type Tagged<Type = unknown, TagName extends PropertyKey = PropertyKey, Ta
11
11
  export type GetTagMetadata<Type extends Tag<unknown, TagName, unknown>, TagName extends PropertyKey> = NonNullable<Type[typeof tag]>[TagName];
12
12
  export type UnwrapTagged<TaggedType extends Tag<unknown, PropertyKey, any>> = TaggedType extends Tagged<infer Type, PropertyKey, any> ? Type : never;
13
13
  export type Untagged<T> = T extends Tagged ? UnwrapTagged<T> : T;
14
- export type UntaggedDeep<T> = T extends Tagged ? UnwrapTagged<T> : T extends readonly (infer U)[] ? UntaggedDeep<U>[] : T extends Record ? {
15
- [P in keyof T]: UntaggedDeep<T[P]>;
14
+ export type UntaggedDeep<T> = Untagged<T> extends any[] | Record ? {
15
+ [P in keyof Untagged<T>]: UntaggedDeep<Untagged<T>[P]>;
16
16
  } : Untagged<T>;
package/types.d.ts CHANGED
@@ -190,7 +190,7 @@ export type DeepPartialArray<T> = DeepPartial<T>[];
190
190
  export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
191
191
  export type BinaryData = ArrayBuffer | ArrayBufferView;
192
192
  export type Paths<T extends Record> = T extends object ? {
193
- [K in keyof T]-?: K extends string | number ? K | `${K}.${Paths<T[K]>}` : never;
193
+ [K in keyof T]-?: K extends string | number ? `${K}` | `${K}.${Paths<T[K]>}` : never;
194
194
  }[keyof T] : never;
195
195
  export type TypeFromPath<T extends Record, Path extends Paths<T> | string> = {
196
196
  [K in Path]: K extends keyof T ? T[K] : K extends `${infer P}.${infer S}` ? T[P] extends Record ? TypeFromPath<T[P], S> : never : never;