Comparing version 1.8.2 to 1.9.0
@@ -1,2 +0,2 @@ | ||
import { C as CommentOptions } from './options-CrqQ-JtY.js'; | ||
import { C as CommentOptions } from './options-BKksCKjK.js'; | ||
import './sorts.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { R as RequiredDecodeOptions, D as DecodeOptions, P as Parent, M as MtAiValue } from './options-CrqQ-JtY.js'; | ||
import { R as RequiredDecodeOptions, D as DecodeOptions, P as Parent, M as MtAiValue } from './options-BKksCKjK.js'; | ||
import { DecodeStream } from './decodeStream.js'; | ||
@@ -3,0 +3,0 @@ import { Tag } from './tag.js'; |
@@ -1,1 +0,1 @@ | ||
import{DCBOR_INT as d,MT as a,NUMBYTES as u}from"./constants.js";import{DiagnosticSizes as w}from"./options.js";import{sortCoreDeterministic as j}from"./sorts.js";import{box as f,getEncoded as h,saveEncoded as N}from"./box.js";import{stringToHex as b,u8concat as y,u8toHex as p}from"./utils.js";import{DecodeStream as E}from"./decodeStream.js";import{Simple as S}from"./simple.js";import{Tag as m}from"./tag.js";import{checkSubnormal as T}from"./float.js";import{encode as I}from"./encoder.js";const D=new Map([[u.ZERO,1],[u.ONE,2],[u.TWO,3],[u.FOUR,5],[u.EIGHT,9]]),v=new Uint8Array(0);class g{static defaultDecodeOptions={...E.defaultOptions,ParentType:g,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:w.PREFERRED,convertUnsafeIntsToFloat:!1,pretty:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:j};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(i,n,e,t){if([this.mt,this.ai,,this.offset]=i,this.left=n,this.parent=e,this.#e=t,e&&(this.depth=e.depth+1),this.mt===a.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===u.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(i,n,e,t){const[s,l,r,c]=i;switch(s){case a.POS_INT:case a.NEG_INT:{if(e.rejectInts)throw new Error(`Unexpected integer: ${r}`);if(e.rejectLargeNegatives&&r<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${r}`);let o=r;return e.convertUnsafeIntsToFloat&&o>=d.MIN&&o<=d.MAX&&(o=Number(r)),e.boxed?f(o,t.toHere(c)):o}case a.SIMPLE_FLOAT:if(l>u.ONE){if(e.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${r}`);if(e.rejectNegativeZero&&Object.is(r,-0))throw new Error("Decoding negative zero");if(e.rejectLongLoundNaN&&isNaN(r)){const o=t.toHere(c);if(o.length!==3||o[1]!==126||o[2]!==0)throw new Error(`Invalid NaN encoding: "${p(o)}"`)}if(e.rejectSubnormals&&T(t.toHere(c+1)),e.rejectLongFloats){const o=I(r,{chunkSize:9,reduceUnsafeNumbers:e.rejectUnsafeFloatInts});if(o[0]>>5!==s)throw new Error(`Should have been encoded as int, not float: ${r}`);if(o.length<D.get(l))throw new Error(`Number should have been encoded shorter: ${r}`)}if(typeof r=="number"&&e.boxed)return f(r,t.toHere(c))}else{if(e.rejectSimple&&r instanceof S)throw new Error(`Invalid simple value: ${r}`);if(e.rejectUndefined&&r===void 0)throw new Error("Unexpected undefined")}return r;case a.BYTE_STRING:case a.UTF8_STRING:if(r===1/0)return new e.ParentType(i,1/0,n,e);if(e.rejectStringsNotNormalizedAs&&typeof r=="string"){const o=r.normalize(e.rejectStringsNotNormalizedAs);if(r!==o)throw new Error(`String not normalized as "${e.rejectStringsNotNormalizedAs}", got [${b(r)}] instead of [${b(o)}]`)}return e.boxed?f(r,t.toHere(c)):r;case a.ARRAY:return new e.ParentType(i,r,n,e);case a.MAP:return new e.ParentType(i,r*2,n,e);case a.TAG:{const o=new e.ParentType(i,1,n,e);return o.children=new m(r),o}}throw new TypeError(`Invalid major type: ${s}`)}push(i,n,e){if(this.children.push(i),this.#t){const t=h(i)||n.toHere(e);this.#t.push(t)}return--this.left}replaceLast(i,n,e){let t,s=-1/0;if(this.children instanceof m?(s=0,t=this.children.contents,this.children.contents=i):(s=this.children.length-1,t=this.children[s],this.children[s]=i),this.#t){const l=h(i)||e.toHere(n.offset);this.#t[s]=l}return t}convert(i){let n;switch(this.mt){case a.ARRAY:n=this.children;break;case a.MAP:{const e=this.#r();if(this.#e.sortKeys){let t;for(const s of e){if(t&&this.#e.sortKeys(t,s)>=0)throw new Error(`Duplicate or out of order key: "0x${s[2]}"`);t=s}}else if(this.#e.rejectDuplicateKeys){const t=new Set;for(const[s,l,r]of e){const c=p(r);if(t.has(c))throw new Error(`Duplicate key: "0x${c}"`);t.add(c)}}n=!this.#e.boxed&&!this.#e.preferMap&&e.every(([t])=>typeof t=="string")?Object.fromEntries(e):new Map(e);break}case a.BYTE_STRING:return y(this.children);case a.UTF8_STRING:{const e=this.children.join("");n=this.#e.boxed?f(e,i.toHere(this.offset)):e;break}case a.TAG:n=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&n&&typeof n=="object"&&N(n,i.toHere(this.offset)),n}#r(){const i=this.children,n=i.length;if(n%2)throw new Error("Missing map value");const e=new Array(n/2);if(this.#t)for(let t=0;t<n;t+=2)e[t>>1]=[i[t],i[t+1],this.#t[t]];else for(let t=0;t<n;t+=2)e[t>>1]=[i[t],i[t+1],v];return e}}export{g as CBORcontainer}; | ||
import{DCBOR_INT as h,MT as c,NUMBYTES as u}from"./constants.js";import{DiagnosticSizes as j}from"./options.js";import{sortCoreDeterministic as y}from"./sorts.js";import{box as f,getEncoded as b,saveEncoded as N}from"./box.js";import{stringToHex as p,u8concat as E,u8toHex as m}from"./utils.js";import{DecodeStream as S}from"./decodeStream.js";import{Simple as T}from"./simple.js";import{Tag as g}from"./tag.js";import{checkSubnormal as I}from"./float.js";import{encode as D}from"./encoder.js";const O=new Map([[u.ZERO,1],[u.ONE,2],[u.TWO,3],[u.FOUR,5],[u.EIGHT,9]]),k=new Uint8Array(0);function v(d,n){return!n.boxed&&!n.preferMap&&d.every(([i])=>typeof i=="string")?Object.fromEntries(d):new Map(d)}class w{static defaultDecodeOptions={...S.defaultOptions,ParentType:w,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:j.PREFERRED,convertUnsafeIntsToFloat:!1,createObject:v,pretty:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:y};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(n,i,e,t){if([this.mt,this.ai,,this.offset]=n,this.left=i,this.parent=e,this.#e=t,e&&(this.depth=e.depth+1),this.mt===c.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===u.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(n,i,e,t){const[s,l,r,a]=n;switch(s){case c.POS_INT:case c.NEG_INT:{if(e.rejectInts)throw new Error(`Unexpected integer: ${r}`);if(e.rejectLargeNegatives&&r<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${r}`);let o=r;return e.convertUnsafeIntsToFloat&&o>=h.MIN&&o<=h.MAX&&(o=Number(r)),e.boxed?f(o,t.toHere(a)):o}case c.SIMPLE_FLOAT:if(l>u.ONE){if(e.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${r}`);if(e.rejectNegativeZero&&Object.is(r,-0))throw new Error("Decoding negative zero");if(e.rejectLongLoundNaN&&isNaN(r)){const o=t.toHere(a);if(o.length!==3||o[1]!==126||o[2]!==0)throw new Error(`Invalid NaN encoding: "${m(o)}"`)}if(e.rejectSubnormals&&I(t.toHere(a+1)),e.rejectLongFloats){const o=D(r,{chunkSize:9,reduceUnsafeNumbers:e.rejectUnsafeFloatInts});if(o[0]>>5!==s)throw new Error(`Should have been encoded as int, not float: ${r}`);if(o.length<O.get(l))throw new Error(`Number should have been encoded shorter: ${r}`)}if(typeof r=="number"&&e.boxed)return f(r,t.toHere(a))}else{if(e.rejectSimple&&r instanceof T)throw new Error(`Invalid simple value: ${r}`);if(e.rejectUndefined&&r===void 0)throw new Error("Unexpected undefined")}return r;case c.BYTE_STRING:case c.UTF8_STRING:if(r===1/0)return new e.ParentType(n,1/0,i,e);if(e.rejectStringsNotNormalizedAs&&typeof r=="string"){const o=r.normalize(e.rejectStringsNotNormalizedAs);if(r!==o)throw new Error(`String not normalized as "${e.rejectStringsNotNormalizedAs}", got [${p(r)}] instead of [${p(o)}]`)}return e.boxed?f(r,t.toHere(a)):r;case c.ARRAY:return new e.ParentType(n,r,i,e);case c.MAP:return new e.ParentType(n,r*2,i,e);case c.TAG:{const o=new e.ParentType(n,1,i,e);return o.children=new g(r),o}}throw new TypeError(`Invalid major type: ${s}`)}push(n,i,e){if(this.children.push(n),this.#t){const t=b(n)||i.toHere(e);this.#t.push(t)}return--this.left}replaceLast(n,i,e){let t,s=-1/0;if(this.children instanceof g?(s=0,t=this.children.contents,this.children.contents=n):(s=this.children.length-1,t=this.children[s],this.children[s]=n),this.#t){const l=b(n)||e.toHere(i.offset);this.#t[s]=l}return t}convert(n){let i;switch(this.mt){case c.ARRAY:i=this.children;break;case c.MAP:{const e=this.#r();if(this.#e.sortKeys){let t;for(const s of e){if(t&&this.#e.sortKeys(t,s)>=0)throw new Error(`Duplicate or out of order key: "0x${s[2]}"`);t=s}}else if(this.#e.rejectDuplicateKeys){const t=new Set;for(const[s,l,r]of e){const a=m(r);if(t.has(a))throw new Error(`Duplicate key: "0x${a}"`);t.add(a)}}i=this.#e.createObject(e,this.#e);break}case c.BYTE_STRING:return E(this.children);case c.UTF8_STRING:{const e=this.children.join("");i=this.#e.boxed?f(e,n.toHere(this.offset)):e;break}case c.TAG:i=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&i&&typeof i=="object"&&N(i,n.toHere(this.offset)),i}#r(){const n=this.children,i=n.length;if(i%2)throw new Error("Missing map value");const e=new Array(i/2);if(this.#t)for(let t=0;t<i;t+=2)e[t>>1]=[n[t],n[t+1],this.#t[t]];else for(let t=0;t<i;t+=2)e[t>>1]=[n[t],n[t+1],k];return e}}export{w as CBORcontainer}; |
@@ -1,2 +0,2 @@ | ||
import { D as DecodeOptions } from './options-CrqQ-JtY.js'; | ||
import { D as DecodeOptions } from './options-BKksCKjK.js'; | ||
import './sorts.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { M as MtAiValue, S as Sliceable, b as DecodeStreamOptions } from './options-CrqQ-JtY.js'; | ||
import { M as MtAiValue, S as Sliceable, b as DecodeStreamOptions } from './options-BKksCKjK.js'; | ||
import './sorts.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { D as DecodeOptions } from './options-CrqQ-JtY.js'; | ||
import { D as DecodeOptions } from './options-BKksCKjK.js'; | ||
import './sorts.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { f as RequiredEncodeOptions, E as EncodeOptions, k as Writer, i as TaggedValue, T as TagNumber } from './options-CrqQ-JtY.js'; | ||
import { f as RequiredEncodeOptions, E as EncodeOptions, k as Writer, i as TaggedValue, T as TagNumber } from './options-BKksCKjK.js'; | ||
import './sorts.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { D as DecodeOptions } from './options-CrqQ-JtY.js'; | ||
export { C as CommentOptions, b as DecodeStreamOptions, c as DecodeValue, a as Decodeable, g as DiagnosticSizes, E as EncodeOptions, M as MtAiValue, P as Parent, d as ParentConstructor, e as RequiredCommentOptions, R as RequiredDecodeOptions, f as RequiredEncodeOptions, h as Simple, S as Sliceable, T as TagNumber, i as TaggedValue, j as ToCBOR, k as Writer, W as WriterOptions } from './options-CrqQ-JtY.js'; | ||
import { D as DecodeOptions } from './options-BKksCKjK.js'; | ||
export { C as CommentOptions, b as DecodeStreamOptions, c as DecodeValue, a as Decodeable, g as DiagnosticSizes, E as EncodeOptions, M as MtAiValue, P as Parent, d as ParentConstructor, e as RequiredCommentOptions, R as RequiredDecodeOptions, f as RequiredEncodeOptions, h as Simple, S as Sliceable, T as TagNumber, i as TaggedValue, j as ToCBOR, k as Writer, W as WriterOptions } from './options-BKksCKjK.js'; | ||
export { version } from './version.js'; | ||
@@ -4,0 +4,0 @@ export { DecodeStream, ValueGenerator } from './decodeStream.js'; |
import './sorts.js'; | ||
export { C as CommentOptions, D as DecodeOptions, b as DecodeStreamOptions, c as DecodeValue, a as Decodeable, g as DiagnosticSizes, E as EncodeOptions, M as MtAiValue, P as Parent, d as ParentConstructor, e as RequiredCommentOptions, R as RequiredDecodeOptions, f as RequiredEncodeOptions, n as RequiredWriterOptions, S as Sliceable, m as StringNormalization, W as WriterOptions } from './options-CrqQ-JtY.js'; | ||
export { C as CommentOptions, D as DecodeOptions, b as DecodeStreamOptions, c as DecodeValue, a as Decodeable, g as DiagnosticSizes, E as EncodeOptions, M as MtAiValue, P as Parent, d as ParentConstructor, e as RequiredCommentOptions, R as RequiredDecodeOptions, f as RequiredEncodeOptions, n as RequiredWriterOptions, S as Sliceable, m as StringNormalization, W as WriterOptions } from './options-BKksCKjK.js'; |
@@ -1,2 +0,2 @@ | ||
export { h as Simple, l as SimpleValue } from './options-CrqQ-JtY.js'; | ||
export { h as Simple, l as SimpleValue } from './options-BKksCKjK.js'; | ||
import './sorts.js'; |
@@ -1,2 +0,2 @@ | ||
import { e as RequiredCommentOptions, R as RequiredDecodeOptions, j as ToCBOR, a as Decodeable, T as TagNumber } from './options-CrqQ-JtY.js'; | ||
import { e as RequiredCommentOptions, R as RequiredDecodeOptions, j as ToCBOR, a as Decodeable, T as TagNumber } from './options-BKksCKjK.js'; | ||
import './sorts.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,3 +0,3 @@ | ||
declare const version = "1.8.2"; | ||
declare const version = "1.9.0"; | ||
export { version }; |
@@ -1,1 +0,1 @@ | ||
const o="1.8.2";export{o as version}; | ||
const o="1.9.0";export{o as version}; |
@@ -1,2 +0,2 @@ | ||
export { T as TagNumber, i as TaggedValue, j as ToCBOR, k as Writer } from './options-CrqQ-JtY.js'; | ||
export { T as TagNumber, i as TaggedValue, j as ToCBOR, k as Writer } from './options-BKksCKjK.js'; | ||
import './sorts.js'; |
{ | ||
"name": "cbor2", | ||
"version": "1.8.2", | ||
"version": "1.9.0", | ||
"description": "Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).", | ||
@@ -5,0 +5,0 @@ "exports": { |
90316
1340