@tstdl/base 0.92.147 → 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.
- package/api/client/client.d.ts +2 -0
- package/api/client/client.js +4 -1
- package/api/utils.d.ts +1 -0
- package/api/utils.js +1 -0
- package/document-management/api/document-management.api.d.ts +13 -0
- package/document-management/api/document-management.api.js +8 -0
- package/document-management/server/services/document-management.service.d.ts +15 -1
- package/document-management/server/services/document-management.service.js +7 -7
- package/examples/document-management/main.js +8 -1
- package/http/client/http-client-request.js +1 -1
- package/http/index.d.ts +1 -0
- package/http/index.js +1 -0
- package/http/tokens.d.ts +5 -0
- package/http/tokens.js +5 -0
- package/package.json +1 -1
package/api/client/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HttpClient, type HttpClientOptions } from '../../http/client/index.js';
|
|
2
|
+
import { bustCacheToken } from '../../http/index.js';
|
|
2
3
|
import { type Resolvable } from '../../injector/interfaces.js';
|
|
3
4
|
import type { Type } from '../../types/index.js';
|
|
4
5
|
import { type ApiClientImplementation, type ApiDefinition, type ApiEndpointDefinition } from '../types.js';
|
|
@@ -13,6 +14,7 @@ export type ClientOptions = {
|
|
|
13
14
|
};
|
|
14
15
|
export type ApiClientHttpRequestContext = {
|
|
15
16
|
endpoint: ApiEndpointDefinition;
|
|
17
|
+
[bustCacheToken]?: boolean;
|
|
16
18
|
};
|
|
17
19
|
export declare const httpClientSymbol: unique symbol;
|
|
18
20
|
export declare const apiDefinitionSymbol: unique symbol;
|
package/api/client/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpClient, HttpClientRequest } from '../../http/client/index.js';
|
|
2
|
-
import { normalizeSingleHttpValue } from '../../http/
|
|
2
|
+
import { bustCacheToken, normalizeSingleHttpValue } from '../../http/index.js';
|
|
3
3
|
import { inject } from '../../injector/inject.js';
|
|
4
4
|
import { Injector } from '../../injector/injector.js';
|
|
5
5
|
import { resolveArgumentType } from '../../injector/interfaces.js';
|
|
@@ -74,6 +74,9 @@ export function compileClient(definition, options = defaultOptions) {
|
|
|
74
74
|
}
|
|
75
75
|
return getServerSentEvents(this[httpClientSymbol].options.baseUrl, resource, endpoint, parameters);
|
|
76
76
|
}
|
|
77
|
+
if (context.endpoint.data?.[bustCacheToken] == true) {
|
|
78
|
+
context[bustCacheToken] = true;
|
|
79
|
+
}
|
|
77
80
|
const request = new HttpClientRequest({
|
|
78
81
|
method,
|
|
79
82
|
url: resource,
|
package/api/utils.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ type GetApiEndpointUrlData = {
|
|
|
5
5
|
defaultPrefix: string | undefined | null;
|
|
6
6
|
explicitVersion?: number | null;
|
|
7
7
|
};
|
|
8
|
+
export declare const defaultAccessControlAllowHeaders = "Content-Type, Authorization";
|
|
8
9
|
export declare function getFullApiEndpointResource({ api, endpoint, defaultPrefix, explicitVersion }: GetApiEndpointUrlData): string;
|
|
9
10
|
export {};
|
package/api/utils.js
CHANGED
|
@@ -2,6 +2,7 @@ import { toArray } from '../utils/array/array.js';
|
|
|
2
2
|
import { compareByValueDescending } from '../utils/comparison.js';
|
|
3
3
|
import { sort } from '../utils/iterable-helpers/sort.js';
|
|
4
4
|
import { isDefined, isNull } from '../utils/type-guards.js';
|
|
5
|
+
export const defaultAccessControlAllowHeaders = 'Content-Type, Authorization';
|
|
5
6
|
export function getFullApiEndpointResource({ api, endpoint, defaultPrefix, explicitVersion }) {
|
|
6
7
|
const versionArray = toArray(isDefined(explicitVersion) ? explicitVersion : endpoint.version);
|
|
7
8
|
const version = sort(versionArray, compareByValueDescending)[0];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bustCacheToken } from '../../http/tokens.js';
|
|
1
2
|
import { ServerSentEvents } from '../../sse/server-sent-events.js';
|
|
2
3
|
import { Document, DocumentCategory, DocumentRequest, DocumentRequestsTemplate, DocumentRequestTemplate, DocumentType } from '../models/index.js';
|
|
3
4
|
import { DocumentCategoryView, DocumentManagementData, DocumentRequestsTemplateData } from '../service-models/index.js';
|
|
@@ -22,6 +23,12 @@ export declare const documentManagementApiDefinition: {
|
|
|
22
23
|
}>;
|
|
23
24
|
result: typeof ServerSentEvents;
|
|
24
25
|
credentials: true;
|
|
26
|
+
data: {
|
|
27
|
+
[bustCacheToken]: boolean;
|
|
28
|
+
};
|
|
29
|
+
cors: {
|
|
30
|
+
accessControlAllowHeaders: string;
|
|
31
|
+
};
|
|
25
32
|
};
|
|
26
33
|
loadDocumentRequestsTemplateData: {
|
|
27
34
|
resource: string;
|
|
@@ -413,6 +420,12 @@ declare const _DocumentManagementApi: import("../../api/client/index.js").ApiCli
|
|
|
413
420
|
}>;
|
|
414
421
|
result: typeof ServerSentEvents;
|
|
415
422
|
credentials: true;
|
|
423
|
+
data: {
|
|
424
|
+
[bustCacheToken]: boolean;
|
|
425
|
+
};
|
|
426
|
+
cors: {
|
|
427
|
+
accessControlAllowHeaders: string;
|
|
428
|
+
};
|
|
416
429
|
};
|
|
417
430
|
loadDocumentRequestsTemplateData: {
|
|
418
431
|
resource: string;
|
|
@@ -6,6 +6,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { compileClient } from '../../api/client/index.js';
|
|
8
8
|
import { defineApi } from '../../api/index.js';
|
|
9
|
+
import { defaultAccessControlAllowHeaders } from '../../api/utils.js';
|
|
10
|
+
import { bustCacheToken } from '../../http/tokens.js';
|
|
9
11
|
import { ReplaceClass } from '../../injector/decorators.js';
|
|
10
12
|
import { array, boolean, literal, number, object, optional, string } from '../../schema/index.js';
|
|
11
13
|
import { ServerSentEvents } from '../../sse/server-sent-events.js';
|
|
@@ -28,6 +30,12 @@ export const documentManagementApiDefinition = defineApi({
|
|
|
28
30
|
parameters: loadDataParametersSchema,
|
|
29
31
|
result: ServerSentEvents,
|
|
30
32
|
credentials: true,
|
|
33
|
+
data: {
|
|
34
|
+
[bustCacheToken]: true,
|
|
35
|
+
},
|
|
36
|
+
cors: {
|
|
37
|
+
accessControlAllowHeaders: `${defaultAccessControlAllowHeaders}, Cache-Control`,
|
|
38
|
+
},
|
|
31
39
|
},
|
|
32
40
|
loadDocumentRequestsTemplateData: {
|
|
33
41
|
resource: 'views/document-requests-template-data',
|
|
@@ -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' } } });
|
package/http/index.d.ts
CHANGED
package/http/index.js
CHANGED
package/http/tokens.d.ts
ADDED
package/http/tokens.js
ADDED