@tstdl/base 0.92.130 → 0.92.131
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/ai/ai.service.js +4 -4
- package/api/server/api-controller.js +1 -2
- package/document-management/api/document-management.api.d.ts +9 -37
- package/document-management/api/document-management.api.js +9 -18
- package/document-management/models/document-request-collection-assignment.model.d.ts +7 -0
- package/document-management/models/{document-request-collection.model.js → document-request-collection-assignment.model.js} +6 -6
- package/document-management/models/index.d.ts +1 -1
- package/document-management/models/index.js +1 -1
- package/document-management/server/api/document-management.api.d.ts +26 -0
- package/document-management/server/api/document-management.api.js +169 -0
- package/document-management/server/api/index.d.ts +1 -0
- package/document-management/server/api/index.js +1 -0
- package/document-management/server/drizzle/{0000_cool_victor_mancha.sql → 0000_magical_madame_hydra.sql} +128 -96
- package/document-management/server/drizzle/meta/0000_snapshot.json +768 -492
- package/document-management/server/drizzle/meta/_journal.json +2 -9
- package/document-management/server/index.d.ts +1 -0
- package/document-management/server/index.js +1 -0
- package/document-management/server/schemas.d.ts +3 -2
- package/document-management/server/schemas.js +3 -2
- package/document-management/server/services/document-category-type.service.d.ts +2 -0
- package/document-management/server/services/document-category-type.service.js +26 -15
- package/document-management/server/services/document-collection.service.js +13 -2
- package/document-management/server/services/document-file.service.js +15 -4
- package/document-management/server/services/document-management-ai.service.js +19 -8
- package/document-management/server/services/document-management-ancillary.service.d.ts +21 -40
- package/document-management/server/services/document-management-ancillary.service.js +25 -14
- package/document-management/server/services/document-management.service.d.ts +1 -1
- package/document-management/server/services/document-management.service.js +53 -34
- package/document-management/server/services/document-property.service.d.ts +2 -34
- package/document-management/server/services/document-property.service.js +20 -8
- package/document-management/server/services/document-request.service.js +11 -11
- package/document-management/server/services/document-validation.service.js +15 -4
- package/document-management/server/services/document-workflow.service.js +27 -16
- package/document-management/server/services/document.service.d.ts +8 -2
- package/document-management/server/services/document.service.js +47 -7
- package/document-management/server/services/index.d.ts +1 -0
- package/document-management/server/services/index.js +1 -0
- package/document-management/server/services/singleton.d.ts +4 -0
- package/document-management/server/services/singleton.js +12 -0
- package/eslint.config.js +1 -0
- package/examples/document-management/categories-and-types.d.ts +324 -0
- package/examples/document-management/categories-and-types.js +363 -0
- package/examples/document-management/main.d.ts +7 -8
- package/examples/document-management/main.js +86 -27
- package/injector/decorators.d.ts +1 -0
- package/injector/decorators.js +41 -12
- package/injector/inject.d.ts +12 -2
- package/injector/injector.d.ts +3 -2
- package/injector/injector.js +87 -36
- package/injector/symbols.d.ts +1 -0
- package/injector/symbols.js +1 -0
- package/module/modules/web-server.module.js +4 -4
- package/orm/server/database.d.ts +0 -4
- package/orm/server/database.js +0 -4
- package/orm/server/drizzle/schema-converter.js +5 -4
- package/orm/server/module.d.ts +0 -4
- package/orm/server/module.js +0 -2
- package/orm/server/query-converter.js +11 -38
- package/orm/server/repository.d.ts +3 -2
- package/orm/server/repository.js +2 -2
- package/orm/server/transaction.d.ts +5 -4
- package/orm/server/transaction.js +8 -3
- package/orm/server/transactional.js +3 -3
- package/orm/sqls.d.ts +4 -1
- package/orm/sqls.js +4 -1
- package/package.json +4 -4
- package/reflection/registry.js +6 -6
- package/document-management/models/document-request-collection.model.d.ts +0 -7
- package/document-management/server/drizzle/0001_concerned_quentin_quire.sql +0 -2
- package/document-management/server/drizzle/meta/0001_snapshot.json +0 -1932
|
@@ -5,15 +5,8 @@
|
|
|
5
5
|
{
|
|
6
6
|
"idx": 0,
|
|
7
7
|
"version": "7",
|
|
8
|
-
"when":
|
|
9
|
-
"tag": "
|
|
10
|
-
"breakpoints": true
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"idx": 1,
|
|
14
|
-
"version": "7",
|
|
15
|
-
"when": 1741944761924,
|
|
16
|
-
"tag": "0001_concerned_quentin_quire",
|
|
8
|
+
"when": 1747907526660,
|
|
9
|
+
"tag": "0000_magical_madame_hydra",
|
|
17
10
|
"breakpoints": true
|
|
18
11
|
}
|
|
19
12
|
]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Document, DocumentAssignmentScope, DocumentAssignmentTask, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentFile, DocumentProperty, DocumentPropertyValue, DocumentRequest,
|
|
1
|
+
import { Document, DocumentAssignmentScope, DocumentAssignmentTask, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentFile, DocumentProperty, DocumentPropertyValue, DocumentRequest, DocumentRequestCollectionAssignment, DocumentRequestsTemplate, DocumentRequestSubmission, DocumentRequestTemplate, DocumentType, DocumentTypeProperty, DocumentTypeValidation, DocumentValidationDefinition, DocumentValidationExecution, DocumentValidationExecutionRelatedDocument, DocumentWorkflow } from '../models/index.js';
|
|
2
2
|
export declare const documentManagementSchema: import("../../orm/server/database-schema.js").DatabaseSchema<"document_management">;
|
|
3
3
|
export declare const aocumentApproval: import("drizzle-orm/pg-core").PgEnum<["pending", "approved", "rejected"]>;
|
|
4
4
|
export declare const documentAssignmentCollectionTarget: import("drizzle-orm/pg-core").PgEnum<["request", "collection"]>;
|
|
@@ -6,6 +6,7 @@ export declare const documentPropertyDataType: import("drizzle-orm/pg-core").PgE
|
|
|
6
6
|
export declare const documentRequestState: import("drizzle-orm/pg-core").PgEnum<["open", "closed", "fulfilled"]>;
|
|
7
7
|
export declare const documentValidationExecutionState: import("drizzle-orm/pg-core").PgEnum<["pending", "error", "running", "completed"]>;
|
|
8
8
|
export declare const documentValidationResultStatus: import("drizzle-orm/pg-core").PgEnum<["warning", "failed", "passed"]>;
|
|
9
|
+
export declare const documentWorkflowFailReason: import("drizzle-orm/pg-core").PgEnum<["no-suitable-collection", "no-suitable-request"]>;
|
|
9
10
|
export declare const documentWorkflowState: import("drizzle-orm/pg-core").PgEnum<["pending", "error", "running", "completed", "failed"]>;
|
|
10
11
|
export declare const documentWorkflowStep: import("drizzle-orm/pg-core").PgEnum<["classification", "extraction", "assignment", "validation"]>;
|
|
11
12
|
export declare const document: import("../../orm/server/types.js").PgTableFromType<typeof Document, "document_management">;
|
|
@@ -18,7 +19,7 @@ export declare const documentFile: import("../../orm/server/types.js").PgTableFr
|
|
|
18
19
|
export declare const documentProperty: import("../../orm/server/types.js").PgTableFromType<typeof DocumentProperty, "document_management">;
|
|
19
20
|
export declare const documentPropertyValue: import("../../orm/server/types.js").PgTableFromType<typeof DocumentPropertyValue, "document_management">;
|
|
20
21
|
export declare const documentRequest: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequest, "document_management">;
|
|
21
|
-
export declare const
|
|
22
|
+
export declare const documentRequestCollectionAssignment: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequestCollectionAssignment, "document_management">;
|
|
22
23
|
export declare const documentRequestsTemplate: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequestsTemplate, "document_management">;
|
|
23
24
|
export declare const documentRequestSubmission: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequestSubmission, "document_management">;
|
|
24
25
|
export declare const documentRequestTemplate: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequestTemplate, "document_management">;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { databaseSchema } from '../../orm/server/database-schema.js';
|
|
2
|
-
import { Document, DocumentApproval, DocumentAssignmentScope, DocumentAssignmentTarget, DocumentAssignmentTask, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentFile, DocumentProperty, DocumentPropertyDataType, DocumentPropertyValue, DocumentRequest,
|
|
2
|
+
import { Document, DocumentApproval, DocumentAssignmentScope, DocumentAssignmentTarget, DocumentAssignmentTask, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentFile, DocumentProperty, DocumentPropertyDataType, DocumentPropertyValue, DocumentRequest, DocumentRequestCollectionAssignment, DocumentRequestState, DocumentRequestsTemplate, DocumentRequestSubmission, DocumentRequestTemplate, DocumentType, DocumentTypeProperty, DocumentTypeValidation, DocumentValidationDefinition, DocumentValidationExecution, DocumentValidationExecutionRelatedDocument, DocumentValidationExecutionState, DocumentValidationResultStatus, DocumentWorkflow, DocumentWorkflowFailReason, DocumentWorkflowState, DocumentWorkflowStep } from '../models/index.js';
|
|
3
3
|
export const documentManagementSchema = databaseSchema('document_management');
|
|
4
4
|
export const aocumentApproval = documentManagementSchema.getEnum(DocumentApproval);
|
|
5
5
|
export const documentAssignmentCollectionTarget = documentManagementSchema.getEnum(DocumentAssignmentTarget);
|
|
@@ -7,6 +7,7 @@ export const documentPropertyDataType = documentManagementSchema.getEnum(Documen
|
|
|
7
7
|
export const documentRequestState = documentManagementSchema.getEnum(DocumentRequestState);
|
|
8
8
|
export const documentValidationExecutionState = documentManagementSchema.getEnum(DocumentValidationExecutionState);
|
|
9
9
|
export const documentValidationResultStatus = documentManagementSchema.getEnum(DocumentValidationResultStatus);
|
|
10
|
+
export const documentWorkflowFailReason = documentManagementSchema.getEnum(DocumentWorkflowFailReason);
|
|
10
11
|
export const documentWorkflowState = documentManagementSchema.getEnum(DocumentWorkflowState);
|
|
11
12
|
export const documentWorkflowStep = documentManagementSchema.getEnum(DocumentWorkflowStep);
|
|
12
13
|
export const document = documentManagementSchema.getTable(Document);
|
|
@@ -19,7 +20,7 @@ export const documentFile = documentManagementSchema.getTable(DocumentFile);
|
|
|
19
20
|
export const documentProperty = documentManagementSchema.getTable(DocumentProperty);
|
|
20
21
|
export const documentPropertyValue = documentManagementSchema.getTable(DocumentPropertyValue);
|
|
21
22
|
export const documentRequest = documentManagementSchema.getTable(DocumentRequest);
|
|
22
|
-
export const
|
|
23
|
+
export const documentRequestCollectionAssignment = documentManagementSchema.getTable(DocumentRequestCollectionAssignment);
|
|
23
24
|
export const documentRequestsTemplate = documentManagementSchema.getTable(DocumentRequestsTemplate);
|
|
24
25
|
export const documentRequestSubmission = documentManagementSchema.getTable(DocumentRequestSubmission);
|
|
25
26
|
export const documentRequestTemplate = documentManagementSchema.getTable(DocumentRequestTemplate);
|
|
@@ -4,6 +4,8 @@ import type { DocumentCategoryView } from '../../service-models/index.js';
|
|
|
4
4
|
export declare const enumTypeKey = "enum-type";
|
|
5
5
|
export declare class DocumentCategoryTypeService extends Transactional {
|
|
6
6
|
#private;
|
|
7
|
+
readonly categoryRepository: import("../../../orm/server/repository.js").EntityRepository<DocumentCategory>;
|
|
8
|
+
readonly typeRepository: import("../../../orm/server/repository.js").EntityRepository<DocumentType>;
|
|
7
9
|
loadCategory(id: string): Promise<DocumentCategory>;
|
|
8
10
|
loadType(id: string): Promise<DocumentType>;
|
|
9
11
|
createCategory(label: string, parentId: string | null, enumKey?: string): Promise<DocumentCategory>;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
1
7
|
var _a;
|
|
8
|
+
var DocumentCategoryTypeService_1;
|
|
2
9
|
import { inject } from '../../../injector/inject.js';
|
|
3
10
|
import { Logger } from '../../../logger/logger.js';
|
|
4
11
|
import { Transactional } from '../../../orm/server/index.js';
|
|
@@ -6,31 +13,32 @@ import { injectRepository } from '../../../orm/server/repository.js';
|
|
|
6
13
|
import { groupToMap } from '../../../utils/iterable-helpers/group-to-map.js';
|
|
7
14
|
import { isUndefined } from '../../../utils/type-guards.js';
|
|
8
15
|
import { DocumentCategory, DocumentType } from '../../models/index.js';
|
|
16
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
9
17
|
export const enumTypeKey = 'enum-type';
|
|
10
|
-
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
let DocumentCategoryTypeService = DocumentCategoryTypeService_1 = class DocumentCategoryTypeService extends Transactional {
|
|
19
|
+
#logger = inject(Logger, DocumentCategoryTypeService_1.name);
|
|
20
|
+
categoryRepository = injectRepository(DocumentCategory);
|
|
21
|
+
typeRepository = injectRepository(DocumentType);
|
|
14
22
|
async loadCategory(id) {
|
|
15
|
-
return this
|
|
23
|
+
return this.categoryRepository.load(id);
|
|
16
24
|
}
|
|
17
25
|
async loadType(id) {
|
|
18
|
-
return this
|
|
26
|
+
return this.typeRepository.load(id);
|
|
19
27
|
}
|
|
20
28
|
async createCategory(label, parentId, enumKey) {
|
|
21
|
-
return this
|
|
29
|
+
return this.categoryRepository.insert({ label, parentId, metadata: { attributes: { [enumTypeKey]: enumKey } } });
|
|
22
30
|
}
|
|
23
31
|
async createType(label, categoryId, enumKey) {
|
|
24
|
-
return this
|
|
32
|
+
return this.typeRepository.insert({ label, categoryId, metadata: { attributes: { [enumTypeKey]: enumKey } } });
|
|
25
33
|
}
|
|
26
34
|
async updateCategory(id, update) {
|
|
27
|
-
return this
|
|
35
|
+
return this.categoryRepository.update(id, update);
|
|
28
36
|
}
|
|
29
37
|
async updateType(id, update) {
|
|
30
|
-
return this
|
|
38
|
+
return this.typeRepository.update(id, update);
|
|
31
39
|
}
|
|
32
40
|
async loadCategoryGraph(categoryId) {
|
|
33
|
-
const category = await this
|
|
41
|
+
const category = await this.categoryRepository.load(categoryId);
|
|
34
42
|
if (category.parentId == null) {
|
|
35
43
|
return [category];
|
|
36
44
|
}
|
|
@@ -39,8 +47,8 @@ export class DocumentCategoryTypeService extends Transactional {
|
|
|
39
47
|
}
|
|
40
48
|
async loadCategoriesAndTypes() {
|
|
41
49
|
const [categories, types] = await Promise.all([
|
|
42
|
-
this
|
|
43
|
-
this
|
|
50
|
+
this.categoryRepository.loadManyByQuery({}, { order: 'label' }),
|
|
51
|
+
this.typeRepository.loadManyByQuery({}, { order: 'label' }),
|
|
44
52
|
]);
|
|
45
53
|
return { categories, types };
|
|
46
54
|
}
|
|
@@ -54,8 +62,11 @@ export class DocumentCategoryTypeService extends Transactional {
|
|
|
54
62
|
}
|
|
55
63
|
return rootCategories.map((category) => getView(category, categoryChildrenMap, categoryTypesMap));
|
|
56
64
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
65
|
+
};
|
|
66
|
+
DocumentCategoryTypeService = DocumentCategoryTypeService_1 = __decorate([
|
|
67
|
+
DocumentManagementSingleton()
|
|
68
|
+
], DocumentCategoryTypeService);
|
|
69
|
+
export { DocumentCategoryTypeService };
|
|
59
70
|
function getView(category, categoryChildrenMap, categoryTypesMap) {
|
|
60
71
|
const childCategories = categoryChildrenMap.get(category.id) ?? [];
|
|
61
72
|
return {
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
1
7
|
import { and, eq, sql } from 'drizzle-orm';
|
|
2
8
|
import { TRANSACTION_TIMESTAMP } from '../../../orm/index.js';
|
|
3
9
|
import { Transactional } from '../../../orm/server/index.js';
|
|
@@ -5,7 +11,8 @@ import { injectRepository } from '../../../orm/server/repository.js';
|
|
|
5
11
|
import { toArray } from '../../../utils/array/index.js';
|
|
6
12
|
import { Document, DocumentCollection, DocumentCollectionAssignment } from '../../models/index.js';
|
|
7
13
|
import { document, documentCollectionAssignment } from '../schemas.js';
|
|
8
|
-
|
|
14
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
15
|
+
let DocumentCollectionService = class DocumentCollectionService extends Transactional {
|
|
9
16
|
#documentRepository = injectRepository(Document);
|
|
10
17
|
#documentCollectionAssignmentRepository = injectRepository(DocumentCollectionAssignment);
|
|
11
18
|
repository = injectRepository(DocumentCollection);
|
|
@@ -38,4 +45,8 @@ export class DocumentCollectionService extends Transactional {
|
|
|
38
45
|
async archiveDocument(documentId, collectionIds) {
|
|
39
46
|
await this.#documentCollectionAssignmentRepository.withSession(this.session).updateManyByQuery({ collectionId: { $in: toArray(collectionIds) }, documentId, archiveTimestamp: null }, { archiveTimestamp: TRANSACTION_TIMESTAMP });
|
|
40
47
|
}
|
|
41
|
-
}
|
|
48
|
+
};
|
|
49
|
+
DocumentCollectionService = __decorate([
|
|
50
|
+
DocumentManagementSingleton()
|
|
51
|
+
], DocumentCollectionService);
|
|
52
|
+
export { DocumentCollectionService };
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
1
7
|
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
8
|
if (value !== null && value !== void 0) {
|
|
3
9
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -51,6 +57,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
51
57
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
58
|
});
|
|
53
59
|
var _a;
|
|
60
|
+
var DocumentFileService_1;
|
|
54
61
|
import sharp, {} from 'sharp';
|
|
55
62
|
import { match } from 'ts-pattern';
|
|
56
63
|
import { AiService } from '../../../ai/ai.service.js';
|
|
@@ -70,13 +77,14 @@ import { isDefined, isUint8Array } from '../../../utils/type-guards.js';
|
|
|
70
77
|
import { millisecondsPerMinute } from '../../../utils/units.js';
|
|
71
78
|
import { Document, DocumentFile } from '../../models/index.js';
|
|
72
79
|
import { DocumentManagementConfig } from '../module.js';
|
|
73
|
-
|
|
80
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
81
|
+
let DocumentFileService = DocumentFileService_1 = class DocumentFileService extends Transactional {
|
|
74
82
|
#documentFileRepository = injectRepository(DocumentFile);
|
|
75
83
|
#documentRepository = injectRepository(Document);
|
|
76
84
|
#aiService = inject(AiService);
|
|
77
85
|
#fileObjectStorage = inject(ObjectStorage, inject(DocumentManagementConfig).fileObjectStorageModule);
|
|
78
86
|
#filePreviewObjectStorage = inject(ObjectStorage, inject(DocumentManagementConfig).filePreviewObjectStorageModule);
|
|
79
|
-
#logger = inject(Logger,
|
|
87
|
+
#logger = inject(Logger, DocumentFileService_1.name);
|
|
80
88
|
#aiFilePartCache = new Map();
|
|
81
89
|
async load(id) {
|
|
82
90
|
return this.#documentFileRepository.load(id);
|
|
@@ -184,8 +192,11 @@ export class DocumentFileService extends Transactional {
|
|
|
184
192
|
'Response-Content-Disposition': `${disposition}; filename = "${encodeURIComponent(filename)}"`,
|
|
185
193
|
});
|
|
186
194
|
}
|
|
187
|
-
}
|
|
188
|
-
|
|
195
|
+
};
|
|
196
|
+
DocumentFileService = DocumentFileService_1 = __decorate([
|
|
197
|
+
DocumentManagementSingleton()
|
|
198
|
+
], DocumentFileService);
|
|
199
|
+
export { DocumentFileService };
|
|
189
200
|
function getDocumentFileKey(id) {
|
|
190
201
|
return `${id.slice(0, 2)}/${id.slice(0, 4)}/${id}`;
|
|
191
202
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
1
7
|
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
8
|
if (value !== null && value !== void 0) {
|
|
3
9
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -51,6 +57,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
51
57
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
58
|
});
|
|
53
59
|
var _a;
|
|
60
|
+
var DocumentManagementAiService_1;
|
|
54
61
|
import { and, isNull as drizzleIsNull, eq, inArray } from 'drizzle-orm';
|
|
55
62
|
import { P, match } from 'ts-pattern';
|
|
56
63
|
import { AiService } from '../../../ai/index.js';
|
|
@@ -65,12 +72,13 @@ import { dateObjectToNumericDate, numericDateToDateObject } from '../../../utils
|
|
|
65
72
|
import { fromEntries, objectEntries } from '../../../utils/object/object.js';
|
|
66
73
|
import { assertDefined, assertDefinedPass, assertNotNull, isNotNull, isNull, isUndefined } from '../../../utils/type-guards.js';
|
|
67
74
|
import { Document, DocumentProperty, DocumentRequestState, DocumentTypeProperty } from '../../models/index.js';
|
|
68
|
-
import { documentCategory, documentRequest,
|
|
75
|
+
import { documentCategory, documentRequest, documentRequestCollectionAssignment, documentType } from '../schemas.js';
|
|
69
76
|
import { DocumentCategoryTypeService } from './document-category-type.service.js';
|
|
70
77
|
import { DocumentFileService } from './document-file.service.js';
|
|
71
78
|
import { DocumentManagementAncillaryService } from './document-management-ancillary.service.js';
|
|
72
79
|
import { DocumentPropertyService } from './document-property.service.js';
|
|
73
|
-
|
|
80
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
81
|
+
let DocumentManagementAiService = DocumentManagementAiService_1 = class DocumentManagementAiService {
|
|
74
82
|
#documentManagementAncillaryService = inject(DocumentManagementAncillaryService);
|
|
75
83
|
#documentCategoryTypeService = inject(DocumentCategoryTypeService);
|
|
76
84
|
#documentFileService = inject(DocumentFileService);
|
|
@@ -79,7 +87,7 @@ export class DocumentManagementAiService {
|
|
|
79
87
|
#documentPropertyRepository = injectRepository(DocumentProperty);
|
|
80
88
|
#documentRepository = injectRepository(Document);
|
|
81
89
|
#documentTypePropertyRepository = injectRepository(DocumentTypeProperty);
|
|
82
|
-
#logger = inject(Logger,
|
|
90
|
+
#logger = inject(Logger, DocumentManagementAiService_1.name);
|
|
83
91
|
async classifyDocumentType(documentId) {
|
|
84
92
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
85
93
|
try {
|
|
@@ -278,16 +286,16 @@ Ordne das Dokument unter "document" einer oder mehreren passenden Collection unt
|
|
|
278
286
|
const openRequestsWithoutDocument = await session
|
|
279
287
|
.select({
|
|
280
288
|
id: documentRequest.id,
|
|
281
|
-
collectionIds: arrayAgg(
|
|
289
|
+
collectionIds: arrayAgg(documentRequestCollectionAssignment.collectionId),
|
|
282
290
|
documentCategory: documentCategory.label,
|
|
283
291
|
documentType: documentType.label,
|
|
284
292
|
comment: documentRequest.comment,
|
|
285
293
|
})
|
|
286
294
|
.from(documentRequest)
|
|
287
|
-
.innerJoin(
|
|
295
|
+
.innerJoin(documentRequestCollectionAssignment, eq(documentRequestCollectionAssignment.requestId, documentRequest.id))
|
|
288
296
|
.innerJoin(documentType, eq(documentType.id, documentRequest.typeId))
|
|
289
297
|
.innerJoin(documentCategory, eq(documentCategory.id, documentType.categoryId))
|
|
290
|
-
.where(and(inArray(
|
|
298
|
+
.where(and(inArray(documentRequestCollectionAssignment.collectionId, collectionIds), eq(documentRequest.typeId, document.typeId), eq(documentRequest.state, DocumentRequestState.Open), drizzleIsNull(documentRequest.documentId)))
|
|
291
299
|
.groupBy(documentRequest.id, documentCategory.label, documentType.label, documentRequest.comment);
|
|
292
300
|
const requestsCollectionIds = distinct(openRequestsWithoutDocument.flatMap((request) => request.collectionIds));
|
|
293
301
|
const collectionNamesMap = await this.#documentManagementAncillaryService.resolveMetadataMap(...requestsCollectionIds);
|
|
@@ -333,8 +341,11 @@ Ordne das Dokument unter "document" der passenden Anforderungen unter "requests"
|
|
|
333
341
|
});
|
|
334
342
|
return result.json.requestId;
|
|
335
343
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
344
|
+
};
|
|
345
|
+
DocumentManagementAiService = DocumentManagementAiService_1 = __decorate([
|
|
346
|
+
DocumentManagementSingleton()
|
|
347
|
+
], DocumentManagementAiService);
|
|
348
|
+
export { DocumentManagementAiService };
|
|
338
349
|
function getDescriptiveTypeLabels(categories, prefix = 'Category: ') {
|
|
339
350
|
return categories.flatMap((category) => [...category.types.map((type) => ({ id: type.id, label: `${prefix}${category.label} | Type: ${type.label}` }), ...getDescriptiveTypeLabels(category.children, `${prefix}${category.label} -> `))]);
|
|
340
351
|
}
|
|
@@ -19,12 +19,19 @@ export declare abstract class DocumentManagementAncillaryService<Token = unknown
|
|
|
19
19
|
[K in keyof T]: DocumentCollectionMetadata;
|
|
20
20
|
}>;
|
|
21
21
|
resolveMetadataMap(...collectionsOrIds: (DocumentCollection | string)[]): Promise<Record<string, DocumentCollectionMetadata>>;
|
|
22
|
+
canReadDocument(documentId: string, token?: Token): Promise<boolean>;
|
|
23
|
+
canManageRequest(requestId: string, token?: Token): Promise<boolean>;
|
|
22
24
|
/**
|
|
23
25
|
* Resolves application-specific metadata for a list of document collections.
|
|
24
26
|
* @param collections An array of DocumentCollection entities.
|
|
25
27
|
* @returns A promise that resolves to an array of DocumentCollectionMetadata, corresponding to the input collections.
|
|
26
28
|
*/
|
|
27
29
|
abstract _resolveMetadata(collections: DocumentCollection[]): DocumentCollectionMetadata[] | Promise<DocumentCollectionMetadata[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Gets the user ID from the request token.
|
|
32
|
+
* @param token The token of the request
|
|
33
|
+
*/
|
|
34
|
+
abstract getUserId(token?: Token): string | Promise<string>;
|
|
28
35
|
/**
|
|
29
36
|
* Checks if a user can read/view a specific document collection and its documents.
|
|
30
37
|
* @param collectionId The ID of the document collection.
|
|
@@ -32,13 +39,19 @@ export declare abstract class DocumentManagementAncillaryService<Token = unknown
|
|
|
32
39
|
*/
|
|
33
40
|
abstract canReadCollection(collectionId: string, token?: Token): boolean | Promise<boolean>;
|
|
34
41
|
/**
|
|
35
|
-
* Checks if a user can
|
|
36
|
-
* This could include changing collection metadata or managing documents within it,
|
|
37
|
-
* such as adding documents or creating document requests for this collection.
|
|
42
|
+
* Checks if a user can create new *unassigned* documents (lands in "inbox", which then require assigning to request/collection) in a specific collection.
|
|
38
43
|
* @param collectionId The ID of the document collection.
|
|
39
|
-
* @param token The token of the request
|
|
44
|
+
* @param token The token of the request.
|
|
40
45
|
*/
|
|
41
|
-
abstract
|
|
46
|
+
abstract canCreateDocuments(collectionId: string, token?: Token): boolean | Promise<boolean>;
|
|
47
|
+
abstract canUpdateDocuments(collectionId: string, token?: Token): boolean | Promise<boolean>;
|
|
48
|
+
abstract canDeleteDocuments(collectionId: string, token?: Token): boolean | Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a user can assign documents to requests in the collection or directly to the collection.
|
|
51
|
+
* @param collectionId The ID of the document collection.
|
|
52
|
+
* @param token The token of the request.
|
|
53
|
+
*/
|
|
54
|
+
abstract canAssignDocuments(collectionId: string, token?: Token): boolean | Promise<boolean>;
|
|
42
55
|
/**
|
|
43
56
|
* Checks if a user can approve a specific document. This implicitly allows fulfilling document requests by approving their linked document.
|
|
44
57
|
* This is usually a privileged action for staff members.
|
|
@@ -56,20 +69,11 @@ export declare abstract class DocumentManagementAncillaryService<Token = unknown
|
|
|
56
69
|
*/
|
|
57
70
|
abstract canRejectDocument(documentId: string, token?: Token): boolean | Promise<boolean>;
|
|
58
71
|
/**
|
|
59
|
-
* Checks if a user can
|
|
60
|
-
* @param
|
|
61
|
-
* @param token The token of the request
|
|
62
|
-
*/
|
|
63
|
-
abstract canReadDocumentRequest(requestId: string, token?: Token): boolean | Promise<boolean>;
|
|
64
|
-
/**
|
|
65
|
-
* Checks if a user can assign an existing document to a document request.
|
|
66
|
-
* This links the document to the request, usually before final fulfillment.
|
|
67
|
-
* @param requestId The ID of the document request.
|
|
68
|
-
* @param documentId The ID of the document to be assigned.
|
|
72
|
+
* Checks if a user can create, update, delete requests and assign documents to them in a collection.
|
|
73
|
+
* @param collectionId The ID of the document collection.
|
|
69
74
|
* @param token The token of the request
|
|
70
|
-
* @returns A promise that resolves to true if assignment is allowed, false otherwise.
|
|
71
75
|
*/
|
|
72
|
-
abstract
|
|
76
|
+
abstract canManageRequests(collectionId: string, token?: Token): boolean | Promise<boolean>;
|
|
73
77
|
/**
|
|
74
78
|
* Checks if a user can manage document categories, types and their properties (create, update, delete).
|
|
75
79
|
* Typically an administrator function.
|
|
@@ -87,29 +91,6 @@ export declare abstract class DocumentManagementAncillaryService<Token = unknown
|
|
|
87
91
|
* @param token The token of the request.
|
|
88
92
|
*/
|
|
89
93
|
abstract canManageDocumentRequestsTemplates(token?: Token): boolean | Promise<boolean>;
|
|
90
|
-
/**
|
|
91
|
-
* Checks if a user can create/upload a new unassigned document (which then requires assigning to request/collection).
|
|
92
|
-
* @param token The token of the request.
|
|
93
|
-
*/
|
|
94
|
-
abstract canCreateUnassignedDocument(token?: Token): boolean | Promise<boolean>;
|
|
95
|
-
/**
|
|
96
|
-
* Checks if a user can create/upload a new document assigned to an request.
|
|
97
|
-
* @param token The token of the request.
|
|
98
|
-
*/
|
|
99
|
-
abstract canCreateRequestAssignedDocument(token?: Token): boolean | Promise<boolean>;
|
|
100
|
-
/**
|
|
101
|
-
* Checks if a user can delete a document.
|
|
102
|
-
* This might be restricted (e.g., only for documents not yet approved, or by administrators).
|
|
103
|
-
* @param documentId The ID of the document.
|
|
104
|
-
* @param token The token of the request.
|
|
105
|
-
* @returns A promise that resolves to true if deletion is allowed, false otherwise.
|
|
106
|
-
*/
|
|
107
|
-
abstract canDeleteDocument(documentId: string, token?: Token): boolean | Promise<boolean>;
|
|
108
|
-
/**
|
|
109
|
-
* Checks if a user can create and close document requests.
|
|
110
|
-
* @param token The token of the request.
|
|
111
|
-
*/
|
|
112
|
-
abstract canManageDocumentRequest(token?: Token): boolean | Promise<boolean>;
|
|
113
94
|
/**
|
|
114
95
|
* Checks if a user can manage document validation definitions and their assignment to types.
|
|
115
96
|
* Typically an administrator function.
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Singleton } from '../../../injector/index.js';
|
|
8
1
|
import { injectRepository } from '../../../orm/server/index.js';
|
|
9
2
|
import { fromEntries } from '../../../utils/object/index.js';
|
|
10
3
|
import { assertDefinedPass, isString } from '../../../utils/type-guards.js';
|
|
11
|
-
import { DocumentCollection } from '../../models/index.js';
|
|
12
|
-
|
|
4
|
+
import { DocumentCollection, DocumentCollectionAssignment, DocumentRequestCollectionAssignment } from '../../models/index.js';
|
|
5
|
+
export class DocumentManagementAncillaryService {
|
|
13
6
|
#documentCollectionRepository = injectRepository(DocumentCollection);
|
|
7
|
+
#documentCollectionAssignmentRepository = injectRepository(DocumentCollectionAssignment);
|
|
8
|
+
#documentRequestCollectionAssignmentRepository = injectRepository(DocumentRequestCollectionAssignment);
|
|
14
9
|
async resolveMetadata(...collectionsOrIds) {
|
|
15
10
|
if (collectionsOrIds.length == 0) {
|
|
16
11
|
return [];
|
|
@@ -30,8 +25,24 @@ let DocumentManagementAncillaryService = class DocumentManagementAncillaryServic
|
|
|
30
25
|
const entries = collectionsOrIds.map((collectionOrId, index) => [isString(collectionOrId) ? collectionOrId : collectionOrId.id, names[index]]);
|
|
31
26
|
return fromEntries(entries);
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
async canReadDocument(documentId, token) {
|
|
29
|
+
const assignments = await this.#documentCollectionAssignmentRepository.loadManyByQuery({ documentId });
|
|
30
|
+
for (const assignment of assignments) {
|
|
31
|
+
const canReadCollection = await this.canReadCollection(assignment.collectionId, token);
|
|
32
|
+
if (canReadCollection) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
async canManageRequest(requestId, token) {
|
|
39
|
+
const assignments = await this.#documentRequestCollectionAssignmentRepository.loadManyByQuery({ requestId });
|
|
40
|
+
for (const assignment of assignments) {
|
|
41
|
+
const canManageRequest = await this.canManageRequests(assignment.collectionId, token);
|
|
42
|
+
if (!canManageRequest) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -6,7 +6,7 @@ export declare class DocumentManagementService extends Transactional {
|
|
|
6
6
|
#private;
|
|
7
7
|
loadData(collectionIds: string[]): Promise<DocumentManagementData>;
|
|
8
8
|
loadDocumentRequestsTemplateData(): Promise<DocumentRequestsTemplateData>;
|
|
9
|
-
initializeCategoriesAndTypes<CategoryKey extends string, TypeKey extends string>(
|
|
9
|
+
initializeCategoriesAndTypes<CategoryKey extends string, TypeKey extends string>(categoryLabels: Record<CategoryKey, string>, categoryParents: Record<CategoryKey, CategoryKey | null>, typeLabels: Record<TypeKey, string>, typeCategories: Record<TypeKey, CategoryKey>): Promise<{
|
|
10
10
|
categories: Record<CategoryKey, DocumentCategory>;
|
|
11
11
|
types: Record<TypeKey, DocumentType>;
|
|
12
12
|
}>;
|