@tstdl/base 0.92.141 → 0.92.143
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-file.service.js +1 -1
- package/ai/ai.service.js +3 -3
- package/ai/types.d.ts +1 -1
- package/api/client/client.d.ts +1 -1
- package/api/client/client.js +10 -4
- package/api/server/middlewares/content-type.middleware.js +8 -7
- package/api/types.js +1 -1
- package/authentication/client/authentication.service.js +3 -3
- package/authentication/server/authentication-ancillary.service.d.ts +11 -1
- package/authentication/server/authentication-ancillary.service.js +1 -1
- package/authentication/server/authentication-secret-requirements.validator.js +1 -1
- package/authentication/server/authentication.api-controller.js +22 -10
- package/authentication/server/authentication.service.d.ts +11 -5
- package/authentication/server/authentication.service.js +97 -49
- package/authentication/server/drizzle.config.js +2 -2
- package/authentication/server/module.js +1 -1
- package/cancellation/token.d.ts +2 -2
- package/cancellation/token.js +4 -4
- package/cookie/cookie.js +2 -2
- package/css/css-variables.js +1 -1
- package/document-management/api/document-management.api.d.ts +122 -24
- package/document-management/api/document-management.api.js +17 -0
- package/document-management/{server/services → authorization}/document-management-authorization.service.d.ts +7 -7
- package/document-management/authorization/document-management-authorization.service.js +2 -0
- package/document-management/authorization/index.d.ts +2 -0
- package/document-management/authorization/index.js +2 -0
- package/document-management/authorization/policies.d.ts +38 -0
- package/document-management/authorization/policies.js +2 -0
- package/document-management/index.d.ts +1 -0
- package/document-management/index.js +1 -0
- package/document-management/models/document-assignment-scope.model.d.ts +1 -0
- package/document-management/models/document-assignment-scope.model.js +10 -3
- package/document-management/models/document-assignment-task.model.d.ts +1 -0
- package/document-management/models/document-assignment-task.model.js +8 -2
- package/document-management/models/document-category.model.d.ts +1 -0
- package/document-management/models/document-category.model.js +7 -1
- package/document-management/models/document-collection-assignment.model.d.ts +1 -0
- package/document-management/models/document-collection-assignment.model.js +12 -4
- package/document-management/models/document-collection.model.d.ts +2 -0
- package/document-management/models/document-collection.model.js +8 -2
- package/document-management/models/document-management-table.d.ts +3 -1
- package/document-management/models/document-management-table.js +2 -2
- package/document-management/models/document-property-value.model.d.ts +1 -0
- package/document-management/models/document-property-value.model.js +9 -3
- package/document-management/models/document-property.model.d.ts +1 -0
- package/document-management/models/document-property.model.js +8 -2
- package/document-management/models/document-request-collection-assignment.model.d.ts +1 -0
- package/document-management/models/document-request-collection-assignment.model.js +12 -4
- package/document-management/models/document-request-template.d.ts +1 -0
- package/document-management/models/document-request-template.js +6 -1
- package/document-management/models/document-request.model.d.ts +1 -0
- package/document-management/models/document-request.model.js +10 -1
- package/document-management/models/document-requests-template.d.ts +1 -0
- package/document-management/models/document-requests-template.js +7 -3
- package/document-management/models/document-tag-assignment.model.d.ts +8 -0
- package/document-management/models/document-tag-assignment.model.js +40 -0
- package/document-management/models/document-tag.model.d.ts +6 -0
- package/document-management/models/{document-request-submission.model.js → document-tag.model.js} +14 -18
- package/document-management/models/document-type-property.model.d.ts +1 -0
- package/document-management/models/document-type-property.model.js +7 -2
- package/document-management/models/document-type-validation.model.d.ts +1 -0
- package/document-management/models/document-type-validation.model.js +8 -2
- package/document-management/models/document-type.model.d.ts +1 -0
- package/document-management/models/document-type.model.js +7 -2
- package/document-management/models/document-validation-definition.model.d.ts +1 -0
- package/document-management/models/document-validation-definition.model.js +7 -2
- package/document-management/models/document-validation-execution-related-document.model.d.ts +1 -0
- package/document-management/models/document-validation-execution-related-document.model.js +10 -3
- package/document-management/models/document-validation-execution.model.d.ts +1 -0
- package/document-management/models/document-validation-execution.model.js +9 -3
- package/document-management/models/document-workflow.model.d.ts +4 -1
- package/document-management/models/document-workflow.model.js +16 -4
- package/document-management/models/document.model.d.ts +2 -2
- package/document-management/models/document.model.js +9 -8
- package/document-management/models/index.d.ts +2 -1
- package/document-management/models/index.js +2 -1
- package/document-management/server/api/document-management.api.d.ts +4 -1
- package/document-management/server/api/document-management.api.js +113 -22
- package/document-management/server/configure.d.ts +2 -2
- package/document-management/server/configure.js +7 -7
- package/document-management/server/drizzle/0000_parallel_mantis.sql +359 -0
- package/document-management/server/drizzle/meta/0000_snapshot.json +784 -260
- package/document-management/server/drizzle/meta/_journal.json +2 -2
- package/document-management/server/module.d.ts +2 -2
- package/document-management/server/module.js +2 -2
- package/document-management/server/schemas.d.ts +6 -5
- package/document-management/server/schemas.js +12 -11
- package/document-management/server/services/document-category-type.service.d.ts +19 -10
- package/document-management/server/services/document-category-type.service.js +34 -27
- package/document-management/server/services/document-collection.service.d.ts +13 -6
- package/document-management/server/services/document-collection.service.js +36 -12
- package/document-management/server/services/document-file.service.d.ts +8 -7
- package/document-management/server/services/document-file.service.js +28 -33
- package/document-management/server/services/document-management-ai.service.d.ts +5 -4
- package/document-management/server/services/document-management-ai.service.js +51 -28
- package/document-management/server/services/document-management-ancillary.service.d.ts +3 -21
- package/document-management/server/services/document-management-ancillary.service.js +0 -24
- package/document-management/server/services/document-management-observation.service.d.ts +15 -0
- package/document-management/server/services/document-management-observation.service.js +160 -0
- package/document-management/server/services/document-management.service.d.ts +6 -5
- package/document-management/server/services/document-management.service.js +112 -86
- package/document-management/server/services/document-property.service.d.ts +15 -7
- package/document-management/server/services/document-property.service.js +52 -20
- package/document-management/server/services/document-request.service.d.ts +13 -24
- package/document-management/server/services/document-request.service.js +39 -62
- package/document-management/server/services/document-tag.service.d.ts +10 -0
- package/document-management/server/services/document-tag.service.js +59 -0
- package/document-management/server/services/document-validation.service.d.ts +8 -8
- package/document-management/server/services/document-validation.service.js +41 -40
- package/document-management/server/services/document-workflow.service.d.ts +6 -5
- package/document-management/server/services/document-workflow.service.js +54 -43
- package/document-management/server/services/document.service.d.ts +12 -11
- package/document-management/server/services/document.service.js +64 -40
- package/document-management/server/services/index.d.ts +2 -1
- package/document-management/server/services/index.js +2 -1
- package/document-management/server/services/singleton.js +2 -2
- package/document-management/server/validators/ai-validation-executor.js +4 -4
- package/document-management/service-models/document-collection-metadata.service-model.d.ts +14 -0
- package/document-management/service-models/document-collection-metadata.service-model.js +1 -0
- package/document-management/service-models/document-folders.view-model.d.ts +1 -7
- package/document-management/service-models/document-folders.view-model.js +3 -15
- package/document-management/service-models/document-management.view-model.d.ts +20 -6
- package/document-management/service-models/document-management.view-model.js +62 -8
- package/document-management/service-models/document.service-model.d.ts +14 -11
- package/document-management/service-models/document.service-model.js +11 -2
- package/document-management/service-models/enriched/enriched-document-assignment.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document-assignment.view.js +0 -2
- package/document-management/service-models/enriched/enriched-document-category.view.d.ts +11 -1
- package/document-management/service-models/enriched/enriched-document-category.view.js +44 -1
- package/document-management/service-models/enriched/enriched-document-collection.view.d.ts +4 -2
- package/document-management/service-models/enriched/enriched-document-collection.view.js +13 -3
- package/document-management/service-models/enriched/enriched-document-management-data.view.d.ts +2 -0
- package/document-management/service-models/enriched/enriched-document-management-data.view.js +4 -2
- package/document-management/service-models/enriched/enriched-document-request.view.d.ts +1 -0
- package/document-management/service-models/enriched/enriched-document-request.view.js +2 -0
- package/document-management/service-models/enriched/enriched-document-type.view.d.ts +9 -1
- package/document-management/service-models/enriched/enriched-document-type.view.js +28 -1
- package/document-management/service-models/enriched/enriched-document.view.d.ts +7 -6
- package/document-management/service-models/enriched/enriched-document.view.js +29 -6
- package/document-management/service-models/{normalized-requests-template-data.model.d.ts → enriched/enriched-requests-template-data.model.d.ts} +6 -6
- package/document-management/service-models/{normalized-requests-template-data.model.js → enriched/enriched-requests-template-data.model.js} +1 -1
- package/document-management/service-models/enriched/index.d.ts +1 -0
- package/document-management/service-models/enriched/index.js +1 -0
- package/document-management/service-models/index.d.ts +2 -2
- package/document-management/service-models/index.js +2 -2
- package/examples/document-management/categories-and-types.d.ts +33 -31
- package/examples/document-management/categories-and-types.js +33 -0
- package/examples/document-management/main.d.ts +5 -4
- package/examples/document-management/main.js +13 -7
- package/function/log.js +2 -2
- package/http/server/node/module.d.ts +4 -1
- package/http/server/node/module.js +10 -1
- package/http/server/node/node-http-server.d.ts +3 -6
- package/http/server/node/node-http-server.js +68 -67
- package/injector/inject.js +6 -6
- package/injector/injector.js +3 -3
- package/jsx/is-component-class.js +1 -1
- package/key-value-store/key-value.store.d.ts +38 -7
- package/key-value-store/key-value.store.js +2 -1
- package/key-value-store/mongo/mongo-key-value.store.d.ts +1 -0
- package/key-value-store/mongo/mongo-key-value.store.js +14 -5
- package/key-value-store/postgres/drizzle/0000_shocking_slipstream.sql +12 -0
- package/key-value-store/postgres/drizzle/meta/0000_snapshot.json +97 -0
- package/key-value-store/postgres/drizzle/meta/_journal.json +13 -0
- package/key-value-store/postgres/drizzle.config.d.ts +2 -0
- package/key-value-store/postgres/drizzle.config.js +11 -0
- package/key-value-store/postgres/index.d.ts +2 -0
- package/key-value-store/postgres/index.js +2 -0
- package/key-value-store/postgres/key-value-store.service.d.ts +17 -0
- package/key-value-store/postgres/key-value-store.service.js +65 -0
- package/key-value-store/postgres/models/index.d.ts +2 -0
- package/key-value-store/postgres/models/index.js +2 -0
- package/key-value-store/postgres/models/key-value.model.d.ts +7 -0
- package/key-value-store/postgres/models/key-value.model.js +35 -0
- package/key-value-store/postgres/models/schemas.d.ts +3 -0
- package/key-value-store/postgres/models/schemas.js +4 -0
- package/key-value-store/postgres/module.d.ts +6 -0
- package/key-value-store/postgres/module.js +23 -0
- package/lock/web/web-lock.d.ts +0 -1
- package/lock/web/web-lock.js +6 -13
- package/orm/data-types/timestamp.js +1 -1
- package/orm/decorators.d.ts +37 -29
- package/orm/decorators.js +44 -24
- package/orm/entity.d.ts +1 -0
- package/orm/query.d.ts +10 -2
- package/orm/repository.types.d.ts +2 -1
- package/orm/schemas/json.d.ts +12 -6
- package/orm/schemas/json.js +12 -5
- package/orm/server/database.js +5 -2
- package/orm/server/drizzle/schema-converter.js +40 -11
- package/orm/server/query-converter.d.ts +2 -1
- package/orm/server/query-converter.js +57 -34
- package/orm/server/repository.d.ts +26 -43
- package/orm/server/repository.js +106 -39
- package/orm/server/transaction.d.ts +2 -1
- package/orm/server/transaction.js +3 -0
- package/orm/server/transactional.d.ts +5 -1
- package/orm/server/transactional.js +34 -4
- package/package.json +14 -11
- package/process/spawn.js +0 -1
- package/promise/deferred-promise.d.ts +4 -3
- package/promise/deferred-promise.js +13 -5
- package/queue/postgres/queue.js +8 -8
- package/reflection/utils.js +3 -3
- package/schema/decorators/class.js +0 -1
- package/schema/decorators/schema.js +1 -1
- package/schema/schemas/boolean.d.ts +1 -1
- package/schema/schemas/boolean.js +2 -2
- package/schema/schemas/number.js +3 -3
- package/schema/schemas/object.js +5 -6
- package/sse/server-sent-events-source.js +4 -1
- package/utils/compression.js +9 -9
- package/utils/date-time.d.ts +1 -0
- package/utils/date-time.js +18 -4
- package/utils/equals.d.ts +7 -0
- package/utils/equals.js +17 -2
- package/utils/function/memoize.js +10 -2
- package/utils/jwt.js +3 -3
- package/utils/object/property-name.d.ts +2 -2
- package/utils/timing.d.ts +2 -2
- package/utils/timing.js +12 -12
- package/document-management/models/document-request-submission.model.d.ts +0 -7
- package/document-management/server/drizzle/0000_moaning_luckman.sql +0 -305
- package/document-management/server/services/document-management-authorization.service.js +0 -28
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import './schemas.js';
|
|
2
2
|
import { type InjectionToken } from '../../injector/index.js';
|
|
3
3
|
import type { DatabaseConfig } from '../../orm/server/module.js';
|
|
4
|
+
import type { DocumentManagementAuthorizationService } from '../authorization/document-management-authorization.service.js';
|
|
4
5
|
import type { DocumentManagementAncillaryService } from './services/document-management-ancillary.service.js';
|
|
5
|
-
|
|
6
|
-
export declare class DocumentManagementConfig {
|
|
6
|
+
export declare class DocumentManagementConfiguration {
|
|
7
7
|
ancillaryService: InjectionToken<DocumentManagementAncillaryService>;
|
|
8
8
|
authorizationService: InjectionToken<DocumentManagementAuthorizationService>;
|
|
9
9
|
fileObjectStorageModule: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import './schemas.js';
|
|
2
2
|
import { inject } from '../../injector/index.js';
|
|
3
3
|
import { Database, migrate } from '../../orm/server/database.js';
|
|
4
|
-
export class
|
|
4
|
+
export class DocumentManagementConfiguration {
|
|
5
5
|
ancillaryService;
|
|
6
6
|
authorizationService;
|
|
7
7
|
fileObjectStorageModule;
|
|
@@ -12,7 +12,7 @@ export class DocumentManagementConfig {
|
|
|
12
12
|
}
|
|
13
13
|
;
|
|
14
14
|
export async function migrateDocumentManagementSchema() {
|
|
15
|
-
const connection = inject(
|
|
15
|
+
const connection = inject(DocumentManagementConfiguration, undefined, { optional: true })?.database?.connection;
|
|
16
16
|
const database = inject(Database, connection);
|
|
17
17
|
await migrate(database, {
|
|
18
18
|
migrationsSchema: 'document_management',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Document, DocumentAssignmentScope, DocumentAssignmentTask, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentProperty, DocumentPropertyValue, DocumentRequest, DocumentRequestCollectionAssignment, DocumentRequestsTemplate,
|
|
1
|
+
import { Document, DocumentAssignmentScope, DocumentAssignmentTask, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentProperty, DocumentPropertyValue, DocumentRequest, DocumentRequestCollectionAssignment, DocumentRequestsTemplate, DocumentRequestTemplate, DocumentTag, DocumentTagAssignment, 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
|
-
export declare const
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const documentApproval: import("drizzle-orm/pg-core").PgEnum<["pending", "approved", "rejected"]>;
|
|
4
|
+
export declare const documentAssignmentTarget: import("drizzle-orm/pg-core").PgEnum<["request", "collection"]>;
|
|
5
5
|
export declare const documentPropertyDataType: import("drizzle-orm/pg-core").PgEnum<["boolean", "date", "decimal", "text", "integer"]>;
|
|
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
9
|
export declare const documentWorkflowFailReason: import("drizzle-orm/pg-core").PgEnum<["no-suitable-collection", "no-suitable-request"]>;
|
|
10
|
-
export declare const documentWorkflowState: import("drizzle-orm/pg-core").PgEnum<["pending", "error", "running", "completed", "failed"]>;
|
|
10
|
+
export declare const documentWorkflowState: import("drizzle-orm/pg-core").PgEnum<["pending", "error", "running", "completed", "failed", "review"]>;
|
|
11
11
|
export declare const documentWorkflowStep: import("drizzle-orm/pg-core").PgEnum<["classification", "extraction", "assignment", "validation"]>;
|
|
12
12
|
export declare const document: import("../../orm/server/types.js").PgTableFromType<typeof Document, "document_management">;
|
|
13
13
|
export declare const documentAssignmentScope: import("../../orm/server/types.js").PgTableFromType<typeof DocumentAssignmentScope, "document_management">;
|
|
@@ -20,8 +20,9 @@ export declare const documentPropertyValue: import("../../orm/server/types.js").
|
|
|
20
20
|
export declare const documentRequest: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequest, "document_management">;
|
|
21
21
|
export declare const documentRequestCollectionAssignment: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequestCollectionAssignment, "document_management">;
|
|
22
22
|
export declare const documentRequestsTemplate: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequestsTemplate, "document_management">;
|
|
23
|
-
export declare const documentRequestSubmission: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequestSubmission, "document_management">;
|
|
24
23
|
export declare const documentRequestTemplate: import("../../orm/server/types.js").PgTableFromType<typeof DocumentRequestTemplate, "document_management">;
|
|
24
|
+
export declare const documentTag: import("../../orm/server/types.js").PgTableFromType<typeof DocumentTag, "document_management">;
|
|
25
|
+
export declare const documentTagAssignment: import("../../orm/server/types.js").PgTableFromType<typeof DocumentTagAssignment, "document_management">;
|
|
25
26
|
export declare const documentType: import("../../orm/server/types.js").PgTableFromType<typeof DocumentType, "document_management">;
|
|
26
27
|
export declare const documentTypeProperty: import("../../orm/server/types.js").PgTableFromType<typeof DocumentTypeProperty, "document_management">;
|
|
27
28
|
export declare const documentTypeValidation: import("../../orm/server/types.js").PgTableFromType<typeof DocumentTypeValidation, "document_management">;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { databaseSchema } from '../../orm/server/database-schema.js';
|
|
2
|
-
import { Document, DocumentApproval, DocumentAssignmentScope, DocumentAssignmentTarget, DocumentAssignmentTask, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentProperty, DocumentPropertyDataType, DocumentPropertyValue, DocumentRequest, DocumentRequestCollectionAssignment, DocumentRequestState, DocumentRequestsTemplate,
|
|
2
|
+
import { Document, DocumentApproval, DocumentAssignmentScope, DocumentAssignmentTarget, DocumentAssignmentTask, DocumentCategory, DocumentCollection, DocumentCollectionAssignment, DocumentProperty, DocumentPropertyDataType, DocumentPropertyValue, DocumentRequest, DocumentRequestCollectionAssignment, DocumentRequestState, DocumentRequestsTemplate, DocumentRequestTemplate, DocumentTag, DocumentTagAssignment, 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
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const documentPropertyDataType = documentManagementSchema.getEnum(DocumentPropertyDataType);
|
|
7
|
-
export const documentRequestState = documentManagementSchema.getEnum(DocumentRequestState);
|
|
8
|
-
export const documentValidationExecutionState = documentManagementSchema.getEnum(DocumentValidationExecutionState);
|
|
9
|
-
export const documentValidationResultStatus = documentManagementSchema.getEnum(DocumentValidationResultStatus);
|
|
10
|
-
export const documentWorkflowFailReason = documentManagementSchema.getEnum(DocumentWorkflowFailReason);
|
|
11
|
-
export const documentWorkflowState = documentManagementSchema.getEnum(DocumentWorkflowState);
|
|
12
|
-
export const documentWorkflowStep = documentManagementSchema.getEnum(DocumentWorkflowStep);
|
|
4
|
+
export const documentApproval = documentManagementSchema.getEnum(DocumentApproval);
|
|
5
|
+
export const documentAssignmentTarget = documentManagementSchema.getEnum(DocumentAssignmentTarget, 'assignment_target');
|
|
6
|
+
export const documentPropertyDataType = documentManagementSchema.getEnum(DocumentPropertyDataType, 'property_data_type');
|
|
7
|
+
export const documentRequestState = documentManagementSchema.getEnum(DocumentRequestState, 'request_state');
|
|
8
|
+
export const documentValidationExecutionState = documentManagementSchema.getEnum(DocumentValidationExecutionState, 'validation_execution_state');
|
|
9
|
+
export const documentValidationResultStatus = documentManagementSchema.getEnum(DocumentValidationResultStatus, 'validation_result_status');
|
|
10
|
+
export const documentWorkflowFailReason = documentManagementSchema.getEnum(DocumentWorkflowFailReason, 'workflow_fail_reason');
|
|
11
|
+
export const documentWorkflowState = documentManagementSchema.getEnum(DocumentWorkflowState, 'workflow_state');
|
|
12
|
+
export const documentWorkflowStep = documentManagementSchema.getEnum(DocumentWorkflowStep, 'workflow_step');
|
|
13
13
|
export const document = documentManagementSchema.getTable(Document);
|
|
14
14
|
export const documentAssignmentScope = documentManagementSchema.getTable(DocumentAssignmentScope);
|
|
15
15
|
export const documentAssignmentTask = documentManagementSchema.getTable(DocumentAssignmentTask);
|
|
@@ -21,8 +21,9 @@ export const documentPropertyValue = documentManagementSchema.getTable(DocumentP
|
|
|
21
21
|
export const documentRequest = documentManagementSchema.getTable(DocumentRequest);
|
|
22
22
|
export const documentRequestCollectionAssignment = documentManagementSchema.getTable(DocumentRequestCollectionAssignment);
|
|
23
23
|
export const documentRequestsTemplate = documentManagementSchema.getTable(DocumentRequestsTemplate);
|
|
24
|
-
export const documentRequestSubmission = documentManagementSchema.getTable(DocumentRequestSubmission);
|
|
25
24
|
export const documentRequestTemplate = documentManagementSchema.getTable(DocumentRequestTemplate);
|
|
25
|
+
export const documentTag = documentManagementSchema.getTable(DocumentTag);
|
|
26
|
+
export const documentTagAssignment = documentManagementSchema.getTable(DocumentTagAssignment);
|
|
26
27
|
export const documentType = documentManagementSchema.getTable(DocumentType);
|
|
27
28
|
export const documentTypeProperty = documentManagementSchema.getTable(DocumentTypeProperty);
|
|
28
29
|
export const documentTypeValidation = documentManagementSchema.getTable(DocumentTypeValidation);
|
|
@@ -2,25 +2,34 @@ import { Transactional } from '../../../orm/server/index.js';
|
|
|
2
2
|
import { DocumentCategory, DocumentType } from '../../models/index.js';
|
|
3
3
|
import type { DocumentCategoryView } from '../../service-models/index.js';
|
|
4
4
|
export declare class DocumentCategoryTypeService extends Transactional {
|
|
5
|
-
#private;
|
|
6
5
|
readonly categoryRepository: import("../../../orm/server/repository.js").EntityRepository<DocumentCategory>;
|
|
7
6
|
readonly typeRepository: import("../../../orm/server/repository.js").EntityRepository<DocumentType>;
|
|
8
|
-
loadCategory(id: string): Promise<DocumentCategory>;
|
|
9
|
-
loadType(id: string): Promise<DocumentType>;
|
|
10
|
-
createCategory(
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
loadCategory(tenantId: string, id: string): Promise<DocumentCategory>;
|
|
8
|
+
loadType(tenantId: string, id: string): Promise<DocumentType>;
|
|
9
|
+
createCategory(data: {
|
|
10
|
+
tenantId: string | null;
|
|
11
|
+
label: string;
|
|
12
|
+
parentId: string | null;
|
|
13
|
+
enumKey?: string;
|
|
14
|
+
}): Promise<DocumentCategory>;
|
|
15
|
+
createType(data: {
|
|
16
|
+
tenantId: string | null;
|
|
17
|
+
label: string;
|
|
18
|
+
categoryId: string;
|
|
19
|
+
enumKey?: string;
|
|
20
|
+
}): Promise<DocumentType>;
|
|
21
|
+
updateCategory(tenantId: string | null, id: string, update: {
|
|
13
22
|
label?: string;
|
|
14
23
|
parentId?: string | null;
|
|
15
24
|
}): Promise<DocumentCategory>;
|
|
16
|
-
updateType(id: string, update: {
|
|
25
|
+
updateType(tenantId: string | null, id: string, update: {
|
|
17
26
|
label?: string;
|
|
18
27
|
categoryId?: string;
|
|
19
28
|
}): Promise<DocumentType>;
|
|
20
|
-
loadCategoryGraph(categoryId: string): Promise<DocumentCategory[]>;
|
|
21
|
-
loadCategoriesAndTypes(): Promise<{
|
|
29
|
+
loadCategoryGraph(tenantId: string, categoryId: string): Promise<DocumentCategory[]>;
|
|
30
|
+
loadCategoriesAndTypes(tenantId: string | null): Promise<{
|
|
22
31
|
categories: DocumentCategory[];
|
|
23
32
|
types: DocumentType[];
|
|
24
33
|
}>;
|
|
25
|
-
loadCategoryViews(): Promise<DocumentCategoryView[]>;
|
|
34
|
+
loadCategoryViews(tenantId: string | null): Promise<DocumentCategoryView[]>;
|
|
26
35
|
}
|
|
@@ -4,10 +4,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
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
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var _a;
|
|
8
|
-
var DocumentCategoryTypeService_1;
|
|
9
|
-
import { inject } from '../../../injector/inject.js';
|
|
10
|
-
import { Logger } from '../../../logger/logger.js';
|
|
11
7
|
import { Transactional } from '../../../orm/server/index.js';
|
|
12
8
|
import { injectRepository } from '../../../orm/server/repository.js';
|
|
13
9
|
import { groupToMap } from '../../../utils/iterable-helpers/group-to-map.js';
|
|
@@ -15,45 +11,56 @@ import { isUndefined } from '../../../utils/type-guards.js';
|
|
|
15
11
|
import { DocumentCategory, DocumentType } from '../../models/index.js';
|
|
16
12
|
import { enumTypeKey } from './enum-type-key.js';
|
|
17
13
|
import { DocumentManagementSingleton } from './singleton.js';
|
|
18
|
-
let DocumentCategoryTypeService =
|
|
19
|
-
#logger = inject(Logger, DocumentCategoryTypeService_1.name);
|
|
14
|
+
let DocumentCategoryTypeService = class DocumentCategoryTypeService extends Transactional {
|
|
20
15
|
categoryRepository = injectRepository(DocumentCategory);
|
|
21
16
|
typeRepository = injectRepository(DocumentType);
|
|
22
|
-
async loadCategory(id) {
|
|
23
|
-
return await this.categoryRepository.
|
|
17
|
+
async loadCategory(tenantId, id) {
|
|
18
|
+
return await this.categoryRepository.loadByQuery({ id, tenantId: { $or: [null, tenantId] } });
|
|
24
19
|
}
|
|
25
|
-
async loadType(id) {
|
|
26
|
-
return await this.typeRepository.
|
|
20
|
+
async loadType(tenantId, id) {
|
|
21
|
+
return await this.typeRepository.loadByQuery({ id, tenantId: { $or: [null, tenantId] } });
|
|
27
22
|
}
|
|
28
|
-
async createCategory(
|
|
29
|
-
return await this.categoryRepository.insert({
|
|
23
|
+
async createCategory(data) {
|
|
24
|
+
return await this.categoryRepository.insert({
|
|
25
|
+
tenantId: data.tenantId,
|
|
26
|
+
label: data.label,
|
|
27
|
+
parentId: data.parentId,
|
|
28
|
+
metadata: { attributes: { [enumTypeKey]: data.enumKey } },
|
|
29
|
+
});
|
|
30
30
|
}
|
|
31
|
-
async createType(
|
|
32
|
-
|
|
31
|
+
async createType(data) {
|
|
32
|
+
// Ensure the category exists for the tenant before creating the type
|
|
33
|
+
await this.categoryRepository.loadByQuery({ tenantId: { $or: [null, data.tenantId] }, id: data.categoryId });
|
|
34
|
+
return await this.typeRepository.insert({
|
|
35
|
+
tenantId: data.tenantId,
|
|
36
|
+
label: data.label,
|
|
37
|
+
categoryId: data.categoryId,
|
|
38
|
+
metadata: { attributes: { [enumTypeKey]: data.enumKey } },
|
|
39
|
+
});
|
|
33
40
|
}
|
|
34
|
-
async updateCategory(id, update) {
|
|
35
|
-
return await this.categoryRepository.
|
|
41
|
+
async updateCategory(tenantId, id, update) {
|
|
42
|
+
return await this.categoryRepository.updateByQuery({ tenantId, id }, update);
|
|
36
43
|
}
|
|
37
|
-
async updateType(id, update) {
|
|
38
|
-
return await this.typeRepository.
|
|
44
|
+
async updateType(tenantId, id, update) {
|
|
45
|
+
return await this.typeRepository.updateByQuery({ tenantId, id }, update);
|
|
39
46
|
}
|
|
40
|
-
async loadCategoryGraph(categoryId) {
|
|
41
|
-
const category = await this.categoryRepository.
|
|
47
|
+
async loadCategoryGraph(tenantId, categoryId) {
|
|
48
|
+
const category = await this.categoryRepository.loadByQuery({ tenantId: { $or: [null, tenantId] }, id: categoryId });
|
|
42
49
|
if (category.parentId == null) {
|
|
43
50
|
return [category];
|
|
44
51
|
}
|
|
45
|
-
const parents = await this.loadCategoryGraph(category.parentId);
|
|
52
|
+
const parents = await this.loadCategoryGraph(tenantId, category.parentId);
|
|
46
53
|
return [...parents, category];
|
|
47
54
|
}
|
|
48
|
-
async loadCategoriesAndTypes() {
|
|
55
|
+
async loadCategoriesAndTypes(tenantId) {
|
|
49
56
|
const [categories, types] = await Promise.all([
|
|
50
|
-
this.categoryRepository.loadManyByQuery({}, { order: 'label' }),
|
|
51
|
-
this.typeRepository.loadManyByQuery({}, { order: 'label' }),
|
|
57
|
+
this.categoryRepository.loadManyByQuery({ tenantId: { $or: [null, tenantId] } }, { order: 'label' }),
|
|
58
|
+
this.typeRepository.loadManyByQuery({ tenantId: { $or: [null, tenantId] } }, { order: 'label' }),
|
|
52
59
|
]);
|
|
53
60
|
return { categories, types };
|
|
54
61
|
}
|
|
55
|
-
async loadCategoryViews() {
|
|
56
|
-
const { categories, types } = await this.loadCategoriesAndTypes();
|
|
62
|
+
async loadCategoryViews(tenantId) {
|
|
63
|
+
const { categories, types } = await this.loadCategoriesAndTypes(tenantId);
|
|
57
64
|
const categoryChildrenMap = groupToMap(categories, (category) => category.parentId);
|
|
58
65
|
const categoryTypesMap = groupToMap(types, (type) => type.categoryId);
|
|
59
66
|
const rootCategories = categoryChildrenMap.get(null);
|
|
@@ -63,7 +70,7 @@ let DocumentCategoryTypeService = DocumentCategoryTypeService_1 = class Document
|
|
|
63
70
|
return rootCategories.map((category) => getView(category, categoryChildrenMap, categoryTypesMap));
|
|
64
71
|
}
|
|
65
72
|
};
|
|
66
|
-
DocumentCategoryTypeService =
|
|
73
|
+
DocumentCategoryTypeService = __decorate([
|
|
67
74
|
DocumentManagementSingleton()
|
|
68
75
|
], DocumentCategoryTypeService);
|
|
69
76
|
export { DocumentCategoryTypeService };
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DocumentCollectionMetadata } from '../../../document-management/service-models/index.js';
|
|
2
|
+
import { type EntityMetadataInsert, type Query } from '../../../orm/index.js';
|
|
2
3
|
import { Transactional } from '../../../orm/server/index.js';
|
|
3
4
|
import type { OneOrMany } from '../../../types.js';
|
|
4
5
|
import { Document, DocumentCollection } from '../../models/index.js';
|
|
5
6
|
export declare class DocumentCollectionService extends Transactional {
|
|
6
7
|
#private;
|
|
7
8
|
readonly repository: import("../../../orm/server/repository.js").EntityRepository<DocumentCollection>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
resolveMetadata<const T extends (DocumentCollection | string)[]>(tenantId: string, collectionsOrIds: T): Promise<{
|
|
10
|
+
[K in keyof T]: DocumentCollectionMetadata;
|
|
11
|
+
}>;
|
|
12
|
+
resolveMetadataMap(tenantId: string, collectionsOrIds: (DocumentCollection | string)[]): Promise<Record<string, DocumentCollectionMetadata>>;
|
|
13
|
+
loadCollectionGraph(tenantId: string, collectionId: string): Promise<DocumentCollection[]>;
|
|
14
|
+
createCollection(tenantId: string, parentId: string | null, options?: {
|
|
15
|
+
metadata?: EntityMetadataInsert;
|
|
16
|
+
}): Promise<DocumentCollection>;
|
|
17
|
+
collectionHasDocumentByFilter(tenantId: string, collectionId: string, filter: Query<Document>): Promise<boolean>;
|
|
18
|
+
assignDocument(document: Document, collectionIds: OneOrMany<string>): Promise<void>;
|
|
19
|
+
archiveDocument(document: Document, collectionIds: OneOrMany<string>): Promise<void>;
|
|
13
20
|
}
|
|
@@ -5,45 +5,69 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { and, eq, sql } from 'drizzle-orm';
|
|
8
|
+
import { inject } from '../../../injector/inject.js';
|
|
8
9
|
import { TRANSACTION_TIMESTAMP } from '../../../orm/index.js';
|
|
9
10
|
import { Transactional } from '../../../orm/server/index.js';
|
|
10
11
|
import { injectRepository } from '../../../orm/server/repository.js';
|
|
11
12
|
import { toArray } from '../../../utils/array/index.js';
|
|
13
|
+
import { fromEntries } from '../../../utils/object/index.js';
|
|
14
|
+
import { assertDefinedPass, isString } from '../../../utils/type-guards.js';
|
|
12
15
|
import { Document, DocumentCollection, DocumentCollectionAssignment } from '../../models/index.js';
|
|
13
16
|
import { document, documentCollectionAssignment } from '../schemas.js';
|
|
17
|
+
import { DocumentManagementAncillaryService } from './document-management-ancillary.service.js';
|
|
14
18
|
import { DocumentManagementSingleton } from './singleton.js';
|
|
15
19
|
let DocumentCollectionService = class DocumentCollectionService extends Transactional {
|
|
20
|
+
#ancillaryService = inject(DocumentManagementAncillaryService);
|
|
16
21
|
#documentRepository = injectRepository(Document);
|
|
17
22
|
#documentCollectionAssignmentRepository = injectRepository(DocumentCollectionAssignment);
|
|
18
23
|
repository = injectRepository(DocumentCollection);
|
|
19
|
-
async
|
|
20
|
-
|
|
24
|
+
async resolveMetadata(tenantId, collectionsOrIds) {
|
|
25
|
+
if (collectionsOrIds.length == 0) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const loadIds = collectionsOrIds.filter((collection) => isString(collection));
|
|
29
|
+
if (loadIds.length == 0) {
|
|
30
|
+
return this.#ancillaryService.resolveMetadata(collectionsOrIds);
|
|
31
|
+
}
|
|
32
|
+
const loadedCollections = await this.repository.loadManyByQuery({ tenantId, id: { $in: loadIds } });
|
|
33
|
+
const collections = collectionsOrIds.map((collectionOrId) => isString(collectionOrId)
|
|
34
|
+
? assertDefinedPass(loadedCollections.find((collection) => collection.id == collectionOrId), `Could not load collection "${collectionOrId}".`)
|
|
35
|
+
: collectionOrId);
|
|
36
|
+
return this.#ancillaryService.resolveMetadata(collections);
|
|
37
|
+
}
|
|
38
|
+
async resolveMetadataMap(tenantId, collectionsOrIds) {
|
|
39
|
+
const names = await this.resolveMetadata(tenantId, collectionsOrIds);
|
|
40
|
+
const entries = collectionsOrIds.map((collectionOrId, index) => [isString(collectionOrId) ? collectionOrId : collectionOrId.id, names[index]]);
|
|
41
|
+
return fromEntries(entries);
|
|
42
|
+
}
|
|
43
|
+
async loadCollectionGraph(tenantId, collectionId) {
|
|
44
|
+
const collection = await this.repository.loadByQuery({ tenantId, id: collectionId });
|
|
21
45
|
if (collection.parentId == null) {
|
|
22
46
|
return [collection];
|
|
23
47
|
}
|
|
24
|
-
const parents = await this.loadCollectionGraph(collection.parentId);
|
|
48
|
+
const parents = await this.loadCollectionGraph(tenantId, collection.parentId);
|
|
25
49
|
return [...parents, collection];
|
|
26
50
|
}
|
|
27
|
-
async createCollection(parentId) {
|
|
28
|
-
return this.repository.withSession(this.session).insert({ parentId });
|
|
51
|
+
async createCollection(tenantId, parentId, options) {
|
|
52
|
+
return await this.repository.withSession(this.session).insert({ tenantId, parentId, metadata: options?.metadata });
|
|
29
53
|
}
|
|
30
|
-
async collectionHasDocumentByFilter(collectionId, filter) {
|
|
54
|
+
async collectionHasDocumentByFilter(tenantId, collectionId, filter) {
|
|
31
55
|
const matchingDocuments = this.session
|
|
32
56
|
.select()
|
|
33
57
|
.from(documentCollectionAssignment)
|
|
34
|
-
.leftJoin(document, eq(document.id, documentCollectionAssignment.documentId))
|
|
35
|
-
.where(and(eq(documentCollectionAssignment.collectionId, collectionId), this.#documentRepository.convertQuery(filter)));
|
|
58
|
+
.leftJoin(document, and(eq(document.tenantId, tenantId), eq(document.id, documentCollectionAssignment.documentId)))
|
|
59
|
+
.where(and(eq(documentCollectionAssignment.tenantId, tenantId), eq(documentCollectionAssignment.collectionId, collectionId), this.#documentRepository.convertQuery(filter)));
|
|
36
60
|
const result = await this.session.execute(sql `SELECT EXISTS(SELECT 1 FROM ${matchingDocuments}))`);
|
|
37
61
|
console.log(result);
|
|
38
62
|
throw new Error('verify');
|
|
39
63
|
// return result[0]!;
|
|
40
64
|
}
|
|
41
|
-
async assignDocument(
|
|
42
|
-
const values = toArray(collectionIds).map((collectionId) => ({ collectionId, documentId, archiveTimestamp: null }));
|
|
65
|
+
async assignDocument(document, collectionIds) {
|
|
66
|
+
const values = toArray(collectionIds).map((collectionId) => ({ tenantId: document.tenantId, collectionId, documentId: document.id, archiveTimestamp: null }));
|
|
43
67
|
await this.#documentCollectionAssignmentRepository.withSession(this.session).upsertMany(['collectionId', 'documentId'], values);
|
|
44
68
|
}
|
|
45
|
-
async archiveDocument(
|
|
46
|
-
await this.#documentCollectionAssignmentRepository.withSession(this.session).updateManyByQuery({ collectionId: { $in: toArray(collectionIds) }, documentId, archiveTimestamp: null }, { archiveTimestamp: TRANSACTION_TIMESTAMP });
|
|
69
|
+
async archiveDocument(document, collectionIds) {
|
|
70
|
+
await this.#documentCollectionAssignmentRepository.withSession(this.session).updateManyByQuery({ tenantId: document.tenantId, collectionId: { $in: toArray(collectionIds) }, documentId: document.id, archiveTimestamp: null }, { archiveTimestamp: TRANSACTION_TIMESTAMP });
|
|
47
71
|
}
|
|
48
72
|
};
|
|
49
73
|
DocumentCollectionService = __decorate([
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FileContentPart } from '../../../ai/types.js';
|
|
2
2
|
import { Transactional } from '../../../orm/server/index.js';
|
|
3
|
+
import { Document } from '../../models/index.js';
|
|
3
4
|
export type DocumentFileMetadata = {
|
|
4
5
|
mimeType: string;
|
|
5
6
|
size: number;
|
|
@@ -25,13 +26,13 @@ export declare class DocumentFileService extends Transactional {
|
|
|
25
26
|
uploadId: string;
|
|
26
27
|
uploadKey: string;
|
|
27
28
|
}): Promise<[DocumentFileMetadata, Uint8Array]>;
|
|
28
|
-
getContent(
|
|
29
|
-
getContentStream(
|
|
30
|
-
getContentUrl(
|
|
31
|
-
getPreview(
|
|
32
|
-
getPreviewStream(
|
|
33
|
-
getPreviewUrl(
|
|
34
|
-
getAiFileContentPart(
|
|
29
|
+
getContent(document: Document): Promise<Uint8Array>;
|
|
30
|
+
getContentStream(document: Document): ReadableStream<Uint8Array>;
|
|
31
|
+
getContentUrl(document: Document, download?: boolean): Promise<string>;
|
|
32
|
+
getPreview(document: Document, page?: number): Promise<Uint8Array>;
|
|
33
|
+
getPreviewStream(document: Document, page?: number): ReadableStream<Uint8Array>;
|
|
34
|
+
getPreviewUrl(document: Document, page?: number): Promise<string>;
|
|
35
|
+
getAiFileContentPart(document: Document): Promise<FileContentPart>;
|
|
35
36
|
private createPreviewIfNotExists;
|
|
36
37
|
private getDocumentFileContentObjectUrl;
|
|
37
38
|
}
|
|
@@ -69,7 +69,6 @@ import { inject } from '../../../injector/inject.js';
|
|
|
69
69
|
import { Logger } from '../../../logger/logger.js';
|
|
70
70
|
import { ObjectStorage } from '../../../object-storage/index.js';
|
|
71
71
|
import { Transactional } from '../../../orm/server/index.js';
|
|
72
|
-
import { injectRepository } from '../../../orm/server/repository.js';
|
|
73
72
|
import { pdfToImage } from '../../../pdf/index.js';
|
|
74
73
|
import { Alphabet } from '../../../utils/alphabet.js';
|
|
75
74
|
import { digest } from '../../../utils/cryptography.js';
|
|
@@ -79,15 +78,14 @@ import { readableStreamFromPromise, readBinaryStream } from '../../../utils/stre
|
|
|
79
78
|
import { isDefined, isNotReadableStream, isNotUint8Array, isUint8Array } from '../../../utils/type-guards.js';
|
|
80
79
|
import { millisecondsPerMinute, secondsPerMinute } from '../../../utils/units.js';
|
|
81
80
|
import { Document } from '../../models/index.js';
|
|
82
|
-
import {
|
|
81
|
+
import { DocumentManagementConfiguration } from '../module.js';
|
|
83
82
|
import { DocumentManagementSingleton } from './singleton.js';
|
|
84
83
|
let DocumentFileService = DocumentFileService_1 = class DocumentFileService extends Transactional {
|
|
85
|
-
#
|
|
86
|
-
#documentRepository = injectRepository(Document);
|
|
84
|
+
#configuration = inject(DocumentManagementConfiguration);
|
|
87
85
|
#aiService = inject(AiService);
|
|
88
|
-
#fileObjectStorage = inject(ObjectStorage, this.#
|
|
89
|
-
#filePreviewObjectStorage = inject(ObjectStorage, this.#
|
|
90
|
-
#fileUploadObjectStorage = inject(ObjectStorage, { module: this.#
|
|
86
|
+
#fileObjectStorage = inject(ObjectStorage, this.#configuration.fileObjectStorageModule);
|
|
87
|
+
#filePreviewObjectStorage = inject(ObjectStorage, this.#configuration.filePreviewObjectStorageModule);
|
|
88
|
+
#fileUploadObjectStorage = inject(ObjectStorage, { module: this.#configuration.fileUploadObjectStorageModule, configuration: { lifecycle: { expiration: { after: 5 * secondsPerMinute } } } });
|
|
91
89
|
#logger = inject(Logger, DocumentFileService_1.name);
|
|
92
90
|
#aiFilePartCache = new Map();
|
|
93
91
|
/**
|
|
@@ -97,8 +95,8 @@ let DocumentFileService = DocumentFileService_1 = class DocumentFileService exte
|
|
|
97
95
|
* @returns upload information
|
|
98
96
|
*/
|
|
99
97
|
async initiateUpload({ key, contentLength }) {
|
|
100
|
-
if (contentLength > (this.#
|
|
101
|
-
throw new ForbiddenError(`Content length exceeds the maximum limit of ${this.#
|
|
98
|
+
if (contentLength > (this.#configuration.maxFileSize ?? Number.POSITIVE_INFINITY)) {
|
|
99
|
+
throw new ForbiddenError(`Content length exceeds the maximum limit of ${this.#configuration.maxFileSize} bytes.`);
|
|
102
100
|
}
|
|
103
101
|
const id = getRandomString(64, Alphabet.LowerUpperCaseNumbers);
|
|
104
102
|
const url = await this.#fileUploadObjectStorage.getUploadUrl(id, currentTimestamp() + (5 * millisecondsPerMinute), { contentLength, metadata: { 'upload-key': key } });
|
|
@@ -113,9 +111,9 @@ let DocumentFileService = DocumentFileService_1 = class DocumentFileService exte
|
|
|
113
111
|
if (content.uploadKey != objectMetadata['upload-key']) {
|
|
114
112
|
throw new ForbiddenError(`Invalid upload key`);
|
|
115
113
|
}
|
|
116
|
-
if (objectContentLength > (this.#
|
|
114
|
+
if (objectContentLength > (this.#configuration.maxFileSize ?? Number.POSITIVE_INFINITY)) {
|
|
117
115
|
await this.#fileUploadObjectStorage.deleteObject(object.key);
|
|
118
|
-
throw new ForbiddenError(`Content length exceeds the maximum limit of ${this.#
|
|
116
|
+
throw new ForbiddenError(`Content length exceeds the maximum limit of ${this.#configuration.maxFileSize} bytes.`);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
119
|
const contentAsUint8Array = isUpload
|
|
@@ -136,41 +134,39 @@ let DocumentFileService = DocumentFileService_1 = class DocumentFileService exte
|
|
|
136
134
|
await this.#fileObjectStorage.uploadObject(objectKey, contentAsUint8Array, { contentLength: contentAsUint8Array.length, contentType: mimeType });
|
|
137
135
|
return metadata;
|
|
138
136
|
}
|
|
139
|
-
async getContent(
|
|
140
|
-
const objectKey = getObjectKey(
|
|
137
|
+
async getContent(document) {
|
|
138
|
+
const objectKey = getObjectKey(document.id);
|
|
141
139
|
return await this.#fileObjectStorage.getContent(objectKey);
|
|
142
140
|
}
|
|
143
|
-
getContentStream(
|
|
144
|
-
const objectKey = getObjectKey(
|
|
141
|
+
getContentStream(document) {
|
|
142
|
+
const objectKey = getObjectKey(document.id);
|
|
145
143
|
return this.#fileObjectStorage.getContentStream(objectKey);
|
|
146
144
|
}
|
|
147
|
-
async getContentUrl(
|
|
148
|
-
|
|
149
|
-
return await this.getDocumentFileContentObjectUrl(document, title ?? documentId, download);
|
|
145
|
+
async getContentUrl(document, download = false) {
|
|
146
|
+
return await this.getDocumentFileContentObjectUrl(document, document.title ?? document.id, download);
|
|
150
147
|
}
|
|
151
|
-
async getPreview(
|
|
152
|
-
const objectKey = getObjectKey(
|
|
153
|
-
await this.createPreviewIfNotExists(
|
|
148
|
+
async getPreview(document, page = 1) {
|
|
149
|
+
const objectKey = getObjectKey(document.id);
|
|
150
|
+
await this.createPreviewIfNotExists(document, page);
|
|
154
151
|
return await this.#filePreviewObjectStorage.getContent(objectKey);
|
|
155
152
|
}
|
|
156
|
-
getPreviewStream(
|
|
153
|
+
getPreviewStream(document, page = 1) {
|
|
157
154
|
return readableStreamFromPromise(async () => {
|
|
158
|
-
const objectKey = getObjectKey(
|
|
159
|
-
await this.createPreviewIfNotExists(
|
|
155
|
+
const objectKey = getObjectKey(document.id);
|
|
156
|
+
await this.createPreviewIfNotExists(document, page);
|
|
160
157
|
return this.#filePreviewObjectStorage.getContentStream(objectKey);
|
|
161
158
|
});
|
|
162
159
|
}
|
|
163
|
-
async getPreviewUrl(
|
|
164
|
-
const objectKey = getObjectKey(
|
|
165
|
-
await this.createPreviewIfNotExists(
|
|
160
|
+
async getPreviewUrl(document, page = 1) {
|
|
161
|
+
const objectKey = getObjectKey(document.id);
|
|
162
|
+
await this.createPreviewIfNotExists(document, page);
|
|
166
163
|
return await this.#filePreviewObjectStorage.getDownloadUrl(objectKey, currentTimestamp() + (5 * millisecondsPerMinute), {
|
|
167
164
|
'Response-Content-Type': 'image/jpeg',
|
|
168
165
|
});
|
|
169
166
|
}
|
|
170
|
-
async getAiFileContentPart(
|
|
167
|
+
async getAiFileContentPart(document) {
|
|
171
168
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
172
169
|
try {
|
|
173
|
-
const document = await this.#documentRepository.load(documentId);
|
|
174
170
|
const cachedAiFilePart = this.#aiFilePartCache.get(document.id);
|
|
175
171
|
if (isDefined(cachedAiFilePart)) {
|
|
176
172
|
if (cachedAiFilePart.timestamp > (currentTimestamp() - (5 * millisecondsPerMinute))) {
|
|
@@ -178,7 +174,7 @@ let DocumentFileService = DocumentFileService_1 = class DocumentFileService exte
|
|
|
178
174
|
}
|
|
179
175
|
this.#aiFilePartCache.delete(document.id);
|
|
180
176
|
}
|
|
181
|
-
const fileContentStream = this.getContentStream(document
|
|
177
|
+
const fileContentStream = this.getContentStream(document);
|
|
182
178
|
const tmpFile = __addDisposableResource(env_1, await TemporaryFile.from(fileContentStream), true);
|
|
183
179
|
const filePart = await this.#aiService.processFile({ path: tmpFile.path, mimeType: document.mimeType });
|
|
184
180
|
this.#aiFilePartCache.set(document.id, { part: filePart, timestamp: currentTimestamp() });
|
|
@@ -194,11 +190,10 @@ let DocumentFileService = DocumentFileService_1 = class DocumentFileService exte
|
|
|
194
190
|
await result_1;
|
|
195
191
|
}
|
|
196
192
|
}
|
|
197
|
-
async createPreviewIfNotExists(
|
|
198
|
-
const key = getObjectKey(
|
|
193
|
+
async createPreviewIfNotExists(document, page = 1) {
|
|
194
|
+
const key = getObjectKey(document.id);
|
|
199
195
|
const hasPreview = await this.#filePreviewObjectStorage.exists(key);
|
|
200
196
|
if (!hasPreview) {
|
|
201
|
-
const document = await this.#documentRepository.load(documentId);
|
|
202
197
|
const content = await this.#fileObjectStorage.getContent(key);
|
|
203
198
|
const image = await match(document.mimeType)
|
|
204
199
|
.with('application/pdf', async () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DocumentPropertyDataType } from '../../models/index.js';
|
|
2
|
+
import { Document } from '../../models/index.js';
|
|
2
3
|
type DocumentInformationExtractionPropertyResult = {
|
|
3
4
|
propertyId: string;
|
|
4
5
|
dataType: DocumentPropertyDataType;
|
|
@@ -14,9 +15,9 @@ export type DocumentInformationExtractionResult = {
|
|
|
14
15
|
};
|
|
15
16
|
export declare class DocumentManagementAiService {
|
|
16
17
|
#private;
|
|
17
|
-
classifyDocumentType(documentId: string): Promise<string>;
|
|
18
|
-
extractDocumentInformation(documentId: string): Promise<DocumentInformationExtractionResult>;
|
|
19
|
-
findSuitableCollectionsForDocument(
|
|
20
|
-
findSuitableRequestForDocument(
|
|
18
|
+
classifyDocumentType(tenantId: string, documentId: string): Promise<string>;
|
|
19
|
+
extractDocumentInformation(tenantId: string, documentId: string): Promise<DocumentInformationExtractionResult>;
|
|
20
|
+
findSuitableCollectionsForDocument(document: Document, collectionIds: string[]): Promise<string[]>;
|
|
21
|
+
findSuitableRequestForDocument(document: Document, collectionIds: string[]): Promise<string | null>;
|
|
21
22
|
}
|
|
22
23
|
export {};
|