pema 0.9.1 → 0.9.2

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.
@@ -4,6 +4,14 @@ import OptionalType from "#OptionalType";
4
4
  import resolve from "#resolve";
5
5
  import Storable from "#Storable";
6
6
  import is from "@rcompat/is";
7
+ function json_with_undefined_object_values(x) {
8
+ if (is.array(x))
9
+ return x.every(json_with_undefined_object_values);
10
+ if (is.dict(x)) {
11
+ return Object.values(x).every(value => is.undefined(value) || json_with_undefined_object_values(value));
12
+ }
13
+ return is.json(x);
14
+ }
7
15
  export default class JSONType extends Storable {
8
16
  #inner;
9
17
  constructor(inner) {
@@ -27,8 +35,9 @@ export default class JSONType extends Storable {
27
35
  // delegate to inner schema for typed validation
28
36
  if (is.defined(this.#inner))
29
37
  return this.#inner.parse(x, options);
30
- if (!is.json(x))
38
+ if (!json_with_undefined_object_values(x)) {
31
39
  throw E.invalid_type(x, "json", options);
40
+ }
32
41
  return JSON.parse(JSON.stringify(x));
33
42
  }
34
43
  toJSON() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pema",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Primate schema validation",
5
5
  "homepage": "https://primate.run/docs/validation",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",