ag-grid-url-sync 0.3.0 → 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 +93 -1
- package/dist/core/ag-grid-url-sync.js +1 -53
- 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.js +0 -5
- package/dist/core/index.js.map +1 -1
- package/dist/core/serialization/formats.js +2 -21
- package/dist/core/serialization/formats.js.map +1 -1
- package/dist/core/serialization/grouped.js +0 -47
- package/dist/core/serialization/grouped.js.map +1 -1
- package/dist/core/serialization/index.js +0 -4
- package/dist/core/serialization/index.js.map +1 -1
- package/dist/core/types.d.ts +4 -4
- package/dist/core/types.js +0 -118
- package/dist/core/types.js.map +1 -1
- package/dist/core/url-generator.js +2 -48
- package/dist/core/url-generator.js.map +1 -1
- package/dist/core/url-parser.js +1 -57
- package/dist/core/url-parser.js.map +1 -1
- package/dist/core/validation.d.ts +4 -4
- package/dist/core/validation.js +1 -78
- 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 +1 -0
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/types.d.ts +96 -0
- package/dist/react/use-ag-grid-url-sync.js +408 -41
- package/dist/react/use-ag-grid-url-sync.js.map +1 -1
- package/package.json +85 -30
package/dist/core/url-parser.js
CHANGED
|
@@ -1,9 +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
3
|
import { detectGroupedSerialization, deserializeGrouped } from './serialization/grouped.js';
|
|
4
|
-
/**
|
|
5
|
-
* Detects if an operation is number-specific
|
|
6
|
-
*/
|
|
7
4
|
function isNumberOperation(operation) {
|
|
8
5
|
return [
|
|
9
6
|
'lessThan',
|
|
@@ -13,9 +10,6 @@ function isNumberOperation(operation) {
|
|
|
13
10
|
'inRange'
|
|
14
11
|
].includes(operation);
|
|
15
12
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Detects if an operation is date-specific
|
|
18
|
-
*/
|
|
19
13
|
function isDateOperation(operation) {
|
|
20
14
|
return [
|
|
21
15
|
'dateBefore',
|
|
@@ -25,16 +19,9 @@ function isDateOperation(operation) {
|
|
|
25
19
|
'dateRange'
|
|
26
20
|
].includes(operation);
|
|
27
21
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Detects if an operation works across multiple filter types (shared operations)
|
|
30
|
-
*/
|
|
31
22
|
function isSharedOperation(operation) {
|
|
32
23
|
return ['eq', 'notEqual', 'blank', 'notBlank'].includes(operation);
|
|
33
24
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Attempts to parse a value as a date and returns the filter type
|
|
36
|
-
* This is used for shared operations to determine if they should be treated as date filters
|
|
37
|
-
*/
|
|
38
25
|
function tryParseAsDate(value) {
|
|
39
26
|
try {
|
|
40
27
|
validateAndParseDate(value);
|
|
@@ -44,22 +31,14 @@ function tryParseAsDate(value) {
|
|
|
44
31
|
return null;
|
|
45
32
|
}
|
|
46
33
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Detects the most appropriate filter type for a shared operation based on the value
|
|
49
|
-
* Priority: Date > Number > Text (if the value can be parsed as date/number, prefer that type)
|
|
50
|
-
*/
|
|
51
34
|
function detectFilterTypeForSharedOperation(operation, value) {
|
|
52
|
-
// Blank operations default to text (most common case)
|
|
53
35
|
if (operation === 'blank' || operation === 'notBlank') {
|
|
54
36
|
return 'text';
|
|
55
37
|
}
|
|
56
|
-
// For eq/notEqual operations, try to detect the most specific type
|
|
57
38
|
if (operation === 'eq' || operation === 'notEqual') {
|
|
58
|
-
// Try date first (most specific format)
|
|
59
39
|
if (tryParseAsDate(value) === 'date') {
|
|
60
40
|
return 'date';
|
|
61
41
|
}
|
|
62
|
-
// Try number second
|
|
63
42
|
try {
|
|
64
43
|
const numValue = parseFloat(value);
|
|
65
44
|
if (!isNaN(numValue) && Number.isFinite(numValue)) {
|
|
@@ -70,16 +49,11 @@ function detectFilterTypeForSharedOperation(operation, value) {
|
|
|
70
49
|
}
|
|
71
50
|
}
|
|
72
51
|
catch {
|
|
73
|
-
// Fall through to text
|
|
74
52
|
}
|
|
75
|
-
// Default to text
|
|
76
53
|
return 'text';
|
|
77
54
|
}
|
|
78
55
|
return 'text';
|
|
79
56
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Extracts column name and operation from a filter parameter
|
|
82
|
-
*/
|
|
83
57
|
function extractColumnAndOperation(param, expectedPrefix) {
|
|
84
58
|
const ensureTrailingUnderscore = (prefix) => prefix.endsWith('_') ? prefix : prefix + '_';
|
|
85
59
|
const sanitizedPrefix = expectedPrefix
|
|
@@ -89,7 +63,6 @@ function extractColumnAndOperation(param, expectedPrefix) {
|
|
|
89
63
|
if (!param.startsWith(prefixToCheck + '_')) {
|
|
90
64
|
throw new InvalidFilterError(`Invalid filter prefix in parameter: ${param}`);
|
|
91
65
|
}
|
|
92
|
-
// Remove prefix and find the last underscore to separate column from operation
|
|
93
66
|
const withoutPrefix = param.substring(prefixToCheck.length + 1);
|
|
94
67
|
const lastUnderscoreIndex = withoutPrefix.lastIndexOf('_');
|
|
95
68
|
if (lastUnderscoreIndex === -1) {
|
|
@@ -102,16 +75,12 @@ function extractColumnAndOperation(param, expectedPrefix) {
|
|
|
102
75
|
}
|
|
103
76
|
return { column, operation };
|
|
104
77
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Parses a URL parameter into a column filter
|
|
107
|
-
*/
|
|
108
78
|
export function parseFilterParam(param, value, expectedPrefix) {
|
|
109
79
|
const { operation } = extractColumnAndOperation(param, expectedPrefix);
|
|
110
80
|
const filterOp = OPERATION_MAP[operation];
|
|
111
81
|
if (!filterOp) {
|
|
112
82
|
throw new InvalidFilterError(`Unsupported filter operation: ${operation}`);
|
|
113
83
|
}
|
|
114
|
-
// Handle date range operations
|
|
115
84
|
if (filterOp === 'dateRange') {
|
|
116
85
|
try {
|
|
117
86
|
const [startDate, endDate] = validateAndParseDateRange(value);
|
|
@@ -126,7 +95,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
126
95
|
throw new InvalidFilterError(error instanceof Error ? error.message : 'Invalid date range');
|
|
127
96
|
}
|
|
128
97
|
}
|
|
129
|
-
// Handle number range operations
|
|
130
98
|
if (filterOp === 'inRange') {
|
|
131
99
|
const rangeParts = value.split(',');
|
|
132
100
|
if (rangeParts.length !== 2) {
|
|
@@ -145,7 +113,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
145
113
|
filterTo: max
|
|
146
114
|
};
|
|
147
115
|
}
|
|
148
|
-
// Handle date-specific operations
|
|
149
116
|
if (isDateOperation(filterOp)) {
|
|
150
117
|
try {
|
|
151
118
|
const dateValue = validateAndParseDate(value);
|
|
@@ -163,7 +130,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
163
130
|
throw new InvalidFilterError(error instanceof Error ? error.message : 'Invalid date filter');
|
|
164
131
|
}
|
|
165
132
|
}
|
|
166
|
-
// Handle number-specific operations
|
|
167
133
|
if (isNumberOperation(filterOp)) {
|
|
168
134
|
const numValue = validateAndParseNumber(value);
|
|
169
135
|
return {
|
|
@@ -172,7 +138,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
172
138
|
filter: numValue
|
|
173
139
|
};
|
|
174
140
|
}
|
|
175
|
-
// Handle shared operations (eq, notEqual, blank, notBlank)
|
|
176
141
|
if (isSharedOperation(filterOp)) {
|
|
177
142
|
const detectedType = detectFilterTypeForSharedOperation(filterOp, value);
|
|
178
143
|
if (detectedType === 'date') {
|
|
@@ -185,7 +150,6 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
185
150
|
};
|
|
186
151
|
}
|
|
187
152
|
catch {
|
|
188
|
-
// If date parsing fails, fall back to text
|
|
189
153
|
}
|
|
190
154
|
}
|
|
191
155
|
if (detectedType === 'number') {
|
|
@@ -203,33 +167,25 @@ export function parseFilterParam(param, value, expectedPrefix) {
|
|
|
203
167
|
}
|
|
204
168
|
}
|
|
205
169
|
catch {
|
|
206
|
-
// Fall through to text handling
|
|
207
170
|
}
|
|
208
171
|
}
|
|
209
|
-
// Handle as text filter (default for shared operations)
|
|
210
172
|
return {
|
|
211
173
|
filterType: 'text',
|
|
212
174
|
type: filterOp,
|
|
213
175
|
filter: filterOp === 'blank' || filterOp === 'notBlank' ? '' : value || ''
|
|
214
176
|
};
|
|
215
177
|
}
|
|
216
|
-
// Handle text-specific operations (existing logic)
|
|
217
178
|
return {
|
|
218
179
|
filterType: 'text',
|
|
219
180
|
type: filterOp,
|
|
220
181
|
filter: value || ''
|
|
221
182
|
};
|
|
222
183
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Converts URL search params into a filter state object
|
|
225
|
-
*/
|
|
226
184
|
export function parseUrlFilters(url, config) {
|
|
227
185
|
try {
|
|
228
|
-
// Handle empty or whitespace-only URLs gracefully
|
|
229
186
|
if (!url || url.trim() === '') {
|
|
230
187
|
return {};
|
|
231
188
|
}
|
|
232
|
-
// Check for obviously malformed URLs that should throw errors
|
|
233
189
|
if (url === 'not-a-url' ||
|
|
234
190
|
url.startsWith('://') ||
|
|
235
191
|
(!url.includes('://') &&
|
|
@@ -238,39 +194,31 @@ export function parseUrlFilters(url, config) {
|
|
|
238
194
|
url.includes('.'))) {
|
|
239
195
|
throw new Error('Invalid URL format');
|
|
240
196
|
}
|
|
241
|
-
// If URL starts with '?' treat as query string only
|
|
242
197
|
let urlToProcess = url;
|
|
243
198
|
if (url.startsWith('?')) {
|
|
244
199
|
urlToProcess = `http://example.com${url}`;
|
|
245
200
|
}
|
|
246
201
|
else if (!url.includes('://') && !url.startsWith('/')) {
|
|
247
|
-
// For other cases without protocol, try to handle as query string
|
|
248
202
|
urlToProcess = `http://example.com?${url}`;
|
|
249
203
|
}
|
|
250
204
|
else {
|
|
251
205
|
urlToProcess = url;
|
|
252
206
|
}
|
|
253
|
-
// First, try to detect grouped serialization
|
|
254
207
|
const DEFAULT_GROUPED_PARAMS = ['grid_filters', 'filters'];
|
|
255
|
-
const groupedDetection = detectGroupedSerialization(urlToProcess, [config.groupedParam, ...DEFAULT_GROUPED_PARAMS]
|
|
256
|
-
);
|
|
208
|
+
const groupedDetection = detectGroupedSerialization(urlToProcess, [config.groupedParam, ...DEFAULT_GROUPED_PARAMS]);
|
|
257
209
|
if (groupedDetection.isGrouped &&
|
|
258
210
|
groupedDetection.value &&
|
|
259
211
|
groupedDetection.format) {
|
|
260
|
-
// Handle grouped serialization
|
|
261
212
|
return deserializeGrouped(groupedDetection.value, groupedDetection.format, config);
|
|
262
213
|
}
|
|
263
|
-
// Handle individual serialization (existing logic)
|
|
264
214
|
const urlObj = new URL(urlToProcess);
|
|
265
215
|
const filterState = {};
|
|
266
216
|
for (const [param, value] of urlObj.searchParams.entries()) {
|
|
267
217
|
if (!param.startsWith(config.paramPrefix))
|
|
268
218
|
continue;
|
|
269
219
|
try {
|
|
270
|
-
// Extract column name and parse the filter parameter
|
|
271
220
|
const { column: columnName } = extractColumnAndOperation(param, config.paramPrefix);
|
|
272
221
|
const filterParam = parseFilterParam(param, value, config.paramPrefix);
|
|
273
|
-
// Apply validation based on filter type
|
|
274
222
|
if (filterParam.filterType === 'text') {
|
|
275
223
|
const validatedValue = validateFilterValue(value, config, filterParam.type);
|
|
276
224
|
filterState[columnName] = {
|
|
@@ -279,20 +227,16 @@ export function parseUrlFilters(url, config) {
|
|
|
279
227
|
};
|
|
280
228
|
}
|
|
281
229
|
else if (filterParam.filterType === 'date') {
|
|
282
|
-
// Date filters are already validated in parseFilterParam
|
|
283
230
|
filterState[columnName] = filterParam;
|
|
284
231
|
}
|
|
285
232
|
else {
|
|
286
|
-
// Number filters are already validated in parseFilterParam
|
|
287
233
|
filterState[columnName] = filterParam;
|
|
288
234
|
}
|
|
289
235
|
}
|
|
290
236
|
catch (error) {
|
|
291
|
-
// Log parsing errors through the configured error handler
|
|
292
237
|
if (config.onParseError) {
|
|
293
238
|
config.onParseError(error);
|
|
294
239
|
}
|
|
295
|
-
// Continue processing other parameters instead of failing completely
|
|
296
240
|
continue;
|
|
297
241
|
}
|
|
298
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;AACxB,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EACnB,MAAM,4BAA4B,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;A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C,CAAC,eAAe,EAAE,CACnF,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -3,11 +3,11 @@ import type { InternalConfig, FilterOperation, DateFilterOperation, ColumnFilter
|
|
|
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:
|
|
9
|
-
readonly groupedParam:
|
|
10
|
-
readonly format:
|
|
8
|
+
readonly serialization: 'individual';
|
|
9
|
+
readonly groupedParam: 'grid_filters';
|
|
10
|
+
readonly format: 'querystring';
|
|
11
11
|
readonly onParseError: () => void;
|
|
12
12
|
};
|
|
13
13
|
/**
|
package/dist/core/validation.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { InvalidFilterError, InvalidDateError, TEXT_FILTER_OPERATIONS, NUMBER_FILTER_OPERATIONS, DATE_FILTER_OPERATIONS } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Default configuration values
|
|
4
|
-
*/
|
|
5
2
|
export const DEFAULT_CONFIG = {
|
|
6
3
|
paramPrefix: 'f_',
|
|
7
4
|
maxValueLength: 200,
|
|
@@ -10,17 +7,7 @@ export const DEFAULT_CONFIG = {
|
|
|
10
7
|
format: 'querystring',
|
|
11
8
|
onParseError: () => { }
|
|
12
9
|
};
|
|
13
|
-
/**
|
|
14
|
-
* Validates a text filter value against configuration constraints
|
|
15
|
-
*
|
|
16
|
-
* @param value - The filter value to validate
|
|
17
|
-
* @param config - Internal configuration with validation rules
|
|
18
|
-
* @param operation - Optional filter operation type. Blank operations (blank/notBlank) bypass value validation
|
|
19
|
-
* @returns The validated filter value (empty string for blank operations)
|
|
20
|
-
* @throws InvalidFilterError if value exceeds maximum length
|
|
21
|
-
*/
|
|
22
10
|
export function validateFilterValue(value, config, operation) {
|
|
23
|
-
// Blank operations don't require value validation
|
|
24
11
|
if (operation === 'blank' || operation === 'notBlank') {
|
|
25
12
|
return '';
|
|
26
13
|
}
|
|
@@ -29,30 +16,15 @@ export function validateFilterValue(value, config, operation) {
|
|
|
29
16
|
}
|
|
30
17
|
return value;
|
|
31
18
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Validates a number filter value
|
|
34
|
-
*
|
|
35
|
-
* @param value - The number value to validate
|
|
36
|
-
* @returns Validation result
|
|
37
|
-
*/
|
|
38
19
|
export function validateNumberFilter(value) {
|
|
39
|
-
// Basic number validation
|
|
40
20
|
if (!Number.isFinite(value)) {
|
|
41
21
|
return { valid: false, error: 'Filter value must be a finite number' };
|
|
42
22
|
}
|
|
43
|
-
// Range validation for precision
|
|
44
23
|
if (Math.abs(value) > Number.MAX_SAFE_INTEGER) {
|
|
45
24
|
return { valid: false, error: 'Number value exceeds safe integer range' };
|
|
46
25
|
}
|
|
47
26
|
return { valid: true };
|
|
48
27
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Validates a number range filter
|
|
51
|
-
*
|
|
52
|
-
* @param min - The minimum value
|
|
53
|
-
* @param max - The maximum value
|
|
54
|
-
* @returns Validation result
|
|
55
|
-
*/
|
|
56
28
|
export function validateNumberRange(min, max) {
|
|
57
29
|
const minResult = validateNumberFilter(min);
|
|
58
30
|
if (!minResult.valid)
|
|
@@ -68,19 +40,11 @@ export function validateNumberRange(min, max) {
|
|
|
68
40
|
}
|
|
69
41
|
return { valid: true };
|
|
70
42
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Validates a parsed number from string input
|
|
73
|
-
*
|
|
74
|
-
* @param value - String representation of number
|
|
75
|
-
* @returns Parsed number or throws InvalidFilterError
|
|
76
|
-
*/
|
|
77
43
|
export function validateAndParseNumber(value) {
|
|
78
44
|
const trimmedValue = value?.trim();
|
|
79
45
|
if (!trimmedValue) {
|
|
80
46
|
throw new InvalidFilterError('Number filter value cannot be empty');
|
|
81
47
|
}
|
|
82
|
-
// Use a regex to validate proper number format before parsing
|
|
83
|
-
// This prevents parseFloat from accepting partial numbers like "42abc" -> 42
|
|
84
48
|
const numberRegex = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
|
|
85
49
|
if (!numberRegex.test(trimmedValue)) {
|
|
86
50
|
throw new InvalidFilterError(`Invalid number format: ${value}`);
|
|
@@ -95,30 +59,19 @@ export function validateAndParseNumber(value) {
|
|
|
95
59
|
}
|
|
96
60
|
return numValue;
|
|
97
61
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Validates and parses a date string in ISO format (YYYY-MM-DD)
|
|
100
|
-
*
|
|
101
|
-
* @param value - String representation of date in ISO format
|
|
102
|
-
* @returns Validated ISO date string
|
|
103
|
-
* @throws InvalidDateError if date format is invalid or date doesn't exist
|
|
104
|
-
*/
|
|
105
62
|
export function validateAndParseDate(value) {
|
|
106
63
|
const trimmedValue = value?.trim();
|
|
107
64
|
if (!trimmedValue) {
|
|
108
65
|
throw new InvalidDateError('Date filter value cannot be empty');
|
|
109
66
|
}
|
|
110
|
-
// Validate ISO date format (YYYY-MM-DD)
|
|
111
67
|
const isoDateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
112
68
|
if (!isoDateRegex.test(trimmedValue)) {
|
|
113
69
|
throw new InvalidDateError(`Invalid date format '${value}'. Expected ISO format YYYY-MM-DD (e.g., 2024-01-15)`);
|
|
114
70
|
}
|
|
115
|
-
|
|
116
|
-
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');
|
|
117
72
|
if (isNaN(date.getTime())) {
|
|
118
73
|
throw new InvalidDateError(`Invalid date '${value}'. Date does not exist in the calendar`);
|
|
119
74
|
}
|
|
120
|
-
// Additional validation: ensure the parsed date matches the input
|
|
121
|
-
// This catches edge cases like February 30th that might parse differently
|
|
122
75
|
const [year, month, day] = trimmedValue.split('-').map(Number);
|
|
123
76
|
if (date.getUTCFullYear() !== year ||
|
|
124
77
|
date.getUTCMonth() + 1 !== month ||
|
|
@@ -127,15 +80,7 @@ export function validateAndParseDate(value) {
|
|
|
127
80
|
}
|
|
128
81
|
return trimmedValue;
|
|
129
82
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Validates a date filter value
|
|
132
|
-
*
|
|
133
|
-
* @param value - The date value to validate
|
|
134
|
-
* @param operation - The date filter operation
|
|
135
|
-
* @returns Validation result
|
|
136
|
-
*/
|
|
137
83
|
export function validateDateFilter(value, operation) {
|
|
138
|
-
// Blank operations don't require date validation
|
|
139
84
|
if (operation === 'blank' || operation === 'notBlank') {
|
|
140
85
|
return { valid: true };
|
|
141
86
|
}
|
|
@@ -150,18 +95,10 @@ export function validateDateFilter(value, operation) {
|
|
|
150
95
|
};
|
|
151
96
|
}
|
|
152
97
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Validates a date range filter
|
|
155
|
-
*
|
|
156
|
-
* @param startDate - The start date (ISO format)
|
|
157
|
-
* @param endDate - The end date (ISO format)
|
|
158
|
-
* @returns Validation result
|
|
159
|
-
*/
|
|
160
98
|
export function validateDateRange(startDate, endDate) {
|
|
161
99
|
try {
|
|
162
100
|
const validStartDate = validateAndParseDate(startDate);
|
|
163
101
|
const validEndDate = validateAndParseDate(endDate);
|
|
164
|
-
// Check that start date <= end date
|
|
165
102
|
if (validStartDate > validEndDate) {
|
|
166
103
|
return {
|
|
167
104
|
valid: false,
|
|
@@ -177,12 +114,6 @@ export function validateDateRange(startDate, endDate) {
|
|
|
177
114
|
};
|
|
178
115
|
}
|
|
179
116
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Validates a date range from comma-separated string input
|
|
182
|
-
*
|
|
183
|
-
* @param rangeValue - Comma-separated date range (e.g., "2024-01-01,2024-12-31")
|
|
184
|
-
* @returns Tuple of [startDate, endDate] or throws InvalidDateError
|
|
185
|
-
*/
|
|
186
117
|
export function validateAndParseDateRange(rangeValue) {
|
|
187
118
|
const trimmedValue = rangeValue?.trim();
|
|
188
119
|
if (!trimmedValue) {
|
|
@@ -200,25 +131,17 @@ export function validateAndParseDateRange(rangeValue) {
|
|
|
200
131
|
}
|
|
201
132
|
return [startDate, endDate];
|
|
202
133
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Validates if an object is a valid column filter
|
|
205
|
-
*
|
|
206
|
-
* @param obj - The object to validate
|
|
207
|
-
* @returns Type guard that narrows the type to ColumnFilter
|
|
208
|
-
*/
|
|
209
134
|
export function isValidColumnFilter(obj) {
|
|
210
135
|
if (!obj || typeof obj !== 'object') {
|
|
211
136
|
return false;
|
|
212
137
|
}
|
|
213
138
|
const filter = obj;
|
|
214
|
-
// Check for required properties
|
|
215
139
|
if (!filter.filterType ||
|
|
216
140
|
!filter.type ||
|
|
217
141
|
typeof filter.filterType !== 'string' ||
|
|
218
142
|
typeof filter.type !== 'string') {
|
|
219
143
|
return false;
|
|
220
144
|
}
|
|
221
|
-
// Validate based on filter type
|
|
222
145
|
if (filter.filterType === 'text') {
|
|
223
146
|
return (typeof filter.filter === 'string' &&
|
|
224
147
|
TEXT_FILTER_OPERATIONS.includes(filter.type));
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;IAC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,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;
|