@basemaps/shared 6.7.0 → 6.11.0

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 (70) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/build/__test__/api.path.test.js +57 -60
  3. package/build/__test__/api.test.js +29 -32
  4. package/build/__test__/env.test.js +9 -12
  5. package/build/__test__/util.test.js +36 -39
  6. package/build/__test__/vdom.parse.test.js +18 -21
  7. package/build/__test__/vdom.test.js +29 -32
  8. package/build/api.js +6 -10
  9. package/build/api.path.d.ts.map +1 -1
  10. package/build/api.path.js +15 -23
  11. package/build/aws/aws.dynamo.table.d.ts.map +1 -1
  12. package/build/aws/aws.dynamo.table.js +1 -2
  13. package/build/cli/__test__/git.tag.test.js +7 -10
  14. package/build/cli/api.key.js +4 -9
  15. package/build/cli/git.tag.js +4 -8
  16. package/build/composite.error.d.ts +1 -7
  17. package/build/composite.error.d.ts.map +1 -1
  18. package/build/composite.error.js +1 -13
  19. package/build/const.d.ts.map +1 -1
  20. package/build/const.js +3 -6
  21. package/build/file/__test__/file.local.test.js +19 -19
  22. package/build/file/__test__/file.operator.test.helper.d.ts.map +1 -1
  23. package/build/file/__test__/file.operator.test.helper.js +17 -21
  24. package/build/file/file.config.d.ts.map +1 -1
  25. package/build/file/file.config.js +2 -7
  26. package/build/file/index.d.ts +3 -3
  27. package/build/file/index.d.ts.map +1 -1
  28. package/build/file/index.js +14 -23
  29. package/build/index.d.ts +13 -14
  30. package/build/index.d.ts.map +1 -1
  31. package/build/index.js +18 -35
  32. package/build/log.d.ts +0 -3
  33. package/build/log.d.ts.map +1 -1
  34. package/build/log.js +6 -16
  35. package/build/logger.fatal.error.d.ts.map +1 -1
  36. package/build/logger.fatal.error.js +1 -5
  37. package/build/proj/__test__/projection.test.js +30 -33
  38. package/build/proj/__test__/projection.tile.matrix.set.test.js +130 -78
  39. package/build/proj/__test__/test.util.d.ts.map +1 -1
  40. package/build/proj/__test__/test.util.js +10 -17
  41. package/build/proj/citm2000.js +1 -4
  42. package/build/proj/nztm2000.js +1 -4
  43. package/build/proj/projection.d.ts +44 -33
  44. package/build/proj/projection.d.ts.map +1 -1
  45. package/build/proj/projection.js +84 -53
  46. package/build/proj/tile.set.name.d.ts.map +1 -1
  47. package/build/proj/tile.set.name.js +3 -7
  48. package/build/util.d.ts.map +1 -1
  49. package/build/util.js +5 -13
  50. package/build/vdom.d.ts.map +1 -1
  51. package/build/vdom.js +4 -11
  52. package/build/vdom.parse.d.ts +1 -1
  53. package/build/vdom.parse.d.ts.map +1 -1
  54. package/build/vdom.parse.js +5 -10
  55. package/package.json +12 -8
  56. package/build/__test__/aws.init.test.d.ts +0 -2
  57. package/build/__test__/aws.init.test.d.ts.map +0 -1
  58. package/build/__test__/aws.init.test.js +0 -9
  59. package/build/aws/api.key.table.d.ts +0 -29
  60. package/build/aws/api.key.table.d.ts.map +0 -1
  61. package/build/aws/api.key.table.js +0 -38
  62. package/build/aws/credentials.d.ts +0 -21
  63. package/build/aws/credentials.d.ts.map +0 -1
  64. package/build/aws/credentials.js +0 -42
  65. package/build/aws/index.d.ts +0 -18
  66. package/build/aws/index.d.ts.map +0 -1
  67. package/build/aws/index.js +0 -38
  68. package/build/aws/object.cache.d.ts +0 -6
  69. package/build/aws/object.cache.d.ts.map +0 -1
  70. package/build/aws/object.cache.js +0 -17
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Projection = void 0;
4
- const tslib_1 = require("tslib");
5
- const geo_1 = require("@basemaps/geo");
6
- const geojson_1 = require("@linzjs/geojson");
7
- const proj4_1 = tslib_1.__importDefault(require("proj4"));
8
- const composite_error_1 = require("../composite.error");
9
- const citm2000_1 = require("./citm2000");
10
- const nztm2000_1 = require("./nztm2000");
11
- proj4_1.default.defs(geo_1.Epsg.Nztm2000.toEpsgString(), nztm2000_1.Nztm2000);
12
- proj4_1.default.defs(geo_1.Epsg.Citm2000.toEpsgString(), citm2000_1.Citm2000);
1
+ import { Epsg } from '@basemaps/geo';
2
+ import { multiPolygonToWgs84, toFeatureMultiPolygon, toFeaturePolygon, } from '@linzjs/geojson';
3
+ import Proj from 'proj4';
4
+ import { CompositeError } from '../composite.error.js';
5
+ import { Citm2000 } from './citm2000.js';
6
+ import { Nztm2000 } from './nztm2000.js';
7
+ Proj.defs(Epsg.Nztm2000.toEpsgString(), Nztm2000);
8
+ Proj.defs(Epsg.Citm2000.toEpsgString(), Citm2000);
13
9
  const CodeMap = new Map();
14
10
  function getEpsgCode(epsgCode) {
15
11
  if (epsgCode == null)
@@ -22,17 +18,17 @@ function getEpsgCode(epsgCode) {
22
18
  return epsgCode.projection.code;
23
19
  return null;
24
20
  }
25
- class Projection {
21
+ export class Projection {
26
22
  /**
27
23
  * Wrapper around TileMatrixSet with utilities for converting Points and Polygons
28
24
  */
29
25
  constructor(epsg) {
30
26
  this.epsg = epsg;
31
27
  try {
32
- this.projection = proj4_1.default(epsg.toEpsgString(), geo_1.Epsg.Wgs84.toEpsgString());
28
+ this.projection = Proj(epsg.toEpsgString(), Epsg.Wgs84.toEpsgString());
33
29
  }
34
30
  catch (err) {
35
- throw new composite_error_1.CompositeError(`Failed to create projection: ${epsg.toEpsgString()}, ${geo_1.Epsg.Wgs84.toEpsgString()}`, err);
31
+ throw new CompositeError(`Failed to create projection: ${epsg.toEpsgString()}, ${Epsg.Wgs84.toEpsgString()}`, 500, err);
36
32
  }
37
33
  }
38
34
  /**
@@ -59,7 +55,7 @@ class Projection {
59
55
  let proj = CodeMap.get(epsgCode);
60
56
  if (proj != null)
61
57
  return proj;
62
- const epsg = geo_1.Epsg.tryGet(epsgCode);
58
+ const epsg = Epsg.tryGet(epsgCode);
63
59
  if (epsg == null)
64
60
  return null;
65
61
  proj = new Projection(epsg);
@@ -67,11 +63,11 @@ class Projection {
67
63
  return proj;
68
64
  }
69
65
  /**
70
- * Project the points in a MultiPolygon array to the `targetProjection`.
71
-
72
- * @return if multipoly is not projected return it verbatim otherwise creates a new multi
73
- * polygon
74
- */
66
+ * Project the points in a MultiPolygon array to the `targetProjection`.
67
+
68
+ * @return if multipoly is not projected return it verbatim otherwise creates a new multi
69
+ * polygon
70
+ */
75
71
  projectMultipolygon(multipoly, targetProjection) {
76
72
  if (targetProjection.epsg.code === this.epsg.code)
77
73
  return multipoly;
@@ -92,33 +88,33 @@ class Projection {
92
88
  return this.projection.inverse;
93
89
  }
94
90
  /**
95
- * Convert a source Bounds to GeoJSON WGS84 BoundingBox. In particular if the bounds crosses the
96
- * anti-meridian then the east component will be less than the west component.
97
-
98
- * @param source
99
- * @returns [west, south, east, north]
100
- */
91
+ * Convert a source Bounds to GeoJSON WGS84 BoundingBox. In particular if the bounds crosses the
92
+ * anti-meridian then the east component will be less than the west component.
93
+
94
+ * @param source
95
+ * @returns [west, south, east, north]
96
+ */
101
97
  boundsToWgs84BoundingBox(source) {
102
98
  const sw = this.toWgs84([source.x, source.y]);
103
99
  const ne = this.toWgs84([source.x + source.width, source.y + source.height]);
104
100
  return [sw[0], sw[1], ne[0], ne[1]];
105
101
  }
106
102
  /**
107
- * Convert a source bounds to a WSG84 GeoJSON Feature
108
-
109
- * @param bounds in source epsg
110
- * @param properties any properties to include in the feature such as name
111
-
112
- * @returns If `bounds` crosses the antimeridian then and east and west pair of non crossing
113
- * polygons will be returned; otherwise a single Polygon will be returned.
114
- */
103
+ * Convert a source bounds to a WSG84 GeoJSON Feature
104
+
105
+ * @param bounds in source epsg
106
+ * @param properties any properties to include in the feature such as name
107
+
108
+ * @returns If `bounds` crosses the antimeridian then and east and west pair of non crossing
109
+ * polygons will be returned; otherwise a single Polygon will be returned.
110
+ */
115
111
  boundsToGeoJsonFeature(bounds, properties = {}) {
116
112
  const sw = [bounds.x, bounds.y];
117
113
  const se = [bounds.x + bounds.width, bounds.y];
118
114
  const nw = [bounds.x, bounds.y + bounds.height];
119
115
  const ne = [bounds.x + bounds.width, bounds.y + bounds.height];
120
- const coords = geojson_1.multiPolygonToWgs84([[[sw, nw, ne, se, sw]]], this.toWgs84);
121
- const feature = coords.length === 1 ? geojson_1.toFeaturePolygon(coords[0], properties) : geojson_1.toFeatureMultiPolygon(coords, properties);
116
+ const coords = multiPolygonToWgs84([[[sw, nw, ne, se, sw]]], this.toWgs84);
117
+ const feature = coords.length === 1 ? toFeaturePolygon(coords[0], properties) : toFeatureMultiPolygon(coords, properties);
122
118
  feature.bbox = this.boundsToWgs84BoundingBox(bounds);
123
119
  return feature;
124
120
  }
@@ -130,14 +126,14 @@ class Projection {
130
126
  };
131
127
  }
132
128
  /**
133
- * Find the closest zoom level to `gsd` (Ground Sampling Distance meters per pixel) that is at
134
- * least as good as `gsd`.
135
-
136
- * @param gsd
137
-
138
- * @param blockFactor How many time bigger the blockSize is compared to tileSize. Leave as 1 to
139
- * not take into account.
140
- */
129
+ * Find the closest zoom level to `gsd` (Ground Sampling Distance meters per pixel) that is at
130
+ * least as good as `gsd`.
131
+
132
+ * @param gsd
133
+
134
+ * @param blockFactor How many time bigger the blockSize is compared to tileSize. Leave as 1 to
135
+ * not take into account.
136
+ */
141
137
  static getTiffResZoom(tms, gsd, blockFactor = 1) {
142
138
  // Get best image resolution
143
139
  let z = 0;
@@ -164,7 +160,43 @@ class Projection {
164
160
  static tileCenterToLatLon(tms, tile) {
165
161
  const point = tms.tileToSource({ x: tile.x + 0.5, y: tile.y + 0.5, z: tile.z });
166
162
  const [lon, lat] = this.get(tms).toWgs84([point.x, point.y]);
167
- return { lat, lon };
163
+ return Projection.wrapLatLon(lat, lon);
164
+ }
165
+ /**
166
+ * Reused from : https://github.com/pelias/api/blob/6a7751f35882698eb885b93635656ec0c2941633/sanitizer/wrap.js
167
+ *
168
+ * Normalize co-ordinates that lie outside of the normal ranges.
169
+ *
170
+ * longitude wrapping simply requires adding +- 360 to the value until it comes in to range.
171
+ * for the latitude values we need to flip the longitude whenever the latitude
172
+ * crosses a pole.
173
+ *
174
+ */
175
+ static wrapLatLon(lat, lon) {
176
+ const point = { lat, lon };
177
+ const quadrant = Math.floor(Math.abs(lat) / 90) % 4;
178
+ const pole = lat > 0 ? 90 : -90;
179
+ const offset = lat % 90;
180
+ switch (quadrant) {
181
+ case 0:
182
+ point.lat = offset;
183
+ break;
184
+ case 1:
185
+ point.lat = pole - offset;
186
+ point.lon += 180;
187
+ break;
188
+ case 2:
189
+ point.lat = -offset;
190
+ point.lon += 180;
191
+ break;
192
+ case 3:
193
+ point.lat = -pole + offset;
194
+ break;
195
+ }
196
+ if (point.lon > 180 || point.lon < -180) {
197
+ point.lon -= Math.floor((point.lon + 180) / 360) * 360;
198
+ }
199
+ return point;
168
200
  }
169
201
  /**
170
202
  * Find the number of alignment levels required to render the tile. Min 1
@@ -176,16 +208,15 @@ class Projection {
176
208
  return Math.max(0, this.getTiffResZoom(tms, gsd, 2) - tile.z);
177
209
  }
178
210
  /**
179
- * Return the expected width in pixels of an image at the tile resolution. Uses
180
- * `this.blockFactor` for HiDPI tiles.
181
-
182
- * @param tile
183
- * @param targetZoom The desired zoom level for the imagery
184
- */
211
+ * Return the expected width in pixels of an image at the tile resolution. Uses
212
+ * `this.blockFactor` for HiDPI tiles.
213
+
214
+ * @param tile
215
+ * @param targetZoom The desired zoom level for the imagery
216
+ */
185
217
  static getImagePixelWidth(tms, tile, targetZoom) {
186
218
  const ul = tms.tileToSource(tile);
187
219
  const lr = tms.tileToSource({ x: tile.x + 1, y: tile.y + 1, z: tile.z });
188
220
  return Math.round((lr.x - ul.x) / tms.pixelScale(targetZoom)) * 2;
189
221
  }
190
222
  }
191
- exports.Projection = Projection;
@@ -1 +1 @@
1
- {"version":3,"file":"tile.set.name.d.ts","sourceRoot":"","sources":["../../src/proj/tile.set.name.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACnB,MAAM,WAAW;CACpB;AAED,wBAAgB,iBAAiB,IAAI,WAAW,EAAE,CAEjD"}
1
+ {"version":3,"file":"tile.set.name.d.ts","sourceRoot":"","sources":["../../src/proj/tile.set.name.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,MAAM,WAAW;CAClB;AAED,wBAAgB,iBAAiB,IAAI,WAAW,EAAE,CAEjD"}
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TileSetNameValues = exports.TileSetName = void 0;
4
- var TileSetName;
1
+ export var TileSetName;
5
2
  (function (TileSetName) {
6
3
  TileSetName["aerial"] = "aerial";
7
- })(TileSetName = exports.TileSetName || (exports.TileSetName = {}));
8
- function TileSetNameValues() {
4
+ })(TileSetName || (TileSetName = {}));
5
+ export function TileSetNameValues() {
9
6
  return [TileSetName.aerial];
10
7
  }
11
- exports.TileSetNameValues = TileSetNameValues;
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,UAAU,KAAK;IACX,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,MAAM,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQxD;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAiBvE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,sCAAsC;AACtC,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAWtE"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,MAAM,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQxD;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAiBvE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,sCAAsC;AACtC,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAWtE"}
package/build/util.js CHANGED
@@ -1,30 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUrlHost = exports.s3ToVsis3 = exports.extractYearRangeFromName = exports.titleizeImageryName = exports.compareName = void 0;
4
- function compareName(a, b) {
1
+ export function compareName(a, b) {
5
2
  return a.name.localeCompare(b.name);
6
3
  }
7
- exports.compareName = compareName;
8
4
  /**
9
5
  * Make a tile imagery name nicer to display as a Title
10
6
  * @example
11
7
  * 'tasman_rural_2018-19_0-3m' => 'Tasman rural 2018-19 0.3m'
12
8
  */
13
- function titleizeImageryName(name) {
9
+ export function titleizeImageryName(name) {
14
10
  return (name[0].toUpperCase() +
15
11
  name
16
12
  .slice(1)
17
13
  .replace(/_(\d+)-(\d+)m/g, ' $1.$2m')
18
14
  .replace(/_/g, ' '));
19
15
  }
20
- exports.titleizeImageryName = titleizeImageryName;
21
16
  /**
22
17
  * Attempt to parse a year from a imagery name
23
18
  * @example wellington_urban_2017_0.10m -> 2017
24
19
  * @param name Imagery name to parse
25
20
  * @return imagery year, -1 for failure to parse
26
21
  */
27
- function extractYearRangeFromName(name) {
22
+ export function extractYearRangeFromName(name) {
28
23
  const re = /(?:^|\D)(\d{4})(?:-(\d{2}))?(?:$|\D)/g;
29
24
  const years = [];
30
25
  for (let m = re.exec(name); m != null; m = re.exec(name)) {
@@ -38,13 +33,11 @@ function extractYearRangeFromName(name) {
38
33
  years.sort();
39
34
  return [years[0], years[years.length - 1] + 1];
40
35
  }
41
- exports.extractYearRangeFromName = extractYearRangeFromName;
42
- function s3ToVsis3(name) {
36
+ export function s3ToVsis3(name) {
43
37
  return name.startsWith('s3://') ? '/vsis3/' + name.slice('s3://'.length) : name;
44
38
  }
45
- exports.s3ToVsis3 = s3ToVsis3;
46
39
  /** Extract the hostname from a url */
47
- function getUrlHost(ref) {
40
+ export function getUrlHost(ref) {
48
41
  if (ref == null)
49
42
  return ref;
50
43
  try {
@@ -60,4 +53,3 @@ function getUrlHost(ref) {
60
53
  }
61
54
  return ref;
62
55
  }
63
- exports.getUrlHost = getUrlHost;
@@ -1 +1 @@
1
- {"version":3,"file":"vdom.d.ts","sourceRoot":"","sources":["../src/vdom.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAIjD;;IAEI;AACJ,8BAAsB,KAAK;IACvB;;;OAGG;IACH,QAAQ,CAAC,KAAK,SAAI,GAAG,MAAM;IAI3B,QAAQ,KAAK,WAAW,IAAI,MAAM,CAAC;IACnC,QAAQ,KAAK,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE;CACvC;AAED;;IAEI;AACJ,qBAAa,SAAU,SAAQ,KAAK;IAChC,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,EAAE,MAAM;IAKxB,QAAQ,CAAC,KAAK,SAAI,GAAG,MAAM;IAI3B,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,WAAW,CAAC,CAAC,EAAE,MAAM,EAExB;CACJ;AAED;;IAEI;AACJ,qBAAa,YAAa,SAAQ,KAAK;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,QAAQ,EAAE,KAAK,EAAE,CAAC;gBAEN,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ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EAAE,UAAU,EAAE,GAAG,UAAU,GAAG,YAAY,CAAC"}
package/build/vdom.js CHANGED
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.V = exports.VNodeElement = exports.VNodeText = exports.VNode = void 0;
4
1
  const indent = (level) => ' '.repeat(level);
5
2
  /**
6
3
  * Virtual Node for storing `sgml` style documents
7
4
  **/
8
- class VNode {
5
+ export class VNode {
9
6
  /**
10
7
  * Convert a virtual dom node to sgml text
11
8
  * @param level current indentation level
@@ -14,11 +11,10 @@ class VNode {
14
11
  return indent(level) + '[VNode]';
15
12
  }
16
13
  }
17
- exports.VNode = VNode;
18
14
  /**
19
15
  * Virtual Text Node for storing text leaf nodes
20
16
  **/
21
- class VNodeText extends VNode {
17
+ export class VNodeText extends VNode {
22
18
  constructor(text) {
23
19
  super();
24
20
  this.text = text;
@@ -33,11 +29,10 @@ class VNodeText extends VNode {
33
29
  this.text = v;
34
30
  }
35
31
  }
36
- exports.VNodeText = VNodeText;
37
32
  /**
38
33
  * Virtual Element Node for storing tagged elements
39
34
  **/
40
- class VNodeElement extends VNode {
35
+ export class VNodeElement extends VNode {
41
36
  constructor(tag, attrs, children) {
42
37
  super();
43
38
  this.tag = tag;
@@ -118,7 +113,6 @@ class VNodeElement extends VNode {
118
113
  return `\n${this.children.map((c) => c.toString(level + 1)).join(`\n`)}\n${indent(level)}`;
119
114
  }
120
115
  }
121
- exports.VNodeElement = VNodeElement;
122
116
  /**
123
117
  * Validate and convert all children to VNodes
124
118
  *
@@ -146,7 +140,7 @@ function normalizeChildren(children) {
146
140
  }
147
141
  return [children];
148
142
  }
149
- function V(tag, arg1, children) {
143
+ export function V(tag, arg1, children) {
150
144
  const hasAttrs = typeof arg1 === 'object' && !Array.isArray(arg1);
151
145
  if (!hasAttrs) {
152
146
  if (children != null)
@@ -155,4 +149,3 @@ function V(tag, arg1, children) {
155
149
  }
156
150
  return new VNodeElement(tag, hasAttrs ? arg1 : {}, normalizeChildren(children));
157
151
  }
158
- exports.V = V;
@@ -1,4 +1,4 @@
1
- import { VNodeElement } from './vdom';
1
+ import { VNodeElement } from './vdom.js';
2
2
  export declare class VNodeParser {
3
3
  root: VNodeElement;
4
4
  tree: VNodeElement[];
@@ -1 +1 @@
1
- {"version":3,"file":"vdom.parse.d.ts","sourceRoot":"","sources":["../src/vdom.parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAa,MAAM,QAAQ,CAAC;AAEjD,qBAAa,WAAW;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,YAAY,EAAE,CAAC;IAErB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;;IAQhD,IAAI,WAAW,IAAI,YAAY,CAE9B;IAED,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CA4B5C"}
1
+ {"version":3,"file":"vdom.parse.d.ts","sourceRoot":"","sources":["../src/vdom.parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAa,MAAM,WAAW,CAAC;AAEpD,qBAAa,WAAW;IACtB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,YAAY,EAAE,CAAC;IAErB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;;IAQhD,IAAI,WAAW,IAAI,YAAY,CAE9B;IAED,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CA4B1C"}
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VNodeParser = void 0;
4
- const tslib_1 = require("tslib");
5
- const sax = tslib_1.__importStar(require("sax"));
6
- const vdom_1 = require("./vdom");
7
- class VNodeParser {
1
+ import sax from 'sax';
2
+ import { VNodeElement, VNodeText } from './vdom.js';
3
+ export class VNodeParser {
8
4
  constructor() {
9
5
  this.tree = [];
10
6
  }
@@ -19,11 +15,11 @@ class VNodeParser {
19
15
  parser.ontext = (text) => {
20
16
  if (text.trim() === '')
21
17
  return; // Skip newlines and empty text
22
- const textNode = new vdom_1.VNodeText(text);
18
+ const textNode = new VNodeText(text);
23
19
  this.currentNode.children.push(textNode);
24
20
  };
25
21
  parser.onopentag = (tag) => {
26
- const currentNode = new vdom_1.VNodeElement(tag.name, tag.attributes, []);
22
+ const currentNode = new VNodeElement(tag.name, tag.attributes, []);
27
23
  if (this.tree.length > 0) {
28
24
  this.currentNode.children.push(currentNode);
29
25
  }
@@ -43,4 +39,3 @@ class VNodeParser {
43
39
  });
44
40
  }
45
41
  }
46
- exports.VNodeParser = VNodeParser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basemaps/shared",
3
- "version": "6.7.0",
3
+ "version": "6.11.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,6 +12,10 @@
12
12
  "url": "https://linz.govt.nz",
13
13
  "organization": true
14
14
  },
15
+ "type": "module",
16
+ "engines": {
17
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
18
+ },
15
19
  "license": "MIT",
16
20
  "main": "./build/index.js",
17
21
  "types": "./build/index.d.ts",
@@ -19,12 +23,12 @@
19
23
  "test": "ospec --globs 'build/**/*.test.js'"
20
24
  },
21
25
  "dependencies": {
22
- "@basemaps/config": "^6.7.0",
23
- "@basemaps/geo": "^6.0.0",
24
- "@basemaps/tiler": "^6.1.0",
25
- "@linzjs/geojson": "^6.0.0",
26
- "@linzjs/metrics": "^6.0.0",
27
- "@linzjs/s3fs": "^6.7.0",
26
+ "@basemaps/config": "^6.10.0",
27
+ "@basemaps/geo": "^6.10.0",
28
+ "@basemaps/tiler": "^6.11.0",
29
+ "@linzjs/geojson": "^6.10.0",
30
+ "@linzjs/metrics": "^6.11.0",
31
+ "@linzjs/s3fs": "^6.9.1",
28
32
  "aws-sdk": "^2.890.0",
29
33
  "base-x": "^3.0.7",
30
34
  "pino": "^6.2.1",
@@ -46,5 +50,5 @@
46
50
  "files": [
47
51
  "build/"
48
52
  ],
49
- "gitHead": "e4c99e98739ca7df52aaad37936c74bcf4fc4e82"
53
+ "gitHead": "e15ab34277b74a70a2b37ecf950e58ca6ba8a843"
50
54
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=aws.init.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aws.init.test.d.ts","sourceRoot":"","sources":["../../src/__test__/aws.init.test.ts"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const ospec_1 = tslib_1.__importDefault(require("ospec"));
5
- ospec_1.default.spec('AWS Init', () => {
6
- ospec_1.default('should update the aws config', () => {
7
- ospec_1.default(process.env['AWS_NODEJS_CONNECTION_REUSE_ENABLED']).equals('1');
8
- });
9
- });
@@ -1,29 +0,0 @@
1
- import { BaseDynamoTable } from './aws.dynamo.table';
2
- /**
3
- * The database format for the ApiKey Table
4
- */
5
- export interface ApiKeyTableRecord extends BaseDynamoTable {
6
- /** Enable / disable a API Key */
7
- enabled: boolean;
8
- /** Timestamp for when this limit expires */
9
- minuteExpireAt: number;
10
- /** Number of api requests this minute */
11
- minuteCount: number;
12
- /** Allow custom limits set per API Key */
13
- minuteLimit?: number;
14
- /** Lock this API Key to a referrer host */
15
- lockToReferrer?: string;
16
- /** Lock this API Key to a list of ips */
17
- lockToIp?: string[];
18
- }
19
- export declare class ApiKeyTable {
20
- private dynamo;
21
- constructor();
22
- /**
23
- * Fetch a ApiKey Record from the database
24
- * @param apiKey The API Key to fetch
25
- */
26
- get(apiKey: string): Promise<ApiKeyTableRecord | null>;
27
- create(apiKey: string): Promise<string>;
28
- }
29
- //# sourceMappingURL=api.key.table.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.key.table.d.ts","sourceRoot":"","sources":["../../src/aws/api.key.table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACtD,iCAAiC;IACjC,OAAO,EAAE,OAAO,CAAC;IAEjB,4CAA4C;IAC5C,cAAc,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAW;;IAMzB;;;OAGG;IACU,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAgBtD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CASvD"}
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiKeyTable = void 0;
4
- const tslib_1 = require("tslib");
5
- const const_1 = require("../const");
6
- const dynamodb_1 = tslib_1.__importDefault(require("aws-sdk/clients/dynamodb"));
7
- class ApiKeyTable {
8
- constructor() {
9
- this.dynamo = new dynamodb_1.default({});
10
- }
11
- /**
12
- * Fetch a ApiKey Record from the database
13
- * @param apiKey The API Key to fetch
14
- */
15
- async get(apiKey) {
16
- const res = await this.dynamo
17
- .getItem({
18
- TableName: const_1.Const.ApiKey.TableName,
19
- Key: { id: { S: apiKey } },
20
- ConsistentRead: false,
21
- })
22
- .promise();
23
- if (res.Item == null) {
24
- return null;
25
- }
26
- return dynamodb_1.default.Converter.unmarshall(res.Item);
27
- }
28
- async create(apiKey) {
29
- await this.dynamo
30
- .putItem({
31
- TableName: const_1.Const.ApiKey.TableName,
32
- Item: { id: { S: apiKey } },
33
- })
34
- .promise();
35
- return apiKey;
36
- }
37
- }
38
- exports.ApiKeyTable = ApiKeyTable;
@@ -1,21 +0,0 @@
1
- import { ObjectCache } from './object.cache';
2
- import { ChainableTemporaryCredentials } from 'aws-sdk/lib/credentials/chainable_temporary_credentials';
3
- import S3 from 'aws-sdk/clients/s3';
4
- export interface StsAssumeRoleConfig {
5
- roleArn: string;
6
- externalId?: string;
7
- }
8
- /**
9
- * Credentials need to be cached or a separate assume role will be called for each individual
10
- * instance of the credential chain
11
- */
12
- declare class CredentialObjectCache extends ObjectCache<ChainableTemporaryCredentials, StsAssumeRoleConfig> {
13
- create(opts: StsAssumeRoleConfig): ChainableTemporaryCredentials;
14
- }
15
- export declare const CredentialsCache: CredentialObjectCache;
16
- declare class S3ObjectCache extends ObjectCache<S3, StsAssumeRoleConfig> {
17
- create(opt: StsAssumeRoleConfig): S3;
18
- }
19
- export declare const S3Cache: S3ObjectCache;
20
- export {};
21
- //# sourceMappingURL=credentials.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/aws/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,EAAE,6BAA6B,EAAE,MAAM,yDAAyD,CAAC;AACxG,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAWpC,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAID;;;GAGG;AACH,cAAM,qBAAsB,SAAQ,WAAW,CAAC,6BAA6B,EAAE,mBAAmB,CAAC;IAC/F,MAAM,CAAC,IAAI,EAAE,mBAAmB,GAAG,6BAA6B;CAWnE;AACD,eAAO,MAAM,gBAAgB,uBAA8B,CAAC;AAE5D,cAAM,aAAc,SAAQ,WAAW,CAAC,EAAE,EAAE,mBAAmB,CAAC;IAC5D,MAAM,CAAC,GAAG,EAAE,mBAAmB,GAAG,EAAE;CAIvC;AAED,eAAO,MAAM,OAAO,eAAsB,CAAC"}
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.S3Cache = exports.CredentialsCache = void 0;
4
- const tslib_1 = require("tslib");
5
- const object_cache_1 = require("./object.cache");
6
- const os_1 = require("os");
7
- const const_1 = require("../const");
8
- const s3_1 = tslib_1.__importDefault(require("aws-sdk/clients/s3"));
9
- /**
10
- * Nasty Hack
11
- *
12
- * to prevent type pollution we do not want to include the entire aws-sdk
13
- * This bypasses the type checker but still inits the AWS SDK so we have access to credentials
14
- */
15
- // eslint-disable-next-line @typescript-eslint/no-var-requires
16
- const AWS = require('aws-sdk');
17
- const OneHourSeconds = 60 * 60;
18
- /**
19
- * Credentials need to be cached or a separate assume role will be called for each individual
20
- * instance of the credential chain
21
- */
22
- class CredentialObjectCache extends object_cache_1.ObjectCache {
23
- create(opts) {
24
- return new AWS.ChainableTemporaryCredentials({
25
- params: {
26
- RoleArn: opts.roleArn,
27
- ExternalId: opts.externalId,
28
- RoleSessionName: `bm-${os_1.hostname().substr(0, 32)}-${Date.now()}`,
29
- DurationSeconds: const_1.Env.getNumber(const_1.Env.AwsRoleDurationHours, 8) * OneHourSeconds,
30
- },
31
- masterCredentials: AWS.config.credentials,
32
- });
33
- }
34
- }
35
- exports.CredentialsCache = new CredentialObjectCache();
36
- class S3ObjectCache extends object_cache_1.ObjectCache {
37
- create(opt) {
38
- const credentials = exports.CredentialsCache.getOrMake(opt.roleArn, opt);
39
- return new s3_1.default({ credentials });
40
- }
41
- }
42
- exports.S3Cache = new S3ObjectCache();
@@ -1,18 +0,0 @@
1
- import { ConfigDynamo } from '@basemaps/config';
2
- import S3 from 'aws-sdk/clients/s3';
3
- import { ChainableTemporaryCredentials } from 'aws-sdk/lib/credentials/chainable_temporary_credentials';
4
- import { ApiKeyTable } from './api.key.table';
5
- import { StsAssumeRoleConfig } from './credentials';
6
- export declare const Aws: {
7
- s3: S3;
8
- credentials: {
9
- /**
10
- * Get a s3 that is bound to a specific role
11
- */
12
- getS3ForRole(opts?: StsAssumeRoleConfig | undefined): S3;
13
- getCredentialsForRole(roleArn: string, externalId?: string | undefined): ChainableTemporaryCredentials;
14
- };
15
- apiKey: ApiKeyTable;
16
- };
17
- export declare const Config: ConfigDynamo;
18
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/aws/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,yDAAyD,CAAC;AAExG,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAA6B,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAG/E,eAAO,MAAM,GAAG;;;QAGR;;WAEG;8DACuC,EAAE;uCAIb,MAAM,oCAAwB,6BAA6B;;;CAKjG,CAAC;AAEF,eAAO,MAAM,MAAM,cAAiD,CAAC"}