@fougere/schema 0.1.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.
Files changed (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/dist/entity.d.ts +117 -0
  4. package/dist/entity.d.ts.map +1 -0
  5. package/dist/entity.js +285 -0
  6. package/dist/entity.js.map +1 -0
  7. package/dist/field/boundary.d.ts +75 -0
  8. package/dist/field/boundary.d.ts.map +1 -0
  9. package/dist/field/boundary.js +76 -0
  10. package/dist/field/boundary.js.map +1 -0
  11. package/dist/field/field.d.ts +64 -0
  12. package/dist/field/field.d.ts.map +1 -0
  13. package/dist/field/field.js +28 -0
  14. package/dist/field/field.js.map +1 -0
  15. package/dist/field/index.d.ts +7 -0
  16. package/dist/field/index.d.ts.map +1 -0
  17. package/dist/field/index.js +9 -0
  18. package/dist/field/index.js.map +1 -0
  19. package/dist/field/lifecycle.d.ts +40 -0
  20. package/dist/field/lifecycle.d.ts.map +1 -0
  21. package/dist/field/lifecycle.js +27 -0
  22. package/dist/field/lifecycle.js.map +1 -0
  23. package/dist/field/meta.d.ts +9 -0
  24. package/dist/field/meta.d.ts.map +1 -0
  25. package/dist/field/meta.js +7 -0
  26. package/dist/field/meta.js.map +1 -0
  27. package/dist/field/role.d.ts +54 -0
  28. package/dist/field/role.d.ts.map +1 -0
  29. package/dist/field/role.js +55 -0
  30. package/dist/field/role.js.map +1 -0
  31. package/dist/field/shape.d.ts +77 -0
  32. package/dist/field/shape.d.ts.map +1 -0
  33. package/dist/field/shape.js +49 -0
  34. package/dist/field/shape.js.map +1 -0
  35. package/dist/hints.d.ts +33 -0
  36. package/dist/hints.d.ts.map +1 -0
  37. package/dist/hints.js +2 -0
  38. package/dist/hints.js.map +1 -0
  39. package/dist/index.d.ts +36 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +46 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/projections/card.d.ts +117 -0
  44. package/dist/projections/card.d.ts.map +1 -0
  45. package/dist/projections/card.js +8 -0
  46. package/dist/projections/card.js.map +1 -0
  47. package/dist/projections/describe.d.ts +25 -0
  48. package/dist/projections/describe.d.ts.map +1 -0
  49. package/dist/projections/describe.js +129 -0
  50. package/dist/projections/describe.js.map +1 -0
  51. package/dist/projections/encode.d.ts +11 -0
  52. package/dist/projections/encode.d.ts.map +1 -0
  53. package/dist/projections/encode.js +26 -0
  54. package/dist/projections/encode.js.map +1 -0
  55. package/dist/projections/io.d.ts +30 -0
  56. package/dist/projections/io.d.ts.map +1 -0
  57. package/dist/projections/io.js +52 -0
  58. package/dist/projections/io.js.map +1 -0
  59. package/dist/projections/lifecycle.d.ts +43 -0
  60. package/dist/projections/lifecycle.d.ts.map +1 -0
  61. package/dist/projections/lifecycle.js +115 -0
  62. package/dist/projections/lifecycle.js.map +1 -0
  63. package/dist/projections/reconstruct.d.ts +36 -0
  64. package/dist/projections/reconstruct.d.ts.map +1 -0
  65. package/dist/projections/reconstruct.js +149 -0
  66. package/dist/projections/reconstruct.js.map +1 -0
  67. package/dist/projections/source.d.ts +41 -0
  68. package/dist/projections/source.d.ts.map +1 -0
  69. package/dist/projections/source.js +37 -0
  70. package/dist/projections/source.js.map +1 -0
  71. package/dist/projections/standard.d.ts +41 -0
  72. package/dist/projections/standard.d.ts.map +1 -0
  73. package/dist/projections/standard.js +10 -0
  74. package/dist/projections/standard.js.map +1 -0
  75. package/dist/projections/typescript.d.ts +53 -0
  76. package/dist/projections/typescript.d.ts.map +1 -0
  77. package/dist/projections/typescript.js +166 -0
  78. package/dist/projections/typescript.js.map +1 -0
  79. package/dist/projections/validation.d.ts +49 -0
  80. package/dist/projections/validation.d.ts.map +1 -0
  81. package/dist/projections/validation.js +140 -0
  82. package/dist/projections/validation.js.map +1 -0
  83. package/dist/unique.d.ts +65 -0
  84. package/dist/unique.d.ts.map +1 -0
  85. package/dist/unique.js +80 -0
  86. package/dist/unique.js.map +1 -0
  87. package/dist/vocabulary/auto.d.ts +8 -0
  88. package/dist/vocabulary/auto.d.ts.map +1 -0
  89. package/dist/vocabulary/auto.js +13 -0
  90. package/dist/vocabulary/auto.js.map +1 -0
  91. package/dist/vocabulary/bool.d.ts +6 -0
  92. package/dist/vocabulary/bool.d.ts.map +1 -0
  93. package/dist/vocabulary/bool.js +9 -0
  94. package/dist/vocabulary/bool.js.map +1 -0
  95. package/dist/vocabulary/date.d.ts +3 -0
  96. package/dist/vocabulary/date.d.ts.map +1 -0
  97. package/dist/vocabulary/date.js +5 -0
  98. package/dist/vocabulary/date.js.map +1 -0
  99. package/dist/vocabulary/email.d.ts +5 -0
  100. package/dist/vocabulary/email.d.ts.map +1 -0
  101. package/dist/vocabulary/email.js +6 -0
  102. package/dist/vocabulary/email.js.map +1 -0
  103. package/dist/vocabulary/immutable.d.ts +9 -0
  104. package/dist/vocabulary/immutable.d.ts.map +1 -0
  105. package/dist/vocabulary/immutable.js +11 -0
  106. package/dist/vocabulary/immutable.js.map +1 -0
  107. package/dist/vocabulary/indexed.d.ts +19 -0
  108. package/dist/vocabulary/indexed.d.ts.map +1 -0
  109. package/dist/vocabulary/indexed.js +21 -0
  110. package/dist/vocabulary/indexed.js.map +1 -0
  111. package/dist/vocabulary/json.d.ts +18 -0
  112. package/dist/vocabulary/json.d.ts.map +1 -0
  113. package/dist/vocabulary/json.js +16 -0
  114. package/dist/vocabulary/json.js.map +1 -0
  115. package/dist/vocabulary/list.d.ts +21 -0
  116. package/dist/vocabulary/list.d.ts.map +1 -0
  117. package/dist/vocabulary/list.js +21 -0
  118. package/dist/vocabulary/list.js.map +1 -0
  119. package/dist/vocabulary/many.d.ts +8 -0
  120. package/dist/vocabulary/many.d.ts.map +1 -0
  121. package/dist/vocabulary/many.js +12 -0
  122. package/dist/vocabulary/many.js.map +1 -0
  123. package/dist/vocabulary/nullable.d.ts +9 -0
  124. package/dist/vocabulary/nullable.d.ts.map +1 -0
  125. package/dist/vocabulary/nullable.js +13 -0
  126. package/dist/vocabulary/nullable.js.map +1 -0
  127. package/dist/vocabulary/number.d.ts +10 -0
  128. package/dist/vocabulary/number.d.ts.map +1 -0
  129. package/dist/vocabulary/number.js +9 -0
  130. package/dist/vocabulary/number.js.map +1 -0
  131. package/dist/vocabulary/oneOf.d.ts +16 -0
  132. package/dist/vocabulary/oneOf.d.ts.map +1 -0
  133. package/dist/vocabulary/oneOf.js +13 -0
  134. package/dist/vocabulary/oneOf.js.map +1 -0
  135. package/dist/vocabulary/optional.d.ts +10 -0
  136. package/dist/vocabulary/optional.d.ts.map +1 -0
  137. package/dist/vocabulary/optional.js +15 -0
  138. package/dist/vocabulary/optional.js.map +1 -0
  139. package/dist/vocabulary/primary.d.ts +22 -0
  140. package/dist/vocabulary/primary.d.ts.map +1 -0
  141. package/dist/vocabulary/primary.js +31 -0
  142. package/dist/vocabulary/primary.js.map +1 -0
  143. package/dist/vocabulary/readOnly.d.ts +10 -0
  144. package/dist/vocabulary/readOnly.d.ts.map +1 -0
  145. package/dist/vocabulary/readOnly.js +12 -0
  146. package/dist/vocabulary/readOnly.js.map +1 -0
  147. package/dist/vocabulary/ref.d.ts +12 -0
  148. package/dist/vocabulary/ref.d.ts.map +1 -0
  149. package/dist/vocabulary/ref.js +20 -0
  150. package/dist/vocabulary/ref.js.map +1 -0
  151. package/dist/vocabulary/text.d.ts +12 -0
  152. package/dist/vocabulary/text.d.ts.map +1 -0
  153. package/dist/vocabulary/text.js +9 -0
  154. package/dist/vocabulary/text.js.map +1 -0
  155. package/dist/vocabulary/unique.d.ts +23 -0
  156. package/dist/vocabulary/unique.d.ts.map +1 -0
  157. package/dist/vocabulary/unique.js +25 -0
  158. package/dist/vocabulary/unique.js.map +1 -0
  159. package/dist/vocabulary/updated.d.ts +8 -0
  160. package/dist/vocabulary/updated.d.ts.map +1 -0
  161. package/dist/vocabulary/updated.js +12 -0
  162. package/dist/vocabulary/updated.js.map +1 -0
  163. package/dist/vocabulary/url.d.ts +5 -0
  164. package/dist/vocabulary/url.d.ts.map +1 -0
  165. package/dist/vocabulary/url.js +6 -0
  166. package/dist/vocabulary/url.js.map +1 -0
  167. package/dist/vocabulary/writeOnly.d.ts +9 -0
  168. package/dist/vocabulary/writeOnly.d.ts.map +1 -0
  169. package/dist/vocabulary/writeOnly.js +11 -0
  170. package/dist/vocabulary/writeOnly.js.map +1 -0
  171. package/package.json +40 -0
@@ -0,0 +1,166 @@
1
+ /**
2
+ * card → TypeScript source — the projection that was missing.
3
+ *
4
+ * `describe` turns a schema into a card and `reconstruct` turns it back into a
5
+ * living judge, so a consumer in another repository validates by the host's rules
6
+ * without holding its code. What it did NOT get is a type: left to infer, a rebuilt
7
+ * schema has an index signature for an instance type, so `post.title` was `any` and
8
+ * `post.titel` compiled. The declaration travelled and the compiler learned nothing.
9
+ *
10
+ * So the card gets a third reader, and it writes the shape where `reconstruct` now
11
+ * accepts it — as the type argument of the class's own base expression, one
12
+ * declaration for the judge and the rows it judges. Same input as the other two
13
+ * readers, same rule: the shape IS JSON Schema, and JSON Schema has a type form.
14
+ *
15
+ * Deliberately NOT a JSON Schema→TS library: the input is not arbitrary JSON Schema,
16
+ * it is a Fougère card, whose vocabulary is closed (`describe` writes it). A general
17
+ * library would carry `$ref`, `allOf`, tuple `items`, `additionalProperties` and the
18
+ * rest of a spec we never emit, and would still need this file to know that
19
+ * `format: date-time` means `Date` here — a fact about our boundary, not about JSON.
20
+ */
21
+ /** What a field's value looks like once `reconstruct` has decoded it. */
22
+ function typeOf(field) {
23
+ const types = Array.isArray(field.type) ? field.type : field.type ? [field.type] : [];
24
+ const nullable = types.includes('null');
25
+ const base = types.find((t) => t !== 'null');
26
+ const inner = baseTypeOf(base, field);
27
+ return nullable ? `${inner} | null` : inner;
28
+ }
29
+ function baseTypeOf(base, field) {
30
+ // A bounded value set IS a type — the enum travels, so the union does too.
31
+ if (field.enum?.length) {
32
+ return field.enum.map((v) => (v === null ? 'null' : JSON.stringify(v))).join(' | ');
33
+ }
34
+ switch (base) {
35
+ case 'string':
36
+ // `date-time` is the wire form of a value the boundary decodes to a Date, and
37
+ // the façade now hands the decoded value on. The type says what you receive.
38
+ return field.format === 'date-time' ? 'Date' : 'string';
39
+ case 'number':
40
+ case 'integer':
41
+ return 'number';
42
+ case 'boolean':
43
+ return 'boolean';
44
+ case 'array':
45
+ // Two distinct things share `array`: a value list carries `items`, a bare `many`
46
+ // relation carries none — the ids of the other side, which the card names as a
47
+ // relation rather than a shape.
48
+ return field.items ? `${typeOf(field.items)}[]` : 'string[]';
49
+ case 'object':
50
+ return field.properties ? objectTypeOf(field.properties, field.required ?? []) : 'Record<string, unknown>';
51
+ default:
52
+ return 'unknown';
53
+ }
54
+ }
55
+ function objectTypeOf(properties, required) {
56
+ const members = Object.entries(properties).map(([name, field]) => {
57
+ const optional = required.includes(name) ? '' : '?';
58
+ return `${propertyKey(name)}${optional}: ${typeOf(field)}`;
59
+ });
60
+ return `{ ${members.join('; ')} }`;
61
+ }
62
+ /** Quote a key only when it is not a plain identifier — generated source stays readable. */
63
+ function propertyKey(name) {
64
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) ? name : JSON.stringify(name);
65
+ }
66
+ /**
67
+ * The anonymous object type one card describes — the members, nothing around them.
68
+ *
69
+ * Every property is present: `required` on a Fougère card answers "what must a CALLER
70
+ * supply at creation", not "what is always there when read" — an `id` the system
71
+ * generates is absent from `required` and always present on a row. Typing the read
72
+ * shape from the create rule would make `post.id` possibly-undefined for everyone.
73
+ */
74
+ export function shapeTypeOf(descriptor, indent = '') {
75
+ const entries = Object.entries(descriptor.properties ?? {});
76
+ if (entries.length === 0)
77
+ return '{}';
78
+ const lines = entries.map(([key, field]) => {
79
+ const doc = field.description ? `${indent} /** ${field.description} */\n` : '';
80
+ return `${doc}${indent} ${propertyKey(key)}: ${typeOf(field)};`;
81
+ });
82
+ return `{\n${lines.join('\n')}\n${indent}}`;
83
+ }
84
+ /**
85
+ * Emit the entity a card describes — ONE class, judge and shape together.
86
+ *
87
+ * An entity is a class here (`class Post extends entity({…}) {}`), and a class is the
88
+ * language's own answer to "a name that is both a value and a type". Emitting an
89
+ * interface next to a const said the same thing twice and relied on declaration
90
+ * merging to look like a class; this IS one.
91
+ *
92
+ * The card travels inline, so the rebuilt judge is exact — the shape written above it
93
+ * is read off that same card, never a second source to keep in step.
94
+ *
95
+ * Requires `reconstruct` in scope: the caller writes the import, since only it knows
96
+ * whether the consumer says `@fougere/schema` or a path.
97
+ */
98
+ export function entitySourceOf(descriptor, options = {}) {
99
+ const name = identifierOf(options.name ?? capitalize(descriptor.title ?? 'Schema'));
100
+ const exported = options.exported === false ? '' : 'export ';
101
+ const card = JSON.stringify(descriptor, null, 2)
102
+ .split('\n')
103
+ .map((line, i) => (i === 0 ? line : ` ${line}`))
104
+ .join('\n');
105
+ return `${exported}class ${name} extends reconstruct<${shapeTypeOf(descriptor)}>(${card}) {}`;
106
+ }
107
+ /**
108
+ * A card names itself, and a card can come from a stranger. Everything else here emits
109
+ * data — a string lands inside `JSON.stringify` — but a name lands in a DECLARATION,
110
+ * so it is the one value that could stop being data. Refuse it here as well as at the
111
+ * caller: the projection should not depend on who calls it to be safe.
112
+ */
113
+ function identifierOf(name) {
114
+ if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) {
115
+ throw new Error(`'${name}' is not a TypeScript identifier — it cannot name a generated declaration`);
116
+ }
117
+ return name;
118
+ }
119
+ function capitalize(s) {
120
+ return s ? s[0].toUpperCase() + s.slice(1) : s;
121
+ }
122
+ /**
123
+ * What one operation hands back, in TypeScript.
124
+ *
125
+ * `output` is the shape of a ROW; `cardinality` is how many rows. Separating them is
126
+ * what makes this honest — `list` returns a page, not an array, and a generator that
127
+ * assumed otherwise would have written a signature that compiles and lies.
128
+ *
129
+ * A page is spelled as what it IS: `ListResult<T> extends Array<T>`, an array carrying
130
+ * its own totals. So the type is the array intersected with them, not a wrapper.
131
+ */
132
+ function returnTypeOf(op, rowType) {
133
+ switch (op.cardinality) {
134
+ case 'many': return `${rowType}[]`;
135
+ case 'page': return `${rowType}[] & { total?: number; endCursor?: string; hasMore?: boolean }`;
136
+ case 'maybe': return `${rowType} | undefined`;
137
+ case 'one': return rowType;
138
+ // `none` says there is no shaped output — a boolean, a void. Saying `unknown` is
139
+ // the truth; guessing `void` would forbid reading a value that does come back.
140
+ case 'none': return 'unknown';
141
+ default: return 'unknown';
142
+ }
143
+ }
144
+ /**
145
+ * Emit the type of a façade — every operation an entity serves, as a caller meets it.
146
+ *
147
+ * This is what `Facade<T>` needs and what no consumer in another repository could have:
148
+ * writing `Facade<ArticleHandler>` used to require importing the handler's class, which
149
+ * `sync` does not carry and should not. The card carries the operations; this reads them.
150
+ *
151
+ * Each op takes an optional invocation and returns a promise — the door's signature, not
152
+ * the handler's. A handler's method takes positional arguments; its door takes the call.
153
+ */
154
+ export function facadeTypeSourceOf(ops, options = {}) {
155
+ const name = options.name ?? 'Facade';
156
+ const exported = options.exported === false ? '' : 'export ';
157
+ const rowType = options.rowType ?? 'unknown';
158
+ const members = ops.map((op) => {
159
+ const doc = op.description ? ` /** ${op.description} */\n` : '';
160
+ return `${doc} ${propertyKey(op.name)}(invocation?: Invocation): Promise<${returnTypeOf(op, rowType)}>;`;
161
+ });
162
+ if (members.length === 0)
163
+ return `${exported}interface ${name} {}`;
164
+ return `${exported}interface ${name} {\n${members.join('\n')}\n}`;
165
+ }
166
+ //# sourceMappingURL=typescript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../src/projections/typescript.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,yEAAyE;AACzE,SAAS,MAAM,CAAC,KAAsB;IACpC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI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G,GAAG,KAAK,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,sCAAsC,YAAY,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC;IAC5G,CAAC,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,QAAQ,aAAa,IAAI,KAAK,CAAC;IACnE,OAAO,GAAG,QAAQ,aAAa,IAAI,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;AACpE,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { AnyField, Fields } from '../field/index.js';
2
+ /**
3
+ * Validation — the Field metadata IS the source of truth.
4
+ *
5
+ * Validation is a projection of one axis: `shape` (the value), a PURE predicate —
6
+ * it answers "is this value valid?" and never mutates the value. Null included:
7
+ * the shape's `[T,'null']` union is judged by the engine, there is no hand-rolled
8
+ * null branch. It never looks at `role` (persistence/domain) — a foreign key is
9
+ * just a string here. Converting a valid value (e.g. an ISO string → a `Date`)
10
+ * is a separate step, the `boundary` axis, applied after the predicate passes.
11
+ * Absence is judged by `lifecycle.create` — any create rule makes it legal and
12
+ * the field is OMITTED from the result, never filled: realising the rule
13
+ * (stamp 'now', apply { value }, generate) belongs to the storage adapter at
14
+ * the point of persistence, whose insert returns the complete row.
15
+ */
16
+ export interface ValidationError {
17
+ path: string;
18
+ message: string;
19
+ }
20
+ export type ValidationResult<T> = {
21
+ success: true;
22
+ data: T;
23
+ } | {
24
+ success: false;
25
+ errors: ValidationError[];
26
+ };
27
+ export type Checked = {
28
+ value: unknown;
29
+ } | {
30
+ error: string;
31
+ };
32
+ /**
33
+ * Validate a present value (null included) against its field — pure, never mutates.
34
+ *
35
+ * Reads `shape` and nothing else, so it answers "is this a legal value?" without ever
36
+ * asking who is speaking. That is what makes it usable on the way OUT of the domain,
37
+ * where the client-only axes (`boundary`, `lifecycle`) do not apply.
38
+ */
39
+ export declare function checkValue(field: AnyField, value: unknown): Checked;
40
+ export interface ValidateOptions {
41
+ /**
42
+ * Patch mode (update). An absent field is OMITTED from the result — not filled,
43
+ * not required — so `validate({ name })` touches only `name`. Set by `partial()`.
44
+ * Distinguishes "absent → don't touch" (patch) from "absent → null" (create).
45
+ */
46
+ patch?: boolean;
47
+ }
48
+ export declare function validateFields(fields: Fields, input: unknown, pathPrefix?: string, opts?: ValidateOptions): ValidationResult<Record<string, unknown>>;
49
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/projections/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAS,MAAM,mBAAmB,CAAC;AAIjE;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAC1B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC;AAElD,MAAM,MAAM,OAAO,GAAG;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAmB7D;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAgCnE;AAED,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,UAAU,SAAK,EACf,IAAI,GAAE,eAAoB,GACzB,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA8E3C"}
@@ -0,0 +1,140 @@
1
+ import { anatomy, boundaryOf, resolveBoundary } from '../field/index.js';
2
+ import { Validator } from '@cfworker/json-schema';
3
+ /**
4
+ * One validator per shape — the shape object IS the source JSON Schema (the closed
5
+ * grammar the helpers emit), handed straight to the engine. Keyed by the shape
6
+ * reference (stable: derivations copy field refs, `partial()` spreads the field but
7
+ * keeps the same `shape`), built once and reused so the parse cost is amortised.
8
+ */
9
+ const validators = new WeakMap();
10
+ function validatorFor(shape) {
11
+ let v = validators.get(shape);
12
+ if (!v) {
13
+ v = new Validator(shape, '2020-12', true);
14
+ validators.set(shape, v);
15
+ }
16
+ return v;
17
+ }
18
+ /**
19
+ * Validate a present value (null included) against its field — pure, never mutates.
20
+ *
21
+ * Reads `shape` and nothing else, so it answers "is this a legal value?" without ever
22
+ * asking who is speaking. That is what makes it usable on the way OUT of the domain,
23
+ * where the client-only axes (`boundary`, `lifecycle`) do not apply.
24
+ */
25
+ export function checkValue(field, value) {
26
+ const shape = field.shape;
27
+ // Relation-only field (`many`): no value shape, just an array of related rows.
28
+ if (!shape) {
29
+ if (field.role?.relation?.kind === 'many') {
30
+ return Array.isArray(value) ? { value } : { error: 'Expected an array' };
31
+ }
32
+ return { value };
33
+ }
34
+ // The pre-engine guards dispatch on the BASE type — `shape.type` itself may be
35
+ // the nullable union. They only short-circuit NON-null values: null always goes
36
+ // to the engine, whose union judges it (that is the whole nullability model).
37
+ const base = anatomy(shape).base;
38
+ if (value !== null) {
39
+ // Opaque JSON (`json()`): no nested shape → passes through unchecked.
40
+ // `json(Entity)` carries `properties` and falls through to the engine,
41
+ // which validates the nesting natively (it's plain JSON Schema).
42
+ if (base?.type === 'object' && !base.properties)
43
+ return { value };
44
+ // A date-time field also accepts a live Date — the domain value, not its JSON wire
45
+ // string — which the boundary then passes through. The engine validates JSON, so a
46
+ // Date (a non-JSON value) skips the schema check here; a date STRING is validated below.
47
+ if (base?.type === 'string' && base.format === 'date-time' && value instanceof Date) {
48
+ return Number.isNaN(value.getTime()) ? { error: 'Invalid date' } : { value };
49
+ }
50
+ // NaN is `typeof number` yet has no JSON form, so the JSON-centric engine accepts it —
51
+ // guard it here (same nature as the Date case: a JS value JSON can't represent).
52
+ if ((base?.type === 'number' || base?.type === 'integer') && typeof value === 'number' && Number.isNaN(value)) {
53
+ return { error: 'Expected a number' };
54
+ }
55
+ }
56
+ const result = validatorFor(shape).validate(value);
57
+ return result.valid ? { value } : { error: result.errors[0]?.error ?? 'Invalid value' };
58
+ }
59
+ export function validateFields(fields, input, pathPrefix = '', opts = {}) {
60
+ if (typeof input !== 'object' || input === null) {
61
+ return { success: false, errors: [{ path: pathPrefix || '.', message: 'Expected an object' }] };
62
+ }
63
+ const data = input;
64
+ const errors = [];
65
+ const out = {};
66
+ // Refuse, never strip: a key outside the contract is an error, not a silent
67
+ // drop. The client derives from the same contract (a form cannot emit a
68
+ // foreign key), so a stranger is a bug or an attack — both deserve the 400.
69
+ // Stripping would also let the envelope diverge from GraphQL, which refuses
70
+ // unknown input keys by construction.
71
+ //
72
+ // A FACT is judged by this same rule, deliberately — the one place it was tempting to
73
+ // relax it. A subscriber's copy of a fact can be older than the sender's, so tolerating
74
+ // a stranger key would let a rolling deployment through; it would also mean a reader
75
+ // silently ignoring a field it was supposed to handle. If the judge refuses, that is
76
+ // the end of it: the sender re-syncs its readers before it ships.
77
+ for (const key of Object.keys(data)) {
78
+ if (!(key in fields)) {
79
+ errors.push({ path: pathPrefix ? `${pathPrefix}.${key}` : key, message: 'Unknown field' });
80
+ }
81
+ }
82
+ for (const [key, field] of Object.entries(fields)) {
83
+ const path = pathPrefix ? `${pathPrefix}.${key}` : key;
84
+ const value = data[key];
85
+ if (value === undefined) {
86
+ if (opts.patch)
87
+ continue; // patch: an unsent field is left untouched
88
+ // A read-only field is server-owned: its absence from a client input is
89
+ // never "Required" (same stance as OpenAPI readOnly+required).
90
+ if (boundaryOf(field).in === 'closed')
91
+ continue;
92
+ // Absence is answered by `lifecycle.create` — a key access on the normal
93
+ // form. The judge only asks "is there a rule?": any rule ('now',
94
+ // 'optional', { value }, { generate }) makes absence legal, and the field
95
+ // is omitted from the result. Realisation is the storage adapter's role.
96
+ if (field.lifecycle?.create !== undefined)
97
+ continue;
98
+ // No create rule: a `many` relation defaults to the empty collection
99
+ // (graph semantics, read on `role` — never a shared `{ value: [] }`).
100
+ if (field.role?.relation?.kind === 'many') {
101
+ out[key] = [];
102
+ continue;
103
+ }
104
+ errors.push({ path, message: 'Required' });
105
+ continue;
106
+ }
107
+ // A PRESENT value can be illegal by an axis other than shape:
108
+ // boundary `in: 'closed'` — a read-only field never crosses inbound;
109
+ // lifecycle `update: 'forbidden'` — re-supplying an immutable field in a patch.
110
+ if (boundaryOf(field).in === 'closed') {
111
+ errors.push({ path, message: 'Read-only' });
112
+ continue;
113
+ }
114
+ if (opts.patch && field.lifecycle?.update === 'forbidden') {
115
+ errors.push({ path, message: 'Immutable' });
116
+ continue;
117
+ }
118
+ // The shape predicate judges the value — null included, via the `[T,'null']`
119
+ // union. Then the boundary's decode converts wire→domain; null skips decode
120
+ // (a legal null is already the domain value, there is nothing to convert).
121
+ const checked = checkValue(field, value);
122
+ if ('error' in checked) {
123
+ errors.push({ path, message: checked.error });
124
+ continue;
125
+ }
126
+ if (checked.value === null) {
127
+ out[key] = null;
128
+ continue;
129
+ }
130
+ const decoded = resolveBoundary(field).decode(checked.value);
131
+ if ('error' in decoded)
132
+ errors.push({ path, message: decoded.error });
133
+ else
134
+ out[key] = decoded.value;
135
+ }
136
+ if (errors.length > 0)
137
+ return { success: false, errors };
138
+ return { success: true, data: out };
139
+ }
140
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/projections/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AA4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,CAAC;IAChC,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACzD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { Fields } from './field/index.js';
2
+ import type { Hints } from './hints.js';
3
+ /**
4
+ * Field names that identify at most one row when taken together.
5
+ *
6
+ * `unique(field)` states a fact about one column; some facts are about a pair.
7
+ * "A book appears once in a list" is true of `(listId, docId)` and of neither
8
+ * alone, and there is no shape that can express it — judging one value never
9
+ * sees the other rows. So it is declared on the entity and realized by storage.
10
+ *
11
+ * Held here rather than in a handler because a handler cannot hold it: a check
12
+ * followed by a write is two round trips, and a concurrent request fits between
13
+ * them. The database is the only place where the promise is keepable.
14
+ */
15
+ export type CompositeUnique<TFields extends Fields> = ReadonlyArray<ReadonlyArray<Extract<keyof TFields, string>>>;
16
+ /**
17
+ * What an entity declares about itself, beyond its fields — the 2nd argument of
18
+ * `entity()`.
19
+ *
20
+ * One object rather than a growing parameter list: a second fact about an entity
21
+ * adds a key here, never a positional argument.
22
+ */
23
+ export interface EntityDeclarations<TFields extends Fields> {
24
+ /** Field groups that must be unique together. */
25
+ unique?: CompositeUnique<TFields>;
26
+ /** Per-consumer hints, keyed by registered adapter. See {@link Hints}. */
27
+ hints?: Hints<TFields>;
28
+ }
29
+ /**
30
+ * Carry composite groups across a field-key transform — the entity-level twin of
31
+ * `deriveHints`.
32
+ *
33
+ * A group whose members did not all survive is dropped rather than narrowed: the
34
+ * pair `(listId, docId)` says nothing about `listId` alone, and keeping the
35
+ * remnant would silently state a stronger fact than the author ever wrote.
36
+ */
37
+ export declare function deriveUnique(groups: CompositeUnique<Fields> | undefined, mapKey: (key: string) => string | undefined): CompositeUnique<Fields> | undefined;
38
+ /**
39
+ * Carry the projected groups across the same key transform — the field-level twin of
40
+ * {@link deriveUnique}, and it has to run with it: the group lives in TWO places once
41
+ * projected (the declaration and each member's role), so remapping one alone left
42
+ * `pick('id','listId')` with a role still claiming a pair whose other member was gone.
43
+ *
44
+ * Same rule as the declaration — a group that lost a member is dropped, not narrowed.
45
+ * The empty self-reference needs no remapping: it names no key, which is exactly why it
46
+ * survives a `rename()` for free.
47
+ */
48
+ export declare function deriveUniqueRoles<TFields extends Fields>(fields: TFields, mapKey: (key: string) => string | undefined): TFields;
49
+ /**
50
+ * Project the entity's composite groups onto the role of every member — the single
51
+ * place the two ways of stating uniqueness meet.
52
+ *
53
+ * The author writes each fact where it lives: `unique(slug)` on the field it is about,
54
+ * `entity(fields, { unique: [['listId','docId']] })` on the entity, because a fact about
55
+ * a pair is held by neither field alone. Both then read as ONE normal form on the role
56
+ * axis, so every consumer — the DDL, the card, a foreign adapter — has a single shape to
57
+ * handle, and a field belonging to two constraints simply carries two member lists.
58
+ *
59
+ * The entity declaration stays the source (`getUnique()` keeps answering it); this is a
60
+ * projection of it, never a second place to edit. A named member group is spelled out
61
+ * here, while a lone `unique()` keeps its `[]` self-reference — resolved by whoever reads
62
+ * it, which is what makes `rename()` free.
63
+ */
64
+ export declare function projectUniqueOntoFields<TFields extends Fields>(fields: TFields, groups: CompositeUnique<TFields> | undefined): TFields;
65
+ //# sourceMappingURL=unique.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique.d.ts","sourceRoot":"","sources":["../src/unique.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,MAAM,IAAI,aAAa,CACjE,aAAa,CAAC,OAAO,CAAC,MAAM,OAAO,EAAE,MAAM,CAAC,CAAC,CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,MAAM;IACxD,iDAAiD;IACjD,MAAM,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC,0EAA0E;IAC1E,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,SAAS,EAC3C,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAC1C,eAAe,CAAC,MAAM,CAAC,GAAG,SAAS,CAQrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,MAAM,EACtD,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAC1C,OAAO,CAkBT;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,MAAM,EAC5D,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,SAAS,GAC3C,OAAO,CAiBT"}
package/dist/unique.js ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Carry composite groups across a field-key transform — the entity-level twin of
3
+ * `deriveHints`.
4
+ *
5
+ * A group whose members did not all survive is dropped rather than narrowed: the
6
+ * pair `(listId, docId)` says nothing about `listId` alone, and keeping the
7
+ * remnant would silently state a stronger fact than the author ever wrote.
8
+ */
9
+ export function deriveUnique(groups, mapKey) {
10
+ if (!groups)
11
+ return undefined;
12
+ const carried = groups
13
+ .map((group) => group.map(mapKey))
14
+ .filter((group) => group.every((key) => key !== undefined));
15
+ return carried.length > 0 ? carried : undefined;
16
+ }
17
+ /**
18
+ * Carry the projected groups across the same key transform — the field-level twin of
19
+ * {@link deriveUnique}, and it has to run with it: the group lives in TWO places once
20
+ * projected (the declaration and each member's role), so remapping one alone left
21
+ * `pick('id','listId')` with a role still claiming a pair whose other member was gone.
22
+ *
23
+ * Same rule as the declaration — a group that lost a member is dropped, not narrowed.
24
+ * The empty self-reference needs no remapping: it names no key, which is exactly why it
25
+ * survives a `rename()` for free.
26
+ */
27
+ export function deriveUniqueRoles(fields, mapKey) {
28
+ const out = { ...fields };
29
+ for (const [key, field] of Object.entries(out)) {
30
+ const groups = field.role?.unique;
31
+ if (!groups?.length)
32
+ continue;
33
+ const carried = groups
34
+ .map((group) => (group.length === 0 ? [] : group.map(mapKey)))
35
+ .filter((group) => group.every((member) => member !== undefined));
36
+ if (carried.length === groups.length)
37
+ continue; // nothing lost, keep the field as is
38
+ const { unique: _dropped, ...rest } = field.role;
39
+ out[key] = {
40
+ ...field,
41
+ role: carried.length ? { ...rest, unique: carried } : rest,
42
+ };
43
+ }
44
+ return out;
45
+ }
46
+ /**
47
+ * Project the entity's composite groups onto the role of every member — the single
48
+ * place the two ways of stating uniqueness meet.
49
+ *
50
+ * The author writes each fact where it lives: `unique(slug)` on the field it is about,
51
+ * `entity(fields, { unique: [['listId','docId']] })` on the entity, because a fact about
52
+ * a pair is held by neither field alone. Both then read as ONE normal form on the role
53
+ * axis, so every consumer — the DDL, the card, a foreign adapter — has a single shape to
54
+ * handle, and a field belonging to two constraints simply carries two member lists.
55
+ *
56
+ * The entity declaration stays the source (`getUnique()` keeps answering it); this is a
57
+ * projection of it, never a second place to edit. A named member group is spelled out
58
+ * here, while a lone `unique()` keeps its `[]` self-reference — resolved by whoever reads
59
+ * it, which is what makes `rename()` free.
60
+ */
61
+ export function projectUniqueOntoFields(fields, groups) {
62
+ if (!groups || groups.length === 0)
63
+ return fields;
64
+ const projected = { ...fields };
65
+ for (const group of groups) {
66
+ const members = [...group];
67
+ for (const key of members) {
68
+ const field = projected[key];
69
+ if (!field)
70
+ continue; // a group naming an absent field states nothing here
71
+ const already = field.role?.unique ?? [];
72
+ projected[key] = {
73
+ ...field,
74
+ role: { ...field.role, unique: [...already, members] },
75
+ };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;IACH,CAAC;IACD,OAAO,SAAoB,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type Field } from '../field/index.js';
2
+ /**
3
+ * Auto-managed timestamp, stamped at creation — optional in `new X(input)`.
4
+ * Immutable by default: a creation timestamp re-supplied in a patch is an
5
+ * error (decided 2026-07-15).
6
+ */
7
+ export declare function auto(): Field<Date, true>;
8
+ //# sourceMappingURL=auto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto.d.ts","sourceRoot":"","sources":["../../src/vocabulary/auto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;GAIG;AACH,wBAAgB,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAKxC"}
@@ -0,0 +1,13 @@
1
+ import { createField } from '../field/index.js';
2
+ /**
3
+ * Auto-managed timestamp, stamped at creation — optional in `new X(input)`.
4
+ * Immutable by default: a creation timestamp re-supplied in a patch is an
5
+ * error (decided 2026-07-15).
6
+ */
7
+ export function auto() {
8
+ return createField({
9
+ shape: { type: 'string', format: 'date-time' },
10
+ lifecycle: { create: 'now', update: 'forbidden' },
11
+ });
12
+ }
13
+ //# sourceMappingURL=auto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto.js","sourceRoot":"","sources":["../../src/vocabulary/auto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAc,MAAM,mBAAmB,CAAC;AAE5D;;;;GAIG;AACH,MAAM,UAAU,IAAI;IAClB,OAAO,WAAW,CAAa;QAC7B,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE;QAC9C,SAAS,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE;KAClD,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type Field } from '../field/index.js';
2
+ export declare function bool(opts?: {
3
+ default?: boolean;
4
+ description?: string;
5
+ }): Field<boolean>;
6
+ //# sourceMappingURL=bool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bool.d.ts","sourceRoot":"","sources":["../../src/vocabulary/bool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE5D,wBAAgB,IAAI,CAAC,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAMvF"}
@@ -0,0 +1,9 @@
1
+ import { createField } from '../field/index.js';
2
+ export function bool(opts) {
3
+ return createField({
4
+ shape: { type: 'boolean' },
5
+ lifecycle: opts?.default !== undefined ? { create: { value: opts.default } } : undefined,
6
+ meta: opts?.description !== undefined ? { description: opts.description } : undefined,
7
+ });
8
+ }
9
+ //# sourceMappingURL=bool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bool.js","sourceRoot":"","sources":["../../src/vocabulary/bool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAc,MAAM,mBAAmB,CAAC;AAE5D,MAAM,UAAU,IAAI,CAAC,IAAkD;IACrE,OAAO,WAAW,CAAU;QAC1B,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QAC1B,SAAS,EAAE,IAAI,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS;QACxF,IAAI,EAAE,IAAI,EAAE,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;KACtF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type Field } from '../field/index.js';
2
+ export declare function date(): Field<Date>;
3
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/vocabulary/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE5D,wBAAgB,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,CAElC"}
@@ -0,0 +1,5 @@
1
+ import { createField } from '../field/index.js';
2
+ export function date() {
3
+ return createField({ shape: { type: 'string', format: 'date-time' } });
4
+ }
5
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/vocabulary/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAc,MAAM,mBAAmB,CAAC;AAE5D,MAAM,UAAU,IAAI;IAClB,OAAO,WAAW,CAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type TextOptions } from './text.js';
2
+ import type { Field } from '../field/index.js';
3
+ /** A string holding an email address — `text({ format: 'email' })`, named. */
4
+ export declare function email(opts?: Omit<TextOptions, 'format'>): Field<string>;
5
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/vocabulary/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,8EAA8E;AAC9E,wBAAgB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAEvE"}
@@ -0,0 +1,6 @@
1
+ import { text } from './text.js';
2
+ /** A string holding an email address — `text({ format: 'email' })`, named. */
3
+ export function email(opts) {
4
+ return text({ ...opts, format: 'email' });
5
+ }
6
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/vocabulary/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoB,MAAM,WAAW,CAAC;AAGnD,8EAA8E;AAC9E,MAAM,UAAU,KAAK,CAAC,IAAkC;IACtD,OAAO,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5C,CAAC"}