extended-dynamic-forms 0.2.0 → 0.3.0
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/README.md +398 -1075
- package/dist/WizardForm.d.ts +4 -1
- package/dist/events/FormEventContext.d.ts +3 -0
- package/dist/events/FormEventHub.d.ts +19 -2
- package/dist/index.es.js +21051 -12923
- package/dist/index.umd.js +63 -36
- package/dist/style.css +1 -1
- package/dist/types/index.d.ts +6 -1
- package/dist/utils/fieldChangeDetector.d.ts +22 -0
- package/dist/widgets/base/index.d.ts +2 -0
- package/dist/widgets/base/types.d.ts +135 -0
- package/dist/widgets/base/utils.d.ts +63 -0
- package/dist/widgets/choice/ChoiceWidget.d.ts +30 -0
- package/dist/widgets/choice/ChoiceWidget.types.d.ts +496 -0
- package/dist/widgets/choice/examples/ChoiceWidget.example.d.ts +7 -0
- package/dist/widgets/choice/hooks/__tests__/useChoiceWidget.test.d.ts +1 -0
- package/dist/widgets/choice/hooks/__tests__/useDataSource.test.d.ts +1 -0
- package/dist/widgets/choice/hooks/examples/useChoiceWidget.example.d.ts +18 -0
- package/dist/widgets/choice/hooks/examples/useDataSourceExample.d.ts +22 -0
- package/dist/widgets/choice/hooks/index.d.ts +6 -0
- package/dist/widgets/choice/hooks/useChoiceWidget.d.ts +65 -0
- package/dist/widgets/choice/hooks/useDataSource.d.ts +69 -0
- package/dist/widgets/choice/index.d.ts +59 -0
- package/dist/widgets/choice/presenters/CheckboxPresenter.d.ts +70 -0
- package/dist/widgets/choice/presenters/DropdownPresenter.d.ts +37 -0
- package/dist/widgets/choice/presenters/PresenterStrategy.d.ts +230 -0
- package/dist/widgets/choice/presenters/RadioPresenter.d.ts +39 -0
- package/dist/widgets/choice/presenters/examples/RadioPresenterExample.d.ts +7 -0
- package/dist/widgets/choice/presenters/index.d.ts +20 -0
- package/dist/widgets/choice/providers/ApiDataSource.d.ts +241 -0
- package/dist/widgets/choice/providers/DataSourceProvider.d.ts +260 -0
- package/dist/widgets/choice/providers/StaticDataSource.d.ts +258 -0
- package/dist/widgets/choice/providers/WebSocketDataSource.d.ts +310 -0
- package/dist/widgets/choice/providers/index.d.ts +12 -0
- package/dist/widgets/choice/utils/index.d.ts +1 -0
- package/dist/widgets/choice/utils/responseMappers.d.ts +342 -0
- package/dist/widgets/date/DateTimeWidget.d.ts +26 -0
- package/dist/widgets/date/EnhancedDateWidget.d.ts +26 -0
- package/dist/widgets/date/index.d.ts +13 -0
- package/dist/widgets/file/FileUploadWidget.d.ts +40 -0
- package/dist/widgets/file/index.d.ts +2 -0
- package/dist/widgets/index.d.ts +33 -17
- package/dist/widgets/input/EmailWidget.d.ts +34 -0
- package/dist/widgets/input/NumberWidget.d.ts +39 -0
- package/dist/widgets/input/TelephoneWidget.d.ts +34 -0
- package/dist/widgets/input/URLWidget.d.ts +34 -0
- package/dist/widgets/input/index.d.ts +7 -0
- package/dist/widgets/text/PasswordWidget.d.ts +45 -0
- package/dist/widgets/text/TextWidget.d.ts +40 -0
- package/dist/widgets/text/TextareaWidget.d.ts +38 -0
- package/dist/widgets/text/index.d.ts +20 -0
- package/package.json +8 -8
- package/dist/vanilla-entry.d.ts +0 -204
- package/dist/widgets/enhanced/EnhancedWidgets.d.ts +0 -37
- package/examples/conditional-v2-example.tsx +0 -64
- package/examples/dynamic-array-items-example.tsx +0 -211
- package/examples/form-devtools-example.tsx +0 -384
- package/examples/global-ui-rules-example.tsx +0 -371
- package/examples/vanilla-js/README.md +0 -212
- package/examples/vanilla-js/basic-form.html +0 -142
- package/examples/vanilla-js/conditional-form.html +0 -159
- package/examples/vanilla-js/wizard-form.html +0 -185
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { ChoiceOption, ApiDataSourceConfig } from '../ChoiceWidget.types';
|
|
2
|
+
import { DataSourceProvider, RetryConfig, DataSourceEventCallbacks } from './DataSourceProvider';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Debounce configuration for search requests
|
|
6
|
+
*/
|
|
7
|
+
interface DebounceConfig {
|
|
8
|
+
/** Debounce delay in milliseconds */
|
|
9
|
+
delayMs: number;
|
|
10
|
+
/** Maximum wait time before forcing execution */
|
|
11
|
+
maxWaitMs?: number;
|
|
12
|
+
/** Whether to execute on leading edge */
|
|
13
|
+
leading?: boolean;
|
|
14
|
+
/** Whether to execute on trailing edge */
|
|
15
|
+
trailing?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* API Data Source Provider
|
|
19
|
+
*
|
|
20
|
+
* Provides robust API integration with caching, error handling, authentication,
|
|
21
|
+
* request debouncing, and response transformation capabilities.
|
|
22
|
+
*
|
|
23
|
+
* Features:
|
|
24
|
+
* - HTTP client with timeout, retry, and cancellation support
|
|
25
|
+
* - Request debouncing for search/filter scenarios
|
|
26
|
+
* - Configurable response transformation
|
|
27
|
+
* - Multiple authentication methods (Bearer, Basic, API Key)
|
|
28
|
+
* - Request/response interceptors
|
|
29
|
+
* - Performance monitoring and metrics
|
|
30
|
+
* - Memory-efficient caching with TTL
|
|
31
|
+
* - Network error recovery with exponential backoff
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const apiConfig: ApiDataSourceConfig = {
|
|
36
|
+
* type: 'api',
|
|
37
|
+
* url: 'https://api.example.com/options',
|
|
38
|
+
* method: 'GET',
|
|
39
|
+
* responseMapper: {
|
|
40
|
+
* type: 'simple',
|
|
41
|
+
* simple: { arrayPath: 'data.items' }
|
|
42
|
+
* },
|
|
43
|
+
* auth: {
|
|
44
|
+
* type: 'bearer',
|
|
45
|
+
* credentials: 'your-token-here'
|
|
46
|
+
* }
|
|
47
|
+
* };
|
|
48
|
+
*
|
|
49
|
+
* const provider = new ApiDataSource(apiConfig);
|
|
50
|
+
* const options = await provider.fetchOptions();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class ApiDataSource extends DataSourceProvider {
|
|
54
|
+
private debounceConfig;
|
|
55
|
+
private config;
|
|
56
|
+
private httpClient;
|
|
57
|
+
private debouncedFetch?;
|
|
58
|
+
private lastRequestUrl?;
|
|
59
|
+
private searchParams?;
|
|
60
|
+
/**
|
|
61
|
+
* Whether this provider supports real-time updates
|
|
62
|
+
* API providers support real-time updates through polling or webhooks
|
|
63
|
+
*/
|
|
64
|
+
readonly supportsRealTime = true;
|
|
65
|
+
/**
|
|
66
|
+
* Constructor for ApiDataSource
|
|
67
|
+
*
|
|
68
|
+
* @param config - API data source configuration
|
|
69
|
+
* @param retryConfig - Retry configuration options
|
|
70
|
+
* @param eventCallbacks - Event callback functions
|
|
71
|
+
* @param debounceConfig - Debounce configuration for search requests
|
|
72
|
+
*/
|
|
73
|
+
constructor(config: ApiDataSourceConfig, retryConfig?: Partial<RetryConfig>, eventCallbacks?: DataSourceEventCallbacks, debounceConfig?: Partial<DebounceConfig>);
|
|
74
|
+
/**
|
|
75
|
+
* Fetch data from API with debouncing support
|
|
76
|
+
*
|
|
77
|
+
* This method automatically debounces requests for search/filter scenarios
|
|
78
|
+
* while providing immediate responses for regular data fetching.
|
|
79
|
+
*/
|
|
80
|
+
protected fetchData(): Promise<ChoiceOption[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Update search parameters and trigger a new request
|
|
83
|
+
*
|
|
84
|
+
* @param params - Search/filter parameters
|
|
85
|
+
*/
|
|
86
|
+
setSearchParams(params: Record<string, string | number | boolean>): void;
|
|
87
|
+
/**
|
|
88
|
+
* Clear search parameters
|
|
89
|
+
*/
|
|
90
|
+
clearSearchParams(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Cancel any pending debounced requests
|
|
93
|
+
*/
|
|
94
|
+
cancelPendingRequests(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Flush any pending debounced requests immediately
|
|
97
|
+
*/
|
|
98
|
+
flushPendingRequests(): Promise<ChoiceOption[]> | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Generate cache key based on URL and parameters
|
|
101
|
+
*/
|
|
102
|
+
protected getCacheKey(): string | null;
|
|
103
|
+
/**
|
|
104
|
+
* Cleanup API-specific resources
|
|
105
|
+
*/
|
|
106
|
+
protected cleanupResources(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Internal method for fetching data from API
|
|
109
|
+
*/
|
|
110
|
+
private fetchDataInternal;
|
|
111
|
+
/**
|
|
112
|
+
* Build complete request configuration
|
|
113
|
+
*/
|
|
114
|
+
private buildRequestConfig;
|
|
115
|
+
/**
|
|
116
|
+
* Build request URL
|
|
117
|
+
*/
|
|
118
|
+
private buildRequestUrl;
|
|
119
|
+
/**
|
|
120
|
+
* Build request parameters combining config params and search params
|
|
121
|
+
*/
|
|
122
|
+
private buildRequestParams;
|
|
123
|
+
/**
|
|
124
|
+
* Add authentication headers to request configuration
|
|
125
|
+
*/
|
|
126
|
+
private addAuthenticationHeaders;
|
|
127
|
+
/**
|
|
128
|
+
* Check if current request has search parameters
|
|
129
|
+
*/
|
|
130
|
+
private hasSearchParams;
|
|
131
|
+
/**
|
|
132
|
+
* Create HTTP client with configuration
|
|
133
|
+
*/
|
|
134
|
+
private createHttpClient;
|
|
135
|
+
/**
|
|
136
|
+
* Validate and normalize API configuration
|
|
137
|
+
*/
|
|
138
|
+
private validateAndNormalizeConfig;
|
|
139
|
+
/**
|
|
140
|
+
* Validate authentication configuration
|
|
141
|
+
*/
|
|
142
|
+
private validateAuthConfig;
|
|
143
|
+
/**
|
|
144
|
+
* Validate response mapper configuration
|
|
145
|
+
*/
|
|
146
|
+
private validateResponseMapper;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Utility function to create ApiDataSource with common configurations
|
|
150
|
+
*/
|
|
151
|
+
export declare function createApiDataSource(config: ApiDataSourceConfig, options?: {
|
|
152
|
+
retryConfig?: Partial<RetryConfig>;
|
|
153
|
+
eventCallbacks?: DataSourceEventCallbacks;
|
|
154
|
+
debounceConfig?: Partial<DebounceConfig>;
|
|
155
|
+
}): ApiDataSource;
|
|
156
|
+
/**
|
|
157
|
+
* Predefined response mappers for common API formats
|
|
158
|
+
*/
|
|
159
|
+
export declare const COMMON_RESPONSE_MAPPERS: {
|
|
160
|
+
/**
|
|
161
|
+
* Simple array response: [{ label: "Option 1", value: "opt1" }]
|
|
162
|
+
*/
|
|
163
|
+
readonly SIMPLE_ARRAY: {
|
|
164
|
+
readonly type: "simple";
|
|
165
|
+
readonly simple: {
|
|
166
|
+
readonly labelField: "label";
|
|
167
|
+
readonly valueField: "value";
|
|
168
|
+
readonly disabledField: "disabled";
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Paginated response: { data: { items: [...] } }
|
|
173
|
+
*/
|
|
174
|
+
readonly PAGINATED_DATA: {
|
|
175
|
+
readonly type: "simple";
|
|
176
|
+
readonly simple: {
|
|
177
|
+
readonly arrayPath: "data.items";
|
|
178
|
+
readonly labelField: "label";
|
|
179
|
+
readonly valueField: "value";
|
|
180
|
+
readonly disabledField: "disabled";
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* REST API response: { results: [...] }
|
|
185
|
+
*/
|
|
186
|
+
readonly REST_RESULTS: {
|
|
187
|
+
readonly type: "simple";
|
|
188
|
+
readonly simple: {
|
|
189
|
+
readonly arrayPath: "results";
|
|
190
|
+
readonly labelField: "name";
|
|
191
|
+
readonly valueField: "id";
|
|
192
|
+
readonly disabledField: "active";
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Nested object structure
|
|
197
|
+
*/
|
|
198
|
+
readonly NESTED_OBJECTS: {
|
|
199
|
+
readonly type: "nested";
|
|
200
|
+
readonly nested: {
|
|
201
|
+
readonly arrayPath: "data.options";
|
|
202
|
+
readonly paths: {
|
|
203
|
+
readonly label: "display.name";
|
|
204
|
+
readonly value: "identifier";
|
|
205
|
+
readonly disabled: "status.disabled";
|
|
206
|
+
readonly description: "display.description";
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Authentication helper functions
|
|
213
|
+
*/
|
|
214
|
+
export declare const AUTH_HELPERS: {
|
|
215
|
+
/**
|
|
216
|
+
* Create Bearer token authentication configuration
|
|
217
|
+
*/
|
|
218
|
+
readonly bearer: (token: string) => {
|
|
219
|
+
type: "bearer";
|
|
220
|
+
credentials: string;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Create Basic authentication configuration
|
|
224
|
+
*/
|
|
225
|
+
readonly basic: (username: string, password: string) => {
|
|
226
|
+
type: "basic";
|
|
227
|
+
credentials: {
|
|
228
|
+
username: string;
|
|
229
|
+
password: string;
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Create API key authentication configuration
|
|
234
|
+
*/
|
|
235
|
+
readonly apiKey: (key: string, headerName?: string) => {
|
|
236
|
+
type: "apiKey";
|
|
237
|
+
credentials: string;
|
|
238
|
+
headerName: string;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
export {};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { ChoiceOption, LoadingState, ErrorState, CacheConfig, ChoiceDataProvider } from '../ChoiceWidget.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retry configuration for handling failed requests
|
|
5
|
+
*/
|
|
6
|
+
export interface RetryConfig {
|
|
7
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
8
|
+
maxAttempts: number;
|
|
9
|
+
/** Base delay between retries in milliseconds (default: 1000) */
|
|
10
|
+
baseDelayMs: number;
|
|
11
|
+
/** Maximum delay between retries in milliseconds (default: 10000) */
|
|
12
|
+
maxDelayMs: number;
|
|
13
|
+
/** Backoff multiplier for exponential backoff (default: 2) */
|
|
14
|
+
backoffMultiplier: number;
|
|
15
|
+
/** Whether to add jitter to retry delays (default: true) */
|
|
16
|
+
jitter: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Default retry configuration
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Performance metrics for monitoring data source operations
|
|
24
|
+
*/
|
|
25
|
+
export interface DataSourceMetrics {
|
|
26
|
+
/** Total number of requests made */
|
|
27
|
+
requestCount: number;
|
|
28
|
+
/** Number of successful requests */
|
|
29
|
+
successCount: number;
|
|
30
|
+
/** Number of failed requests */
|
|
31
|
+
errorCount: number;
|
|
32
|
+
/** Number of cache hits */
|
|
33
|
+
cacheHitCount: number;
|
|
34
|
+
/** Number of cache misses */
|
|
35
|
+
cacheMissCount: number;
|
|
36
|
+
/** Average response time in milliseconds */
|
|
37
|
+
averageResponseTimeMs: number;
|
|
38
|
+
/** Last request timestamp */
|
|
39
|
+
lastRequestTimestamp?: number;
|
|
40
|
+
/** Last error timestamp */
|
|
41
|
+
lastErrorTimestamp?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Event callbacks for data source operations
|
|
45
|
+
*/
|
|
46
|
+
export interface DataSourceEventCallbacks {
|
|
47
|
+
/** Called when data loading starts */
|
|
48
|
+
onLoadingStart?: (provider: DataSourceProvider) => void;
|
|
49
|
+
/** Called when data loading completes successfully */
|
|
50
|
+
onLoadingComplete?: (provider: DataSourceProvider, data: ChoiceOption[]) => void;
|
|
51
|
+
/** Called when an error occurs */
|
|
52
|
+
onError?: (provider: DataSourceProvider, error: Error) => void;
|
|
53
|
+
/** Called when cache is hit */
|
|
54
|
+
onCacheHit?: (provider: DataSourceProvider, key: string) => void;
|
|
55
|
+
/** Called when cache is missed */
|
|
56
|
+
onCacheMiss?: (provider: DataSourceProvider, key: string) => void;
|
|
57
|
+
/** Called when cache is cleared */
|
|
58
|
+
onCacheCleared?: (provider: DataSourceProvider, key?: string) => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Abstract base class for data source providers
|
|
62
|
+
*
|
|
63
|
+
* Provides common functionality for all data source implementations including:
|
|
64
|
+
* - Caching with configurable TTL
|
|
65
|
+
* - Loading state management
|
|
66
|
+
* - Error handling with retry logic
|
|
67
|
+
* - Performance metrics
|
|
68
|
+
* - Memory-efficient cache cleanup
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* class ApiDataSourceProvider extends DataSourceProvider {
|
|
73
|
+
* protected async fetchData(): Promise<ChoiceOption[]> {
|
|
74
|
+
* const response = await fetch(this.config.url);
|
|
75
|
+
* return this.mapResponse(await response.json());
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare abstract class DataSourceProvider implements ChoiceDataProvider {
|
|
81
|
+
private static memoryCache;
|
|
82
|
+
private static cacheCleanupInterval?;
|
|
83
|
+
private static instanceCount;
|
|
84
|
+
protected cache: CacheConfig;
|
|
85
|
+
protected retryConfig: RetryConfig;
|
|
86
|
+
protected loadingState: LoadingState;
|
|
87
|
+
protected errorState: ErrorState;
|
|
88
|
+
protected metrics: DataSourceMetrics;
|
|
89
|
+
protected eventCallbacks?: DataSourceEventCallbacks;
|
|
90
|
+
protected instanceId: string;
|
|
91
|
+
protected isDestroyed: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Whether this provider supports caching
|
|
94
|
+
*/
|
|
95
|
+
readonly supportsCaching = true;
|
|
96
|
+
/**
|
|
97
|
+
* Whether this provider supports real-time updates
|
|
98
|
+
* Subclasses should override this if they support real-time updates
|
|
99
|
+
*/
|
|
100
|
+
readonly supportsRealTime: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Constructor for DataSourceProvider
|
|
103
|
+
*
|
|
104
|
+
* @param cacheConfig - Cache configuration options
|
|
105
|
+
* @param retryConfig - Retry configuration options
|
|
106
|
+
* @param eventCallbacks - Event callback functions
|
|
107
|
+
*/
|
|
108
|
+
constructor(cacheConfig?: Partial<CacheConfig>, retryConfig?: Partial<RetryConfig>, eventCallbacks?: DataSourceEventCallbacks);
|
|
109
|
+
/**
|
|
110
|
+
* Fetch options from the data source
|
|
111
|
+
*
|
|
112
|
+
* This is the main public method that handles caching, loading states,
|
|
113
|
+
* error handling, and retry logic.
|
|
114
|
+
*
|
|
115
|
+
* @returns Promise resolving to array of choice options
|
|
116
|
+
* @throws Error if provider is destroyed or max retries exceeded
|
|
117
|
+
*/
|
|
118
|
+
fetchOptions(): Promise<ChoiceOption[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Get current loading state
|
|
121
|
+
*/
|
|
122
|
+
getLoadingState(): LoadingState;
|
|
123
|
+
/**
|
|
124
|
+
* Get current error state
|
|
125
|
+
*/
|
|
126
|
+
getErrorState(): ErrorState;
|
|
127
|
+
/**
|
|
128
|
+
* Get performance metrics
|
|
129
|
+
*/
|
|
130
|
+
getMetrics(): DataSourceMetrics;
|
|
131
|
+
/**
|
|
132
|
+
* Clear specific cache entry or all cache entries
|
|
133
|
+
*
|
|
134
|
+
* @param key - Cache key to clear, or undefined to clear all
|
|
135
|
+
*/
|
|
136
|
+
clearCache(key?: string): void;
|
|
137
|
+
/**
|
|
138
|
+
* Clear error state
|
|
139
|
+
*/
|
|
140
|
+
clearError(): void;
|
|
141
|
+
/**
|
|
142
|
+
* Reset metrics to initial state
|
|
143
|
+
*/
|
|
144
|
+
resetMetrics(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Check if cache contains valid data for the given key
|
|
147
|
+
*
|
|
148
|
+
* @param key - Cache key to check
|
|
149
|
+
* @returns true if cache contains valid data
|
|
150
|
+
*/
|
|
151
|
+
hasCachedData(key?: string): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Cleanup resources and destroy the provider
|
|
154
|
+
*
|
|
155
|
+
* Should be called when the provider is no longer needed
|
|
156
|
+
* to prevent memory leaks and cleanup resources.
|
|
157
|
+
*/
|
|
158
|
+
cleanup(): void;
|
|
159
|
+
/**
|
|
160
|
+
* Fetch data from the actual data source
|
|
161
|
+
*
|
|
162
|
+
* Subclasses must implement this method to fetch data from their
|
|
163
|
+
* specific data source (API, file, database, etc.)
|
|
164
|
+
*
|
|
165
|
+
* @returns Promise resolving to array of choice options
|
|
166
|
+
*/
|
|
167
|
+
protected abstract fetchData(): Promise<ChoiceOption[]>;
|
|
168
|
+
/**
|
|
169
|
+
* Generate a unique cache key for this data source
|
|
170
|
+
*
|
|
171
|
+
* Subclasses should implement this to generate a unique cache key
|
|
172
|
+
* based on their configuration (URL, parameters, etc.)
|
|
173
|
+
*
|
|
174
|
+
* @returns Cache key string or null if caching should be disabled
|
|
175
|
+
*/
|
|
176
|
+
protected abstract getCacheKey(): string | null;
|
|
177
|
+
/**
|
|
178
|
+
* Cleanup subclass-specific resources
|
|
179
|
+
*
|
|
180
|
+
* Subclasses can override this to cleanup their specific resources
|
|
181
|
+
* (abort controllers, event listeners, etc.)
|
|
182
|
+
*/
|
|
183
|
+
protected cleanupResources(): void;
|
|
184
|
+
/**
|
|
185
|
+
* Set loading state and notify callbacks
|
|
186
|
+
*
|
|
187
|
+
* @param isLoading - Whether currently loading
|
|
188
|
+
* @param message - Optional loading message
|
|
189
|
+
* @param progress - Optional progress percentage (0-100)
|
|
190
|
+
*/
|
|
191
|
+
protected setLoadingState(isLoading: boolean, message?: string, progress?: number): void;
|
|
192
|
+
/**
|
|
193
|
+
* Validate fetched data and transform if necessary
|
|
194
|
+
*
|
|
195
|
+
* @param data - Raw data to validate
|
|
196
|
+
* @returns Validated and transformed choice options
|
|
197
|
+
* @throws Error if data is invalid
|
|
198
|
+
*/
|
|
199
|
+
protected validateAndTransformData(data: ChoiceOption[]): ChoiceOption[];
|
|
200
|
+
/**
|
|
201
|
+
* Log debug messages (only in development)
|
|
202
|
+
*
|
|
203
|
+
* @param message - Debug message to log
|
|
204
|
+
* @param data - Optional data to include in log
|
|
205
|
+
*/
|
|
206
|
+
protected logDebug(message: string, data?: unknown): void;
|
|
207
|
+
/**
|
|
208
|
+
* Log error messages
|
|
209
|
+
*
|
|
210
|
+
* @param message - Error message to log
|
|
211
|
+
* @param error - Optional error object
|
|
212
|
+
*/
|
|
213
|
+
protected logError(message: string, error?: Error): void;
|
|
214
|
+
/**
|
|
215
|
+
* Fetch data with retry logic and exponential backoff
|
|
216
|
+
*/
|
|
217
|
+
private fetchWithRetry;
|
|
218
|
+
/**
|
|
219
|
+
* Get cached data if valid
|
|
220
|
+
*/
|
|
221
|
+
private getCachedData;
|
|
222
|
+
/**
|
|
223
|
+
* Set cached data with TTL
|
|
224
|
+
*/
|
|
225
|
+
private setCachedData;
|
|
226
|
+
/**
|
|
227
|
+
* Handle errors and update error state
|
|
228
|
+
*/
|
|
229
|
+
private handleError;
|
|
230
|
+
/**
|
|
231
|
+
* Update performance metrics
|
|
232
|
+
*/
|
|
233
|
+
private updateMetrics;
|
|
234
|
+
/**
|
|
235
|
+
* Start periodic cache cleanup
|
|
236
|
+
*/
|
|
237
|
+
private startCacheCleanup;
|
|
238
|
+
/**
|
|
239
|
+
* Stop periodic cache cleanup
|
|
240
|
+
*/
|
|
241
|
+
private stopCacheCleanup;
|
|
242
|
+
/**
|
|
243
|
+
* Run cache cleanup to remove expired entries
|
|
244
|
+
*/
|
|
245
|
+
private runCacheCleanup;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Utility function to create a simple hash for cache keys
|
|
249
|
+
*
|
|
250
|
+
* @param input - String to hash
|
|
251
|
+
* @returns Simple hash string
|
|
252
|
+
*/
|
|
253
|
+
export declare function createSimpleHash(input: string): string;
|
|
254
|
+
/**
|
|
255
|
+
* Utility function to validate choice options array
|
|
256
|
+
*
|
|
257
|
+
* @param options - Options array to validate
|
|
258
|
+
* @returns Validation errors or null if valid
|
|
259
|
+
*/
|
|
260
|
+
export declare function validateChoiceOptions(options: unknown): string[] | null;
|