Skip to content

Commit 6f685ff

Browse files
authored
Merge pull request #106 from wellcrafted-dev/braden-w/export-json-types
feat!: move JsonValue/JsonObject to wellcrafted/json
2 parents ccacc17 + 7e1da94 commit 6f685ff

File tree

6 files changed

+39
-23
lines changed

6 files changed

+39
-23
lines changed

.changeset/move-json-types.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wellcrafted": minor
3+
---
4+
5+
Move `JsonValue` and `JsonObject` types to `wellcrafted/json` export path.
6+
7+
**BREAKING:** `JsonValue` and `JsonObject` are no longer exported from `wellcrafted/error`. Import them from `wellcrafted/json` instead.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"types": "./dist/error/index.d.ts",
1818
"import": "./dist/error/index.js"
1919
},
20+
"./json": {
21+
"types": "./dist/json.d.ts",
22+
"import": "./dist/json.js"
23+
},
2024
"./brand": {
2125
"types": "./dist/brand.d.ts",
2226
"import": "./dist/brand.js"

src/error/defineErrors.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { describe, it, expect, expectTypeOf } from "bun:test";
22
import { defineErrors } from "./defineErrors.js";
33
import { extractErrorMessage } from "./extractErrorMessage.js";
4-
import type {
5-
AnyTaggedError,
6-
InferError,
7-
InferErrors,
8-
JsonObject,
9-
} from "./types.js";
4+
import type { AnyTaggedError, InferError, InferErrors } from "./types.js";
5+
import type { JsonObject } from "../json.js";
106

117
// =============================================================================
128
// Basic factories — message at call site equivalent

src/error/types.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
import type { Err } from "../result/result.js";
22

3-
/**
4-
* JSON-serializable value types for error context.
5-
* Ensures all error data can be safely serialized via JSON.stringify.
6-
*/
7-
export type JsonValue =
8-
| string
9-
| number
10-
| boolean
11-
| null
12-
| JsonValue[]
13-
| { [key: string]: JsonValue };
14-
15-
/**
16-
* JSON-serializable object type for error context.
17-
*/
18-
export type JsonObject = Record<string, JsonValue>;
19-
203
/**
214
* Base type for any tagged error, used as a minimum constraint.
225
*/

src/json.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* JSON-serializable value types.
3+
* Ensures data can be safely serialized via JSON.stringify.
4+
*
5+
* @example
6+
* ```typescript
7+
* import type { JsonValue, JsonObject } from "wellcrafted/json";
8+
*
9+
* const value: JsonValue = { key: [1, "two", true, null] };
10+
* const obj: JsonObject = { name: "Alice", age: 30 };
11+
* ```
12+
*/
13+
export type JsonValue =
14+
| string
15+
| number
16+
| boolean
17+
| null
18+
| JsonValue[]
19+
| { [key: string]: JsonValue };
20+
21+
/**
22+
* JSON-serializable object type.
23+
* A record where every value is a {@link JsonValue}.
24+
*/
25+
export type JsonObject = Record<string, JsonValue>;

tsdown.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default defineConfig({
44
entry: [
55
"src/result/index.ts",
66
"src/error/index.ts",
7+
"src/json.ts",
78
"src/brand.ts",
89
"src/query/index.ts",
910
"src/standard-schema/index.ts",

0 commit comments

Comments
 (0)