@power-plant/schema 0.0.74 → 0.0.75

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/dist/codegen.cjs CHANGED
@@ -303,10 +303,10 @@ ${generateStatements(definition, "value", "path", "result", "errors").join("\n")
303
303
  * @param value - The input value to parse.
304
304
  * @returns The parsed value conforming to the schema or an array of validation errors.
305
305
  */
306
- export function parseSafe(value: unknown) {
306
+ export function parseSafe(value: unknown): ${stringifyType(schema)} | { path: string; failure: string }[] {
307
307
  const errors: { path: string; failure: string }[] = [];
308
308
 
309
- let result;
309
+ let result!: ${stringifyType(schema)};
310
310
  ${generateStatements(schema, "value", "\"$\"", "result", "errors").join("\n")}
311
311
 
312
312
  if (errors.length > 0) {
@@ -324,9 +324,9 @@ export function parseSafe(value: unknown) {
324
324
  *
325
325
  * @param value - The input value to parse.
326
326
  * @returns The parsed value conforming to the schema.
327
- * @throws {Error} When the input value cannot be parsed into a valid result according to the schema.
327
+ * @throws When the input value cannot be parsed into a valid result according to the schema.
328
328
  */
329
- export function parse(value: unknown) {
329
+ export function parse(value: unknown): ${stringifyType(schema)} {
330
330
  const result = parseSafe(value);
331
331
  if (Array.isArray(result) && result.length > 0 && result.every(error => "path" in error && typeof error.path === "string" && error.path && "failure" in error && typeof error.failure === "string" && error.failure)) {
332
332
  throw new Error(\`The following validation errors occurred while parsing the input value: \\n\${Object.entries(result.reduce((acc, error) => ((acc[error.path] ??= []).push(error.failure), acc), {})).map(([path, failures]) => \`\${path.replace(/^\\$\\./, "") ? \`\${path.replace(/^\\$\\./, "")}: \\n\` : ""}\${failures.map(failure => \` - \${failure}\`).join("\\n")}\`).join("\\n")}\`);
package/dist/codegen.mjs CHANGED
@@ -302,10 +302,10 @@ ${generateStatements(definition, "value", "path", "result", "errors").join("\n")
302
302
  * @param value - The input value to parse.
303
303
  * @returns The parsed value conforming to the schema or an array of validation errors.
304
304
  */
305
- export function parseSafe(value: unknown) {
305
+ export function parseSafe(value: unknown): ${stringifyType(schema)} | { path: string; failure: string }[] {
306
306
  const errors: { path: string; failure: string }[] = [];
307
307
 
308
- let result;
308
+ let result!: ${stringifyType(schema)};
309
309
  ${generateStatements(schema, "value", "\"$\"", "result", "errors").join("\n")}
310
310
 
311
311
  if (errors.length > 0) {
@@ -323,9 +323,9 @@ export function parseSafe(value: unknown) {
323
323
  *
324
324
  * @param value - The input value to parse.
325
325
  * @returns The parsed value conforming to the schema.
326
- * @throws {Error} When the input value cannot be parsed into a valid result according to the schema.
326
+ * @throws When the input value cannot be parsed into a valid result according to the schema.
327
327
  */
328
- export function parse(value: unknown) {
328
+ export function parse(value: unknown): ${stringifyType(schema)} {
329
329
  const result = parseSafe(value);
330
330
  if (Array.isArray(result) && result.length > 0 && result.every(error => "path" in error && typeof error.path === "string" && error.path && "failure" in error && typeof error.failure === "string" && error.failure)) {
331
331
  throw new Error(\`The following validation errors occurred while parsing the input value: \\n\${Object.entries(result.reduce((acc, error) => ((acc[error.path] ??= []).push(error.failure), acc), {})).map(([path, failures]) => \`\${path.replace(/^\\$\\./, "") ? \`\${path.replace(/^\\$\\./, "")}: \\n\` : ""}\${failures.map(failure => \` - \${failure}\`).join("\\n")}\`).join("\\n")}\`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@power-plant/schema",
3
- "version": "0.0.74",
3
+ "version": "0.0.75",
4
4
  "private": false,
5
5
  "description": "A Power Plant utility package to help managing schemas.",
6
6
  "keywords": [
@@ -185,5 +185,5 @@
185
185
  },
186
186
  "publishConfig": { "access": "public" },
187
187
  "inlinedDependencies": { "@deepkit/type-compiler": "1.0.19" },
188
- "gitHead": "bb0ad8b94b0eb600e56b87605d7196fb7275727b"
188
+ "gitHead": "5030d7876addbb22c300e7e5ee8ae5b505e6aa9f"
189
189
  }