@alloy-js/json 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/babel.config.cjs +4 -1
- package/dist/src/components/JsonArray.d.ts +14 -8
- package/dist/src/components/JsonArray.d.ts.map +1 -1
- package/dist/src/components/JsonArray.js +66 -42
- package/dist/src/components/JsonArray.js.map +1 -1
- package/dist/src/components/JsonObject.d.ts +3 -0
- package/dist/src/components/JsonObject.d.ts.map +1 -1
- package/dist/src/components/JsonObject.js +46 -23
- package/dist/src/components/JsonObject.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +5 -5
- package/dist/test/array.test.d.ts.map +1 -1
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/src/components/JsonArray.tsx +58 -41
- package/src/components/JsonObject.tsx +47 -29
- package/src/components/SourceFile.tsx +10 -7
- package/temp/api.json +114 -6
- package/test/array.test.tsx +36 -6
- package/test/object.test.tsx +40 -11
- package/test/reference.test.tsx +50 -41
- package/test/utils.tsx +7 -5
- package/test/vitest.d.ts +7 -1
- package/vitest.config.ts +1 -1
package/test/reference.test.tsx
CHANGED
|
@@ -12,18 +12,21 @@ import { SourceFile } from "../src/components/SourceFile.jsx";
|
|
|
12
12
|
it("references objects within the same file", () => {
|
|
13
13
|
const objectValue = refkey();
|
|
14
14
|
const nullKey = refkey();
|
|
15
|
-
const template =
|
|
15
|
+
const template = (
|
|
16
16
|
<Output>
|
|
17
17
|
<SourceFile path="test.json">
|
|
18
18
|
<JsonObject refkey={objectValue}>
|
|
19
19
|
<JsonObjectProperty name="nullValue">
|
|
20
|
-
<JsonValue jsValue={null} refkey={nullKey}
|
|
20
|
+
<JsonValue jsValue={null} refkey={nullKey} />
|
|
21
|
+
</JsonObjectProperty>
|
|
22
|
+
<JsonObjectProperty name="refToNull">{nullKey}</JsonObjectProperty>
|
|
23
|
+
<JsonObjectProperty name="refToObject">
|
|
24
|
+
{objectValue}
|
|
21
25
|
</JsonObjectProperty>
|
|
22
|
-
<JsonObjectProperty name="refToNull">{nullKey}</JsonObjectProperty>,
|
|
23
|
-
<JsonObjectProperty name="refToObject">{objectValue}</JsonObjectProperty>
|
|
24
26
|
</JsonObject>
|
|
25
27
|
</SourceFile>
|
|
26
|
-
</Output
|
|
28
|
+
</Output>
|
|
29
|
+
);
|
|
27
30
|
|
|
28
31
|
expect(template).toRenderTo(`
|
|
29
32
|
{
|
|
@@ -37,28 +40,30 @@ it("references objects within the same file", () => {
|
|
|
37
40
|
it("references objects across files", () => {
|
|
38
41
|
const objectValue = refkey();
|
|
39
42
|
const nullKey = refkey();
|
|
40
|
-
const template =
|
|
43
|
+
const template = (
|
|
41
44
|
<Output>
|
|
42
45
|
<SourceFile path="test.json">
|
|
43
46
|
<JsonObject refkey={objectValue}>
|
|
44
47
|
<JsonObjectProperty name="nullValue">
|
|
45
|
-
<JsonValue jsValue={null} refkey={nullKey}
|
|
48
|
+
<JsonValue jsValue={null} refkey={nullKey} />
|
|
46
49
|
</JsonObjectProperty>
|
|
47
50
|
</JsonObject>
|
|
48
51
|
</SourceFile>
|
|
49
52
|
<SourceFile path="test.json">
|
|
50
53
|
<JsonObject>
|
|
51
|
-
<JsonObjectProperty name="refToNull">{nullKey}</JsonObjectProperty
|
|
52
|
-
<JsonObjectProperty name="refToObject">
|
|
54
|
+
<JsonObjectProperty name="refToNull">{nullKey}</JsonObjectProperty>
|
|
55
|
+
<JsonObjectProperty name="refToObject">
|
|
56
|
+
{objectValue}
|
|
57
|
+
</JsonObjectProperty>
|
|
53
58
|
</JsonObject>
|
|
54
59
|
</SourceFile>
|
|
55
|
-
</Output
|
|
60
|
+
</Output>
|
|
61
|
+
);
|
|
56
62
|
|
|
57
63
|
expect(template).toRenderTo(`
|
|
58
64
|
{
|
|
59
|
-
"nullValue": null
|
|
60
|
-
}
|
|
61
|
-
{
|
|
65
|
+
"nullValue": null
|
|
66
|
+
}{
|
|
62
67
|
"refToNull": "test.json#/nullValue",
|
|
63
68
|
"refToObject": "test.json#"
|
|
64
69
|
}
|
|
@@ -68,30 +73,32 @@ it("references objects across files", () => {
|
|
|
68
73
|
it("references objects across files and directories", () => {
|
|
69
74
|
const objectValue = refkey();
|
|
70
75
|
const nullKey = refkey();
|
|
71
|
-
const template =
|
|
76
|
+
const template = (
|
|
72
77
|
<Output>
|
|
73
78
|
<SourceDirectory path="subdir">
|
|
74
79
|
<SourceFile path="test.json">
|
|
75
80
|
<JsonObject refkey={objectValue}>
|
|
76
81
|
<JsonObjectProperty name="nullValue">
|
|
77
|
-
<JsonValue jsValue={null} refkey={nullKey}
|
|
82
|
+
<JsonValue jsValue={null} refkey={nullKey} />
|
|
78
83
|
</JsonObjectProperty>
|
|
79
84
|
</JsonObject>
|
|
80
|
-
</SourceFile>
|
|
85
|
+
</SourceFile>
|
|
81
86
|
</SourceDirectory>
|
|
82
87
|
<SourceFile path="test.json">
|
|
83
88
|
<JsonObject>
|
|
84
|
-
<JsonObjectProperty name="refToNull">{nullKey}</JsonObjectProperty
|
|
85
|
-
<JsonObjectProperty name="refToObject">
|
|
89
|
+
<JsonObjectProperty name="refToNull">{nullKey}</JsonObjectProperty>
|
|
90
|
+
<JsonObjectProperty name="refToObject">
|
|
91
|
+
{objectValue}
|
|
92
|
+
</JsonObjectProperty>
|
|
86
93
|
</JsonObject>
|
|
87
94
|
</SourceFile>
|
|
88
|
-
</Output
|
|
95
|
+
</Output>
|
|
96
|
+
);
|
|
89
97
|
|
|
90
98
|
expect(template).toRenderTo(`
|
|
91
99
|
{
|
|
92
|
-
"nullValue": null
|
|
93
|
-
}
|
|
94
|
-
{
|
|
100
|
+
"nullValue": null
|
|
101
|
+
}{
|
|
95
102
|
"refToNull": "subdir/test.json#/nullValue",
|
|
96
103
|
"refToObject": "subdir/test.json#"
|
|
97
104
|
}
|
|
@@ -101,25 +108,22 @@ it("references objects across files and directories", () => {
|
|
|
101
108
|
it("references arrays within the same file", () => {
|
|
102
109
|
const arrayValue = refkey();
|
|
103
110
|
const nullKey = refkey();
|
|
104
|
-
const template =
|
|
111
|
+
const template = (
|
|
105
112
|
<Output>
|
|
106
113
|
<SourceFile path="test.json">
|
|
107
114
|
<JsonArray refkey={arrayValue}>
|
|
108
|
-
<JsonArrayElement>{nullKey}</JsonArrayElement
|
|
109
|
-
<JsonArrayElement>{arrayValue}</JsonArrayElement
|
|
115
|
+
<JsonArrayElement>{nullKey}</JsonArrayElement>
|
|
116
|
+
<JsonArrayElement>{arrayValue}</JsonArrayElement>
|
|
110
117
|
<JsonArrayElement>
|
|
111
118
|
<JsonValue jsValue={null} refkey={nullKey} />
|
|
112
119
|
</JsonArrayElement>
|
|
113
120
|
</JsonArray>
|
|
114
121
|
</SourceFile>
|
|
115
|
-
</Output
|
|
122
|
+
</Output>
|
|
123
|
+
);
|
|
116
124
|
|
|
117
125
|
expect(template).toRenderTo(`
|
|
118
|
-
[
|
|
119
|
-
"#/2",
|
|
120
|
-
"#",
|
|
121
|
-
null
|
|
122
|
-
]
|
|
126
|
+
["#/2", "#", null]
|
|
123
127
|
`);
|
|
124
128
|
});
|
|
125
129
|
|
|
@@ -128,19 +132,23 @@ it("does complex references", () => {
|
|
|
128
132
|
const arrayValue = refkey();
|
|
129
133
|
const nullKey = refkey();
|
|
130
134
|
const nestedKey = refkey();
|
|
131
|
-
const template =
|
|
135
|
+
const template = (
|
|
132
136
|
<Output>
|
|
133
137
|
<SourceFile path="test.json">
|
|
134
138
|
<JsonObject refkey={objectValue}>
|
|
135
139
|
<JsonObjectProperty name="nullValue">
|
|
136
|
-
<JsonValue jsValue={null} refkey={nullKey}
|
|
140
|
+
<JsonValue jsValue={null} refkey={nullKey} />
|
|
141
|
+
</JsonObjectProperty>
|
|
142
|
+
<JsonObjectProperty name="refToNull">{nullKey}</JsonObjectProperty>
|
|
143
|
+
<JsonObjectProperty name="refToObject">
|
|
144
|
+
{objectValue}
|
|
145
|
+
</JsonObjectProperty>
|
|
146
|
+
<JsonObjectProperty name="refToNested">
|
|
147
|
+
{nestedKey}
|
|
137
148
|
</JsonObjectProperty>
|
|
138
|
-
<JsonObjectProperty name="refToNull">{nullKey}</JsonObjectProperty>,
|
|
139
|
-
<JsonObjectProperty name="refToObject">{objectValue}</JsonObjectProperty>
|
|
140
|
-
<JsonObjectProperty name="refToNested">{nestedKey}</JsonObjectProperty>
|
|
141
149
|
<JsonObjectProperty name="nestedArray">
|
|
142
150
|
<JsonArray refkey={arrayValue}>
|
|
143
|
-
<JsonArrayElement>{nullKey}</JsonArrayElement
|
|
151
|
+
<JsonArrayElement>{nullKey}</JsonArrayElement>
|
|
144
152
|
<JsonArrayElement>{arrayValue}</JsonArrayElement>
|
|
145
153
|
<JsonArrayElement>
|
|
146
154
|
<JsonObject>
|
|
@@ -153,17 +161,18 @@ it("does complex references", () => {
|
|
|
153
161
|
</JsonObjectProperty>
|
|
154
162
|
</JsonObject>
|
|
155
163
|
</SourceFile>
|
|
156
|
-
</Output
|
|
164
|
+
</Output>
|
|
165
|
+
);
|
|
157
166
|
|
|
158
167
|
expect(template).toRenderTo(`
|
|
159
168
|
{
|
|
160
169
|
"nullValue": null,
|
|
161
170
|
"refToNull": "#/nullValue",
|
|
162
|
-
"refToObject": "#"
|
|
163
|
-
"refToNested": "#/nestedArray/2/nestedProp"
|
|
171
|
+
"refToObject": "#",
|
|
172
|
+
"refToNested": "#/nestedArray/2/nestedProp",
|
|
164
173
|
"nestedArray": [
|
|
165
174
|
"#/nullValue",
|
|
166
|
-
"#/nestedArray"
|
|
175
|
+
"#/nestedArray",
|
|
167
176
|
{
|
|
168
177
|
"nestedProp": "hi"
|
|
169
178
|
}
|
package/test/utils.tsx
CHANGED
|
@@ -3,9 +3,11 @@ import { JsonValue } from "../src/components/JsonValue.jsx";
|
|
|
3
3
|
import { SourceFile } from "../src/components/SourceFile.jsx";
|
|
4
4
|
|
|
5
5
|
export function jsonTest(jsValue: unknown) {
|
|
6
|
-
return
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
return (
|
|
7
|
+
<Output>
|
|
8
|
+
<SourceFile path="test.json">
|
|
9
|
+
<JsonValue jsValue={jsValue} />
|
|
10
|
+
</SourceFile>
|
|
11
|
+
</Output>
|
|
12
|
+
);
|
|
11
13
|
}
|
package/test/vitest.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import "vitest";
|
|
2
2
|
|
|
3
|
+
interface ToRenderToRenderOptions {
|
|
4
|
+
printWidth?: number;
|
|
5
|
+
tabWidth?: number;
|
|
6
|
+
useTabs?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
interface CustomMatchers<R = unknown> {
|
|
4
|
-
toRenderTo: (str: string) => R;
|
|
10
|
+
toRenderTo: (str: string, options?: ToRenderToRenderOptions) => R;
|
|
5
11
|
}
|
|
6
12
|
|
|
7
13
|
declare module "vitest" {
|
package/vitest.config.ts
CHANGED
|
@@ -12,7 +12,7 @@ export default defineConfig({
|
|
|
12
12
|
sourceMaps: "both",
|
|
13
13
|
babelHelpers: "bundled",
|
|
14
14
|
extensions: [".ts", ".tsx"],
|
|
15
|
-
presets: ["@babel/preset-typescript", "@alloy-js/babel-preset"],
|
|
15
|
+
presets: ["@babel/preset-typescript", ["@alloy-js/babel-preset"]],
|
|
16
16
|
}),
|
|
17
17
|
],
|
|
18
18
|
});
|