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
@@ -0,0 +1,236 @@
1
+ import { InvalidFilterError } from './types.js';
2
+ import { operatorById, operatorFromUrl, isOperationOnlyFor, isSharedOperation } from './operators.js';
3
+ import { validateFilterValue, validateAndParseNumber, parseExactNumber, validateNumberRange, validateAndParseDate, validateAndParseDateRange, validateDateFilter } from './validation.js';
4
+ import { DEFAULT_CONFIG, resolveOptions } from './options.js';
5
+ import { reportIssue, toIssue } from './issues.js';
6
+ const FILTER_TYPES = {
7
+ TEXT: 'text',
8
+ NUMBER: 'number',
9
+ DATE: 'date'
10
+ };
11
+ export function resolveParamPrefix(paramPrefix) {
12
+ const prefix = paramPrefix || DEFAULT_CONFIG.paramPrefix;
13
+ return prefix.endsWith('_') ? prefix : `${prefix}_`;
14
+ }
15
+ function serializeColumnFilter(columnName, filter, paramPrefix) {
16
+ const urlOperation = operatorById(filter.type)?.url;
17
+ if (!urlOperation)
18
+ return null;
19
+ const paramName = `${paramPrefix}${columnName}_${urlOperation}`;
20
+ if (filter.type === 'dateRange' || filter.type === 'inRange') {
21
+ return 'filterTo' in filter && filter.filterTo !== undefined
22
+ ? [paramName, `${filter.filter},${filter.filterTo}`]
23
+ : null;
24
+ }
25
+ if (filter.type === 'blank' || filter.type === 'notBlank') {
26
+ return [paramName, 'true'];
27
+ }
28
+ if (filter.filterType === FILTER_TYPES.NUMBER ||
29
+ filter.filterType === FILTER_TYPES.DATE) {
30
+ const value = String(filter.filter);
31
+ return value ? [paramName, value] : null;
32
+ }
33
+ if (filter.filterType === FILTER_TYPES.TEXT && filter.filter) {
34
+ return [paramName, filter.filter];
35
+ }
36
+ return null;
37
+ }
38
+ export function serializeFilters(filterState, config = {}) {
39
+ const options = resolveOptions(config);
40
+ const params = new URLSearchParams();
41
+ for (const [column, filter] of Object.entries(filterState)) {
42
+ if (filter.filterType !== FILTER_TYPES.TEXT &&
43
+ filter.filterType !== FILTER_TYPES.NUMBER &&
44
+ filter.filterType !== FILTER_TYPES.DATE)
45
+ continue;
46
+ let checkedFilter = filter;
47
+ if (filter.filterType === FILTER_TYPES.TEXT) {
48
+ try {
49
+ checkedFilter = {
50
+ ...filter,
51
+ filter: validateFilterValue(filter.filter, options, filter.type)
52
+ };
53
+ }
54
+ catch (error) {
55
+ reportIssue(options, toIssue(error, 'INVALID_PARAM', column));
56
+ continue;
57
+ }
58
+ }
59
+ const param = serializeColumnFilter(column, checkedFilter, resolveParamPrefix(options.paramPrefix));
60
+ if (param) {
61
+ params.append(...param);
62
+ }
63
+ }
64
+ return params;
65
+ }
66
+ function tryParseAsDate(value) {
67
+ try {
68
+ validateAndParseDate(value);
69
+ return 'date';
70
+ }
71
+ catch {
72
+ return null;
73
+ }
74
+ }
75
+ function detectFilterTypeForSharedOperation(operation, value) {
76
+ if (operation === 'blank' || operation === 'notBlank') {
77
+ return 'text';
78
+ }
79
+ if (operation === 'eq' || operation === 'notEqual') {
80
+ if (tryParseAsDate(value) === 'date') {
81
+ return 'date';
82
+ }
83
+ if (parseExactNumber(value) !== null) {
84
+ return 'number';
85
+ }
86
+ return 'text';
87
+ }
88
+ return 'text';
89
+ }
90
+ function extractColumnAndOperation(param, expectedPrefix) {
91
+ const prefix = resolveParamPrefix(expectedPrefix);
92
+ if (!param.startsWith(prefix)) {
93
+ throw new InvalidFilterError(`Invalid filter prefix in parameter: ${param}`);
94
+ }
95
+ const withoutPrefix = param.substring(prefix.length);
96
+ const lastUnderscoreIndex = withoutPrefix.lastIndexOf('_');
97
+ if (lastUnderscoreIndex === -1) {
98
+ throw new InvalidFilterError(`Invalid filter parameter format: ${param}`);
99
+ }
100
+ const column = withoutPrefix.substring(0, lastUnderscoreIndex);
101
+ const operation = withoutPrefix.substring(lastUnderscoreIndex + 1);
102
+ if (!column.trim()) {
103
+ throw new InvalidFilterError(`Empty column name in parameter: ${param}`);
104
+ }
105
+ return { column, operation };
106
+ }
107
+ export function parseFilterParam(param, value, expectedPrefix) {
108
+ const { operation } = extractColumnAndOperation(param, expectedPrefix);
109
+ return parseFilterOperation(operation, value);
110
+ }
111
+ function parseFilterOperation(operation, value) {
112
+ const filterOp = operatorFromUrl(operation)?.id;
113
+ if (!filterOp) {
114
+ throw new InvalidFilterError(`Unsupported filter operation: ${operation}`);
115
+ }
116
+ if (filterOp === 'dateRange') {
117
+ try {
118
+ const [startDate, endDate] = validateAndParseDateRange(value);
119
+ return {
120
+ filterType: 'date',
121
+ type: filterOp,
122
+ filter: startDate,
123
+ filterTo: endDate
124
+ };
125
+ }
126
+ catch (error) {
127
+ throw new InvalidFilterError(error instanceof Error ? error.message : 'Invalid date range', undefined, { code: 'INVALID_DATE' });
128
+ }
129
+ }
130
+ if (filterOp === 'inRange') {
131
+ const rangeParts = value.split(',');
132
+ if (rangeParts.length !== 2) {
133
+ throw new InvalidFilterError('Range operation requires exactly two values separated by comma', undefined, { code: 'INVALID_NUMBER' });
134
+ }
135
+ const min = validateAndParseNumber(rangeParts[0] || '');
136
+ const max = validateAndParseNumber(rangeParts[1] || '');
137
+ const rangeValidation = validateNumberRange(min, max);
138
+ if (!rangeValidation.valid) {
139
+ throw new InvalidFilterError(rangeValidation.error || 'Invalid range values', undefined, { code: 'INVALID_NUMBER' });
140
+ }
141
+ return {
142
+ filterType: 'number',
143
+ type: filterOp,
144
+ filter: min,
145
+ filterTo: max
146
+ };
147
+ }
148
+ if (isOperationOnlyFor(filterOp, 'date')) {
149
+ try {
150
+ const dateValue = validateAndParseDate(value);
151
+ const validation = validateDateFilter(dateValue, filterOp);
152
+ if (!validation.valid) {
153
+ throw new InvalidFilterError(validation.error || 'Invalid date filter');
154
+ }
155
+ return {
156
+ filterType: 'date',
157
+ type: filterOp,
158
+ filter: dateValue
159
+ };
160
+ }
161
+ catch (error) {
162
+ throw new InvalidFilterError(error instanceof Error ? error.message : 'Invalid date filter', undefined, { code: 'INVALID_DATE' });
163
+ }
164
+ }
165
+ if (isOperationOnlyFor(filterOp, 'number')) {
166
+ const numValue = validateAndParseNumber(value);
167
+ return {
168
+ filterType: 'number',
169
+ type: filterOp,
170
+ filter: numValue
171
+ };
172
+ }
173
+ if (isSharedOperation(filterOp)) {
174
+ const detectedType = detectFilterTypeForSharedOperation(filterOp, value);
175
+ if (detectedType === 'date') {
176
+ try {
177
+ const dateValue = validateAndParseDate(value);
178
+ return {
179
+ filterType: 'date',
180
+ type: filterOp,
181
+ filter: dateValue
182
+ };
183
+ }
184
+ catch {
185
+ }
186
+ }
187
+ if (detectedType === 'number') {
188
+ const numValue = parseExactNumber(value);
189
+ if (numValue !== null) {
190
+ return {
191
+ filterType: 'number',
192
+ type: filterOp,
193
+ filter: numValue
194
+ };
195
+ }
196
+ }
197
+ return {
198
+ filterType: 'text',
199
+ type: filterOp,
200
+ filter: filterOp === 'blank' || filterOp === 'notBlank' ? '' : value || ''
201
+ };
202
+ }
203
+ return {
204
+ filterType: 'text',
205
+ type: filterOp,
206
+ filter: value || ''
207
+ };
208
+ }
209
+ export function parseIndividualParams(searchParams, config) {
210
+ const filters = new Map();
211
+ const prefix = resolveParamPrefix(config.paramPrefix);
212
+ for (const [param, value] of searchParams.entries()) {
213
+ if (!param.startsWith(prefix))
214
+ continue;
215
+ let columnName;
216
+ try {
217
+ const parts = extractColumnAndOperation(param, prefix);
218
+ columnName = parts.column;
219
+ const { operation } = parts;
220
+ const filterParam = parseFilterOperation(operation, value);
221
+ if (filterParam.filterType === 'text') {
222
+ const validatedValue = validateFilterValue(value, config, filterParam.type);
223
+ filters.set(parts.column, { ...filterParam, filter: validatedValue });
224
+ }
225
+ else {
226
+ filters.set(parts.column, filterParam);
227
+ }
228
+ }
229
+ catch (error) {
230
+ reportIssue(config, toIssue(error, 'INVALID_PARAM', columnName));
231
+ continue;
232
+ }
233
+ }
234
+ return Object.fromEntries(filters);
235
+ }
236
+ //# sourceMappingURL=individual-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"individual-params.js","sourceRoot":"","sources":["../../src/core/individual-params.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EACL,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAQlD,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAA;AAQV,MAAM,UAAU,kBAAkB,CAAC,WAAoB;IACrD,MAAM,MAAM,GAAG,WAAW,IAAI,cAAc,CAAC,WAAW,CAAA;IAExD,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAA;AACrD,CAAC;AAQD,SAAS,qBAAqB,CAC5B,UAAkB,EAClB,MA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E,SAAQ;QACV,CAAC;IACH,CAAC;IAGD,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** Sets the column of an issue. An issue that has a column keeps it. */
2
+ export declare function attachColumn(error: Error, column: string): void;
@@ -0,0 +1,11 @@
1
+ export function attachColumn(error, column) {
2
+ if (Object.getOwnPropertyDescriptor(error, 'column') !== undefined)
3
+ return;
4
+ Object.defineProperty(error, 'column', {
5
+ value: column,
6
+ enumerable: true,
7
+ writable: false,
8
+ configurable: true
9
+ });
10
+ }
11
+ //# sourceMappingURL=issue-columns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue-columns.js","sourceRoot":"","sources":["../../src/core/issue-columns.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,YAAY,CAAC,KAAY,EAAE,MAAc;IACvD,IAAI,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,SAAS;QAAE,OAAM;IAE1E,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE;QACrC,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,KAAK;QAEf,YAAY,EAAE,IAAI;KACnB,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { IssueCode, ResolvedOptions } from './types.js';
2
+ import { URLSyncError } from './types.js';
3
+ /** The codes for a filter that is dropped or not valid */
4
+ export declare const DATA_ISSUE_CODES: ReadonlySet<IssueCode>;
5
+ /** Whether the error is a data issue: a filter that is dropped or not valid */
6
+ export declare function isDataIssue(error: unknown): error is URLSyncError;
7
+ /**
8
+ * The caught value as an issue. A URLSyncError keeps its class and code, and
9
+ * gets the column if it has none. Any other value becomes a URLSyncError with
10
+ * the code, and the original error is its cause.
11
+ */
12
+ export declare function toIssue(cause: unknown, code: IssueCode, column?: string): URLSyncError;
13
+ /** Options for one call, and the issues that the call reports */
14
+ export interface IssueCollector {
15
+ options: ResolvedOptions;
16
+ issues: URLSyncError[];
17
+ }
18
+ /**
19
+ * Options that also keep each issue they report, so a method can return the
20
+ * issues of one call (#229). The caller's onParseError still gets each one.
21
+ */
22
+ export declare function collectIssues(options: ResolvedOptions): IssueCollector;
23
+ /** Whether throwOnError picks the issue (#229) */
24
+ export declare function shouldThrow(throwOnError: ResolvedOptions['throwOnError'], issue: URLSyncError): boolean;
25
+ /**
26
+ * Reports one issue to the caller. An issue that throwOnError picks is thrown
27
+ * instead, and it does not reach onParseError (#229).
28
+ */
29
+ export declare function reportIssue(options: ResolvedOptions, issue: URLSyncError): void;
30
+ /**
31
+ * Rethrows an issue that reportIssue threw. A catch that wraps errors calls
32
+ * this first, so a thrown issue reaches the caller one time, not wrapped again.
33
+ */
34
+ export declare function rethrowIfThrown(cause: unknown): void;
@@ -0,0 +1,58 @@
1
+ import { URLSyncError } from './types.js';
2
+ import { attachColumn } from './issue-columns.js';
3
+ import { toError } from './to-error.js';
4
+ export const DATA_ISSUE_CODES = new Set([
5
+ 'INVALID_PARAM',
6
+ 'INVALID_NUMBER',
7
+ 'INVALID_DATE',
8
+ 'VALUE_TOO_LONG',
9
+ 'INVALID_GROUPED',
10
+ 'TYPE_MISMATCH',
11
+ 'INVALID_URL'
12
+ ]);
13
+ export function isDataIssue(error) {
14
+ return error instanceof URLSyncError && DATA_ISSUE_CODES.has(error.code);
15
+ }
16
+ export function toIssue(cause, code, column) {
17
+ if (cause instanceof URLSyncError) {
18
+ if (column !== undefined)
19
+ attachColumn(cause, column);
20
+ return cause;
21
+ }
22
+ const error = toError(cause);
23
+ return new URLSyncError(error.message, error, { code, column });
24
+ }
25
+ export function collectIssues(options) {
26
+ const issues = [];
27
+ return {
28
+ issues,
29
+ options: {
30
+ ...options,
31
+ onParseError: error => {
32
+ if (error instanceof URLSyncError)
33
+ issues.push(error);
34
+ options.onParseError(error);
35
+ }
36
+ }
37
+ };
38
+ }
39
+ const thrownIssues = new WeakSet();
40
+ export function shouldThrow(throwOnError, issue) {
41
+ if (throwOnError === undefined || throwOnError === false)
42
+ return false;
43
+ if (throwOnError === true)
44
+ return true;
45
+ return throwOnError(issue);
46
+ }
47
+ export function reportIssue(options, issue) {
48
+ if (shouldThrow(options.throwOnError, issue)) {
49
+ thrownIssues.add(issue);
50
+ throw issue;
51
+ }
52
+ options.onParseError(issue);
53
+ }
54
+ export function rethrowIfThrown(cause) {
55
+ if (cause instanceof Error && thrownIssues.has(cause))
56
+ throw cause;
57
+ }
58
+ //# sourceMappingURL=issues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issues.js","sourceRoot":"","sources":["../../src/core/issues.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAOvC,MAAM,CAAC,MAAM,gBAAgB,GAA2B,IAAI,GAAG,CAAY;IACzE,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,eAAe;IACf,aAAa;CACd,CAAC,CAAA;AAGF,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,YAAY,YAAY,IAAI,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC1E,CAAC;AAOD,MAAM,UAAU,OAAO,CACrB,KAAc,EACd,IAAe,EACf,MAAe;IAEf,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;QAClC,IAAI,MAAM,KAAK,SAAS;YAAE,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAErD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IAE5B,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;AACjE,CAAC;AAYD,MAAM,UAAU,aAAa,CAAC,OAAwB;IACpD,MAAM,MAAM,GAAmB,EAAE,CAAA;IAEjC,OAAO;QACL,MAAM;QACN,OAAO,EAAE;YACP,GAAG,OAAO;YACV,YAAY,EAAE,KAAK,CAAC,EAAE;gBAEpB,IAAI,KAAK,YAAY,YAAY;oBAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACrD,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;YAC7B,CAAC;SACF;KACF,CAAA;AACH,CAAC;AAGD,MAAM,YAAY,GAAG,IAAI,OAAO,EAAS,CAAA;AAGzC,MAAM,UAAU,WAAW,CACzB,YAA6C,EAC7C,KAAmB;IAEnB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,KAAK;QAAE,OAAO,KAAK,CAAA;IAEtE,IAAI,YAAY,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAEtC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAMD,MAAM,UAAU,WAAW,CACzB,OAAwB,EACxB,KAAmB;IAEnB,IAAI,WAAW,CAAC,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;QAC7C,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAEvB,MAAM,KAAK,CAAA;IACb,CAAC;IAED,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC;AAMD,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,KAAK,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,MAAM,KAAK,CAAA;AACpE,CAAC"}
@@ -0,0 +1,189 @@
1
+ /** A filter type that the library supports */
2
+ export type OperatorFilterType = 'text' | 'number' | 'date';
3
+ declare const ALL_TYPES: readonly ['text', 'number', 'date'];
4
+ /**
5
+ * Row order matters: the public operation lists keep their old order, and
6
+ * the deprecated reverse AG Grid map keeps its old "last row wins" values.
7
+ * Keep text-only rows first, then shared rows, then number-only rows, then
8
+ * date-only rows.
9
+ */
10
+ export declare const OPERATORS: readonly [{
11
+ readonly id: 'contains';
12
+ readonly url: 'contains';
13
+ readonly agGrid: 'contains';
14
+ readonly types: readonly ["text"];
15
+ readonly arity: 1;
16
+ }, {
17
+ readonly id: 'notContains';
18
+ readonly url: 'notContains';
19
+ readonly agGrid: 'notContains';
20
+ readonly types: readonly ["text"];
21
+ readonly arity: 1;
22
+ }, {
23
+ readonly id: 'startsWith';
24
+ readonly url: 'startsWith';
25
+ readonly agGrid: 'startsWith';
26
+ readonly types: readonly ["text"];
27
+ readonly arity: 1;
28
+ }, {
29
+ readonly id: 'endsWith';
30
+ readonly url: 'endsWith';
31
+ readonly agGrid: 'endsWith';
32
+ readonly types: readonly ["text"];
33
+ readonly arity: 1;
34
+ }, {
35
+ readonly id: 'eq';
36
+ readonly url: 'eq';
37
+ readonly agGrid: 'equals';
38
+ readonly types: readonly ["text", "number", "date"];
39
+ readonly arity: 1;
40
+ }, {
41
+ readonly id: 'notEqual';
42
+ readonly url: 'neq';
43
+ readonly agGrid: 'notEqual';
44
+ readonly types: readonly ["text", "number", "date"];
45
+ readonly arity: 1;
46
+ }, {
47
+ readonly id: 'blank';
48
+ readonly url: 'blank';
49
+ readonly agGrid: 'blank';
50
+ readonly types: readonly ["text", "number", "date"];
51
+ readonly arity: 0;
52
+ }, {
53
+ readonly id: 'notBlank';
54
+ readonly url: 'notBlank';
55
+ readonly agGrid: 'notBlank';
56
+ readonly types: readonly ["text", "number", "date"];
57
+ readonly arity: 0;
58
+ }, {
59
+ readonly id: 'lessThan';
60
+ readonly url: 'lt';
61
+ readonly agGrid: 'lessThan';
62
+ readonly types: readonly ["number"];
63
+ readonly arity: 1;
64
+ }, {
65
+ readonly id: 'lessThanOrEqual';
66
+ readonly url: 'lte';
67
+ readonly agGrid: 'lessThanOrEqual';
68
+ readonly types: readonly ["number"];
69
+ readonly arity: 1;
70
+ }, {
71
+ readonly id: 'greaterThan';
72
+ readonly url: 'gt';
73
+ readonly agGrid: 'greaterThan';
74
+ readonly types: readonly ["number"];
75
+ readonly arity: 1;
76
+ }, {
77
+ readonly id: 'greaterThanOrEqual';
78
+ readonly url: 'gte';
79
+ readonly agGrid: 'greaterThanOrEqual';
80
+ readonly types: readonly ["number"];
81
+ readonly arity: 1;
82
+ }, {
83
+ readonly id: 'inRange';
84
+ readonly url: 'range';
85
+ readonly agGrid: 'inRange';
86
+ readonly types: readonly ["number"];
87
+ readonly arity: 2;
88
+ }, {
89
+ readonly id: 'dateBefore';
90
+ readonly url: 'before';
91
+ readonly agGrid: 'lessThan';
92
+ readonly types: readonly ["date"];
93
+ readonly arity: 1;
94
+ }, {
95
+ readonly id: 'dateBeforeOrEqual';
96
+ readonly url: 'beforeEq';
97
+ readonly agGrid: 'lessThanOrEqual';
98
+ readonly types: readonly ["date"];
99
+ readonly arity: 1;
100
+ }, {
101
+ readonly id: 'dateAfter';
102
+ readonly url: 'after';
103
+ readonly agGrid: 'greaterThan';
104
+ readonly types: readonly ["date"];
105
+ readonly arity: 1;
106
+ }, {
107
+ readonly id: 'dateAfterOrEqual';
108
+ readonly url: 'afterEq';
109
+ readonly agGrid: 'greaterThanOrEqual';
110
+ readonly types: readonly ["date"];
111
+ readonly arity: 1;
112
+ }, {
113
+ readonly id: 'dateRange';
114
+ readonly url: 'daterange';
115
+ readonly agGrid: 'inRange';
116
+ readonly types: readonly ["date"];
117
+ readonly arity: 2;
118
+ }];
119
+ export type Operator = (typeof OPERATORS)[number];
120
+ export type OperatorId = Operator['id'];
121
+ /**
122
+ * The ids of the rows in `Ops` that match `Match`, in table order, as a tuple
123
+ * with a literal type at each index
124
+ */
125
+ type IdsWhere<Ops extends readonly unknown[], Match> = Ops extends readonly [
126
+ infer Head,
127
+ ...infer Rest
128
+ ] ? Head extends Match ? Head extends {
129
+ id: infer Id;
130
+ } ? [Id, ...IdsWhere<Rest, Match>] : IdsWhere<Rest, Match> : IdsWhere<Rest, Match> : [];
131
+ /**
132
+ * The tuples for each filter type, in a map. A generic `T` then indexes
133
+ * concrete tuples, so TypeScript can compare the generic type with a list of
134
+ * ids.
135
+ */
136
+ type OnlyForTuples = {
137
+ [K in OperatorFilterType]: Readonly<IdsWhere<typeof OPERATORS, {
138
+ types: readonly [K];
139
+ }>>;
140
+ };
141
+ /** Ids of the operations that only one filter type supports, as a tuple */
142
+ export type OperationsOnlyForTuple<T extends OperatorFilterType> = OnlyForTuples[T];
143
+ /** Ids of the operations that every filter type supports, as a tuple */
144
+ export type SharedOperationsTuple = Readonly<IdsWhere<typeof OPERATORS, {
145
+ types: typeof ALL_TYPES;
146
+ }>>;
147
+ /**
148
+ * Ids of the operations that a filter type supports, as a tuple: its own
149
+ * operations first, then the shared ones
150
+ */
151
+ export type OperationsForTuple<T extends OperatorFilterType> = {
152
+ [K in OperatorFilterType]: readonly [
153
+ ...OnlyForTuples[K],
154
+ ...SharedOperationsTuple
155
+ ];
156
+ }[T];
157
+ /** Ids of the operations that a filter type supports, shared ones included */
158
+ export type OperationsFor<T extends OperatorFilterType> = OperationsForTuple<T>[number];
159
+ /** Ids of the operations that only one filter type supports */
160
+ export type OperationsOnlyFor<T extends OperatorFilterType> = OperationsOnlyForTuple<T>[number];
161
+ /** Ids of the operations that every filter type supports */
162
+ export type SharedOperationId = SharedOperationsTuple[number];
163
+ /** The operations that only `type` supports, in table order */
164
+ export declare function operationsOnlyFor<T extends OperatorFilterType>(type: T): OperationsOnlyForTuple<T>;
165
+ /** The operations that every filter type supports, in table order */
166
+ export declare function sharedOperations(): SharedOperationsTuple;
167
+ /**
168
+ * The operations that `type` supports: its own operations first, then the
169
+ * shared ones
170
+ */
171
+ export declare function operationsFor<T extends OperatorFilterType>(type: T): OperationsForTuple<T>;
172
+ /** The operator with this internal id */
173
+ export declare function operatorById(id: string): Operator | undefined;
174
+ /** The operator with this name in a URL param (`gt`, `before`, `neq`, …) */
175
+ export declare function operatorFromUrl(urlName: string): Operator | undefined;
176
+ /**
177
+ * The operator for an AG Grid operation name on a filter type. The key is the
178
+ * pair, because AG Grid uses one name for a number and a date operation
179
+ * (`lessThan` is `lessThan` on a number filter and `dateBefore` on a date
180
+ * filter).
181
+ */
182
+ export declare function operatorFromAgGrid(filterType: string | undefined, agGridName: string | undefined): Operator | undefined;
183
+ /** Whether `id` is an operation that only `type` supports */
184
+ export declare function isOperationOnlyFor<T extends OperatorFilterType>(id: string, type: T): id is OperationsOnlyFor<T>;
185
+ /** Whether `id` is an operation that every filter type supports */
186
+ export declare function isSharedOperation(id: string): id is SharedOperationId;
187
+ /** Whether `id` is an operation that `type` supports */
188
+ export declare function isOperationFor<T extends OperatorFilterType>(id: string, type: T): id is OperationsFor<T>;
189
+ export {};
@@ -0,0 +1,60 @@
1
+ const ALL_TYPES = ['text', 'number', 'date'];
2
+ export const OPERATORS = [
3
+ { id: 'contains', url: 'contains', agGrid: 'contains', types: ['text'], arity: 1 },
4
+ { id: 'notContains', url: 'notContains', agGrid: 'notContains', types: ['text'], arity: 1 },
5
+ { id: 'startsWith', url: 'startsWith', agGrid: 'startsWith', types: ['text'], arity: 1 },
6
+ { id: 'endsWith', url: 'endsWith', agGrid: 'endsWith', types: ['text'], arity: 1 },
7
+ { id: 'eq', url: 'eq', agGrid: 'equals', types: ALL_TYPES, arity: 1 },
8
+ { id: 'notEqual', url: 'neq', agGrid: 'notEqual', types: ALL_TYPES, arity: 1 },
9
+ { id: 'blank', url: 'blank', agGrid: 'blank', types: ALL_TYPES, arity: 0 },
10
+ { id: 'notBlank', url: 'notBlank', agGrid: 'notBlank', types: ALL_TYPES, arity: 0 },
11
+ { id: 'lessThan', url: 'lt', agGrid: 'lessThan', types: ['number'], arity: 1 },
12
+ { id: 'lessThanOrEqual', url: 'lte', agGrid: 'lessThanOrEqual', types: ['number'], arity: 1 },
13
+ { id: 'greaterThan', url: 'gt', agGrid: 'greaterThan', types: ['number'], arity: 1 },
14
+ { id: 'greaterThanOrEqual', url: 'gte', agGrid: 'greaterThanOrEqual', types: ['number'], arity: 1 },
15
+ { id: 'inRange', url: 'range', agGrid: 'inRange', types: ['number'], arity: 2 },
16
+ { id: 'dateBefore', url: 'before', agGrid: 'lessThan', types: ['date'], arity: 1 },
17
+ { id: 'dateBeforeOrEqual', url: 'beforeEq', agGrid: 'lessThanOrEqual', types: ['date'], arity: 1 },
18
+ { id: 'dateAfter', url: 'after', agGrid: 'greaterThan', types: ['date'], arity: 1 },
19
+ { id: 'dateAfterOrEqual', url: 'afterEq', agGrid: 'greaterThanOrEqual', types: ['date'], arity: 1 },
20
+ { id: 'dateRange', url: 'daterange', agGrid: 'inRange', types: ['date'], arity: 2 }
21
+ ];
22
+ const isShared = (op) => op.types.length === ALL_TYPES.length;
23
+ const supports = (op, type) => op.types.some(own => own === type);
24
+ export function operationsOnlyFor(type) {
25
+ const ids = OPERATORS.flatMap(op => !isShared(op) && supports(op, type) ? [op.id] : []);
26
+ return ids;
27
+ }
28
+ export function sharedOperations() {
29
+ const ids = OPERATORS.flatMap(op => isShared(op) ? [op.id] : []);
30
+ return ids;
31
+ }
32
+ export function operationsFor(type) {
33
+ const own = operationsOnlyFor(type);
34
+ const ids = [...own, ...sharedOperations()];
35
+ return ids;
36
+ }
37
+ const BY_ID = new Map(OPERATORS.map(op => [op.id, op]));
38
+ const BY_URL = new Map(OPERATORS.map(op => [op.url, op]));
39
+ export function operatorById(id) {
40
+ return BY_ID.get(id);
41
+ }
42
+ export function operatorFromUrl(urlName) {
43
+ return BY_URL.get(urlName);
44
+ }
45
+ export function operatorFromAgGrid(filterType, agGridName) {
46
+ return OPERATORS.find(op => op.agGrid === agGridName && supports(op, filterType));
47
+ }
48
+ export function isOperationOnlyFor(id, type) {
49
+ const op = operatorById(id);
50
+ return op !== undefined && !isShared(op) && supports(op, type);
51
+ }
52
+ export function isSharedOperation(id) {
53
+ const op = operatorById(id);
54
+ return op !== undefined && isShared(op);
55
+ }
56
+ export function isOperationFor(id, type) {
57
+ const op = operatorById(id);
58
+ return op !== undefined && supports(op, type);
59
+ }
60
+ //# sourceMappingURL=operators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operators.js","sourceRoot":"","sources":["../../src/core/operators.ts"],"names":[],"mappings":"AAaA,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAA;AASrD,MAAM,CAAC,MAAM,SAAS,GAAG;IAEvB,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;IAClF,EAAE,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;IAC3F,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;IACxF,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;IAElF,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE;IACrE,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE;IAC9E,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE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AAC,EAAU;IAC1C,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,CAAC,CAAA;IAE3B,OAAO,EAAE,KAAK,SAAS,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAA;AACzC,CAAC;AAGD,MAAM,UAAU,cAAc,CAC5B,EAAU,EACV,IAAO;IAEP,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,CAAC,CAAA;IAE3B,OAAO,EAAE,KAAK,SAAS,IAAI,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAC/C,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { AGGridUrlSyncConfig, ResolvedOptions } from './types.js';
2
+ /**
3
+ * Default configuration values
4
+ */
5
+ export declare const DEFAULT_CONFIG: {
6
+ readonly paramPrefix: 'f_';
7
+ readonly maxValueLength: 200;
8
+ readonly serialization: 'individual';
9
+ readonly groupedParam: 'grid_filters';
10
+ readonly format: 'querystring';
11
+ readonly onParseError: () => void;
12
+ readonly throwOnError: false;
13
+ };
14
+ /**
15
+ * Fills in the default of each option that the config leaves out or sets to
16
+ * undefined. The result has only the options, so a `gridApi` or any other
17
+ * key in the config is not copied. The config is not changed.
18
+ *
19
+ * An empty `paramPrefix` is kept: the prefix rules read it as the default.
20
+ */
21
+ export declare function resolveOptions(options?: AGGridUrlSyncConfig): ResolvedOptions;