Skip to content

Commit cbf160a

Browse files
committed
Consolidate @zarrita/typedarray into @zarrita/core (#254)
* Consolidate `@zarrita/typedarray` into `@zarrita/core` This also starts the deprecation of `@zarrita/typedarray`. It's a small module and it makes sense to keep it in the core to simplify project structure. * Add changesets
1 parent 0354c30 commit cbf160a

19 files changed

+117
-135
lines changed

.changeset/four-bats-knock.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@zarrita/typedarray": patch
3+
"@zarrita/indexing": patch
4+
"@zarrita/ndarray": patch
5+
"zarrita": patch
6+
"@zarrita/core": patch
7+
---
8+
9+
Remove \`@zarrita/typedarray\` package (now included in zarrita)

.changeset/nervous-boxes-exist.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"zarrita": patch
3+
---
4+
5+
Export `BoolArray`, `UnicodeStringArray`, and `ByteStringArrary`

.changeset/quiet-queens-chew.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zarrita/typedarray": patch
3+
---
4+
5+
Deprecate package and move into zarrita

packages/core/__tests__/open.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import * as path from "node:path";
22
import * as url from "node:url";
33
import { type AbsolutePath, FileSystemStore } from "@zarrita/storage";
4-
import {
5-
BoolArray,
6-
ByteStringArray,
7-
UnicodeStringArray,
8-
} from "@zarrita/typedarray";
94
import { afterEach, describe, expect, it, vi } from "vitest";
105

116
import { NodeNotFoundError } from "../src/errors.js";
@@ -17,6 +12,11 @@ import type {
1712
GroupMetadataV2,
1813
} from "../src/metadata.js";
1914
import { open } from "../src/open.js";
15+
import {
16+
BoolArray,
17+
ByteStringArray,
18+
UnicodeStringArray,
19+
} from "../src/typedarray.js";
2020

2121
function range(n: number) {
2222
return Array.from({ length: n }, (_, i) => i);

packages/typedarray/__tests__/index.test.ts packages/core/__tests__/typedarray.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
BoolArray,
55
ByteStringArray,
66
UnicodeStringArray,
7-
} from "../src/index.js";
7+
} from "../src/typedarray.js";
88

99
describe("BoolArray.constructor", () => {
1010
test("new (size: number) -> BoolArray", () => {

packages/core/__tests__/util.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
BoolArray,
1212
ByteStringArray,
1313
UnicodeStringArray,
14-
} from "@zarrita/typedarray";
14+
} from "../src/typedarray.js";
1515

1616
describe("get_ctr", () => {
1717
test.each<[DataType, unknown]>([

packages/core/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
},
1616
"dependencies": {
1717
"@zarrita/storage": "workspace:^",
18-
"@zarrita/typedarray": "workspace:^",
1918
"numcodecs": "^0.3.2"
2019
},
2120
"publishConfig": {

packages/core/src/codecs/transpose.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {
2-
BoolArray,
3-
ByteStringArray,
4-
UnicodeStringArray,
5-
} from "@zarrita/typedarray";
61
import type {
72
Chunk,
83
DataType,
94
Scalar,
105
TypedArray,
116
TypedArrayConstructor,
127
} from "../metadata.js";
8+
import {
9+
BoolArray,
10+
ByteStringArray,
11+
UnicodeStringArray,
12+
} from "../typedarray.js";
1313
import { get_strides } from "../util.js";
1414

1515
type TypedArrayProxy<D extends DataType> = {

packages/core/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export { KeyError, NodeNotFoundError } from "./errors.js";
2+
export {
3+
BoolArray,
4+
ByteStringArray,
5+
UnicodeStringArray,
6+
} from "./typedarray.js";
27
export {
38
Array,
49
get_context as _internal_get_array_context,

packages/core/src/metadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
BoolArray,
33
ByteStringArray,
44
UnicodeStringArray,
5-
} from "@zarrita/typedarray";
5+
} from "./typedarray.js";
66

77
/** @category Number */
88
export type Int8 = "int8";

packages/typedarray/src/index.ts packages/core/src/typedarray.ts

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* Custom array-like views (i.e., TypedArrays) for Zarr binary data buffers.
3+
*
4+
* @module
5+
*/
6+
7+
/**
8+
* An array-like view of a fixed-length boolean buffer.
9+
*
10+
* Encoded as 1 byte per value.
11+
*/
112
export class BoolArray {
213
#bytes: Uint8Array;
314

@@ -58,6 +69,11 @@ export class BoolArray {
5869
}
5970
}
6071

72+
/**
73+
* An array-like view of a fixed-length byte buffer.
74+
*
75+
* Encodes a raw byte sequences without enforced encoding.
76+
*/
6177
export class ByteStringArray {
6278
_data: Uint8Array;
6379
chars: number;
@@ -147,6 +163,11 @@ export class ByteStringArray {
147163
}
148164
}
149165

166+
/**
167+
* An array-like view of a fixed-length Unicode string buffer.
168+
*
169+
* Encoded as UTF-32 code points.
170+
*/
150171
export class UnicodeStringArray {
151172
#data: Int32Array;
152173
chars: number;

packages/core/src/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
BoolArray,
33
ByteStringArray,
44
UnicodeStringArray,
5-
} from "@zarrita/typedarray";
5+
} from "./typedarray.js";
66

77
import type {
88
ArrayMetadata,

packages/indexing/__tests__/get.test.ts

+18-53
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import * as path from "node:path";
22
import * as url from "node:url";
33
import * as zarr from "@zarrita/core";
44
import FSStore from "@zarrita/storage/fs";
5-
import {
6-
BoolArray,
7-
ByteStringArray,
8-
UnicodeStringArray,
9-
} from "@zarrita/typedarray";
105
import { describe, expect, it } from "vitest";
116

127
import { get } from "../src/ops.js";
@@ -218,49 +213,29 @@ describe("get v2", () => {
218213

219214
it("1d.contiguous.U13.le", async () => {
220215
let res = await get_v2("/1d.contiguous.U13.le");
221-
expect(res.data).toBeInstanceOf(UnicodeStringArray);
222-
expect(Array.from(res.data as UnicodeStringArray)).toStrictEqual([
223-
"a",
224-
"b",
225-
"cc",
226-
"d",
227-
]);
216+
expect(res.data).toBeInstanceOf(zarr.UnicodeStringArray);
217+
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
228218
expect(res.shape).toStrictEqual([4]);
229219
});
230220

231221
it("1d.contiguous.U13.be", async () => {
232222
let res = await get_v2("/1d.contiguous.U13.be");
233-
expect(res.data).toBeInstanceOf(UnicodeStringArray);
234-
expect(Array.from(res.data as UnicodeStringArray)).toStrictEqual([
235-
"a",
236-
"b",
237-
"cc",
238-
"d",
239-
]);
223+
expect(res.data).toBeInstanceOf(zarr.UnicodeStringArray);
224+
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
240225
expect(res.shape).toStrictEqual([4]);
241226
});
242227

243228
it("1d.contiguous.U7", async () => {
244229
let res = await get_v2("/1d.contiguous.U7");
245-
expect(res.data).toBeInstanceOf(UnicodeStringArray);
246-
expect(Array.from(res.data as UnicodeStringArray)).toStrictEqual([
247-
"a",
248-
"b",
249-
"cc",
250-
"d",
251-
]);
230+
expect(res.data).toBeInstanceOf(zarr.UnicodeStringArray);
231+
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
252232
expect(res.shape).toStrictEqual([4]);
253233
});
254234

255235
it("1d.contiguous.S7", async () => {
256236
let res = await get_v2("/1d.contiguous.S7");
257-
expect(res.data).toBeInstanceOf(ByteStringArray);
258-
expect(Array.from(res.data as UnicodeStringArray)).toStrictEqual([
259-
"a",
260-
"b",
261-
"cc",
262-
"d",
263-
]);
237+
expect(res.data).toBeInstanceOf(zarr.ByteStringArray);
238+
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
264239
expect(res.shape).toStrictEqual([4]);
265240
});
266241

@@ -277,12 +252,7 @@ describe("get v2", () => {
277252
],
278253
}
279254
`);
280-
expect(Array.from(res.data as BoolArray)).toStrictEqual([
281-
true,
282-
false,
283-
true,
284-
false,
285-
]);
255+
expect(Array.from(res.data)).toStrictEqual([true, false, true, false]);
286256
});
287257

288258
it("2d.contiguous.i2", async () => {
@@ -414,12 +384,7 @@ describe("get v2", () => {
414384

415385
it("2d.chunked.U7", async () => {
416386
let res = await get_v2("/2d.chunked.U7");
417-
expect(Array.from(res.data as UnicodeStringArray)).toStrictEqual([
418-
"a",
419-
"b",
420-
"cc",
421-
"d",
422-
]);
387+
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
423388
expect(res.shape).toStrictEqual([2, 2]);
424389
});
425390

@@ -545,9 +510,9 @@ describe("get v2", () => {
545510
let res = await get_v2("/3d.chunked.mixed.i2.F");
546511
// biome-ignore format: the array should not be formatted
547512
expect(res.data).toStrictEqual(new Int16Array([
548-
0, 9, 18, 3, 12, 21, 6, 15, 24,
549-
1, 10, 19, 4, 13, 22, 7, 16, 25,
550-
2, 11, 20, 5, 14, 23, 8, 17, 26,
513+
0, 9, 18, 3, 12, 21, 6, 15, 24,
514+
1, 10, 19, 4, 13, 22, 7, 16, 25,
515+
2, 11, 20, 5, 14, 23, 8, 17, 26,
551516
]));
552517
expect(res.shape).toStrictEqual([3, 3, 3]);
553518
expect(res.stride).toStrictEqual([1, 3, 9]);
@@ -632,8 +597,8 @@ describe("get v3", () => {
632597

633598
it("1d.contiguous.b1", async () => {
634599
let res = await get_v3("/1d.contiguous.b1");
635-
expect(res.data).toBeInstanceOf(BoolArray);
636-
expect(Array.from(res.data as BoolArray)).toStrictEqual([
600+
expect(res.data).toBeInstanceOf(zarr.BoolArray);
601+
expect(Array.from(res.data as zarr.BoolArray)).toStrictEqual([
637602
true,
638603
false,
639604
true,
@@ -695,9 +660,9 @@ describe("get v3", () => {
695660
let res = await get_v3("/3d.chunked.mixed.i2.F");
696661
// biome-ignore format: the array should not be formatted
697662
expect(res.data).toStrictEqual(new Int16Array([
698-
0, 9, 18, 3, 12, 21, 6, 15, 24,
699-
1, 10, 19, 4, 13, 22, 7, 16, 25,
700-
2, 11, 20, 5, 14, 23, 8, 17, 26,
663+
0, 9, 18, 3, 12, 21, 6, 15, 24,
664+
1, 10, 19, 4, 13, 22, 7, 16, 25,
665+
2, 11, 20, 5, 14, 23, 8, 17, 26,
701666
]));
702667
expect(res.shape).toStrictEqual([3, 3, 3]);
703668
expect(res.stride).toStrictEqual([1, 3, 9]);

packages/ndarray/__tests__/index.test.ts

+12-37
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { get } from "../src/index.js";
66

77
import * as zarr from "@zarrita/core";
88
import { FileSystemStore } from "@zarrita/storage";
9-
import {
10-
BoolArray,
11-
ByteStringArray,
12-
UnicodeStringArray,
13-
} from "@zarrita/typedarray";
149

1510
let __dirname = path.dirname(url.fileURLToPath(import.meta.url));
1611

@@ -124,7 +119,7 @@ describe("ndarray", () => {
124119
kind: "array",
125120
});
126121
let res = await get(arr);
127-
expect(res.data).toBeInstanceOf(UnicodeStringArray);
122+
expect(res.data).toBeInstanceOf(zarr.UnicodeStringArray);
128123
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
129124
expect(res.shape).toStrictEqual([4]);
130125
});
@@ -134,13 +129,8 @@ describe("ndarray", () => {
134129
kind: "array",
135130
});
136131
let res = await get(arr);
137-
expect(res.data).toBeInstanceOf(UnicodeStringArray);
138-
expect(Array.from(res.data as UnicodeStringArray)).toStrictEqual([
139-
"a",
140-
"b",
141-
"cc",
142-
"d",
143-
]);
132+
expect(res.data).toBeInstanceOf(zarr.UnicodeStringArray);
133+
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
144134
expect(res.shape).toStrictEqual([4]);
145135
});
146136

@@ -149,13 +139,8 @@ describe("ndarray", () => {
149139
kind: "array",
150140
});
151141
let res = await get(arr);
152-
expect(res.data).toBeInstanceOf(UnicodeStringArray);
153-
expect(Array.from(res.data as UnicodeStringArray)).toStrictEqual([
154-
"a",
155-
"b",
156-
"cc",
157-
"d",
158-
]);
142+
expect(res.data).toBeInstanceOf(zarr.UnicodeStringArray);
143+
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
159144
expect(res.shape).toStrictEqual([4]);
160145
});
161146

@@ -164,13 +149,8 @@ describe("ndarray", () => {
164149
kind: "array",
165150
});
166151
let res = await get(arr);
167-
expect(res.data).toBeInstanceOf(ByteStringArray);
168-
expect(Array.from(res.data as ByteStringArray)).toStrictEqual([
169-
"a",
170-
"b",
171-
"cc",
172-
"d",
173-
]);
152+
expect(res.data).toBeInstanceOf(zarr.ByteStringArray);
153+
expect(Array.from(res.data)).toStrictEqual(["a", "b", "cc", "d"]);
174154
expect(res.shape).toStrictEqual([4]);
175155
});
176156

@@ -179,13 +159,8 @@ describe("ndarray", () => {
179159
kind: "array",
180160
});
181161
let res = await get(arr);
182-
expect(res.data).toBeInstanceOf(BoolArray);
183-
expect(Array.from(res.data as BoolArray)).toStrictEqual([
184-
true,
185-
false,
186-
true,
187-
false,
188-
]);
162+
expect(res.data).toBeInstanceOf(zarr.BoolArray);
163+
expect(Array.from(res.data)).toStrictEqual([true, false, true, false]);
189164
expect(res.shape).toStrictEqual([4]);
190165
});
191166

@@ -290,9 +265,9 @@ describe("ndarray", () => {
290265
let res = await get(arr);
291266
// biome-ignore format: the array should not be formatted
292267
expect(res.data).toStrictEqual(new Int16Array([
293-
0, 9, 18, 3, 12, 21, 6, 15, 24,
294-
1, 10, 19, 4, 13, 22, 7, 16, 25,
295-
2, 11, 20, 5, 14, 23, 8, 17, 26,
268+
0, 9, 18, 3, 12, 21, 6, 15, 24,
269+
1, 10, 19, 4, 13, 22, 7, 16, 25,
270+
2, 11, 20, 5, 14, 23, 8, 17, 26,
296271
]));
297272
expect(res.shape).toStrictEqual([3, 3, 3]);
298273
expect(res.stride).toStrictEqual([1, 3, 9]);

0 commit comments

Comments
 (0)