ag-grid-url-sync 0.3.0 → 0.5.0
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 +144 -14
- package/dist/core/ag-grid-url-sync.d.ts +13 -0
- package/dist/core/ag-grid-url-sync.js +10 -55
- 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/individual-params.d.ts +19 -0
- package/dist/core/individual-params.js +260 -0
- package/dist/core/individual-params.js.map +1 -0
- package/dist/core/serialization/formats.d.ts +8 -9
- package/dist/core/serialization/formats.js +63 -65
- package/dist/core/serialization/formats.js.map +1 -1
- package/dist/core/serialization/grouped.d.ts +10 -5
- package/dist/core/serialization/grouped.js +4 -51
- 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 +42 -9
- package/dist/core/types.js +0 -118
- package/dist/core/types.js.map +1 -1
- package/dist/core/url-generator.d.ts +10 -7
- package/dist/core/url-generator.js +25 -165
- package/dist/core/url-generator.js.map +1 -1
- package/dist/core/url-parser.d.ts +19 -7
- package/dist/core/url-parser.js +28 -294
- package/dist/core/url-parser.js.map +1 -1
- package/dist/core/validation.d.ts +6 -6
- 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 +103 -1
- package/dist/react/use-ag-grid-url-sync.js +406 -46
- package/dist/react/use-ag-grid-url-sync.js.map +1 -1
- package/package.json +98 -31
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
import { InvalidSerializationError } from '../types.js';
|
|
2
2
|
import { QueryStringSerializer, JsonSerializer, Base64Serializer } from './formats.js';
|
|
3
|
-
/**
|
|
4
|
-
* Registry of available format serializers
|
|
5
|
-
*/
|
|
6
3
|
const FORMAT_SERIALIZERS = {
|
|
7
4
|
querystring: new QueryStringSerializer(),
|
|
8
5
|
json: new JsonSerializer(),
|
|
9
6
|
base64: new Base64Serializer()
|
|
10
7
|
};
|
|
11
|
-
/**
|
|
12
|
-
* Serialize filter state using grouped serialization
|
|
13
|
-
* @param filterState - The filter state to serialize
|
|
14
|
-
* @param config - Internal configuration
|
|
15
|
-
* @returns Grouped serialization result with parameter name and value
|
|
16
|
-
*/
|
|
17
8
|
export function serializeGrouped(filterState, config) {
|
|
18
9
|
try {
|
|
19
10
|
const serializer = FORMAT_SERIALIZERS[config.format];
|
|
20
11
|
if (!serializer) {
|
|
21
12
|
throw new Error(`Unknown serialization format: ${config.format}`);
|
|
22
13
|
}
|
|
23
|
-
const value = serializer.serialize(filterState);
|
|
14
|
+
const value = serializer.serialize(filterState, config);
|
|
24
15
|
return {
|
|
25
16
|
paramName: config.groupedParam,
|
|
26
17
|
value
|
|
@@ -28,50 +19,33 @@ export function serializeGrouped(filterState, config) {
|
|
|
28
19
|
}
|
|
29
20
|
catch (error) {
|
|
30
21
|
const serializationError = new InvalidSerializationError(config.format, error);
|
|
31
|
-
config.onParseError(serializationError);
|
|
32
|
-
// Return empty state on error
|
|
22
|
+
config.onParseError?.(serializationError);
|
|
33
23
|
return {
|
|
34
24
|
paramName: config.groupedParam,
|
|
35
25
|
value: ''
|
|
36
26
|
};
|
|
37
27
|
}
|
|
38
28
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Deserialize grouped filter state from URL parameter value
|
|
41
|
-
* @param value - The serialized value from URL parameter
|
|
42
|
-
* @param format - The serialization format to use
|
|
43
|
-
* @param config - Internal configuration for error handling
|
|
44
|
-
* @returns Deserialized filter state
|
|
45
|
-
*/
|
|
46
29
|
export function deserializeGrouped(value, format, config) {
|
|
47
30
|
try {
|
|
48
31
|
const serializer = FORMAT_SERIALIZERS[format];
|
|
49
32
|
if (!serializer) {
|
|
50
33
|
throw new Error(`Unknown serialization format: ${format}`);
|
|
51
34
|
}
|
|
52
|
-
return serializer.deserialize(value);
|
|
35
|
+
return serializer.deserialize(value, config);
|
|
53
36
|
}
|
|
54
37
|
catch (error) {
|
|
55
38
|
const serializationError = new InvalidSerializationError(format, error);
|
|
56
|
-
config.onParseError(serializationError);
|
|
57
|
-
// Return empty state on error
|
|
39
|
+
config.onParseError?.(serializationError);
|
|
58
40
|
return {};
|
|
59
41
|
}
|
|
60
42
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Detect if a URL contains grouped serialization parameters
|
|
63
|
-
* @param url - URL to analyze
|
|
64
|
-
* @param possibleParams - Array of possible grouped parameter names to check
|
|
65
|
-
* @returns Detection result with format and value if found
|
|
66
|
-
*/
|
|
67
43
|
export function detectGroupedSerialization(url, possibleParams) {
|
|
68
44
|
try {
|
|
69
45
|
const urlObj = new URL(url);
|
|
70
|
-
// Check each possible parameter name
|
|
71
46
|
for (const paramName of possibleParams) {
|
|
72
47
|
const value = urlObj.searchParams.get(paramName);
|
|
73
48
|
if (value) {
|
|
74
|
-
// Try to detect format by attempting to parse
|
|
75
49
|
const format = detectFormat(value);
|
|
76
50
|
if (format) {
|
|
77
51
|
return {
|
|
@@ -90,33 +64,21 @@ export function detectGroupedSerialization(url, possibleParams) {
|
|
|
90
64
|
return { isGrouped: false };
|
|
91
65
|
}
|
|
92
66
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Detect the serialization format of a value
|
|
95
|
-
* @param value - The serialized value
|
|
96
|
-
* @returns The detected format
|
|
97
|
-
*/
|
|
98
67
|
function detectFormat(value) {
|
|
99
|
-
// Try base64 first (most specific)
|
|
100
68
|
if (isBase64Format(value)) {
|
|
101
69
|
return 'base64';
|
|
102
70
|
}
|
|
103
|
-
// Try JSON format
|
|
104
71
|
if (isJsonFormat(value)) {
|
|
105
72
|
return 'json';
|
|
106
73
|
}
|
|
107
74
|
return 'querystring';
|
|
108
75
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Check if value appears to be base64 encoded
|
|
111
|
-
*/
|
|
112
76
|
function isBase64Format(value) {
|
|
113
77
|
try {
|
|
114
|
-
// Base64 pattern check
|
|
115
78
|
const base64Pattern = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
116
79
|
if (!base64Pattern.test(value)) {
|
|
117
80
|
return false;
|
|
118
81
|
}
|
|
119
|
-
// Try to decode and parse as JSON
|
|
120
82
|
const decoded = atob(value);
|
|
121
83
|
JSON.parse(decoded);
|
|
122
84
|
return true;
|
|
@@ -125,9 +87,6 @@ function isBase64Format(value) {
|
|
|
125
87
|
return false;
|
|
126
88
|
}
|
|
127
89
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Check if value appears to be JSON
|
|
130
|
-
*/
|
|
131
90
|
function isJsonFormat(value) {
|
|
132
91
|
try {
|
|
133
92
|
const parsed = JSON.parse(value);
|
|
@@ -137,15 +96,9 @@ function isJsonFormat(value) {
|
|
|
137
96
|
return false;
|
|
138
97
|
}
|
|
139
98
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Get all available serialization formats
|
|
142
|
-
*/
|
|
143
99
|
export function getAvailableFormats() {
|
|
144
100
|
return Object.keys(FORMAT_SERIALIZERS);
|
|
145
101
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Get a specific format serializer
|
|
148
|
-
*/
|
|
149
102
|
export function getFormatSerializer(format) {
|
|
150
103
|
return FORMAT_SERIALIZERS[format] || null;
|
|
151
104
|
}
|
|
@@ -1 +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,C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AAK,CAAC,EAAE,CAAC;QACxB,OAAO,MAAM,CAAA;IACf,CAAC;IAED,OAAO,aAAa,CAAA;AACtB,CAAC;AAKD,SAAS,cAAc,CAAC,KAAa;IACnC,IAAI,CAAC;QAEH,MAAM,aAAa,GAAG,wBAAwB,CAAA;QAC9C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAA;QACd,CAAC;QAGD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACnB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAKD,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAChC,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,CAAA;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAKD,MAAM,UAAU,mBAAmB;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAA0B,CAAA;AACjE,CAAC;AAKD,MAAM,UAAU,mBAAmB,CACjC,MAA2B;IAE3B,OAAO,kBAAkB,CAAC,MAAM,CAAC,IAAI,IAAI,CAAA;AAC3C,CAAC"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serialization module for ag-grid-url-sync
|
|
3
|
-
* Provides grouped serialization functionality with multiple format support
|
|
4
|
-
*/
|
|
5
1
|
export { serializeGrouped, deserializeGrouped, detectGroupedSerialization, getAvailableFormats, getFormatSerializer } from './grouped.js';
|
|
6
2
|
export { QueryStringSerializer, JsonSerializer, Base64Serializer } from './formats.js';
|
|
7
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/serialization/index.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -42,6 +42,10 @@ export interface AGGridUrlSyncConfig {
|
|
|
42
42
|
/**
|
|
43
43
|
* Optional error handler for parsing errors.
|
|
44
44
|
* Allows graceful error handling without breaking the application.
|
|
45
|
+
*
|
|
46
|
+
* In grouped mode, an error that comes from the grouped URL value is an
|
|
47
|
+
* `InvalidSerializationError`, and the original error is in `error.cause`.
|
|
48
|
+
* In individual mode, the same failure arrives with no wrapper.
|
|
45
49
|
*/
|
|
46
50
|
onParseError?: (error: Error) => void;
|
|
47
51
|
/**
|
|
@@ -60,29 +64,48 @@ export interface AGGridUrlSyncConfig {
|
|
|
60
64
|
*/
|
|
61
65
|
format?: SerializationFormat;
|
|
62
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Configuration for URL parsing and serialization operations that don't require GridApi.
|
|
69
|
+
* Use this type when you only need to parse filters from URLs or serialize filters to URLs
|
|
70
|
+
* without actually applying them to a grid.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // Parse filters without a grid instance
|
|
75
|
+
* const config: ParseConfig = {
|
|
76
|
+
* ...DEFAULT_CONFIG,
|
|
77
|
+
* onParseError: (error) => console.error(error)
|
|
78
|
+
* }
|
|
79
|
+
* const filters = parseUrlFilters(url, config)
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export interface ParseConfig extends Required<AGGridUrlSyncConfig> {
|
|
83
|
+
/** AG Grid API instance - not read by parsing/serialization operations */
|
|
84
|
+
gridApi?: AGGridApi | null;
|
|
85
|
+
}
|
|
63
86
|
/**
|
|
64
87
|
* Internal configuration with all required fields and runtime dependencies
|
|
65
88
|
*/
|
|
66
|
-
export interface InternalConfig extends
|
|
89
|
+
export interface InternalConfig extends ParseConfig {
|
|
67
90
|
/** AG Grid API instance for filter operations */
|
|
68
91
|
gridApi: AGGridApi;
|
|
69
92
|
}
|
|
70
93
|
/**
|
|
71
94
|
* Text-only filter operations for string-based filtering
|
|
72
95
|
*/
|
|
73
|
-
export declare const TEXT_ONLY_OPERATIONS: readonly [
|
|
96
|
+
export declare const TEXT_ONLY_OPERATIONS: readonly ['contains', 'notContains', 'startsWith', 'endsWith'];
|
|
74
97
|
/**
|
|
75
98
|
* Number-only filter operations for numeric comparisons
|
|
76
99
|
*/
|
|
77
|
-
export declare const NUMBER_ONLY_OPERATIONS: readonly [
|
|
100
|
+
export declare const NUMBER_ONLY_OPERATIONS: readonly ['lessThan', 'lessThanOrEqual', 'greaterThan', 'greaterThanOrEqual', 'inRange'];
|
|
78
101
|
/**
|
|
79
102
|
* Date-specific filter operations for temporal comparisons
|
|
80
103
|
*/
|
|
81
|
-
export declare const DATE_ONLY_OPERATIONS: readonly [
|
|
104
|
+
export declare const DATE_ONLY_OPERATIONS: readonly ['dateBefore', 'dateBeforeOrEqual', 'dateAfter', 'dateAfterOrEqual', 'dateRange'];
|
|
82
105
|
/**
|
|
83
106
|
* Operations shared across multiple filter types
|
|
84
107
|
*/
|
|
85
|
-
export declare const SHARED_OPERATIONS: readonly [
|
|
108
|
+
export declare const SHARED_OPERATIONS: readonly ['eq', 'notEqual', 'blank', 'notBlank'];
|
|
86
109
|
/**
|
|
87
110
|
* All supported filter operations across text, number, and date filters
|
|
88
111
|
*/
|
|
@@ -276,10 +299,20 @@ export interface GroupedSerializationResult {
|
|
|
276
299
|
* Format-specific serializer interface
|
|
277
300
|
*/
|
|
278
301
|
export interface FormatSerializer {
|
|
279
|
-
/**
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
302
|
+
/**
|
|
303
|
+
* Serialize filter state to string
|
|
304
|
+
* @param config - Caller's configuration. All serializers honour
|
|
305
|
+
* maxValueLength and onParseError. JSON and Base64 drop over-length text
|
|
306
|
+
* values and report them through onParseError (see #213, #207).
|
|
307
|
+
*/
|
|
308
|
+
serialize(filterState: FilterState, config?: ParseConfig): string;
|
|
309
|
+
/**
|
|
310
|
+
* Deserialize string to filter state
|
|
311
|
+
* @param config - Caller's configuration. All serializers honour
|
|
312
|
+
* maxValueLength and onParseError. JSON and Base64 drop over-length text
|
|
313
|
+
* values and report them through onParseError (see #213, #207).
|
|
314
|
+
*/
|
|
315
|
+
deserialize(value: string, config?: ParseConfig): FilterState;
|
|
283
316
|
/** Format identifier */
|
|
284
317
|
format: SerializationFormat;
|
|
285
318
|
}
|
package/dist/core/types.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// FILTER OPERATION DEFINITIONS
|
|
3
|
-
// ============================================================================
|
|
4
|
-
/**
|
|
5
|
-
* Text-only filter operations for string-based filtering
|
|
6
|
-
*/
|
|
7
1
|
export const TEXT_ONLY_OPERATIONS = [
|
|
8
2
|
'contains',
|
|
9
3
|
'notContains',
|
|
10
4
|
'startsWith',
|
|
11
5
|
'endsWith'
|
|
12
6
|
];
|
|
13
|
-
/**
|
|
14
|
-
* Number-only filter operations for numeric comparisons
|
|
15
|
-
*/
|
|
16
7
|
export const NUMBER_ONLY_OPERATIONS = [
|
|
17
8
|
'lessThan',
|
|
18
9
|
'lessThanOrEqual',
|
|
@@ -20,9 +11,6 @@ export const NUMBER_ONLY_OPERATIONS = [
|
|
|
20
11
|
'greaterThanOrEqual',
|
|
21
12
|
'inRange'
|
|
22
13
|
];
|
|
23
|
-
/**
|
|
24
|
-
* Date-specific filter operations for temporal comparisons
|
|
25
|
-
*/
|
|
26
14
|
export const DATE_ONLY_OPERATIONS = [
|
|
27
15
|
'dateBefore',
|
|
28
16
|
'dateBeforeOrEqual',
|
|
@@ -30,93 +18,48 @@ export const DATE_ONLY_OPERATIONS = [
|
|
|
30
18
|
'dateAfterOrEqual',
|
|
31
19
|
'dateRange'
|
|
32
20
|
];
|
|
33
|
-
/**
|
|
34
|
-
* Operations shared across multiple filter types
|
|
35
|
-
*/
|
|
36
21
|
export const SHARED_OPERATIONS = [
|
|
37
22
|
'eq',
|
|
38
23
|
'notEqual',
|
|
39
24
|
'blank',
|
|
40
25
|
'notBlank'
|
|
41
26
|
];
|
|
42
|
-
/**
|
|
43
|
-
* Complete list of valid text filter operations
|
|
44
|
-
*/
|
|
45
27
|
export const TEXT_FILTER_OPERATIONS = [
|
|
46
28
|
...TEXT_ONLY_OPERATIONS,
|
|
47
29
|
...SHARED_OPERATIONS
|
|
48
30
|
];
|
|
49
|
-
/**
|
|
50
|
-
* Complete list of valid number filter operations
|
|
51
|
-
*/
|
|
52
31
|
export const NUMBER_FILTER_OPERATIONS = [
|
|
53
32
|
...NUMBER_ONLY_OPERATIONS,
|
|
54
33
|
...SHARED_OPERATIONS
|
|
55
34
|
];
|
|
56
|
-
/**
|
|
57
|
-
* Valid date filter operations as const array
|
|
58
|
-
*/
|
|
59
35
|
export const DATE_FILTER_OPERATIONS = [
|
|
60
36
|
...DATE_ONLY_OPERATIONS,
|
|
61
37
|
...SHARED_OPERATIONS
|
|
62
38
|
];
|
|
63
|
-
// ============================================================================
|
|
64
|
-
// TYPE GUARDS
|
|
65
|
-
// ============================================================================
|
|
66
|
-
/**
|
|
67
|
-
* Type guard to check if an operation is text-specific
|
|
68
|
-
*/
|
|
69
39
|
export function isTextFilterOperation(op) {
|
|
70
40
|
return TEXT_FILTER_OPERATIONS.includes(op);
|
|
71
41
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Type guard to check if an operation is number-specific
|
|
74
|
-
*/
|
|
75
42
|
export function isNumberFilterOperation(op) {
|
|
76
43
|
return NUMBER_FILTER_OPERATIONS.includes(op);
|
|
77
44
|
}
|
|
78
|
-
/**
|
|
79
|
-
* Type guard to check if an operation is date-specific
|
|
80
|
-
*/
|
|
81
45
|
export function isDateFilterOperation(op) {
|
|
82
46
|
return DATE_FILTER_OPERATIONS.includes(op);
|
|
83
47
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Type guard to check if an operation requires a range (two values)
|
|
86
|
-
*/
|
|
87
48
|
export function isRangeOperation(op) {
|
|
88
49
|
return op === 'inRange' || op === 'dateRange';
|
|
89
50
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Type guard to check if an operation is a blank operation
|
|
92
|
-
*/
|
|
93
51
|
export function isBlankOperation(op) {
|
|
94
52
|
return op === 'blank' || op === 'notBlank';
|
|
95
53
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Type guard to check if a filter is a text filter
|
|
98
|
-
*/
|
|
99
54
|
export function isTextFilter(filter) {
|
|
100
55
|
return filter.filterType === 'text';
|
|
101
56
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Type guard to check if a filter is a number filter
|
|
104
|
-
*/
|
|
105
57
|
export function isNumberFilter(filter) {
|
|
106
58
|
return filter.filterType === 'number';
|
|
107
59
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Type guard to check if a filter is a date filter
|
|
110
|
-
*/
|
|
111
60
|
export function isDateFilter(filter) {
|
|
112
61
|
return filter.filterType === 'date';
|
|
113
62
|
}
|
|
114
|
-
// ============================================================================
|
|
115
|
-
// ERROR TYPES
|
|
116
|
-
// ============================================================================
|
|
117
|
-
/**
|
|
118
|
-
* Base error class for all URL sync operations
|
|
119
|
-
*/
|
|
120
63
|
export class URLSyncError extends Error {
|
|
121
64
|
cause;
|
|
122
65
|
constructor(message, cause) {
|
|
@@ -125,36 +68,24 @@ export class URLSyncError extends Error {
|
|
|
125
68
|
this.name = 'URLSyncError';
|
|
126
69
|
}
|
|
127
70
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Error thrown when filter validation fails
|
|
130
|
-
*/
|
|
131
71
|
export class InvalidFilterError extends URLSyncError {
|
|
132
72
|
constructor(message, cause) {
|
|
133
73
|
super(message, cause);
|
|
134
74
|
this.name = 'InvalidFilterError';
|
|
135
75
|
}
|
|
136
76
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Error thrown when URL parsing fails
|
|
139
|
-
*/
|
|
140
77
|
export class InvalidURLError extends URLSyncError {
|
|
141
78
|
constructor(message, cause) {
|
|
142
79
|
super(message, cause);
|
|
143
80
|
this.name = 'InvalidURLError';
|
|
144
81
|
}
|
|
145
82
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Error thrown when date validation fails
|
|
148
|
-
*/
|
|
149
83
|
export class InvalidDateError extends InvalidFilterError {
|
|
150
84
|
constructor(message, cause) {
|
|
151
85
|
super(message, cause);
|
|
152
86
|
this.name = 'InvalidDateError';
|
|
153
87
|
}
|
|
154
88
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Error thrown when serialization/deserialization fails
|
|
157
|
-
*/
|
|
158
89
|
export class InvalidSerializationError extends Error {
|
|
159
90
|
constructor(format, cause) {
|
|
160
91
|
super(`Invalid ${format} serialization: ${cause.message}`);
|
|
@@ -162,69 +93,34 @@ export class InvalidSerializationError extends Error {
|
|
|
162
93
|
this.cause = cause;
|
|
163
94
|
}
|
|
164
95
|
}
|
|
165
|
-
// ============================================================================
|
|
166
|
-
// OPERATION MAPPINGS
|
|
167
|
-
// ============================================================================
|
|
168
|
-
/**
|
|
169
|
-
* Operation Mapping Strategy:
|
|
170
|
-
*
|
|
171
|
-
* We use three different naming conventions for better user experience:
|
|
172
|
-
*
|
|
173
|
-
* 1. URL Parameters: Short, clean names for URLs (e.g., 'eq', 'neq', 'before', 'after')
|
|
174
|
-
* 2. Internal Types: Consistent naming for our FilterOperation type
|
|
175
|
-
* 3. AG Grid Operations: Exact names expected by AG Grid API (e.g., 'equals', 'notEqual', 'lessThan')
|
|
176
|
-
*
|
|
177
|
-
* This approach keeps URLs readable while maintaining compatibility with AG Grid.
|
|
178
|
-
*/
|
|
179
|
-
/**
|
|
180
|
-
* URL shorthand mappings for cleaner URLs.
|
|
181
|
-
* Maps internal operation names to shorter URL parameter names.
|
|
182
|
-
* Operations not listed here use their internal name as URL param.
|
|
183
|
-
*/
|
|
184
96
|
const URL_SHORTHAND_MAPPINGS = {
|
|
185
|
-
// Shared operations
|
|
186
97
|
notEqual: 'neq',
|
|
187
|
-
// Number operations
|
|
188
98
|
lessThan: 'lt',
|
|
189
99
|
lessThanOrEqual: 'lte',
|
|
190
100
|
greaterThan: 'gt',
|
|
191
101
|
greaterThanOrEqual: 'gte',
|
|
192
102
|
inRange: 'range',
|
|
193
|
-
// Date operations
|
|
194
103
|
dateBefore: 'before',
|
|
195
104
|
dateBeforeOrEqual: 'beforeEq',
|
|
196
105
|
dateAfter: 'after',
|
|
197
106
|
dateAfterOrEqual: 'afterEq',
|
|
198
107
|
dateRange: 'daterange'
|
|
199
108
|
};
|
|
200
|
-
/**
|
|
201
|
-
* AG Grid operation name mappings.
|
|
202
|
-
* Maps internal operation names to AG Grid API operation names.
|
|
203
|
-
* Operations not listed here use their internal name for AG Grid.
|
|
204
|
-
*/
|
|
205
109
|
const AG_GRID_NAME_MAPPINGS = {
|
|
206
|
-
// Shared operations
|
|
207
110
|
eq: 'equals',
|
|
208
|
-
// Date operations (AG Grid uses generic names)
|
|
209
111
|
dateBefore: 'lessThan',
|
|
210
112
|
dateBeforeOrEqual: 'lessThanOrEqual',
|
|
211
113
|
dateAfter: 'greaterThan',
|
|
212
114
|
dateAfterOrEqual: 'greaterThanOrEqual',
|
|
213
115
|
dateRange: 'inRange'
|
|
214
116
|
};
|
|
215
|
-
/**
|
|
216
|
-
* Creates operation mapping tables for URL and AG Grid integration
|
|
217
|
-
*/
|
|
218
117
|
function createOperationMaps() {
|
|
219
|
-
// Get all unique operations across filter types
|
|
220
118
|
const allOperations = [
|
|
221
119
|
...TEXT_FILTER_OPERATIONS,
|
|
222
120
|
...NUMBER_FILTER_OPERATIONS,
|
|
223
121
|
...DATE_FILTER_OPERATIONS
|
|
224
122
|
];
|
|
225
|
-
// Remove duplicates (operations like 'eq', 'blank' appear in multiple arrays)
|
|
226
123
|
const uniqueOperations = [...new Set(allOperations)];
|
|
227
|
-
// Generate URL mappings (bidirectional)
|
|
228
124
|
const operationMap = {};
|
|
229
125
|
const internalToUrlMap = {};
|
|
230
126
|
uniqueOperations.forEach(operation => {
|
|
@@ -232,7 +128,6 @@ function createOperationMaps() {
|
|
|
232
128
|
operationMap[urlName] = operation;
|
|
233
129
|
internalToUrlMap[operation] = urlName;
|
|
234
130
|
});
|
|
235
|
-
// Generate AG Grid mappings (bidirectional)
|
|
236
131
|
const agGridMap = {};
|
|
237
132
|
const reverseAgGridMap = {};
|
|
238
133
|
uniqueOperations.forEach(operation => {
|
|
@@ -248,22 +143,9 @@ function createOperationMaps() {
|
|
|
248
143
|
reverseAgGridMap
|
|
249
144
|
};
|
|
250
145
|
}
|
|
251
|
-
// Generate all mappings dynamically
|
|
252
146
|
const mappings = createOperationMaps();
|
|
253
|
-
/**
|
|
254
|
-
* Maps URL operation names to internal operation types
|
|
255
|
-
*/
|
|
256
147
|
export const OPERATION_MAP = mappings.operationMap;
|
|
257
|
-
/**
|
|
258
|
-
* Maps internal operation types to URL operation names
|
|
259
|
-
*/
|
|
260
148
|
export const INTERNAL_TO_URL_OPERATION_MAP = mappings.internalToUrlMap;
|
|
261
|
-
/**
|
|
262
|
-
* Maps internal operation types to AG Grid operation names
|
|
263
|
-
*/
|
|
264
149
|
export const AG_GRID_OPERATION_NAMES = mappings.agGridMap;
|
|
265
|
-
/**
|
|
266
|
-
* Maps AG Grid operation names to internal operation types
|
|
267
|
-
*/
|
|
268
150
|
export const REVERSE_AG_GRID_OPERATION_NAMES = mappings.reverseAgGridMap;
|
|
269
151
|
//# sourceMappingURL=types.js.map
|
package/dist/core/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAuHA,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,UAAU;IACV,aAAa;IACb,YAAY;IACZ,UAAU;CACF,CAAA;AAKV,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,UAAU;IACV,iBAAiB;IACjB,aAAa;IACb,oBAAoB;IACpB,SAAS;CACD,CAAA;AAKV,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,YAAY;IACZ,mBAAmB;IACnB,WAAW;IACX,kBAAkB;IAClB,WAAW;CACH,CAAA;AAKV,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI;IACJ,UAAU;IACV,OAAO;IACP,UAAU;CACF,CAAA;AAcV,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,GAAG,oBAAoB;IACvB,GAAG,iBAAiB;CACZ,CAAA;AAKV,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,GAAG,sBAAsB;IACzB,GAAG,iBAAiB;CACZ,CAAA;AAKV,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,GAAG,oBAAoB;IACvB,GAAG,iBAAiB;CACZ,CAAA;AAyGV,MAAM,UAAU,qBAAqB,CACnC,EAAmB;IAEnB,OAAO,sBAAsB,CAAC,QAAQ,CAAC,EAAyB,CAAC,CAAA;AACnE,CAAC;AAKD,MAAM,UAAU,uBAAuB,CACrC,EAAmB;IAEnB,OAAO,wBAAwB,CAAC,QAAQ,CAAC,EAA2B,CAAC,CAAA;AACvE,CAAC;AAKD,MAAM,UAAU,qBAAqB,CACnC,EAAmB;IAEnB,OAAO,sBAAsB,CAAC,QAAQ,CAAC,EAAyB,CAAC,CAAA;AACnE,CAAC;AAKD,MAAM,UAAU,gBAAgB,CAAC,EAAmB;IAClD,O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CAAA;IACvC,CAAC,CAAC,CAAA;IAGF,MAAM,SAAS,GAA2B,EAAE,CAAA;IAC5C,MAAM,gBAAgB,GAAoC,EAAE,CAAA;IAE5D,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QACnC,MAAM,UAAU,GACd,qBAAqB,CAAC,SAA+C,CAAC;YACtE,SAAS,CAAA;QACX,SAAS,CAAC,SAAS,CAAC,GAAG,UAAU,CAAA;QACjC,gBAAgB,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;IAC1C,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,YAAY;QACZ,gBAAgB;QAChB,SAAS;QACT,gBAAgB;KACR,CAAA;AACZ,CAAC;AAGD,MAAM,QAAQ,GAAG,mBAAmB,EAAE,CAAA;AAKtC,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC,YAAY,CAAA;AAKlD,MAAM,CAAC,MAAM,6BAA6B,GAAG,QAAQ,CAAC,gBAAgB,CAAA;AAKtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,QAAQ,CAAC,SAAS,CAAA;AAKzD,MAAM,CAAC,MAAM,+BAA+B,GAAG,QAAQ,CAAC,gBAAgB,CAAA"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { FilterState,
|
|
1
|
+
import type { FilterState, ParseConfig } from './types.js';
|
|
2
|
+
import { serializeFilters } from './individual-params.js';
|
|
3
|
+
export { serializeFilters };
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
5
|
+
* Generates a URL with the current filter state.
|
|
6
|
+
* This function does not require a GridApi instance: leave `config.gridApi` out
|
|
7
|
+
* (or set it to `null`) when you only need to generate URLs without a grid.
|
|
8
|
+
*
|
|
9
|
+
* The host app's own params are kept, including repeated keys. Filter params
|
|
10
|
+
* from either mode are replaced.
|
|
4
11
|
*/
|
|
5
|
-
export declare function
|
|
6
|
-
/**
|
|
7
|
-
* Generates a URL with the current filter state
|
|
8
|
-
*/
|
|
9
|
-
export declare function generateUrl(baseUrl: string, filterState: FilterState, config: InternalConfig): string;
|
|
12
|
+
export declare function generateUrl(baseUrl: string, filterState: FilterState, config: ParseConfig): string;
|