ag-grid-url-sync 0.2.1 → 0.2.3
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 +7 -0
- package/README.md +138 -96
- package/dist/core/grid-integration.d.ts +5 -0
- package/dist/core/grid-integration.js +208 -23
- package/dist/core/grid-integration.js.map +1 -1
- package/dist/core/types.d.ts +204 -71
- package/dist/core/types.js +232 -52
- package/dist/core/types.js.map +1 -1
- package/dist/core/url-generator.js +96 -12
- package/dist/core/url-generator.js.map +1 -1
- package/dist/core/url-parser.js +223 -15
- package/dist/core/url-parser.js.map +1 -1
- package/dist/core/validation.d.ts +64 -2
- package/dist/core/validation.js +173 -2
- package/dist/core/validation.js.map +1 -1
- package/dist/react/types.d.ts +5 -0
- package/dist/react/use-ag-grid-url-sync.js +42 -27
- package/dist/react/use-ag-grid-url-sync.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,25 +1,99 @@
|
|
|
1
1
|
import { validateFilterValue } from './validation.js';
|
|
2
2
|
import { INTERNAL_TO_URL_OPERATION_MAP } from './types.js';
|
|
3
|
+
const FILTER_TYPES = {
|
|
4
|
+
TEXT: 'text',
|
|
5
|
+
NUMBER: 'number',
|
|
6
|
+
DATE: 'date'
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Serializes a single column filter to URL parameter
|
|
10
|
+
*/
|
|
11
|
+
function serializeColumnFilter(columnName, filter, paramPrefix) {
|
|
12
|
+
const urlOperation = INTERNAL_TO_URL_OPERATION_MAP[filter.type];
|
|
13
|
+
if (!urlOperation)
|
|
14
|
+
return '';
|
|
15
|
+
const paramName = `${paramPrefix}${columnName}_${urlOperation}`;
|
|
16
|
+
// Handle date range operations
|
|
17
|
+
if (filter.type === 'dateRange' && filter.filterType === FILTER_TYPES.DATE) {
|
|
18
|
+
// Type guard: ensure this is a DateColumnFilter with dateRange operation
|
|
19
|
+
if ('filterTo' in filter && filter.filterTo !== undefined) {
|
|
20
|
+
// Don't encode the comma for range values - handle this directly
|
|
21
|
+
return `${paramName}=${filter.filter},${filter.filterTo}`;
|
|
22
|
+
}
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
// Handle number range operations
|
|
26
|
+
if (filter.type === 'inRange' && filter.filterType === FILTER_TYPES.NUMBER) {
|
|
27
|
+
// Type guard: ensure this is a NumberColumnFilter with inRange operation
|
|
28
|
+
if ('filterTo' in filter && filter.filterTo !== undefined) {
|
|
29
|
+
// Don't encode the comma for range values - handle this directly
|
|
30
|
+
return `${paramName}=${filter.filter},${filter.filterTo}`;
|
|
31
|
+
}
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
// Handle blank operations (shared across text, number, and date)
|
|
35
|
+
if (filter.type === 'blank' || filter.type === 'notBlank') {
|
|
36
|
+
return `${paramName}=true`;
|
|
37
|
+
}
|
|
38
|
+
// Handle date operations (ISO date format preservation)
|
|
39
|
+
if (filter.filterType === FILTER_TYPES.DATE) {
|
|
40
|
+
return `${paramName}=${filter.filter}`; // ISO dates don't need URL encoding
|
|
41
|
+
}
|
|
42
|
+
// Handle number operations
|
|
43
|
+
if (filter.filterType === FILTER_TYPES.NUMBER) {
|
|
44
|
+
return `${paramName}=${filter.filter}`;
|
|
45
|
+
}
|
|
46
|
+
// Handle text operations (existing logic)
|
|
47
|
+
if (filter.filterType === FILTER_TYPES.TEXT && filter.filter) {
|
|
48
|
+
// Note: Validation should be done at the serializeFilters level, not here
|
|
49
|
+
return `${paramName}=${encodeURIComponent(filter.filter.toString())}`;
|
|
50
|
+
}
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Helper function to append a serialized parameter to URLSearchParams
|
|
55
|
+
*/
|
|
56
|
+
function appendSerializedParam(serialized, params, isRangeOperation = false) {
|
|
57
|
+
const [paramName, paramValue] = serialized.split('=');
|
|
58
|
+
if (paramName && paramValue) {
|
|
59
|
+
if (isRangeOperation) {
|
|
60
|
+
// For range operations (which contain commas), don't decode
|
|
61
|
+
params.append(paramName, paramValue);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// For regular operations, decode special characters for text filters
|
|
65
|
+
params.append(paramName, decodeURIComponent(paramValue));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
3
69
|
/**
|
|
4
70
|
* Converts a filter state object into URL search parameters
|
|
5
71
|
*/
|
|
6
72
|
export function serializeFilters(filterState, config) {
|
|
7
73
|
const params = new URLSearchParams();
|
|
8
74
|
for (const [column, filter] of Object.entries(filterState)) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
75
|
+
// Support text, number, and date filters
|
|
76
|
+
if (filter.filterType !== FILTER_TYPES.TEXT &&
|
|
77
|
+
filter.filterType !== FILTER_TYPES.NUMBER &&
|
|
78
|
+
filter.filterType !== FILTER_TYPES.DATE)
|
|
13
79
|
continue;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
80
|
+
// Apply validation for text filters before serialization
|
|
81
|
+
if (filter.filterType === FILTER_TYPES.TEXT) {
|
|
82
|
+
const validatedValue = validateFilterValue(filter.filter, config, filter.type);
|
|
83
|
+
const updatedFilter = { ...filter, filter: validatedValue };
|
|
84
|
+
const serialized = serializeColumnFilter(column, updatedFilter, config.paramPrefix);
|
|
85
|
+
if (serialized) {
|
|
86
|
+
appendSerializedParam(serialized, params, false); // Text filters are not range operations
|
|
87
|
+
}
|
|
18
88
|
}
|
|
19
89
|
else {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
90
|
+
// Number and date filters don't need additional validation as they're already validated
|
|
91
|
+
const serialized = serializeColumnFilter(column, filter, config.paramPrefix);
|
|
92
|
+
if (serialized) {
|
|
93
|
+
// Check if this is a range operation
|
|
94
|
+
const isRangeOp = filter.type === 'inRange' || filter.type === 'dateRange';
|
|
95
|
+
appendSerializedParam(serialized, params, isRangeOp);
|
|
96
|
+
}
|
|
23
97
|
}
|
|
24
98
|
}
|
|
25
99
|
return params;
|
|
@@ -36,7 +110,17 @@ export function generateUrl(baseUrl, filterState, config) {
|
|
|
36
110
|
filterParams.append(key, value);
|
|
37
111
|
}
|
|
38
112
|
}
|
|
39
|
-
|
|
113
|
+
const queryString = filterParams.toString();
|
|
114
|
+
// If no filters, return the base URL without query string or trailing slash
|
|
115
|
+
if (!queryString) {
|
|
116
|
+
let result = url.toString().replace(/\?$/, '');
|
|
117
|
+
// Remove trailing slash for root paths when no query parameters
|
|
118
|
+
if (result.endsWith('/') && result === url.origin + '/') {
|
|
119
|
+
result = result.slice(0, -1);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
url.search = queryString;
|
|
40
124
|
return url.toString();
|
|
41
125
|
}
|
|
42
126
|
//# sourceMappingURL=url-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-generator.js","sourceRoot":"","sources":["../../src/core/url-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAA;AAE1D;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"url-generator.js","sourceRoot":"","sources":["../../src/core/url-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAA;AAE1D,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAA;AAEV;;GAEG;AACH,SAAS,qBAAqB,CAC5B,UAAkB,EAClB,MAAoB,EACpB,WAAmB;IAEnB,MAAM,YAAY,GAChB,6BAA6B,CAC3B,MAAM,CAAC,IAAkD,CAC1D,CAAA;IACH,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAA;IAE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AC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACjC,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAA;IAE3C,4EAA4E;IAC5E,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,IAAI,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC9C,gEAAgE;QAChE,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACxD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC9B,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED,GAAG,CAAC,MAAM,GAAG,WAAW,CAAA;IACxB,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;AACvB,CAAC"}
|
package/dist/core/url-parser.js
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
import { InvalidFilterError, InvalidURLError, OPERATION_MAP } from './types.js';
|
|
2
|
-
import { validateFilterValue, DEFAULT_CONFIG } from './validation.js';
|
|
2
|
+
import { validateFilterValue, validateAndParseNumber, validateNumberRange, validateNumberFilter, validateAndParseDate, validateAndParseDateRange, validateDateFilter, DEFAULT_CONFIG } from './validation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Detects if an operation is number-specific
|
|
5
|
+
*/
|
|
6
|
+
function isNumberOperation(operation) {
|
|
7
|
+
return [
|
|
8
|
+
'lessThan',
|
|
9
|
+
'lessThanOrEqual',
|
|
10
|
+
'greaterThan',
|
|
11
|
+
'greaterThanOrEqual',
|
|
12
|
+
'inRange'
|
|
13
|
+
].includes(operation);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Detects if an operation is date-specific
|
|
17
|
+
*/
|
|
18
|
+
function isDateOperation(operation) {
|
|
19
|
+
return [
|
|
20
|
+
'dateBefore',
|
|
21
|
+
'dateBeforeOrEqual',
|
|
22
|
+
'dateAfter',
|
|
23
|
+
'dateAfterOrEqual',
|
|
24
|
+
'dateRange'
|
|
25
|
+
].includes(operation);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Detects if an operation works across multiple filter types (shared operations)
|
|
29
|
+
*/
|
|
30
|
+
function isSharedOperation(operation) {
|
|
31
|
+
return ['eq', 'notEqual', 'blank', 'notBlank'].includes(operation);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Attempts to parse a value as a date and returns the filter type
|
|
35
|
+
* This is used for shared operations to determine if they should be treated as date filters
|
|
36
|
+
*/
|
|
37
|
+
function tryParseAsDate(value) {
|
|
38
|
+
try {
|
|
39
|
+
validateAndParseDate(value);
|
|
40
|
+
return 'date';
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Detects the most appropriate filter type for a shared operation based on the value
|
|
48
|
+
* Priority: Date > Number > Text (if the value can be parsed as date/number, prefer that type)
|
|
49
|
+
*/
|
|
50
|
+
function detectFilterTypeForSharedOperation(operation, value) {
|
|
51
|
+
// Blank operations default to text (most common case)
|
|
52
|
+
if (operation === 'blank' || operation === 'notBlank') {
|
|
53
|
+
return 'text';
|
|
54
|
+
}
|
|
55
|
+
// For eq/notEqual operations, try to detect the most specific type
|
|
56
|
+
if (operation === 'eq' || operation === 'notEqual') {
|
|
57
|
+
// Try date first (most specific format)
|
|
58
|
+
if (tryParseAsDate(value) === 'date') {
|
|
59
|
+
return 'date';
|
|
60
|
+
}
|
|
61
|
+
// Try number second
|
|
62
|
+
try {
|
|
63
|
+
const numValue = parseFloat(value);
|
|
64
|
+
if (!isNaN(numValue) && Number.isFinite(numValue)) {
|
|
65
|
+
const validation = validateNumberFilter(numValue);
|
|
66
|
+
if (validation.valid) {
|
|
67
|
+
return 'number';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Fall through to text
|
|
73
|
+
}
|
|
74
|
+
// Default to text
|
|
75
|
+
return 'text';
|
|
76
|
+
}
|
|
77
|
+
return 'text';
|
|
78
|
+
}
|
|
3
79
|
/**
|
|
4
80
|
* Extracts column name and operation from a filter parameter
|
|
5
81
|
*/
|
|
@@ -34,14 +110,109 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
34
110
|
if (!filterOp) {
|
|
35
111
|
throw new InvalidFilterError(`Unsupported filter operation: ${operation}`);
|
|
36
112
|
}
|
|
37
|
-
//
|
|
38
|
-
if (filterOp === '
|
|
113
|
+
// Handle date range operations
|
|
114
|
+
if (filterOp === 'dateRange') {
|
|
115
|
+
try {
|
|
116
|
+
const [startDate, endDate] = validateAndParseDateRange(value);
|
|
117
|
+
return {
|
|
118
|
+
filterType: 'date',
|
|
119
|
+
type: filterOp,
|
|
120
|
+
filter: startDate,
|
|
121
|
+
filterTo: endDate
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw new InvalidFilterError(error instanceof Error ? error.message : 'Invalid date range');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Handle number range operations
|
|
129
|
+
if (filterOp === 'inRange') {
|
|
130
|
+
const rangeParts = value.split(',');
|
|
131
|
+
if (rangeParts.length !== 2) {
|
|
132
|
+
throw new InvalidFilterError('Range operation requires exactly two values separated by comma');
|
|
133
|
+
}
|
|
134
|
+
const min = validateAndParseNumber(rangeParts[0] || '');
|
|
135
|
+
const max = validateAndParseNumber(rangeParts[1] || '');
|
|
136
|
+
const rangeValidation = validateNumberRange(min, max);
|
|
137
|
+
if (!rangeValidation.valid) {
|
|
138
|
+
throw new InvalidFilterError(rangeValidation.error || 'Invalid range values');
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
filterType: 'number',
|
|
142
|
+
type: filterOp,
|
|
143
|
+
filter: min,
|
|
144
|
+
filterTo: max
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// Handle date-specific operations
|
|
148
|
+
if (isDateOperation(filterOp)) {
|
|
149
|
+
try {
|
|
150
|
+
const dateValue = validateAndParseDate(value);
|
|
151
|
+
const validation = validateDateFilter(dateValue, filterOp);
|
|
152
|
+
if (!validation.valid) {
|
|
153
|
+
throw new InvalidFilterError(validation.error || 'Invalid date filter');
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
filterType: 'date',
|
|
157
|
+
type: filterOp,
|
|
158
|
+
filter: dateValue
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw new InvalidFilterError(error instanceof Error ? error.message : 'Invalid date filter');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Handle number-specific operations
|
|
166
|
+
if (isNumberOperation(filterOp)) {
|
|
167
|
+
const numValue = validateAndParseNumber(value);
|
|
168
|
+
return {
|
|
169
|
+
filterType: 'number',
|
|
170
|
+
type: filterOp,
|
|
171
|
+
filter: numValue
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// Handle shared operations (eq, notEqual, blank, notBlank)
|
|
175
|
+
if (isSharedOperation(filterOp)) {
|
|
176
|
+
const detectedType = detectFilterTypeForSharedOperation(filterOp, value);
|
|
177
|
+
if (detectedType === 'date') {
|
|
178
|
+
try {
|
|
179
|
+
const dateValue = validateAndParseDate(value);
|
|
180
|
+
return {
|
|
181
|
+
filterType: 'date',
|
|
182
|
+
type: filterOp,
|
|
183
|
+
filter: dateValue
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// If date parsing fails, fall back to text
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (detectedType === 'number') {
|
|
191
|
+
try {
|
|
192
|
+
const numValue = parseFloat(value);
|
|
193
|
+
if (!isNaN(numValue) && Number.isFinite(numValue)) {
|
|
194
|
+
const validation = validateNumberFilter(numValue);
|
|
195
|
+
if (validation.valid) {
|
|
196
|
+
return {
|
|
197
|
+
filterType: 'number',
|
|
198
|
+
type: filterOp,
|
|
199
|
+
filter: numValue
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// Fall through to text handling
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Handle as text filter (default for shared operations)
|
|
39
209
|
return {
|
|
40
210
|
filterType: 'text',
|
|
41
211
|
type: filterOp,
|
|
42
|
-
filter: ''
|
|
212
|
+
filter: filterOp === 'blank' || filterOp === 'notBlank' ? '' : value || ''
|
|
43
213
|
};
|
|
44
214
|
}
|
|
215
|
+
// Handle text-specific operations (existing logic)
|
|
45
216
|
return {
|
|
46
217
|
filterType: 'text',
|
|
47
218
|
type: filterOp,
|
|
@@ -53,7 +224,32 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
53
224
|
*/
|
|
54
225
|
export function parseUrlFilters(url, config) {
|
|
55
226
|
try {
|
|
56
|
-
|
|
227
|
+
// Handle empty or whitespace-only URLs gracefully
|
|
228
|
+
if (!url || url.trim() === '') {
|
|
229
|
+
return {};
|
|
230
|
+
}
|
|
231
|
+
// Check for obviously malformed URLs that should throw errors
|
|
232
|
+
if (url === 'not-a-url' ||
|
|
233
|
+
url.startsWith('://') ||
|
|
234
|
+
(!url.includes('://') &&
|
|
235
|
+
!url.startsWith('/') &&
|
|
236
|
+
!url.startsWith('?') &&
|
|
237
|
+
url.includes('.'))) {
|
|
238
|
+
throw new Error('Invalid URL format');
|
|
239
|
+
}
|
|
240
|
+
// If URL starts with '?' treat as query string only
|
|
241
|
+
let urlToProcess = url;
|
|
242
|
+
if (url.startsWith('?')) {
|
|
243
|
+
urlToProcess = `http://example.com${url}`;
|
|
244
|
+
}
|
|
245
|
+
else if (!url.includes('://') && !url.startsWith('/')) {
|
|
246
|
+
// For other cases without protocol, try to handle as query string
|
|
247
|
+
urlToProcess = `http://example.com?${url}`;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
urlToProcess = url;
|
|
251
|
+
}
|
|
252
|
+
const urlObj = new URL(urlToProcess);
|
|
57
253
|
const filterState = {};
|
|
58
254
|
for (const [param, value] of urlObj.searchParams.entries()) {
|
|
59
255
|
if (!param.startsWith(config.paramPrefix))
|
|
@@ -62,24 +258,36 @@ export function parseUrlFilters(url, config) {
|
|
|
62
258
|
// Extract column name and parse the filter parameter
|
|
63
259
|
const { column: columnName } = extractColumnAndOperation(param, config.paramPrefix);
|
|
64
260
|
const filterParam = parseFilterParam(param, value, config.paramPrefix);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
261
|
+
// Apply validation based on filter type
|
|
262
|
+
if (filterParam.filterType === 'text') {
|
|
263
|
+
const validatedValue = validateFilterValue(value, config, filterParam.type);
|
|
264
|
+
filterState[columnName] = {
|
|
265
|
+
...filterParam,
|
|
266
|
+
filter: validatedValue
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
else if (filterParam.filterType === 'date') {
|
|
270
|
+
// Date filters are already validated in parseFilterParam
|
|
271
|
+
filterState[columnName] = filterParam;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
// Number filters are already validated in parseFilterParam
|
|
275
|
+
filterState[columnName] = filterParam;
|
|
276
|
+
}
|
|
70
277
|
}
|
|
71
|
-
catch (
|
|
278
|
+
catch (error) {
|
|
279
|
+
// Log parsing errors through the configured error handler
|
|
72
280
|
if (config.onParseError) {
|
|
73
|
-
config.onParseError(
|
|
281
|
+
config.onParseError(error);
|
|
74
282
|
}
|
|
75
|
-
//
|
|
283
|
+
// Continue processing other parameters instead of failing completely
|
|
76
284
|
continue;
|
|
77
285
|
}
|
|
78
286
|
}
|
|
79
287
|
return filterState;
|
|
80
288
|
}
|
|
81
|
-
catch (
|
|
82
|
-
throw new InvalidURLError(`Failed to parse URL: ${
|
|
289
|
+
catch (error) {
|
|
290
|
+
throw new InvalidURLError(`Failed to parse URL: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
83
291
|
}
|
|
84
292
|
}
|
|
85
293
|
//# sourceMappingURL=url-parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-parser.js","sourceRoot":"","sources":["../../src/core/url-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/E,OAAO,
|
|
1
|
+
{"version":3,"file":"url-parser.js","sourceRoot":"","sources":["../../src/core/url-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/E,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,EACzB,kBAAkB,EAClB,cAAc,EACf,MAAM,iBAAiB,CAAA;AAExB;;GAEG;AACH,SAAS,iBAAiB,CAAC,SAAiB;IAC1C,OAAO;QACL,UAAU;QACV,iBAAiB;QACjB,aAAa;QACb,oBAAoB;QACpB,SAAS;KACV,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;AACvB,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,SAAiB;IACxC,OAAO;QACL,YAAY;QACZ,mBAAmB;QACnB,WAAW;QACX,kBAAkB;QAClB,WAAW;KACZ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;AACvB,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB,CAAC,SAAiB;IAC1C,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;AACpE,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,KAAa;IACnC,IAAI,CAAC;Q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E,MAAM,CAAC,WAAW,CAAC,CAAA;gBAEtE,wCAAwC;gBACxC,IAAI,WAAW,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;oBACtC,MAAM,cAAc,GAAG,mBAAmB,CACxC,KAAK,EACL,MAAM,EACN,WAAW,CAAC,IAAI,CACjB,CAAA;oBACD,WAAW,CAAC,UAAU,CAAC,GAAG;wBACxB,GAAG,WAAW;wBACd,MAAM,EAAE,cAAc;qBACvB,CAAA;gBACH,CAAC;qBAAM,IAAI,WAAW,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;oBAC7C,yDAAyD;oBACzD,WAAW,CAAC,UAAU,CAAC,GAAG,WAAW,CAAA;gBACvC,CAAC;qBAAM,CAAC;oBACN,2DAA2D;oBAC3D,WAAW,CAAC,UAAU,CAAC,GAAG,WAAW,CAAA;gBACvC,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,0DAA0D;gBAC1D,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;oBACxB,MAAM,CAAC,YAAY,CAAC,KAAc,CAAC,CAAA;gBACrC,CAAC;gBACD,qEAAqE;gBACrE,SAAQ;YACV,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAA;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,eAAe,CACvB,wBAAwB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CACnF,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InternalConfig, FilterOperation } from './types.js';
|
|
1
|
+
import type { InternalConfig, FilterOperation, DateFilterOperation } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Default configuration values
|
|
4
4
|
*/
|
|
@@ -7,7 +7,16 @@ export declare const DEFAULT_CONFIG: {
|
|
|
7
7
|
readonly maxValueLength: 200;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Validation result interface
|
|
11
|
+
*/
|
|
12
|
+
export type ValidationResult = {
|
|
13
|
+
valid: true;
|
|
14
|
+
} | {
|
|
15
|
+
valid: false;
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Validates a text filter value against configuration constraints
|
|
11
20
|
*
|
|
12
21
|
* @param value - The filter value to validate
|
|
13
22
|
* @param config - Internal configuration with validation rules
|
|
@@ -16,3 +25,56 @@ export declare const DEFAULT_CONFIG: {
|
|
|
16
25
|
* @throws InvalidFilterError if value exceeds maximum length
|
|
17
26
|
*/
|
|
18
27
|
export declare function validateFilterValue(value: string, config: InternalConfig, operation?: FilterOperation): string;
|
|
28
|
+
/**
|
|
29
|
+
* Validates a number filter value
|
|
30
|
+
*
|
|
31
|
+
* @param value - The number value to validate
|
|
32
|
+
* @returns Validation result
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateNumberFilter(value: number): ValidationResult;
|
|
35
|
+
/**
|
|
36
|
+
* Validates a number range filter
|
|
37
|
+
*
|
|
38
|
+
* @param min - The minimum value
|
|
39
|
+
* @param max - The maximum value
|
|
40
|
+
* @returns Validation result
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateNumberRange(min: number, max: number): ValidationResult;
|
|
43
|
+
/**
|
|
44
|
+
* Validates a parsed number from string input
|
|
45
|
+
*
|
|
46
|
+
* @param value - String representation of number
|
|
47
|
+
* @returns Parsed number or throws InvalidFilterError
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateAndParseNumber(value: string): number;
|
|
50
|
+
/**
|
|
51
|
+
* Validates and parses a date string in ISO format (YYYY-MM-DD)
|
|
52
|
+
*
|
|
53
|
+
* @param value - String representation of date in ISO format
|
|
54
|
+
* @returns Validated ISO date string
|
|
55
|
+
* @throws InvalidDateError if date format is invalid or date doesn't exist
|
|
56
|
+
*/
|
|
57
|
+
export declare function validateAndParseDate(value: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Validates a date filter value
|
|
60
|
+
*
|
|
61
|
+
* @param value - The date value to validate
|
|
62
|
+
* @param operation - The date filter operation
|
|
63
|
+
* @returns Validation result
|
|
64
|
+
*/
|
|
65
|
+
export declare function validateDateFilter(value: string, operation: DateFilterOperation): ValidationResult;
|
|
66
|
+
/**
|
|
67
|
+
* Validates a date range filter
|
|
68
|
+
*
|
|
69
|
+
* @param startDate - The start date (ISO format)
|
|
70
|
+
* @param endDate - The end date (ISO format)
|
|
71
|
+
* @returns Validation result
|
|
72
|
+
*/
|
|
73
|
+
export declare function validateDateRange(startDate: string, endDate: string): ValidationResult;
|
|
74
|
+
/**
|
|
75
|
+
* Validates a date range from comma-separated string input
|
|
76
|
+
*
|
|
77
|
+
* @param rangeValue - Comma-separated date range (e.g., "2024-01-01,2024-12-31")
|
|
78
|
+
* @returns Tuple of [startDate, endDate] or throws InvalidDateError
|
|
79
|
+
*/
|
|
80
|
+
export declare function validateAndParseDateRange(rangeValue: string): [string, string];
|