@geospatial-sdk/core 0.0.5-alpha.1 → 0.0.5-alpha.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.
Files changed (65) hide show
  1. package/dist/fixtures/geojson.fixtures.d.ts +4 -0
  2. package/dist/fixtures/geojson.fixtures.d.ts.map +1 -0
  3. package/dist/fixtures/geojson.fixtures.js +55121 -0
  4. package/dist/fixtures/map-context.fixtures.d.ts +16 -0
  5. package/dist/fixtures/map-context.fixtures.d.ts.map +1 -0
  6. package/dist/fixtures/map-context.fixtures.js +73 -0
  7. package/dist/lib/index.d.ts +3 -0
  8. package/dist/lib/index.d.ts.map +1 -0
  9. package/dist/lib/index.js +3 -0
  10. package/dist/lib/model/index.d.ts +3 -0
  11. package/dist/lib/model/index.d.ts.map +1 -0
  12. package/dist/lib/model/index.js +2 -0
  13. package/dist/lib/model/map-context-diff.d.ts +35 -0
  14. package/dist/lib/model/map-context-diff.d.ts.map +1 -0
  15. package/dist/lib/model/map-context-diff.js +1 -0
  16. package/dist/lib/model/map-context.d.ts +78 -0
  17. package/dist/lib/model/map-context.d.ts.map +1 -0
  18. package/dist/lib/model/map-context.js +1 -0
  19. package/dist/lib/utils/freeze.d.ts +2 -0
  20. package/dist/lib/utils/freeze.d.ts.map +1 -0
  21. package/dist/lib/utils/freeze.js +15 -0
  22. package/dist/lib/utils/freeze.test.d.ts +2 -0
  23. package/dist/lib/utils/freeze.test.d.ts.map +1 -0
  24. package/dist/lib/utils/freeze.test.js +51 -0
  25. package/dist/lib/utils/index.d.ts +5 -0
  26. package/dist/lib/utils/index.d.ts.map +1 -0
  27. package/dist/lib/utils/index.js +4 -0
  28. package/dist/lib/utils/map-context-diff.d.ts +22 -0
  29. package/dist/lib/utils/map-context-diff.d.ts.map +1 -0
  30. package/dist/lib/utils/map-context-diff.js +79 -0
  31. package/dist/lib/utils/map-context-diff.test.d.ts +2 -0
  32. package/dist/lib/utils/map-context-diff.test.d.ts.map +1 -0
  33. package/dist/lib/utils/map-context-diff.test.js +217 -0
  34. package/dist/lib/utils/map-context.d.ts +6 -0
  35. package/dist/lib/utils/map-context.d.ts.map +1 -0
  36. package/dist/lib/utils/map-context.js +36 -0
  37. package/dist/lib/utils/map-context.test.d.ts +2 -0
  38. package/dist/lib/utils/map-context.test.d.ts.map +1 -0
  39. package/dist/lib/utils/map-context.test.js +131 -0
  40. package/dist/lib/utils/url.d.ts +7 -0
  41. package/dist/lib/utils/url.d.ts.map +1 -0
  42. package/dist/lib/utils/url.js +17 -0
  43. package/dist/lib/utils/url.test.d.ts +2 -0
  44. package/dist/lib/utils/url.test.d.ts.map +1 -0
  45. package/dist/lib/utils/url.test.js +8 -0
  46. package/dist/utils/index.d.ts +1 -0
  47. package/dist/utils/index.d.ts.map +1 -1
  48. package/dist/utils/index.js +1 -0
  49. package/dist/utils/map-context-diff.d.ts +1 -4
  50. package/dist/utils/map-context-diff.d.ts.map +1 -1
  51. package/dist/utils/map-context-diff.js +1 -33
  52. package/dist/utils/map-context-diff.test.js +1 -120
  53. package/dist/utils/map-context.d.ts +6 -0
  54. package/dist/utils/map-context.d.ts.map +1 -0
  55. package/dist/utils/map-context.js +36 -0
  56. package/dist/utils/map-context.test.d.ts +2 -0
  57. package/dist/utils/map-context.test.d.ts.map +1 -0
  58. package/dist/utils/map-context.test.js +150 -0
  59. package/lib/model/map-context-diff.ts +4 -4
  60. package/lib/utils/index.ts +1 -0
  61. package/lib/utils/map-context-diff.test.ts +8 -310
  62. package/lib/utils/map-context-diff.ts +1 -43
  63. package/lib/utils/map-context.test.ts +294 -0
  64. package/lib/utils/map-context.ts +51 -0
  65. package/package.json +2 -2
@@ -0,0 +1,217 @@
1
+ import { computeMapContextDiff } from "./map-context-diff";
2
+ import { SAMPLE_CONTEXT, SAMPLE_LAYER1, SAMPLE_LAYER2, SAMPLE_LAYER3, SAMPLE_LAYER4, SAMPLE_LAYER5, } from "../../fixtures/map-context.fixtures";
3
+ describe("Context diff utils", () => {
4
+ describe("computeMapContextDiff", () => {
5
+ let contextOld;
6
+ let contextNew;
7
+ let diff;
8
+ describe("no change", () => {
9
+ beforeEach(() => {
10
+ contextOld = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER2, SAMPLE_LAYER1] });
11
+ contextNew = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER2, SAMPLE_LAYER1] });
12
+ });
13
+ it("outputs the correct diff", () => {
14
+ diff = computeMapContextDiff(contextNew, contextOld);
15
+ expect(diff).toEqual({
16
+ layersAdded: [],
17
+ layersChanged: [],
18
+ layersRemoved: [],
19
+ layersReordered: [],
20
+ viewChanges: {},
21
+ });
22
+ });
23
+ });
24
+ describe("layers added", () => {
25
+ beforeEach(() => {
26
+ contextOld = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER1] });
27
+ contextNew = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER2, SAMPLE_LAYER1, SAMPLE_LAYER4] });
28
+ });
29
+ it("outputs the correct diff", () => {
30
+ diff = computeMapContextDiff(contextNew, contextOld);
31
+ expect(diff).toEqual({
32
+ layersAdded: [
33
+ {
34
+ layer: SAMPLE_LAYER2,
35
+ position: 0,
36
+ },
37
+ {
38
+ layer: SAMPLE_LAYER4,
39
+ position: 2,
40
+ },
41
+ ],
42
+ layersChanged: [],
43
+ layersRemoved: [],
44
+ layersReordered: [],
45
+ viewChanges: {},
46
+ });
47
+ });
48
+ });
49
+ describe("layers removed", () => {
50
+ beforeEach(() => {
51
+ contextOld = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER2, SAMPLE_LAYER1, SAMPLE_LAYER4] });
52
+ contextNew = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER4] });
53
+ });
54
+ it("outputs the correct diff", () => {
55
+ diff = computeMapContextDiff(contextNew, contextOld);
56
+ expect(diff).toEqual({
57
+ layersAdded: [],
58
+ layersChanged: [],
59
+ layersRemoved: [
60
+ {
61
+ layer: SAMPLE_LAYER2,
62
+ position: 0,
63
+ },
64
+ {
65
+ layer: SAMPLE_LAYER1,
66
+ position: 1,
67
+ },
68
+ ],
69
+ layersReordered: [],
70
+ viewChanges: {},
71
+ });
72
+ });
73
+ });
74
+ describe("layers changed", () => {
75
+ beforeEach(() => {
76
+ contextOld = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER2, Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 123, version: 3 })] });
77
+ contextNew = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [
78
+ Object.assign(Object.assign({}, SAMPLE_LAYER2), { extras: { prop: true } }),
79
+ Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 123, version: 10 }),
80
+ ] });
81
+ });
82
+ it("outputs the correct diff", () => {
83
+ diff = computeMapContextDiff(contextNew, contextOld);
84
+ expect(diff).toEqual({
85
+ layersAdded: [],
86
+ layersChanged: [
87
+ {
88
+ layer: contextNew.layers[0],
89
+ position: 0,
90
+ },
91
+ {
92
+ layer: contextNew.layers[1],
93
+ position: 1,
94
+ },
95
+ ],
96
+ layersRemoved: [],
97
+ layersReordered: [],
98
+ viewChanges: {},
99
+ });
100
+ });
101
+ });
102
+ describe("reordering", () => {
103
+ describe("three layers reordered", () => {
104
+ beforeEach(() => {
105
+ contextOld = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER1, SAMPLE_LAYER2, SAMPLE_LAYER3] });
106
+ contextNew = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER2, SAMPLE_LAYER1, SAMPLE_LAYER3] });
107
+ });
108
+ it("outputs the correct diff", () => {
109
+ diff = computeMapContextDiff(contextNew, contextOld);
110
+ expect(diff).toEqual({
111
+ layersAdded: [],
112
+ layersChanged: [],
113
+ layersRemoved: [],
114
+ layersReordered: [
115
+ {
116
+ layer: SAMPLE_LAYER2,
117
+ newPosition: 0,
118
+ previousPosition: 1,
119
+ },
120
+ {
121
+ layer: SAMPLE_LAYER1,
122
+ newPosition: 1,
123
+ previousPosition: 0,
124
+ },
125
+ ],
126
+ viewChanges: {},
127
+ });
128
+ });
129
+ });
130
+ describe("four layers reordered", () => {
131
+ beforeEach(() => {
132
+ contextOld = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [
133
+ SAMPLE_LAYER1,
134
+ SAMPLE_LAYER3,
135
+ SAMPLE_LAYER4,
136
+ SAMPLE_LAYER2,
137
+ ] });
138
+ contextNew = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [
139
+ SAMPLE_LAYER4,
140
+ SAMPLE_LAYER3,
141
+ SAMPLE_LAYER1,
142
+ SAMPLE_LAYER2,
143
+ ] });
144
+ });
145
+ it("outputs the correct diff", () => {
146
+ diff = computeMapContextDiff(contextNew, contextOld);
147
+ expect(diff).toEqual({
148
+ layersAdded: [],
149
+ layersChanged: [],
150
+ layersRemoved: [],
151
+ layersReordered: [
152
+ {
153
+ layer: SAMPLE_LAYER4,
154
+ newPosition: 0,
155
+ previousPosition: 2,
156
+ },
157
+ {
158
+ layer: SAMPLE_LAYER1,
159
+ newPosition: 2,
160
+ previousPosition: 0,
161
+ },
162
+ ],
163
+ viewChanges: {},
164
+ });
165
+ });
166
+ });
167
+ });
168
+ describe("combined changes", () => {
169
+ let changedLayer;
170
+ beforeEach(() => {
171
+ changedLayer = Object.assign(Object.assign({}, SAMPLE_LAYER3), { extras: { prop: true } });
172
+ contextOld = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER1, SAMPLE_LAYER5, SAMPLE_LAYER3, SAMPLE_LAYER4] });
173
+ contextNew = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER2, changedLayer, SAMPLE_LAYER5] });
174
+ });
175
+ it("outputs the correct diff", () => {
176
+ diff = computeMapContextDiff(contextNew, contextOld);
177
+ expect(diff).toEqual({
178
+ layersAdded: [
179
+ {
180
+ layer: SAMPLE_LAYER2,
181
+ position: 0,
182
+ },
183
+ ],
184
+ layersChanged: [
185
+ {
186
+ layer: changedLayer,
187
+ position: 1,
188
+ },
189
+ ],
190
+ layersRemoved: [
191
+ {
192
+ layer: SAMPLE_LAYER1,
193
+ position: 0,
194
+ },
195
+ {
196
+ layer: SAMPLE_LAYER4,
197
+ position: 3,
198
+ },
199
+ ],
200
+ layersReordered: [
201
+ {
202
+ layer: changedLayer,
203
+ newPosition: 1,
204
+ previousPosition: 2,
205
+ },
206
+ {
207
+ layer: SAMPLE_LAYER5,
208
+ newPosition: 2,
209
+ previousPosition: 1,
210
+ },
211
+ ],
212
+ viewChanges: {},
213
+ });
214
+ });
215
+ });
216
+ });
217
+ });
@@ -0,0 +1,6 @@
1
+ import { MapContext, MapContextLayer } from "../model";
2
+ export declare function getLayerHash(layer: MapContextLayer, includeExtras?: boolean): string;
3
+ export declare function isLayerSame(layerA: MapContextLayer, layerB: MapContextLayer): boolean;
4
+ export declare function isLayerSameAndUnchanged(layerA: MapContextLayer, layerB: MapContextLayer): boolean;
5
+ export declare function getLayerPosition(context: MapContext, layerModel: MapContextLayer): number;
6
+ //# sourceMappingURL=map-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-context.d.ts","sourceRoot":"","sources":["../../../lib/utils/map-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEvD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,eAAe,EACtB,aAAa,UAAQ,GACpB,MAAM,CAkBR;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAKT;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAKT;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,eAAe,GAC1B,MAAM,CAER"}
@@ -0,0 +1,36 @@
1
+ export function getLayerHash(layer, includeExtras = false) {
2
+ function getHash(input) {
3
+ if (input instanceof Object) {
4
+ const obj = {};
5
+ const keys = Object.keys(input).sort();
6
+ for (const key of keys) {
7
+ if (!includeExtras && key === "extras")
8
+ continue;
9
+ obj[key] = getHash(input[key]);
10
+ }
11
+ const hash = JSON.stringify(obj)
12
+ .split("")
13
+ .reduce((prev, curr) => (prev << 5) - prev + curr.charCodeAt(0), 0);
14
+ return (hash >>> 0).toString();
15
+ }
16
+ else {
17
+ return JSON.stringify(input);
18
+ }
19
+ }
20
+ return getHash(layer);
21
+ }
22
+ export function isLayerSame(layerA, layerB) {
23
+ if ("id" in layerA && "id" in layerB) {
24
+ return layerA.id == layerB.id;
25
+ }
26
+ return getLayerHash(layerA) === getLayerHash(layerB);
27
+ }
28
+ export function isLayerSameAndUnchanged(layerA, layerB) {
29
+ if ("id" in layerA && "id" in layerB) {
30
+ return layerA.id == layerB.id && layerA.version == layerB.version;
31
+ }
32
+ return getLayerHash(layerA, true) === getLayerHash(layerB, true);
33
+ }
34
+ export function getLayerPosition(context, layerModel) {
35
+ return context.layers.findIndex((l) => isLayerSame(layerModel, l));
36
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=map-context.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-context.test.d.ts","sourceRoot":"","sources":["../../../lib/utils/map-context.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,131 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { describe } from "vitest";
13
+ import { getLayerHash, getLayerPosition, isLayerSame, isLayerSameAndUnchanged, } from "./map-context";
14
+ import { SAMPLE_CONTEXT, SAMPLE_LAYER1, SAMPLE_LAYER2, } from "../../fixtures/map-context.fixtures";
15
+ describe("Map context utils", () => {
16
+ describe("isLayerSame", () => {
17
+ describe("layers with id", () => {
18
+ it("compares non-strictly by id", () => {
19
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "b" }))).toBe(false);
20
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab" }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "ab" }))).toBe(true);
21
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "01" }))).toBe(true);
22
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: 1 }))).toBe(true);
23
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 2 }))).toBe(false);
24
+ });
25
+ });
26
+ describe("layers without id", () => {
27
+ it("compares by properties", () => {
28
+ expect(isLayerSame(SAMPLE_LAYER1, SAMPLE_LAYER1)).toBe(true);
29
+ expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { name: "abc" }))).toBe(false);
30
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org", name: SAMPLE_LAYER1.name }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org" }))).toBe(true);
31
+ expect(isLayerSame(SAMPLE_LAYER1, SAMPLE_LAYER2)).toBe(false);
32
+ });
33
+ it("ignores extras prop", () => {
34
+ expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { otherProp: "abc" } }))).toBe(true);
35
+ expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: undefined }))).toBe(true);
36
+ const { extras } = SAMPLE_LAYER1, layer = __rest(SAMPLE_LAYER1, ["extras"]);
37
+ expect(isLayerSame(SAMPLE_LAYER1, layer)).toBe(true);
38
+ });
39
+ });
40
+ describe("layers with and without id", () => {
41
+ it("compares by properties", () => {
42
+ expect(isLayerSame(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }))).toBe(false);
43
+ expect(isLayerSame(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }), Object.assign(Object.assign({ id: "123" }, SAMPLE_LAYER1), { name: SAMPLE_LAYER1.name }))).toBe(true);
44
+ });
45
+ });
46
+ });
47
+ describe("isLayerSameAndUnchanged", () => {
48
+ describe("layers with id", () => {
49
+ it("compares non-strictly by id and version field", () => {
50
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "b" }))).toBe(false);
51
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "a" }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "a" }))).toBe(true);
52
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 2 }), Object.assign(Object.assign({}, SAMPLE_LAYER2), { id: "ab", version: 2 }))).toBe(true);
53
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 2 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "ab", version: 1 }))).toBe(false);
54
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: 1 }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "01", version: 3 }))).toBe(false);
55
+ });
56
+ });
57
+ describe("layers without id", () => {
58
+ it("compares by properties, including extras", () => {
59
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, SAMPLE_LAYER1)).toBe(true);
60
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { name: "abc" }))).toBe(false);
61
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org", name: SAMPLE_LAYER1.name }), Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://abc.org" }))).toBe(true);
62
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, SAMPLE_LAYER2)).toBe(false);
63
+ });
64
+ it("takes into account extras prop", () => {
65
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { otherProp: "abc" } }))).toBe(false);
66
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: undefined }))).toBe(false);
67
+ const { extras } = SAMPLE_LAYER1, layer = __rest(SAMPLE_LAYER1, ["extras"]);
68
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, layer)).toBe(false);
69
+ });
70
+ });
71
+ describe("layers with and without id", () => {
72
+ it("compares by properties", () => {
73
+ expect(isLayerSameAndUnchanged(SAMPLE_LAYER1, Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }))).toBe(false);
74
+ expect(isLayerSameAndUnchanged(Object.assign(Object.assign({}, SAMPLE_LAYER1), { id: "123" }), Object.assign(Object.assign({ id: "123" }, SAMPLE_LAYER1), { name: SAMPLE_LAYER1.name }))).toBe(true);
75
+ });
76
+ });
77
+ });
78
+ describe("getLayerHash", () => {
79
+ it("works with serializable entities", () => {
80
+ expect(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
81
+ array: [11, 22, null, undefined],
82
+ object: {},
83
+ undef: undefined,
84
+ } }))).toBeTypeOf("string");
85
+ });
86
+ it("ignores extra property by default", () => {
87
+ expect(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
88
+ array: [11, 22, null, undefined],
89
+ object: {},
90
+ } }))).toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: { hello: "world" } })));
91
+ });
92
+ it("works with non-serializable entities (but they are ignored)", () => {
93
+ const hash = getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
94
+ func: () => 123,
95
+ canvas: document.createElement("canvas"),
96
+ } }), true);
97
+ expect(hash).toBeTypeOf("string");
98
+ expect(hash).toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {
99
+ func: () => 456,
100
+ canvas: document.createElement("div"),
101
+ } }), true));
102
+ expect(hash).not.toEqual(getLayerHash(Object.assign(Object.assign({}, SAMPLE_LAYER1), { extras: {} }), true));
103
+ });
104
+ it("does not take into account properties order", () => {
105
+ expect(getLayerHash({
106
+ type: "wms",
107
+ url: "http://abc.org/wms",
108
+ name: "myLayer",
109
+ extras: {
110
+ array: [1, 2, 3],
111
+ object: {},
112
+ },
113
+ }, true)).toEqual(getLayerHash({
114
+ extras: {
115
+ array: [1, 2, 3],
116
+ object: {},
117
+ },
118
+ url: "http://abc.org/wms",
119
+ type: "wms",
120
+ name: "myLayer",
121
+ }, true));
122
+ });
123
+ });
124
+ describe("getLayerPosition", () => {
125
+ it("returns the index of the layer in the context", () => {
126
+ const context = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER1, SAMPLE_LAYER2] });
127
+ expect(getLayerPosition(context, SAMPLE_LAYER1)).toBe(0);
128
+ expect(getLayerPosition(context, SAMPLE_LAYER2)).toBe(1);
129
+ });
130
+ });
131
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Removes the given search params from the URL completely; this is case-insensitive
3
+ * @param url
4
+ * @param searchParams
5
+ */
6
+ export declare function removeSearchParams(url: string, searchParams: string[]): string;
7
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../lib/utils/url.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EAAE,GACrB,MAAM,CAWR"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Removes the given search params from the URL completely; this is case-insensitive
3
+ * @param url
4
+ * @param searchParams
5
+ */
6
+ export function removeSearchParams(url, searchParams) {
7
+ const toDelete = [];
8
+ const urlObj = new URL(url, window.location.toString());
9
+ const keysLower = searchParams.map((p) => p.toLowerCase());
10
+ for (const param of urlObj.searchParams.keys()) {
11
+ if (keysLower.indexOf(param.toLowerCase()) > -1) {
12
+ toDelete.push(param);
13
+ }
14
+ }
15
+ toDelete.map((param) => urlObj.searchParams.delete(param));
16
+ return urlObj.toString();
17
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=url.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.test.d.ts","sourceRoot":"","sources":["../../../lib/utils/url.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { removeSearchParams } from "./url";
2
+ describe("URL utils", () => {
3
+ describe("removeSearchParams", () => {
4
+ it("removes given search params in a case insensitive way", () => {
5
+ expect(removeSearchParams("http://my.org/abc/?arg0=1234&arg1=aaa&Arg1=111&ARG2=&aRG3=fff&arg4=5678", ["ARG1", "arg2", "arg3"])).toEqual("http://my.org/abc/?arg0=1234&arg4=5678");
6
+ });
7
+ });
8
+ });
@@ -1,4 +1,5 @@
1
1
  export * from "./url";
2
2
  export * from "./freeze";
3
3
  export { computeMapContextDiff } from "./map-context-diff";
4
+ export { getLayerPosition } from "./map-context";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from "./url";
2
2
  export * from "./freeze";
3
3
  export { computeMapContextDiff } from "./map-context-diff";
4
+ export { getLayerPosition } from "./map-context";
@@ -1,7 +1,4 @@
1
- import { MapContext, MapContextDiff, MapContextLayer } from "../model";
2
- export declare function getLayerHash(layer: MapContextLayer, includeExtras?: boolean): string;
3
- export declare function isLayerSame(layerA: MapContextLayer, layerB: MapContextLayer): boolean;
4
- export declare function isLayerSameAndUnchanged(layerA: MapContextLayer, layerB: MapContextLayer): boolean;
1
+ import { MapContext, MapContextDiff } from "../model";
5
2
  /**
6
3
  * The following logic is produced by identifying layers in both context
7
4
  * and determining whether they have been added, removed, changed or reordered.
@@ -1 +1 @@
1
- {"version":3,"file":"map-context-diff.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,eAAe,EAIhB,MAAM,UAAU,CAAC;AAElB,wBAAgB,YAAY,CAC1B,KAAK,EAAE,eAAe,EACtB,aAAa,UAAQ,GACpB,MAAM,CAkBR;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAKT;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAKT;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EACvB,eAAe,EAAE,UAAU,GAC1B,cAAc,CAqEhB"}
1
+ {"version":3,"file":"map-context-diff.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EAKf,MAAM,UAAU,CAAC;AAGlB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EACvB,eAAe,EAAE,UAAU,GAC1B,cAAc,CAqEhB"}
@@ -1,36 +1,4 @@
1
- export function getLayerHash(layer, includeExtras = false) {
2
- function getHash(input) {
3
- if (input instanceof Object) {
4
- const obj = {};
5
- const keys = Object.keys(input).sort();
6
- for (const key of keys) {
7
- if (!includeExtras && key === "extras")
8
- continue;
9
- obj[key] = getHash(input[key]);
10
- }
11
- const hash = JSON.stringify(obj)
12
- .split("")
13
- .reduce((prev, curr) => (prev << 5) - prev + curr.charCodeAt(0), 0);
14
- return (hash >>> 0).toString();
15
- }
16
- else {
17
- return JSON.stringify(input);
18
- }
19
- }
20
- return getHash(layer);
21
- }
22
- export function isLayerSame(layerA, layerB) {
23
- if ("id" in layerA && "id" in layerB) {
24
- return layerA.id == layerB.id;
25
- }
26
- return getLayerHash(layerA) === getLayerHash(layerB);
27
- }
28
- export function isLayerSameAndUnchanged(layerA, layerB) {
29
- if ("id" in layerA && "id" in layerB) {
30
- return layerA.id == layerB.id && layerA.version == layerB.version;
31
- }
32
- return getLayerHash(layerA, true) === getLayerHash(layerB, true);
33
- }
1
+ import { isLayerSame, isLayerSameAndUnchanged } from "./map-context";
34
2
  /**
35
3
  * The following logic is produced by identifying layers in both context
36
4
  * and determining whether they have been added, removed, changed or reordered.