@alloy-js/json 0.23.0-dev.2 → 0.23.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/dev/src/components/array.test.js +51 -0
  3. package/dist/dev/src/components/array.test.js.map +1 -0
  4. package/dist/dev/src/components/index.js +6 -0
  5. package/dist/dev/src/components/index.js.map +1 -0
  6. package/dist/dev/src/components/json-array.js +163 -0
  7. package/dist/dev/src/components/json-array.js.map +1 -0
  8. package/dist/dev/src/components/json-object.js +187 -0
  9. package/dist/dev/src/components/json-object.js.map +1 -0
  10. package/dist/dev/src/components/json-value.js +62 -0
  11. package/dist/dev/src/components/json-value.js.map +1 -0
  12. package/dist/dev/src/components/json-value.test.js +66 -0
  13. package/dist/dev/src/components/json-value.test.js.map +1 -0
  14. package/dist/dev/src/components/object.test.js +118 -0
  15. package/dist/dev/src/components/object.test.js.map +1 -0
  16. package/dist/dev/src/components/primitives.test.js +7 -0
  17. package/dist/dev/src/components/primitives.test.js.map +1 -0
  18. package/dist/dev/src/components/reference.js +15 -0
  19. package/dist/dev/src/components/reference.js.map +1 -0
  20. package/dist/dev/src/components/reference.test.js +476 -0
  21. package/dist/dev/src/components/reference.test.js.map +1 -0
  22. package/dist/dev/src/components/source-file.js +52 -0
  23. package/dist/dev/src/components/source-file.js.map +1 -0
  24. package/dist/dev/src/components/stc/index.js +10 -0
  25. package/dist/dev/src/components/stc/index.js.map +1 -0
  26. package/dist/dev/src/context/JsonFileContext.js +10 -0
  27. package/dist/dev/src/context/JsonFileContext.js.map +1 -0
  28. package/dist/dev/src/context/index.js +2 -0
  29. package/dist/dev/src/context/index.js.map +1 -0
  30. package/dist/dev/src/index.js +4 -0
  31. package/dist/dev/src/index.js.map +1 -0
  32. package/dist/dev/src/symbols/index.js +51 -0
  33. package/dist/dev/src/symbols/index.js.map +1 -0
  34. package/dist/dev/src/symbols/json-symbol.js +59 -0
  35. package/dist/dev/src/symbols/json-symbol.js.map +1 -0
  36. package/dist/dev/test/utils.js +31 -0
  37. package/dist/dev/test/utils.js.map +1 -0
  38. package/dist/dev/test/vitest.setup.js +2 -0
  39. package/dist/dev/test/vitest.setup.js.map +1 -0
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/docs/api/components/JsonArrayElement.md +65 -0
  42. package/docs/api/components/JsonObject.md +91 -0
  43. package/docs/api/components/JsonObjectProperty.md +67 -0
  44. package/docs/api/components/JsonValue.md +28 -0
  45. package/docs/api/components/Reference.md +31 -0
  46. package/docs/api/components/SourceFile.md +36 -0
  47. package/docs/api/components/index.md +8 -0
  48. package/docs/api/contexts/JsonFile-context.md +21 -0
  49. package/docs/api/contexts/index.md +3 -0
  50. package/docs/api/functions/index.md +4 -0
  51. package/docs/api/functions/ref.md +18 -0
  52. package/docs/api/functions/useJsonFileContext.md +17 -0
  53. package/docs/api/index.md +7 -0
  54. package/docs/api/types/CreateJsonSymbolOptions.md +9 -0
  55. package/docs/api/types/JsonArrayElementProps.md +5 -0
  56. package/docs/api/types/JsonArrayProps.md +5 -0
  57. package/docs/api/types/JsonArrayPropsBase.md +7 -0
  58. package/docs/api/types/JsonObjectProps.md +5 -0
  59. package/docs/api/types/JsonObjectPropsBase.md +8 -0
  60. package/docs/api/types/JsonOutputSymbol.md +16 -0
  61. package/docs/api/types/ObjectPropertyProps.md +5 -0
  62. package/docs/api/types/index.md +10 -0
  63. package/docs/api/variables/JsonSymbolFlags.md +5 -0
  64. package/docs/api/variables/index.md +3 -0
  65. package/package.json +9 -7
  66. package/vitest.config.ts +8 -0
@@ -0,0 +1,91 @@
1
+ # JsonObject
2
+
3
+ Create a JSON Object. An object can be created by providing a JS object value which will be serialized to JSON. Else, you can provide children that comprise the object’s JSON representation.
4
+
5
+ ## Overload 1
6
+
7
+ Create a JSON object by providing children that define the object’s contents. The children should use the [JsonObjectProperty](../jsonobjectproperty/) component to define individual object properties.
8
+
9
+ * jsx
10
+
11
+ ```tsx
12
+ import { JsonObject } from "@alloy-js/json";
13
+
14
+
15
+ <JsonObject
16
+ refkey={Refkey | Refkey[]}
17
+ style={{
18
+ concise?: boolean;
19
+ }}
20
+ >
21
+ {children}
22
+ </JsonObject>
23
+ ```
24
+
25
+ * stc
26
+
27
+ ```ts
28
+ import { JsonObject } from "@alloy-js/json/stc";
29
+
30
+
31
+ JsonObject({
32
+ refkey: Refkey | Refkey[],
33
+ style: {
34
+ concise?: boolean;
35
+ },
36
+ }).children(children)
37
+ ```
38
+
39
+ ### Props
40
+
41
+ | | | |
42
+ | -------- | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
43
+ | children | [Children](../../../core/types/children/) | The contents of the JSON object. Likely to contain [JsonObjectProperty](../jsonobjectproperty/) components. |
44
+ | refkey | optional [Refkey](../../../core/types/refkey/) \| [Refkey](../../../core/types/refkey/)\[] | The refkey or array of refkeys for the JSON object. When provided, this value can be referenced elsewhere via this refkey. |
45
+ | style | optional { concise?: boolean; } | |
46
+
47
+ ## Overload 2
48
+
49
+ Create a JSON object by providing a JS value that will be serialized to JSON.
50
+
51
+ * jsx
52
+
53
+ ```tsx
54
+ import { JsonObject } from "@alloy-js/json";
55
+
56
+
57
+ <JsonObject
58
+ jsValue={[string, unknown][] | Map<string, unknown> | Record<string, unknown>}
59
+ refkey={Refkey | Refkey[]}
60
+ style={{
61
+ concise?: boolean;
62
+ }}
63
+ />
64
+ ```
65
+
66
+ * stc
67
+
68
+ ```ts
69
+ import { JsonObject } from "@alloy-js/json/stc";
70
+
71
+
72
+ JsonObject({
73
+ jsValue: [string, unknown][] | Map<string, unknown> | Record<string, unknown>,
74
+ refkey: Refkey | Refkey[],
75
+ style: {
76
+ concise?: boolean;
77
+ },
78
+ }).children(children)
79
+ ```
80
+
81
+ ### Props
82
+
83
+ | | | |
84
+ | ------- | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
85
+ | jsValue | \[string, unknown]\[] \| Map\<string, unknown> \| Record\<string, unknown> | The JS value to serialize to JSON. This can be an array of key-value pairs, a map, or a vanilla JS object. |
86
+ | refkey | optional [Refkey](../../../core/types/refkey/) \| [Refkey](../../../core/types/refkey/)\[] | The refkey or array of refkeys for the JSON object. When provided, this value can be referenced elsewhere via this refkey. |
87
+ | style | optional { concise?: boolean; } | |
88
+
89
+ ## See also
90
+
91
+ * \[unresolved link]
@@ -0,0 +1,67 @@
1
+ # JsonObjectProperty
2
+
3
+ Create a JSON object property. A property can be created by providing a JS property value or children that defines the value.
4
+
5
+ ## Overload 1
6
+
7
+ Create a JSON object property with a name and children. The children become the value of the property.
8
+
9
+ * jsx
10
+
11
+ ```tsx
12
+ import { JsonObjectProperty } from "@alloy-js/json";
13
+
14
+
15
+ <JsonObjectProperty name="string">
16
+ {children}
17
+ </JsonObjectProperty>
18
+ ```
19
+
20
+ * stc
21
+
22
+ ```ts
23
+ import { JsonObjectProperty } from "@alloy-js/json/stc";
24
+
25
+
26
+ JsonObjectProperty({ name: string }).children(children)
27
+ ```
28
+
29
+ ### Props
30
+
31
+ | | | |
32
+ | -------- | ----------------------------------------- | - |
33
+ | children | [Children](../../../core/types/children/) | |
34
+ | name | string | |
35
+
36
+ ## Overload 2
37
+
38
+ Create a JSON object property with a name and a JS value. The JS value is serialized to JSON for the property
39
+
40
+ * jsx
41
+
42
+ ```tsx
43
+ import { JsonObjectProperty } from "@alloy-js/json";
44
+
45
+
46
+ <JsonObjectProperty jsValue={unknown} name="string" />
47
+ ```
48
+
49
+ * stc
50
+
51
+ ```ts
52
+ import { JsonObjectProperty } from "@alloy-js/json/stc";
53
+
54
+
55
+ JsonObjectProperty({ jsValue: unknown, name: string }).children(children)
56
+ ```
57
+
58
+ ### Props
59
+
60
+ | | | |
61
+ | ------- | ------- | - |
62
+ | jsValue | unknown | |
63
+ | name | string | |
64
+
65
+ ## See also
66
+
67
+ * [MemberDeclaration context](../../../core/contexts/memberdeclaration-context/)
@@ -0,0 +1,28 @@
1
+ # JsonValue
2
+
3
+ Create a JSON value from a JS value. When the provided JS value is an object, the [JsonObject](../jsonobject/) component will be used. When the provided JS value is an array, the [JsonArray](../jsonarray/) component will be used. Otherwise, the JS value will be serialized to a string, number, boolean, or null as appropriate.
4
+
5
+ * jsx
6
+
7
+ ```tsx
8
+ import { JsonValue } from "@alloy-js/json";
9
+
10
+
11
+ <JsonValue jsValue={unknown} refkey={Refkey | Refkey[]} />
12
+ ```
13
+
14
+ * stc
15
+
16
+ ```ts
17
+ import { JsonValue } from "@alloy-js/json/stc";
18
+
19
+
20
+ JsonValue({ jsValue: unknown, refkey: Refkey | Refkey[] }).children(children)
21
+ ```
22
+
23
+ ## Props
24
+
25
+ | | | |
26
+ | ------- | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- |
27
+ | jsValue | unknown | The JS value to serialize to JSON. When provided, thi |
28
+ | refkey | optional [Refkey](../../../core/types/refkey/) \| [Refkey](../../../core/types/refkey/)\[] | The refkey or array of refkeys for the JSON value. When provided, this value can be referenced elsewhere via this refkey. |
@@ -0,0 +1,31 @@
1
+ # Reference
2
+
3
+ Emit a reference to a JSON value by its refkey.
4
+
5
+ * jsx
6
+
7
+ ```tsx
8
+ import { Reference } from "@alloy-js/json";
9
+
10
+
11
+ <Reference refkey={Refkey} />
12
+ ```
13
+
14
+ * stc
15
+
16
+ ```ts
17
+ import { Reference } from "@alloy-js/json/stc";
18
+
19
+
20
+ Reference({ refkey: Refkey }).children(children)
21
+ ```
22
+
23
+ ## Props
24
+
25
+ | | | |
26
+ | ------ | ------------------------------------- | --------------------------------------- |
27
+ | refkey | [Refkey](../../../core/types/refkey/) | The refkey for the symbol to reference. |
28
+
29
+ ## Remarks
30
+
31
+ Note that when you place a refkey in a template, the refkey will be converted into a reference automatically. Using this component directly is generally not required or recommended.
@@ -0,0 +1,36 @@
1
+ # SourceFile
2
+
3
+ Creates a JSON source file which defines a JSON value.
4
+
5
+ * jsx
6
+
7
+ ```tsx
8
+ import { SourceFile } from "@alloy-js/json";
9
+
10
+
11
+ <SourceFile path="string">
12
+ {children}
13
+ </SourceFile>
14
+ ```
15
+
16
+ * stc
17
+
18
+ ```ts
19
+ import { SourceFile } from "@alloy-js/json/stc";
20
+
21
+
22
+ SourceFile({ path: string }).children(children)
23
+ ```
24
+
25
+ ## Props
26
+
27
+ | | | |
28
+ | -------- | -------------------------------------------------- | -------------------------------------------------------------- |
29
+ | children | optional [Children](../../../core/types/children/) | The contents of the source file |
30
+ | path | string | The path for this source file relative to the parent directory |
31
+
32
+ ## See also
33
+
34
+ * [JsonFile context](../../contexts/jsonfile-context/)
35
+ * [MemberDeclaration context](../../../core/contexts/memberdeclaration-context/)
36
+ * [SourceFile context](../../../core/contexts/sourcefile-context/)
@@ -0,0 +1,8 @@
1
+ # json — components
2
+
3
+ - [JsonArrayElement](JsonArrayElement.md) — Create a JSON Array element.
4
+ - [JsonObject](JsonObject.md) — Create a JSON Object.
5
+ - [JsonObjectProperty](JsonObjectProperty.md) — Create a JSON object property.
6
+ - [JsonValue](JsonValue.md) — Create a JSON value from a JS value.
7
+ - [Reference](Reference.md) — Emit a reference to a JSON value by its refkey.
8
+ - [SourceFile](SourceFile.md) — Creates a JSON source file which defines a JSON value.
@@ -0,0 +1,21 @@
1
+ # JsonFile context
2
+
3
+ Provides information about the current JSON source file. This context is used to allow references between JSON files.
4
+
5
+ ```ts
6
+ const JsonFileContext: ComponentContext<JsonFileContext>
7
+ ```
8
+
9
+ ## Accessor
10
+
11
+ ```ts
12
+ const myContext = useContext(JsonFileContext);
13
+ ```
14
+
15
+ ## Context interface
16
+
17
+ | | | |
18
+ | ------ | ------------------------------------------------- | -------------------------------------------------------------------------- |
19
+ | path | optional string | The path of the current JSON file. May be different from the path on disk. |
20
+ | symbol | [JsonOutputSymbol](../../types/jsonoutputsymbol/) | The symbol for the value in this JSON file |
21
+ | url | optional string | The URL of the current JSON file |
@@ -0,0 +1,3 @@
1
+ # json — contexts
2
+
3
+ - [JsonFile context](JsonFile-context.md) — Provides information about the current JSON source file.
@@ -0,0 +1,4 @@
1
+ # json — functions
2
+
3
+ - [ref](ref.md) — import { ref } from "@alloy-js/json";
4
+ - [useJsonFileContext](useJsonFileContext.md) — import { useJsonFileContext } from "@alloy-js/json";
@@ -0,0 +1,18 @@
1
+ # ref
2
+
3
+ ```ts
4
+ import { ref } from "@alloy-js/json";
5
+
6
+
7
+ function ref(refkey: Refkey): string | (() => string);
8
+ ```
9
+
10
+ ## Parameters
11
+
12
+ | | | |
13
+ | ------ | ------ | - |
14
+ | refkey | Refkey | |
15
+
16
+ ## Returns
17
+
18
+ string | (() => string)
@@ -0,0 +1,17 @@
1
+ # useJsonFileContext
2
+
3
+ ```ts
4
+ import { useJsonFileContext } from "@alloy-js/json";
5
+
6
+
7
+ function useJsonFileContext(): JsonFileContext | undefined;
8
+ ```
9
+
10
+ ## Parameters
11
+
12
+ | |
13
+ | - |
14
+
15
+ ## Returns
16
+
17
+ [JsonFile context interface](../../contexts/jsonfile-context/) | undefined
@@ -0,0 +1,7 @@
1
+ # @alloy-js/json API Reference
2
+
3
+ - [components](components/index.md) (6 items)
4
+ - [contexts](contexts/index.md) (1 items)
5
+ - [functions](functions/index.md) (2 items)
6
+ - [types](types/index.md) (8 items)
7
+ - [variables](variables/index.md) (1 items)
@@ -0,0 +1,9 @@
1
+ # CreateJsonSymbolOptions
2
+
3
+ ## Members
4
+
5
+ Extends [OutputSymbolOptions](../../../core/types/outputsymboloptions/)
6
+
7
+ | | | |
8
+ | --------- | ------------------------------------------------------------ | - |
9
+ | jsonFlags | optional [JsonSymbolFlags](../../variables/jsonsymbolflags/) | |
@@ -0,0 +1,5 @@
1
+ # JsonArrayElementProps
2
+
3
+ ```ts
4
+ type JsonArrayElementProps = JsonArrayElementPropsWithJsValue | JsonArrayElementPropsWithChildren;
5
+ ```
@@ -0,0 +1,5 @@
1
+ # JsonArrayProps
2
+
3
+ ```ts
4
+ type JsonArrayProps = JsonArrayPropsWithJsValue | JsonArrayPropsWithChildren;
5
+ ```
@@ -0,0 +1,7 @@
1
+ # JsonArrayPropsBase
2
+
3
+ ## Members
4
+
5
+ | | | |
6
+ | ------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- |
7
+ | refkey | optional [Refkey](../../../core/types/refkey/) \| [Refkey](../../../core/types/refkey/)\[] | The refkey or array of refkeys for the JSON array. When provided, this value can be referenced elsewhere via this refkey. |
@@ -0,0 +1,5 @@
1
+ # JsonObjectProps
2
+
3
+ ```ts
4
+ type JsonObjectProps = JsonObjectPropsWithChildren | JsonObjectPropsWithJsValue;
5
+ ```
@@ -0,0 +1,8 @@
1
+ # JsonObjectPropsBase
2
+
3
+ ## Members
4
+
5
+ | | | |
6
+ | ------ | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
7
+ | refkey | optional [Refkey](../../../core/types/refkey/) \| [Refkey](../../../core/types/refkey/)\[] | The refkey or array of refkeys for the JSON object. When provided, this value can be referenced elsewhere via this refkey. |
8
+ | style | optional { concise?: boolean; } | |
@@ -0,0 +1,16 @@
1
+ # JsonOutputSymbol
2
+
3
+ JsonOutputSymbol is created for JSON Values with a refkey. For JSON objects and arrays, the symbol will have the `StaticMemberContainer` flag. For JSON values that are members of an object or an array, the symbol will have the `StaticMember` flag.
4
+
5
+ ## Members
6
+
7
+ Extends [OutputSymbol](../../../core/types/outputsymbol/)
8
+
9
+ | | | |
10
+ | ------------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
11
+ | constructor | (name: string, spaces: OutputSpace\[] \| OutputSpace \| undefined, options: CreateJsonSymbolOptions) | Constructs a new instance of the [`JsonOutputSymbol`](JsonOutputSymbol.md) class |
12
+ | copy | () => JsonOutputSymbol | |
13
+ | debugInfo | Record\<string, unknown> | |
14
+ | jsonFlags | [JsonSymbolFlags](../../variables/jsonsymbolflags/) | |
15
+ | memberSpaces | readonly \[“static”] | |
16
+ | staticMembers | import(“@alloy-js/core”).[OutputMemberSpace](../../../core/types/outputmemberspace/) | |
@@ -0,0 +1,5 @@
1
+ # ObjectPropertyProps
2
+
3
+ ```ts
4
+ type ObjectPropertyProps = ObjectPropertyPropsWithChildren | ObjectPropertyPropsWithJsValue;
5
+ ```
@@ -0,0 +1,10 @@
1
+ # json — types
2
+
3
+ - [CreateJsonSymbolOptions](CreateJsonSymbolOptions.md) — Extends [OutputSymbolOptions](../../../core/types/outputsymboloptions/)
4
+ - [JsonArrayElementProps](JsonArrayElementProps.md) — type JsonArrayElementProps = JsonArrayElementPropsWithJsValue | JsonArrayElementPropsWithChildren;
5
+ - [JsonArrayProps](JsonArrayProps.md) — type JsonArrayProps = JsonArrayPropsWithJsValue | JsonArrayPropsWithChildren;
6
+ - [JsonArrayPropsBase](JsonArrayPropsBase.md)
7
+ - [JsonObjectProps](JsonObjectProps.md) — type JsonObjectProps = JsonObjectPropsWithChildren | JsonObjectPropsWithJsValue;
8
+ - [JsonObjectPropsBase](JsonObjectPropsBase.md)
9
+ - [JsonOutputSymbol](JsonOutputSymbol.md) — JsonOutputSymbol is created for JSON Values with a refkey.
10
+ - [ObjectPropertyProps](ObjectPropertyProps.md) — type ObjectPropertyProps = ObjectPropertyPropsWithChildren | ObjectPropertyPropsWithJsValue;
@@ -0,0 +1,5 @@
1
+ # JsonSymbolFlags
2
+
3
+ ```ts
4
+ enum JsonSymbolFlags
5
+ ```
@@ -0,0 +1,3 @@
1
+ # json — variables
2
+
3
+ - [JsonSymbolFlags](JsonSymbolFlags.md) — enum JsonSymbolFlags
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/json",
3
- "version": "0.23.0-dev.2",
3
+ "version": "0.23.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,9 +8,11 @@
8
8
  },
9
9
  "exports": {
10
10
  ".": {
11
+ "development": "./dist/dev/src/index.js",
11
12
  "import": "./dist/src/index.js"
12
13
  },
13
14
  "./stc": {
15
+ "development": "./dist/dev/src/components/stc/index.js",
14
16
  "import": "./dist/src/components/stc/index.js"
15
17
  }
16
18
  },
@@ -21,22 +23,22 @@
21
23
  "author": "brian.terlson@microsoft.com",
22
24
  "license": "MIT",
23
25
  "dependencies": {
24
- "@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.8",
25
- "pathe": "^2.0.3"
26
+ "pathe": "^2.0.3",
27
+ "@alloy-js/core": "~0.23.0"
26
28
  },
27
29
  "devDependencies": {
28
- "@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.3",
29
- "@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.1",
30
30
  "@microsoft/api-extractor": "~7.52.8",
31
31
  "@rollup/plugin-typescript": "^12.1.2",
32
32
  "concurrently": "^9.2.0",
33
33
  "typescript": "^5.8.3",
34
- "vitest": "3.2.4"
34
+ "vitest": "3.2.4",
35
+ "@alloy-js/cli": "~0.23.0",
36
+ "@alloy-js/rollup-plugin": "~0.1.1"
35
37
  },
36
38
  "type": "module",
37
39
  "scripts": {
38
40
  "generate-docs": "api-extractor run",
39
- "build": "alloy build && pnpm run generate-docs",
41
+ "build": "alloy build --with-dev && pnpm run generate-docs",
40
42
  "clean": "rimraf dist/ .temp/",
41
43
  "test:watch": "vitest -w",
42
44
  "watch": "alloy build --watch",
package/vitest.config.ts CHANGED
@@ -2,6 +2,14 @@ import alloyPlugin from "@alloy-js/rollup-plugin";
2
2
  import { defineConfig } from "vitest/config";
3
3
 
4
4
  export default defineConfig({
5
+ resolve: {
6
+ conditions: ["source"],
7
+ },
8
+ ssr: {
9
+ resolve: {
10
+ conditions: ["source"],
11
+ },
12
+ },
5
13
  esbuild: {
6
14
  jsx: "preserve",
7
15
  sourcemap: "both",