@naturalcycles/js-lib 14.83.0 → 14.83.1
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Promisable } from '../typeFest';
|
|
1
2
|
export declare type MemoSerializer = (args: any[]) => any;
|
|
2
3
|
export declare const jsonMemoSerializer: MemoSerializer;
|
|
3
4
|
export interface MemoCache<KEY = any, VALUE = any> {
|
|
@@ -16,24 +17,18 @@ export interface AsyncMemoCache<KEY = any, VALUE = any> {
|
|
|
16
17
|
* This also means that you CANNOT store `undefined` value in the Cache, as it'll be treated as a MISS.
|
|
17
18
|
* You CAN store `null` value instead, it will be treated as a HIT.
|
|
18
19
|
*/
|
|
19
|
-
get(k: KEY):
|
|
20
|
-
set(k: KEY, v: VALUE):
|
|
20
|
+
get(k: KEY): Promisable<VALUE | undefined>;
|
|
21
|
+
set(k: KEY, v: VALUE): Promisable<void>;
|
|
21
22
|
/**
|
|
22
23
|
* Clear is only called when `.dropCache()` is called.
|
|
23
24
|
* Otherwise the Cache is "persistent" (never cleared).
|
|
24
25
|
*/
|
|
25
|
-
clear():
|
|
26
|
+
clear(): Promisable<void>;
|
|
26
27
|
}
|
|
27
|
-
export declare class MapMemoCache<KEY = any, VALUE = any> implements MemoCache<KEY, VALUE> {
|
|
28
|
+
export declare class MapMemoCache<KEY = any, VALUE = any> implements MemoCache<KEY, VALUE>, AsyncMemoCache<KEY, VALUE> {
|
|
28
29
|
private m;
|
|
29
30
|
has(k: KEY): boolean;
|
|
30
31
|
get(k: KEY): VALUE | undefined;
|
|
31
32
|
set(k: KEY, v: VALUE): void;
|
|
32
33
|
clear(): void;
|
|
33
34
|
}
|
|
34
|
-
export declare class MapAsyncMemoCache<KEY = any, VALUE = any> implements AsyncMemoCache<KEY, VALUE> {
|
|
35
|
-
private m;
|
|
36
|
-
get(k: KEY): Promise<VALUE | undefined>;
|
|
37
|
-
set(k: KEY, v: VALUE): Promise<void>;
|
|
38
|
-
clear(): Promise<void>;
|
|
39
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MapMemoCache = exports.jsonMemoSerializer = void 0;
|
|
4
4
|
const object_util_1 = require("../object/object.util");
|
|
5
5
|
const jsonMemoSerializer = args => {
|
|
6
6
|
if (args.length === 0)
|
|
@@ -73,18 +73,3 @@ class MapMemoCache {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
exports.MapMemoCache = MapMemoCache;
|
|
76
|
-
class MapAsyncMemoCache {
|
|
77
|
-
constructor() {
|
|
78
|
-
this.m = new Map();
|
|
79
|
-
}
|
|
80
|
-
async get(k) {
|
|
81
|
-
return this.m.get(k);
|
|
82
|
-
}
|
|
83
|
-
async set(k, v) {
|
|
84
|
-
this.m.set(k, v);
|
|
85
|
-
}
|
|
86
|
-
async clear() {
|
|
87
|
-
this.m.clear();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.MapAsyncMemoCache = MapAsyncMemoCache;
|
|
@@ -68,17 +68,3 @@ export class MapMemoCache {
|
|
|
68
68
|
this.m.clear();
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
export class MapAsyncMemoCache {
|
|
72
|
-
constructor() {
|
|
73
|
-
this.m = new Map();
|
|
74
|
-
}
|
|
75
|
-
async get(k) {
|
|
76
|
-
return this.m.get(k);
|
|
77
|
-
}
|
|
78
|
-
async set(k, v) {
|
|
79
|
-
this.m.set(k, v);
|
|
80
|
-
}
|
|
81
|
-
async clear() {
|
|
82
|
-
this.m.clear();
|
|
83
|
-
}
|
|
84
|
-
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _isPrimitive } from '../object/object.util'
|
|
2
|
+
import { Promisable } from '../typeFest'
|
|
2
3
|
|
|
3
4
|
export type MemoSerializer = (args: any[]) => any
|
|
4
5
|
|
|
@@ -28,14 +29,14 @@ export interface AsyncMemoCache<KEY = any, VALUE = any> {
|
|
|
28
29
|
* This also means that you CANNOT store `undefined` value in the Cache, as it'll be treated as a MISS.
|
|
29
30
|
* You CAN store `null` value instead, it will be treated as a HIT.
|
|
30
31
|
*/
|
|
31
|
-
get(k: KEY):
|
|
32
|
-
set(k: KEY, v: VALUE):
|
|
32
|
+
get(k: KEY): Promisable<VALUE | undefined>
|
|
33
|
+
set(k: KEY, v: VALUE): Promisable<void>
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Clear is only called when `.dropCache()` is called.
|
|
36
37
|
* Otherwise the Cache is "persistent" (never cleared).
|
|
37
38
|
*/
|
|
38
|
-
clear():
|
|
39
|
+
clear(): Promisable<void>
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
// SingleValueMemoCache and ObjectMemoCache are example-only, not used in production code
|
|
@@ -84,7 +85,9 @@ export class ObjectMemoCache implements MemoCache {
|
|
|
84
85
|
}
|
|
85
86
|
*/
|
|
86
87
|
|
|
87
|
-
export class MapMemoCache<KEY = any, VALUE = any>
|
|
88
|
+
export class MapMemoCache<KEY = any, VALUE = any>
|
|
89
|
+
implements MemoCache<KEY, VALUE>, AsyncMemoCache<KEY, VALUE>
|
|
90
|
+
{
|
|
88
91
|
private m = new Map<KEY, VALUE>()
|
|
89
92
|
|
|
90
93
|
has(k: KEY): boolean {
|
|
@@ -103,19 +106,3 @@ export class MapMemoCache<KEY = any, VALUE = any> implements MemoCache<KEY, VALU
|
|
|
103
106
|
this.m.clear()
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
|
-
|
|
107
|
-
export class MapAsyncMemoCache<KEY = any, VALUE = any> implements AsyncMemoCache<KEY, VALUE> {
|
|
108
|
-
private m = new Map<KEY, VALUE>()
|
|
109
|
-
|
|
110
|
-
async get(k: KEY): Promise<VALUE | undefined> {
|
|
111
|
-
return this.m.get(k)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async set(k: KEY, v: VALUE): Promise<void> {
|
|
115
|
-
this.m.set(k, v)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async clear(): Promise<void> {
|
|
119
|
-
this.m.clear()
|
|
120
|
-
}
|
|
121
|
-
}
|