@searchspring/snap-url-manager 0.26.1 → 0.27.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/dist/cjs/Translators/Url/UrlTranslator.d.ts +29 -25
- package/dist/cjs/Translators/Url/UrlTranslator.d.ts.map +1 -1
- package/dist/cjs/Translators/Url/UrlTranslator.js +30 -29
- package/dist/cjs/UrlManager/UrlManager.d.ts +1 -1
- package/dist/cjs/UrlManager/UrlManager.d.ts.map +1 -1
- package/dist/cjs/types.d.ts +2 -2
- package/dist/cjs/types.js +2 -2
- package/dist/esm/Translators/Url/UrlTranslator.d.ts +29 -25
- package/dist/esm/Translators/Url/UrlTranslator.d.ts.map +1 -1
- package/dist/esm/Translators/Url/UrlTranslator.js +29 -28
- package/dist/esm/UrlManager/UrlManager.d.ts +5 -5
- package/dist/esm/UrlManager/UrlManager.d.ts.map +1 -1
- package/dist/esm/types.d.ts +2 -2
- package/dist/esm/types.js +2 -2
- package/package.json +2 -2
|
@@ -2,45 +2,49 @@ import { UrlState, Translator, ParamLocationType } from '../../types';
|
|
|
2
2
|
declare type UrlParameter = {
|
|
3
3
|
key: Array<string>;
|
|
4
4
|
value: string;
|
|
5
|
-
type: ParamLocationType;
|
|
5
|
+
type: keyof typeof ParamLocationType;
|
|
6
6
|
};
|
|
7
7
|
declare type MapOptions = {
|
|
8
|
-
name
|
|
9
|
-
type
|
|
8
|
+
name: string;
|
|
9
|
+
type: keyof typeof ParamLocationType;
|
|
10
10
|
};
|
|
11
|
-
declare type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
declare type UnnamedMapOptions = {
|
|
12
|
+
type: keyof typeof ParamLocationType;
|
|
13
|
+
};
|
|
14
|
+
export declare type CoreMap = {
|
|
15
|
+
query: MapOptions;
|
|
16
|
+
oq: MapOptions;
|
|
17
|
+
rq: MapOptions;
|
|
18
|
+
tag: MapOptions;
|
|
19
|
+
page: MapOptions;
|
|
20
|
+
pageSize: MapOptions;
|
|
21
|
+
sort: MapOptions;
|
|
22
|
+
filter: MapOptions;
|
|
20
23
|
};
|
|
21
24
|
declare type CustomMap = {
|
|
22
|
-
[param: string]:
|
|
23
|
-
type?: ParamLocationType;
|
|
24
|
-
};
|
|
25
|
+
[param: string]: UnnamedMapOptions;
|
|
25
26
|
};
|
|
26
27
|
export declare type UrlTranslatorParametersConfig = {
|
|
27
|
-
core
|
|
28
|
-
custom
|
|
28
|
+
core: CoreMap;
|
|
29
|
+
custom: CustomMap;
|
|
29
30
|
};
|
|
30
31
|
export declare type UrlTranslatorConfig = {
|
|
31
|
-
urlRoot
|
|
32
|
-
settings
|
|
33
|
-
corePrefix
|
|
34
|
-
coreType?: ParamLocationType;
|
|
35
|
-
customType
|
|
36
|
-
rootParams
|
|
32
|
+
urlRoot: string;
|
|
33
|
+
settings: {
|
|
34
|
+
corePrefix: string;
|
|
35
|
+
coreType?: keyof typeof ParamLocationType;
|
|
36
|
+
customType: keyof typeof ParamLocationType;
|
|
37
|
+
rootParams: boolean;
|
|
37
38
|
};
|
|
38
|
-
parameters
|
|
39
|
+
parameters: UrlTranslatorParametersConfig;
|
|
39
40
|
};
|
|
41
|
+
declare type DeepPartial<T> = Partial<{
|
|
42
|
+
[P in keyof T]: DeepPartial<T[P]>;
|
|
43
|
+
}>;
|
|
40
44
|
export declare class UrlTranslator implements Translator {
|
|
41
45
|
protected config: UrlTranslatorConfig;
|
|
42
46
|
protected reverseMapping: Record<string, string>;
|
|
43
|
-
constructor(config?: UrlTranslatorConfig);
|
|
47
|
+
constructor(config?: DeepPartial<UrlTranslatorConfig>);
|
|
44
48
|
bindExternalEvents(update: () => void): void;
|
|
45
49
|
getCurrentUrl(): string;
|
|
46
50
|
getConfig(): UrlTranslatorConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UrlTranslator.d.ts","sourceRoot":"","sources":["../../../../src/Translators/Url/UrlTranslator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAA0D,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE9H,aAAK,YAAY,GAAG;IACnB,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"UrlTranslator.d.ts","sourceRoot":"","sources":["../../../../src/Translators/Url/UrlTranslator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAA0D,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE9H,aAAK,YAAY,GAAG;IACnB,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,OAAO,iBAAiB,CAAC;CACrC,CAAC;AAEF,aAAK,UAAU,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,OAAO,iBAAiB,CAAC;CACrC,CAAC;AAEF,aAAK,iBAAiB,GAAG;IACxB,IAAI,EAAE,MAAM,OAAO,iBAAiB,CAAC;CACrC,CAAC;AAEF,oBAAY,OAAO,GAAG;IACrB,KAAK,EAAE,UAAU,CAAC;IAClB,EAAE,EAAE,UAAU,CAAC;IACf,EAAE,EAAE,UAAU,CAAC;IACf,GAAG,EAAE,UAAU,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,UAAU,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF,aAAK,SAAS,GAAG;IAChB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAC;CACnC,CAAC;AAEF,oBAAY,6BAA6B,GAAG;IAC3C,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,SAAS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E,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,QAAQ;IA2DtE,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,QAAQ;IAalE,SAAS,CAAC,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,QAAQ;IAsBhE,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IA0ClC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC;IAS7D,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC;IAyDjE,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC;IAgB/D,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC;IAsBjF,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC;IAwC3D,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAUnD"}
|
|
@@ -30,19 +30,19 @@ var defaultConfig = {
|
|
|
30
30
|
urlRoot: '',
|
|
31
31
|
settings: {
|
|
32
32
|
corePrefix: '',
|
|
33
|
-
customType: types_1.ParamLocationType.
|
|
33
|
+
customType: types_1.ParamLocationType.hash,
|
|
34
34
|
rootParams: true,
|
|
35
35
|
},
|
|
36
36
|
parameters: {
|
|
37
37
|
core: {
|
|
38
|
-
query: { name: 'q', type: types_1.ParamLocationType.
|
|
39
|
-
oq: { name: 'oq', type: types_1.ParamLocationType.
|
|
40
|
-
rq: { name: 'rq', type: types_1.ParamLocationType.
|
|
41
|
-
tag: { name: 'tag', type: types_1.ParamLocationType.
|
|
42
|
-
page: { name: 'page', type: types_1.ParamLocationType.
|
|
43
|
-
pageSize: { name: 'pageSize', type: types_1.ParamLocationType.
|
|
44
|
-
sort: { name: 'sort', type: types_1.ParamLocationType.
|
|
45
|
-
filter: { name: 'filter', type: types_1.ParamLocationType.
|
|
38
|
+
query: { name: 'q', type: types_1.ParamLocationType.query },
|
|
39
|
+
oq: { name: 'oq', type: types_1.ParamLocationType.query },
|
|
40
|
+
rq: { name: 'rq', type: types_1.ParamLocationType.query },
|
|
41
|
+
tag: { name: 'tag', type: types_1.ParamLocationType.query },
|
|
42
|
+
page: { name: 'page', type: types_1.ParamLocationType.query },
|
|
43
|
+
pageSize: { name: 'pageSize', type: types_1.ParamLocationType.hash },
|
|
44
|
+
sort: { name: 'sort', type: types_1.ParamLocationType.hash },
|
|
45
|
+
filter: { name: 'filter', type: types_1.ParamLocationType.hash },
|
|
46
46
|
},
|
|
47
47
|
custom: {},
|
|
48
48
|
},
|
|
@@ -50,28 +50,29 @@ var defaultConfig = {
|
|
|
50
50
|
var CORE_FIELDS = ['query', 'oq', 'rq', 'tag', 'page', 'pageSize', 'sort', 'filter'];
|
|
51
51
|
var UrlTranslator = /** @class */ (function () {
|
|
52
52
|
function UrlTranslator(config) {
|
|
53
|
-
if (config === void 0) { config = {}; }
|
|
54
53
|
var _this = this;
|
|
54
|
+
var _a;
|
|
55
55
|
this.reverseMapping = {};
|
|
56
|
-
this.config = (0, deepmerge_1.default)(defaultConfig, config);
|
|
56
|
+
this.config = (0, deepmerge_1.default)(defaultConfig, config || {});
|
|
57
57
|
Object.keys(this.config.parameters.core).forEach(function (param) {
|
|
58
|
-
var _a, _b
|
|
58
|
+
var _a, _b;
|
|
59
|
+
var coreParam = _this.config.parameters.core[param];
|
|
59
60
|
// param prefix
|
|
60
61
|
if (_this.config.settings.corePrefix) {
|
|
61
|
-
|
|
62
|
+
coreParam.name = _this.config.settings.corePrefix + coreParam.name;
|
|
62
63
|
}
|
|
63
64
|
// global type override
|
|
64
|
-
var paramType = _this.config.settings.coreType;
|
|
65
|
+
var paramType = (_a = _this.config.settings) === null || _a === void 0 ? void 0 : _a.coreType;
|
|
65
66
|
if (paramType && Object.values(types_1.ParamLocationType).includes(paramType)) {
|
|
66
|
-
|
|
67
|
+
coreParam.type = (((_b = config === null || config === void 0 ? void 0 : config.parameters) === null || _b === void 0 ? void 0 : _b.core) && coreParam.type) || paramType;
|
|
67
68
|
}
|
|
68
69
|
// create reverse mapping for quick lookup later
|
|
69
|
-
_this.reverseMapping[
|
|
70
|
+
_this.reverseMapping[coreParam.name] = param;
|
|
70
71
|
});
|
|
71
|
-
var implicit = this.config.settings.customType;
|
|
72
|
+
var implicit = (_a = this.config.settings) === null || _a === void 0 ? void 0 : _a.customType;
|
|
72
73
|
if (implicit && !Object.values(types_1.ParamLocationType).includes(implicit)) {
|
|
73
74
|
// invalid type specified - falling back to hash as implicit type
|
|
74
|
-
this.config.settings.customType = types_1.ParamLocationType.
|
|
75
|
+
this.config.settings.customType = types_1.ParamLocationType.hash;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
UrlTranslator.prototype.bindExternalEvents = function (update) {
|
|
@@ -100,7 +101,7 @@ var UrlTranslator = /** @class */ (function () {
|
|
|
100
101
|
.filter(function (v) { return v; })
|
|
101
102
|
.map(function (kvPair) {
|
|
102
103
|
var _a = kvPair.split('=').map(function (v) { return decodeURIComponent(v.replace(/\+/g, ' ')); }), key = _a[0], value = _a[1];
|
|
103
|
-
return { key: key.split('.'), value: value, type: types_1.ParamLocationType.
|
|
104
|
+
return { key: key.split('.'), value: value, type: types_1.ParamLocationType.query };
|
|
104
105
|
})
|
|
105
106
|
.filter(function (param) {
|
|
106
107
|
// remove core fields that do not contain a value
|
|
@@ -126,17 +127,17 @@ var UrlTranslator = /** @class */ (function () {
|
|
|
126
127
|
})
|
|
127
128
|
.forEach(function (decodedHashEntries) {
|
|
128
129
|
if (decodedHashEntries.length == 1) {
|
|
129
|
-
params.push({ key: [decodedHashEntries[0]], value:
|
|
130
|
+
params.push({ key: [decodedHashEntries[0]], value: '', type: types_1.ParamLocationType.hash });
|
|
130
131
|
}
|
|
131
132
|
else if (decodedHashEntries.length && decodedHashEntries.length <= 3) {
|
|
132
133
|
var _a = decodedHashEntries.reverse(), value = _a[0], keys = _a.slice(1);
|
|
133
|
-
params.push({ key: keys.reverse(), value: value, type: types_1.ParamLocationType.
|
|
134
|
+
params.push({ key: keys.reverse(), value: value, type: types_1.ParamLocationType.hash });
|
|
134
135
|
}
|
|
135
136
|
else if (decodedHashEntries.length && decodedHashEntries.length == 4) {
|
|
136
137
|
// range filter
|
|
137
138
|
var path0 = decodedHashEntries[0], path1 = decodedHashEntries[1], low = decodedHashEntries[2], high = decodedHashEntries[3];
|
|
138
|
-
params.push({ key: [path0, path1, 'low'], value: low, type: types_1.ParamLocationType.
|
|
139
|
-
params.push({ key: [path0, path1, 'high'], value: high, type: types_1.ParamLocationType.
|
|
139
|
+
params.push({ key: [path0, path1, 'low'], value: low, type: types_1.ParamLocationType.hash });
|
|
140
|
+
params.push({ key: [path0, path1, 'high'], value: high, type: types_1.ParamLocationType.hash });
|
|
140
141
|
}
|
|
141
142
|
});
|
|
142
143
|
return params;
|
|
@@ -284,8 +285,8 @@ var UrlTranslator = /** @class */ (function () {
|
|
|
284
285
|
var rootUrlParams = this.config.settings.rootParams ? this.parseUrlParams(this.config.urlRoot) : [];
|
|
285
286
|
var stateParams = this.stateToParams(state);
|
|
286
287
|
var params = __spreadArray(__spreadArray([], rootUrlParams, true), stateParams, true);
|
|
287
|
-
var queryParams = params.filter(function (p) { return p.type == types_1.ParamLocationType.
|
|
288
|
-
var hashParams = params.filter(function (p) { return p.type == types_1.ParamLocationType.
|
|
288
|
+
var queryParams = params.filter(function (p) { return p.type == types_1.ParamLocationType.query; });
|
|
289
|
+
var hashParams = params.filter(function (p) { return p.type == types_1.ParamLocationType.hash; });
|
|
289
290
|
var paramString = (queryParams.length
|
|
290
291
|
? '?' +
|
|
291
292
|
queryParams
|
|
@@ -338,7 +339,7 @@ var UrlTranslator = /** @class */ (function () {
|
|
|
338
339
|
else if (typeof value == 'object' &&
|
|
339
340
|
typeof value[types_1.RangeValueProperties.LOW] != 'undefined' &&
|
|
340
341
|
typeof value[types_1.RangeValueProperties.HIGH] != 'undefined') {
|
|
341
|
-
if (filterConfig.type == types_1.ParamLocationType.
|
|
342
|
+
if (filterConfig.type == types_1.ParamLocationType.query) {
|
|
342
343
|
return [
|
|
343
344
|
{
|
|
344
345
|
key: [filterConfig.name, key, types_1.RangeValueProperties.LOW],
|
|
@@ -352,7 +353,7 @@ var UrlTranslator = /** @class */ (function () {
|
|
|
352
353
|
},
|
|
353
354
|
];
|
|
354
355
|
}
|
|
355
|
-
else if (filterConfig.type == types_1.ParamLocationType.
|
|
356
|
+
else if (filterConfig.type == types_1.ParamLocationType.hash) {
|
|
356
357
|
return [
|
|
357
358
|
{
|
|
358
359
|
key: [filterConfig.name, key, '' + ((_c = value[types_1.RangeValueProperties.LOW]) !== null && _c !== void 0 ? _c : '*')],
|
|
@@ -418,10 +419,10 @@ var UrlTranslator = /** @class */ (function () {
|
|
|
418
419
|
}));
|
|
419
420
|
}
|
|
420
421
|
else {
|
|
421
|
-
params = params.concat({ key: __spreadArray(__spreadArray([], currentPath, true), [key], false), value:
|
|
422
|
+
params = params.concat({ key: __spreadArray(__spreadArray([], currentPath, true), [key], false), value: '', type: type_1 });
|
|
422
423
|
}
|
|
423
424
|
}
|
|
424
|
-
else if (typeof value == 'object' && Object.keys(value).length) {
|
|
425
|
+
else if (typeof value == 'object' && Object.keys(value || {}).length) {
|
|
425
426
|
addRecursive(value, __spreadArray(__spreadArray([], currentPath, true), [key], false));
|
|
426
427
|
}
|
|
427
428
|
else {
|
|
@@ -44,7 +44,7 @@ export declare class UrlManager {
|
|
|
44
44
|
}): void;
|
|
45
45
|
detach(reset?: boolean): UrlManager;
|
|
46
46
|
get link(): Record<string, any>;
|
|
47
|
-
subscribe(cb: (prev
|
|
47
|
+
subscribe(cb: (prev?: ImmutableObject<UrlState>, next?: ImmutableObject<UrlState>) => void): () => void;
|
|
48
48
|
}
|
|
49
49
|
export {};
|
|
50
50
|
//# sourceMappingURL=UrlManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UrlManager.d.ts","sourceRoot":"","sources":["../../../src/UrlManager/UrlManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,aAAK,QAAQ,GAAG;IACf,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACpB,CAAC;AAEF,cAAM,WAAW;IAChB,OAAO,CAAC,SAAS,CAAyB;;IAM1C,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI;IAMxB,MAAM;CAGN;AAED,qBAAa,UAAU;IAcd,MAAM,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAInE,OAAO,CAAC,SAAS;IACV,QAAQ,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;IAlBlC,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,QAAQ,CAAyE;IACzF,OAAO,CAAC,WAAW,CAAyE;IAC5F,OAAO,CAAC,UAAU,CAAyE;IAC3F,OAAO,CAAC,WAAW,CAAyE;IAE5F,OAAO,CAAC,SAAS,CAAC,CAA4B;IAE9C,OAAO,CAAC,WAAW,CAAc;gBAGhC,UAAU,EAAE,UAAU,EACf,MAAM,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnE,WAAW,CAAC,EAAE,QAAQ,GAAG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MjC,IAAI,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAM9B;IAED,SAAS,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;CAQvG"}
|
package/dist/cjs/types.d.ts
CHANGED
package/dist/cjs/types.js
CHANGED
|
@@ -8,6 +8,6 @@ var RangeValueProperties;
|
|
|
8
8
|
})(RangeValueProperties = exports.RangeValueProperties || (exports.RangeValueProperties = {}));
|
|
9
9
|
var ParamLocationType;
|
|
10
10
|
(function (ParamLocationType) {
|
|
11
|
-
ParamLocationType["
|
|
12
|
-
ParamLocationType["
|
|
11
|
+
ParamLocationType["hash"] = "hash";
|
|
12
|
+
ParamLocationType["query"] = "query";
|
|
13
13
|
})(ParamLocationType = exports.ParamLocationType || (exports.ParamLocationType = {}));
|
|
@@ -2,45 +2,49 @@ import { UrlState, Translator, ParamLocationType } from '../../types';
|
|
|
2
2
|
declare type UrlParameter = {
|
|
3
3
|
key: Array<string>;
|
|
4
4
|
value: string;
|
|
5
|
-
type: ParamLocationType;
|
|
5
|
+
type: keyof typeof ParamLocationType;
|
|
6
6
|
};
|
|
7
7
|
declare type MapOptions = {
|
|
8
|
-
name
|
|
9
|
-
type
|
|
8
|
+
name: string;
|
|
9
|
+
type: keyof typeof ParamLocationType;
|
|
10
10
|
};
|
|
11
|
-
declare type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
declare type UnnamedMapOptions = {
|
|
12
|
+
type: keyof typeof ParamLocationType;
|
|
13
|
+
};
|
|
14
|
+
export declare type CoreMap = {
|
|
15
|
+
query: MapOptions;
|
|
16
|
+
oq: MapOptions;
|
|
17
|
+
rq: MapOptions;
|
|
18
|
+
tag: MapOptions;
|
|
19
|
+
page: MapOptions;
|
|
20
|
+
pageSize: MapOptions;
|
|
21
|
+
sort: MapOptions;
|
|
22
|
+
filter: MapOptions;
|
|
20
23
|
};
|
|
21
24
|
declare type CustomMap = {
|
|
22
|
-
[param: string]:
|
|
23
|
-
type?: ParamLocationType;
|
|
24
|
-
};
|
|
25
|
+
[param: string]: UnnamedMapOptions;
|
|
25
26
|
};
|
|
26
27
|
export declare type UrlTranslatorParametersConfig = {
|
|
27
|
-
core
|
|
28
|
-
custom
|
|
28
|
+
core: CoreMap;
|
|
29
|
+
custom: CustomMap;
|
|
29
30
|
};
|
|
30
31
|
export declare type UrlTranslatorConfig = {
|
|
31
|
-
urlRoot
|
|
32
|
-
settings
|
|
33
|
-
corePrefix
|
|
34
|
-
coreType?: ParamLocationType;
|
|
35
|
-
customType
|
|
36
|
-
rootParams
|
|
32
|
+
urlRoot: string;
|
|
33
|
+
settings: {
|
|
34
|
+
corePrefix: string;
|
|
35
|
+
coreType?: keyof typeof ParamLocationType;
|
|
36
|
+
customType: keyof typeof ParamLocationType;
|
|
37
|
+
rootParams: boolean;
|
|
37
38
|
};
|
|
38
|
-
parameters
|
|
39
|
+
parameters: UrlTranslatorParametersConfig;
|
|
39
40
|
};
|
|
41
|
+
declare type DeepPartial<T> = Partial<{
|
|
42
|
+
[P in keyof T]: DeepPartial<T[P]>;
|
|
43
|
+
}>;
|
|
40
44
|
export declare class UrlTranslator implements Translator {
|
|
41
45
|
protected config: UrlTranslatorConfig;
|
|
42
46
|
protected reverseMapping: Record<string, string>;
|
|
43
|
-
constructor(config?: UrlTranslatorConfig);
|
|
47
|
+
constructor(config?: DeepPartial<UrlTranslatorConfig>);
|
|
44
48
|
bindExternalEvents(update: () => void): void;
|
|
45
49
|
getCurrentUrl(): string;
|
|
46
50
|
getConfig(): UrlTranslatorConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UrlTranslator.d.ts","sourceRoot":"","sources":["../../../../src/Translators/Url/UrlTranslator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAA0D,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE9H,aAAK,YAAY,GAAG;IACnB,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"UrlTranslator.d.ts","sourceRoot":"","sources":["../../../../src/Translators/Url/UrlTranslator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAA0D,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE9H,aAAK,YAAY,GAAG;IACnB,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,OAAO,iBAAiB,CAAC;CACrC,CAAC;AAEF,aAAK,UAAU,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,OAAO,iBAAiB,CAAC;CACrC,CAAC;AAEF,aAAK,iBAAiB,GAAG;IACxB,IAAI,EAAE,MAAM,OAAO,iBAAiB,CAAC;CACrC,CAAC;AAEF,oBAAY,OAAO,GAAG;IACrB,KAAK,EAAE,UAAU,CAAC;IAClB,EAAE,EAAE,UAAU,CAAC;IACf,EAAE,EAAE,UAAU,CAAC;IACf,GAAG,EAAE,UAAU,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,UAAU,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF,aAAK,SAAS,GAAG;IAChB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAC;CACnC,CAAC;AAEF,oBAAY,6BAA6B,GAAG;IAC3C,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,o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YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,QAAQ;IA2DtE,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,QAAQ;IAalE,SAAS,CAAC,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,QAAQ;IAsBhE,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IA0ClC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC;IAS7D,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC;IAyDjE,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC;IAgB/D,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC;IAsBjF,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC;IAwC3D,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAUnD"}
|
|
@@ -4,45 +4,46 @@ const defaultConfig = {
|
|
|
4
4
|
urlRoot: '',
|
|
5
5
|
settings: {
|
|
6
6
|
corePrefix: '',
|
|
7
|
-
customType: ParamLocationType.
|
|
7
|
+
customType: ParamLocationType.hash,
|
|
8
8
|
rootParams: true,
|
|
9
9
|
},
|
|
10
10
|
parameters: {
|
|
11
11
|
core: {
|
|
12
|
-
query: { name: 'q', type: ParamLocationType.
|
|
13
|
-
oq: { name: 'oq', type: ParamLocationType.
|
|
14
|
-
rq: { name: 'rq', type: ParamLocationType.
|
|
15
|
-
tag: { name: 'tag', type: ParamLocationType.
|
|
16
|
-
page: { name: 'page', type: ParamLocationType.
|
|
17
|
-
pageSize: { name: 'pageSize', type: ParamLocationType.
|
|
18
|
-
sort: { name: 'sort', type: ParamLocationType.
|
|
19
|
-
filter: { name: 'filter', type: ParamLocationType.
|
|
12
|
+
query: { name: 'q', type: ParamLocationType.query },
|
|
13
|
+
oq: { name: 'oq', type: ParamLocationType.query },
|
|
14
|
+
rq: { name: 'rq', type: ParamLocationType.query },
|
|
15
|
+
tag: { name: 'tag', type: ParamLocationType.query },
|
|
16
|
+
page: { name: 'page', type: ParamLocationType.query },
|
|
17
|
+
pageSize: { name: 'pageSize', type: ParamLocationType.hash },
|
|
18
|
+
sort: { name: 'sort', type: ParamLocationType.hash },
|
|
19
|
+
filter: { name: 'filter', type: ParamLocationType.hash },
|
|
20
20
|
},
|
|
21
21
|
custom: {},
|
|
22
22
|
},
|
|
23
23
|
};
|
|
24
24
|
const CORE_FIELDS = ['query', 'oq', 'rq', 'tag', 'page', 'pageSize', 'sort', 'filter'];
|
|
25
25
|
export class UrlTranslator {
|
|
26
|
-
constructor(config
|
|
26
|
+
constructor(config) {
|
|
27
27
|
this.reverseMapping = {};
|
|
28
|
-
this.config = deepmerge(defaultConfig, config);
|
|
28
|
+
this.config = deepmerge(defaultConfig, config || {});
|
|
29
29
|
Object.keys(this.config.parameters.core).forEach((param) => {
|
|
30
|
+
const coreParam = this.config.parameters.core[param];
|
|
30
31
|
// param prefix
|
|
31
32
|
if (this.config.settings.corePrefix) {
|
|
32
|
-
|
|
33
|
+
coreParam.name = this.config.settings.corePrefix + coreParam.name;
|
|
33
34
|
}
|
|
34
35
|
// global type override
|
|
35
|
-
const paramType = this.config.settings
|
|
36
|
+
const paramType = this.config.settings?.coreType;
|
|
36
37
|
if (paramType && Object.values(ParamLocationType).includes(paramType)) {
|
|
37
|
-
|
|
38
|
+
coreParam.type = (config?.parameters?.core && coreParam.type) || paramType;
|
|
38
39
|
}
|
|
39
40
|
// create reverse mapping for quick lookup later
|
|
40
|
-
this.reverseMapping[
|
|
41
|
+
this.reverseMapping[coreParam.name] = param;
|
|
41
42
|
});
|
|
42
|
-
const implicit = this.config.settings
|
|
43
|
+
const implicit = this.config.settings?.customType;
|
|
43
44
|
if (implicit && !Object.values(ParamLocationType).includes(implicit)) {
|
|
44
45
|
// invalid type specified - falling back to hash as implicit type
|
|
45
|
-
this.config.settings.customType = ParamLocationType.
|
|
46
|
+
this.config.settings.customType = ParamLocationType.hash;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
bindExternalEvents(update) {
|
|
@@ -70,7 +71,7 @@ export class UrlTranslator {
|
|
|
70
71
|
.filter((v) => v)
|
|
71
72
|
.map((kvPair) => {
|
|
72
73
|
const [key, value] = kvPair.split('=').map((v) => decodeURIComponent(v.replace(/\+/g, ' ')));
|
|
73
|
-
return { key: key.split('.'), value, type: ParamLocationType.
|
|
74
|
+
return { key: key.split('.'), value, type: ParamLocationType.query };
|
|
74
75
|
})
|
|
75
76
|
.filter((param) => {
|
|
76
77
|
// remove core fields that do not contain a value
|
|
@@ -95,17 +96,17 @@ export class UrlTranslator {
|
|
|
95
96
|
})
|
|
96
97
|
.forEach((decodedHashEntries) => {
|
|
97
98
|
if (decodedHashEntries.length == 1) {
|
|
98
|
-
params.push({ key: [decodedHashEntries[0]], value:
|
|
99
|
+
params.push({ key: [decodedHashEntries[0]], value: '', type: ParamLocationType.hash });
|
|
99
100
|
}
|
|
100
101
|
else if (decodedHashEntries.length && decodedHashEntries.length <= 3) {
|
|
101
102
|
const [value, ...keys] = decodedHashEntries.reverse();
|
|
102
|
-
params.push({ key: keys.reverse(), value, type: ParamLocationType.
|
|
103
|
+
params.push({ key: keys.reverse(), value, type: ParamLocationType.hash });
|
|
103
104
|
}
|
|
104
105
|
else if (decodedHashEntries.length && decodedHashEntries.length == 4) {
|
|
105
106
|
// range filter
|
|
106
107
|
const [path0, path1, low, high] = decodedHashEntries;
|
|
107
|
-
params.push({ key: [path0, path1, 'low'], value: low, type: ParamLocationType.
|
|
108
|
-
params.push({ key: [path0, path1, 'high'], value: high, type: ParamLocationType.
|
|
108
|
+
params.push({ key: [path0, path1, 'low'], value: low, type: ParamLocationType.hash });
|
|
109
|
+
params.push({ key: [path0, path1, 'high'], value: high, type: ParamLocationType.hash });
|
|
109
110
|
}
|
|
110
111
|
});
|
|
111
112
|
return params;
|
|
@@ -266,8 +267,8 @@ export class UrlTranslator {
|
|
|
266
267
|
const rootUrlParams = this.config.settings.rootParams ? this.parseUrlParams(this.config.urlRoot) : [];
|
|
267
268
|
const stateParams = this.stateToParams(state);
|
|
268
269
|
const params = [...rootUrlParams, ...stateParams];
|
|
269
|
-
const queryParams = params.filter((p) => p.type == ParamLocationType.
|
|
270
|
-
const hashParams = params.filter((p) => p.type == ParamLocationType.
|
|
270
|
+
const queryParams = params.filter((p) => p.type == ParamLocationType.query);
|
|
271
|
+
const hashParams = params.filter((p) => p.type == ParamLocationType.hash);
|
|
271
272
|
const paramString = (queryParams.length
|
|
272
273
|
? '?' +
|
|
273
274
|
queryParams
|
|
@@ -324,7 +325,7 @@ export class UrlTranslator {
|
|
|
324
325
|
else if (typeof value == 'object' &&
|
|
325
326
|
typeof value[RangeValueProperties.LOW] != 'undefined' &&
|
|
326
327
|
typeof value[RangeValueProperties.HIGH] != 'undefined') {
|
|
327
|
-
if (filterConfig.type == ParamLocationType.
|
|
328
|
+
if (filterConfig.type == ParamLocationType.query) {
|
|
328
329
|
return [
|
|
329
330
|
{
|
|
330
331
|
key: [filterConfig.name, key, RangeValueProperties.LOW],
|
|
@@ -338,7 +339,7 @@ export class UrlTranslator {
|
|
|
338
339
|
},
|
|
339
340
|
];
|
|
340
341
|
}
|
|
341
|
-
else if (filterConfig.type == ParamLocationType.
|
|
342
|
+
else if (filterConfig.type == ParamLocationType.hash) {
|
|
342
343
|
return [
|
|
343
344
|
{
|
|
344
345
|
key: [filterConfig.name, key, '' + (value[RangeValueProperties.LOW] ?? '*')],
|
|
@@ -402,10 +403,10 @@ export class UrlTranslator {
|
|
|
402
403
|
}));
|
|
403
404
|
}
|
|
404
405
|
else {
|
|
405
|
-
params = params.concat({ key: [...currentPath, key], value:
|
|
406
|
+
params = params.concat({ key: [...currentPath, key], value: '', type });
|
|
406
407
|
}
|
|
407
408
|
}
|
|
408
|
-
else if (typeof value == 'object' && Object.keys(value).length) {
|
|
409
|
+
else if (typeof value == 'object' && Object.keys(value || {}).length) {
|
|
409
410
|
addRecursive(value, [...currentPath, key]);
|
|
410
411
|
}
|
|
411
412
|
else {
|
|
@@ -11,11 +11,11 @@ declare class WatcherPool {
|
|
|
11
11
|
notify(): void;
|
|
12
12
|
}
|
|
13
13
|
export declare class UrlManager {
|
|
14
|
-
linker?: (urlManager: UrlManager) => Record<string, unknown
|
|
14
|
+
linker?: ((urlManager: UrlManager) => Record<string, unknown>) | undefined;
|
|
15
15
|
private omissions;
|
|
16
16
|
detached?: {
|
|
17
17
|
url: string;
|
|
18
|
-
};
|
|
18
|
+
} | undefined;
|
|
19
19
|
private translator;
|
|
20
20
|
private urlState;
|
|
21
21
|
private globalState;
|
|
@@ -23,9 +23,9 @@ export declare class UrlManager {
|
|
|
23
23
|
private mergedState;
|
|
24
24
|
private prevState?;
|
|
25
25
|
private watcherPool;
|
|
26
|
-
constructor(translator: Translator, linker?: (urlManager: UrlManager) => Record<string, unknown
|
|
26
|
+
constructor(translator: Translator, linker?: ((urlManager: UrlManager) => Record<string, unknown>) | undefined, globalState?: UrlState | ImmutableObject<UrlState>, localState?: UrlState | ImmutableObject<UrlState>, watcherPool?: WatcherPool, omissions?: Array<omission>, detached?: {
|
|
27
27
|
url: string;
|
|
28
|
-
});
|
|
28
|
+
} | undefined);
|
|
29
29
|
private without;
|
|
30
30
|
private getTranslatorUrl;
|
|
31
31
|
refresh(): void;
|
|
@@ -44,7 +44,7 @@ export declare class UrlManager {
|
|
|
44
44
|
}): void;
|
|
45
45
|
detach(reset?: boolean): UrlManager;
|
|
46
46
|
get link(): Record<string, any>;
|
|
47
|
-
subscribe(cb: (prev
|
|
47
|
+
subscribe(cb: (prev?: ImmutableObject<UrlState>, next?: ImmutableObject<UrlState>) => void): () => void;
|
|
48
48
|
}
|
|
49
49
|
export {};
|
|
50
50
|
//# sourceMappingURL=UrlManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UrlManager.d.ts","sourceRoot":"","sources":["../../../src/UrlManager/UrlManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,aAAK,QAAQ,GAAG;IACf,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACpB,CAAC;AAEF,cAAM,WAAW;IAChB,OAAO,CAAC,SAAS,CAAyB;;IAM1C,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI;IAMxB,MAAM;CAGN;AAED,qBAAa,UAAU;IAcd,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"UrlManager.d.ts","sourceRoot":"","sources":["../../../src/UrlManager/UrlManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,aAAK,QAAQ,GAAG;IACf,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACpB,CAAC;AAEF,cAAM,WAAW;IAChB,OAAO,CAAC,SAAS,CAAyB;;IAM1C,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI;IAMxB,MAAM;CAGN;AAED,qBAAa,UAAU;IAcd,MAAM,CAAC,gBAAe,UAAU,KAAK,OAAO,MAAM,EAAE,OAAO,CAAC;IAInE,OAAO,CAAC,SAAS;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EAAE,OAAO,CAAC,CAAC,GAAG,UAAU;IAgBxH,WAAW,CAAC,OAAO,EAAE,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,GAAG,UAAU;IAItE,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI9C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,EAAE,CAAC,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI;IAU7C,MAAM,CAAC,KAAK,UAAQ,GAAG,UAAU;IAMjC,IAAI,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAM9B;IAED,SAAS,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;CAQvG"}
|
package/dist/esm/types.d.ts
CHANGED
package/dist/esm/types.js
CHANGED
|
@@ -5,6 +5,6 @@ export var RangeValueProperties;
|
|
|
5
5
|
})(RangeValueProperties || (RangeValueProperties = {}));
|
|
6
6
|
export var ParamLocationType;
|
|
7
7
|
(function (ParamLocationType) {
|
|
8
|
-
ParamLocationType["
|
|
9
|
-
ParamLocationType["
|
|
8
|
+
ParamLocationType["hash"] = "hash";
|
|
9
|
+
ParamLocationType["query"] = "query";
|
|
10
10
|
})(ParamLocationType || (ParamLocationType = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchspring/snap-url-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.2",
|
|
4
4
|
"description": "Snap URL Manager",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"files": [
|
|
28
28
|
"dist/**/*"
|
|
29
29
|
],
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "4b0a534583ab1ef24fdda8c408ec23296c135ef4"
|
|
31
31
|
}
|