Skip to content

Commit

Permalink
chore: update exports and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sagold committed Apr 13, 2024
1 parent 1e36606 commit 89b1e4d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 223 deletions.
18 changes: 11 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import { Draft06, draft06Config } from "./lib/draft06";
import { Draft07, draft07Config } from "./lib/draft07";
import { Draft2019, draft2019Config } from "./lib/draft2019";
import { JsonEditor, draftJsonEditorConfig } from "./lib/jsoneditor";
import { isJsonError } from "./lib/types";
import { createNode, isJsonError, isSchemaNode } from "./lib/types";

const config = { strings };

export {
config,
createCustomError,
createError,
createNode, // v10
Draft,
Draft04, // core implementing draft04 specs
draft04Config, // config implementing draft04 specs
Expand All @@ -36,14 +37,15 @@ export {
draft2019Config, // config implementing draft2019-09 specs
draftJsonEditorConfig, // adjusted config of draft04 to better support the json-editor
getTypeOf, // returns the javascript datatype
isDynamicSchema, // NEW
isDynamicSchema, // v8
isJsonError,
isSchemaNode, // v10
JsonEditor, // adjusted core of draft07 to better support the json-editor
mergeSchema, // NEW
reduceSchema, // NEW
mergeSchema, // v8
reduceSchema, // v8
render,
resolveAllOf,
resolveDynamicSchema, // NEW
resolveDynamicSchema, // v8
resolveOneOf,
resolveOneOfFuzzy,
resolveRef,
Expand All @@ -63,7 +65,8 @@ import {
JsonError,
JsonValidator,
JsonTypeValidator,
ErrorData
ErrorData,
SchemaNode
} from "./lib/types";
import { JSType } from "./lib/getTypeOf";

Expand All @@ -79,5 +82,6 @@ export type {
JsonSchema,
JsonTypeValidator,
JsonValidator,
JSType
JSType,
SchemaNode
};
2 changes: 1 addition & 1 deletion lib/draft2019/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { resolveAnyOf } from "../features/anyOf";
import { resolveOneOf } from "../features/oneOf";
import createSchemaOf from "../createSchemaOf";
import getChildSchemaSelection from "../getChildSchemaSelection";
import step from "./step";
import step from "../step";
import TYPES from "../draft06/validation/type";
import validate from "../validate";
import { DraftConfig, Draft } from "../draft";
Expand Down
196 changes: 0 additions & 196 deletions lib/draft2019/step.ts

This file was deleted.

25 changes: 6 additions & 19 deletions lib/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import createSchemaOf from "./createSchemaOf";
import { JsonSchema, JsonError, isJsonError, SchemaNode } from "./types";
import { reduceSchema } from "./reduceSchema";

type StepFunction = (
node: SchemaNode,
key: string,
data: any
) => SchemaNode | JsonError | undefined;
type StepFunction = (node: SchemaNode, key: string, data: any) => SchemaNode | JsonError | undefined;

const stepType: Record<string, StepFunction> = {
array: (node, key, data) => {
Expand Down Expand Up @@ -158,11 +154,7 @@ const stepType: Record<string, StepFunction> = {
* @param [pointer] - pointer to schema and data (parent of key)
* @return Schema or Error if failed resolving key
*/
export default function step(
node: SchemaNode,
key: string | number,
data?: any
): SchemaNode | JsonError {
export default function step(node: SchemaNode, key: string | number, data?: any): SchemaNode | JsonError {
const { draft, schema, pointer } = node;
const typeOfData = getTypeOf(data);
let schemaType = schema.type ?? typeOfData;
Expand All @@ -183,16 +175,11 @@ export default function step(

const stepFunction = stepType[schemaType];
if (stepFunction) {
const schemaResult = stepFunction(node, `${key}`, data);
if (schemaResult === undefined) {
return draft.errors.schemaWarning({
pointer,
value: data,
schema,
key
});
const childNode = stepFunction(node, `${key}`, data);
if (childNode === undefined) {
return draft.errors.schemaWarning({ pointer, value: data, schema, key });
}
return schemaResult;
return childNode;
}

return new Error(`Unsupported schema type ${schema.type} for key ${key}`) as JsonError;
Expand Down

0 comments on commit 89b1e4d

Please sign in to comment.