@clairejs/server 3.26.0 → 3.26.1
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/README.md +4 -0
- package/dist/http/file-upload/AbstractFileUploadHandler.d.ts +0 -2
- package/dist/http/file-upload/FileUploadHandler.d.ts +0 -2
- package/dist/http/file-upload/FileUploadHandler.js +0 -8
- package/dist/http/repository/ModelRepository.d.ts +4 -2
- package/dist/http/repository/ModelRepository.js +17 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,4 @@ export declare abstract class AbstractFileUploadHandler {
|
|
|
2
2
|
abstract moveFile(fromUri: string, toUri: string): Promise<void>;
|
|
3
3
|
abstract copyFile(fromUri: string, toUri: string): Promise<void>;
|
|
4
4
|
abstract removeFile(uri: string): Promise<void>;
|
|
5
|
-
abstract resolvePublicUrl(uri: string): Promise<string>;
|
|
6
|
-
abstract resolvePrivateUrl(uri: string): Promise<string>;
|
|
7
5
|
}
|
|
@@ -8,6 +8,4 @@ export declare class FileUploadHandler extends AbstractFileUploadHandler {
|
|
|
8
8
|
moveFile(fromURI: string, toURI: string): Promise<void>;
|
|
9
9
|
copyFile(fromURI: string, toURI: string): Promise<void>;
|
|
10
10
|
removeFile(uri: string): Promise<void>;
|
|
11
|
-
resolvePublicUrl(uri: string): Promise<string>;
|
|
12
|
-
resolvePrivateUrl(uri: string): Promise<string>;
|
|
13
11
|
}
|
|
@@ -19,12 +19,4 @@ export class FileUploadHandler extends AbstractFileUploadHandler {
|
|
|
19
19
|
async removeFile(uri) {
|
|
20
20
|
await this.fileService.removeObject([this.getPath(uri)]);
|
|
21
21
|
}
|
|
22
|
-
async resolvePublicUrl(uri) {
|
|
23
|
-
const result = await this.fileService.getAccessUrls([this.getPath(uri)], true);
|
|
24
|
-
return result[0];
|
|
25
|
-
}
|
|
26
|
-
async resolvePrivateUrl(uri) {
|
|
27
|
-
const result = await this.fileService.getAccessUrls([this.getPath(uri)], false);
|
|
28
|
-
return result[0];
|
|
29
|
-
}
|
|
30
22
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { AbstractModel, Constructor, CreateManyRequestBody, CreateManyResponseBody, GetManyQueries, GetManyResponseBody, UpdateManyBody, UpdateManyQueries, UpdateManyResponse
|
|
1
|
+
import { AbstractLogger, AbstractModel, Constructor, CreateManyRequestBody, CreateManyResponseBody, GetManyQueries, GetManyResponseBody, UpdateManyBody, UpdateManyQueries, UpdateManyResponse } from "@clairejs/core";
|
|
2
2
|
import { AbstractDbAdapter, ITransaction, QueryCondition } from "@clairejs/orm";
|
|
3
3
|
import { IPrincipal } from "../../common/auth/IPrincipal";
|
|
4
|
-
import { ICrudRepository } from "./ICrudRepository";
|
|
5
4
|
import { AbstractRepository } from "./AbstractRepository";
|
|
5
|
+
import { ICrudRepository } from "./ICrudRepository";
|
|
6
6
|
export declare class ModelRepository<T extends AbstractModel> extends AbstractRepository<T> implements ICrudRepository<T> {
|
|
7
7
|
protected readonly model: Constructor<T>;
|
|
8
8
|
protected readonly db: AbstractDbAdapter;
|
|
9
9
|
private fileUploadHandler?;
|
|
10
|
+
private fileService?;
|
|
10
11
|
constructor(model: Constructor<T>, db: AbstractDbAdapter);
|
|
11
12
|
private getNestedQueries;
|
|
12
13
|
private getUploadHandler;
|
|
14
|
+
private getFileService;
|
|
13
15
|
private getRequestQueryConditionFromQuery;
|
|
14
16
|
uriHandling(records: Partial<T>[]): Promise<() => Promise<void>>;
|
|
15
17
|
beforeReturning(records: Partial<T>[]): Promise<void>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { DataType, getModelById, getServiceProvider,
|
|
1
|
+
import { DataType, Errors, getModelById, getServiceProvider, getSystemLocale, leanData, MODEL_FIELD_SEPARATOR, omitData, RangeQueryDto, uniqueReducer, } from "@clairejs/core";
|
|
2
2
|
import { getDirectFields, getSafeUpdate, } from "@clairejs/orm";
|
|
3
|
+
import { AbstractFileService } from "../../services/AbstractFileService";
|
|
4
|
+
import { LocaleEntry } from "../../system/locale/LocaleEntry";
|
|
5
|
+
import { LocaleTranslation } from "../../system/locale/LocaleTranslation";
|
|
3
6
|
import { AbstractFileUploadHandler } from "../file-upload/AbstractFileUploadHandler";
|
|
4
7
|
import { AbstractRepository } from "./AbstractRepository";
|
|
5
|
-
import { LocaleTranslation } from "../../system/locale/LocaleTranslation";
|
|
6
|
-
import { LocaleEntry } from "../../system/locale/LocaleEntry";
|
|
7
8
|
const resolveUris = (record, field) => {
|
|
8
9
|
return field.vectorProps?.elementDataType === DataType.STRING ? record[field.name] : [record[field.name]];
|
|
9
10
|
};
|
|
@@ -14,6 +15,7 @@ export class ModelRepository extends AbstractRepository {
|
|
|
14
15
|
model;
|
|
15
16
|
db;
|
|
16
17
|
fileUploadHandler;
|
|
18
|
+
fileService;
|
|
17
19
|
constructor(model, db) {
|
|
18
20
|
super(model);
|
|
19
21
|
this.model = model;
|
|
@@ -44,6 +46,14 @@ export class ModelRepository extends AbstractRepository {
|
|
|
44
46
|
}
|
|
45
47
|
return this.fileUploadHandler;
|
|
46
48
|
}
|
|
49
|
+
async getFileService() {
|
|
50
|
+
if (this.fileService === undefined) {
|
|
51
|
+
const injector = getServiceProvider().getInjector();
|
|
52
|
+
this.fileService = injector.resolveOptional(AbstractFileService) || null;
|
|
53
|
+
await injector.initInstances();
|
|
54
|
+
}
|
|
55
|
+
return this.fileService;
|
|
56
|
+
}
|
|
47
57
|
getRequestQueryConditionFromQuery(queries, modelMetadata) {
|
|
48
58
|
const result = [];
|
|
49
59
|
for (const fieldMetadata of getDirectFields(modelMetadata)) {
|
|
@@ -176,8 +186,8 @@ export class ModelRepository extends AbstractRepository {
|
|
|
176
186
|
}
|
|
177
187
|
async beforeReturning(records) {
|
|
178
188
|
//-- resolve url
|
|
179
|
-
const
|
|
180
|
-
if (!
|
|
189
|
+
const fileService = await this.getFileService();
|
|
190
|
+
if (!fileService) {
|
|
181
191
|
return;
|
|
182
192
|
}
|
|
183
193
|
const mappingOperations = [];
|
|
@@ -195,8 +205,8 @@ export class ModelRepository extends AbstractRepository {
|
|
|
195
205
|
mappingOperations.push((async () => {
|
|
196
206
|
const urls = await Promise.all(uris.map(async (uri) => {
|
|
197
207
|
return field.mimeProps?.public
|
|
198
|
-
? await
|
|
199
|
-
: await
|
|
208
|
+
? (await fileService.getAccessUrls([uri], true))[0]
|
|
209
|
+
: (await fileService.getAccessUrls([uri], false))[0];
|
|
200
210
|
}));
|
|
201
211
|
assignUrls(record, field, urls);
|
|
202
212
|
})());
|