Skip to content

Commit f38c7a4

Browse files
authored
Jsr from anode (#534)
* dom lib avail on tsconfig * jsr trial * make initial release for now * export livestore bits from schema * make sure livestore version matches up * fix * bump version * re-export sql * bump versions * include publishing flow * push it up * bump schema 0.1.4 * release schema 0.1.5 * include Adapter * release 0.1.6 * switch to OIDC * publish 0.1.7 * formatting
1 parent 3f4730f commit f38c7a4

34 files changed

+662
-27
lines changed

.github/workflows/publish.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Publish Schema Package
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
id-token: write # Required for npm provenance and JSR OIDC
10+
contents: read
11+
12+
jobs:
13+
validate-and-publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: pnpm/action-setup@v4
19+
with:
20+
version: 10
21+
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: "23"
25+
registry-url: "https://registry.npmjs.org"
26+
27+
- name: Install JSR CLI
28+
run: npm install -g jsr
29+
30+
- name: Install dependencies
31+
run: pnpm install --frozen-lockfile
32+
33+
- name: Validate version consistency
34+
run: |
35+
PACKAGE_VERSION=$(node -p "require('./packages/schema/package.json').version")
36+
JSR_VERSION=$(node -p "require('./packages/schema/jsr.json').version")
37+
38+
echo "package.json version: $PACKAGE_VERSION"
39+
echo "jsr.json version: $JSR_VERSION"
40+
41+
if [ "$PACKAGE_VERSION" != "$JSR_VERSION" ]; then
42+
echo "❌ Version mismatch: package.json ($PACKAGE_VERSION) != jsr.json ($JSR_VERSION)"
43+
exit 1
44+
fi
45+
46+
echo "✅ Versions match: $PACKAGE_VERSION"
47+
48+
- name: Extract tag version
49+
id: tag_version
50+
run: |
51+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
52+
echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT
53+
echo "Tag version: $TAG_VERSION"
54+
55+
- name: Validate tag matches package version
56+
run: |
57+
PACKAGE_VERSION=$(node -p "require('./packages/schema/package.json').version")
58+
TAG_VERSION="${{ steps.tag_version.outputs.tag_version }}"
59+
60+
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
61+
echo "❌ Tag version ($TAG_VERSION) doesn't match package version ($PACKAGE_VERSION)"
62+
exit 1
63+
fi
64+
65+
echo "✅ Tag version matches package version: $TAG_VERSION"
66+
67+
- name: Run type check
68+
run: pnpm --filter schema type-check
69+
70+
- name: Run lint check
71+
run: pnpm --filter schema lint:check
72+
73+
- name: Run format check
74+
run: pnpm --filter schema format:check
75+
76+
- name: Test JSR publish (dry run)
77+
run: pnpm --filter schema exec jsr publish --dry-run --allow-slow-types --allow-dirty
78+
79+
- name: Publish to npm
80+
run: pnpm --filter schema publish --access public --no-git-checks --provenance
81+
82+
- name: Publish to JSR
83+
run: pnpm --filter schema exec jsr publish --allow-slow-types
84+
85+
- name: Create GitHub Release
86+
uses: actions/create-release@v1
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
with:
90+
tag_name: ${{ github.ref }}
91+
release_name: Schema v${{ steps.tag_version.outputs.tag_version }}
92+
body: |
93+
Published @runtimed/schema v${{ steps.tag_version.outputs.tag_version }} to:
94+
- npm: https://www.npmjs.com/package/@runtimed/schema
95+
- JSR: https://jsr.io/@runtimed/schema
96+
draft: false
97+
prerelease: false

backend/sync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import { type Env, type ExecutionContext } from "./types";
66

77
import { getValidatedUser } from "./auth";
8-
import { Schema } from "@livestore/livestore";
8+
import { Schema } from "@runtimed/schema";
99

1010
export class WebSocketServer extends makeDurableObject({
1111
onPush: async (message) => {

docs/schema-publishing.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# Schema Package Publishing
2+
3+
This document explains how to publish the `@runtimed/schema` package to both npm and JSR.
4+
5+
## Overview
6+
7+
The `@runtimed/schema` package is published to two registries:
8+
9+
- **npm**: https://www.npmjs.com/package/@runtimed/schema
10+
- **JSR**: https://jsr.io/@runtimed/schema
11+
12+
Both registries are kept in sync with matching version numbers.
13+
14+
## Prerequisites
15+
16+
### For Automated Publishing (GitHub Actions)
17+
18+
1. **NPM_TOKEN**: npm access token with publish permissions
19+
- Generate at: https://www.npmjs.com/settings/tokens
20+
- Add to GitHub repository secrets
21+
22+
2. **JSR_TOKEN**: JSR access token with publish permissions
23+
- Generate at: https://jsr.io/account/tokens
24+
- Add to GitHub repository secrets
25+
26+
### For Manual Publishing
27+
28+
1. **npm**: Authenticated with `npm login`
29+
2. **JSR**: JSR CLI installed (`npm install -g jsr`)
30+
31+
## Automated Publishing (Recommended)
32+
33+
Publishing is automated via GitHub Actions when you push a git tag:
34+
35+
### 1. Update Version
36+
37+
Use the provided script to update both `package.json` and `jsr.json`:
38+
39+
```bash
40+
# Bump to a new version (e.g., 0.1.3)
41+
pnpm bump-schema 0.1.3
42+
```
43+
44+
This script:
45+
46+
- Updates version in both `package.json` and `jsr.json`
47+
- Validates version format
48+
- Stages changes for git commit
49+
50+
### 2. Test Locally
51+
52+
Before publishing, test that everything works:
53+
54+
```bash
55+
pnpm test-publish
56+
```
57+
58+
This runs:
59+
60+
- Version consistency check
61+
- Type checking
62+
- Linting
63+
- Format checking
64+
- Dry run publishing to both registries
65+
66+
### 3. Commit and Tag
67+
68+
```bash
69+
git commit -m "Bump schema version to v0.1.3"
70+
git tag v0.1.3
71+
git push origin HEAD --tags
72+
```
73+
74+
### 4. GitHub Actions Takes Over
75+
76+
The workflow (`.github/workflows/publish.yml`) automatically:
77+
78+
1. Validates version consistency
79+
2. Runs all checks (type, lint, format)
80+
3. Tests dry run publishing
81+
4. Publishes to npm
82+
5. Publishes to JSR
83+
6. Creates GitHub release
84+
85+
## Manual Publishing
86+
87+
If you need to publish manually:
88+
89+
### 1. Prepare and Test
90+
91+
```bash
92+
# Update versions
93+
pnpm bump-schema 0.1.3
94+
95+
# Test everything
96+
pnpm test-publish
97+
```
98+
99+
### 2. Publish to npm
100+
101+
```bash
102+
pnpm --filter schema publish --access public --no-git-checks
103+
```
104+
105+
### 3. Publish to JSR
106+
107+
```bash
108+
pnpm --filter schema exec jsr publish --allow-slow-types
109+
```
110+
111+
## Workflow Details
112+
113+
### Version Management
114+
115+
- Both `package.json` and `jsr.json` must have matching version numbers
116+
- Use semantic versioning (e.g., `0.1.3`, `1.0.0`, `2.1.0-beta.1`)
117+
- The `bump-schema` script ensures consistency
118+
119+
### Validation Steps
120+
121+
The publishing process includes several validation steps:
122+
123+
1. **Version Consistency**: Both files have matching versions
124+
2. **Tag Validation**: Git tag matches package version
125+
3. **Type Check**: TypeScript compilation without errors
126+
4. **Lint Check**: ESLint passes with no warnings
127+
5. **Format Check**: Prettier formatting is correct
128+
6. **Publish Dry Run**: Both registries accept the package
129+
130+
### Publishing Strategy
131+
132+
- **Tags trigger publishing**: Only git tags starting with `v` trigger the workflow
133+
- **Both registries**: Package is published to npm and JSR simultaneously
134+
- **Failure handling**: If either registry fails, the workflow stops
135+
- **GitHub Release**: Automatically created with links to both registries
136+
137+
## Troubleshooting
138+
139+
### Version Mismatch
140+
141+
```bash
142+
❌ Version mismatch: package.json (0.1.2) != jsr.json (0.1.1)
143+
```
144+
145+
**Solution**: Use `pnpm bump-schema <version>` to sync versions.
146+
147+
### JSR Slow Types Warning
148+
149+
```
150+
Warning Publishing a library with slow types is not recommended.
151+
```
152+
153+
This is expected. The schema package uses complex TypeScript types that JSR considers "slow types". We use `--allow-slow-types` to publish anyway.
154+
155+
### npm Authentication
156+
157+
```bash
158+
npm error code ENEEDAUTH
159+
```
160+
161+
**Solution**: Run `npm login` or ensure `NPM_TOKEN` is set correctly.
162+
163+
### JSR Authentication
164+
165+
```bash
166+
error: Unauthorized
167+
```
168+
169+
**Solution**: Ensure `JSR_TOKEN` is set correctly in GitHub secrets or run `jsr auth` for manual publishing.
170+
171+
### Git Tag Issues
172+
173+
```bash
174+
❌ Tag version (0.1.3) doesn't match package version (0.1.2)
175+
```
176+
177+
**Solution**: Ensure you've committed the version bump before tagging, or update the tag to match the package version.
178+
179+
## Scripts Reference
180+
181+
| Script | Command | Purpose |
182+
| ------------ | ---------------------------------------------------------- | ------------------------------------- |
183+
| Version Bump | `pnpm bump-schema <version>` | Update package versions consistently |
184+
| Test Publish | `pnpm test-publish` | Validate everything before publishing |
185+
| Manual npm | `pnpm --filter schema publish --access public` | Publish to npm only |
186+
| Manual JSR | `pnpm --filter schema exec jsr publish --allow-slow-types` | Publish to JSR only |
187+
188+
## Package Structure
189+
190+
```
191+
packages/schema/
192+
├── package.json # npm package configuration
193+
├── jsr.json # JSR package configuration
194+
├── README.md # Package documentation
195+
├── src/
196+
│ ├── index.ts # Main export
197+
│ ├── tables.ts # Database schema
198+
│ ├── types.ts # TypeScript types
199+
│ └── queries/ # Query helpers
200+
└── tsconfig.json # TypeScript configuration
201+
```
202+
203+
## Release Checklist
204+
205+
- [ ] Version numbers match in `package.json` and `jsr.json`
206+
- [ ] `pnpm test-publish` passes all checks
207+
- [ ] Changes committed to git
208+
- [ ] Git tag created and pushed
209+
- [ ] GitHub Actions workflow completes successfully
210+
- [ ] Both npm and JSR packages are live
211+
- [ ] GitHub release is created
212+
213+
## Support
214+
215+
For issues with the publishing process:
216+
217+
1. Check GitHub Actions logs for detailed error messages
218+
2. Test locally with `pnpm test-publish`
219+
3. Verify authentication tokens are valid
220+
4. Ensure version numbers are consistent

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"dev:runtime": "./scripts/dev-runtime.sh",
2020
"build:iframe": "cd iframe-outputs && vite build",
2121
"build": "vite build --mode development",
22+
"bump-schema": "./scripts/bump-schema-version.sh",
23+
"test-publish": "./scripts/test-publish.sh",
2224
"build:preview": "vite build --mode preview",
2325
"build:production": "./scripts/optimize-build.sh && vite build --mode production",
2426
"build:production:fast": "vite build --mode production",

packages/schema/jsr.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@runtimed/schema",
3+
"version": "0.1.7",
4+
"exports": "./src/index.ts",
5+
"license": "BSD-3-Clause"
6+
}

packages/schema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@runtimed/schema",
3-
"version": "0.1.0",
3+
"version": "0.1.7",
44
"type": "module",
55
"description": "Schema definitions for Anode - event-sourced notebook system",
66
"exports": "./src/index.ts",

packages/schema/src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,28 @@ import {
44
Events,
55
Schema,
66
Store as LiveStore,
7+
queryDb,
8+
SessionIdSymbol,
9+
signal,
10+
createStorePromise,
11+
sql,
712
} from "@livestore/livestore";
813

14+
export type { BootStatus, Adapter } from "@livestore/livestore";
15+
16+
export {
17+
makeSchema,
18+
State,
19+
Events,
20+
Schema,
21+
LiveStore,
22+
queryDb,
23+
SessionIdSymbol,
24+
signal,
25+
createStorePromise,
26+
sql,
27+
};
28+
929
export * as queries from "./queries/index.ts";
1030

1131
/**

packages/schema/src/queries/cellOrdering.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { tables } from "../tables.ts";
2-
import { queryDb } from "@livestore/livestore";
2+
import { queryDb } from "@runtimed/schema";
33

44
/**
55
* Cell ordering queries using fractional indexing

packages/schema/src/queries/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { tables } from "../tables.ts";
2-
import { queryDb } from "@livestore/livestore";
2+
import { queryDb } from "@runtimed/schema";
33

44
export * from "./outputDeltas.ts";
55
export * from "./cellOrdering.ts";

0 commit comments

Comments
 (0)