@fougere/schema 0.12.3-alpha.0 → 0.12.5-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 +4 -13
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaConstraints.d.ts +2 -2
- package/dist/SchemaConstraints.d.ts.map +1 -1
- package/dist/SchemaConstraints.js +6 -10
- package/dist/SchemaConstraints.js.map +1 -1
- package/dist/SchemaDefinition.d.ts +7 -10
- package/dist/SchemaDefinition.d.ts.map +1 -1
- package/dist/SchemaDefinition.js +9 -23
- package/dist/SchemaDefinition.js.map +1 -1
- package/dist/SchemaView.d.ts +2 -2
- package/dist/SchemaView.d.ts.map +1 -1
- package/dist/axis/boundary/Boundary.d.ts +6 -1
- package/dist/axis/boundary/Boundary.d.ts.map +1 -1
- package/dist/axis/boundary/Boundary.js +81 -9
- package/dist/axis/boundary/Boundary.js.map +1 -1
- package/dist/axis/boundary/Decoder.js +1 -1
- package/dist/axis/boundary/Decoder.js.map +1 -1
- package/dist/axis/shape/Shape.d.ts +4 -0
- package/dist/axis/shape/Shape.d.ts.map +1 -1
- package/dist/axis/shape/Shape.js +7 -3
- package/dist/axis/shape/Shape.js.map +1 -1
- package/dist/entity/EntityAdapterSet.d.ts +1 -0
- package/dist/entity/EntityAdapterSet.d.ts.map +1 -1
- package/dist/entity/EntityAdapterSet.js +2 -1
- package/dist/entity/EntityAdapterSet.js.map +1 -1
- package/dist/projection/card/Card.d.ts.map +1 -1
- package/dist/projection/card/Card.js +3 -6
- package/dist/projection/card/Card.js.map +1 -1
- package/dist/projection/card/Diff.d.ts.map +1 -1
- package/dist/projection/card/Diff.js +2 -4
- package/dist/projection/card/Diff.js.map +1 -1
- package/dist/validator/FieldValueValidator.js +2 -2
- package/dist/validator/FieldValueValidator.js.map +1 -1
- package/package.json +11 -11
- package/src/Schema.ts +14 -25
- package/src/SchemaConstraints.ts +10 -14
- package/src/SchemaDefinition.ts +17 -33
- package/src/SchemaView.ts +2 -2
- package/src/axis/boundary/Boundary.ts +81 -8
- package/src/axis/boundary/Decoder.ts +1 -1
- package/src/axis/shape/Shape.ts +8 -5
- package/src/entity/EntityAdapterSet.ts +3 -1
- package/src/projection/card/Card.ts +3 -6
- package/src/projection/card/Diff.ts +2 -4
- package/src/validator/FieldValueValidator.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Card.d.ts","sourceRoot":"","sources":["../../../src/projection/card/Card.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Card.d.ts","sourceRoot":"","sources":["../../../src/projection/card/Card.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIpD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAW,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,KAAK,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAErD;;;;GAIG;AACH,qBAAa,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACd,QAAQ,CAAC,UAAU,EAAE,gBAAgB;IAAzD,OAAO,eAAsD;IAE7D,MAAM,CAAC,UAAU,CAAC,OAAO,SAAS,MAAM,EACtC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,EAC3B,IAAI,CAAC,EAAE,MAAM,GACZ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CA2BvB;IAED,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAAC,CAAC,CAAC,CAE/E;IAED;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAEzC;IAED,IAAI,MAAM,IAAI,WAAW,GAAG,SAAS,CAEpC;IAED,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAuC1E;IAED,sFAAsF;IACtF,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI,CAEjD;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Axes } from '../../axis/Axes.js';
|
|
2
|
+
import { Shapes } from '../../axis/shape/Shape.js';
|
|
2
3
|
import { CardForms } from './CardForms.js';
|
|
3
4
|
import { clean, isObject } from '../../lib/utils.js';
|
|
4
5
|
import { Field } from '../../field/Field.js';
|
|
@@ -29,7 +30,7 @@ export class Card {
|
|
|
29
30
|
required.push(key);
|
|
30
31
|
}
|
|
31
32
|
for (const kind of ['unique', 'index'])
|
|
32
|
-
for (const group of
|
|
33
|
+
for (const group of kind === 'unique' ? schema.getUnique() : schema.getIndex())
|
|
33
34
|
for (const member of group)
|
|
34
35
|
carryGroup(properties[member], kind, group);
|
|
35
36
|
const descriptor = {
|
|
@@ -139,11 +140,7 @@ function originOf(schema) {
|
|
|
139
140
|
* `{ type: 'string', maxLength: 200 }` → the same shape `text({ max: 200 })` states
|
|
140
141
|
*/
|
|
141
142
|
function reconstructShape(property) {
|
|
142
|
-
const types =
|
|
143
|
-
? property.type
|
|
144
|
-
: property.type
|
|
145
|
-
? [property.type]
|
|
146
|
-
: [];
|
|
143
|
+
const types = Shapes.typesOf(property);
|
|
147
144
|
if (!types.some((type) => type !== 'null'))
|
|
148
145
|
return undefined;
|
|
149
146
|
// `describeField` writes the shape whole, so it is read whole: a list of keywords here
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Card.js","sourceRoot":"","sources":["../../../src/projection/card/Card.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAIzC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAKvD,OAAO,EAAE,OAAO,EAAa,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD;;;;GAIG;AACH,MAAM,OAAO,IAAI;IACc,UAAU;IAAvC,YAA6B,UAA4B;0BAA5B,UAAU;IAAqB,CAAC;IAE7D,MAAM,CAAC,UAAU,CACf,MAA2B,EAC3B,IAAa;QAEb,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAClC,MAAM,SAAS,GAAG,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;QAC5C,MA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I,GAAI,SAAiD,EAAE,CAAC,IAAI,CAAC,CAAC;QACxE,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,IAAI,KAAK,SAAS;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrF,CAAC;IAED,OAAO,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,EAAW,EAAE,GAAG,CAAC,CAAC;AACrD,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CACjB,QAAqC,EACrC,IAAwB,EACxB,KAAwB;IAExB,IAAI,CAAC,QAAQ;QAAE,OAAO;IACtB,MAAM,SAAS,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,CAA0C,CAAC;IAC1F,MAAM,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;IACrC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diff.d.ts","sourceRoot":"","sources":["../../../src/projection/card/Diff.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Diff.d.ts","sourceRoot":"","sources":["../../../src/projection/card/Diff.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,IAAI;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,yFAAyF;IACzF,SAAS,EAAE,eAAe,EAAE,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CACrB,GAAG,EAAE,gBAAgB,EACrB,EAAE,EAAE,gBAAgB,EACpB,OAAO,GAAE,WAAgB,GACxB,IAAI,CAmCN"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dequal } from 'dequal';
|
|
2
2
|
import { Axes } from '../../axis/Axes.js';
|
|
3
|
+
import { Shapes } from '../../axis/shape/Shape.js';
|
|
3
4
|
/**
|
|
4
5
|
* What changed between two descriptions of the same entity, read from the wire form alone.
|
|
5
6
|
* FR : ce qui a changé entre deux descriptions d'une même entité, lu du seul format du fil.
|
|
@@ -76,10 +77,7 @@ function shapeOf(descriptor) {
|
|
|
76
77
|
* `typesOf({ type: ['null', 'string'] })` → `['null', 'string']`
|
|
77
78
|
*/
|
|
78
79
|
function typesOf(descriptor) {
|
|
79
|
-
|
|
80
|
-
if (type === undefined)
|
|
81
|
-
return [];
|
|
82
|
-
return (Array.isArray(type) ? [...type] : [type]).sort();
|
|
80
|
+
return [...Shapes.typesOf(descriptor)].sort();
|
|
83
81
|
}
|
|
84
82
|
/**
|
|
85
83
|
* The shape without its type, which is what tells a `reshaped` from a `retyped`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diff.js","sourceRoot":"","sources":["../../../src/projection/card/Diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"Diff.js","sourceRoot":"","sources":["../../../src/projection/card/Diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM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C,OAAO,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAEtD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -17,7 +17,6 @@ export class FieldValueValidator {
|
|
|
17
17
|
validate(value) {
|
|
18
18
|
const shape = this.field.shape;
|
|
19
19
|
const type = Shapes.typeOf(shape);
|
|
20
|
-
const base = Shapes.of(shape).base;
|
|
21
20
|
if (value !== null) {
|
|
22
21
|
if (type === 'date' && value instanceof Date) {
|
|
23
22
|
return Number.isNaN(value.getTime()) ? { message: 'Invalid date' } : { value };
|
|
@@ -27,7 +26,8 @@ export class FieldValueValidator {
|
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
const plan = FieldValueValidator.planFor(shape);
|
|
30
|
-
const
|
|
29
|
+
const travelling = type === 'object' || type === 'array' ? Boundary.forShape(shape).encode(value) : value;
|
|
30
|
+
const refusal = JsonSchemaValidator.of(shape).refusalOf(travelling, []);
|
|
31
31
|
if (refusal) {
|
|
32
32
|
return refusal.path.length > 0 ? { message: refusal.message, path: refusal.path } : { message: refusal.message };
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldValueValidator.js","sourceRoot":"","sources":["../../src/validator/FieldValueValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO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xC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,IAAI,aAAa,CAAC,EAAE,CAAC;YACxC,MAAM,IAAI,WAAW,CACnB,oBAAoB,IAAI,+CAA+C,IAAI,UAAU;gBACnF,wBAAwB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,gDAAgD,CAC5G,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/schema",
|
|
3
|
-
"version": "0.12.
|
|
4
|
-
"description": "The entity and its 4 axes
|
|
3
|
+
"version": "0.12.5-alpha.0",
|
|
4
|
+
"description": "The entity and its 4 axes — shape, role, lifecycle, boundary. Subject-owned judgments, edge-safe.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
7
7
|
"typescript",
|
|
@@ -32,18 +32,12 @@
|
|
|
32
32
|
"dist",
|
|
33
33
|
"src"
|
|
34
34
|
],
|
|
35
|
-
"scripts": {
|
|
36
|
-
"build": "rm -rf dist && tsc",
|
|
37
|
-
"test": "vitest run",
|
|
38
|
-
"test:watch": "vitest",
|
|
39
|
-
"typecheck": "tsc --noEmit -p tsconfig.test.json",
|
|
40
|
-
"prepublishOnly": "pnpm run build"
|
|
41
|
-
},
|
|
42
35
|
"dependencies": {
|
|
43
36
|
"@cfworker/json-schema": "^4.1.1",
|
|
44
37
|
"@paralleldrive/cuid2": "^3.3.0",
|
|
45
38
|
"@standard-schema/spec": "^1.1.0",
|
|
46
|
-
"dequal": "^2.0.3"
|
|
39
|
+
"dequal": "^2.0.3",
|
|
40
|
+
"@types/json-schema": "^7.0.15"
|
|
47
41
|
},
|
|
48
42
|
"devDependencies": {
|
|
49
43
|
"@tanstack/form-core": "^1.33.5",
|
|
@@ -52,5 +46,11 @@
|
|
|
52
46
|
},
|
|
53
47
|
"publishConfig": {
|
|
54
48
|
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "rm -rf dist && tsc",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:watch": "vitest",
|
|
54
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json"
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
}
|
package/src/Schema.ts
CHANGED
|
@@ -8,8 +8,7 @@ import { type PreviousNames } from './entity/PreviousNames.js';
|
|
|
8
8
|
import { type EntityAdapters } from './entity/EntityAdapters.js';
|
|
9
9
|
import { InputValidator } from './validator/InputValidator.js';
|
|
10
10
|
import { SchemaDerivation } from './SchemaDerivation.js';
|
|
11
|
-
import { type
|
|
12
|
-
import { SchemaDefinition } from './SchemaDefinition.js';
|
|
11
|
+
import { SchemaDefinition, type SchemaDeclaration } from './SchemaDefinition.js';
|
|
13
12
|
import { type ValidateOptions } from './validator/ValidateOptions.js';
|
|
14
13
|
|
|
15
14
|
import type { SchemaView } from './SchemaView.js';
|
|
@@ -54,11 +53,11 @@ export class Schema {
|
|
|
54
53
|
static getAdapters(): EntityAdapters<Fields> {
|
|
55
54
|
return this.definition.adapterSet.adapters;
|
|
56
55
|
}
|
|
57
|
-
static getUnique(): FieldGroups<Fields>
|
|
56
|
+
static getUnique(): FieldGroups<Fields> {
|
|
58
57
|
return this.definition.constraints.unique;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
static getIndex(): FieldGroups<Fields>
|
|
60
|
+
static getIndex(): FieldGroups<Fields> {
|
|
62
61
|
return this.definition.constraints.index;
|
|
63
62
|
}
|
|
64
63
|
static getOpts(): ValidateOptions {
|
|
@@ -150,26 +149,16 @@ export class Schema {
|
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
static compose<T extends SchemaView[]>(...sources: T): SchemaConstructor<Merged<T>> {
|
|
153
|
-
return Schema.subclass(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
previous?: PreviousNames<TFields>;
|
|
164
|
-
anchored?: boolean;
|
|
165
|
-
constraints?: SchemaConstraints;
|
|
166
|
-
}): SchemaConstructor<TFields> {
|
|
167
|
-
return Schema.subclass(
|
|
168
|
-
SchemaDefinition.of(declaration),
|
|
169
|
-
) as unknown as SchemaConstructor<TFields>;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private static subclass(definition: SchemaDefinition): SchemaConstructor<Fields> {
|
|
152
|
+
return Schema.subclass(SchemaDefinition.merged(sources));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static of<TFields extends Fields>(declaration: SchemaDeclaration<TFields>): SchemaConstructor<TFields> {
|
|
156
|
+
return Schema.subclass(SchemaDefinition.of(declaration));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private static subclass<TFields extends Fields = Fields>(
|
|
160
|
+
definition: SchemaDefinition,
|
|
161
|
+
): SchemaConstructor<TFields> {
|
|
173
162
|
class Derived extends Schema {}
|
|
174
163
|
Derived.definition = definition;
|
|
175
164
|
Object.defineProperty(Derived, 'name', {
|
|
@@ -177,7 +166,7 @@ export class Schema {
|
|
|
177
166
|
configurable: true,
|
|
178
167
|
});
|
|
179
168
|
|
|
180
|
-
return Derived as unknown as SchemaConstructor<
|
|
169
|
+
return Derived as unknown as SchemaConstructor<TFields>;
|
|
181
170
|
}
|
|
182
171
|
}
|
|
183
172
|
|
package/src/SchemaConstraints.ts
CHANGED
|
@@ -10,15 +10,12 @@ import { type FieldGroups } from './entity/FieldGroups.js';
|
|
|
10
10
|
* argument in a list that has already lost one.
|
|
11
11
|
*/
|
|
12
12
|
export class SchemaConstraints<TFields extends Fields = Fields> {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
private constructor(
|
|
14
|
+
readonly unique: FieldGroups<TFields>,
|
|
15
|
+
readonly index: FieldGroups<TFields>,
|
|
16
|
+
) {}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
if (unique) this.unique = unique;
|
|
18
|
-
if (index) this.index = index;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static readonly none = new SchemaConstraints();
|
|
18
|
+
static readonly none = new SchemaConstraints([], []);
|
|
22
19
|
|
|
23
20
|
/**
|
|
24
21
|
* The order is part of a group, so `['a','b']` and `['b','a']` are two constraints.
|
|
@@ -41,21 +38,20 @@ export class SchemaConstraints<TFields extends Fields = Fields> {
|
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
const deduped = <TFields extends Fields>(
|
|
44
|
-
groups
|
|
45
|
-
): FieldGroups<TFields>
|
|
46
|
-
if (!groups) return undefined;
|
|
41
|
+
groups: FieldGroups<TFields> = [],
|
|
42
|
+
): FieldGroups<TFields> => {
|
|
47
43
|
const seen = new Map<string, readonly FieldName<TFields>[]>();
|
|
48
44
|
for (const group of groups) seen.set(JSON.stringify(group), group);
|
|
49
45
|
|
|
50
|
-
return
|
|
46
|
+
return [...seen.values()];
|
|
51
47
|
};
|
|
52
48
|
|
|
53
49
|
const survivors = (
|
|
54
|
-
groups: FieldGroups<Fields
|
|
50
|
+
groups: FieldGroups<Fields>,
|
|
55
51
|
transform: (key: string) => string | undefined,
|
|
56
52
|
): string[][] => {
|
|
57
53
|
const kept: string[][] = [];
|
|
58
|
-
for (const group of groups
|
|
54
|
+
for (const group of groups) {
|
|
59
55
|
const renamed = group.map(transform);
|
|
60
56
|
if (renamed.every((key): key is string => key !== undefined)) kept.push(renamed);
|
|
61
57
|
}
|
package/src/SchemaDefinition.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { FieldSet } from './field/FieldSet.js';
|
|
|
3
3
|
|
|
4
4
|
import { type EntityDeclarations } from './entity/EntityDeclarations.js';
|
|
5
5
|
import { type PreviousNames } from './entity/PreviousNames.js';
|
|
6
|
-
import { type EntityAdapters } from './entity/EntityAdapters.js';
|
|
7
6
|
import { EntityAdapterSet } from './entity/EntityAdapterSet.js';
|
|
8
7
|
import { SchemaDerivation } from './SchemaDerivation.js';
|
|
9
8
|
import { type ValidateOptions } from './validator/ValidateOptions.js';
|
|
@@ -28,6 +27,13 @@ interface SchemaState {
|
|
|
28
27
|
constraints: SchemaConstraints;
|
|
29
28
|
}
|
|
30
29
|
|
|
30
|
+
/** What a schema is built from; the rest is stated by `declares` or inherited by a derivation. */
|
|
31
|
+
export interface SchemaDeclaration<TFields extends Fields> {
|
|
32
|
+
fields: TFields;
|
|
33
|
+
opts?: ValidateOptions;
|
|
34
|
+
constraints?: SchemaConstraints;
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
/** The keys a derivation keeps, in the order it keeps them, under the names they take. */
|
|
32
38
|
type Renaming = ReadonlyMap<string, string>;
|
|
33
39
|
|
|
@@ -74,53 +80,31 @@ export class SchemaDefinition {
|
|
|
74
80
|
* What they do not name is kept, and that is the whole difference with `derived`.
|
|
75
81
|
*/
|
|
76
82
|
private restated(state: Partial<SchemaState>): SchemaDefinition {
|
|
77
|
-
return new SchemaDefinition({
|
|
78
|
-
fields: this.fields,
|
|
79
|
-
adapterSet: this.adapterSet,
|
|
80
|
-
opts: this.opts,
|
|
81
|
-
previous: this.previous,
|
|
82
|
-
derivation: this.derivation,
|
|
83
|
-
anchored: this.anchored,
|
|
84
|
-
constraints: this.constraints,
|
|
85
|
-
...state,
|
|
86
|
-
});
|
|
83
|
+
return new SchemaDefinition({ ...this, ...state });
|
|
87
84
|
}
|
|
88
85
|
|
|
89
86
|
/** Built complete or not at all — no static assigned on the side. */
|
|
90
|
-
static of(declaration: {
|
|
91
|
-
|
|
92
|
-
adapters?: EntityAdapters<Fields>;
|
|
93
|
-
opts?: ValidateOptions;
|
|
94
|
-
previous?: PreviousNames<Fields>;
|
|
95
|
-
derivation?: SchemaDerivation;
|
|
96
|
-
anchored?: boolean;
|
|
97
|
-
constraints?: SchemaConstraints;
|
|
98
|
-
}): SchemaDefinition {
|
|
99
|
-
return new SchemaDefinition({
|
|
87
|
+
static of(declaration: SchemaDeclaration<Fields>): SchemaDefinition {
|
|
88
|
+
return SchemaDefinition.derived({
|
|
100
89
|
fields: declaration.fields,
|
|
101
|
-
adapterSet: EntityAdapterSet.
|
|
90
|
+
adapterSet: EntityAdapterSet.none,
|
|
102
91
|
opts: declaration.opts ?? {},
|
|
103
|
-
|
|
104
|
-
derivation: declaration.derivation,
|
|
105
|
-
anchored: declaration.anchored ?? false,
|
|
92
|
+
derivation: undefined,
|
|
106
93
|
constraints: declaration.constraints ?? SchemaConstraints.none,
|
|
107
94
|
});
|
|
108
95
|
}
|
|
109
96
|
|
|
110
97
|
declaring(declarations: EntityDeclarations<Fields>): SchemaDefinition {
|
|
111
|
-
const
|
|
98
|
+
const adapterSet = EntityAdapterSet.of(declarations.adapters);
|
|
112
99
|
this.assertKnown('declares', [
|
|
113
|
-
...
|
|
100
|
+
...adapterSet.fieldNames,
|
|
114
101
|
...Object.keys(declarations.previous ?? {}),
|
|
115
102
|
]);
|
|
116
103
|
const declared = FieldSet.declaring(this.fields, declarations);
|
|
117
104
|
|
|
118
105
|
return this.restated({
|
|
119
106
|
fields: declared.fields,
|
|
120
|
-
adapterSet: EntityAdapterSet.merged([
|
|
121
|
-
this.adapterSet,
|
|
122
|
-
EntityAdapterSet.of(declarations.adapters),
|
|
123
|
-
]),
|
|
107
|
+
adapterSet: EntityAdapterSet.merged([this.adapterSet, adapterSet]),
|
|
124
108
|
previous: declarations.previous ?? this.previous,
|
|
125
109
|
constraints:
|
|
126
110
|
declarations.unique === undefined && declarations.index === undefined
|
|
@@ -204,8 +188,8 @@ export class SchemaDefinition {
|
|
|
204
188
|
for (const view of views) {
|
|
205
189
|
Object.assign(fields, view.getFields());
|
|
206
190
|
opts = { ...opts, ...view.getOpts() };
|
|
207
|
-
groups.unique.push(...
|
|
208
|
-
groups.index.push(...
|
|
191
|
+
groups.unique.push(...view.getUnique());
|
|
192
|
+
groups.index.push(...view.getIndex());
|
|
209
193
|
}
|
|
210
194
|
|
|
211
195
|
return SchemaDefinition.derived({
|
package/src/SchemaView.ts
CHANGED
|
@@ -17,8 +17,8 @@ export interface SchemaView<TFields extends Fields = Fields> {
|
|
|
17
17
|
readonly anchored?: boolean;
|
|
18
18
|
getFields(): TFields;
|
|
19
19
|
getAdapters(): EntityAdapters<TFields>;
|
|
20
|
-
getUnique(): FieldGroups<TFields
|
|
21
|
-
getIndex(): FieldGroups<TFields
|
|
20
|
+
getUnique(): FieldGroups<TFields>;
|
|
21
|
+
getIndex(): FieldGroups<TFields>;
|
|
22
22
|
getOpts(): ValidateOptions;
|
|
23
23
|
validate(input: unknown): ValidationResult<Values<TFields>>;
|
|
24
24
|
}
|
|
@@ -6,6 +6,7 @@ import { type Shape } from '../shape/Shape.js';
|
|
|
6
6
|
import { Shapes } from '../shape/Shape.js';
|
|
7
7
|
import { SchemaError } from '../../SchemaError.js';
|
|
8
8
|
import { Format, type Accepted } from '../../lib/Format.js';
|
|
9
|
+
import { isObject } from '../../lib/utils.js';
|
|
9
10
|
|
|
10
11
|
const closedOr = <Verb extends 'decode' | 'encode'>(verb: Verb) =>
|
|
11
12
|
Format.either(Format.tokens(['closed']), Format.of().key(verb, Format.text).needs(verb).closed());
|
|
@@ -66,23 +67,95 @@ export class Boundary {
|
|
|
66
67
|
|
|
67
68
|
return new Boundary(rules, {
|
|
68
69
|
decode:
|
|
69
|
-
|
|
70
|
-
?
|
|
71
|
-
:
|
|
70
|
+
rules.in === 'closed'
|
|
71
|
+
? identityDecoder
|
|
72
|
+
: typeof declared.rules.in === 'object'
|
|
73
|
+
? Boundaries.decoders.resolve(declared.rules.in.decode)
|
|
74
|
+
: derived.decode,
|
|
72
75
|
encode:
|
|
73
|
-
|
|
74
|
-
?
|
|
75
|
-
:
|
|
76
|
+
rules.out === 'closed'
|
|
77
|
+
? identityEncoder
|
|
78
|
+
: typeof declared.rules.out === 'object'
|
|
79
|
+
? Boundaries.encoders.resolve(declared.rules.out.encode)
|
|
80
|
+
: derived.encode,
|
|
76
81
|
});
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* `date-time` means a `Date` on both sides, without a word in the entity — and so does a
|
|
86
|
+
* `date-time` inside `json(Address)`, read off the properties the shape already states.
|
|
87
|
+
*/
|
|
80
88
|
static forShape(shape: Shape | undefined): Boundary {
|
|
81
|
-
if (Shapes.typeOf(shape) === 'date')
|
|
89
|
+
if (Shapes.typeOf(shape) === 'date') {
|
|
90
|
+
return new Boundary(Boundaries.aliases.resolve('isoDate'), {
|
|
91
|
+
decode: Boundaries.decoders.resolve('isoDate'),
|
|
92
|
+
encode: Boundaries.encoders.resolve('isoDate'),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const base = Shapes.of(shape).base;
|
|
97
|
+
if (base?.type === 'object' && base.properties) return Boundary.within(base.properties as Record<string, Shape>);
|
|
98
|
+
if (base?.type === 'array' && base.items) return Boundary.each(Boundary.forShape(base.items));
|
|
82
99
|
|
|
83
100
|
return new Boundary();
|
|
84
101
|
}
|
|
85
102
|
|
|
103
|
+
private static within(properties: Record<string, Shape>): Boundary {
|
|
104
|
+
const boundaries = Object.entries(properties)
|
|
105
|
+
.map(([key, shape]) => [key, Boundary.forShape(shape)] as const)
|
|
106
|
+
.filter(([, boundary]) => boundary.decode !== identityDecoder);
|
|
107
|
+
if (boundaries.length === 0) return new Boundary();
|
|
108
|
+
|
|
109
|
+
const decode: Decoder = (value) => {
|
|
110
|
+
if (!isObject(value)) return { value };
|
|
111
|
+
const row: Record<string, unknown> = { ...value };
|
|
112
|
+
for (const [key, boundary] of boundaries) {
|
|
113
|
+
if (row[key] === null || row[key] === undefined) continue;
|
|
114
|
+
const verdict = boundary.decode(row[key]);
|
|
115
|
+
if ('message' in verdict) return { ...verdict, path: [key, ...(verdict.path ?? [])] };
|
|
116
|
+
row[key] = verdict.value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return { value: row };
|
|
120
|
+
};
|
|
121
|
+
const encode: Encoder = (value) => {
|
|
122
|
+
if (!isObject(value)) return value;
|
|
123
|
+
const row: Record<string, unknown> = { ...value };
|
|
124
|
+
for (const [key, boundary] of boundaries) {
|
|
125
|
+
if (row[key] === null || row[key] === undefined) continue;
|
|
126
|
+
row[key] = boundary.encode(row[key]);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return row;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
return new Boundary({}, { decode, encode });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private static each(item: Boundary): Boundary {
|
|
136
|
+
if (item.decode === identityDecoder) return new Boundary();
|
|
137
|
+
|
|
138
|
+
const decode: Decoder = (value) => {
|
|
139
|
+
if (!Array.isArray(value)) return { value };
|
|
140
|
+
const items: unknown[] = [];
|
|
141
|
+
for (const [index, element] of value.entries()) {
|
|
142
|
+
if (element === null || element === undefined) {
|
|
143
|
+
items.push(element);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const verdict = item.decode(element);
|
|
147
|
+
if ('message' in verdict) return { ...verdict, path: [String(index), ...(verdict.path ?? [])] };
|
|
148
|
+
items.push(verdict.value);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return { value: items };
|
|
152
|
+
};
|
|
153
|
+
const encode: Encoder = (value) =>
|
|
154
|
+
Array.isArray(value) ? value.map((element) => (element === null || element === undefined ? element : item.encode(element))) : value;
|
|
155
|
+
|
|
156
|
+
return new Boundary({}, { decode, encode });
|
|
157
|
+
}
|
|
158
|
+
|
|
86
159
|
/** The dual of `declared`: what `readOnly()` writes back on the field, not a judge. */
|
|
87
160
|
declaring(overrides: BoundaryRules): BoundaryRules {
|
|
88
161
|
return { in: overrides.in ?? this.rules.in, out: overrides.out ?? this.rules.out };
|
|
@@ -40,6 +40,6 @@ Boundaries.decoders.register('isoDate', (value) => {
|
|
|
40
40
|
return { message: 'Expected a date' };
|
|
41
41
|
});
|
|
42
42
|
Boundaries.encoders.register('isoDate', (value) =>
|
|
43
|
-
value instanceof Date ? value.toISOString() : value,
|
|
43
|
+
value instanceof Date && !Number.isNaN(value.getTime()) ? value.toISOString() : value,
|
|
44
44
|
);
|
|
45
45
|
Boundaries.aliases.register('isoDate', { in: { decode: 'isoDate' }, out: { encode: 'isoDate' } });
|
package/src/axis/shape/Shape.ts
CHANGED
|
@@ -80,10 +80,6 @@ type _ShapeTypesAreTheStandardsLessNull = Assert<
|
|
|
80
80
|
: false
|
|
81
81
|
>;
|
|
82
82
|
|
|
83
|
-
/** Every type name a shape states, whether it states one or a union of them. */
|
|
84
|
-
const typesOf = (shape: Shape): readonly string[] =>
|
|
85
|
-
(Array.isArray(shape.type) ? shape.type : [shape.type]) as readonly string[];
|
|
86
|
-
|
|
87
83
|
export class Shapes {
|
|
88
84
|
private static readonly cache = new WeakMap<object, ShapeParts>();
|
|
89
85
|
private static readonly none: ShapeParts = { base: undefined, nullable: false };
|
|
@@ -128,7 +124,7 @@ export class Shapes {
|
|
|
128
124
|
* `{ type: 'string', enum: ['draft'] }` → `{ type: ['string','null'], enum: ['draft', null] }`
|
|
129
125
|
*/
|
|
130
126
|
static nullable(shape: Shape): Shape {
|
|
131
|
-
const types = typesOf(shape);
|
|
127
|
+
const types = Shapes.typesOf(shape);
|
|
132
128
|
if (types.includes('null')) return shape;
|
|
133
129
|
|
|
134
130
|
const nullable = { ...shape, type: [...types, 'null'] } as unknown as Shape;
|
|
@@ -142,6 +138,13 @@ export class Shapes {
|
|
|
142
138
|
return nullable;
|
|
143
139
|
}
|
|
144
140
|
|
|
141
|
+
/** Every type name a shape states — none, since a card may carry a property with no `type`. */
|
|
142
|
+
static typesOf(shape: { type?: string | readonly string[] }): readonly string[] {
|
|
143
|
+
if (shape.type === undefined) return [];
|
|
144
|
+
|
|
145
|
+
return typeof shape.type === 'string' ? [shape.type] : shape.type;
|
|
146
|
+
}
|
|
147
|
+
|
|
145
148
|
static of(shape?: Shape): ShapeParts {
|
|
146
149
|
if (!shape) return this.none;
|
|
147
150
|
let parts = this.cache.get(shape);
|
|
@@ -12,12 +12,14 @@ export class EntityAdapterSet {
|
|
|
12
12
|
*/
|
|
13
13
|
private constructor(readonly adapters: EntityAdapters<Fields>) {}
|
|
14
14
|
|
|
15
|
+
static readonly none = new EntityAdapterSet({});
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* Stops a malformed declaration from propagating, by checking its two levels.
|
|
17
19
|
* `of({ sql: { body: 3 } })` → passes; `of({ sql: 'oops' })` → throws, naming `adapters.sql`
|
|
18
20
|
*/
|
|
19
21
|
static of(adapters?: EntityAdapters<Fields>): EntityAdapterSet {
|
|
20
|
-
if (!adapters) return
|
|
22
|
+
if (!adapters) return EntityAdapterSet.none;
|
|
21
23
|
|
|
22
24
|
if (!isObject(adapters)) {
|
|
23
25
|
throw new SchemaError(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Axes } from '../../axis/Axes.js';
|
|
2
|
+
import { Shapes } from '../../axis/shape/Shape.js';
|
|
2
3
|
import { CardForms } from './CardForms.js';
|
|
3
4
|
import { type Resolver } from '../../axis/Resolver.js';
|
|
4
5
|
import { clean, isObject } from '../../lib/utils.js';
|
|
@@ -42,7 +43,7 @@ export class Card<T = Values<Fields>> {
|
|
|
42
43
|
if (validator.requires(field)) required.push(key);
|
|
43
44
|
}
|
|
44
45
|
for (const kind of ['unique', 'index'] as const)
|
|
45
|
-
for (const group of
|
|
46
|
+
for (const group of kind === 'unique' ? schema.getUnique() : schema.getIndex())
|
|
46
47
|
for (const member of group) carryGroup(properties[member], kind, group);
|
|
47
48
|
|
|
48
49
|
const descriptor: SchemaDescriptor = {
|
|
@@ -172,11 +173,7 @@ function originOf(schema: SchemaView): DerivedFrom | undefined {
|
|
|
172
173
|
* `{ type: 'string', maxLength: 200 }` → the same shape `text({ max: 200 })` states
|
|
173
174
|
*/
|
|
174
175
|
function reconstructShape(property: FieldDescriptor): Field['shape'] | undefined {
|
|
175
|
-
const types =
|
|
176
|
-
? property.type
|
|
177
|
-
: property.type
|
|
178
|
-
? [property.type]
|
|
179
|
-
: [];
|
|
176
|
+
const types = Shapes.typesOf(property);
|
|
180
177
|
if (!types.some((type) => type !== 'null')) return undefined;
|
|
181
178
|
|
|
182
179
|
// `describeField` writes the shape whole, so it is read whole: a list of keywords here
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dequal } from 'dequal';
|
|
2
2
|
import { Axes } from '../../axis/Axes.js';
|
|
3
|
+
import { Shapes } from '../../axis/shape/Shape.js';
|
|
3
4
|
import type { FieldDescriptor } from './FieldDescriptor.js';
|
|
4
5
|
import type { FieldExtension } from './FieldExtension.js';
|
|
5
6
|
|
|
@@ -117,10 +118,7 @@ function shapeOf(descriptor: FieldDescriptor): Record<string, unknown> {
|
|
|
117
118
|
* `typesOf({ type: ['null', 'string'] })` → `['null', 'string']`
|
|
118
119
|
*/
|
|
119
120
|
function typesOf(descriptor: FieldDescriptor): TypeSet {
|
|
120
|
-
|
|
121
|
-
if (type === undefined) return [];
|
|
122
|
-
|
|
123
|
-
return (Array.isArray(type) ? [...type] : [type]).sort();
|
|
121
|
+
return [...Shapes.typesOf(descriptor)].sort();
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
/**
|