zerde 0.1.5 → 0.1.6

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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ParseOptions as ParseOptions$1 } from "jsonc-parser";
2
2
  import { CreateNodeOptions, DocumentOptions, ParseOptions as ParseOptions$2, SchemaOptions, ToJSOptions, ToStringOptions } from "yaml";
3
- import * as neverthrow4 from "neverthrow";
4
3
  import * as neverthrow3 from "neverthrow";
4
+ import * as neverthrow4 from "neverthrow";
5
5
  import * as neverthrow0 from "neverthrow";
6
6
  import { ResultAsync } from "neverthrow";
7
7
  import { StandardSchemaV1, StandardSchemaV1 as StandardSchemaV1$1 } from "@standard-schema/spec";
@@ -55,7 +55,7 @@ declare const parseIt: (stringifiedContent: string, parseOptions: Partial<{
55
55
  json: ParseJSONOptions;
56
56
  yaml: ParseYAMLOptions;
57
57
  format: string;
58
- }>) => neverthrow4.Result<unknown, ParseError>;
58
+ }>) => neverthrow3.Result<unknown, ParseError>;
59
59
  //#endregion
60
60
  //#region src/schema.d.ts
61
61
  interface StringSchema extends StandardSchemaV1$1<string> {
@@ -82,7 +82,7 @@ declare const stringifyIt: (unknownContent: unknown, formatAndStringifyOptions:
82
82
  yaml: StringifyYAMLOptions;
83
83
  }> & {
84
84
  format: string;
85
- }>) => neverthrow3.Result<string, StringifyError>;
85
+ }>) => neverthrow4.Result<string, StringifyError>;
86
86
  //#endregion
87
87
  //#region src/typeHelpers.d.ts
88
88
  type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{parse as e}from"jsonc-parser";import{configure as t}from"safe-stable-stringify";import{parse as n,stringify as r}from"yaml";import{ResultAsync as i,fromThrowable as a}from"neverthrow";const o={allowEmptyContent:!1,allowTrailingComma:!1,disallowComments:!0};function s(t,n){let r={...o,...n},i=[],a=e(t,i,r);if(i.length>0)throw SyntaxError(`Could not parse JSON`,{cause:i});return a}const c=0,l=t({bigint:!1,circularValue:TypeError,deterministic:!0,strict:!0});function u(e,t){let n=l(e,null,t);if(n===void 0)throw SyntaxError(`safe-stable-stringify should have thrown an error if trying to stringify an invalid json object`);return n}function d(e,t){return n(e,t)}function f(e,t){return r(e,{sortMapEntries:!0,...t})}const p=Object.keys,m=Object.entries;var h=class extends Error{constructor(e,t){super(e,{cause:t.cause}),this.name=this.constructor.name}};const g=[`.`,`/`,`\\`,`+`];function _(e){let t=e.trim().toLowerCase();if(!t)return t;let n=t.indexOf(`;`);n>0&&(t=t.slice(0,n));let r=Math.max(...g.map(e=>t.lastIndexOf(e)));return r<0?t:t.slice(r+1)}if(import.meta.vitest){let{describe:e,it:t,expect:n}=import.meta.vitest,r={lowercase:`json`,uppercase:`JSON`,mixedcase:`jSoN`,extension:`.json`,file:`file.json`,"file with path":`some/path/to/file.json`,"file with a windows path":`some\\path\\to\\file.json`,"basic media type":`application/json`,"complex media type":`application/customFormat+json`,"media type with charset":`application/customFormat+json; charset=utf-8`};e(`extractFormatSuffix`,()=>{for(let[e,i]of m(r)){let r=`Can handle ${e}: ${i}`;t(r,()=>{n(_(i)).toEqual(`json`)})}})}var v=class extends h{tag=`ParseError`;constructor(e){super(`Could not parse content`,{cause:e}),this.name=`ParseError`}};const y={json:o,yaml:{}},b=a((e,t)=>{let{format:n,...r}=t,i=p(r).sort().at(0)??``,a=_(n??i);return a===`yaml`||a===`yml`?d(e,r.yaml):a===`json`?s(e,r.json):e},e=>new v(e));function x(e=`Invalid type`){return{type:`string`,message:e,"~standard":{version:1,vendor:`StandardSchema`,validate(t){return typeof t==`string`?{value:t}:{issues:[{message:e}]}}}}}var S=class extends h{tag=`StringifyError`;constructor(e){super(`Could not stringify content`,{cause:e}),this.name=`StringifyError`}};const C={json:c,yaml:{}},w=a((e,t)=>{if(typeof e==`string`)return e;let{format:n,...r}=t,i=_(n??``);return i===`yaml`||i===`yml`?f(e,r.yaml):u(e,r.json)},e=>new S(e));var T=class extends h{tag=`ValidationError`;originalValue;issues;constructor(e,t){super(`Content was not valid`,{cause:void 0}),this.originalValue=e,this.issues=t,this.name=`ValidationError`}};const E=i.fromThrowable(async(e,t)=>{let n=await t[`~standard`].validate(e);if(n.issues){let t=n.issues.map(t=>({...t,input:D(e,t)}));throw new T(e,t)}return n.value},e=>e);function D(e,t){let n=e;for(let e of t.path??[])n=n[e];return n}if(import.meta.vitest){let{describe:e,it:t,expect:n}=import.meta.vitest,r=[[`simpleObject`,[`hello`],{hello:`world`},`world`],[`nestedObject`,[`deeply`,`nested`,`object`],{deeply:{nested:{object:`someValue`}}},`someValue`],[`array`,[1],[`zero`,`one`],`one`],[`noPath`,void 0,{hello:`world`},{hello:`world`}]];e(`extractOriginalInput`,()=>{for(let[e,i,a,o]of r){let r={message:`something went wrong`,path:i};t(`Can handle ${e}`,()=>{n(D(a,r)).toEqual(o)})}})}var O=class{parseOptions;stringifyOptions;constructor(e={}){this.parseOptions={...y,...e.parse},this.stringifyOptions={...C,...e.stringify}}parse=(e,t,n)=>{if(typeof e==`string`){let r=typeof n==`string`?{format:n}:n,i={...this.parseOptions,...r};return b(e,i).asyncAndThen(e=>E(e,t))}return E(e,t)};stringify=(e,t,n)=>{let r=typeof n==`string`?{format:n}:n,i={...this.stringifyOptions,...r};return E(e,t).andThen(e=>w(e,i))}};const k=new O,A=k.parse,j=k.stringify;export{h as EnhancedError,v as ParseError,S as StringifyError,T as ValidationError,O as Zerde,o as defaultParseJSONOptions,y as defaultParseOptions,c as defaultStringifyJSONOptions,C as defaultStringifyOptions,_ as extractFormatSuffix,m as objectEntries,p as objectKeys,b as parseIt,s as parseJSON,x as parseString,d as parseYAML,w as stringifyIt,u as stringifyJSON,f as stringifyYAML,E as validateIt,k as zerde,A as zparse,j as zstringify};
1
+ import{parse as e}from"jsonc-parser";import{configure as t}from"safe-stable-stringify";import{serializeError as n}from"serialize-error";import{parse as r,stringify as i}from"yaml";import{ResultAsync as a,fromThrowable as o}from"neverthrow";const s={allowEmptyContent:!1,allowTrailingComma:!1,disallowComments:!0};function c(t,n){try{return JSON.parse(t)}catch{let r={...s,...n},i=[],a=e(t,i,r);if(i.length>0)throw SyntaxError(`Could not parse JSON`,{cause:i});return a}}const l=0,u=t({bigint:!1,circularValue:TypeError,deterministic:!0,strict:!0});function d(e,t){let r=Error.isError(e)?n(e):e,i=u(r,null,t);if(i===void 0)throw SyntaxError(`safe-stable-stringify should have thrown an error if trying to stringify an invalid json object`);return i}function f(e,t){return r(e,t)}function p(e,t){return i(e,{sortMapEntries:!0,...t})}const m=Object.keys,h=Object.entries;var g=class extends Error{constructor(e,t){super(e,{cause:t.cause}),this.name=this.constructor.name}};const _=[`.`,`/`,`\\`,`+`];function v(e){let t=e.trim().toLowerCase();if(!t)return t;let n=t.indexOf(`;`);n>0&&(t=t.slice(0,n));let r=Math.max(..._.map(e=>t.lastIndexOf(e)));return r<0?t:t.slice(r+1)}if(import.meta.vitest){let{describe:e,it:t,expect:n}=import.meta.vitest,r={lowercase:`json`,uppercase:`JSON`,mixedcase:`jSoN`,extension:`.json`,file:`file.json`,"file with path":`some/path/to/file.json`,"file with a windows path":`some\\path\\to\\file.json`,"basic media type":`application/json`,"complex media type":`application/customFormat+json`,"media type with charset":`application/customFormat+json; charset=utf-8`};e(`extractFormatSuffix`,()=>{for(let[e,i]of h(r)){let r=`Can handle ${e}: ${i}`;t(r,()=>{n(v(i)).toEqual(`json`)})}})}var y=class extends g{tag=`ParseError`;constructor(e){super(`Could not parse content`,{cause:e}),this.name=`ParseError`}};const b={json:s,yaml:{}},x=o((e,t)=>{let{format:n,...r}=t,i=m(r).sort().at(0)??``,a=v(n??i);return a===`yaml`||a===`yml`?f(e,r.yaml):a===`json`?c(e,r.json):e},e=>new y(e));function S(e=`Invalid type`){return{type:`string`,message:e,"~standard":{version:1,vendor:`StandardSchema`,validate(t){return typeof t==`string`?{value:t}:{issues:[{message:e}]}}}}}var C=class extends g{tag=`StringifyError`;constructor(e){super(`Could not stringify content`,{cause:e}),this.name=`StringifyError`}};const w={json:l,yaml:{}},T=o((e,t)=>{if(typeof e==`string`)return e;let{format:n,...r}=t,i=v(n??``);return i===`yaml`||i===`yml`?p(e,r.yaml):d(e,r.json)},e=>new C(e));var E=class extends g{tag=`ValidationError`;originalValue;issues;constructor(e,t){super(`Content was not valid`,{cause:void 0}),this.originalValue=e,this.issues=t,this.name=`ValidationError`}};const D=a.fromThrowable(async(e,t)=>{let n=await t[`~standard`].validate(e);if(n.issues){let t=n.issues.map(t=>({...t,input:O(e,t)}));throw new E(e,t)}return n.value},e=>e);function O(e,t){let n=e;for(let e of t.path??[])n=n[e];return n}if(import.meta.vitest){let{describe:e,it:t,expect:n}=import.meta.vitest,r=[[`simpleObject`,[`hello`],{hello:`world`},`world`],[`nestedObject`,[`deeply`,`nested`,`object`],{deeply:{nested:{object:`someValue`}}},`someValue`],[`array`,[1],[`zero`,`one`],`one`],[`noPath`,void 0,{hello:`world`},{hello:`world`}]];e(`extractOriginalInput`,()=>{for(let[e,i,a,o]of r){let r={message:`something went wrong`,path:i};t(`Can handle ${e}`,()=>{n(O(a,r)).toEqual(o)})}})}var k=class{parseOptions;stringifyOptions;constructor(e={}){this.parseOptions={...b,...e.parse},this.stringifyOptions={...w,...e.stringify}}parse=(e,t,n)=>{if(typeof e==`string`){let r=typeof n==`string`?{format:n}:n,i={...this.parseOptions,...r};return x(e,i).asyncAndThen(e=>D(e,t))}return D(e,t)};stringify=(e,t,n)=>{let r=typeof n==`string`?{format:n}:n,i={...this.stringifyOptions,...r};return D(e,t).andThen(e=>T(e,i))}};const A=new k,j=A.parse,M=A.stringify;export{g as EnhancedError,y as ParseError,C as StringifyError,E as ValidationError,k as Zerde,s as defaultParseJSONOptions,b as defaultParseOptions,l as defaultStringifyJSONOptions,w as defaultStringifyOptions,v as extractFormatSuffix,h as objectEntries,m as objectKeys,x as parseIt,c as parseJSON,S as parseString,f as parseYAML,T as stringifyIt,d as stringifyJSON,p as stringifyYAML,D as validateIt,A as zerde,j as zparse,M as zstringify};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zerde",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "parsing, and stringifying combined with schema validation",
5
5
  "keywords": [
6
6
  "parse",
@@ -44,10 +44,11 @@
44
44
  "test:watch": "vitest"
45
45
  },
46
46
  "dependencies": {
47
- "@standard-schema/spec": "^1.0.0",
47
+ "@standard-schema/spec": "^1.1.0",
48
48
  "jsonc-parser": "^3.3.1",
49
49
  "neverthrow": "^8.2.0",
50
50
  "safe-stable-stringify": "^2.5.0",
51
- "yaml": "^2.8.2"
51
+ "serialize-error": "^13.0.1",
52
+ "yaml": "^2.8.3"
52
53
  }
53
54
  }