@clairejs/server 3.22.7 → 3.22.9
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 +7 -1
- package/dist/common/decorator.d.ts +1 -1
- package/dist/http/common/HttpResponse.d.ts +0 -1
- package/dist/http/repository/DtoRepository.d.ts +6 -6
- package/dist/http/repository/ModelRepository.d.ts +1 -1
- package/dist/job/AbstractJobScheduler.d.ts +3 -2
- package/dist/job/AbstractJobScheduler.js +16 -19
- package/dist/job/AwsJobScheduler.d.ts +4 -0
- package/dist/job/AwsJobScheduler.js +6 -4
- package/dist/job/LocalJobScheduler.d.ts +2 -2
- package/dist/job/LocalJobScheduler.js +4 -4
- package/dist/job/decorators.d.ts +5 -2
- package/dist/job/decorators.js +2 -2
- package/dist/logging/FileLogMedium.js +2 -1
- package/dist/services/AbstractFileService.d.ts +0 -1
- package/dist/services/implementations/LocalFileService.d.ts +0 -1
- package/dist/services/implementations/S3FileService.d.ts +0 -1
- package/dist/socket/LocalSocketManager.d.ts +0 -1
- package/dist/system/locale/decorators.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
-
#### 3.22.
|
|
3
|
+
#### 3.22.9
|
|
4
4
|
|
|
5
|
+
- fix typing issue with job handler function
|
|
6
|
+
- fix providing transaction to job remove function
|
|
7
|
+
|
|
8
|
+
#### 3.22.8
|
|
9
|
+
|
|
10
|
+
- remove log, aws job scheduler issue fixed
|
|
5
11
|
- add log
|
|
6
12
|
- fix Lambda Wrapper resolve job scheduler
|
|
7
13
|
- add log to debug aws cron
|
|
@@ -4,4 +4,4 @@ import { AbstractHttpController } from "../http/controller/AbstractHttpControlle
|
|
|
4
4
|
export declare const Controller: (config?: {
|
|
5
5
|
mount?: string;
|
|
6
6
|
permissionGroup?: string;
|
|
7
|
-
}) => <T extends
|
|
7
|
+
}) => <T extends AbstractHttpController | AbstractSocketController>(constructor: Constructor<T>) => void;
|
|
@@ -12,20 +12,20 @@ export interface MappingMetadata<R extends Identifiable, K extends AbstractModel
|
|
|
12
12
|
rootMapping: (ks?: DeepPartial<K>[]) => DeepPartial<R>;
|
|
13
13
|
nestedMapping?: DtoDissolver<R, K>;
|
|
14
14
|
}
|
|
15
|
-
export declare const SingleMap: <R extends Identifiable, K extends AbstractModel>(modelClass: Constructor<K>, forwardOps: (ops?: QueryCondition<R>[]
|
|
15
|
+
export declare const SingleMap: <R extends Identifiable, K extends AbstractModel>(modelClass: Constructor<K>, forwardOps: (ops?: QueryCondition<R>[]) => QueryCondition<K>[] | undefined, forwardMapping: (t: DeepPartial<K>) => DeepPartial<K> | undefined, rootMapping: (k?: DeepPartial<K>) => DeepPartial<R>, nestedMapping?: DtoDissolver<R, K>) => {
|
|
16
16
|
multiple: boolean;
|
|
17
17
|
modelClass: Constructor<K>;
|
|
18
|
-
forwardOps: (ops?: QueryCondition<R>[]
|
|
18
|
+
forwardOps: (ops?: QueryCondition<R>[]) => QueryCondition<K>[] | undefined;
|
|
19
19
|
forwardMapping: (t: DeepPartial<K>[]) => DeepPartial<K>[] | undefined;
|
|
20
|
-
rootMapping: (ks?: DeepPartial<K>[]
|
|
20
|
+
rootMapping: (ks?: DeepPartial<K>[]) => DeepPartial<R>;
|
|
21
21
|
nestedMapping: DtoDissolver<R, K> | undefined;
|
|
22
22
|
};
|
|
23
|
-
export declare const MultipleMap: <R extends Identifiable, K extends AbstractModel>(modelClass: Constructor<K>, forwardOps: (ops?: QueryCondition<R>[]
|
|
23
|
+
export declare const MultipleMap: <R extends Identifiable, K extends AbstractModel>(modelClass: Constructor<K>, forwardOps: (ops?: QueryCondition<R>[]) => QueryCondition<K>[] | undefined, forwardMapping: (t: DeepPartial<K>[]) => DeepPartial<K>[] | undefined, rootMapping: (ks?: DeepPartial<K>[]) => DeepPartial<R>, nestedMapping?: DtoDissolver<R, K>) => {
|
|
24
24
|
multiple: boolean;
|
|
25
25
|
modelClass: Constructor<K>;
|
|
26
|
-
forwardOps: (ops?: QueryCondition<R>[]
|
|
26
|
+
forwardOps: (ops?: QueryCondition<R>[]) => QueryCondition<K>[] | undefined;
|
|
27
27
|
forwardMapping: (t: DeepPartial<K>[]) => DeepPartial<K>[] | undefined;
|
|
28
|
-
rootMapping: (ks?: DeepPartial<K>[]
|
|
28
|
+
rootMapping: (ks?: DeepPartial<K>[]) => DeepPartial<R>;
|
|
29
29
|
nestedMapping: DtoDissolver<R, K> | undefined;
|
|
30
30
|
};
|
|
31
31
|
export declare class DtoRepository<T extends Identifiable> extends AbstractRepository<T> implements ICrudRepository<T> {
|
|
@@ -27,7 +27,7 @@ export declare class ModelRepository<T extends AbstractModel> extends AbstractRe
|
|
|
27
27
|
tx: ITransaction;
|
|
28
28
|
logger?: AbstractLogger;
|
|
29
29
|
}): Promise<UpdateManyResponse<T>>;
|
|
30
|
-
getMany({ queries, ops, tx, logger, }: {
|
|
30
|
+
getMany({ queries, ops, tx, logger: _logger, }: {
|
|
31
31
|
queries?: GetManyQueries<T>;
|
|
32
32
|
ops?: QueryCondition<T>[];
|
|
33
33
|
tx?: ITransaction;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AbstractLogger } from "@clairejs/core";
|
|
2
2
|
import { ITransaction, ITransactionFactory } from "@clairejs/orm";
|
|
3
3
|
import { CustomJobInfo, JobInfo, JobInfoMetadata, ScheduledJob } from "./interfaces";
|
|
4
|
+
export type JobHandlerFn = (job: ScheduledJob, tx: ITransaction) => Promise<ScheduledJob | void>;
|
|
4
5
|
interface JobHandlerMetadata extends JobInfoMetadata {
|
|
5
|
-
handlerFn:
|
|
6
|
+
handlerFn: JobHandlerFn;
|
|
6
7
|
}
|
|
7
8
|
export declare abstract class AbstractJobScheduler {
|
|
8
9
|
protected readonly logger: AbstractLogger;
|
|
@@ -31,7 +32,7 @@ export declare abstract class AbstractJobScheduler {
|
|
|
31
32
|
* Remove the scheduled job and prevent if from running in the future
|
|
32
33
|
* @param id The job id returned from scheduleJobAt function
|
|
33
34
|
*/
|
|
34
|
-
abstract removeJob(id: string): Promise<void>;
|
|
35
|
+
abstract removeJob(id: string, tx?: ITransaction): Promise<void>;
|
|
35
36
|
/**
|
|
36
37
|
* Execute the scheduled job
|
|
37
38
|
* @param job The schedled job info to execute
|
|
@@ -35,28 +35,26 @@ export class AbstractJobScheduler {
|
|
|
35
35
|
//-- run job
|
|
36
36
|
const allJobs = await this.getAvailableJobInfo();
|
|
37
37
|
const jobHandler = allJobs.find((j) => j.jobName === job.jobName);
|
|
38
|
-
if (!jobHandler) {
|
|
39
|
-
//-- remove job
|
|
40
|
-
this.logger.info(`Remove job with id: ${job.id} as handler is not found`);
|
|
41
|
-
await this.removeJob(job.id);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
38
|
const tx = await this.db.createTransaction();
|
|
45
39
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
if (!jobHandler) {
|
|
41
|
+
//-- remove job
|
|
42
|
+
this.logger.info(`Remove job with id: ${job.id} as handler is not found`);
|
|
43
|
+
await this.removeJob(job.id, tx);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const newJob = await jobHandler.handlerFn({ ...job }, tx);
|
|
47
|
+
if (job.at) {
|
|
48
|
+
if (!newJob) {
|
|
49
|
+
await this.removeJob(job.id, tx);
|
|
50
|
+
this.logger.info(`Remove one-time job ${job.jobName} at timestamp ${job.at}`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await this.afterJob(newJob, tx);
|
|
54
|
+
}
|
|
57
55
|
}
|
|
56
|
+
this.logger.debug("Job tx commiting");
|
|
58
57
|
}
|
|
59
|
-
this.logger.debug("Job tx commiting");
|
|
60
58
|
await tx.commit();
|
|
61
59
|
this.logger.debug("Job tx committed");
|
|
62
60
|
}
|
|
@@ -64,6 +62,5 @@ export class AbstractJobScheduler {
|
|
|
64
62
|
this.logger.error("Error handling job", err);
|
|
65
63
|
await tx.rollback();
|
|
66
64
|
}
|
|
67
|
-
return;
|
|
68
65
|
}
|
|
69
66
|
}
|
|
@@ -3,6 +3,10 @@ import { AbstractDbAdapter, ITransaction } from "@clairejs/orm";
|
|
|
3
3
|
import aws from "aws-sdk";
|
|
4
4
|
import { AbstractJobScheduler } from "./AbstractJobScheduler";
|
|
5
5
|
import { JobInfo, ScheduledJob } from "./interfaces";
|
|
6
|
+
/**
|
|
7
|
+
* Following EventBrige permissions is required: listRules, putRule, deleteRule, listTargetsByRule, putTargets, removeTargets.
|
|
8
|
+
* Also update Lambda function to alow function invocation from events.amazonaws.com.
|
|
9
|
+
*/
|
|
6
10
|
export declare class AwsJobScheduler extends AbstractJobScheduler {
|
|
7
11
|
protected readonly logger: AbstractLogger;
|
|
8
12
|
protected readonly db: AbstractDbAdapter;
|
|
@@ -12,6 +12,10 @@ import { AbstractDbAdapter } from "@clairejs/orm";
|
|
|
12
12
|
import assert from "assert";
|
|
13
13
|
import aws from "aws-sdk";
|
|
14
14
|
import { AbstractJobScheduler } from "./AbstractJobScheduler";
|
|
15
|
+
/**
|
|
16
|
+
* Following EventBrige permissions is required: listRules, putRule, deleteRule, listTargetsByRule, putTargets, removeTargets.
|
|
17
|
+
* Also update Lambda function to alow function invocation from events.amazonaws.com.
|
|
18
|
+
*/
|
|
15
19
|
let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
16
20
|
logger;
|
|
17
21
|
db;
|
|
@@ -20,9 +24,7 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
20
24
|
eventBusName;
|
|
21
25
|
jobNamePrefix;
|
|
22
26
|
eventbridge = new aws.EventBridge();
|
|
23
|
-
constructor(logger, db, uniqueJobIdFactory,
|
|
24
|
-
//-- ARN of the API lambda function, following EventBrige permissions is required: listRules, putRule, deleteRule, listTargetsByRule, putTargets, removeTargets
|
|
25
|
-
apiLambdaFunctionArn, eventBusName = "default", jobNamePrefix = "claire-aws-job-") {
|
|
27
|
+
constructor(logger, db, uniqueJobIdFactory, apiLambdaFunctionArn, eventBusName = "default", jobNamePrefix = "claire-aws-job-") {
|
|
26
28
|
super(logger, db);
|
|
27
29
|
this.logger = logger;
|
|
28
30
|
this.db = db;
|
|
@@ -116,7 +118,7 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
116
118
|
Input: JSON.stringify({
|
|
117
119
|
requestContext: {
|
|
118
120
|
cronScheduler: {
|
|
119
|
-
data: { ...jobInfo, jobId },
|
|
121
|
+
data: { ...jobInfo, id: jobId },
|
|
120
122
|
},
|
|
121
123
|
},
|
|
122
124
|
}),
|
|
@@ -65,6 +65,6 @@ export declare class LocalJobScheduler extends AbstractJobScheduler implements I
|
|
|
65
65
|
protected isActiveScheduler(): boolean;
|
|
66
66
|
getAllScheduledJobs(): Promise<ScheduledJob[]>;
|
|
67
67
|
syncJobs(): Promise<void>;
|
|
68
|
-
protected scheduleJob(jobInfo: JobInfo): Promise<string>;
|
|
69
|
-
removeJob(id: string): Promise<void>;
|
|
68
|
+
protected scheduleJob(jobInfo: JobInfo, tx?: ITransaction): Promise<string>;
|
|
69
|
+
removeJob(id: string, tx?: ITransaction): Promise<void>;
|
|
70
70
|
}
|
|
@@ -195,7 +195,7 @@ let LocalJobScheduler = class LocalJobScheduler extends AbstractJobScheduler {
|
|
|
195
195
|
}
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
198
|
-
async scheduleJob(jobInfo) {
|
|
198
|
+
async scheduleJob(jobInfo, tx) {
|
|
199
199
|
if (this.isActive) {
|
|
200
200
|
//-- case each job type
|
|
201
201
|
if (jobInfo.at) {
|
|
@@ -205,7 +205,7 @@ let LocalJobScheduler = class LocalJobScheduler extends AbstractJobScheduler {
|
|
|
205
205
|
jobName: jobInfo.jobName,
|
|
206
206
|
params: jobInfo.params,
|
|
207
207
|
at: jobInfo.at,
|
|
208
|
-
}));
|
|
208
|
+
}, tx));
|
|
209
209
|
//-- use the lib
|
|
210
210
|
const scheduledJob = { ...jobInfo, id };
|
|
211
211
|
const timeout = setTimeout(() => {
|
|
@@ -237,7 +237,7 @@ let LocalJobScheduler = class LocalJobScheduler extends AbstractJobScheduler {
|
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
async removeJob(id) {
|
|
240
|
+
async removeJob(id, tx) {
|
|
241
241
|
if (this.isActive) {
|
|
242
242
|
//-- remove from holder
|
|
243
243
|
const job = this.jobHolder[id];
|
|
@@ -246,7 +246,7 @@ let LocalJobScheduler = class LocalJobScheduler extends AbstractJobScheduler {
|
|
|
246
246
|
this.jobHolder[id] = undefined;
|
|
247
247
|
}
|
|
248
248
|
//-- remove from persistence
|
|
249
|
-
await this.jobRepo.removeJobById(id);
|
|
249
|
+
await this.jobRepo.removeJobById(id, tx);
|
|
250
250
|
}
|
|
251
251
|
else {
|
|
252
252
|
//-- get unique message id
|
package/dist/job/decorators.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { AbstractJobController } from "./AbstractJobController";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { JobHandlerFn } from "./AbstractJobScheduler";
|
|
3
|
+
type Descriptor<T> = Omit<TypedPropertyDescriptor<T>, "set">;
|
|
4
|
+
export declare const CronJob: (jobName: string, cron: string) => <T extends AbstractJobController>(prototype: T, propertyKey: keyof T, _descriptor: Descriptor<JobHandlerFn>) => void;
|
|
5
|
+
export declare const CustomJob: (jobName: string) => <T extends AbstractJobController>(prototype: T, propertyKey: keyof T, _descriptor: Descriptor<JobHandlerFn>) => void;
|
|
6
|
+
export {};
|
package/dist/job/decorators.js
CHANGED
|
@@ -7,7 +7,7 @@ jobName,
|
|
|
7
7
|
/**
|
|
8
8
|
* Cron expression
|
|
9
9
|
*/
|
|
10
|
-
cron) => (prototype, propertyKey) => {
|
|
10
|
+
cron) => (prototype, propertyKey, _descriptor) => {
|
|
11
11
|
const metadata = initObjectMetadata(prototype);
|
|
12
12
|
if (!metadata.jobs) {
|
|
13
13
|
metadata.jobs = [];
|
|
@@ -26,7 +26,7 @@ export const CustomJob = (
|
|
|
26
26
|
/**
|
|
27
27
|
* Unique name of job
|
|
28
28
|
*/
|
|
29
|
-
jobName) => (prototype, propertyKey) => {
|
|
29
|
+
jobName) => (prototype, propertyKey, _descriptor) => {
|
|
30
30
|
const metadata = initObjectMetadata(prototype);
|
|
31
31
|
if (!metadata.jobs) {
|
|
32
32
|
metadata.jobs = [];
|
|
@@ -11,7 +11,8 @@ var FileLogMedium_1;
|
|
|
11
11
|
import fs from "fs";
|
|
12
12
|
import path from "path";
|
|
13
13
|
import { LogLevel, Initable } from "@clairejs/core";
|
|
14
|
-
let FileLogMedium =
|
|
14
|
+
let FileLogMedium = class FileLogMedium {
|
|
15
|
+
static { FileLogMedium_1 = this; }
|
|
15
16
|
static levels = Object.values(LogLevel);
|
|
16
17
|
destination;
|
|
17
18
|
separated;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AbstractModel } from "@clairejs/core";
|
|
2
|
-
export declare const LocaleOf: <T>(referenceColumn: keyof T) => <K extends string>(prototype: T & AbstractModel & { [k in K]?: Record<string, string
|
|
2
|
+
export declare const LocaleOf: <T>(referenceColumn: keyof T) => <K extends string>(prototype: T & AbstractModel & { [k in K]?: Record<string, string>; }, propertyKey: K) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clairejs/server",
|
|
3
|
-
"version": "3.22.
|
|
3
|
+
"version": "3.22.9",
|
|
4
4
|
"description": "Claire server NodeJs framework written in Typescript.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"id-sdk": "^1.5.16",
|
|
53
53
|
"mocha": "^10.2.0",
|
|
54
54
|
"ts-node": "^10.9.1",
|
|
55
|
-
"typescript": "^5.
|
|
55
|
+
"typescript": "^5.5.4",
|
|
56
56
|
"uuid": "^9.0.0"
|
|
57
57
|
}
|
|
58
58
|
}
|