Skip to content

Commit 8bda581

Browse files
authored
feat: Dual publish packages to jsr (#180)
1 parent 16d8055 commit 8bda581

File tree

23 files changed

+414
-106
lines changed

23 files changed

+414
-106
lines changed

.changeset/famous-days-kneel.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zarrita/core": patch
3+
---
4+
5+
Fix codec mapping

.github/workflows/jsr.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Publish JSR
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
packages: [ 'zarrita', 'core', 'typedarray', 'storage', 'indexing', 'ndarray' ]
14+
permissions:
15+
contents: read
16+
id-token: write # The OIDC ID token is used for authentication with JSR.
17+
steps:
18+
- uses: actions/checkout@v4
19+
- run: npx jsr publish
20+
working-directory: packages/${{ matrix.packages }}

.github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
uses: changesets/action@v1
2727
with:
2828
title: Create Release
29+
version: pnpm run version
2930
publish: pnpm changeset publish
3031
env:
3132
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

biome.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
},
1919
"files": {
20-
"ignore": ["fixtures", ".changeset", "package.json"]
20+
"ignore": ["fixtures", ".changeset", "package.json", "jsr.json"]
2121
},
2222
"vcs": {
2323
"enabled": true,

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"clean": "pnpm --recursive exec rm -rf dist",
66
"test": "vitest --api",
77
"format": "format .",
8-
"lint": "biome lint .",
8+
"lint": "biome ci .",
99
"fix": "biome check --apply .",
10-
"publint": "pnpm --recursive --filter=\"./packages/**\" exec publint"
10+
"publint": "pnpm --recursive --filter=\"./packages/**\" exec publint",
11+
"version": "changeset version && node ./scripts/sync-jsr.mjs"
1112
},
1213
"devDependencies": {
1314
"@biomejs/biome": "1.7.3",

packages/core/jsr.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@zarrita/core",
3+
"version": "0.1.0-next.10",
4+
"imports": {
5+
"@zarrita/storage": "jsr:@zarrita/storage@^0.1.0-next.5",
6+
"@zarrita/typedarray": "jsr:@zarrita/typedarray@^0.1.0-next.3",
7+
"numcodecs": "npm:numcodecs@^0.3.1"
8+
},
9+
"exports": {
10+
".": "./src/index.ts"
11+
},
12+
"publish": {
13+
"exclude": [
14+
"package.json"
15+
]
16+
}
17+
}

packages/core/src/codecs.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ function create_default_registry(): Map<string, () => Promise<CodecEntry>> {
3232
.set("json2", () => JsonCodec);
3333
}
3434

35-
export const registry = create_default_registry();
35+
export const registry: Map<string, () => Promise<CodecEntry>> =
36+
create_default_registry();
3637

3738
export function create_codec_pipeline<Dtype extends DataType>(
3839
chunk_metadata: ChunkMetadata<Dtype>,
39-
) {
40+
): {
41+
encode(chunk: Chunk<Dtype>): Promise<Uint8Array>;
42+
decode(bytes: Uint8Array): Promise<Chunk<Dtype>>;
43+
} {
4044
let codecs: Awaited<ReturnType<typeof load_codecs>>;
4145
return {
4246
async encode(chunk: Chunk<Dtype>): Promise<Uint8Array> {
@@ -94,13 +98,13 @@ async function load_codecs<D extends DataType>(chunk_meta: ChunkMetadata<D>) {
9498
let codec = Codec.fromConfig(meta.configuration, chunk_meta);
9599
switch (codec.kind) {
96100
case "array_to_array":
97-
array_to_array.push(codec);
101+
array_to_array.push(codec as unknown as ArrayToArrayCodec<D>);
98102
break;
99103
case "array_to_bytes":
100-
array_to_bytes = codec;
104+
array_to_bytes = codec as unknown as ArrayToBytesCodec<D>;
101105
break;
102106
default:
103-
bytes_to_bytes.push(codec);
107+
bytes_to_bytes.push(codec as unknown as BytesToBytesCodec);
104108
}
105109
}
106110
if (!array_to_bytes) {

packages/core/src/hierarchy.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { create_codec_pipeline } from "./codecs.js";
33
import { create_sharded_chunk_getter } from "./codecs/sharding.js";
44
import type {
55
ArrayMetadata,
6+
Attributes,
67
Chunk,
78
DataType,
89
GroupMetadata,
@@ -57,7 +58,7 @@ export class Group<Store extends Readable> extends Location<Store> {
5758
super(store, path);
5859
this.#metadata = metadata;
5960
}
60-
get attrs() {
61+
get attrs(): Attributes {
6162
return this.#metadata.attributes;
6263
}
6364
}
@@ -166,19 +167,19 @@ export class Array<
166167
this[CONTEXT_MARKER] = create_context(this, metadata);
167168
}
168169

169-
get attrs() {
170+
get attrs(): Attributes {
170171
return this.#metadata.attributes;
171172
}
172173

173-
get shape() {
174+
get shape(): number[] {
174175
return this.#metadata.shape;
175176
}
176177

177-
get chunks() {
178+
get chunks(): number[] {
178179
return this[CONTEXT_MARKER].chunk_shape;
179180
}
180181

181-
get dtype() {
182+
get dtype(): Dtype {
182183
return this.#metadata.data_type;
183184
}
184185

packages/indexing/jsr.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@zarrita/indexing",
3+
"version": "0.1.0-next.12",
4+
"imports": {
5+
"@zarrita/core": "jsr:@zarrita/core@^0.1.0-next.10",
6+
"@zarrita/storage": "jsr:@zarrita/storage@^0.1.0-next.5",
7+
"@zarrita/typedarray": "jsr:@zarrita/typedarray@^0.1.0-next.3"
8+
},
9+
"exports": {
10+
".": "./src/index.ts"
11+
},
12+
"publish": {
13+
"exclude": [
14+
"package.json"
15+
]
16+
}
17+
}

packages/indexing/src/ops.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ export async function get<
146146
arr: core.Array<D, Store>,
147147
selection: Sel | null = null,
148148
opts: GetOptions<Parameters<Store["get"]>[1]> = {},
149-
) {
149+
): Promise<
150+
null extends Sel[number]
151+
? core.Chunk<D>
152+
: Slice extends Sel[number]
153+
? core.Chunk<D>
154+
: core.Scalar<D>
155+
> {
150156
return get_with_setter<D, Store, core.Chunk<D>, Sel>(
151157
arr,
152158
selection,
@@ -161,7 +167,7 @@ export async function set<D extends core.DataType>(
161167
selection: (null | Slice | number)[] | null,
162168
value: core.Scalar<D> | core.Chunk<D>,
163169
opts: SetOptions = {},
164-
) {
170+
): Promise<void> {
165171
return set_with_setter<D, core.Chunk<D>>(arr, selection, value, opts, setter);
166172
}
167173

0 commit comments

Comments
 (0)