Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ jobs:
node-version: 20
cache: "npm"

- name: Install FlatBuffers compiler
run: |
curl -L https://github.com/google/flatbuffers/releases/download/v25.2.10/Linux.flatc.binary.clang++-18.zip -o flatc.zip
unzip flatc.zip -d /usr/local/bin/
chmod +x /usr/local/bin/flatc

- name: Install dependencies
run: npm ci

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Dependencies
node_modules/

# Local tooling (downloaded by scripts/ensure-flatc.sh)
.bin/

# Build output
dist/

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ npm run test
npm run typecheck
```

To regenerate FlatBuffers TypeScript after syncing schemas, run `npm run generate:fbs`.
The pinned `flatc` compiler is downloaded automatically if not already available.
The version is set in `scripts/ensure-flatc.sh`.

## API

### IcechunkStore
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"prepare": "test -d tests/data || ./scripts/sync-fixtures.sh && test -d flatbuffers || ./scripts/sync-flatbuffers.sh",
"sync:fixtures": "./scripts/sync-fixtures.sh",
"sync:fbs": "./scripts/sync-flatbuffers.sh",
"generate:fbs": "flatc -T -o ./src/format/flatbuffers --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs ./src/format/flatbuffers && prettier --write src/format/flatbuffers/generated",
"check:fbs": "flatc -T -o /tmp/fbs-check --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs /tmp/fbs-check && prettier --write /tmp/fbs-check/generated && diff -r /tmp/fbs-check/generated src/format/flatbuffers/generated"
"generate:fbs": "FLATC=\"$(./scripts/ensure-flatc.sh)\" && \"$FLATC\" -T -o ./src/format/flatbuffers --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs ./src/format/flatbuffers && prettier --write src/format/flatbuffers/generated",
"check:fbs": "rm -rf /tmp/fbs-check && FLATC=\"$(./scripts/ensure-flatc.sh)\" && \"$FLATC\" -T -o /tmp/fbs-check --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs /tmp/fbs-check && prettier --write /tmp/fbs-check/generated && diff -r /tmp/fbs-check/generated src/format/flatbuffers/generated"
},
"keywords": [
"icechunk",
Expand Down
50 changes: 50 additions & 0 deletions scripts/ensure-flatc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Ensure the pinned flatc version is available at .bin/flatc.
# Downloads it if missing or wrong version. Prints the path on stdout.
#
# Usage:
# FLATC="$(./scripts/ensure-flatc.sh)"
# "$FLATC" -T -o ./src/format/flatbuffers --gen-all ./flatbuffers/all.fbs

set -euo pipefail
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's recommended to verify that the required tools (curl and unzip) are available before proceeding with the download and extraction process to provide a clearer error message if they are missing.

Suggested change
set -euo pipefail
set -euo pipefail
# Check dependencies
for cmd in curl unzip; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "error: $cmd is required but not installed." >&2
exit 1
fi
done


FLATC_VERSION="25.12.19"

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
BIN_DIR="$PROJECT_DIR/.bin"
FLATC="$BIN_DIR/flatc"

# Check if we already have the right version
if [ -x "$FLATC" ]; then
current=$("$FLATC" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
if [ "$current" = "$FLATC_VERSION" ]; then
echo "$FLATC"
exit 0
fi
echo "flatc in .bin/ is v$current, need v$FLATC_VERSION" >&2
fi

# Download
case "$(uname -s)" in
Linux) ASSET="Linux.flatc.binary.clang++-18.zip" ;;
Darwin) ASSET="Mac.flatc.binary.zip" ;;
*)
echo "error: cannot download flatc for $(uname -s)" >&2
echo "Install flatc v$FLATC_VERSION to .bin/flatc manually." >&2
exit 1
;;
esac

mkdir -p "$BIN_DIR"

URL="https://github.com/google/flatbuffers/releases/download/v${FLATC_VERSION}/${ASSET}"
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT

echo "Downloading flatc v${FLATC_VERSION}..." >&2
curl -fsSL "$URL" -o "$TMPDIR/flatc.zip"
unzip -o -q "$TMPDIR/flatc.zip" -d "$BIN_DIR/"
chmod +x "$FLATC"

echo "$FLATC"
15 changes: 15 additions & 0 deletions src/format/flatbuffers/generated/move-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import * as flatbuffers from "flatbuffers";

import { NodeType } from "../generated/node-type.js";
import { ObjectId8 } from "../generated/object-id8.js";

export class MoveOperation {
bb: flatbuffers.ByteBuffer | null = null;
bb_pos = 0;
Expand Down Expand Up @@ -38,4 +41,16 @@ export class MoveOperation {
? this.bb!.__string(this.bb_pos + offset, optionalEncoding)
: null;
}

nodeId(obj?: ObjectId8): ObjectId8 | null {
const offset = this.bb!.__offset(this.bb_pos, 8);
return offset
? (obj || new ObjectId8()).__init(this.bb_pos + offset, this.bb!)
: null;
}

nodeType(): NodeType {
const offset = this.bb!.__offset(this.bb_pos, 10);
return offset ? this.bb!.readUint8(this.bb_pos + offset) : NodeType.Group;
}
}
6 changes: 6 additions & 0 deletions src/format/flatbuffers/generated/node-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// automatically generated by the FlatBuffers compiler, do not modify

export enum NodeType {
Group = 0,
Array = 1,
}
Loading