@fougere/schema 0.11.0-alpha.0 → 0.12.1-alpha.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/dist/Schema.d.ts +1 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +4 -3
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaConstructor.d.ts +3 -4
- package/dist/SchemaConstructor.d.ts.map +1 -1
- package/dist/SchemaDefinition.d.ts.map +1 -1
- package/dist/SchemaDefinition.js +2 -1
- package/dist/SchemaDefinition.js.map +1 -1
- package/dist/SchemaError.d.ts +4 -0
- package/dist/SchemaError.d.ts.map +1 -0
- package/dist/SchemaError.js +7 -0
- package/dist/SchemaError.js.map +1 -0
- package/dist/SchemaView.d.ts +1 -1
- package/dist/SchemaView.d.ts.map +1 -1
- package/dist/axis/Axes.d.ts +16 -0
- package/dist/axis/Axes.d.ts.map +1 -0
- package/dist/axis/Axes.js +27 -0
- package/dist/axis/Axes.js.map +1 -0
- package/dist/axis/Axis.d.ts +5 -9
- package/dist/axis/Axis.d.ts.map +1 -1
- package/dist/axis/Axis.js +1 -10
- package/dist/axis/Axis.js.map +1 -1
- package/dist/axis/boundary/Boundary.d.ts +29 -3
- package/dist/axis/boundary/Boundary.d.ts.map +1 -1
- package/dist/axis/boundary/Boundary.js +15 -11
- package/dist/axis/boundary/Boundary.js.map +1 -1
- package/dist/axis/boundary/Decoder.d.ts +10 -7
- package/dist/axis/boundary/Decoder.d.ts.map +1 -1
- package/dist/axis/boundary/Decoder.js +2 -2
- package/dist/axis/boundary/Decoder.js.map +1 -1
- package/dist/axis/lifecycle/Generators.d.ts +5 -5
- package/dist/axis/lifecycle/Generators.d.ts.map +1 -1
- package/dist/axis/lifecycle/Generators.js +5 -15
- package/dist/axis/lifecycle/Generators.js.map +1 -1
- package/dist/axis/lifecycle/Lifecycle.d.ts +18 -6
- package/dist/axis/lifecycle/Lifecycle.d.ts.map +1 -1
- package/dist/axis/lifecycle/Lifecycle.js +29 -14
- package/dist/axis/lifecycle/Lifecycle.js.map +1 -1
- package/dist/axis/lifecycle/apply.d.ts.map +1 -1
- package/dist/axis/lifecycle/apply.js +5 -22
- package/dist/axis/lifecycle/apply.js.map +1 -1
- package/dist/axis/role/Role.d.ts +18 -6
- package/dist/axis/role/Role.d.ts.map +1 -1
- package/dist/axis/role/Role.js +30 -16
- package/dist/axis/role/Role.js.map +1 -1
- package/dist/axis/shape/Shape.d.ts +2 -2
- package/dist/axis/shape/Shape.d.ts.map +1 -1
- package/dist/axis/shape/Shape.js +2 -2
- package/dist/axis/shape/Shape.js.map +1 -1
- package/dist/axis/shape/{Formats.d.ts → StringFormats.d.ts} +3 -3
- package/dist/axis/shape/StringFormats.d.ts.map +1 -0
- package/dist/axis/shape/{Formats.js → StringFormats.js} +3 -3
- package/dist/axis/shape/StringFormats.js.map +1 -0
- package/dist/entity/EntityAdapterSet.d.ts.map +1 -1
- package/dist/entity/EntityAdapterSet.js +3 -2
- package/dist/entity/EntityAdapterSet.js.map +1 -1
- package/dist/entity.d.ts +0 -1
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +0 -1
- package/dist/entity.js.map +1 -1
- package/dist/field/Field.d.ts +11 -5
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +10 -7
- package/dist/field/Field.js.map +1 -1
- package/dist/field/FieldFormat.d.ts +9 -0
- package/dist/field/FieldFormat.d.ts.map +1 -0
- package/dist/field/FieldFormat.js +12 -0
- package/dist/field/FieldFormat.js.map +1 -0
- package/dist/field/FieldSet.d.ts.map +1 -1
- package/dist/field/FieldSet.js +5 -3
- package/dist/field/FieldSet.js.map +1 -1
- package/dist/field/FougereFieldAxes.d.ts +3 -0
- package/dist/field/FougereFieldAxes.d.ts.map +1 -0
- package/dist/field/FougereFieldAxes.js +2 -0
- package/dist/field/FougereFieldAxes.js.map +1 -0
- package/dist/field/Meta.d.ts +5 -3
- package/dist/field/Meta.d.ts.map +1 -1
- package/dist/field/Meta.js +2 -1
- package/dist/field/Meta.js.map +1 -1
- package/dist/field/Values.d.ts +6 -0
- package/dist/field/Values.d.ts.map +1 -0
- package/dist/field/Values.js.map +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/Format.d.ts +56 -0
- package/dist/lib/Format.d.ts.map +1 -0
- package/dist/lib/Format.js +95 -0
- package/dist/lib/Format.js.map +1 -0
- package/dist/lib/JsonSchema.d.ts +2 -0
- package/dist/lib/JsonSchema.d.ts.map +1 -0
- package/dist/lib/JsonSchema.js +2 -0
- package/dist/lib/JsonSchema.js.map +1 -0
- package/dist/lib/Registry.d.ts +5 -4
- package/dist/lib/Registry.d.ts.map +1 -1
- package/dist/lib/Registry.js +14 -8
- package/dist/lib/Registry.js.map +1 -1
- package/dist/lib/ValidationResult.d.ts +2 -0
- package/dist/lib/ValidationResult.d.ts.map +1 -1
- package/dist/lib/ValidationResult.js +6 -0
- package/dist/lib/ValidationResult.js.map +1 -1
- package/dist/lib/Verdict.d.ts +12 -0
- package/dist/lib/Verdict.d.ts.map +1 -0
- package/dist/lib/Verdict.js +2 -0
- package/dist/lib/Verdict.js.map +1 -0
- package/dist/projection/Cases.js +52 -54
- package/dist/projection/Cases.js.map +1 -1
- package/dist/projection/Visibility.d.ts +11 -0
- package/dist/projection/Visibility.d.ts.map +1 -1
- package/dist/projection/Visibility.js +22 -0
- package/dist/projection/Visibility.js.map +1 -1
- package/dist/projection/card/Bundle.d.ts.map +1 -1
- package/dist/projection/card/Bundle.js +2 -1
- package/dist/projection/card/Bundle.js.map +1 -1
- package/dist/projection/card/Card.d.ts +1 -1
- package/dist/projection/card/Card.d.ts.map +1 -1
- package/dist/projection/card/Card.js +19 -11
- package/dist/projection/card/Card.js.map +1 -1
- package/dist/projection/card/CardForm.d.ts +7 -0
- package/dist/projection/card/CardForm.d.ts.map +1 -0
- package/dist/projection/card/CardForm.js +2 -0
- package/dist/projection/card/CardForm.js.map +1 -0
- package/dist/projection/card/CardForms.d.ts +10 -0
- package/dist/projection/card/CardForms.d.ts.map +1 -0
- package/dist/projection/card/CardForms.js +12 -0
- package/dist/projection/card/CardForms.js.map +1 -0
- package/dist/projection/card/Change.d.ts +2 -2
- package/dist/projection/card/Change.d.ts.map +1 -1
- package/dist/projection/card/Diff.d.ts.map +1 -1
- package/dist/projection/card/Diff.js +36 -39
- package/dist/projection/card/Diff.js.map +1 -1
- package/dist/projection/card/FieldExtension.d.ts +4 -2
- package/dist/projection/card/FieldExtension.d.ts.map +1 -1
- package/dist/projection/card/RoleDescriptor.d.ts +9 -2
- package/dist/projection/card/RoleDescriptor.d.ts.map +1 -1
- package/dist/projection/card/RoleDescriptor.js +40 -1
- package/dist/projection/card/RoleDescriptor.js.map +1 -1
- package/dist/projection/card/admission.d.ts +0 -14
- package/dist/projection/card/admission.d.ts.map +1 -1
- package/dist/projection/card/admission.js +2 -21
- package/dist/projection/card/admission.js.map +1 -1
- package/dist/validator/FieldDeclarationValidator.d.ts.map +1 -1
- package/dist/validator/FieldDeclarationValidator.js +5 -17
- package/dist/validator/FieldDeclarationValidator.js.map +1 -1
- package/dist/validator/FieldValueValidator.d.ts +3 -3
- package/dist/validator/FieldValueValidator.d.ts.map +1 -1
- package/dist/validator/FieldValueValidator.js +18 -35
- package/dist/validator/FieldValueValidator.js.map +1 -1
- package/dist/validator/InputValidator.d.ts +3 -0
- package/dist/validator/InputValidator.d.ts.map +1 -1
- package/dist/validator/InputValidator.js +28 -31
- package/dist/validator/InputValidator.js.map +1 -1
- package/dist/validator/JsonSchemaValidator.d.ts +23 -0
- package/dist/validator/JsonSchemaValidator.d.ts.map +1 -0
- package/dist/validator/JsonSchemaValidator.js +113 -0
- package/dist/validator/JsonSchemaValidator.js.map +1 -0
- package/dist/vocabulary/primitive/list.d.ts.map +1 -1
- package/dist/vocabulary/primitive/list.js +2 -1
- package/dist/vocabulary/primitive/list.js.map +1 -1
- package/dist/vocabulary/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary/vocabulary.js +9 -6
- package/dist/vocabulary/vocabulary.js.map +1 -1
- package/package.json +1 -1
- package/src/Schema.ts +6 -4
- package/src/SchemaConstructor.ts +4 -4
- package/src/SchemaDefinition.ts +2 -1
- package/src/SchemaError.ts +7 -0
- package/src/SchemaView.ts +1 -1
- package/src/axis/Axes.ts +34 -0
- package/src/axis/Axis.ts +5 -20
- package/src/axis/boundary/Boundary.ts +26 -13
- package/src/axis/boundary/Decoder.ts +5 -4
- package/src/axis/lifecycle/Generators.ts +6 -18
- package/src/axis/lifecycle/Lifecycle.ts +41 -19
- package/src/axis/lifecycle/apply.ts +13 -21
- package/src/axis/role/Role.ts +35 -19
- package/src/axis/shape/Shape.ts +3 -3
- package/src/axis/shape/{Formats.ts → StringFormats.ts} +2 -2
- package/src/entity/EntityAdapterSet.ts +3 -2
- package/src/entity.ts +0 -1
- package/src/field/Field.ts +23 -12
- package/src/field/FieldFormat.ts +18 -0
- package/src/field/FieldSet.ts +5 -3
- package/src/field/FougereFieldAxes.ts +2 -0
- package/src/field/Meta.ts +5 -3
- package/src/{Values.ts → field/Values.ts} +2 -2
- package/src/index.ts +8 -3
- package/src/lib/Format.ts +139 -0
- package/src/lib/JsonSchema.ts +1 -0
- package/src/lib/Registry.ts +18 -9
- package/src/lib/ValidationResult.ts +8 -0
- package/src/lib/Verdict.ts +10 -0
- package/src/projection/Cases.ts +61 -57
- package/src/projection/Visibility.ts +22 -0
- package/src/projection/card/Bundle.ts +2 -1
- package/src/projection/card/Card.ts +24 -13
- package/src/projection/card/CardForm.ts +8 -0
- package/src/projection/card/CardForms.ts +13 -0
- package/src/projection/card/Change.ts +2 -2
- package/src/projection/card/Diff.ts +44 -44
- package/src/projection/card/FieldExtension.ts +5 -2
- package/src/projection/card/RoleDescriptor.ts +48 -2
- package/src/projection/card/admission.ts +2 -34
- package/src/validator/FieldDeclarationValidator.ts +5 -17
- package/src/validator/FieldValueValidator.ts +22 -46
- package/src/validator/InputValidator.ts +30 -32
- package/src/validator/JsonSchemaValidator.ts +142 -0
- package/src/vocabulary/primitive/list.ts +2 -1
- package/src/vocabulary/vocabulary.ts +9 -6
- package/dist/PartialValues.d.ts +0 -4
- package/dist/PartialValues.d.ts.map +0 -1
- package/dist/PartialValues.js +0 -2
- package/dist/PartialValues.js.map +0 -1
- package/dist/Values.d.ts +0 -6
- package/dist/Values.d.ts.map +0 -1
- package/dist/Values.js.map +0 -1
- package/dist/axis/boundary/Boundaries.d.ts +0 -17
- package/dist/axis/boundary/Boundaries.d.ts.map +0 -1
- package/dist/axis/boundary/Boundaries.js +0 -25
- package/dist/axis/boundary/Boundaries.js.map +0 -1
- package/dist/axis/boundary/BoundaryAxis.d.ts +0 -4
- package/dist/axis/boundary/BoundaryAxis.d.ts.map +0 -1
- package/dist/axis/boundary/BoundaryAxis.js +0 -30
- package/dist/axis/boundary/BoundaryAxis.js.map +0 -1
- package/dist/axis/boundary/BoundaryRef.d.ts +0 -3
- package/dist/axis/boundary/BoundaryRef.d.ts.map +0 -1
- package/dist/axis/boundary/BoundaryRef.js +0 -2
- package/dist/axis/boundary/BoundaryRef.js.map +0 -1
- package/dist/axis/boundary/BoundaryRules.d.ts +0 -9
- package/dist/axis/boundary/BoundaryRules.d.ts.map +0 -1
- package/dist/axis/boundary/BoundaryRules.js +0 -2
- package/dist/axis/boundary/BoundaryRules.js.map +0 -1
- package/dist/axis/lifecycle/Clock.d.ts +0 -18
- package/dist/axis/lifecycle/Clock.d.ts.map +0 -1
- package/dist/axis/lifecycle/Clock.js +0 -25
- package/dist/axis/lifecycle/Clock.js.map +0 -1
- package/dist/axis/lifecycle/LifecycleAxis.d.ts +0 -4
- package/dist/axis/lifecycle/LifecycleAxis.d.ts.map +0 -1
- package/dist/axis/lifecycle/LifecycleAxis.js +0 -52
- package/dist/axis/lifecycle/LifecycleAxis.js.map +0 -1
- package/dist/axis/lifecycle/LifecycleRules.d.ts +0 -12
- package/dist/axis/lifecycle/LifecycleRules.d.ts.map +0 -1
- package/dist/axis/lifecycle/LifecycleRules.js +0 -3
- package/dist/axis/lifecycle/LifecycleRules.js.map +0 -1
- package/dist/axis/role/RoleAxis.d.ts +0 -5
- package/dist/axis/role/RoleAxis.d.ts.map +0 -1
- package/dist/axis/role/RoleAxis.js +0 -93
- package/dist/axis/role/RoleAxis.js.map +0 -1
- package/dist/axis/role/RoleRules.d.ts +0 -8
- package/dist/axis/role/RoleRules.d.ts.map +0 -1
- package/dist/axis/role/RoleRules.js +0 -2
- package/dist/axis/role/RoleRules.js.map +0 -1
- package/dist/axis/shape/Formats.d.ts.map +0 -1
- package/dist/axis/shape/Formats.js.map +0 -1
- package/dist/lib/Checked.d.ts +0 -11
- package/dist/lib/Checked.d.ts.map +0 -1
- package/dist/lib/Checked.js +0 -2
- package/dist/lib/Checked.js.map +0 -1
- package/dist/projection/card/RelationDescriptor.d.ts +0 -5
- package/dist/projection/card/RelationDescriptor.d.ts.map +0 -1
- package/dist/projection/card/RelationDescriptor.js +0 -2
- package/dist/projection/card/RelationDescriptor.js.map +0 -1
- package/dist/projection/standard.d.ts +0 -14
- package/dist/projection/standard.d.ts.map +0 -1
- package/dist/projection/standard.js +0 -2
- package/dist/projection/standard.js.map +0 -1
- package/dist/validator/AdapterFieldValidator.d.ts +0 -14
- package/dist/validator/AdapterFieldValidator.d.ts.map +0 -1
- package/dist/validator/AdapterFieldValidator.js +0 -36
- package/dist/validator/AdapterFieldValidator.js.map +0 -1
- package/src/PartialValues.ts +0 -4
- package/src/axis/boundary/Boundaries.ts +0 -36
- package/src/axis/boundary/BoundaryAxis.ts +0 -32
- package/src/axis/boundary/BoundaryRef.ts +0 -3
- package/src/axis/boundary/BoundaryRules.ts +0 -4
- package/src/axis/lifecycle/Clock.ts +0 -26
- package/src/axis/lifecycle/LifecycleAxis.ts +0 -55
- package/src/axis/lifecycle/LifecycleRules.ts +0 -9
- package/src/axis/role/RoleAxis.ts +0 -104
- package/src/axis/role/RoleRules.ts +0 -8
- package/src/lib/Checked.ts +0 -5
- package/src/projection/card/RelationDescriptor.ts +0 -3
- package/src/projection/standard.ts +0 -13
- package/src/validator/AdapterFieldValidator.ts +0 -40
- /package/dist/{Values.js → field/Values.js} +0 -0
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { Axis } from '../Axis.js';
|
|
2
|
-
import type { Resolver } from '../Resolver.js';
|
|
3
|
-
import { refuse, oneOfTokens } from '../../projection/card/admission.js';
|
|
4
|
-
import { isObject, lowerFirst, shown } from '../../lib/utils.js';
|
|
5
|
-
import type { ValidationError } from '../../lib/ValidationError.js';
|
|
6
|
-
import { type EntityConstructor } from './EntityConstructor.js';
|
|
7
|
-
import { ON_DELETE, RELATION_KINDS, type Relation } from './Relation.js';
|
|
8
|
-
import { type RoleRules } from './RoleRules.js';
|
|
9
|
-
import type { RoleDescriptor } from '../../projection/card/RoleDescriptor.js';
|
|
10
|
-
|
|
11
|
-
export const roleAxis: Axis<RoleRules, RoleDescriptor> = {
|
|
12
|
-
slot: 'role',
|
|
13
|
-
|
|
14
|
-
validator(value, errors) {
|
|
15
|
-
if (!isObject(value)) {
|
|
16
|
-
errors.push({ path: ['role'], message: `Expected an object — got ${shown(value)}` });
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
for (const flag of ['primary', 'index', 'unique'] as const) {
|
|
20
|
-
if (value[flag] !== undefined && typeof value[flag] !== 'boolean') {
|
|
21
|
-
errors.push({
|
|
22
|
-
path: ['role', flag],
|
|
23
|
-
message: `Expected a boolean — got ${shown(value[flag])}`,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (value.relation !== undefined) validateRelation(value.relation, errors);
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
/** A card carries the target's NAME: a class cannot cross a process boundary. */
|
|
31
|
-
describe(role, key) {
|
|
32
|
-
const descriptor: Mutable<RoleDescriptor> = {};
|
|
33
|
-
if (role.primary) descriptor.primary = true;
|
|
34
|
-
if (role.unique) descriptor.unique = [[key]];
|
|
35
|
-
if (role.index) descriptor.index = true;
|
|
36
|
-
if (role.relation) {
|
|
37
|
-
const target = role.relation.to() as { name?: string };
|
|
38
|
-
descriptor.relation = {
|
|
39
|
-
to: lowerFirst(target.name ?? ''),
|
|
40
|
-
kind: role.relation.kind,
|
|
41
|
-
...(role.relation.onDelete ? { onDelete: role.relation.onDelete } : {}),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return Object.keys(descriptor).length ? descriptor : undefined;
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
reconstruct(wire, resolve?: Resolver) {
|
|
48
|
-
const rules: RoleRules = {};
|
|
49
|
-
if (wire.primary) rules.primary = true;
|
|
50
|
-
if (wire.unique?.some((group) => group.length === 1)) rules.unique = true;
|
|
51
|
-
if (wire.index) rules.index = true;
|
|
52
|
-
if (wire.relation) {
|
|
53
|
-
// `validator` cannot serve here: it demands `() => Post` where a card carries a name.
|
|
54
|
-
if (!oneOfTokens(wire.relation.kind, RELATION_KINDS)) {
|
|
55
|
-
refuse(
|
|
56
|
-
`role.relation.kind is ${JSON.stringify(wire.relation.kind)}`,
|
|
57
|
-
`Expected one of ${RELATION_KINDS.join(', ')}.`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
if (wire.relation.onDelete !== undefined && !oneOfTokens(wire.relation.onDelete, ON_DELETE)) {
|
|
61
|
-
refuse(
|
|
62
|
-
`role.relation.onDelete is ${JSON.stringify(wire.relation.onDelete)}`,
|
|
63
|
-
`Expected one of ${ON_DELETE.join(', ')}.`,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
const name = wire.relation.to;
|
|
67
|
-
rules.relation = {
|
|
68
|
-
to: () => (resolve?.(name) ?? ({ name } as unknown)) as EntityConstructor,
|
|
69
|
-
kind: wire.relation.kind as Relation['kind'],
|
|
70
|
-
...(wire.relation.onDelete ? { onDelete: wire.relation.onDelete as Relation['onDelete'] } : {}),
|
|
71
|
-
} as RoleRules['relation'];
|
|
72
|
-
}
|
|
73
|
-
return rules;
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Judges a relation where `to` is a thunk; a card states a NAME, resolved by `toSchema` first.
|
|
79
|
-
* FR : juge une relation dont `to` est une fonction ; une carte y met un NOM, résolu avant.
|
|
80
|
-
* `{ to: User, kind: 'one' }` → `Expected a function returning the target entity, … () => Post`
|
|
81
|
-
*/
|
|
82
|
-
function validateRelation(relation: unknown, errors: ValidationError[]): void {
|
|
83
|
-
if (!isObject(relation)) {
|
|
84
|
-
errors.push({ path: ['role', 'relation'], message: `Expected an object — got ${shown(relation)}` });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (!oneOfTokens(relation.kind, RELATION_KINDS)) {
|
|
88
|
-
errors.push({
|
|
89
|
-
path: ['role', 'relation', 'kind'],
|
|
90
|
-
message: `Expected 'one' or 'many' — got ${shown(relation.kind)}`,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
if (typeof relation.to !== 'function') {
|
|
94
|
-
errors.push({ path: ['role', 'relation', 'to'], message: 'Expected a function returning the target entity, such as () => Post' });
|
|
95
|
-
}
|
|
96
|
-
if (relation.onDelete !== undefined && !oneOfTokens(relation.onDelete, ON_DELETE)) {
|
|
97
|
-
errors.push({
|
|
98
|
-
path: ['role', 'relation', 'onDelete'],
|
|
99
|
-
message: `Expected 'cascade', 'restrict' or 'set null' — got ${shown(relation.onDelete)}`,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
type Mutable<T> = { -readonly [K in keyof T]: T[K] };
|
package/src/lib/Checked.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Standard Schema interface, from the package that owns it.
|
|
3
|
-
*
|
|
4
|
-
* This file used to CARRY the spec — 47 lines of hand-copied interface — and the copy had
|
|
5
|
-
* silently fallen a version behind: v1.1 gave `Props` a base it extends (`StandardTypedV1`)
|
|
6
|
-
* and gave `validate` a second `options` parameter. Nothing broke, because a realization may
|
|
7
|
-
* ignore an optional argument, which is exactly why nobody noticed. A standard is owned by
|
|
8
|
-
* whoever publishes it; the package is types only (`index.js` is zero bytes), so importing
|
|
9
|
-
* it costs a browser nothing.
|
|
10
|
-
*
|
|
11
|
-
* Documented: [Standard Schema](https://fougere.dev/docs/schema/standard-schema).
|
|
12
|
-
*/
|
|
13
|
-
export type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Validator } from '@cfworker/json-schema';
|
|
2
|
-
import type { Shape } from '../axis/shape/Shape.js';
|
|
3
|
-
import { isObject } from '../lib/utils.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The format is DATA, not a TypeScript interface: an interface is erased before a JS
|
|
7
|
-
* caller, a config or a card from another language could be measured against it.
|
|
8
|
-
*/
|
|
9
|
-
export class AdapterFieldValidator {
|
|
10
|
-
private constructor(private readonly validator: Validator) {}
|
|
11
|
-
|
|
12
|
-
/** Compiled once, at the adapter's own module load. */
|
|
13
|
-
static of(format: Shape): AdapterFieldValidator {
|
|
14
|
-
return new AdapterFieldValidator(new Validator(format as object, '2020-12', true));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** `Post.adapters.sql.body.columnType: Property "postgre" does not match …` */
|
|
18
|
-
assert(entries: unknown, path: string): void {
|
|
19
|
-
if (entries === undefined) return;
|
|
20
|
-
|
|
21
|
-
if (!isObject(entries)) {
|
|
22
|
-
throw new Error(
|
|
23
|
-
`${path}: expected an object keyed by field name, got ${typeof entries}.`,
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
for (const [field, entry] of Object.entries(entries)) {
|
|
28
|
-
const verdict = this.validator.validate(entry);
|
|
29
|
-
if (verdict.valid) continue;
|
|
30
|
-
|
|
31
|
-
// The engine reports outermost first and ends on `False boolean schema`, which names
|
|
32
|
-
// nothing. The last unit above that one is the one carrying the offending key.
|
|
33
|
-
const units = verdict.errors.filter((unit) => unit.keyword !== 'false');
|
|
34
|
-
const failure = units[units.length - 1] ?? verdict.errors[0];
|
|
35
|
-
const nested = (failure?.instanceLocation ?? '#').slice(1).replaceAll('/', '.');
|
|
36
|
-
|
|
37
|
-
throw new Error(`${path}.${field}${nested}: ${failure?.error ?? 'does not match the format'}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
File without changes
|