@geospatial-sdk/core 0.0.5-dev.20 → 0.0.5-dev.21
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/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +7 -1
- package/lib/utils/hash.test.ts +66 -0
- package/lib/utils/hash.ts +7 -1
- package/package.json +2 -2
package/dist/utils/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../lib/utils/hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../lib/utils/hash.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,GAAE,MAAM,EAAO,GAAG,MAAM,CAiBzE"}
|
package/dist/utils/hash.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
function isGeoJsonGeometry(object) {
|
|
2
|
+
return "type" in object && "coordinates" in object;
|
|
3
|
+
}
|
|
1
4
|
export function getHash(input, ignoreKeys = []) {
|
|
2
|
-
if (input instanceof Object) {
|
|
5
|
+
if (input instanceof Object && isGeoJsonGeometry(input)) {
|
|
6
|
+
return JSON.stringify(input); // do not compute an actual hash as it will take too long
|
|
7
|
+
}
|
|
8
|
+
else if (input instanceof Object) {
|
|
3
9
|
const obj = {};
|
|
4
10
|
const keys = Object.keys(input).sort();
|
|
5
11
|
for (const key of keys) {
|
package/lib/utils/hash.test.ts
CHANGED
|
@@ -33,4 +33,70 @@ describe("getHash", () => {
|
|
|
33
33
|
const hashB = getHash("null");
|
|
34
34
|
expect(hashB).not.toEqual(hashA);
|
|
35
35
|
});
|
|
36
|
+
it("stable with identical GeoJSON geometry", () => {
|
|
37
|
+
const hashA = getHash({
|
|
38
|
+
geometry: {
|
|
39
|
+
type: "Polygon",
|
|
40
|
+
properties: {},
|
|
41
|
+
coordinates: [
|
|
42
|
+
[
|
|
43
|
+
[-10, -10],
|
|
44
|
+
[-10, 20],
|
|
45
|
+
[10, 20],
|
|
46
|
+
[10, -10],
|
|
47
|
+
[-10, -10],
|
|
48
|
+
],
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const hashB = getHash({
|
|
53
|
+
geometry: {
|
|
54
|
+
type: "Polygon",
|
|
55
|
+
properties: {},
|
|
56
|
+
coordinates: [
|
|
57
|
+
[
|
|
58
|
+
[-10, -10],
|
|
59
|
+
[-10, 20],
|
|
60
|
+
[10, 20],
|
|
61
|
+
[10, -10],
|
|
62
|
+
[-10, -10],
|
|
63
|
+
],
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
expect(hashB).toEqual(hashA);
|
|
68
|
+
});
|
|
69
|
+
it("different if GeoJSON geometry properties are not in the same order", () => {
|
|
70
|
+
const hashA = getHash({
|
|
71
|
+
geometry: {
|
|
72
|
+
coordinates: [
|
|
73
|
+
[
|
|
74
|
+
[-10, -10],
|
|
75
|
+
[-10, 20],
|
|
76
|
+
[10, 20],
|
|
77
|
+
[10, -10],
|
|
78
|
+
[-10, -10],
|
|
79
|
+
],
|
|
80
|
+
],
|
|
81
|
+
type: "Polygon",
|
|
82
|
+
properties: {},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
const hashB = getHash({
|
|
86
|
+
geometry: {
|
|
87
|
+
type: "Polygon",
|
|
88
|
+
properties: {},
|
|
89
|
+
coordinates: [
|
|
90
|
+
[
|
|
91
|
+
[-10, -10],
|
|
92
|
+
[-10, 20],
|
|
93
|
+
[10, 20],
|
|
94
|
+
[10, -10],
|
|
95
|
+
[-10, -10],
|
|
96
|
+
],
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
expect(hashB).not.toEqual(hashA);
|
|
101
|
+
});
|
|
36
102
|
});
|
package/lib/utils/hash.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
function isGeoJsonGeometry(object: object) {
|
|
2
|
+
return "type" in object && "coordinates" in object;
|
|
3
|
+
}
|
|
4
|
+
|
|
1
5
|
export function getHash(input: unknown, ignoreKeys: string[] = []): string {
|
|
2
|
-
if (input instanceof Object) {
|
|
6
|
+
if (input instanceof Object && isGeoJsonGeometry(input)) {
|
|
7
|
+
return JSON.stringify(input); // do not compute an actual hash as it will take too long
|
|
8
|
+
} else if (input instanceof Object) {
|
|
3
9
|
const obj: Record<string, string> = {};
|
|
4
10
|
const keys = Object.keys(input).sort();
|
|
5
11
|
for (const key of keys) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geospatial-sdk/core",
|
|
3
|
-
"version": "0.0.5-dev.
|
|
3
|
+
"version": "0.0.5-dev.21+89507d8",
|
|
4
4
|
"description": "Core functions and models for the SDK",
|
|
5
5
|
"author": "Olivia <olivia.guyot@camptocamp.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "vitest",
|
|
23
23
|
"build": "tsc"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "89507d8f401028ad8340d960ace5de574fa6e966",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@camptocamp/ogc-client": "1.1.1-dev.c75dcba",
|
|
28
28
|
"proj4": "^2.9.2"
|