@ultimat3/schema 22.9.0 → 22.10.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/CLAUDE.md +2 -1
- package/package.json +1 -1
- package/src/error-codes.ts +29 -0
- package/src/errors.ts +3 -23
- package/src/index.ts +2 -2
package/CLAUDE.md
CHANGED
|
@@ -20,7 +20,8 @@ provider → t`. `char-count.ts` is imported by BOTH `validators.ts` (which reje
|
|
|
20
20
|
`describe-value.ts` (which renders the length in the same message), because they disagreed: the
|
|
21
21
|
rule counted code points and the message counted UTF-16 units, so `t.string.min(3)` refused `'👍a'`
|
|
22
22
|
with "at least 3 chars, received a string of 3 characters".
|
|
23
|
-
`standard.ts` and `errors.ts` depend on nothing but each other
|
|
23
|
+
`standard.ts` and `errors.ts` depend on nothing but each other and `error-codes.ts`, a leaf of
|
|
24
|
+
plain data that core imports ALONE so a browser graph never keeps the `SchemaError` classes. `iso-date.ts` imports nothing and
|
|
24
25
|
is imported by `validators.ts` and `coerce.ts` — the two doors a `t.date` string comes through, so
|
|
25
26
|
the rule that a clock time must carry an offset or `Z` has one copy, not one per door.
|
|
26
27
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Single responsibility: the DECLARATIONS of this package's error codes, as data — no class.
|
|
2
|
+
//
|
|
3
|
+
// A leaf of its own, apart from `errors.ts`, because `@ultimat3/core` registers these at load
|
|
4
|
+
// (`schema-error-codes.ts`) and core's error contract is in every browser bundle that holds a typed
|
|
5
|
+
// client. Declared beside `SchemaError`, the codes dragged the class in with them: a class with a
|
|
6
|
+
// computed member (`[ULTIMATE_ERROR_BRAND]`) is not removable by a bundler, so every island paid
|
|
7
|
+
// for a server-side validation error it can never construct. Importing only this file keeps
|
|
8
|
+
// `errors.ts` out of that graph.
|
|
9
|
+
|
|
10
|
+
export interface SchemaErrorCodeDeclaration {
|
|
11
|
+
readonly title: string;
|
|
12
|
+
readonly docs?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Pass to `registerErrorCodes()` from a package that may import both tiers (the CLI does this
|
|
17
|
+
* at boot) so the terminal and the dev overlay render these codes identically.
|
|
18
|
+
*/
|
|
19
|
+
export const SCHEMA_ERROR_CODES: Readonly<Record<string, SchemaErrorCodeDeclaration>> =
|
|
20
|
+
Object.freeze({
|
|
21
|
+
X_VALIDATION_FAILED: { title: 'value did not match its schema' },
|
|
22
|
+
X_SCHEMA_UNSUPPORTED: { title: 'the active schema provider cannot do this' },
|
|
23
|
+
X_SCHEMA_DISCRIMINANT_INVALID: {
|
|
24
|
+
title: 'a discriminated union member can never be dispatched to',
|
|
25
|
+
},
|
|
26
|
+
X_SCHEMA_DEFAULT_UNSHAREABLE: {
|
|
27
|
+
title: 'a schema default cannot be copied per parse',
|
|
28
|
+
},
|
|
29
|
+
});
|
package/src/errors.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// import `@ultimat3/core`, so `SchemaError` reproduces the `UltimateError` shape structurally
|
|
3
3
|
// and carries the same `Symbol.for('ultimate.error')` brand — `isUltimateError()` still matches.
|
|
4
4
|
|
|
5
|
+
import { SCHEMA_ERROR_CODES } from './error-codes';
|
|
5
6
|
import { formatIssues } from './standard';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -48,30 +49,9 @@ export const ULTIMATE_ERROR_BRAND: unique symbol = Symbol.for('ultimate.error');
|
|
|
48
49
|
*/
|
|
49
50
|
const ERROR_DOCS_URL = 'https://github.com/developerz-ai/ultimate/wiki/Error-Codes';
|
|
50
51
|
|
|
51
|
-
export interface SchemaErrorCodeDeclaration {
|
|
52
|
-
readonly title: string;
|
|
53
|
-
readonly docs?: string | undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Pass to `registerErrorCodes()` from a package that may import both tiers (the CLI does this
|
|
58
|
-
* at boot) so the terminal and the dev overlay render these codes identically.
|
|
59
|
-
*/
|
|
60
|
-
export const SCHEMA_ERROR_CODES: Readonly<Record<string, SchemaErrorCodeDeclaration>> =
|
|
61
|
-
Object.freeze({
|
|
62
|
-
X_VALIDATION_FAILED: { title: 'value did not match its schema' },
|
|
63
|
-
X_SCHEMA_UNSUPPORTED: { title: 'the active schema provider cannot do this' },
|
|
64
|
-
X_SCHEMA_DISCRIMINANT_INVALID: {
|
|
65
|
-
title: 'a discriminated union member can never be dispatched to',
|
|
66
|
-
},
|
|
67
|
-
X_SCHEMA_DEFAULT_UNSHAREABLE: {
|
|
68
|
-
title: 'a schema default cannot be copied per parse',
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
52
|
/**
|
|
73
|
-
* Derived, never re-typed: the declarations
|
|
74
|
-
* cannot fall out of step with what `SchemaError` renders locally.
|
|
53
|
+
* Derived, never re-typed: the declarations in `error-codes.ts` are the single source, so a title
|
|
54
|
+
* edited there cannot fall out of step with what `SchemaError` renders locally.
|
|
75
55
|
*/
|
|
76
56
|
const TITLES: Readonly<Record<string, string>> = Object.freeze(
|
|
77
57
|
Object.fromEntries(
|
package/src/index.ts
CHANGED
|
@@ -25,8 +25,9 @@ export type { QuerySource } from './coerce';
|
|
|
25
25
|
export { coerceInput, coerceNode, coerceQuery } from './coerce';
|
|
26
26
|
export { describeValue, expected } from './describe-value';
|
|
27
27
|
export { discriminatedUnionSchema } from './discriminated-union';
|
|
28
|
+
export type { SchemaErrorCodeDeclaration } from './error-codes';
|
|
29
|
+
export { SCHEMA_ERROR_CODES } from './error-codes';
|
|
28
30
|
export type {
|
|
29
|
-
SchemaErrorCodeDeclaration,
|
|
30
31
|
SchemaErrorInit,
|
|
31
32
|
SchemaErrorJSON,
|
|
32
33
|
ValidationIssue,
|
|
@@ -34,7 +35,6 @@ export type {
|
|
|
34
35
|
export {
|
|
35
36
|
DiscriminantInvalidError,
|
|
36
37
|
isSchemaError,
|
|
37
|
-
SCHEMA_ERROR_CODES,
|
|
38
38
|
SchemaError,
|
|
39
39
|
SchemaUnsupportedError,
|
|
40
40
|
ULTIMATE_ERROR_BRAND,
|