@geospatial-sdk/core 0.0.5-alpha.2 → 0.0.5-alpha.9
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/model/map-context-diff.d.ts +4 -4
- package/dist/model/map-context.d.ts +4 -0
- package/dist/model/map-context.d.ts.map +1 -1
- package/lib/model/map-context.ts +4 -0
- package/lib/utils/map-context.test.ts +10 -1
- package/package.json +2 -2
- package/dist/fixtures/geojson.fixtures.d.ts +0 -4
- package/dist/fixtures/geojson.fixtures.d.ts.map +0 -1
- package/dist/fixtures/geojson.fixtures.js +0 -55121
- package/dist/fixtures/map-context.fixtures.d.ts +0 -16
- package/dist/fixtures/map-context.fixtures.d.ts.map +0 -1
- package/dist/fixtures/map-context.fixtures.js +0 -73
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/index.js +0 -3
- package/dist/lib/model/index.d.ts +0 -3
- package/dist/lib/model/index.d.ts.map +0 -1
- package/dist/lib/model/index.js +0 -2
- package/dist/lib/model/map-context-diff.d.ts +0 -35
- package/dist/lib/model/map-context-diff.d.ts.map +0 -1
- package/dist/lib/model/map-context-diff.js +0 -1
- package/dist/lib/model/map-context.d.ts +0 -78
- package/dist/lib/model/map-context.d.ts.map +0 -1
- package/dist/lib/model/map-context.js +0 -1
- package/dist/lib/utils/freeze.d.ts +0 -2
- package/dist/lib/utils/freeze.d.ts.map +0 -1
- package/dist/lib/utils/freeze.js +0 -15
- package/dist/lib/utils/freeze.test.d.ts +0 -2
- package/dist/lib/utils/freeze.test.d.ts.map +0 -1
- package/dist/lib/utils/freeze.test.js +0 -51
- package/dist/lib/utils/index.d.ts +0 -5
- package/dist/lib/utils/index.d.ts.map +0 -1
- package/dist/lib/utils/index.js +0 -4
- package/dist/lib/utils/map-context-diff.d.ts +0 -22
- package/dist/lib/utils/map-context-diff.d.ts.map +0 -1
- package/dist/lib/utils/map-context-diff.js +0 -79
- package/dist/lib/utils/map-context-diff.test.d.ts +0 -2
- package/dist/lib/utils/map-context-diff.test.d.ts.map +0 -1
- package/dist/lib/utils/map-context-diff.test.js +0 -217
- package/dist/lib/utils/map-context.d.ts +0 -6
- package/dist/lib/utils/map-context.d.ts.map +0 -1
- package/dist/lib/utils/map-context.js +0 -36
- package/dist/lib/utils/map-context.test.d.ts +0 -2
- package/dist/lib/utils/map-context.test.d.ts.map +0 -1
- package/dist/lib/utils/map-context.test.js +0 -131
- package/dist/lib/utils/url.d.ts +0 -7
- package/dist/lib/utils/url.d.ts.map +0 -1
- package/dist/lib/utils/url.js +0 -17
- package/dist/lib/utils/url.test.d.ts +0 -2
- package/dist/lib/utils/url.test.d.ts.map +0 -1
- package/dist/lib/utils/url.test.js +0 -8
- package/dist/utils/freeze.test.d.ts +0 -2
- package/dist/utils/freeze.test.d.ts.map +0 -1
- package/dist/utils/freeze.test.js +0 -51
- package/dist/utils/map-context-diff.test.d.ts +0 -2
- package/dist/utils/map-context-diff.test.d.ts.map +0 -1
- package/dist/utils/map-context-diff.test.js +0 -251
- package/dist/utils/map-context.test.d.ts +0 -2
- package/dist/utils/map-context.test.d.ts.map +0 -1
- package/dist/utils/map-context.test.js +0 -150
- package/dist/utils/url.test.d.ts +0 -2
- package/dist/utils/url.test.d.ts.map +0 -1
- package/dist/utils/url.test.js +0 -8
|
@@ -1,217 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map-context.test.d.ts","sourceRoot":"","sources":["../../../lib/utils/map-context.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,131 +0,0 @@
|
|
|
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
|
-
});
|
package/dist/lib/utils/url.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/lib/utils/url.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"url.test.d.ts","sourceRoot":"","sources":["../../../lib/utils/url.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"freeze.test.d.ts","sourceRoot":"","sources":["../../lib/utils/freeze.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { deepFreeze } from "./freeze";
|
|
2
|
-
describe("freeze util", () => {
|
|
3
|
-
describe("deepFreeze", () => {
|
|
4
|
-
let obj;
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
obj = deepFreeze({
|
|
7
|
-
ab: "cde",
|
|
8
|
-
fg: {
|
|
9
|
-
h: true,
|
|
10
|
-
ij: 12,
|
|
11
|
-
},
|
|
12
|
-
k: [
|
|
13
|
-
{
|
|
14
|
-
l: 456,
|
|
15
|
-
mn: ["opqr"],
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
it("prevents mutation of root properties", () => {
|
|
21
|
-
expect(() => {
|
|
22
|
-
obj.ab = "AA";
|
|
23
|
-
}).toThrow();
|
|
24
|
-
});
|
|
25
|
-
it("prevents mutation of nested properties", () => {
|
|
26
|
-
expect(() => {
|
|
27
|
-
obj.fg.h = "AA";
|
|
28
|
-
}).toThrow();
|
|
29
|
-
});
|
|
30
|
-
it("prevents mutation of objects inside nested arrays", () => {
|
|
31
|
-
expect(() => {
|
|
32
|
-
obj.k[0].l = "AA";
|
|
33
|
-
}).toThrow();
|
|
34
|
-
});
|
|
35
|
-
describe("starting with array", () => {
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
obj = deepFreeze([
|
|
38
|
-
{
|
|
39
|
-
l: 456,
|
|
40
|
-
mn: ["opqr"],
|
|
41
|
-
},
|
|
42
|
-
]);
|
|
43
|
-
});
|
|
44
|
-
it("prevents mutation of nested objects", () => {
|
|
45
|
-
expect(() => {
|
|
46
|
-
obj[0].l = "AA";
|
|
47
|
-
}).toThrow();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map-context-diff.test.d.ts","sourceRoot":"","sources":["../../lib/utils/map-context-diff.test.ts"],"names":[],"mappings":""}
|