@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.
Files changed (62) hide show
  1. package/CHANGELOG.md +307 -1
  2. package/README.md +173 -89
  3. package/SECURITY.md +24 -1
  4. package/index.d.ts +601 -29
  5. package/package.json +28 -3
  6. package/src/checks.js +789 -0
  7. package/src/codec.js +201 -46
  8. package/src/coerce/index.d.ts +34 -0
  9. package/src/coerce/index.js +385 -0
  10. package/src/compile/emit.js +87 -28
  11. package/src/compile/index.js +9 -4
  12. package/src/context.js +6 -1
  13. package/src/definition/index.d.ts +19 -0
  14. package/src/definition/index.js +27 -0
  15. package/src/derive/index.d.ts +86 -0
  16. package/src/derive/index.js +273 -0
  17. package/src/errors.js +46 -4
  18. package/src/formats/index.d.ts +20 -8
  19. package/src/formats/index.js +450 -39
  20. package/src/generators/fromjsonschema.js +21 -2
  21. package/src/generators/index.js +1 -1
  22. package/src/generators/jsonschema.js +90 -21
  23. package/src/generators/typescript.js +11 -0
  24. package/src/index.js +3 -2
  25. package/src/issues.js +9 -7
  26. package/src/kinds.js +15 -3
  27. package/src/lint.js +38 -0
  28. package/src/locales/en.js +6 -0
  29. package/src/locales/uk.js +6 -0
  30. package/src/metadata.js +6 -24
  31. package/src/model/data.js +67 -10
  32. package/src/model/diff.js +7 -4
  33. package/src/model/index.js +1 -1
  34. package/src/model/infer.js +10 -3
  35. package/src/model/merge.js +16 -9
  36. package/src/model/restore.js +52 -7
  37. package/src/model/sample.js +28 -4
  38. package/src/model.js +54 -56
  39. package/src/mongodb/bson.js +130 -0
  40. package/src/mongodb/document.js +217 -0
  41. package/src/mongodb/index.d.ts +133 -0
  42. package/src/mongodb/index.js +24 -0
  43. package/src/mongodb/indexes.js +79 -0
  44. package/src/mongodb/update.js +258 -0
  45. package/src/preprocessor.js +1 -2
  46. package/src/prototypes/abstract.js +41 -67
  47. package/src/prototypes/collections.js +3 -90
  48. package/src/prototypes/flags.js +34 -0
  49. package/src/prototypes/json.js +0 -11
  50. package/src/prototypes/reference.js +0 -76
  51. package/src/prototypes/scalars.js +17 -96
  52. package/src/prototypes/schema.js +1 -10
  53. package/src/prototypes/tuple.js +0 -26
  54. package/src/prototypes/union.js +12 -82
  55. package/src/rules.js +33 -157
  56. package/src/schema.js +105 -220
  57. package/src/snapshot.js +216 -41
  58. package/src/stream/index.js +1 -1
  59. package/src/struct.js +6 -91
  60. package/src/types.js +43 -6
  61. package/src/util.js +43 -0
  62. 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