Skip to content

Commit

Permalink
fix: clean up passing in options
Browse files Browse the repository at this point in the history
  • Loading branch information
willfarrell committed Aug 28, 2022
1 parent 9fac423 commit 2aa29ca
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 260 deletions.
26 changes: 9 additions & 17 deletions packages/validate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,31 @@ import { createTransformStream } from '@datastream/core'
import _ajv from 'ajv/dist/2020.js'
import formats from 'ajv-formats'
import formatsDraft2019 from 'ajv-formats-draft2019'
// import ajvErrors from 'ajv-errors'
import uriResolver from 'fast-uri'

const Ajv = _ajv.default // esm workaround for linting

const ajvDefaults = {
strict: true,
coerceTypes: 'array',
coerceTypes: true,
allErrors: true,
useDefaults: 'empty',
uriResolver
}

const jsonSchemaValidateDefaults = {
idxStart: 0,
key: 'ajvErrors',
language: 'en',
availableLanguages: undefined
}
export const validateStream = (
{ schema, idxStart, resultKey, ...ajvOptions },
streamOptions
) => {
idxStart ??= 0
// language ??= 'en'

export const validateStream = (validateOptions, streamOptions) => {
let {
schema,
idxStart,
resultKey /* language, availableLanguages */,
...ajvOptions
} = {
...jsonSchemaValidateDefaults,
...validateOptions
}
if (typeof schema !== 'function') {
const ajv = new Ajv({ ...ajvDefaults, ...ajvOptions })
formats(ajv)
formatsDraft2019(ajv)
// ajvErrors(ajv)
schema = ajv.compile(schema)
}

Expand Down
Loading

0 comments on commit 2aa29ca

Please sign in to comment.