adapt-authoring-jsonschema 1.0.0 → 1.1.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/lib/JsonSchema.js CHANGED
@@ -135,7 +135,7 @@ class JsonSchema {
135
135
  let parent = await this.getParent()
136
136
 
137
137
  while (parent) {
138
- const parentBuilt = _.cloneDeep((await parent.build(options)).built)
138
+ const parentBuilt = _.cloneDeep((await parent.build({ ...options, compile: false })).built)
139
139
  built = await this.patch(parentBuilt, built, { strict: !parent.name === BASE_SCHEMA_NAME })
140
140
  parent = await parent.getParent()
141
141
  }
@@ -149,7 +149,9 @@ class JsonSchema {
149
149
  }))
150
150
  }
151
151
  this.built = built
152
- this.compiled = await this.validator.compileAsync(built)
152
+ if(options.compile !== false) { // don't compile when option present (e.g. when running build recursively)
153
+ this.compiled = await this.validator.compileAsync(built)
154
+ }
153
155
  this.isBuilding = false
154
156
  this.lastBuildTime = Date.now()
155
157
 
@@ -202,6 +204,10 @@ class JsonSchema {
202
204
  const opts = _.defaults(options, { useDefaults: true, ignoreRequired: false })
203
205
  const data = _.defaultsDeep(_.cloneDeep(dataToValidate), opts.useDefaults ? this.getObjectDefaults() : {})
204
206
 
207
+ if(!this.compiled) { // fallback in the case that the compiled function is missing
208
+ await this.log('warn', 'NO_COMPILED_FUNC', this.name)
209
+ await this.validator.compileAsync(this.built)
210
+ }
205
211
  this.compiled(data)
206
212
 
207
213
  const errors = this.compiled.errors && this.compiled.errors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-jsonschema",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Module to add support for the JSON schema specification",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-jsonschema",
6
6
  "license": "GPL-3.0",