ag-grid-url-sync 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -22
- package/dist/core/grid-integration.d.ts +1 -1
- package/dist/core/grid-integration.js +101 -6
- package/dist/core/grid-integration.js.map +1 -1
- package/dist/core/types.d.ts +174 -36
- package/dist/core/types.js +179 -37
- package/dist/core/types.js.map +1 -1
- package/dist/core/url-generator.js +53 -15
- package/dist/core/url-generator.js.map +1 -1
- package/dist/core/url-parser.js +164 -35
- package/dist/core/url-parser.js.map +1 -1
- package/dist/core/validation.d.ts +38 -5
- package/dist/core/validation.js +115 -3
- package/dist/core/validation.js.map +1 -1
- package/dist/react/types.d.ts +5 -0
- package/dist/react/use-ag-grid-url-sync.js +42 -27
- package/dist/react/use-ag-grid-url-sync.js.map +1 -1
- package/package.json +2 -2
package/dist/core/types.js
CHANGED
|
@@ -1,89 +1,220 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// FILTER OPERATION DEFINITIONS
|
|
3
|
+
// ============================================================================
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
5
|
+
* Text-only filter operations for string-based filtering
|
|
3
6
|
*/
|
|
4
|
-
export const
|
|
7
|
+
export const TEXT_ONLY_OPERATIONS = [
|
|
5
8
|
'contains',
|
|
6
|
-
'eq',
|
|
7
9
|
'notContains',
|
|
8
|
-
'notEqual',
|
|
9
10
|
'startsWith',
|
|
10
|
-
'endsWith'
|
|
11
|
-
'blank',
|
|
12
|
-
'notBlank'
|
|
11
|
+
'endsWith'
|
|
13
12
|
];
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
14
|
+
* Number-only filter operations for numeric comparisons
|
|
16
15
|
*/
|
|
17
|
-
export const
|
|
18
|
-
'eq',
|
|
19
|
-
'notEqual',
|
|
16
|
+
export const NUMBER_ONLY_OPERATIONS = [
|
|
20
17
|
'lessThan',
|
|
21
18
|
'lessThanOrEqual',
|
|
22
19
|
'greaterThan',
|
|
23
20
|
'greaterThanOrEqual',
|
|
24
|
-
'inRange'
|
|
21
|
+
'inRange'
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Date-specific filter operations for temporal comparisons
|
|
25
|
+
*/
|
|
26
|
+
export const DATE_ONLY_OPERATIONS = [
|
|
27
|
+
'dateBefore',
|
|
28
|
+
'dateBeforeOrEqual',
|
|
29
|
+
'dateAfter',
|
|
30
|
+
'dateAfterOrEqual',
|
|
31
|
+
'dateRange'
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Operations shared across multiple filter types
|
|
35
|
+
*/
|
|
36
|
+
export const SHARED_OPERATIONS = [
|
|
37
|
+
'eq',
|
|
38
|
+
'notEqual',
|
|
25
39
|
'blank',
|
|
26
40
|
'notBlank'
|
|
27
41
|
];
|
|
28
42
|
/**
|
|
29
|
-
*
|
|
43
|
+
* Complete list of valid text filter operations
|
|
44
|
+
*/
|
|
45
|
+
export const TEXT_FILTER_OPERATIONS = [
|
|
46
|
+
...TEXT_ONLY_OPERATIONS,
|
|
47
|
+
...SHARED_OPERATIONS
|
|
48
|
+
];
|
|
49
|
+
/**
|
|
50
|
+
* Complete list of valid number filter operations
|
|
51
|
+
*/
|
|
52
|
+
export const NUMBER_FILTER_OPERATIONS = [
|
|
53
|
+
...NUMBER_ONLY_OPERATIONS,
|
|
54
|
+
...SHARED_OPERATIONS
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* Valid date filter operations as const array
|
|
58
|
+
*/
|
|
59
|
+
export const DATE_FILTER_OPERATIONS = [
|
|
60
|
+
...DATE_ONLY_OPERATIONS,
|
|
61
|
+
...SHARED_OPERATIONS
|
|
62
|
+
];
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// TYPE GUARDS
|
|
65
|
+
// ============================================================================
|
|
66
|
+
/**
|
|
67
|
+
* Type guard to check if an operation is text-specific
|
|
68
|
+
*/
|
|
69
|
+
export function isTextFilterOperation(op) {
|
|
70
|
+
return TEXT_FILTER_OPERATIONS.includes(op);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Type guard to check if an operation is number-specific
|
|
74
|
+
*/
|
|
75
|
+
export function isNumberFilterOperation(op) {
|
|
76
|
+
return NUMBER_FILTER_OPERATIONS.includes(op);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Type guard to check if an operation is date-specific
|
|
80
|
+
*/
|
|
81
|
+
export function isDateFilterOperation(op) {
|
|
82
|
+
return DATE_FILTER_OPERATIONS.includes(op);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Type guard to check if an operation requires a range (two values)
|
|
86
|
+
*/
|
|
87
|
+
export function isRangeOperation(op) {
|
|
88
|
+
return op === 'inRange' || op === 'dateRange';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Type guard to check if an operation is a blank operation
|
|
92
|
+
*/
|
|
93
|
+
export function isBlankOperation(op) {
|
|
94
|
+
return op === 'blank' || op === 'notBlank';
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Type guard to check if a filter is a text filter
|
|
98
|
+
*/
|
|
99
|
+
export function isTextFilter(filter) {
|
|
100
|
+
return filter.filterType === 'text';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Type guard to check if a filter is a number filter
|
|
104
|
+
*/
|
|
105
|
+
export function isNumberFilter(filter) {
|
|
106
|
+
return filter.filterType === 'number';
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Type guard to check if a filter is a date filter
|
|
110
|
+
*/
|
|
111
|
+
export function isDateFilter(filter) {
|
|
112
|
+
return filter.filterType === 'date';
|
|
113
|
+
}
|
|
114
|
+
// ============================================================================
|
|
115
|
+
// ERROR TYPES
|
|
116
|
+
// ============================================================================
|
|
117
|
+
/**
|
|
118
|
+
* Base error class for all URL sync operations
|
|
30
119
|
*/
|
|
31
120
|
export class URLSyncError extends Error {
|
|
32
|
-
|
|
121
|
+
cause;
|
|
122
|
+
constructor(message, cause) {
|
|
33
123
|
super(message);
|
|
124
|
+
this.cause = cause;
|
|
34
125
|
this.name = 'URLSyncError';
|
|
35
126
|
}
|
|
36
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Error thrown when filter validation fails
|
|
130
|
+
*/
|
|
37
131
|
export class InvalidFilterError extends URLSyncError {
|
|
38
|
-
constructor(message) {
|
|
39
|
-
super(message);
|
|
132
|
+
constructor(message, cause) {
|
|
133
|
+
super(message, cause);
|
|
40
134
|
this.name = 'InvalidFilterError';
|
|
41
135
|
}
|
|
42
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Error thrown when URL parsing fails
|
|
139
|
+
*/
|
|
43
140
|
export class InvalidURLError extends URLSyncError {
|
|
44
|
-
constructor(message) {
|
|
45
|
-
super(message);
|
|
141
|
+
constructor(message, cause) {
|
|
142
|
+
super(message, cause);
|
|
46
143
|
this.name = 'InvalidURLError';
|
|
47
144
|
}
|
|
48
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Error thrown when date validation fails
|
|
148
|
+
*/
|
|
149
|
+
export class InvalidDateError extends InvalidFilterError {
|
|
150
|
+
constructor(message, cause) {
|
|
151
|
+
super(message, cause);
|
|
152
|
+
this.name = 'InvalidDateError';
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// ============================================================================
|
|
156
|
+
// OPERATION MAPPINGS
|
|
157
|
+
// ============================================================================
|
|
49
158
|
/**
|
|
50
159
|
* Operation Mapping Strategy:
|
|
51
160
|
*
|
|
52
161
|
* We use three different naming conventions for better user experience:
|
|
53
162
|
*
|
|
54
|
-
* 1. URL Parameters: Short, clean names for URLs (e.g., 'eq', 'neq', '
|
|
163
|
+
* 1. URL Parameters: Short, clean names for URLs (e.g., 'eq', 'neq', 'before', 'after')
|
|
55
164
|
* 2. Internal Types: Consistent naming for our FilterOperation type
|
|
56
|
-
* 3. AG Grid Operations: Exact names expected by AG Grid API (e.g., 'equals', 'notEqual')
|
|
165
|
+
* 3. AG Grid Operations: Exact names expected by AG Grid API (e.g., 'equals', 'notEqual', 'lessThan')
|
|
57
166
|
*
|
|
58
167
|
* This approach keeps URLs readable while maintaining compatibility with AG Grid.
|
|
59
168
|
*/
|
|
60
169
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
170
|
+
* URL shorthand mappings for cleaner URLs.
|
|
171
|
+
* Maps internal operation names to shorter URL parameter names.
|
|
172
|
+
* Operations not listed here use their internal name as URL param.
|
|
63
173
|
*/
|
|
64
174
|
const URL_SHORTHAND_MAPPINGS = {
|
|
175
|
+
// Shared operations
|
|
65
176
|
notEqual: 'neq',
|
|
177
|
+
// Number operations
|
|
66
178
|
lessThan: 'lt',
|
|
67
179
|
lessThanOrEqual: 'lte',
|
|
68
180
|
greaterThan: 'gt',
|
|
69
181
|
greaterThanOrEqual: 'gte',
|
|
70
|
-
inRange: 'range'
|
|
182
|
+
inRange: 'range',
|
|
183
|
+
// Date operations
|
|
184
|
+
dateBefore: 'before',
|
|
185
|
+
dateBeforeOrEqual: 'beforeEq',
|
|
186
|
+
dateAfter: 'after',
|
|
187
|
+
dateAfterOrEqual: 'afterEq',
|
|
188
|
+
dateRange: 'daterange'
|
|
71
189
|
};
|
|
72
190
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
191
|
+
* AG Grid operation name mappings.
|
|
192
|
+
* Maps internal operation names to AG Grid API operation names.
|
|
193
|
+
* Operations not listed here use their internal name for AG Grid.
|
|
75
194
|
*/
|
|
76
195
|
const AG_GRID_NAME_MAPPINGS = {
|
|
77
|
-
|
|
196
|
+
// Shared operations
|
|
197
|
+
eq: 'equals',
|
|
198
|
+
// Date operations (AG Grid uses generic names)
|
|
199
|
+
dateBefore: 'lessThan',
|
|
200
|
+
dateBeforeOrEqual: 'lessThanOrEqual',
|
|
201
|
+
dateAfter: 'greaterThan',
|
|
202
|
+
dateAfterOrEqual: 'greaterThanOrEqual',
|
|
203
|
+
dateRange: 'inRange'
|
|
78
204
|
};
|
|
79
205
|
/**
|
|
80
|
-
*
|
|
206
|
+
* Creates operation mapping tables for URL and AG Grid integration
|
|
81
207
|
*/
|
|
82
208
|
function createOperationMaps() {
|
|
83
|
-
|
|
84
|
-
|
|
209
|
+
// Get all unique operations across filter types
|
|
210
|
+
const allOperations = [
|
|
211
|
+
...TEXT_FILTER_OPERATIONS,
|
|
212
|
+
...NUMBER_FILTER_OPERATIONS,
|
|
213
|
+
...DATE_FILTER_OPERATIONS
|
|
214
|
+
];
|
|
215
|
+
// Remove duplicates (operations like 'eq', 'blank' appear in multiple arrays)
|
|
85
216
|
const uniqueOperations = [...new Set(allOperations)];
|
|
86
|
-
// Generate URL mappings
|
|
217
|
+
// Generate URL mappings (bidirectional)
|
|
87
218
|
const operationMap = {};
|
|
88
219
|
const internalToUrlMap = {};
|
|
89
220
|
uniqueOperations.forEach(operation => {
|
|
@@ -91,7 +222,7 @@ function createOperationMaps() {
|
|
|
91
222
|
operationMap[urlName] = operation;
|
|
92
223
|
internalToUrlMap[operation] = urlName;
|
|
93
224
|
});
|
|
94
|
-
// Generate AG Grid mappings
|
|
225
|
+
// Generate AG Grid mappings (bidirectional)
|
|
95
226
|
const agGridMap = {};
|
|
96
227
|
const reverseAgGridMap = {};
|
|
97
228
|
uniqueOperations.forEach(operation => {
|
|
@@ -108,10 +239,21 @@ function createOperationMaps() {
|
|
|
108
239
|
};
|
|
109
240
|
}
|
|
110
241
|
// Generate all mappings dynamically
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
export const
|
|
116
|
-
|
|
242
|
+
const mappings = createOperationMaps();
|
|
243
|
+
/**
|
|
244
|
+
* Maps URL operation names to internal operation types
|
|
245
|
+
*/
|
|
246
|
+
export const OPERATION_MAP = mappings.operationMap;
|
|
247
|
+
/**
|
|
248
|
+
* Maps internal operation types to URL operation names
|
|
249
|
+
*/
|
|
250
|
+
export const INTERNAL_TO_URL_OPERATION_MAP = mappings.internalToUrlMap;
|
|
251
|
+
/**
|
|
252
|
+
* Maps internal operation types to AG Grid operation names
|
|
253
|
+
*/
|
|
254
|
+
export const AG_GRID_OPERATION_NAMES = mappings.agGridMap;
|
|
255
|
+
/**
|
|
256
|
+
* Maps AG Grid operation names to internal operation types
|
|
257
|
+
*/
|
|
258
|
+
export const REVERSE_AG_GRID_OPERATION_NAMES = mappings.reverseAgGridMap;
|
|
117
259
|
//# 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":"AAoDA,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,UAAU;IACV,aAAa;IACb,YAAY;IACZ,UAAU;CACF,CAAA;AAEV;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,UAAU;IACV,iBAAiB;IACjB,aAAa;IACb,oBAAoB;IACpB,SAAS;CACD,CAAA;AAEV;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,YAAY;IACZ,mBAAmB;IACnB,WAAW;IACX,kBAAkB;IAClB,WAAW;CACH,CAAA;AAEV;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI;IACJ,UAAU;IACV,OAAO;IACP,UAAU;CACF,CAAA;AAWV;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,GAAG,oBAAoB;IACvB,GAAG,iBAAiB;CACZ,CAAA;AAEV;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,GAAG,sBAAsB;IACzB,GAAG,iBAAiB;CACZ,CAAA;AAEV;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG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;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,QAAQ,CAAC,gBAAgB,CAAA;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,QAAQ,CAAC,SAAS,CAAA;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,QAAQ,CAAC,gBAAgB,CAAA"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { validateFilterValue } from './validation.js';
|
|
2
2
|
import { INTERNAL_TO_URL_OPERATION_MAP } from './types.js';
|
|
3
|
+
const FILTER_TYPES = {
|
|
4
|
+
TEXT: 'text',
|
|
5
|
+
NUMBER: 'number',
|
|
6
|
+
DATE: 'date'
|
|
7
|
+
};
|
|
3
8
|
/**
|
|
4
9
|
* Serializes a single column filter to URL parameter
|
|
5
10
|
*/
|
|
@@ -8,8 +13,17 @@ function serializeColumnFilter(columnName, filter, paramPrefix) {
|
|
|
8
13
|
if (!urlOperation)
|
|
9
14
|
return '';
|
|
10
15
|
const paramName = `${paramPrefix}${columnName}_${urlOperation}`;
|
|
11
|
-
// Handle range operations
|
|
12
|
-
if (filter.type === '
|
|
16
|
+
// Handle date range operations
|
|
17
|
+
if (filter.type === 'dateRange' && filter.filterType === FILTER_TYPES.DATE) {
|
|
18
|
+
// Type guard: ensure this is a DateColumnFilter with dateRange operation
|
|
19
|
+
if ('filterTo' in filter && filter.filterTo !== undefined) {
|
|
20
|
+
// Don't encode the comma for range values - handle this directly
|
|
21
|
+
return `${paramName}=${filter.filter},${filter.filterTo}`;
|
|
22
|
+
}
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
// Handle number range operations
|
|
26
|
+
if (filter.type === 'inRange' && filter.filterType === FILTER_TYPES.NUMBER) {
|
|
13
27
|
// Type guard: ensure this is a NumberColumnFilter with inRange operation
|
|
14
28
|
if ('filterTo' in filter && filter.filterTo !== undefined) {
|
|
15
29
|
// Don't encode the comma for range values - handle this directly
|
|
@@ -17,16 +31,20 @@ function serializeColumnFilter(columnName, filter, paramPrefix) {
|
|
|
17
31
|
}
|
|
18
32
|
return '';
|
|
19
33
|
}
|
|
20
|
-
// Handle blank operations
|
|
34
|
+
// Handle blank operations (shared across text, number, and date)
|
|
21
35
|
if (filter.type === 'blank' || filter.type === 'notBlank') {
|
|
22
36
|
return `${paramName}=true`;
|
|
23
37
|
}
|
|
38
|
+
// Handle date operations (ISO date format preservation)
|
|
39
|
+
if (filter.filterType === FILTER_TYPES.DATE) {
|
|
40
|
+
return `${paramName}=${filter.filter}`; // ISO dates don't need URL encoding
|
|
41
|
+
}
|
|
24
42
|
// Handle number operations
|
|
25
|
-
if (filter.filterType ===
|
|
43
|
+
if (filter.filterType === FILTER_TYPES.NUMBER) {
|
|
26
44
|
return `${paramName}=${filter.filter}`;
|
|
27
45
|
}
|
|
28
46
|
// Handle text operations (existing logic)
|
|
29
|
-
if (filter.filterType ===
|
|
47
|
+
if (filter.filterType === FILTER_TYPES.TEXT && filter.filter) {
|
|
30
48
|
// Note: Validation should be done at the serializeFilters level, not here
|
|
31
49
|
return `${paramName}=${encodeURIComponent(filter.filter.toString())}`;
|
|
32
50
|
}
|
|
@@ -35,11 +53,17 @@ function serializeColumnFilter(columnName, filter, paramPrefix) {
|
|
|
35
53
|
/**
|
|
36
54
|
* Helper function to append a serialized parameter to URLSearchParams
|
|
37
55
|
*/
|
|
38
|
-
function appendSerializedParam(serialized, params) {
|
|
56
|
+
function appendSerializedParam(serialized, params, isRangeOperation = false) {
|
|
39
57
|
const [paramName, paramValue] = serialized.split('=');
|
|
40
58
|
if (paramName && paramValue) {
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
if (isRangeOperation) {
|
|
60
|
+
// For range operations (which contain commas), don't decode
|
|
61
|
+
params.append(paramName, paramValue);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// For regular operations, decode special characters for text filters
|
|
65
|
+
params.append(paramName, decodeURIComponent(paramValue));
|
|
66
|
+
}
|
|
43
67
|
}
|
|
44
68
|
}
|
|
45
69
|
/**
|
|
@@ -48,23 +72,27 @@ function appendSerializedParam(serialized, params) {
|
|
|
48
72
|
export function serializeFilters(filterState, config) {
|
|
49
73
|
const params = new URLSearchParams();
|
|
50
74
|
for (const [column, filter] of Object.entries(filterState)) {
|
|
51
|
-
// Support
|
|
52
|
-
if (filter.filterType !==
|
|
75
|
+
// Support text, number, and date filters
|
|
76
|
+
if (filter.filterType !== FILTER_TYPES.TEXT &&
|
|
77
|
+
filter.filterType !== FILTER_TYPES.NUMBER &&
|
|
78
|
+
filter.filterType !== FILTER_TYPES.DATE)
|
|
53
79
|
continue;
|
|
54
80
|
// Apply validation for text filters before serialization
|
|
55
|
-
if (filter.filterType ===
|
|
81
|
+
if (filter.filterType === FILTER_TYPES.TEXT) {
|
|
56
82
|
const validatedValue = validateFilterValue(filter.filter, config, filter.type);
|
|
57
83
|
const updatedFilter = { ...filter, filter: validatedValue };
|
|
58
84
|
const serialized = serializeColumnFilter(column, updatedFilter, config.paramPrefix);
|
|
59
85
|
if (serialized) {
|
|
60
|
-
appendSerializedParam(serialized, params);
|
|
86
|
+
appendSerializedParam(serialized, params, false); // Text filters are not range operations
|
|
61
87
|
}
|
|
62
88
|
}
|
|
63
89
|
else {
|
|
64
|
-
// Number filters don't need additional validation as they're already validated
|
|
90
|
+
// Number and date filters don't need additional validation as they're already validated
|
|
65
91
|
const serialized = serializeColumnFilter(column, filter, config.paramPrefix);
|
|
66
92
|
if (serialized) {
|
|
67
|
-
|
|
93
|
+
// Check if this is a range operation
|
|
94
|
+
const isRangeOp = filter.type === 'inRange' || filter.type === 'dateRange';
|
|
95
|
+
appendSerializedParam(serialized, params, isRangeOp);
|
|
68
96
|
}
|
|
69
97
|
}
|
|
70
98
|
}
|
|
@@ -82,7 +110,17 @@ export function generateUrl(baseUrl, filterState, config) {
|
|
|
82
110
|
filterParams.append(key, value);
|
|
83
111
|
}
|
|
84
112
|
}
|
|
85
|
-
|
|
113
|
+
const queryString = filterParams.toString();
|
|
114
|
+
// If no filters, return the base URL without query string or trailing slash
|
|
115
|
+
if (!queryString) {
|
|
116
|
+
let result = url.toString().replace(/\?$/, '');
|
|
117
|
+
// Remove trailing slash for root paths when no query parameters
|
|
118
|
+
if (result.endsWith('/') && result === url.origin + '/') {
|
|
119
|
+
result = result.slice(0, -1);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
url.search = queryString;
|
|
86
124
|
return url.toString();
|
|
87
125
|
}
|
|
88
126
|
//# sourceMappingURL=url-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-generator.js","sourceRoot":"","sources":["../../src/core/url-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAA;AAE1D;;GAEG;AACH,SAAS,qBAAqB,CAC5B,UAAkB,EAClB,MAAoB,EACpB,WAAmB;IAEnB,MAAM,YAAY,GAChB,6BAA6B,CAC3B,MAAM,CAAC,IAAkD,CAC1D,CAAA;IACH,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAA;IAE5B,MAAM,SAAS,GAAG,GAAG,WAAW,GAAG,UAAU,IAAI,YAAY,EAAE,CAAA;IAE/D,
|
|
1
|
+
{"version":3,"file":"url-generator.js","sourceRoot":"","sources":["../../src/core/url-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAA;AAE1D,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAA;AAEV;;GAEG;AACH,SAAS,qBAAqB,CAC5B,UAAkB,EAClB,MAAoB,EACpB,WAAmB;IAEnB,MAAM,YAAY,GAChB,6BAA6B,C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