@tstdl/base 0.92.148 → 0.92.149
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.
|
@@ -3,6 +3,20 @@ import { Transactional } from '../../../orm/server/index.js';
|
|
|
3
3
|
import type { Record } from '../../../types/index.js';
|
|
4
4
|
import { DocumentCategory, DocumentType, type DocumentProperty, type DocumentPropertyDataType } from '../../models/index.js';
|
|
5
5
|
import type { DocumentManagementData, DocumentRequestsTemplateData } from '../../service-models/index.js';
|
|
6
|
+
export type CategoryLabels<CategoryKey extends string> = Record<CategoryKey, string>;
|
|
7
|
+
export type CategoryParents<CategoryKey extends string> = Record<CategoryKey, CategoryKey | null>;
|
|
8
|
+
export type TypeLabels<TypeKey extends string> = Record<TypeKey, string>;
|
|
9
|
+
export type TypeCategories<TypeKey extends string, CategoryKey extends string> = Record<TypeKey, CategoryKey>;
|
|
10
|
+
export type PropertyConfigurations<DocumentPropertyKey extends string> = Record<DocumentPropertyKey, [DocumentPropertyDataType, label: string]>;
|
|
11
|
+
export type TypeProperties<TypeKey extends string, DocumentPropertyKey extends string> = Record<TypeKey, DocumentPropertyKey[]>;
|
|
12
|
+
export type CategoriesAndTypesInitializationData<CategoryKey extends string, TypeKey extends string, DocumentPropertyKey extends string> = {
|
|
13
|
+
categoryLabels: CategoryLabels<CategoryKey>;
|
|
14
|
+
categoryParents: CategoryParents<NoInfer<CategoryKey>>;
|
|
15
|
+
typeLabels: TypeLabels<TypeKey>;
|
|
16
|
+
typeCategories: TypeCategories<NoInfer<TypeKey>, NoInfer<CategoryKey>>;
|
|
17
|
+
propertyConfigurations: PropertyConfigurations<DocumentPropertyKey>;
|
|
18
|
+
typeProperties: TypeProperties<NoInfer<TypeKey>, NoInfer<DocumentPropertyKey>>;
|
|
19
|
+
};
|
|
6
20
|
export declare class DocumentManagementService extends Transactional {
|
|
7
21
|
#private;
|
|
8
22
|
/**
|
|
@@ -14,7 +28,7 @@ export declare class DocumentManagementService extends Transactional {
|
|
|
14
28
|
loadDataStream(tenantId: string, collectionIds: string[], cancellationSignal: CancellationSignal): AsyncIterableIterator<DocumentManagementData>;
|
|
15
29
|
loadData(tenantId: string, collectionIds: string[]): Promise<DocumentManagementData>;
|
|
16
30
|
loadDocumentRequestsTemplateData(tenantId: string | null): Promise<DocumentRequestsTemplateData>;
|
|
17
|
-
initializeCategoriesAndTypes<CategoryKey extends string, TypeKey extends string, DocumentPropertyKey extends string>(tenantId: string | null,
|
|
31
|
+
initializeCategoriesAndTypes<CategoryKey extends string, TypeKey extends string, DocumentPropertyKey extends string>(tenantId: string | null, data: CategoriesAndTypesInitializationData<CategoryKey, TypeKey, DocumentPropertyKey>): Promise<{
|
|
18
32
|
categories: Record<CategoryKey, DocumentCategory>;
|
|
19
33
|
types: Record<TypeKey, DocumentType>;
|
|
20
34
|
properties: Record<DocumentPropertyKey, DocumentProperty>;
|
|
@@ -177,10 +177,10 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
|
|
|
177
177
|
return { templates };
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
|
-
async initializeCategoriesAndTypes(tenantId,
|
|
181
|
-
const categoryEntries = objectEntries(categoryLabels);
|
|
182
|
-
const typeEntries = objectEntries(typeLabels);
|
|
183
|
-
const propertyEntries = objectEntries(
|
|
180
|
+
async initializeCategoriesAndTypes(tenantId, data) {
|
|
181
|
+
const categoryEntries = objectEntries(data.categoryLabels);
|
|
182
|
+
const typeEntries = objectEntries(data.typeLabels);
|
|
183
|
+
const propertyEntries = objectEntries(data.propertyConfigurations);
|
|
184
184
|
const { categoryMap, typeMap, propertyMap } = await this.transaction(async (tx) => {
|
|
185
185
|
const { categories: dbCategories, types: dbTypes } = await this.#documentCategoryTypeService.withTransaction(tx).loadCategoriesAndTypes(tenantId);
|
|
186
186
|
const dbProperties = await this.#documentPropertyService.withTransaction(tx).repository.loadManyByQuery({ tenantId });
|
|
@@ -192,7 +192,7 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
|
|
|
192
192
|
const enumKeyPropertyMap = groupToSingleMap(properties, (property) => property.metadata.attributes[enumTypeKey]);
|
|
193
193
|
for (const [enumKey, label] of categoryEntries) {
|
|
194
194
|
const category = enumKeyCategoryMap.get(enumKey);
|
|
195
|
-
const parentKey = assertDefinedPass(categoryParents[enumKey], `Parent category not defined for ${enumKey}`);
|
|
195
|
+
const parentKey = assertDefinedPass(data.categoryParents[enumKey], `Parent category not defined for ${enumKey}`);
|
|
196
196
|
const parentCategory = isNull(parentKey) ? null : assertDefinedPass(enumKeyCategoryMap.get(parentKey));
|
|
197
197
|
const parentCategoryId = parentCategory?.id ?? null;
|
|
198
198
|
if (isUndefined(category)) {
|
|
@@ -208,7 +208,7 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
|
|
|
208
208
|
}
|
|
209
209
|
for (const [enumKey, label] of typeEntries) {
|
|
210
210
|
const type = enumKeyTypeMap.get(enumKey);
|
|
211
|
-
const enumCategory = typeCategories[enumKey];
|
|
211
|
+
const enumCategory = data.typeCategories[enumKey];
|
|
212
212
|
const category = assertDefinedPass(enumKeyCategoryMap.get(enumCategory));
|
|
213
213
|
if (isUndefined(type)) {
|
|
214
214
|
const type = await this.#documentCategoryTypeService.withTransaction(tx).createType({ tenantId, label, categoryId: category.id, enumKey });
|
|
@@ -234,7 +234,7 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
|
|
|
234
234
|
this.#logger.info(`Updated property ${updatedProperty.label} of type ${updatedProperty.dataType}`);
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
for (const [typeKey, propertyKeys] of objectEntries(typeProperties)) {
|
|
237
|
+
for (const [typeKey, propertyKeys] of objectEntries(data.typeProperties)) {
|
|
238
238
|
const type = assertDefinedPass(enumKeyTypeMap.get(typeKey), `Type ${typeKey} not found.`);
|
|
239
239
|
const newEntities = propertyKeys.map((propertyKey) => ({
|
|
240
240
|
tenantId,
|
|
@@ -134,7 +134,14 @@ async function bootstrap() {
|
|
|
134
134
|
async function main() {
|
|
135
135
|
const tenantId = '00000000-0000-0000-0000-000000000000';
|
|
136
136
|
const [documentManagementService, documentCollectionService] = await injectManyAsync(DocumentManagementService, DocumentCollectionService, DocumentCategoryTypeService, DocumentRequestService);
|
|
137
|
-
const { categories, types } = await documentManagementService.initializeCategoriesAndTypes(tenantId,
|
|
137
|
+
const { categories, types } = await documentManagementService.initializeCategoriesAndTypes(tenantId, {
|
|
138
|
+
categoryLabels: TstdlDocumentCategoryLabels,
|
|
139
|
+
categoryParents: TstdlCategoryParents,
|
|
140
|
+
typeLabels: TstdlDocumentTypeLabels,
|
|
141
|
+
typeCategories: TstdlDocumentTypeCategories,
|
|
142
|
+
propertyConfigurations: TstdlDocumentPropertyConfiguration,
|
|
143
|
+
typeProperties: TstdlDocumentTypeProperties,
|
|
144
|
+
});
|
|
138
145
|
const collectionCount = await documentCollectionService.repository.count();
|
|
139
146
|
if (collectionCount == 0) {
|
|
140
147
|
await documentCollectionService.createCollection(tenantId, null, { metadata: { attributes: { name: 'Objekt ABC' } } });
|