@clairejs/server 3.22.8 → 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 CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Change Log
2
2
 
3
+ #### 3.22.9
4
+
5
+ - fix typing issue with job handler function
6
+ - fix providing transaction to job remove function
7
+
3
8
  #### 3.22.8
4
9
 
5
10
  - remove log, aws job scheduler issue fixed
@@ -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 AbstractSocketController | AbstractHttpController>(constructor: Constructor<T>) => void;
7
+ }) => <T extends AbstractHttpController | AbstractSocketController>(constructor: Constructor<T>) => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  export interface CookieOptions {
3
2
  maxAge?: number | undefined;
4
3
  expires?: Date | undefined;
@@ -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>[] | undefined) => QueryCondition<K>[] | undefined, forwardMapping: (t: DeepPartial<K>) => DeepPartial<K> | undefined, rootMapping: (k?: DeepPartial<K> | undefined) => DeepPartial<R>, nestedMapping?: DtoDissolver<R, K> | undefined) => {
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>[] | undefined) => QueryCondition<K>[] | undefined;
18
+ forwardOps: (ops?: QueryCondition<R>[]) => QueryCondition<K>[] | undefined;
19
19
  forwardMapping: (t: DeepPartial<K>[]) => DeepPartial<K>[] | undefined;
20
- rootMapping: (ks?: DeepPartial<K>[] | undefined) => DeepPartial<R>;
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>[] | undefined) => QueryCondition<K>[] | undefined, forwardMapping: (t: DeepPartial<K>[]) => DeepPartial<K>[] | undefined, rootMapping: (ks?: DeepPartial<K>[] | undefined) => DeepPartial<R>, nestedMapping?: DtoDissolver<R, K> | undefined) => {
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>[] | undefined) => QueryCondition<K>[] | undefined;
26
+ forwardOps: (ops?: QueryCondition<R>[]) => QueryCondition<K>[] | undefined;
27
27
  forwardMapping: (t: DeepPartial<K>[]) => DeepPartial<K>[] | undefined;
28
- rootMapping: (ks?: DeepPartial<K>[] | undefined) => DeepPartial<R>;
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: (job: ScheduledJob, tx: ITransaction) => Promise<ScheduledJob | undefined>;
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,25 +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
- const newJob = await jobHandler.handlerFn({ ...job }, tx);
47
- if (job.at) {
48
- if (!newJob) {
49
- await this.removeJob(job.id);
50
- this.logger.info(`Remove one-time job ${job.jobName} at timestamp ${job.at}`);
51
- }
52
- else {
53
- await this.afterJob(newJob, tx);
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
+ }
54
55
  }
56
+ this.logger.debug("Job tx commiting");
55
57
  }
56
- this.logger.debug("Job tx commiting");
57
58
  await tx.commit();
58
59
  this.logger.debug("Job tx committed");
59
60
  }
@@ -61,6 +62,5 @@ export class AbstractJobScheduler {
61
62
  this.logger.error("Error handling job", err);
62
63
  await tx.rollback();
63
64
  }
64
- return;
65
65
  }
66
66
  }
@@ -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
@@ -1,3 +1,6 @@
1
1
  import { AbstractJobController } from "./AbstractJobController";
2
- export declare const CronJob: (jobName: string, cron: string) => <T extends AbstractJobController>(prototype: T, propertyKey: keyof T) => void;
3
- export declare const CustomJob: (jobName: string) => <T extends AbstractJobController>(prototype: T, propertyKey: keyof T) => void;
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 {};
@@ -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 = FileLogMedium_1 = class 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,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FileOperation } from "../common/FileOperation";
3
2
  import { GetUploadUrlResponseBody } from "../controllers/dto/upload";
4
3
  export declare abstract class AbstractFileService {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FileOperation } from "../../common/FileOperation";
3
2
  import { AbstractFileService } from "../AbstractFileService";
4
3
  export declare class LocalFileService extends AbstractFileService {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { AbstractLogger } from "@clairejs/core";
3
2
  import { FileOperation } from "../../common/FileOperation";
4
3
  import { AbstractFileService } from "../AbstractFileService";
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { AbstractLogger, IInit } from "@clairejs/core";
3
2
  import WebSocket from "ws";
4
3
  import { Server } from "http";
@@ -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> | undefined; }, propertyKey: K) => void;
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.8",
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.0.4",
55
+ "typescript": "^5.5.4",
56
56
  "uuid": "^9.0.0"
57
57
  }
58
58
  }