@power-plant/schema 0.0.3 → 0.0.5

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.
Files changed (79) hide show
  1. package/dist/codegen.cjs +77 -1
  2. package/dist/codegen.d.cts +1 -1
  3. package/dist/codegen.d.mts +1 -1
  4. package/dist/codegen.mjs +78 -1
  5. package/dist/codegen.mjs.map +1 -0
  6. package/dist/constants-CwyhgVEl.cjs +1 -0
  7. package/dist/constants-lk1mMbgx.mjs +2 -0
  8. package/dist/constants-lk1mMbgx.mjs.map +1 -0
  9. package/dist/helpers-B5sr5S3X.cjs +1 -0
  10. package/dist/helpers-Bh_V7xwV.mjs +2 -0
  11. package/dist/helpers-Bh_V7xwV.mjs.map +1 -0
  12. package/dist/index.cjs +1 -1
  13. package/dist/index.d.cts +616 -31
  14. package/dist/index.d.cts.map +1 -1
  15. package/dist/index.d.mts +616 -31
  16. package/dist/index.d.mts.map +1 -1
  17. package/dist/index.mjs +2 -1
  18. package/dist/index.mjs.map +1 -0
  19. package/dist/{types.d.cts → types-BawP3FVI.d.mts} +81 -180
  20. package/dist/types-BawP3FVI.d.mts.map +1 -0
  21. package/dist/{types.d.mts → types-BmNamqlM.d.cts} +80 -179
  22. package/dist/types-BmNamqlM.d.cts.map +1 -0
  23. package/dist/valibot.cjs +1 -0
  24. package/dist/valibot.d.cts +14 -0
  25. package/dist/valibot.d.cts.map +1 -0
  26. package/dist/valibot.d.mts +14 -0
  27. package/dist/valibot.d.mts.map +1 -0
  28. package/dist/valibot.mjs +2 -0
  29. package/dist/valibot.mjs.map +1 -0
  30. package/dist/zod.cjs +1 -0
  31. package/dist/zod.d.cts +14 -0
  32. package/dist/zod.d.cts.map +1 -0
  33. package/dist/zod.d.mts +14 -0
  34. package/dist/zod.d.mts.map +1 -0
  35. package/dist/zod.mjs +2 -0
  36. package/dist/zod.mjs.map +1 -0
  37. package/package.json +26 -91
  38. package/dist/constants-u7ovYS9e.d.cts +0 -31
  39. package/dist/constants-u7ovYS9e.d.cts.map +0 -1
  40. package/dist/constants-u7ovYS9e.d.mts +0 -31
  41. package/dist/constants-u7ovYS9e.d.mts.map +0 -1
  42. package/dist/constants.cjs +0 -1
  43. package/dist/constants.d.cts +0 -2
  44. package/dist/constants.d.mts +0 -2
  45. package/dist/constants.mjs +0 -2
  46. package/dist/constants.mjs.map +0 -1
  47. package/dist/extract.cjs +0 -1
  48. package/dist/extract.d.cts +0 -143
  49. package/dist/extract.d.cts.map +0 -1
  50. package/dist/extract.d.mts +0 -143
  51. package/dist/extract.d.mts.map +0 -1
  52. package/dist/extract.mjs +0 -2
  53. package/dist/extract.mjs.map +0 -1
  54. package/dist/helpers.cjs +0 -1
  55. package/dist/helpers.d.cts +0 -134
  56. package/dist/helpers.d.cts.map +0 -1
  57. package/dist/helpers.d.mts +0 -134
  58. package/dist/helpers.d.mts.map +0 -1
  59. package/dist/helpers.mjs +0 -1
  60. package/dist/metadata-CsY3HrP2.cjs +0 -77
  61. package/dist/metadata-DIEpQjbq.mjs +0 -78
  62. package/dist/metadata-DIEpQjbq.mjs.map +0 -1
  63. package/dist/metadata.cjs +0 -1
  64. package/dist/metadata.d.cts +0 -94
  65. package/dist/metadata.d.cts.map +0 -1
  66. package/dist/metadata.d.mts +0 -94
  67. package/dist/metadata.d.mts.map +0 -1
  68. package/dist/metadata.mjs +0 -1
  69. package/dist/type-checks.cjs +0 -1
  70. package/dist/type-checks.d.cts +0 -331
  71. package/dist/type-checks.d.cts.map +0 -1
  72. package/dist/type-checks.d.mts +0 -331
  73. package/dist/type-checks.d.mts.map +0 -1
  74. package/dist/type-checks.mjs +0 -2
  75. package/dist/type-checks.mjs.map +0 -1
  76. package/dist/types.cjs +0 -0
  77. package/dist/types.d.cts.map +0 -1
  78. package/dist/types.d.mts.map +0 -1
  79. package/dist/types.mjs +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@power-plant/schema",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "description": "A Power Plant utility package to help managing schemas.",
6
6
  "keywords": [
@@ -77,90 +77,25 @@
77
77
  "default": "./dist/codegen.mjs"
78
78
  }
79
79
  },
80
- "./constants": {
81
- "require": {
82
- "types": "./dist/constants.d.cts",
83
- "default": "./dist/constants.cjs"
84
- },
85
- "import": {
86
- "types": "./dist/constants.d.mts",
87
- "default": "./dist/constants.mjs"
88
- },
89
- "default": {
90
- "types": "./dist/constants.d.mts",
91
- "default": "./dist/constants.mjs"
92
- }
93
- },
94
- "./extract": {
95
- "require": {
96
- "types": "./dist/extract.d.cts",
97
- "default": "./dist/extract.cjs"
98
- },
99
- "import": {
100
- "types": "./dist/extract.d.mts",
101
- "default": "./dist/extract.mjs"
102
- },
103
- "default": {
104
- "types": "./dist/extract.d.mts",
105
- "default": "./dist/extract.mjs"
106
- }
107
- },
108
- "./helpers": {
109
- "require": {
110
- "types": "./dist/helpers.d.cts",
111
- "default": "./dist/helpers.cjs"
112
- },
113
- "import": {
114
- "types": "./dist/helpers.d.mts",
115
- "default": "./dist/helpers.mjs"
116
- },
117
- "default": {
118
- "types": "./dist/helpers.d.mts",
119
- "default": "./dist/helpers.mjs"
120
- }
121
- },
122
- "./metadata": {
123
- "require": {
124
- "types": "./dist/metadata.d.cts",
125
- "default": "./dist/metadata.cjs"
126
- },
127
- "import": {
128
- "types": "./dist/metadata.d.mts",
129
- "default": "./dist/metadata.mjs"
130
- },
131
- "default": {
132
- "types": "./dist/metadata.d.mts",
133
- "default": "./dist/metadata.mjs"
134
- }
135
- },
136
80
  "./package.json": "./package.json",
137
- "./type-checks": {
81
+ "./valibot": {
138
82
  "require": {
139
- "types": "./dist/type-checks.d.cts",
140
- "default": "./dist/type-checks.cjs"
83
+ "types": "./dist/valibot.d.cts",
84
+ "default": "./dist/valibot.cjs"
141
85
  },
142
86
  "import": {
143
- "types": "./dist/type-checks.d.mts",
144
- "default": "./dist/type-checks.mjs"
87
+ "types": "./dist/valibot.d.mts",
88
+ "default": "./dist/valibot.mjs"
145
89
  },
146
90
  "default": {
147
- "types": "./dist/type-checks.d.mts",
148
- "default": "./dist/type-checks.mjs"
91
+ "types": "./dist/valibot.d.mts",
92
+ "default": "./dist/valibot.mjs"
149
93
  }
150
94
  },
151
- "./types": {
152
- "require": {
153
- "types": "./dist/types.d.cts",
154
- "default": "./dist/types.cjs"
155
- },
156
- "import": {
157
- "types": "./dist/types.d.mts",
158
- "default": "./dist/types.mjs"
159
- },
160
- "default": {
161
- "types": "./dist/types.d.mts",
162
- "default": "./dist/types.mjs"
163
- }
95
+ "./zod": {
96
+ "require": { "types": "./dist/zod.d.cts", "default": "./dist/zod.cjs" },
97
+ "import": { "types": "./dist/zod.d.mts", "default": "./dist/zod.mjs" },
98
+ "default": { "types": "./dist/zod.d.mts", "default": "./dist/zod.mjs" }
164
99
  }
165
100
  },
166
101
  "main": "./dist/index.cjs",
@@ -170,19 +105,19 @@
170
105
  "files": ["dist"],
171
106
  "dependencies": {
172
107
  "@standard-schema/spec": "^1.1.0",
173
- "@stryke/convert": "^0.7.23",
174
- "@stryke/date": "^0.0.4",
175
- "@stryke/hash": "^0.13.46",
176
- "@stryke/helpers": "^0.10.32",
177
- "@stryke/json": "^0.15.16",
178
- "@stryke/path": "^0.29.19",
179
- "@stryke/resolve": "^0.0.8",
180
- "@stryke/string-format": "^0.17.34",
181
- "@stryke/type-checks": "^0.6.25",
182
- "@stryke/types": "^0.12.20",
183
- "@stryke/unique-id": "^0.3.104",
184
- "@stryke/url": "^0.4.43",
185
- "@stryke/zod": "^0.3.38",
108
+ "@stryke/convert": "^0.7.25",
109
+ "@stryke/date": "^0.0.6",
110
+ "@stryke/hash": "^0.13.48",
111
+ "@stryke/helpers": "^0.10.34",
112
+ "@stryke/json": "^0.15.18",
113
+ "@stryke/path": "^0.29.21",
114
+ "@stryke/resolve": "^0.0.10",
115
+ "@stryke/string-format": "^0.17.36",
116
+ "@stryke/type-checks": "^0.6.27",
117
+ "@stryke/types": "^0.12.22",
118
+ "@stryke/unique-id": "^0.3.106",
119
+ "@stryke/url": "^0.4.45",
120
+ "@stryke/zod": "^0.3.40",
186
121
  "@valibot/to-json-schema": "^1.7.1",
187
122
  "defu": "^6.1.7",
188
123
  "ts-json-schema-generator": "^2.9.0",
@@ -205,5 +140,5 @@
205
140
  "zod": { "optional": true }
206
141
  },
207
142
  "publishConfig": { "access": "public" },
208
- "gitHead": "43169e6b829afa991d5a0a3ea05a49b800aa9d44"
143
+ "gitHead": "bdd629384084ca6a276f91c0ee5b3fdfca4b6f2e"
209
144
  }
@@ -1,31 +0,0 @@
1
- //#region src/constants.d.ts
2
- declare const JsonSchemaTypeNames: {
3
- readonly STRING: "string";
4
- readonly NUMBER: "number";
5
- readonly INTEGER: "integer";
6
- readonly BOOLEAN: "boolean";
7
- readonly NULL: "null";
8
- readonly OBJECT: "object";
9
- readonly ARRAY: "array";
10
- };
11
- declare const JSON_SCHEMA_PRIMITIVE_TYPES: readonly ["string", "number", "integer", "boolean", "null"];
12
- declare const JSON_SCHEMA_TYPES: readonly ["string", "number", "integer", "boolean", "null", "array", "object"];
13
- declare const JSON_SCHEMA_METADATA_KEYS: ("$id" | "$schema" | "$vocabulary" | "$comment" | "$anchor" | "$defs" | "$dynamicRef" | "$dynamicAnchor" | "name" | "version" | "displayName" | "description" | "docs" | "examples" | "alias" | "tags" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
14
- /**
15
- * Keywords whose values are a flat record of named JSON Schema fragments.
16
- * Each child schema is merged recursively with its counterpart.
17
- */
18
- declare const SCHEMA_RECORD_KEYWORDS: Set<string>;
19
- /**
20
- * Keywords whose value is a single JSON Schema fragment that should be
21
- * recursively merged when both sides define it.
22
- */
23
- declare const SCHEMA_SINGLE_KEYWORDS: Set<string>;
24
- /**
25
- * Keywords whose values are arrays of JSON Schema fragments that should be
26
- * concatenated (rather than overridden) during a merge.
27
- */
28
- declare const SCHEMA_ARRAY_CONCAT_KEYWORDS: Set<string>;
29
- //#endregion
30
- export { SCHEMA_ARRAY_CONCAT_KEYWORDS as a, JsonSchemaTypeNames as i, JSON_SCHEMA_PRIMITIVE_TYPES as n, SCHEMA_RECORD_KEYWORDS as o, JSON_SCHEMA_TYPES as r, SCHEMA_SINGLE_KEYWORDS as s, JSON_SCHEMA_METADATA_KEYS as t };
31
- //# sourceMappingURL=constants-u7ovYS9e.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-u7ovYS9e.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAoBa,mBAAA;EAAA;;;;;;;;cAUA,2BAAA;AAAA,cAQA,iBAAA;AAAA,cAMA,yBAAA;;;AAdb;;cA4Ca,sBAAA,EAAsB,GAAA;;AAtCzB;AAEV;;cAgDa,sBAAA,EAAsB,GAAA;;AA5CzB;AAEV;;cA2Da,4BAAA,EAA4B,GAAA"}
@@ -1,31 +0,0 @@
1
- //#region src/constants.d.ts
2
- declare const JsonSchemaTypeNames: {
3
- readonly STRING: "string";
4
- readonly NUMBER: "number";
5
- readonly INTEGER: "integer";
6
- readonly BOOLEAN: "boolean";
7
- readonly NULL: "null";
8
- readonly OBJECT: "object";
9
- readonly ARRAY: "array";
10
- };
11
- declare const JSON_SCHEMA_PRIMITIVE_TYPES: readonly ["string", "number", "integer", "boolean", "null"];
12
- declare const JSON_SCHEMA_TYPES: readonly ["string", "number", "integer", "boolean", "null", "array", "object"];
13
- declare const JSON_SCHEMA_METADATA_KEYS: ("$id" | "$schema" | "$vocabulary" | "$comment" | "$anchor" | "$defs" | "$dynamicRef" | "$dynamicAnchor" | "name" | "version" | "displayName" | "description" | "docs" | "examples" | "alias" | "tags" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
14
- /**
15
- * Keywords whose values are a flat record of named JSON Schema fragments.
16
- * Each child schema is merged recursively with its counterpart.
17
- */
18
- declare const SCHEMA_RECORD_KEYWORDS: Set<string>;
19
- /**
20
- * Keywords whose value is a single JSON Schema fragment that should be
21
- * recursively merged when both sides define it.
22
- */
23
- declare const SCHEMA_SINGLE_KEYWORDS: Set<string>;
24
- /**
25
- * Keywords whose values are arrays of JSON Schema fragments that should be
26
- * concatenated (rather than overridden) during a merge.
27
- */
28
- declare const SCHEMA_ARRAY_CONCAT_KEYWORDS: Set<string>;
29
- //#endregion
30
- export { SCHEMA_ARRAY_CONCAT_KEYWORDS as a, JsonSchemaTypeNames as i, JSON_SCHEMA_PRIMITIVE_TYPES as n, SCHEMA_RECORD_KEYWORDS as o, JSON_SCHEMA_TYPES as r, SCHEMA_SINGLE_KEYWORDS as s, JSON_SCHEMA_METADATA_KEYS as t };
31
- //# sourceMappingURL=constants-u7ovYS9e.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-u7ovYS9e.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":""}
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e={STRING:`string`,NUMBER:`number`,INTEGER:`integer`,BOOLEAN:`boolean`,NULL:`null`,OBJECT:`object`,ARRAY:`array`},t=[e.STRING,e.NUMBER,e.INTEGER,e.BOOLEAN,e.NULL],n=[...t,e.ARRAY,e.OBJECT],r=[`$id`,`$schema`,`$vocabulary`,`$comment`,`$anchor`,`$defs`,`$dynamicRef`,`$dynamicAnchor`,`alias`,`deprecated`,`description`,`displayName`,`docs`,`examples`,`hidden`,`ignore`,`internal`,`name`,`readOnly`,`runtime`,`tags`,`version`,`writeOnly`],i=new Set([`properties`,`patternProperties`,`$defs`,`definitions`,`dependentSchemas`]),a=new Set([`if`,`then`,`else`,`not`,`contains`,`items`,`additionalProperties`,`unevaluatedProperties`,`propertyNames`,`unevaluatedItems`]),o=new Set([`allOf`,`anyOf`,`oneOf`]);exports.JSON_SCHEMA_METADATA_KEYS=r,exports.JSON_SCHEMA_PRIMITIVE_TYPES=t,exports.JSON_SCHEMA_TYPES=n,exports.JsonSchemaTypeNames=e,exports.SCHEMA_ARRAY_CONCAT_KEYWORDS=o,exports.SCHEMA_RECORD_KEYWORDS=i,exports.SCHEMA_SINGLE_KEYWORDS=a;
@@ -1,2 +0,0 @@
1
- import { a as SCHEMA_ARRAY_CONCAT_KEYWORDS, i as JsonSchemaTypeNames, n as JSON_SCHEMA_PRIMITIVE_TYPES, o as SCHEMA_RECORD_KEYWORDS, r as JSON_SCHEMA_TYPES, s as SCHEMA_SINGLE_KEYWORDS, t as JSON_SCHEMA_METADATA_KEYS } from "./constants-u7ovYS9e.cjs";
2
- export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, SCHEMA_ARRAY_CONCAT_KEYWORDS, SCHEMA_RECORD_KEYWORDS, SCHEMA_SINGLE_KEYWORDS };
@@ -1,2 +0,0 @@
1
- import { a as SCHEMA_ARRAY_CONCAT_KEYWORDS, i as JsonSchemaTypeNames, n as JSON_SCHEMA_PRIMITIVE_TYPES, o as SCHEMA_RECORD_KEYWORDS, r as JSON_SCHEMA_TYPES, s as SCHEMA_SINGLE_KEYWORDS, t as JSON_SCHEMA_METADATA_KEYS } from "./constants-u7ovYS9e.mjs";
2
- export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, SCHEMA_ARRAY_CONCAT_KEYWORDS, SCHEMA_RECORD_KEYWORDS, SCHEMA_SINGLE_KEYWORDS };
@@ -1,2 +0,0 @@
1
- const e={STRING:`string`,NUMBER:`number`,INTEGER:`integer`,BOOLEAN:`boolean`,NULL:`null`,OBJECT:`object`,ARRAY:`array`},t=[e.STRING,e.NUMBER,e.INTEGER,e.BOOLEAN,e.NULL],n=[...t,e.ARRAY,e.OBJECT],r=[`$id`,`$schema`,`$vocabulary`,`$comment`,`$anchor`,`$defs`,`$dynamicRef`,`$dynamicAnchor`,`alias`,`deprecated`,`description`,`displayName`,`docs`,`examples`,`hidden`,`ignore`,`internal`,`name`,`readOnly`,`runtime`,`tags`,`version`,`writeOnly`],i=new Set([`properties`,`patternProperties`,`$defs`,`definitions`,`dependentSchemas`]),a=new Set([`if`,`then`,`else`,`not`,`contains`,`items`,`additionalProperties`,`unevaluatedProperties`,`propertyNames`,`unevaluatedItems`]),o=new Set([`allOf`,`anyOf`,`oneOf`]);export{r as JSON_SCHEMA_METADATA_KEYS,t as JSON_SCHEMA_PRIMITIVE_TYPES,n as JSON_SCHEMA_TYPES,e as JsonSchemaTypeNames,o as SCHEMA_ARRAY_CONCAT_KEYWORDS,i as SCHEMA_RECORD_KEYWORDS,a as SCHEMA_SINGLE_KEYWORDS};
2
- //# sourceMappingURL=constants.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.mjs","names":[],"sources":[],"mappings":""}
package/dist/extract.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./metadata-CsY3HrP2.cjs"),t=require("./type-checks.cjs");let n=require("@stryke/type-checks"),r=require("@stryke/type-checks/is-set-object"),i=require("@stryke/string-format/list"),a=require("@stryke/path/find"),o=require("@stryke/resolve/constants"),s=require("@stryke/convert/extract-file-reference"),c=require("@stryke/hash"),l=require("@stryke/helpers/deep-clone"),u=require("@stryke/json"),d=require("@stryke/resolve/load"),f=require("@stryke/zod"),p=require("@valibot/to-json-schema"),m=require("ts-json-schema-generator/dist/factory/generator.js");const h=`https://power-plant.invalid/`;function g(e){return!(0,r.isSetObject)(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e?!1:Object.keys(e).every(e=>e===`schema`||e===`meta`)}function _(e){return g(e)?{input:e.schema,meta:(0,n.isSetString)(e.meta)?{description:e.meta}:e.meta}:{input:e}}function v(e){return e.endsWith(`#`)?e.slice(0,-1):e}function y(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function b(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function x(e){return e.length===0?``:`/${e.map(e=>b(e)).join(`/`)}`}function S(e,t){try{return v(new URL(e,t).toString())}catch{return v(e)}}function C(e,t,i,a,o){if(!(0,r.isSetObject)(e))return;let s=e,c=x(t),l=(0,n.isSetString)(s.$id)?S(s.$id,i):i,u=y(l);if(a.set(l,c),a.set(u,c),(0,n.isSetString)(s.$anchor)&&a.set(`${u}#${s.$anchor}`,c),(0,n.isSetString)(s.$dynamicAnchor)){let e=`${u}#${s.$dynamicAnchor}`;a.set(e,c),o.set(e,`#${s.$dynamicAnchor}`)}for(let[e,n]of Object.entries(s)){if(Array.isArray(n)){n.forEach((n,r)=>{C(n,[...t,e,String(r)],l,a,o)});continue}C(n,[...t,e],l,a,o)}}function w(e,t,i,a,o){if(!(0,r.isSetObject)(e))return;let s=e,c=(0,n.isSetString)(s.$id)?S(s.$id,i):i;if((0,n.isSetString)(s.$ref)){let e=S(s.$ref,c),t=a.get(e)??a.get(y(e));t!==void 0&&(s.$ref=t.length>0?`#${t}`:`#`)}if((0,n.isSetString)(s.$dynamicRef)){let e=S(s.$dynamicRef,c),t=o.get(e);if(t)s.$dynamicRef=t;else{let t=a.get(e)??a.get(y(e));t!==void 0&&(s.$dynamicRef=t.length>0?`#${t}`:`#`)}}for(let[e,n]of Object.entries(s)){if(Array.isArray(n)){n.forEach((n,r)=>{w(n,[...t,e,String(r)],c,a,o)});continue}w(n,[...t,e],c,a,o)}}function T(e){if(!(0,r.isSetObject)(e))return e;let t=(0,l.deepClone)(e),i=(0,n.isSetString)(t.$id)?S(t.$id,h):h,a=new Map,o=new Map;return C(t,[],i,a,o),w(t,[],i,a,o),t}function E(e){if(t.isUntypedSchema(e))return k(e);if((0,r.isSetObject)(e)){if(t.isUntypedInput(e))return A(e);let n=e;if(`$schema`in n&&t.isUntypedSchema(n.$schema))return k(n.$schema)}return e}function D(e){return Array.isArray(e)?e.map(e=>E(e)):e}function O(e){return(0,p.toJsonSchema)(e,{target:`draft-2020-12`})}function k(e){let t=e,i={};for(let[e,a]of Object.entries(t))if(!(e===`tsType`||e===`markdownType`||e===`tags`||e===`args`||e===`resolve`)){if(e===`id`&&(0,n.isSetString)(a)){i.$id=a;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!(0,r.isSetObject)(a)){i[e]=a;continue}i[e]=Object.fromEntries(Object.entries(a).map(([e,t])=>[e,E(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){i[e]=E(a);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){i[e]=D(a);continue}i[e]=a}return i}function A(e){let n=e,i=t.isUntypedSchema(n.$schema)?k(n.$schema):{},a={};for(let[e,i]of Object.entries(n)){if(e.startsWith(`$`)||!(0,r.isSetObject)(i))continue;if(t.isUntypedInput(i)){a[e]=A(i);continue}let n=i;if(`$schema`in n&&t.isUntypedSchema(n.$schema)){a[e]=k(n.$schema);continue}t.isUntypedSchema(i)&&(a[e]=k(i))}if(!t.isJsonSchemaObject(i))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let o={...(0,r.isSetObject)(i.properties)?i.properties:{},...a};return{...i,type:i.type??`object`,...Object.keys(o).length>0?{properties:o}:{}}}function j(e,i){let{input:a}=_(i);if(t.isSchemaWithSource(a)||t.isSchema(a))return(0,c.murmurhash)({variant:e,input:a.schema});if((0,n.isSetString)(a)||typeof a==`boolean`)return(0,c.murmurhash)({variant:e,input:a});if((0,r.isSetObject)(a)){if((0,f.isZod3Type)(a))return(0,c.murmurhash)({variant:e,input:a._def});if((0,u.isStandardJsonSchema)(a))return(0,c.murmurhash)({variant:e,input:a[`~standard`]});if(t.isJsonSchema(a))return(0,c.murmurhash)({variant:e,input:a});if(t.isValibotSchema(a))return(0,c.murmurhash)({variant:e,input:O(a)});if(t.isUntypedInput(a))return(0,c.murmurhash)({variant:e,input:A(a)});if(t.isUntypedSchema(a))return(0,c.murmurhash)({variant:e,input:k(a)})}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 M(e){if((0,r.isSetObject)(e)){if((0,f.isZod3Type)(e))return(0,f.extractJsonSchema)(e,{target:`draft-2020-12`});if(t.isUntypedInputStrict(e))return A(e);if(t.isUntypedSchemaStrict(e))return k(e);if((0,u.isStandardJsonSchema)(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(t.isValibotSchema(e))return O(e);if(t.isJsonSchema(e))return e}}function N(e){if((0,r.isSetObject)(e)){if((0,f.isZod3Type)(e))return`zod3`;if(t.isUntypedInputStrict(e)||t.isUntypedSchemaStrict(e))return`untyped`;if((0,u.isStandardJsonSchema)(e))return`standard-schema`;if(t.isJsonSchema(e))return`json-schema`;if(t.isValibotSchema(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 P(e){let{input:r}=_(e);return t.isSchemaWithSource(r)||t.isSchema(r)?r.variant:(0,n.isSetString)(r)||t.isFileReference(r)?`file-reference`:N(r)}async function F(e,n){if(t.isSchemaWithSource(e))return e.schema;let r=n??N(e),i;if((r===`zod3`||r===`json-schema`||r===`standard-schema`||r===`untyped`||r===`valibot`)&&(i=M(e)),i)return T(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 I(e,t){if(e===`zod3`)return{hash:j(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:j(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:j(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:j(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:j(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 L(e,t={}){let n=(0,s.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 r=n.export??`*`;try{return(0,m.createGenerator)({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}`)}}function R(t,n){let r=t.schema,i=t.meta??{};return i.name=e.u(r,i,n?.name),i.version=e.d(r,i,n?.version),i.id=e.c(r,i),i.displayName=e.o(r,i,n?.displayName),i.description=e.a(`A schema that describes the shape of the {displayName} specification.`,t.schema,i,n?.description),i.examples=e.s(t.schema,i,n?.examples),i.links=e.l(t.schema,i,n?.links),n?.deprecated&&(i.deprecated=n?.deprecated),n?.usage&&(i.usage=n?.usage),n?.tags&&(i.tags=n?.tags),i}async function z(e,n={}){let{input:r,meta:c}=_(e);if(t.isSchemaWithSource(r))return{...r,meta:R(r,c)};if(t.isSchema(r))return{...r,meta:R(r,c),source:{hash:j(`json-schema`,r.schema),variant:`json-schema`,schema:r.schema}};let l,u=c,f=P(r),p=j(f,r);if(f===`file-reference`){let e=(0,s.extractFileReference)(r);if(!e)throw Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(r)}". 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 c=(0,a.findFileExtensionSafe)(e.file);if(c&&!o.VALID_OBJECT_SOURCE_EXTENSIONS.includes(c))throw Error(`The provided schema file input "${e.file}" has an invalid file extension (.${c}). Please ensure that the file has one of the following extensions: ${(0,i.list)(o.VALID_OBJECT_SOURCE_EXTENSIONS,{conjunction:`or`})}.`);let f=await(0,d.loadSafe)(r,n);f??=await L(r,n);let{input:p,meta:m}=_(f);u?m&&(u={...m,...u}):u=m,l=t.isSchemaWithSource(p)?p.source:t.isSchema(p)?{hash:j(`json-schema`,p.schema),variant:`json-schema`,schema:p.schema}:I(N(p),p)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(f))l=I(f,r);else throw Error(`Invalid schema definition input "${f}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);let m={variant:f,source:l,schema:await F(l.schema,l.variant),hash:p,meta:{}};return m.meta=R(m,u),m}async function B(e,n={}){let r=_(e),i=r.input;if(t.isSchemaWithSource(i)||t.isSchemaOf(i))return{...i,meta:R(i,r.meta)};let a=await z(e,n);if(a.meta=R(a,r.meta),!a?.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 a}exports.bundleReferences=T,exports.extract=B,exports.extractHash=j,exports.extractJsonSchema=M,exports.extractResolvedVariant=N,exports.extractSchema=F,exports.extractSchemaMeta=R,exports.extractSchemaWithSource=z,exports.extractSource=I,exports.extractTSType=L,exports.extractVariant=P;
@@ -1,143 +0,0 @@
1
- import { ExtractedSchema, InferExtractOptions, JsonSchema, SchemaInput, SchemaInputVariant, SchemaMeta, SchemaMetaInput, SchemaOf, SchemaSource, SchemaSourceInput, SchemaSourceVariant } from "./types.cjs";
2
- import { InferLoadOptions } from "@stryke/resolve/types";
3
- import { FileReferenceInput } from "@stryke/types";
4
-
5
- //#region src/extract.d.ts
6
- /**
7
- * Bundles all external references in a JSON Schema into a single schema document by collecting all reference targets and rewriting the references to point to the bundled definitions. This ensures that the resulting schema is self-contained and can be used independently without relying on external documents.
8
- *
9
- * @param schema - The JSON Schema to bundle references for.
10
- * @returns A new JSON Schema with all references bundled and rewritten to point to the bundled definitions.
11
- */
12
- declare function bundleReferences(schema: JsonSchema): JsonSchema;
13
- /**
14
- * Creates a hash string for a given schema definition input.
15
- */
16
- declare function extractHash(variant: SchemaInputVariant, input: SchemaInput): string;
17
- /**
18
- * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
19
- *
20
- * @param schema - The schema input to extract a JSON Schema from.
21
- * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.
22
- */
23
- declare function extractJsonSchema(schema: unknown): JsonSchema | undefined;
24
- /**
25
- * Resolves the concrete source variant for a schema source input.
26
- *
27
- * @param input - The schema source input to inspect.
28
- * @returns The resolved schema source variant.
29
- * @throws Will throw an error when the input cannot be mapped to a supported source variant.
30
- */
31
- declare function extractResolvedVariant(input: SchemaSourceInput): SchemaSourceVariant;
32
- /**
33
- * Determines the top-level input variant for schema extraction.
34
- *
35
- * @param input - The schema input to classify.
36
- * @returns The resolved schema input variant.
37
- */
38
- declare function extractVariant(input: SchemaInput): SchemaInputVariant;
39
- /**
40
- * Extracts and normalizes a JSON Schema from a concrete schema source input.
41
- *
42
- * @param input - The schema source input to extract from.
43
- * @param variant - Optional source variant override. When omitted, the variant is inferred from the input.
44
- * @returns A promise that resolves to a bundled JSON Schema.
45
- * @throws Will throw an error if no valid JSON Schema can be extracted from the input.
46
- */
47
- declare function extractSchema(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JsonSchema>;
48
- /**
49
- * Builds source metadata for a schema input using a known source variant.
50
- *
51
- * @param variant - The schema source variant associated with the input.
52
- * @param input - The schema source input to wrap.
53
- * @returns The normalized schema source payload, including the source hash and variant.
54
- * @throws Will throw an error if the provided variant is unsupported.
55
- */
56
- declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
57
- /**
58
- * Resolves a type definition to a JSON Schema. This function passes the provided file reference to ts-json-schema-generator, using the referenced export name as the target type when one is provided.
59
- *
60
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
61
- * @param options - Optional overrides reserved for API compatibility.
62
- * @returns A promise that resolves to the generated JSON Schema.
63
- */
64
- declare function extractTSType(input: FileReferenceInput, options?: InferLoadOptions<typeof input>): Promise<JsonSchema>;
65
- /**
66
- * Extracts and normalizes {@link SchemaMeta | schema metadata} from a given {@link SchemaMetaInput}. This function ensures that the metadata is in a consistent format, converting version numbers to strings and filtering out any invalid or empty tags.
67
- *
68
- * @param schema - The schema from which to extract metadata.
69
- * @param input - The schema metadata input to extract and normalize.
70
- * @returns The normalized schema metadata.
71
- */
72
- declare function extractSchemaMeta<TSpec = any>(schema: SchemaOf<TSpec>, input?: SchemaMetaInput<TSpec>): SchemaMeta<TSpec>;
73
- /**
74
- * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a {@link FileReferenceInput} to an exported TypeScript type definition or any of the previous options. If the input is a {@link FileReferenceInput} (e.g. a file path with an export), the source code will be bundled with [esbuild](esbuild.github.io) using [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator) to obtain the actual schema definition before extraction.
75
- *
76
- * @example
77
- * ```ts
78
- * Resolve a schema definition from a JSON schema file
79
- * const schema1 = await extract(context, "./schemas/my-json-schema.json");
80
- * // Resolve a schema definition from a TypeScript module export
81
- * const schema2 = await extract(context, "./schemas.ts#MySchema");
82
- * // Resolve a schema definition from a JSON Schema object
83
- * const schema3 = await extract(context, schemaObject);
84
- * // Resolve a schema definition from a Zod schema
85
- * const schema4 = await extract(context, zodSchema);
86
- * // Resolve a schema definition from a Valibot schema
87
- * const schema5 = await extract(context, valibotSchema);
88
- * // Resolve a schema definition from an untyped schema
89
- * const schema6 = await extract(context, untypedSchema);
90
- * ```
91
- *
92
- * @see https://zod.dev/
93
- * @see https://valibot.dev/
94
- * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec
95
- * @see https://json-schema.org/
96
- * @see https://ajv.js.org/json-type-definition.html
97
- * @see https://github.com/vega/ts-json-schema-generator
98
- * @see https://github.com/unjs/untyped
99
- * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
100
- *
101
- * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a {@link FileReferenceInput} to an exported TypeScript type definition or any of the previous options.
102
- * @param options - Optional overrides for the configuration used during extraction.
103
- * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.
104
- * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.
105
- */
106
- declare function extractSchemaWithSource<TSpec = any>(input: SchemaInput, options?: InferExtractOptions<typeof input>): Promise<ExtractedSchema<TSpec>>;
107
- /**
108
- * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a {@link FileReferenceInput} to an exported TypeScript type definition or any of the previous options. If the input is a {@link FileReferenceInput} (e.g. a file path with an export), the source code will be bundled with [esbuild](esbuild.github.io) using [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator) to obtain the actual schema definition before extraction.
109
- *
110
- * @example
111
- * ```ts
112
- * Resolve a schema definition from a JSON schema file
113
- * const schema1 = await extract(context, "./schemas/my-json-schema.json");
114
- * // Resolve a schema definition from a TypeScript module export
115
- * const schema2 = await extract(context, "./schemas.ts#MySchema");
116
- * // Resolve a schema definition from a JSON Schema object
117
- * const schema3 = await extract(context, schemaObject);
118
- * // Resolve a schema definition from a Zod schema
119
- * const schema4 = await extract(context, zodSchema);
120
- * // Resolve a schema definition from a Valibot schema
121
- * const schema5 = await extract(context, valibotSchema);
122
- * // Resolve a schema definition from an untyped schema
123
- * const schema6 = await extract(context, untypedSchema);
124
- * ```
125
- *
126
- * @see https://zod.dev/
127
- * @see https://valibot.dev/
128
- * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec
129
- * @see https://json-schema.org/
130
- * @see https://ajv.js.org/json-type-definition.html
131
- * @see https://github.com/vega/ts-json-schema-generator
132
- * @see https://github.com/unjs/untyped
133
- * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
134
- *
135
- * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a {@link FileReferenceInput} to an exported TypeScript type definition or any of the previous options.
136
- * @param options - Optional overrides for the configuration used during extraction.
137
- * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.
138
- * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.
139
- */
140
- declare function extract<TSpec = any>(input: SchemaInput<TSpec>, options?: InferExtractOptions<typeof input>): Promise<SchemaOf<TSpec>>;
141
- //#endregion
142
- export { bundleReferences, extract, extractHash, extractJsonSchema, extractResolvedVariant, extractSchema, extractSchemaMeta, extractSchemaWithSource, extractSource, extractTSType, extractVariant };
143
- //# sourceMappingURL=extract.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;AAwRA;;;;iBAAgB,gBAAA,CAAiB,MAAA,EAAQ,UAAA,GAAa,UAAU;;;;iBAgMhD,WAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAW;AAFpB;;;;;;AAAA,iBAkDgB,iBAAA,CAAkB,MAAA,YAAkB,UAAU;;;AAhD1C;AAgDpB;;;;iBAoCgB,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;AAFtB;;;;;;AAAA,iBA4BgB,cAAA,CAAe,KAAA,EAAO,WAAA,GAAc,kBAAkB;;AA1BhD;AA0BtB;;;;;;iBAsBsB,aAAA,CACpB,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,UAAA;;AAzB2D;AAsBtE;;;;;;iBAsCgB,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;;;;;;;;iBA6CmB,aAAA,CACpB,KAAA,EAAO,kBAAA,EACP,OAAA,GAAS,gBAAA,QAAwB,KAAA,IAChC,OAAA,CAAQ,UAAA;;AAtFU;AAmCrB;;;;;iBAuFgB,iBAAA,cACd,MAAA,EAAQ,QAAA,CAAS,KAAA,GACjB,KAAA,GAAQ,eAAA,CAAgB,KAAA,IACvB,UAAA,CAAW,KAAA;;;;;;;;;AAvFC;AA6Cf;;;;;;;;;;;;;;;;;;AAGqB;AAoCrB;;;;;iBAsEsB,uBAAA,cACpB,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,mBAAA,QAA2B,KAAA,IACnC,OAAA,CAAQ,eAAA,CAAgB,KAAA;;;;;;;;;;;;;;;;AAtER;AAmEnB;;;;;;;;;;;;;;;;;iBA2JsB,OAAA,cACpB,KAAA,EAAO,WAAA,CAAY,KAAA,GACnB,OAAA,GAAS,mBAAA,QAA2B,KAAA,IACnC,OAAA,CAAQ,QAAA,CAAS,KAAA"}
@@ -1,143 +0,0 @@
1
- import { ExtractedSchema, InferExtractOptions, JsonSchema, SchemaInput, SchemaInputVariant, SchemaMeta, SchemaMetaInput, SchemaOf, SchemaSource, SchemaSourceInput, SchemaSourceVariant } from "./types.mjs";
2
- import { InferLoadOptions } from "@stryke/resolve/types";
3
- import { FileReferenceInput } from "@stryke/types";
4
-
5
- //#region src/extract.d.ts
6
- /**
7
- * Bundles all external references in a JSON Schema into a single schema document by collecting all reference targets and rewriting the references to point to the bundled definitions. This ensures that the resulting schema is self-contained and can be used independently without relying on external documents.
8
- *
9
- * @param schema - The JSON Schema to bundle references for.
10
- * @returns A new JSON Schema with all references bundled and rewritten to point to the bundled definitions.
11
- */
12
- declare function bundleReferences(schema: JsonSchema): JsonSchema;
13
- /**
14
- * Creates a hash string for a given schema definition input.
15
- */
16
- declare function extractHash(variant: SchemaInputVariant, input: SchemaInput): string;
17
- /**
18
- * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
19
- *
20
- * @param schema - The schema input to extract a JSON Schema from.
21
- * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.
22
- */
23
- declare function extractJsonSchema(schema: unknown): JsonSchema | undefined;
24
- /**
25
- * Resolves the concrete source variant for a schema source input.
26
- *
27
- * @param input - The schema source input to inspect.
28
- * @returns The resolved schema source variant.
29
- * @throws Will throw an error when the input cannot be mapped to a supported source variant.
30
- */
31
- declare function extractResolvedVariant(input: SchemaSourceInput): SchemaSourceVariant;
32
- /**
33
- * Determines the top-level input variant for schema extraction.
34
- *
35
- * @param input - The schema input to classify.
36
- * @returns The resolved schema input variant.
37
- */
38
- declare function extractVariant(input: SchemaInput): SchemaInputVariant;
39
- /**
40
- * Extracts and normalizes a JSON Schema from a concrete schema source input.
41
- *
42
- * @param input - The schema source input to extract from.
43
- * @param variant - Optional source variant override. When omitted, the variant is inferred from the input.
44
- * @returns A promise that resolves to a bundled JSON Schema.
45
- * @throws Will throw an error if no valid JSON Schema can be extracted from the input.
46
- */
47
- declare function extractSchema(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JsonSchema>;
48
- /**
49
- * Builds source metadata for a schema input using a known source variant.
50
- *
51
- * @param variant - The schema source variant associated with the input.
52
- * @param input - The schema source input to wrap.
53
- * @returns The normalized schema source payload, including the source hash and variant.
54
- * @throws Will throw an error if the provided variant is unsupported.
55
- */
56
- declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
57
- /**
58
- * Resolves a type definition to a JSON Schema. This function passes the provided file reference to ts-json-schema-generator, using the referenced export name as the target type when one is provided.
59
- *
60
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
61
- * @param options - Optional overrides reserved for API compatibility.
62
- * @returns A promise that resolves to the generated JSON Schema.
63
- */
64
- declare function extractTSType(input: FileReferenceInput, options?: InferLoadOptions<typeof input>): Promise<JsonSchema>;
65
- /**
66
- * Extracts and normalizes {@link SchemaMeta | schema metadata} from a given {@link SchemaMetaInput}. This function ensures that the metadata is in a consistent format, converting version numbers to strings and filtering out any invalid or empty tags.
67
- *
68
- * @param schema - The schema from which to extract metadata.
69
- * @param input - The schema metadata input to extract and normalize.
70
- * @returns The normalized schema metadata.
71
- */
72
- declare function extractSchemaMeta<TSpec = any>(schema: SchemaOf<TSpec>, input?: SchemaMetaInput<TSpec>): SchemaMeta<TSpec>;
73
- /**
74
- * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a {@link FileReferenceInput} to an exported TypeScript type definition or any of the previous options. If the input is a {@link FileReferenceInput} (e.g. a file path with an export), the source code will be bundled with [esbuild](esbuild.github.io) using [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator) to obtain the actual schema definition before extraction.
75
- *
76
- * @example
77
- * ```ts
78
- * Resolve a schema definition from a JSON schema file
79
- * const schema1 = await extract(context, "./schemas/my-json-schema.json");
80
- * // Resolve a schema definition from a TypeScript module export
81
- * const schema2 = await extract(context, "./schemas.ts#MySchema");
82
- * // Resolve a schema definition from a JSON Schema object
83
- * const schema3 = await extract(context, schemaObject);
84
- * // Resolve a schema definition from a Zod schema
85
- * const schema4 = await extract(context, zodSchema);
86
- * // Resolve a schema definition from a Valibot schema
87
- * const schema5 = await extract(context, valibotSchema);
88
- * // Resolve a schema definition from an untyped schema
89
- * const schema6 = await extract(context, untypedSchema);
90
- * ```
91
- *
92
- * @see https://zod.dev/
93
- * @see https://valibot.dev/
94
- * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec
95
- * @see https://json-schema.org/
96
- * @see https://ajv.js.org/json-type-definition.html
97
- * @see https://github.com/vega/ts-json-schema-generator
98
- * @see https://github.com/unjs/untyped
99
- * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
100
- *
101
- * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a {@link FileReferenceInput} to an exported TypeScript type definition or any of the previous options.
102
- * @param options - Optional overrides for the configuration used during extraction.
103
- * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.
104
- * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.
105
- */
106
- declare function extractSchemaWithSource<TSpec = any>(input: SchemaInput, options?: InferExtractOptions<typeof input>): Promise<ExtractedSchema<TSpec>>;
107
- /**
108
- * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a {@link FileReferenceInput} to an exported TypeScript type definition or any of the previous options. If the input is a {@link FileReferenceInput} (e.g. a file path with an export), the source code will be bundled with [esbuild](esbuild.github.io) using [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator) to obtain the actual schema definition before extraction.
109
- *
110
- * @example
111
- * ```ts
112
- * Resolve a schema definition from a JSON schema file
113
- * const schema1 = await extract(context, "./schemas/my-json-schema.json");
114
- * // Resolve a schema definition from a TypeScript module export
115
- * const schema2 = await extract(context, "./schemas.ts#MySchema");
116
- * // Resolve a schema definition from a JSON Schema object
117
- * const schema3 = await extract(context, schemaObject);
118
- * // Resolve a schema definition from a Zod schema
119
- * const schema4 = await extract(context, zodSchema);
120
- * // Resolve a schema definition from a Valibot schema
121
- * const schema5 = await extract(context, valibotSchema);
122
- * // Resolve a schema definition from an untyped schema
123
- * const schema6 = await extract(context, untypedSchema);
124
- * ```
125
- *
126
- * @see https://zod.dev/
127
- * @see https://valibot.dev/
128
- * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec
129
- * @see https://json-schema.org/
130
- * @see https://ajv.js.org/json-type-definition.html
131
- * @see https://github.com/vega/ts-json-schema-generator
132
- * @see https://github.com/unjs/untyped
133
- * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
134
- *
135
- * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a {@link FileReferenceInput} to an exported TypeScript type definition or any of the previous options.
136
- * @param options - Optional overrides for the configuration used during extraction.
137
- * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.
138
- * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.
139
- */
140
- declare function extract<TSpec = any>(input: SchemaInput<TSpec>, options?: InferExtractOptions<typeof input>): Promise<SchemaOf<TSpec>>;
141
- //#endregion
142
- export { bundleReferences, extract, extractHash, extractJsonSchema, extractResolvedVariant, extractSchema, extractSchemaMeta, extractSchemaWithSource, extractSource, extractTSType, extractVariant };
143
- //# sourceMappingURL=extract.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":""}
package/dist/extract.mjs DELETED
@@ -1,2 +0,0 @@
1
- import{isFileReference as e,isJsonSchema as t,isJsonSchemaObject as n,isSchema as r,isSchemaOf as i,isSchemaWithSource as a,isUntypedInput as o,isUntypedInputStrict as s,isUntypedSchema as c,isUntypedSchemaStrict as l,isValibotSchema as u}from"./type-checks.mjs";import{a as d,c as f,d as p,l as ee,o as m,s as h,u as g}from"./metadata-DIEpQjbq.mjs";import{isSetString as _}from"@stryke/type-checks";import{isSetObject as v}from"@stryke/type-checks/is-set-object";import{list as y}from"@stryke/string-format/list";import{findFileExtensionSafe as b}from"@stryke/path/find";import{VALID_OBJECT_SOURCE_EXTENSIONS as x}from"@stryke/resolve/constants";import{extractFileReference as S}from"@stryke/convert/extract-file-reference";import{murmurhash as C}from"@stryke/hash";import{deepClone as w}from"@stryke/helpers/deep-clone";import{isStandardJsonSchema as T}from"@stryke/json";import{loadSafe as te}from"@stryke/resolve/load";import{extractJsonSchema as ne,isZod3Type as E}from"@stryke/zod";import{toJsonSchema as D}from"@valibot/to-json-schema";import{createGenerator as O}from"ts-json-schema-generator/dist/factory/generator.js";const k=`https://power-plant.invalid/`;function A(e){return!v(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e?!1:Object.keys(e).every(e=>e===`schema`||e===`meta`)}function j(e){return A(e)?{input:e.schema,meta:_(e.meta)?{description:e.meta}:e.meta}:{input:e}}function M(e){return e.endsWith(`#`)?e.slice(0,-1):e}function N(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function P(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function F(e){return e.length===0?``:`/${e.map(e=>P(e)).join(`/`)}`}function I(e,t){try{return M(new URL(e,t).toString())}catch{return M(e)}}function L(e,t,n,r,i){if(!v(e))return;let a=e,o=F(t),s=_(a.$id)?I(a.$id,n):n,c=N(s);if(r.set(s,o),r.set(c,o),_(a.$anchor)&&r.set(`${c}#${a.$anchor}`,o),_(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)=>{L(n,[...t,e,String(a)],s,r,i)});continue}L(n,[...t,e],s,r,i)}}function R(e,t,n,r,i){if(!v(e))return;let a=e,o=_(a.$id)?I(a.$id,n):n;if(_(a.$ref)){let e=I(a.$ref,o),t=r.get(e)??r.get(N(e));t!==void 0&&(a.$ref=t.length>0?`#${t}`:`#`)}if(_(a.$dynamicRef)){let e=I(a.$dynamicRef,o),t=i.get(e);if(t)a.$dynamicRef=t;else{let t=r.get(e)??r.get(N(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)=>{R(n,[...t,e,String(a)],o,r,i)});continue}R(n,[...t,e],o,r,i)}}function z(e){if(!v(e))return e;let t=w(e),n=_(t.$id)?I(t.$id,k):k,r=new Map,i=new Map;return L(t,[],n,r,i),R(t,[],n,r,i),t}function B(e){if(c(e))return U(e);if(v(e)){if(o(e))return W(e);let t=e;if(`$schema`in t&&c(t.$schema))return U(t.$schema)}return e}function V(e){return Array.isArray(e)?e.map(e=>B(e)):e}function H(e){return D(e,{target:`draft-2020-12`})}function U(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`&&_(r)){n.$id=r;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!v(r)){n[e]=r;continue}n[e]=Object.fromEntries(Object.entries(r).map(([e,t])=>[e,B(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=B(r);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=V(r);continue}n[e]=r}return n}function W(e){let t=e,r=c(t.$schema)?U(t.$schema):{},i={};for(let[e,n]of Object.entries(t)){if(e.startsWith(`$`)||!v(n))continue;if(o(n)){i[e]=W(n);continue}let t=n;if(`$schema`in t&&c(t.$schema)){i[e]=U(t.$schema);continue}c(n)&&(i[e]=U(n))}if(!n(r))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let a={...v(r.properties)?r.properties:{},...i};return{...r,type:r.type??`object`,...Object.keys(a).length>0?{properties:a}:{}}}function G(e,n){let{input:i}=j(n);if(a(i)||r(i))return C({variant:e,input:i.schema});if(_(i)||typeof i==`boolean`)return C({variant:e,input:i});if(v(i)){if(E(i))return C({variant:e,input:i._def});if(T(i))return C({variant:e,input:i[`~standard`]});if(t(i))return C({variant:e,input:i});if(u(i))return C({variant:e,input:H(i)});if(o(i))return C({variant:e,input:W(i)});if(c(i))return C({variant:e,input:U(i)})}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 K(e){if(v(e)){if(E(e))return ne(e,{target:`draft-2020-12`});if(s(e))return W(e);if(l(e))return U(e);if(T(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(u(e))return H(e);if(t(e))return e}}function q(e){if(v(e)){if(E(e))return`zod3`;if(s(e)||l(e))return`untyped`;if(T(e))return`standard-schema`;if(t(e))return`json-schema`;if(u(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 J(t){let{input:n}=j(t);return a(n)||r(n)?n.variant:_(n)||e(n)?`file-reference`:q(n)}async function Y(e,t){if(a(e))return e.schema;let n=t??q(e),r;if((n===`zod3`||n===`json-schema`||n===`standard-schema`||n===`untyped`||n===`valibot`)&&(r=K(e)),r)return z(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 X(e,t){if(e===`zod3`)return{hash:G(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:G(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:G(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:G(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:G(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 Z(e,t={}){let n=S(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 O({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}`)}}function Q(e,t){let n=e.schema,r=e.meta??{};return r.name=g(n,r,t?.name),r.version=p(n,r,t?.version),r.id=f(n,r),r.displayName=m(n,r,t?.displayName),r.description=d(`A schema that describes the shape of the {displayName} specification.`,e.schema,r,t?.description),r.examples=h(e.schema,r,t?.examples),r.links=ee(e.schema,r,t?.links),t?.deprecated&&(r.deprecated=t?.deprecated),t?.usage&&(r.usage=t?.usage),t?.tags&&(r.tags=t?.tags),r}async function $(e,t={}){let{input:n,meta:i}=j(e);if(a(n))return{...n,meta:Q(n,i)};if(r(n))return{...n,meta:Q(n,i),source:{hash:G(`json-schema`,n.schema),variant:`json-schema`,schema:n.schema}};let o,s=i,c=J(n),l=G(c,n);if(c===`file-reference`){let e=S(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=b(e.file);if(i&&!x.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: ${y(x,{conjunction:`or`})}.`);let c=await te(n,t);c??=await Z(n,t);let{input:l,meta:u}=j(c);s?u&&(s={...u,...s}):s=u,o=a(l)?l.source:r(l)?{hash:G(`json-schema`,l.schema),variant:`json-schema`,schema:l.schema}:X(q(l),l)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(c))o=X(c,n);else throw Error(`Invalid schema definition input "${c}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);let u={variant:c,source:o,schema:await Y(o.schema,o.variant),hash:l,meta:{}};return u.meta=Q(u,s),u}async function re(e,t={}){let n=j(e),r=n.input;if(a(r)||i(r))return{...r,meta:Q(r,n.meta)};let o=await $(e,t);if(o.meta=Q(o,n.meta),!o?.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 o}export{z as bundleReferences,re as extract,G as extractHash,K as extractJsonSchema,q as extractResolvedVariant,Y as extractSchema,Q as extractSchemaMeta,$ as extractSchemaWithSource,X as extractSource,Z as extractTSType,J as extractVariant};
2
- //# sourceMappingURL=extract.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract.mjs","names":[],"sources":[],"mappings":""}
package/dist/helpers.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./metadata-CsY3HrP2.cjs");exports.addProperty=e.g,exports.getJsonSchema=e._,exports.getJsonSchemaObject=e.v,exports.getProperties=e.y,exports.getPropertiesList=e.b,exports.getProperty=e.x,exports.isPropertyOptional=e.S,exports.isSchemaNullable=e.C,exports.isValidSchemaInputFile=e.w,exports.merge=e.T,exports.mergeMetadata=e.E;