@tstdl/base 0.92.129 → 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 +25 -55
- 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 +10 -2
- package/document-management/server/services/document.service.js +61 -8
- 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/document-management/service-models/document.service-model.d.ts +8 -9
- package/document-management/service-models/document.service-model.js +1 -1
- 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
|
@@ -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 { Enumerable } from '../../../enumerable/index.js';
|
|
2
8
|
import { inject } from '../../../injector/index.js';
|
|
3
9
|
import { getEntityMap } from '../../../orm/index.js';
|
|
@@ -6,14 +12,15 @@ import { distinct } from '../../../utils/array/index.js';
|
|
|
6
12
|
import { compareByValueSelectionToOrder } from '../../../utils/comparison.js';
|
|
7
13
|
import { groupToMap, groupToSingleMap } from '../../../utils/iterable-helpers/index.js';
|
|
8
14
|
import { fromEntries, objectEntries } from '../../../utils/object/index.js';
|
|
9
|
-
import { assertDefinedPass, isNotNull, isNull, isUndefined } from '../../../utils/type-guards.js';
|
|
10
|
-
import { DocumentApproval, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentFile, DocumentRequest,
|
|
15
|
+
import { assertDefinedPass, isNotNull, isNotNullOrUndefined, isNull, isUndefined } from '../../../utils/type-guards.js';
|
|
16
|
+
import { DocumentApproval, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentFile, DocumentRequest, DocumentRequestCollectionAssignment, DocumentRequestTemplate, DocumentRequestsTemplate, DocumentType, DocumentValidationExecution, DocumentWorkflowStep } from '../../models/index.js';
|
|
11
17
|
import { DocumentCategoryTypeService, enumTypeKey } from './document-category-type.service.js';
|
|
12
18
|
import { DocumentManagementAncillaryService } from './document-management-ancillary.service.js';
|
|
13
19
|
import { DocumentPropertyService } from './document-property.service.js';
|
|
14
20
|
import { DocumentWorkflowService } from './document-workflow.service.js';
|
|
15
21
|
import { DocumentService } from './document.service.js';
|
|
16
|
-
|
|
22
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
23
|
+
let DocumentManagementService = class DocumentManagementService extends Transactional {
|
|
17
24
|
#ancillaryService = inject(DocumentManagementAncillaryService);
|
|
18
25
|
#documentCategoryTypeService = inject(DocumentCategoryTypeService);
|
|
19
26
|
#documentCollectionRepository = injectRepository(DocumentCollection);
|
|
@@ -22,7 +29,7 @@ export class DocumentManagementService extends Transactional {
|
|
|
22
29
|
#documentFileRepository = injectRepository(DocumentFile);
|
|
23
30
|
#documentService = inject(DocumentService);
|
|
24
31
|
#documentPropertyService = inject(DocumentPropertyService);
|
|
25
|
-
#
|
|
32
|
+
#documentRequestCollectionAssignmentRepository = injectRepository(DocumentRequestCollectionAssignment);
|
|
26
33
|
#documentRequestRepository = injectRepository(DocumentRequest);
|
|
27
34
|
#documentRequestsTemplateRepository = injectRepository(DocumentRequestsTemplate);
|
|
28
35
|
#documentRequestTemplateRepository = injectRepository(DocumentRequestTemplate);
|
|
@@ -30,20 +37,20 @@ export class DocumentManagementService extends Transactional {
|
|
|
30
37
|
#documentWorkflowService = inject(DocumentWorkflowService);
|
|
31
38
|
#documentValidationExecutionRepository = injectRepository(DocumentValidationExecution);
|
|
32
39
|
async loadData(collectionIds) {
|
|
33
|
-
return this.transaction(async (tx) => {
|
|
34
|
-
const [collections, collectionsMetadataMap,
|
|
40
|
+
return await this.transaction(async (tx) => {
|
|
41
|
+
const [collections, collectionsMetadataMap, documentAssignments, requestAssignments, categories, types] = await Promise.all([
|
|
35
42
|
this.#documentCollectionRepository.withTransaction(tx).loadMany(collectionIds),
|
|
36
43
|
this.#ancillaryService.resolveMetadataMap(...collectionIds),
|
|
37
44
|
this.#documentCollectionAssignmentRepository.withTransaction(tx).loadManyByQuery({ collectionId: { $in: collectionIds } }),
|
|
38
|
-
this.#
|
|
45
|
+
this.#documentRequestCollectionAssignmentRepository.withTransaction(tx).loadManyByQuery({ collectionId: { $in: collectionIds } }),
|
|
39
46
|
this.#documentCategoryRepository.withTransaction(tx).loadManyByQuery({}, { order: 'label' }),
|
|
40
47
|
this.#documentTypeRepository.withTransaction(tx).loadManyByQuery({}, { order: 'label' }),
|
|
41
48
|
]);
|
|
42
|
-
const requestIds =
|
|
49
|
+
const requestIds = requestAssignments.map((requestCollection) => requestCollection.requestId);
|
|
43
50
|
const requests = await this.#documentRequestRepository.withTransaction(tx).loadManyByQuery({ id: { $in: requestIds } }, { order: { 'metadata.createTimestamp': 'desc' } });
|
|
44
|
-
const
|
|
51
|
+
const assignmentDocumentIds = documentAssignments.map((assignment) => assignment.documentId);
|
|
45
52
|
const requestDocumentIds = requests.map((request) => request.documentId).filter(isNotNull);
|
|
46
|
-
const documentIds = distinct([...
|
|
53
|
+
const documentIds = distinct([...assignmentDocumentIds, ...requestDocumentIds]);
|
|
47
54
|
const [documents, propertyValues] = await Promise.all([
|
|
48
55
|
this.#documentService.withTransaction(tx).repository.loadManyByQuery({ id: { $in: documentIds } }, { order: { 'metadata.createTimestamp': 'desc' } }),
|
|
49
56
|
this.#documentPropertyService.withTransaction(tx).loadDocumentProperties(documentIds),
|
|
@@ -73,7 +80,7 @@ export class DocumentManagementService extends Transactional {
|
|
|
73
80
|
const validations = (isNotNull(currentWorkflow) && (currentWorkflow.step == DocumentWorkflowStep.Validation)) ? workflowValidationMap.get(currentWorkflow.id) ?? [] : null;
|
|
74
81
|
return {
|
|
75
82
|
...document,
|
|
76
|
-
collectionAssignments:
|
|
83
|
+
collectionAssignments: documentAssignments.filter((collectionDocument) => collectionDocument.documentId == document.id),
|
|
77
84
|
properties: valuesMap.get(document.id) ?? [],
|
|
78
85
|
currentWorkflow,
|
|
79
86
|
validations,
|
|
@@ -81,7 +88,7 @@ export class DocumentManagementService extends Transactional {
|
|
|
81
88
|
});
|
|
82
89
|
const requestViews = requests.map((request) => ({
|
|
83
90
|
...request,
|
|
84
|
-
collectionIds:
|
|
91
|
+
collectionIds: requestAssignments.filter((requestCollection) => requestCollection.requestId == request.id).map((requestCollection) => requestCollection.collectionId),
|
|
85
92
|
document: isNull(request.documentId) ? null : documentIdMap.get(request.documentId) ?? null,
|
|
86
93
|
}));
|
|
87
94
|
return {
|
|
@@ -95,32 +102,39 @@ export class DocumentManagementService extends Transactional {
|
|
|
95
102
|
});
|
|
96
103
|
}
|
|
97
104
|
async loadDocumentRequestsTemplateData() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
return await this.transaction(async (tx) => {
|
|
106
|
+
const [requestsTemplates, requestTemplates] = await Promise.all([
|
|
107
|
+
this.#documentRequestsTemplateRepository.withTransaction(tx).loadManyByQuery({}, { order: 'label' }),
|
|
108
|
+
this.#documentRequestTemplateRepository.withTransaction(tx).loadManyByQuery({}),
|
|
109
|
+
]);
|
|
110
|
+
const templates = requestsTemplates.map((requestsTemplate) => ({
|
|
111
|
+
...requestsTemplate,
|
|
112
|
+
requestTemplates: requestTemplates.filter((requestTemplate) => requestTemplate.requestsTemplateId == requestsTemplate.id),
|
|
113
|
+
}));
|
|
114
|
+
return { templates };
|
|
115
|
+
});
|
|
107
116
|
}
|
|
108
|
-
async initializeCategoriesAndTypes(
|
|
109
|
-
const categoryEntries = objectEntries(
|
|
110
|
-
const typeEntries = objectEntries(
|
|
117
|
+
async initializeCategoriesAndTypes(categoryLabels, categoryParents, typeLabels, typeCategories) {
|
|
118
|
+
const categoryEntries = objectEntries(categoryLabels);
|
|
119
|
+
const typeEntries = objectEntries(typeLabels);
|
|
111
120
|
const { categoryMap, typeMap } = await this.transaction(async (tx) => {
|
|
112
|
-
const { categories, types } = await this.#documentCategoryTypeService.loadCategoriesAndTypes();
|
|
121
|
+
const { categories: dbCategories, types: dbTypes } = await this.#documentCategoryTypeService.withTransaction(tx).loadCategoriesAndTypes();
|
|
122
|
+
const categories = dbCategories.filter((category) => isNotNullOrUndefined(category.metadata.attributes[enumTypeKey]));
|
|
123
|
+
const types = dbTypes.filter((type) => isNotNullOrUndefined(type.metadata.attributes[enumTypeKey]));
|
|
113
124
|
const enumKeyCategoryMap = groupToSingleMap(categories, (category) => category.metadata.attributes[enumTypeKey]);
|
|
114
125
|
const enumKeyTypeMap = groupToSingleMap(types, (type) => type.metadata.attributes[enumTypeKey]);
|
|
115
126
|
for (const [key, label] of categoryEntries) {
|
|
116
127
|
const category = enumKeyCategoryMap.get(key);
|
|
117
|
-
const
|
|
128
|
+
const parentKey = assertDefinedPass(categoryParents[key], `Parent category not defined for ${key}`);
|
|
129
|
+
const parentCategory = isNull(parentKey) ? null : assertDefinedPass(enumKeyCategoryMap.get(parentKey));
|
|
130
|
+
const parentCategoryId = parentCategory?.id ?? null;
|
|
118
131
|
if (isUndefined(category)) {
|
|
119
|
-
const category = await this.#documentCategoryTypeService.withTransaction(tx).createCategory(label,
|
|
120
|
-
|
|
132
|
+
const category = await this.#documentCategoryTypeService.withTransaction(tx).createCategory(label, parentCategoryId, key);
|
|
133
|
+
enumKeyCategoryMap.set(key, category);
|
|
121
134
|
}
|
|
122
|
-
else if ((category.label != label) || (category.parentId !=
|
|
123
|
-
await this.#documentCategoryTypeService.withTransaction(tx).updateCategory(category.id, { label, parentId });
|
|
135
|
+
else if ((category.label != label) || (category.parentId != parentCategoryId)) {
|
|
136
|
+
const updatedCategory = await this.#documentCategoryTypeService.withTransaction(tx).updateCategory(category.id, { label, parentId: parentCategoryId });
|
|
137
|
+
enumKeyCategoryMap.set(key, updatedCategory);
|
|
124
138
|
}
|
|
125
139
|
}
|
|
126
140
|
for (const [key, label] of typeEntries) {
|
|
@@ -128,11 +142,12 @@ export class DocumentManagementService extends Transactional {
|
|
|
128
142
|
const enumCategory = typeCategories[key];
|
|
129
143
|
const category = assertDefinedPass(enumKeyCategoryMap.get(enumCategory));
|
|
130
144
|
if (isUndefined(type)) {
|
|
131
|
-
const type = await this.#documentCategoryTypeService.createType(label, category.id, key);
|
|
132
|
-
|
|
145
|
+
const type = await this.#documentCategoryTypeService.withTransaction(tx).createType(label, category.id, key);
|
|
146
|
+
enumKeyTypeMap.set(key, type);
|
|
133
147
|
}
|
|
134
148
|
else if ((type.categoryId != category.id) || (type.label != label)) {
|
|
135
|
-
await this.#documentCategoryTypeService.withTransaction(tx).updateType(type.id, { categoryId: category.id, label: label });
|
|
149
|
+
const updatedType = await this.#documentCategoryTypeService.withTransaction(tx).updateType(type.id, { categoryId: category.id, label: label });
|
|
150
|
+
enumKeyTypeMap.set(key, updatedType);
|
|
136
151
|
}
|
|
137
152
|
}
|
|
138
153
|
return { categoryMap: enumKeyCategoryMap, typeMap: enumKeyTypeMap };
|
|
@@ -144,4 +159,8 @@ export class DocumentManagementService extends Transactional {
|
|
|
144
159
|
types: fromEntries(mappedTypes),
|
|
145
160
|
};
|
|
146
161
|
}
|
|
147
|
-
}
|
|
162
|
+
};
|
|
163
|
+
DocumentManagementService = __decorate([
|
|
164
|
+
DocumentManagementSingleton()
|
|
165
|
+
], DocumentManagementService);
|
|
166
|
+
export { DocumentManagementService };
|
|
@@ -6,40 +6,8 @@ export declare class DocumentPropertyService extends Transactional {
|
|
|
6
6
|
#private;
|
|
7
7
|
readonly repository: import("../../../orm/server/repository.js").EntityRepository<Document>;
|
|
8
8
|
readonly documentProperties: import("drizzle-orm/pg-core").WithSubqueryWithSelection<{
|
|
9
|
-
documentId: import("drizzle-orm
|
|
10
|
-
|
|
11
|
-
tableName: "document";
|
|
12
|
-
dataType: "string";
|
|
13
|
-
columnType: "PgUUID";
|
|
14
|
-
data: string;
|
|
15
|
-
driverParam: string;
|
|
16
|
-
notNull: true;
|
|
17
|
-
hasDefault: true;
|
|
18
|
-
isPrimaryKey: true;
|
|
19
|
-
isAutoincrement: false;
|
|
20
|
-
hasRuntimeDefault: false;
|
|
21
|
-
enumValues: undefined;
|
|
22
|
-
baseColumn: never;
|
|
23
|
-
identity: undefined;
|
|
24
|
-
generated: undefined;
|
|
25
|
-
}, {}, {}>;
|
|
26
|
-
propertyId: import("drizzle-orm/pg-core").PgColumn<{
|
|
27
|
-
name: string;
|
|
28
|
-
tableName: "document_property";
|
|
29
|
-
dataType: "string";
|
|
30
|
-
columnType: "PgUUID";
|
|
31
|
-
data: string;
|
|
32
|
-
driverParam: string;
|
|
33
|
-
notNull: true;
|
|
34
|
-
hasDefault: true;
|
|
35
|
-
isPrimaryKey: true;
|
|
36
|
-
isAutoincrement: false;
|
|
37
|
-
hasRuntimeDefault: false;
|
|
38
|
-
enumValues: undefined;
|
|
39
|
-
baseColumn: never;
|
|
40
|
-
identity: undefined;
|
|
41
|
-
generated: undefined;
|
|
42
|
-
}, {}, {}>;
|
|
9
|
+
documentId: import("drizzle-orm").SQL.Aliased<string>;
|
|
10
|
+
propertyId: import("drizzle-orm").SQL.Aliased<string>;
|
|
43
11
|
label: import("drizzle-orm/pg-core").PgColumn<{
|
|
44
12
|
name: "label";
|
|
45
13
|
tableName: "document_property";
|
|
@@ -1,12 +1,19 @@
|
|
|
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, isNotNull as drizzleIsNotNull, eq, inArray } from 'drizzle-orm';
|
|
2
8
|
import { BadRequestError } from '../../../errors/bad-request.error.js';
|
|
3
|
-
import { coalesce, getEntityMap, toJsonb } from '../../../orm/index.js';
|
|
9
|
+
import { autoAlias, coalesce, getEntityMap, toJsonb } from '../../../orm/index.js';
|
|
4
10
|
import { Transactional } from '../../../orm/server/index.js';
|
|
5
11
|
import { injectRepository } from '../../../orm/server/repository.js';
|
|
6
12
|
import { toArray } from '../../../utils/array/index.js';
|
|
7
13
|
import { assertBooleanPass, assertDefinedPass, assertNumberPass, assertStringPass, isBoolean, isNotNull, isNull, isNumber, isString } from '../../../utils/type-guards.js';
|
|
8
14
|
import { Document, DocumentProperty, DocumentPropertyDataType, DocumentPropertyValue, DocumentTypeProperty } from '../../models/index.js';
|
|
9
15
|
import { document, documentProperty, documentPropertyValue, documentType, documentTypeProperty } from '../schemas.js';
|
|
16
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
10
17
|
const documentPropertyValueValidators = {
|
|
11
18
|
[DocumentPropertyDataType.Text]: (value) => isString(value) || isNull(value),
|
|
12
19
|
[DocumentPropertyDataType.Integer]: (value) => isNumber(value) || isNull(value),
|
|
@@ -14,15 +21,15 @@ const documentPropertyValueValidators = {
|
|
|
14
21
|
[DocumentPropertyDataType.Boolean]: (value) => isBoolean(value) || isNull(value),
|
|
15
22
|
[DocumentPropertyDataType.Date]: (value) => isNumber(value) || isNull(value),
|
|
16
23
|
};
|
|
17
|
-
|
|
24
|
+
let DocumentPropertyService = class DocumentPropertyService extends Transactional {
|
|
18
25
|
#documentPropertyRepository = injectRepository(DocumentProperty);
|
|
19
26
|
#documentPropertyValueRepository = injectRepository(DocumentPropertyValue);
|
|
20
27
|
#documentTypePropertyRepository = injectRepository(DocumentTypeProperty);
|
|
21
28
|
repository = injectRepository(Document).withSession(this.session);
|
|
22
|
-
documentProperties = this.session.$with('documentProperties').as(
|
|
29
|
+
documentProperties = this.session.$with('documentProperties').as((qb) => qb
|
|
23
30
|
.select({
|
|
24
|
-
documentId: document.id,
|
|
25
|
-
propertyId: documentProperty.id,
|
|
31
|
+
documentId: autoAlias(document.id),
|
|
32
|
+
propertyId: autoAlias(documentProperty.id),
|
|
26
33
|
label: documentProperty.label,
|
|
27
34
|
dataType: documentProperty.dataType,
|
|
28
35
|
value: coalesce(toJsonb(documentPropertyValue.text), toJsonb(documentPropertyValue.integer), toJsonb(documentPropertyValue.decimal), toJsonb(documentPropertyValue.boolean), toJsonb(documentPropertyValue.date)).as('value'),
|
|
@@ -33,13 +40,14 @@ export class DocumentPropertyService extends Transactional {
|
|
|
33
40
|
.innerJoin(documentProperty, eq(documentProperty.id, documentTypeProperty.propertyId))
|
|
34
41
|
.leftJoin(documentPropertyValue, and(eq(documentPropertyValue.documentId, document.id), eq(documentPropertyValue.propertyId, documentProperty.id))));
|
|
35
42
|
async createProperty(label, dataType) {
|
|
36
|
-
return this.#documentPropertyRepository.insert({ label, dataType });
|
|
43
|
+
return await this.#documentPropertyRepository.insert({ label, dataType });
|
|
37
44
|
}
|
|
38
45
|
async assignPropertyToType(typeId, propertyId) {
|
|
39
46
|
await this.#documentTypePropertyRepository.insert({ typeId, propertyId });
|
|
40
47
|
}
|
|
41
48
|
async loadDocumentProperties(documentId, includeNulls = false) {
|
|
42
|
-
return this.session
|
|
49
|
+
return await this.session
|
|
50
|
+
.with(this.documentProperties)
|
|
43
51
|
.select({
|
|
44
52
|
documentId: this.documentProperties.documentId,
|
|
45
53
|
propertyId: this.documentProperties.propertyId,
|
|
@@ -77,7 +85,11 @@ export class DocumentPropertyService extends Transactional {
|
|
|
77
85
|
await this.#documentPropertyValueRepository.withTransaction(tx).upsertMany(['documentId', 'propertyId'], upserts);
|
|
78
86
|
});
|
|
79
87
|
}
|
|
80
|
-
}
|
|
88
|
+
};
|
|
89
|
+
DocumentPropertyService = __decorate([
|
|
90
|
+
DocumentManagementSingleton()
|
|
91
|
+
], DocumentPropertyService);
|
|
92
|
+
export { DocumentPropertyService };
|
|
81
93
|
function validatePropertyValue(propertyId, dataType, value) {
|
|
82
94
|
const valid = documentPropertyValueValidators[dataType](value);
|
|
83
95
|
if (!valid) {
|
|
@@ -6,14 +6,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { count, isNotNull as dbIsNotNull, isNull as dbIsNull, eq, inArray, sql } from 'drizzle-orm';
|
|
8
8
|
import { BadRequestError } from '../../../errors/index.js';
|
|
9
|
-
import { Injectable } from '../../../injector/index.js';
|
|
10
9
|
import { Transactional, injectRepository } from '../../../orm/server/index.js';
|
|
11
10
|
import { toArray } from '../../../utils/array/index.js';
|
|
12
11
|
import { assertDefinedPass, isNotNull } from '../../../utils/type-guards.js';
|
|
13
|
-
import { DocumentApproval, DocumentCollectionAssignment, DocumentRequest,
|
|
14
|
-
import { document, documentRequest,
|
|
12
|
+
import { DocumentApproval, DocumentCollectionAssignment, DocumentRequest, DocumentRequestCollectionAssignment, DocumentRequestState, DocumentRequestTemplate, DocumentRequestsTemplate } from '../../models/index.js';
|
|
13
|
+
import { document, documentRequest, documentRequestCollectionAssignment } from '../schemas.js';
|
|
14
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
15
15
|
let DocumentRequestService = class DocumentRequestService extends Transactional {
|
|
16
|
-
#
|
|
16
|
+
#documentRequestCollectionAssignmentRepository = injectRepository(DocumentRequestCollectionAssignment);
|
|
17
17
|
#documentRequestRepository = injectRepository(DocumentRequest);
|
|
18
18
|
#documentRequestTemplateRepository = injectRepository(DocumentRequestTemplate);
|
|
19
19
|
#documentRequestsTemplateRepository = injectRepository(DocumentRequestsTemplate);
|
|
@@ -21,8 +21,8 @@ let DocumentRequestService = class DocumentRequestService extends Transactional
|
|
|
21
21
|
async getRequestStats(collectionIds) {
|
|
22
22
|
const relevantRequests = this.session.$with('relevant_requests').as(this.session.selectDistinct({ id: documentRequest.id })
|
|
23
23
|
.from(documentRequest)
|
|
24
|
-
.innerJoin(
|
|
25
|
-
.where(inArray(
|
|
24
|
+
.innerJoin(documentRequestCollectionAssignment, eq(documentRequestCollectionAssignment.requestId, documentRequest.id))
|
|
25
|
+
.where(inArray(documentRequestCollectionAssignment.collectionId, toArray(collectionIds))));
|
|
26
26
|
const [result] = await this.session.with(relevantRequests)
|
|
27
27
|
.select({
|
|
28
28
|
total: count(sql `${documentRequest.id})`),
|
|
@@ -69,8 +69,8 @@ let DocumentRequestService = class DocumentRequestService extends Transactional
|
|
|
69
69
|
}
|
|
70
70
|
return this.transaction(async (tx) => {
|
|
71
71
|
const request = await this.#documentRequestRepository.withTransaction(tx).insert({ typeId, documentId: null, comment, state: DocumentRequestState.Open });
|
|
72
|
-
const
|
|
73
|
-
await this.#
|
|
72
|
+
const newDocumentRequestCollectionAssignments = collectionIds.map((collectionId) => ({ requestId: request.id, collectionId }));
|
|
73
|
+
await this.#documentRequestCollectionAssignmentRepository.withTransaction(tx).insertMany(newDocumentRequestCollectionAssignments);
|
|
74
74
|
return request;
|
|
75
75
|
});
|
|
76
76
|
}
|
|
@@ -89,7 +89,7 @@ let DocumentRequestService = class DocumentRequestService extends Transactional
|
|
|
89
89
|
if (isNotNull(request.documentId)) {
|
|
90
90
|
throw new BadRequestError('Cannot delete requests which have an assigned document.');
|
|
91
91
|
}
|
|
92
|
-
await this.#
|
|
92
|
+
await this.#documentRequestCollectionAssignmentRepository.withTransaction(tx).deleteManyByQuery({ requestId: id });
|
|
93
93
|
await this.#documentRequestRepository.withTransaction(tx).delete(id);
|
|
94
94
|
});
|
|
95
95
|
}
|
|
@@ -118,7 +118,7 @@ let DocumentRequestService = class DocumentRequestService extends Transactional
|
|
|
118
118
|
if (request.state == DocumentRequestState.Fulfilled) {
|
|
119
119
|
throw new BadRequestError('Document request is already fulfilled.');
|
|
120
120
|
}
|
|
121
|
-
const targetCollectionIds = await this.#
|
|
121
|
+
const targetCollectionIds = await this.#documentRequestCollectionAssignmentRepository.withTransaction(tx).loadManyByQuery({ requestId });
|
|
122
122
|
if (targetCollectionIds.length == 0) {
|
|
123
123
|
throw new Error('No document request collection for document request found.');
|
|
124
124
|
}
|
|
@@ -133,6 +133,6 @@ let DocumentRequestService = class DocumentRequestService extends Transactional
|
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
DocumentRequestService = __decorate([
|
|
136
|
-
|
|
136
|
+
DocumentManagementSingleton()
|
|
137
137
|
], DocumentRequestService);
|
|
138
138
|
export { DocumentRequestService };
|
|
@@ -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 DocumentValidationService_1;
|
|
2
9
|
import { DocumentWorkflowStep } from '../../../document-management/models/document-workflow.model.js';
|
|
3
10
|
import { Document, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentProperty, DocumentPropertyValue, DocumentType, DocumentTypeProperty, DocumentTypeValidation, DocumentValidationDefinition, DocumentValidationExecution, DocumentValidationExecutionRelatedDocument, DocumentValidationExecutionState, DocumentValidationResultStatus } from '../../../document-management/models/index.js';
|
|
4
11
|
import { BadRequestError } from '../../../errors/bad-request.error.js';
|
|
@@ -14,8 +21,9 @@ import { currentTimestamp } from '../../../utils/date-time.js';
|
|
|
14
21
|
import { isNull, isUndefined } from '../../../utils/type-guards.js';
|
|
15
22
|
import { millisecondsPerMinute } from '../../../utils/units.js';
|
|
16
23
|
import { DocumentWorkflowService } from './document-workflow.service.js';
|
|
24
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
17
25
|
const DOCUMENT_VALIDATION_EXECUTORS = injectionToken('DocumentValidationExecutors');
|
|
18
|
-
|
|
26
|
+
let DocumentValidationService = DocumentValidationService_1 = class DocumentValidationService {
|
|
19
27
|
#documentManagementService = injectRepository(DocumentCollection);
|
|
20
28
|
#documentCollectionAssignmentRepository = injectRepository(DocumentCollectionAssignment);
|
|
21
29
|
#documentService = injectRepository(Document);
|
|
@@ -31,7 +39,7 @@ export class DocumentValidationService {
|
|
|
31
39
|
#documentTypeValidationService = injectRepository(DocumentTypeValidation);
|
|
32
40
|
#queue = inject((Queue), { name: 'DocumentManagement: validation', processTimeout: 5 * millisecondsPerMinute, maxTries: 3 });
|
|
33
41
|
#executors = injectAll(DOCUMENT_VALIDATION_EXECUTORS);
|
|
34
|
-
#logger = inject(Logger,
|
|
42
|
+
#logger = inject(Logger, DocumentValidationService_1.name);
|
|
35
43
|
#executorMap = new Map(this.#executors.map((executor) => [executor.identifier, executor]));
|
|
36
44
|
[afterResolve](_, { cancellationSignal }) {
|
|
37
45
|
this.processQueue(cancellationSignal);
|
|
@@ -136,8 +144,11 @@ export class DocumentValidationService {
|
|
|
136
144
|
await this.setExecutionError(executionId, 'Internal error');
|
|
137
145
|
}
|
|
138
146
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
147
|
+
};
|
|
148
|
+
DocumentValidationService = DocumentValidationService_1 = __decorate([
|
|
149
|
+
DocumentManagementSingleton()
|
|
150
|
+
], DocumentValidationService);
|
|
151
|
+
export { DocumentValidationService };
|
|
141
152
|
export function registerDocumentValidationExecutor(...executors) {
|
|
142
153
|
for (const executor of executors) {
|
|
143
154
|
Injector.register(DOCUMENT_VALIDATION_EXECUTORS, { useToken: executor }, { multi: true });
|
|
@@ -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 DocumentWorkflowService_1;
|
|
2
9
|
import { match } from 'ts-pattern';
|
|
3
10
|
import { DocumentAssignmentScope } from '../../../document-management/models/document-assignment-scope.model.js';
|
|
4
11
|
import { DocumentAssignmentTask } from '../../../document-management/models/document-assignment-task.model.js';
|
|
@@ -18,7 +25,8 @@ import { DocumentCollectionService } from './document-collection.service.js';
|
|
|
18
25
|
import { DocumentManagementAiService } from './document-management-ai.service.js';
|
|
19
26
|
import { DocumentRequestService } from './document-request.service.js';
|
|
20
27
|
import { DocumentService } from './document.service.js';
|
|
21
|
-
|
|
28
|
+
import { DocumentManagementSingleton } from './singleton.js';
|
|
29
|
+
let DocumentWorkflowService = DocumentWorkflowService_1 = class DocumentWorkflowService extends Transactional {
|
|
22
30
|
#documentManagementAiService = inject(DocumentManagementAiService);
|
|
23
31
|
#documentService = inject(DocumentService);
|
|
24
32
|
#documentCollectionService = inject(DocumentCollectionService);
|
|
@@ -26,25 +34,25 @@ export class DocumentWorkflowService extends Transactional {
|
|
|
26
34
|
#documentAssignmentTaskRepository = injectRepository(DocumentAssignmentTask);
|
|
27
35
|
#documentAssignmentScopeRepository = injectRepository(DocumentAssignmentScope);
|
|
28
36
|
#queue = inject((Queue), { name: 'DocumentWorkflow', processTimeout: 5 * 60 * 1000, maxTries: 3 });
|
|
29
|
-
#logger = inject(Logger,
|
|
37
|
+
#logger = inject(Logger, DocumentWorkflowService_1.name);
|
|
30
38
|
repository = injectRepository(DocumentWorkflow).withSession(this.session);
|
|
31
39
|
[afterResolve](_, { cancellationSignal }) {
|
|
32
40
|
if (this.isInTransaction) {
|
|
33
41
|
return;
|
|
34
42
|
}
|
|
35
|
-
this.#queue.process({ concurrency: 5, cancellationSignal }, async (job) => this.processWorkflowJob(job), this.#logger);
|
|
43
|
+
this.#queue.process({ concurrency: 5, cancellationSignal }, async (job) => await this.processWorkflowJob(job), this.#logger);
|
|
36
44
|
}
|
|
37
45
|
async loadLatestWorkflow(documentId) {
|
|
38
|
-
return this.repository.loadByQuery({ documentId }, { order: { 'metadata.createTimestamp': 'desc' } });
|
|
46
|
+
return await this.repository.loadByQuery({ documentId }, { order: { 'metadata.createTimestamp': 'desc' } });
|
|
39
47
|
}
|
|
40
48
|
async tryLoadLatestWorkflow(documentId) {
|
|
41
|
-
return this.repository.tryLoadByQuery({ documentId }, { order: { 'metadata.createTimestamp': 'desc' } });
|
|
49
|
+
return await this.repository.tryLoadByQuery({ documentId }, { order: { 'metadata.createTimestamp': 'desc' } });
|
|
42
50
|
}
|
|
43
51
|
async loadLatestWorkflows(documentIds) {
|
|
44
|
-
return this.repository.loadManyByQuery({ documentId: { $in: documentIds } }, { distinct: ['documentId'], order: { 'metadata.createTimestamp': 'desc' } });
|
|
52
|
+
return await this.repository.loadManyByQuery({ documentId: { $in: documentIds } }, { distinct: ['metadata.createTimestamp', 'documentId'], order: { 'metadata.createTimestamp': 'desc' } });
|
|
45
53
|
}
|
|
46
54
|
async proceedWorkflow(documentId, userId) {
|
|
47
|
-
|
|
55
|
+
await this.transaction(async (tx) => {
|
|
48
56
|
const workflow = await this.withTransaction(tx).loadLatestWorkflow(documentId);
|
|
49
57
|
if (workflow.state != DocumentWorkflowState.Completed) {
|
|
50
58
|
throw new BadRequestError('Current workflow is not completed');
|
|
@@ -55,8 +63,8 @@ export class DocumentWorkflowService extends Transactional {
|
|
|
55
63
|
await this.repository.withTransaction(tx).update(workflow.id, { completeUserId: userId });
|
|
56
64
|
await match(workflow.step)
|
|
57
65
|
.with(DocumentWorkflowStep.Classification, () => _throw(new BadRequestError('Proceeding from classification occurs automatically.')))
|
|
58
|
-
.with(DocumentWorkflowStep.Extraction, async () => this.withTransaction(tx).initiateWorkflow(documentId, DocumentWorkflowStep.Assignment))
|
|
59
|
-
.with(DocumentWorkflowStep.Assignment, async () => this.withTransaction(tx).initiateWorkflow(documentId, DocumentWorkflowStep.Validation))
|
|
66
|
+
.with(DocumentWorkflowStep.Extraction, async () => await this.withTransaction(tx).initiateWorkflow(documentId, DocumentWorkflowStep.Assignment))
|
|
67
|
+
.with(DocumentWorkflowStep.Assignment, async () => await this.withTransaction(tx).initiateWorkflow(documentId, DocumentWorkflowStep.Validation))
|
|
60
68
|
.with(DocumentWorkflowStep.Validation, () => { })
|
|
61
69
|
.exhaustive();
|
|
62
70
|
});
|
|
@@ -75,10 +83,10 @@ export class DocumentWorkflowService extends Transactional {
|
|
|
75
83
|
try {
|
|
76
84
|
await this.setWorkflowState(workflow.id, DocumentWorkflowState.Running);
|
|
77
85
|
await match(workflow.step)
|
|
78
|
-
.with(DocumentWorkflowStep.Classification, async () => this.processClassificationWorkflow(workflow))
|
|
79
|
-
.with(DocumentWorkflowStep.Extraction, async () => this.processExtractionWorkflow(workflow))
|
|
80
|
-
.with(DocumentWorkflowStep.Assignment, async () => this.processAssignmentWorkflow(workflow))
|
|
81
|
-
.with(DocumentWorkflowStep.Validation, async () => this.processValidationWorkflow(workflow))
|
|
86
|
+
.with(DocumentWorkflowStep.Classification, async () => await this.processClassificationWorkflow(workflow))
|
|
87
|
+
.with(DocumentWorkflowStep.Extraction, async () => await this.processExtractionWorkflow(workflow))
|
|
88
|
+
.with(DocumentWorkflowStep.Assignment, async () => await this.processAssignmentWorkflow(workflow))
|
|
89
|
+
.with(DocumentWorkflowStep.Validation, async () => await this.processValidationWorkflow(workflow))
|
|
82
90
|
.exhaustive();
|
|
83
91
|
await this.setWorkflowState(workflow.id, DocumentWorkflowState.Completed);
|
|
84
92
|
if (workflow.step == DocumentWorkflowStep.Classification) {
|
|
@@ -100,7 +108,7 @@ export class DocumentWorkflowService extends Transactional {
|
|
|
100
108
|
}
|
|
101
109
|
async processExtractionWorkflow(workflow) {
|
|
102
110
|
const extraction = await this.#documentManagementAiService.extractDocumentInformation(workflow.documentId);
|
|
103
|
-
await this.#documentService.
|
|
111
|
+
await this.#documentService.update(workflow.documentId, extraction);
|
|
104
112
|
}
|
|
105
113
|
async processAssignmentWorkflow(workflow) {
|
|
106
114
|
const assignmentTask = await this.#documentAssignmentTaskRepository.loadByQuery({ documentId: workflow.documentId });
|
|
@@ -128,5 +136,8 @@ export class DocumentWorkflowService extends Transactional {
|
|
|
128
136
|
async processValidationWorkflow(_workflow) {
|
|
129
137
|
throw new NotImplementedError();
|
|
130
138
|
}
|
|
131
|
-
}
|
|
132
|
-
|
|
139
|
+
};
|
|
140
|
+
DocumentWorkflowService = DocumentWorkflowService_1 = __decorate([
|
|
141
|
+
DocumentManagementSingleton()
|
|
142
|
+
], DocumentWorkflowService);
|
|
143
|
+
export { DocumentWorkflowService };
|
|
@@ -5,10 +5,18 @@ import { Document } from '../../models/index.js';
|
|
|
5
5
|
export declare class DocumentService extends Transactional {
|
|
6
6
|
#private;
|
|
7
7
|
readonly repository: import("../../../orm/server/repository.js").EntityRepository<Document>;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
create({ typeId, title, subtitle, date, summary, tags, approval, comment, originalFileName, assignment, properties, metadata }: CreateDocumentParameters, content: Uint8Array | ReadableStream<Uint8Array>, { createUserId }: {
|
|
9
|
+
createUserId?: string;
|
|
10
|
+
}): Promise<Document>;
|
|
11
|
+
update(id: string, update: Partial<Pick<Document, UpdatableDocumentProperties>> & {
|
|
10
12
|
properties?: SetDocumentPropertyParameters[];
|
|
11
13
|
}): Promise<void>;
|
|
14
|
+
getContent(documentOrId: Document | string): Promise<Uint8Array>;
|
|
15
|
+
getContentStream(documentOrId: Document | string): ReadableStream<Uint8Array>;
|
|
16
|
+
getContentUrl(documentOrId: Document | string, download?: boolean): Promise<string>;
|
|
17
|
+
getPreview(documentOrId: Document | string, page?: number): Promise<Uint8Array>;
|
|
18
|
+
getPreviewStream(documentOrId: Document | string, page?: number): ReadableStream<Uint8Array>;
|
|
19
|
+
getPreviewUrl(documentOrId: Document | string, page?: number): Promise<string>;
|
|
12
20
|
/**
|
|
13
21
|
* @returns collectionIds from either direct assignment or automatic assignment scope
|
|
14
22
|
*/
|