@tstdl/base 0.92.52 → 0.92.53

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.
@@ -96,24 +96,26 @@ let AuthenticationService = class AuthenticationService {
96
96
  const actualSubject = await this.resolveSubject(subject);
97
97
  const now = currentTimestamp();
98
98
  const end = now + this.refreshTokenTimeToLive;
99
- const session = await this.sessionRepository.insert({
100
- subject: actualSubject,
101
- begin: now,
102
- end,
103
- refreshTokenHashVersion: 0,
104
- refreshTokenSalt: new Uint8Array(),
105
- refreshTokenHash: new Uint8Array()
106
- });
107
- const tokenPayload = await this.authenticationAncillaryService?.getTokenPayload(actualSubject, authenticationData, { action: GetTokenPayloadContextAction.GetToken });
108
- const { token, jsonToken } = await this.createToken({ additionalTokenPayload: tokenPayload, subject: actualSubject, impersonator, sessionId: session.id, refreshTokenExpiration: end, timestamp: now });
109
- const refreshToken = await this.createRefreshToken(actualSubject, session.id, end, { impersonator });
110
- await this.sessionRepository.update(session.id, {
111
- end,
112
- refreshTokenHashVersion: 1,
113
- refreshTokenSalt: refreshToken.salt,
114
- refreshTokenHash: refreshToken.hash
99
+ return this.sessionRepository.transaction(async (sessionRepository) => {
100
+ const session = await sessionRepository.insert({
101
+ subject: actualSubject,
102
+ begin: now,
103
+ end,
104
+ refreshTokenHashVersion: 0,
105
+ refreshTokenSalt: new Uint8Array(),
106
+ refreshTokenHash: new Uint8Array()
107
+ });
108
+ const tokenPayload = await this.authenticationAncillaryService?.getTokenPayload(actualSubject, authenticationData, { action: GetTokenPayloadContextAction.GetToken });
109
+ const { token, jsonToken } = await this.createToken({ additionalTokenPayload: tokenPayload, subject: actualSubject, impersonator, sessionId: session.id, refreshTokenExpiration: end, timestamp: now });
110
+ const refreshToken = await this.createRefreshToken(actualSubject, session.id, end, { impersonator });
111
+ await sessionRepository.update(session.id, {
112
+ end,
113
+ refreshTokenHashVersion: 1,
114
+ refreshTokenSalt: refreshToken.salt,
115
+ refreshTokenHash: refreshToken.hash
116
+ });
117
+ return { token, jsonToken, refreshToken: refreshToken.token };
115
118
  });
116
- return { token, jsonToken, refreshToken: refreshToken.token };
117
119
  }
118
120
  async endSession(sessionId) {
119
121
  const now = currentTimestamp();
@@ -30,6 +30,7 @@ export declare class EntityRepositoryConfig {
30
30
  schema: string;
31
31
  }
32
32
  export type TransactionHandler<T extends Entity, R> = (repository: EntityRepository<T>, transaction: Transaction) => Promise<R>;
33
+ export declare const ENTITY_TYPE: import("../../injector/token.js").InjectionToken<EntityType<any>, never>;
33
34
  export declare class EntityRepository<T extends Entity = Entity> implements Resolvable<EntityType<T>> {
34
35
  #private;
35
36
  readonly type: EntityType<T>;
@@ -109,5 +110,5 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
109
110
  protected getAttributesUpdate(attributes: EntityMetadataAttributes | undefined): SQL<unknown> | undefined;
110
111
  }
111
112
  export declare function injectRepository<T extends Entity>(type: EntityType<T>): EntityRepository<T>;
112
- export declare function getRepository<T extends Entity>(type: EntityType<T>, config: EntityRepositoryConfig): Type<EntityRepository<T>>;
113
+ export declare function getRepository<T extends Entity>(type: EntityType<T>, config?: EntityRepositoryConfig): Type<EntityRepository<T>>;
113
114
  export {};
@@ -14,6 +14,7 @@ import { NotFoundError } from '../../errors/not-found.error.js';
14
14
  import { Singleton } from '../../injector/decorators.js';
15
15
  import { inject, injectArgument } from '../../injector/inject.js';
16
16
  import { resolveArgumentType } from '../../injector/interfaces.js';
17
+ import { injectionToken } from '../../injector/token.js';
17
18
  import { Schema } from '../../schema/schema.js';
18
19
  import { toArray } from '../../utils/array/array.js';
19
20
  import { fromDeepObjectEntries } from '../../utils/object/object.js';
@@ -26,6 +27,7 @@ export const repositoryType = Symbol('repositoryType');
26
27
  export class EntityRepositoryConfig {
27
28
  schema;
28
29
  }
30
+ export const ENTITY_TYPE = injectionToken('EntityType');
29
31
  const TRANSACTION_TIMESTAMP = sql `transaction_timestamp()`;
30
32
  let EntityRepository = class EntityRepository {
31
33
  #repositoryConstructor;
@@ -41,7 +43,7 @@ let EntityRepository = class EntityRepository {
41
43
  }
42
44
  constructor(type, table, columnDefinitions, columnDefinitionsMap, session) {
43
45
  this.#repositoryConstructor = new.target;
44
- this.type = type ?? injectArgument(this);
46
+ this.type = type ?? injectArgument(this, { optional: true }) ?? inject(ENTITY_TYPE);
45
47
  this.table = table ?? getDrizzleTableFromType(this.type, inject(EntityRepositoryConfig).schema);
46
48
  this.columnDefinitions = columnDefinitions ?? getColumnDefinitions(this.table);
47
49
  this.columnDefinitionsMap = columnDefinitionsMap ?? new Map(this.columnDefinitions.map((column) => [column.objectPath.path, column]));
@@ -425,7 +427,7 @@ export function getRepository(type, config) {
425
427
  [className]: class extends EntityRepository {
426
428
  }
427
429
  }[className];
428
- const injectorDecorator = Singleton({ providers: [{ provide: EntityRepositoryConfig, useValue: config }] });
430
+ const injectorDecorator = Singleton({ providers: [{ provide: ENTITY_TYPE, useValue: type }, { provide: EntityRepositoryConfig, useValue: config }] });
429
431
  injectorDecorator(entityRepositoryClass);
430
432
  return entityRepositoryClass;
431
433
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.52",
3
+ "version": "0.92.53",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"