@tstdl/base 0.93.61 → 0.93.62
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/document-management/api/document-management.api.d.ts +8 -8
- package/document-management/models/document-assignment-scope.model.d.ts +3 -4
- package/document-management/models/document-assignment-scope.model.js +5 -9
- package/document-management/models/document-assignment-task.model.d.ts +3 -4
- package/document-management/models/document-assignment-task.model.js +4 -8
- package/document-management/models/document-category.model.d.ts +3 -4
- package/document-management/models/document-category.model.js +4 -8
- package/document-management/models/document-collection-assignment.model.d.ts +2 -3
- package/document-management/models/document-collection-assignment.model.js +4 -9
- package/document-management/models/document-collection.model.d.ts +3 -4
- package/document-management/models/document-collection.model.js +4 -8
- package/document-management/models/document-property-value.model.d.ts +3 -4
- package/document-management/models/document-property-value.model.js +5 -9
- package/document-management/models/document-property.model.d.ts +3 -4
- package/document-management/models/document-property.model.js +3 -7
- package/document-management/models/document-request-collection-assignment.model.d.ts +3 -4
- package/document-management/models/document-request-collection-assignment.model.js +5 -9
- package/document-management/models/document-request-template.d.ts +2 -3
- package/document-management/models/document-request-template.js +4 -9
- package/document-management/models/document-request.model.d.ts +3 -4
- package/document-management/models/document-request.model.js +5 -9
- package/document-management/models/document-requests-template.d.ts +2 -3
- package/document-management/models/document-requests-template.js +2 -7
- package/document-management/models/document-tag-assignment.model.d.ts +3 -4
- package/document-management/models/document-tag-assignment.model.js +5 -9
- package/document-management/models/document-tag.model.d.ts +3 -4
- package/document-management/models/document-tag.model.js +3 -7
- package/document-management/models/document-type-property.model.d.ts +2 -3
- package/document-management/models/document-type-property.model.js +4 -9
- package/document-management/models/document-type-validation.model.d.ts +2 -3
- package/document-management/models/document-type-validation.model.js +4 -9
- package/document-management/models/document-type.model.d.ts +3 -4
- package/document-management/models/document-type.model.js +4 -8
- package/document-management/models/document-validation-definition.model.d.ts +3 -4
- package/document-management/models/document-validation-definition.model.js +3 -7
- package/document-management/models/document-validation-execution-related-document.model.d.ts +3 -4
- package/document-management/models/document-validation-execution-related-document.model.js +5 -9
- package/document-management/models/document-validation-execution.model.d.ts +3 -4
- package/document-management/models/document-validation-execution.model.js +5 -9
- package/document-management/models/document-workflow.model.d.ts +3 -4
- package/document-management/models/document-workflow.model.js +4 -8
- package/document-management/models/document.model.d.ts +3 -4
- package/document-management/models/document.model.js +4 -8
- package/document-management/server/drizzle/0001_lyrical_wong.sql +123 -0
- package/document-management/server/drizzle/meta/0001_snapshot.json +2728 -0
- package/document-management/server/drizzle/meta/_journal.json +7 -0
- package/document-management/server/services/document-category-type.service.d.ts +6 -6
- package/document-management/server/services/document-category-type.service.js +6 -6
- package/document-management/server/services/document-management-ai.service.js +2 -2
- package/document-management/server/services/document-management.service.d.ts +2 -2
- package/document-management/server/services/document-property.service.d.ts +4 -4
- package/document-management/server/services/document-property.service.js +3 -3
- package/document-management/server/services/document-request.service.d.ts +2 -2
- package/document-management/server/services/document-request.service.js +1 -1
- package/document-management/server/services/document-tag.service.d.ts +1 -1
- package/document-management/server/services/document-tag.service.js +2 -2
- package/document-management/server/services/document-validation.service.js +6 -6
- package/document-management/server/services/document.service.js +1 -5
- package/document-management/service-models/document-management.view-model.d.ts +1 -1
- package/document-management/service-models/document-management.view-model.js +1 -1
- package/document-management/service-models/document.service-model.d.ts +4 -4
- package/document-management/service-models/enriched/enriched-document-category.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document-type.view.d.ts +1 -1
- package/orm/decorators.d.ts +18 -7
- package/orm/decorators.js +10 -2
- package/orm/entity.d.ts +2 -2
- package/orm/entity.js +2 -0
- package/orm/server/drizzle/schema-converter.d.ts +3 -3
- package/orm/server/drizzle/schema-converter.js +22 -5
- package/package.json +3 -3
|
@@ -7,29 +7,29 @@ export declare class DocumentCategoryTypeService extends Transactional {
|
|
|
7
7
|
loadCategory(tenantId: string, id: string): Promise<DocumentCategory>;
|
|
8
8
|
loadType(tenantId: string, id: string): Promise<DocumentType>;
|
|
9
9
|
createCategory(data: {
|
|
10
|
-
tenantId: string
|
|
10
|
+
tenantId: string;
|
|
11
11
|
label: string;
|
|
12
12
|
parentId: string | null;
|
|
13
13
|
enumKey?: string;
|
|
14
14
|
}): Promise<DocumentCategory>;
|
|
15
15
|
createType(data: {
|
|
16
|
-
tenantId: string
|
|
16
|
+
tenantId: string;
|
|
17
17
|
label: string;
|
|
18
18
|
categoryId: string;
|
|
19
19
|
enumKey?: string;
|
|
20
20
|
}): Promise<DocumentType>;
|
|
21
|
-
updateCategory(tenantId: string
|
|
21
|
+
updateCategory(tenantId: string, id: string, update: {
|
|
22
22
|
label?: string;
|
|
23
23
|
parentId?: string | null;
|
|
24
24
|
}): Promise<DocumentCategory>;
|
|
25
|
-
updateType(tenantId: string
|
|
25
|
+
updateType(tenantId: string, id: string, update: {
|
|
26
26
|
label?: string;
|
|
27
27
|
categoryId?: string;
|
|
28
28
|
}): Promise<DocumentType>;
|
|
29
29
|
loadCategoryGraph(tenantId: string, categoryId: string): Promise<DocumentCategory[]>;
|
|
30
|
-
loadCategoriesAndTypes(tenantId: string
|
|
30
|
+
loadCategoriesAndTypes(tenantId: string): Promise<{
|
|
31
31
|
categories: DocumentCategory[];
|
|
32
32
|
types: DocumentType[];
|
|
33
33
|
}>;
|
|
34
|
-
loadCategoryViews(tenantId: string
|
|
34
|
+
loadCategoryViews(tenantId: string): Promise<DocumentCategoryView[]>;
|
|
35
35
|
}
|
|
@@ -14,10 +14,10 @@ let DocumentCategoryTypeService = class DocumentCategoryTypeService extends Tran
|
|
|
14
14
|
categoryRepository = injectRepository(DocumentCategory);
|
|
15
15
|
typeRepository = injectRepository(DocumentType);
|
|
16
16
|
async loadCategory(tenantId, id) {
|
|
17
|
-
return await this.categoryRepository.loadByQuery({
|
|
17
|
+
return await this.categoryRepository.loadByQuery({ tenantId, id });
|
|
18
18
|
}
|
|
19
19
|
async loadType(tenantId, id) {
|
|
20
|
-
return await this.typeRepository.loadByQuery({
|
|
20
|
+
return await this.typeRepository.loadByQuery({ tenantId, id });
|
|
21
21
|
}
|
|
22
22
|
async createCategory(data) {
|
|
23
23
|
return await this.categoryRepository.insert({
|
|
@@ -29,7 +29,7 @@ let DocumentCategoryTypeService = class DocumentCategoryTypeService extends Tran
|
|
|
29
29
|
}
|
|
30
30
|
async createType(data) {
|
|
31
31
|
// Ensure the category exists for the tenant before creating the type
|
|
32
|
-
await this.categoryRepository.loadByQuery({ tenantId:
|
|
32
|
+
await this.categoryRepository.loadByQuery({ tenantId: data.tenantId, id: data.categoryId });
|
|
33
33
|
return await this.typeRepository.insert({
|
|
34
34
|
tenantId: data.tenantId,
|
|
35
35
|
label: data.label,
|
|
@@ -44,7 +44,7 @@ let DocumentCategoryTypeService = class DocumentCategoryTypeService extends Tran
|
|
|
44
44
|
return await this.typeRepository.updateByQuery({ tenantId, id }, update);
|
|
45
45
|
}
|
|
46
46
|
async loadCategoryGraph(tenantId, categoryId) {
|
|
47
|
-
const category = await this.categoryRepository.loadByQuery({ tenantId
|
|
47
|
+
const category = await this.categoryRepository.loadByQuery({ tenantId, id: categoryId });
|
|
48
48
|
if (category.parentId == null) {
|
|
49
49
|
return [category];
|
|
50
50
|
}
|
|
@@ -53,8 +53,8 @@ let DocumentCategoryTypeService = class DocumentCategoryTypeService extends Tran
|
|
|
53
53
|
}
|
|
54
54
|
async loadCategoriesAndTypes(tenantId) {
|
|
55
55
|
const [categories, types] = await Promise.all([
|
|
56
|
-
this.categoryRepository.loadManyByQuery({ tenantId
|
|
57
|
-
this.typeRepository.loadManyByQuery({ tenantId
|
|
56
|
+
this.categoryRepository.loadManyByQuery({ tenantId }, { order: 'label' }),
|
|
57
|
+
this.typeRepository.loadManyByQuery({ tenantId }, { order: 'label' }),
|
|
58
58
|
]);
|
|
59
59
|
return { categories, types };
|
|
60
60
|
}
|
|
@@ -154,9 +154,9 @@ let DocumentManagementAiService = DocumentManagementAiService_1 = class Document
|
|
|
154
154
|
if (isNull(document.typeId)) {
|
|
155
155
|
throw new Error(`Document ${document.id} has no type`);
|
|
156
156
|
}
|
|
157
|
-
const typeProperties = await this.#documentTypePropertyRepository.loadManyByQuery({ tenantId
|
|
157
|
+
const typeProperties = await this.#documentTypePropertyRepository.loadManyByQuery({ tenantId, typeId: document.typeId });
|
|
158
158
|
const propertyIds = typeProperties.map((property) => property.propertyId);
|
|
159
|
-
const properties = (propertyIds.length > 0) ? await this.#documentPropertyRepository.loadManyByQuery({ tenantId
|
|
159
|
+
const properties = (propertyIds.length > 0) ? await this.#documentPropertyRepository.loadManyByQuery({ tenantId, id: { $in: propertyIds } }) : undefined;
|
|
160
160
|
const propertiesSchemaEntries = properties?.map((property) => {
|
|
161
161
|
const schema = match(property.dataType)
|
|
162
162
|
.with('text', () => nullable(string()))
|
|
@@ -96,8 +96,8 @@ export declare class DocumentManagementService extends Transactional {
|
|
|
96
96
|
getRelevantDocumentCollectionIds(tenantId: string, documentId: string): Promise<string[]>;
|
|
97
97
|
loadDataStream(tenantId: string, collectionIds: string[], cancellationSignal: CancellationSignal): AsyncGenerator<DocumentManagementData>;
|
|
98
98
|
loadData(tenantId: string, collectionIds: string[]): Promise<DocumentManagementData>;
|
|
99
|
-
loadDocumentRequestsTemplateData(tenantId: string
|
|
100
|
-
initializeCategoriesAndTypes<CategoryKey extends string, TypeKey extends string, DocumentPropertyKey extends string>(tenantId: string
|
|
99
|
+
loadDocumentRequestsTemplateData(tenantId: string): Promise<DocumentRequestsTemplateData>;
|
|
100
|
+
initializeCategoriesAndTypes<CategoryKey extends string, TypeKey extends string, DocumentPropertyKey extends string>(tenantId: string, data: CategoriesAndTypesInitializationData<CategoryKey, TypeKey, DocumentPropertyKey>): Promise<{
|
|
101
101
|
categories: Record<CategoryKey, DocumentCategory>;
|
|
102
102
|
types: Record<TypeKey, DocumentType>;
|
|
103
103
|
properties: Record<DocumentPropertyKey, DocumentProperty>;
|
|
@@ -46,18 +46,18 @@ export declare class DocumentPropertyService extends Transactional {
|
|
|
46
46
|
}, {}, {}>;
|
|
47
47
|
value: import("drizzle-orm").SQL.Aliased<string | number | boolean | null>;
|
|
48
48
|
}, "documentProperties">;
|
|
49
|
-
loadViews(tenantId: string
|
|
49
|
+
loadViews(tenantId: string): Promise<DocumentPropertyView[]>;
|
|
50
50
|
createProperty(data: {
|
|
51
|
-
tenantId: string
|
|
51
|
+
tenantId: string;
|
|
52
52
|
label: string;
|
|
53
53
|
dataType: DocumentPropertyDataType;
|
|
54
54
|
enumKey?: string;
|
|
55
55
|
}): Promise<DocumentProperty>;
|
|
56
|
-
updateProperty(tenantId: string
|
|
56
|
+
updateProperty(tenantId: string, id: string, update: {
|
|
57
57
|
label?: string;
|
|
58
58
|
dataType?: DocumentPropertyDataType;
|
|
59
59
|
}): Promise<DocumentProperty>;
|
|
60
|
-
assignPropertyToType(tenantId: string
|
|
60
|
+
assignPropertyToType(tenantId: string, typeId: string, propertyId: string): Promise<void>;
|
|
61
61
|
loadDocumentPropertyValues(tenantId: string, documentId: OneOrMany<string>, includeNulls?: boolean): Promise<DocumentPropertyValueView[]>;
|
|
62
62
|
setPropertyValues(document: Document, propertyValues: SetDocumentPropertyParameters[]): Promise<void>;
|
|
63
63
|
}
|
|
@@ -46,8 +46,8 @@ let DocumentPropertyService = class DocumentPropertyService extends Transactiona
|
|
|
46
46
|
.innerJoin(documentProperty, and(eq(documentProperty.id, documentTypeProperty.propertyId), or(drizzleIsNull(documentProperty.tenantId), eq(documentProperty.tenantId, document.tenantId))))
|
|
47
47
|
.leftJoin(documentPropertyValue, and(eq(documentPropertyValue.tenantId, document.tenantId), eq(documentPropertyValue.documentId, document.id), eq(documentPropertyValue.propertyId, documentProperty.id))));
|
|
48
48
|
async loadViews(tenantId) {
|
|
49
|
-
const properties = await this.#documentPropertyRepository.loadManyByQuery({ tenantId
|
|
50
|
-
const typeProperties = await this.#documentTypePropertyRepository.loadManyByQuery({ tenantId
|
|
49
|
+
const properties = await this.#documentPropertyRepository.loadManyByQuery({ tenantId });
|
|
50
|
+
const typeProperties = await this.#documentTypePropertyRepository.loadManyByQuery({ tenantId });
|
|
51
51
|
return properties.map((property) => {
|
|
52
52
|
const typeIds = typeProperties
|
|
53
53
|
.filter((typeProperty) => typeProperty.propertyId == property.id)
|
|
@@ -94,7 +94,7 @@ let DocumentPropertyService = class DocumentPropertyService extends Transactiona
|
|
|
94
94
|
}
|
|
95
95
|
await this.transaction(async (tx) => {
|
|
96
96
|
const propertyIds = propertyValues.map((property) => property.propertyId);
|
|
97
|
-
const properties = await this.#documentPropertyRepository.withTransaction(tx).loadManyByQuery({ tenantId:
|
|
97
|
+
const properties = await this.#documentPropertyRepository.withTransaction(tx).loadManyByQuery({ tenantId: document.tenantId, id: { $in: propertyIds } });
|
|
98
98
|
const propertiesMap = getEntityMap(properties);
|
|
99
99
|
const upserts = propertyValues.filter((value) => isNotNull(value.value)).map(({ propertyId, value, metadata }) => {
|
|
100
100
|
const property = propertiesMap.get(propertyId);
|
|
@@ -5,8 +5,8 @@ import type { RequestStats } from '../../service-models/index.js';
|
|
|
5
5
|
export declare class DocumentRequestService extends Transactional {
|
|
6
6
|
#private;
|
|
7
7
|
getRequestStats(tenantId: string, collectionIds: OneOrMany<string>): Promise<RequestStats>;
|
|
8
|
-
createRequestsTemplate(tenantId: string
|
|
9
|
-
updateRequestsTemplate(tenantId: string
|
|
8
|
+
createRequestsTemplate(tenantId: string, parameters: Pick<DocumentRequestsTemplate, 'label' | 'description'>): Promise<DocumentRequestsTemplate>;
|
|
9
|
+
updateRequestsTemplate(tenantId: string, id: string, parameters: Pick<DocumentRequestsTemplate, 'label' | 'description' | 'metadata'>): Promise<DocumentRequestsTemplate>;
|
|
10
10
|
applyRequestsTemplate(tenantId: string, id: string, collectionIds: string[]): Promise<void>;
|
|
11
11
|
deleteRequestsTemplate(tenantId: string, id: string): Promise<DocumentRequestsTemplate>;
|
|
12
12
|
createRequestTemplate(tenantId: string, requestsTemplateId: string, typeId: string, comment: string): Promise<DocumentRequestTemplate>;
|
|
@@ -46,7 +46,7 @@ let DocumentRequestService = class DocumentRequestService extends Transactional
|
|
|
46
46
|
return await this.#documentRequestsTemplateRepository.updateByQuery({ tenantId, id }, parameters);
|
|
47
47
|
}
|
|
48
48
|
async applyRequestsTemplate(tenantId, id, collectionIds) {
|
|
49
|
-
const requestTemplates = await this.#documentRequestTemplateRepository.loadManyByQuery({ tenantId
|
|
49
|
+
const requestTemplates = await this.#documentRequestTemplateRepository.loadManyByQuery({ tenantId, requestsTemplateId: id });
|
|
50
50
|
await this.transaction(async (tx) => {
|
|
51
51
|
for (const { typeId, comment } of requestTemplates) {
|
|
52
52
|
await this.withTransaction(tx).createRequest(tenantId, typeId, collectionIds, comment);
|
|
@@ -3,7 +3,7 @@ import { DocumentTag, DocumentTagAssignment, type Document } from '../../models/
|
|
|
3
3
|
export declare class DocumentTagService extends Transactional {
|
|
4
4
|
readonly tagRepository: import("../../../orm/server/index.js").EntityRepository<DocumentTag>;
|
|
5
5
|
readonly tagAssignmentRepository: import("../../../orm/server/index.js").EntityRepository<DocumentTagAssignment>;
|
|
6
|
-
loadTags(tenantId: string
|
|
6
|
+
loadTags(tenantId: string): Promise<DocumentTag[]>;
|
|
7
7
|
loadOrCreate(tenantId: string, labels: string[]): Promise<DocumentTag[]>;
|
|
8
8
|
loadDocumentTags(tenantId: string, documentId: string): Promise<DocumentTag[]>;
|
|
9
9
|
assignTags(document: Document, labels: string[]): Promise<void>;
|
|
@@ -14,7 +14,7 @@ let DocumentTagService = class DocumentTagService extends Transactional {
|
|
|
14
14
|
tagRepository = injectRepository(DocumentTag);
|
|
15
15
|
tagAssignmentRepository = injectRepository(DocumentTagAssignment);
|
|
16
16
|
async loadTags(tenantId) {
|
|
17
|
-
return await this.tagRepository.loadManyByQuery({ tenantId
|
|
17
|
+
return await this.tagRepository.loadManyByQuery({ tenantId }, { order: { label: 'asc' } });
|
|
18
18
|
}
|
|
19
19
|
async loadOrCreate(tenantId, labels) {
|
|
20
20
|
if (labels.length === 0) {
|
|
@@ -22,7 +22,7 @@ let DocumentTagService = class DocumentTagService extends Transactional {
|
|
|
22
22
|
}
|
|
23
23
|
return await this.tagRepository.transaction(async (tx) => {
|
|
24
24
|
const existingTags = await this.tagRepository.withTransaction(tx).loadManyByQuery({
|
|
25
|
-
tenantId
|
|
25
|
+
tenantId,
|
|
26
26
|
label: { $in: labels },
|
|
27
27
|
});
|
|
28
28
|
const newLabels = labels.filter((label) => !existingTags.some((tag) => tag.label == label));
|
|
@@ -56,9 +56,9 @@ let DocumentValidationService = DocumentValidationService_1 = class DocumentVali
|
|
|
56
56
|
throw new BadRequestError('Document has no type');
|
|
57
57
|
}
|
|
58
58
|
const workflow = await this.#documentWorkflowService.initiateWorkflow(document.tenantId, documentId, DocumentWorkflowStep.Validation);
|
|
59
|
-
const typeValidations = await this.#documentTypeValidationService.loadManyByQuery({ tenantId
|
|
59
|
+
const typeValidations = await this.#documentTypeValidationService.loadManyByQuery({ tenantId, typeId: document.typeId });
|
|
60
60
|
for (const typeValidation of typeValidations) {
|
|
61
|
-
const validationDefinition = await this.#validationDefinitionService.loadByQuery({ tenantId
|
|
61
|
+
const validationDefinition = await this.#validationDefinitionService.loadByQuery({ tenantId, id: typeValidation.validationId });
|
|
62
62
|
const execution = await this.#validationExecutionService.insert({
|
|
63
63
|
tenantId: document.tenantId,
|
|
64
64
|
definitionId: validationDefinition.id,
|
|
@@ -95,15 +95,15 @@ let DocumentValidationService = DocumentValidationService_1 = class DocumentVali
|
|
|
95
95
|
}
|
|
96
96
|
const [documentCollections, documentTypeProperties, type] = await Promise.all([
|
|
97
97
|
this.#documentCollectionAssignmentRepository.loadManyByQuery({ tenantId, documentId: document.id }),
|
|
98
|
-
this.#documentTypePropertyService.loadManyByQuery({ tenantId
|
|
99
|
-
this.#documentTypeService.loadByQuery({ tenantId
|
|
98
|
+
this.#documentTypePropertyService.loadManyByQuery({ tenantId, typeId: document.typeId }),
|
|
99
|
+
this.#documentTypeService.loadByQuery({ tenantId, id: document.typeId }),
|
|
100
100
|
]);
|
|
101
101
|
const documentCollectionIds = getEntityIds(documentCollections);
|
|
102
102
|
const documentPropertyIds = getEntityIds(documentTypeProperties);
|
|
103
103
|
const [collections, category, properties, propertyValues] = await Promise.all([
|
|
104
104
|
this.#documentManagementService.loadManyByQuery({ tenantId, id: { $in: documentCollectionIds } }),
|
|
105
|
-
this.#documentCategoryService.loadByQuery({ tenantId
|
|
106
|
-
this.#documentPropertyService.loadManyByQuery({ tenantId
|
|
105
|
+
this.#documentCategoryService.loadByQuery({ tenantId, id: type.categoryId }),
|
|
106
|
+
this.#documentPropertyService.loadManyByQuery({ tenantId, id: { $in: documentPropertyIds } }),
|
|
107
107
|
this.#documentPropertyValueService.loadManyByQuery({ tenantId, documentId: document.id }),
|
|
108
108
|
]);
|
|
109
109
|
return {
|
|
@@ -16,7 +16,7 @@ import { toArray } from '../../../utils/array/index.js';
|
|
|
16
16
|
import { objectKeys } from '../../../utils/object/object.js';
|
|
17
17
|
import { readableStreamFromPromise } from '../../../utils/stream/from-promise.js';
|
|
18
18
|
import { tryIgnoreLogAsync } from '../../../utils/try-ignore.js';
|
|
19
|
-
import { isDefined, isNotReadableStream, isNotUint8Array,
|
|
19
|
+
import { isDefined, isNotReadableStream, isNotUint8Array, isUndefined } from '../../../utils/type-guards.js';
|
|
20
20
|
import { Document, DocumentApproval, DocumentAssignmentScope, DocumentAssignmentTask, DocumentType, DocumentWorkflowStep } from '../../models/index.js';
|
|
21
21
|
import { DocumentCollectionService } from './document-collection.service.js';
|
|
22
22
|
import { DocumentFileService } from './document-file.service.js';
|
|
@@ -42,10 +42,6 @@ let DocumentService = DocumentService_1 = class DocumentService extends Transact
|
|
|
42
42
|
async create(tenantId, { typeId, title, subtitle, date, summary, tags, approval, comment, originalFileName, assignment, properties, metadata }, contentSource, { createUserId }) {
|
|
43
43
|
const document = await this.transaction(async (tx) => {
|
|
44
44
|
const isUpload = isNotUint8Array(contentSource) && isNotReadableStream(contentSource);
|
|
45
|
-
if (isString(typeId)) {
|
|
46
|
-
// verify that the type exists for the tenant
|
|
47
|
-
await this.#documentTypeRepository.loadByQuery({ tenantId: { $or: [null, tenantId] }, id: typeId });
|
|
48
|
-
}
|
|
49
45
|
const document = await this.repository.withTransaction(tx).insert({
|
|
50
46
|
tenantId,
|
|
51
47
|
typeId: typeId ?? null,
|
|
@@ -40,7 +40,7 @@ export declare class DocumentRequestView extends DocumentRequest {
|
|
|
40
40
|
}
|
|
41
41
|
export declare class DocumentPropertyView implements TypedOmit<DocumentProperty, 'metadata'> {
|
|
42
42
|
id: string;
|
|
43
|
-
tenantId: string
|
|
43
|
+
tenantId: string;
|
|
44
44
|
label: string;
|
|
45
45
|
dataType: DocumentPropertyDataType;
|
|
46
46
|
typeIds: string[];
|
|
@@ -144,7 +144,7 @@ __decorate([
|
|
|
144
144
|
], DocumentPropertyView.prototype, "id", void 0);
|
|
145
145
|
__decorate([
|
|
146
146
|
StringProperty({ nullable: true }),
|
|
147
|
-
__metadata("design:type",
|
|
147
|
+
__metadata("design:type", String)
|
|
148
148
|
], DocumentPropertyView.prototype, "tenantId", void 0);
|
|
149
149
|
__decorate([
|
|
150
150
|
StringProperty(),
|
|
@@ -20,10 +20,10 @@ export declare const updateDocumentCollectionsParametersSchema: import("../../sc
|
|
|
20
20
|
}>;
|
|
21
21
|
export declare const createDocumentParametersSchema: import("../../schema/index.js").ObjectSchema<{
|
|
22
22
|
date?: import("../../orm/index.js").NumericDate | null | undefined;
|
|
23
|
+
summary?: string | null | undefined;
|
|
23
24
|
title?: string | null | undefined;
|
|
24
25
|
typeId?: import("../../orm/index.js").Uuid | null | undefined;
|
|
25
26
|
subtitle?: string | null | undefined;
|
|
26
|
-
summary?: string | null | undefined;
|
|
27
27
|
comment?: string | null | undefined;
|
|
28
28
|
approval?: import("../models/document.model.js").DocumentApproval | undefined;
|
|
29
29
|
originalFileName?: string | null | undefined;
|
|
@@ -97,7 +97,7 @@ export declare const createDocumentRequestsTemplateParametersSchema: import("../
|
|
|
97
97
|
export declare const updateDocumentRequestsTemplateParametersSchema: import("../../schema/index.js").ObjectSchema<{
|
|
98
98
|
id: import("../../orm/index.js").IsPrimaryKey<import("../../orm/index.js").HasDefault<import("../../orm/index.js").Uuid>>;
|
|
99
99
|
description?: string | null | undefined;
|
|
100
|
-
tenantId?:
|
|
100
|
+
tenantId?: import("../../orm/index.js").Uuid | undefined;
|
|
101
101
|
label?: string | undefined;
|
|
102
102
|
metadata?: Partial<{
|
|
103
103
|
attributes: import("../../orm/index.js").HasDefault<import("../../orm/index.js").Json<import("../../orm/index.js").EntityMetadataAttributes>>;
|
|
@@ -126,7 +126,7 @@ export declare const createDocumentRequestTemplateParametersSchema: import("../.
|
|
|
126
126
|
}>;
|
|
127
127
|
export declare const updateDocumentRequestTemplateParametersSchema: import("../../schema/index.js").ObjectSchema<{
|
|
128
128
|
id: import("../../orm/index.js").IsPrimaryKey<import("../../orm/index.js").HasDefault<import("../../orm/index.js").Uuid>>;
|
|
129
|
-
tenantId?:
|
|
129
|
+
tenantId?: import("../../orm/index.js").Uuid | undefined;
|
|
130
130
|
typeId?: import("../../orm/index.js").Uuid | undefined;
|
|
131
131
|
comment?: string | null | undefined;
|
|
132
132
|
metadata?: Partial<{
|
|
@@ -181,8 +181,8 @@ export declare const setDocumentPropertiesParametersSchema: import("../../schema
|
|
|
181
181
|
documentId: string;
|
|
182
182
|
}>;
|
|
183
183
|
export declare const createDocumentCategoryParametersSchema: import("../../schema/index.js").ObjectSchema<{
|
|
184
|
-
parentId: import("../../orm/index.js").Uuid | null;
|
|
185
184
|
label: string;
|
|
185
|
+
parentId: import("../../orm/index.js").Uuid | null;
|
|
186
186
|
metadata?: Partial<{
|
|
187
187
|
attributes: import("../../orm/index.js").HasDefault<import("../../orm/index.js").Json<import("../../orm/index.js").EntityMetadataAttributes>>;
|
|
188
188
|
}> | undefined;
|
|
@@ -6,7 +6,7 @@ import type { EnrichedDocument } from './enriched-document.view.js';
|
|
|
6
6
|
export declare class EnrichedDocumentCategory implements TypedOmit<DocumentCategory, 'parentId' | 'metadata'> {
|
|
7
7
|
#private;
|
|
8
8
|
readonly id: string;
|
|
9
|
-
readonly tenantId: string
|
|
9
|
+
readonly tenantId: string;
|
|
10
10
|
readonly label: string;
|
|
11
11
|
readonly parent: EnrichedDocumentCategory | null;
|
|
12
12
|
readonly helper: {
|
|
@@ -6,7 +6,7 @@ import type { EnrichedDocumentManagementData } from './enriched-document-managem
|
|
|
6
6
|
export declare class EnrichedDocumentType implements TypedOmit<DocumentType, 'categoryId' | 'metadata'> {
|
|
7
7
|
#private;
|
|
8
8
|
readonly id: string;
|
|
9
|
-
readonly tenantId: string
|
|
9
|
+
readonly tenantId: string;
|
|
10
10
|
readonly label: string;
|
|
11
11
|
readonly category: EnrichedDocumentCategory;
|
|
12
12
|
readonly helper: {
|
package/orm/decorators.d.ts
CHANGED
|
@@ -63,10 +63,8 @@ export type OrmColumnReflectionData = {
|
|
|
63
63
|
type: AbstractConstructor;
|
|
64
64
|
prefix?: string | null;
|
|
65
65
|
};
|
|
66
|
-
references?:
|
|
67
|
-
|
|
68
|
-
targetColumn?: TargetColumnPath<any>;
|
|
69
|
-
}[];
|
|
66
|
+
references?: ReferenceReflectionData[];
|
|
67
|
+
tenantReference?: TypedOmit<ReferenceReflectionData, 'excludeTenant'>[];
|
|
70
68
|
paradeField?: ParadeFieldOptions;
|
|
71
69
|
tsVector?: TsVectorOptions<any>;
|
|
72
70
|
encrypted?: boolean;
|
|
@@ -75,6 +73,11 @@ export type OrmColumnReflectionData = {
|
|
|
75
73
|
mode: 'soft' | 'hard';
|
|
76
74
|
};
|
|
77
75
|
};
|
|
76
|
+
type ReferenceReflectionData<T extends AnyEntity = AnyEntity> = {
|
|
77
|
+
target: () => EntityType<T>;
|
|
78
|
+
targetColumn?: TargetColumnPath<T>;
|
|
79
|
+
excludeTenant?: boolean;
|
|
80
|
+
};
|
|
78
81
|
/**
|
|
79
82
|
* Reflection data for unique constraints.
|
|
80
83
|
*/
|
|
@@ -236,8 +239,17 @@ export declare function PrimaryKeyProperty(): PropertyDecorator;
|
|
|
236
239
|
* Define a foreign key relationship.
|
|
237
240
|
* @param type A function returning the referenced entity type.
|
|
238
241
|
*/
|
|
239
|
-
export declare function
|
|
240
|
-
export declare function
|
|
242
|
+
export declare function Reference<T extends AnyEntity>(target: () => EntityType<T>, targetColumn?: TargetColumnPath<T>): PropertyDecorator;
|
|
243
|
+
export declare function Reference<T extends AnyEntity>(target: () => EntityType, options?: TypedOmit<ReferenceReflectionData<T>, 'target'>): PropertyDecorator;
|
|
244
|
+
export {
|
|
245
|
+
/** @deprecated use {@link Reference} instead. */
|
|
246
|
+
Reference as References };
|
|
247
|
+
/**
|
|
248
|
+
* Define a foreign key relationship.
|
|
249
|
+
* @param type A function returning the referenced entity type.
|
|
250
|
+
*/
|
|
251
|
+
export declare function TenantReference(target: () => EntityType): PropertyDecorator;
|
|
252
|
+
export declare function TenantReference<T extends AnyEntity>(target: () => EntityType<T>, targetColumn?: TargetColumnPath<T>): PropertyDecorator;
|
|
241
253
|
/**
|
|
242
254
|
* Define a table check constraint.
|
|
243
255
|
* @template T The entity type.
|
|
@@ -375,4 +387,3 @@ export declare function ParadeIndex<T extends BaseEntity>(options: ParadeIndexRe
|
|
|
375
387
|
export declare function ParadeIndex(options?: ParadeFieldOptions): PropertyDecorator;
|
|
376
388
|
export declare function ParadeCompoundIndex<T extends BaseEntity>(alias: string, compoundColumns: ParadeIndexCompoundColumnColumnsProvider<T>, options?: TypedOmit<ParadeFieldOptions, 'alias'>): ClassDecorator;
|
|
377
389
|
export declare function ParadeExpressionIndex<T extends BaseEntity>(alias: string, expression: ParadeIndexExpressionProvider<T>, options?: TypedOmit<ParadeFieldOptions, 'alias'>): ClassDecorator;
|
|
378
|
-
export {};
|
package/orm/decorators.js
CHANGED
|
@@ -68,8 +68,16 @@ export function Column(options) {
|
|
|
68
68
|
export function PrimaryKeyProperty() {
|
|
69
69
|
return createColumnDecorator({ primaryKey: true });
|
|
70
70
|
}
|
|
71
|
-
export function
|
|
72
|
-
|
|
71
|
+
export function Reference(target, targetColumnOrOptions) {
|
|
72
|
+
const targetColumn = (isString(targetColumnOrOptions) ? targetColumnOrOptions : targetColumnOrOptions?.targetColumn);
|
|
73
|
+
const options = isString(targetColumnOrOptions) ? undefined : targetColumnOrOptions;
|
|
74
|
+
return createColumnDecorator({ references: [{ target, targetColumn, excludeTenant: options?.excludeTenant }] });
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
/** @deprecated use {@link Reference} instead. */
|
|
78
|
+
Reference as References };
|
|
79
|
+
export function TenantReference(target, targetColumn) {
|
|
80
|
+
return createColumnDecorator({ tenantReference: [{ target, targetColumn: targetColumn }] });
|
|
73
81
|
}
|
|
74
82
|
/**
|
|
75
83
|
* Define a table check constraint.
|
package/orm/entity.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AbstractType } from '../types/index.js';
|
|
2
2
|
import type { Embedded, HasDefault, IsPrimaryKey, Json, Timestamp, Uuid } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Represents the type (constructor) of an entity, potentially holding an entity name.
|
|
5
5
|
* @template T - The entity class type.
|
|
6
6
|
*/
|
|
7
|
-
export interface EntityType<T extends BaseEntity = BaseEntity | Entity> extends
|
|
7
|
+
export interface EntityType<T extends BaseEntity = BaseEntity | Entity> extends AbstractType<T> {
|
|
8
8
|
readonly entityName?: string;
|
|
9
9
|
}
|
|
10
10
|
export type AnyEntity = BaseEntity | Entity;
|
package/orm/entity.js
CHANGED
|
@@ -81,6 +81,7 @@ export class TenantEntity extends Entity {
|
|
|
81
81
|
tenantId;
|
|
82
82
|
}
|
|
83
83
|
__decorate([
|
|
84
|
+
PrimaryKeyProperty(),
|
|
84
85
|
UuidProperty(),
|
|
85
86
|
__metadata("design:type", String)
|
|
86
87
|
], TenantEntity.prototype, "tenantId", void 0);
|
|
@@ -88,6 +89,7 @@ export class TenantBaseEntity extends BaseEntity {
|
|
|
88
89
|
tenantId;
|
|
89
90
|
}
|
|
90
91
|
__decorate([
|
|
92
|
+
PrimaryKeyProperty(),
|
|
91
93
|
UuidProperty(),
|
|
92
94
|
__metadata("design:type", String)
|
|
93
95
|
], TenantBaseEntity.prototype, "tenantId", void 0);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type PgEnum, type PgSchema, type PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
2
|
+
import type { Enumeration } from '../../../types/index.js';
|
|
3
|
+
import { type EntityType } from '../../entity.js';
|
|
4
4
|
import type { ColumnDefinition, ColumnDefinitionsMap, PgTableFromType } from '../types.js';
|
|
5
5
|
type ConverterContext = {
|
|
6
|
-
type:
|
|
6
|
+
type: EntityType;
|
|
7
7
|
property: string;
|
|
8
8
|
};
|
|
9
9
|
export declare const getDrizzleTableFromType: typeof _getDrizzleTableFromType;
|
|
@@ -11,11 +11,13 @@ import { compareByValueSelectionToOrder, orderRest } from '../../../utils/compar
|
|
|
11
11
|
import { decodeText, encodeUtf8 } from '../../../utils/encoding.js';
|
|
12
12
|
import { enumValues } from '../../../utils/enum.js';
|
|
13
13
|
import { memoize, memoizeSingle } from '../../../utils/function/memoize.js';
|
|
14
|
+
import { typeExtends } from '../../../utils/index.js';
|
|
14
15
|
import { compileDereferencer } from '../../../utils/object/dereference.js';
|
|
15
16
|
import { fromEntries, mapObjectKeysToSnakeCase, objectEntries } from '../../../utils/object/object.js';
|
|
16
17
|
import { assertDefined, assertDefinedPass, isArray, isDefined, isNotNull, isNotNullOrUndefined, isNull, isString, isUndefined } from '../../../utils/type-guards.js';
|
|
17
18
|
import { resolveValueOrProvider } from '../../../utils/value-or-provider.js';
|
|
18
19
|
import { bytea, numericDate, timestamp, tsvector } from '../../data-types/index.js';
|
|
20
|
+
import { TenantBaseEntity, TenantEntity } from '../../entity.js';
|
|
19
21
|
import { getEnumName } from '../../enums.js';
|
|
20
22
|
import { JsonSchema, NumericDateSchema, NumericSchema, TimestampSchema, TsVectorSchema, UuidSchema } from '../../schemas/index.js';
|
|
21
23
|
import { decryptBytes, encryptBytes } from '../encryption.js';
|
|
@@ -87,7 +89,9 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
87
89
|
return builder;
|
|
88
90
|
}
|
|
89
91
|
function buildPrimaryKey(table) {
|
|
90
|
-
const columns = primaryKeyColumnDefinitions
|
|
92
|
+
const columns = primaryKeyColumnDefinitions
|
|
93
|
+
.toSorted(compareByValueSelectionToOrder(['tenantId', 'id', orderRest], (columnDefinition) => columnDefinition.name))
|
|
94
|
+
.map((columnDefinition) => table[columnDefinition.name]);
|
|
91
95
|
return primaryKey({
|
|
92
96
|
name: mergedTableReflectionData.compoundPrimaryKeyName ?? getPrimaryKeyName(tableName, columns, { naming: mergedTableReflectionData.compoundPrimaryKeyNaming }),
|
|
93
97
|
columns,
|
|
@@ -185,6 +189,17 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
185
189
|
}
|
|
186
190
|
return buildIndex(table, indexData, columnDefinition.name);
|
|
187
191
|
}).filter(isDefined)),
|
|
192
|
+
...columnDefinitions.flatMap((columnDefinition) => {
|
|
193
|
+
return columnDefinition.reflectionData?.tenantReference?.map((tenantReferenceData) => {
|
|
194
|
+
const foreignTable = getDrizzleTableFromType(tenantReferenceData.target(), dbSchema.schemaName);
|
|
195
|
+
const nonTenantColumn = tenantReferenceData.targetColumn ?? 'id';
|
|
196
|
+
return foreignKey({
|
|
197
|
+
name: getForeignKeyName(tableName, [nonTenantColumn]),
|
|
198
|
+
columns: [getColumn(table, 'tenantId'), getColumn(table, columnDefinition.name)],
|
|
199
|
+
foreignColumns: [getColumn(foreignTable, 'tenantId'), getColumn(foreignTable, nonTenantColumn)],
|
|
200
|
+
});
|
|
201
|
+
}) ?? [];
|
|
202
|
+
}),
|
|
188
203
|
...tableReflectionDatas.flatMap((tableReflectionData) => {
|
|
189
204
|
return tableReflectionData.foreignKeys?.map((foreignKeyData) => {
|
|
190
205
|
const foreignTable = getDrizzleTableFromType(foreignKeyData.target(), dbSchema.schemaName);
|
|
@@ -283,14 +298,16 @@ function getPostgresColumn(tableName, columnName, dbSchema, propertySchema, refl
|
|
|
283
298
|
if ((reflectionData.primaryKey == true) && (options.skipPrimaryKey != true)) {
|
|
284
299
|
column = column.primaryKey();
|
|
285
300
|
}
|
|
286
|
-
for (const { target, targetColumn } of reflectionData.references ?? []) {
|
|
301
|
+
for (const { target, targetColumn, excludeTenant } of reflectionData.references ?? []) {
|
|
287
302
|
column = column.references(() => {
|
|
288
|
-
const
|
|
303
|
+
const targetType = target();
|
|
304
|
+
if ((excludeTenant != true) && (typeExtends(context.type, TenantBaseEntity) || typeExtends(context.type, TenantEntity)) && (typeExtends(targetType, TenantBaseEntity) || typeExtends(targetType, TenantEntity))) {
|
|
305
|
+
throw new Error(`${context.type.entityName ?? context.type.name} references ${targetType.entityName ?? targetType.name} via ${targetColumn ?? 'id'} without tenantId. This may lead to data integrity issues. Use \`@TenantReference()\` or set \`excludeTenant: true\` in the Reference decorator options to avoid this warning.`);
|
|
306
|
+
}
|
|
307
|
+
const targetTable = getDrizzleTableFromType(targetType, dbSchema.schemaName);
|
|
289
308
|
return targetTable[(targetColumn ?? 'id')];
|
|
290
309
|
});
|
|
291
310
|
}
|
|
292
|
-
if (isDefined(reflectionData.references)) {
|
|
293
|
-
}
|
|
294
311
|
return column;
|
|
295
312
|
}
|
|
296
313
|
function getPostgresBaseColumn(columnName, dbSchema, schema, reflectionData, context) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.93.
|
|
3
|
+
"version": "0.93.62",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -138,8 +138,8 @@
|
|
|
138
138
|
"type-fest": "^5.3"
|
|
139
139
|
},
|
|
140
140
|
"peerDependencies": {
|
|
141
|
-
"@google-cloud/storage": "^7.
|
|
142
|
-
"@google/genai": "^1.
|
|
141
|
+
"@google-cloud/storage": "^7.18",
|
|
142
|
+
"@google/genai": "^1.31",
|
|
143
143
|
"@tstdl/angular": "^0.93",
|
|
144
144
|
"@zxcvbn-ts/core": "^3.0",
|
|
145
145
|
"@zxcvbn-ts/language-common": "^3.0",
|