@tsed/directus-sdk 8.19.5 → 8.20.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.
- package/lib/esm/extends/cache.js +6 -0
- package/lib/esm/index.js +1 -0
- package/lib/types/extends/cache.d.ts +73 -0
- package/lib/types/index.d.ts +1 -0
- package/package.json +2 -2
- package/readme.md +1 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProviderBuilder } from "@tsed/di";
|
|
2
|
+
import { DirectusCacheInterceptor } from "../cache/index.js";
|
|
3
|
+
ProviderBuilder.add("directusCache", function directusCache(propertyKey, options = {}) {
|
|
4
|
+
this.intercept(propertyKey, DirectusCacheInterceptor, options);
|
|
5
|
+
return this;
|
|
6
|
+
});
|
package/lib/esm/index.js
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Type } from "@tsed/core";
|
|
2
|
+
import { type DirectusCacheOptions } from "../cache/index.js";
|
|
3
|
+
declare global {
|
|
4
|
+
namespace TsED {
|
|
5
|
+
interface ClassProviderBuilder<Token extends Type> {
|
|
6
|
+
/**
|
|
7
|
+
* Programmatically applies cache interception to a method using Directus cache infrastructure.
|
|
8
|
+
*
|
|
9
|
+
* This function allows you to add caching to a method after the class is defined,
|
|
10
|
+
* which is useful when you can't use decorators or need dynamic cache configuration.
|
|
11
|
+
*
|
|
12
|
+
* @example Basic usage
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import {injectable} from "@tsed/di";
|
|
16
|
+
* import {useDirectusCache} from "@tsed/directus-sdk";
|
|
17
|
+
*
|
|
18
|
+
* export class JiraIssueClient {
|
|
19
|
+
* search(query: string) {
|
|
20
|
+
* // Expensive search operation
|
|
21
|
+
* return this.performSearch(query);
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* injectable(JiraIssueClient)
|
|
26
|
+
* .directusCache("search", { ttl: 900000 });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ### With custom options
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* injectable(MyService)
|
|
33
|
+
* .directusCache("fetchData", {
|
|
34
|
+
* ttl: 60000,
|
|
35
|
+
* keyGenerator: (id: string) => `data:${id}`,
|
|
36
|
+
* namespace: "my_service:data",
|
|
37
|
+
* useSystemCache: false
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* ### Applying cache to multiple methods
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* import {injectable} from "@tsed/di";
|
|
45
|
+
* import {useDirectusCache} from "@tsed/directus-sdk";
|
|
46
|
+
*
|
|
47
|
+
* export class ApiClient {
|
|
48
|
+
* getUser(id: string) { }
|
|
49
|
+
* getPosts() { }
|
|
50
|
+
* }
|
|
51
|
+
* injectable(ApiClient)
|
|
52
|
+
* .directusCache("getUser", { ttl: 300000 })
|
|
53
|
+
* .directusCache("getPosts", { ttl: 60000 });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @template K - The class type
|
|
57
|
+
* @template Props - The property key type (method name)
|
|
58
|
+
*
|
|
59
|
+
* @param propertyKey - The name of the method to cache
|
|
60
|
+
* @param options - Cache configuration options
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* - Must be called after the class is marked as `@Injectable()` or `injectable()`
|
|
64
|
+
* - The class must be registered in the DI container
|
|
65
|
+
* - Prefer using the `@Cache` decorator when possible for better readability
|
|
66
|
+
*
|
|
67
|
+
* @see {@link Cache} decorator for the declarative approach
|
|
68
|
+
* @see {@link DirectusCacheInterceptor} for implementation details
|
|
69
|
+
*/
|
|
70
|
+
directusCache(propertyKey: keyof InstanceType<Token>, options?: DirectusCacheOptions): this;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
package/lib/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/directus-sdk",
|
|
3
3
|
"description": "A library to integrate Directus SDK with Ts.ED, facilitating the creation of extensions (endpoints, hooks, operations) and the use of Directus services.",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.20.1",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@directus/extensions-sdk": "13.1.1",
|
|
44
44
|
"@directus/sdk": "20.2.0",
|
|
45
45
|
"@directus/types": "13.4.0",
|
|
46
|
-
"@tsed/barrels": "8.
|
|
46
|
+
"@tsed/barrels": "8.20.1",
|
|
47
47
|
"@tsed/logger-connect": "8.0.4",
|
|
48
48
|
"@types/express": "4.17.21",
|
|
49
49
|
"typescript": "5.9.3",
|
package/readme.md
CHANGED
|
@@ -350,8 +350,7 @@ export class JiraIssueClient {
|
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
injectable(JiraIssueClient);
|
|
354
|
-
useDirectusCache(JiraIssueClient, "search", {ttl: 900000});
|
|
353
|
+
injectable(JiraIssueClient).directusCache("search", {ttl: 900000});
|
|
355
354
|
```
|
|
356
355
|
|
|
357
356
|
## 🔧 Advanced Usage
|