@elastic/ems-client 7.17.1 → 7.17.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.
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
32
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
+ return new (P || (P = Promise))(function (resolve, reject) {
34
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
38
+ });
39
+ };
40
+ var __importDefault = (this && this.__importDefault) || function (mod) {
41
+ return (mod && mod.__esModule) ? mod : { "default": mod };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.FileLayer = exports.EMSFormatType = void 0;
45
+ const url_1 = __importDefault(require("url"));
46
+ const ems_service_1 = require("./ems_service");
47
+ const topojson = __importStar(require("topojson-client"));
48
+ var EMSFormatType;
49
+ (function (EMSFormatType) {
50
+ EMSFormatType["geojson"] = "geojson";
51
+ EMSFormatType["topojson"] = "topojson";
52
+ })(EMSFormatType || (exports.EMSFormatType = EMSFormatType = {}));
53
+ class FileLayer extends ems_service_1.AbstractEmsService {
54
+ constructor(config, emsClient, proxyPath) {
55
+ super(config, emsClient, proxyPath);
56
+ this._config = config;
57
+ }
58
+ getGeoJson() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ var _a;
61
+ const cachedGeoJson = this._emsClient.getCachedGeoJson(this.getId());
62
+ if (cachedGeoJson) {
63
+ return cachedGeoJson;
64
+ }
65
+ const format = this.getDefaultFormatType();
66
+ const fetchUrl = this.getDefaultFormatUrl();
67
+ let geojson;
68
+ const fetchedJson = yield this._emsClient.getManifest(fetchUrl);
69
+ if (fetchedJson) {
70
+ if (format === 'geojson') {
71
+ geojson = fetchedJson;
72
+ }
73
+ else if (format === 'topojson') {
74
+ const meta = this.getDefaultFormatMeta();
75
+ const featureCollectionPath = (_a = meta === null || meta === void 0 ? void 0 : meta.feature_collection_path) !== null && _a !== void 0 ? _a : 'data';
76
+ // @ts-expect-error see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/52156
77
+ geojson = topojson.feature(fetchedJson, featureCollectionPath);
78
+ }
79
+ else {
80
+ return;
81
+ }
82
+ this._emsClient.cacheGeoJson(this.getId(), geojson);
83
+ return geojson;
84
+ }
85
+ return;
86
+ });
87
+ }
88
+ getFields() {
89
+ return this._config.fields;
90
+ }
91
+ getFieldsInLanguage() {
92
+ return this.getFields().map((field) => {
93
+ return {
94
+ type: field.type,
95
+ name: field.id,
96
+ description: this._emsClient.getValueInLanguage(field.label),
97
+ };
98
+ });
99
+ }
100
+ getDisplayName() {
101
+ const layerName = this._emsClient.getValueInLanguage(this._config.layer_name);
102
+ return layerName ? layerName : '';
103
+ }
104
+ getId() {
105
+ return this._config.layer_id;
106
+ }
107
+ hasId(id) {
108
+ const matchesLegacyId = this._config.legacy_ids.indexOf(id) >= 0;
109
+ return this._config.layer_id === id || matchesLegacyId;
110
+ }
111
+ getEMSHotLink() {
112
+ const landingPageString = this._emsClient.getLandingPageUrl();
113
+ const urlObject = url_1.default.parse(landingPageString, true);
114
+ urlObject.hash = `file/${this.getId()}`;
115
+ urlObject.query = Object.assign(Object.assign({}, urlObject.query), { locale: this._emsClient.getLocale() });
116
+ return url_1.default.format(urlObject);
117
+ }
118
+ getDefaultFormatType() {
119
+ const format = this._getDefaultFormat();
120
+ return format.type;
121
+ }
122
+ getFormatOfType(type) {
123
+ const format = this._getFormatOfType(type);
124
+ return format.type;
125
+ }
126
+ getDefaultFormatMeta() {
127
+ const format = this._getDefaultFormat();
128
+ return this._getFormatMeta(format);
129
+ }
130
+ getFormatOfTypeMeta(type) {
131
+ const format = this._getFormatOfType(type);
132
+ return this._getFormatMeta(format);
133
+ }
134
+ getDefaultFormatUrl() {
135
+ const format = this._getDefaultFormat();
136
+ return this._getFormatUrl(format);
137
+ }
138
+ getFormatOfTypeUrl(type) {
139
+ const format = this._getFormatOfType(type);
140
+ return this._getFormatUrl(format);
141
+ }
142
+ getCreatedAt() {
143
+ return this._config.created_at;
144
+ }
145
+ getApiUrl() {
146
+ return this._emsClient.getFileApiUrl();
147
+ }
148
+ _getFormatUrl(format) {
149
+ const url = this._proxyPath + this._getAbsoluteUrl(format.url);
150
+ return this._emsClient.extendUrlWithParams(url);
151
+ }
152
+ _getFormatMeta(format) {
153
+ if ('meta' in format) {
154
+ return format.meta;
155
+ }
156
+ else {
157
+ return;
158
+ }
159
+ }
160
+ _getDefaultFormat() {
161
+ const defaultFormat = this._config.formats.find((format) => {
162
+ return format.legacy_default;
163
+ });
164
+ if (defaultFormat) {
165
+ return defaultFormat;
166
+ }
167
+ return this._config.formats[0];
168
+ }
169
+ _getFormatOfType(type) {
170
+ const requestedFormat = this._config.formats.find((format) => {
171
+ return format.type === type;
172
+ });
173
+ return requestedFormat || this._getDefaultFormat();
174
+ }
175
+ }
176
+ exports.FileLayer = FileLayer;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.TMSService = exports.FileLayer = exports.LATEST_API_URL_PATH = exports.EMSClient = void 0;
10
+ var ems_client_1 = require("./ems_client");
11
+ Object.defineProperty(exports, "EMSClient", { enumerable: true, get: function () { return ems_client_1.EMSClient; } });
12
+ Object.defineProperty(exports, "LATEST_API_URL_PATH", { enumerable: true, get: function () { return ems_client_1.LATEST_API_URL_PATH; } });
13
+ var file_layer_1 = require("./file_layer");
14
+ Object.defineProperty(exports, "FileLayer", { enumerable: true, get: function () { return file_layer_1.FileLayer; } });
15
+ var tms_service_1 = require("./tms_service");
16
+ Object.defineProperty(exports, "TMSService", { enumerable: true, get: function () { return tms_service_1.TMSService; } });
@@ -11,15 +11,15 @@ var _semver = _interopRequireDefault(require("semver"));
11
11
  var _url = require("url");
12
12
  var _utils = require("./utils");
13
13
  var _lruCache = _interopRequireDefault(require("lru-cache"));
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
17
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
18
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
19
- * or more contributor license agreements. Licensed under the Elastic License
20
- * 2.0; you may not use this file except in compliance with the Elastic License
21
- * 2.0.
22
- */
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
17
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
18
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
19
+ * or more contributor license agreements. Licensed under the Elastic License
20
+ * 2.0; you may not use this file except in compliance with the Elastic License
21
+ * 2.0.
22
+ */
23
23
  const DEFAULT_EMS_VERSION = '7.17';
24
24
  /**
25
25
  * plugins cannot have upstream dependencies on core/*-kibana.
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.AbstractEmsService = void 0;
7
7
  var _origin = require("./origin");
8
8
  var _utils = require("./utils");
9
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
12
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
13
- * or more contributor license agreements. Licensed under the Elastic License
14
- * 2.0; you may not use this file except in compliance with the Elastic License
15
- * 2.0.
16
- */
9
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
11
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
12
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
13
+ * or more contributor license agreements. Licensed under the Elastic License
14
+ * 2.0; you may not use this file except in compliance with the Elastic License
15
+ * 2.0.
16
+ */
17
17
  class AbstractEmsService {
18
18
  constructor(config, emsClient, proxyPath) {
19
19
  _defineProperty(this, "_emsClient", void 0);
@@ -8,16 +8,16 @@ var _url = _interopRequireDefault(require("url"));
8
8
  var _ems_service = require("./ems_service");
9
9
  var topojson = _interopRequireWildcard(require("topojson-client"));
10
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
15
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
16
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
17
- * or more contributor license agreements. Licensed under the Elastic License
18
- * 2.0; you may not use this file except in compliance with the Elastic License
19
- * 2.0.
20
- */
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
15
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
16
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
17
+ * or more contributor license agreements. Licensed under the Elastic License
18
+ * 2.0; you may not use this file except in compliance with the Elastic License
19
+ * 2.0.
20
+ */
21
21
  let EMSFormatType = exports.EMSFormatType = /*#__PURE__*/function (EMSFormatType) {
22
22
  EMSFormatType["geojson"] = "geojson";
23
23
  EMSFormatType["topojson"] = "topojson";
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.TMSService = void 0;
7
7
  var _lodash = _interopRequireDefault(require("lodash"));
8
8
  var _ems_service = require("./ems_service");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
12
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
13
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
14
- * or more contributor license agreements. Licensed under the Elastic License
15
- * 2.0; you may not use this file except in compliance with the Elastic License
16
- * 2.0.
17
- */
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
12
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
13
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
14
+ * or more contributor license agreements. Licensed under the Elastic License
15
+ * 2.0; you may not use this file except in compliance with the Elastic License
16
+ * 2.0.
17
+ */
18
18
  class TMSService extends _ems_service.AbstractEmsService {
19
19
  constructor(config, emsClient, proxyPath) {
20
20
  super(config, emsClient, proxyPath);
@@ -1,6 +1,6 @@
1
1
  import { EMSClient, TMSServiceConfig } from './ems_client';
2
2
  import { AbstractEmsService } from './ems_service';
3
- declare type EmsVectorSource = {
3
+ type EmsVectorSource = {
4
4
  type: 'vector';
5
5
  url: string;
6
6
  tiles: string[];
@@ -10,10 +10,10 @@ declare type EmsVectorSource = {
10
10
  maxzoom?: number;
11
11
  attribution?: string;
12
12
  };
13
- declare type EmsVectorSources = {
13
+ type EmsVectorSources = {
14
14
  [sourceName: string]: EmsVectorSource;
15
15
  };
16
- declare type EmsVectorStyle = {
16
+ type EmsVectorStyle = {
17
17
  sources: EmsVectorSources;
18
18
  sprite: string;
19
19
  glyphs: string;
@@ -28,17 +28,17 @@ declare type EmsVectorStyle = {
28
28
  version: number;
29
29
  zoom?: number;
30
30
  };
31
- declare type EmsSprite = {
31
+ type EmsSprite = {
32
32
  height: number;
33
33
  pixelRatio: number;
34
34
  width: number;
35
35
  x: number;
36
36
  y: number;
37
37
  };
38
- declare type EmsSpriteSheet = {
38
+ type EmsSpriteSheet = {
39
39
  [spriteName: string]: EmsSprite;
40
40
  };
41
- declare type EmsRasterStyle = {
41
+ type EmsRasterStyle = {
42
42
  tilejson: string;
43
43
  name: string;
44
44
  attribution: string;