@fougere/schema 0.2.0-alpha.1 → 0.3.0-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/EntityDeclarations.d.ts +22 -0
- package/dist/EntityDeclarations.d.ts.map +1 -0
- package/dist/EntityDeclarations.js +19 -0
- package/dist/EntityDeclarations.js.map +1 -0
- package/dist/Field.d.ts +21 -0
- package/dist/Field.d.ts.map +1 -0
- package/dist/Field.js +50 -0
- package/dist/Field.js.map +1 -0
- package/dist/Schema.d.ts +67 -0
- package/dist/Schema.d.ts.map +1 -0
- package/dist/Schema.js +152 -0
- package/dist/Schema.js.map +1 -0
- package/dist/SchemaView.d.ts +18 -0
- package/dist/SchemaView.d.ts.map +1 -0
- package/dist/SchemaView.js +2 -0
- package/dist/SchemaView.js.map +1 -0
- package/dist/axis/Axis.d.ts +10 -0
- package/dist/axis/Axis.d.ts.map +1 -0
- package/dist/axis/Axis.js +9 -0
- package/dist/axis/Axis.js.map +1 -0
- package/dist/axis/Meta.d.ts +4 -0
- package/dist/axis/Meta.d.ts.map +1 -0
- package/dist/axis/Meta.js +2 -0
- package/dist/axis/Meta.js.map +1 -0
- package/dist/axis/boundary/Boundaries.d.ts +20 -0
- package/dist/axis/boundary/Boundaries.d.ts.map +1 -0
- package/dist/axis/boundary/Boundaries.js +31 -0
- package/dist/axis/boundary/Boundaries.js.map +1 -0
- package/dist/axis/boundary/Boundary.d.ts +26 -0
- package/dist/axis/boundary/Boundary.d.ts.map +1 -0
- package/dist/axis/boundary/Boundary.js +53 -0
- package/dist/axis/boundary/Boundary.js.map +1 -0
- package/dist/axis/boundary/axis.d.ts +4 -0
- package/dist/axis/boundary/axis.d.ts.map +1 -0
- package/dist/axis/boundary/axis.js +29 -0
- package/dist/axis/boundary/axis.js.map +1 -0
- package/dist/axis/lifecycle/Generators.d.ts +4 -0
- package/dist/axis/lifecycle/Generators.d.ts.map +1 -0
- package/dist/axis/lifecycle/Generators.js +8 -0
- package/dist/axis/lifecycle/Generators.js.map +1 -0
- package/dist/axis/lifecycle/Lifecycle.d.ts +28 -0
- package/dist/axis/lifecycle/Lifecycle.d.ts.map +1 -0
- package/dist/axis/lifecycle/Lifecycle.js +38 -0
- package/dist/axis/lifecycle/Lifecycle.js.map +1 -0
- package/dist/axis/lifecycle/apply.d.ts +8 -0
- package/dist/axis/lifecycle/apply.d.ts.map +1 -0
- package/dist/axis/lifecycle/apply.js +72 -0
- package/dist/axis/lifecycle/apply.js.map +1 -0
- package/dist/axis/lifecycle/axis.d.ts +4 -0
- package/dist/axis/lifecycle/axis.d.ts.map +1 -0
- package/dist/axis/lifecycle/axis.js +46 -0
- package/dist/axis/lifecycle/axis.js.map +1 -0
- package/dist/axis/role/Relation.d.ts +10 -0
- package/dist/axis/role/Relation.d.ts.map +1 -0
- package/dist/axis/role/Relation.js +6 -0
- package/dist/axis/role/Relation.js.map +1 -0
- package/dist/axis/role/Role.d.ts +38 -0
- package/dist/axis/role/Role.d.ts.map +1 -0
- package/dist/axis/role/Role.js +50 -0
- package/dist/axis/role/Role.js.map +1 -0
- package/dist/axis/role/axis.d.ts +5 -0
- package/dist/axis/role/axis.d.ts.map +1 -0
- package/dist/axis/role/axis.js +101 -0
- package/dist/axis/role/axis.js.map +1 -0
- package/dist/axis/shape/Formats.d.ts +8 -0
- package/dist/axis/shape/Formats.d.ts.map +1 -0
- package/dist/axis/shape/Formats.js +10 -0
- package/dist/axis/shape/Formats.js.map +1 -0
- package/dist/axis/shape/Shape.d.ts +58 -0
- package/dist/axis/shape/Shape.d.ts.map +1 -0
- package/dist/axis/shape/Shape.js +52 -0
- package/dist/axis/shape/Shape.js.map +1 -0
- package/dist/card/Descriptor.d.ts +55 -0
- package/dist/card/Descriptor.d.ts.map +1 -0
- package/dist/card/Descriptor.js +2 -0
- package/dist/card/Descriptor.js.map +1 -0
- package/dist/card/describe.d.ts +12 -0
- package/dist/card/describe.d.ts.map +1 -0
- package/dist/card/describe.js +83 -0
- package/dist/card/describe.js.map +1 -0
- package/dist/card/diff.d.ts +140 -0
- package/dist/card/diff.d.ts.map +1 -0
- package/dist/card/diff.js +123 -0
- package/dist/card/diff.js.map +1 -0
- package/dist/card/reconstruct.d.ts +11 -0
- package/dist/card/reconstruct.d.ts.map +1 -0
- package/dist/card/reconstruct.js +83 -0
- package/dist/card/reconstruct.js.map +1 -0
- package/dist/card/typescript.d.ts +17 -0
- package/dist/card/typescript.d.ts.map +1 -0
- package/dist/card/typescript.js +93 -0
- package/dist/card/typescript.js.map +1 -0
- package/dist/clean.d.ts +2 -0
- package/dist/clean.d.ts.map +1 -0
- package/dist/{projections/card.js → clean.js} +1 -2
- package/dist/clean.js.map +1 -0
- package/dist/constraint/FieldGroup.d.ts +21 -0
- package/dist/constraint/FieldGroup.d.ts.map +1 -0
- package/dist/constraint/FieldGroup.js +65 -0
- package/dist/constraint/FieldGroup.js.map +1 -0
- package/dist/constraint/Unique.d.ts +4 -0
- package/dist/constraint/Unique.d.ts.map +1 -0
- package/dist/constraint/Unique.js +4 -0
- package/dist/constraint/Unique.js.map +1 -0
- package/dist/entity.d.ts +4 -116
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +13 -289
- package/dist/entity.js.map +1 -1
- package/dist/index.d.ts +35 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -26
- package/dist/index.js.map +1 -1
- package/dist/judge/Judge.d.ts +14 -0
- package/dist/judge/Judge.d.ts.map +1 -0
- package/dist/judge/Judge.js +161 -0
- package/dist/judge/Judge.js.map +1 -0
- package/dist/judge/cases.d.ts +50 -0
- package/dist/judge/cases.d.ts.map +1 -0
- package/dist/judge/cases.js +100 -0
- package/dist/judge/cases.js.map +1 -0
- package/dist/judge/form.d.ts +11 -0
- package/dist/judge/form.d.ts.map +1 -0
- package/dist/judge/form.js +18 -0
- package/dist/judge/form.js.map +1 -0
- package/dist/judge/options.d.ts +4 -0
- package/dist/judge/options.d.ts.map +1 -0
- package/dist/judge/options.js +2 -0
- package/dist/judge/options.js.map +1 -0
- package/dist/judge/result.d.ts +17 -0
- package/dist/judge/result.d.ts.map +1 -0
- package/dist/judge/result.js +2 -0
- package/dist/judge/result.js.map +1 -0
- package/dist/name.d.ts +1 -14
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -14
- package/dist/name.js.map +1 -1
- package/dist/projection/encode.d.ts +3 -0
- package/dist/projection/encode.d.ts.map +1 -0
- package/dist/projection/encode.js +19 -0
- package/dist/projection/encode.js.map +1 -0
- package/dist/projection/io.d.ts +4 -0
- package/dist/projection/io.d.ts.map +1 -0
- package/dist/projection/io.js +29 -0
- package/dist/projection/io.js.map +1 -0
- package/dist/projection/source.d.ts +7 -0
- package/dist/projection/source.d.ts.map +1 -0
- package/dist/projection/source.js +11 -0
- package/dist/projection/source.js.map +1 -0
- package/dist/{projections → projection}/standard.d.ts +0 -8
- package/dist/projection/standard.d.ts.map +1 -0
- package/dist/projection/standard.js +2 -0
- package/dist/projection/standard.js.map +1 -0
- package/dist/same.d.ts +6 -0
- package/dist/same.d.ts.map +1 -0
- package/dist/same.js +35 -0
- package/dist/same.js.map +1 -0
- package/dist/vocabulary/bool.d.ts +1 -1
- package/dist/vocabulary/bool.d.ts.map +1 -1
- package/dist/vocabulary/bool.js +2 -2
- package/dist/vocabulary/bool.js.map +1 -1
- package/dist/vocabulary/created.d.ts +2 -12
- package/dist/vocabulary/created.d.ts.map +1 -1
- package/dist/vocabulary/created.js +3 -14
- package/dist/vocabulary/created.js.map +1 -1
- package/dist/vocabulary/date.d.ts +1 -1
- package/dist/vocabulary/date.d.ts.map +1 -1
- package/dist/vocabulary/date.js +2 -2
- package/dist/vocabulary/date.js.map +1 -1
- package/dist/vocabulary/email.d.ts +1 -2
- package/dist/vocabulary/email.d.ts.map +1 -1
- package/dist/vocabulary/email.js +0 -1
- package/dist/vocabulary/email.js.map +1 -1
- package/dist/vocabulary/immutable.d.ts +2 -8
- package/dist/vocabulary/immutable.d.ts.map +1 -1
- package/dist/vocabulary/immutable.js +4 -10
- package/dist/vocabulary/immutable.js.map +1 -1
- package/dist/vocabulary/indexed.d.ts +2 -18
- package/dist/vocabulary/indexed.d.ts.map +1 -1
- package/dist/vocabulary/indexed.js +2 -20
- package/dist/vocabulary/indexed.js.map +1 -1
- package/dist/vocabulary/json.d.ts +3 -16
- package/dist/vocabulary/json.d.ts.map +1 -1
- package/dist/vocabulary/json.js +12 -9
- package/dist/vocabulary/json.js.map +1 -1
- package/dist/vocabulary/list.d.ts +2 -16
- package/dist/vocabulary/list.d.ts.map +1 -1
- package/dist/vocabulary/list.js +3 -15
- package/dist/vocabulary/list.js.map +1 -1
- package/dist/vocabulary/many.d.ts +2 -6
- package/dist/vocabulary/many.d.ts.map +1 -1
- package/dist/vocabulary/many.js +4 -7
- package/dist/vocabulary/many.js.map +1 -1
- package/dist/vocabulary/nullable.d.ts +2 -8
- package/dist/vocabulary/nullable.d.ts.map +1 -1
- package/dist/vocabulary/nullable.js +5 -12
- package/dist/vocabulary/nullable.js.map +1 -1
- package/dist/vocabulary/number.d.ts +1 -1
- package/dist/vocabulary/number.d.ts.map +1 -1
- package/dist/vocabulary/number.js +2 -2
- package/dist/vocabulary/number.js.map +1 -1
- package/dist/vocabulary/oneOf.d.ts +1 -8
- package/dist/vocabulary/oneOf.d.ts.map +1 -1
- package/dist/vocabulary/oneOf.js +2 -2
- package/dist/vocabulary/oneOf.js.map +1 -1
- package/dist/vocabulary/optional.d.ts +2 -9
- package/dist/vocabulary/optional.d.ts.map +1 -1
- package/dist/vocabulary/optional.js +6 -14
- package/dist/vocabulary/optional.js.map +1 -1
- package/dist/vocabulary/primary.d.ts +4 -17
- package/dist/vocabulary/primary.d.ts.map +1 -1
- package/dist/vocabulary/primary.js +10 -13
- package/dist/vocabulary/primary.js.map +1 -1
- package/dist/vocabulary/readOnly.d.ts +2 -9
- package/dist/vocabulary/readOnly.d.ts.map +1 -1
- package/dist/vocabulary/readOnly.js +5 -11
- package/dist/vocabulary/readOnly.js.map +1 -1
- package/dist/vocabulary/ref.d.ts +2 -7
- package/dist/vocabulary/ref.d.ts.map +1 -1
- package/dist/vocabulary/ref.js +3 -8
- package/dist/vocabulary/ref.js.map +1 -1
- package/dist/vocabulary/text.d.ts +2 -2
- package/dist/vocabulary/text.d.ts.map +1 -1
- package/dist/vocabulary/text.js +2 -2
- package/dist/vocabulary/text.js.map +1 -1
- package/dist/vocabulary/unique.d.ts +2 -22
- package/dist/vocabulary/unique.d.ts.map +1 -1
- package/dist/vocabulary/unique.js +5 -24
- package/dist/vocabulary/unique.js.map +1 -1
- package/dist/vocabulary/updated.d.ts +2 -7
- package/dist/vocabulary/updated.d.ts.map +1 -1
- package/dist/vocabulary/updated.js +1 -7
- package/dist/vocabulary/updated.js.map +1 -1
- package/dist/vocabulary/url.d.ts +1 -2
- package/dist/vocabulary/url.d.ts.map +1 -1
- package/dist/vocabulary/url.js +0 -1
- package/dist/vocabulary/url.js.map +1 -1
- package/dist/vocabulary/vocabulary.d.ts +5 -0
- package/dist/vocabulary/vocabulary.d.ts.map +1 -0
- package/dist/vocabulary/vocabulary.js +31 -0
- package/dist/vocabulary/vocabulary.js.map +1 -0
- package/dist/vocabulary/writeOnly.d.ts +2 -8
- package/dist/vocabulary/writeOnly.d.ts.map +1 -1
- package/dist/vocabulary/writeOnly.js +5 -10
- package/dist/vocabulary/writeOnly.js.map +1 -1
- package/package.json +2 -2
- package/dist/field/boundary.d.ts +0 -86
- package/dist/field/boundary.d.ts.map +0 -1
- package/dist/field/boundary.js +0 -94
- package/dist/field/boundary.js.map +0 -1
- package/dist/field/field.d.ts +0 -64
- package/dist/field/field.d.ts.map +0 -1
- package/dist/field/field.js +0 -28
- package/dist/field/field.js.map +0 -1
- package/dist/field/index.d.ts +0 -7
- package/dist/field/index.d.ts.map +0 -1
- package/dist/field/index.js +0 -9
- package/dist/field/index.js.map +0 -1
- package/dist/field/lifecycle.d.ts +0 -40
- package/dist/field/lifecycle.d.ts.map +0 -1
- package/dist/field/lifecycle.js +0 -27
- package/dist/field/lifecycle.js.map +0 -1
- package/dist/field/meta.d.ts +0 -9
- package/dist/field/meta.d.ts.map +0 -1
- package/dist/field/meta.js +0 -7
- package/dist/field/meta.js.map +0 -1
- package/dist/field/role.d.ts +0 -54
- package/dist/field/role.d.ts.map +0 -1
- package/dist/field/role.js +0 -55
- package/dist/field/role.js.map +0 -1
- package/dist/field/shape.d.ts +0 -77
- package/dist/field/shape.d.ts.map +0 -1
- package/dist/field/shape.js +0 -49
- package/dist/field/shape.js.map +0 -1
- package/dist/hints.d.ts +0 -33
- package/dist/hints.d.ts.map +0 -1
- package/dist/hints.js +0 -2
- package/dist/hints.js.map +0 -1
- package/dist/projections/card.d.ts +0 -117
- package/dist/projections/card.d.ts.map +0 -1
- package/dist/projections/card.js.map +0 -1
- package/dist/projections/describe.d.ts +0 -25
- package/dist/projections/describe.d.ts.map +0 -1
- package/dist/projections/describe.js +0 -136
- package/dist/projections/describe.js.map +0 -1
- package/dist/projections/encode.d.ts +0 -11
- package/dist/projections/encode.d.ts.map +0 -1
- package/dist/projections/encode.js +0 -26
- package/dist/projections/encode.js.map +0 -1
- package/dist/projections/io.d.ts +0 -30
- package/dist/projections/io.d.ts.map +0 -1
- package/dist/projections/io.js +0 -52
- package/dist/projections/io.js.map +0 -1
- package/dist/projections/lifecycle.d.ts +0 -43
- package/dist/projections/lifecycle.d.ts.map +0 -1
- package/dist/projections/lifecycle.js +0 -115
- package/dist/projections/lifecycle.js.map +0 -1
- package/dist/projections/reconstruct.d.ts +0 -36
- package/dist/projections/reconstruct.d.ts.map +0 -1
- package/dist/projections/reconstruct.js +0 -149
- package/dist/projections/reconstruct.js.map +0 -1
- package/dist/projections/source.d.ts +0 -41
- package/dist/projections/source.d.ts.map +0 -1
- package/dist/projections/source.js +0 -37
- package/dist/projections/source.js.map +0 -1
- package/dist/projections/standard.d.ts.map +0 -1
- package/dist/projections/standard.js +0 -10
- package/dist/projections/standard.js.map +0 -1
- package/dist/projections/typescript.d.ts +0 -53
- package/dist/projections/typescript.d.ts.map +0 -1
- package/dist/projections/typescript.js +0 -184
- package/dist/projections/typescript.js.map +0 -1
- package/dist/projections/validation.d.ts +0 -57
- package/dist/projections/validation.d.ts.map +0 -1
- package/dist/projections/validation.js +0 -148
- package/dist/projections/validation.js.map +0 -1
- package/dist/unique.d.ts +0 -65
- package/dist/unique.d.ts.map +0 -1
- package/dist/unique.js +0 -80
- package/dist/unique.js.map +0 -1
package/dist/entity.js
CHANGED
|
@@ -1,291 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function asSchemaConstructor(impl) {
|
|
15
|
-
return impl;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Carry hints across a field-key transform — the schema-level twin of `cloneField`'s
|
|
19
|
-
* invariant: a derivation preserves everything it doesn't explicitly change. `transform`
|
|
20
|
-
* maps an old key to its new name, or to `undefined` when the field is dropped; each
|
|
21
|
-
* adapter's per-field hints follow their fields.
|
|
22
|
-
*/
|
|
23
|
-
function deriveHints(hints, transform) {
|
|
24
|
-
if (!hints)
|
|
25
|
-
return undefined;
|
|
26
|
-
const out = {};
|
|
27
|
-
for (const [adapter, perField] of Object.entries(hints)) {
|
|
28
|
-
if (!perField || typeof perField !== 'object')
|
|
29
|
-
continue;
|
|
30
|
-
const mapped = {};
|
|
31
|
-
for (const [key, hint] of Object.entries(perField)) {
|
|
32
|
-
const next = transform(key);
|
|
33
|
-
if (next !== undefined)
|
|
34
|
-
mapped[next] = hint;
|
|
35
|
-
}
|
|
36
|
-
if (Object.keys(mapped).length)
|
|
37
|
-
out[adapter] = mapped;
|
|
38
|
-
}
|
|
39
|
-
return Object.keys(out).length ? out : undefined;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Refuse a key the schema does not carry, naming it and what was expected — the twin of
|
|
43
|
-
* `assertListOptions` in `@fougere/core`, applied to the derivation algebra.
|
|
44
|
-
*
|
|
45
|
-
* `pick` skipped an unknown key and `omit` filtered on a key nothing matched, so a typo
|
|
46
|
-
* was silently obeyed. `pick('titel')` returned a view without the field, and — the
|
|
47
|
-
* dangerous half — `omit('ownerUserID')` removed NOTHING: the field stayed in the input
|
|
48
|
-
* view, so the façade's unknown-key refusal no longer applied to it, and a client could
|
|
49
|
-
* write the very field the view was written to close. Measured: the view accepted
|
|
50
|
-
* `ownerUserId: 'someone-else'`.
|
|
51
|
-
*
|
|
52
|
-
* TypeScript catches this at the call site when the key is a literal. It does not when
|
|
53
|
-
* the keys come from a variable, from JSON, or across a package boundary — and a view
|
|
54
|
-
* that quietly widens is not a thing to leave to the type-checker alone.
|
|
55
|
-
*/
|
|
56
|
-
function assertKnownKeys(operation, keys, fields) {
|
|
57
|
-
const strangers = keys.filter((key) => !(key in fields));
|
|
58
|
-
if (strangers.length === 0)
|
|
59
|
-
return;
|
|
60
|
-
throw new Error(`${operation}(): unknown field ${strangers.map((s) => `\`${s}\``).join(', ')}. ` +
|
|
61
|
-
`This schema carries ${Object.keys(fields).join(', ')}.`);
|
|
62
|
-
}
|
|
63
|
-
/** Create a schema constructor from a field record. */
|
|
64
|
-
/**
|
|
65
|
-
* The runtime name a derivation carries when no class declaration named it.
|
|
66
|
-
*
|
|
67
|
-
* `class Post extends entity({…}) {}` is named by its declaration; `User.pick('id')` has
|
|
68
|
-
* only the factory's own class to be named after. A reader — the scanner, notably — needs
|
|
69
|
-
* to tell one from the other, so the name is stamped from here rather than read off a
|
|
70
|
-
* class whose identifier someone could rename without noticing the other end.
|
|
71
|
-
*/
|
|
72
|
-
export const ANONYMOUS_SCHEMA_NAME = 'Schema';
|
|
73
|
-
export function createSchemaConstructor(fields, source, hints, opts = {}, unique) {
|
|
74
|
-
class Schema {
|
|
75
|
-
/** Trusted constructor — assigns already-shaped data. Validate untrusted input via `validate()`/`from()` first. */
|
|
76
|
-
constructor(data) {
|
|
77
|
-
if (data)
|
|
78
|
-
Object.assign(this, data);
|
|
79
|
-
}
|
|
80
|
-
static get ['~standard']() {
|
|
81
|
-
return {
|
|
82
|
-
version: 1,
|
|
83
|
-
vendor: 'fougere',
|
|
84
|
-
validate(value) {
|
|
85
|
-
const result = validateFields(fields, value, opts);
|
|
86
|
-
if (result.success) {
|
|
87
|
-
return { value: result.data };
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
issues: result.errors.map((e) => ({
|
|
91
|
-
message: e.message,
|
|
92
|
-
// ONE segment, not a split: `validateFields` joins with `.` only when it
|
|
93
|
-
// receives a `pathPrefix`, and no caller passes one — the recursion that
|
|
94
|
-
// parameter exists for is not written. So a path is always a single field
|
|
95
|
-
// name, and splitting it invented segments for a name legally spelled `a.b`.
|
|
96
|
-
// The day nested objects report their own path, this becomes a real split
|
|
97
|
-
// and the joining side has to say where the boundaries are.
|
|
98
|
-
path: e.path && e.path !== '.' ? [{ key: e.path }] : undefined,
|
|
99
|
-
})),
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
static source = source;
|
|
105
|
-
static getFields() {
|
|
106
|
-
return fields;
|
|
107
|
-
}
|
|
108
|
-
static getHints() {
|
|
109
|
-
return hints;
|
|
110
|
-
}
|
|
111
|
-
static getUnique() {
|
|
112
|
-
return unique;
|
|
113
|
-
}
|
|
114
|
-
static getOpts() {
|
|
115
|
-
return opts;
|
|
116
|
-
}
|
|
117
|
-
static validate(input) {
|
|
118
|
-
return validateFields(fields, input, opts);
|
|
119
|
-
}
|
|
120
|
-
static from(data) {
|
|
121
|
-
// Trusted projection: keep known keys, drop the rest. Runs the boundary's decode
|
|
122
|
-
// (the same wire→domain step validate() applies) so the returned value matches
|
|
123
|
-
// its declared type — a date-string in becomes the `Date` the type promises.
|
|
124
|
-
// Best-effort: a value that fails to decode is kept as-is rather than dropped.
|
|
125
|
-
const result = {};
|
|
126
|
-
for (const [key, field] of Object.entries(fields)) {
|
|
127
|
-
if (!(key in data))
|
|
128
|
-
continue;
|
|
129
|
-
const value = data[key];
|
|
130
|
-
if (value === null || value === undefined) {
|
|
131
|
-
result[key] = value;
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
const decoded = resolveBoundary(field).decode(value);
|
|
135
|
-
result[key] = 'error' in decoded ? value : decoded.value;
|
|
136
|
-
}
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
// Every derivation carries hints and opts — same invariant as cloneField, one
|
|
140
|
-
// level up: change the fields you mean, keep everything else the view holds.
|
|
141
|
-
//
|
|
142
|
-
// `source ?? this` records WHERE a view came from, once, at the first derivation:
|
|
143
|
-
// `this` is the class the static was called on (`Post`), and a view of a view keeps
|
|
144
|
-
// the origin rather than the intermediate. The slot existed and was only ever
|
|
145
|
-
// propagated — `entity()` passes `undefined` — so `describe` read an empty field and
|
|
146
|
-
// titled a view `Schema`, the anonymous class. One reader assumed it; now two do
|
|
147
|
-
// (GraphQL names `PostStatus` from it, so an input view and the type share one enum).
|
|
148
|
-
static pick(...keys) {
|
|
149
|
-
assertKnownKeys('pick', keys, fields);
|
|
150
|
-
const picked = {};
|
|
151
|
-
for (const key of keys) {
|
|
152
|
-
if (fields[key])
|
|
153
|
-
picked[key] = fields[key];
|
|
154
|
-
}
|
|
155
|
-
const survives = (k) => (keys.includes(k) ? k : undefined);
|
|
156
|
-
return createSchemaConstructor(deriveUniqueRoles(picked, survives), source ?? this, deriveHints(hints, survives), opts, deriveUnique(unique, survives));
|
|
157
|
-
}
|
|
158
|
-
static omit(...keys) {
|
|
159
|
-
assertKnownKeys('omit', keys, fields);
|
|
160
|
-
const omitted = {};
|
|
161
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
162
|
-
if (!keys.includes(key))
|
|
163
|
-
omitted[key] = value;
|
|
164
|
-
}
|
|
165
|
-
const survives = (k) => (keys.includes(k) ? undefined : k);
|
|
166
|
-
return createSchemaConstructor(deriveUniqueRoles(omitted, survives), source ?? this, deriveHints(hints, survives), opts, deriveUnique(unique, survives));
|
|
167
|
-
}
|
|
168
|
-
static partial() {
|
|
169
|
-
// patch mode: an unsent field is omitted ("don't touch"), enforced by
|
|
170
|
-
// ValidateOptions.patch — the fields themselves are untouched, so `null`
|
|
171
|
-
// stays legal only where the base field is nullable. partial() moves the
|
|
172
|
-
// presence axis, never the nullity axis.
|
|
173
|
-
return createSchemaConstructor({ ...fields }, source ?? this, hints, { ...opts, patch: true }, unique);
|
|
174
|
-
}
|
|
175
|
-
static extend(extra) {
|
|
176
|
-
return createSchemaConstructor({ ...fields, ...extra }, source ?? this, hints, opts, unique);
|
|
177
|
-
}
|
|
178
|
-
static named(name) {
|
|
179
|
-
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) {
|
|
180
|
-
throw new Error(`named(): \`${name}\` is not a valid class name.`);
|
|
181
|
-
}
|
|
182
|
-
// It renames in place, so it may only name what has no name. On a declared class
|
|
183
|
-
// `Post.named('Other')` would silently retarget its table, its GraphQL type and
|
|
184
|
-
// its registration key — every projection reads this name.
|
|
185
|
-
if (this.name !== ANONYMOUS_SCHEMA_NAME) {
|
|
186
|
-
throw new Error(`named(): \`${this.name}\` is already named by its class declaration.`);
|
|
187
|
-
}
|
|
188
|
-
Object.defineProperty(this, 'name', { value: name, configurable: true });
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
static rename(mapping) {
|
|
192
|
-
assertKnownKeys('rename', Object.keys(mapping), fields);
|
|
193
|
-
const renamed = {};
|
|
194
|
-
for (const [key, field] of Object.entries(fields)) {
|
|
195
|
-
renamed[mapping[key] ?? key] = field;
|
|
196
|
-
}
|
|
197
|
-
const remap = (k) => mapping[k] ?? k;
|
|
198
|
-
return createSchemaConstructor(deriveUniqueRoles(renamed, remap), source ?? this, deriveHints(hints, remap), opts, deriveUnique(unique, remap));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
Object.defineProperty(Schema, 'name', { value: ANONYMOUS_SCHEMA_NAME, configurable: true });
|
|
202
|
-
return asSchemaConstructor(Schema);
|
|
203
|
-
}
|
|
204
|
-
// ─── Public entry ───────────────────────────────
|
|
205
|
-
/**
|
|
206
|
-
* Define an entity — the factory that produces a schema-carrying class.
|
|
207
|
-
*
|
|
208
|
-
* ```ts
|
|
209
|
-
* class Post extends entity({ id: primary(), title: text({ min: 1 }) }) {}
|
|
210
|
-
*
|
|
211
|
-
* new Post({ id, title }) // real instance, data-typed (NOT a bag of Fields)
|
|
212
|
-
* Post.getFields() // metadata, no instantiation
|
|
213
|
-
* Post.pick('title') // derived view, same static API
|
|
214
|
-
* function publish(p: Post) // `Post` IS the data type — no Infer needed
|
|
215
|
-
* ```
|
|
216
|
-
*
|
|
217
|
-
* The class carries data + schema metadata only. No business behaviour lives on
|
|
218
|
-
* an entity — that belongs to handlers/commands (keeps form and behaviour apart).
|
|
219
|
-
*
|
|
220
|
-
* An optional 2nd argument carries per-consumer hints (see {@link Hints}) for the
|
|
221
|
-
* irreducible bits a neutral field can't express — only adapters present in the
|
|
222
|
-
* compilation are accepted; the field declarations themselves stay adapter-blind.
|
|
223
|
-
*/
|
|
224
|
-
export function entity(fields, declarations) {
|
|
225
|
-
// This is the only place that knows both the field KEYS and the entity's declarations,
|
|
226
|
-
// so it is where a composite group becomes readable on each member's role axis. The
|
|
227
|
-
// declaration remains the source — `getUnique()` still answers it.
|
|
228
|
-
const projected = projectUniqueOntoFields(fields, declarations?.unique);
|
|
229
|
-
assertDefaultsAreValid(projected);
|
|
230
|
-
return createSchemaConstructor(projected, undefined, declarations?.hints, {}, declarations?.unique);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* A declared default must satisfy its own shape — checked once, here.
|
|
234
|
-
*
|
|
235
|
-
* `applyCreate` writes it into every row without passing the client judge, which is
|
|
236
|
-
* correct: the judge asks "is what the CALLER sent legal", and this value comes from the
|
|
237
|
-
* author. But that means `text({ min: 5, default: 'ab' })` produced rows the entity's own
|
|
238
|
-
* `validate` refuses — silently on a store that judges nothing, as a constraint violation
|
|
239
|
-
* on SQL, as a validator error on MongoDB. Three symptoms, one cause, none of them naming
|
|
240
|
-
* it.
|
|
241
|
-
*
|
|
242
|
-
* The value is static and so is the shape, so the answer is static: it belongs at the
|
|
243
|
-
* declaration, not on every write. `oneOf` closes its own case in the type system; this
|
|
244
|
-
* catches what no type can — a bound, a pattern, a format.
|
|
245
|
-
*/
|
|
246
|
-
function assertDefaultsAreValid(fields) {
|
|
247
|
-
for (const [name, field] of Object.entries(fields)) {
|
|
248
|
-
const create = field.lifecycle?.create;
|
|
249
|
-
if (typeof create !== 'object' || create === null || !('value' in create))
|
|
250
|
-
continue;
|
|
251
|
-
const checked = checkValue(field, create.value);
|
|
252
|
-
if ('error' in checked) {
|
|
253
|
-
throw new Error(`Field '${name}': the declared default ${JSON.stringify(create.value)} `
|
|
254
|
-
+ `is not a legal value for it — ${checked.error}. It would be written into every row `
|
|
255
|
-
+ `without passing the judge.`);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Compose multiple entities/schemas into a single SchemaConstructor.
|
|
261
|
-
*
|
|
262
|
-
* ```ts
|
|
263
|
-
* class User extends compose(UserBase, Timestamps) {}
|
|
264
|
-
* class SearchPosts extends compose(Post.pick('title'), Pagination) {}
|
|
265
|
-
* ```
|
|
266
|
-
*
|
|
267
|
-
* One merge law for EVERYTHING a schema carries — fields, hints, opts: left to
|
|
268
|
-
* right, later sources override earlier ones on conflict (hints merge per adapter,
|
|
269
|
-
* per field key). Use .rename() before compose() to avoid field conflicts.
|
|
270
|
-
*/
|
|
271
|
-
export function compose(...sources) {
|
|
272
|
-
const merged = {};
|
|
273
|
-
const mergedHints = {};
|
|
274
|
-
let mergedOpts = {};
|
|
275
|
-
for (const source of sources) {
|
|
276
|
-
Object.assign(merged, source.getFields());
|
|
277
|
-
const carrier = source;
|
|
278
|
-
const hints = carrier.getHints?.();
|
|
279
|
-
if (hints) {
|
|
280
|
-
for (const [adapter, perField] of Object.entries(hints)) {
|
|
281
|
-
if (!perField || typeof perField !== 'object')
|
|
282
|
-
continue;
|
|
283
|
-
mergedHints[adapter] = { ...mergedHints[adapter], ...perField };
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
mergedOpts = { ...mergedOpts, ...carrier.getOpts?.() };
|
|
287
|
-
}
|
|
288
|
-
const hints = Object.keys(mergedHints).length ? mergedHints : undefined;
|
|
289
|
-
return asSchemaConstructor(createSchemaConstructor(merged, undefined, hints, mergedOpts));
|
|
1
|
+
import { Field } from './Field.js';
|
|
2
|
+
import { Unique } from './constraint/Unique.js';
|
|
3
|
+
import { Schema } from './Schema.js';
|
|
4
|
+
export function entity(originalFields, declarations) {
|
|
5
|
+
let fields = {};
|
|
6
|
+
for (const [key, field] of Object.entries(originalFields))
|
|
7
|
+
fields[key] = new Field(field, key);
|
|
8
|
+
for (const group of declarations?.unique ?? [])
|
|
9
|
+
fields = new Unique(group).onto(fields);
|
|
10
|
+
const schema = Schema.of(fields, undefined, declarations?.hints, {});
|
|
11
|
+
if (declarations?.previous)
|
|
12
|
+
Object.assign(schema, { previous: declarations.previous });
|
|
13
|
+
return schema;
|
|
290
14
|
}
|
|
291
15
|
//# sourceMappingURL=entity.js.map
|
package/dist/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAA0B,MAAM,aAAa,CAAC;AAE7D,MAAM,UAAU,MAAM,CACpB,cAAuB,EACvB,YAA0C;IAE1C,IAAI,MAAM,GAAW,EAAE,CAAC;IAExB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC;QACvD,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEtC,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,MAAM,IAAI,EAAE;QAC5C,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE1C,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,MAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IAChF,IAAI,YAAY,EAAE,QAAQ;QAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;IACvF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { type
|
|
4
|
-
export {
|
|
1
|
+
export { Field, type Fields } from './Field.js';
|
|
2
|
+
export { type Shape, Anatomy } from './axis/shape/Shape.js';
|
|
3
|
+
export { type StringFormat, type FormatPredicate, Formats } from './axis/shape/Formats.js';
|
|
4
|
+
export { Role, primaryFieldOf, type RoleRules } from './axis/role/Role.js';
|
|
5
|
+
export { type Relation, type EntityConstructor } from './axis/role/Relation.js';
|
|
6
|
+
export { Lifecycle, type LifecycleRules } from './axis/lifecycle/Lifecycle.js';
|
|
7
|
+
export { type GeneratorRef, registerGenerator } from './axis/lifecycle/Generators.js';
|
|
8
|
+
export { Boundary, type BoundaryRules, type BoundaryRef } from './axis/boundary/Boundary.js';
|
|
9
|
+
export { type Decoder, type Encoder, Boundaries } from './axis/boundary/Boundaries.js';
|
|
10
|
+
export { type Meta } from './axis/Meta.js';
|
|
11
|
+
export { FieldGroup } from './constraint/FieldGroup.js';
|
|
12
|
+
export { Unique } from './constraint/Unique.js';
|
|
13
|
+
export { Schema, ANONYMOUS_SCHEMA_NAME, type SchemaConstructor } from './Schema.js';
|
|
14
|
+
export { casesFor, holds, refusalBranches, type Case } from './judge/cases.js';
|
|
15
|
+
export { type SchemaView, type Row, type PartialRow } from './SchemaView.js';
|
|
16
|
+
export { type FougereHints, type Hints } from './EntityDeclarations.js';
|
|
17
|
+
export { same } from './same.js';
|
|
5
18
|
export { primary } from './vocabulary/primary.js';
|
|
6
|
-
export { text
|
|
19
|
+
export { text } from './vocabulary/text.js';
|
|
7
20
|
export { email } from './vocabulary/email.js';
|
|
8
21
|
export { url } from './vocabulary/url.js';
|
|
9
|
-
export { list
|
|
22
|
+
export { list } from './vocabulary/list.js';
|
|
10
23
|
export { number } from './vocabulary/number.js';
|
|
11
24
|
export { bool } from './vocabulary/bool.js';
|
|
12
25
|
export { date } from './vocabulary/date.js';
|
|
@@ -23,15 +36,20 @@ export { indexed } from './vocabulary/indexed.js';
|
|
|
23
36
|
export { readOnly } from './vocabulary/readOnly.js';
|
|
24
37
|
export { writeOnly } from './vocabulary/writeOnly.js';
|
|
25
38
|
export { json } from './vocabulary/json.js';
|
|
26
|
-
export { applyCreate, applyUpdate } from './
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export { type
|
|
36
|
-
export type
|
|
39
|
+
export { applyCreate, applyUpdate, freezeClock } from './axis/lifecycle/apply.js';
|
|
40
|
+
export { encodeFields } from './projection/encode.js';
|
|
41
|
+
export { inputFields, outputFields } from './projection/io.js';
|
|
42
|
+
export { registrationKeyOf, classNameOf } from './name.js';
|
|
43
|
+
export { describe, describeSet, sourceNameOf } from './card/describe.js';
|
|
44
|
+
export { reconstruct, reconstructSet } from './card/reconstruct.js';
|
|
45
|
+
export { diff, diffSet } from './card/diff.js';
|
|
46
|
+
export type { Change, Diff, DiffOptions, SetDiff, SetDiffOptions, RenameCandidate, TypeSet } from './card/diff.js';
|
|
47
|
+
export { entitySourceOf, facadeTypeSourceOf, type TypeSourceOptions, type OpDescriptor } from './card/typescript.js';
|
|
48
|
+
export { type SchemaBundle, type SchemaDescriptor, type FieldDescriptor, type FieldExtension, type RoleDescriptor, type RelationDescriptor } from './card/Descriptor.js';
|
|
49
|
+
export { type SchemaSource, schemaOf, fieldsOf } from './projection/source.js';
|
|
50
|
+
export type { StandardSchemaV1 } from './projection/standard.js';
|
|
51
|
+
export { entity } from './entity.js';
|
|
52
|
+
export { Judge } from './judge/Judge.js';
|
|
53
|
+
export { type ValidateOptions } from './judge/options.js';
|
|
54
|
+
export { type ValidationError, type ValidationResult, type Checked } from './judge/result.js';
|
|
37
55
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,KAAK,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,SAAS,E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EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACnH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACrH,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACzK,OAAO,EAAE,KAAK,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC/E,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
|
|
1
|
+
export { Field } from './Field.js';
|
|
2
|
+
export { Anatomy } from './axis/shape/Shape.js';
|
|
3
|
+
export { Formats } from './axis/shape/Formats.js';
|
|
4
|
+
export { Role, primaryFieldOf } from './axis/role/Role.js';
|
|
5
|
+
export { Lifecycle } from './axis/lifecycle/Lifecycle.js';
|
|
6
|
+
export { registerGenerator } from './axis/lifecycle/Generators.js';
|
|
7
|
+
export { Boundary } from './axis/boundary/Boundary.js';
|
|
8
|
+
export { Boundaries } from './axis/boundary/Boundaries.js';
|
|
9
|
+
export { FieldGroup } from './constraint/FieldGroup.js';
|
|
10
|
+
export { Unique } from './constraint/Unique.js';
|
|
11
|
+
export { Schema, ANONYMOUS_SCHEMA_NAME } from './Schema.js';
|
|
12
|
+
export { casesFor, holds, refusalBranches } from './judge/cases.js';
|
|
13
|
+
export { same } from './same.js';
|
|
8
14
|
export { primary } from './vocabulary/primary.js';
|
|
9
15
|
export { text } from './vocabulary/text.js';
|
|
10
16
|
export { email } from './vocabulary/email.js';
|
|
@@ -26,23 +32,16 @@ export { indexed } from './vocabulary/indexed.js';
|
|
|
26
32
|
export { readOnly } from './vocabulary/readOnly.js';
|
|
27
33
|
export { writeOnly } from './vocabulary/writeOnly.js';
|
|
28
34
|
export { json } from './vocabulary/json.js';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
|
|
41
|
-
export { registrationKeyOf } from './name.js';
|
|
42
|
-
// descriptor (the card): the portable, serialisable identity of a schema
|
|
43
|
-
export { describe, describeSet, sourceNameOf } from './projections/describe.js';
|
|
44
|
-
export { reconstruct, reconstructSet } from './projections/reconstruct.js';
|
|
45
|
-
export { shapeTypeOf, entitySourceOf, facadeTypeSourceOf } from './projections/typescript.js';
|
|
46
|
-
// source: the one reader that takes a live class OR a card — what an adapter stands on
|
|
47
|
-
export { schemaOf, fieldsOf, uniqueOf } from './projections/source.js';
|
|
35
|
+
export { applyCreate, applyUpdate, freezeClock } from './axis/lifecycle/apply.js';
|
|
36
|
+
export { encodeFields } from './projection/encode.js';
|
|
37
|
+
export { inputFields, outputFields } from './projection/io.js';
|
|
38
|
+
export { registrationKeyOf, classNameOf } from './name.js';
|
|
39
|
+
export { describe, describeSet, sourceNameOf } from './card/describe.js';
|
|
40
|
+
export { reconstruct, reconstructSet } from './card/reconstruct.js';
|
|
41
|
+
// What separates two descriptors — one calculation, read by a DDL, a codec and a boot.
|
|
42
|
+
export { diff, diffSet } from './card/diff.js';
|
|
43
|
+
export { entitySourceOf, facadeTypeSourceOf } from './card/typescript.js';
|
|
44
|
+
export { schemaOf, fieldsOf } from './projection/source.js';
|
|
45
|
+
export { entity } from './entity.js';
|
|
46
|
+
export { Judge } from './judge/Judge.js';
|
|
48
47
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,YAAY,CAAC;AAChD,OAAO,EAAc,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAA2C,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,IAAI,EAAE,cAAc,EAAkB,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAuB,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAqB,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAwC,MAAM,6BAA6B,CAAC;AAC7F,OAAO,EAA8B,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEvF,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAA0B,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAa,MAAM,kBAAkB,CAAC;AAG/E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAA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E,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACpE,uFAAuF;AACvF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAA6C,MAAM,sBAAsB,CAAC;AAErH,OAAO,EAAqB,QAAQ,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAG/E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Field, Fields } from '../Field.js';
|
|
2
|
+
import type { Checked, ValidationResult } from './result.js';
|
|
3
|
+
import type { ValidateOptions } from './options.js';
|
|
4
|
+
export declare class Judge {
|
|
5
|
+
private static readonly plans;
|
|
6
|
+
private static planFor;
|
|
7
|
+
private static customFormatOf;
|
|
8
|
+
static value(field: Field, value: unknown): Checked;
|
|
9
|
+
static field(value: unknown): ValidationResult<Field>;
|
|
10
|
+
static onAbsent(field: Field): 'skip' | 'empty-list' | null;
|
|
11
|
+
static row(fields: Fields, input: unknown, opts?: ValidateOptions): ValidationResult<Record<string, unknown>>;
|
|
12
|
+
static isField(value: unknown): value is Field;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Judge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Judge.d.ts","sourceRoot":"","sources":["../../src/judge/Judge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOjD,OAAO,KAAK,EAAE,OAAO,EAAmB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAUpD,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAoC;IAEjE,OAAO,CAAC,MAAM,CAAC,OAAO;IAetB,OAAO,CAAC,MAAM,CAAC,cAAc;IAW7B,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAmBlD;IAED,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAuCpD;IAED,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,YAAY,GAAG,IAAI,CAK1D;IAED,MAAM,CAAC,GAAG,CACR,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,eAAoB,GACvB,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAqD7C;IAED,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAE7C;CACF"}
|