@t4h.framework/cache 0.0.0-experimental-c0d4325
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/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/ActivityCacheClaim.d.ts +9 -0
- package/dist/ActivityCacheClaim.d.ts.map +1 -0
- package/dist/ActivityCacheClaim.js +3 -0
- package/dist/ActivityCacheClaim.js.map +1 -0
- package/dist/CacheClaim.d.ts +9 -0
- package/dist/CacheClaim.d.ts.map +1 -0
- package/dist/CacheClaim.js +3 -0
- package/dist/CacheClaim.js.map +1 -0
- package/dist/cache.d.ts +2 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +2 -0
- package/dist/cache.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tech four humans
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @t4h.framework/cache
|
|
2
|
+
|
|
3
|
+
Cache claim for key-value storage within activities.
|
|
4
|
+
|
|
5
|
+
## Claim
|
|
6
|
+
|
|
7
|
+
### CacheClaim
|
|
8
|
+
|
|
9
|
+
Abstract dependency for caching serializable values. An activity declares this claim when it needs to cache data (e.g. tokens, computed results). The runtime provides a concrete implementation (e.g. Redis, in-memory).
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { CacheClaim } from '@t4h.framework/cache'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Interface
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
interface CacheClaimSetOptions {
|
|
19
|
+
ttl?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
abstract class CacheClaim {
|
|
23
|
+
public abstract get<T extends Serializable>(key: string): T | undefined | Promise<T | undefined>
|
|
24
|
+
public abstract set(key: string, value: Serializable, options?: CacheClaimSetOptions): Promise<void>
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Usage inside an activity
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { SyncActivity, Claim } from '@t4h.framework/core'
|
|
32
|
+
import { CacheClaim } from '@t4h.framework/cache'
|
|
33
|
+
|
|
34
|
+
class GetCachedConfigActivity extends SyncActivity<
|
|
35
|
+
[key: string],
|
|
36
|
+
{ key: string },
|
|
37
|
+
any
|
|
38
|
+
> {
|
|
39
|
+
private readonly claims = new Claim({
|
|
40
|
+
cache: CacheClaim,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
public async toInput(key: string) {
|
|
44
|
+
return { key }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async run(input: { key: string }) {
|
|
48
|
+
const cached = await this.claims.cache.get(input.key)
|
|
49
|
+
|
|
50
|
+
if (cached) return cached
|
|
51
|
+
|
|
52
|
+
const value = { setting: 'default' }
|
|
53
|
+
await this.claims.cache.set(input.key, value, { ttl: 3600 })
|
|
54
|
+
|
|
55
|
+
return value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public toOutput(output: any) {
|
|
59
|
+
return output
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Runtime provider
|
|
65
|
+
|
|
66
|
+
The runtime must supply a concrete implementation:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
{ provide: CacheClaim, value: new RedisCacheClaimImpl() }
|
|
70
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Serializable } from '@t4h.framework/core';
|
|
2
|
+
export interface CacheClaimSetOptions {
|
|
3
|
+
ttl?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare abstract class CacheClaim {
|
|
6
|
+
abstract get<T extends Serializable>(key: string): T | undefined | Promise<T | undefined>;
|
|
7
|
+
abstract set(key: string, value: Serializable, options?: CacheClaimSetOptions): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ActivityCacheClaim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActivityCacheClaim.d.ts","sourceRoot":"","sources":["../src/ActivityCacheClaim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,8BAAsB,UAAU;aACd,GAAG,CAAC,CAAC,SAAS,YAAY,EACxC,GAAG,EAAE,MAAM,GACV,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;aAEzB,GAAG,CACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActivityCacheClaim.js","sourceRoot":"","sources":["../src/ActivityCacheClaim.ts"],"names":[],"mappings":"AAMA,MAAM,OAAgB,UAAU;CAU/B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Serializable } from '@t4h.framework/core';
|
|
2
|
+
export interface CacheClaimSetOptions {
|
|
3
|
+
ttl?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare abstract class CacheClaim {
|
|
6
|
+
abstract get<T extends Serializable>(key: string): T | undefined | Promise<T | undefined>;
|
|
7
|
+
abstract set(key: string, value: Serializable, options?: CacheClaimSetOptions): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=CacheClaim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheClaim.d.ts","sourceRoot":"","sources":["../src/CacheClaim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,8BAAsB,UAAU;aACd,GAAG,CAAC,CAAC,SAAS,YAAY,EACxC,GAAG,EAAE,MAAM,GACV,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;aAEzB,GAAG,CACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheClaim.js","sourceRoot":"","sources":["../src/CacheClaim.ts"],"names":[],"mappings":"AAMA,MAAM,OAAgB,UAAU;CAU/B"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@t4h.framework/cache",
|
|
3
|
+
"version": "0.0.0-experimental-c0d4325",
|
|
4
|
+
"description": "Cache module for the T4H Framework",
|
|
5
|
+
"homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/cache",
|
|
6
|
+
"bugs": "https://github.com/tech4humans-brasil/framework/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/tech4humans-brasil/framework.git",
|
|
10
|
+
"directory": "packages/cache"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Tech4Humans <contact@tech4h.com.br> (https://tech4h.com.br)",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
"types": "./dist/cache.d.ts",
|
|
17
|
+
"import": "./dist/cache.js"
|
|
18
|
+
},
|
|
19
|
+
"module": "./dist/cache.js",
|
|
20
|
+
"types": "./dist/cache.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc --project tsconfig.build.json",
|
|
27
|
+
"check-types": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint .",
|
|
29
|
+
"prepublishOnly": "yarn build"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@t4h.framework/core": "workspace:^"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@t4h.framework/core": "workspace:^"
|
|
39
|
+
},
|
|
40
|
+
"packageManager": "yarn@4.12.0",
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22"
|
|
43
|
+
},
|
|
44
|
+
"stableVersion": "0.0.0"
|
|
45
|
+
}
|