@clairejs/server 3.26.0 → 3.26.2
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 +8 -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/dist/job/AbstractJobScheduler.d.ts +5 -0
- package/dist/job/AbstractJobScheduler.js +2 -0
- package/dist/job/AwsJobScheduler.d.ts +1 -0
- package/dist/job/AwsJobScheduler.js +8 -0
- package/dist/job/LocalJobScheduler.d.ts +1 -0
- package/dist/job/LocalJobScheduler.js +3 -0
- 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
|
})());
|
|
@@ -29,6 +29,11 @@ export declare abstract class AbstractJobScheduler {
|
|
|
29
29
|
* @param id The job id returned from scheduleJobAt function
|
|
30
30
|
*/
|
|
31
31
|
protected abstract cancelJob(id: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Clean up the job after it has been executed
|
|
34
|
+
* @param job The job to clean up
|
|
35
|
+
*/
|
|
36
|
+
protected abstract cleanupJob(job: AbstractJob): Promise<void>;
|
|
32
37
|
/**
|
|
33
38
|
* Remove the scheduled job and prevent if from running in the future
|
|
34
39
|
* @param id The job id returned from scheduleJobAt function
|
|
@@ -129,6 +129,8 @@ export class AbstractJobScheduler {
|
|
|
129
129
|
await jobHandler.handlerFn(job);
|
|
130
130
|
//-- job run success, update
|
|
131
131
|
update.lastSuccessAt = Date.now();
|
|
132
|
+
//-- clean up
|
|
133
|
+
await this.cleanupJob(job);
|
|
132
134
|
//-- reset retry count if this is cron job
|
|
133
135
|
if (job.cron) {
|
|
134
136
|
if (job.retryCount) {
|
|
@@ -19,6 +19,7 @@ export declare class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
19
19
|
constructor(logger: AbstractLogger, db: AbstractDbAdapter, jobRepo: AbstractJobRepository, apiLambdaFunctionArn: string, jobNamespace: string, eventBusName?: string);
|
|
20
20
|
handleCron(jobInfo: AbstractJob): Promise<void>;
|
|
21
21
|
private generateCronFromTimestamp;
|
|
22
|
+
protected cleanupJob(job: AbstractJob): Promise<void>;
|
|
22
23
|
protected getScheduledJobs(): Promise<AbstractJob[]>;
|
|
23
24
|
protected _scheduleJob(jobInfo: AbstractJob): Promise<void>;
|
|
24
25
|
cancelJob(jobId: string): Promise<void>;
|
|
@@ -49,6 +49,14 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
49
49
|
date.getUTCFullYear(),
|
|
50
50
|
].join(" ");
|
|
51
51
|
}
|
|
52
|
+
async cleanupJob(job) {
|
|
53
|
+
if (job.cron) {
|
|
54
|
+
//-- do nothing
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
await this.cancelJob(job.id);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
52
60
|
async getScheduledJobs() {
|
|
53
61
|
const allRules = await this.eventbridge
|
|
54
62
|
.listRules({
|
|
@@ -50,6 +50,7 @@ export declare class LocalJobScheduler extends AbstractJobScheduler implements I
|
|
|
50
50
|
private sendJob;
|
|
51
51
|
private processMessage;
|
|
52
52
|
private extendMutexKey;
|
|
53
|
+
protected cleanupJob(): Promise<void>;
|
|
53
54
|
init(): Promise<void>;
|
|
54
55
|
exit(): void;
|
|
55
56
|
protected getScheduledJobs(): Promise<AbstractJob[]>;
|
|
@@ -103,6 +103,9 @@ let LocalJobScheduler = class LocalJobScheduler extends AbstractJobScheduler {
|
|
|
103
103
|
await this.redisClient.setex(this.holdMutexKey, this.keyRetentionDurationSeconds, 1);
|
|
104
104
|
this.logger.debug("Scheduler extends mutex key");
|
|
105
105
|
}
|
|
106
|
+
async cleanupJob() {
|
|
107
|
+
//-- do nothing
|
|
108
|
+
}
|
|
106
109
|
async init() {
|
|
107
110
|
this.logger.debug("LocalJobScheduler init");
|
|
108
111
|
//-- subscribe to multi client channel
|