Skip to content

Commit c1d3f8d

Browse files
authored
Add oxa CLI package (#27)
* refactor(typescript): rename script to typecheck * chore(*): move typecheck and rename to monorepo to avoid confusion * feat(cli): initial iteration of `oxa` and `oxa-core` * chore(oxa-core): silence warning * ci(primary): typecheck `oxa-core` after codegen * chore(oca core): formatting * ci(primary): fix filter for oxa-types * ci(primary): fix order * ci(oxa types): build for oxa-core * build(oxa): ensure schema.json is copied over * docs(readme): separate out docs for oxa types * refactor(oxa core): rename to `@oxa/core`
1 parent 0710a37 commit c1d3f8d

File tree

16 files changed

+2111
-8
lines changed

16 files changed

+2111
-8
lines changed

.github/workflows/primary.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131

3232
- run: pnpm install --frozen-lockfile
3333

34-
# Typecheck generation code in scripts/ (before format/lint possibly change line numbers)
35-
- run: pnpm typecheck
34+
# Typecheck codegen scripts (before format/lint possibly change line numbers)
35+
- run: pnpm --filter scripts typecheck
3636

3737
# On push: auto-fix formatting and linting (will be committed)
3838
- run: pnpm format
@@ -50,13 +50,22 @@ jobs:
5050
run: pnpm codegen all
5151

5252
# Typecheck generated code (TypeScript via tsc, Python via ty, Rust via cargo)
53-
- run: pnpm test
53+
# Note: oxa-types-ts uses build (not typecheck) to produce dist/*.d.ts for @oxa/core
54+
- run: pnpm build
5455
working-directory: packages/oxa-types-ts
5556
- run: uv run ty check src/
5657
working-directory: packages/oxa-types-py
5758
- run: cargo check
5859
working-directory: packages/oxa-types-rs
5960

61+
# Build and test @oxa/core
62+
- run: pnpm --filter @oxa/core typecheck
63+
- run: pnpm --filter @oxa/core build
64+
- run: pnpm --filter @oxa/core test
65+
66+
# Build oxa (copy bundled CLI)
67+
- run: pnpm --filter oxa build
68+
6069
- name: Commit changes
6170
if: github.event_name == 'push'
6271
run: |

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "oxa",
2+
"name": "oxa-monorepo",
33
"version": "0.1.0",
44
"private": true,
55
"type": "module",
@@ -12,7 +12,6 @@
1212
"format:check": "prettier --check .",
1313
"lint": "eslint .",
1414
"lint:fix": "eslint --fix .",
15-
"typecheck": "tsc -p scripts/tsconfig.json",
1615
"build": "pnpm -r build",
1716
"test": "pnpm -r test"
1817
},
@@ -22,6 +21,7 @@
2221
"prettier": "^3.7.4",
2322
"tsx": "^4.21.0",
2423
"typescript": "^5.9.3",
25-
"typescript-eslint": "^8.50.0"
24+
"typescript-eslint": "^8.50.0",
25+
"vitest": "^4.0.16"
2626
}
2727
}

packages/oxa-core/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# @oxa/core
2+
3+
Validation library for OXA documents.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @oxa/core
9+
```
10+
11+
For CLI usage, see [`oxa`](https://www.npmjs.com/package/oxa).
12+
13+
## Usage
14+
15+
```typescript
16+
import { validate, validateFile, validateJson, validateYaml } from "@oxa/core";
17+
import type { Document } from "@oxa/core";
18+
19+
// Validate a document object
20+
const doc: Document = {
21+
type: "Document",
22+
metadata: {},
23+
title: [{ type: "Text", value: "Hello", classes: [], data: {} }],
24+
children: [],
25+
};
26+
27+
const result = validate(doc);
28+
if (result.valid) {
29+
console.log("Document is valid!");
30+
} else {
31+
console.error("Validation errors:", result.errors);
32+
}
33+
34+
// Validate a file (JSON or YAML based on extension)
35+
const fileResult = validateFile("./document.json");
36+
37+
// Validate JSON string
38+
const jsonResult = validateJson('{"type": "Document", ...}');
39+
40+
// Validate YAML string
41+
const yamlResult = validateYaml("type: Document\n...");
42+
43+
// Validate against a specific type
44+
const headingResult = validate(data, { type: "Heading" });
45+
```
46+
47+
## API
48+
49+
### `validate(data, options?)`
50+
51+
Validate a parsed document object against the OXA schema.
52+
53+
### `validateJson(json, options?)`
54+
55+
Validate a JSON string against the OXA schema.
56+
57+
### `validateYaml(yaml, options?)`
58+
59+
Validate a YAML string against the OXA schema.
60+
61+
### `validateFile(filePath, options?)`
62+
63+
Validate a file (JSON or YAML based on extension).
64+
65+
### `getSchema()`
66+
67+
Get the bundled OXA JSON schema.
68+
69+
### `getTypeNames()`
70+
71+
Get available type names from the schema definitions.
72+
73+
## Related Packages
74+
75+
- [`oxa`](https://www.npmjs.com/package/oxa) - CLI for validating OXA documents
76+
- [`oxa-types`](https://www.npmjs.com/package/oxa-types) - TypeScript type definitions

packages/oxa-core/package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "@oxa/core",
3+
"version": "0.1.0",
4+
"description": "Validation library for OXA documents",
5+
"type": "module",
6+
"main": "./dist/index.js",
7+
"types": "./dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"types": "./dist/index.d.ts",
11+
"import": "./dist/index.js"
12+
},
13+
"./schema.json": "./dist/schema.json"
14+
},
15+
"files": [
16+
"dist"
17+
],
18+
"scripts": {
19+
"build": "tsc && cp ../../schema/schema.json dist/ && pnpm run build:bundle",
20+
"build:bundle": "esbuild src/cli.ts --bundle --platform=node --target=node22 --format=cjs --outfile=dist/cli.bundle.cjs --banner:js='#!/usr/bin/env node' --log-override:empty-import-meta=silent",
21+
"test": "vitest run",
22+
"typecheck": "tsc --noEmit"
23+
},
24+
"dependencies": {
25+
"oxa-types": "workspace:*",
26+
"ajv": "^8.17.1",
27+
"ajv-formats": "^3.0.1",
28+
"commander": "^14.0.0",
29+
"js-yaml": "^4.1.0"
30+
},
31+
"devDependencies": {
32+
"@types/js-yaml": "^4.0.9",
33+
"@types/node": "^22.0.0",
34+
"esbuild": "^0.25.0",
35+
"execa": "^9.5.0"
36+
},
37+
"keywords": [
38+
"oxa",
39+
"validate",
40+
"schema",
41+
"json",
42+
"yaml"
43+
],
44+
"license": "MIT",
45+
"repository": {
46+
"type": "git",
47+
"url": "git+https://github.com/oxa-dev/oxa.git",
48+
"directory": "packages/oxa-core"
49+
},
50+
"engines": {
51+
"node": ">=22"
52+
}
53+
}

0 commit comments

Comments
 (0)