extended-dynamic-forms 0.2.1 → 0.3.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/README.md +387 -1392
- package/dist/events/FormEventContext.d.ts +3 -0
- package/dist/index.es.js +22516 -14517
- package/dist/index.umd.js +63 -36
- package/dist/style.css +1 -1
- 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 +5 -5
- package/dist/vanilla-entry.d.ts +0 -232
- package/dist/widgets/enhanced/EnhancedWidgets.d.ts +0 -37
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { DataSourceProvider, DataSourceEventCallbacks } from './DataSourceProvider';
|
|
2
|
+
import { ChoiceOption, StaticDataSourceConfig, SearchConfig, CacheConfig } from '../ChoiceWidget.types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration interface for StaticDataSource
|
|
6
|
+
*/
|
|
7
|
+
export interface StaticDataSourceOptions {
|
|
8
|
+
/** Cache configuration (optional for static data, but maintains consistency) */
|
|
9
|
+
cache?: Partial<CacheConfig>;
|
|
10
|
+
/** Event callbacks for monitoring operations */
|
|
11
|
+
eventCallbacks?: DataSourceEventCallbacks;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Static data source provider for immediate, synchronous access to option arrays
|
|
15
|
+
*
|
|
16
|
+
* Provides in-memory option storage with immediate data availability.
|
|
17
|
+
* While static data doesn't require caching, this provider maintains
|
|
18
|
+
* consistency with async providers by supporting the caching interface.
|
|
19
|
+
*
|
|
20
|
+
* Key features:
|
|
21
|
+
* - Immediate data availability (no async loading required)
|
|
22
|
+
* - Option validation and error reporting
|
|
23
|
+
* - Support for option filtering and searching
|
|
24
|
+
* - Memory optimization for large option sets
|
|
25
|
+
* - Consistent interface with async providers
|
|
26
|
+
* - Integration with FormEventHub system
|
|
27
|
+
*
|
|
28
|
+
* @example Basic usage:
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const config: StaticDataSourceConfig = {
|
|
31
|
+
* type: 'static',
|
|
32
|
+
* options: [
|
|
33
|
+
* { label: 'Option 1', value: 'opt1' },
|
|
34
|
+
* { label: 'Option 2', value: 'opt2' }
|
|
35
|
+
* ]
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* const provider = new StaticDataSource(config);
|
|
39
|
+
* const options = await provider.fetchOptions();
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example With search filtering:
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const provider = new StaticDataSource(config);
|
|
45
|
+
* const filtered = provider.searchOptions('search term', {
|
|
46
|
+
* enabled: true,
|
|
47
|
+
* searchFields: ['label', 'description'],
|
|
48
|
+
* caseSensitive: false
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example With option groups:
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const config: StaticDataSourceConfig = {
|
|
55
|
+
* type: 'static',
|
|
56
|
+
* options: [
|
|
57
|
+
* { label: 'Admin', value: 'admin', metadata: { group: 'roles' } },
|
|
58
|
+
* { label: 'User', value: 'user', metadata: { group: 'roles' } },
|
|
59
|
+
* { label: 'Manager', value: 'manager', metadata: { group: 'roles' } }
|
|
60
|
+
* ]
|
|
61
|
+
* };
|
|
62
|
+
*
|
|
63
|
+
* const provider = new StaticDataSource(config);
|
|
64
|
+
* const grouped = provider.getGroupedOptions();
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare class StaticDataSource extends DataSourceProvider {
|
|
68
|
+
private readonly validatedOptions;
|
|
69
|
+
private readonly optionGroups;
|
|
70
|
+
/**
|
|
71
|
+
* Whether this provider supports real-time updates
|
|
72
|
+
* Static data can be updated in memory immediately
|
|
73
|
+
*/
|
|
74
|
+
readonly supportsRealTime = true;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new StaticDataSource instance
|
|
77
|
+
*
|
|
78
|
+
* @param config - Static data source configuration
|
|
79
|
+
* @param options - Additional configuration options
|
|
80
|
+
* @throws Error if configuration or options are invalid
|
|
81
|
+
*/
|
|
82
|
+
constructor(config: StaticDataSourceConfig, options?: StaticDataSourceOptions);
|
|
83
|
+
/**
|
|
84
|
+
* Fetch options from static data
|
|
85
|
+
*
|
|
86
|
+
* Since data is static and already validated, this method returns
|
|
87
|
+
* the pre-validated options immediately. The async interface is
|
|
88
|
+
* maintained for consistency with other data source providers.
|
|
89
|
+
*
|
|
90
|
+
* @returns Promise resolving to validated choice options
|
|
91
|
+
*/
|
|
92
|
+
protected fetchData(): Promise<ChoiceOption[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate cache key for static data
|
|
95
|
+
*
|
|
96
|
+
* Static data doesn't need caching since it's immediately available.
|
|
97
|
+
* We return null to disable caching and ensure fresh copies are always returned.
|
|
98
|
+
*
|
|
99
|
+
* @returns null to disable caching for static data
|
|
100
|
+
*/
|
|
101
|
+
protected getCacheKey(): string | null;
|
|
102
|
+
/**
|
|
103
|
+
* Search and filter options based on search configuration
|
|
104
|
+
*
|
|
105
|
+
* Provides efficient in-memory searching with support for:
|
|
106
|
+
* - Multiple search fields (label, value, description)
|
|
107
|
+
* - Case-sensitive/insensitive matching
|
|
108
|
+
* - Custom filter functions
|
|
109
|
+
* - Optimized performance for large option sets
|
|
110
|
+
*
|
|
111
|
+
* @param searchTerm - Term to search for
|
|
112
|
+
* @param searchConfig - Search configuration options
|
|
113
|
+
* @returns Filtered array of options
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const filtered = provider.searchOptions('admin', {
|
|
118
|
+
* enabled: true,
|
|
119
|
+
* searchFields: ['label', 'description'],
|
|
120
|
+
* caseSensitive: false
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
searchOptions(searchTerm: string, searchConfig: SearchConfig): ChoiceOption[];
|
|
125
|
+
/**
|
|
126
|
+
* Get options grouped by category/group
|
|
127
|
+
*
|
|
128
|
+
* Organizes options into groups based on metadata.group property.
|
|
129
|
+
* Returns a Map where keys are group names and values are option arrays.
|
|
130
|
+
* Options without a group are placed in an 'ungrouped' category.
|
|
131
|
+
*
|
|
132
|
+
* @returns Map of group names to option arrays
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const grouped = provider.getGroupedOptions();
|
|
137
|
+
* for (const [groupName, options] of grouped) {
|
|
138
|
+
* console.log(`${groupName}: ${options.length} options`);
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
getGroupedOptions(): Map<string, ChoiceOption[]>;
|
|
143
|
+
/**
|
|
144
|
+
* Get options by specific group name
|
|
145
|
+
*
|
|
146
|
+
* @param groupName - Name of the group to retrieve
|
|
147
|
+
* @returns Array of options in the specified group
|
|
148
|
+
*/
|
|
149
|
+
getOptionsByGroup(groupName: string): ChoiceOption[];
|
|
150
|
+
/**
|
|
151
|
+
* Get all available group names
|
|
152
|
+
*
|
|
153
|
+
* @returns Array of group names
|
|
154
|
+
*/
|
|
155
|
+
getGroupNames(): string[];
|
|
156
|
+
/**
|
|
157
|
+
* Update static options in memory
|
|
158
|
+
*
|
|
159
|
+
* Provides real-time option updates for static data sources.
|
|
160
|
+
* This method validates new options and updates the internal cache.
|
|
161
|
+
*
|
|
162
|
+
* @param newOptions - New options array to replace existing options
|
|
163
|
+
* @throws Error if new options are invalid
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const newOptions = [
|
|
168
|
+
* { label: 'New Option 1', value: 'new1' },
|
|
169
|
+
* { label: 'New Option 2', value: 'new2' }
|
|
170
|
+
* ];
|
|
171
|
+
*
|
|
172
|
+
* provider.updateOptions(newOptions);
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
updateOptions(newOptions: ChoiceOption[]): void;
|
|
176
|
+
/**
|
|
177
|
+
* Add new options to existing set
|
|
178
|
+
*
|
|
179
|
+
* @param additionalOptions - Options to add
|
|
180
|
+
* @throws Error if any new options are invalid
|
|
181
|
+
*/
|
|
182
|
+
addOptions(additionalOptions: ChoiceOption[]): void;
|
|
183
|
+
/**
|
|
184
|
+
* Remove options by value
|
|
185
|
+
*
|
|
186
|
+
* @param values - Array of values to remove
|
|
187
|
+
* @returns Number of options removed
|
|
188
|
+
*/
|
|
189
|
+
removeOptions(values: (string | number | boolean)[]): number;
|
|
190
|
+
/**
|
|
191
|
+
* Get option by value
|
|
192
|
+
*
|
|
193
|
+
* @param value - Value to search for
|
|
194
|
+
* @returns Option with matching value or null if not found
|
|
195
|
+
*/
|
|
196
|
+
getOptionByValue(value: string | number | boolean): ChoiceOption | null;
|
|
197
|
+
/**
|
|
198
|
+
* Check if option exists with given value
|
|
199
|
+
*
|
|
200
|
+
* @param value - Value to check
|
|
201
|
+
* @returns True if option exists
|
|
202
|
+
*/
|
|
203
|
+
hasOptionWithValue(value: string | number | boolean): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Get total number of options
|
|
206
|
+
*
|
|
207
|
+
* @returns Total option count
|
|
208
|
+
*/
|
|
209
|
+
getOptionCount(): number;
|
|
210
|
+
/**
|
|
211
|
+
* Get memory usage statistics for large datasets
|
|
212
|
+
*
|
|
213
|
+
* @returns Memory usage information
|
|
214
|
+
*/
|
|
215
|
+
getMemoryStats(): {
|
|
216
|
+
optionCount: number;
|
|
217
|
+
groupCount: number;
|
|
218
|
+
estimatedMemoryKB: number;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Override to ensure deep copying of metadata for static data
|
|
222
|
+
*/
|
|
223
|
+
protected validateAndTransformData(data: ChoiceOption[]): ChoiceOption[];
|
|
224
|
+
/**
|
|
225
|
+
* No cleanup needed for static data, but method provided for consistency
|
|
226
|
+
*/
|
|
227
|
+
protected cleanupResources(): void;
|
|
228
|
+
/**
|
|
229
|
+
* Validate the static data source configuration
|
|
230
|
+
*/
|
|
231
|
+
private validateConfig;
|
|
232
|
+
/**
|
|
233
|
+
* Build option groups for efficient lookup
|
|
234
|
+
*/
|
|
235
|
+
private buildOptionGroups;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Factory function to create StaticDataSource instances
|
|
239
|
+
*
|
|
240
|
+
* @param config - Static data source configuration
|
|
241
|
+
* @param options - Additional configuration options
|
|
242
|
+
* @returns New StaticDataSource instance
|
|
243
|
+
*/
|
|
244
|
+
export declare function createStaticDataSource(config: StaticDataSourceConfig, options?: StaticDataSourceOptions): StaticDataSource;
|
|
245
|
+
/**
|
|
246
|
+
* Type guard to check if an option has a group
|
|
247
|
+
*
|
|
248
|
+
* @param option - Option to check
|
|
249
|
+
* @returns True if option has a group defined
|
|
250
|
+
*/
|
|
251
|
+
export declare function hasGroup(option: ChoiceOption): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Utility to create grouped static options
|
|
254
|
+
*
|
|
255
|
+
* @param groups - Object mapping group names to option arrays
|
|
256
|
+
* @returns Flattened array of options with group metadata
|
|
257
|
+
*/
|
|
258
|
+
export declare function createGroupedOptions(groups: Record<string, Omit<ChoiceOption, 'metadata'>[]>): ChoiceOption[];
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { DataSourceProvider, DataSourceEventCallbacks } from './DataSourceProvider';
|
|
2
|
+
import { ChoiceOption, WebSocketDataSourceConfig, WebSocketMessage, CacheConfig } from '../ChoiceWidget.types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration interface for WebSocketDataSource
|
|
6
|
+
*/
|
|
7
|
+
export interface WebSocketDataSourceOptions {
|
|
8
|
+
/** Cache configuration (for offline support) */
|
|
9
|
+
cache?: Partial<CacheConfig>;
|
|
10
|
+
/** Event callbacks for monitoring operations */
|
|
11
|
+
eventCallbacks?: DataSourceEventCallbacks;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Connection states for WebSocket
|
|
15
|
+
*/
|
|
16
|
+
export declare enum WebSocketConnectionState {
|
|
17
|
+
DISCONNECTED = "disconnected",
|
|
18
|
+
CONNECTING = "connecting",
|
|
19
|
+
CONNECTED = "connected",
|
|
20
|
+
RECONNECTING = "reconnecting",
|
|
21
|
+
FAILED = "failed"
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* WebSocket data source provider for real-time option updates
|
|
25
|
+
*
|
|
26
|
+
* Provides real-time data synchronization through WebSocket connections.
|
|
27
|
+
* Supports automatic reconnection, heartbeat monitoring, and offline caching.
|
|
28
|
+
*
|
|
29
|
+
* Key features:
|
|
30
|
+
* - Real-time option updates from server
|
|
31
|
+
* - Automatic reconnection with exponential backoff
|
|
32
|
+
* - Heartbeat monitoring for connection health
|
|
33
|
+
* - Request-response pattern with message correlation
|
|
34
|
+
* - Search request debouncing
|
|
35
|
+
* - Offline cache for resilience
|
|
36
|
+
* - Authentication support (Bearer, Query, Header)
|
|
37
|
+
*
|
|
38
|
+
* @example Basic usage:
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const config: WebSocketDataSourceConfig = {
|
|
41
|
+
* type: 'websocket',
|
|
42
|
+
* url: 'ws://localhost:8080/choices',
|
|
43
|
+
* auth: {
|
|
44
|
+
* type: 'bearer',
|
|
45
|
+
* credentials: 'your-token'
|
|
46
|
+
* }
|
|
47
|
+
* };
|
|
48
|
+
*
|
|
49
|
+
* const provider = new WebSocketDataSource(config);
|
|
50
|
+
* const options = await provider.fetchOptions();
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Real-time search:
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const config: WebSocketDataSourceConfig = {
|
|
56
|
+
* type: 'websocket',
|
|
57
|
+
* url: 'ws://localhost:8080/choices',
|
|
58
|
+
* messageHandling: {
|
|
59
|
+
* enableRealtimeSearch: true,
|
|
60
|
+
* searchDebounceMs: 300
|
|
61
|
+
* }
|
|
62
|
+
* };
|
|
63
|
+
*
|
|
64
|
+
* const provider = new WebSocketDataSource(config);
|
|
65
|
+
* provider.setSearchParams({ search: 'query' });
|
|
66
|
+
* const results = await provider.fetchOptions();
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare class WebSocketDataSource extends DataSourceProvider {
|
|
70
|
+
private readonly config;
|
|
71
|
+
private websocket;
|
|
72
|
+
private connectionState;
|
|
73
|
+
private reconnectAttempts;
|
|
74
|
+
private heartbeatInterval;
|
|
75
|
+
private responseTimeout;
|
|
76
|
+
private searchTimeout;
|
|
77
|
+
private pendingRequests;
|
|
78
|
+
private currentOptions;
|
|
79
|
+
private currentSearchParams;
|
|
80
|
+
/**
|
|
81
|
+
* Whether this provider supports real-time updates
|
|
82
|
+
* WebSocket providers always support real-time updates
|
|
83
|
+
*/
|
|
84
|
+
readonly supportsRealTime = true;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a new WebSocketDataSource instance
|
|
87
|
+
*
|
|
88
|
+
* @param config - WebSocket data source configuration
|
|
89
|
+
* @param options - Additional configuration options
|
|
90
|
+
* @throws Error if configuration is invalid
|
|
91
|
+
*/
|
|
92
|
+
constructor(config: WebSocketDataSourceConfig, options?: WebSocketDataSourceOptions);
|
|
93
|
+
/**
|
|
94
|
+
* Fetch options from WebSocket data source
|
|
95
|
+
*
|
|
96
|
+
* Establishes connection if needed and requests current options.
|
|
97
|
+
* Returns cached data immediately if available and fresh.
|
|
98
|
+
*
|
|
99
|
+
* @returns Promise resolving to choice options
|
|
100
|
+
* @throws Error if connection fails or request times out
|
|
101
|
+
*/
|
|
102
|
+
protected fetchData(): Promise<ChoiceOption[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Generate cache key for WebSocket data source
|
|
105
|
+
*
|
|
106
|
+
* @returns Cache key string including URL and search parameters
|
|
107
|
+
*/
|
|
108
|
+
protected getCacheKey(): string | null;
|
|
109
|
+
/**
|
|
110
|
+
* Set search parameters for real-time search
|
|
111
|
+
*
|
|
112
|
+
* @param params - Search parameters to apply
|
|
113
|
+
*/
|
|
114
|
+
setSearchParams(params: Record<string, string | number | boolean>): void;
|
|
115
|
+
/**
|
|
116
|
+
* Clear search parameters
|
|
117
|
+
*/
|
|
118
|
+
clearSearchParams(): void;
|
|
119
|
+
/**
|
|
120
|
+
* Get current connection state
|
|
121
|
+
*
|
|
122
|
+
* @returns Current WebSocket connection state
|
|
123
|
+
*/
|
|
124
|
+
getConnectionState(): WebSocketConnectionState;
|
|
125
|
+
/**
|
|
126
|
+
* Force reconnection to WebSocket server
|
|
127
|
+
*
|
|
128
|
+
* @returns Promise that resolves when reconnection is complete
|
|
129
|
+
*/
|
|
130
|
+
reconnect(): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Send a message to the WebSocket server
|
|
133
|
+
*
|
|
134
|
+
* @param message - Message to send
|
|
135
|
+
* @throws Error if not connected
|
|
136
|
+
*/
|
|
137
|
+
sendMessage(message: WebSocketMessage): void;
|
|
138
|
+
/**
|
|
139
|
+
* Subscribe to real-time option updates
|
|
140
|
+
*
|
|
141
|
+
* @param callback - Function to call when options are updated
|
|
142
|
+
* @returns Unsubscribe function
|
|
143
|
+
*/
|
|
144
|
+
subscribeToUpdates(callback: (options: ChoiceOption[]) => void): () => void;
|
|
145
|
+
/**
|
|
146
|
+
* Cleanup WebSocket resources
|
|
147
|
+
*/
|
|
148
|
+
protected cleanupResources(): void;
|
|
149
|
+
/**
|
|
150
|
+
* Validate WebSocket configuration
|
|
151
|
+
*/
|
|
152
|
+
private validateConfig;
|
|
153
|
+
/**
|
|
154
|
+
* Normalize configuration with defaults
|
|
155
|
+
*/
|
|
156
|
+
private normalizeConfig;
|
|
157
|
+
/**
|
|
158
|
+
* Ensure WebSocket connection is established
|
|
159
|
+
*/
|
|
160
|
+
private ensureConnection;
|
|
161
|
+
/**
|
|
162
|
+
* Establish WebSocket connection
|
|
163
|
+
*/
|
|
164
|
+
private connect;
|
|
165
|
+
/**
|
|
166
|
+
* Build connection URL with authentication
|
|
167
|
+
*/
|
|
168
|
+
private buildConnectionUrl;
|
|
169
|
+
/**
|
|
170
|
+
* Authenticate the WebSocket connection
|
|
171
|
+
*/
|
|
172
|
+
private authenticateConnection;
|
|
173
|
+
/**
|
|
174
|
+
* Request initial options from server
|
|
175
|
+
*/
|
|
176
|
+
private requestInitialOptions;
|
|
177
|
+
/**
|
|
178
|
+
* Handle incoming WebSocket messages
|
|
179
|
+
*/
|
|
180
|
+
private handleMessage;
|
|
181
|
+
/**
|
|
182
|
+
* Handle search response messages
|
|
183
|
+
*/
|
|
184
|
+
private handleSearchResponse;
|
|
185
|
+
/**
|
|
186
|
+
* Handle options update messages (real-time updates)
|
|
187
|
+
*/
|
|
188
|
+
private handleOptionsUpdate;
|
|
189
|
+
/**
|
|
190
|
+
* Handle options add messages
|
|
191
|
+
*/
|
|
192
|
+
private handleOptionsAdd;
|
|
193
|
+
/**
|
|
194
|
+
* Handle options remove messages
|
|
195
|
+
*/
|
|
196
|
+
private handleOptionsRemove;
|
|
197
|
+
/**
|
|
198
|
+
* Handle options patch messages
|
|
199
|
+
*/
|
|
200
|
+
private handleOptionsPatch;
|
|
201
|
+
/**
|
|
202
|
+
* Handle error messages from server
|
|
203
|
+
*/
|
|
204
|
+
private handleErrorMessage;
|
|
205
|
+
/**
|
|
206
|
+
* Handle heartbeat messages
|
|
207
|
+
*/
|
|
208
|
+
private handleHeartbeat;
|
|
209
|
+
/**
|
|
210
|
+
* Handle WebSocket connection close
|
|
211
|
+
*/
|
|
212
|
+
private handleConnectionClose;
|
|
213
|
+
/**
|
|
214
|
+
* Handle WebSocket connection errors
|
|
215
|
+
*/
|
|
216
|
+
private handleConnectionError;
|
|
217
|
+
/**
|
|
218
|
+
* Schedule reconnection with exponential backoff
|
|
219
|
+
*/
|
|
220
|
+
private scheduleReconnection;
|
|
221
|
+
/**
|
|
222
|
+
* Start heartbeat monitoring
|
|
223
|
+
*/
|
|
224
|
+
private startHeartbeat;
|
|
225
|
+
/**
|
|
226
|
+
* Debounce search requests
|
|
227
|
+
*/
|
|
228
|
+
private debounceSearch;
|
|
229
|
+
/**
|
|
230
|
+
* Send search request to server
|
|
231
|
+
*/
|
|
232
|
+
private sendSearchRequest;
|
|
233
|
+
/**
|
|
234
|
+
* Transform response data using configured mapper
|
|
235
|
+
*/
|
|
236
|
+
private transformResponseData;
|
|
237
|
+
/**
|
|
238
|
+
* Apply simple response mapper
|
|
239
|
+
*/
|
|
240
|
+
private applySimpleMapper;
|
|
241
|
+
/**
|
|
242
|
+
* Apply nested response mapper
|
|
243
|
+
*/
|
|
244
|
+
private applyNestedMapper;
|
|
245
|
+
/**
|
|
246
|
+
* Get cached data safely
|
|
247
|
+
*/
|
|
248
|
+
private getWebSocketCachedData;
|
|
249
|
+
/**
|
|
250
|
+
* Set cached data safely
|
|
251
|
+
*/
|
|
252
|
+
private setWebSocketCachedData;
|
|
253
|
+
/**
|
|
254
|
+
* Generate unique message ID
|
|
255
|
+
*/
|
|
256
|
+
private generateMessageId;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Factory function to create WebSocketDataSource instances
|
|
260
|
+
*
|
|
261
|
+
* @param config - WebSocket data source configuration
|
|
262
|
+
* @param options - Additional configuration options
|
|
263
|
+
* @returns New WebSocketDataSource instance
|
|
264
|
+
*/
|
|
265
|
+
export declare function createWebSocketDataSource(config: WebSocketDataSourceConfig, options?: WebSocketDataSourceOptions): WebSocketDataSource;
|
|
266
|
+
/**
|
|
267
|
+
* Common WebSocket authentication helpers
|
|
268
|
+
*/
|
|
269
|
+
export declare const WS_AUTH_HELPERS: {
|
|
270
|
+
/**
|
|
271
|
+
* Bearer token authentication
|
|
272
|
+
*/
|
|
273
|
+
bearer: (token: string) => {
|
|
274
|
+
type: "bearer";
|
|
275
|
+
credentials: string;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Query parameter authentication
|
|
279
|
+
*/
|
|
280
|
+
query: (token: string, paramName?: string) => {
|
|
281
|
+
type: "query";
|
|
282
|
+
credentials: string;
|
|
283
|
+
paramName: string;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Header-based authentication
|
|
287
|
+
*/
|
|
288
|
+
header: (token: string, headerName?: string) => {
|
|
289
|
+
type: "header";
|
|
290
|
+
credentials: string;
|
|
291
|
+
paramName: string;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Common WebSocket message helpers
|
|
296
|
+
*/
|
|
297
|
+
export declare const WS_MESSAGE_HELPERS: {
|
|
298
|
+
/**
|
|
299
|
+
* Create a search request message
|
|
300
|
+
*/
|
|
301
|
+
searchRequest: (searchParams?: Record<string, unknown>, messageId?: string) => WebSocketMessage;
|
|
302
|
+
/**
|
|
303
|
+
* Create a heartbeat ping message
|
|
304
|
+
*/
|
|
305
|
+
heartbeatPing: (messageId?: string) => WebSocketMessage;
|
|
306
|
+
/**
|
|
307
|
+
* Create an options update message
|
|
308
|
+
*/
|
|
309
|
+
optionsUpdate: (options: ChoiceOption[], messageId?: string) => WebSocketMessage;
|
|
310
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choice Widget Data Source Providers
|
|
3
|
+
*
|
|
4
|
+
* This module provides data source providers for the Choice Widget,
|
|
5
|
+
* enabling flexible data sourcing from various backends including
|
|
6
|
+
* static data, APIs, and other external sources.
|
|
7
|
+
*/
|
|
8
|
+
export { DataSourceProvider, type RetryConfig, type DataSourceMetrics, type DataSourceEventCallbacks, DEFAULT_RETRY_CONFIG, createSimpleHash, validateChoiceOptions, } from './DataSourceProvider';
|
|
9
|
+
export { StaticDataSource, type StaticDataSourceOptions, createStaticDataSource, hasGroup, createGroupedOptions, } from './StaticDataSource';
|
|
10
|
+
export { ApiDataSource, createApiDataSource, COMMON_RESPONSE_MAPPERS, AUTH_HELPERS, } from './ApiDataSource';
|
|
11
|
+
export { WebSocketDataSource, createWebSocketDataSource, WebSocketConnectionState, type WebSocketDataSourceOptions, WS_AUTH_HELPERS, WS_MESSAGE_HELPERS, } from './WebSocketDataSource';
|
|
12
|
+
export type { ChoiceOption, LoadingState, ErrorState, CacheConfig, StaticDataSourceConfig, ApiDataSourceConfig, WebSocketDataSourceConfig, SearchConfig, DataSourceConfig, ChoiceDataProvider, ChoiceCache, ResponseMapper, ResponseMapperConfig, HttpMethod, WebSocketMessage, WebSocketMessageType, } from '../ChoiceWidget.types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './responseMappers';
|