@tmlmobilidade/utils 20251007.1740.45-staging.0 → 20251008.1444.19

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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './src/batching/index.js';
2
+ export * from './src/caching/index.js';
2
3
  export * from './src/css/index.js';
3
4
  export * from './src/dates/index.js';
4
5
  export * from './src/files/files.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './src/batching/index.js';
2
+ export * from './src/caching/index.js';
2
3
  export * from './src/css/index.js';
3
4
  export * from './src/dates/index.js';
4
5
  export * from './src/files/files.js';
@@ -0,0 +1,8 @@
1
+ export declare class Cache<K, V> {
2
+ private ttlMs;
3
+ private store;
4
+ constructor(ttlMs: number);
5
+ delete(key: K): void;
6
+ get(key: K): null | V;
7
+ set(key: K, value: V): void;
8
+ }
@@ -0,0 +1,23 @@
1
+ export class Cache {
2
+ ttlMs;
3
+ store = new Map();
4
+ constructor(ttlMs) {
5
+ this.ttlMs = ttlMs;
6
+ }
7
+ delete(key) {
8
+ this.store.delete(key);
9
+ }
10
+ get(key) {
11
+ const entry = this.store.get(key);
12
+ if (!entry)
13
+ return null;
14
+ if (Date.now() > entry.expiresAt) {
15
+ this.store.delete(key);
16
+ return null;
17
+ }
18
+ return entry.value;
19
+ }
20
+ set(key, value) {
21
+ this.store.set(key, { expiresAt: Date.now() + this.ttlMs, value });
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ export * from './cache.js';
@@ -0,0 +1 @@
1
+ export * from './cache.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/utils",
3
- "version": "20251007.1740.45-staging.0",
3
+ "version": "20251008.1444.19",
4
4
  "author": "João de Vasconcelos & Jusi Monteiro",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "homepage": "https://github.com/tmlmobilidade/services#readme",
@@ -54,7 +54,7 @@
54
54
  "@tmlmobilidade/tsconfig": "*",
55
55
  "@tmlmobilidade/types": "*",
56
56
  "@types/luxon": "3.7.1",
57
- "@types/node": "24.6.1",
57
+ "@types/node": "24.7.0",
58
58
  "@types/papaparse": "5.3.16",
59
59
  "resolve-tspaths": "0.8.23",
60
60
  "rimraf": "6.0.1",