@power-plant/schema 0.0.12 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,7 +33,7 @@ The Power Plant monorepo is a collection of packages that are designed to work t
33
33
 
34
34
  <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
35
35
 
36
- [![Version](https://img.shields.io/badge/version-0.0.11-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://docs.stormsoftware.com/projects/power-plant)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/power-plant/release.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
36
+ [![Version](https://img.shields.io/badge/version-0.0.14-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://docs.stormsoftware.com/projects/power-plant)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/power-plant/release.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
37
37
 
38
38
  <!-- prettier-ignore-start -->
39
39
  <!-- markdownlint-disable -->
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./constants-CjTQhR-l.cjs"),t=require("./storage-CgfRQlqS.cjs"),n=require("./helpers-CrePPGkD.cjs");let r=require("@stryke/convert/extract-file-reference"),i=require("@stryke/hash"),a=require("@stryke/helpers/deep-clone"),o=require("@stryke/json"),s=require("@stryke/path/find"),c=require("@stryke/resolve/constants"),l=require("@stryke/resolve/load"),u=require("@stryke/string-format/list"),d=require("@stryke/type-checks"),f=require("@stryke/type-checks/is-set-object"),p=require("@stryke/zod"),m=require("@valibot/to-json-schema"),h=require("ts-json-schema-generator/dist/factory/generator.js");const g=`https://power-plant.invalid/`;function _(e){return!(!(0,f.isSetObject)(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e)}function v(e){return _(e)?e.schema:e}function y(e){return e.endsWith(`#`)?e.slice(0,-1):e}function b(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function x(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function S(e){return e.length===0?``:`/${e.map(e=>x(e)).join(`/`)}`}function C(e,t){try{return y(new URL(e,t).toString())}catch{return y(e)}}function w(e,t,n,r,i){if(!(0,f.isSetObject)(e))return;let a=e,o=S(t),s=(0,d.isSetString)(a.$id)?C(a.$id,n):n,c=b(s);if(r.set(s,o),r.set(c,o),(0,d.isSetString)(a.$anchor)&&r.set(`${c}#${a.$anchor}`,o),(0,d.isSetString)(a.$dynamicAnchor)){let e=`${c}#${a.$dynamicAnchor}`;r.set(e,o),i.set(e,`#${a.$dynamicAnchor}`)}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{w(n,[...t,e,String(a)],s,r,i)});continue}w(n,[...t,e],s,r,i)}}function T(e,t,n,r,i){if(!(0,f.isSetObject)(e))return;let a=e,o=(0,d.isSetString)(a.$id)?C(a.$id,n):n;if((0,d.isSetString)(a.$ref)){let e=C(a.$ref,o),t=r.get(e)??r.get(b(e));t!==void 0&&(a.$ref=t.length>0?`#${t}`:`#`)}if((0,d.isSetString)(a.$dynamicRef)){let e=C(a.$dynamicRef,o),t=i.get(e);if(t)a.$dynamicRef=t;else{let t=r.get(e)??r.get(b(e));t!==void 0&&(a.$dynamicRef=t.length>0?`#${t}`:`#`)}}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{T(n,[...t,e,String(a)],o,r,i)});continue}T(n,[...t,e],o,r,i)}}function E(e){if(!(0,f.isSetObject)(e))return e;let t=(0,a.deepClone)(e),n=(0,d.isSetString)(t.$id)?C(t.$id,g):g,r=new Map,i=new Map;return w(t,[],n,r,i),T(t,[],n,r,i),t}function D(e){if(n.nt(e))return A(e);if((0,f.isSetObject)(e)){if(n.et(e))return j(e);let t=e;if(`$schema`in t&&n.nt(t.$schema))return A(t.$schema)}return e}function O(e){return Array.isArray(e)?e.map(e=>D(e)):e}function k(e){return(0,m.toJsonSchema)(e,{target:`draft-2020-12`})}function A(e){let t=e,n={};for(let[e,r]of Object.entries(t))if(!(e===`tsType`||e===`markdownType`||e===`tags`||e===`args`||e===`resolve`)){if(e===`id`&&(0,d.isSetString)(r)){n.$id=r;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!(0,f.isSetObject)(r)){n[e]=r;continue}n[e]=Object.fromEntries(Object.entries(r).map(([e,t])=>[e,D(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=D(r);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=O(r);continue}n[e]=r}return n}function j(e){let t=e,r=n.nt(t.$schema)?A(t.$schema):{},i={};for(let[e,r]of Object.entries(t)){if(e.startsWith(`$`)||!(0,f.isSetObject)(r))continue;if(n.et(r)){i[e]=j(r);continue}let t=r;if(`$schema`in t&&n.nt(t.$schema)){i[e]=A(t.$schema);continue}n.nt(r)&&(i[e]=A(r))}if(!n.I(r))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let a={...(0,f.isSetObject)(r.properties)?r.properties:{},...i};return{...r,type:r.type??`object`,...Object.keys(a).length>0?{properties:a}:{}}}function M(e,t){let r=v(t);if(n.Q(r)||n.Y(r))return(0,i.murmurhash)({variant:e,input:r.schema});if((0,d.isSetString)(r)||typeof r==`boolean`)return(0,i.murmurhash)({variant:e,input:r});if((0,f.isSetObject)(r)){if((0,p.isZod3Type)(r))return(0,i.murmurhash)({variant:e,input:r._def});if((0,o.isStandardJsonSchema)(r))return(0,i.murmurhash)({variant:e,input:r[`~standard`]});if(n._(r))return(0,i.murmurhash)({variant:e,input:r});if(n.it(r))return(0,i.murmurhash)({variant:e,input:k(r)});if(n.et(r))return(0,i.murmurhash)({variant:e,input:j(r)});if(n.nt(r))return(0,i.murmurhash)({variant:e,input:A(r)})}throw Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`)}function N(e){if((0,f.isSetObject)(e)){if((0,p.isZod3Type)(e))return(0,p.extractJsonSchema)(e,{target:`draft-2020-12`});if(n.tt(e))return j(e);if(n.rt(e))return A(e);if((0,o.isStandardJsonSchema)(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(n.it(e))return k(e);if(n._(e))return e}}function P(e){if((0,f.isSetObject)(e)){if((0,p.isZod3Type)(e))return`zod3`;if(n.tt(e)||n.rt(e))return`untyped`;if((0,o.isStandardJsonSchema)(e))return`standard-schema`;if(n._(e))return`json-schema`;if(n.it(e))return`valibot`}throw Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`)}function F(e){let t=v(e);return n.Q(t)||n.Y(t)?t.variant:(0,d.isSetString)(t)||n.g(t)?`file-reference`:P(t)}async function I(e,t){if(n.Q(e))return e.schema;let r=t??P(e),i;if((r===`zod3`||r===`json-schema`||r===`standard-schema`||r===`untyped`||r===`valibot`)&&(i=N(e)),i)return E(i);throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`)}function L(e,t){if(e===`zod3`)return{hash:M(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:M(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:M(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:M(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:M(e,t),variant:`valibot`,schema:t};throw Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`)}async function R(e,t={}){let n=(0,r.extractFileReference)(e);if(!n)throw Error(`Failed to extract a file reference from the provided input. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);let i=n.export??`*`;try{return(0,h.createGenerator)({path:n.file,type:i,expose:`export`,jsDoc:`extended`,...t}).createSchema(i)}catch(e){throw Error(`Failed to generate a JSON schema for "${n.file}" using the type "${i}". Error: ${e.message}`)}}async function z(e,i={}){let a=v(e);if(n.Q(a))return a;if(n.Y(a))return{...a,source:{hash:M(`json-schema`,a.schema),variant:`json-schema`,schema:a.schema}};let o,d=F(a),f=M(d,a);if(d===`file-reference`){let e=(0,r.extractFileReference)(a);if(!e)throw Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(a)}". Please ensure that the input is correctly formatted as a file reference (e.g. "./schema.ts#MySchema") and that the file exists at the specified path.`);let d=(0,s.findFileExtensionSafe)(e.file);if(d&&!c.VALID_OBJECT_SOURCE_EXTENSIONS.includes(d))throw Error(`The provided schema file input "${e.file}" has an invalid file extension (.${d}). Please ensure that the file has one of the following extensions: ${(0,u.list)(c.VALID_OBJECT_SOURCE_EXTENSIONS,{conjunction:`or`})}.`);let f;i.storage&&(f=t.t(i.storage));let p=await(0,l.loadSafe)(a,{...i,fs:f});p??=await R(a,{...i,fs:f});let m=v(p);o=n.Q(m)?m.source:n.Y(m)?{hash:M(`json-schema`,m.schema),variant:`json-schema`,schema:m.schema}:L(P(m),m)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(d))o=L(d,a);else throw Error(`Invalid schema definition input "${d}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);return{variant:d,source:o,schema:await I(o.schema,o.variant),hash:f}}async function B(e,t={}){let r=v(e);if(n.Q(r)||n.Z(r))return r;let i=await z(e,t);if(!i?.schema)throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);return i}exports.JSON_SCHEMA_METADATA_KEYS=e.t,exports.JSON_SCHEMA_PRIMITIVE_TYPES=e.n,exports.JSON_SCHEMA_TYPES=e.r,exports.JsonSchemaTypeNames=e.i,exports.SCHEMA_ARRAY_CONCAT_KEYWORDS=e.a,exports.SCHEMA_RECORD_KEYWORDS=e.o,exports.SCHEMA_SINGLE_KEYWORDS=e.s,exports.addProperty=n.t,exports.applyJsonSchemaMetadata=n.p,exports.bundleReferences=E,exports.createStoragePromises=t.n,exports.extract=B,exports.extractHash=M,exports.extractJsonSchema=N,exports.extractResolvedVariant=P,exports.extractSchema=I,exports.extractSchemaWithSource=z,exports.extractSource=L,exports.extractTSType=R,exports.extractVariant=F,exports.getJsonSchema=n.n,exports.getJsonSchemaObject=n.r,exports.getPrimarySchemaType=n.m,exports.getProperties=n.i,exports.getPropertiesList=n.a,exports.getProperty=n.o,exports.isFileReference=n.g,exports.isJsonSchema=n._,exports.isJsonSchemaAllOf=n.v,exports.isJsonSchemaAny=n.y,exports.isJsonSchemaAnyOf=n.b,exports.isJsonSchemaArray=n.x,exports.isJsonSchemaBigint=n.S,exports.isJsonSchemaBoolean=n.C,exports.isJsonSchemaDate=n.w,exports.isJsonSchemaDecimal=n.T,exports.isJsonSchemaEnum=n.E,exports.isJsonSchemaInteger=n.D,exports.isJsonSchemaKeywords=n.O,exports.isJsonSchemaLiteral=n.k,exports.isJsonSchemaMap=n.A,exports.isJsonSchemaNativeEnum=n.j,exports.isJsonSchemaNever=n.M,exports.isJsonSchemaNull=n.N,exports.isJsonSchemaNullable=n.P,exports.isJsonSchemaNumber=n.F,exports.isJsonSchemaObject=n.I,exports.isJsonSchemaPrimitiveType=n.L,exports.isJsonSchemaPrimitiveUnion=n.R,exports.isJsonSchemaRecord=n.z,exports.isJsonSchemaRef=n.B,exports.isJsonSchemaSet=n.V,exports.isJsonSchemaString=n.H,exports.isJsonSchemaTuple=n.U,exports.isJsonSchemaType=n.W,exports.isJsonSchemaUndefined=n.G,exports.isJsonSchemaUnion=n.K,exports.isJsonSchemaUnknown=n.q,exports.isNullOnlyJsonSchema=n.J,exports.isPropertyOptional=n.s,exports.isSchema=n.Y,exports.isSchemaNullable=n.c,exports.isSchemaObject=n.X,exports.isSchemaOf=n.Z,exports.isSchemaWithSource=n.Q,exports.isStandardSchema=n.$,exports.isUntypedConfig=n.et,exports.isUntypedConfigStrict=n.tt,exports.isUntypedSchema=n.nt,exports.isUntypedSchemaStrict=n.rt,exports.isValibotSchema=n.it,exports.isValidSchemaConfigFile=n.l,exports.mapStorageToFileSystem=t.t,exports.merge=n.u,exports.mergeMetadata=n.d,exports.normalizeKey=t.r,exports.readSchemaTypes=n.h,exports.traverseSchema=n.f;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./constants-CjTQhR-l.cjs"),t=require("./storage-CgfRQlqS.cjs"),n=require("./helpers-CrePPGkD.cjs");let r=require("@stryke/convert/extract-file-reference"),i=require("@stryke/hash"),a=require("@stryke/helpers/deep-clone"),o=require("@stryke/json"),s=require("@stryke/path/find"),c=require("@stryke/resolve/constants"),l=require("@stryke/resolve/load"),u=require("@stryke/string-format/list"),d=require("@stryke/type-checks"),f=require("@stryke/type-checks/is-set-object"),p=require("@stryke/zod"),m=require("@valibot/to-json-schema"),h=require("ts-json-schema-generator/dist/factory/generator.js");const g=`https://power-plant.invalid/`;function _(e){return!(!(0,f.isSetObject)(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e)}function v(e){return _(e)?e.schema:e}function y(e){return e.endsWith(`#`)?e.slice(0,-1):e}function b(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function x(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function S(e){return e.length===0?``:`/${e.map(e=>x(e)).join(`/`)}`}function C(e,t){try{return y(new URL(e,t).toString())}catch{return y(e)}}function w(e,t,n,r,i){if(!(0,f.isSetObject)(e))return;let a=e,o=S(t),s=(0,d.isSetString)(a.$id)?C(a.$id,n):n,c=b(s);if(r.set(s,o),r.set(c,o),(0,d.isSetString)(a.$anchor)&&r.set(`${c}#${a.$anchor}`,o),(0,d.isSetString)(a.$dynamicAnchor)){let e=`${c}#${a.$dynamicAnchor}`;r.set(e,o),i.set(e,`#${a.$dynamicAnchor}`)}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{w(n,[...t,e,String(a)],s,r,i)});continue}w(n,[...t,e],s,r,i)}}function T(e,t,n,r,i){if(!(0,f.isSetObject)(e))return;let a=e,o=(0,d.isSetString)(a.$id)?C(a.$id,n):n;if((0,d.isSetString)(a.$ref)){let e=C(a.$ref,o),t=r.get(e)??r.get(b(e));t!==void 0&&(a.$ref=t.length>0?`#${t}`:`#`)}if((0,d.isSetString)(a.$dynamicRef)){let e=C(a.$dynamicRef,o),t=i.get(e);if(t)a.$dynamicRef=t;else{let t=r.get(e)??r.get(b(e));t!==void 0&&(a.$dynamicRef=t.length>0?`#${t}`:`#`)}}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{T(n,[...t,e,String(a)],o,r,i)});continue}T(n,[...t,e],o,r,i)}}function E(e){if(!(0,f.isSetObject)(e))return e;let t=(0,a.deepClone)(e),n=(0,d.isSetString)(t.$id)?C(t.$id,g):g,r=new Map,i=new Map;return w(t,[],n,r,i),T(t,[],n,r,i),t}function D(e){if(n.nt(e))return A(e);if((0,f.isSetObject)(e)){if(n.et(e))return j(e);let t=e;if(`$schema`in t&&n.nt(t.$schema))return A(t.$schema)}return e}function O(e){return Array.isArray(e)?e.map(e=>D(e)):e}function k(e){return(0,m.toJsonSchema)(e,{target:`draft-2020-12`})}function A(e){let t=e,n={};for(let[e,r]of Object.entries(t))if(e!==`tsType`&&e!==`markdownType`&&e!==`tags`&&e!==`args`&&e!==`resolve`){if(e===`id`&&(0,d.isSetString)(r)){n.$id=r;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!(0,f.isSetObject)(r)){n[e]=r;continue}n[e]=Object.fromEntries(Object.entries(r).map(([e,t])=>[e,D(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=D(r);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=O(r);continue}n[e]=r}return n}function j(e){let t=e,r=n.nt(t.$schema)?A(t.$schema):{},i={};for(let[e,r]of Object.entries(t)){if(e.startsWith(`$`)||!(0,f.isSetObject)(r))continue;if(n.et(r)){i[e]=j(r);continue}let t=r;if(`$schema`in t&&n.nt(t.$schema)){i[e]=A(t.$schema);continue}n.nt(r)&&(i[e]=A(r))}if(!n.I(r))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let a={...(0,f.isSetObject)(r.properties)?r.properties:{},...i};return{...r,type:r.type??`object`,...Object.keys(a).length>0?{properties:a}:{}}}function M(e,t){let r=v(t);if(n.Q(r)||n.Y(r))return(0,i.murmurhash)({variant:e,input:r.schema});if((0,d.isSetString)(r)||typeof r==`boolean`)return(0,i.murmurhash)({variant:e,input:r});if((0,f.isSetObject)(r)){if((0,p.isZod3Type)(r))return(0,i.murmurhash)({variant:e,input:r._def});if((0,o.isStandardJsonSchema)(r))return(0,i.murmurhash)({variant:e,input:r[`~standard`]});if(n._(r))return(0,i.murmurhash)({variant:e,input:r});if(n.it(r))return(0,i.murmurhash)({variant:e,input:k(r)});if(n.et(r))return(0,i.murmurhash)({variant:e,input:j(r)});if(n.nt(r))return(0,i.murmurhash)({variant:e,input:A(r)})}throw Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`)}function N(e){if((0,f.isSetObject)(e)){if((0,p.isZod3Type)(e))return(0,p.extractJsonSchema)(e,{target:`draft-2020-12`});if(n.tt(e))return j(e);if(n.rt(e))return A(e);if((0,o.isStandardJsonSchema)(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(n.it(e))return k(e);if(n._(e))return e}}function P(e){if((0,f.isSetObject)(e)){if((0,p.isZod3Type)(e))return`zod3`;if(n.tt(e)||n.rt(e))return`untyped`;if((0,o.isStandardJsonSchema)(e))return`standard-schema`;if(n._(e))return`json-schema`;if(n.it(e))return`valibot`}throw Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`)}function F(e){let t=v(e);return n.Q(t)||n.Y(t)?t.variant:(0,d.isSetString)(t)||n.g(t)?`file-reference`:P(t)}async function I(e,t){if(n.Q(e))return e.schema;let r=t??P(e),i;if((r===`zod3`||r===`json-schema`||r===`standard-schema`||r===`untyped`||r===`valibot`)&&(i=N(e)),i)return E(i);throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`)}function L(e,t){if(e===`zod3`)return{hash:M(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:M(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:M(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:M(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:M(e,t),variant:`valibot`,schema:t};throw Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`)}async function R(e,t={}){let n=(0,r.extractFileReference)(e);if(!n)throw Error(`Failed to extract a file reference from the provided input. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);let i=n.export??`*`;try{return(0,h.createGenerator)({path:n.file,type:i,expose:`export`,jsDoc:`extended`,...t}).createSchema(i)}catch(e){throw Error(`Failed to generate a JSON schema for "${n.file}" using the type "${i}". Error: ${e.message}`)}}async function z(e,i={}){let a=v(e);if(n.Q(a))return a;if(n.Y(a))return{...a,source:{hash:M(`json-schema`,a.schema),variant:`json-schema`,schema:a.schema}};let o,d=F(a),f=M(d,a);if(d===`file-reference`){let e=(0,r.extractFileReference)(a);if(!e)throw Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(a)}". Please ensure that the input is correctly formatted as a file reference (e.g. "./schema.ts#MySchema") and that the file exists at the specified path.`);let d=(0,s.findFileExtensionSafe)(e.file);if(d&&!c.VALID_OBJECT_SOURCE_EXTENSIONS.includes(d))throw Error(`The provided schema file input "${e.file}" has an invalid file extension (.${d}). Please ensure that the file has one of the following extensions: ${(0,u.list)(c.VALID_OBJECT_SOURCE_EXTENSIONS,{conjunction:`or`})}.`);let f;i.storage&&(f=t.t(i.storage));let p=await(0,l.loadSafe)(a,{...i,fs:f});p??=await R(a,{...i,fs:f});let m=v(p);o=n.Q(m)?m.source:n.Y(m)?{hash:M(`json-schema`,m.schema),variant:`json-schema`,schema:m.schema}:L(P(m),m)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(d))o=L(d,a);else throw Error(`Invalid schema definition input "${d}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);return{variant:d,source:o,schema:await I(o.schema,o.variant),hash:f}}async function B(e,t={}){let r=v(e);if(n.Q(r)||n.Z(r))return r;let i=await z(e,t);if(!i?.schema)throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);return i}exports.JSON_SCHEMA_METADATA_KEYS=e.t,exports.JSON_SCHEMA_PRIMITIVE_TYPES=e.n,exports.JSON_SCHEMA_TYPES=e.r,exports.JsonSchemaTypeNames=e.i,exports.SCHEMA_ARRAY_CONCAT_KEYWORDS=e.a,exports.SCHEMA_RECORD_KEYWORDS=e.o,exports.SCHEMA_SINGLE_KEYWORDS=e.s,exports.addProperty=n.t,exports.applyJsonSchemaMetadata=n.p,exports.bundleReferences=E,exports.createStoragePromises=t.n,exports.extract=B,exports.extractHash=M,exports.extractJsonSchema=N,exports.extractResolvedVariant=P,exports.extractSchema=I,exports.extractSchemaWithSource=z,exports.extractSource=L,exports.extractTSType=R,exports.extractVariant=F,exports.getJsonSchema=n.n,exports.getJsonSchemaObject=n.r,exports.getPrimarySchemaType=n.m,exports.getProperties=n.i,exports.getPropertiesList=n.a,exports.getProperty=n.o,exports.isFileReference=n.g,exports.isJsonSchema=n._,exports.isJsonSchemaAllOf=n.v,exports.isJsonSchemaAny=n.y,exports.isJsonSchemaAnyOf=n.b,exports.isJsonSchemaArray=n.x,exports.isJsonSchemaBigint=n.S,exports.isJsonSchemaBoolean=n.C,exports.isJsonSchemaDate=n.w,exports.isJsonSchemaDecimal=n.T,exports.isJsonSchemaEnum=n.E,exports.isJsonSchemaInteger=n.D,exports.isJsonSchemaKeywords=n.O,exports.isJsonSchemaLiteral=n.k,exports.isJsonSchemaMap=n.A,exports.isJsonSchemaNativeEnum=n.j,exports.isJsonSchemaNever=n.M,exports.isJsonSchemaNull=n.N,exports.isJsonSchemaNullable=n.P,exports.isJsonSchemaNumber=n.F,exports.isJsonSchemaObject=n.I,exports.isJsonSchemaPrimitiveType=n.L,exports.isJsonSchemaPrimitiveUnion=n.R,exports.isJsonSchemaRecord=n.z,exports.isJsonSchemaRef=n.B,exports.isJsonSchemaSet=n.V,exports.isJsonSchemaString=n.H,exports.isJsonSchemaTuple=n.U,exports.isJsonSchemaType=n.W,exports.isJsonSchemaUndefined=n.G,exports.isJsonSchemaUnion=n.K,exports.isJsonSchemaUnknown=n.q,exports.isNullOnlyJsonSchema=n.J,exports.isPropertyOptional=n.s,exports.isSchema=n.Y,exports.isSchemaNullable=n.c,exports.isSchemaObject=n.X,exports.isSchemaOf=n.Z,exports.isSchemaWithSource=n.Q,exports.isStandardSchema=n.$,exports.isUntypedConfig=n.et,exports.isUntypedConfigStrict=n.tt,exports.isUntypedSchema=n.nt,exports.isUntypedSchemaStrict=n.rt,exports.isValibotSchema=n.it,exports.isValidSchemaConfigFile=n.l,exports.mapStorageToFileSystem=t.t,exports.merge=n.u,exports.mergeMetadata=n.d,exports.normalizeKey=t.r,exports.readSchemaTypes=n.h,exports.traverseSchema=n.f;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"./constants-lk1mMbgx.mjs";import{n as s,r as c,t as l}from"./storage-BccFP9xn.mjs";import{$ as ee,A as te,B as ne,C as re,D as u,E as d,F as ie,G as ae,H as oe,I as f,J as se,K as ce,L as le,M as ue,N as de,O as fe,P as pe,Q as p,R as me,S as he,T as ge,U as _e,V as ve,W as ye,X as be,Y as m,Z as h,_ as g,a as xe,b as Se,c as Ce,d as we,et as _,f as Te,g as v,h as Ee,i as De,it as y,j as Oe,k as ke,l as b,m as x,n as S,nt as C,o as w,p as Ae,q as je,r as Me,rt as T,s as Ne,t as Pe,tt as E,u as Fe,v as Ie,w as Le,x as Re,y as ze,z as Be}from"./helpers-CfLw5cNk.mjs";import{extractFileReference as D}from"@stryke/convert/extract-file-reference";import{murmurhash as O}from"@stryke/hash";import{deepClone as Ve}from"@stryke/helpers/deep-clone";import{isStandardJsonSchema as k}from"@stryke/json";import{findFileExtensionSafe as He}from"@stryke/path/find";import{VALID_OBJECT_SOURCE_EXTENSIONS as A}from"@stryke/resolve/constants";import{loadSafe as Ue}from"@stryke/resolve/load";import{list as We}from"@stryke/string-format/list";import{isSetString as j}from"@stryke/type-checks";import{isSetObject as M}from"@stryke/type-checks/is-set-object";import{extractJsonSchema as Ge,isZod3Type as N}from"@stryke/zod";import{toJsonSchema as Ke}from"@valibot/to-json-schema";import{createGenerator as qe}from"ts-json-schema-generator/dist/factory/generator.js";const P=`https://power-plant.invalid/`;function Je(e){return!(!M(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e)}function F(e){return Je(e)?e.schema:e}function I(e){return e.endsWith(`#`)?e.slice(0,-1):e}function L(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function Ye(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function Xe(e){return e.length===0?``:`/${e.map(e=>Ye(e)).join(`/`)}`}function R(e,t){try{return I(new URL(e,t).toString())}catch{return I(e)}}function z(e,t,n,r,i){if(!M(e))return;let a=e,o=Xe(t),s=j(a.$id)?R(a.$id,n):n,c=L(s);if(r.set(s,o),r.set(c,o),j(a.$anchor)&&r.set(`${c}#${a.$anchor}`,o),j(a.$dynamicAnchor)){let e=`${c}#${a.$dynamicAnchor}`;r.set(e,o),i.set(e,`#${a.$dynamicAnchor}`)}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{z(n,[...t,e,String(a)],s,r,i)});continue}z(n,[...t,e],s,r,i)}}function B(e,t,n,r,i){if(!M(e))return;let a=e,o=j(a.$id)?R(a.$id,n):n;if(j(a.$ref)){let e=R(a.$ref,o),t=r.get(e)??r.get(L(e));t!==void 0&&(a.$ref=t.length>0?`#${t}`:`#`)}if(j(a.$dynamicRef)){let e=R(a.$dynamicRef,o),t=i.get(e);if(t)a.$dynamicRef=t;else{let t=r.get(e)??r.get(L(e));t!==void 0&&(a.$dynamicRef=t.length>0?`#${t}`:`#`)}}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{B(n,[...t,e,String(a)],o,r,i)});continue}B(n,[...t,e],o,r,i)}}function V(e){if(!M(e))return e;let t=Ve(e),n=j(t.$id)?R(t.$id,P):P,r=new Map,i=new Map;return z(t,[],n,r,i),B(t,[],n,r,i),t}function H(e){if(C(e))return W(e);if(M(e)){if(_(e))return G(e);let t=e;if(`$schema`in t&&C(t.$schema))return W(t.$schema)}return e}function Ze(e){return Array.isArray(e)?e.map(e=>H(e)):e}function U(e){return Ke(e,{target:`draft-2020-12`})}function W(e){let t=e,n={};for(let[e,r]of Object.entries(t))if(!(e===`tsType`||e===`markdownType`||e===`tags`||e===`args`||e===`resolve`)){if(e===`id`&&j(r)){n.$id=r;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!M(r)){n[e]=r;continue}n[e]=Object.fromEntries(Object.entries(r).map(([e,t])=>[e,H(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=H(r);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=Ze(r);continue}n[e]=r}return n}function G(e){let t=e,n=C(t.$schema)?W(t.$schema):{},r={};for(let[e,n]of Object.entries(t)){if(e.startsWith(`$`)||!M(n))continue;if(_(n)){r[e]=G(n);continue}let t=n;if(`$schema`in t&&C(t.$schema)){r[e]=W(t.$schema);continue}C(n)&&(r[e]=W(n))}if(!f(n))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let i={...M(n.properties)?n.properties:{},...r};return{...n,type:n.type??`object`,...Object.keys(i).length>0?{properties:i}:{}}}function K(e,t){let n=F(t);if(p(n)||m(n))return O({variant:e,input:n.schema});if(j(n)||typeof n==`boolean`)return O({variant:e,input:n});if(M(n)){if(N(n))return O({variant:e,input:n._def});if(k(n))return O({variant:e,input:n[`~standard`]});if(g(n))return O({variant:e,input:n});if(y(n))return O({variant:e,input:U(n)});if(_(n))return O({variant:e,input:G(n)});if(C(n))return O({variant:e,input:W(n)})}throw Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`)}function q(e){if(M(e)){if(N(e))return Ge(e,{target:`draft-2020-12`});if(E(e))return G(e);if(T(e))return W(e);if(k(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(y(e))return U(e);if(g(e))return e}}function J(e){if(M(e)){if(N(e))return`zod3`;if(E(e)||T(e))return`untyped`;if(k(e))return`standard-schema`;if(g(e))return`json-schema`;if(y(e))return`valibot`}throw Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`)}function Y(e){let t=F(e);return p(t)||m(t)?t.variant:j(t)||v(t)?`file-reference`:J(t)}async function X(e,t){if(p(e))return e.schema;let n=t??J(e),r;if((n===`zod3`||n===`json-schema`||n===`standard-schema`||n===`untyped`||n===`valibot`)&&(r=q(e)),r)return V(r);throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`)}function Z(e,t){if(e===`zod3`)return{hash:K(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:K(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:K(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:K(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:K(e,t),variant:`valibot`,schema:t};throw Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`)}async function Q(e,t={}){let n=D(e);if(!n)throw Error(`Failed to extract a file reference from the provided input. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);let r=n.export??`*`;try{return qe({path:n.file,type:r,expose:`export`,jsDoc:`extended`,...t}).createSchema(r)}catch(e){throw Error(`Failed to generate a JSON schema for "${n.file}" using the type "${r}". Error: ${e.message}`)}}async function $(e,t={}){let n=F(e);if(p(n))return n;if(m(n))return{...n,source:{hash:K(`json-schema`,n.schema),variant:`json-schema`,schema:n.schema}};let r,i=Y(n),a=K(i,n);if(i===`file-reference`){let e=D(n);if(!e)throw Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(n)}". Please ensure that the input is correctly formatted as a file reference (e.g. "./schema.ts#MySchema") and that the file exists at the specified path.`);let i=He(e.file);if(i&&!A.includes(i))throw Error(`The provided schema file input "${e.file}" has an invalid file extension (.${i}). Please ensure that the file has one of the following extensions: ${We(A,{conjunction:`or`})}.`);let a;t.storage&&(a=l(t.storage));let o=await Ue(n,{...t,fs:a});o??=await Q(n,{...t,fs:a});let s=F(o);r=p(s)?s.source:m(s)?{hash:K(`json-schema`,s.schema),variant:`json-schema`,schema:s.schema}:Z(J(s),s)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(i))r=Z(i,n);else throw Error(`Invalid schema definition input "${i}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);return{variant:i,source:r,schema:await X(r.schema,r.variant),hash:a}}async function Qe(e,t={}){let n=F(e);if(p(n)||h(n))return n;let r=await $(e,t);if(!r?.schema)throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);return r}export{o as JSON_SCHEMA_METADATA_KEYS,n as JSON_SCHEMA_PRIMITIVE_TYPES,i as JSON_SCHEMA_TYPES,t as JsonSchemaTypeNames,e as SCHEMA_ARRAY_CONCAT_KEYWORDS,r as SCHEMA_RECORD_KEYWORDS,a as SCHEMA_SINGLE_KEYWORDS,Pe as addProperty,Ae as applyJsonSchemaMetadata,V as bundleReferences,s as createStoragePromises,Qe as extract,K as extractHash,q as extractJsonSchema,J as extractResolvedVariant,X as extractSchema,$ as extractSchemaWithSource,Z as extractSource,Q as extractTSType,Y as extractVariant,S as getJsonSchema,Me as getJsonSchemaObject,x as getPrimarySchemaType,De as getProperties,xe as getPropertiesList,w as getProperty,v as isFileReference,g as isJsonSchema,Ie as isJsonSchemaAllOf,ze as isJsonSchemaAny,Se as isJsonSchemaAnyOf,Re as isJsonSchemaArray,he as isJsonSchemaBigint,re as isJsonSchemaBoolean,Le as isJsonSchemaDate,ge as isJsonSchemaDecimal,d as isJsonSchemaEnum,u as isJsonSchemaInteger,fe as isJsonSchemaKeywords,ke as isJsonSchemaLiteral,te as isJsonSchemaMap,Oe as isJsonSchemaNativeEnum,ue as isJsonSchemaNever,de as isJsonSchemaNull,pe as isJsonSchemaNullable,ie as isJsonSchemaNumber,f as isJsonSchemaObject,le as isJsonSchemaPrimitiveType,me as isJsonSchemaPrimitiveUnion,Be as isJsonSchemaRecord,ne as isJsonSchemaRef,ve as isJsonSchemaSet,oe as isJsonSchemaString,_e as isJsonSchemaTuple,ye as isJsonSchemaType,ae as isJsonSchemaUndefined,ce as isJsonSchemaUnion,je as isJsonSchemaUnknown,se as isNullOnlyJsonSchema,Ne as isPropertyOptional,m as isSchema,Ce as isSchemaNullable,be as isSchemaObject,h as isSchemaOf,p as isSchemaWithSource,ee as isStandardSchema,_ as isUntypedConfig,E as isUntypedConfigStrict,C as isUntypedSchema,T as isUntypedSchemaStrict,y as isValibotSchema,b as isValidSchemaConfigFile,l as mapStorageToFileSystem,Fe as merge,we as mergeMetadata,c as normalizeKey,Ee as readSchemaTypes,Te as traverseSchema};
1
+ import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"./constants-lk1mMbgx.mjs";import{n as s,r as c,t as l}from"./storage-BccFP9xn.mjs";import{$ as ee,A as te,B as ne,C as re,D as u,E as d,F as ie,G as ae,H as oe,I as f,J as se,K as ce,L as le,M as ue,N as de,O as fe,P as pe,Q as p,R as me,S as he,T as ge,U as _e,V as ve,W as ye,X as be,Y as m,Z as h,_ as g,a as xe,b as Se,c as Ce,d as we,et as _,f as Te,g as v,h as Ee,i as De,it as y,j as Oe,k as ke,l as b,m as x,n as S,nt as C,o as w,p as Ae,q as je,r as Me,rt as T,s as Ne,t as Pe,tt as E,u as Fe,v as Ie,w as Le,x as Re,y as ze,z as Be}from"./helpers-CfLw5cNk.mjs";import{extractFileReference as D}from"@stryke/convert/extract-file-reference";import{murmurhash as O}from"@stryke/hash";import{deepClone as Ve}from"@stryke/helpers/deep-clone";import{isStandardJsonSchema as k}from"@stryke/json";import{findFileExtensionSafe as He}from"@stryke/path/find";import{VALID_OBJECT_SOURCE_EXTENSIONS as A}from"@stryke/resolve/constants";import{loadSafe as Ue}from"@stryke/resolve/load";import{list as We}from"@stryke/string-format/list";import{isSetString as j}from"@stryke/type-checks";import{isSetObject as M}from"@stryke/type-checks/is-set-object";import{extractJsonSchema as Ge,isZod3Type as N}from"@stryke/zod";import{toJsonSchema as Ke}from"@valibot/to-json-schema";import{createGenerator as qe}from"ts-json-schema-generator/dist/factory/generator.js";const P=`https://power-plant.invalid/`;function Je(e){return!(!M(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e)}function F(e){return Je(e)?e.schema:e}function I(e){return e.endsWith(`#`)?e.slice(0,-1):e}function L(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function Ye(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function Xe(e){return e.length===0?``:`/${e.map(e=>Ye(e)).join(`/`)}`}function R(e,t){try{return I(new URL(e,t).toString())}catch{return I(e)}}function z(e,t,n,r,i){if(!M(e))return;let a=e,o=Xe(t),s=j(a.$id)?R(a.$id,n):n,c=L(s);if(r.set(s,o),r.set(c,o),j(a.$anchor)&&r.set(`${c}#${a.$anchor}`,o),j(a.$dynamicAnchor)){let e=`${c}#${a.$dynamicAnchor}`;r.set(e,o),i.set(e,`#${a.$dynamicAnchor}`)}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{z(n,[...t,e,String(a)],s,r,i)});continue}z(n,[...t,e],s,r,i)}}function B(e,t,n,r,i){if(!M(e))return;let a=e,o=j(a.$id)?R(a.$id,n):n;if(j(a.$ref)){let e=R(a.$ref,o),t=r.get(e)??r.get(L(e));t!==void 0&&(a.$ref=t.length>0?`#${t}`:`#`)}if(j(a.$dynamicRef)){let e=R(a.$dynamicRef,o),t=i.get(e);if(t)a.$dynamicRef=t;else{let t=r.get(e)??r.get(L(e));t!==void 0&&(a.$dynamicRef=t.length>0?`#${t}`:`#`)}}for(let[e,n]of Object.entries(a)){if(Array.isArray(n)){n.forEach((n,a)=>{B(n,[...t,e,String(a)],o,r,i)});continue}B(n,[...t,e],o,r,i)}}function V(e){if(!M(e))return e;let t=Ve(e),n=j(t.$id)?R(t.$id,P):P,r=new Map,i=new Map;return z(t,[],n,r,i),B(t,[],n,r,i),t}function H(e){if(C(e))return W(e);if(M(e)){if(_(e))return G(e);let t=e;if(`$schema`in t&&C(t.$schema))return W(t.$schema)}return e}function Ze(e){return Array.isArray(e)?e.map(e=>H(e)):e}function U(e){return Ke(e,{target:`draft-2020-12`})}function W(e){let t=e,n={};for(let[e,r]of Object.entries(t))if(e!==`tsType`&&e!==`markdownType`&&e!==`tags`&&e!==`args`&&e!==`resolve`){if(e===`id`&&j(r)){n.$id=r;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!M(r)){n[e]=r;continue}n[e]=Object.fromEntries(Object.entries(r).map(([e,t])=>[e,H(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=H(r);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=Ze(r);continue}n[e]=r}return n}function G(e){let t=e,n=C(t.$schema)?W(t.$schema):{},r={};for(let[e,n]of Object.entries(t)){if(e.startsWith(`$`)||!M(n))continue;if(_(n)){r[e]=G(n);continue}let t=n;if(`$schema`in t&&C(t.$schema)){r[e]=W(t.$schema);continue}C(n)&&(r[e]=W(n))}if(!f(n))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let i={...M(n.properties)?n.properties:{},...r};return{...n,type:n.type??`object`,...Object.keys(i).length>0?{properties:i}:{}}}function K(e,t){let n=F(t);if(p(n)||m(n))return O({variant:e,input:n.schema});if(j(n)||typeof n==`boolean`)return O({variant:e,input:n});if(M(n)){if(N(n))return O({variant:e,input:n._def});if(k(n))return O({variant:e,input:n[`~standard`]});if(g(n))return O({variant:e,input:n});if(y(n))return O({variant:e,input:U(n)});if(_(n))return O({variant:e,input:G(n)});if(C(n))return O({variant:e,input:W(n)})}throw Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`)}function q(e){if(M(e)){if(N(e))return Ge(e,{target:`draft-2020-12`});if(E(e))return G(e);if(T(e))return W(e);if(k(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(y(e))return U(e);if(g(e))return e}}function J(e){if(M(e)){if(N(e))return`zod3`;if(E(e)||T(e))return`untyped`;if(k(e))return`standard-schema`;if(g(e))return`json-schema`;if(y(e))return`valibot`}throw Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`)}function Y(e){let t=F(e);return p(t)||m(t)?t.variant:j(t)||v(t)?`file-reference`:J(t)}async function X(e,t){if(p(e))return e.schema;let n=t??J(e),r;if((n===`zod3`||n===`json-schema`||n===`standard-schema`||n===`untyped`||n===`valibot`)&&(r=q(e)),r)return V(r);throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`)}function Z(e,t){if(e===`zod3`)return{hash:K(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:K(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:K(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:K(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:K(e,t),variant:`valibot`,schema:t};throw Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`)}async function Q(e,t={}){let n=D(e);if(!n)throw Error(`Failed to extract a file reference from the provided input. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);let r=n.export??`*`;try{return qe({path:n.file,type:r,expose:`export`,jsDoc:`extended`,...t}).createSchema(r)}catch(e){throw Error(`Failed to generate a JSON schema for "${n.file}" using the type "${r}". Error: ${e.message}`)}}async function $(e,t={}){let n=F(e);if(p(n))return n;if(m(n))return{...n,source:{hash:K(`json-schema`,n.schema),variant:`json-schema`,schema:n.schema}};let r,i=Y(n),a=K(i,n);if(i===`file-reference`){let e=D(n);if(!e)throw Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(n)}". Please ensure that the input is correctly formatted as a file reference (e.g. "./schema.ts#MySchema") and that the file exists at the specified path.`);let i=He(e.file);if(i&&!A.includes(i))throw Error(`The provided schema file input "${e.file}" has an invalid file extension (.${i}). Please ensure that the file has one of the following extensions: ${We(A,{conjunction:`or`})}.`);let a;t.storage&&(a=l(t.storage));let o=await Ue(n,{...t,fs:a});o??=await Q(n,{...t,fs:a});let s=F(o);r=p(s)?s.source:m(s)?{hash:K(`json-schema`,s.schema),variant:`json-schema`,schema:s.schema}:Z(J(s),s)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(i))r=Z(i,n);else throw Error(`Invalid schema definition input "${i}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);return{variant:i,source:r,schema:await X(r.schema,r.variant),hash:a}}async function Qe(e,t={}){let n=F(e);if(p(n)||h(n))return n;let r=await $(e,t);if(!r?.schema)throw Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);return r}export{o as JSON_SCHEMA_METADATA_KEYS,n as JSON_SCHEMA_PRIMITIVE_TYPES,i as JSON_SCHEMA_TYPES,t as JsonSchemaTypeNames,e as SCHEMA_ARRAY_CONCAT_KEYWORDS,r as SCHEMA_RECORD_KEYWORDS,a as SCHEMA_SINGLE_KEYWORDS,Pe as addProperty,Ae as applyJsonSchemaMetadata,V as bundleReferences,s as createStoragePromises,Qe as extract,K as extractHash,q as extractJsonSchema,J as extractResolvedVariant,X as extractSchema,$ as extractSchemaWithSource,Z as extractSource,Q as extractTSType,Y as extractVariant,S as getJsonSchema,Me as getJsonSchemaObject,x as getPrimarySchemaType,De as getProperties,xe as getPropertiesList,w as getProperty,v as isFileReference,g as isJsonSchema,Ie as isJsonSchemaAllOf,ze as isJsonSchemaAny,Se as isJsonSchemaAnyOf,Re as isJsonSchemaArray,he as isJsonSchemaBigint,re as isJsonSchemaBoolean,Le as isJsonSchemaDate,ge as isJsonSchemaDecimal,d as isJsonSchemaEnum,u as isJsonSchemaInteger,fe as isJsonSchemaKeywords,ke as isJsonSchemaLiteral,te as isJsonSchemaMap,Oe as isJsonSchemaNativeEnum,ue as isJsonSchemaNever,de as isJsonSchemaNull,pe as isJsonSchemaNullable,ie as isJsonSchemaNumber,f as isJsonSchemaObject,le as isJsonSchemaPrimitiveType,me as isJsonSchemaPrimitiveUnion,Be as isJsonSchemaRecord,ne as isJsonSchemaRef,ve as isJsonSchemaSet,oe as isJsonSchemaString,_e as isJsonSchemaTuple,ye as isJsonSchemaType,ae as isJsonSchemaUndefined,ce as isJsonSchemaUnion,je as isJsonSchemaUnknown,se as isNullOnlyJsonSchema,Ne as isPropertyOptional,m as isSchema,Ce as isSchemaNullable,be as isSchemaObject,h as isSchemaOf,p as isSchemaWithSource,ee as isStandardSchema,_ as isUntypedConfig,E as isUntypedConfigStrict,C as isUntypedSchema,T as isUntypedSchemaStrict,y as isValibotSchema,b as isValidSchemaConfigFile,l as mapStorageToFileSystem,Fe as merge,we as mergeMetadata,c as normalizeKey,Ee as readSchemaTypes,Te as traverseSchema};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"valibot.d.cts","names":[],"sources":["../src/valibot.ts"],"mappings":";;;cAuDa,iBAAe,EAAA;;;iBAIZ,MAAM,gBAAgB,EAAE,eAAe,QAAQ,UAAO,EAAA,aAAA,EAAA;;;cA6BzD,YAAY,EAAE,cAAc"}
1
+ {"version":3,"file":"valibot.d.cts","names":[],"sources":["../src/valibot.ts"],"mappings":";;;cAuDa,iBAAe,EAAA;;;iBAIZ,MAAM,gBAAgB,EAAE,eAAe,QAAQ,UAAO,EAAA,aAAA,EAAA;;eAErE;cA2BY,YAqEP,EAAE,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"zod.d.cts","names":[],"sources":["../src/zod.ts"],"mappings":";;;;cAgEa,iBAAe,EAAA;;;iBAIZ,MAAM,UAAU,EAAE,aAAa,QAAQ,IAAC,EAAA,uBAAA,EAAA;;;cA6B3C,YAAY,EAAE,YAAY;;;;;;;;iBAgFvB,YACd,QAAQ,aAAa,gBACrB,SAAQ,kBAAkB,GAAG,qBAC5B,GAAG"}
1
+ {"version":3,"file":"zod.d.cts","names":[],"sources":["../src/zod.ts"],"mappings":";;;;cAgEa,iBAAe,EAAA;;GAE1B,EAAA,KAAA;iBAEc,MAAM,UAAU,EAAE,aAAa,QAAQ,IAAC,EAAA,uBAAA,EAAA;;GAEvD,EAAA,KAAA,SAAA;cA2BY,YAAY,EAAE,YAAY;;;;;;;;iBAgFvB,YACd,QAAQ,aAAa,gBACrB,SAAQ,kBAAkB,GAAG,qBAC5B,GAAG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@power-plant/schema",
3
- "version": "0.0.12",
3
+ "version": "0.0.16",
4
4
  "private": false,
5
5
  "description": "A Power Plant utility package to help managing schemas.",
6
6
  "keywords": [
@@ -140,9 +140,9 @@
140
140
  "untyped": "^1.5.2"
141
141
  },
142
142
  "devDependencies": {
143
- "@powerlines/plugin-tsdown": "^0.1.543",
143
+ "@powerlines/plugin-tsdown": "^0.1.545",
144
144
  "@types/node": "^25.9.5",
145
- "powerlines": "^0.47.142",
145
+ "powerlines": "^0.47.144",
146
146
  "valibot": "^1.4.2",
147
147
  "zod": "^4.4.3"
148
148
  },
@@ -155,5 +155,5 @@
155
155
  "zod": { "optional": true }
156
156
  },
157
157
  "publishConfig": { "access": "public" },
158
- "gitHead": "27e84d9116561bc573590459566dc4443b02b9c6"
158
+ "gitHead": "8cb4ebd50961de43b9482885f5ba5779b8ded913"
159
159
  }