Skip to content

Commit

Permalink
feat: add .toMeta() method on schemas during build
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Mar 29, 2024
1 parent 4adf1ed commit 9a36b18
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const genfun = require('./generate-function')
const { buildSchemas } = require('./pointer')
const { compile } = require('./compile')
const { deepEqual } = require('./scope-functions')
const { name, version } = require('../package.json')

const jsonCheckWithErrors = (validate) =>
function validateIsJSON(data) {
Expand Down Expand Up @@ -33,6 +34,7 @@ const validator = (
const { scope, refs } = compile(arg, options) // only a single ref
if (opts.dryRun) return
if (opts.lint) return scope.lintErrors
const meta = { builder: { name, version }, variant: parse ? 'parser' : 'validator', mode }
const fun = genfun()
if (parse) {
scope.parseWrap = opts.includeErrors ? parseWithErrors : parseWithoutErrors
Expand All @@ -55,6 +57,7 @@ const validator = (
const validate = fun.makeFunction(scope)
validate.toModule = ({ semi = true } = {}) => fun.makeModule(scope) + (semi ? ';' : '')
validate.toJSON = () => schema
validate.toMeta = () => meta
return validate
}

Expand Down

0 comments on commit 9a36b18

Please sign in to comment.