@vitessce/zarr 3.6.13 → 3.6.15

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 (2) hide show
  1. package/dist/index.js +273 -230
  2. package/package.json +12 -12
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
6
6
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
7
  var __privateSet = (obj, member, value, setter2) => (__accessCheck(obj, member, "write to private field"), setter2 ? setter2.call(obj, value) : member.set(obj, value), value);
8
8
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
- var _bytes, _encoder, _data, _stride, _TypedArray, _BYTES_PER_ELEMENT, _shape, _endian, _encoder_config, _decoder_config, _order, _inverseOrder, _shape2, _strides, _metadata, _metadata2, _a2, _overrides, _use_suffix_request, _FetchStore_instances, merge_init_fn, _overrides2, _refs, _opts, _overrides3;
9
+ var _overrides, _use_suffix_request, _FetchStore_instances, merge_init_fn, _bytes, _encoder, _data, _stride, _TypedArray, _BYTES_PER_ELEMENT, _shape, _endian, _encoder_config, _decoder_config, _order, _inverseOrder, _shape2, _strides, _metadata, _metadata2, _a2, _overrides2, _refs, _opts, _overrides3;
10
10
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
11
11
  function getDefaultExportFromCjs(x) {
12
12
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
@@ -290,18 +290,113 @@ function requireLoglevel() {
290
290
  }
291
291
  var loglevelExports = requireLoglevel();
292
292
  const log = /* @__PURE__ */ getDefaultExportFromCjs(loglevelExports);
293
- class NodeNotFoundError extends Error {
294
- constructor(context, options = {}) {
295
- super(`Node not found: ${context}`, options);
296
- this.name = "NodeNotFoundError";
293
+ function strip_prefix(path) {
294
+ return path.slice(1);
295
+ }
296
+ function uri2href(url) {
297
+ let [protocol, rest] = (typeof url === "string" ? url : url.href).split("://");
298
+ if (protocol === "https" || protocol === "http") {
299
+ return url;
300
+ }
301
+ if (protocol === "gc") {
302
+ return `https://storage.googleapis.com/${rest}`;
303
+ }
304
+ if (protocol === "s3") {
305
+ return `https://s3.amazonaws.com/${rest}`;
297
306
  }
307
+ throw Error(`Protocol not supported, got: ${JSON.stringify(protocol)}`);
298
308
  }
299
- class KeyError extends Error {
300
- constructor(path) {
301
- super(`Missing key: ${path}`);
302
- this.name = "KeyError";
309
+ function fetch_range(url, offset, length, opts = {}) {
310
+ if (offset !== void 0 && length !== void 0) {
311
+ opts = {
312
+ ...opts,
313
+ headers: {
314
+ ...opts.headers,
315
+ Range: `bytes=${offset}-${offset + length - 1}`
316
+ }
317
+ };
318
+ }
319
+ return fetch(url, opts);
320
+ }
321
+ function merge_init(storeOverrides, requestOverrides) {
322
+ return {
323
+ ...storeOverrides,
324
+ ...requestOverrides,
325
+ headers: {
326
+ ...storeOverrides.headers,
327
+ ...requestOverrides.headers
328
+ }
329
+ };
330
+ }
331
+ function assert$1(expression, msg = "") {
332
+ if (!expression)
333
+ throw new Error(msg);
334
+ }
335
+ function resolve(root2, path) {
336
+ const base = typeof root2 === "string" ? new URL(root2) : root2;
337
+ if (!base.pathname.endsWith("/")) {
338
+ base.pathname += "/";
339
+ }
340
+ const resolved = new URL(path.slice(1), base);
341
+ resolved.search = base.search;
342
+ return resolved;
343
+ }
344
+ async function handle_response(response) {
345
+ if (response.status === 404) {
346
+ return void 0;
347
+ }
348
+ if (response.status === 200 || response.status === 206) {
349
+ return new Uint8Array(await response.arrayBuffer());
350
+ }
351
+ throw new Error(`Unexpected response status ${response.status} ${response.statusText}`);
352
+ }
353
+ async function fetch_suffix(url, suffix_length, init, use_suffix_request) {
354
+ if (use_suffix_request) {
355
+ return fetch(url, {
356
+ ...init,
357
+ headers: { ...init.headers, Range: `bytes=-${suffix_length}` }
358
+ });
359
+ }
360
+ let response = await fetch(url, { ...init, method: "HEAD" });
361
+ if (!response.ok) {
362
+ return response;
363
+ }
364
+ let content_length = response.headers.get("Content-Length");
365
+ let length = Number(content_length);
366
+ return fetch_range(url, length - suffix_length, length, init);
367
+ }
368
+ class FetchStore {
369
+ constructor(url, options = {}) {
370
+ __privateAdd(this, _FetchStore_instances);
371
+ __privateAdd(this, _overrides);
372
+ __privateAdd(this, _use_suffix_request);
373
+ this.url = url;
374
+ __privateSet(this, _overrides, options.overrides ?? {});
375
+ __privateSet(this, _use_suffix_request, options.useSuffixRequest ?? false);
376
+ }
377
+ async get(key, options = {}) {
378
+ let href = resolve(this.url, key).href;
379
+ let response = await fetch(href, __privateMethod(this, _FetchStore_instances, merge_init_fn).call(this, options));
380
+ return handle_response(response);
381
+ }
382
+ async getRange(key, range2, options = {}) {
383
+ let url = resolve(this.url, key);
384
+ let init = __privateMethod(this, _FetchStore_instances, merge_init_fn).call(this, options);
385
+ let response;
386
+ if ("suffixLength" in range2) {
387
+ response = await fetch_suffix(url, range2.suffixLength, init, __privateGet(this, _use_suffix_request));
388
+ } else {
389
+ response = await fetch_range(url, range2.offset, range2.length, init);
390
+ }
391
+ return handle_response(response);
303
392
  }
304
393
  }
394
+ _overrides = new WeakMap();
395
+ _use_suffix_request = new WeakMap();
396
+ _FetchStore_instances = new WeakSet();
397
+ merge_init_fn = function(overrides) {
398
+ return merge_init(__privateGet(this, _overrides), overrides);
399
+ };
305
400
  class BoolArray {
306
401
  constructor(x, byteOffset, length) {
307
402
  __privateAdd(this, _bytes);
@@ -507,7 +602,7 @@ function get_ctr(data_type) {
507
602
  float64: Float64Array,
508
603
  bool: BoolArray
509
604
  }[data_type];
510
- assert$1(ctr, `Unknown or unsupported data_type: ${data_type}`);
605
+ assert(ctr, `Unknown or unsupported data_type: ${data_type}`);
511
606
  return ctr;
512
607
  }
513
608
  function get_strides(shape, order) {
@@ -515,7 +610,7 @@ function get_strides(shape, order) {
515
610
  if (typeof order === "string") {
516
611
  order = order === "C" ? Array.from({ length: rank }, (_, i) => i) : Array.from({ length: rank }, (_, i) => rank - 1 - i);
517
612
  }
518
- assert$1(rank === order.length, "Order length must match the number of dimensions.");
613
+ assert(rank === order.length, "Order length must match the number of dimensions.");
519
614
  let step = 1;
520
615
  let stride = new Array(rank);
521
616
  for (let i = order.length - 1; i >= 0; i--) {
@@ -540,7 +635,7 @@ function coerce_dtype(dtype) {
540
635
  return { data_type: "v2:object" };
541
636
  }
542
637
  let match = dtype.match(/^([<|>])(.*)$/);
543
- assert$1(match, `Invalid dtype: ${dtype}`);
638
+ assert(match, `Invalid dtype: ${dtype}`);
544
639
  let [, endian, rest] = match;
545
640
  let data_type = {
546
641
  b1: "bool",
@@ -556,7 +651,7 @@ function coerce_dtype(dtype) {
556
651
  f4: "float32",
557
652
  f8: "float64"
558
653
  }[rest] ?? (rest.startsWith("S") || rest.startsWith("U") ? `v2:${rest}` : void 0);
559
- assert$1(data_type, `Unsupported or unknown dtype: ${dtype}`);
654
+ assert(data_type, `Unsupported or unknown dtype: ${dtype}`);
560
655
  if (endian === "|") {
561
656
  return { data_type };
562
657
  }
@@ -639,14 +734,14 @@ function rethrow_unless(error, ...errors) {
639
734
  throw error;
640
735
  }
641
736
  }
642
- function assert$1(expression, msg = "") {
737
+ function assert(expression, msg = "") {
643
738
  if (!expression) {
644
739
  throw new Error(msg);
645
740
  }
646
741
  }
647
742
  async function decompress(data, { format, signal }) {
648
743
  const response = data instanceof Response ? data : new Response(data);
649
- assert$1(response.body, "Response does not contain body.");
744
+ assert(response.body, "Response does not contain body.");
650
745
  try {
651
746
  const decompressedResponse = new Response(response.body.pipeThrough(new DecompressionStream(format), { signal }));
652
747
  const buffer = await decompressedResponse.arrayBuffer();
@@ -659,7 +754,7 @@ async function decompress(data, { format, signal }) {
659
754
  class BitroundCodec {
660
755
  constructor(configuration, _meta) {
661
756
  this.kind = "array_to_array";
662
- assert$1(configuration.keepbits >= 0, "keepbits must be zero or positive");
757
+ assert(configuration.keepbits >= 0, "keepbits must be zero or positive");
663
758
  }
664
759
  static fromConfig(configuration, meta) {
665
760
  return new BitroundCodec(configuration, meta);
@@ -764,9 +859,9 @@ class GzipCodec {
764
859
  }
765
860
  }
766
861
  function throw_on_nan_replacer(_key, value) {
767
- assert$1(!Number.isNaN(value), "JsonCodec allow_nan is false but NaN was encountered during encoding.");
768
- assert$1(value !== Number.POSITIVE_INFINITY, "JsonCodec allow_nan is false but Infinity was encountered during encoding.");
769
- assert$1(value !== Number.NEGATIVE_INFINITY, "JsonCodec allow_nan is false but -Infinity was encountered during encoding.");
862
+ assert(!Number.isNaN(value), "JsonCodec allow_nan is false but NaN was encountered during encoding.");
863
+ assert(value !== Number.POSITIVE_INFINITY, "JsonCodec allow_nan is false but Infinity was encountered during encoding.");
864
+ assert(value !== Number.NEGATIVE_INFINITY, "JsonCodec allow_nan is false but -Infinity was encountered during encoding.");
770
865
  return value;
771
866
  }
772
867
  function sort_keys_replacer(_key, value) {
@@ -807,9 +902,9 @@ const _JsonCodec = class _JsonCodec {
807
902
  }
808
903
  encode(buf) {
809
904
  const { indent, encoding, ensure_ascii, check_circular, allow_nan, sort_keys } = __privateGet(this, _encoder_config);
810
- assert$1(encoding === "utf-8", "JsonCodec does not yet support non-utf-8 encoding.");
905
+ assert(encoding === "utf-8", "JsonCodec does not yet support non-utf-8 encoding.");
811
906
  const replacer_functions = [];
812
- assert$1(check_circular, "JsonCodec does not yet support skipping the check for circular references during encoding.");
907
+ assert(check_circular, "JsonCodec does not yet support skipping the check for circular references during encoding.");
813
908
  if (!allow_nan) {
814
909
  replacer_functions.push(throw_on_nan_replacer);
815
910
  }
@@ -819,7 +914,7 @@ const _JsonCodec = class _JsonCodec {
819
914
  const items = Array.from(buf.data);
820
915
  items.push("|O");
821
916
  items.push(buf.shape);
822
- let replacer = void 0;
917
+ let replacer;
823
918
  if (replacer_functions.length) {
824
919
  replacer = (key, value) => {
825
920
  let new_value = value;
@@ -841,11 +936,11 @@ const _JsonCodec = class _JsonCodec {
841
936
  }
842
937
  decode(bytes) {
843
938
  const { strict } = __privateGet(this, _decoder_config);
844
- assert$1(strict, "JsonCodec does not yet support non-strict decoding.");
939
+ assert(strict, "JsonCodec does not yet support non-strict decoding.");
845
940
  const items = json_decode_object(bytes);
846
941
  const shape = items.pop();
847
942
  items.pop();
848
- assert$1(shape, "0D not implemented for JsonCodec.");
943
+ assert(shape, "0D not implemented for JsonCodec.");
849
944
  const stride = get_strides(shape, "C");
850
945
  const data = items;
851
946
  return { data, shape, stride };
@@ -914,12 +1009,12 @@ function convert_array_order(src, target) {
914
1009
  }
915
1010
  function get_order(chunk) {
916
1011
  let rank = chunk.shape.length;
917
- assert$1(rank === chunk.stride.length, "Shape and stride must have the same length.");
1012
+ assert(rank === chunk.stride.length, "Shape and stride must have the same length.");
918
1013
  return chunk.stride.map((s, i) => ({ stride: s, index: i })).sort((a, b) => b.stride - a.stride).map((entry) => entry.index);
919
1014
  }
920
1015
  function matches_order(chunk, target) {
921
1016
  let source = get_order(chunk);
922
- assert$1(source.length === target.length, "Orders must match");
1017
+ assert(source.length === target.length, "Orders must match");
923
1018
  return source.every((dim, i) => dim === target[i]);
924
1019
  }
925
1020
  const _TransposeCodec = class _TransposeCodec {
@@ -944,7 +1039,7 @@ const _TransposeCodec = class _TransposeCodec {
944
1039
  } else {
945
1040
  order = value;
946
1041
  order.forEach((x, i) => {
947
- assert$1(inverseOrder[x] === void 0, `Invalid permutation: ${JSON.stringify(value)}`);
1042
+ assert(inverseOrder[x] === void 0, `Invalid permutation: ${JSON.stringify(value)}`);
948
1043
  inverseOrder[x] = i;
949
1044
  });
950
1045
  }
@@ -1054,7 +1149,7 @@ async function load_codecs(chunk_meta) {
1054
1149
  let promises = chunk_meta.codecs.map(async (meta) => {
1055
1150
  var _a3;
1056
1151
  let Codec = await ((_a3 = registry.get(meta.name)) == null ? void 0 : _a3());
1057
- assert$1(Codec, `Unknown codec: ${meta.name}`);
1152
+ assert(Codec, `Unknown codec: ${meta.name}`);
1058
1153
  return { Codec, meta };
1059
1154
  });
1060
1155
  let array_to_array = [];
@@ -1074,7 +1169,7 @@ async function load_codecs(chunk_meta) {
1074
1169
  }
1075
1170
  }
1076
1171
  if (!array_to_bytes) {
1077
- assert$1(is_typed_array_like_meta(chunk_meta), `Cannot encode ${chunk_meta.data_type} to bytes without a codec`);
1172
+ assert(is_typed_array_like_meta(chunk_meta), `Cannot encode ${chunk_meta.data_type} to bytes without a codec`);
1078
1173
  array_to_bytes = BytesCodec.fromConfig({ endian: "little" }, chunk_meta);
1079
1174
  }
1080
1175
  return { array_to_array, array_to_bytes, bytes_to_bytes };
@@ -1082,9 +1177,21 @@ async function load_codecs(chunk_meta) {
1082
1177
  function is_typed_array_like_meta(meta) {
1083
1178
  return meta.data_type !== "v2:object";
1084
1179
  }
1180
+ class NodeNotFoundError extends Error {
1181
+ constructor(context, options = {}) {
1182
+ super(`Node not found: ${context}`, options);
1183
+ this.name = "NodeNotFoundError";
1184
+ }
1185
+ }
1186
+ class KeyError extends Error {
1187
+ constructor(path) {
1188
+ super(`Missing key: ${path}`);
1189
+ this.name = "KeyError";
1190
+ }
1191
+ }
1085
1192
  const MAX_BIG_UINT = 18446744073709551615n;
1086
1193
  function create_sharded_chunk_getter(location, shard_shape, encode_shard_key, sharding_config) {
1087
- assert$1(location.store.getRange, "Store does not support range requests");
1194
+ assert(location.store.getRange, "Store does not support range requests");
1088
1195
  let get_range = location.store.getRange.bind(location.store);
1089
1196
  let index_shape = shard_shape.map((d, i) => d / sharding_config.chunk_shape[i]);
1090
1197
  let index_codec = create_codec_pipeline({
@@ -1261,105 +1368,6 @@ let Array$1 = (_a2 = class extends (_a = Location, _a) {
1261
1368
  return is_dtype(this.dtype, query);
1262
1369
  }
1263
1370
  }, _metadata2 = new WeakMap(), _a2);
1264
- let VERSION_COUNTER = create_version_counter();
1265
- function create_version_counter() {
1266
- let version_counts = /* @__PURE__ */ new WeakMap();
1267
- function get_counts(store) {
1268
- let counts = version_counts.get(store) ?? { v2: 0, v3: 0 };
1269
- version_counts.set(store, counts);
1270
- return counts;
1271
- }
1272
- return {
1273
- increment(store, version) {
1274
- get_counts(store)[version] += 1;
1275
- },
1276
- version_max(store) {
1277
- let counts = get_counts(store);
1278
- return counts.v3 > counts.v2 ? "v3" : "v2";
1279
- }
1280
- };
1281
- }
1282
- async function load_attrs(location) {
1283
- let meta_bytes = await location.store.get(location.resolve(".zattrs").path);
1284
- if (!meta_bytes)
1285
- return {};
1286
- return json_decode_object(meta_bytes);
1287
- }
1288
- async function open_v2(location, options = {}) {
1289
- let loc = "store" in location ? location : new Location(location);
1290
- let attrs = {};
1291
- if (options.attrs ?? true)
1292
- attrs = await load_attrs(loc);
1293
- if (options.kind === "array")
1294
- return open_array_v2(loc, attrs);
1295
- if (options.kind === "group")
1296
- return open_group_v2(loc, attrs);
1297
- return open_array_v2(loc, attrs).catch((err) => {
1298
- rethrow_unless(err, NodeNotFoundError);
1299
- return open_group_v2(loc, attrs);
1300
- });
1301
- }
1302
- async function open_array_v2(location, attrs) {
1303
- let { path } = location.resolve(".zarray");
1304
- let meta = await location.store.get(path);
1305
- if (!meta) {
1306
- throw new NodeNotFoundError("v2 array", {
1307
- cause: new KeyError(path)
1308
- });
1309
- }
1310
- VERSION_COUNTER.increment(location.store, "v2");
1311
- return new Array$1(location.store, location.path, v2_to_v3_array_metadata(json_decode_object(meta), attrs));
1312
- }
1313
- async function open_group_v2(location, attrs) {
1314
- let { path } = location.resolve(".zgroup");
1315
- let meta = await location.store.get(path);
1316
- if (!meta) {
1317
- throw new NodeNotFoundError("v2 group", {
1318
- cause: new KeyError(path)
1319
- });
1320
- }
1321
- VERSION_COUNTER.increment(location.store, "v2");
1322
- return new Group(location.store, location.path, v2_to_v3_group_metadata(json_decode_object(meta), attrs));
1323
- }
1324
- async function _open_v3(location) {
1325
- let { store, path } = location.resolve("zarr.json");
1326
- let meta = await location.store.get(path);
1327
- if (!meta) {
1328
- throw new NodeNotFoundError("v3 array or group", {
1329
- cause: new KeyError(path)
1330
- });
1331
- }
1332
- let meta_doc = json_decode_object(meta);
1333
- if (meta_doc.node_type === "array") {
1334
- meta_doc.fill_value = ensure_correct_scalar(meta_doc);
1335
- }
1336
- return meta_doc.node_type === "array" ? new Array$1(store, location.path, meta_doc) : new Group(store, location.path, meta_doc);
1337
- }
1338
- async function open_v3(location, options = {}) {
1339
- let loc = "store" in location ? location : new Location(location);
1340
- let node = await _open_v3(loc);
1341
- VERSION_COUNTER.increment(loc.store, "v3");
1342
- if (options.kind === void 0)
1343
- return node;
1344
- if (options.kind === "array" && node instanceof Array$1)
1345
- return node;
1346
- if (options.kind === "group" && node instanceof Group)
1347
- return node;
1348
- let kind = node instanceof Array$1 ? "array" : "group";
1349
- throw new Error(`Expected node of kind ${options.kind}, found ${kind}.`);
1350
- }
1351
- async function open(location, options = {}) {
1352
- let store = "store" in location ? location.store : location;
1353
- let version_max = VERSION_COUNTER.version_max(store);
1354
- let open_primary = version_max === "v2" ? open.v2 : open.v3;
1355
- let open_secondary = version_max === "v2" ? open.v3 : open.v2;
1356
- return open_primary(location, options).catch((err) => {
1357
- rethrow_unless(err, NodeNotFoundError);
1358
- return open_secondary(location, options);
1359
- });
1360
- }
1361
- open.v2 = open_v2;
1362
- open.v3 = open_v3;
1363
1371
  function* range$3(start, stop, step = 1) {
1364
1372
  if (stop === void 0) {
1365
1373
  stop = start;
@@ -1740,113 +1748,105 @@ function set_from_chunk_binary(dest, src, bytes_per_element2, projections) {
1740
1748
  }, bytes_per_element2, projs);
1741
1749
  }
1742
1750
  }
1743
- function strip_prefix(path) {
1744
- return path.slice(1);
1745
- }
1746
- function uri2href(url) {
1747
- let [protocol, rest] = (typeof url === "string" ? url : url.href).split("://");
1748
- if (protocol === "https" || protocol === "http") {
1749
- return url;
1750
- }
1751
- if (protocol === "gc") {
1752
- return `https://storage.googleapis.com/${rest}`;
1753
- }
1754
- if (protocol === "s3") {
1755
- return `https://s3.amazonaws.com/${rest}`;
1756
- }
1757
- throw Error(`Protocol not supported, got: ${JSON.stringify(protocol)}`);
1758
- }
1759
- function fetch_range(url, offset, length, opts = {}) {
1760
- if (offset !== void 0 && length !== void 0) {
1761
- opts = {
1762
- ...opts,
1763
- headers: {
1764
- ...opts.headers,
1765
- Range: `bytes=${offset}-${offset + length - 1}`
1766
- }
1767
- };
1751
+ let VERSION_COUNTER = create_version_counter();
1752
+ function create_version_counter() {
1753
+ let version_counts = /* @__PURE__ */ new WeakMap();
1754
+ function get_counts(store) {
1755
+ let counts = version_counts.get(store) ?? { v2: 0, v3: 0 };
1756
+ version_counts.set(store, counts);
1757
+ return counts;
1768
1758
  }
1769
- return fetch(url, opts);
1770
- }
1771
- function merge_init(storeOverrides, requestOverrides) {
1772
1759
  return {
1773
- ...storeOverrides,
1774
- ...requestOverrides,
1775
- headers: {
1776
- ...storeOverrides.headers,
1777
- ...requestOverrides.headers
1760
+ increment(store, version) {
1761
+ get_counts(store)[version] += 1;
1762
+ },
1763
+ version_max(store) {
1764
+ let counts = get_counts(store);
1765
+ return counts.v3 > counts.v2 ? "v3" : "v2";
1778
1766
  }
1779
1767
  };
1780
1768
  }
1781
- function assert(expression, msg = "") {
1782
- if (!expression)
1783
- throw new Error(msg);
1769
+ async function load_attrs(location) {
1770
+ let meta_bytes = await location.store.get(location.resolve(".zattrs").path);
1771
+ if (!meta_bytes)
1772
+ return {};
1773
+ return json_decode_object(meta_bytes);
1784
1774
  }
1785
- function resolve(root2, path) {
1786
- const base = typeof root2 === "string" ? new URL(root2) : root2;
1787
- if (!base.pathname.endsWith("/")) {
1788
- base.pathname += "/";
1789
- }
1790
- const resolved = new URL(path.slice(1), base);
1791
- resolved.search = base.search;
1792
- return resolved;
1775
+ async function open_v2(location, options = {}) {
1776
+ let loc = "store" in location ? location : new Location(location);
1777
+ let attrs = {};
1778
+ if (options.attrs ?? true)
1779
+ attrs = await load_attrs(loc);
1780
+ if (options.kind === "array")
1781
+ return open_array_v2(loc, attrs);
1782
+ if (options.kind === "group")
1783
+ return open_group_v2(loc, attrs);
1784
+ return open_array_v2(loc, attrs).catch((err) => {
1785
+ rethrow_unless(err, NodeNotFoundError);
1786
+ return open_group_v2(loc, attrs);
1787
+ });
1793
1788
  }
1794
- async function handle_response(response) {
1795
- if (response.status === 404) {
1796
- return void 0;
1797
- }
1798
- if (response.status === 200 || response.status === 206) {
1799
- return new Uint8Array(await response.arrayBuffer());
1789
+ async function open_array_v2(location, attrs) {
1790
+ let { path } = location.resolve(".zarray");
1791
+ let meta = await location.store.get(path);
1792
+ if (!meta) {
1793
+ throw new NodeNotFoundError("v2 array", {
1794
+ cause: new KeyError(path)
1795
+ });
1800
1796
  }
1801
- throw new Error(`Unexpected response status ${response.status} ${response.statusText}`);
1797
+ VERSION_COUNTER.increment(location.store, "v2");
1798
+ return new Array$1(location.store, location.path, v2_to_v3_array_metadata(json_decode_object(meta), attrs));
1802
1799
  }
1803
- async function fetch_suffix(url, suffix_length, init, use_suffix_request) {
1804
- if (use_suffix_request) {
1805
- return fetch(url, {
1806
- ...init,
1807
- headers: { ...init.headers, Range: `bytes=-${suffix_length}` }
1800
+ async function open_group_v2(location, attrs) {
1801
+ let { path } = location.resolve(".zgroup");
1802
+ let meta = await location.store.get(path);
1803
+ if (!meta) {
1804
+ throw new NodeNotFoundError("v2 group", {
1805
+ cause: new KeyError(path)
1808
1806
  });
1809
1807
  }
1810
- let response = await fetch(url, { ...init, method: "HEAD" });
1811
- if (!response.ok) {
1812
- return response;
1813
- }
1814
- let content_length = response.headers.get("Content-Length");
1815
- let length = Number(content_length);
1816
- return fetch_range(url, length - suffix_length, length, init);
1808
+ VERSION_COUNTER.increment(location.store, "v2");
1809
+ return new Group(location.store, location.path, v2_to_v3_group_metadata(json_decode_object(meta), attrs));
1817
1810
  }
1818
- class FetchStore {
1819
- constructor(url, options = {}) {
1820
- __privateAdd(this, _FetchStore_instances);
1821
- __privateAdd(this, _overrides);
1822
- __privateAdd(this, _use_suffix_request);
1823
- this.url = url;
1824
- __privateSet(this, _overrides, options.overrides ?? {});
1825
- __privateSet(this, _use_suffix_request, options.useSuffixRequest ?? false);
1826
- }
1827
- async get(key, options = {}) {
1828
- let href = resolve(this.url, key).href;
1829
- let response = await fetch(href, __privateMethod(this, _FetchStore_instances, merge_init_fn).call(this, options));
1830
- return handle_response(response);
1811
+ async function _open_v3(location) {
1812
+ let { store, path } = location.resolve("zarr.json");
1813
+ let meta = await location.store.get(path);
1814
+ if (!meta) {
1815
+ throw new NodeNotFoundError("v3 array or group", {
1816
+ cause: new KeyError(path)
1817
+ });
1831
1818
  }
1832
- async getRange(key, range2, options = {}) {
1833
- let url = resolve(this.url, key);
1834
- let init = __privateMethod(this, _FetchStore_instances, merge_init_fn).call(this, options);
1835
- let response;
1836
- if ("suffixLength" in range2) {
1837
- response = await fetch_suffix(url, range2.suffixLength, init, __privateGet(this, _use_suffix_request));
1838
- } else {
1839
- response = await fetch_range(url, range2.offset, range2.length, init);
1840
- }
1841
- return handle_response(response);
1819
+ let meta_doc = json_decode_object(meta);
1820
+ if (meta_doc.node_type === "array") {
1821
+ meta_doc.fill_value = ensure_correct_scalar(meta_doc);
1842
1822
  }
1823
+ return meta_doc.node_type === "array" ? new Array$1(store, location.path, meta_doc) : new Group(store, location.path, meta_doc);
1843
1824
  }
1844
- _overrides = new WeakMap();
1845
- _use_suffix_request = new WeakMap();
1846
- _FetchStore_instances = new WeakSet();
1847
- merge_init_fn = function(overrides) {
1848
- return merge_init(__privateGet(this, _overrides), overrides);
1849
- };
1825
+ async function open_v3(location, options = {}) {
1826
+ let loc = "store" in location ? location : new Location(location);
1827
+ let node = await _open_v3(loc);
1828
+ VERSION_COUNTER.increment(loc.store, "v3");
1829
+ if (options.kind === void 0)
1830
+ return node;
1831
+ if (options.kind === "array" && node instanceof Array$1)
1832
+ return node;
1833
+ if (options.kind === "group" && node instanceof Group)
1834
+ return node;
1835
+ let kind = node instanceof Array$1 ? "array" : "group";
1836
+ throw new Error(`Expected node of kind ${options.kind}, found ${kind}.`);
1837
+ }
1838
+ async function open(location, options = {}) {
1839
+ let store = "store" in location ? location.store : location;
1840
+ let version_max = VERSION_COUNTER.version_max(store);
1841
+ let open_primary = version_max === "v2" ? open.v2 : open.v3;
1842
+ let open_secondary = version_max === "v2" ? open.v3 : open.v2;
1843
+ return open_primary(location, options).catch((err) => {
1844
+ rethrow_unless(err, NodeNotFoundError);
1845
+ return open_secondary(location, options);
1846
+ });
1847
+ }
1848
+ open.v2 = open_v2;
1849
+ open.v3 = open_v3;
1850
1850
  function getV2DataType(dtype) {
1851
1851
  const mapping = {
1852
1852
  int8: "|i1",
@@ -2699,7 +2699,7 @@ class HTTPRangeReader {
2699
2699
  ...__privateGet(this, _overrides2),
2700
2700
  method: "HEAD"
2701
2701
  });
2702
- assert(req.ok, `failed http request ${this.url}, status: ${req.status}: ${req.statusText}`);
2702
+ assert$1(req.ok, `failed http request ${this.url}, status: ${req.status}: ${req.statusText}`);
2703
2703
  this.length = Number(req.headers.get("content-length"));
2704
2704
  if (Number.isNaN(this.length)) {
2705
2705
  throw Error("could not get length");
@@ -2712,14 +2712,19 @@ class HTTPRangeReader {
2712
2712
  return new Uint8Array(0);
2713
2713
  }
2714
2714
  const req = await fetch_range(this.url, offset, size, __privateGet(this, _overrides2));
2715
- assert(req.ok, `failed http request ${this.url}, status: ${req.status} offset: ${offset} size: ${size}: ${req.statusText}`);
2715
+ assert$1(req.ok, `failed http request ${this.url}, status: ${req.status} offset: ${offset} size: ${size}: ${req.statusText}`);
2716
2716
  return new Uint8Array(await req.arrayBuffer());
2717
2717
  }
2718
2718
  }
2719
2719
  _overrides2 = new WeakMap();
2720
2720
  class ZipFileStore {
2721
- constructor(reader) {
2722
- this.info = unzip(reader);
2721
+ constructor(reader, opts = {}) {
2722
+ this.info = unzip(reader).then((info) => {
2723
+ if (opts.transformEntries) {
2724
+ info.entries = opts.transformEntries(info.entries);
2725
+ }
2726
+ return info;
2727
+ });
2723
2728
  }
2724
2729
  async get(key) {
2725
2730
  let entry = (await this.info).entries[strip_prefix(key)];
@@ -2731,10 +2736,10 @@ class ZipFileStore {
2731
2736
  return strip_prefix(key) in (await this.info).entries;
2732
2737
  }
2733
2738
  static fromUrl(href, opts = {}) {
2734
- return new ZipFileStore(new HTTPRangeReader(href, opts));
2739
+ return new ZipFileStore(new HTTPRangeReader(href, opts), opts);
2735
2740
  }
2736
- static fromBlob(blob) {
2737
- return new ZipFileStore(new BlobReader2(blob));
2741
+ static fromBlob(blob, opts = {}) {
2742
+ return new ZipFileStore(new BlobReader2(blob), opts);
2738
2743
  }
2739
2744
  }
2740
2745
  function parse$1(template, re2 = /{{(.*?)}}/) {
@@ -3015,10 +3020,31 @@ class RelaxedFetchStore extends FetchStore {
3015
3020
  }
3016
3021
  }
3017
3022
  }
3023
+ function transformEntriesForZipFileStore(entries) {
3024
+ const topLevelZarrDirectories = new Set(Object.keys(entries).map((k) => k.split("/")[0]).filter((firstPathItem) => firstPathItem == null ? void 0 : firstPathItem.endsWith(".zarr")));
3025
+ if (topLevelZarrDirectories.size === 0) {
3026
+ return entries;
3027
+ }
3028
+ if (topLevelZarrDirectories.size > 1) {
3029
+ throw Error("expected exactly one top-level .zarr directory");
3030
+ }
3031
+ const topLevelZarrDirectory = Array.from(topLevelZarrDirectories)[0];
3032
+ const newEntries = Object.fromEntries(Object.entries(entries).map(([k, v]) => {
3033
+ let newKey = k;
3034
+ if (k.split("/")[0] === topLevelZarrDirectory) {
3035
+ newKey = k.substring(topLevelZarrDirectory.length + 1);
3036
+ }
3037
+ return [newKey, v];
3038
+ }));
3039
+ return newEntries;
3040
+ }
3018
3041
  function zarrOpenRoot(url, fileType, opts) {
3019
3042
  let store;
3020
3043
  if (fileType && fileType.endsWith(".zip")) {
3021
- store = ZipFileStore.fromUrl(url, { overrides: opts == null ? void 0 : opts.requestInit });
3044
+ store = ZipFileStore.fromUrl(url, {
3045
+ overrides: opts == null ? void 0 : opts.requestInit,
3046
+ transformEntries: transformEntriesForZipFileStore
3047
+ });
3022
3048
  } else if (fileType && fileType.endsWith(".h5ad")) {
3023
3049
  if (!(opts == null ? void 0 : opts.refSpecUrl)) {
3024
3050
  throw new Error("refSpecUrl is required for H5AD files");
@@ -4145,6 +4171,7 @@ const FileType$1 = {
4145
4171
  OBS_SPOTS_SPATIALDATA_ZARR: "obsSpots.spatialdata.zarr",
4146
4172
  FEATURE_LABELS_SPATIALDATA_ZARR: "featureLabels.spatialdata.zarr",
4147
4173
  OBS_POINTS_SPATIALDATA_ZARR: "obsPoints.spatialdata.zarr",
4174
+ OBS_EMBEDDING_SPATIALDATA_ZARR: "obsEmbedding.spatialdata.zarr",
4148
4175
  // SpatialData - zipped
4149
4176
  IMAGE_SPATIALDATA_ZARR_ZIP: "image.spatialdata.zarr.zip",
4150
4177
  LABELS_SPATIALDATA_ZARR_ZIP: "labels.spatialdata.zarr.zip",
@@ -4154,6 +4181,7 @@ const FileType$1 = {
4154
4181
  OBS_SPOTS_SPATIALDATA_ZARR_ZIP: "obsSpots.spatialdata.zarr.zip",
4155
4182
  FEATURE_LABELS_SPATIALDATA_ZARR_ZIP: "featureLabels.spatialdata.zarr.zip",
4156
4183
  OBS_POINTS_SPATIALDATA_ZARR_ZIP: "obsPoints.spatialdata.zarr.zip",
4184
+ OBS_EMBEDDING_SPATIALDATA_ZARR_ZIP: "obsEmbedding.spatialdata.zarr.zip",
4157
4185
  // MuData
4158
4186
  OBS_FEATURE_MATRIX_MUDATA_ZARR: "obsFeatureMatrix.mudata.zarr",
4159
4187
  OBS_SETS_MUDATA_ZARR: "obsSets.mudata.zarr",
@@ -4401,6 +4429,7 @@ const CoordinationType$1 = {
4401
4429
  [FileType$1.OBS_SETS_SPATIALDATA_ZARR]: DataType$1.OBS_SETS,
4402
4430
  [FileType$1.FEATURE_LABELS_SPATIALDATA_ZARR]: DataType$1.FEATURE_LABELS,
4403
4431
  [FileType$1.OBS_POINTS_SPATIALDATA_ZARR]: DataType$1.OBS_POINTS,
4432
+ [FileType$1.OBS_EMBEDDING_SPATIALDATA_ZARR]: DataType$1.OBS_EMBEDDING,
4404
4433
  // For new file types to support old file types
4405
4434
  [FileType$1.OBS_EMBEDDING_CELLS_JSON]: DataType$1.OBS_EMBEDDING,
4406
4435
  [FileType$1.OBS_LOCATIONS_CELLS_JSON]: DataType$1.OBS_LOCATIONS,
@@ -4577,6 +4606,9 @@ const CoordinationType$1 = {
4577
4606
  },
4578
4607
  [FileType$1.OBS_POINTS_SPATIALDATA_ZARR]: {
4579
4608
  zip: FileType$1.OBS_POINTS_SPATIALDATA_ZARR_ZIP
4609
+ },
4610
+ [FileType$1.OBS_EMBEDDING_SPATIALDATA_ZARR]: {
4611
+ zip: FileType$1.OBS_EMBEDDING_SPATIALDATA_ZARR_ZIP
4580
4612
  }
4581
4613
  });
4582
4614
  [
@@ -14422,6 +14454,16 @@ const obsSetsSpatialdataSchema = z.object({
14422
14454
  tablePath: z.string().optional().describe("The path to a table which contains the index for the set values."),
14423
14455
  obsSets: annDataObsSetsArr
14424
14456
  });
14457
+ annDataObsEmbedding.extend({
14458
+ // We extend anndataObsEmbedding which already has properties like `dims` and `path`.
14459
+ region: z.string().describe("The name of a region to use to filter instances (i.e., rows) in the table").optional(),
14460
+ tablePath: z.string().optional().describe("The path to a table which contains the index for the set values.")
14461
+ });
14462
+ const obsEmbeddingSpatialdataSchemaConvenience = z.union([
14463
+ annDataObsEmbedding,
14464
+ // For convenience, allow an array of items with `embeddingType` properties.
14465
+ z.array(annDataConvenienceObsEmbeddingItem)
14466
+ ]);
14425
14467
  z.object({
14426
14468
  targetX: z.number(),
14427
14469
  targetY: z.number(),
@@ -14530,9 +14572,10 @@ z.object({
14530
14572
  // TODO: obsPoints
14531
14573
  // TODO: obsLocations
14532
14574
  obsSets: obsSetsSpatialdataSchema,
14533
- // TODO: obsEmbedding
14575
+ obsEmbedding: obsEmbeddingSpatialdataSchemaConvenience,
14534
14576
  // TODO: obsLabels
14535
14577
  // TODO: featureLabels
14578
+ // TODO: allow specifying tablePath and region at the top-level here.
14536
14579
  coordinateSystem: z.string().optional().describe("The name of a coordinate transformation output used to transform all elements which lack a per-element coordinateSystem property.")
14537
14580
  }).partial();
14538
14581
  z.object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/zarr",
3
- "version": "3.6.13",
3
+ "version": "3.6.15",
4
4
  "author": "HIDIVE Lab at HMS",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -18,22 +18,22 @@
18
18
  "dependencies": {
19
19
  "d3-array": "^2.4.0",
20
20
  "lodash-es": "^4.17.21",
21
- "zarrita": "0.5.2",
21
+ "zarrita": "0.5.3",
22
22
  "apache-arrow": "^17.0.0",
23
23
  "parquet-wasm": "^0.6.1",
24
24
  "ol": "^10.2.1",
25
- "@vitessce/abstract": "3.6.13",
26
- "@vitessce/error": "3.6.13",
27
- "@vitessce/constants-internal": "3.6.13",
28
- "@vitessce/image-utils": "3.6.13",
29
- "@vitessce/utils": "3.6.13",
30
- "@vitessce/sets-utils": "3.6.13",
31
- "@vitessce/zarr-utils": "3.6.13",
32
- "@vitessce/config": "3.6.13",
33
- "@vitessce/globals": "3.6.13"
25
+ "@vitessce/abstract": "3.6.15",
26
+ "@vitessce/error": "3.6.15",
27
+ "@vitessce/constants-internal": "3.6.15",
28
+ "@vitessce/sets-utils": "3.6.15",
29
+ "@vitessce/image-utils": "3.6.15",
30
+ "@vitessce/utils": "3.6.15",
31
+ "@vitessce/zarr-utils": "3.6.15",
32
+ "@vitessce/config": "3.6.15",
33
+ "@vitessce/globals": "3.6.15"
34
34
  },
35
35
  "devDependencies": {
36
- "@vitessce/types": "3.6.13"
36
+ "@vitessce/types": "3.6.15"
37
37
  },
38
38
  "scripts": {
39
39
  "bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",