@alexify/metaschema 3.2.0 → 3.4.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/CHANGELOG.md +307 -1
- package/README.md +173 -89
- package/SECURITY.md +24 -1
- package/index.d.ts +601 -29
- package/package.json +28 -3
- package/src/checks.js +789 -0
- package/src/codec.js +201 -46
- package/src/coerce/index.d.ts +34 -0
- package/src/coerce/index.js +385 -0
- package/src/compile/emit.js +87 -28
- package/src/compile/index.js +9 -4
- package/src/context.js +6 -1
- package/src/definition/index.d.ts +19 -0
- package/src/definition/index.js +27 -0
- package/src/derive/index.d.ts +86 -0
- package/src/derive/index.js +273 -0
- package/src/errors.js +46 -4
- package/src/formats/index.d.ts +20 -8
- package/src/formats/index.js +450 -39
- package/src/generators/fromjsonschema.js +21 -2
- package/src/generators/index.js +1 -1
- package/src/generators/jsonschema.js +90 -21
- package/src/generators/typescript.js +11 -0
- package/src/index.js +3 -2
- package/src/issues.js +9 -7
- package/src/kinds.js +15 -3
- package/src/lint.js +38 -0
- package/src/locales/en.js +6 -0
- package/src/locales/uk.js +6 -0
- package/src/metadata.js +6 -24
- package/src/model/data.js +67 -10
- package/src/model/diff.js +7 -4
- package/src/model/index.js +1 -1
- package/src/model/infer.js +10 -3
- package/src/model/merge.js +16 -9
- package/src/model/restore.js +52 -7
- package/src/model/sample.js +28 -4
- package/src/model.js +54 -56
- package/src/mongodb/bson.js +130 -0
- package/src/mongodb/document.js +217 -0
- package/src/mongodb/index.d.ts +133 -0
- package/src/mongodb/index.js +24 -0
- package/src/mongodb/indexes.js +79 -0
- package/src/mongodb/update.js +258 -0
- package/src/preprocessor.js +1 -2
- package/src/prototypes/abstract.js +41 -67
- package/src/prototypes/collections.js +3 -90
- package/src/prototypes/flags.js +34 -0
- package/src/prototypes/json.js +0 -11
- package/src/prototypes/reference.js +0 -76
- package/src/prototypes/scalars.js +17 -96
- package/src/prototypes/schema.js +1 -10
- package/src/prototypes/tuple.js +0 -26
- package/src/prototypes/union.js +12 -82
- package/src/rules.js +33 -157
- package/src/schema.js +105 -220
- package/src/snapshot.js +216 -41
- package/src/stream/index.js +1 -1
- package/src/struct.js +6 -91
- package/src/types.js +43 -6
- package/src/util.js +43 -0
- package/src/validation.js +313 -0
package/SECURITY.md
CHANGED
|
@@ -53,7 +53,9 @@ Some things work as intended and are not vulnerabilities:
|
|
|
53
53
|
`canEval()` runs `new Function('')` once; under a CSP with a `report-uri` that one violation
|
|
54
54
|
is reported, and under a report-only policy the probe succeeds and every build is reported. A
|
|
55
55
|
check the generator cannot build is reported (`compile().error`, `register({ onFallback })`),
|
|
56
|
-
never installed. The core entry never calls `new Function`.
|
|
56
|
+
never installed. The core entry never calls `new Function`. The checks are compiled on their
|
|
57
|
+
first use (3.4), so a rule changed on a built field after construction reaches the generator
|
|
58
|
+
too; it reaches the source as a literal or a name of the scope all the same.
|
|
57
59
|
- **Input shape is checked strictly.** Every key that is not in the schema is reported as
|
|
58
60
|
unexpected (`has unexpected keys: ...`, the first ten of them), including `constructor`,
|
|
59
61
|
`__proto__` and `toString`, unless the schema or the call says `unknown: 'ignore'`. Fields
|
|
@@ -73,6 +75,27 @@ Some things work as intended and are not vulnerabilities:
|
|
|
73
75
|
all the same: those documents are untrusted input for their structure (a keyword outside the
|
|
74
76
|
subset, a key named `__proto__`, a depth past the limit are errors, never a looser schema),
|
|
75
77
|
but a pattern in them is the importer's to review or to bound.
|
|
78
|
+
- **A snapshot is data, both ways.** What `schema.toSnapshot()` and `model.toJSON()` return is
|
|
79
|
+
a copy (the `custom` metadata of a kind, the indexes and the `database` metadata included):
|
|
80
|
+
no function, no object of the model, a function as `{ $function: true }`. Read back by
|
|
81
|
+
`fromJSON`, a snapshot is untrusted input: its tags (`$date`, `$bigint`, `$bytes`, `$map`,
|
|
82
|
+
`$set`) are read into values and a tag that does not read is `ERR_INVALID_SNAPSHOT`; a value
|
|
83
|
+
shaped like a `Date` or a `RegExp` (`{ "constructor": { "name": "Date" } }`) is data; its
|
|
84
|
+
`root` names one of its entities; a field key `root` is refused like the methods of a field;
|
|
85
|
+
the walks are bounded (128 levels, and a chain of entities of any length orders without
|
|
86
|
+
recursion). A model restored from a snapshot validates its structure with placeholders for the
|
|
87
|
+
functions, which `model.placeholders` lists.
|
|
88
|
+
- **Binary data is bounded by its `length`.** The `bytes` converter of `./coerce` decodes
|
|
89
|
+
canonical base64 only, in linear time, and leaves a text whose bytes would be over
|
|
90
|
+
`length.max` undecoded, so a field with a `length` caps what a request can make it allocate;
|
|
91
|
+
a `bytes` field without one decodes a text of any size, like a string field without
|
|
92
|
+
`length.max` holds one. `fromDocument` of `./mongodb` reads a generic Binary (subtype 0 or
|
|
93
|
+
2) into a copy of its bytes and leaves any other subtype to the check.
|
|
94
|
+
- **The definition entry does not validate.** A schema built through
|
|
95
|
+
`@alexify/metaschema/definition` throws `ERR_NOT_REGISTERED` from every way to validate until
|
|
96
|
+
the core entry of the same copy of the package is loaded, and has no `~standard`, so a
|
|
97
|
+
consumer of Standard Schema never takes it for a validator. A schema of another copy (two
|
|
98
|
+
versions of the package installed) does not validate with this copy's core and says so.
|
|
76
99
|
- **Samples are input.** `infer` of the model subpath walks the values it is given with a depth
|
|
77
100
|
limit, trusts no key (`__proto__`, `constructor` and the names of the methods of a field are
|
|
78
101
|
keys of the definition, written as own properties), and checks the definition it built
|