Skip to content

Commit

Permalink
feat: Dual publish packages to jsr (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt authored May 28, 2024
1 parent 16d8055 commit 8bda581
Show file tree
Hide file tree
Showing 23 changed files with 414 additions and 106 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-days-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zarrita/core": patch
---

Fix codec mapping
20 changes: 20 additions & 0 deletions .github/workflows/jsr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish JSR

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
packages: [ 'zarrita', 'core', 'typedarray', 'storage', 'indexing', 'ndarray' ]
permissions:
contents: read
id-token: write # The OIDC ID token is used for authentication with JSR.
steps:
- uses: actions/checkout@v4
- run: npx jsr publish
working-directory: packages/${{ matrix.packages }}
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
uses: changesets/action@v1
with:
title: Create Release
version: pnpm run version
publish: pnpm changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
},
"files": {
"ignore": ["fixtures", ".changeset", "package.json"]
"ignore": ["fixtures", ".changeset", "package.json", "jsr.json"]
},
"vcs": {
"enabled": true,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"clean": "pnpm --recursive exec rm -rf dist",
"test": "vitest --api",
"format": "format .",
"lint": "biome lint .",
"lint": "biome ci .",
"fix": "biome check --apply .",
"publint": "pnpm --recursive --filter=\"./packages/**\" exec publint"
"publint": "pnpm --recursive --filter=\"./packages/**\" exec publint",
"version": "changeset version && node ./scripts/sync-jsr.mjs"
},
"devDependencies": {
"@biomejs/biome": "1.7.3",
Expand Down
17 changes: 17 additions & 0 deletions packages/core/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@zarrita/core",
"version": "0.1.0-next.10",
"imports": {
"@zarrita/storage": "jsr:@zarrita/storage@^0.1.0-next.5",
"@zarrita/typedarray": "jsr:@zarrita/typedarray@^0.1.0-next.3",
"numcodecs": "npm:numcodecs@^0.3.1"
},
"exports": {
".": "./src/index.ts"
},
"publish": {
"exclude": [
"package.json"
]
}
}
14 changes: 9 additions & 5 deletions packages/core/src/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ function create_default_registry(): Map<string, () => Promise<CodecEntry>> {
.set("json2", () => JsonCodec);
}

export const registry = create_default_registry();
export const registry: Map<string, () => Promise<CodecEntry>> =
create_default_registry();

export function create_codec_pipeline<Dtype extends DataType>(
chunk_metadata: ChunkMetadata<Dtype>,
) {
): {
encode(chunk: Chunk<Dtype>): Promise<Uint8Array>;
decode(bytes: Uint8Array): Promise<Chunk<Dtype>>;
} {
let codecs: Awaited<ReturnType<typeof load_codecs>>;
return {
async encode(chunk: Chunk<Dtype>): Promise<Uint8Array> {
Expand Down Expand Up @@ -94,13 +98,13 @@ async function load_codecs<D extends DataType>(chunk_meta: ChunkMetadata<D>) {
let codec = Codec.fromConfig(meta.configuration, chunk_meta);
switch (codec.kind) {
case "array_to_array":
array_to_array.push(codec);
array_to_array.push(codec as unknown as ArrayToArrayCodec<D>);
break;
case "array_to_bytes":
array_to_bytes = codec;
array_to_bytes = codec as unknown as ArrayToBytesCodec<D>;
break;
default:
bytes_to_bytes.push(codec);
bytes_to_bytes.push(codec as unknown as BytesToBytesCodec);
}
}
if (!array_to_bytes) {
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { create_codec_pipeline } from "./codecs.js";
import { create_sharded_chunk_getter } from "./codecs/sharding.js";
import type {
ArrayMetadata,
Attributes,
Chunk,
DataType,
GroupMetadata,
Expand Down Expand Up @@ -57,7 +58,7 @@ export class Group<Store extends Readable> extends Location<Store> {
super(store, path);
this.#metadata = metadata;
}
get attrs() {
get attrs(): Attributes {
return this.#metadata.attributes;
}
}
Expand Down Expand Up @@ -166,19 +167,19 @@ export class Array<
this[CONTEXT_MARKER] = create_context(this, metadata);
}

get attrs() {
get attrs(): Attributes {
return this.#metadata.attributes;
}

get shape() {
get shape(): number[] {
return this.#metadata.shape;
}

get chunks() {
get chunks(): number[] {
return this[CONTEXT_MARKER].chunk_shape;
}

get dtype() {
get dtype(): Dtype {
return this.#metadata.data_type;
}

Expand Down
17 changes: 17 additions & 0 deletions packages/indexing/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@zarrita/indexing",
"version": "0.1.0-next.12",
"imports": {
"@zarrita/core": "jsr:@zarrita/core@^0.1.0-next.10",
"@zarrita/storage": "jsr:@zarrita/storage@^0.1.0-next.5",
"@zarrita/typedarray": "jsr:@zarrita/typedarray@^0.1.0-next.3"
},
"exports": {
".": "./src/index.ts"
},
"publish": {
"exclude": [
"package.json"
]
}
}
10 changes: 8 additions & 2 deletions packages/indexing/src/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ export async function get<
arr: core.Array<D, Store>,
selection: Sel | null = null,
opts: GetOptions<Parameters<Store["get"]>[1]> = {},
) {
): Promise<
null extends Sel[number]
? core.Chunk<D>
: Slice extends Sel[number]
? core.Chunk<D>
: core.Scalar<D>
> {
return get_with_setter<D, Store, core.Chunk<D>, Sel>(
arr,
selection,
Expand All @@ -161,7 +167,7 @@ export async function set<D extends core.DataType>(
selection: (null | Slice | number)[] | null,
value: core.Scalar<D> | core.Chunk<D>,
opts: SetOptions = {},
) {
): Promise<void> {
return set_with_setter<D, core.Chunk<D>>(arr, selection, value, opts, setter);
}

Expand Down
Loading

0 comments on commit 8bda581

Please sign in to comment.