imean-service-engine 1.2.2 → 1.2.3

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/dist/mod.cjs CHANGED
@@ -483,8 +483,10 @@ var ActionHandler = class {
483
483
  async _handle(req) {
484
484
  const span = api.trace.getActiveSpan();
485
485
  const { args, requestHash } = await this._validate(req);
486
+ const cacheHash = typeof this.metadata.cache === "function" ? this.metadata.cache(...args) : requestHash;
487
+ const cacheKey = `${this.moduleName}.${this.actionName}.${hashText(ejson3__default.default.stringify(cacheHash))}`;
488
+ span?.setAttribute("args", JSON.stringify(args));
486
489
  if (!this.metadata.stream && this.metadata.cache && !this.microservice.options.disableCache) {
487
- const cacheKey = `${this.moduleName}.${this.actionName}.${requestHash}`;
488
490
  const cached = await this.microservice.cache.get(cacheKey);
489
491
  const now = Date.now();
490
492
  if (cached !== null && (!this.metadata.ttl || cached?.expireAt > now)) {
@@ -530,7 +532,6 @@ var ActionHandler = class {
530
532
  }
531
533
  }
532
534
  if (this.metadata.cache && !this.microservice.options.disableCache) {
533
- const cacheKey = `${this.moduleName}.${this.actionName}.${requestHash}`;
534
535
  const now = Date.now();
535
536
  this.microservice.cache.set(
536
537
  cacheKey,
package/dist/mod.d.cts CHANGED
@@ -6,20 +6,21 @@ import { LRUCache } from 'lru-cache';
6
6
  export { default as dayjs } from 'dayjs';
7
7
  import winston from 'winston';
8
8
 
9
+ type CacheFn = (...args: any[]) => any;
9
10
  interface ActionOptions {
10
11
  params?: z.ZodType<any>[];
11
12
  returns?: z.ZodType<any>;
12
13
  idempotence?: boolean;
13
14
  description?: string;
14
15
  printError?: boolean;
15
- cache?: boolean;
16
+ cache?: boolean | CacheFn;
16
17
  ttl?: number;
17
18
  stream?: boolean;
18
19
  }
19
20
  interface ActionMetadata extends ActionOptions {
20
21
  name: string;
21
22
  idempotence: boolean;
22
- cache?: boolean;
23
+ cache?: boolean | CacheFn;
23
24
  ttl?: number;
24
25
  stream?: boolean;
25
26
  }
@@ -258,4 +259,4 @@ declare function Schedule(options: ScheduleOptions): Function;
258
259
 
259
260
  declare const logger: winston.Logger;
260
261
 
261
- export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, type EtcdConfig, type EventServiceInfo, Microservice, type MicroserviceOptions, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, type PreStartChecker, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, type ServiceStats, type StatisticsEvent, type StreamResponse, logger, startCheck };
262
+ export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, type CacheFn, type EtcdConfig, type EventServiceInfo, Microservice, type MicroserviceOptions, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, type PreStartChecker, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, type ServiceStats, type StatisticsEvent, type StreamResponse, logger, startCheck };
package/dist/mod.d.ts CHANGED
@@ -6,20 +6,21 @@ import { LRUCache } from 'lru-cache';
6
6
  export { default as dayjs } from 'dayjs';
7
7
  import winston from 'winston';
8
8
 
9
+ type CacheFn = (...args: any[]) => any;
9
10
  interface ActionOptions {
10
11
  params?: z.ZodType<any>[];
11
12
  returns?: z.ZodType<any>;
12
13
  idempotence?: boolean;
13
14
  description?: string;
14
15
  printError?: boolean;
15
- cache?: boolean;
16
+ cache?: boolean | CacheFn;
16
17
  ttl?: number;
17
18
  stream?: boolean;
18
19
  }
19
20
  interface ActionMetadata extends ActionOptions {
20
21
  name: string;
21
22
  idempotence: boolean;
22
- cache?: boolean;
23
+ cache?: boolean | CacheFn;
23
24
  ttl?: number;
24
25
  stream?: boolean;
25
26
  }
@@ -258,4 +259,4 @@ declare function Schedule(options: ScheduleOptions): Function;
258
259
 
259
260
  declare const logger: winston.Logger;
260
261
 
261
- export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, type EtcdConfig, type EventServiceInfo, Microservice, type MicroserviceOptions, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, type PreStartChecker, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, type ServiceStats, type StatisticsEvent, type StreamResponse, logger, startCheck };
262
+ export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, type CacheFn, type EtcdConfig, type EventServiceInfo, Microservice, type MicroserviceOptions, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, type PreStartChecker, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, type ServiceStats, type StatisticsEvent, type StreamResponse, logger, startCheck };
package/dist/mod.js CHANGED
@@ -474,8 +474,10 @@ var ActionHandler = class {
474
474
  async _handle(req) {
475
475
  const span = trace.getActiveSpan();
476
476
  const { args, requestHash } = await this._validate(req);
477
+ const cacheHash = typeof this.metadata.cache === "function" ? this.metadata.cache(...args) : requestHash;
478
+ const cacheKey = `${this.moduleName}.${this.actionName}.${hashText(ejson3.stringify(cacheHash))}`;
479
+ span?.setAttribute("args", JSON.stringify(args));
477
480
  if (!this.metadata.stream && this.metadata.cache && !this.microservice.options.disableCache) {
478
- const cacheKey = `${this.moduleName}.${this.actionName}.${requestHash}`;
479
481
  const cached = await this.microservice.cache.get(cacheKey);
480
482
  const now = Date.now();
481
483
  if (cached !== null && (!this.metadata.ttl || cached?.expireAt > now)) {
@@ -521,7 +523,6 @@ var ActionHandler = class {
521
523
  }
522
524
  }
523
525
  if (this.metadata.cache && !this.microservice.options.disableCache) {
524
- const cacheKey = `${this.moduleName}.${this.actionName}.${requestHash}`;
525
526
  const now = Date.now();
526
527
  this.microservice.cache.set(
527
528
  cacheKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imean-service-engine",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "microservice engine",
5
5
  "keywords": [
6
6
  "microservice",