From 1074c7d87fd947614c31d118b1fe60032918adea Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sat, 14 Feb 2026 11:06:59 -0500 Subject: [PATCH] feat(fizarrita): export internals for custom codec workers Export fizarrita's internal building blocks so consumers can compose custom Web Workers that extend the standard codec worker with additional functionality (e.g. computing statistics during decode). Newly exported from the main entry point: - get-worker: DEFAULT_WORKER_URL, getStoreId, createCacheKey, ArrayMetadata, readArrayMetadata, probeActualChunkShape - worker-rpc: workerDecode, workerDecodeInto, workerEncode, getMetaId - internals/codec-pipeline: create_codec_pipeline - internals/util: get_ctr, get_strides, create_chunk_key_encoder, createBuffer, assertSharedArrayBufferAvailable - internals/setter: setter, compat_chunk, set_from_chunk_binary - internals/indexer: BasicIndexer, normalize_selection, slice, slice_indices - types: Projection, Indices Added subpath exports in package.json for direct deep imports: - ./internals/codec-pipeline - ./internals/setter - ./internals/util Bumps version to 1.3.0. --- fizarrita/package.json | 14 +++++++++++++- fizarrita/src/get-worker.ts | 12 ++++++------ fizarrita/src/index.ts | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/fizarrita/package.json b/fizarrita/package.json index a39bba6..ae2a597 100644 --- a/fizarrita/package.json +++ b/fizarrita/package.json @@ -1,6 +1,6 @@ { "name": "@fideus-labs/fizarrita", - "version": "1.2.0", + "version": "1.3.0", "description": "Worker-pool-accelerated get/set for zarrita.js — offloads codec encode/decode to Web Workers.", "type": "module", "main": "./dist/index.js", @@ -13,6 +13,18 @@ "./codec-worker": { "types": "./dist/codec-worker.d.ts", "import": "./dist/codec-worker.js" + }, + "./internals/codec-pipeline": { + "types": "./dist/internals/codec-pipeline.d.ts", + "import": "./dist/internals/codec-pipeline.js" + }, + "./internals/setter": { + "types": "./dist/internals/setter.d.ts", + "import": "./dist/internals/setter.js" + }, + "./internals/util": { + "types": "./dist/internals/util.d.ts", + "import": "./dist/internals/util.js" } }, "files": [ diff --git a/fizarrita/src/get-worker.ts b/fizarrita/src/get-worker.ts index 543c3a1..cd1684e 100644 --- a/fizarrita/src/get-worker.ts +++ b/fizarrita/src/get-worker.ts @@ -35,7 +35,7 @@ import { workerDecode, workerDecodeInto, getMetaId } from './worker-rpc.js' * Default URL for the codec worker. Uses `import.meta.url` to resolve * relative to this module. */ -const DEFAULT_WORKER_URL = new URL('./codec-worker.js', import.meta.url) +export const DEFAULT_WORKER_URL = new URL('./codec-worker.js', import.meta.url) /** Shared TextDecoder instance. */ const decoder = new TextDecoder() @@ -54,14 +54,14 @@ const NULL_CACHE: ChunkCache = { const storeIdMap = new WeakMap() let storeIdCounter = 0 -function getStoreId(store: Readable): string { +export function getStoreId(store: Readable): string { if (!storeIdMap.has(store)) { storeIdMap.set(store, storeIdCounter++) } return `store_${storeIdMap.get(store)}` } -function createCacheKey( +export function createCacheKey( arr: ZarrArray, encodeChunkKey: (chunk_coords: number[]) => string, chunk_coords: number[], @@ -75,13 +75,13 @@ function createCacheKey( // Unified metadata reader — reads zarr.json once, returns everything needed // --------------------------------------------------------------------------- -interface ArrayMetadata { +export interface ArrayMetadata { codecMeta: CodecChunkMeta encodeChunkKey: (chunk_coords: number[]) => string fillValue: Scalar | null } -async function readArrayMetadata( +export async function readArrayMetadata( arr: ZarrArray, ): Promise { const store = arr.store @@ -526,7 +526,7 @@ async function validateCandidateChunkShape( +export async function probeActualChunkShape( arr: ZarrArray, encodeChunkKey: (chunk_coords: number[]) => string, codecMeta: CodecChunkMeta, diff --git a/fizarrita/src/index.ts b/fizarrita/src/index.ts index a7c1dc4..e563acd 100644 --- a/fizarrita/src/index.ts +++ b/fizarrita/src/index.ts @@ -6,11 +6,46 @@ * WorkerPool with bounded concurrency. */ -export { getWorker, readZstdFrameContentSize, readBloscFrameContentSize, inferChunkShape } from './get-worker.js' +export { + getWorker, + readZstdFrameContentSize, + readBloscFrameContentSize, + inferChunkShape, + DEFAULT_WORKER_URL, + readArrayMetadata, + probeActualChunkShape, + createCacheKey, + getStoreId, +} from './get-worker.js' +export type { ArrayMetadata } from './get-worker.js' export { setWorker } from './set-worker.js' export type { GetWorkerOptions, SetWorkerOptions, CodecChunkMeta, ChunkCache, + Projection, + Indices, } from './types.js' + +// Internals — exported for building custom workers that extend the codec worker +export { create_codec_pipeline } from './internals/codec-pipeline.js' +export { + get_ctr, + get_strides, + create_chunk_key_encoder, + createBuffer, + assertSharedArrayBufferAvailable, +} from './internals/util.js' +export type { ChunkKeyEncoding } from './internals/util.js' +export { setter, compat_chunk, set_from_chunk_binary } from './internals/setter.js' +export { + BasicIndexer, + normalize_selection, + slice, + slice_indices, +} from './internals/indexer.js' +export type { ChunkProjection, IndexerProjection } from './internals/indexer.js' + +// Worker RPC helpers — for composing custom workers +export { workerDecode, workerDecodeInto, workerEncode, getMetaId } from './worker-rpc.js'