Last active
January 2, 2019 19:57
-
-
Save ottomata/5f2aaf01a7a8a52a77f5828b18f0e4b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const bunyan = require('bunyan'); | |
const _ = require('lodash'); | |
const { | |
resolveUri | |
} = require('./lib/event-util'); | |
const EventValidator = require('./lib/EventValidator'); | |
const logger = bunyan.createLogger( | |
{ name: 'EventValidatorScratch', src: true, level: 'debug' } | |
); | |
const l = console.log; | |
const testEvent_draft4 = { | |
'$schema': '/test_draft4/0.0.1', | |
meta: { | |
stream: 'test_draft4.event', | |
id: '5e1dd101-641c-11e8-ab6c-b083fecf1287', | |
}, | |
test: 'test_value_0' | |
}; | |
function resolveSchemaUri(uri) { | |
return resolveUri(uri, './test/schemas/'); | |
} | |
const ev1 = new EventValidator({ | |
resolveSchemaUri, | |
}); | |
const ev2 = new EventValidator({ | |
resolveSchemaUri, | |
}); | |
async function compileSchema(ev, uri) { | |
l('getting', uri); | |
const validator = ev.ajv.getSchema(uri); | |
if (validator) { | |
return validator.schema; | |
} | |
const schema = await ev.loadSchema(uri, ev); | |
return await ev.ajv.compileAsync(schema); | |
} | |
async function main() { | |
await compileSchema(ev1, '/test_draft4/0.0.1'); | |
await compileSchema(ev1, '/test_draft4/0.0.1'); | |
console.log('===?', ev1.ajv._schemas === ev2.ajv._schemas); | |
l('ev1', _.keys(ev1.ajv._schemas)); | |
l('ev2', _.keys(ev2.ajv._schemas)); | |
await compileSchema(ev2, '/test_draft4/0.0.1'); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment