@kosdev-code/kos-ui-sdk 0.1.0-dev.5053 → 0.1.0-dev.5070
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/core/core/decorators/index.d.ts +2 -0
- package/core/core/decorators/index.d.ts.map +1 -1
- package/core/core/decorators/kos-execution-context.d.ts +60 -0
- package/core/core/decorators/kos-execution-context.d.ts.map +1 -0
- package/core/core/decorators/kos-service-request.d.ts +368 -0
- package/core/core/decorators/kos-service-request.d.ts.map +1 -0
- package/core/core/kosModel.d.ts +2 -0
- package/core/core/kosModel.d.ts.map +1 -1
- package/core/core/model/kos-model-component-factory.d.ts +4 -0
- package/core/core/model/kos-model-component-factory.d.ts.map +1 -1
- package/core/core/model/kos-service-request-manager.d.ts +77 -0
- package/core/core/model/kos-service-request-manager.d.ts.map +1 -0
- package/core/core/model/model-introspection-utils.d.ts +1 -0
- package/core/core/model/model-introspection-utils.d.ts.map +1 -1
- package/core/core/model/service-response-store.d.ts +140 -0
- package/core/core/model/service-response-store.d.ts.map +1 -0
- package/core/types/index.d.ts +1 -0
- package/core/types/index.d.ts.map +1 -1
- package/core/types/service-response-store.d.ts +96 -0
- package/core/types/service-response-store.d.ts.map +1 -0
- package/core/util/index.d.ts +1 -0
- package/core/util/index.d.ts.map +1 -1
- package/core/util/kos-service-request.d.ts +8 -0
- package/core/util/kos-service-request.d.ts.map +1 -1
- package/core/util/service-response.d.ts +110 -0
- package/core/util/service-response.d.ts.map +1 -0
- package/index.cjs +69 -69
- package/index.cjs.map +1 -1
- package/index.js +7169 -6533
- package/index.js.map +1 -1
- package/models/decorators/future-service.d.ts +7 -0
- package/models/decorators/future-service.d.ts.map +1 -1
- package/models/utils/service.d.ts +58 -2
- package/models/utils/service.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ResponseCacheConfig } from '../../types/service-response-store';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ServiceResponseStore manages keyed storage of service responses with flexible retention policies.
|
|
5
|
+
*
|
|
6
|
+
* Responses are stored by `{method}:{path}` key (e.g., 'GET:/api/ingredients')
|
|
7
|
+
* and can be configured with different retention policies to control caching behavior.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const store = new ServiceResponseStore();
|
|
11
|
+
*
|
|
12
|
+
* // Store with TTL (replaces on each request)
|
|
13
|
+
* store.set('GET:/api/status', statusData, {
|
|
14
|
+
* retention: ResponseRetention.TTL,
|
|
15
|
+
* ttl: 5 * 60 * 1000
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Store with TTL extension (keeps existing data, extends TTL)
|
|
19
|
+
* const stored = store.set('GET:/api/expensive', expensiveData, {
|
|
20
|
+
* retention: ResponseRetention.TTL,
|
|
21
|
+
* ttl: 5 * 60 * 1000,
|
|
22
|
+
* extendOnRefresh: true
|
|
23
|
+
* });
|
|
24
|
+
* // stored === false if cache was extended, true if new data stored
|
|
25
|
+
*
|
|
26
|
+
* // Retrieve
|
|
27
|
+
* const status = store.get('GET:/api/status');
|
|
28
|
+
*/
|
|
29
|
+
export declare class ServiceResponseStore {
|
|
30
|
+
private responses;
|
|
31
|
+
private retentionPolicies;
|
|
32
|
+
private cleanupTimers;
|
|
33
|
+
/**
|
|
34
|
+
* Store a response with retention policy
|
|
35
|
+
*
|
|
36
|
+
* @param key - Storage key (typically `{method}:{path}`)
|
|
37
|
+
* @param response - Response data to cache
|
|
38
|
+
* @param config - Caching configuration (defaults to SINGLE retention)
|
|
39
|
+
* @returns true if response was stored, false if refresh extended existing TTL
|
|
40
|
+
*/
|
|
41
|
+
set<T>(key: string, response: T, config?: ResponseCacheConfig): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get response if not expired
|
|
44
|
+
*
|
|
45
|
+
* @param key - Storage key
|
|
46
|
+
* @returns Response data or undefined if not found/expired
|
|
47
|
+
*/
|
|
48
|
+
get<T = any>(key: string): T | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Get response by path and method
|
|
51
|
+
*
|
|
52
|
+
* @param path - API path
|
|
53
|
+
* @param method - HTTP method (defaults to 'get')
|
|
54
|
+
* @returns Response data or undefined if not found/expired
|
|
55
|
+
*/
|
|
56
|
+
getByPath<T = any>(path: string, method?: string): T | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Check if response exists and is not expired
|
|
59
|
+
*
|
|
60
|
+
* @param key - Storage key
|
|
61
|
+
* @returns true if valid response exists
|
|
62
|
+
*/
|
|
63
|
+
has(key: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Manually delete a response
|
|
66
|
+
*
|
|
67
|
+
* @param key - Storage key
|
|
68
|
+
*/
|
|
69
|
+
delete(key: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Clear all responses for a path (all methods)
|
|
72
|
+
*
|
|
73
|
+
* @param path - API path to clear
|
|
74
|
+
*/
|
|
75
|
+
clearPath(path: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Clear all responses
|
|
78
|
+
*/
|
|
79
|
+
clear(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Get count of cached responses
|
|
82
|
+
*/
|
|
83
|
+
get size(): number;
|
|
84
|
+
/**
|
|
85
|
+
* Check if a response should be cleaned up after handler completes
|
|
86
|
+
*
|
|
87
|
+
* @param key - Storage key
|
|
88
|
+
* @returns true if response has IMMEDIATE retention policy
|
|
89
|
+
*/
|
|
90
|
+
shouldCleanupAfterHandler(key: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Zone 2: Evaluates if TTL should be extended instead of replacing data
|
|
93
|
+
*/
|
|
94
|
+
private shouldExtendTTL;
|
|
95
|
+
/**
|
|
96
|
+
* Extend TTL for existing cached response
|
|
97
|
+
*/
|
|
98
|
+
private extendExistingTTL;
|
|
99
|
+
/**
|
|
100
|
+
* Zone 3: Reset cleanup timer for a cached response
|
|
101
|
+
*/
|
|
102
|
+
private resetCleanupTimer;
|
|
103
|
+
/**
|
|
104
|
+
* Clear cleanup timer if it exists
|
|
105
|
+
*/
|
|
106
|
+
private clearTimerIfExists;
|
|
107
|
+
/**
|
|
108
|
+
* Create cached response object with metadata
|
|
109
|
+
*/
|
|
110
|
+
private createCachedResponse;
|
|
111
|
+
/**
|
|
112
|
+
* Calculate expiration timestamp based on config
|
|
113
|
+
*/
|
|
114
|
+
private calculateExpiresAt;
|
|
115
|
+
/**
|
|
116
|
+
* Store response with retention policy
|
|
117
|
+
*/
|
|
118
|
+
private storeResponse;
|
|
119
|
+
/**
|
|
120
|
+
* Zone 2: Configures retention policy for a stored response
|
|
121
|
+
*/
|
|
122
|
+
private applyRetentionPolicy;
|
|
123
|
+
/**
|
|
124
|
+
* Make storage key from path and method
|
|
125
|
+
*/
|
|
126
|
+
private makeKey;
|
|
127
|
+
/**
|
|
128
|
+
* Extract path from storage key
|
|
129
|
+
*/
|
|
130
|
+
private extractPath;
|
|
131
|
+
/**
|
|
132
|
+
* Extract method from storage key
|
|
133
|
+
*/
|
|
134
|
+
private extractMethod;
|
|
135
|
+
/**
|
|
136
|
+
* Cleanup expired responses (called periodically if needed)
|
|
137
|
+
*/
|
|
138
|
+
cleanup(): void;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=service-response-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-response-store.d.ts","sourceRoot":"","sources":["../../../../../../../packages/sdk/kos-ui-sdk/src/core/core/model/service-response-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEpB,MAAM,oCAAoC,CAAC;AAmD5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,iBAAiB,CAA0C;IACnE,OAAO,CAAC,aAAa,CAAqC;IAE1D;;;;;;;OAOG;IACH,GAAG,CAAC,CAAC,EACH,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,EACX,MAAM,GAAE,mBAA6D,GACpE,OAAO;IAWV;;;;;OAKG;IACH,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAcxC;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,SAAQ,GAAG,CAAC,GAAG,SAAS;IAI/D;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAWzB;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ7B;;OAEG;IACH,KAAK,IAAI,IAAI;IAOb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;OAKG;IACH,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAK/C;;OAEG;IACH,OAAO,CAAC,eAAe;IAevB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAKzB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAM1B;;OAEG;IACH,OAAO,CAAC,aAAa;IAUrB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAiC5B;;OAEG;IACH,OAAO,CAAC,OAAO;IAIf;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,aAAa;IAIrB;;OAEG;IACH,OAAO,IAAI,IAAI;CAQhB"}
|
package/core/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response retention policies for ServiceResponseStore
|
|
3
|
+
* Controls how long service responses are cached and when they're cleaned up
|
|
4
|
+
*/
|
|
5
|
+
export declare enum ResponseRetention {
|
|
6
|
+
/**
|
|
7
|
+
* Clear immediately after handler completes
|
|
8
|
+
* Use for one-time operations with no caching needs
|
|
9
|
+
*
|
|
10
|
+
* Note: Response remains available during handler execution (including async handlers).
|
|
11
|
+
* Cleanup happens AFTER the handler returns/resolves via ServiceRequestManager.
|
|
12
|
+
*/
|
|
13
|
+
IMMEDIATE = "immediate",
|
|
14
|
+
/**
|
|
15
|
+
* Keep until next response for same path
|
|
16
|
+
* Default behavior - previous response replaced on new request
|
|
17
|
+
*/
|
|
18
|
+
SINGLE = "single",
|
|
19
|
+
/**
|
|
20
|
+
* Keep for specified duration (ms)
|
|
21
|
+
* Automatic cleanup after TTL expires
|
|
22
|
+
*/
|
|
23
|
+
TTL = "ttl",
|
|
24
|
+
/**
|
|
25
|
+
* Keep until model is destroyed
|
|
26
|
+
* Use for data needed throughout model lifetime
|
|
27
|
+
*/
|
|
28
|
+
PERMANENT = "permanent",
|
|
29
|
+
/**
|
|
30
|
+
* Keep until explicitly cleared
|
|
31
|
+
* Manual cleanup required via clearServiceResponse()
|
|
32
|
+
*/
|
|
33
|
+
MANUAL = "manual"
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for response caching behavior
|
|
37
|
+
*/
|
|
38
|
+
export interface ResponseCacheConfig {
|
|
39
|
+
/**
|
|
40
|
+
* Retention policy determining when response is cleaned up
|
|
41
|
+
*/
|
|
42
|
+
retention: ResponseRetention;
|
|
43
|
+
/**
|
|
44
|
+
* Time-to-live in milliseconds (required for TTL retention)
|
|
45
|
+
*/
|
|
46
|
+
ttl?: number;
|
|
47
|
+
/**
|
|
48
|
+
* For TTL retention: extend TTL instead of replacing data on new request
|
|
49
|
+
*
|
|
50
|
+
* When false (default): New request clears old data and stores new data with fresh TTL
|
|
51
|
+
* When true: If cached data exists and hasn't expired, extend TTL without replacing data
|
|
52
|
+
*
|
|
53
|
+
* Use extendOnRefresh=true to avoid re-running expensive operations when cached data is still valid.
|
|
54
|
+
*
|
|
55
|
+
* @default false
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Replace on each request (default)
|
|
59
|
+
* cache: { retention: ResponseRetention.TTL, ttl: 5 * 60 * 1000 }
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Extend TTL on refresh - avoid re-fetching if cache valid
|
|
63
|
+
* cache: { retention: ResponseRetention.TTL, ttl: 5 * 60 * 1000, extendOnRefresh: true }
|
|
64
|
+
*/
|
|
65
|
+
extendOnRefresh?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Maximum number of responses to cache per path (future use)
|
|
68
|
+
*/
|
|
69
|
+
maxSize?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Cached response with metadata
|
|
73
|
+
*/
|
|
74
|
+
export interface CachedResponse<T = any> {
|
|
75
|
+
/**
|
|
76
|
+
* The response data
|
|
77
|
+
*/
|
|
78
|
+
data: T;
|
|
79
|
+
/**
|
|
80
|
+
* When the response was cached (timestamp)
|
|
81
|
+
*/
|
|
82
|
+
timestamp: number;
|
|
83
|
+
/**
|
|
84
|
+
* The API path this response came from
|
|
85
|
+
*/
|
|
86
|
+
path: string;
|
|
87
|
+
/**
|
|
88
|
+
* The HTTP method used
|
|
89
|
+
*/
|
|
90
|
+
method: string;
|
|
91
|
+
/**
|
|
92
|
+
* When this response expires (for TTL retention)
|
|
93
|
+
*/
|
|
94
|
+
expiresAt?: number;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=service-response-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-response-store.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/types/service-response-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,iBAAiB;IAC3B;;;;;;OAMG;IACH,SAAS,cAAc;IAEvB;;;OAGG;IACH,MAAM,WAAW;IAEjB;;;OAGG;IACH,GAAG,QAAQ;IAEX;;;OAGG;IACH,SAAS,cAAc;IAEvB;;;OAGG;IACH,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,SAAS,EAAE,iBAAiB,CAAC;IAE7B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;;;;;;;;;;OAiBG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACrC;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;IAER;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
package/core/util/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export * from './paired-client-heartbeat';
|
|
|
26
26
|
export * from './pipe';
|
|
27
27
|
export * from './retry-with-exponential-backoff';
|
|
28
28
|
export * from './service-factory';
|
|
29
|
+
export * from './service-response';
|
|
29
30
|
export * from './session-utils';
|
|
30
31
|
export * from './wait-for-request';
|
|
31
32
|
export * from './when-ready';
|
package/core/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,QAAQ,CAAC;AACvB,cAAc,kCAAkC,CAAC;AACjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,QAAQ,CAAC;AACvB,cAAc,kCAAkC,CAAC;AACjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
|
|
@@ -49,6 +49,14 @@ export type ClientResponse<Paths extends Record<string, any>, K extends keyof Pa
|
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
} ? R[keyof R] : unknown;
|
|
52
|
+
export type ClientParams<Paths extends Record<string, any>, K extends keyof Paths, M extends AvailableMethods<Paths[K]> | string> = Paths[K][M] extends {
|
|
53
|
+
parameters: infer P;
|
|
54
|
+
} ? P : never;
|
|
55
|
+
export type ClientBody<Paths extends Record<string, any>, K extends keyof Paths, M extends AvailableMethods<Paths[K]> | string> = Paths[K][M] extends {
|
|
56
|
+
requestBody: {
|
|
57
|
+
content: infer B;
|
|
58
|
+
};
|
|
59
|
+
} ? B[keyof B] : never;
|
|
52
60
|
export type ServiceResponse<T> = [string, null] | [null, T];
|
|
53
61
|
export type DeepRequired<T> = {
|
|
54
62
|
[K in keyof T]-?: T[K] extends object ? DeepRequired<T[K]> : T[K];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kos-service-request.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/util/kos-service-request.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;CAI1B,CAAC;AAIF,KAAK,YAAY,CAAC,CAAC,IAAI;KACpB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,CAAC;CAC7D,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,OAAO,CACvC,YAAY,CAAC,CAAC,CAAC,EACf,YAAY,GAAG,aAAa,CAC7B,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;KAC5B,MAAM,IAAI,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG;SAC5C,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,SAAS,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;KAClE,CAAC,MAAM,CAAC,GAAG,MAAM;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,SAAS,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;KAAE,CAAC;CAC7E,CAAC;AAEF,KAAK,eAAe,CAClB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,CAAC,SAAS,MAAM,KAAK,IACnB,KAAK,CAAC,CAAC,CAAC,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AAE,WAAW,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,CAAA;KAAE,CAAA;CAAE,GAC7D,CAAC,CAAC,MAAM,CAAC,CAAC,GACV,KAAK,CAAC;AASV,MAAM,MAAM,cAAc,CACxB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,CAAC,SAAS,MAAM,KAAK,EACrB,CAAC,SAAS,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAC3C,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;IAAE,SAAS,EAAE;QAAE,GAAG,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,GAChE,CAAC,CAAC,MAAM,CAAC,CAAC,GACV,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"kos-service-request.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/util/kos-service-request.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;CAI1B,CAAC;AAIF,KAAK,YAAY,CAAC,CAAC,IAAI;KACpB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,CAAC;CAC7D,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,OAAO,CACvC,YAAY,CAAC,CAAC,CAAC,EACf,YAAY,GAAG,aAAa,CAC7B,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;KAC5B,MAAM,IAAI,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG;SAC5C,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,SAAS,gBAAgB,CAAC,CAAC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AM,EAAE,GAAG,CAAC,EACjC,CAAC,SAAS,MAAM,KAAK,EACrB,CAAC,SAAS,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAC3C,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;IAAE,WAAW,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,CAAA;KAAE,CAAA;CAAE,GACzD,CAAC,CAAC,MAAM,CAAC,CAAC,GACV,KAAK,CAAC;AAEV,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAE5D,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAC3B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAClE,CAAC;AACF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAmD/D,KAAK,cAAc,GAAG,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,MAAM,CAAC,CAAC;AAC/D,wBAAgB,YAAY,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;sRAQ9C,cAAc;qVAOd,cAAc;gVAQd,cAAc;4VAOd,cAAc;EAU7B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { IKosDataModel } from '../core/kosModel';
|
|
2
|
+
import { ApiPath, HttpMethod } from '../core/decorators/kos-service-request';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utility functions for accessing cached service responses from ServiceResponseStore
|
|
6
|
+
*
|
|
7
|
+
* These functions provide type-safe access to responses stored by @kosServiceRequest
|
|
8
|
+
* decorated methods, eliminating the need for "magic last parameter" patterns.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* @kosServiceRequest({
|
|
13
|
+
* path: PATH_INGREDIENTS,
|
|
14
|
+
* method: 'get',
|
|
15
|
+
* lifecycle: DependencyLifecycle.LOAD
|
|
16
|
+
* })
|
|
17
|
+
* private onIngredientsLoaded(): void {
|
|
18
|
+
* const response = getServiceResponse(this, PATH_INGREDIENTS, 'get');
|
|
19
|
+
* this.processIngredients(response.data.ingredients);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Get cached service response by path and method
|
|
25
|
+
*
|
|
26
|
+
* Returns the response data cached by @kosServiceRequest decorated methods.
|
|
27
|
+
* TypeScript will infer types from your OpenAPI schema when using typed path constants.
|
|
28
|
+
*
|
|
29
|
+
* For cross-package scenarios where OpenAPI specs differ, you can optionally
|
|
30
|
+
* provide an explicit type parameter.
|
|
31
|
+
*
|
|
32
|
+
* @param model - The KOS model instance
|
|
33
|
+
* @param path - The API path constant
|
|
34
|
+
* @param method - The HTTP method (defaults to 'get')
|
|
35
|
+
* @returns The cached response data, or undefined if not found/expired
|
|
36
|
+
*
|
|
37
|
+
* @example Standard usage (types inferred from OpenAPI)
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const status = getServiceResponse(this, PATH_DEVICE_STATUS, 'get');
|
|
40
|
+
* // TypeScript infers the type from PATH_DEVICE_STATUS
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example Cross-package usage with explicit type (when OpenAPI schemas differ)
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Studio models using different OpenAPI than main SDK
|
|
46
|
+
* const vms = getServiceResponse<StudioVMResponse>(this, PATH_VMS, 'get');
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function getServiceResponse<T = any>(model: IKosDataModel, path: ApiPath, method?: HttpMethod): T | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Check if a cached response exists for the given path and method
|
|
52
|
+
*
|
|
53
|
+
* @param model - The KOS model instance
|
|
54
|
+
* @param path - The API path constant
|
|
55
|
+
* @param method - The HTTP method (defaults to 'get')
|
|
56
|
+
* @returns true if a valid cached response exists
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* if (hasCachedResponse(this, PATH_DEVICE_STATUS, 'get')) {
|
|
61
|
+
* // Use cached data
|
|
62
|
+
* const status = getServiceResponse(this, PATH_DEVICE_STATUS, 'get');
|
|
63
|
+
* } else {
|
|
64
|
+
* // Fetch fresh data
|
|
65
|
+
* await this.refreshStatus();
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function hasCachedResponse(model: IKosDataModel, path: ApiPath, method?: HttpMethod): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Manually clear a cached service response
|
|
72
|
+
*
|
|
73
|
+
* @param model - The KOS model instance
|
|
74
|
+
* @param path - The API path constant
|
|
75
|
+
* @param method - The HTTP method (defaults to 'get')
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Clear cached response to force refresh on next request
|
|
80
|
+
* clearServiceResponse(this, PATH_TEMP_DATA, 'post');
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function clearServiceResponse(model: IKosDataModel, path: ApiPath, method?: HttpMethod): void;
|
|
84
|
+
/**
|
|
85
|
+
* Clear all cached responses for a specific path (all methods)
|
|
86
|
+
*
|
|
87
|
+
* @param model - The KOS model instance
|
|
88
|
+
* @param path - The API path constant
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Clear all cached responses for this endpoint
|
|
93
|
+
* clearPath(this, PATH_INGREDIENTS);
|
|
94
|
+
* // Clears GET, POST, PUT, DELETE responses for this path
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function clearPath(model: IKosDataModel, path: ApiPath): void;
|
|
98
|
+
/**
|
|
99
|
+
* Clear all cached service responses in the model
|
|
100
|
+
*
|
|
101
|
+
* @param model - The KOS model instance
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Clear all cached responses (typically during model cleanup)
|
|
106
|
+
* clearAllServiceResponses(this);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function clearAllServiceResponses(model: IKosDataModel): void;
|
|
110
|
+
//# sourceMappingURL=service-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-response.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/util/service-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACX,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EACxC,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,OAAO,EACb,MAAM,GAAE,UAAkB,GACzB,CAAC,GAAG,SAAS,CAOf;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,OAAO,EACb,MAAM,GAAE,UAAkB,GACzB,OAAO,CAOT;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,OAAO,EACb,MAAM,GAAE,UAAkB,GACzB,IAAI,CAON;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAOnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAOnE"}
|