@wavemaker-ai/variables 1.0.0-rc.647655 → 1.0.0-rc.647671
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/npm-shrinkwrap.json +26 -53
- package/package-lock.json +26 -53
- package/package.json +1 -1
- package/src/interceptor/cache-interceptor.d.ts +11 -0
- package/src/interceptor/cache-interceptor.js +104 -0
- package/src/interceptor/cache-interceptor.js.map +1 -0
- package/src/interceptor/index.d.ts +9 -0
- package/src/interceptor/index.js +10 -0
- package/src/interceptor/index.js.map +1 -0
- package/src/interceptor/intercept-context.d.ts +15 -0
- package/src/interceptor/intercept-context.js +9 -0
- package/src/interceptor/intercept-context.js.map +1 -0
- package/src/interceptor/intercept.service.d.ts +6 -0
- package/src/interceptor/intercept.service.js +69 -0
- package/src/interceptor/intercept.service.js.map +1 -0
- package/src/interceptor/interceptor.d.ts +17 -0
- package/src/interceptor/interceptor.js +12 -0
- package/src/interceptor/interceptor.js.map +1 -0
- package/src/interceptor/interceptor.manager.d.ts +8 -0
- package/src/interceptor/interceptor.manager.js +17 -0
- package/src/interceptor/interceptor.manager.js.map +1 -0
- package/src/interceptor/storage.d.ts +56 -0
- package/src/interceptor/storage.js +237 -0
- package/src/interceptor/storage.js.map +1 -0
- package/src/manager/variable/service-variable.manager.js +2 -2
- package/src/manager/variable/service-variable.manager.js.map +1 -1
- package/src/model/variable/crud-variable.d.ts +1 -0
- package/src/model/variable/crud-variable.js +3 -0
- package/src/model/variable/crud-variable.js.map +1 -1
- package/src/model/variable/service-variable.d.ts +1 -0
- package/src/model/variable/service-variable.js +3 -0
- package/src/model/variable/service-variable.js.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intercept.service.js","sourceRoot":"./","sources":["src/interceptor/intercept.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;IAEI,0BAAoB,kBAAsC;QAAtC,uBAAkB,GAAlB,kBAAkB,CAAoB;IAE1D,CAAC;IAEK,oCAAS,GAAf,UAAgB,OAAY;;;;;;;wBAClB,oBAAoB,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;wBACrE,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;4BACpC,sBAAO,OAAO,CAAC,OAAO,EAAE,EAAC;wBAC7B,CAAC;wBACD,qBAAM,OAAO,CAAC,GAAG,CAAC,oBAAoB;iCACjC,GAAG,CAAC,UAAM,WAAW;;4CAAI,qBAAM,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,EAAA;4CAApC,sBAAA,SAAoC,EAAA;;qCAAA,CAAC,CAAC,EAAA;;wBADpE,SACoE,CAAC;wBACrE,sBAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAC;;;;KACnC;IACL,uBAAC;AAAD,CAAC,AAfD,IAeC","sourcesContent":["import { InterceptorManager } from \"./interceptor.manager\";\n\nexport class InterceptService {\n \n constructor(private interceptorManager: InterceptorManager) {\n\n }\n\n async intercept(context: any) {\n const matchingInterceptors = this.interceptorManager.filter(context);\n if (matchingInterceptors.length === 0) {\n return context.proceed();\n }\n await Promise.all(matchingInterceptors\n .map(async interceptor => await interceptor.intercept(context)));\n return context.variable.dataSet;\n }\n}"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InterceptContext } from "./intercept-context";
|
|
2
|
+
export interface Interceptor<IC extends InterceptContext<any>> {
|
|
3
|
+
match: (context: IC) => boolean;
|
|
4
|
+
intercept: (context: IC) => Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
export declare abstract class BaseInterceptor<IC extends InterceptContext<any>> implements Interceptor<IC> {
|
|
7
|
+
protected options: {
|
|
8
|
+
match?: (context: IC) => boolean;
|
|
9
|
+
intercept?: (context: IC) => Promise<any>;
|
|
10
|
+
};
|
|
11
|
+
constructor(options: {
|
|
12
|
+
match?: (context: IC) => boolean;
|
|
13
|
+
intercept?: (context: IC) => Promise<any>;
|
|
14
|
+
});
|
|
15
|
+
match(context: IC): boolean;
|
|
16
|
+
abstract intercept(context: IC): Promise<any>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var BaseInterceptor = /** @class */ (function () {
|
|
2
|
+
function BaseInterceptor(options) {
|
|
3
|
+
this.options = options;
|
|
4
|
+
}
|
|
5
|
+
BaseInterceptor.prototype.match = function (context) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
return !!((_b = (_a = this.options).match) === null || _b === void 0 ? void 0 : _b.call(_a, context));
|
|
8
|
+
};
|
|
9
|
+
return BaseInterceptor;
|
|
10
|
+
}());
|
|
11
|
+
export { BaseInterceptor };
|
|
12
|
+
//# sourceMappingURL=interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.js","sourceRoot":"./","sources":["src/interceptor/interceptor.ts"],"names":[],"mappings":"AAOA;IAEE,yBAAsB,OAGrB;QAHqB,YAAO,GAAP,OAAO,CAG5B;IACD,CAAC;IAED,+BAAK,GAAL,UAAM,OAAW;;QACf,OAAO,CAAC,CAAC,CAAA,MAAA,MAAA,IAAI,CAAC,OAAO,EAAC,KAAK,mDAAG,OAAO,CAAC,CAAA,CAAC;IACzC,CAAC;IAGH,sBAAC;AAAD,CAAC,AAbD,IAaC","sourcesContent":["import { InterceptContext } from \"./intercept-context\";\n\nexport interface Interceptor<IC extends InterceptContext<any>> {\n match: (context: IC) => boolean;\n intercept: (context: IC) => Promise<any>;\n}\n\nexport abstract class BaseInterceptor<IC extends InterceptContext<any>> implements Interceptor<IC> {\n\n constructor(protected options: {\n match?: (context: IC) => boolean;\n intercept?: (context: IC) => Promise<any>;\n }) {\n }\n\n match(context: IC) {\n return !!this.options.match?.(context);\n }\n\n abstract intercept(context: IC): Promise<any>;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InterceptContext } from "./intercept-context";
|
|
2
|
+
import { Interceptor } from "./interceptor";
|
|
3
|
+
export declare class InterceptorManager {
|
|
4
|
+
private interceptors;
|
|
5
|
+
add(interceptor: Interceptor<any>): void;
|
|
6
|
+
remove(interceptor: Interceptor<any>): void;
|
|
7
|
+
filter(contextToMatch: InterceptContext<any>): Interceptor<any>[];
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var InterceptorManager = /** @class */ (function () {
|
|
2
|
+
function InterceptorManager() {
|
|
3
|
+
this.interceptors = [];
|
|
4
|
+
}
|
|
5
|
+
InterceptorManager.prototype.add = function (interceptor) {
|
|
6
|
+
this.interceptors.push(interceptor);
|
|
7
|
+
};
|
|
8
|
+
InterceptorManager.prototype.remove = function (interceptor) {
|
|
9
|
+
this.interceptors = this.interceptors.filter(function (i) { return i !== interceptor; });
|
|
10
|
+
};
|
|
11
|
+
InterceptorManager.prototype.filter = function (contextToMatch) {
|
|
12
|
+
return this.interceptors.filter(function (i) { return i.match(contextToMatch); });
|
|
13
|
+
};
|
|
14
|
+
return InterceptorManager;
|
|
15
|
+
}());
|
|
16
|
+
export { InterceptorManager };
|
|
17
|
+
//# sourceMappingURL=interceptor.manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.manager.js","sourceRoot":"./","sources":["src/interceptor/interceptor.manager.ts"],"names":[],"mappings":"AAGA;IAAA;QAEY,iBAAY,GAAuB,EAAE,CAAC;IAalD,CAAC;IAXG,gCAAG,GAAH,UAAI,WAA6B;QAC7B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC;IAED,mCAAM,GAAN,UAAO,WAA6B;QAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,KAAK,WAAW,EAAjB,CAAiB,CAAC,CAAC;IACzE,CAAC;IAED,mCAAM,GAAN,UAAO,cAAqC;QACxC,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,EAAvB,CAAuB,CAAC,CAAC;IAClE,CAAC;IACL,yBAAC;AAAD,CAAC,AAfD,IAeC","sourcesContent":["import { InterceptContext } from \"./intercept-context\";\nimport { Interceptor } from \"./interceptor\";\n\nexport class InterceptorManager {\n\n private interceptors: Interceptor<any>[] = [];\n\n add(interceptor: Interceptor<any>) {\n this.interceptors.push(interceptor);\n }\n\n remove(interceptor: Interceptor<any>) {\n this.interceptors = this.interceptors.filter(i => i !== interceptor);\n }\n\n filter(contextToMatch: InterceptContext<any>) {\n return this.interceptors.filter(i => i.match(contextToMatch));\n }\n}"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface StorageService {
|
|
2
|
+
setItem(key: string, value: any, ttl: number): Promise<void>;
|
|
3
|
+
getItem(key: string): Promise<any>;
|
|
4
|
+
removeItem(key: string): Promise<void>;
|
|
5
|
+
clear(): Promise<any>;
|
|
6
|
+
}
|
|
7
|
+
export interface CacheStats {
|
|
8
|
+
totalEntries: number;
|
|
9
|
+
maxEntries: number;
|
|
10
|
+
usagePercent: number;
|
|
11
|
+
}
|
|
12
|
+
export interface StorageConfig {
|
|
13
|
+
maxEntries?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface CacheEntry {
|
|
16
|
+
value: any;
|
|
17
|
+
createdAt: number;
|
|
18
|
+
lastAccessedAt: number;
|
|
19
|
+
ttl: number | undefined;
|
|
20
|
+
}
|
|
21
|
+
declare class SimpleStorageService implements StorageService {
|
|
22
|
+
private cache;
|
|
23
|
+
private keyPrefix;
|
|
24
|
+
constructor(cache: any, keyPrefix: string);
|
|
25
|
+
getKey(key: string): string;
|
|
26
|
+
setItem(key: string, value: any, ttl: number): Promise<void>;
|
|
27
|
+
getItem(key: string): Promise<any>;
|
|
28
|
+
removeItem(key: string): Promise<void>;
|
|
29
|
+
clear(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export declare class SessionStorageService extends SimpleStorageService {
|
|
32
|
+
static cache: Record<string, CacheEntry>;
|
|
33
|
+
static maxEntries: number;
|
|
34
|
+
static cleanupInterval: NodeJS.Timeout | null;
|
|
35
|
+
static configure(config: StorageConfig): void;
|
|
36
|
+
private constructor();
|
|
37
|
+
static getInstance(keyPrefix: string): SessionStorageService;
|
|
38
|
+
setItem(key: string, value: any, ttl: number): Promise<void>;
|
|
39
|
+
static evictIfNeeded(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Evict the N least recently used entries.
|
|
42
|
+
* @param count - The number of entries to evict.
|
|
43
|
+
*/
|
|
44
|
+
private static evictLRU;
|
|
45
|
+
/**
|
|
46
|
+
* The keys with expired TTL are removed from the cache.
|
|
47
|
+
*/
|
|
48
|
+
static cleanEntriesWithExpiredTTL(): number;
|
|
49
|
+
static scheduleTTLCleanup(interval: number): void;
|
|
50
|
+
static stopCleanup(): void;
|
|
51
|
+
}
|
|
52
|
+
export declare class TemporaryStorageService extends SimpleStorageService {
|
|
53
|
+
private constructor();
|
|
54
|
+
static getInstance(keyPrefix: string): TemporaryStorageService;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
27
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
+
function step(op) {
|
|
30
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
32
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
+
switch (op[0]) {
|
|
35
|
+
case 0: case 1: t = op; break;
|
|
36
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
+
default:
|
|
40
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
+
if (t[2]) _.ops.pop();
|
|
45
|
+
_.trys.pop(); continue;
|
|
46
|
+
}
|
|
47
|
+
op = body.call(thisArg, _);
|
|
48
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var SimpleStorageService = /** @class */ (function () {
|
|
53
|
+
function SimpleStorageService(cache, keyPrefix) {
|
|
54
|
+
this.cache = cache;
|
|
55
|
+
this.keyPrefix = keyPrefix;
|
|
56
|
+
this.keyPrefix = keyPrefix;
|
|
57
|
+
}
|
|
58
|
+
SimpleStorageService.prototype.getKey = function (key) {
|
|
59
|
+
return this.keyPrefix + key;
|
|
60
|
+
};
|
|
61
|
+
SimpleStorageService.prototype.setItem = function (key, value, ttl) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var record;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
record = {
|
|
66
|
+
value: value,
|
|
67
|
+
createdAt: Date.now(),
|
|
68
|
+
lastAccessedAt: Date.now(),
|
|
69
|
+
ttl: ttl && ttl > 0 ? Date.now() + ttl : undefined
|
|
70
|
+
};
|
|
71
|
+
this.cache[this.getKey(key)] = record;
|
|
72
|
+
return [2 /*return*/];
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
SimpleStorageService.prototype.getItem = function (key) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var value, ttl;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
value = this.cache[this.getKey(key)];
|
|
83
|
+
if (!value) {
|
|
84
|
+
// Do not create placeholder entries for missing keys
|
|
85
|
+
return [2 /*return*/, null];
|
|
86
|
+
}
|
|
87
|
+
ttl = value.ttl;
|
|
88
|
+
if (!(ttl && ttl < Date.now())) return [3 /*break*/, 2];
|
|
89
|
+
return [4 /*yield*/, this.removeItem(key)];
|
|
90
|
+
case 1:
|
|
91
|
+
_a.sent();
|
|
92
|
+
return [2 /*return*/, null];
|
|
93
|
+
case 2:
|
|
94
|
+
// Update the last accessed time which helps in LRU eviction.
|
|
95
|
+
value.lastAccessedAt = Date.now();
|
|
96
|
+
return [2 /*return*/, value.value];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
SimpleStorageService.prototype.removeItem = function (key) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
delete this.cache[this.getKey(key)];
|
|
105
|
+
return [2 /*return*/];
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
SimpleStorageService.prototype.clear = function () {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
// For SessionStorageService, clear the static cache
|
|
113
|
+
if (this.cache === SessionStorageService.cache) {
|
|
114
|
+
SessionStorageService.cache = {};
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
this.cache = {};
|
|
118
|
+
}
|
|
119
|
+
return [2 /*return*/];
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
return SimpleStorageService;
|
|
124
|
+
}());
|
|
125
|
+
var DEFAULT_MAX_ENTRIES = 100;
|
|
126
|
+
var SessionStorageService = /** @class */ (function (_super) {
|
|
127
|
+
__extends(SessionStorageService, _super);
|
|
128
|
+
function SessionStorageService(keyPrefix) {
|
|
129
|
+
return _super.call(this, SessionStorageService.cache, keyPrefix) || this;
|
|
130
|
+
}
|
|
131
|
+
SessionStorageService.configure = function (config) {
|
|
132
|
+
if (config.maxEntries !== undefined && config.maxEntries > 0) {
|
|
133
|
+
SessionStorageService.maxEntries = config.maxEntries;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
SessionStorageService.getInstance = function (keyPrefix) {
|
|
137
|
+
return new SessionStorageService(keyPrefix);
|
|
138
|
+
};
|
|
139
|
+
SessionStorageService.prototype.setItem = function (key, value, ttl) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
+
var fullKey;
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
switch (_a.label) {
|
|
144
|
+
case 0:
|
|
145
|
+
fullKey = this.getKey(key);
|
|
146
|
+
if (!!SessionStorageService.cache[fullKey]) return [3 /*break*/, 2];
|
|
147
|
+
return [4 /*yield*/, SessionStorageService.evictIfNeeded()];
|
|
148
|
+
case 1:
|
|
149
|
+
_a.sent();
|
|
150
|
+
_a.label = 2;
|
|
151
|
+
case 2:
|
|
152
|
+
_super.prototype.setItem.call(this, key, value, ttl);
|
|
153
|
+
return [2 /*return*/];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
SessionStorageService.evictIfNeeded = function () {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
var currentCount, countAfterCleanup, entriesToEvict;
|
|
161
|
+
return __generator(this, function (_a) {
|
|
162
|
+
currentCount = Object.keys(SessionStorageService.cache).length;
|
|
163
|
+
if (currentCount < SessionStorageService.maxEntries) {
|
|
164
|
+
return [2 /*return*/];
|
|
165
|
+
}
|
|
166
|
+
SessionStorageService.cleanEntriesWithExpiredTTL();
|
|
167
|
+
countAfterCleanup = Object.keys(SessionStorageService.cache).length;
|
|
168
|
+
if (countAfterCleanup < SessionStorageService.maxEntries) {
|
|
169
|
+
return [2 /*return*/];
|
|
170
|
+
}
|
|
171
|
+
entriesToEvict = Math.max(1, Math.floor(SessionStorageService.maxEntries * 0.1));
|
|
172
|
+
SessionStorageService.evictLRU(entriesToEvict);
|
|
173
|
+
return [2 /*return*/];
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Evict the N least recently used entries.
|
|
179
|
+
* @param count - The number of entries to evict.
|
|
180
|
+
*/
|
|
181
|
+
SessionStorageService.evictLRU = function (count) {
|
|
182
|
+
var entries = Object.entries(SessionStorageService.cache)
|
|
183
|
+
.map(function (_a) {
|
|
184
|
+
var key = _a[0], entry = _a[1];
|
|
185
|
+
return ({ key: key, lastAccessedAt: entry.lastAccessedAt });
|
|
186
|
+
})
|
|
187
|
+
.sort(function (a, b) { return a.lastAccessedAt - b.lastAccessedAt; });
|
|
188
|
+
for (var i = 0; i < Math.min(count, entries.length); i++) {
|
|
189
|
+
delete SessionStorageService.cache[entries[i].key];
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* The keys with expired TTL are removed from the cache.
|
|
194
|
+
*/
|
|
195
|
+
SessionStorageService.cleanEntriesWithExpiredTTL = function () {
|
|
196
|
+
var now = Date.now();
|
|
197
|
+
var cleanedCount = 0;
|
|
198
|
+
for (var key in SessionStorageService.cache) {
|
|
199
|
+
var entry = SessionStorageService.cache[key];
|
|
200
|
+
if (entry.ttl && entry.ttl < now) {
|
|
201
|
+
// Keys in cache are already full keys, so delete directly
|
|
202
|
+
delete SessionStorageService.cache[key];
|
|
203
|
+
cleanedCount++;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return cleanedCount;
|
|
207
|
+
};
|
|
208
|
+
SessionStorageService.scheduleTTLCleanup = function (interval) {
|
|
209
|
+
if (SessionStorageService.cleanupInterval) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
SessionStorageService.cleanupInterval = setInterval(SessionStorageService.cleanEntriesWithExpiredTTL, interval);
|
|
213
|
+
};
|
|
214
|
+
SessionStorageService.stopCleanup = function () {
|
|
215
|
+
if (SessionStorageService.cleanupInterval) {
|
|
216
|
+
clearInterval(SessionStorageService.cleanupInterval);
|
|
217
|
+
SessionStorageService.cleanupInterval = null;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
SessionStorageService.cache = {};
|
|
221
|
+
SessionStorageService.maxEntries = DEFAULT_MAX_ENTRIES;
|
|
222
|
+
SessionStorageService.cleanupInterval = null;
|
|
223
|
+
return SessionStorageService;
|
|
224
|
+
}(SimpleStorageService));
|
|
225
|
+
export { SessionStorageService };
|
|
226
|
+
var TemporaryStorageService = /** @class */ (function (_super) {
|
|
227
|
+
__extends(TemporaryStorageService, _super);
|
|
228
|
+
function TemporaryStorageService(keyPrefix) {
|
|
229
|
+
return _super.call(this, {}, keyPrefix) || this;
|
|
230
|
+
}
|
|
231
|
+
TemporaryStorageService.getInstance = function (keyPrefix) {
|
|
232
|
+
return new TemporaryStorageService(keyPrefix);
|
|
233
|
+
};
|
|
234
|
+
return TemporaryStorageService;
|
|
235
|
+
}(SimpleStorageService));
|
|
236
|
+
export { TemporaryStorageService };
|
|
237
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"./","sources":["src/interceptor/storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA;IAGI,8BAAoB,KAAU,EAAU,SAAiB;QAArC,UAAK,GAAL,KAAK,CAAK;QAAU,cAAS,GAAT,SAAS,CAAQ;QACrD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,qCAAM,GAAN,UAAO,GAAW;QACd,OAAO,IAAI,CAAC,SAAS,GAA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IAAI,qBAAqB,CAAC,KAAK,EAAE,CAAC;YAC5C,IAAM,KAAK,GAAG,qBAAqB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC/C,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC;gBAC/B,0DAA0D;gBAC1D,OAAO,qBAAqB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACxC,YAAY,EAAE,CAAC;YACnB,CAAC;QACL,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;IAEM,wCAAkB,GAAzB,UAA0B,QAAgB;QACtC,IAAI,qBAAqB,CAAC,eAAe,EAAE,CAAC;YACxC,OAAO;QACX,CAAC;QACD,qBAAqB,CAAC,eAAe,GAAG,WAAW,CAC/C,qBAAqB,CAAC,0BAA0B,EAChD,QAAQ,CACX,CAAC;IACN,CAAC;IAEM,iCAAW,GAAlB;QACI,IAAI,qBAAqB,CAAC,eAAe,EAAE,CAAC;YACxC,aAAa,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC;YACrD,qBAAqB,CAAC,eAAe,GAAG,IAAI,CAAC;QACjD,CAAC;IACL,CAAC;IArFM,2BAAK,GAA+B,EAAE,CAAC;IACvC,gCAAU,GAAW,mBAAmB,CAAC;IACzC,qCAAe,GAA0B,IAAI,CAAC;IAoFzD,4BAAC;CAAA,AAvFD,CAA2C,oBAAoB,GAuF9D;SAvFY,qBAAqB;AAyFlC;IAA6C,2CAAoB;IAC7D,iCAAoB,SAAiB;QACjC,OAAA,MAAK,YAAC,EAAE,EAAE,SAAS,CAAC,SAAC;IACzB,CAAC;IAEM,mCAAW,GAAlB,UAAmB,SAAiB;QAChC,OAAO,IAAI,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;IACL,8BAAC;AAAD,CAAC,AARD,CAA6C,oBAAoB,GAQhE","sourcesContent":["export interface StorageService {\n setItem(key: string, value: any, ttl: number): Promise<void>;\n getItem(key: string): Promise<any>;\n removeItem(key: string): Promise<void>;\n clear(): Promise<any>;\n}\n\nexport interface CacheStats {\n totalEntries: number;\n maxEntries: number;\n usagePercent: number;\n}\n\nexport interface StorageConfig {\n maxEntries?: number;\n}\n\nexport interface CacheEntry {\n value: any;\n createdAt: number;\n lastAccessedAt: number;\n ttl: number | undefined;\n}\n\nclass SimpleStorageService implements StorageService {\n \n \n constructor(private cache: any, private keyPrefix: string) {\n this.keyPrefix = keyPrefix;\n }\n\n getKey(key: string) {\n return this.keyPrefix + key;\n }\n\n\n public async setItem(key: string, value: any, ttl: number) {\n const record: CacheEntry = {\n value,\n createdAt: Date.now(),\n lastAccessedAt: Date.now(),\n ttl: ttl && ttl > 0 ? Date.now() + ttl : undefined\n };\n this.cache[this.getKey(key)] = record;\n }\n\n public async getItem(key: string) {\n const value = this.cache[this.getKey(key)];\n if (!value) {\n // Do not create placeholder entries for missing keys\n return null;\n }\n\n const ttl = value.ttl;\n if (ttl && ttl < Date.now()) {\n await this.removeItem(key);\n return null;\n }\n // Update the last accessed time which helps in LRU eviction.\n value.lastAccessedAt = Date.now();\n return value.value;\n }\n\n public async removeItem(key: string) {\n delete this.cache[this.getKey(key)];\n }\n\n public async clear() {\n // For SessionStorageService, clear the static cache\n if (this.cache === SessionStorageService.cache) {\n SessionStorageService.cache = {} as any;\n } else {\n this.cache = {} as any;\n }\n }\n}\n\nconst DEFAULT_MAX_ENTRIES = 100;\nexport class SessionStorageService extends SimpleStorageService {\n static cache: Record<string, CacheEntry> = {};\n static maxEntries: number = DEFAULT_MAX_ENTRIES;\n static cleanupInterval: NodeJS.Timeout | null = null;\n\n static configure(config: StorageConfig) {\n if (config.maxEntries !== undefined && config.maxEntries > 0) {\n SessionStorageService.maxEntries = config.maxEntries;\n }\n }\n\n private constructor(keyPrefix: string) {\n super(SessionStorageService.cache, keyPrefix);\n }\n\n static getInstance(keyPrefix: string) {\n return new SessionStorageService(keyPrefix);\n }\n\n public async setItem(key: string, value: any, ttl: number) {\n const fullKey = this.getKey(key);\n if (!SessionStorageService.cache[fullKey]) {\n await SessionStorageService.evictIfNeeded();\n }\n super.setItem(key, value, ttl);\n }\n\n static async evictIfNeeded(): Promise<void> {\n const currentCount = Object.keys(SessionStorageService.cache).length;\n if (currentCount < SessionStorageService.maxEntries) {\n return;\n }\n SessionStorageService.cleanEntriesWithExpiredTTL();\n const countAfterCleanup = Object.keys(SessionStorageService.cache).length;\n if (countAfterCleanup < SessionStorageService.maxEntries) {\n return;\n }\n const entriesToEvict = Math.max(1, Math.floor(SessionStorageService.maxEntries * 0.1));\n SessionStorageService.evictLRU(entriesToEvict);\n }\n\n /**\n * Evict the N least recently used entries.\n * @param count - The number of entries to evict.\n */\n private static evictLRU(count: number): void {\n const entries = Object.entries(SessionStorageService.cache)\n .map(([key, entry]) => ({ key, lastAccessedAt: entry.lastAccessedAt }))\n .sort((a, b) => a.lastAccessedAt - b.lastAccessedAt);\n for (let i = 0; i < Math.min(count, entries.length); i++) {\n delete SessionStorageService.cache[entries[i].key];\n }\n }\n\n /**\n * The keys with expired TTL are removed from the cache.\n */\n static cleanEntriesWithExpiredTTL(): number {\n const now = Date.now();\n let cleanedCount = 0;\n for (const key in SessionStorageService.cache) {\n const entry = SessionStorageService.cache[key];\n if (entry.ttl && entry.ttl < now) {\n // Keys in cache are already full keys, so delete directly\n delete SessionStorageService.cache[key];\n cleanedCount++;\n }\n }\n return cleanedCount;\n }\n\n static scheduleTTLCleanup(interval: number): void {\n if (SessionStorageService.cleanupInterval) {\n return;\n }\n SessionStorageService.cleanupInterval = setInterval(\n SessionStorageService.cleanEntriesWithExpiredTTL,\n interval\n );\n }\n\n static stopCleanup(): void {\n if (SessionStorageService.cleanupInterval) {\n clearInterval(SessionStorageService.cleanupInterval);\n SessionStorageService.cleanupInterval = null;\n }\n }\n}\n\nexport class TemporaryStorageService extends SimpleStorageService {\n private constructor(keyPrefix: string) {\n super({}, keyPrefix);\n }\n\n static getInstance(keyPrefix: string) {\n return new TemporaryStorageService(keyPrefix);\n }\n}"]}
|
|
@@ -547,9 +547,9 @@ var ServiceVariableManager = /** @class */ (function (_super) {
|
|
|
547
547
|
// });
|
|
548
548
|
// the _observable property on variable is used store the observable using which the network call is made
|
|
549
549
|
// this can be used to cancel the variable calls.
|
|
550
|
-
variable.
|
|
550
|
+
variable.makeHttpCall(requestParams, inputFields, function (response) {
|
|
551
551
|
successHandler(response, resolve);
|
|
552
|
-
}
|
|
552
|
+
}, function (err) {
|
|
553
553
|
err = err || {};
|
|
554
554
|
err.error = err.error || '{}';
|
|
555
555
|
var validJSON = getValidJSON(err.error);
|