@punks/backend-entity-manager 0.0.191 → 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.
- package/dist/cjs/index.js +35 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/cache.d.ts +12 -1
- package/dist/cjs/types/integrations/cache/typeorm/instance.d.ts +3 -2
- package/dist/esm/index.js +35 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/cache.d.ts +12 -1
- package/dist/esm/types/integrations/cache/typeorm/instance.d.ts +3 -2
- package/dist/index.d.ts +15 -3
- package/package.json +1 -1
|
@@ -2,9 +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
16
|
getInstanceName(): string;
|
|
7
|
-
|
|
17
|
+
getEntries(): Promise<CacheEntryInfo[]>;
|
|
18
|
+
getEntry(key: string): Promise<CacheEntryDetail | undefined>;
|
|
8
19
|
get<T>(key: string): Promise<T | undefined>;
|
|
9
20
|
set<T>(key: string, input: {
|
|
10
21
|
value: T;
|
|
@@ -1,16 +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
8
|
getInstanceName(): string;
|
|
9
|
+
getEntries(): Promise<CacheEntryInfo[]>;
|
|
10
|
+
getEntry(key: string): Promise<CacheEntryDetail | undefined>;
|
|
9
11
|
retrieve<T>(key: string, input: {
|
|
10
12
|
ttl: CacheTtl;
|
|
11
13
|
valueFactory: () => Promise<T>;
|
|
12
14
|
}): Promise<T>;
|
|
13
|
-
getAll<T>(): Promise<T[]>;
|
|
14
15
|
get<T>(key: string): Promise<T | undefined>;
|
|
15
16
|
set<T>(key: string, { ttl, value }: {
|
|
16
17
|
value: T;
|
package/dist/esm/index.js
CHANGED
|
@@ -2333,6 +2333,41 @@ class TypeormCacheInstance {
|
|
|
2333
2333
|
getInstanceName() {
|
|
2334
2334
|
return this.instanceName;
|
|
2335
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
|
+
}
|
|
2336
2371
|
async retrieve(key, input) {
|
|
2337
2372
|
const item = await this.getRepository().findOne({
|
|
2338
2373
|
where: {
|
|
@@ -2347,15 +2382,6 @@ class TypeormCacheInstance {
|
|
|
2347
2382
|
await this.set(key, { value, ttl: input.ttl });
|
|
2348
2383
|
return value;
|
|
2349
2384
|
}
|
|
2350
|
-
async getAll() {
|
|
2351
|
-
const items = await this.getRepository().find({
|
|
2352
|
-
where: {
|
|
2353
|
-
instance: this.instanceName,
|
|
2354
|
-
expirationTime: MoreThanOrEqual(new Date()),
|
|
2355
|
-
},
|
|
2356
|
-
});
|
|
2357
|
-
return items.map((item) => item.data);
|
|
2358
|
-
}
|
|
2359
2385
|
async get(key) {
|
|
2360
2386
|
const item = await this.getRepository().findOne({
|
|
2361
2387
|
where: {
|