ag-grid-url-sync 0.2.4 → 0.4.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 +395 -23
- package/dist/core/ag-grid-url-sync.d.ts +16 -1
- package/dist/core/ag-grid-url-sync.js +19 -41
- package/dist/core/ag-grid-url-sync.js.map +1 -1
- package/dist/core/grid-integration.js +5 -67
- package/dist/core/grid-integration.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/serialization/formats.d.ts +29 -0
- package/dist/core/serialization/formats.js +68 -0
- package/dist/core/serialization/formats.js.map +1 -0
- package/dist/core/serialization/grouped.d.ts +36 -0
- package/dist/core/serialization/grouped.js +105 -0
- package/dist/core/serialization/grouped.js.map +1 -0
- package/dist/core/serialization/index.d.ts +7 -0
- package/dist/core/serialization/index.js +3 -0
- package/dist/core/serialization/index.js.map +1 -0
- package/dist/core/types.d.ts +75 -5
- package/dist/core/types.js +7 -115
- package/dist/core/types.js.map +1 -1
- package/dist/core/url-generator.js +44 -38
- package/dist/core/url-generator.js.map +1 -1
- package/dist/core/url-parser.js +8 -52
- package/dist/core/url-parser.js.map +1 -1
- package/dist/core/validation.d.ts +13 -2
- package/dist/core/validation.js +34 -72
- package/dist/core/validation.js.map +1 -1
- package/dist/core/view-storage.d.ts +63 -0
- package/dist/core/view-storage.js +112 -0
- package/dist/core/view-storage.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/types.d.ts +108 -1
- package/dist/react/use-ag-grid-url-sync.js +440 -42
- package/dist/react/use-ag-grid-url-sync.js.map +1 -1
- package/package.json +101 -30
package/dist/core/url-parser.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { InvalidFilterError, InvalidURLError, OPERATION_MAP } from './types.js';
|
|
2
2
|
import { validateFilterValue, validateAndParseNumber, validateNumberRange, validateNumberFilter, validateAndParseDate, validateAndParseDateRange, validateDateFilter, DEFAULT_CONFIG } from './validation.js';
|
|
3
|
-
|
|
4
|
-
* Detects if an operation is number-specific
|
|
5
|
-
*/
|
|
3
|
+
import { detectGroupedSerialization, deserializeGrouped } from './serialization/grouped.js';
|
|
6
4
|
function isNumberOperation(operation) {
|
|
7
5
|
return [
|
|
8
6
|
'lessThan',
|
|
@@ -12,9 +10,6 @@ function isNumberOperation(operation) {
|
|
|
12
10
|
'inRange'
|
|
13
11
|
].includes(operation);
|
|
14
12
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Detects if an operation is date-specific
|
|
17
|
-
*/
|
|
18
13
|
function isDateOperation(operation) {
|
|
19
14
|
return [
|
|
20
15
|
'dateBefore',
|
|
@@ -24,16 +19,9 @@ function isDateOperation(operation) {
|
|
|
24
19
|
'dateRange'
|
|
25
20
|
].includes(operation);
|
|
26
21
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Detects if an operation works across multiple filter types (shared operations)
|
|
29
|
-
*/
|
|
30
22
|
function isSharedOperation(operation) {
|
|
31
23
|
return ['eq', 'notEqual', 'blank', 'notBlank'].includes(operation);
|
|
32
24
|
}
|
|
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
25
|
function tryParseAsDate(value) {
|
|
38
26
|
try {
|
|
39
27
|
validateAndParseDate(value);
|
|
@@ -43,22 +31,14 @@ function tryParseAsDate(value) {
|
|
|
43
31
|
return null;
|
|
44
32
|
}
|
|
45
33
|
}
|
|
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
34
|
function detectFilterTypeForSharedOperation(operation, value) {
|
|
51
|
-
// Blank operations default to text (most common case)
|
|
52
35
|
if (operation === 'blank' || operation === 'notBlank') {
|
|
53
36
|
return 'text';
|
|
54
37
|
}
|
|
55
|
-
// For eq/notEqual operations, try to detect the most specific type
|
|
56
38
|
if (operation === 'eq' || operation === 'notEqual') {
|
|
57
|
-
// Try date first (most specific format)
|
|
58
39
|
if (tryParseAsDate(value) === 'date') {
|
|
59
40
|
return 'date';
|
|
60
41
|
}
|
|
61
|
-
// Try number second
|
|
62
42
|
try {
|
|
63
43
|
const numValue = parseFloat(value);
|
|
64
44
|
if (!isNaN(numValue) && Number.isFinite(numValue)) {
|
|
@@ -69,16 +49,11 @@ function detectFilterTypeForSharedOperation(operation, value) {
|
|
|
69
49
|
}
|
|
70
50
|
}
|
|
71
51
|
catch {
|
|
72
|
-
// Fall through to text
|
|
73
52
|
}
|
|
74
|
-
// Default to text
|
|
75
53
|
return 'text';
|
|
76
54
|
}
|
|
77
55
|
return 'text';
|
|
78
56
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Extracts column name and operation from a filter parameter
|
|
81
|
-
*/
|
|
82
57
|
function extractColumnAndOperation(param, expectedPrefix) {
|
|
83
58
|
const ensureTrailingUnderscore = (prefix) => prefix.endsWith('_') ? prefix : prefix + '_';
|
|
84
59
|
const sanitizedPrefix = expectedPrefix
|
|
@@ -88,7 +63,6 @@ function extractColumnAndOperation(param, expectedPrefix) {
|
|
|
88
63
|
if (!param.startsWith(prefixToCheck + '_')) {
|
|
89
64
|
throw new InvalidFilterError(`Invalid filter prefix in parameter: ${param}`);
|
|
90
65
|
}
|
|
91
|
-
// Remove prefix and find the last underscore to separate column from operation
|
|
92
66
|
const withoutPrefix = param.substring(prefixToCheck.length + 1);
|
|
93
67
|
const lastUnderscoreIndex = withoutPrefix.lastIndexOf('_');
|
|
94
68
|
if (lastUnderscoreIndex === -1) {
|
|
@@ -101,16 +75,12 @@ function extractColumnAndOperation(param, expectedPrefix) {
|
|
|
101
75
|
}
|
|
102
76
|
return { column, operation };
|
|
103
77
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Parses a URL parameter into a column filter
|
|
106
|
-
*/
|
|
107
78
|
export function parseFilterParam(param, value, expectedPrefix) {
|
|
108
79
|
const { operation } = extractColumnAndOperation(param, expectedPrefix);
|
|
109
80
|
const filterOp = OPERATION_MAP[operation];
|
|
110
81
|
if (!filterOp) {
|
|
111
82
|
throw new InvalidFilterError(`Unsupported filter operation: ${operation}`);
|
|
112
83
|
}
|
|
113
|
-
// Handle date range operations
|
|
114
84
|
if (filterOp === 'dateRange') {
|
|
115
85
|
try {
|
|
116
86
|
const [startDate, endDate] = validateAndParseDateRange(value);
|
|
@@ -125,7 +95,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
125
95
|
throw new InvalidFilterError(error instanceof Error ? error.message : 'Invalid date range');
|
|
126
96
|
}
|
|
127
97
|
}
|
|
128
|
-
// Handle number range operations
|
|
129
98
|
if (filterOp === 'inRange') {
|
|
130
99
|
const rangeParts = value.split(',');
|
|
131
100
|
if (rangeParts.length !== 2) {
|
|
@@ -144,7 +113,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
144
113
|
filterTo: max
|
|
145
114
|
};
|
|
146
115
|
}
|
|
147
|
-
// Handle date-specific operations
|
|
148
116
|
if (isDateOperation(filterOp)) {
|
|
149
117
|
try {
|
|
150
118
|
const dateValue = validateAndParseDate(value);
|
|
@@ -162,7 +130,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
162
130
|
throw new InvalidFilterError(error instanceof Error ? error.message : 'Invalid date filter');
|
|
163
131
|
}
|
|
164
132
|
}
|
|
165
|
-
// Handle number-specific operations
|
|
166
133
|
if (isNumberOperation(filterOp)) {
|
|
167
134
|
const numValue = validateAndParseNumber(value);
|
|
168
135
|
return {
|
|
@@ -171,7 +138,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
171
138
|
filter: numValue
|
|
172
139
|
};
|
|
173
140
|
}
|
|
174
|
-
// Handle shared operations (eq, notEqual, blank, notBlank)
|
|
175
141
|
if (isSharedOperation(filterOp)) {
|
|
176
142
|
const detectedType = detectFilterTypeForSharedOperation(filterOp, value);
|
|
177
143
|
if (detectedType === 'date') {
|
|
@@ -184,7 +150,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
184
150
|
};
|
|
185
151
|
}
|
|
186
152
|
catch {
|
|
187
|
-
// If date parsing fails, fall back to text
|
|
188
153
|
}
|
|
189
154
|
}
|
|
190
155
|
if (detectedType === 'number') {
|
|
@@ -202,33 +167,25 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
202
167
|
}
|
|
203
168
|
}
|
|
204
169
|
catch {
|
|
205
|
-
// Fall through to text handling
|
|
206
170
|
}
|
|
207
171
|
}
|
|
208
|
-
// Handle as text filter (default for shared operations)
|
|
209
172
|
return {
|
|
210
173
|
filterType: 'text',
|
|
211
174
|
type: filterOp,
|
|
212
175
|
filter: filterOp === 'blank' || filterOp === 'notBlank' ? '' : value || ''
|
|
213
176
|
};
|
|
214
177
|
}
|
|
215
|
-
// Handle text-specific operations (existing logic)
|
|
216
178
|
return {
|
|
217
179
|
filterType: 'text',
|
|
218
180
|
type: filterOp,
|
|
219
181
|
filter: value || ''
|
|
220
182
|
};
|
|
221
183
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Converts URL search params into a filter state object
|
|
224
|
-
*/
|
|
225
184
|
export function parseUrlFilters(url, config) {
|
|
226
185
|
try {
|
|
227
|
-
// Handle empty or whitespace-only URLs gracefully
|
|
228
186
|
if (!url || url.trim() === '') {
|
|
229
187
|
return {};
|
|
230
188
|
}
|
|
231
|
-
// Check for obviously malformed URLs that should throw errors
|
|
232
189
|
if (url === 'not-a-url' ||
|
|
233
190
|
url.startsWith('://') ||
|
|
234
191
|
(!url.includes('://') &&
|
|
@@ -237,28 +194,31 @@ export function parseUrlFilters(url, config) {
|
|
|
237
194
|
url.includes('.'))) {
|
|
238
195
|
throw new Error('Invalid URL format');
|
|
239
196
|
}
|
|
240
|
-
// If URL starts with '?' treat as query string only
|
|
241
197
|
let urlToProcess = url;
|
|
242
198
|
if (url.startsWith('?')) {
|
|
243
199
|
urlToProcess = `http://example.com${url}`;
|
|
244
200
|
}
|
|
245
201
|
else if (!url.includes('://') && !url.startsWith('/')) {
|
|
246
|
-
// For other cases without protocol, try to handle as query string
|
|
247
202
|
urlToProcess = `http://example.com?${url}`;
|
|
248
203
|
}
|
|
249
204
|
else {
|
|
250
205
|
urlToProcess = url;
|
|
251
206
|
}
|
|
207
|
+
const DEFAULT_GROUPED_PARAMS = ['grid_filters', 'filters'];
|
|
208
|
+
const groupedDetection = detectGroupedSerialization(urlToProcess, [config.groupedParam, ...DEFAULT_GROUPED_PARAMS]);
|
|
209
|
+
if (groupedDetection.isGrouped &&
|
|
210
|
+
groupedDetection.value &&
|
|
211
|
+
groupedDetection.format) {
|
|
212
|
+
return deserializeGrouped(groupedDetection.value, groupedDetection.format, config);
|
|
213
|
+
}
|
|
252
214
|
const urlObj = new URL(urlToProcess);
|
|
253
215
|
const filterState = {};
|
|
254
216
|
for (const [param, value] of urlObj.searchParams.entries()) {
|
|
255
217
|
if (!param.startsWith(config.paramPrefix))
|
|
256
218
|
continue;
|
|
257
219
|
try {
|
|
258
|
-
// Extract column name and parse the filter parameter
|
|
259
220
|
const { column: columnName } = extractColumnAndOperation(param, config.paramPrefix);
|
|
260
221
|
const filterParam = parseFilterParam(param, value, config.paramPrefix);
|
|
261
|
-
// Apply validation based on filter type
|
|
262
222
|
if (filterParam.filterType === 'text') {
|
|
263
223
|
const validatedValue = validateFilterValue(value, config, filterParam.type);
|
|
264
224
|
filterState[columnName] = {
|
|
@@ -267,20 +227,16 @@ export function parseUrlFilters(url, config) {
|
|
|
267
227
|
};
|
|
268
228
|
}
|
|
269
229
|
else if (filterParam.filterType === 'date') {
|
|
270
|
-
// Date filters are already validated in parseFilterParam
|
|
271
230
|
filterState[columnName] = filterParam;
|
|
272
231
|
}
|
|
273
232
|
else {
|
|
274
|
-
// Number filters are already validated in parseFilterParam
|
|
275
233
|
filterState[columnName] = filterParam;
|
|
276
234
|
}
|
|
277
235
|
}
|
|
278
236
|
catch (error) {
|
|
279
|
-
// Log parsing errors through the configured error handler
|
|
280
237
|
if (config.onParseError) {
|
|
281
238
|
config.onParseError(error);
|
|
282
239
|
}
|
|
283
|
-
// Continue processing other parameters instead of failing completely
|
|
284
240
|
continue;
|
|
285
241
|
}
|
|
286
242
|
}
|
|
@@ -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,EACL,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,EACzB,kBAAkB,EAClB,cAAc,EACf,MAAM,iBAAiB,CAAA;
|
|
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;AACxB,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EACnB,MAAM,4BAA4B,CAAA;AAKnC,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;AAKD,SAAS,eAAe,CAAC,SAAiB;IACxC,OAAO;QACL,YAAY;QACZ,mBAAmB;QACnB,WAAW;QACX,kBAAkB;QAClB,WAA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Config, FilterOperation, DateFilterOperation } from './types.js';
|
|
1
|
+
import type { InternalConfig, FilterOperation, DateFilterOperation, ColumnFilter } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Default configuration values
|
|
4
4
|
*/
|
|
5
5
|
export declare const DEFAULT_CONFIG: {
|
|
6
|
-
readonly paramPrefix:
|
|
6
|
+
readonly paramPrefix: 'f_';
|
|
7
7
|
readonly maxValueLength: 200;
|
|
8
|
+
readonly serialization: 'individual';
|
|
9
|
+
readonly groupedParam: 'grid_filters';
|
|
10
|
+
readonly format: 'querystring';
|
|
11
|
+
readonly onParseError: () => void;
|
|
8
12
|
};
|
|
9
13
|
/**
|
|
10
14
|
* Validation result interface
|
|
@@ -78,3 +82,10 @@ export declare function validateDateRange(startDate: string, endDate: string): V
|
|
|
78
82
|
* @returns Tuple of [startDate, endDate] or throws InvalidDateError
|
|
79
83
|
*/
|
|
80
84
|
export declare function validateAndParseDateRange(rangeValue: string): [string, string];
|
|
85
|
+
/**
|
|
86
|
+
* Validates if an object is a valid column filter
|
|
87
|
+
*
|
|
88
|
+
* @param obj - The object to validate
|
|
89
|
+
* @returns Type guard that narrows the type to ColumnFilter
|
|
90
|
+
*/
|
|
91
|
+
export declare function isValidColumnFilter(obj: unknown): obj is ColumnFilter;
|
package/dist/core/validation.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
import { InvalidFilterError, InvalidDateError } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Default configuration values
|
|
4
|
-
*/
|
|
1
|
+
import { InvalidFilterError, InvalidDateError, TEXT_FILTER_OPERATIONS, NUMBER_FILTER_OPERATIONS, DATE_FILTER_OPERATIONS } from './types.js';
|
|
5
2
|
export const DEFAULT_CONFIG = {
|
|
6
3
|
paramPrefix: 'f_',
|
|
7
|
-
maxValueLength: 200
|
|
4
|
+
maxValueLength: 200,
|
|
5
|
+
serialization: 'individual',
|
|
6
|
+
groupedParam: 'grid_filters',
|
|
7
|
+
format: 'querystring',
|
|
8
|
+
onParseError: () => { }
|
|
8
9
|
};
|
|
9
|
-
/**
|
|
10
|
-
* Validates a text filter value against configuration constraints
|
|
11
|
-
*
|
|
12
|
-
* @param value - The filter value to validate
|
|
13
|
-
* @param config - Internal configuration with validation rules
|
|
14
|
-
* @param operation - Optional filter operation type. Blank operations (blank/notBlank) bypass value validation
|
|
15
|
-
* @returns The validated filter value (empty string for blank operations)
|
|
16
|
-
* @throws InvalidFilterError if value exceeds maximum length
|
|
17
|
-
*/
|
|
18
10
|
export function validateFilterValue(value, config, operation) {
|
|
19
|
-
// Blank operations don't require value validation
|
|
20
11
|
if (operation === 'blank' || operation === 'notBlank') {
|
|
21
12
|
return '';
|
|
22
13
|
}
|
|
@@ -25,30 +16,15 @@ export function validateFilterValue(value, config, operation) {
|
|
|
25
16
|
}
|
|
26
17
|
return value;
|
|
27
18
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Validates a number filter value
|
|
30
|
-
*
|
|
31
|
-
* @param value - The number value to validate
|
|
32
|
-
* @returns Validation result
|
|
33
|
-
*/
|
|
34
19
|
export function validateNumberFilter(value) {
|
|
35
|
-
// Basic number validation
|
|
36
20
|
if (!Number.isFinite(value)) {
|
|
37
21
|
return { valid: false, error: 'Filter value must be a finite number' };
|
|
38
22
|
}
|
|
39
|
-
// Range validation for precision
|
|
40
23
|
if (Math.abs(value) > Number.MAX_SAFE_INTEGER) {
|
|
41
24
|
return { valid: false, error: 'Number value exceeds safe integer range' };
|
|
42
25
|
}
|
|
43
26
|
return { valid: true };
|
|
44
27
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Validates a number range filter
|
|
47
|
-
*
|
|
48
|
-
* @param min - The minimum value
|
|
49
|
-
* @param max - The maximum value
|
|
50
|
-
* @returns Validation result
|
|
51
|
-
*/
|
|
52
28
|
export function validateNumberRange(min, max) {
|
|
53
29
|
const minResult = validateNumberFilter(min);
|
|
54
30
|
if (!minResult.valid)
|
|
@@ -64,19 +40,11 @@ export function validateNumberRange(min, max) {
|
|
|
64
40
|
}
|
|
65
41
|
return { valid: true };
|
|
66
42
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Validates a parsed number from string input
|
|
69
|
-
*
|
|
70
|
-
* @param value - String representation of number
|
|
71
|
-
* @returns Parsed number or throws InvalidFilterError
|
|
72
|
-
*/
|
|
73
43
|
export function validateAndParseNumber(value) {
|
|
74
44
|
const trimmedValue = value?.trim();
|
|
75
45
|
if (!trimmedValue) {
|
|
76
46
|
throw new InvalidFilterError('Number filter value cannot be empty');
|
|
77
47
|
}
|
|
78
|
-
// Use a regex to validate proper number format before parsing
|
|
79
|
-
// This prevents parseFloat from accepting partial numbers like "42abc" -> 42
|
|
80
48
|
const numberRegex = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
|
|
81
49
|
if (!numberRegex.test(trimmedValue)) {
|
|
82
50
|
throw new InvalidFilterError(`Invalid number format: ${value}`);
|
|
@@ -91,30 +59,19 @@ export function validateAndParseNumber(value) {
|
|
|
91
59
|
}
|
|
92
60
|
return numValue;
|
|
93
61
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Validates and parses a date string in ISO format (YYYY-MM-DD)
|
|
96
|
-
*
|
|
97
|
-
* @param value - String representation of date in ISO format
|
|
98
|
-
* @returns Validated ISO date string
|
|
99
|
-
* @throws InvalidDateError if date format is invalid or date doesn't exist
|
|
100
|
-
*/
|
|
101
62
|
export function validateAndParseDate(value) {
|
|
102
63
|
const trimmedValue = value?.trim();
|
|
103
64
|
if (!trimmedValue) {
|
|
104
65
|
throw new InvalidDateError('Date filter value cannot be empty');
|
|
105
66
|
}
|
|
106
|
-
// Validate ISO date format (YYYY-MM-DD)
|
|
107
67
|
const isoDateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
108
68
|
if (!isoDateRegex.test(trimmedValue)) {
|
|
109
69
|
throw new InvalidDateError(`Invalid date format '${value}'. Expected ISO format YYYY-MM-DD (e.g., 2024-01-15)`);
|
|
110
70
|
}
|
|
111
|
-
|
|
112
|
-
const date = new Date(trimmedValue + 'T00:00:00.000Z'); // Force UTC to avoid timezone issues
|
|
71
|
+
const date = new Date(trimmedValue + 'T00:00:00.000Z');
|
|
113
72
|
if (isNaN(date.getTime())) {
|
|
114
73
|
throw new InvalidDateError(`Invalid date '${value}'. Date does not exist in the calendar`);
|
|
115
74
|
}
|
|
116
|
-
// Additional validation: ensure the parsed date matches the input
|
|
117
|
-
// This catches edge cases like February 30th that might parse differently
|
|
118
75
|
const [year, month, day] = trimmedValue.split('-').map(Number);
|
|
119
76
|
if (date.getUTCFullYear() !== year ||
|
|
120
77
|
date.getUTCMonth() + 1 !== month ||
|
|
@@ -123,15 +80,7 @@ export function validateAndParseDate(value) {
|
|
|
123
80
|
}
|
|
124
81
|
return trimmedValue;
|
|
125
82
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Validates a date filter value
|
|
128
|
-
*
|
|
129
|
-
* @param value - The date value to validate
|
|
130
|
-
* @param operation - The date filter operation
|
|
131
|
-
* @returns Validation result
|
|
132
|
-
*/
|
|
133
83
|
export function validateDateFilter(value, operation) {
|
|
134
|
-
// Blank operations don't require date validation
|
|
135
84
|
if (operation === 'blank' || operation === 'notBlank') {
|
|
136
85
|
return { valid: true };
|
|
137
86
|
}
|
|
@@ -146,18 +95,10 @@ export function validateDateFilter(value, operation) {
|
|
|
146
95
|
};
|
|
147
96
|
}
|
|
148
97
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Validates a date range filter
|
|
151
|
-
*
|
|
152
|
-
* @param startDate - The start date (ISO format)
|
|
153
|
-
* @param endDate - The end date (ISO format)
|
|
154
|
-
* @returns Validation result
|
|
155
|
-
*/
|
|
156
98
|
export function validateDateRange(startDate, endDate) {
|
|
157
99
|
try {
|
|
158
100
|
const validStartDate = validateAndParseDate(startDate);
|
|
159
101
|
const validEndDate = validateAndParseDate(endDate);
|
|
160
|
-
// Check that start date <= end date
|
|
161
102
|
if (validStartDate > validEndDate) {
|
|
162
103
|
return {
|
|
163
104
|
valid: false,
|
|
@@ -173,12 +114,6 @@ export function validateDateRange(startDate, endDate) {
|
|
|
173
114
|
};
|
|
174
115
|
}
|
|
175
116
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Validates a date range from comma-separated string input
|
|
178
|
-
*
|
|
179
|
-
* @param rangeValue - Comma-separated date range (e.g., "2024-01-01,2024-12-31")
|
|
180
|
-
* @returns Tuple of [startDate, endDate] or throws InvalidDateError
|
|
181
|
-
*/
|
|
182
117
|
export function validateAndParseDateRange(rangeValue) {
|
|
183
118
|
const trimmedValue = rangeValue?.trim();
|
|
184
119
|
if (!trimmedValue) {
|
|
@@ -196,4 +131,31 @@ export function validateAndParseDateRange(rangeValue) {
|
|
|
196
131
|
}
|
|
197
132
|
return [startDate, endDate];
|
|
198
133
|
}
|
|
134
|
+
export function isValidColumnFilter(obj) {
|
|
135
|
+
if (!obj || typeof obj !== 'object') {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const filter = obj;
|
|
139
|
+
if (!filter.filterType ||
|
|
140
|
+
!filter.type ||
|
|
141
|
+
typeof filter.filterType !== 'string' ||
|
|
142
|
+
typeof filter.type !== 'string') {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
if (filter.filterType === 'text') {
|
|
146
|
+
return (typeof filter.filter === 'string' &&
|
|
147
|
+
TEXT_FILTER_OPERATIONS.includes(filter.type));
|
|
148
|
+
}
|
|
149
|
+
if (filter.filterType === 'number') {
|
|
150
|
+
return (typeof filter.filter === 'number' &&
|
|
151
|
+
NUMBER_FILTER_OPERATIONS.includes(filter.type) &&
|
|
152
|
+
(filter.filterTo === undefined || typeof filter.filterTo === 'number'));
|
|
153
|
+
}
|
|
154
|
+
if (filter.filterType === 'date') {
|
|
155
|
+
return (typeof filter.filter === 'string' &&
|
|
156
|
+
DATE_FILTER_OPERATIONS.includes(filter.type) &&
|
|
157
|
+
(filter.filterTo === undefined || typeof filter.filterTo === 'string'));
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
199
161
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/core/validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/core/validation.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAKnB,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,GAAG;IACnB,aAAa,EAAE,YAAqB;IACpC,YAAY,EAAE,cAAc;IAC5B,MAAM,EAAE,aAAsB;IAC9B,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;CACd,CAAA;AAqBV,MAAM,UAAU,mBAAmB,CACjC,KAAa,EACb,MAAsB,EACtB,SAA2B;IAG3B,IAAI,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;QACtD,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;QACzC,MAAM,IAAI,kBAAkB,CAC1B,0CAA0C,MAAM,CAAC,cAAc,aAAa,CAC7E,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAQD,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAEhD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,sCAAsC,EAAE,CAAA;IACxE,CAAC;IAGD,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC9C,OAAO,EAAE,KAAK,EAAE,KAAK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C;QACnC,OAAO,CACL,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;YACjC,wBAAwB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAA6B,CAAC;YACvE,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CACvE,CAAA;IACH,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;QACjC,OAAO,CACL,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;YACjC,sBAAsB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAA2B,CAAC;YACnE,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CACvE,CAAA;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { FilterModel } from 'ag-grid-community';
|
|
2
|
+
/**
|
|
3
|
+
* A saved snapshot of a grid's filters.
|
|
4
|
+
*/
|
|
5
|
+
export interface GridView {
|
|
6
|
+
/** Stable generated id */
|
|
7
|
+
id: string;
|
|
8
|
+
/** User-supplied display name */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Epoch millis of the last write */
|
|
11
|
+
updatedAt: number;
|
|
12
|
+
/** AG Grid's native filter model, stored as-is */
|
|
13
|
+
filterModel: FilterModel;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Read/write access to one grid's saved views.
|
|
17
|
+
*/
|
|
18
|
+
export interface ViewStore {
|
|
19
|
+
/** All saved views, in save order */
|
|
20
|
+
listViews(): GridView[];
|
|
21
|
+
/** Id of the active view, or null */
|
|
22
|
+
getActiveViewId(): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Records which view is active.
|
|
25
|
+
*
|
|
26
|
+
* Named `persist…` rather than `set…` so it cannot be mistaken for a React
|
|
27
|
+
* state setter: this writes storage and triggers no re-render.
|
|
28
|
+
*
|
|
29
|
+
* Writing the value the pointer already holds is a no-op, so callers need not
|
|
30
|
+
* check first and a redundant call cannot fail on blocked storage.
|
|
31
|
+
*/
|
|
32
|
+
persistActiveViewId(id: string | null): void;
|
|
33
|
+
/**
|
|
34
|
+
* Saves a filter model under a name and makes it active.
|
|
35
|
+
*
|
|
36
|
+
* Names are unique and matched exactly after trimming, so saving over an
|
|
37
|
+
* existing name updates that view in place, keeping its id and its position
|
|
38
|
+
* in the list, rather than adding a duplicate label. That is what gives
|
|
39
|
+
* "load, adjust, re-save" its update semantics without a separate method.
|
|
40
|
+
*
|
|
41
|
+
* A null or undefined filterModel is stored as an empty model, since that is
|
|
42
|
+
* what AG Grid means by it and what getFilterModel returns in practice.
|
|
43
|
+
*
|
|
44
|
+
* @throws when the name is empty, or when the write fails: storage full,
|
|
45
|
+
* blocked by policy, or no DOM present
|
|
46
|
+
*/
|
|
47
|
+
saveView(name: string, filterModel: FilterModel): GridView;
|
|
48
|
+
/**
|
|
49
|
+
* Deletes a view, clearing the active id if it pointed at that view.
|
|
50
|
+
*
|
|
51
|
+
* Deleting an id that is not stored is a no-op, so it cannot fail on blocked
|
|
52
|
+
* storage.
|
|
53
|
+
*/
|
|
54
|
+
deleteView(id: string): void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a store bound to one storage key.
|
|
58
|
+
*
|
|
59
|
+
* All reads degrade to an empty store rather than throwing: storage may be
|
|
60
|
+
* absent (SSR), blocked by policy, or hold a corrupt or foreign blob. Writes do
|
|
61
|
+
* throw, so callers can tell the user a view wasn't saved.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createViewStore(storageKey: string): ViewStore;
|