@power-plant/schema 0.0.2 → 0.0.4

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 (63) hide show
  1. package/README.md +221 -1
  2. package/dist/codegen.cjs +3 -3
  3. package/dist/codegen.mjs +2 -2
  4. package/dist/{constants-Cx9_Shfk.d.cts → constants-lihlIQu7.d.cts} +3 -4
  5. package/dist/constants-lihlIQu7.d.cts.map +1 -0
  6. package/dist/{constants-Cx9_Shfk.d.mts → constants-lihlIQu7.d.mts} +3 -4
  7. package/dist/constants-lihlIQu7.d.mts.map +1 -0
  8. package/dist/constants.cjs +1 -1
  9. package/dist/constants.d.cts +2 -2
  10. package/dist/constants.d.mts +2 -2
  11. package/dist/constants.mjs +1 -1
  12. package/dist/extract.cjs +1 -1
  13. package/dist/extract.d.cts +14 -9
  14. package/dist/extract.d.cts.map +1 -1
  15. package/dist/extract.d.mts +14 -9
  16. package/dist/extract.mjs +2 -1
  17. package/dist/extract.mjs.map +1 -0
  18. package/dist/helpers.cjs +1 -1
  19. package/dist/helpers.d.cts +21 -10
  20. package/dist/helpers.d.cts.map +1 -1
  21. package/dist/helpers.d.mts +21 -10
  22. package/dist/helpers.mjs +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.d.cts +6 -9
  25. package/dist/index.d.cts.map +1 -1
  26. package/dist/index.d.mts +6 -9
  27. package/dist/index.mjs +1 -1
  28. package/dist/metadata.cjs +1 -1
  29. package/dist/metadata.mjs +1 -1
  30. package/dist/type-checks.cjs +1 -1
  31. package/dist/type-checks.d.cts +13 -6
  32. package/dist/type-checks.d.cts.map +1 -1
  33. package/dist/type-checks.d.mts +13 -6
  34. package/dist/type-checks.mjs +1 -1
  35. package/dist/types.d.cts +63 -47
  36. package/dist/types.d.cts.map +1 -1
  37. package/dist/types.d.mts +63 -47
  38. package/package.json +19 -64
  39. package/dist/bundle.cjs +0 -1
  40. package/dist/bundle.d.cts +0 -18
  41. package/dist/bundle.d.cts.map +0 -1
  42. package/dist/bundle.d.mts +0 -18
  43. package/dist/bundle.d.mts.map +0 -1
  44. package/dist/bundle.mjs +0 -2
  45. package/dist/bundle.mjs.map +0 -1
  46. package/dist/constants-Cx9_Shfk.d.cts.map +0 -1
  47. package/dist/constants-Cx9_Shfk.d.mts.map +0 -1
  48. package/dist/persistence-B9pzElsC.mjs +0 -2
  49. package/dist/persistence-B9pzElsC.mjs.map +0 -1
  50. package/dist/persistence-CLni2zCP.cjs +0 -1
  51. package/dist/persistence.cjs +0 -1
  52. package/dist/persistence.d.cts +0 -58
  53. package/dist/persistence.d.cts.map +0 -1
  54. package/dist/persistence.d.mts +0 -58
  55. package/dist/persistence.d.mts.map +0 -1
  56. package/dist/persistence.mjs +0 -1
  57. package/dist/resolve.cjs +0 -1
  58. package/dist/resolve.d.cts +0 -45
  59. package/dist/resolve.d.cts.map +0 -1
  60. package/dist/resolve.d.mts +0 -45
  61. package/dist/resolve.d.mts.map +0 -1
  62. package/dist/resolve.mjs +0 -2
  63. package/dist/resolve.mjs.map +0 -1
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@power-plant/schema",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
- "description": "A package containing a Power Plant package to help managing schemas.",
5
+ "description": "A Power Plant utility package to help managing schemas.",
6
6
  "keywords": [
7
7
  "zod",
8
8
  "valibot",
@@ -21,7 +21,7 @@
21
21
  "repository": {
22
22
  "type": "github",
23
23
  "url": "https://github.com/storm-software/power-plant.git",
24
- "directory": "packages/schema"
24
+ "directory": "packages/base/schema"
25
25
  },
26
26
  "funding": {
27
27
  "type": "github",
@@ -63,20 +63,6 @@
63
63
  "default": "./dist/index.mjs"
64
64
  }
65
65
  },
66
- "./bundle": {
67
- "require": {
68
- "types": "./dist/bundle.d.cts",
69
- "default": "./dist/bundle.cjs"
70
- },
71
- "import": {
72
- "types": "./dist/bundle.d.mts",
73
- "default": "./dist/bundle.mjs"
74
- },
75
- "default": {
76
- "types": "./dist/bundle.d.mts",
77
- "default": "./dist/bundle.mjs"
78
- }
79
- },
80
66
  "./codegen": {
81
67
  "require": {
82
68
  "types": "./dist/codegen.d.cts",
@@ -148,34 +134,6 @@
148
134
  }
149
135
  },
150
136
  "./package.json": "./package.json",
151
- "./persistence": {
152
- "require": {
153
- "types": "./dist/persistence.d.cts",
154
- "default": "./dist/persistence.cjs"
155
- },
156
- "import": {
157
- "types": "./dist/persistence.d.mts",
158
- "default": "./dist/persistence.mjs"
159
- },
160
- "default": {
161
- "types": "./dist/persistence.d.mts",
162
- "default": "./dist/persistence.mjs"
163
- }
164
- },
165
- "./resolve": {
166
- "require": {
167
- "types": "./dist/resolve.d.cts",
168
- "default": "./dist/resolve.cjs"
169
- },
170
- "import": {
171
- "types": "./dist/resolve.d.mts",
172
- "default": "./dist/resolve.mjs"
173
- },
174
- "default": {
175
- "types": "./dist/resolve.d.mts",
176
- "default": "./dist/resolve.mjs"
177
- }
178
- },
179
137
  "./type-checks": {
180
138
  "require": {
181
139
  "types": "./dist/type-checks.d.cts",
@@ -211,33 +169,30 @@
211
169
  "typings": "dist/index.d.mts",
212
170
  "files": ["dist"],
213
171
  "dependencies": {
214
- "@msgpack/msgpack": "^3.1.3",
215
172
  "@standard-schema/spec": "^1.1.0",
216
- "@stryke/convert": "^0.7.16",
217
- "@stryke/env": "^0.20.103",
218
- "@stryke/hash": "^0.13.39",
219
- "@stryke/helpers": "^0.10.25",
220
- "@stryke/json": "^0.15.9",
221
- "@stryke/path": "^0.29.12",
222
- "@stryke/string-format": "^0.17.27",
223
- "@stryke/type-checks": "^0.6.18",
224
- "@stryke/types": "^0.12.13",
225
- "@stryke/url": "^0.4.36",
226
- "@stryke/zod": "^0.3.31",
173
+ "@stryke/convert": "^0.7.24",
174
+ "@stryke/date": "^0.0.5",
175
+ "@stryke/hash": "^0.13.47",
176
+ "@stryke/helpers": "^0.10.33",
177
+ "@stryke/json": "^0.15.17",
178
+ "@stryke/path": "^0.29.20",
179
+ "@stryke/resolve": "^0.0.9",
180
+ "@stryke/string-format": "^0.17.35",
181
+ "@stryke/type-checks": "^0.6.26",
182
+ "@stryke/types": "^0.12.21",
183
+ "@stryke/unique-id": "^0.3.105",
184
+ "@stryke/url": "^0.4.44",
185
+ "@stryke/zod": "^0.3.39",
227
186
  "@valibot/to-json-schema": "^1.7.1",
228
187
  "defu": "^6.1.7",
229
- "esbuild": "^0.27.7",
230
- "jiti": "^2.7.0",
231
- "smol-toml": "^1.7.0",
232
188
  "ts-json-schema-generator": "^2.9.0",
233
189
  "typescript": "^6.0.3",
234
- "untyped": "^1.5.2",
235
- "yaml": "^2.9.0"
190
+ "untyped": "^1.5.2"
236
191
  },
237
192
  "devDependencies": {
238
193
  "@powerlines/plugin-tsdown": "^0.1.540",
239
194
  "@types/node": "^25.9.4",
240
- "powerlines": "^0.47.139",
195
+ "powerlines": "0.47.139",
241
196
  "valibot": "^1.4.1",
242
197
  "zod": "^4.4.3"
243
198
  },
@@ -250,5 +205,5 @@
250
205
  "zod": { "optional": true }
251
206
  },
252
207
  "publishConfig": { "access": "public" },
253
- "gitHead": "fed188fe5551ef432c38014dcc714161e4cb812d"
208
+ "gitHead": "4f510175050312992ba4fa174eafdc56edd1f69b"
254
209
  }
package/dist/bundle.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@stryke/helpers/omit"),t=require("esbuild"),n=require("node:fs");async function r(r,i={}){if(!r||!(0,n.existsSync)(r))throw Error(`Module not found: "${r}". Please check the path and try again.`);let a=await(0,t.build)({platform:`node`,format:`esm`,...(0,e.omit)(i,[`debug`]),logLevel:`silent`,entryPoints:[r],write:!1,sourcemap:!1,splitting:!1,treeShaking:!0,bundle:!0,packages:`bundle`,keepNames:!0,metafile:!1});if(a.errors.length>0)throw Error(`Failed to bundle ${r}: ${a.errors.map(e=>e.text).join(`, `)}`);if(!a.outputFiles||a.outputFiles.filter(Boolean).length===0)throw Error(`No output files generated for ${r}. Please check the configuration and try again.`);return a.outputFiles.filter(Boolean)[0]}exports.bundle=r;
package/dist/bundle.d.cts DELETED
@@ -1,18 +0,0 @@
1
- import { DeepPartial } from "@stryke/types/base";
2
- import { BuildOptions, OutputFile } from "esbuild";
3
-
4
- //#region src/bundle.d.ts
5
- type BundleOptions = DeepPartial<BuildOptions> & {
6
- debug?: boolean;
7
- };
8
- /**
9
- * Bundle a type definition to a module.
10
- *
11
- * @param file - The file path to bundle.
12
- * @param options - Optional overrides for the ESBuild configuration.
13
- * @returns A promise that resolves to the bundled module.
14
- */
15
- declare function bundle(file: string, options?: BundleOptions): Promise<OutputFile>;
16
- //#endregion
17
- export { BundleOptions, bundle };
18
- //# sourceMappingURL=bundle.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.d.cts","names":[],"sources":["../src/bundle.ts"],"mappings":";;;;KAwBY,aAAA,GAAgB,WAAW,CAAC,YAAA;EACtC,KAAA;AAAA;;;;;;;;iBAUoB,MAAA,CACpB,IAAA,UACA,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,UAAA"}
package/dist/bundle.d.mts DELETED
@@ -1,18 +0,0 @@
1
- import { BuildOptions, OutputFile } from "esbuild";
2
- import { DeepPartial } from "@stryke/types/base";
3
-
4
- //#region src/bundle.d.ts
5
- type BundleOptions = DeepPartial<BuildOptions> & {
6
- debug?: boolean;
7
- };
8
- /**
9
- * Bundle a type definition to a module.
10
- *
11
- * @param file - The file path to bundle.
12
- * @param options - Optional overrides for the ESBuild configuration.
13
- * @returns A promise that resolves to the bundled module.
14
- */
15
- declare function bundle(file: string, options?: BundleOptions): Promise<OutputFile>;
16
- //#endregion
17
- export { BundleOptions, bundle };
18
- //# sourceMappingURL=bundle.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.d.mts","names":[],"sources":["../src/bundle.ts"],"mappings":""}
package/dist/bundle.mjs DELETED
@@ -1,2 +0,0 @@
1
- import{omit as e}from"@stryke/helpers/omit";import{build as t}from"esbuild";import{existsSync as n}from"node:fs";async function r(r,i={}){if(!r||!n(r))throw Error(`Module not found: "${r}". Please check the path and try again.`);let a=await t({platform:`node`,format:`esm`,...e(i,[`debug`]),logLevel:`silent`,entryPoints:[r],write:!1,sourcemap:!1,splitting:!1,treeShaking:!0,bundle:!0,packages:`bundle`,keepNames:!0,metafile:!1});if(a.errors.length>0)throw Error(`Failed to bundle ${r}: ${a.errors.map(e=>e.text).join(`, `)}`);if(!a.outputFiles||a.outputFiles.filter(Boolean).length===0)throw Error(`No output files generated for ${r}. Please check the configuration and try again.`);return a.outputFiles.filter(Boolean)[0]}export{r as bundle};
2
- //# sourceMappingURL=bundle.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-Cx9_Shfk.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAoBa,4BAAA;AAAA,cAiBA,mBAAA;EAAA;;;;;;;;cAUA,2BAAA;AAAA,cAQA,iBAAA;AAAA,cAMA,yBAAA;;;;;cAoBA,sBAAA,EAAsB,GAAA;;AAlCnC;;;cA8Ca,sBAAA,EAAsB,GAAA;AAxCzB;AAEV;;;AAFU,cAyDG,4BAAA,EAA4B,GAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-Cx9_Shfk.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":""}
@@ -1,2 +0,0 @@
1
- import{VALID_SOURCE_FILE_EXTENSIONS as e}from"./constants.mjs";import{isFileReference as t,isJsonSchema as n,isJsonSchemaObject as r,isSchema 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{resolveSafe as d,resolveTSType as f}from"./resolve.mjs";import{isSetString as p}from"@stryke/type-checks";import{extractFileReference as m}from"@stryke/convert/extract-file-reference";import{findFileExtensionSafe as h}from"@stryke/path/find";import{mkdir as g,readFile as _,writeFile as v}from"node:fs/promises";import{existsSync as y}from"node:fs";import{joinPaths as b}from"@stryke/path/join";import{getEnvPaths as ee}from"@stryke/env/get-env-paths";import{murmurhash as x}from"@stryke/hash";import{deepClone as S}from"@stryke/helpers/deep-clone";import{isStandardJsonSchema as C}from"@stryke/json";import{list as te}from"@stryke/string-format/list";import{isSetObject as w}from"@stryke/type-checks/is-set-object";import{extractJsonSchema as T,isZod3Type as E}from"@stryke/zod";import{toJsonSchema as D}from"@valibot/to-json-schema";const O=`https://powerlines.invalid/`;function ne(e){return!w(e)||!(`schema`in e)||`hash`in e||`variant`in e||`source`in e?!1:Object.keys(e).every(e=>e===`schema`||e===`meta`)}function k(e){return ne(e)?{input:e.schema,meta:e.meta}:{input:e}}function A(e){return e.endsWith(`#`)?e.slice(0,-1):e}function j(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function M(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function N(e){return e.length===0?``:`/${e.map(e=>M(e)).join(`/`)}`}function P(e,t){try{return A(new URL(e,t).toString())}catch{return A(e)}}function F(e,t,n,r,i){if(!w(e))return;let a=e,o=N(t),s=p(a.$id)?P(a.$id,n):n,c=j(s);if(r.set(s,o),r.set(c,o),p(a.$anchor)&&r.set(`${c}#${a.$anchor}`,o),p(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)=>{F(n,[...t,e,String(a)],s,r,i)});continue}F(n,[...t,e],s,r,i)}}function I(e,t,n,r,i){if(!w(e))return;let a=e,o=p(a.$id)?P(a.$id,n):n;if(p(a.$ref)){let e=P(a.$ref,o),t=r.get(e)??r.get(j(e));t!==void 0&&(a.$ref=t.length>0?`#${t}`:`#`)}if(p(a.$dynamicRef)){let e=P(a.$dynamicRef,o),t=i.get(e);if(t)a.$dynamicRef=t;else{let t=r.get(e)??r.get(j(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)=>{I(n,[...t,e,String(a)],o,r,i)});continue}I(n,[...t,e],o,r,i)}}function L(e){if(!w(e))return e;let t=S(e),n=p(t.$id)?P(t.$id,O):O,r=new Map,i=new Map;return F(t,[],n,r,i),I(t,[],n,r,i),t}function R(e){if(c(e))return V(e);if(w(e)){if(o(e))return H(e);let t=e;if(`$schema`in t&&c(t.$schema))return V(t.$schema)}return e}function z(e){return Array.isArray(e)?e.map(e=>R(e)):e}function B(e){return D(e,{target:`draft-2020-12`})}function V(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`&&p(r)){n.$id=r;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!w(r)){n[e]=r;continue}n[e]=Object.fromEntries(Object.entries(r).map(([e,t])=>[e,R(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=R(r);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=z(r);continue}n[e]=r}return n}function H(e){let t=e,n=c(t.$schema)?V(t.$schema):{},i={};for(let[e,n]of Object.entries(t)){if(e.startsWith(`$`)||!w(n))continue;if(o(n)){i[e]=H(n);continue}let t=n;if(`$schema`in t&&c(t.$schema)){i[e]=V(t.$schema);continue}c(n)&&(i[e]=V(n))}if(!r(n))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let a={...w(n.properties)?n.properties:{},...i};return{...n,type:n.type??`object`,...Object.keys(a).length>0?{properties:a}:{}}}function U(e,t){let{input:r}=k(t);if(a(r)||i(r))return x({variant:e,input:r.schema});if(p(r)||typeof r==`boolean`)return x({variant:e,input:r});if(w(r)){if(E(r))return x({variant:e,input:r._def});if(C(r))return x({variant:e,input:r[`~standard`]});if(n(r))return x({variant:e,input:r});if(u(r))return x({variant:e,input:B(r)});if(o(r))return x({variant:e,input:H(r)});if(c(r))return x({variant:e,input:V(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 W(e){if(w(e)){if(E(e))return T(e,{target:`draft-2020-12`});if(s(e))return H(e);if(l(e))return V(e);if(C(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(u(e))return B(e);if(n(e))return e}}function G(e){if(w(e)){if(E(e))return`zod3`;if(s(e)||l(e))return`untyped`;if(C(e))return`standard-schema`;if(n(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 K(e){let{input:n}=k(e);return a(n)||i(n)?n.variant:p(n)||t(n)?`file-reference`:G(n)}async function q(e,t){if(a(e))return e.schema;let n=t??G(e),r;if((n===`zod3`||n===`json-schema`||n===`standard-schema`||n===`untyped`||n===`valibot`)&&(r=W(e)),r)return L(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 J(e,t){if(e===`zod3`)return{hash:U(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:U(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:U(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:U(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:U(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 Y(t,n={}){let{input:r,meta:o}=k(t);if(a(r))return o===void 0?r:{...r,meta:o};if(i(r))return{...r,...o===void 0?{}:{meta:o},source:{hash:U(`json-schema`,r.schema),variant:`json-schema`,schema:r.schema}};let s,c=K(r),l=U(c,r),u=o;if(c===`file-reference`){let t=m(r);if(!t)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 o=h(t.file);if(o&&!e.includes(o))throw Error(`The provided schema file input "${t.file}" has an invalid file extension (.${o}). Please ensure that the file has one of the following extensions: ${te(e,{conjunction:`or`})}.`);let c=await d(r,n);c??=await f(r,n);let{input:l,meta:p}=k(c);u===void 0&&p!==void 0&&(u=p),s=a(l)?l.source:i(l)?{hash:U(`json-schema`,l.schema),variant:`json-schema`,schema:l.schema}:J(G(l),l)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(c))s=J(c,r);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 p={variant:c,source:s,schema:await q(s.schema,s.variant),hash:l};return u!==void 0&&(p.meta=u),p}async function re(e,t={}){let{input:n,meta:r}=k(e);if(a(n)||i(n))return r===void 0?n:{...n,meta:r};let o,s=K(n),c=U(s,n),l=t.cachePath??ee().cache,u={cachePath:l},d=b(X(u),`${c}.json`);if(t.skipCache!==!0&&y(d)){let e=await _(d,`utf8`);if(e){let t={variant:s,hash:c,schema:JSON.parse(e)};r!==void 0&&(t.meta=r),o=t}}if(o??=await Y(e,{...t,cachePath:l}),r!==void 0&&o&&(o.meta=r),!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 t.skipCache!==!0&&await Q(u,o),o}function X(e){return b(e.cachePath,`schemas`)}function Z(e,t){let n=U(K(t),t);return b(X(e),`${n}.json`)}async function Q(e,t){if(!i(t))throw Error(`The provided input is not a valid schema. A valid schema must have a "variant" property indicating the type of the input and a "schema" property containing the parsed JSON Schema object.`);let n=X(e),r=e.fs?.mkdir??g,a=e.fs?.write??v;!y(n)&&!e.fs?.mkdir?await g(n,{recursive:!0}):e.fs?.mkdir&&await r(n,{recursive:!0}),await a(Z(e,t),JSON.stringify(t.schema))}async function $(e,t){let n=Z(e,t),r=e.fs?.exists??(async e=>Promise.resolve(y(e))),a=e.fs?.read??_;if(!await r(n))return;let o=await a(n);if(!o)return;let s=JSON.parse(typeof o==`string`?o:o.toString());if(i(s))return s}async function ie(e,t){let n=await $(e,t);if(!n){let e=K(t),n=U(e,t);throw Error(`The ${e} schema with hash "${n}" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`)}return n}export{Q as a,U as c,q as d,Y as f,$ as i,W as l,K as m,Z as n,L as o,J as p,ie as r,re as s,X as t,G as u};
2
- //# sourceMappingURL=persistence-B9pzElsC.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persistence-B9pzElsC.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +0,0 @@
1
- const e=require("./constants.cjs"),t=require("./type-checks.cjs"),n=require("./resolve.cjs");let r=require("@stryke/type-checks"),i=require("@stryke/convert/extract-file-reference"),a=require("@stryke/path/find"),o=require("node:fs/promises"),s=require("node:fs"),c=require("@stryke/path/join"),l=require("@stryke/env/get-env-paths"),u=require("@stryke/hash"),d=require("@stryke/helpers/deep-clone"),f=require("@stryke/json"),p=require("@stryke/string-format/list"),m=require("@stryke/type-checks/is-set-object"),h=require("@stryke/zod"),g=require("@valibot/to-json-schema");const _=`https://powerlines.invalid/`;function v(e){return!(0,m.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 y(e){return v(e)?{input:e.schema,meta:e.meta}:{input:e}}function b(e){return e.endsWith(`#`)?e.slice(0,-1):e}function x(e){let t=e.indexOf(`#`);return t>=0?e.slice(0,t):e}function S(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function C(e){return e.length===0?``:`/${e.map(e=>S(e)).join(`/`)}`}function w(e,t){try{return b(new URL(e,t).toString())}catch{return b(e)}}function T(e,t,n,i,a){if(!(0,m.isSetObject)(e))return;let o=e,s=C(t),c=(0,r.isSetString)(o.$id)?w(o.$id,n):n,l=x(c);if(i.set(c,s),i.set(l,s),(0,r.isSetString)(o.$anchor)&&i.set(`${l}#${o.$anchor}`,s),(0,r.isSetString)(o.$dynamicAnchor)){let e=`${l}#${o.$dynamicAnchor}`;i.set(e,s),a.set(e,`#${o.$dynamicAnchor}`)}for(let[e,n]of Object.entries(o)){if(Array.isArray(n)){n.forEach((n,r)=>{T(n,[...t,e,String(r)],c,i,a)});continue}T(n,[...t,e],c,i,a)}}function E(e,t,n,i,a){if(!(0,m.isSetObject)(e))return;let o=e,s=(0,r.isSetString)(o.$id)?w(o.$id,n):n;if((0,r.isSetString)(o.$ref)){let e=w(o.$ref,s),t=i.get(e)??i.get(x(e));t!==void 0&&(o.$ref=t.length>0?`#${t}`:`#`)}if((0,r.isSetString)(o.$dynamicRef)){let e=w(o.$dynamicRef,s),t=a.get(e);if(t)o.$dynamicRef=t;else{let t=i.get(e)??i.get(x(e));t!==void 0&&(o.$dynamicRef=t.length>0?`#${t}`:`#`)}}for(let[e,n]of Object.entries(o)){if(Array.isArray(n)){n.forEach((n,r)=>{E(n,[...t,e,String(r)],s,i,a)});continue}E(n,[...t,e],s,i,a)}}function D(e){if(!(0,m.isSetObject)(e))return e;let t=(0,d.deepClone)(e),n=(0,r.isSetString)(t.$id)?w(t.$id,_):_,i=new Map,a=new Map;return T(t,[],n,i,a),E(t,[],n,i,a),t}function O(e){if(t.isUntypedSchema(e))return j(e);if((0,m.isSetObject)(e)){if(t.isUntypedInput(e))return M(e);let n=e;if(`$schema`in n&&t.isUntypedSchema(n.$schema))return j(n.$schema)}return e}function k(e){return Array.isArray(e)?e.map(e=>O(e)):e}function A(e){return(0,g.toJsonSchema)(e,{target:`draft-2020-12`})}function j(e){let t=e,n={};for(let[e,i]of Object.entries(t))if(!(e===`tsType`||e===`markdownType`||e===`tags`||e===`args`||e===`resolve`)){if(e===`id`&&(0,r.isSetString)(i)){n.$id=i;continue}if(e===`properties`||e===`patternProperties`||e===`dependentSchemas`||e===`$defs`||e===`definitions`){if(!(0,m.isSetObject)(i)){n[e]=i;continue}n[e]=Object.fromEntries(Object.entries(i).map(([e,t])=>[e,O(t)]));continue}if(e===`items`||e===`contains`||e===`if`||e===`then`||e===`else`||e===`not`||e===`propertyNames`||e===`additionalProperties`||e===`unevaluatedProperties`){n[e]=O(i);continue}if(e===`oneOf`||e===`anyOf`||e===`allOf`){n[e]=k(i);continue}n[e]=i}return n}function M(e){let n=e,r=t.isUntypedSchema(n.$schema)?j(n.$schema):{},i={};for(let[e,r]of Object.entries(n)){if(e.startsWith(`$`)||!(0,m.isSetObject)(r))continue;if(t.isUntypedInput(r)){i[e]=M(r);continue}let n=r;if(`$schema`in n&&t.isUntypedSchema(n.$schema)){i[e]=j(n.$schema);continue}t.isUntypedSchema(r)&&(i[e]=j(r))}if(!t.isJsonSchemaObject(r))throw Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);let a={...(0,m.isSetObject)(r.properties)?r.properties:{},...i};return{...r,type:r.type??`object`,...Object.keys(a).length>0?{properties:a}:{}}}function N(e,n){let{input:i}=y(n);if(t.isSchemaWithSource(i)||t.isSchema(i))return(0,u.murmurhash)({variant:e,input:i.schema});if((0,r.isSetString)(i)||typeof i==`boolean`)return(0,u.murmurhash)({variant:e,input:i});if((0,m.isSetObject)(i)){if((0,h.isZod3Type)(i))return(0,u.murmurhash)({variant:e,input:i._def});if((0,f.isStandardJsonSchema)(i))return(0,u.murmurhash)({variant:e,input:i[`~standard`]});if(t.isJsonSchema(i))return(0,u.murmurhash)({variant:e,input:i});if(t.isValibotSchema(i))return(0,u.murmurhash)({variant:e,input:A(i)});if(t.isUntypedInput(i))return(0,u.murmurhash)({variant:e,input:M(i)});if(t.isUntypedSchema(i))return(0,u.murmurhash)({variant:e,input:j(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 P(e){if((0,m.isSetObject)(e)){if((0,h.isZod3Type)(e))return(0,h.extractJsonSchema)(e,{target:`draft-2020-12`});if(t.isUntypedInputStrict(e))return M(e);if(t.isUntypedSchemaStrict(e))return j(e);if((0,f.isStandardJsonSchema)(e))return e[`~standard`].jsonSchema.input({target:`draft-2020-12`});if(t.isValibotSchema(e))return A(e);if(t.isJsonSchema(e))return e}}function F(e){if((0,m.isSetObject)(e)){if((0,h.isZod3Type)(e))return`zod3`;if(t.isUntypedInputStrict(e)||t.isUntypedSchemaStrict(e))return`untyped`;if((0,f.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 I(e){let{input:n}=y(e);return t.isSchemaWithSource(n)||t.isSchema(n)?n.variant:(0,r.isSetString)(n)||t.isFileReference(n)?`file-reference`:F(n)}async function L(e,n){if(t.isSchemaWithSource(e))return e.schema;let r=n??F(e),i;if((r===`zod3`||r===`json-schema`||r===`standard-schema`||r===`untyped`||r===`valibot`)&&(i=P(e)),i)return D(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 R(e,t){if(e===`zod3`)return{hash:N(e,t),variant:`zod3`,schema:t};if(e===`untyped`)return{hash:N(e,t),variant:`untyped`,schema:t};if(e===`standard-schema`)return{hash:N(e,t),variant:`standard-schema`,schema:t};if(e===`json-schema`)return{hash:N(e,t),variant:`json-schema`,schema:t};if(e===`valibot`)return{hash:N(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(r,o={}){let{input:s,meta:c}=y(r);if(t.isSchemaWithSource(s))return c===void 0?s:{...s,meta:c};if(t.isSchema(s))return{...s,...c===void 0?{}:{meta:c},source:{hash:N(`json-schema`,s.schema),variant:`json-schema`,schema:s.schema}};let l,u=I(s),d=N(u,s),f=c;if(u===`file-reference`){let r=(0,i.extractFileReference)(s);if(!r)throw Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(s)}". 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)(r.file);if(c&&!e.VALID_SOURCE_FILE_EXTENSIONS.includes(c))throw Error(`The provided schema file input "${r.file}" has an invalid file extension (.${c}). Please ensure that the file has one of the following extensions: ${(0,p.list)(e.VALID_SOURCE_FILE_EXTENSIONS,{conjunction:`or`})}.`);let u=await n.resolveSafe(s,o);u??=await n.resolveTSType(s,o);let{input:d,meta:m}=y(u);f===void 0&&m!==void 0&&(f=m),l=t.isSchemaWithSource(d)?d.source:t.isSchema(d)?{hash:N(`json-schema`,d.schema),variant:`json-schema`,schema:d.schema}:R(F(d),d)}else if([`json-schema`,`standard-schema`,`zod3`,`untyped`,`valibot`,`reflection`].includes(u))l=R(u,s);else throw Error(`Invalid schema definition input "${u}". The variant must be one of "file-reference", "json-schema", "standard-schema", "zod3", "valibot", "untyped", or "reflection".`);let m={variant:u,source:l,schema:await L(l.schema,l.variant),hash:d};return f!==void 0&&(m.meta=f),m}async function B(e,n={}){let{input:r,meta:i}=y(e);if(t.isSchemaWithSource(r)||t.isSchema(r))return i===void 0?r:{...r,meta:i};let a,u=I(r),d=N(u,r),f=n.cachePath??(0,l.getEnvPaths)().cache,p={cachePath:f},m=(0,c.joinPaths)(V(p),`${d}.json`);if(n.skipCache!==!0&&(0,s.existsSync)(m)){let e=await(0,o.readFile)(m,`utf8`);if(e){let t={variant:u,hash:d,schema:JSON.parse(e)};i!==void 0&&(t.meta=i),a=t}}if(a??=await z(e,{...n,cachePath:f}),i!==void 0&&a&&(a.meta=i),!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 n.skipCache!==!0&&await U(p,a),a}function V(e){return(0,c.joinPaths)(e.cachePath,`schemas`)}function H(e,t){let n=N(I(t),t);return(0,c.joinPaths)(V(e),`${n}.json`)}async function U(e,n){if(!t.isSchema(n))throw Error(`The provided input is not a valid schema. A valid schema must have a "variant" property indicating the type of the input and a "schema" property containing the parsed JSON Schema object.`);let r=V(e),i=e.fs?.mkdir??o.mkdir,a=e.fs?.write??o.writeFile;!(0,s.existsSync)(r)&&!e.fs?.mkdir?await(0,o.mkdir)(r,{recursive:!0}):e.fs?.mkdir&&await i(r,{recursive:!0}),await a(H(e,n),JSON.stringify(n.schema))}async function W(e,n){let r=H(e,n),i=e.fs?.exists??(async e=>Promise.resolve((0,s.existsSync)(e))),a=e.fs?.read??o.readFile;if(!await i(r))return;let c=await a(r);if(!c)return;let l=JSON.parse(typeof c==`string`?c:c.toString());if(t.isSchema(l))return l}async function G(e,t){let n=await W(e,t);if(!n){let e=I(t),n=N(e,t);throw Error(`The ${e} schema with hash "${n}" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`)}return n}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return F}});
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("./type-checks.cjs");const e=require("./persistence-CLni2zCP.cjs");exports.getCacheDirectory=e.t,exports.getCacheFilePath=e.n,exports.readSchema=e.r,exports.readSchemaSafe=e.i,exports.writeSchema=e.a;
@@ -1,58 +0,0 @@
1
- import { Schema, SchemaInput } from "./types.cjs";
2
- import { Buffer } from "node:buffer";
3
-
4
- //#region src/persistence.d.ts
5
- interface PersistenceContext {
6
- cachePath: string;
7
- fs?: {
8
- exists?: (path: string) => Promise<boolean>;
9
- read?: (path: string) => Promise<string | Buffer>;
10
- write?: (path: string, data: string | Buffer) => Promise<void>;
11
- mkdir?: (path: string, options: {
12
- recursive: boolean;
13
- }) => Promise<void>;
14
- };
15
- }
16
- /**
17
- * A helper function to get the cache directory path for storing schemas. This function takes a cache path as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the provided cache path with a subdirectory named "schemas". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.
18
- *
19
- * @param context - The context object containing the cache path.
20
- * @returns The path to the cache directory for storing schemas, constructed by joining the provided cache path with the "schemas" subdirectory.
21
- */
22
- declare function getCacheDirectory(context: PersistenceContext): string;
23
- /**
24
- * A helper function to get the file path for a cached schema based on the provided context and schema input. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file by joining the cache directory path (obtained from the `getCacheDirectory` function) with a filename derived from the extracted hash. The resulting file path points to where the cached schema should be stored or retrieved from in the file system. This function is essential for ensuring that all operations related to caching schemas use a consistent method for determining the correct file path based on the schema's unique identifier (hash).
25
- *
26
- * @param context - The context object containing the cache path.
27
- * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.
28
- * @returns The file path to the cached schema JSON file, constructed by joining the cache directory path with a filename derived from the extracted hash of the schema input.
29
- */
30
- declare function getCacheFilePath(context: PersistenceContext, input: SchemaInput): string;
31
- /**
32
- * Writes a given schema to the file system using the provided context. This function first checks if the input is a valid schema using the `isSchema` type guard. If the input is not a valid schema, it throws an error indicating that the provided input is invalid. If the input is valid, it proceeds to write the schema to a JSON file in the cache directory specified by the context. The file is named using the hash of the schema to ensure uniqueness and easy retrieval in future operations. The schema is serialized to JSON format before being written to the file system. This function is asynchronous and returns a promise that resolves once the writing operation is complete.
33
- *
34
- * @param context - The context object containing the cache path and file system utilities.
35
- * @param schema - The schema to be written to the file system, which must be a valid schema object containing a `variant`, `schema`, and `hash` property.
36
- * @throws Will throw an error if the provided input is not a valid schema.
37
- */
38
- declare function writeSchema(context: PersistenceContext, schema: Schema): Promise<void>;
39
- /**
40
- * A helper function to read a schema from the file system using the provided context. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file based on the context provided and the extracted hash. The function checks if the file exists in the cache; if it does not exist, it returns `undefined`. If the file exists, it reads the contents of the file, parses it as JSON, and returns the resulting object. This function is asynchronous and returns a promise that resolves to either the parsed schema object or `undefined` if the schema is not found in the cache.
41
- *
42
- * @param context - The context object containing the cache path and file system utilities.
43
- * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
44
- * @returns A promise that resolves to the parsed schema object if found in the cache, or `undefined` if the schema does not exist in the cache.
45
- */
46
- declare function readSchemaSafe(context: PersistenceContext, input: SchemaInput): Promise<Schema | undefined>;
47
- /**
48
- * Reads a schema from the file system using the provided context and input. This function first attempts to read the schema using the `readSchemaSafe` helper function, which returns `undefined` if the schema is not found in the cache. If the schema is not found, this function throws an error indicating that the schema with the specified variant and hash does not exist in the cache. The error message suggests that this may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. It advises ensuring that the schema is properly written to the cache before attempting to read it. If the schema is successfully read from the cache, it is returned as a parsed object. This function is asynchronous and returns a promise that resolves to the parsed schema object if found, or throws an error if the schema is not found in the cache.
49
- *
50
- * @param context - The context object containing the cache path and file system utilities.
51
- * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
52
- * @returns A promise that resolves to the parsed schema object if found in the cache, or throws an error if the schema does not exist in the cache.
53
- * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.
54
- */
55
- declare function readSchema(context: PersistenceContext, input: SchemaInput): Promise<Schema>;
56
- //#endregion
57
- export { PersistenceContext, getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema };
58
- //# sourceMappingURL=persistence.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persistence.d.cts","names":[],"sources":["../src/persistence.ts"],"mappings":";;;;UA0BiB,kBAAA;EACf,SAAA;EACA,EAAA;IACE,MAAA,IAAU,IAAA,aAAiB,OAAA;IAC3B,IAAA,IAAQ,IAAA,aAAiB,OAAA,UAAiB,MAAA;IAC1C,KAAA,IAAS,IAAA,UAAc,IAAA,WAAe,MAAA,KAAW,OAAA;IACjD,KAAA,IAAS,IAAA,UAAc,OAAA;MAAW,SAAA;IAAA,MAAyB,OAAA;EAAA;AAAA;;;;;;;iBAU/C,iBAAA,CAAkB,OAA2B,EAAlB,kBAAkB;;;;;;;;iBAW7C,gBAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAW;;;;;;;;iBAeE,WAAA,CAAY,OAAA,EAAS,kBAAA,EAAoB,MAAA,EAAQ,MAAA,GAAM,OAAA;AA5B7E;;;;AAA6D;AAW7D;;AAXA,iBA0DsB,cAAA,CACpB,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA;;;;;;;AAhDS;AAepB;iBAkEsB,UAAA,CACpB,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA"}
@@ -1,58 +0,0 @@
1
- import { Schema, SchemaInput } from "./types.mjs";
2
- import { Buffer } from "node:buffer";
3
-
4
- //#region src/persistence.d.ts
5
- interface PersistenceContext {
6
- cachePath: string;
7
- fs?: {
8
- exists?: (path: string) => Promise<boolean>;
9
- read?: (path: string) => Promise<string | Buffer>;
10
- write?: (path: string, data: string | Buffer) => Promise<void>;
11
- mkdir?: (path: string, options: {
12
- recursive: boolean;
13
- }) => Promise<void>;
14
- };
15
- }
16
- /**
17
- * A helper function to get the cache directory path for storing schemas. This function takes a cache path as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the provided cache path with a subdirectory named "schemas". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.
18
- *
19
- * @param context - The context object containing the cache path.
20
- * @returns The path to the cache directory for storing schemas, constructed by joining the provided cache path with the "schemas" subdirectory.
21
- */
22
- declare function getCacheDirectory(context: PersistenceContext): string;
23
- /**
24
- * A helper function to get the file path for a cached schema based on the provided context and schema input. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file by joining the cache directory path (obtained from the `getCacheDirectory` function) with a filename derived from the extracted hash. The resulting file path points to where the cached schema should be stored or retrieved from in the file system. This function is essential for ensuring that all operations related to caching schemas use a consistent method for determining the correct file path based on the schema's unique identifier (hash).
25
- *
26
- * @param context - The context object containing the cache path.
27
- * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.
28
- * @returns The file path to the cached schema JSON file, constructed by joining the cache directory path with a filename derived from the extracted hash of the schema input.
29
- */
30
- declare function getCacheFilePath(context: PersistenceContext, input: SchemaInput): string;
31
- /**
32
- * Writes a given schema to the file system using the provided context. This function first checks if the input is a valid schema using the `isSchema` type guard. If the input is not a valid schema, it throws an error indicating that the provided input is invalid. If the input is valid, it proceeds to write the schema to a JSON file in the cache directory specified by the context. The file is named using the hash of the schema to ensure uniqueness and easy retrieval in future operations. The schema is serialized to JSON format before being written to the file system. This function is asynchronous and returns a promise that resolves once the writing operation is complete.
33
- *
34
- * @param context - The context object containing the cache path and file system utilities.
35
- * @param schema - The schema to be written to the file system, which must be a valid schema object containing a `variant`, `schema`, and `hash` property.
36
- * @throws Will throw an error if the provided input is not a valid schema.
37
- */
38
- declare function writeSchema(context: PersistenceContext, schema: Schema): Promise<void>;
39
- /**
40
- * A helper function to read a schema from the file system using the provided context. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file based on the context provided and the extracted hash. The function checks if the file exists in the cache; if it does not exist, it returns `undefined`. If the file exists, it reads the contents of the file, parses it as JSON, and returns the resulting object. This function is asynchronous and returns a promise that resolves to either the parsed schema object or `undefined` if the schema is not found in the cache.
41
- *
42
- * @param context - The context object containing the cache path and file system utilities.
43
- * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
44
- * @returns A promise that resolves to the parsed schema object if found in the cache, or `undefined` if the schema does not exist in the cache.
45
- */
46
- declare function readSchemaSafe(context: PersistenceContext, input: SchemaInput): Promise<Schema | undefined>;
47
- /**
48
- * Reads a schema from the file system using the provided context and input. This function first attempts to read the schema using the `readSchemaSafe` helper function, which returns `undefined` if the schema is not found in the cache. If the schema is not found, this function throws an error indicating that the schema with the specified variant and hash does not exist in the cache. The error message suggests that this may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. It advises ensuring that the schema is properly written to the cache before attempting to read it. If the schema is successfully read from the cache, it is returned as a parsed object. This function is asynchronous and returns a promise that resolves to the parsed schema object if found, or throws an error if the schema is not found in the cache.
49
- *
50
- * @param context - The context object containing the cache path and file system utilities.
51
- * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
52
- * @returns A promise that resolves to the parsed schema object if found in the cache, or throws an error if the schema does not exist in the cache.
53
- * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.
54
- */
55
- declare function readSchema(context: PersistenceContext, input: SchemaInput): Promise<Schema>;
56
- //#endregion
57
- export { PersistenceContext, getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema };
58
- //# sourceMappingURL=persistence.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persistence.d.mts","names":[],"sources":["../src/persistence.ts"],"mappings":""}
@@ -1 +0,0 @@
1
- import"./type-checks.mjs";import{a as e,i as t,n,r,t as i}from"./persistence-B9pzElsC.mjs";export{i as getCacheDirectory,n as getCacheFilePath,r as readSchema,t as readSchemaSafe,e as writeSchema};
package/dist/resolve.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./bundle.cjs");let t=require("@stryke/convert/extract-file-reference"),n=require("@stryke/path/find"),r=require("@stryke/type-checks/is-set-string"),i=require("@stryke/url/helpers"),a=require("jiti"),o=require("node:fs/promises"),s=require("node:path"),c=require("smol-toml"),l=require("ts-json-schema-generator/dist/factory/generator.js"),u=require("yaml");async function d(r,i={}){let o=(0,t.extractFileReference)(r);if(!o)throw Error(`Failed to extract a file reference from the provided input ${JSON.stringify(r)}. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);let c=await e.bundle(o.file,i),l;try{let e=c.path===`<stdout>`?(0,s.resolve)(process.cwd(),`${o.file}.bundled${(0,s.extname)(o.file)||`.mjs`}`):c.path;l=await(0,a.createJiti)(i?.cwd??process.cwd()).evalModule(c.text,{filename:e,ext:(0,n.findFileDotExtension)(e)})}catch(e){throw Error(`Failed to evaluate the bundled module for "${o.file}". Error: ${e.message}${i.debug?`\n\nBundle output for module: \n${c.text&&c.text.length>5e4?`${c.text.slice(0,5e4)}\n... [truncated]`:c.text}`:``}`)}return l}async function f(e,n={}){let r=(0,t.extractFileReference)(e);if(!r)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=r.export??`*`;try{return(0,l.createGenerator)({path:r.file,type:i,expose:`export`,jsDoc:`extended`,...n}).createSchema(i)}catch(e){throw Error(`Failed to generate a JSON schema for "${r.file}" using the type "${i}". Error: ${e.message}`)}}async function p(e,a){if((0,r.isSetString)(e)&&(0,i.isValidURL)(e)&&!e.startsWith(`file://`))try{let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch the JSON file from the URL "${e}". HTTP status: ${t.status} ${t.statusText}`);return await t.json()}catch(t){throw Error(`Failed to fetch or parse the JSON file from the URL "${e}". Error: ${t.message}`)}let s=(0,t.extractFileReference)(e);if(!s)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 l=(0,n.findFileExtensionSafe)(s.file);if(l.startsWith(`json`))try{let e=await(0,o.readFile)(s.file,`utf8`);if(!(0,r.isSetString)(e))throw Error(`The file at "${s.file}" could not be read as a string. Please ensure the file exists and contains valid JSON.`);return JSON.parse(e)}catch(e){throw Error(`Failed to read or parse the JSON file at "${s.file}". Please ensure the file exists and contains valid JSON. Error: ${e.message}`)}else if(l===`yaml`||l===`yml`)try{let e=await(0,o.readFile)(s.file,`utf8`);if(!(0,r.isSetString)(e))throw Error(`The file at "${s.file}" could not be read as a string. Please ensure the file exists and contains valid YAML.`);return(0,u.parse)(e)}catch(e){throw Error(`Failed to read or parse the YAML file at "${s.file}". Please ensure the file exists and contains valid YAML. Error: ${e.message}`)}else if(l===`toml`)try{let e=await(0,o.readFile)(s.file,`utf8`);if(!(0,r.isSetString)(e))throw Error(`The file at "${s.file}" could not be read as a string. Please ensure the file exists and contains valid TOML.`);return(0,c.parse)(e)}catch(e){throw Error(`Failed to read or parse the TOML file at "${s.file}". Please ensure the file exists and contains valid TOML. Error: ${e.message}`)}let f=await d(s,a),p=s.export;p||=`default`;let m=f[p]??f[`__Ω${p}`];if(m===void 0)throw Error(`The export "${p}" could not be resolved in the "${s.file}" module. ${Object.keys(f).length===0?`After bundling, no exports were found in the module. Please ensure that the "${s.file}" module has a "${p}" export with the desired value.`:`After bundling, the available exports were: ${Object.keys(f).join(`, `)}. Please ensure that the export exists and is correctly named.`}`);return m}async function m(e,t){try{return await p(e,t)}catch{return}}exports.resolve=p,exports.resolveModule=d,exports.resolveSafe=m,exports.resolveTSType=f;
@@ -1,45 +0,0 @@
1
- import { BundleOptions } from "./bundle.cjs";
2
- import { JsonSchema } from "./types.cjs";
3
- import { FileReferenceInput } from "@stryke/types/configuration";
4
- import { Config } from "ts-json-schema-generator/dist/src/Config.js";
5
-
6
- //#region src/resolve.d.ts
7
- interface ResolveOptions extends BundleOptions, Partial<Config> {
8
- cwd?: string;
9
- tsconfig?: string;
10
- }
11
- /**
12
- * Compiles a type definition to a module and returns the module.
13
- *
14
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
15
- * @param options - Optional overrides for the ESBuild configuration.
16
- * @returns A promise that resolves to the compiled module.
17
- */
18
- declare function resolveModule<TResult>(input: FileReferenceInput, options?: ResolveOptions): Promise<TResult>;
19
- /**
20
- * 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.
21
- *
22
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
23
- * @param options - Optional overrides reserved for API compatibility.
24
- * @returns A promise that resolves to the generated JSON Schema.
25
- */
26
- declare function resolveTSType(input: FileReferenceInput, options?: ResolveOptions): Promise<JsonSchema>;
27
- /**
28
- * Compiles a type definition to a module and returns the specified export from the module.
29
- *
30
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
31
- * @param options - Optional overrides for the ESBuild configuration.
32
- * @returns A promise that resolves to the compiled module.
33
- */
34
- declare function resolve<TResult>(input: FileReferenceInput, options?: ResolveOptions): Promise<TResult>;
35
- /**
36
- * Safely compiles a type definition to a module and returns the specified export from the module.
37
- *
38
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
39
- * @param options - Optional overrides for the ESBuild configuration.
40
- * @returns A promise that resolves to the compiled module.
41
- */
42
- declare function resolveSafe<TResult>(input: FileReferenceInput, options?: ResolveOptions): Promise<TResult | undefined>;
43
- //#endregion
44
- export { ResolveOptions, resolve, resolveModule, resolveSafe, resolveTSType };
45
- //# sourceMappingURL=resolve.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve.d.cts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;UAkCiB,cAAA,SACP,aAAA,EAAe,OAAA,CAAQ,MAAA;EAC/B,GAAA;EACA,QAAA;AAAA;;;;;;;;iBAUoB,aAAA,UACpB,KAAA,EAAO,kBAAA,EACP,OAAA,GAAS,cAAA,GACR,OAAA,CAAQ,OAAA;;;;;AAbD;AAUV;;iBA0DsB,aAAA,CACpB,KAAA,EAAO,kBAAA,EACP,OAAA,GAAS,cAAA,GACR,OAAA,CAAQ,UAAA;;;;;;;;iBAoCW,OAAA,UACpB,KAAA,EAAO,kBAAA,EACP,OAAA,GAAU,cAAA,GACT,OAAA,CAAQ,OAAA;;;;;;;AAjGO;iBAsNI,WAAA,UACpB,KAAA,EAAO,kBAAA,EACP,OAAA,GAAU,cAAA,GACT,OAAA,CAAQ,OAAA"}
@@ -1,45 +0,0 @@
1
- import { BundleOptions } from "./bundle.mjs";
2
- import { JsonSchema } from "./types.mjs";
3
- import { FileReferenceInput } from "@stryke/types/configuration";
4
- import { Config } from "ts-json-schema-generator/dist/src/Config.js";
5
-
6
- //#region src/resolve.d.ts
7
- interface ResolveOptions extends BundleOptions, Partial<Config> {
8
- cwd?: string;
9
- tsconfig?: string;
10
- }
11
- /**
12
- * Compiles a type definition to a module and returns the module.
13
- *
14
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
15
- * @param options - Optional overrides for the ESBuild configuration.
16
- * @returns A promise that resolves to the compiled module.
17
- */
18
- declare function resolveModule<TResult>(input: FileReferenceInput, options?: ResolveOptions): Promise<TResult>;
19
- /**
20
- * 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.
21
- *
22
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
23
- * @param options - Optional overrides reserved for API compatibility.
24
- * @returns A promise that resolves to the generated JSON Schema.
25
- */
26
- declare function resolveTSType(input: FileReferenceInput, options?: ResolveOptions): Promise<JsonSchema>;
27
- /**
28
- * Compiles a type definition to a module and returns the specified export from the module.
29
- *
30
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
31
- * @param options - Optional overrides for the ESBuild configuration.
32
- * @returns A promise that resolves to the compiled module.
33
- */
34
- declare function resolve<TResult>(input: FileReferenceInput, options?: ResolveOptions): Promise<TResult>;
35
- /**
36
- * Safely compiles a type definition to a module and returns the specified export from the module.
37
- *
38
- * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
39
- * @param options - Optional overrides for the ESBuild configuration.
40
- * @returns A promise that resolves to the compiled module.
41
- */
42
- declare function resolveSafe<TResult>(input: FileReferenceInput, options?: ResolveOptions): Promise<TResult | undefined>;
43
- //#endregion
44
- export { ResolveOptions, resolve, resolveModule, resolveSafe, resolveTSType };
45
- //# sourceMappingURL=resolve.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/resolve.ts"],"mappings":""}
package/dist/resolve.mjs DELETED
@@ -1,2 +0,0 @@
1
- import{bundle as e}from"./bundle.mjs";import{extractFileReference as t}from"@stryke/convert/extract-file-reference";import{findFileDotExtension as n,findFileExtensionSafe as r}from"@stryke/path/find";import{isSetString as i}from"@stryke/type-checks/is-set-string";import{isValidURL as a}from"@stryke/url/helpers";import{createJiti as o}from"jiti";import{readFile as s}from"node:fs/promises";import{extname as c,resolve as l}from"node:path";import{parse as u}from"smol-toml";import{createGenerator as d}from"ts-json-schema-generator/dist/factory/generator.js";import{parse as f}from"yaml";async function p(r,i={}){let a=t(r);if(!a)throw Error(`Failed to extract a file reference from the provided input ${JSON.stringify(r)}. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);let s=await e(a.file,i),u;try{let e=s.path===`<stdout>`?l(process.cwd(),`${a.file}.bundled${c(a.file)||`.mjs`}`):s.path;u=await o(i?.cwd??process.cwd()).evalModule(s.text,{filename:e,ext:n(e)})}catch(e){throw Error(`Failed to evaluate the bundled module for "${a.file}". Error: ${e.message}${i.debug?`\n\nBundle output for module: \n${s.text&&s.text.length>5e4?`${s.text.slice(0,5e4)}\n... [truncated]`:s.text}`:``}`)}return u}async function m(e,n={}){let r=t(e);if(!r)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=r.export??`*`;try{return d({path:r.file,type:i,expose:`export`,jsDoc:`extended`,...n}).createSchema(i)}catch(e){throw Error(`Failed to generate a JSON schema for "${r.file}" using the type "${i}". Error: ${e.message}`)}}async function h(e,n){if(i(e)&&a(e)&&!e.startsWith(`file://`))try{let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch the JSON file from the URL "${e}". HTTP status: ${t.status} ${t.statusText}`);return await t.json()}catch(t){throw Error(`Failed to fetch or parse the JSON file from the URL "${e}". Error: ${t.message}`)}let o=t(e);if(!o)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 c=r(o.file);if(c.startsWith(`json`))try{let e=await s(o.file,`utf8`);if(!i(e))throw Error(`The file at "${o.file}" could not be read as a string. Please ensure the file exists and contains valid JSON.`);return JSON.parse(e)}catch(e){throw Error(`Failed to read or parse the JSON file at "${o.file}". Please ensure the file exists and contains valid JSON. Error: ${e.message}`)}else if(c===`yaml`||c===`yml`)try{let e=await s(o.file,`utf8`);if(!i(e))throw Error(`The file at "${o.file}" could not be read as a string. Please ensure the file exists and contains valid YAML.`);return f(e)}catch(e){throw Error(`Failed to read or parse the YAML file at "${o.file}". Please ensure the file exists and contains valid YAML. Error: ${e.message}`)}else if(c===`toml`)try{let e=await s(o.file,`utf8`);if(!i(e))throw Error(`The file at "${o.file}" could not be read as a string. Please ensure the file exists and contains valid TOML.`);return u(e)}catch(e){throw Error(`Failed to read or parse the TOML file at "${o.file}". Please ensure the file exists and contains valid TOML. Error: ${e.message}`)}let l=await p(o,n),d=o.export;d||=`default`;let m=l[d]??l[`__Ω${d}`];if(m===void 0)throw Error(`The export "${d}" could not be resolved in the "${o.file}" module. ${Object.keys(l).length===0?`After bundling, no exports were found in the module. Please ensure that the "${o.file}" module has a "${d}" export with the desired value.`:`After bundling, the available exports were: ${Object.keys(l).join(`, `)}. Please ensure that the export exists and is correctly named.`}`);return m}async function g(e,t){try{return await h(e,t)}catch{return}}export{h as resolve,p as resolveModule,g as resolveSafe,m as resolveTSType};
2
- //# sourceMappingURL=resolve.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve.mjs","names":[],"sources":[],"mappings":""}