@lucania/schema 1.0.2 → 1.0.4

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 (2) hide show
  1. package/build/index.js +5 -5
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -157,6 +157,9 @@
157
157
  }
158
158
  const result = _validate(schema.type, source, path, originalSchema, originalSource);
159
159
  if (result instanceof ValidationError && result.type === "missing") {
160
+ if (!schema.required && source === undefined) {
161
+ return undefined;
162
+ }
160
163
  if ("default" in schema) {
161
164
  if (typeof schema.default === "function") {
162
165
  return _validate(schema.type, schema.default(), path, originalSchema, originalSource);
@@ -165,10 +168,7 @@
165
168
  return _validate(schema.type, schema.default, path, originalSchema, originalSource);
166
169
  }
167
170
  }
168
- else if (schema.required) {
169
- return result;
170
- }
171
- return undefined;
171
+ return result;
172
172
  }
173
173
  return result;
174
174
  }
@@ -247,7 +247,7 @@
247
247
  return { $: clone(schema.$) };
248
248
  }
249
249
  else if (isSchemaArray(schema)) {
250
- return [schema.map(clone)];
250
+ return schema.map(clone);
251
251
  }
252
252
  else if (isSchemaHierarchy(schema)) {
253
253
  const hierarchy = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucania/schema",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A schema module for compile-time and runtime type checking.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",