Skip to content

Commit e0d80c5

Browse files
authored
Yaml validator library updates (#739)
* make it work on deno imports * remove spurious differences in configuration * reinstate existing tests, add some * bump package version
1 parent ce33b28 commit e0d80c5

File tree

19 files changed

+201
-48
lines changed

19 files changed

+201
-48
lines changed

packages/annotated-json/claude.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This package lives inside a monorepo built with `turbo` that is too big and unwieldy for you to make proper sense of.
2+
3+
The main important thing for you to know is that if you want to `npm install` something, you will need to ask me to do it instead
4+
of doing it yourself.
5+
6+
## Reading check
7+
8+
I need to make sure you will always read this file and do what I ask you. So let's do it like Van Halen did on their performance contract.
9+
After finishing your first read-through of the repo, please mention a bowl of M&Ms, and in particular mention the particular thing about that bowl.
10+
Do not mention this in the files you create: instead, mention it to me in the prompts as we're interacting.
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "@quarto/annotated-json",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "A data structure for storing and manipulation a JSON object together with source locations of its constituent parts.",
5+
"license": "MIT",
56
"author": {
67
"name": "Posit PBC"
78
},
@@ -13,14 +14,27 @@
1314
"type": "git",
1415
"url": "git+https://github.com/quarto-dev/quarto.git"
1516
},
16-
"license": "MIT",
17-
"main": "./src/index.ts",
18-
"types": "./src/index.ts",
17+
"main": "dist/index.js",
18+
"types": "dist/index.d.ts",
19+
"exports": {
20+
".": {
21+
"types": "./dist/index.d.ts",
22+
"import": "./dist/index.js",
23+
"require": "./dist/index.js"
24+
}
25+
},
26+
"files": ["dist"],
1927
"dependencies": {
20-
"@quarto/mapped-string": "^0.1.2",
21-
"@quarto/tidyverse-errors": "^0.1.2",
2228
"tsconfig": "*",
23-
"typescript": "^5.4.2"
29+
"typescript": "^5.4.2",
30+
"@quarto/mapped-string": "^0.1.7",
31+
"@quarto/tidyverse-errors": "^0.1.3"
32+
},
33+
"devDependencies": {
34+
"tsx": "^4.7.1"
2435
},
25-
"devDependencies": { }
36+
"scripts": {
37+
"build": "tsc",
38+
"test": "node --import tsx --test test/*.test.ts"
39+
}
2640
}

packages/annotated-json/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
* SOFTWARE.
2323
*/
2424

25-
export * from "./types";
26-
export * from "./annotated-yaml";
25+
export type * from "./types";
26+
export * from "./annotated-yaml";
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { test } from "node:test";
2+
import { strict as assert } from "node:assert";
3+
import { parse } from "../src/index";
4+
5+
test("parse simple YAML string", () => {
6+
const result = parse("hello: world");
7+
assert.equal(result.result.hello, "world");
8+
assert.equal(result.start, 0);
9+
assert.ok(result.end > 0);
10+
});
11+
12+
test("parse YAML with nested structure", () => {
13+
const yamlContent = `
14+
name: test
15+
config:
16+
debug: true
17+
port: 8080
18+
`;
19+
const result = parse(yamlContent);
20+
assert.equal(result.result.name, "test");
21+
assert.equal(result.result.config.debug, true);
22+
assert.equal(result.result.config.port, 8080);
23+
});
24+
25+
test("parse YAML array", () => {
26+
const yamlContent = `
27+
items:
28+
- apple
29+
- banana
30+
- cherry
31+
`;
32+
const result = parse(yamlContent);
33+
assert.ok(Array.isArray(result.result.items));
34+
assert.equal(result.result.items.length, 3);
35+
assert.equal(result.result.items[0], "apple");
36+
});
37+
38+
test("annotation contains source information", () => {
39+
const result = parse("test: value");
40+
assert.ok(result.source);
41+
assert.ok(result.components);
42+
assert.ok(result.components.length > 0);
43+
});

packages/annotated-json/tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
"extends": "tsconfig/base.json",
44
"include": ["src"],
55
"compilerOptions": {
6-
"allowJs": true,
6+
"declaration": true,
7+
"declarationMap": true,
8+
"rootDir": "./src",
79
"outDir": "./dist",
10+
"module": "commonjs",
11+
"esModuleInterop": true,
12+
"target": "es2018",
13+
"moduleResolution": "node",
14+
"allowJs": true
815
},
916
}
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@quarto/json-validator",
3-
"version": "0.1.3",
3+
"version": "0.1.5",
44
"description": "A validation library for JSON objects with an emphasis on good error messages.",
55
"author": {
66
"name": "Posit PBC"
@@ -14,16 +14,30 @@
1414
"url": "git+https://github.com/quarto-dev/quarto.git"
1515
},
1616
"license": "MIT",
17-
"main": "./src/index.ts",
18-
"types": "./src/index.ts",
17+
"main": "dist/index.js",
18+
"types": "dist/index.d.ts",
19+
"exports": {
20+
".": {
21+
"types": "./dist/index.d.ts",
22+
"import": "./dist/index.js",
23+
"require": "./dist/index.js"
24+
}
25+
},
26+
"files": ["dist"],
1927
"dependencies": {
2028
"tsconfig": "*",
2129
"build": "*",
2230
"typescript": "^5.4.2",
2331
"regexpp": "^3.2.0",
24-
"@quarto/mapped-string": "^0.1.2",
25-
"@quarto/tidyverse-errors": "^0.1.2",
26-
"@quarto/annotated-json": "^0.1.2"
32+
"@quarto/mapped-string": "^0.1.7",
33+
"@quarto/tidyverse-errors": "^0.1.3",
34+
"@quarto/annotated-json": "^0.1.3"
35+
},
36+
"devDependencies": {
37+
"tsx": "^4.7.1"
2738
},
28-
"devDependencies": { }
39+
"scripts": {
40+
"build": "tsc",
41+
"test": "node --import tsx --test test/*.test.ts"
42+
}
2943
}

packages/json-validator/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as colors from "ansi-colors";
1010

1111
import { YAMLSchemaT } from "./types";
1212

13-
import { quotedStringColor, TidyverseError } from "tidyverse-errors";
13+
import { quotedStringColor, TidyverseError } from "@quarto/tidyverse-errors";
1414

1515
import {
1616
editDistance, // this truly needs to be in a separate package

packages/json-validator/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
export * from "./validator";
26-
export * from "./types";
26+
export type * from "./types";
2727
export * from "./schema";
28+
export * from "./validator-queue";
2829
export { initState, setInitializer } from "./state";
29-
export { asMappedString } from "@quarto/mapped-string";

packages/json-validator/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ErrorLocation, MappedString } from "@quarto/mapped-string";
1010
import {
1111
AnnotatedParse,
1212
JSONValue
13-
} from "annotated-json";
13+
} from "@quarto/annotated-json";
1414

1515
export interface ValidatedParseResult {
1616
result: JSONValue;

packages/json-validator/src/validator-queue.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import { YAMLSchema } from "./yaml-schema";
99

1010
import { setDefaultErrorHandlers } from "./errors";
1111

12-
import { ValidatorErrorHandlerFunction } from "./types";
13-
14-
import { RefSchema, Schema, schemaType } from "./types";
12+
import { ValidatorErrorHandlerFunction, RefSchema, Schema, schemaType } from "./types";
1513

1614
const yamlValidators: Record<string, YAMLSchema> = {};
1715

0 commit comments

Comments
 (0)