@workflowai/schema
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -5,3 +5,3 @@ import { z } from './zod'; | ||
export type Definition = { | ||
jsonSchemaTitle: string; | ||
jsonSchemaDefinitionKey: string; | ||
zodSchema: { | ||
@@ -8,0 +8,0 @@ input: ZodExtensionName; |
@@ -6,3 +6,3 @@ "use strict"; | ||
{ | ||
jsonSchemaTitle: 'DatetimeLocal', | ||
jsonSchemaDefinitionKey: 'DatetimeLocal', | ||
zodSchema: { | ||
@@ -14,3 +14,3 @@ input: 'datetimeLocal', | ||
{ | ||
jsonSchemaTitle: 'Image', | ||
jsonSchemaDefinitionKey: 'Image', | ||
zodSchema: { | ||
@@ -17,0 +17,0 @@ input: 'imageInput', |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.outputSchemaToZod = exports.inputSchemaToZod = void 0; | ||
const json_refs_1 = require("json-refs"); | ||
const json_schema_to_zod_1 = require("json-schema-to-zod"); | ||
const definitions_1 = require("./definitions"); | ||
const json_schema_refs_1 = require("./json-schema-refs"); | ||
const makeParserOverride = (type) => (schema, _refs) => { | ||
if (schema.title) { | ||
const definition = definitions_1.definitions.find(({ jsonSchemaTitle }) => jsonSchemaTitle === schema.title); | ||
if (schema.$ref) { | ||
const definition = definitions_1.definitions.find(({ jsonSchemaDefinitionKey }) => jsonSchemaDefinitionKey === schema.$ref.split('/$defs/').pop()); | ||
if (definition) { | ||
@@ -19,3 +19,3 @@ return `z.${definition.zodSchema[type]}()`; | ||
const schemaToZod = async (jsonSchema, parserOverride) => { | ||
const { resolved: resolvedJsonSchema } = await (0, json_refs_1.resolveRefs)(jsonSchema); | ||
const resolvedJsonSchema = (0, json_schema_refs_1.hydrateRefs)(jsonSchema, { keepRefs: true }); | ||
return (0, json_schema_to_zod_1.jsonSchemaToZod)(resolvedJsonSchema, { parserOverride }); | ||
@@ -22,0 +22,0 @@ }; |
@@ -7,10 +7,10 @@ "use strict"; | ||
const zod_1 = require("./zod"); | ||
const { input: inputSchemaDefinitions, output: outputSchemaDefinitions } = definitions_1.definitions.reduce((result, { jsonSchemaTitle, zodSchema }) => ({ | ||
const { input: inputSchemaDefinitions, output: outputSchemaDefinitions } = definitions_1.definitions.reduce((result, { jsonSchemaDefinitionKey, zodSchema }) => ({ | ||
input: { | ||
...result.input, | ||
[jsonSchemaTitle]: zod_1.z[zodSchema.input](), | ||
[jsonSchemaDefinitionKey]: zod_1.z[zodSchema.input](), | ||
}, | ||
output: { | ||
...result.output, | ||
[jsonSchemaTitle]: zod_1.z[zodSchema.output](), | ||
[jsonSchemaDefinitionKey]: zod_1.z[zodSchema.output](), | ||
}, | ||
@@ -17,0 +17,0 @@ }), { input: {}, output: {} }); |
export const definitions = [ | ||
{ | ||
jsonSchemaTitle: 'DatetimeLocal', | ||
jsonSchemaDefinitionKey: 'DatetimeLocal', | ||
zodSchema: { | ||
@@ -10,3 +10,3 @@ input: 'datetimeLocal', | ||
{ | ||
jsonSchemaTitle: 'Image', | ||
jsonSchemaDefinitionKey: 'Image', | ||
zodSchema: { | ||
@@ -13,0 +13,0 @@ input: 'imageInput', |
@@ -1,7 +0,7 @@ | ||
import { resolveRefs } from 'json-refs'; | ||
import { jsonSchemaToZod, } from 'json-schema-to-zod'; | ||
import { definitions } from './definitions'; | ||
import { hydrateRefs } from './json-schema-refs'; | ||
const makeParserOverride = (type) => (schema, _refs) => { | ||
if (schema.title) { | ||
const definition = definitions.find(({ jsonSchemaTitle }) => jsonSchemaTitle === schema.title); | ||
if (schema.$ref) { | ||
const definition = definitions.find(({ jsonSchemaDefinitionKey }) => jsonSchemaDefinitionKey === schema.$ref.split('/$defs/').pop()); | ||
if (definition) { | ||
@@ -16,3 +16,3 @@ return `z.${definition.zodSchema[type]}()`; | ||
const schemaToZod = async (jsonSchema, parserOverride) => { | ||
const { resolved: resolvedJsonSchema } = await resolveRefs(jsonSchema); | ||
const resolvedJsonSchema = hydrateRefs(jsonSchema, { keepRefs: true }); | ||
return jsonSchemaToZod(resolvedJsonSchema, { parserOverride }); | ||
@@ -19,0 +19,0 @@ }; |
import { zodToJsonSchema } from 'zod-to-json-schema'; | ||
import { definitions } from './definitions'; | ||
import { z } from './zod'; | ||
const { input: inputSchemaDefinitions, output: outputSchemaDefinitions } = definitions.reduce((result, { jsonSchemaTitle, zodSchema }) => ({ | ||
const { input: inputSchemaDefinitions, output: outputSchemaDefinitions } = definitions.reduce((result, { jsonSchemaDefinitionKey, zodSchema }) => ({ | ||
input: { | ||
...result.input, | ||
[jsonSchemaTitle]: z[zodSchema.input](), | ||
[jsonSchemaDefinitionKey]: z[zodSchema.input](), | ||
}, | ||
output: { | ||
...result.output, | ||
[jsonSchemaTitle]: z[zodSchema.output](), | ||
[jsonSchemaDefinitionKey]: z[zodSchema.output](), | ||
}, | ||
@@ -13,0 +13,0 @@ }), { input: {}, output: {} }); |
@@ -5,3 +5,3 @@ import { z } from './zod'; | ||
export type Definition = { | ||
jsonSchemaTitle: string; | ||
jsonSchemaDefinitionKey: string; | ||
zodSchema: { | ||
@@ -8,0 +8,0 @@ input: ZodExtensionName; |
{ | ||
"name": "@workflowai/schema", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "workflowAI schema helpers", | ||
@@ -44,7 +44,5 @@ "author": "workflowAI", | ||
"dry": "npm run build && npm pub --dry-run", | ||
"prepublishOnly--DISABLED": "npm run test && npm run build", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"json-refs": "^3.0.15", | ||
"json-schema-to-zod": "^2.1.0", | ||
@@ -51,0 +49,0 @@ "zod": "^3.23.7", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57066
3
79
1291
- Removedjson-refs@^3.0.15
- Removedargparse@1.0.10(transitive)
- Removedasap@2.0.6(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcommander@4.1.1(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcookiejar@2.1.4(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddezalgo@1.0.4(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedesprima@4.0.1(transitive)
- Removedfast-safe-stringify@2.1.1(transitive)
- Removedform-data@4.0.1(transitive)
- Removedformidable@2.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.6(transitive)
- Removedgopd@1.2.0(transitive)
- Removedgraphlib@2.1.8(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhexoid@1.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedjson-refs@3.0.15(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@2.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.1.3(transitive)
- Removednative-promise-only@0.8.1(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-loader@1.0.12(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.13.1(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@7.6.3(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedslash@3.0.0(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedsuperagent@7.1.6(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwrappy@1.0.2(transitive)