adapt-authoring-jsonschema 1.1.0 → 1.1.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.
package/lib/JsonSchema.js CHANGED
@@ -202,11 +202,10 @@ class JsonSchema {
202
202
  */
203
203
  validate (dataToValidate, options) {
204
204
  const opts = _.defaults(options, { useDefaults: true, ignoreRequired: false })
205
- const data = _.defaultsDeep(_.cloneDeep(dataToValidate), opts.useDefaults ? this.getObjectDefaults() : {})
206
-
205
+ const data = _.defaults(_.cloneDeep(dataToValidate), opts.useDefaults ? this.getObjectDefaults() : {})
207
206
  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)
207
+ this.log('warn', 'NO_COMPILED_FUNC', this.name)
208
+ this.validator.compile(this.built)
210
209
  }
211
210
  this.compiled(data)
212
211
 
@@ -67,8 +67,11 @@ class JsonSchemaModule extends AbstractModule {
67
67
  this.getConfig('xssWhitelist'))
68
68
  })
69
69
  .then(() => this.addStringFormats(this.getConfig('formatOverrides')))
70
- .then(() => this.registerSchemas())
70
+ .then(() => this.registerSchemas({ quiet: true })) // note: supress logging here as other schemas will likely be added
71
71
  .catch(e => this.log('error', e))
72
+
73
+ this.app.onReady()
74
+ .then(() => this.logSchemas())
72
75
  }
73
76
 
74
77
  /**
@@ -108,7 +111,7 @@ class JsonSchemaModule extends AbstractModule {
108
111
  * Searches all Adapt dependencies for any local JSON schemas and registers them for use in the app. Schemas must be located in in a `/schema` folder, and be named appropriately: `*.schema.json`.
109
112
  * @return {Promise}
110
113
  */
111
- async registerSchemas () {
114
+ async registerSchemas ({ quiet }) {
112
115
  await this.resetSchemaRegistry()
113
116
  await Promise.all(Object.values(this.app.dependencies).map(async d => {
114
117
  if(d.name === this.name) return
@@ -117,7 +120,8 @@ class JsonSchemaModule extends AbstractModule {
117
120
  .filter(r => r.status === 'rejected')
118
121
  .forEach(r => this.log('warn', r.reason))
119
122
  }))
120
- this.registerSchemasHook.invoke();
123
+ await this.registerSchemasHook.invoke()
124
+ if(quiet !== true) this.logSchemas()
121
125
  }
122
126
 
123
127
  /**
@@ -140,7 +144,7 @@ class JsonSchemaModule extends AbstractModule {
140
144
  this.schemaExtensions?.[schema.name]?.forEach(s => schema.addExtension(s))
141
145
  if (schema.raw.$patch) this.extendSchema(schema.raw.$patch?.source?.$ref, schema.name)
142
146
 
143
- this.log('debug', 'REGISTER_SCHEMA', schema.name, filePath)
147
+ this.log('verbose', 'REGISTER_SCHEMA', schema.name, filePath)
144
148
  }
145
149
 
146
150
  /**
@@ -189,7 +193,7 @@ class JsonSchemaModule extends AbstractModule {
189
193
  if (!this.schemaExtensions[baseSchemaName]) this.schemaExtensions[baseSchemaName] = []
190
194
  this.schemaExtensions[baseSchemaName].push(extSchemaName)
191
195
  }
192
- this.log('debug', 'EXTEND_SCHEMA', baseSchemaName, extSchemaName)
196
+ this.log('verbose', 'EXTEND_SCHEMA', baseSchemaName, extSchemaName)
193
197
  }
194
198
 
195
199
  /**
@@ -204,6 +208,17 @@ class JsonSchemaModule extends AbstractModule {
204
208
  if (!schema) throw this.app.errors.MISSING_SCHEMA.setData({ schemaName })
205
209
  return schema.build(options)
206
210
  }
211
+
212
+ /**
213
+ * Logs all registered schemas & schema extensions
214
+ */
215
+ logSchemas () {
216
+ this.log('debug', 'SCHEMAS', Object.keys(this.schemas))
217
+ this.log('debug', 'SCHEMA_EXTENSIONS', Object.entries(this.schemas).reduce((m, [k, v]) => {
218
+ if(v.extensions.length) m[k] = v.extensions
219
+ return m
220
+ }, {}))
221
+ }
207
222
  }
208
223
 
209
224
  export default JsonSchemaModule
@@ -1,5 +1,5 @@
1
1
  export default {
2
- a: ['class', 'href', 'target', 'title'],
2
+ a: ['class', 'href', 'rel', 'target', 'title'],
3
3
  abbr: ['title'],
4
4
  address: [],
5
5
  area: ['alt', 'coords', 'href', 'shape'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-jsonschema",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
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",