@loaders.gl/arcgis 5.0.0-beta.5 → 5.0.0-beta.6

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/index.cjs CHANGED
@@ -367,6 +367,7 @@ async function loadLibraryInWorker(libraryUrl, moduleLibraryUrl = libraryUrl) {
367
367
  } catch {
368
368
  const moduleUrl = new URL(moduleLibraryUrl, globalThis.location.href).href;
369
369
  const library = await import(
370
+ /* webpackIgnore: true */
370
371
  /* @vite-ignore */
371
372
  moduleUrl
372
373
  );
@@ -1827,6 +1828,8 @@ var init_http_file_transport = __esm({
1827
1828
  identityHints;
1828
1829
  /** Failure objects already included in telemetry. */
1829
1830
  countedFailures = /* @__PURE__ */ new WeakSet();
1831
+ /** Observer for cumulative transport counters, including asynchronous cancellation. */
1832
+ onTelemetry;
1830
1833
  /** Mutable counters backing immutable telemetry snapshots. */
1831
1834
  telemetry = {
1832
1835
  requestedBytes: 0,
@@ -1840,6 +1843,7 @@ var init_http_file_transport = __esm({
1840
1843
  constructor(url, options) {
1841
1844
  validateKnownByteLength(options.byteLength);
1842
1845
  this.url = url;
1846
+ this.onTelemetry = options.onTelemetry;
1843
1847
  this.fetchFunction = options.fetch || ((input, init) => globalThis.fetch(input, init));
1844
1848
  this.fetchOptions = options.fetchOptions ? { ...options.fetchOptions, headers: new Headers(options.fetchOptions.headers) } : void 0;
1845
1849
  this.consistency = options.consistency || "best-effort";
@@ -1866,6 +1870,7 @@ var init_http_file_transport = __esm({
1866
1870
  }
1867
1871
  /** Counts each failure object once even when it passes through several async layers. */
1868
1872
  trackFailure(error) {
1873
+ var _a2;
1869
1874
  if (typeof error === "object" && error !== null) {
1870
1875
  if (this.countedFailures.has(error)) {
1871
1876
  return;
@@ -1877,10 +1882,11 @@ var init_http_file_transport = __esm({
1877
1882
  } else {
1878
1883
  this.telemetry.errorCount++;
1879
1884
  }
1885
+ (_a2 = this.onTelemetry) == null ? void 0 : _a2.call(this, this.getTelemetry(), error);
1880
1886
  }
1881
1887
  /** Performs and validates one exact HTTP range request. */
1882
1888
  async requestRange(offset, length, signal, expectedIdentity) {
1883
- var _a2;
1889
+ var _a2, _b;
1884
1890
  const requestStartTime = getTimestamp2();
1885
1891
  const abortContext = createCombinedAbortContext(signal, (_a2 = this.fetchOptions) == null ? void 0 : _a2.signal);
1886
1892
  this.telemetry.requestCount++;
@@ -1897,7 +1903,13 @@ var init_http_file_transport = __esm({
1897
1903
  await cancelResponse(response);
1898
1904
  throw new Error(`HTTP byte-range request expected 206, received ${response.status}`);
1899
1905
  }
1900
- const contentRange = await readContentRange(response);
1906
+ const contentRange = response.headers.has("Content-Range") ? await readContentRange(response) : await this.inferContentRange(
1907
+ response,
1908
+ offset,
1909
+ length,
1910
+ expectedIdentity,
1911
+ abortContext.signal
1912
+ );
1901
1913
  const responseIdentity = getResponseIdentity(response, contentRange.byteLength);
1902
1914
  const responseError = getIdentityError(
1903
1915
  expectedIdentity,
@@ -1931,6 +1943,45 @@ var init_http_file_transport = __esm({
1931
1943
  } finally {
1932
1944
  abortContext.removeAbortListeners();
1933
1945
  this.telemetry.networkTimeMs += getTimestamp2() - requestStartTime;
1946
+ (_b = this.onTelemetry) == null ? void 0 : _b.call(this, this.getTelemetry());
1947
+ }
1948
+ }
1949
+ /** Infers bounds for a CORS-filtered 206; the caller still validates the body length. */
1950
+ async inferContentRange(response, offset, length, expectedIdentity, signal) {
1951
+ var _a2;
1952
+ try {
1953
+ let byteLength = (expectedIdentity == null ? void 0 : expectedIdentity.byteLength) ?? this.identityHints.byteLength;
1954
+ if (byteLength === void 0) {
1955
+ const headers = new Headers((_a2 = this.fetchOptions) == null ? void 0 : _a2.headers);
1956
+ headers.delete("Range");
1957
+ this.telemetry.requestCount++;
1958
+ const metadata = await this.fetchFunction(this.url, {
1959
+ ...this.fetchOptions,
1960
+ method: "HEAD",
1961
+ body: void 0,
1962
+ headers,
1963
+ signal
1964
+ });
1965
+ await cancelResponse(metadata);
1966
+ const value = metadata.headers.get("Content-Length");
1967
+ byteLength = value && /^\d+$/.test(value) ? Number(value) : NaN;
1968
+ if (metadata.status !== 200 || !Number.isSafeInteger(byteLength) || byteLength < offset + length) {
1969
+ throw new Error(
1970
+ "HTTP byte-range response is missing Content-Range and HEAD did not provide a valid file length"
1971
+ );
1972
+ }
1973
+ const identityError = getIdentityError(
1974
+ getResponseIdentity(metadata, byteLength),
1975
+ getResponseIdentity(response, byteLength),
1976
+ this.identityHints,
1977
+ this.consistency
1978
+ );
1979
+ if (identityError) throw new Error(identityError);
1980
+ }
1981
+ return { offset, endOffset: offset + length - 1, byteLength };
1982
+ } catch (error) {
1983
+ await cancelResponse(response);
1984
+ throw error;
1934
1985
  }
1935
1986
  }
1936
1987
  /** Validates and consumes the special empty-object identity response. */
@@ -2180,7 +2231,7 @@ function getSourceLoaderOptions(options) {
2180
2231
  if (options == null ? void 0 : options.core) {
2181
2232
  loadOptions.core = { ...options.core };
2182
2233
  const parserCore = loadOptions.core;
2183
- for (const key of ["type", "attributions", "loaders", "onError", "loadOptions"]) {
2234
+ for (const key of ["type", "name", "attributions", "loaders", "onError", "loadOptions"]) {
2184
2235
  delete parserCore[key];
2185
2236
  }
2186
2237
  if (Object.keys(parserCore).length === 0) {
@@ -2215,6 +2266,44 @@ function unavailableCoreApiMethod(methodName) {
2215
2266
  );
2216
2267
  };
2217
2268
  }
2269
+ function getDataSourceName(data, options) {
2270
+ var _a2, _b, _c;
2271
+ const explicitName = (_a2 = options.core) == null ? void 0 : _a2.name;
2272
+ if (explicitName !== void 0) {
2273
+ if (typeof explicitName !== "string" || !explicitName.trim())
2274
+ throw new Error("Data source name must be a non-empty string.");
2275
+ return explicitName;
2276
+ }
2277
+ if (data && typeof data === "object") {
2278
+ const named = data;
2279
+ if (typeof named.name === "string" && named.name.trim())
2280
+ return data instanceof Blob ? removeFileExtension(named.name) : named.name;
2281
+ const metadata = (_b = named.schema) == null ? void 0 : _b.metadata;
2282
+ const embeddedName = metadata instanceof Map ? metadata.get("name") : metadata == null ? void 0 : metadata.name;
2283
+ if (typeof embeddedName === "string" && embeddedName.trim()) return embeddedName;
2284
+ }
2285
+ if (typeof data === "string") {
2286
+ try {
2287
+ const url = new URL(data.replace(/\\/g, "/"), "https://source.invalid/");
2288
+ if (!["data:", "blob:"].includes(url.protocol)) {
2289
+ let basename = url.pathname.split("/").filter(Boolean).pop();
2290
+ if (basename) {
2291
+ try {
2292
+ basename = decodeURIComponent(basename);
2293
+ } catch {
2294
+ }
2295
+ return removeFileExtension(basename);
2296
+ }
2297
+ }
2298
+ } catch {
2299
+ }
2300
+ }
2301
+ return ((_c = options.core) == null ? void 0 : _c.type) && options.core.type !== "auto" ? options.core.type : "source";
2302
+ }
2303
+ function removeFileExtension(name) {
2304
+ const extension = name.lastIndexOf(".");
2305
+ return extension > 0 ? name.slice(0, extension) : name;
2306
+ }
2218
2307
  var UNAVAILABLE_CORE_API, DataSource;
2219
2308
  var init_data_source = __esm({
2220
2309
  "../core/src/loader-utils/lib/sources/data-source.ts"() {
@@ -2246,6 +2335,8 @@ var init_data_source = __esm({
2246
2335
  options;
2247
2336
  data;
2248
2337
  url;
2338
+ /** Stable query-visible name, resolved without fetching source data. */
2339
+ name;
2249
2340
  /** Shared parser options derived from the source options, excluding source-only core controls. */
2250
2341
  loadOptions;
2251
2342
  /** A resolved fetch function extracted from the shared core options. */
@@ -2262,6 +2353,7 @@ var init_data_source = __esm({
2262
2353
  );
2263
2354
  this.data = data;
2264
2355
  this.url = typeof data === "string" ? resolvePath(data) : "";
2356
+ this.name = getDataSourceName(data, this.options);
2265
2357
  const loadOptions = resolveAuthenticationOptions(getSourceLoaderOptions(this.options));
2266
2358
  this.loadOptions = loadOptions;
2267
2359
  const fetch2 = getFetchFunction(loadOptions);
@@ -2270,6 +2362,9 @@ var init_data_source = __esm({
2270
2362
  this.fetch = fetch2;
2271
2363
  }
2272
2364
  setProps(options) {
2365
+ var _a2;
2366
+ if (((_a2 = options.core) == null ? void 0 : _a2.name) !== void 0 && options.core.name !== this.name)
2367
+ throw new Error("Data source names are fixed at creation.");
2273
2368
  const mergedOptions = mergeOptions(this.options, options);
2274
2369
  const loadOptions = resolveAuthenticationOptions(getSourceLoaderOptions(mergedOptions));
2275
2370
  this.options = mergedOptions;