ag-grid-url-sync 0.5.0 → 0.5.2
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 +339 -66
- package/dist/core/ag-grid-url-sync.d.ts +16 -9
- package/dist/core/ag-grid-url-sync.js +23 -19
- package/dist/core/ag-grid-url-sync.js.map +1 -1
- package/dist/core/codecs.d.ts +28 -0
- package/dist/core/codecs.js +39 -0
- package/dist/core/codecs.js.map +1 -0
- package/dist/core/data-issue-codes.d.ts +3 -0
- package/dist/core/data-issue-codes.js +10 -0
- package/dist/core/data-issue-codes.js.map +1 -0
- package/dist/core/grid-integration.d.ts +38 -2
- package/dist/core/grid-integration.js +169 -128
- package/dist/core/grid-integration.js.map +1 -1
- package/dist/core/grid-url-sync.d.ts +62 -0
- package/dist/core/grid-url-sync.js +738 -0
- package/dist/core/grid-url-sync.js.map +1 -0
- package/dist/core/index.d.ts +4 -1
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/individual-params.d.ts +12 -5
- package/dist/core/individual-params.js +38 -62
- package/dist/core/individual-params.js.map +1 -1
- package/dist/core/issue-columns.d.ts +2 -0
- package/dist/core/issue-columns.js +11 -0
- package/dist/core/issue-columns.js.map +1 -0
- package/dist/core/issues.d.ts +34 -0
- package/dist/core/issues.js +51 -0
- package/dist/core/issues.js.map +1 -0
- package/dist/core/operators.d.ts +189 -0
- package/dist/core/operators.js +60 -0
- package/dist/core/operators.js.map +1 -0
- package/dist/core/options.d.ts +21 -0
- package/dist/core/options.js +21 -0
- package/dist/core/options.js.map +1 -0
- package/dist/core/own-write.d.ts +138 -0
- package/dist/core/own-write.js +133 -0
- package/dist/core/own-write.js.map +1 -0
- package/dist/core/schemas.d.ts +51 -0
- package/dist/core/schemas.js +59 -0
- package/dist/core/schemas.js.map +1 -0
- package/dist/core/serialization/formats.d.ts +7 -7
- package/dist/core/serialization/formats.js +34 -28
- package/dist/core/serialization/formats.js.map +1 -1
- package/dist/core/serialization/grouped.d.ts +9 -12
- package/dist/core/serialization/grouped.js +24 -17
- package/dist/core/serialization/grouped.js.map +1 -1
- package/dist/core/to-error.d.ts +5 -0
- package/dist/core/to-error.js +4 -0
- package/dist/core/to-error.js.map +1 -0
- package/dist/core/types.d.ts +296 -43
- package/dist/core/types.js +39 -108
- package/dist/core/types.js.map +1 -1
- package/dist/core/url-generator.d.ts +4 -4
- package/dist/core/url-generator.js +9 -7
- package/dist/core/url-generator.js.map +1 -1
- package/dist/core/url-parser.d.ts +4 -4
- package/dist/core/url-parser.js +6 -4
- package/dist/core/url-parser.js.map +1 -1
- package/dist/core/validation.d.ts +21 -14
- package/dist/core/validation.js +58 -54
- package/dist/core/validation.js.map +1 -1
- package/dist/core/view-storage.js +21 -19
- package/dist/core/view-storage.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/sync-holder.d.ts +22 -0
- package/dist/react/sync-holder.js +68 -0
- package/dist/react/sync-holder.js.map +1 -0
- package/dist/react/sync-options.d.ts +17 -0
- package/dist/react/sync-options.js +22 -0
- package/dist/react/sync-options.js.map +1 -0
- package/dist/react/types.d.ts +101 -14
- package/dist/react/use-ag-grid-url-sync.d.ts +3 -0
- package/dist/react/use-ag-grid-url-sync.js +344 -499
- package/dist/react/use-ag-grid-url-sync.js.map +1 -1
- package/dist/react/use-grid-url-sync.d.ts +14 -0
- package/dist/react/use-grid-url-sync.js +206 -0
- package/dist/react/use-grid-url-sync.js.map +1 -0
- package/package.json +35 -15
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { TEXT_FILTER_OPERATIONS, NUMBER_FILTER_OPERATIONS, DATE_FILTER_OPERATIONS } from './types.js';
|
|
3
|
+
export const JsonObjectSchema = v.record(v.string(), v.unknown());
|
|
4
|
+
const TextFilterSchema = v.object({
|
|
5
|
+
filterType: v.literal('text'),
|
|
6
|
+
type: v.picklist(TEXT_FILTER_OPERATIONS),
|
|
7
|
+
filter: v.string()
|
|
8
|
+
});
|
|
9
|
+
const NumberFilterSchema = v.object({
|
|
10
|
+
filterType: v.literal('number'),
|
|
11
|
+
type: v.picklist(NUMBER_FILTER_OPERATIONS),
|
|
12
|
+
filter: v.number(),
|
|
13
|
+
filterTo: v.exactOptional(v.number())
|
|
14
|
+
});
|
|
15
|
+
const DateFilterSchema = v.object({
|
|
16
|
+
filterType: v.literal('date'),
|
|
17
|
+
type: v.picklist(DATE_FILTER_OPERATIONS),
|
|
18
|
+
filter: v.string(),
|
|
19
|
+
filterTo: v.exactOptional(v.string())
|
|
20
|
+
});
|
|
21
|
+
export const ColumnFilterSchema = v.variant('filterType', [
|
|
22
|
+
TextFilterSchema,
|
|
23
|
+
NumberFilterSchema,
|
|
24
|
+
DateFilterSchema
|
|
25
|
+
]);
|
|
26
|
+
export const GridViewSchema = v.object({
|
|
27
|
+
id: v.string(),
|
|
28
|
+
name: v.string(),
|
|
29
|
+
updatedAt: v.number(),
|
|
30
|
+
filterModel: JsonObjectSchema
|
|
31
|
+
});
|
|
32
|
+
export const StoredViewsSchema = v.looseObject({
|
|
33
|
+
views: v.fallback(v.array(v.unknown()), []),
|
|
34
|
+
activeId: v.fallback(v.nullable(v.string()), null)
|
|
35
|
+
});
|
|
36
|
+
const agGridOperation = v.fallback(v.optional(v.string()), undefined);
|
|
37
|
+
const agGridValue = v.fallback(v.optional(v.union([v.string(), v.number(), v.null()])), undefined);
|
|
38
|
+
const agGridDate = v.fallback(v.optional(v.nullable(v.string())), undefined);
|
|
39
|
+
export const AgGridFilterSchema = v.variant('filterType', [
|
|
40
|
+
v.looseObject({
|
|
41
|
+
filterType: v.literal('text'),
|
|
42
|
+
type: agGridOperation,
|
|
43
|
+
filter: agGridValue
|
|
44
|
+
}),
|
|
45
|
+
v.looseObject({
|
|
46
|
+
filterType: v.literal('number'),
|
|
47
|
+
type: agGridOperation,
|
|
48
|
+
filter: agGridValue,
|
|
49
|
+
filterTo: agGridValue
|
|
50
|
+
}),
|
|
51
|
+
v.looseObject({
|
|
52
|
+
filterType: v.literal('date'),
|
|
53
|
+
type: agGridOperation,
|
|
54
|
+
filter: agGridValue,
|
|
55
|
+
dateFrom: agGridDate,
|
|
56
|
+
dateTo: agGridDate
|
|
57
|
+
})
|
|
58
|
+
]);
|
|
59
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/core/schemas.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAGnB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;AAMjE,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAA;AAEF,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,wBAAwB,CAAC;IAC1C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,QAAQ,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CACtC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC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EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EACvD,SAAS,CACV,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;AAG5E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE;IACxD,CAAC,CAAC,WAAW,CAAC;QACZ,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE,WAAW;KACpB,CAAC;IACF,CAAC,CAAC,WAAW,CAAC;QACZ,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC/B,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE,WAAW;QAEnB,QAAQ,EAAE,WAAW;KACtB,CAAC;IACF,CAAC,CAAC,WAAW,CAAC;QACZ,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE,UAAU;QACpB,MAAM,EAAE,UAAU;KACnB,CAAC;CACH,CAAC,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { FilterState, SerializationFormat, FormatSerializer,
|
|
1
|
+
import type { FilterState, SerializationFormat, FormatSerializer, AGGridUrlSyncConfig } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* QueryString format serializer
|
|
4
4
|
* Writes the individual filter parameters as one query string value
|
|
5
5
|
*/
|
|
6
6
|
export declare class QueryStringSerializer implements FormatSerializer {
|
|
7
7
|
readonly format: SerializationFormat;
|
|
8
|
-
serialize(filterState: FilterState, config?:
|
|
9
|
-
deserialize(value: string, config?:
|
|
8
|
+
serialize(filterState: FilterState, config?: AGGridUrlSyncConfig): string;
|
|
9
|
+
deserialize(value: string, config?: AGGridUrlSyncConfig): FilterState;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* JSON format serializer
|
|
@@ -14,8 +14,8 @@ export declare class QueryStringSerializer implements FormatSerializer {
|
|
|
14
14
|
*/
|
|
15
15
|
export declare class JsonSerializer implements FormatSerializer {
|
|
16
16
|
readonly format: SerializationFormat;
|
|
17
|
-
serialize(filterState: FilterState, config?:
|
|
18
|
-
deserialize(value: string, config?:
|
|
17
|
+
serialize(filterState: FilterState, config?: AGGridUrlSyncConfig): string;
|
|
18
|
+
deserialize(value: string, config?: AGGridUrlSyncConfig): FilterState;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Base64 format serializer
|
|
@@ -23,6 +23,6 @@ export declare class JsonSerializer implements FormatSerializer {
|
|
|
23
23
|
*/
|
|
24
24
|
export declare class Base64Serializer implements FormatSerializer {
|
|
25
25
|
readonly format: SerializationFormat;
|
|
26
|
-
serialize(filterState: FilterState, config?:
|
|
27
|
-
deserialize(value: string, config?:
|
|
26
|
+
serialize(filterState: FilterState, config?: AGGridUrlSyncConfig): string;
|
|
27
|
+
deserialize(value: string, config?: AGGridUrlSyncConfig): FilterState;
|
|
28
28
|
}
|
|
@@ -1,38 +1,45 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
1
2
|
import { InvalidSerializationError } from '../types.js';
|
|
2
3
|
import { parseIndividualParams, serializeFilters } from '../individual-params.js';
|
|
3
|
-
import {
|
|
4
|
+
import { validateFilterValue } from '../validation.js';
|
|
5
|
+
import { DEFAULT_CONFIG, resolveOptions } from '../options.js';
|
|
6
|
+
import { reportIssue, rethrowIfThrown, toIssue } from '../issues.js';
|
|
7
|
+
import { ColumnFilterSchema, JsonObjectSchema } from '../schemas.js';
|
|
8
|
+
import { toError } from '../to-error.js';
|
|
4
9
|
function dropOverLengthTextValues(filterState, config, format) {
|
|
5
|
-
const cfg = config
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
catch (error) {
|
|
13
|
-
cfg.onParseError?.(new InvalidSerializationError(format, error));
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
10
|
+
const cfg = resolveOptions(config);
|
|
11
|
+
const kept = Object.entries(filterState).filter(([column, filter]) => {
|
|
12
|
+
if (filter.filterType !== 'text')
|
|
13
|
+
return true;
|
|
14
|
+
try {
|
|
15
|
+
validateFilterValue(filter.filter, cfg, filter.type);
|
|
16
|
+
return true;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
catch (error) {
|
|
19
|
+
const issue = toIssue(error, 'VALUE_TOO_LONG', column);
|
|
20
|
+
reportIssue(cfg, new InvalidSerializationError(format, issue));
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return Object.fromEntries(kept);
|
|
20
25
|
}
|
|
21
26
|
function parseAndValidateJson(value) {
|
|
22
27
|
try {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
28
|
+
const json = JSON.parse(value);
|
|
29
|
+
if (!v.is(JsonObjectSchema, json)) {
|
|
25
30
|
throw new Error('Invalid JSON: must be an object');
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
const entries = Object.entries(json).map(([columnId, filter]) => {
|
|
33
|
+
const column = v.safeParse(ColumnFilterSchema, filter);
|
|
34
|
+
if (!column.success) {
|
|
29
35
|
throw new Error(`Invalid JSON: filter for column ${columnId} is not a valid filter object`);
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
return [columnId, column.output];
|
|
38
|
+
});
|
|
39
|
+
return Object.fromEntries(entries);
|
|
33
40
|
}
|
|
34
41
|
catch (error) {
|
|
35
|
-
throw new Error(`JSON parsing failed: ${error.message}`);
|
|
42
|
+
throw new Error(`JSON parsing failed: ${toError(error).message}`);
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
export class QueryStringSerializer {
|
|
@@ -45,13 +52,11 @@ export class QueryStringSerializer {
|
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
function innerConfig(config) {
|
|
48
|
-
|
|
49
|
-
return DEFAULT_CONFIG;
|
|
50
|
-
const onParseError = config.onParseError ?? DEFAULT_CONFIG.onParseError;
|
|
55
|
+
const outer = resolveOptions(config);
|
|
51
56
|
return {
|
|
52
57
|
...DEFAULT_CONFIG,
|
|
53
|
-
maxValueLength:
|
|
54
|
-
onParseError: error =>
|
|
58
|
+
maxValueLength: outer.maxValueLength,
|
|
59
|
+
onParseError: error => reportIssue(outer, new InvalidSerializationError('querystring', error))
|
|
55
60
|
};
|
|
56
61
|
}
|
|
57
62
|
export class JsonSerializer {
|
|
@@ -75,7 +80,8 @@ export class Base64Serializer {
|
|
|
75
80
|
return dropOverLengthTextValues(parseAndValidateJson(decoded), config, 'base64');
|
|
76
81
|
}
|
|
77
82
|
catch (error) {
|
|
78
|
-
|
|
83
|
+
rethrowIfThrown(error);
|
|
84
|
+
throw new Error(`Base64 decoding failed: ${toError(error).message}`);
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.js","sourceRoot":"","sources":["../../../src/core/serialization/formats.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formats.js","sourceRoot":"","sources":["../../../src/core/serialization/formats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAQ5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,eAA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AC,CAAC,EAAE,GAAG,CAAC,EAAE,CACjE,CAAA;AACH,CAAC"}
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
import type { FilterState, SerializationFormat, FormatSerializer, GroupedSerializationResult,
|
|
1
|
+
import type { FilterState, SerializationFormat, FormatSerializer, GroupedSerializationResult, GroupedDetectionResult, AGGridUrlSyncConfig } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Serialize filter state using grouped serialization
|
|
4
4
|
* @param filterState - The filter state to serialize
|
|
5
|
-
* @param config -
|
|
5
|
+
* @param config - Options (no grid needed). An option that is left out gets
|
|
6
|
+
* its default.
|
|
6
7
|
* @returns Grouped serialization result with parameter name and value
|
|
7
8
|
*/
|
|
8
|
-
export declare function serializeGrouped(filterState: FilterState, config
|
|
9
|
+
export declare function serializeGrouped(filterState: FilterState, config?: AGGridUrlSyncConfig): GroupedSerializationResult;
|
|
9
10
|
/**
|
|
10
11
|
* Deserialize grouped filter state from URL parameter value
|
|
11
12
|
* @param value - The serialized value from URL parameter
|
|
12
13
|
* @param format - The serialization format to use
|
|
13
|
-
* @param config -
|
|
14
|
+
* @param config - Options for validation and error handling (no grid
|
|
15
|
+
* needed). An option that is left out gets its default.
|
|
14
16
|
* @returns Deserialized filter state
|
|
15
17
|
*/
|
|
16
|
-
export declare function deserializeGrouped(value: string, format: SerializationFormat, config
|
|
18
|
+
export declare function deserializeGrouped(value: string, format: SerializationFormat, config?: AGGridUrlSyncConfig): FilterState;
|
|
17
19
|
/**
|
|
18
20
|
* Detect if a URL contains grouped serialization parameters
|
|
19
21
|
*
|
|
20
22
|
* @deprecated parseUrlFilters no longer uses this. It reads only
|
|
21
23
|
* `config.groupedParam` and decodes it with `config.format`, because a guessed
|
|
22
24
|
* format takes any non-empty value as grouped filters (#210). This function
|
|
23
|
-
* will be removed in
|
|
25
|
+
* will be removed in 0.6.0.
|
|
24
26
|
* @param url - URL to analyze
|
|
25
27
|
* @param possibleParams - Array of possible grouped parameter names to check
|
|
26
28
|
* @returns Detection result with format and value if found
|
|
27
29
|
*/
|
|
28
|
-
export declare function detectGroupedSerialization(url: string, possibleParams: string[]):
|
|
29
|
-
isGrouped: boolean;
|
|
30
|
-
paramName?: string;
|
|
31
|
-
format?: SerializationFormat;
|
|
32
|
-
value?: string;
|
|
33
|
-
};
|
|
30
|
+
export declare function detectGroupedSerialization(url: string, possibleParams: string[]): GroupedDetectionResult;
|
|
34
31
|
/**
|
|
35
32
|
* Get all available serialization formats
|
|
36
33
|
*/
|
|
@@ -1,42 +1,51 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
1
2
|
import { InvalidSerializationError } from '../types.js';
|
|
2
3
|
import { QueryStringSerializer, JsonSerializer, Base64Serializer } from './formats.js';
|
|
4
|
+
import { JsonObjectSchema } from '../schemas.js';
|
|
5
|
+
import { toError } from '../to-error.js';
|
|
6
|
+
import { resolveOptions } from '../options.js';
|
|
7
|
+
import { reportIssue, rethrowIfThrown } from '../issues.js';
|
|
3
8
|
const FORMAT_SERIALIZERS = {
|
|
4
9
|
querystring: new QueryStringSerializer(),
|
|
5
10
|
json: new JsonSerializer(),
|
|
6
11
|
base64: new Base64Serializer()
|
|
7
12
|
};
|
|
8
|
-
export function serializeGrouped(filterState, config) {
|
|
13
|
+
export function serializeGrouped(filterState, config = {}) {
|
|
14
|
+
const options = resolveOptions(config);
|
|
9
15
|
try {
|
|
10
|
-
const serializer = FORMAT_SERIALIZERS[
|
|
16
|
+
const serializer = FORMAT_SERIALIZERS[options.format];
|
|
11
17
|
if (!serializer) {
|
|
12
|
-
throw new Error(`Unknown serialization format: ${
|
|
18
|
+
throw new Error(`Unknown serialization format: ${options.format}`);
|
|
13
19
|
}
|
|
14
|
-
const value = serializer.serialize(filterState,
|
|
20
|
+
const value = serializer.serialize(filterState, options);
|
|
15
21
|
return {
|
|
16
|
-
paramName:
|
|
22
|
+
paramName: options.groupedParam,
|
|
17
23
|
value
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
26
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
rethrowIfThrown(error);
|
|
28
|
+
const serializationError = new InvalidSerializationError(options.format, toError(error));
|
|
29
|
+
reportIssue(options, serializationError);
|
|
23
30
|
return {
|
|
24
|
-
paramName:
|
|
31
|
+
paramName: options.groupedParam,
|
|
25
32
|
value: ''
|
|
26
33
|
};
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
|
-
export function deserializeGrouped(value, format, config) {
|
|
36
|
+
export function deserializeGrouped(value, format, config = {}) {
|
|
37
|
+
const options = resolveOptions(config);
|
|
30
38
|
try {
|
|
31
39
|
const serializer = FORMAT_SERIALIZERS[format];
|
|
32
40
|
if (!serializer) {
|
|
33
41
|
throw new Error(`Unknown serialization format: ${format}`);
|
|
34
42
|
}
|
|
35
|
-
return serializer.deserialize(value,
|
|
43
|
+
return serializer.deserialize(value, options);
|
|
36
44
|
}
|
|
37
45
|
catch (error) {
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
rethrowIfThrown(error);
|
|
47
|
+
const serializationError = new InvalidSerializationError(format, toError(error));
|
|
48
|
+
reportIssue(options, serializationError);
|
|
40
49
|
return {};
|
|
41
50
|
}
|
|
42
51
|
}
|
|
@@ -59,8 +68,7 @@ export function detectGroupedSerialization(url, possibleParams) {
|
|
|
59
68
|
}
|
|
60
69
|
return { isGrouped: false };
|
|
61
70
|
}
|
|
62
|
-
catch
|
|
63
|
-
console.error(`Error detecting grouped serialization: ${error}`);
|
|
71
|
+
catch {
|
|
64
72
|
return { isGrouped: false };
|
|
65
73
|
}
|
|
66
74
|
}
|
|
@@ -89,15 +97,14 @@ function isBase64Format(value) {
|
|
|
89
97
|
}
|
|
90
98
|
function isJsonFormat(value) {
|
|
91
99
|
try {
|
|
92
|
-
|
|
93
|
-
return typeof parsed === 'object' && parsed !== null;
|
|
100
|
+
return v.is(JsonObjectSchema, JSON.parse(value));
|
|
94
101
|
}
|
|
95
102
|
catch {
|
|
96
103
|
return false;
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
106
|
export function getAvailableFormats() {
|
|
100
|
-
return Object.
|
|
107
|
+
return Object.values(FORMAT_SERIALIZERS).map(serializer => serializer.format);
|
|
101
108
|
}
|
|
102
109
|
export function getFormatSerializer(format) {
|
|
103
110
|
return FORMAT_SERIALIZERS[format] || null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grouped.js","sourceRoot":"","sources":["../../../src/core/serialization/grouped.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"grouped.js","sourceRoot":"","sources":["../../../src/core/serialization/grouped.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAS5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAK3D,MAAM,kBAAkB,GAAkD;IACxE,WAAW,EAAE,IAAI,qBAAqB,EAAE;IACxC,IAAI,EAAE,IAAI,cAAc,EAAE;IAC1B,MAAM,EAAE,IAAI,gBAAgB,EAAE;CAC/B,CAAA;AASD,MAAM,UAAU,gBAAgB,CAC9B,WAAwB,EACxB,MAAM,GAAwB,EAAE;IAEhC,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,CAAA;IAEtC,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAErD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,CAAC,MAAM,EAAE,CAA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