@punks/backend-entity-manager 0.0.190 → 0.0.192

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.
@@ -2,8 +2,20 @@ export type CacheTtl = {
2
2
  value: number;
3
3
  unit: "years" | "months" | "days" | "hours" | "minutes" | "seconds";
4
4
  };
5
+ export type CacheEntryInfo = {
6
+ instanceName: string;
7
+ key: string;
8
+ expiration: Date;
9
+ createdOn: Date;
10
+ updatedOn: Date;
11
+ };
12
+ export type CacheEntryDetail = CacheEntryInfo & {
13
+ data: any;
14
+ };
5
15
  export interface ICacheInstance {
6
- getAll<T>(): Promise<T[]>;
16
+ getInstanceName(): string;
17
+ getEntries(): Promise<CacheEntryInfo[]>;
18
+ getEntry(key: string): Promise<CacheEntryDetail | undefined>;
7
19
  get<T>(key: string): Promise<T | undefined>;
8
20
  set<T>(key: string, input: {
9
21
  value: T;
@@ -1,15 +1,17 @@
1
1
  import { Repository } from "typeorm";
2
- import { CacheTtl, ICacheInstance } from "../../../abstractions";
2
+ import { CacheEntryDetail, CacheEntryInfo, CacheTtl, ICacheInstance } from "../../../abstractions";
3
3
  import { ICacheDatabaseItem } from "./types";
4
4
  export declare abstract class TypeormCacheInstance<TEntity extends ICacheDatabaseItem> implements ICacheInstance {
5
5
  protected readonly instanceName: string;
6
6
  private readonly logger;
7
7
  constructor(instanceName: string);
8
+ getInstanceName(): string;
9
+ getEntries(): Promise<CacheEntryInfo[]>;
10
+ getEntry(key: string): Promise<CacheEntryDetail | undefined>;
8
11
  retrieve<T>(key: string, input: {
9
12
  ttl: CacheTtl;
10
13
  valueFactory: () => Promise<T>;
11
14
  }): Promise<T>;
12
- getAll<T>(): Promise<T[]>;
13
15
  get<T>(key: string): Promise<T | undefined>;
14
16
  set<T>(key: string, { ttl, value }: {
15
17
  value: T;
package/dist/esm/index.js CHANGED
@@ -2330,6 +2330,44 @@ class TypeormCacheInstance {
2330
2330
  this.instanceName = instanceName;
2331
2331
  this.logger = Log.getLogger(`TypeOrm Cache Instance ${instanceName}`);
2332
2332
  }
2333
+ getInstanceName() {
2334
+ return this.instanceName;
2335
+ }
2336
+ async getEntries() {
2337
+ const items = await this.getRepository().find({
2338
+ where: {
2339
+ instance: this.instanceName,
2340
+ expirationTime: MoreThanOrEqual(new Date()),
2341
+ },
2342
+ });
2343
+ return items.map((item) => ({
2344
+ instanceName: this.instanceName,
2345
+ key: item.key,
2346
+ expiration: item.expirationTime,
2347
+ createdOn: item.createdOn,
2348
+ updatedOn: item.updatedOn,
2349
+ }));
2350
+ }
2351
+ async getEntry(key) {
2352
+ const item = await this.getRepository().findOne({
2353
+ where: {
2354
+ instance: this.instanceName,
2355
+ key,
2356
+ expirationTime: MoreThanOrEqual(new Date()),
2357
+ },
2358
+ });
2359
+ if (!item) {
2360
+ return undefined;
2361
+ }
2362
+ return {
2363
+ instanceName: this.instanceName,
2364
+ key: item.key,
2365
+ expiration: item.expirationTime,
2366
+ createdOn: item.createdOn,
2367
+ updatedOn: item.updatedOn,
2368
+ data: item.data,
2369
+ };
2370
+ }
2333
2371
  async retrieve(key, input) {
2334
2372
  const item = await this.getRepository().findOne({
2335
2373
  where: {
@@ -2344,15 +2382,6 @@ class TypeormCacheInstance {
2344
2382
  await this.set(key, { value, ttl: input.ttl });
2345
2383
  return value;
2346
2384
  }
2347
- async getAll() {
2348
- const items = await this.getRepository().find({
2349
- where: {
2350
- instance: this.instanceName,
2351
- expirationTime: MoreThanOrEqual(new Date()),
2352
- },
2353
- });
2354
- return items.map((item) => item.data);
2355
- }
2356
2385
  async get(key) {
2357
2386
  const item = await this.getRepository().findOne({
2358
2387
  where: {