ag-grid-url-sync 0.4.1 → 0.5.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.
Files changed (58) hide show
  1. package/README.md +143 -50
  2. package/dist/core/ag-grid-url-sync.d.ts +19 -5
  3. package/dist/core/ag-grid-url-sync.js +28 -17
  4. package/dist/core/ag-grid-url-sync.js.map +1 -1
  5. package/dist/core/grid-integration.d.ts +27 -1
  6. package/dist/core/grid-integration.js +161 -129
  7. package/dist/core/grid-integration.js.map +1 -1
  8. package/dist/core/index.d.ts +2 -1
  9. package/dist/core/index.js +2 -1
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/core/individual-params.d.ts +26 -0
  12. package/dist/core/individual-params.js +236 -0
  13. package/dist/core/individual-params.js.map +1 -0
  14. package/dist/core/issue-columns.d.ts +2 -0
  15. package/dist/core/issue-columns.js +11 -0
  16. package/dist/core/issue-columns.js.map +1 -0
  17. package/dist/core/issues.d.ts +34 -0
  18. package/dist/core/issues.js +58 -0
  19. package/dist/core/issues.js.map +1 -0
  20. package/dist/core/operators.d.ts +189 -0
  21. package/dist/core/operators.js +60 -0
  22. package/dist/core/operators.js.map +1 -0
  23. package/dist/core/options.d.ts +21 -0
  24. package/dist/core/options.js +21 -0
  25. package/dist/core/options.js.map +1 -0
  26. package/dist/core/schemas.d.ts +51 -0
  27. package/dist/core/schemas.js +59 -0
  28. package/dist/core/schemas.js.map +1 -0
  29. package/dist/core/serialization/formats.d.ts +8 -9
  30. package/dist/core/serialization/formats.js +70 -47
  31. package/dist/core/serialization/formats.js.map +1 -1
  32. package/dist/core/serialization/grouped.d.ts +13 -11
  33. package/dist/core/serialization/grouped.js +24 -17
  34. package/dist/core/serialization/grouped.js.map +1 -1
  35. package/dist/core/to-error.d.ts +5 -0
  36. package/dist/core/to-error.js +4 -0
  37. package/dist/core/to-error.js.map +1 -0
  38. package/dist/core/types.d.ts +172 -33
  39. package/dist/core/types.js +35 -108
  40. package/dist/core/types.js.map +1 -1
  41. package/dist/core/url-generator.d.ts +10 -7
  42. package/dist/core/url-generator.js +29 -121
  43. package/dist/core/url-generator.js.map +1 -1
  44. package/dist/core/url-parser.d.ts +19 -7
  45. package/dist/core/url-parser.js +31 -239
  46. package/dist/core/url-parser.js.map +1 -1
  47. package/dist/core/validation.d.ts +21 -14
  48. package/dist/core/validation.js +58 -54
  49. package/dist/core/validation.js.map +1 -1
  50. package/dist/core/view-storage.js +21 -19
  51. package/dist/core/view-storage.js.map +1 -1
  52. package/dist/index.d.ts +2 -1
  53. package/dist/index.js +2 -1
  54. package/dist/index.js.map +1 -1
  55. package/dist/react/types.d.ts +36 -11
  56. package/dist/react/use-ag-grid-url-sync.js +151 -97
  57. package/dist/react/use-ag-grid-url-sync.js.map +1 -1
  58. package/package.json +35 -16
@@ -1,4 +1,5 @@
1
1
  import type { GridApi as AGGridApi, TextFilterModel, NumberFilterModel, DateFilterModel } from 'ag-grid-community';
2
+ import { type Operator, type OperationsFor } from './operators.js';
2
3
  /**
3
4
  * Serialization modes for URL parameters
4
5
  */
@@ -29,64 +30,124 @@ export type SerializationFormat = 'querystring' | 'json' | 'base64';
29
30
  */
30
31
  export interface AGGridUrlSyncConfig {
31
32
  /**
32
- * Prefix for URL parameters (only used in individual mode)
33
+ * Prefix for URL parameters (only used in individual mode).
34
+ * A prefix without a trailing `_` gets one, so 'filter' and 'filter_' both
35
+ * give `?filter_name_contains=john`. An empty prefix means the default.
33
36
  * @default 'f_'
34
37
  * @example 'filter_' results in URLs like '?filter_name_contains=john'
35
38
  */
36
- paramPrefix?: string;
39
+ paramPrefix?: string | undefined;
37
40
  /**
38
41
  * Maximum length for filter values to prevent URL length issues
39
42
  * @default 200
40
43
  */
41
- maxValueLength?: number;
44
+ maxValueLength?: number | undefined;
42
45
  /**
43
- * Optional error handler for parsing errors.
44
- * Allows graceful error handling without breaking the application.
46
+ * Optional handler for issues: a filter that is dropped or not valid, in a
47
+ * URL, a value, or the grid model. The filter is skipped and the others are
48
+ * kept. Each error is a `URLSyncError` with a `code` (for example
49
+ * `VALUE_TOO_LONG`) and, when it is known, a `column`. In the core, an error
50
+ * from the grid API also comes here, as `GRID_ERROR` (the React hook sends it
51
+ * to `onError`). A URL that cannot be read is thrown as `INVALID_URL`, not
52
+ * sent here. The library never writes to the console, so an issue with no
53
+ * handler is silent (#220).
54
+ *
55
+ * In grouped mode, an error that comes from the grouped URL value is an
56
+ * `InvalidSerializationError`, and the original error is in `error.cause`.
57
+ * The wrapper has the code and the column of the original issue, so a check
58
+ * on `error.code` works the same in both modes.
45
59
  */
46
- onParseError?: (error: Error) => void;
60
+ onParseError?: ((error: Error) => void) | undefined;
47
61
  /**
48
62
  * Serialization mode for URL parameters
49
63
  * @default 'individual'
50
64
  */
51
- serialization?: SerializationMode;
65
+ serialization?: SerializationMode | undefined;
52
66
  /**
53
67
  * Parameter name for grouped serialization
54
68
  * @default 'grid_filters'
55
69
  */
56
- groupedParam?: string;
70
+ groupedParam?: string | undefined;
57
71
  /**
58
72
  * Serialization format for grouped mode
59
73
  * @default 'querystring'
60
74
  */
61
- format?: SerializationFormat;
75
+ format?: SerializationFormat | undefined;
76
+ /**
77
+ * Throw an issue instead of reporting it (#229), like TanStack Query's
78
+ * `throwOnError`. `true` throws every issue, and a function throws the
79
+ * issues for which it gives `true`. In the core, a thrown issue is not sent
80
+ * to `onParseError`, and the first one stops the call. In the React hook,
81
+ * each issue is still sent to `onParseError` one time, and the picked issue
82
+ * is thrown during render, so an error boundary catches it. The library does
83
+ * not change the address bar, so remove the bad param before the boundary
84
+ * resets, or the same issue is thrown again.
85
+ *
86
+ * A function that throws makes the library throw that error.
87
+ * @default false
88
+ */
89
+ throwOnError?: boolean | ((issue: URLSyncError) => boolean) | undefined;
90
+ }
91
+ /**
92
+ * The options with a value for each one: the config after the defaults are
93
+ * filled in. It has no `gridApi`: the grid is an argument of the functions
94
+ * that read it (#219).
95
+ *
96
+ * A caller can set an option to undefined (#258), so `Required` is not enough:
97
+ * it keeps the undefined.
98
+ */
99
+ export type ResolvedOptions = {
100
+ [K in Exclude<keyof AGGridUrlSyncConfig, 'throwOnError'>]-?: Exclude<AGGridUrlSyncConfig[K], undefined>;
101
+ } & {
102
+ /**
103
+ * Optional, so that ParseConfig and InternalConfig, which extend this type,
104
+ * get no new required key (#229). resolveOptions always sets it.
105
+ */
106
+ throwOnError?: Exclude<AGGridUrlSyncConfig['throwOnError'], undefined>;
107
+ };
108
+ /**
109
+ * Configuration for URL parsing and serialization operations that don't require GridApi.
110
+ *
111
+ * @deprecated The parse and serialize functions take a partial
112
+ * `AGGridUrlSyncConfig` and fill in the defaults, so you do not need this
113
+ * type. Use `ResolvedOptions` for a config with every option set. This type
114
+ * will be removed in 0.6.0.
115
+ */
116
+ export interface ParseConfig extends ResolvedOptions {
117
+ /** AG Grid API instance - not read by parsing/serialization operations */
118
+ gridApi?: AGGridApi | null;
62
119
  }
63
120
  /**
64
121
  * Internal configuration with all required fields and runtime dependencies
122
+ *
123
+ * @deprecated Give the grid API to `getFilterModel(gridApi, options)` and
124
+ * `applyFilterModel(filterState, gridApi, options)` as an argument. This type
125
+ * will be removed in 0.6.0.
65
126
  */
66
- export interface InternalConfig extends Required<AGGridUrlSyncConfig> {
127
+ export interface InternalConfig extends ParseConfig {
67
128
  /** AG Grid API instance for filter operations */
68
129
  gridApi: AGGridApi;
69
130
  }
70
131
  /**
71
132
  * Text-only filter operations for string-based filtering
72
133
  */
73
- export declare const TEXT_ONLY_OPERATIONS: readonly ['contains', 'notContains', 'startsWith', 'endsWith'];
134
+ export declare const TEXT_ONLY_OPERATIONS: readonly ["contains", "notContains", "startsWith", "endsWith"];
74
135
  /**
75
136
  * Number-only filter operations for numeric comparisons
76
137
  */
77
- export declare const NUMBER_ONLY_OPERATIONS: readonly ['lessThan', 'lessThanOrEqual', 'greaterThan', 'greaterThanOrEqual', 'inRange'];
138
+ export declare const NUMBER_ONLY_OPERATIONS: readonly ["lessThan", "lessThanOrEqual", "greaterThan", "greaterThanOrEqual", "inRange"];
78
139
  /**
79
140
  * Date-specific filter operations for temporal comparisons
80
141
  */
81
- export declare const DATE_ONLY_OPERATIONS: readonly ['dateBefore', 'dateBeforeOrEqual', 'dateAfter', 'dateAfterOrEqual', 'dateRange'];
142
+ export declare const DATE_ONLY_OPERATIONS: readonly ["dateBefore", "dateBeforeOrEqual", "dateAfter", "dateAfterOrEqual", "dateRange"];
82
143
  /**
83
144
  * Operations shared across multiple filter types
84
145
  */
85
- export declare const SHARED_OPERATIONS: readonly ['eq', 'notEqual', 'blank', 'notBlank'];
146
+ export declare const SHARED_OPERATIONS: readonly ["eq", "notEqual", "blank", "notBlank"];
86
147
  /**
87
148
  * All supported filter operations across text, number, and date filters
88
149
  */
89
- export type FilterOperation = (typeof TEXT_ONLY_OPERATIONS)[number] | (typeof NUMBER_ONLY_OPERATIONS)[number] | (typeof DATE_ONLY_OPERATIONS)[number] | (typeof SHARED_OPERATIONS)[number];
150
+ export type FilterOperation = Operator['id'];
90
151
  /**
91
152
  * Complete list of valid text filter operations
92
153
  */
@@ -96,29 +157,33 @@ export declare const TEXT_FILTER_OPERATIONS: readonly ["contains", "notContains"
96
157
  */
97
158
  export declare const NUMBER_FILTER_OPERATIONS: readonly ["lessThan", "lessThanOrEqual", "greaterThan", "greaterThanOrEqual", "inRange", "eq", "notEqual", "blank", "notBlank"];
98
159
  /**
99
- * Valid date filter operations as const array
160
+ * Valid date filter operations
100
161
  */
101
162
  export declare const DATE_FILTER_OPERATIONS: readonly ["dateBefore", "dateBeforeOrEqual", "dateAfter", "dateAfterOrEqual", "dateRange", "eq", "notEqual", "blank", "notBlank"];
102
163
  /**
103
164
  * Text-specific filter operations
104
165
  */
105
- export type TextFilterOperation = (typeof TEXT_FILTER_OPERATIONS)[number];
166
+ export type TextFilterOperation = OperationsFor<'text'>;
106
167
  /**
107
168
  * Number-specific filter operations
108
169
  */
109
- export type NumberFilterOperation = (typeof NUMBER_FILTER_OPERATIONS)[number];
170
+ export type NumberFilterOperation = OperationsFor<'number'>;
110
171
  /**
111
172
  * Date-specific filter operations
112
173
  */
113
- export type DateFilterOperation = (typeof DATE_FILTER_OPERATIONS)[number];
174
+ export type DateFilterOperation = OperationsFor<'date'>;
114
175
  /**
115
176
  * Range operations that require two values (from/to)
116
177
  */
117
- export type RangeOperation = 'inRange' | 'dateRange';
178
+ export type RangeOperation = Extract<Operator, {
179
+ arity: 2;
180
+ }>['id'];
118
181
  /**
119
182
  * Operations that don't require a filter value
120
183
  */
121
- export type BlankOperation = 'blank' | 'notBlank';
184
+ export type BlankOperation = Extract<Operator, {
185
+ arity: 0;
186
+ }>['id'];
122
187
  /**
123
188
  * Supported filter types
124
189
  */
@@ -201,35 +266,56 @@ export declare function isNumberFilter(filter: ColumnFilter): filter is NumberCo
201
266
  * Type guard to check if a filter is a date filter
202
267
  */
203
268
  export declare function isDateFilter(filter: ColumnFilter): filter is DateColumnFilter;
269
+ /**
270
+ * The reason for an issue (#220). Data issues are a filter that is dropped or
271
+ * not valid. The other codes are failures of an operation.
272
+ */
273
+ export type IssueCode = 'INVALID_PARAM' | 'INVALID_NUMBER' | 'INVALID_DATE' | 'VALUE_TOO_LONG' | 'INVALID_GROUPED' | 'TYPE_MISMATCH' | 'INVALID_URL' | 'GRID_ERROR' | 'NOT_READY' | 'VIEW_NOT_FOUND' | 'VIEW_NAME_REQUIRED' | 'STORAGE_UNAVAILABLE' | 'STORAGE_FULL' | 'STORAGE_WRITE_FAILED' | 'UNKNOWN';
274
+ /** The code and the column of an issue, when the default is not right */
275
+ export interface IssueDetails {
276
+ code?: IssueCode | undefined;
277
+ column?: string | undefined;
278
+ }
204
279
  /**
205
280
  * Base error class for all URL sync operations
206
281
  */
207
282
  export declare class URLSyncError extends Error {
208
283
  readonly cause?: Error | undefined;
209
- constructor(message: string, cause?: Error | undefined);
284
+ /** The reason for the error */
285
+ readonly code: IssueCode;
286
+ /** The column of the filter, when it is known */
287
+ readonly column?: string;
288
+ constructor(message: string, cause?: Error | undefined, details?: IssueDetails);
210
289
  }
211
290
  /**
212
291
  * Error thrown when filter validation fails
213
292
  */
214
293
  export declare class InvalidFilterError extends URLSyncError {
215
- constructor(message: string, cause?: Error);
294
+ constructor(message: string, cause?: Error, details?: IssueDetails);
216
295
  }
217
296
  /**
218
297
  * Error thrown when URL parsing fails
219
298
  */
220
299
  export declare class InvalidURLError extends URLSyncError {
221
- constructor(message: string, cause?: Error);
300
+ constructor(message: string, cause?: Error, details?: IssueDetails);
222
301
  }
223
302
  /**
224
303
  * Error thrown when date validation fails
225
304
  */
226
305
  export declare class InvalidDateError extends InvalidFilterError {
227
- constructor(message: string, cause?: Error);
306
+ constructor(message: string, cause?: Error, details?: IssueDetails);
228
307
  }
229
308
  /**
230
- * Error thrown when serialization/deserialization fails
231
- */
232
- export declare class InvalidSerializationError extends Error {
309
+ * Error thrown when serialization/deserialization fails.
310
+ *
311
+ * When the cause is an issue inside the grouped value (for example a value
312
+ * over maxValueLength), this error has the same code and column, so a filter
313
+ * gives the same code in both modes. `INVALID_GROUPED` means that the grouped
314
+ * value itself does not decode.
315
+ */
316
+ export declare class InvalidSerializationError extends URLSyncError {
317
+ /** The grouped format: querystring, json or base64 */
318
+ readonly format: string;
233
319
  constructor(format: string, cause: Error);
234
320
  }
235
321
  /**
@@ -263,6 +349,28 @@ export interface RawAGGridFilter {
263
349
  dateFrom?: string;
264
350
  dateTo?: string;
265
351
  }
352
+ /**
353
+ * The URL with the current filter state, and whether the grid has filters
354
+ */
355
+ export interface UrlState {
356
+ /** The URL with the current filter state and the page's own params */
357
+ url: string;
358
+ /** Whether the grid has filters that the library supports */
359
+ hasFilters: boolean;
360
+ /**
361
+ * The issues of this call (#229): filters that the grid read or the URL
362
+ * leaves out. The same objects also go to `onParseError`.
363
+ */
364
+ issues: readonly URLSyncError[];
365
+ }
366
+ /** The result of an apply method (#229) */
367
+ export interface ApplyResult {
368
+ /**
369
+ * The issues of this call: filters that were dropped. The same objects
370
+ * also go to `onParseError`.
371
+ */
372
+ issues: readonly URLSyncError[];
373
+ }
266
374
  /**
267
375
  * Grouped serialization result
268
376
  */
@@ -276,10 +384,20 @@ export interface GroupedSerializationResult {
276
384
  * Format-specific serializer interface
277
385
  */
278
386
  export interface FormatSerializer {
279
- /** Serialize filter state to string */
280
- serialize(filterState: FilterState): string;
281
- /** Deserialize string to filter state */
282
- deserialize(value: string): FilterState;
387
+ /**
388
+ * Serialize filter state to string
389
+ * @param config - Caller's configuration. All serializers honour
390
+ * maxValueLength and onParseError. JSON and Base64 drop over-length text
391
+ * values and report them through onParseError (see #213, #207).
392
+ */
393
+ serialize(filterState: FilterState, config?: ResolvedOptions): string;
394
+ /**
395
+ * Deserialize string to filter state
396
+ * @param config - Caller's configuration. All serializers honour
397
+ * maxValueLength and onParseError. JSON and Base64 drop over-length text
398
+ * values and report them through onParseError (see #213, #207).
399
+ */
400
+ deserialize(value: string, config?: ResolvedOptions): FilterState;
283
401
  /** Format identifier */
284
402
  format: SerializationFormat;
285
403
  }
@@ -296,20 +414,41 @@ export interface GroupedDetectionResult {
296
414
  /** The raw value if grouped */
297
415
  value?: string;
298
416
  }
417
+ /**
418
+ * Operation Mapping Strategy:
419
+ *
420
+ * We use three different naming conventions for better user experience:
421
+ *
422
+ * 1. URL Parameters: Short, clean names for URLs (e.g., 'eq', 'neq', 'before', 'after')
423
+ * 2. Internal Types: Consistent naming for our FilterOperation type
424
+ * 3. AG Grid Operations: Exact names expected by AG Grid API (e.g., 'equals', 'notEqual', 'lessThan')
425
+ *
426
+ * The operator table in `operators.ts` holds all three names for each
427
+ * operation (#217). The maps below are derived from it and kept only for
428
+ * callers that use them.
429
+ */
299
430
  /**
300
431
  * Maps URL operation names to internal operation types
432
+ * @deprecated Derived from the operator table. Will be removed in 0.6.0.
301
433
  */
302
434
  export declare const OPERATION_MAP: Record<string, FilterOperation>;
303
435
  /**
304
436
  * Maps internal operation types to URL operation names
437
+ * @deprecated Derived from the operator table. Will be removed in 0.6.0.
305
438
  */
306
439
  export declare const INTERNAL_TO_URL_OPERATION_MAP: Record<FilterOperation, string>;
307
440
  /**
308
441
  * Maps internal operation types to AG Grid operation names
442
+ * @deprecated Derived from the operator table. Will be removed in 0.6.0.
309
443
  */
310
444
  export declare const AG_GRID_OPERATION_NAMES: Record<string, string>;
311
445
  /**
312
- * Maps AG Grid operation names to internal operation types
446
+ * Maps AG Grid operation names to internal operation types.
447
+ *
448
+ * AG Grid uses one name for a number and a date operation, so this map is
449
+ * wrong for one of them: `lessThan` gives `dateBefore`. The last row in the
450
+ * operator table wins, as before.
451
+ * @deprecated The key needs the filter type too. Will be removed in 0.6.0.
313
452
  */
314
453
  export declare const REVERSE_AG_GRID_OPERATION_NAMES: Record<string, FilterOperation>;
315
454
  export {};
@@ -1,55 +1,26 @@
1
- export const TEXT_ONLY_OPERATIONS = [
2
- 'contains',
3
- 'notContains',
4
- 'startsWith',
5
- 'endsWith'
6
- ];
7
- export const NUMBER_ONLY_OPERATIONS = [
8
- 'lessThan',
9
- 'lessThanOrEqual',
10
- 'greaterThan',
11
- 'greaterThanOrEqual',
12
- 'inRange'
13
- ];
14
- export const DATE_ONLY_OPERATIONS = [
15
- 'dateBefore',
16
- 'dateBeforeOrEqual',
17
- 'dateAfter',
18
- 'dateAfterOrEqual',
19
- 'dateRange'
20
- ];
21
- export const SHARED_OPERATIONS = [
22
- 'eq',
23
- 'notEqual',
24
- 'blank',
25
- 'notBlank'
26
- ];
27
- export const TEXT_FILTER_OPERATIONS = [
28
- ...TEXT_ONLY_OPERATIONS,
29
- ...SHARED_OPERATIONS
30
- ];
31
- export const NUMBER_FILTER_OPERATIONS = [
32
- ...NUMBER_ONLY_OPERATIONS,
33
- ...SHARED_OPERATIONS
34
- ];
35
- export const DATE_FILTER_OPERATIONS = [
36
- ...DATE_ONLY_OPERATIONS,
37
- ...SHARED_OPERATIONS
38
- ];
1
+ import { attachColumn } from './issue-columns.js';
2
+ import { OPERATORS, operationsFor, operationsOnlyFor, sharedOperations, isOperationFor, operatorById } from './operators.js';
3
+ export const TEXT_ONLY_OPERATIONS = operationsOnlyFor('text');
4
+ export const NUMBER_ONLY_OPERATIONS = operationsOnlyFor('number');
5
+ export const DATE_ONLY_OPERATIONS = operationsOnlyFor('date');
6
+ export const SHARED_OPERATIONS = sharedOperations();
7
+ export const TEXT_FILTER_OPERATIONS = operationsFor('text');
8
+ export const NUMBER_FILTER_OPERATIONS = operationsFor('number');
9
+ export const DATE_FILTER_OPERATIONS = operationsFor('date');
39
10
  export function isTextFilterOperation(op) {
40
- return TEXT_FILTER_OPERATIONS.includes(op);
11
+ return isOperationFor(op, 'text');
41
12
  }
42
13
  export function isNumberFilterOperation(op) {
43
- return NUMBER_FILTER_OPERATIONS.includes(op);
14
+ return isOperationFor(op, 'number');
44
15
  }
45
16
  export function isDateFilterOperation(op) {
46
- return DATE_FILTER_OPERATIONS.includes(op);
17
+ return isOperationFor(op, 'date');
47
18
  }
48
19
  export function isRangeOperation(op) {
49
- return op === 'inRange' || op === 'dateRange';
20
+ return operatorById(op)?.arity === 2;
50
21
  }
51
22
  export function isBlankOperation(op) {
52
- return op === 'blank' || op === 'notBlank';
23
+ return operatorById(op)?.arity === 0;
53
24
  }
54
25
  export function isTextFilter(filter) {
55
26
  return filter.filterType === 'text';
@@ -62,90 +33,46 @@ export function isDateFilter(filter) {
62
33
  }
63
34
  export class URLSyncError extends Error {
64
35
  cause;
65
- constructor(message, cause) {
36
+ code;
37
+ constructor(message, cause, details = {}) {
66
38
  super(message);
67
39
  this.cause = cause;
68
40
  this.name = 'URLSyncError';
41
+ this.code = details.code ?? 'UNKNOWN';
42
+ if (details.column !== undefined)
43
+ attachColumn(this, details.column);
69
44
  }
70
45
  }
71
46
  export class InvalidFilterError extends URLSyncError {
72
- constructor(message, cause) {
73
- super(message, cause);
47
+ constructor(message, cause, details = {}) {
48
+ super(message, cause, { ...details, code: details.code ?? 'INVALID_PARAM' });
74
49
  this.name = 'InvalidFilterError';
75
50
  }
76
51
  }
77
52
  export class InvalidURLError extends URLSyncError {
78
- constructor(message, cause) {
79
- super(message, cause);
53
+ constructor(message, cause, details = {}) {
54
+ super(message, cause, { ...details, code: details.code ?? 'INVALID_URL' });
80
55
  this.name = 'InvalidURLError';
81
56
  }
82
57
  }
83
58
  export class InvalidDateError extends InvalidFilterError {
84
- constructor(message, cause) {
85
- super(message, cause);
59
+ constructor(message, cause, details = {}) {
60
+ super(message, cause, { ...details, code: details.code ?? 'INVALID_DATE' });
86
61
  this.name = 'InvalidDateError';
87
62
  }
88
63
  }
89
- export class InvalidSerializationError extends Error {
64
+ export class InvalidSerializationError extends URLSyncError {
65
+ format;
90
66
  constructor(format, cause) {
91
- super(`Invalid ${format} serialization: ${cause.message}`);
67
+ super(`Invalid ${format} serialization: ${cause.message}`, cause, cause instanceof URLSyncError
68
+ ? { code: cause.code, column: cause.column }
69
+ : { code: 'INVALID_GROUPED' });
92
70
  this.name = 'InvalidSerializationError';
93
- this.cause = cause;
71
+ this.format = format;
94
72
  }
95
73
  }
96
- const URL_SHORTHAND_MAPPINGS = {
97
- notEqual: 'neq',
98
- lessThan: 'lt',
99
- lessThanOrEqual: 'lte',
100
- greaterThan: 'gt',
101
- greaterThanOrEqual: 'gte',
102
- inRange: 'range',
103
- dateBefore: 'before',
104
- dateBeforeOrEqual: 'beforeEq',
105
- dateAfter: 'after',
106
- dateAfterOrEqual: 'afterEq',
107
- dateRange: 'daterange'
108
- };
109
- const AG_GRID_NAME_MAPPINGS = {
110
- eq: 'equals',
111
- dateBefore: 'lessThan',
112
- dateBeforeOrEqual: 'lessThanOrEqual',
113
- dateAfter: 'greaterThan',
114
- dateAfterOrEqual: 'greaterThanOrEqual',
115
- dateRange: 'inRange'
116
- };
117
- function createOperationMaps() {
118
- const allOperations = [
119
- ...TEXT_FILTER_OPERATIONS,
120
- ...NUMBER_FILTER_OPERATIONS,
121
- ...DATE_FILTER_OPERATIONS
122
- ];
123
- const uniqueOperations = [...new Set(allOperations)];
124
- const operationMap = {};
125
- const internalToUrlMap = {};
126
- uniqueOperations.forEach(operation => {
127
- const urlName = URL_SHORTHAND_MAPPINGS[operation] || operation;
128
- operationMap[urlName] = operation;
129
- internalToUrlMap[operation] = urlName;
130
- });
131
- const agGridMap = {};
132
- const reverseAgGridMap = {};
133
- uniqueOperations.forEach(operation => {
134
- const agGridName = AG_GRID_NAME_MAPPINGS[operation] ||
135
- operation;
136
- agGridMap[operation] = agGridName;
137
- reverseAgGridMap[agGridName] = operation;
138
- });
139
- return {
140
- operationMap,
141
- internalToUrlMap,
142
- agGridMap,
143
- reverseAgGridMap
144
- };
145
- }
146
- const mappings = createOperationMaps();
147
- export const OPERATION_MAP = mappings.operationMap;
148
- export const INTERNAL_TO_URL_OPERATION_MAP = mappings.internalToUrlMap;
149
- export const AG_GRID_OPERATION_NAMES = mappings.agGridMap;
150
- export const REVERSE_AG_GRID_OPERATION_NAMES = mappings.reverseAgGridMap;
74
+ export const OPERATION_MAP = Object.fromEntries(OPERATORS.map(op => [op.url, op.id]));
75
+ export const INTERNAL_TO_URL_OPERATION_MAP = Object.fromEntries(OPERATORS.map(op => [op.id, op.url]));
76
+ export const AG_GRID_OPERATION_NAMES = Object.fromEntries(OPERATORS.map(op => [op.id, op.agGrid]));
77
+ export const REVERSE_AG_GRID_OPERATION_NAMES = Object.fromEntries(OPERATORS.map(op => [op.agGrid, op.id]));
151
78
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AA+FA,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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E,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAM1D,MAAM,CAAC,MAAM,6BAA6B,GAGxC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAGtD,CAAA;AAMH,MAAM,CAAC,MAAM,uBAAuB,GAClC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAU7D,MAAM,CAAC,MAAM,+BAA+B,GAC1C,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
@@ -1,9 +1,12 @@
1
- import type { FilterState, InternalConfig } from './types.js';
1
+ import type { AGGridUrlSyncConfig, FilterState } from './types.js';
2
+ import { serializeFilters } from './individual-params.js';
3
+ export { serializeFilters };
2
4
  /**
3
- * Converts a filter state object into URL search parameters
5
+ * Generates a URL with the current filter state.
6
+ * This function does not need a grid. An option that the config leaves out
7
+ * gets its default.
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 serializeFilters(filterState: FilterState, config: InternalConfig): URLSearchParams;
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?: AGGridUrlSyncConfig): string;