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
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { AG_GRID_OPERATION_NAMES, REVERSE_AG_GRID_OPERATION_NAMES, TEXT_FILTER_OPERATIONS, NUMBER_FILTER_OPERATIONS, DATE_FILTER_OPERATIONS } from './types.js';
|
|
2
|
-
// Map AG Grid number operations to our internal number operations
|
|
3
|
-
// Since AG Grid uses generic names, we need to be explicit about number operations
|
|
4
2
|
const AG_GRID_TO_NUMBER_OPERATION_MAP = {
|
|
5
3
|
lessThan: 'lessThan',
|
|
6
4
|
lessThanOrEqual: 'lessThanOrEqual',
|
|
@@ -12,74 +10,48 @@ const AG_GRID_TO_NUMBER_OPERATION_MAP = {
|
|
|
12
10
|
blank: 'blank',
|
|
13
11
|
notBlank: 'notBlank'
|
|
14
12
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Type guard to check if a value is a valid number operation key
|
|
17
|
-
*/
|
|
18
13
|
function isValidNumberOperation(operation) {
|
|
19
14
|
return Boolean(operation && operation in AG_GRID_TO_NUMBER_OPERATION_MAP);
|
|
20
15
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Converts a date string to ISO format (YYYY-MM-DD)
|
|
23
|
-
* Handles both date strings and undefined values
|
|
24
|
-
* Returns an empty string if the input is undefined or invalid
|
|
25
|
-
*/
|
|
26
16
|
function toIsoDateString(val) {
|
|
27
17
|
if (!val)
|
|
28
18
|
return '';
|
|
29
19
|
const match = val.match(/^(\d{4}-\d{2}-\d{2})/);
|
|
30
20
|
return match?.[1] ? match[1] : val || '';
|
|
31
21
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Type predicate to check if an operation is a valid text filter operation
|
|
34
|
-
*/
|
|
35
22
|
function isTextFilterOperation(operation) {
|
|
36
23
|
return TEXT_FILTER_OPERATIONS.includes(operation);
|
|
37
24
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Type predicate to check if an operation is a valid number filter operation
|
|
40
|
-
*/
|
|
41
25
|
function isNumberFilterOperation(operation) {
|
|
42
26
|
return NUMBER_FILTER_OPERATIONS.includes(operation);
|
|
43
27
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Type predicate to check if an operation is a valid date filter operation
|
|
46
|
-
*/
|
|
47
28
|
function isDateFilterOperation(operation) {
|
|
48
29
|
return DATE_FILTER_OPERATIONS.includes(operation);
|
|
49
30
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Detects the expected filter type for a column based on AG Grid configuration
|
|
52
|
-
*/
|
|
53
31
|
export function detectColumnFilterType(gridApi, columnId) {
|
|
54
32
|
try {
|
|
55
33
|
const column = gridApi.getColumn(columnId);
|
|
56
34
|
if (!column)
|
|
57
|
-
return 'text';
|
|
35
|
+
return 'text';
|
|
58
36
|
const colDef = column.getColDef();
|
|
59
|
-
// 1. Explicit filter configuration takes priority
|
|
60
37
|
if (colDef.filter === 'agDateColumnFilter')
|
|
61
38
|
return 'date';
|
|
62
39
|
if (colDef.filter === 'agNumberColumnFilter')
|
|
63
40
|
return 'number';
|
|
64
41
|
if (colDef.filter === 'agTextColumnFilter')
|
|
65
42
|
return 'text';
|
|
66
|
-
// 2. Cell data type configuration
|
|
67
43
|
if (colDef.cellDataType === 'date')
|
|
68
44
|
return 'date';
|
|
69
45
|
if (colDef.cellDataType === 'number')
|
|
70
46
|
return 'number';
|
|
71
47
|
if (colDef.cellDataType === 'text')
|
|
72
48
|
return 'text';
|
|
73
|
-
// 3. Default to text for backward compatibility
|
|
74
49
|
return 'text';
|
|
75
50
|
}
|
|
76
51
|
catch {
|
|
77
|
-
return 'text';
|
|
52
|
+
return 'text';
|
|
78
53
|
}
|
|
79
54
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Gets the current filter model from AG Grid
|
|
82
|
-
*/
|
|
83
55
|
export function getFilterModel(config) {
|
|
84
56
|
try {
|
|
85
57
|
const model = config.gridApi.getFilterModel();
|
|
@@ -91,28 +63,20 @@ export function getFilterModel(config) {
|
|
|
91
63
|
if (!filter || typeof filter !== 'object')
|
|
92
64
|
continue;
|
|
93
65
|
const { filterType, type, filter: value, filterTo, dateFrom, dateTo } = filter;
|
|
94
|
-
// Handle text filters
|
|
95
66
|
if (filterType === 'text') {
|
|
96
|
-
// Map AG Grid operations back to our internal operations using centralized mapping
|
|
97
67
|
const internalOperation = REVERSE_AG_GRID_OPERATION_NAMES[type];
|
|
98
|
-
// Use type predicate to validate and narrow the type
|
|
99
68
|
if (internalOperation && isTextFilterOperation(internalOperation)) {
|
|
100
69
|
filterState[column] = {
|
|
101
70
|
filterType: 'text',
|
|
102
|
-
type: internalOperation,
|
|
71
|
+
type: internalOperation,
|
|
103
72
|
filter: String(value || '')
|
|
104
73
|
};
|
|
105
74
|
}
|
|
106
75
|
}
|
|
107
|
-
// Handle number filters
|
|
108
76
|
else if (filterType === 'number') {
|
|
109
|
-
// For number filters, we need to handle the mapping carefully since
|
|
110
|
-
// AG Grid uses the same operation names for numbers and dates
|
|
111
|
-
// Use the explicit number mapping instead of the reverse AG Grid mapping
|
|
112
77
|
const internalOperation = isValidNumberOperation(type)
|
|
113
78
|
? AG_GRID_TO_NUMBER_OPERATION_MAP[type]
|
|
114
79
|
: null;
|
|
115
|
-
// If the operation type is not recognized, report the error
|
|
116
80
|
if (!internalOperation) {
|
|
117
81
|
if (config.onParseError) {
|
|
118
82
|
config.onParseError(new Error(`Unknown number filter operation '${type}' for column '${column}'. ` +
|
|
@@ -120,20 +84,16 @@ export function getFilterModel(config) {
|
|
|
120
84
|
}
|
|
121
85
|
continue;
|
|
122
86
|
}
|
|
123
|
-
// Use type predicate to validate and narrow the type
|
|
124
87
|
if (internalOperation && isNumberFilterOperation(internalOperation)) {
|
|
125
|
-
// Validate that the filter value is actually a number
|
|
126
88
|
const numericValue = typeof value === 'number' ? value : Number(value);
|
|
127
|
-
// Skip invalid number filters
|
|
128
89
|
if (isNaN(numericValue)) {
|
|
129
90
|
continue;
|
|
130
91
|
}
|
|
131
92
|
const numberFilter = {
|
|
132
93
|
filterType: 'number',
|
|
133
|
-
type: internalOperation,
|
|
94
|
+
type: internalOperation,
|
|
134
95
|
filter: numericValue
|
|
135
96
|
};
|
|
136
|
-
// Handle range operations
|
|
137
97
|
if (internalOperation === 'inRange' && typeof filterTo === 'number') {
|
|
138
98
|
;
|
|
139
99
|
numberFilter.filterTo = filterTo;
|
|
@@ -141,14 +101,9 @@ export function getFilterModel(config) {
|
|
|
141
101
|
filterState[column] = numberFilter;
|
|
142
102
|
}
|
|
143
103
|
}
|
|
144
|
-
// Handle date filters
|
|
145
104
|
else if (filterType === 'date') {
|
|
146
|
-
// Map AG Grid date operations back to our internal operations
|
|
147
105
|
const internalOperation = REVERSE_AG_GRID_OPERATION_NAMES[type];
|
|
148
|
-
// For date operations, we need to handle the special case where AG Grid uses
|
|
149
|
-
// generic operation names but we have date-specific internal names
|
|
150
106
|
let mappedOperation = internalOperation;
|
|
151
|
-
// Map AG Grid generic date operations to our date-specific operations
|
|
152
107
|
const AG_GRID_TO_DATE_OPERATION_MAP = {
|
|
153
108
|
lessThan: 'dateBefore',
|
|
154
109
|
lessThanOrEqual: 'dateBeforeOrEqual',
|
|
@@ -159,14 +114,12 @@ export function getFilterModel(config) {
|
|
|
159
114
|
mappedOperation = type
|
|
160
115
|
? AG_GRID_TO_DATE_OPERATION_MAP[type] || internalOperation
|
|
161
116
|
: internalOperation;
|
|
162
|
-
// Use type predicate to validate and narrow the type
|
|
163
117
|
if (mappedOperation && isDateFilterOperation(mappedOperation)) {
|
|
164
118
|
const dateFilter = {
|
|
165
119
|
filterType: 'date',
|
|
166
120
|
type: mappedOperation,
|
|
167
121
|
filter: toIsoDateString(dateFrom || String(value || ''))
|
|
168
122
|
};
|
|
169
|
-
// Handle date range operations (AG Grid uses dateFrom/dateTo)
|
|
170
123
|
if (mappedOperation === 'dateRange' && dateTo) {
|
|
171
124
|
;
|
|
172
125
|
dateFilter.filterTo = toIsoDateString(dateTo);
|
|
@@ -184,21 +137,16 @@ export function getFilterModel(config) {
|
|
|
184
137
|
return {};
|
|
185
138
|
}
|
|
186
139
|
}
|
|
187
|
-
/**
|
|
188
|
-
* Converts internal filter to AG Grid filter format
|
|
189
|
-
*/
|
|
190
140
|
function convertToAGGridFilter(filter) {
|
|
191
141
|
if (filter.filterType === 'date') {
|
|
192
|
-
// Handle date range operations
|
|
193
142
|
if (filter.type === 'dateRange') {
|
|
194
143
|
return {
|
|
195
144
|
filterType: 'date',
|
|
196
|
-
type: 'inRange',
|
|
145
|
+
type: 'inRange',
|
|
197
146
|
dateFrom: filter.filter,
|
|
198
147
|
dateTo: filter.filterTo || null
|
|
199
148
|
};
|
|
200
149
|
}
|
|
201
|
-
// Handle blank operations for dates
|
|
202
150
|
if (filter.type === 'blank' || filter.type === 'notBlank') {
|
|
203
151
|
return {
|
|
204
152
|
filterType: 'date',
|
|
@@ -207,7 +155,6 @@ function convertToAGGridFilter(filter) {
|
|
|
207
155
|
dateTo: null
|
|
208
156
|
};
|
|
209
157
|
}
|
|
210
|
-
// Map date-specific operations to AG Grid generic operations
|
|
211
158
|
const dateOperationMapping = {
|
|
212
159
|
dateBefore: 'lessThan',
|
|
213
160
|
dateBeforeOrEqual: 'lessThanOrEqual',
|
|
@@ -231,7 +178,6 @@ function convertToAGGridFilter(filter) {
|
|
|
231
178
|
type: agGridOperation,
|
|
232
179
|
filter: filter.filter
|
|
233
180
|
};
|
|
234
|
-
// Only include filterTo if it's defined
|
|
235
181
|
return filter.filterTo !== undefined
|
|
236
182
|
? { ...baseFilter, filterTo: filter.filterTo }
|
|
237
183
|
: baseFilter;
|
|
@@ -242,7 +188,6 @@ function convertToAGGridFilter(filter) {
|
|
|
242
188
|
filter: filter.filter
|
|
243
189
|
};
|
|
244
190
|
}
|
|
245
|
-
// Text filter handling
|
|
246
191
|
const agGridOperation = AG_GRID_OPERATION_NAMES[filter.type];
|
|
247
192
|
return {
|
|
248
193
|
filterType: 'text',
|
|
@@ -250,18 +195,13 @@ function convertToAGGridFilter(filter) {
|
|
|
250
195
|
filter: filter.filter
|
|
251
196
|
};
|
|
252
197
|
}
|
|
253
|
-
/**
|
|
254
|
-
* Applies a filter state to AG Grid
|
|
255
|
-
*/
|
|
256
198
|
export function applyFilterModel(filterState, config) {
|
|
257
199
|
try {
|
|
258
200
|
const model = {};
|
|
259
201
|
for (const [column, filter] of Object.entries(filterState)) {
|
|
260
202
|
if (!filter || typeof filter !== 'object')
|
|
261
203
|
continue;
|
|
262
|
-
// Detect expected filter type for this column
|
|
263
204
|
const expectedType = detectColumnFilterType(config.gridApi, column);
|
|
264
|
-
// Validate filter type compatibility
|
|
265
205
|
if (filter.filterType === 'date' && expectedType !== 'date') {
|
|
266
206
|
console.warn(`Column '${column}' expects a ${expectedType} filter but received a date filter. This may indicate a configuration mismatch in the column definition or filter application.`);
|
|
267
207
|
continue;
|
|
@@ -270,13 +210,11 @@ export function applyFilterModel(filterState, config) {
|
|
|
270
210
|
console.warn(`Column '${column}' expects a ${expectedType} filter but received a number filter. This may indicate a configuration mismatch in the column definition or filter application.`);
|
|
271
211
|
continue;
|
|
272
212
|
}
|
|
273
|
-
// Convert to AG Grid filter model
|
|
274
213
|
const agGridFilter = convertToAGGridFilter(filter);
|
|
275
214
|
if (agGridFilter) {
|
|
276
215
|
model[column] = agGridFilter;
|
|
277
216
|
}
|
|
278
217
|
}
|
|
279
|
-
// Apply the filter model to AG Grid
|
|
280
218
|
config.gridApi.setFilterModel(model);
|
|
281
219
|
}
|
|
282
220
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-integration.js","sourceRoot":"","sources":["../../src/core/grid-integration.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"grid-integration.js","sourceRoot":"","sources":["../../src/core/grid-integration.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAKnB,MAAM,+BAA+B,GAAG;IACtC,QAAQ,EAAE,UAAU;IACpB,eAAe,EAAE,iBAAiB;IAClC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,CAAC,GAAG,YAAY,CAAA;YAC9B,CAAC;QACH,CAAC;QAGD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACxB,MAAM,CAAC,YAAY,CAAC,KAAc,CAAC,CAAA;QACrC,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { validateFilterValue, DEFAULT_CONFIG } from './validation.js';
|
|
|
4
4
|
export { parseUrlFilters, parseFilterParam } from './url-parser.js';
|
|
5
5
|
export { serializeFilters, generateUrl } from './url-generator.js';
|
|
6
6
|
export { getFilterModel, applyFilterModel } from './grid-integration.js';
|
|
7
|
+
export * from './serialization/index.js';
|
package/dist/core/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export { AGGridUrlSync, createUrlSync } from './ag-grid-url-sync.js';
|
|
2
2
|
export * from './types.js';
|
|
3
|
-
// Validation utilities
|
|
4
3
|
export { validateFilterValue, DEFAULT_CONFIG } from './validation.js';
|
|
5
|
-
// URL parsing utilities
|
|
6
4
|
export { parseUrlFilters, parseFilterParam } from './url-parser.js';
|
|
7
|
-
// URL generation utilities
|
|
8
5
|
export { serializeFilters, generateUrl } from './url-generator.js';
|
|
9
|
-
// AG Grid integration utilities
|
|
10
6
|
export { getFilterModel, applyFilterModel } from './grid-integration.js';
|
|
7
|
+
export * from './serialization/index.js';
|
|
11
8
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAEpE,cAAc,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAEpE,cAAc,YAAY,CAAA;AAG1B,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGrE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGnE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGlE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxE,cAAc,0BAA0B,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FilterState, SerializationFormat, FormatSerializer } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* QueryString format serializer
|
|
4
|
+
* Reuses existing URL generation logic but groups into single parameter
|
|
5
|
+
*/
|
|
6
|
+
export declare class QueryStringSerializer implements FormatSerializer {
|
|
7
|
+
readonly format: SerializationFormat;
|
|
8
|
+
serialize(filterState: FilterState): string;
|
|
9
|
+
deserialize(value: string): FilterState;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* JSON format serializer
|
|
13
|
+
* Serializes FilterState directly as JSON
|
|
14
|
+
*/
|
|
15
|
+
export declare class JsonSerializer implements FormatSerializer {
|
|
16
|
+
readonly format: SerializationFormat;
|
|
17
|
+
serialize(filterState: FilterState): string;
|
|
18
|
+
deserialize(value: string): FilterState;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Base64 format serializer
|
|
22
|
+
* JSON encoded then base64 encoded for maximum compactness
|
|
23
|
+
*/
|
|
24
|
+
export declare class Base64Serializer implements FormatSerializer {
|
|
25
|
+
readonly format: SerializationFormat;
|
|
26
|
+
private jsonSerializer;
|
|
27
|
+
serialize(filterState: FilterState): string;
|
|
28
|
+
deserialize(value: string): FilterState;
|
|
29
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DEFAULT_CONFIG } from '../index.js';
|
|
2
|
+
import { generateUrl } from '../url-generator.js';
|
|
3
|
+
import { parseUrlFilters } from '../url-parser.js';
|
|
4
|
+
import { isValidColumnFilter } from '../validation.js';
|
|
5
|
+
export class QueryStringSerializer {
|
|
6
|
+
format = 'querystring';
|
|
7
|
+
serialize(filterState) {
|
|
8
|
+
const tempConfig = {
|
|
9
|
+
gridApi: null,
|
|
10
|
+
...DEFAULT_CONFIG
|
|
11
|
+
};
|
|
12
|
+
const tempUrl = generateUrl('http://example.com', filterState, tempConfig);
|
|
13
|
+
const urlObj = new URL(tempUrl);
|
|
14
|
+
return urlObj.search.slice(1);
|
|
15
|
+
}
|
|
16
|
+
deserialize(value) {
|
|
17
|
+
const tempUrl = `http://example.com?${value}`;
|
|
18
|
+
const tempConfig = {
|
|
19
|
+
gridApi: null,
|
|
20
|
+
...DEFAULT_CONFIG
|
|
21
|
+
};
|
|
22
|
+
return parseUrlFilters(tempUrl, tempConfig);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class JsonSerializer {
|
|
26
|
+
format = 'json';
|
|
27
|
+
serialize(filterState) {
|
|
28
|
+
return JSON.stringify(filterState);
|
|
29
|
+
}
|
|
30
|
+
deserialize(value) {
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(value);
|
|
33
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
34
|
+
throw new Error('Invalid JSON: must be an object');
|
|
35
|
+
}
|
|
36
|
+
for (const [columnId, filter] of Object.entries(parsed)) {
|
|
37
|
+
if (typeof columnId !== 'string') {
|
|
38
|
+
throw new Error('Invalid JSON: column IDs must be strings');
|
|
39
|
+
}
|
|
40
|
+
if (!isValidColumnFilter(filter)) {
|
|
41
|
+
throw new Error(`Invalid JSON: filter for column ${columnId} is not a valid filter object`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error(`JSON parsing failed: ${error.message}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class Base64Serializer {
|
|
52
|
+
format = 'base64';
|
|
53
|
+
jsonSerializer = new JsonSerializer();
|
|
54
|
+
serialize(filterState) {
|
|
55
|
+
const jsonString = this.jsonSerializer.serialize(filterState);
|
|
56
|
+
return btoa(jsonString);
|
|
57
|
+
}
|
|
58
|
+
deserialize(value) {
|
|
59
|
+
try {
|
|
60
|
+
const decoded = atob(value);
|
|
61
|
+
return this.jsonSerializer.deserialize(decoded);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw new Error(`Base64 decoding failed: ${error.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=formats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.js","sourceRoot":"","sources":["../../../src/core/serialization/formats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAO5C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAMtD,MAAM,OAAO,qBAAqB;IACvB,MAAM,GAAwB,aAAa,CAAA;IAEpD,SAAS,CAAC,WAAwB;QAEhC,MAAM,UAAU,GAAmB;YACjC,OAAO,EAAE,IAAW;YACpB,GAAG,cAAc;SAClB,CAAA;QAGD,MAAM,OAAO,GAAG,WAAW,CAAC,oBAAoB,EAAE,WAAW,EAAE,UAAU,CAAC,CAAA;QAC1E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;QAG/B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC/B,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GAAG,IAAI,cAAc,EAAE,CAAA;IAE7C,SAAS,CAAC,WAAwB;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;QAC7D,OAAO,IAAI,CAAC,UAAU,CAAC,CAAA;IACzB,CAAC;IAED,WAAW,CAAC,KAAa;QACvB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;YAC3B,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QACjD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,2BAA4B,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;QACxE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FilterState, SerializationFormat, FormatSerializer, GroupedSerializationResult, InternalConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Serialize filter state using grouped serialization
|
|
4
|
+
* @param filterState - The filter state to serialize
|
|
5
|
+
* @param config - Internal configuration
|
|
6
|
+
* @returns Grouped serialization result with parameter name and value
|
|
7
|
+
*/
|
|
8
|
+
export declare function serializeGrouped(filterState: FilterState, config: InternalConfig): GroupedSerializationResult;
|
|
9
|
+
/**
|
|
10
|
+
* Deserialize grouped filter state from URL parameter value
|
|
11
|
+
* @param value - The serialized value from URL parameter
|
|
12
|
+
* @param format - The serialization format to use
|
|
13
|
+
* @param config - Internal configuration for error handling
|
|
14
|
+
* @returns Deserialized filter state
|
|
15
|
+
*/
|
|
16
|
+
export declare function deserializeGrouped(value: string, format: SerializationFormat, config: InternalConfig): FilterState;
|
|
17
|
+
/**
|
|
18
|
+
* Detect if a URL contains grouped serialization parameters
|
|
19
|
+
* @param url - URL to analyze
|
|
20
|
+
* @param possibleParams - Array of possible grouped parameter names to check
|
|
21
|
+
* @returns Detection result with format and value if found
|
|
22
|
+
*/
|
|
23
|
+
export declare function detectGroupedSerialization(url: string, possibleParams: string[]): {
|
|
24
|
+
isGrouped: boolean;
|
|
25
|
+
paramName?: string;
|
|
26
|
+
format?: SerializationFormat;
|
|
27
|
+
value?: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Get all available serialization formats
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAvailableFormats(): SerializationFormat[];
|
|
33
|
+
/**
|
|
34
|
+
* Get a specific format serializer
|
|
35
|
+
*/
|
|
36
|
+
export declare function getFormatSerializer(format: SerializationFormat): FormatSerializer | null;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { InvalidSerializationError } from '../types.js';
|
|
2
|
+
import { QueryStringSerializer, JsonSerializer, Base64Serializer } from './formats.js';
|
|
3
|
+
const FORMAT_SERIALIZERS = {
|
|
4
|
+
querystring: new QueryStringSerializer(),
|
|
5
|
+
json: new JsonSerializer(),
|
|
6
|
+
base64: new Base64Serializer()
|
|
7
|
+
};
|
|
8
|
+
export function serializeGrouped(filterState, config) {
|
|
9
|
+
try {
|
|
10
|
+
const serializer = FORMAT_SERIALIZERS[config.format];
|
|
11
|
+
if (!serializer) {
|
|
12
|
+
throw new Error(`Unknown serialization format: ${config.format}`);
|
|
13
|
+
}
|
|
14
|
+
const value = serializer.serialize(filterState);
|
|
15
|
+
return {
|
|
16
|
+
paramName: config.groupedParam,
|
|
17
|
+
value
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
const serializationError = new InvalidSerializationError(config.format, error);
|
|
22
|
+
config.onParseError(serializationError);
|
|
23
|
+
return {
|
|
24
|
+
paramName: config.groupedParam,
|
|
25
|
+
value: ''
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function deserializeGrouped(value, format, config) {
|
|
30
|
+
try {
|
|
31
|
+
const serializer = FORMAT_SERIALIZERS[format];
|
|
32
|
+
if (!serializer) {
|
|
33
|
+
throw new Error(`Unknown serialization format: ${format}`);
|
|
34
|
+
}
|
|
35
|
+
return serializer.deserialize(value);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const serializationError = new InvalidSerializationError(format, error);
|
|
39
|
+
config.onParseError(serializationError);
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function detectGroupedSerialization(url, possibleParams) {
|
|
44
|
+
try {
|
|
45
|
+
const urlObj = new URL(url);
|
|
46
|
+
for (const paramName of possibleParams) {
|
|
47
|
+
const value = urlObj.searchParams.get(paramName);
|
|
48
|
+
if (value) {
|
|
49
|
+
const format = detectFormat(value);
|
|
50
|
+
if (format) {
|
|
51
|
+
return {
|
|
52
|
+
isGrouped: true,
|
|
53
|
+
paramName,
|
|
54
|
+
format,
|
|
55
|
+
value
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { isGrouped: false };
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error(`Error detecting grouped serialization: ${error}`);
|
|
64
|
+
return { isGrouped: false };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function detectFormat(value) {
|
|
68
|
+
if (isBase64Format(value)) {
|
|
69
|
+
return 'base64';
|
|
70
|
+
}
|
|
71
|
+
if (isJsonFormat(value)) {
|
|
72
|
+
return 'json';
|
|
73
|
+
}
|
|
74
|
+
return 'querystring';
|
|
75
|
+
}
|
|
76
|
+
function isBase64Format(value) {
|
|
77
|
+
try {
|
|
78
|
+
const base64Pattern = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
79
|
+
if (!base64Pattern.test(value)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const decoded = atob(value);
|
|
83
|
+
JSON.parse(decoded);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function isJsonFormat(value) {
|
|
91
|
+
try {
|
|
92
|
+
const parsed = JSON.parse(value);
|
|
93
|
+
return typeof parsed === 'object' && parsed !== null;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export function getAvailableFormats() {
|
|
100
|
+
return Object.keys(FORMAT_SERIALIZERS);
|
|
101
|
+
}
|
|
102
|
+
export function getFormatSerializer(format) {
|
|
103
|
+
return FORMAT_SERIALIZERS[format] || null;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=grouped.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grouped.js","sourceRoot":"","sources":["../../../src/core/serialization/grouped.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EACjB,MAAM,cAAc,CAAA;AAKrB,MAAM,kBAAkB,GAAkD;IACxE,WAAW,EAAE,IAAI,qBAAqB,EAAE;IACxC,IAAI,EAAE,IAAI,cAAc,EAAE;IAC1B,MAAM,EAAE,IAAI,gBAAgB,EAAE;CAC/B,CAAA;AAQD,MAAM,UAAU,gBAAgB,CAC9B,WAAwB,EACxB,MAAsB;IAEtB,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACpD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,iCAAiC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QACnE,CAAC;QAED,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;QAE/C,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,YAAY;YAC9B,KAAK;SACN,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,kBAAkB,GAAG,IAAI,yBA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AO,kBAAkB,CAAC,MAAM,CAAC,IAAI,IAAI,CAAA;AAC3C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization module for ag-grid-url-sync
|
|
3
|
+
* Provides grouped serialization functionality with multiple format support
|
|
4
|
+
*/
|
|
5
|
+
export { serializeGrouped, deserializeGrouped, detectGroupedSerialization, getAvailableFormats, getFormatSerializer } from './grouped.js';
|
|
6
|
+
export { QueryStringSerializer, JsonSerializer, Base64Serializer } from './formats.js';
|
|
7
|
+
export type { FormatSerializer, GroupedSerializationResult, SerializationFormat, SerializationMode } from '../types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/serialization/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EACjB,MAAM,cAAc,CAAA"}
|