Skip to content

Commit edad492

Browse files
authored
Document zarrita entry and open module in JSDoc (#405)
* Decompose withRangeBatching into withRangeCoalescing + withCaching Drop withRangeBatching entirely. Split it into two primitives: - withRangeCoalescing: microtask-tick batcher with no cache state. Emits onFlush callbacks with immutable FlushReport objects for observability instead of a top-level .stats getter. - withCaching: byte cache keyed by a user-supplied CacheKey policy function. Returns undefined to skip caching, a string to store under. Ships cacheKeys.getsOnly (default), getsAndRanges, and getsAndShardIndices as built-in policies. Add a minimal ByteCache interface (has / get / set). Plain Map satisfies it and is the default when no cache option is supplied; users who want bounded eviction can drop in any ByteCache-compatible container. All APIs were unreleased, so no deprecation shims. * Document zarrita entry and open module in JSDoc Adopt Deno std library's JSDoc conventions on the zarrita public API, starting with the package entry point and the `open` module. The goal is hover-driven discoverability in editors: a user landing on `zarr.open` in VS Code should see a summary, a runnable example, and links to related symbols without leaving the tooltip. Both files gain `@module` blocks with a short pitch and an end-to-end example lifted from the cookbook. `open`, `open.v2`, and `open.v3` get full JSDoc with `@example Usage` blocks, `@param`/`@returns`, `@throws` for the two errors the fallback path actually surfaces, and `@category Read` so future TypeDoc output can group symbols. Symbol references use `{@linkcode}` to render monospace in hovers; URL references stay on `{@link}`. Overload signatures each carry a short doc stub with `@category` rather than a single doc on the implementation. VS Code resolves hovers per-matched overload, so a stub on each one is the cheapest way to keep all three call forms documented without duplicating the full block three times. This is the first of several passes — remaining core modules (`create`, `hierarchy`, indexing, extensions, errors, codecs, typedarray) and the `@zarrita/storage` entry files will follow the same conventions in later commits.
1 parent 306460e commit edad492

File tree

2 files changed

+120
-2
lines changed

2 files changed

+120
-2
lines changed

packages/zarrita/src/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/**
2+
* A minimal, modular Zarr implementation for JavaScript.
3+
*
4+
* Zarrita reads and writes chunked, n-dimensional arrays backed by pluggable
5+
* stores (HTTP, filesystem, in-memory, ...) and supports both Zarr v2 and v3
6+
* on-disk formats. The API is deliberately small: open an {@linkcode Array}
7+
* or {@linkcode Group} from a store, then read or write chunks with
8+
* {@linkcode get} and {@linkcode set}.
9+
*
10+
* ```ts
11+
* import * as zarr from "zarrita";
12+
*
13+
* const store = new zarr.FetchStore("https://example.com/data.zarr");
14+
* const arr = await zarr.open(store, { kind: "array" });
15+
*
16+
* // Read a 2D sub-region into an ndarray-like view.
17+
* const region = await zarr.get(arr, [zarr.slice(0, 10), null]);
18+
* console.log(region.shape, region.data);
19+
* ```
20+
*
21+
* See the {@link https://manzt.github.io/zarrita.js/ | cookbook} for more
22+
* recipes (creation, consolidated metadata, store extensions, slicing).
23+
*
24+
* @module
25+
*/
26+
127
// re-export all the storage interface types
228
export type * from "@zarrita/storage";
329
// re-export fetch store from storage

packages/zarrita/src/open.ts

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* Open Zarr arrays and groups from a {@link Readable} store.
3+
*
4+
* The main entry point is {@linkcode open}, which auto-detects whether the
5+
* target node is a Zarr v2 or v3 array/group. Use {@linkcode open.v2} or
6+
* {@linkcode open.v3} to pin a specific format.
7+
*
8+
* ```ts
9+
* import * as zarr from "zarrita";
10+
*
11+
* const store = new zarr.FetchStore("https://example.com/data.zarr");
12+
*
13+
* // Auto-detect version and node kind.
14+
* const node = await zarr.open(store);
15+
*
16+
* // Or narrow to an array (throws NotFoundError if it's a group).
17+
* const arr = await zarr.open(store, { kind: "array" });
18+
* ```
19+
*
20+
* @module
21+
*/
22+
123
import type { Readable } from "@zarrita/storage";
224
import { InvalidMetadataError, NotFoundError } from "./errors.js";
325
import type { ArrayExtension } from "./extension/define-array.js";
@@ -208,16 +230,59 @@ type OpenOptions = {
208230
signal?: AbortSignal;
209231
};
210232

233+
/**
234+
* Open a Zarr array or group, auto-detecting the on-disk format version.
235+
*
236+
* Tries Zarr v3 and v2 in the order most likely to succeed for the given
237+
* store (based on previous opens), falling back to the other version on
238+
* {@linkcode NotFoundError} or {@linkcode InvalidMetadataError}. Pass `kind`
239+
* to require a specific node type, or use {@linkcode open.v2} /
240+
* {@linkcode open.v3} to pin the format.
241+
*
242+
* @example Usage
243+
* ```ts
244+
* import * as zarr from "zarrita";
245+
*
246+
* const store = new zarr.FetchStore("https://example.com/data.zarr");
247+
* const arr = await zarr.open(store, { kind: "array" });
248+
* console.log(arr.shape, arr.dtype);
249+
* ```
250+
*
251+
* @example Child node of a group
252+
* ```ts
253+
* import * as zarr from "zarrita";
254+
*
255+
* const store = new zarr.FetchStore("https://example.com/data.zarr");
256+
* const group = await zarr.open(store, { kind: "group" });
257+
* const child = await zarr.open(group.resolve("temperature"), { kind: "array" });
258+
* ```
259+
*
260+
* @param location A {@linkcode Readable} store, or a {@linkcode Location}
261+
* pointing at a node within a store.
262+
* @param options Open options. Set `kind` to `"array"` or `"group"` to
263+
* require that node type, or pass an `AbortSignal` to cancel the request.
264+
* @returns The opened {@linkcode Array} or {@linkcode Group}.
265+
* @throws {NotFoundError} If no array or group exists at the location, or if
266+
* the node kind does not match `options.kind`.
267+
* @throws {InvalidMetadataError} If metadata is present but malformed.
268+
* @category Read
269+
*/
211270
export function open<Store extends Readable>(
212271
location: Location<Store> | Store,
213272
options: OpenOptions & { kind: "group" },
214273
): Promise<Group<Store>>;
215-
274+
/**
275+
* Open a Zarr array or group, auto-detecting the on-disk format version.
276+
* @category Read
277+
*/
216278
export function open<Store extends Readable>(
217279
location: Location<Store> | Store,
218280
options: OpenOptions & { kind: "array" },
219281
): Promise<Array<DataType, Store>>;
220-
282+
/**
283+
* Open a Zarr array or group, auto-detecting the on-disk format version.
284+
* @category Read
285+
*/
221286
export function open<Store extends Readable>(
222287
location: Location<Store> | Store,
223288
options?: OpenOptions,
@@ -240,5 +305,32 @@ export async function open<Store extends Readable>(
240305
});
241306
}
242307

308+
/**
309+
* Open a Zarr v2 array or group, ignoring any v3 metadata that may coexist.
310+
*
311+
* @example Usage
312+
* ```ts
313+
* import * as zarr from "zarrita";
314+
*
315+
* const store = new zarr.FetchStore("https://example.com/legacy.zarr");
316+
* const arr = await zarr.open.v2(store, { kind: "array" });
317+
* ```
318+
*
319+
* @category Read
320+
*/
243321
open.v2 = openV2;
322+
323+
/**
324+
* Open a Zarr v3 array or group, ignoring any v2 metadata that may coexist.
325+
*
326+
* @example Usage
327+
* ```ts
328+
* import * as zarr from "zarrita";
329+
*
330+
* const store = new zarr.FetchStore("https://example.com/data.zarr");
331+
* const group = await zarr.open.v3(store, { kind: "group" });
332+
* ```
333+
*
334+
* @category Read
335+
*/
244336
open.v3 = openV3;

0 commit comments

Comments
 (0)