@tstdl/base 0.92.52 → 0.92.54
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/authentication/server/authentication.service.js +19 -17
- package/document-management/models/document-property.model.d.ts +8 -6
- package/document-management/models/document-property.model.js +8 -8
- package/document-management/models/schemas.d.ts +1 -1
- package/document-management/server/services/document-management.service.js +1 -1
- package/orm/server/database-schema.d.ts +2 -2
- package/orm/server/database-schema.js +2 -1
- package/orm/server/repository.d.ts +2 -2
- package/orm/server/repository.js +4 -5
- package/package.json +1 -1
|
@@ -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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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();
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { type EnumType } from '../../enumeration/enumeration.js';
|
|
1
2
|
import { Entity } from '../../orm/entity.js';
|
|
2
|
-
export declare
|
|
3
|
-
Text
|
|
4
|
-
Integer
|
|
5
|
-
Decimal
|
|
6
|
-
Boolean
|
|
7
|
-
}
|
|
3
|
+
export declare const DocumentPropertyDataType: {
|
|
4
|
+
readonly Text: "text";
|
|
5
|
+
readonly Integer: "integer";
|
|
6
|
+
readonly Decimal: "decimal";
|
|
7
|
+
readonly Boolean: "boolean";
|
|
8
|
+
};
|
|
9
|
+
export type DocumentPropertyDataType = EnumType<typeof DocumentPropertyDataType>;
|
|
8
10
|
export declare class DocumentProperty extends Entity {
|
|
9
11
|
label: string;
|
|
10
12
|
dataType: DocumentPropertyDataType;
|
|
@@ -7,15 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
+
import { defineEnum } from '../../enumeration/enumeration.js';
|
|
10
11
|
import { Entity } from '../../orm/entity.js';
|
|
11
12
|
import { Enumeration, StringProperty } from '../../schema/index.js';
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})(DocumentPropertyDataType || (DocumentPropertyDataType = {}));
|
|
13
|
+
export const DocumentPropertyDataType = defineEnum('DocumentPropertyDataType', {
|
|
14
|
+
Text: 'text',
|
|
15
|
+
Integer: 'integer',
|
|
16
|
+
Decimal: 'decimal',
|
|
17
|
+
Boolean: 'boolean'
|
|
18
|
+
});
|
|
19
19
|
export class DocumentProperty extends Entity {
|
|
20
20
|
label;
|
|
21
21
|
dataType;
|
|
@@ -26,5 +26,5 @@ __decorate([
|
|
|
26
26
|
], DocumentProperty.prototype, "label", void 0);
|
|
27
27
|
__decorate([
|
|
28
28
|
Enumeration(DocumentPropertyDataType),
|
|
29
|
-
__metadata("design:type",
|
|
29
|
+
__metadata("design:type", String)
|
|
30
30
|
], DocumentProperty.prototype, "dataType", void 0);
|
|
@@ -13,7 +13,7 @@ import { DocumentTypeProperty } from './document-type-property.model.js';
|
|
|
13
13
|
import { DocumentType } from './document-type.model.js';
|
|
14
14
|
import { Document } from './document.model.js';
|
|
15
15
|
export declare const documentManagementSchema: import("../../orm/server/database-schema.js").DatabaseSchema<"document_management">;
|
|
16
|
-
export declare const dataType: import("drizzle-orm/pg-core").PgEnum<["
|
|
16
|
+
export declare const dataType: import("drizzle-orm/pg-core").PgEnum<["boolean", "decimal", "text", "integer"]>;
|
|
17
17
|
export declare const documentCategory: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCategory>;
|
|
18
18
|
export declare const documentCollectionDocument: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCollectionDocument>;
|
|
19
19
|
export declare const documentCollection: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCollection>;
|
|
@@ -371,6 +371,6 @@ const validators = {
|
|
|
371
371
|
function validatePropertyValue(propertyId, dataType, value) {
|
|
372
372
|
const valid = validators[dataType](value);
|
|
373
373
|
if (!valid) {
|
|
374
|
-
throw new BadRequestError(`Invalid value for data type ${
|
|
374
|
+
throw new BadRequestError(`Invalid value for data type ${dataType} for property ${propertyId}.`);
|
|
375
375
|
}
|
|
376
376
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { PgEnum } from 'drizzle-orm/pg-core';
|
|
2
2
|
import type { Enumeration, EnumerationValue, UnionToTuple } from '../../types.js';
|
|
3
|
-
import { type PgTableFromType } from './drizzle/schema-converter.js';
|
|
4
3
|
import type { EntityType } from '../entity.js';
|
|
4
|
+
import { type PgTableFromType } from './drizzle/schema-converter.js';
|
|
5
5
|
export declare class DatabaseSchema<Name extends string> {
|
|
6
6
|
readonly name: Name;
|
|
7
7
|
constructor(name: Name);
|
|
8
8
|
getTable<T extends EntityType>(type: T): PgTableFromType<Name, T>;
|
|
9
|
-
getEnum<T extends Enumeration>(enumeration: T, name
|
|
9
|
+
getEnum<T extends Enumeration>(enumeration: T, name?: string): PgEnum<UnionToTuple<`${EnumerationValue<T>}`> extends [string, ...string[]] ? UnionToTuple<`${EnumerationValue<T>}`> : never>;
|
|
10
10
|
}
|
|
11
11
|
export declare function databaseSchema<Name extends string>(name: Name): DatabaseSchema<Name>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getEnumName } from '../../enumeration/enumeration.js';
|
|
1
2
|
import { getDrizzleTableFromType, getPgEnum, registerEnum } from './drizzle/schema-converter.js';
|
|
2
3
|
export class DatabaseSchema {
|
|
3
4
|
name;
|
|
@@ -7,7 +8,7 @@ export class DatabaseSchema {
|
|
|
7
8
|
getTable(type) {
|
|
8
9
|
return getDrizzleTableFromType(type, this.name);
|
|
9
10
|
}
|
|
10
|
-
getEnum(enumeration, name) {
|
|
11
|
+
getEnum(enumeration, name = getEnumName(enumeration)) {
|
|
11
12
|
registerEnum(enumeration, name);
|
|
12
13
|
return getPgEnum(this.name, enumeration); // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
13
14
|
}
|
|
@@ -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>;
|
|
@@ -38,7 +39,6 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
|
|
|
38
39
|
readonly columnDefinitionsMap: Map<string, ColumnDefinition>;
|
|
39
40
|
readonly session: Database | PgTransaction;
|
|
40
41
|
readonly isInTransaction: boolean;
|
|
41
|
-
get tx(): PgTransaction;
|
|
42
42
|
readonly [resolveArgumentType]: EntityType<T>;
|
|
43
43
|
constructor(type?: EntityType<T>, table?: PgTableFromType<string, EntityType>, columnDefinitions?: ColumnDefinition[], columnDefinitionsMap?: Map<string, ColumnDefinition>, session?: Database | PgTransaction);
|
|
44
44
|
withOptionalTransaction(transaction: Transaction | undefined): EntityRepository<T>;
|
|
@@ -109,5 +109,5 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
|
|
|
109
109
|
protected getAttributesUpdate(attributes: EntityMetadataAttributes | undefined): SQL<unknown> | undefined;
|
|
110
110
|
}
|
|
111
111
|
export declare function injectRepository<T extends Entity>(type: EntityType<T>): EntityRepository<T>;
|
|
112
|
-
export declare function getRepository<T extends Entity>(type: EntityType<T>, config
|
|
112
|
+
export declare function getRepository<T extends Entity>(type: EntityType<T>, config?: EntityRepositoryConfig): Type<EntityRepository<T>>;
|
|
113
113
|
export {};
|
package/orm/server/repository.js
CHANGED
|
@@ -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;
|
|
@@ -36,12 +38,9 @@ let EntityRepository = class EntityRepository {
|
|
|
36
38
|
columnDefinitionsMap;
|
|
37
39
|
session;
|
|
38
40
|
isInTransaction;
|
|
39
|
-
get tx() {
|
|
40
|
-
return this.session;
|
|
41
|
-
}
|
|
42
41
|
constructor(type, table, columnDefinitions, columnDefinitionsMap, session) {
|
|
43
42
|
this.#repositoryConstructor = new.target;
|
|
44
|
-
this.type = type ?? injectArgument(this);
|
|
43
|
+
this.type = type ?? injectArgument(this, { optional: true }) ?? inject(ENTITY_TYPE);
|
|
45
44
|
this.table = table ?? getDrizzleTableFromType(this.type, inject(EntityRepositoryConfig).schema);
|
|
46
45
|
this.columnDefinitions = columnDefinitions ?? getColumnDefinitions(this.table);
|
|
47
46
|
this.columnDefinitionsMap = columnDefinitionsMap ?? new Map(this.columnDefinitions.map((column) => [column.objectPath.path, column]));
|
|
@@ -425,7 +424,7 @@ export function getRepository(type, config) {
|
|
|
425
424
|
[className]: class extends EntityRepository {
|
|
426
425
|
}
|
|
427
426
|
}[className];
|
|
428
|
-
const injectorDecorator = Singleton({ providers: [{ provide: EntityRepositoryConfig, useValue: config }] });
|
|
427
|
+
const injectorDecorator = Singleton({ providers: [{ provide: ENTITY_TYPE, useValue: type }, { provide: EntityRepositoryConfig, useValue: config }] });
|
|
429
428
|
injectorDecorator(entityRepositoryClass);
|
|
430
429
|
return entityRepositoryClass;
|
|
431
430
|
}
|