@power-plant/schema 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +221 -1
- package/dist/codegen.cjs +1 -77
- package/dist/codegen.mjs +1 -78
- package/dist/{constants-Cx9_Shfk.d.cts → constants-u7ovYS9e.d.cts} +3 -4
- package/dist/constants-u7ovYS9e.d.cts.map +1 -0
- package/dist/{constants-Cx9_Shfk.d.mts → constants-u7ovYS9e.d.mts} +3 -4
- package/dist/constants-u7ovYS9e.d.mts.map +1 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.d.cts +2 -2
- package/dist/constants.d.mts +2 -2
- package/dist/constants.mjs +1 -1
- package/dist/extract.cjs +1 -1
- package/dist/extract.d.cts +22 -9
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +22 -9
- package/dist/extract.mjs +2 -1
- package/dist/extract.mjs.map +1 -0
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.d.cts +14 -3
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +14 -3
- package/dist/helpers.mjs +1 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -10
- package/dist/index.mjs +1 -1
- package/dist/metadata-CsY3HrP2.cjs +77 -0
- package/dist/metadata-DIEpQjbq.mjs +78 -0
- package/dist/metadata-DIEpQjbq.mjs.map +1 -0
- package/dist/metadata.cjs +1 -1
- package/dist/metadata.d.cts +65 -2
- package/dist/metadata.d.cts.map +1 -1
- package/dist/metadata.d.mts +65 -2
- package/dist/metadata.mjs +1 -2
- package/dist/type-checks.cjs +1 -1
- package/dist/type-checks.d.cts +10 -3
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +10 -3
- package/dist/type-checks.mjs +1 -1
- package/dist/types.d.cts +206 -37
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +206 -37
- package/package.json +19 -64
- package/dist/bundle.cjs +0 -1
- package/dist/bundle.d.cts +0 -18
- package/dist/bundle.d.cts.map +0 -1
- package/dist/bundle.d.mts +0 -18
- package/dist/bundle.d.mts.map +0 -1
- package/dist/bundle.mjs +0 -2
- package/dist/bundle.mjs.map +0 -1
- package/dist/codegen.mjs.map +0 -1
- package/dist/constants-Cx9_Shfk.d.cts.map +0 -1
- package/dist/constants-Cx9_Shfk.d.mts.map +0 -1
- package/dist/helpers.mjs.map +0 -1
- package/dist/metadata.mjs.map +0 -1
- package/dist/persistence-B9pzElsC.mjs +0 -2
- package/dist/persistence-B9pzElsC.mjs.map +0 -1
- package/dist/persistence-CLni2zCP.cjs +0 -1
- package/dist/persistence.cjs +0 -1
- package/dist/persistence.d.cts +0 -58
- package/dist/persistence.d.cts.map +0 -1
- package/dist/persistence.d.mts +0 -58
- package/dist/persistence.d.mts.map +0 -1
- package/dist/persistence.mjs +0 -1
- package/dist/resolve.cjs +0 -1
- package/dist/resolve.d.cts +0 -45
- package/dist/resolve.d.cts.map +0 -1
- package/dist/resolve.d.mts +0 -45
- package/dist/resolve.d.mts.map +0 -1
- package/dist/resolve.mjs +0 -2
- package/dist/resolve.mjs.map +0 -1
package/dist/persistence.d.cts
DELETED
|
@@ -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"}
|
package/dist/persistence.d.mts
DELETED
|
@@ -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":""}
|
package/dist/persistence.mjs
DELETED
|
@@ -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;
|
package/dist/resolve.d.cts
DELETED
|
@@ -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
|
package/dist/resolve.d.cts.map
DELETED
|
@@ -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"}
|
package/dist/resolve.d.mts
DELETED
|
@@ -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
|
package/dist/resolve.d.mts.map
DELETED
|
@@ -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
|
package/dist/resolve.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.mjs","names":[],"sources":[],"mappings":""}
|