@geospatial-sdk/core 0.0.5-dev.75 → 0.0.5-dev.77
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 +4 -3
- package/lib/utils/hash.test.ts +48 -0
- package/lib/utils/hash.ts +6 -3
- 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":"AAOA,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,GAAE,MAAM,EAAO,GAAG,MAAM,CAoBzE"}
|
package/dist/utils/hash.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
function isGeoJsonGeometry(object) {
|
|
2
2
|
return "type" in object && ("coordinates" in object || "features" in object);
|
|
3
3
|
}
|
|
4
|
+
const bigintReplacer = (key, value) => typeof value === "bigint" ? value.toString() : value;
|
|
4
5
|
export function getHash(input, ignoreKeys = []) {
|
|
5
6
|
if (input instanceof Date) {
|
|
6
7
|
return input.toISOString();
|
|
7
8
|
}
|
|
8
9
|
if (input instanceof Object && isGeoJsonGeometry(input)) {
|
|
9
|
-
return JSON.stringify(input); // do not compute an actual hash as it will take too long
|
|
10
|
+
return JSON.stringify(input, bigintReplacer); // do not compute an actual hash as it will take too long
|
|
10
11
|
}
|
|
11
12
|
else if (input instanceof Object) {
|
|
12
13
|
const obj = {};
|
|
@@ -16,12 +17,12 @@ export function getHash(input, ignoreKeys = []) {
|
|
|
16
17
|
continue;
|
|
17
18
|
obj[key] = getHash(input[key]);
|
|
18
19
|
}
|
|
19
|
-
const hash = JSON.stringify(obj)
|
|
20
|
+
const hash = JSON.stringify(obj, bigintReplacer)
|
|
20
21
|
.split("")
|
|
21
22
|
.reduce((prev, curr) => (prev << 5) - prev + curr.charCodeAt(0), 0);
|
|
22
23
|
return (hash >>> 0).toString();
|
|
23
24
|
}
|
|
24
25
|
else {
|
|
25
|
-
return JSON.stringify(input);
|
|
26
|
+
return JSON.stringify(input, bigintReplacer);
|
|
26
27
|
}
|
|
27
28
|
}
|
package/lib/utils/hash.test.ts
CHANGED
|
@@ -129,4 +129,52 @@ describe("getHash", () => {
|
|
|
129
129
|
});
|
|
130
130
|
expect(hashB).not.toEqual(hashA);
|
|
131
131
|
});
|
|
132
|
+
it("stable with bigint values", () => {
|
|
133
|
+
const hashA = getHash({
|
|
134
|
+
aa: "bb",
|
|
135
|
+
cc: 9007199254740991n,
|
|
136
|
+
});
|
|
137
|
+
const hashB = getHash({
|
|
138
|
+
aa: "bb",
|
|
139
|
+
cc: 9007199254740991n,
|
|
140
|
+
});
|
|
141
|
+
expect(hashB).toEqual(hashA);
|
|
142
|
+
});
|
|
143
|
+
it("supports bigint in geojson", () => {
|
|
144
|
+
const hash = getHash({
|
|
145
|
+
type: "FeatureCollection",
|
|
146
|
+
features: [
|
|
147
|
+
{
|
|
148
|
+
type: "Feature",
|
|
149
|
+
properties: {
|
|
150
|
+
adresse: "Façade Esplanade",
|
|
151
|
+
code_insee: 59350n,
|
|
152
|
+
dtdate: 1785767040000,
|
|
153
|
+
etat: "OUVERT",
|
|
154
|
+
geom: "POINT (703523.791143476 7060856.34054855)",
|
|
155
|
+
latitude: 50.644637,
|
|
156
|
+
longitude: 3.049734,
|
|
157
|
+
nbr_libre: 138n,
|
|
158
|
+
nbr_total: 270n,
|
|
159
|
+
nom: "Petit Paradis",
|
|
160
|
+
txt_aff: "95",
|
|
161
|
+
ville: "LILLE",
|
|
162
|
+
},
|
|
163
|
+
geometry: {
|
|
164
|
+
coordinates: [
|
|
165
|
+
[
|
|
166
|
+
[2.789133, 50.49973],
|
|
167
|
+
[3.272498, 50.49973],
|
|
168
|
+
[3.272498, 50.794577],
|
|
169
|
+
[2.789133, 50.794577],
|
|
170
|
+
[2.789133, 50.49973],
|
|
171
|
+
],
|
|
172
|
+
],
|
|
173
|
+
type: "Polygon",
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
expect(hash).toBeTruthy();
|
|
179
|
+
});
|
|
132
180
|
});
|
package/lib/utils/hash.ts
CHANGED
|
@@ -2,12 +2,15 @@ function isGeoJsonGeometry(object: object) {
|
|
|
2
2
|
return "type" in object && ("coordinates" in object || "features" in object);
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
+
const bigintReplacer = (key: string, value: unknown) =>
|
|
6
|
+
typeof value === "bigint" ? value.toString() : value;
|
|
7
|
+
|
|
5
8
|
export function getHash(input: unknown, ignoreKeys: string[] = []): string {
|
|
6
9
|
if (input instanceof Date) {
|
|
7
10
|
return input.toISOString();
|
|
8
11
|
}
|
|
9
12
|
if (input instanceof Object && isGeoJsonGeometry(input)) {
|
|
10
|
-
return JSON.stringify(input); // do not compute an actual hash as it will take too long
|
|
13
|
+
return JSON.stringify(input, bigintReplacer); // do not compute an actual hash as it will take too long
|
|
11
14
|
} else if (input instanceof Object) {
|
|
12
15
|
const obj: Record<string, string> = {};
|
|
13
16
|
const keys = Object.keys(input).sort();
|
|
@@ -15,11 +18,11 @@ export function getHash(input: unknown, ignoreKeys: string[] = []): string {
|
|
|
15
18
|
if (ignoreKeys.includes(key)) continue;
|
|
16
19
|
obj[key] = getHash(input[key as keyof typeof input]);
|
|
17
20
|
}
|
|
18
|
-
const hash = JSON.stringify(obj)
|
|
21
|
+
const hash = JSON.stringify(obj, bigintReplacer)
|
|
19
22
|
.split("")
|
|
20
23
|
.reduce((prev, curr) => (prev << 5) - prev + curr.charCodeAt(0), 0);
|
|
21
24
|
return (hash >>> 0).toString();
|
|
22
25
|
} else {
|
|
23
|
-
return JSON.stringify(input);
|
|
26
|
+
return JSON.stringify(input, bigintReplacer);
|
|
24
27
|
}
|
|
25
28
|
}
|
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.77+7336550",
|
|
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": "73365508ad14273ecaf735a05bf702cf2fc76d42",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"chroma-js": "^2.4.2",
|
|
28
28
|
"proj4": "^2.9.2"
|