@kittycad/react-shared 0.1.4 → 0.1.5

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.js CHANGED
@@ -49,7 +49,7 @@ function styleInject(css, ref) {
49
49
  }
50
50
  }
51
51
 
52
- var css_248z = "@import \"./colors.css\";*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }\n/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:\"\"}:host,html{-webkit-text-size-adjust:100%;font-feature-settings:normal;-webkit-tap-highlight-color:transparent;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-feature-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}.visible{visibility:visible}.absolute{position:absolute}.relative{position:relative}.left-\\[-1px\\]{left:-1px}.top-\\[2px\\]{top:2px}.z-0{z-index:0}.col-span-1{grid-column:span 1/span 1}.mx-auto{margin-left:auto;margin-right:auto}.my-0{margin-bottom:0;margin-top:0}.\\!mb-0{margin-bottom:0!important}.block{display:block}.flex{display:flex}.inline-flex{display:inline-flex}.h-1\\.5{height:.375rem}.h-10{height:2.5rem}.h-11{height:2.75rem}.h-4{height:1rem}.h-5{height:1.25rem}.h-8{height:2rem}.h-\\[40px\\]{height:40px}.min-h-\\[calc\\(100vh-733px\\)\\]{min-height:calc(100vh - 733px)}.w-4{width:1rem}.w-5{width:1.25rem}.w-8{width:2rem}.w-9{width:2.25rem}.w-\\[120px\\]{width:120px}.w-full{width:100%}.max-w-2xl{max-width:42rem}.max-w-4xl{max-width:56rem}.flex-1{flex:1 1 0%}.flex-grow{flex-grow:1}.origin-center{transform-origin:center}.translate-y-\\[0\\]{--tw-translate-y:0;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}.animate-spin{animation:spin 1s linear infinite}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.flex-row{flex-direction:row}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-baseline{align-items:baseline}.items-stretch{align-items:stretch}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-2{gap:.5rem}.gap-4{gap:1rem}.self-center{align-self:center}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.border{border-width:1px}.border-none{border-style:none}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity,1))}.border-ml-black{border-color:var(--chalkboard-100)}.\\!bg-transparent{background-color:transparent!important}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity,1))}.bg-gray-300{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.bg-gray-50{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.bg-ml-black{background-color:var(--chalkboard-100)}.bg-ml-green{--tw-bg-opacity:1;background-color:rgb(41 255 164/var(--tw-bg-opacity,1))}.bg-primary{--tw-bg-opacity:1;background-color:oklch(var(--_primary)/var(--tw-bg-opacity,1))}.bg-transparent{background-color:transparent}.p-1{padding:.25rem}.p-4{padding:1rem}.px-0{padding-left:0;padding-right:0}.px-2{padding-left:.5rem;padding-right:.5rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.py-1{padding-bottom:.25rem;padding-top:.25rem}.py-2{padding-bottom:.5rem;padding-top:.5rem}.pb-0\\.5{padding-bottom:.125rem}.pb-1{padding-bottom:.25rem}.pb-\\[3px\\]{padding-bottom:3px}.pb-\\[5px\\]{padding-bottom:5px}.text-center{text-align:center}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.text-base{font-size:1rem;line-height:1.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.uppercase{text-transform:uppercase}.normal-case{text-transform:none}.leading-normal{line-height:1.5}.\\!text-chalkboard-100{--tw-text-opacity:1!important;color:oklch(var(--_chalkboard-100)/var(--tw-text-opacity,1))!important}.\\!text-ml-white{--tw-text-opacity:1!important;color:rgb(255 255 255/var(--tw-text-opacity,1))!important}.text-current{color:currentColor}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.text-inherit{color:inherit}.text-ml-black{color:var(--chalkboard-100)}.text-ml-grey{color:var(--chalkboard-80)}.text-ml-white,.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.\\!no-underline{text-decoration-line:none!important}.outline{outline-style:solid}.transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.before\\:absolute:before{content:var(--tw-content);position:absolute}.before\\:-inset-y-1\\/4:before{bottom:-25%;content:var(--tw-content);top:-25%}.before\\:left-1\\/2:before{content:var(--tw-content);left:50%}.before\\:z-\\[-1\\]:before{content:var(--tw-content);z-index:-1}.before\\:w-\\[1px\\]:before{content:var(--tw-content);width:1px}.before\\:origin-center:before{content:var(--tw-content);transform-origin:center}.before\\:rotate-45:before{--tw-rotate:45deg;content:var(--tw-content);transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.before\\:opacity-30:before{content:var(--tw-content);opacity:.3}.before\\:content-\\[\\'\\'\\]:before{--tw-content:\"\";content:var(--tw-content)}.hover\\:bg-gray-100:hover{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.hover\\:bg-gray-300:hover{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.hover\\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.hover\\:opacity-80:hover{opacity:.8}.focus-visible\\:outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:pointer-events-none:disabled{pointer-events:none}.disabled\\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:opacity-50:disabled{opacity:.5}.group:hover .group-hover\\:\\!text-white{--tw-text-opacity:1!important;color:rgb(255 255 255/var(--tw-text-opacity,1))!important}.dark\\:bg-transparent:is(.dark *){background-color:transparent}.dark\\:\\!text-ml-green:is(.dark *){--tw-text-opacity:1!important;color:rgb(41 255 164/var(--tw-text-opacity,1))!important}@media (min-width:640px){.sm\\:flex-row{flex-direction:row}}@media (min-width:768px){.md\\:col-span-2{grid-column:span 2/span 2}.md\\:flex{display:flex}.md\\:flex-nowrap{flex-wrap:nowrap}.md\\:gap-12{gap:3rem}.md\\:text-4xl{font-size:2.25rem;line-height:2.5rem}}@media (min-width:1024px){.lg\\:text-5xl{font-size:3rem;line-height:1}.lg\\:text-lg{font-size:1.125rem;line-height:1.75rem}}@media (min-width:1280px){.xl\\:text-6xl{font-size:3.75rem;line-height:1}}";
52
+ var css_248z = "@import \"./colors.css\";*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }\n/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:\"\"}:host,html{-webkit-text-size-adjust:100%;font-feature-settings:normal;-webkit-tap-highlight-color:transparent;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-feature-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}.visible{visibility:visible}.static{position:static}.absolute{position:absolute}.relative{position:relative}.left-\\[-1px\\]{left:-1px}.top-\\[2px\\]{top:2px}.z-0{z-index:0}.col-span-1{grid-column:span 1/span 1}.mx-auto{margin-left:auto;margin-right:auto}.my-0{margin-bottom:0;margin-top:0}.\\!mb-0{margin-bottom:0!important}.block{display:block}.flex{display:flex}.inline-flex{display:inline-flex}.h-1\\.5{height:.375rem}.h-10{height:2.5rem}.h-11{height:2.75rem}.h-4{height:1rem}.h-5{height:1.25rem}.h-8{height:2rem}.h-\\[40px\\]{height:40px}.min-h-\\[calc\\(100vh-733px\\)\\]{min-height:calc(100vh - 733px)}.w-4{width:1rem}.w-5{width:1.25rem}.w-8{width:2rem}.w-9{width:2.25rem}.w-\\[120px\\]{width:120px}.w-full{width:100%}.max-w-2xl{max-width:42rem}.max-w-4xl{max-width:56rem}.flex-1{flex:1 1 0%}.flex-grow{flex-grow:1}.origin-center{transform-origin:center}.translate-y-\\[0\\]{--tw-translate-y:0;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}.animate-spin{animation:spin 1s linear infinite}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.flex-row{flex-direction:row}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-baseline{align-items:baseline}.items-stretch{align-items:stretch}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-2{gap:.5rem}.gap-4{gap:1rem}.self-center{align-self:center}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.border{border-width:1px}.border-none{border-style:none}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity,1))}.border-ml-black{border-color:var(--chalkboard-100)}.\\!bg-transparent{background-color:transparent!important}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity,1))}.bg-gray-300{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.bg-gray-50{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.bg-ml-black{background-color:var(--chalkboard-100)}.bg-ml-green{--tw-bg-opacity:1;background-color:rgb(41 255 164/var(--tw-bg-opacity,1))}.bg-primary{--tw-bg-opacity:1;background-color:oklch(var(--_primary)/var(--tw-bg-opacity,1))}.bg-transparent{background-color:transparent}.p-1{padding:.25rem}.p-4{padding:1rem}.px-0{padding-left:0;padding-right:0}.px-2{padding-left:.5rem;padding-right:.5rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.py-1{padding-bottom:.25rem;padding-top:.25rem}.py-2{padding-bottom:.5rem;padding-top:.5rem}.pb-0\\.5{padding-bottom:.125rem}.pb-1{padding-bottom:.25rem}.pb-\\[3px\\]{padding-bottom:3px}.pb-\\[5px\\]{padding-bottom:5px}.text-center{text-align:center}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.text-base{font-size:1rem;line-height:1.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.uppercase{text-transform:uppercase}.normal-case{text-transform:none}.leading-normal{line-height:1.5}.\\!text-chalkboard-100{--tw-text-opacity:1!important;color:oklch(var(--_chalkboard-100)/var(--tw-text-opacity,1))!important}.\\!text-ml-white{--tw-text-opacity:1!important;color:rgb(255 255 255/var(--tw-text-opacity,1))!important}.text-current{color:currentColor}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.text-inherit{color:inherit}.text-ml-black{color:var(--chalkboard-100)}.text-ml-grey{color:var(--chalkboard-80)}.text-ml-white,.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.\\!no-underline{text-decoration-line:none!important}.outline{outline-style:solid}.transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.before\\:absolute:before{content:var(--tw-content);position:absolute}.before\\:-inset-y-1\\/4:before{bottom:-25%;content:var(--tw-content);top:-25%}.before\\:left-1\\/2:before{content:var(--tw-content);left:50%}.before\\:z-\\[-1\\]:before{content:var(--tw-content);z-index:-1}.before\\:w-\\[1px\\]:before{content:var(--tw-content);width:1px}.before\\:origin-center:before{content:var(--tw-content);transform-origin:center}.before\\:rotate-45:before{--tw-rotate:45deg;content:var(--tw-content);transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.before\\:opacity-30:before{content:var(--tw-content);opacity:.3}.before\\:content-\\[\\'\\'\\]:before{--tw-content:\"\";content:var(--tw-content)}.hover\\:bg-gray-100:hover{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.hover\\:bg-gray-300:hover{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.hover\\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.hover\\:opacity-80:hover{opacity:.8}.focus-visible\\:outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:pointer-events-none:disabled{pointer-events:none}.disabled\\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:opacity-50:disabled{opacity:.5}.group:hover .group-hover\\:\\!text-white{--tw-text-opacity:1!important;color:rgb(255 255 255/var(--tw-text-opacity,1))!important}.dark\\:bg-transparent:is(.dark *){background-color:transparent}.dark\\:\\!text-ml-green:is(.dark *){--tw-text-opacity:1!important;color:rgb(41 255 164/var(--tw-text-opacity,1))!important}@media (min-width:640px){.sm\\:flex-row{flex-direction:row}}@media (min-width:768px){.md\\:col-span-2{grid-column:span 2/span 2}.md\\:flex{display:flex}.md\\:flex-nowrap{flex-wrap:nowrap}.md\\:gap-12{gap:3rem}.md\\:text-4xl{font-size:2.25rem;line-height:2.5rem}}@media (min-width:1024px){.lg\\:text-5xl{font-size:3rem;line-height:1}.lg\\:text-lg{font-size:1.125rem;line-height:1.75rem}}@media (min-width:1280px){.xl\\:text-6xl{font-size:3.75rem;line-height:1}}";
53
53
  styleInject(css_248z,{"insertAt":"top"});
54
54
 
55
55
  function r$2(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r$2(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r$2(e))&&(n&&(n+=" "),n+=t);return n}
@@ -2727,11 +2727,11 @@ var S = {
2727
2727
  SECONDARY: "secondary"
2728
2728
  },
2729
2729
  P$1 = ["fa-classic", "fa-duotone", "fa-sharp", "fa-sharp-duotone"];
2730
- var s$1 = "classic",
2730
+ var s$2 = "classic",
2731
2731
  t$1 = "duotone",
2732
- r = "sharp",
2733
- o$1 = "sharp-duotone",
2734
- L = [s$1, t$1, r, o$1];
2732
+ r$1 = "sharp",
2733
+ o$2 = "sharp-duotone",
2734
+ L = [s$2, t$1, r$1, o$2];
2735
2735
  var G = {
2736
2736
  classic: {
2737
2737
  900: "fas",
@@ -2885,7 +2885,7 @@ var t$1$1 = {
2885
2885
  PRIMARY: "primary",
2886
2886
  SECONDARY: "secondary"
2887
2887
  },
2888
- r$1 = ["fa-classic", "fa-duotone", "fa-sharp", "fa-sharp-duotone"];
2888
+ r$1$1 = ["fa-classic", "fa-duotone", "fa-sharp", "fa-sharp-duotone"];
2889
2889
  var bt$1 = ["fak", "fa-kit", "fakd", "fa-kit-duotone"];
2890
2890
  var Yt = {
2891
2891
  "Font Awesome Kit": {
@@ -2958,7 +2958,7 @@ var ua = {
2958
2958
  }
2959
2959
  },
2960
2960
  x$1 = ["fa-solid", "fa-regular", "fa-light", "fa-thin", "fa-duotone", "fa-brands"],
2961
- Ia = ["fa", "fas", "far", "fal", "fat", "fad", "fadr", "fadl", "fadt", "fab", "fass", "fasr", "fasl", "fast", "fasds", "fasdr", "fasdl", "fasdt", ...r$1, ...x$1],
2961
+ Ia = ["fa", "fas", "far", "fal", "fat", "fad", "fadr", "fadl", "fadt", "fab", "fass", "fasr", "fasl", "fast", "fasds", "fasdr", "fasdl", "fasdt", ...r$1$1, ...x$1],
2962
2962
  m$1 = ["solid", "regular", "light", "thin", "duotone", "brands"],
2963
2963
  c$1$1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
2964
2964
  F$1 = c$1$1.concat([11, 12, 13, 14, 15, 16, 17, 18, 19, 20]),
@@ -3006,7 +3006,7 @@ function familyProxy(obj) {
3006
3006
  // Defaults to the classic family if family is not available
3007
3007
  return new Proxy(obj, {
3008
3008
  get(target, prop) {
3009
- return prop in target ? target[prop] : target[s$1];
3009
+ return prop in target ? target[prop] : target[s$2];
3010
3010
  }
3011
3011
  });
3012
3012
  }
@@ -3015,23 +3015,23 @@ const _PREFIX_TO_STYLE = _objectSpread2$1({}, S);
3015
3015
  // We changed FACSSClassesToStyleId in the icons repo to be canonical and as such, "classic" family does not have any
3016
3016
  // duotone styles. But we do still need duotone in _PREFIX_TO_STYLE below, so we are manually adding
3017
3017
  // {'fa-duotone': 'duotone'}
3018
- _PREFIX_TO_STYLE[s$1] = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, {
3018
+ _PREFIX_TO_STYLE[s$2] = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, {
3019
3019
  'fa-duotone': 'duotone'
3020
- }), S[s$1]), St['kit']), St['kit-duotone']);
3020
+ }), S[s$2]), St['kit']), St['kit-duotone']);
3021
3021
  const PREFIX_TO_STYLE = familyProxy(_PREFIX_TO_STYLE);
3022
3022
  const _STYLE_TO_PREFIX = _objectSpread2$1({}, xt);
3023
3023
 
3024
3024
  // We changed FAStyleIdToShortPrefixId in the icons repo to be canonical and as such, "classic" family does not have any
3025
3025
  // duotone styles. But we do still need duotone in _STYLE_TO_PREFIX below, so we are manually adding {duotone: 'fad'}
3026
- _STYLE_TO_PREFIX[s$1] = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, {
3026
+ _STYLE_TO_PREFIX[s$2] = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, {
3027
3027
  duotone: 'fad'
3028
- }), _STYLE_TO_PREFIX[s$1]), Et['kit']), Et['kit-duotone']);
3028
+ }), _STYLE_TO_PREFIX[s$2]), Et['kit']), Et['kit-duotone']);
3029
3029
  const STYLE_TO_PREFIX = familyProxy(_STYLE_TO_PREFIX);
3030
3030
  const _PREFIX_TO_LONG_STYLE = _objectSpread2$1({}, ga);
3031
- _PREFIX_TO_LONG_STYLE[s$1] = _objectSpread2$1(_objectSpread2$1({}, _PREFIX_TO_LONG_STYLE[s$1]), Wt['kit']);
3031
+ _PREFIX_TO_LONG_STYLE[s$2] = _objectSpread2$1(_objectSpread2$1({}, _PREFIX_TO_LONG_STYLE[s$2]), Wt['kit']);
3032
3032
  const PREFIX_TO_LONG_STYLE = familyProxy(_PREFIX_TO_LONG_STYLE);
3033
3033
  const _LONG_STYLE_TO_PREFIX = _objectSpread2$1({}, ua);
3034
- _LONG_STYLE_TO_PREFIX[s$1] = _objectSpread2$1(_objectSpread2$1({}, _LONG_STYLE_TO_PREFIX[s$1]), Ct['kit']);
3034
+ _LONG_STYLE_TO_PREFIX[s$2] = _objectSpread2$1(_objectSpread2$1({}, _LONG_STYLE_TO_PREFIX[s$2]), Ct['kit']);
3035
3035
  familyProxy(_LONG_STYLE_TO_PREFIX);
3036
3036
  const ICON_SELECTION_SYNTAX_PATTERN = p$1; // eslint-disable-line no-useless-escape
3037
3037
 
@@ -3070,7 +3070,7 @@ if (DOCUMENT && typeof DOCUMENT.querySelector === 'function') {
3070
3070
  }
3071
3071
  const _default = {
3072
3072
  styleDefault: 'solid',
3073
- familyDefault: s$1,
3073
+ familyDefault: s$2,
3074
3074
  cssPrefix: DEFAULT_CSS_PREFIX,
3075
3075
  replacementClass: DEFAULT_REPLACEMENT_CLASS,
3076
3076
  autoReplaceSvg: true,
@@ -3601,7 +3601,7 @@ const emptyCanonicalIcon = () => {
3601
3601
  };
3602
3602
  };
3603
3603
  function getFamilyId(values) {
3604
- let family = s$1;
3604
+ let family = s$2;
3605
3605
  const famProps = FAMILY_NAMES.reduce((acc, familyId) => {
3606
3606
  acc[familyId] = "".concat(config.cssPrefix, "-").concat(familyId);
3607
3607
  return acc;
@@ -3616,7 +3616,7 @@ function getFamilyId(values) {
3616
3616
  function getCanonicalPrefix(styleOrPrefix) {
3617
3617
  let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3618
3618
  const {
3619
- family = s$1
3619
+ family = s$2
3620
3620
  } = params;
3621
3621
  const style = PREFIX_TO_STYLE[family][styleOrPrefix];
3622
3622
 
@@ -3705,9 +3705,9 @@ function applyShimAndAlias(skipLookups, givenPrefix, canonical) {
3705
3705
  };
3706
3706
  }
3707
3707
  const newCanonicalFamilies = L.filter(familyId => {
3708
- return familyId !== s$1 || familyId !== t$1;
3708
+ return familyId !== s$2 || familyId !== t$1;
3709
3709
  });
3710
- const newCanonicalStyles = Object.keys(ga).filter(key => key !== s$1).map(key => Object.keys(ga[key])).flat();
3710
+ const newCanonicalStyles = Object.keys(ga).filter(key => key !== s$2).map(key => Object.keys(ga[key])).flat();
3711
3711
  function getDefaultCanonicalPrefix(prefixOptions) {
3712
3712
  const {
3713
3713
  values,
@@ -3757,7 +3757,7 @@ class Library {
3757
3757
  defineIcons(key, additions[key]);
3758
3758
 
3759
3759
  // TODO can we stop doing this? We can't get the icons by 'fa-solid' any longer so this probably needs to change
3760
- const longPrefix = PREFIX_TO_LONG_STYLE[s$1][key];
3760
+ const longPrefix = PREFIX_TO_LONG_STYLE[s$2][key];
3761
3761
  if (longPrefix) defineIcons(longPrefix, additions[key]);
3762
3762
  build();
3763
3763
  });
@@ -3907,7 +3907,7 @@ const dom = {
3907
3907
  });
3908
3908
  }
3909
3909
  };
3910
- const parse = {
3910
+ const parse$1 = {
3911
3911
  icon: icon => {
3912
3912
  if (icon === null) {
3913
3913
  return null;
@@ -3948,7 +3948,7 @@ const api = {
3948
3948
  noAuto,
3949
3949
  config,
3950
3950
  dom,
3951
- parse,
3951
+ parse: parse$1,
3952
3952
  library,
3953
3953
  findIconDefinition,
3954
3954
  toHtml
@@ -5509,7 +5509,7 @@ api.noAuto;
5509
5509
  api.config;
5510
5510
  api.library;
5511
5511
  api.dom;
5512
- const parse$1 = api.parse;
5512
+ const parse$1$1 = api.parse;
5513
5513
  api.findIconDefinition;
5514
5514
  api.toHtml;
5515
5515
  const icon = api.icon;
@@ -7026,8 +7026,8 @@ function normalizeIconArgs(icon) {
7026
7026
  return icon;
7027
7027
  }
7028
7028
 
7029
- if (parse$1.icon) {
7030
- return parse$1.icon(icon);
7029
+ if (parse$1$1.icon) {
7030
+ return parse$1$1.icon(icon);
7031
7031
  } // if the icon is null, there's nothing to do
7032
7032
 
7033
7033
 
@@ -7109,7 +7109,7 @@ var FontAwesomeIcon = /*#__PURE__*/g$2.forwardRef(function (props, ref) {
7109
7109
  maskId = allProps.maskId;
7110
7110
  var iconLookup = normalizeIconArgs(iconArgs);
7111
7111
  var classes = objectWithKey('classes', [].concat(_toConsumableArray(classList(allProps)), _toConsumableArray((className || '').split(' '))));
7112
- var transform = objectWithKey('transform', typeof allProps.transform === 'string' ? parse$1.transform(allProps.transform) : allProps.transform);
7112
+ var transform = objectWithKey('transform', typeof allProps.transform === 'string' ? parse$1$1.transform(allProps.transform) : allProps.transform);
7113
7113
  var mask = objectWithKey('mask', normalizeIconArgs(maskArgs));
7114
7114
  var renderedIcon = icon(iconLookup, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, classes), transform), mask), {}, {
7115
7115
  symbol: symbol,
@@ -8401,10 +8401,10 @@ var freeModule$2 = freeExports$2 && typeof module == 'object' && module && !modu
8401
8401
  var moduleExports$2 = freeModule$2 && freeModule$2.exports === freeExports$2;
8402
8402
 
8403
8403
  /** Built-in value references. */
8404
- var Buffer$1 = moduleExports$2 ? root.Buffer : undefined;
8404
+ var Buffer$2 = moduleExports$2 ? root.Buffer : undefined;
8405
8405
 
8406
8406
  /* Built-in method references for those with the same name as other `lodash` methods. */
8407
- var nativeIsBuffer = Buffer$1 ? Buffer$1.isBuffer : undefined;
8407
+ var nativeIsBuffer = Buffer$2 ? Buffer$2.isBuffer : undefined;
8408
8408
 
8409
8409
  /**
8410
8410
  * Checks if `value` is a buffer.
@@ -8858,8 +8858,8 @@ var freeModule = freeExports && typeof module == 'object' && module && !module.n
8858
8858
  var moduleExports = freeModule && freeModule.exports === freeExports;
8859
8859
 
8860
8860
  /** Built-in value references. */
8861
- var Buffer = moduleExports ? root.Buffer : undefined,
8862
- allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined;
8861
+ var Buffer$1 = moduleExports ? root.Buffer : undefined,
8862
+ allocUnsafe = Buffer$1 ? Buffer$1.allocUnsafe : undefined;
8863
8863
 
8864
8864
  /**
8865
8865
  * Creates a clone of `buffer`.
@@ -9161,7 +9161,7 @@ function initCloneArray(array) {
9161
9161
  }
9162
9162
 
9163
9163
  /** Built-in value references. */
9164
- var Uint8Array = root.Uint8Array;
9164
+ var Uint8Array$1 = root.Uint8Array;
9165
9165
 
9166
9166
  /**
9167
9167
  * Creates a clone of `arrayBuffer`.
@@ -9172,7 +9172,7 @@ var Uint8Array = root.Uint8Array;
9172
9172
  */
9173
9173
  function cloneArrayBuffer(arrayBuffer) {
9174
9174
  var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
9175
- new Uint8Array(result).set(new Uint8Array(arrayBuffer));
9175
+ new Uint8Array$1(result).set(new Uint8Array$1(arrayBuffer));
9176
9176
  return result;
9177
9177
  }
9178
9178
 
@@ -9377,7 +9377,7 @@ var nodeIsMap = nodeUtil && nodeUtil.isMap;
9377
9377
  * _.isMap(new WeakMap);
9378
9378
  * // => false
9379
9379
  */
9380
- var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
9380
+ var isMap$1 = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
9381
9381
 
9382
9382
  /** `Object#toString` result references. */
9383
9383
  var setTag$1 = '[object Set]';
@@ -9531,7 +9531,7 @@ function baseClone(value, bitmask, customizer, key, object, stack) {
9531
9531
  value.forEach(function(subValue) {
9532
9532
  result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
9533
9533
  });
9534
- } else if (isMap(value)) {
9534
+ } else if (isMap$1(value)) {
9535
9535
  value.forEach(function(subValue, key) {
9536
9536
  result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
9537
9537
  });
@@ -11674,9 +11674,9 @@ var Form = /*#__PURE__*/g$2.forwardRef(function (props, ref) {
11674
11674
  });
11675
11675
  Form.displayName = 'Form';
11676
11676
 
11677
- let e={data:""},t=t=>"object"==typeof window?((t?t.querySelector("#_goober"):window._goober)||Object.assign((t||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:t||e,l=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,a=/\/\*[^]*?\*\/| +/g,n=/\n+/g,o=(e,t)=>{let r="",l="",a="";for(let n in e){let c=e[n];"@"==n[0]?"i"==n[1]?r=n+" "+c+";":l+="f"==n[1]?o(c,n):n+"{"+o(c,"k"==n[1]?"":t)+"}":"object"==typeof c?l+=o(c,t?t.replace(/([^,])+/g,e=>n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,t=>/&/.test(t)?t.replace(/&/g,e):e?e+" "+t:t)):n):null!=c&&(n=/^--/.test(n)?n:n.replace(/[A-Z]/g,"-$&").toLowerCase(),a+=o.p?o.p(n,c):n+":"+c+";");}return r+(t&&a?t+"{"+a+"}":a)+l},c$1={},s=e=>{if("object"==typeof e){let t="";for(let r in e)t+=r+s(e[r]);return t}return e},i=(e,t,r,i,p)=>{let u=s(e),d=c$1[u]||(c$1[u]=(e=>{let t=0,r=11;for(;t<e.length;)r=101*r+e.charCodeAt(t++)>>>0;return "go"+r})(u));if(!c$1[d]){let t=u!==e?e:(e=>{let t,r,o=[{}];for(;t=l.exec(e.replace(a,""));)t[4]?o.shift():t[3]?(r=t[3].replace(n," ").trim(),o.unshift(o[0][r]=o[0][r]||{})):o[0][t[1]]=t[2].replace(n," ").trim();return o[0]})(e);c$1[d]=o(p?{["@keyframes "+d]:t}:t,r?"":"."+d);}let f=r&&c$1.g?c$1.g:null;return r&&(c$1.g=c$1[d]),((e,t,r,l)=>{l?t.data=t.data.replace(l,e):-1===t.data.indexOf(e)&&(t.data=r?e+t.data:t.data+e);})(c$1[d],t,i,f),d},p=(e,t,r)=>e.reduce((e,l,a)=>{let n=t[a];if(n&&n.call){let e=n(r),t=e&&e.props&&e.props.className||/^go/.test(e)&&e;n=t?"."+t:e&&"object"==typeof e?e.props?"":o(e,""):false===e?"":e;}return e+l+(null==n?"":n)},"");function u$1(e){let r=this||{},l=e.call?e(r.p):e;return i(l.unshift?l.raw?p(l,[].slice.call(arguments,1),r.p):l.reduce((e,t)=>Object.assign(e,t&&t.call?t(r.p):t),{}):l,t(r.target),r.g,r.o,r.k)}let d,f$1,g;u$1.bind({g:1});let h=u$1.bind({k:1});function m(e,t,r,l){o.p=t,d=e,f$1=r,g=l;}function j(e,t){let r=this||{};return function(){let l=arguments;function a(n,o){let c=Object.assign({},n),s=c.className||a.className;r.p=Object.assign({theme:f$1&&f$1()},c),r.o=/ *go\d+/.test(s),c.className=u$1.apply(r,l)+(s?" "+s:"");let i=e;return e[0]&&(i=c.as||e,delete c.as),g&&i[0]&&g(c),d(i,c)}return a}}
11677
+ let e={data:""},t=t=>"object"==typeof window?((t?t.querySelector("#_goober"):window._goober)||Object.assign((t||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:t||e,l$1=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,a$1=/\/\*[^]*?\*\/| +/g,n=/\n+/g,o$1=(e,t)=>{let r="",l="",a="";for(let n in e){let c=e[n];"@"==n[0]?"i"==n[1]?r=n+" "+c+";":l+="f"==n[1]?o$1(c,n):n+"{"+o$1(c,"k"==n[1]?"":t)+"}":"object"==typeof c?l+=o$1(c,t?t.replace(/([^,])+/g,e=>n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,t=>/&/.test(t)?t.replace(/&/g,e):e?e+" "+t:t)):n):null!=c&&(n=/^--/.test(n)?n:n.replace(/[A-Z]/g,"-$&").toLowerCase(),a+=o$1.p?o$1.p(n,c):n+":"+c+";");}return r+(t&&a?t+"{"+a+"}":a)+l},c$2={},s$1=e=>{if("object"==typeof e){let t="";for(let r in e)t+=r+s$1(e[r]);return t}return e},i=(e,t,r,i,p)=>{let u=s$1(e),d=c$2[u]||(c$2[u]=(e=>{let t=0,r=11;for(;t<e.length;)r=101*r+e.charCodeAt(t++)>>>0;return "go"+r})(u));if(!c$2[d]){let t=u!==e?e:(e=>{let t,r,o=[{}];for(;t=l$1.exec(e.replace(a$1,""));)t[4]?o.shift():t[3]?(r=t[3].replace(n," ").trim(),o.unshift(o[0][r]=o[0][r]||{})):o[0][t[1]]=t[2].replace(n," ").trim();return o[0]})(e);c$2[d]=o$1(p?{["@keyframes "+d]:t}:t,r?"":"."+d);}let f=r&&c$2.g?c$2.g:null;return r&&(c$2.g=c$2[d]),((e,t,r,l)=>{l?t.data=t.data.replace(l,e):-1===t.data.indexOf(e)&&(t.data=r?e+t.data:t.data+e);})(c$2[d],t,i,f),d},p=(e,t,r)=>e.reduce((e,l,a)=>{let n=t[a];if(n&&n.call){let e=n(r),t=e&&e.props&&e.props.className||/^go/.test(e)&&e;n=t?"."+t:e&&"object"==typeof e?e.props?"":o$1(e,""):false===e?"":e;}return e+l+(null==n?"":n)},"");function u$1(e){let r=this||{},l=e.call?e(r.p):e;return i(l.unshift?l.raw?p(l,[].slice.call(arguments,1),r.p):l.reduce((e,t)=>Object.assign(e,t&&t.call?t(r.p):t),{}):l,t(r.target),r.g,r.o,r.k)}let d,f$1,g;u$1.bind({g:1});let h=u$1.bind({k:1});function m(e,t,r,l){o$1.p=t,d=e,f$1=r,g=l;}function j(e,t){let r=this||{};return function(){let l=arguments;function a(n,o){let c=Object.assign({},n),s=c.className||a.className;r.p=Object.assign({theme:f$1&&f$1()},c),r.o=/ *go\d+/.test(s),c.className=u$1.apply(r,l)+(s?" "+s:"");let i=e;return e[0]&&(i=c.as||e,delete c.as),g&&i[0]&&g(c),d(i,c)}return a}}
11678
11678
 
11679
- var W=e=>typeof e=="function",f=(e,t)=>W(e)?e(t):e;var F=(()=>{let e=0;return ()=>(++e).toString()})(),A=(()=>{let e;return ()=>{if(e===void 0&&typeof window<"u"){let t=matchMedia("(prefers-reduced-motion: reduce)");e=!t||t.matches;}return e}})();var Y=20;var U=(e,t)=>{switch(t.type){case 0:return {...e,toasts:[t.toast,...e.toasts].slice(0,Y)};case 1:return {...e,toasts:e.toasts.map(o=>o.id===t.toast.id?{...o,...t.toast}:o)};case 2:let{toast:r}=t;return U(e,{type:e.toasts.find(o=>o.id===r.id)?1:0,toast:r});case 3:let{toastId:s}=t;return {...e,toasts:e.toasts.map(o=>o.id===s||s===void 0?{...o,dismissed:true,visible:false}:o)};case 4:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(o=>o.id!==t.toastId)};case 5:return {...e,pausedAt:t.time};case 6:let a=t.time-(e.pausedAt||0);return {...e,pausedAt:void 0,toasts:e.toasts.map(o=>({...o,pauseDuration:o.pauseDuration+a}))}}},P=[],y={toasts:[],pausedAt:void 0},u=e=>{y=U(y,e),P.forEach(t=>{t(y);});};var J=(e,t="blank",r)=>({createdAt:Date.now(),visible:true,dismissed:false,type:t,ariaProps:{role:"status","aria-live":"polite"},message:e,pauseDuration:0,...r,id:(r==null?void 0:r.id)||F()}),x=e=>(t,r)=>{let s=J(t,e,r);return u({type:2,toast:s}),s.id},c=(e,t)=>x("blank")(e,t);c.error=x("error");c.success=x("success");c.loading=x("loading");c.custom=x("custom");c.dismiss=e=>{u({type:3,toastId:e});};c.remove=e=>u({type:4,toastId:e});c.promise=(e,t,r)=>{let s=c.loading(t.loading,{...r,...r==null?void 0:r.loading});return typeof e=="function"&&(e=e()),e.then(a=>{let o=t.success?f(t.success,a):void 0;return o?c.success(o,{id:s,...r,...r==null?void 0:r.success}):c.dismiss(s),a}).catch(a=>{let o=t.error?f(t.error,a):void 0;o?c.error(o,{id:s,...r,...r==null?void 0:r.error}):c.dismiss(s);}),e};var oe=h`
11679
+ var W=e=>typeof e=="function",f=(e,t)=>W(e)?e(t):e;var F=(()=>{let e=0;return ()=>(++e).toString()})(),A=(()=>{let e;return ()=>{if(e===void 0&&typeof window<"u"){let t=matchMedia("(prefers-reduced-motion: reduce)");e=!t||t.matches;}return e}})();var Y=20;var U=(e,t)=>{switch(t.type){case 0:return {...e,toasts:[t.toast,...e.toasts].slice(0,Y)};case 1:return {...e,toasts:e.toasts.map(o=>o.id===t.toast.id?{...o,...t.toast}:o)};case 2:let{toast:r}=t;return U(e,{type:e.toasts.find(o=>o.id===r.id)?1:0,toast:r});case 3:let{toastId:s}=t;return {...e,toasts:e.toasts.map(o=>o.id===s||s===void 0?{...o,dismissed:true,visible:false}:o)};case 4:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(o=>o.id!==t.toastId)};case 5:return {...e,pausedAt:t.time};case 6:let a=t.time-(e.pausedAt||0);return {...e,pausedAt:void 0,toasts:e.toasts.map(o=>({...o,pauseDuration:o.pauseDuration+a}))}}},P=[],y$1={toasts:[],pausedAt:void 0},u=e=>{y$1=U(y$1,e),P.forEach(t=>{t(y$1);});};var J=(e,t="blank",r)=>({createdAt:Date.now(),visible:true,dismissed:false,type:t,ariaProps:{role:"status","aria-live":"polite"},message:e,pauseDuration:0,...r,id:(r==null?void 0:r.id)||F()}),x=e=>(t,r)=>{let s=J(t,e,r);return u({type:2,toast:s}),s.id},c$1=(e,t)=>x("blank")(e,t);c$1.error=x("error");c$1.success=x("success");c$1.loading=x("loading");c$1.custom=x("custom");c$1.dismiss=e=>{u({type:3,toastId:e});};c$1.remove=e=>u({type:4,toastId:e});c$1.promise=(e,t,r)=>{let s=c$1.loading(t.loading,{...r,...r==null?void 0:r.loading});return typeof e=="function"&&(e=e()),e.then(a=>{let o=t.success?f(t.success,a):void 0;return o?c$1.success(o,{id:s,...r,...r==null?void 0:r.success}):c$1.dismiss(s),a}).catch(a=>{let o=t.error?f(t.error,a):void 0;o?c$1.error(o,{id:s,...r,...r==null?void 0:r.error}):c$1.dismiss(s);}),e};var oe=h`
11680
11680
  from {
11681
11681
  transform: scale(0) rotate(45deg);
11682
11682
  opacity: 0;
@@ -11700,7 +11700,7 @@ from {
11700
11700
  to {
11701
11701
  transform: scale(1) rotate(90deg);
11702
11702
  opacity: 1;
11703
- }`,k=j("div")`
11703
+ }`,k$1=j("div")`
11704
11704
  width: 20px;
11705
11705
  opacity: 0;
11706
11706
  height: 20px;
@@ -11822,7 +11822,7 @@ to {
11822
11822
  min-width: 20px;
11823
11823
  animation: ${fe} 0.3s 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275)
11824
11824
  forwards;
11825
- `,M=({toast:e})=>{let{icon:t,type:r,iconTheme:s}=e;return t!==void 0?typeof t=="string"?g__namespace.createElement(Te,null,t):t:r==="blank"?null:g__namespace.createElement(le,null,g__namespace.createElement(V,{...s}),r!=="loading"&&g__namespace.createElement(ue,null,r==="error"?g__namespace.createElement(k,{...s}):g__namespace.createElement(_,{...s})))};var ye=e=>`
11825
+ `,M=({toast:e})=>{let{icon:t,type:r,iconTheme:s}=e;return t!==void 0?typeof t=="string"?g__namespace.createElement(Te,null,t):t:r==="blank"?null:g__namespace.createElement(le,null,g__namespace.createElement(V,{...s}),r!=="loading"&&g__namespace.createElement(ue,null,r==="error"?g__namespace.createElement(k$1,{...s}):g__namespace.createElement(_,{...s})))};var ye=e=>`
11826
11826
  0% {transform: translate3d(0,${e*-200}%,0) scale(.6); opacity:.5;}
11827
11827
  100% {transform: translate3d(0,0,0) scale(1); opacity:1;}
11828
11828
  `,ge=e=>`
@@ -13549,13 +13549,13 @@ create$6$1.prototype = StringSchema$1.prototype;
13549
13549
  //
13550
13550
 
13551
13551
  let invalidDate$1 = new Date('');
13552
- let isDate$1 = obj => Object.prototype.toString.call(obj) === '[object Date]';
13552
+ let isDate$2 = obj => Object.prototype.toString.call(obj) === '[object Date]';
13553
13553
  let DateSchema$1 = class DateSchema extends Schema {
13554
13554
  constructor() {
13555
13555
  super({
13556
13556
  type: 'date',
13557
13557
  check(v) {
13558
- return isDate$1(v) && !isNaN(v.getTime());
13558
+ return isDate$2(v) && !isNaN(v.getTime());
13559
13559
  }
13560
13560
  });
13561
13561
  this.withMutation(() => {
@@ -19936,7 +19936,7 @@ function parseIsoDate(date) {
19936
19936
  // @ts-ignore
19937
19937
  let invalidDate = new Date('');
19938
19938
 
19939
- let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
19939
+ let isDate$1 = obj => Object.prototype.toString.call(obj) === '[object Date]';
19940
19940
 
19941
19941
  function create$3() {
19942
19942
  return new DateSchema();
@@ -19957,7 +19957,7 @@ class DateSchema extends BaseSchema {
19957
19957
  }
19958
19958
 
19959
19959
  _typeCheck(v) {
19960
- return isDate(v) && !isNaN(v.getTime());
19960
+ return isDate$1(v) && !isNaN(v.getTime());
19961
19961
  }
19962
19962
 
19963
19963
  prepareParam(ref, name) {
@@ -21742,13 +21742,13 @@ function EmailLoginForm({ theme = 'default', buttonClassName = '', className, id
21742
21742
  // Make sure the status code is in the 200 range.
21743
21743
  if (response.status >= 200 && response.status < 300) {
21744
21744
  // Create a success toast.
21745
- c.success('Email sent! Check your inbox.', {
21745
+ c$1.success('Email sent! Check your inbox.', {
21746
21746
  duration: 4000,
21747
21747
  className: 'email-toast-success',
21748
21748
  });
21749
21749
  }
21750
21750
  else {
21751
- c.error('Something went wrong in sending your email.', {
21751
+ c$1.error('Something went wrong in sending your email.', {
21752
21752
  duration: 4000,
21753
21753
  className: 'email-toast-error',
21754
21754
  });
@@ -21756,7 +21756,7 @@ function EmailLoginForm({ theme = 'default', buttonClassName = '', className, id
21756
21756
  }
21757
21757
  }
21758
21758
  catch (error) {
21759
- c.error('Something went wrong in sending your email.', {
21759
+ c$1.error('Something went wrong in sending your email.', {
21760
21760
  duration: 4000,
21761
21761
  className: 'email-toast-error',
21762
21762
  });
@@ -21940,7 +21940,3420 @@ const BillingDialog = (props) => {
21940
21940
  defaultProps.text?.paragraph?.limited }), jsxRuntime.jsx(BillingRemaining, { mode: exports.BillingRemainingMode.ProgressBarStretch, error: props.error, credits: props.credits, allowance: props.allowance }), !hasUnlimited && (jsxRuntime.jsx("a", { className: "bg-ml-black text-ml-white rounded-lg text-center p-1 cursor-pointer", href: props.upgradeHref || defaultProps.upgradeHref, target: "_blank", rel: "noopener noreferrer", "data-testid": "billing-upgrade-button", onClick: props.upgradeClick, children: props.text?.button?.limited || defaultProps.text?.button?.limited }))] })] }));
21941
21941
  };
21942
21942
 
21943
+ const TypedArrayPrototypeGetSymbolToStringTag = (() => {
21944
+ const g = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag).get;
21945
+ return (value) => g.call(value);
21946
+ })();
21947
+ function isUint8Array(value) {
21948
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === 'Uint8Array';
21949
+ }
21950
+ function isAnyArrayBuffer(value) {
21951
+ return (typeof value === 'object' &&
21952
+ value != null &&
21953
+ Symbol.toStringTag in value &&
21954
+ (value[Symbol.toStringTag] === 'ArrayBuffer' ||
21955
+ value[Symbol.toStringTag] === 'SharedArrayBuffer'));
21956
+ }
21957
+ function isRegExp(regexp) {
21958
+ return regexp instanceof RegExp || Object.prototype.toString.call(regexp) === '[object RegExp]';
21959
+ }
21960
+ function isMap(value) {
21961
+ return (typeof value === 'object' &&
21962
+ value != null &&
21963
+ Symbol.toStringTag in value &&
21964
+ value[Symbol.toStringTag] === 'Map');
21965
+ }
21966
+ function isDate(date) {
21967
+ return date instanceof Date || Object.prototype.toString.call(date) === '[object Date]';
21968
+ }
21969
+ function defaultInspect(x, _options) {
21970
+ return JSON.stringify(x, (k, v) => {
21971
+ if (typeof v === 'bigint') {
21972
+ return { $numberLong: `${v}` };
21973
+ }
21974
+ else if (isMap(v)) {
21975
+ return Object.fromEntries(v);
21976
+ }
21977
+ return v;
21978
+ });
21979
+ }
21980
+ function getStylizeFunction(options) {
21981
+ const stylizeExists = options != null &&
21982
+ typeof options === 'object' &&
21983
+ 'stylize' in options &&
21984
+ typeof options.stylize === 'function';
21985
+ if (stylizeExists) {
21986
+ return options.stylize;
21987
+ }
21988
+ }
21989
+
21990
+ const BSON_MAJOR_VERSION = 6;
21991
+ const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
21992
+ const BSON_INT32_MAX = 0x7fffffff;
21993
+ const BSON_INT32_MIN = -2147483648;
21994
+ const BSON_INT64_MAX = Math.pow(2, 63) - 1;
21995
+ const BSON_INT64_MIN = -Math.pow(2, 63);
21996
+ const JS_INT_MAX = Math.pow(2, 53);
21997
+ const JS_INT_MIN = -Math.pow(2, 53);
21998
+ const BSON_BINARY_SUBTYPE_UUID_NEW = 4;
21999
+
22000
+ class BSONError extends Error {
22001
+ get bsonError() {
22002
+ return true;
22003
+ }
22004
+ get name() {
22005
+ return 'BSONError';
22006
+ }
22007
+ constructor(message, options) {
22008
+ super(message, options);
22009
+ }
22010
+ static isBSONError(value) {
22011
+ return (value != null &&
22012
+ typeof value === 'object' &&
22013
+ 'bsonError' in value &&
22014
+ value.bsonError === true &&
22015
+ 'name' in value &&
22016
+ 'message' in value &&
22017
+ 'stack' in value);
22018
+ }
22019
+ }
22020
+ class BSONVersionError extends BSONError {
22021
+ get name() {
22022
+ return 'BSONVersionError';
22023
+ }
22024
+ constructor() {
22025
+ super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.x.x`);
22026
+ }
22027
+ }
22028
+ class BSONRuntimeError extends BSONError {
22029
+ get name() {
22030
+ return 'BSONRuntimeError';
22031
+ }
22032
+ constructor(message) {
22033
+ super(message);
22034
+ }
22035
+ }
22036
+ class BSONOffsetError extends BSONError {
22037
+ get name() {
22038
+ return 'BSONOffsetError';
22039
+ }
22040
+ constructor(message, offset, options) {
22041
+ super(`${message}. offset: ${offset}`, options);
22042
+ this.offset = offset;
22043
+ }
22044
+ }
22045
+
22046
+ let TextDecoderFatal;
22047
+ let TextDecoderNonFatal;
22048
+ function parseUtf8(buffer, start, end, fatal) {
22049
+ if (fatal) {
22050
+ TextDecoderFatal ??= new TextDecoder('utf8', { fatal: true });
22051
+ try {
22052
+ return TextDecoderFatal.decode(buffer.subarray(start, end));
22053
+ }
22054
+ catch (cause) {
22055
+ throw new BSONError('Invalid UTF-8 string in BSON document', { cause });
22056
+ }
22057
+ }
22058
+ TextDecoderNonFatal ??= new TextDecoder('utf8', { fatal: false });
22059
+ return TextDecoderNonFatal.decode(buffer.subarray(start, end));
22060
+ }
22061
+
22062
+ function tryReadBasicLatin(uint8array, start, end) {
22063
+ if (uint8array.length === 0) {
22064
+ return '';
22065
+ }
22066
+ const stringByteLength = end - start;
22067
+ if (stringByteLength === 0) {
22068
+ return '';
22069
+ }
22070
+ if (stringByteLength > 20) {
22071
+ return null;
22072
+ }
22073
+ if (stringByteLength === 1 && uint8array[start] < 128) {
22074
+ return String.fromCharCode(uint8array[start]);
22075
+ }
22076
+ if (stringByteLength === 2 && uint8array[start] < 128 && uint8array[start + 1] < 128) {
22077
+ return String.fromCharCode(uint8array[start]) + String.fromCharCode(uint8array[start + 1]);
22078
+ }
22079
+ if (stringByteLength === 3 &&
22080
+ uint8array[start] < 128 &&
22081
+ uint8array[start + 1] < 128 &&
22082
+ uint8array[start + 2] < 128) {
22083
+ return (String.fromCharCode(uint8array[start]) +
22084
+ String.fromCharCode(uint8array[start + 1]) +
22085
+ String.fromCharCode(uint8array[start + 2]));
22086
+ }
22087
+ const latinBytes = [];
22088
+ for (let i = start; i < end; i++) {
22089
+ const byte = uint8array[i];
22090
+ if (byte > 127) {
22091
+ return null;
22092
+ }
22093
+ latinBytes.push(byte);
22094
+ }
22095
+ return String.fromCharCode(...latinBytes);
22096
+ }
22097
+ function tryWriteBasicLatin(destination, source, offset) {
22098
+ if (source.length === 0)
22099
+ return 0;
22100
+ if (source.length > 25)
22101
+ return null;
22102
+ if (destination.length - offset < source.length)
22103
+ return null;
22104
+ for (let charOffset = 0, destinationOffset = offset; charOffset < source.length; charOffset++, destinationOffset++) {
22105
+ const char = source.charCodeAt(charOffset);
22106
+ if (char > 127)
22107
+ return null;
22108
+ destination[destinationOffset] = char;
22109
+ }
22110
+ return source.length;
22111
+ }
22112
+
22113
+ function nodejsMathRandomBytes(byteLength) {
22114
+ return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
22115
+ }
22116
+ const nodejsRandomBytes = nodejsMathRandomBytes;
22117
+ const nodeJsByteUtils = {
22118
+ toLocalBufferType(potentialBuffer) {
22119
+ if (Buffer.isBuffer(potentialBuffer)) {
22120
+ return potentialBuffer;
22121
+ }
22122
+ if (ArrayBuffer.isView(potentialBuffer)) {
22123
+ return Buffer.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
22124
+ }
22125
+ const stringTag = potentialBuffer?.[Symbol.toStringTag] ?? Object.prototype.toString.call(potentialBuffer);
22126
+ if (stringTag === 'ArrayBuffer' ||
22127
+ stringTag === 'SharedArrayBuffer' ||
22128
+ stringTag === '[object ArrayBuffer]' ||
22129
+ stringTag === '[object SharedArrayBuffer]') {
22130
+ return Buffer.from(potentialBuffer);
22131
+ }
22132
+ throw new BSONError(`Cannot create Buffer from the passed potentialBuffer.`);
22133
+ },
22134
+ allocate(size) {
22135
+ return Buffer.alloc(size);
22136
+ },
22137
+ allocateUnsafe(size) {
22138
+ return Buffer.allocUnsafe(size);
22139
+ },
22140
+ equals(a, b) {
22141
+ return nodeJsByteUtils.toLocalBufferType(a).equals(b);
22142
+ },
22143
+ fromNumberArray(array) {
22144
+ return Buffer.from(array);
22145
+ },
22146
+ fromBase64(base64) {
22147
+ return Buffer.from(base64, 'base64');
22148
+ },
22149
+ toBase64(buffer) {
22150
+ return nodeJsByteUtils.toLocalBufferType(buffer).toString('base64');
22151
+ },
22152
+ fromISO88591(codePoints) {
22153
+ return Buffer.from(codePoints, 'binary');
22154
+ },
22155
+ toISO88591(buffer) {
22156
+ return nodeJsByteUtils.toLocalBufferType(buffer).toString('binary');
22157
+ },
22158
+ fromHex(hex) {
22159
+ return Buffer.from(hex, 'hex');
22160
+ },
22161
+ toHex(buffer) {
22162
+ return nodeJsByteUtils.toLocalBufferType(buffer).toString('hex');
22163
+ },
22164
+ toUTF8(buffer, start, end, fatal) {
22165
+ const basicLatin = end - start <= 20 ? tryReadBasicLatin(buffer, start, end) : null;
22166
+ if (basicLatin != null) {
22167
+ return basicLatin;
22168
+ }
22169
+ const string = nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
22170
+ if (fatal) {
22171
+ for (let i = 0; i < string.length; i++) {
22172
+ if (string.charCodeAt(i) === 0xfffd) {
22173
+ parseUtf8(buffer, start, end, true);
22174
+ break;
22175
+ }
22176
+ }
22177
+ }
22178
+ return string;
22179
+ },
22180
+ utf8ByteLength(input) {
22181
+ return Buffer.byteLength(input, 'utf8');
22182
+ },
22183
+ encodeUTF8Into(buffer, source, byteOffset) {
22184
+ const latinBytesWritten = tryWriteBasicLatin(buffer, source, byteOffset);
22185
+ if (latinBytesWritten != null) {
22186
+ return latinBytesWritten;
22187
+ }
22188
+ return nodeJsByteUtils.toLocalBufferType(buffer).write(source, byteOffset, undefined, 'utf8');
22189
+ },
22190
+ randomBytes: nodejsRandomBytes,
22191
+ swap32(buffer) {
22192
+ return nodeJsByteUtils.toLocalBufferType(buffer).swap32();
22193
+ }
22194
+ };
22195
+
22196
+ function isReactNative() {
22197
+ const { navigator } = globalThis;
22198
+ return typeof navigator === 'object' && navigator.product === 'ReactNative';
22199
+ }
22200
+ function webMathRandomBytes(byteLength) {
22201
+ if (byteLength < 0) {
22202
+ throw new RangeError(`The argument 'byteLength' is invalid. Received ${byteLength}`);
22203
+ }
22204
+ return webByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
22205
+ }
22206
+ const webRandomBytes = (() => {
22207
+ const { crypto } = globalThis;
22208
+ if (crypto != null && typeof crypto.getRandomValues === 'function') {
22209
+ return (byteLength) => {
22210
+ return crypto.getRandomValues(webByteUtils.allocate(byteLength));
22211
+ };
22212
+ }
22213
+ else {
22214
+ if (isReactNative()) {
22215
+ const { console } = globalThis;
22216
+ console?.warn?.('BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.');
22217
+ }
22218
+ return webMathRandomBytes;
22219
+ }
22220
+ })();
22221
+ const HEX_DIGIT = /(\d|[a-f])/i;
22222
+ const webByteUtils = {
22223
+ toLocalBufferType(potentialUint8array) {
22224
+ const stringTag = potentialUint8array?.[Symbol.toStringTag] ??
22225
+ Object.prototype.toString.call(potentialUint8array);
22226
+ if (stringTag === 'Uint8Array') {
22227
+ return potentialUint8array;
22228
+ }
22229
+ if (ArrayBuffer.isView(potentialUint8array)) {
22230
+ return new Uint8Array(potentialUint8array.buffer.slice(potentialUint8array.byteOffset, potentialUint8array.byteOffset + potentialUint8array.byteLength));
22231
+ }
22232
+ if (stringTag === 'ArrayBuffer' ||
22233
+ stringTag === 'SharedArrayBuffer' ||
22234
+ stringTag === '[object ArrayBuffer]' ||
22235
+ stringTag === '[object SharedArrayBuffer]') {
22236
+ return new Uint8Array(potentialUint8array);
22237
+ }
22238
+ throw new BSONError(`Cannot make a Uint8Array from passed potentialBuffer.`);
22239
+ },
22240
+ allocate(size) {
22241
+ if (typeof size !== 'number') {
22242
+ throw new TypeError(`The "size" argument must be of type number. Received ${String(size)}`);
22243
+ }
22244
+ return new Uint8Array(size);
22245
+ },
22246
+ allocateUnsafe(size) {
22247
+ return webByteUtils.allocate(size);
22248
+ },
22249
+ equals(a, b) {
22250
+ if (a.byteLength !== b.byteLength) {
22251
+ return false;
22252
+ }
22253
+ for (let i = 0; i < a.byteLength; i++) {
22254
+ if (a[i] !== b[i]) {
22255
+ return false;
22256
+ }
22257
+ }
22258
+ return true;
22259
+ },
22260
+ fromNumberArray(array) {
22261
+ return Uint8Array.from(array);
22262
+ },
22263
+ fromBase64(base64) {
22264
+ return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
22265
+ },
22266
+ toBase64(uint8array) {
22267
+ return btoa(webByteUtils.toISO88591(uint8array));
22268
+ },
22269
+ fromISO88591(codePoints) {
22270
+ return Uint8Array.from(codePoints, c => c.charCodeAt(0) & 0xff);
22271
+ },
22272
+ toISO88591(uint8array) {
22273
+ return Array.from(Uint16Array.from(uint8array), b => String.fromCharCode(b)).join('');
22274
+ },
22275
+ fromHex(hex) {
22276
+ const evenLengthHex = hex.length % 2 === 0 ? hex : hex.slice(0, hex.length - 1);
22277
+ const buffer = [];
22278
+ for (let i = 0; i < evenLengthHex.length; i += 2) {
22279
+ const firstDigit = evenLengthHex[i];
22280
+ const secondDigit = evenLengthHex[i + 1];
22281
+ if (!HEX_DIGIT.test(firstDigit)) {
22282
+ break;
22283
+ }
22284
+ if (!HEX_DIGIT.test(secondDigit)) {
22285
+ break;
22286
+ }
22287
+ const hexDigit = Number.parseInt(`${firstDigit}${secondDigit}`, 16);
22288
+ buffer.push(hexDigit);
22289
+ }
22290
+ return Uint8Array.from(buffer);
22291
+ },
22292
+ toHex(uint8array) {
22293
+ return Array.from(uint8array, byte => byte.toString(16).padStart(2, '0')).join('');
22294
+ },
22295
+ toUTF8(uint8array, start, end, fatal) {
22296
+ const basicLatin = end - start <= 20 ? tryReadBasicLatin(uint8array, start, end) : null;
22297
+ if (basicLatin != null) {
22298
+ return basicLatin;
22299
+ }
22300
+ return parseUtf8(uint8array, start, end, fatal);
22301
+ },
22302
+ utf8ByteLength(input) {
22303
+ return new TextEncoder().encode(input).byteLength;
22304
+ },
22305
+ encodeUTF8Into(uint8array, source, byteOffset) {
22306
+ const bytes = new TextEncoder().encode(source);
22307
+ uint8array.set(bytes, byteOffset);
22308
+ return bytes.byteLength;
22309
+ },
22310
+ randomBytes: webRandomBytes,
22311
+ swap32(buffer) {
22312
+ if (buffer.length % 4 !== 0) {
22313
+ throw new RangeError('Buffer size must be a multiple of 32-bits');
22314
+ }
22315
+ for (let i = 0; i < buffer.length; i += 4) {
22316
+ const byte0 = buffer[i];
22317
+ const byte1 = buffer[i + 1];
22318
+ const byte2 = buffer[i + 2];
22319
+ const byte3 = buffer[i + 3];
22320
+ buffer[i] = byte3;
22321
+ buffer[i + 1] = byte2;
22322
+ buffer[i + 2] = byte1;
22323
+ buffer[i + 3] = byte0;
22324
+ }
22325
+ return buffer;
22326
+ }
22327
+ };
22328
+
22329
+ const hasGlobalBuffer = typeof Buffer === 'function' && Buffer.prototype?._isBuffer !== true;
22330
+ const ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
22331
+
22332
+ class BSONValue {
22333
+ get [BSON_VERSION_SYMBOL]() {
22334
+ return BSON_MAJOR_VERSION;
22335
+ }
22336
+ [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
22337
+ return this.inspect(depth, options, inspect);
22338
+ }
22339
+ }
22340
+
22341
+ const FLOAT = new Float64Array(1);
22342
+ const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
22343
+ FLOAT[0] = -1;
22344
+ const isBigEndian = FLOAT_BYTES[7] === 0;
22345
+ const NumberUtils = {
22346
+ isBigEndian,
22347
+ getNonnegativeInt32LE(source, offset) {
22348
+ if (source[offset + 3] > 127) {
22349
+ throw new RangeError(`Size cannot be negative at offset: ${offset}`);
22350
+ }
22351
+ return (source[offset] |
22352
+ (source[offset + 1] << 8) |
22353
+ (source[offset + 2] << 16) |
22354
+ (source[offset + 3] << 24));
22355
+ },
22356
+ getInt32LE(source, offset) {
22357
+ return (source[offset] |
22358
+ (source[offset + 1] << 8) |
22359
+ (source[offset + 2] << 16) |
22360
+ (source[offset + 3] << 24));
22361
+ },
22362
+ getUint32LE(source, offset) {
22363
+ return (source[offset] +
22364
+ source[offset + 1] * 256 +
22365
+ source[offset + 2] * 65536 +
22366
+ source[offset + 3] * 16777216);
22367
+ },
22368
+ getUint32BE(source, offset) {
22369
+ return (source[offset + 3] +
22370
+ source[offset + 2] * 256 +
22371
+ source[offset + 1] * 65536 +
22372
+ source[offset] * 16777216);
22373
+ },
22374
+ getBigInt64LE(source, offset) {
22375
+ const hi = BigInt(source[offset + 4] +
22376
+ source[offset + 5] * 256 +
22377
+ source[offset + 6] * 65536 +
22378
+ (source[offset + 7] << 24));
22379
+ const lo = BigInt(source[offset] +
22380
+ source[offset + 1] * 256 +
22381
+ source[offset + 2] * 65536 +
22382
+ source[offset + 3] * 16777216);
22383
+ return (hi << BigInt(32)) + lo;
22384
+ },
22385
+ getFloat64LE: isBigEndian
22386
+ ? (source, offset) => {
22387
+ FLOAT_BYTES[7] = source[offset];
22388
+ FLOAT_BYTES[6] = source[offset + 1];
22389
+ FLOAT_BYTES[5] = source[offset + 2];
22390
+ FLOAT_BYTES[4] = source[offset + 3];
22391
+ FLOAT_BYTES[3] = source[offset + 4];
22392
+ FLOAT_BYTES[2] = source[offset + 5];
22393
+ FLOAT_BYTES[1] = source[offset + 6];
22394
+ FLOAT_BYTES[0] = source[offset + 7];
22395
+ return FLOAT[0];
22396
+ }
22397
+ : (source, offset) => {
22398
+ FLOAT_BYTES[0] = source[offset];
22399
+ FLOAT_BYTES[1] = source[offset + 1];
22400
+ FLOAT_BYTES[2] = source[offset + 2];
22401
+ FLOAT_BYTES[3] = source[offset + 3];
22402
+ FLOAT_BYTES[4] = source[offset + 4];
22403
+ FLOAT_BYTES[5] = source[offset + 5];
22404
+ FLOAT_BYTES[6] = source[offset + 6];
22405
+ FLOAT_BYTES[7] = source[offset + 7];
22406
+ return FLOAT[0];
22407
+ },
22408
+ setInt32BE(destination, offset, value) {
22409
+ destination[offset + 3] = value;
22410
+ value >>>= 8;
22411
+ destination[offset + 2] = value;
22412
+ value >>>= 8;
22413
+ destination[offset + 1] = value;
22414
+ value >>>= 8;
22415
+ destination[offset] = value;
22416
+ return 4;
22417
+ },
22418
+ setInt32LE(destination, offset, value) {
22419
+ destination[offset] = value;
22420
+ value >>>= 8;
22421
+ destination[offset + 1] = value;
22422
+ value >>>= 8;
22423
+ destination[offset + 2] = value;
22424
+ value >>>= 8;
22425
+ destination[offset + 3] = value;
22426
+ return 4;
22427
+ },
22428
+ setBigInt64LE(destination, offset, value) {
22429
+ const mask32bits = BigInt(0xffff_ffff);
22430
+ let lo = Number(value & mask32bits);
22431
+ destination[offset] = lo;
22432
+ lo >>= 8;
22433
+ destination[offset + 1] = lo;
22434
+ lo >>= 8;
22435
+ destination[offset + 2] = lo;
22436
+ lo >>= 8;
22437
+ destination[offset + 3] = lo;
22438
+ let hi = Number((value >> BigInt(32)) & mask32bits);
22439
+ destination[offset + 4] = hi;
22440
+ hi >>= 8;
22441
+ destination[offset + 5] = hi;
22442
+ hi >>= 8;
22443
+ destination[offset + 6] = hi;
22444
+ hi >>= 8;
22445
+ destination[offset + 7] = hi;
22446
+ return 8;
22447
+ },
22448
+ setFloat64LE: isBigEndian
22449
+ ? (destination, offset, value) => {
22450
+ FLOAT[0] = value;
22451
+ destination[offset] = FLOAT_BYTES[7];
22452
+ destination[offset + 1] = FLOAT_BYTES[6];
22453
+ destination[offset + 2] = FLOAT_BYTES[5];
22454
+ destination[offset + 3] = FLOAT_BYTES[4];
22455
+ destination[offset + 4] = FLOAT_BYTES[3];
22456
+ destination[offset + 5] = FLOAT_BYTES[2];
22457
+ destination[offset + 6] = FLOAT_BYTES[1];
22458
+ destination[offset + 7] = FLOAT_BYTES[0];
22459
+ return 8;
22460
+ }
22461
+ : (destination, offset, value) => {
22462
+ FLOAT[0] = value;
22463
+ destination[offset] = FLOAT_BYTES[0];
22464
+ destination[offset + 1] = FLOAT_BYTES[1];
22465
+ destination[offset + 2] = FLOAT_BYTES[2];
22466
+ destination[offset + 3] = FLOAT_BYTES[3];
22467
+ destination[offset + 4] = FLOAT_BYTES[4];
22468
+ destination[offset + 5] = FLOAT_BYTES[5];
22469
+ destination[offset + 6] = FLOAT_BYTES[6];
22470
+ destination[offset + 7] = FLOAT_BYTES[7];
22471
+ return 8;
22472
+ }
22473
+ };
22474
+
22475
+ class Binary extends BSONValue {
22476
+ get _bsontype() {
22477
+ return 'Binary';
22478
+ }
22479
+ constructor(buffer, subType) {
22480
+ super();
22481
+ if (!(buffer == null) &&
22482
+ typeof buffer === 'string' &&
22483
+ !ArrayBuffer.isView(buffer) &&
22484
+ !isAnyArrayBuffer(buffer) &&
22485
+ !Array.isArray(buffer)) {
22486
+ throw new BSONError('Binary can only be constructed from Uint8Array or number[]');
22487
+ }
22488
+ this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
22489
+ if (buffer == null) {
22490
+ this.buffer = ByteUtils.allocate(Binary.BUFFER_SIZE);
22491
+ this.position = 0;
22492
+ }
22493
+ else {
22494
+ this.buffer = Array.isArray(buffer)
22495
+ ? ByteUtils.fromNumberArray(buffer)
22496
+ : ByteUtils.toLocalBufferType(buffer);
22497
+ this.position = this.buffer.byteLength;
22498
+ }
22499
+ }
22500
+ put(byteValue) {
22501
+ if (typeof byteValue === 'string' && byteValue.length !== 1) {
22502
+ throw new BSONError('only accepts single character String');
22503
+ }
22504
+ else if (typeof byteValue !== 'number' && byteValue.length !== 1)
22505
+ throw new BSONError('only accepts single character Uint8Array or Array');
22506
+ let decodedByte;
22507
+ if (typeof byteValue === 'string') {
22508
+ decodedByte = byteValue.charCodeAt(0);
22509
+ }
22510
+ else if (typeof byteValue === 'number') {
22511
+ decodedByte = byteValue;
22512
+ }
22513
+ else {
22514
+ decodedByte = byteValue[0];
22515
+ }
22516
+ if (decodedByte < 0 || decodedByte > 255) {
22517
+ throw new BSONError('only accepts number in a valid unsigned byte range 0-255');
22518
+ }
22519
+ if (this.buffer.byteLength > this.position) {
22520
+ this.buffer[this.position++] = decodedByte;
22521
+ }
22522
+ else {
22523
+ const newSpace = ByteUtils.allocate(Binary.BUFFER_SIZE + this.buffer.length);
22524
+ newSpace.set(this.buffer, 0);
22525
+ this.buffer = newSpace;
22526
+ this.buffer[this.position++] = decodedByte;
22527
+ }
22528
+ }
22529
+ write(sequence, offset) {
22530
+ offset = typeof offset === 'number' ? offset : this.position;
22531
+ if (this.buffer.byteLength < offset + sequence.length) {
22532
+ const newSpace = ByteUtils.allocate(this.buffer.byteLength + sequence.length);
22533
+ newSpace.set(this.buffer, 0);
22534
+ this.buffer = newSpace;
22535
+ }
22536
+ if (ArrayBuffer.isView(sequence)) {
22537
+ this.buffer.set(ByteUtils.toLocalBufferType(sequence), offset);
22538
+ this.position =
22539
+ offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
22540
+ }
22541
+ else if (typeof sequence === 'string') {
22542
+ throw new BSONError('input cannot be string');
22543
+ }
22544
+ }
22545
+ read(position, length) {
22546
+ length = length && length > 0 ? length : this.position;
22547
+ const end = position + length;
22548
+ return this.buffer.subarray(position, end > this.position ? this.position : end);
22549
+ }
22550
+ value() {
22551
+ return this.buffer.length === this.position
22552
+ ? this.buffer
22553
+ : this.buffer.subarray(0, this.position);
22554
+ }
22555
+ length() {
22556
+ return this.position;
22557
+ }
22558
+ toJSON() {
22559
+ return ByteUtils.toBase64(this.buffer.subarray(0, this.position));
22560
+ }
22561
+ toString(encoding) {
22562
+ if (encoding === 'hex')
22563
+ return ByteUtils.toHex(this.buffer.subarray(0, this.position));
22564
+ if (encoding === 'base64')
22565
+ return ByteUtils.toBase64(this.buffer.subarray(0, this.position));
22566
+ if (encoding === 'utf8' || encoding === 'utf-8')
22567
+ return ByteUtils.toUTF8(this.buffer, 0, this.position, false);
22568
+ return ByteUtils.toUTF8(this.buffer, 0, this.position, false);
22569
+ }
22570
+ toExtendedJSON(options) {
22571
+ options = options || {};
22572
+ if (this.sub_type === Binary.SUBTYPE_VECTOR) {
22573
+ validateBinaryVector(this);
22574
+ }
22575
+ const base64String = ByteUtils.toBase64(this.buffer);
22576
+ const subType = Number(this.sub_type).toString(16);
22577
+ if (options.legacy) {
22578
+ return {
22579
+ $binary: base64String,
22580
+ $type: subType.length === 1 ? '0' + subType : subType
22581
+ };
22582
+ }
22583
+ return {
22584
+ $binary: {
22585
+ base64: base64String,
22586
+ subType: subType.length === 1 ? '0' + subType : subType
22587
+ }
22588
+ };
22589
+ }
22590
+ toUUID() {
22591
+ if (this.sub_type === Binary.SUBTYPE_UUID) {
22592
+ return new UUID(this.buffer.subarray(0, this.position));
22593
+ }
22594
+ throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`);
22595
+ }
22596
+ static createFromHexString(hex, subType) {
22597
+ return new Binary(ByteUtils.fromHex(hex), subType);
22598
+ }
22599
+ static createFromBase64(base64, subType) {
22600
+ return new Binary(ByteUtils.fromBase64(base64), subType);
22601
+ }
22602
+ static fromExtendedJSON(doc, options) {
22603
+ options = options || {};
22604
+ let data;
22605
+ let type;
22606
+ if ('$binary' in doc) {
22607
+ if (options.legacy && typeof doc.$binary === 'string' && '$type' in doc) {
22608
+ type = doc.$type ? parseInt(doc.$type, 16) : 0;
22609
+ data = ByteUtils.fromBase64(doc.$binary);
22610
+ }
22611
+ else {
22612
+ if (typeof doc.$binary !== 'string') {
22613
+ type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
22614
+ data = ByteUtils.fromBase64(doc.$binary.base64);
22615
+ }
22616
+ }
22617
+ }
22618
+ else if ('$uuid' in doc) {
22619
+ type = 4;
22620
+ data = UUID.bytesFromString(doc.$uuid);
22621
+ }
22622
+ if (!data) {
22623
+ throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
22624
+ }
22625
+ return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
22626
+ }
22627
+ inspect(depth, options, inspect) {
22628
+ inspect ??= defaultInspect;
22629
+ const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
22630
+ const base64Arg = inspect(base64, options);
22631
+ const subTypeArg = inspect(this.sub_type, options);
22632
+ return `Binary.createFromBase64(${base64Arg}, ${subTypeArg})`;
22633
+ }
22634
+ toInt8Array() {
22635
+ if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
22636
+ throw new BSONError('Binary sub_type is not Vector');
22637
+ }
22638
+ if (this.buffer[0] !== Binary.VECTOR_TYPE.Int8) {
22639
+ throw new BSONError('Binary datatype field is not Int8');
22640
+ }
22641
+ validateBinaryVector(this);
22642
+ return new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
22643
+ }
22644
+ toFloat32Array() {
22645
+ if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
22646
+ throw new BSONError('Binary sub_type is not Vector');
22647
+ }
22648
+ if (this.buffer[0] !== Binary.VECTOR_TYPE.Float32) {
22649
+ throw new BSONError('Binary datatype field is not Float32');
22650
+ }
22651
+ validateBinaryVector(this);
22652
+ const floatBytes = new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
22653
+ if (NumberUtils.isBigEndian)
22654
+ ByteUtils.swap32(floatBytes);
22655
+ return new Float32Array(floatBytes.buffer);
22656
+ }
22657
+ toPackedBits() {
22658
+ if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
22659
+ throw new BSONError('Binary sub_type is not Vector');
22660
+ }
22661
+ if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
22662
+ throw new BSONError('Binary datatype field is not packed bit');
22663
+ }
22664
+ validateBinaryVector(this);
22665
+ return new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
22666
+ }
22667
+ toBits() {
22668
+ if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
22669
+ throw new BSONError('Binary sub_type is not Vector');
22670
+ }
22671
+ if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
22672
+ throw new BSONError('Binary datatype field is not packed bit');
22673
+ }
22674
+ validateBinaryVector(this);
22675
+ const byteCount = this.length() - 2;
22676
+ const bitCount = byteCount * 8 - this.buffer[1];
22677
+ const bits = new Int8Array(bitCount);
22678
+ for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
22679
+ const byteOffset = (bitOffset / 8) | 0;
22680
+ const byte = this.buffer[byteOffset + 2];
22681
+ const shift = 7 - (bitOffset % 8);
22682
+ const bit = (byte >> shift) & 1;
22683
+ bits[bitOffset] = bit;
22684
+ }
22685
+ return bits;
22686
+ }
22687
+ static fromInt8Array(array) {
22688
+ const buffer = ByteUtils.allocate(array.byteLength + 2);
22689
+ buffer[0] = Binary.VECTOR_TYPE.Int8;
22690
+ buffer[1] = 0;
22691
+ const intBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
22692
+ buffer.set(intBytes, 2);
22693
+ const bin = new this(buffer, this.SUBTYPE_VECTOR);
22694
+ validateBinaryVector(bin);
22695
+ return bin;
22696
+ }
22697
+ static fromFloat32Array(array) {
22698
+ const binaryBytes = ByteUtils.allocate(array.byteLength + 2);
22699
+ binaryBytes[0] = Binary.VECTOR_TYPE.Float32;
22700
+ binaryBytes[1] = 0;
22701
+ const floatBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
22702
+ binaryBytes.set(floatBytes, 2);
22703
+ if (NumberUtils.isBigEndian)
22704
+ ByteUtils.swap32(new Uint8Array(binaryBytes.buffer, 2));
22705
+ const bin = new this(binaryBytes, this.SUBTYPE_VECTOR);
22706
+ validateBinaryVector(bin);
22707
+ return bin;
22708
+ }
22709
+ static fromPackedBits(array, padding = 0) {
22710
+ const buffer = ByteUtils.allocate(array.byteLength + 2);
22711
+ buffer[0] = Binary.VECTOR_TYPE.PackedBit;
22712
+ buffer[1] = padding;
22713
+ buffer.set(array, 2);
22714
+ const bin = new this(buffer, this.SUBTYPE_VECTOR);
22715
+ validateBinaryVector(bin);
22716
+ return bin;
22717
+ }
22718
+ static fromBits(bits) {
22719
+ const byteLength = (bits.length + 7) >>> 3;
22720
+ const bytes = new Uint8Array(byteLength + 2);
22721
+ bytes[0] = Binary.VECTOR_TYPE.PackedBit;
22722
+ const remainder = bits.length % 8;
22723
+ bytes[1] = remainder === 0 ? 0 : 8 - remainder;
22724
+ for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
22725
+ const byteOffset = bitOffset >>> 3;
22726
+ const bit = bits[bitOffset];
22727
+ if (bit !== 0 && bit !== 1) {
22728
+ throw new BSONError(`Invalid bit value at ${bitOffset}: must be 0 or 1, found ${bits[bitOffset]}`);
22729
+ }
22730
+ if (bit === 0)
22731
+ continue;
22732
+ const shift = 7 - (bitOffset % 8);
22733
+ bytes[byteOffset + 2] |= bit << shift;
22734
+ }
22735
+ return new this(bytes, Binary.SUBTYPE_VECTOR);
22736
+ }
22737
+ }
22738
+ Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
22739
+ Binary.BUFFER_SIZE = 256;
22740
+ Binary.SUBTYPE_DEFAULT = 0;
22741
+ Binary.SUBTYPE_FUNCTION = 1;
22742
+ Binary.SUBTYPE_BYTE_ARRAY = 2;
22743
+ Binary.SUBTYPE_UUID_OLD = 3;
22744
+ Binary.SUBTYPE_UUID = 4;
22745
+ Binary.SUBTYPE_MD5 = 5;
22746
+ Binary.SUBTYPE_ENCRYPTED = 6;
22747
+ Binary.SUBTYPE_COLUMN = 7;
22748
+ Binary.SUBTYPE_SENSITIVE = 8;
22749
+ Binary.SUBTYPE_VECTOR = 9;
22750
+ Binary.SUBTYPE_USER_DEFINED = 128;
22751
+ Binary.VECTOR_TYPE = Object.freeze({
22752
+ Int8: 0x03,
22753
+ Float32: 0x27,
22754
+ PackedBit: 0x10
22755
+ });
22756
+ function validateBinaryVector(vector) {
22757
+ if (vector.sub_type !== Binary.SUBTYPE_VECTOR)
22758
+ return;
22759
+ const size = vector.position;
22760
+ const datatype = vector.buffer[0];
22761
+ const padding = vector.buffer[1];
22762
+ if ((datatype === Binary.VECTOR_TYPE.Float32 || datatype === Binary.VECTOR_TYPE.Int8) &&
22763
+ padding !== 0) {
22764
+ throw new BSONError('Invalid Vector: padding must be zero for int8 and float32 vectors');
22765
+ }
22766
+ if (datatype === Binary.VECTOR_TYPE.Float32) {
22767
+ if (size !== 0 && size - 2 !== 0 && (size - 2) % 4 !== 0) {
22768
+ throw new BSONError('Invalid Vector: Float32 vector must contain a multiple of 4 bytes');
22769
+ }
22770
+ }
22771
+ if (datatype === Binary.VECTOR_TYPE.PackedBit && padding !== 0 && size === 2) {
22772
+ throw new BSONError('Invalid Vector: padding must be zero for packed bit vectors that are empty');
22773
+ }
22774
+ if (datatype === Binary.VECTOR_TYPE.PackedBit && padding > 7) {
22775
+ throw new BSONError(`Invalid Vector: padding must be a value between 0 and 7. found: ${padding}`);
22776
+ }
22777
+ }
22778
+ const UUID_BYTE_LENGTH = 16;
22779
+ const UUID_WITHOUT_DASHES = /^[0-9A-F]{32}$/i;
22780
+ const UUID_WITH_DASHES = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
22781
+ class UUID extends Binary {
22782
+ constructor(input) {
22783
+ let bytes;
22784
+ if (input == null) {
22785
+ bytes = UUID.generate();
22786
+ }
22787
+ else if (input instanceof UUID) {
22788
+ bytes = ByteUtils.toLocalBufferType(new Uint8Array(input.buffer));
22789
+ }
22790
+ else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
22791
+ bytes = ByteUtils.toLocalBufferType(input);
22792
+ }
22793
+ else if (typeof input === 'string') {
22794
+ bytes = UUID.bytesFromString(input);
22795
+ }
22796
+ else {
22797
+ throw new BSONError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
22798
+ }
22799
+ super(bytes, BSON_BINARY_SUBTYPE_UUID_NEW);
22800
+ }
22801
+ get id() {
22802
+ return this.buffer;
22803
+ }
22804
+ set id(value) {
22805
+ this.buffer = value;
22806
+ }
22807
+ toHexString(includeDashes = true) {
22808
+ if (includeDashes) {
22809
+ return [
22810
+ ByteUtils.toHex(this.buffer.subarray(0, 4)),
22811
+ ByteUtils.toHex(this.buffer.subarray(4, 6)),
22812
+ ByteUtils.toHex(this.buffer.subarray(6, 8)),
22813
+ ByteUtils.toHex(this.buffer.subarray(8, 10)),
22814
+ ByteUtils.toHex(this.buffer.subarray(10, 16))
22815
+ ].join('-');
22816
+ }
22817
+ return ByteUtils.toHex(this.buffer);
22818
+ }
22819
+ toString(encoding) {
22820
+ if (encoding === 'hex')
22821
+ return ByteUtils.toHex(this.id);
22822
+ if (encoding === 'base64')
22823
+ return ByteUtils.toBase64(this.id);
22824
+ return this.toHexString();
22825
+ }
22826
+ toJSON() {
22827
+ return this.toHexString();
22828
+ }
22829
+ equals(otherId) {
22830
+ if (!otherId) {
22831
+ return false;
22832
+ }
22833
+ if (otherId instanceof UUID) {
22834
+ return ByteUtils.equals(otherId.id, this.id);
22835
+ }
22836
+ try {
22837
+ return ByteUtils.equals(new UUID(otherId).id, this.id);
22838
+ }
22839
+ catch {
22840
+ return false;
22841
+ }
22842
+ }
22843
+ toBinary() {
22844
+ return new Binary(this.id, Binary.SUBTYPE_UUID);
22845
+ }
22846
+ static generate() {
22847
+ const bytes = ByteUtils.randomBytes(UUID_BYTE_LENGTH);
22848
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
22849
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
22850
+ return bytes;
22851
+ }
22852
+ static isValid(input) {
22853
+ if (!input) {
22854
+ return false;
22855
+ }
22856
+ if (typeof input === 'string') {
22857
+ return UUID.isValidUUIDString(input);
22858
+ }
22859
+ if (isUint8Array(input)) {
22860
+ return input.byteLength === UUID_BYTE_LENGTH;
22861
+ }
22862
+ return (input._bsontype === 'Binary' &&
22863
+ input.sub_type === this.SUBTYPE_UUID &&
22864
+ input.buffer.byteLength === 16);
22865
+ }
22866
+ static createFromHexString(hexString) {
22867
+ const buffer = UUID.bytesFromString(hexString);
22868
+ return new UUID(buffer);
22869
+ }
22870
+ static createFromBase64(base64) {
22871
+ return new UUID(ByteUtils.fromBase64(base64));
22872
+ }
22873
+ static bytesFromString(representation) {
22874
+ if (!UUID.isValidUUIDString(representation)) {
22875
+ throw new BSONError('UUID string representation must be 32 hex digits or canonical hyphenated representation');
22876
+ }
22877
+ return ByteUtils.fromHex(representation.replace(/-/g, ''));
22878
+ }
22879
+ static isValidUUIDString(representation) {
22880
+ return UUID_WITHOUT_DASHES.test(representation) || UUID_WITH_DASHES.test(representation);
22881
+ }
22882
+ inspect(depth, options, inspect) {
22883
+ inspect ??= defaultInspect;
22884
+ return `new UUID(${inspect(this.toHexString(), options)})`;
22885
+ }
22886
+ }
22887
+
22888
+ class Code extends BSONValue {
22889
+ get _bsontype() {
22890
+ return 'Code';
22891
+ }
22892
+ constructor(code, scope) {
22893
+ super();
22894
+ this.code = code.toString();
22895
+ this.scope = scope ?? null;
22896
+ }
22897
+ toJSON() {
22898
+ if (this.scope != null) {
22899
+ return { code: this.code, scope: this.scope };
22900
+ }
22901
+ return { code: this.code };
22902
+ }
22903
+ toExtendedJSON() {
22904
+ if (this.scope) {
22905
+ return { $code: this.code, $scope: this.scope };
22906
+ }
22907
+ return { $code: this.code };
22908
+ }
22909
+ static fromExtendedJSON(doc) {
22910
+ return new Code(doc.$code, doc.$scope);
22911
+ }
22912
+ inspect(depth, options, inspect) {
22913
+ inspect ??= defaultInspect;
22914
+ let parametersString = inspect(this.code, options);
22915
+ const multiLineFn = parametersString.includes('\n');
22916
+ if (this.scope != null) {
22917
+ parametersString += `,${multiLineFn ? '\n' : ' '}${inspect(this.scope, options)}`;
22918
+ }
22919
+ const endingNewline = multiLineFn && this.scope === null;
22920
+ return `new Code(${multiLineFn ? '\n' : ''}${parametersString}${endingNewline ? '\n' : ''})`;
22921
+ }
22922
+ }
22923
+
22924
+ function isDBRefLike(value) {
22925
+ return (value != null &&
22926
+ typeof value === 'object' &&
22927
+ '$id' in value &&
22928
+ value.$id != null &&
22929
+ '$ref' in value &&
22930
+ typeof value.$ref === 'string' &&
22931
+ (!('$db' in value) || ('$db' in value && typeof value.$db === 'string')));
22932
+ }
22933
+ class DBRef extends BSONValue {
22934
+ get _bsontype() {
22935
+ return 'DBRef';
22936
+ }
22937
+ constructor(collection, oid, db, fields) {
22938
+ super();
22939
+ const parts = collection.split('.');
22940
+ if (parts.length === 2) {
22941
+ db = parts.shift();
22942
+ collection = parts.shift();
22943
+ }
22944
+ this.collection = collection;
22945
+ this.oid = oid;
22946
+ this.db = db;
22947
+ this.fields = fields || {};
22948
+ }
22949
+ get namespace() {
22950
+ return this.collection;
22951
+ }
22952
+ set namespace(value) {
22953
+ this.collection = value;
22954
+ }
22955
+ toJSON() {
22956
+ const o = Object.assign({
22957
+ $ref: this.collection,
22958
+ $id: this.oid
22959
+ }, this.fields);
22960
+ if (this.db != null)
22961
+ o.$db = this.db;
22962
+ return o;
22963
+ }
22964
+ toExtendedJSON(options) {
22965
+ options = options || {};
22966
+ let o = {
22967
+ $ref: this.collection,
22968
+ $id: this.oid
22969
+ };
22970
+ if (options.legacy) {
22971
+ return o;
22972
+ }
22973
+ if (this.db)
22974
+ o.$db = this.db;
22975
+ o = Object.assign(o, this.fields);
22976
+ return o;
22977
+ }
22978
+ static fromExtendedJSON(doc) {
22979
+ const copy = Object.assign({}, doc);
22980
+ delete copy.$ref;
22981
+ delete copy.$id;
22982
+ delete copy.$db;
22983
+ return new DBRef(doc.$ref, doc.$id, doc.$db, copy);
22984
+ }
22985
+ inspect(depth, options, inspect) {
22986
+ inspect ??= defaultInspect;
22987
+ const args = [
22988
+ inspect(this.namespace, options),
22989
+ inspect(this.oid, options),
22990
+ ...(this.db ? [inspect(this.db, options)] : []),
22991
+ ...(Object.keys(this.fields).length > 0 ? [inspect(this.fields, options)] : [])
22992
+ ];
22993
+ args[1] = inspect === defaultInspect ? `new ObjectId(${args[1]})` : args[1];
22994
+ return `new DBRef(${args.join(', ')})`;
22995
+ }
22996
+ }
22997
+
22998
+ function removeLeadingZerosAndExplicitPlus(str) {
22999
+ if (str === '') {
23000
+ return str;
23001
+ }
23002
+ let startIndex = 0;
23003
+ const isNegative = str[startIndex] === '-';
23004
+ const isExplicitlyPositive = str[startIndex] === '+';
23005
+ if (isExplicitlyPositive || isNegative) {
23006
+ startIndex += 1;
23007
+ }
23008
+ let foundInsignificantZero = false;
23009
+ for (; startIndex < str.length && str[startIndex] === '0'; ++startIndex) {
23010
+ foundInsignificantZero = true;
23011
+ }
23012
+ if (!foundInsignificantZero) {
23013
+ return isExplicitlyPositive ? str.slice(1) : str;
23014
+ }
23015
+ return `${isNegative ? '-' : ''}${str.length === startIndex ? '0' : str.slice(startIndex)}`;
23016
+ }
23017
+ function validateStringCharacters(str, radix) {
23018
+ radix = radix ?? 10;
23019
+ const validCharacters = '0123456789abcdefghijklmnopqrstuvwxyz'.slice(0, radix);
23020
+ const regex = new RegExp(`[^-+${validCharacters}]`, 'i');
23021
+ return regex.test(str) ? false : str;
23022
+ }
23023
+
23024
+ let wasm = undefined;
23025
+ try {
23026
+ wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11])), {}).exports;
23027
+ }
23028
+ catch {
23029
+ }
23030
+ const TWO_PWR_16_DBL = 1 << 16;
23031
+ const TWO_PWR_24_DBL = 1 << 24;
23032
+ const TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
23033
+ const TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
23034
+ const TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
23035
+ const INT_CACHE = {};
23036
+ const UINT_CACHE = {};
23037
+ const MAX_INT64_STRING_LENGTH = 20;
23038
+ const DECIMAL_REG_EX = /^(\+?0|(\+|-)?[1-9][0-9]*)$/;
23039
+ class Long extends BSONValue {
23040
+ get _bsontype() {
23041
+ return 'Long';
23042
+ }
23043
+ get __isLong__() {
23044
+ return true;
23045
+ }
23046
+ constructor(lowOrValue = 0, highOrUnsigned, unsigned) {
23047
+ super();
23048
+ const unsignedBool = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : Boolean(unsigned);
23049
+ const high = typeof highOrUnsigned === 'number' ? highOrUnsigned : 0;
23050
+ const res = typeof lowOrValue === 'string'
23051
+ ? Long.fromString(lowOrValue, unsignedBool)
23052
+ : typeof lowOrValue === 'bigint'
23053
+ ? Long.fromBigInt(lowOrValue, unsignedBool)
23054
+ : { low: lowOrValue | 0, high: high | 0, unsigned: unsignedBool };
23055
+ this.low = res.low;
23056
+ this.high = res.high;
23057
+ this.unsigned = res.unsigned;
23058
+ }
23059
+ static fromBits(lowBits, highBits, unsigned) {
23060
+ return new Long(lowBits, highBits, unsigned);
23061
+ }
23062
+ static fromInt(value, unsigned) {
23063
+ let obj, cachedObj, cache;
23064
+ if (unsigned) {
23065
+ value >>>= 0;
23066
+ if ((cache = 0 <= value && value < 256)) {
23067
+ cachedObj = UINT_CACHE[value];
23068
+ if (cachedObj)
23069
+ return cachedObj;
23070
+ }
23071
+ obj = Long.fromBits(value, (value | 0) < 0 ? -1 : 0, true);
23072
+ if (cache)
23073
+ UINT_CACHE[value] = obj;
23074
+ return obj;
23075
+ }
23076
+ else {
23077
+ value |= 0;
23078
+ if ((cache = -128 <= value && value < 128)) {
23079
+ cachedObj = INT_CACHE[value];
23080
+ if (cachedObj)
23081
+ return cachedObj;
23082
+ }
23083
+ obj = Long.fromBits(value, value < 0 ? -1 : 0, false);
23084
+ if (cache)
23085
+ INT_CACHE[value] = obj;
23086
+ return obj;
23087
+ }
23088
+ }
23089
+ static fromNumber(value, unsigned) {
23090
+ if (isNaN(value))
23091
+ return unsigned ? Long.UZERO : Long.ZERO;
23092
+ if (unsigned) {
23093
+ if (value < 0)
23094
+ return Long.UZERO;
23095
+ if (value >= TWO_PWR_64_DBL)
23096
+ return Long.MAX_UNSIGNED_VALUE;
23097
+ }
23098
+ else {
23099
+ if (value <= -9223372036854776e3)
23100
+ return Long.MIN_VALUE;
23101
+ if (value + 1 >= TWO_PWR_63_DBL)
23102
+ return Long.MAX_VALUE;
23103
+ }
23104
+ if (value < 0)
23105
+ return Long.fromNumber(-value, unsigned).neg();
23106
+ return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
23107
+ }
23108
+ static fromBigInt(value, unsigned) {
23109
+ const FROM_BIGINT_BIT_MASK = BigInt(0xffffffff);
23110
+ const FROM_BIGINT_BIT_SHIFT = BigInt(32);
23111
+ return new Long(Number(value & FROM_BIGINT_BIT_MASK), Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK), unsigned);
23112
+ }
23113
+ static _fromString(str, unsigned, radix) {
23114
+ if (str.length === 0)
23115
+ throw new BSONError('empty string');
23116
+ if (radix < 2 || 36 < radix)
23117
+ throw new BSONError('radix');
23118
+ let p;
23119
+ if ((p = str.indexOf('-')) > 0)
23120
+ throw new BSONError('interior hyphen');
23121
+ else if (p === 0) {
23122
+ return Long._fromString(str.substring(1), unsigned, radix).neg();
23123
+ }
23124
+ const radixToPower = Long.fromNumber(Math.pow(radix, 8));
23125
+ let result = Long.ZERO;
23126
+ for (let i = 0; i < str.length; i += 8) {
23127
+ const size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
23128
+ if (size < 8) {
23129
+ const power = Long.fromNumber(Math.pow(radix, size));
23130
+ result = result.mul(power).add(Long.fromNumber(value));
23131
+ }
23132
+ else {
23133
+ result = result.mul(radixToPower);
23134
+ result = result.add(Long.fromNumber(value));
23135
+ }
23136
+ }
23137
+ result.unsigned = unsigned;
23138
+ return result;
23139
+ }
23140
+ static fromStringStrict(str, unsignedOrRadix, radix) {
23141
+ let unsigned = false;
23142
+ if (typeof unsignedOrRadix === 'number') {
23143
+ (radix = unsignedOrRadix), (unsignedOrRadix = false);
23144
+ }
23145
+ else {
23146
+ unsigned = !!unsignedOrRadix;
23147
+ }
23148
+ radix ??= 10;
23149
+ if (str.trim() !== str) {
23150
+ throw new BSONError(`Input: '${str}' contains leading and/or trailing whitespace`);
23151
+ }
23152
+ if (!validateStringCharacters(str, radix)) {
23153
+ throw new BSONError(`Input: '${str}' contains invalid characters for radix: ${radix}`);
23154
+ }
23155
+ const cleanedStr = removeLeadingZerosAndExplicitPlus(str);
23156
+ const result = Long._fromString(cleanedStr, unsigned, radix);
23157
+ if (result.toString(radix).toLowerCase() !== cleanedStr.toLowerCase()) {
23158
+ throw new BSONError(`Input: ${str} is not representable as ${result.unsigned ? 'an unsigned' : 'a signed'} 64-bit Long ${radix != null ? `with radix: ${radix}` : ''}`);
23159
+ }
23160
+ return result;
23161
+ }
23162
+ static fromString(str, unsignedOrRadix, radix) {
23163
+ let unsigned = false;
23164
+ if (typeof unsignedOrRadix === 'number') {
23165
+ (radix = unsignedOrRadix), (unsignedOrRadix = false);
23166
+ }
23167
+ else {
23168
+ unsigned = !!unsignedOrRadix;
23169
+ }
23170
+ radix ??= 10;
23171
+ if (str === 'NaN' && radix < 24) {
23172
+ return Long.ZERO;
23173
+ }
23174
+ else if ((str === 'Infinity' || str === '+Infinity' || str === '-Infinity') && radix < 35) {
23175
+ return Long.ZERO;
23176
+ }
23177
+ return Long._fromString(str, unsigned, radix);
23178
+ }
23179
+ static fromBytes(bytes, unsigned, le) {
23180
+ return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
23181
+ }
23182
+ static fromBytesLE(bytes, unsigned) {
23183
+ return new Long(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24), bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24), unsigned);
23184
+ }
23185
+ static fromBytesBE(bytes, unsigned) {
23186
+ return new Long((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7], (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3], unsigned);
23187
+ }
23188
+ static isLong(value) {
23189
+ return (value != null &&
23190
+ typeof value === 'object' &&
23191
+ '__isLong__' in value &&
23192
+ value.__isLong__ === true);
23193
+ }
23194
+ static fromValue(val, unsigned) {
23195
+ if (typeof val === 'number')
23196
+ return Long.fromNumber(val, unsigned);
23197
+ if (typeof val === 'string')
23198
+ return Long.fromString(val, unsigned);
23199
+ return Long.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
23200
+ }
23201
+ add(addend) {
23202
+ if (!Long.isLong(addend))
23203
+ addend = Long.fromValue(addend);
23204
+ const a48 = this.high >>> 16;
23205
+ const a32 = this.high & 0xffff;
23206
+ const a16 = this.low >>> 16;
23207
+ const a00 = this.low & 0xffff;
23208
+ const b48 = addend.high >>> 16;
23209
+ const b32 = addend.high & 0xffff;
23210
+ const b16 = addend.low >>> 16;
23211
+ const b00 = addend.low & 0xffff;
23212
+ let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
23213
+ c00 += a00 + b00;
23214
+ c16 += c00 >>> 16;
23215
+ c00 &= 0xffff;
23216
+ c16 += a16 + b16;
23217
+ c32 += c16 >>> 16;
23218
+ c16 &= 0xffff;
23219
+ c32 += a32 + b32;
23220
+ c48 += c32 >>> 16;
23221
+ c32 &= 0xffff;
23222
+ c48 += a48 + b48;
23223
+ c48 &= 0xffff;
23224
+ return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
23225
+ }
23226
+ and(other) {
23227
+ if (!Long.isLong(other))
23228
+ other = Long.fromValue(other);
23229
+ return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
23230
+ }
23231
+ compare(other) {
23232
+ if (!Long.isLong(other))
23233
+ other = Long.fromValue(other);
23234
+ if (this.eq(other))
23235
+ return 0;
23236
+ const thisNeg = this.isNegative(), otherNeg = other.isNegative();
23237
+ if (thisNeg && !otherNeg)
23238
+ return -1;
23239
+ if (!thisNeg && otherNeg)
23240
+ return 1;
23241
+ if (!this.unsigned)
23242
+ return this.sub(other).isNegative() ? -1 : 1;
23243
+ return other.high >>> 0 > this.high >>> 0 ||
23244
+ (other.high === this.high && other.low >>> 0 > this.low >>> 0)
23245
+ ? -1
23246
+ : 1;
23247
+ }
23248
+ comp(other) {
23249
+ return this.compare(other);
23250
+ }
23251
+ divide(divisor) {
23252
+ if (!Long.isLong(divisor))
23253
+ divisor = Long.fromValue(divisor);
23254
+ if (divisor.isZero())
23255
+ throw new BSONError('division by zero');
23256
+ if (wasm) {
23257
+ if (!this.unsigned &&
23258
+ this.high === -2147483648 &&
23259
+ divisor.low === -1 &&
23260
+ divisor.high === -1) {
23261
+ return this;
23262
+ }
23263
+ const low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
23264
+ return Long.fromBits(low, wasm.get_high(), this.unsigned);
23265
+ }
23266
+ if (this.isZero())
23267
+ return this.unsigned ? Long.UZERO : Long.ZERO;
23268
+ let approx, rem, res;
23269
+ if (!this.unsigned) {
23270
+ if (this.eq(Long.MIN_VALUE)) {
23271
+ if (divisor.eq(Long.ONE) || divisor.eq(Long.NEG_ONE))
23272
+ return Long.MIN_VALUE;
23273
+ else if (divisor.eq(Long.MIN_VALUE))
23274
+ return Long.ONE;
23275
+ else {
23276
+ const halfThis = this.shr(1);
23277
+ approx = halfThis.div(divisor).shl(1);
23278
+ if (approx.eq(Long.ZERO)) {
23279
+ return divisor.isNegative() ? Long.ONE : Long.NEG_ONE;
23280
+ }
23281
+ else {
23282
+ rem = this.sub(divisor.mul(approx));
23283
+ res = approx.add(rem.div(divisor));
23284
+ return res;
23285
+ }
23286
+ }
23287
+ }
23288
+ else if (divisor.eq(Long.MIN_VALUE))
23289
+ return this.unsigned ? Long.UZERO : Long.ZERO;
23290
+ if (this.isNegative()) {
23291
+ if (divisor.isNegative())
23292
+ return this.neg().div(divisor.neg());
23293
+ return this.neg().div(divisor).neg();
23294
+ }
23295
+ else if (divisor.isNegative())
23296
+ return this.div(divisor.neg()).neg();
23297
+ res = Long.ZERO;
23298
+ }
23299
+ else {
23300
+ if (!divisor.unsigned)
23301
+ divisor = divisor.toUnsigned();
23302
+ if (divisor.gt(this))
23303
+ return Long.UZERO;
23304
+ if (divisor.gt(this.shru(1)))
23305
+ return Long.UONE;
23306
+ res = Long.UZERO;
23307
+ }
23308
+ rem = this;
23309
+ while (rem.gte(divisor)) {
23310
+ approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
23311
+ const log2 = Math.ceil(Math.log(approx) / Math.LN2);
23312
+ const delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48);
23313
+ let approxRes = Long.fromNumber(approx);
23314
+ let approxRem = approxRes.mul(divisor);
23315
+ while (approxRem.isNegative() || approxRem.gt(rem)) {
23316
+ approx -= delta;
23317
+ approxRes = Long.fromNumber(approx, this.unsigned);
23318
+ approxRem = approxRes.mul(divisor);
23319
+ }
23320
+ if (approxRes.isZero())
23321
+ approxRes = Long.ONE;
23322
+ res = res.add(approxRes);
23323
+ rem = rem.sub(approxRem);
23324
+ }
23325
+ return res;
23326
+ }
23327
+ div(divisor) {
23328
+ return this.divide(divisor);
23329
+ }
23330
+ equals(other) {
23331
+ if (!Long.isLong(other))
23332
+ other = Long.fromValue(other);
23333
+ if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
23334
+ return false;
23335
+ return this.high === other.high && this.low === other.low;
23336
+ }
23337
+ eq(other) {
23338
+ return this.equals(other);
23339
+ }
23340
+ getHighBits() {
23341
+ return this.high;
23342
+ }
23343
+ getHighBitsUnsigned() {
23344
+ return this.high >>> 0;
23345
+ }
23346
+ getLowBits() {
23347
+ return this.low;
23348
+ }
23349
+ getLowBitsUnsigned() {
23350
+ return this.low >>> 0;
23351
+ }
23352
+ getNumBitsAbs() {
23353
+ if (this.isNegative()) {
23354
+ return this.eq(Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
23355
+ }
23356
+ const val = this.high !== 0 ? this.high : this.low;
23357
+ let bit;
23358
+ for (bit = 31; bit > 0; bit--)
23359
+ if ((val & (1 << bit)) !== 0)
23360
+ break;
23361
+ return this.high !== 0 ? bit + 33 : bit + 1;
23362
+ }
23363
+ greaterThan(other) {
23364
+ return this.comp(other) > 0;
23365
+ }
23366
+ gt(other) {
23367
+ return this.greaterThan(other);
23368
+ }
23369
+ greaterThanOrEqual(other) {
23370
+ return this.comp(other) >= 0;
23371
+ }
23372
+ gte(other) {
23373
+ return this.greaterThanOrEqual(other);
23374
+ }
23375
+ ge(other) {
23376
+ return this.greaterThanOrEqual(other);
23377
+ }
23378
+ isEven() {
23379
+ return (this.low & 1) === 0;
23380
+ }
23381
+ isNegative() {
23382
+ return !this.unsigned && this.high < 0;
23383
+ }
23384
+ isOdd() {
23385
+ return (this.low & 1) === 1;
23386
+ }
23387
+ isPositive() {
23388
+ return this.unsigned || this.high >= 0;
23389
+ }
23390
+ isZero() {
23391
+ return this.high === 0 && this.low === 0;
23392
+ }
23393
+ lessThan(other) {
23394
+ return this.comp(other) < 0;
23395
+ }
23396
+ lt(other) {
23397
+ return this.lessThan(other);
23398
+ }
23399
+ lessThanOrEqual(other) {
23400
+ return this.comp(other) <= 0;
23401
+ }
23402
+ lte(other) {
23403
+ return this.lessThanOrEqual(other);
23404
+ }
23405
+ modulo(divisor) {
23406
+ if (!Long.isLong(divisor))
23407
+ divisor = Long.fromValue(divisor);
23408
+ if (wasm) {
23409
+ const low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
23410
+ return Long.fromBits(low, wasm.get_high(), this.unsigned);
23411
+ }
23412
+ return this.sub(this.div(divisor).mul(divisor));
23413
+ }
23414
+ mod(divisor) {
23415
+ return this.modulo(divisor);
23416
+ }
23417
+ rem(divisor) {
23418
+ return this.modulo(divisor);
23419
+ }
23420
+ multiply(multiplier) {
23421
+ if (this.isZero())
23422
+ return Long.ZERO;
23423
+ if (!Long.isLong(multiplier))
23424
+ multiplier = Long.fromValue(multiplier);
23425
+ if (wasm) {
23426
+ const low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
23427
+ return Long.fromBits(low, wasm.get_high(), this.unsigned);
23428
+ }
23429
+ if (multiplier.isZero())
23430
+ return Long.ZERO;
23431
+ if (this.eq(Long.MIN_VALUE))
23432
+ return multiplier.isOdd() ? Long.MIN_VALUE : Long.ZERO;
23433
+ if (multiplier.eq(Long.MIN_VALUE))
23434
+ return this.isOdd() ? Long.MIN_VALUE : Long.ZERO;
23435
+ if (this.isNegative()) {
23436
+ if (multiplier.isNegative())
23437
+ return this.neg().mul(multiplier.neg());
23438
+ else
23439
+ return this.neg().mul(multiplier).neg();
23440
+ }
23441
+ else if (multiplier.isNegative())
23442
+ return this.mul(multiplier.neg()).neg();
23443
+ if (this.lt(Long.TWO_PWR_24) && multiplier.lt(Long.TWO_PWR_24))
23444
+ return Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
23445
+ const a48 = this.high >>> 16;
23446
+ const a32 = this.high & 0xffff;
23447
+ const a16 = this.low >>> 16;
23448
+ const a00 = this.low & 0xffff;
23449
+ const b48 = multiplier.high >>> 16;
23450
+ const b32 = multiplier.high & 0xffff;
23451
+ const b16 = multiplier.low >>> 16;
23452
+ const b00 = multiplier.low & 0xffff;
23453
+ let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
23454
+ c00 += a00 * b00;
23455
+ c16 += c00 >>> 16;
23456
+ c00 &= 0xffff;
23457
+ c16 += a16 * b00;
23458
+ c32 += c16 >>> 16;
23459
+ c16 &= 0xffff;
23460
+ c16 += a00 * b16;
23461
+ c32 += c16 >>> 16;
23462
+ c16 &= 0xffff;
23463
+ c32 += a32 * b00;
23464
+ c48 += c32 >>> 16;
23465
+ c32 &= 0xffff;
23466
+ c32 += a16 * b16;
23467
+ c48 += c32 >>> 16;
23468
+ c32 &= 0xffff;
23469
+ c32 += a00 * b32;
23470
+ c48 += c32 >>> 16;
23471
+ c32 &= 0xffff;
23472
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
23473
+ c48 &= 0xffff;
23474
+ return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
23475
+ }
23476
+ mul(multiplier) {
23477
+ return this.multiply(multiplier);
23478
+ }
23479
+ negate() {
23480
+ if (!this.unsigned && this.eq(Long.MIN_VALUE))
23481
+ return Long.MIN_VALUE;
23482
+ return this.not().add(Long.ONE);
23483
+ }
23484
+ neg() {
23485
+ return this.negate();
23486
+ }
23487
+ not() {
23488
+ return Long.fromBits(~this.low, ~this.high, this.unsigned);
23489
+ }
23490
+ notEquals(other) {
23491
+ return !this.equals(other);
23492
+ }
23493
+ neq(other) {
23494
+ return this.notEquals(other);
23495
+ }
23496
+ ne(other) {
23497
+ return this.notEquals(other);
23498
+ }
23499
+ or(other) {
23500
+ if (!Long.isLong(other))
23501
+ other = Long.fromValue(other);
23502
+ return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
23503
+ }
23504
+ shiftLeft(numBits) {
23505
+ if (Long.isLong(numBits))
23506
+ numBits = numBits.toInt();
23507
+ if ((numBits &= 63) === 0)
23508
+ return this;
23509
+ else if (numBits < 32)
23510
+ return Long.fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
23511
+ else
23512
+ return Long.fromBits(0, this.low << (numBits - 32), this.unsigned);
23513
+ }
23514
+ shl(numBits) {
23515
+ return this.shiftLeft(numBits);
23516
+ }
23517
+ shiftRight(numBits) {
23518
+ if (Long.isLong(numBits))
23519
+ numBits = numBits.toInt();
23520
+ if ((numBits &= 63) === 0)
23521
+ return this;
23522
+ else if (numBits < 32)
23523
+ return Long.fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
23524
+ else
23525
+ return Long.fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
23526
+ }
23527
+ shr(numBits) {
23528
+ return this.shiftRight(numBits);
23529
+ }
23530
+ shiftRightUnsigned(numBits) {
23531
+ if (Long.isLong(numBits))
23532
+ numBits = numBits.toInt();
23533
+ numBits &= 63;
23534
+ if (numBits === 0)
23535
+ return this;
23536
+ else {
23537
+ const high = this.high;
23538
+ if (numBits < 32) {
23539
+ const low = this.low;
23540
+ return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
23541
+ }
23542
+ else if (numBits === 32)
23543
+ return Long.fromBits(high, 0, this.unsigned);
23544
+ else
23545
+ return Long.fromBits(high >>> (numBits - 32), 0, this.unsigned);
23546
+ }
23547
+ }
23548
+ shr_u(numBits) {
23549
+ return this.shiftRightUnsigned(numBits);
23550
+ }
23551
+ shru(numBits) {
23552
+ return this.shiftRightUnsigned(numBits);
23553
+ }
23554
+ subtract(subtrahend) {
23555
+ if (!Long.isLong(subtrahend))
23556
+ subtrahend = Long.fromValue(subtrahend);
23557
+ return this.add(subtrahend.neg());
23558
+ }
23559
+ sub(subtrahend) {
23560
+ return this.subtract(subtrahend);
23561
+ }
23562
+ toInt() {
23563
+ return this.unsigned ? this.low >>> 0 : this.low;
23564
+ }
23565
+ toNumber() {
23566
+ if (this.unsigned)
23567
+ return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
23568
+ return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
23569
+ }
23570
+ toBigInt() {
23571
+ return BigInt(this.toString());
23572
+ }
23573
+ toBytes(le) {
23574
+ return le ? this.toBytesLE() : this.toBytesBE();
23575
+ }
23576
+ toBytesLE() {
23577
+ const hi = this.high, lo = this.low;
23578
+ return [
23579
+ lo & 0xff,
23580
+ (lo >>> 8) & 0xff,
23581
+ (lo >>> 16) & 0xff,
23582
+ lo >>> 24,
23583
+ hi & 0xff,
23584
+ (hi >>> 8) & 0xff,
23585
+ (hi >>> 16) & 0xff,
23586
+ hi >>> 24
23587
+ ];
23588
+ }
23589
+ toBytesBE() {
23590
+ const hi = this.high, lo = this.low;
23591
+ return [
23592
+ hi >>> 24,
23593
+ (hi >>> 16) & 0xff,
23594
+ (hi >>> 8) & 0xff,
23595
+ hi & 0xff,
23596
+ lo >>> 24,
23597
+ (lo >>> 16) & 0xff,
23598
+ (lo >>> 8) & 0xff,
23599
+ lo & 0xff
23600
+ ];
23601
+ }
23602
+ toSigned() {
23603
+ if (!this.unsigned)
23604
+ return this;
23605
+ return Long.fromBits(this.low, this.high, false);
23606
+ }
23607
+ toString(radix) {
23608
+ radix = radix || 10;
23609
+ if (radix < 2 || 36 < radix)
23610
+ throw new BSONError('radix');
23611
+ if (this.isZero())
23612
+ return '0';
23613
+ if (this.isNegative()) {
23614
+ if (this.eq(Long.MIN_VALUE)) {
23615
+ const radixLong = Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
23616
+ return div.toString(radix) + rem1.toInt().toString(radix);
23617
+ }
23618
+ else
23619
+ return '-' + this.neg().toString(radix);
23620
+ }
23621
+ const radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned);
23622
+ let rem = this;
23623
+ let result = '';
23624
+ while (true) {
23625
+ const remDiv = rem.div(radixToPower);
23626
+ const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
23627
+ let digits = intval.toString(radix);
23628
+ rem = remDiv;
23629
+ if (rem.isZero()) {
23630
+ return digits + result;
23631
+ }
23632
+ else {
23633
+ while (digits.length < 6)
23634
+ digits = '0' + digits;
23635
+ result = '' + digits + result;
23636
+ }
23637
+ }
23638
+ }
23639
+ toUnsigned() {
23640
+ if (this.unsigned)
23641
+ return this;
23642
+ return Long.fromBits(this.low, this.high, true);
23643
+ }
23644
+ xor(other) {
23645
+ if (!Long.isLong(other))
23646
+ other = Long.fromValue(other);
23647
+ return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
23648
+ }
23649
+ eqz() {
23650
+ return this.isZero();
23651
+ }
23652
+ le(other) {
23653
+ return this.lessThanOrEqual(other);
23654
+ }
23655
+ toExtendedJSON(options) {
23656
+ if (options && options.relaxed)
23657
+ return this.toNumber();
23658
+ return { $numberLong: this.toString() };
23659
+ }
23660
+ static fromExtendedJSON(doc, options) {
23661
+ const { useBigInt64 = false, relaxed = true } = { ...options };
23662
+ if (doc.$numberLong.length > MAX_INT64_STRING_LENGTH) {
23663
+ throw new BSONError('$numberLong string is too long');
23664
+ }
23665
+ if (!DECIMAL_REG_EX.test(doc.$numberLong)) {
23666
+ throw new BSONError(`$numberLong string "${doc.$numberLong}" is in an invalid format`);
23667
+ }
23668
+ if (useBigInt64) {
23669
+ const bigIntResult = BigInt(doc.$numberLong);
23670
+ return BigInt.asIntN(64, bigIntResult);
23671
+ }
23672
+ const longResult = Long.fromString(doc.$numberLong);
23673
+ if (relaxed) {
23674
+ return longResult.toNumber();
23675
+ }
23676
+ return longResult;
23677
+ }
23678
+ inspect(depth, options, inspect) {
23679
+ inspect ??= defaultInspect;
23680
+ const longVal = inspect(this.toString(), options);
23681
+ const unsignedVal = this.unsigned ? `, ${inspect(this.unsigned, options)}` : '';
23682
+ return `new Long(${longVal}${unsignedVal})`;
23683
+ }
23684
+ }
23685
+ Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
23686
+ Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
23687
+ Long.ZERO = Long.fromInt(0);
23688
+ Long.UZERO = Long.fromInt(0, true);
23689
+ Long.ONE = Long.fromInt(1);
23690
+ Long.UONE = Long.fromInt(1, true);
23691
+ Long.NEG_ONE = Long.fromInt(-1);
23692
+ Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
23693
+ Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
23694
+
23695
+ const PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
23696
+ const PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
23697
+ const PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
23698
+ const EXPONENT_MAX = 6111;
23699
+ const EXPONENT_MIN = -6176;
23700
+ const EXPONENT_BIAS = 6176;
23701
+ const MAX_DIGITS = 34;
23702
+ const NAN_BUFFER = ByteUtils.fromNumberArray([
23703
+ 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
23704
+ ].reverse());
23705
+ const INF_NEGATIVE_BUFFER = ByteUtils.fromNumberArray([
23706
+ 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
23707
+ ].reverse());
23708
+ const INF_POSITIVE_BUFFER = ByteUtils.fromNumberArray([
23709
+ 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
23710
+ ].reverse());
23711
+ const EXPONENT_REGEX = /^([-+])?(\d+)?$/;
23712
+ const COMBINATION_MASK = 0x1f;
23713
+ const EXPONENT_MASK = 0x3fff;
23714
+ const COMBINATION_INFINITY = 30;
23715
+ const COMBINATION_NAN = 31;
23716
+ function isDigit(value) {
23717
+ return !isNaN(parseInt(value, 10));
23718
+ }
23719
+ function divideu128(value) {
23720
+ const DIVISOR = Long.fromNumber(1000 * 1000 * 1000);
23721
+ let _rem = Long.fromNumber(0);
23722
+ if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
23723
+ return { quotient: value, rem: _rem };
23724
+ }
23725
+ for (let i = 0; i <= 3; i++) {
23726
+ _rem = _rem.shiftLeft(32);
23727
+ _rem = _rem.add(new Long(value.parts[i], 0));
23728
+ value.parts[i] = _rem.div(DIVISOR).low;
23729
+ _rem = _rem.modulo(DIVISOR);
23730
+ }
23731
+ return { quotient: value, rem: _rem };
23732
+ }
23733
+ function multiply64x2(left, right) {
23734
+ if (!left && !right) {
23735
+ return { high: Long.fromNumber(0), low: Long.fromNumber(0) };
23736
+ }
23737
+ const leftHigh = left.shiftRightUnsigned(32);
23738
+ const leftLow = new Long(left.getLowBits(), 0);
23739
+ const rightHigh = right.shiftRightUnsigned(32);
23740
+ const rightLow = new Long(right.getLowBits(), 0);
23741
+ let productHigh = leftHigh.multiply(rightHigh);
23742
+ let productMid = leftHigh.multiply(rightLow);
23743
+ const productMid2 = leftLow.multiply(rightHigh);
23744
+ let productLow = leftLow.multiply(rightLow);
23745
+ productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
23746
+ productMid = new Long(productMid.getLowBits(), 0)
23747
+ .add(productMid2)
23748
+ .add(productLow.shiftRightUnsigned(32));
23749
+ productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
23750
+ productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0));
23751
+ return { high: productHigh, low: productLow };
23752
+ }
23753
+ function lessThan(left, right) {
23754
+ const uhleft = left.high >>> 0;
23755
+ const uhright = right.high >>> 0;
23756
+ if (uhleft < uhright) {
23757
+ return true;
23758
+ }
23759
+ else if (uhleft === uhright) {
23760
+ const ulleft = left.low >>> 0;
23761
+ const ulright = right.low >>> 0;
23762
+ if (ulleft < ulright)
23763
+ return true;
23764
+ }
23765
+ return false;
23766
+ }
23767
+ function invalidErr(string, message) {
23768
+ throw new BSONError(`"${string}" is not a valid Decimal128 string - ${message}`);
23769
+ }
23770
+ class Decimal128 extends BSONValue {
23771
+ get _bsontype() {
23772
+ return 'Decimal128';
23773
+ }
23774
+ constructor(bytes) {
23775
+ super();
23776
+ if (typeof bytes === 'string') {
23777
+ this.bytes = Decimal128.fromString(bytes).bytes;
23778
+ }
23779
+ else if (bytes instanceof Uint8Array || isUint8Array(bytes)) {
23780
+ if (bytes.byteLength !== 16) {
23781
+ throw new BSONError('Decimal128 must take a Buffer of 16 bytes');
23782
+ }
23783
+ this.bytes = bytes;
23784
+ }
23785
+ else {
23786
+ throw new BSONError('Decimal128 must take a Buffer or string');
23787
+ }
23788
+ }
23789
+ static fromString(representation) {
23790
+ return Decimal128._fromString(representation, { allowRounding: false });
23791
+ }
23792
+ static fromStringWithRounding(representation) {
23793
+ return Decimal128._fromString(representation, { allowRounding: true });
23794
+ }
23795
+ static _fromString(representation, options) {
23796
+ let isNegative = false;
23797
+ let sawSign = false;
23798
+ let sawRadix = false;
23799
+ let foundNonZero = false;
23800
+ let significantDigits = 0;
23801
+ let nDigitsRead = 0;
23802
+ let nDigits = 0;
23803
+ let radixPosition = 0;
23804
+ let firstNonZero = 0;
23805
+ const digits = [0];
23806
+ let nDigitsStored = 0;
23807
+ let digitsInsert = 0;
23808
+ let lastDigit = 0;
23809
+ let exponent = 0;
23810
+ let significandHigh = new Long(0, 0);
23811
+ let significandLow = new Long(0, 0);
23812
+ let biasedExponent = 0;
23813
+ let index = 0;
23814
+ if (representation.length >= 7000) {
23815
+ throw new BSONError('' + representation + ' not a valid Decimal128 string');
23816
+ }
23817
+ const stringMatch = representation.match(PARSE_STRING_REGEXP);
23818
+ const infMatch = representation.match(PARSE_INF_REGEXP);
23819
+ const nanMatch = representation.match(PARSE_NAN_REGEXP);
23820
+ if ((!stringMatch && !infMatch && !nanMatch) || representation.length === 0) {
23821
+ throw new BSONError('' + representation + ' not a valid Decimal128 string');
23822
+ }
23823
+ if (stringMatch) {
23824
+ const unsignedNumber = stringMatch[2];
23825
+ const e = stringMatch[4];
23826
+ const expSign = stringMatch[5];
23827
+ const expNumber = stringMatch[6];
23828
+ if (e && expNumber === undefined)
23829
+ invalidErr(representation, 'missing exponent power');
23830
+ if (e && unsignedNumber === undefined)
23831
+ invalidErr(representation, 'missing exponent base');
23832
+ if (e === undefined && (expSign || expNumber)) {
23833
+ invalidErr(representation, 'missing e before exponent');
23834
+ }
23835
+ }
23836
+ if (representation[index] === '+' || representation[index] === '-') {
23837
+ sawSign = true;
23838
+ isNegative = representation[index++] === '-';
23839
+ }
23840
+ if (!isDigit(representation[index]) && representation[index] !== '.') {
23841
+ if (representation[index] === 'i' || representation[index] === 'I') {
23842
+ return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
23843
+ }
23844
+ else if (representation[index] === 'N') {
23845
+ return new Decimal128(NAN_BUFFER);
23846
+ }
23847
+ }
23848
+ while (isDigit(representation[index]) || representation[index] === '.') {
23849
+ if (representation[index] === '.') {
23850
+ if (sawRadix)
23851
+ invalidErr(representation, 'contains multiple periods');
23852
+ sawRadix = true;
23853
+ index = index + 1;
23854
+ continue;
23855
+ }
23856
+ if (nDigitsStored < MAX_DIGITS) {
23857
+ if (representation[index] !== '0' || foundNonZero) {
23858
+ if (!foundNonZero) {
23859
+ firstNonZero = nDigitsRead;
23860
+ }
23861
+ foundNonZero = true;
23862
+ digits[digitsInsert++] = parseInt(representation[index], 10);
23863
+ nDigitsStored = nDigitsStored + 1;
23864
+ }
23865
+ }
23866
+ if (foundNonZero)
23867
+ nDigits = nDigits + 1;
23868
+ if (sawRadix)
23869
+ radixPosition = radixPosition + 1;
23870
+ nDigitsRead = nDigitsRead + 1;
23871
+ index = index + 1;
23872
+ }
23873
+ if (sawRadix && !nDigitsRead)
23874
+ throw new BSONError('' + representation + ' not a valid Decimal128 string');
23875
+ if (representation[index] === 'e' || representation[index] === 'E') {
23876
+ const match = representation.substr(++index).match(EXPONENT_REGEX);
23877
+ if (!match || !match[2])
23878
+ return new Decimal128(NAN_BUFFER);
23879
+ exponent = parseInt(match[0], 10);
23880
+ index = index + match[0].length;
23881
+ }
23882
+ if (representation[index])
23883
+ return new Decimal128(NAN_BUFFER);
23884
+ if (!nDigitsStored) {
23885
+ digits[0] = 0;
23886
+ nDigits = 1;
23887
+ nDigitsStored = 1;
23888
+ significantDigits = 0;
23889
+ }
23890
+ else {
23891
+ lastDigit = nDigitsStored - 1;
23892
+ significantDigits = nDigits;
23893
+ if (significantDigits !== 1) {
23894
+ while (representation[firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)] === '0') {
23895
+ significantDigits = significantDigits - 1;
23896
+ }
23897
+ }
23898
+ }
23899
+ if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
23900
+ exponent = EXPONENT_MIN;
23901
+ }
23902
+ else {
23903
+ exponent = exponent - radixPosition;
23904
+ }
23905
+ while (exponent > EXPONENT_MAX) {
23906
+ lastDigit = lastDigit + 1;
23907
+ if (lastDigit >= MAX_DIGITS) {
23908
+ if (significantDigits === 0) {
23909
+ exponent = EXPONENT_MAX;
23910
+ break;
23911
+ }
23912
+ invalidErr(representation, 'overflow');
23913
+ }
23914
+ exponent = exponent - 1;
23915
+ }
23916
+ if (options.allowRounding) {
23917
+ while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
23918
+ if (lastDigit === 0 && significantDigits < nDigitsStored) {
23919
+ exponent = EXPONENT_MIN;
23920
+ significantDigits = 0;
23921
+ break;
23922
+ }
23923
+ if (nDigitsStored < nDigits) {
23924
+ nDigits = nDigits - 1;
23925
+ }
23926
+ else {
23927
+ lastDigit = lastDigit - 1;
23928
+ }
23929
+ if (exponent < EXPONENT_MAX) {
23930
+ exponent = exponent + 1;
23931
+ }
23932
+ else {
23933
+ const digitsString = digits.join('');
23934
+ if (digitsString.match(/^0+$/)) {
23935
+ exponent = EXPONENT_MAX;
23936
+ break;
23937
+ }
23938
+ invalidErr(representation, 'overflow');
23939
+ }
23940
+ }
23941
+ if (lastDigit + 1 < significantDigits) {
23942
+ let endOfString = nDigitsRead;
23943
+ if (sawRadix) {
23944
+ firstNonZero = firstNonZero + 1;
23945
+ endOfString = endOfString + 1;
23946
+ }
23947
+ if (sawSign) {
23948
+ firstNonZero = firstNonZero + 1;
23949
+ endOfString = endOfString + 1;
23950
+ }
23951
+ const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
23952
+ let roundBit = 0;
23953
+ if (roundDigit >= 5) {
23954
+ roundBit = 1;
23955
+ if (roundDigit === 5) {
23956
+ roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
23957
+ for (let i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
23958
+ if (parseInt(representation[i], 10)) {
23959
+ roundBit = 1;
23960
+ break;
23961
+ }
23962
+ }
23963
+ }
23964
+ }
23965
+ if (roundBit) {
23966
+ let dIdx = lastDigit;
23967
+ for (; dIdx >= 0; dIdx--) {
23968
+ if (++digits[dIdx] > 9) {
23969
+ digits[dIdx] = 0;
23970
+ if (dIdx === 0) {
23971
+ if (exponent < EXPONENT_MAX) {
23972
+ exponent = exponent + 1;
23973
+ digits[dIdx] = 1;
23974
+ }
23975
+ else {
23976
+ return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
23977
+ }
23978
+ }
23979
+ }
23980
+ else {
23981
+ break;
23982
+ }
23983
+ }
23984
+ }
23985
+ }
23986
+ }
23987
+ else {
23988
+ while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
23989
+ if (lastDigit === 0) {
23990
+ if (significantDigits === 0) {
23991
+ exponent = EXPONENT_MIN;
23992
+ break;
23993
+ }
23994
+ invalidErr(representation, 'exponent underflow');
23995
+ }
23996
+ if (nDigitsStored < nDigits) {
23997
+ if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
23998
+ significantDigits !== 0) {
23999
+ invalidErr(representation, 'inexact rounding');
24000
+ }
24001
+ nDigits = nDigits - 1;
24002
+ }
24003
+ else {
24004
+ if (digits[lastDigit] !== 0) {
24005
+ invalidErr(representation, 'inexact rounding');
24006
+ }
24007
+ lastDigit = lastDigit - 1;
24008
+ }
24009
+ if (exponent < EXPONENT_MAX) {
24010
+ exponent = exponent + 1;
24011
+ }
24012
+ else {
24013
+ invalidErr(representation, 'overflow');
24014
+ }
24015
+ }
24016
+ if (lastDigit + 1 < significantDigits) {
24017
+ if (sawRadix) {
24018
+ firstNonZero = firstNonZero + 1;
24019
+ }
24020
+ if (sawSign) {
24021
+ firstNonZero = firstNonZero + 1;
24022
+ }
24023
+ const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
24024
+ if (roundDigit !== 0) {
24025
+ invalidErr(representation, 'inexact rounding');
24026
+ }
24027
+ }
24028
+ }
24029
+ significandHigh = Long.fromNumber(0);
24030
+ significandLow = Long.fromNumber(0);
24031
+ if (significantDigits === 0) {
24032
+ significandHigh = Long.fromNumber(0);
24033
+ significandLow = Long.fromNumber(0);
24034
+ }
24035
+ else if (lastDigit < 17) {
24036
+ let dIdx = 0;
24037
+ significandLow = Long.fromNumber(digits[dIdx++]);
24038
+ significandHigh = new Long(0, 0);
24039
+ for (; dIdx <= lastDigit; dIdx++) {
24040
+ significandLow = significandLow.multiply(Long.fromNumber(10));
24041
+ significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
24042
+ }
24043
+ }
24044
+ else {
24045
+ let dIdx = 0;
24046
+ significandHigh = Long.fromNumber(digits[dIdx++]);
24047
+ for (; dIdx <= lastDigit - 17; dIdx++) {
24048
+ significandHigh = significandHigh.multiply(Long.fromNumber(10));
24049
+ significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx]));
24050
+ }
24051
+ significandLow = Long.fromNumber(digits[dIdx++]);
24052
+ for (; dIdx <= lastDigit; dIdx++) {
24053
+ significandLow = significandLow.multiply(Long.fromNumber(10));
24054
+ significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
24055
+ }
24056
+ }
24057
+ const significand = multiply64x2(significandHigh, Long.fromString('100000000000000000'));
24058
+ significand.low = significand.low.add(significandLow);
24059
+ if (lessThan(significand.low, significandLow)) {
24060
+ significand.high = significand.high.add(Long.fromNumber(1));
24061
+ }
24062
+ biasedExponent = exponent + EXPONENT_BIAS;
24063
+ const dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) };
24064
+ if (significand.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))) {
24065
+ dec.high = dec.high.or(Long.fromNumber(0x3).shiftLeft(61));
24066
+ dec.high = dec.high.or(Long.fromNumber(biasedExponent).and(Long.fromNumber(0x3fff).shiftLeft(47)));
24067
+ dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x7fffffffffff)));
24068
+ }
24069
+ else {
24070
+ dec.high = dec.high.or(Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
24071
+ dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x1ffffffffffff)));
24072
+ }
24073
+ dec.low = significand.low;
24074
+ if (isNegative) {
24075
+ dec.high = dec.high.or(Long.fromString('9223372036854775808'));
24076
+ }
24077
+ const buffer = ByteUtils.allocateUnsafe(16);
24078
+ index = 0;
24079
+ buffer[index++] = dec.low.low & 0xff;
24080
+ buffer[index++] = (dec.low.low >> 8) & 0xff;
24081
+ buffer[index++] = (dec.low.low >> 16) & 0xff;
24082
+ buffer[index++] = (dec.low.low >> 24) & 0xff;
24083
+ buffer[index++] = dec.low.high & 0xff;
24084
+ buffer[index++] = (dec.low.high >> 8) & 0xff;
24085
+ buffer[index++] = (dec.low.high >> 16) & 0xff;
24086
+ buffer[index++] = (dec.low.high >> 24) & 0xff;
24087
+ buffer[index++] = dec.high.low & 0xff;
24088
+ buffer[index++] = (dec.high.low >> 8) & 0xff;
24089
+ buffer[index++] = (dec.high.low >> 16) & 0xff;
24090
+ buffer[index++] = (dec.high.low >> 24) & 0xff;
24091
+ buffer[index++] = dec.high.high & 0xff;
24092
+ buffer[index++] = (dec.high.high >> 8) & 0xff;
24093
+ buffer[index++] = (dec.high.high >> 16) & 0xff;
24094
+ buffer[index++] = (dec.high.high >> 24) & 0xff;
24095
+ return new Decimal128(buffer);
24096
+ }
24097
+ toString() {
24098
+ let biased_exponent;
24099
+ let significand_digits = 0;
24100
+ const significand = new Array(36);
24101
+ for (let i = 0; i < significand.length; i++)
24102
+ significand[i] = 0;
24103
+ let index = 0;
24104
+ let is_zero = false;
24105
+ let significand_msb;
24106
+ let significand128 = { parts: [0, 0, 0, 0] };
24107
+ let j, k;
24108
+ const string = [];
24109
+ index = 0;
24110
+ const buffer = this.bytes;
24111
+ const low = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
24112
+ const midl = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
24113
+ const midh = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
24114
+ const high = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
24115
+ index = 0;
24116
+ const dec = {
24117
+ low: new Long(low, midl),
24118
+ high: new Long(midh, high)
24119
+ };
24120
+ if (dec.high.lessThan(Long.ZERO)) {
24121
+ string.push('-');
24122
+ }
24123
+ const combination = (high >> 26) & COMBINATION_MASK;
24124
+ if (combination >> 3 === 3) {
24125
+ if (combination === COMBINATION_INFINITY) {
24126
+ return string.join('') + 'Infinity';
24127
+ }
24128
+ else if (combination === COMBINATION_NAN) {
24129
+ return 'NaN';
24130
+ }
24131
+ else {
24132
+ biased_exponent = (high >> 15) & EXPONENT_MASK;
24133
+ significand_msb = 0x08 + ((high >> 14) & 0x01);
24134
+ }
24135
+ }
24136
+ else {
24137
+ significand_msb = (high >> 14) & 0x07;
24138
+ biased_exponent = (high >> 17) & EXPONENT_MASK;
24139
+ }
24140
+ const exponent = biased_exponent - EXPONENT_BIAS;
24141
+ significand128.parts[0] = (high & 0x3fff) + ((significand_msb & 0xf) << 14);
24142
+ significand128.parts[1] = midh;
24143
+ significand128.parts[2] = midl;
24144
+ significand128.parts[3] = low;
24145
+ if (significand128.parts[0] === 0 &&
24146
+ significand128.parts[1] === 0 &&
24147
+ significand128.parts[2] === 0 &&
24148
+ significand128.parts[3] === 0) {
24149
+ is_zero = true;
24150
+ }
24151
+ else {
24152
+ for (k = 3; k >= 0; k--) {
24153
+ let least_digits = 0;
24154
+ const result = divideu128(significand128);
24155
+ significand128 = result.quotient;
24156
+ least_digits = result.rem.low;
24157
+ if (!least_digits)
24158
+ continue;
24159
+ for (j = 8; j >= 0; j--) {
24160
+ significand[k * 9 + j] = least_digits % 10;
24161
+ least_digits = Math.floor(least_digits / 10);
24162
+ }
24163
+ }
24164
+ }
24165
+ if (is_zero) {
24166
+ significand_digits = 1;
24167
+ significand[index] = 0;
24168
+ }
24169
+ else {
24170
+ significand_digits = 36;
24171
+ while (!significand[index]) {
24172
+ significand_digits = significand_digits - 1;
24173
+ index = index + 1;
24174
+ }
24175
+ }
24176
+ const scientific_exponent = significand_digits - 1 + exponent;
24177
+ if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
24178
+ if (significand_digits > 34) {
24179
+ string.push(`${0}`);
24180
+ if (exponent > 0)
24181
+ string.push(`E+${exponent}`);
24182
+ else if (exponent < 0)
24183
+ string.push(`E${exponent}`);
24184
+ return string.join('');
24185
+ }
24186
+ string.push(`${significand[index++]}`);
24187
+ significand_digits = significand_digits - 1;
24188
+ if (significand_digits) {
24189
+ string.push('.');
24190
+ }
24191
+ for (let i = 0; i < significand_digits; i++) {
24192
+ string.push(`${significand[index++]}`);
24193
+ }
24194
+ string.push('E');
24195
+ if (scientific_exponent > 0) {
24196
+ string.push(`+${scientific_exponent}`);
24197
+ }
24198
+ else {
24199
+ string.push(`${scientific_exponent}`);
24200
+ }
24201
+ }
24202
+ else {
24203
+ if (exponent >= 0) {
24204
+ for (let i = 0; i < significand_digits; i++) {
24205
+ string.push(`${significand[index++]}`);
24206
+ }
24207
+ }
24208
+ else {
24209
+ let radix_position = significand_digits + exponent;
24210
+ if (radix_position > 0) {
24211
+ for (let i = 0; i < radix_position; i++) {
24212
+ string.push(`${significand[index++]}`);
24213
+ }
24214
+ }
24215
+ else {
24216
+ string.push('0');
24217
+ }
24218
+ string.push('.');
24219
+ while (radix_position++ < 0) {
24220
+ string.push('0');
24221
+ }
24222
+ for (let i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
24223
+ string.push(`${significand[index++]}`);
24224
+ }
24225
+ }
24226
+ }
24227
+ return string.join('');
24228
+ }
24229
+ toJSON() {
24230
+ return { $numberDecimal: this.toString() };
24231
+ }
24232
+ toExtendedJSON() {
24233
+ return { $numberDecimal: this.toString() };
24234
+ }
24235
+ static fromExtendedJSON(doc) {
24236
+ return Decimal128.fromString(doc.$numberDecimal);
24237
+ }
24238
+ inspect(depth, options, inspect) {
24239
+ inspect ??= defaultInspect;
24240
+ const d128string = inspect(this.toString(), options);
24241
+ return `new Decimal128(${d128string})`;
24242
+ }
24243
+ }
24244
+
24245
+ class Double extends BSONValue {
24246
+ get _bsontype() {
24247
+ return 'Double';
24248
+ }
24249
+ constructor(value) {
24250
+ super();
24251
+ if (value instanceof Number) {
24252
+ value = value.valueOf();
24253
+ }
24254
+ this.value = +value;
24255
+ }
24256
+ static fromString(value) {
24257
+ const coercedValue = Number(value);
24258
+ if (value === 'NaN')
24259
+ return new Double(NaN);
24260
+ if (value === 'Infinity')
24261
+ return new Double(Infinity);
24262
+ if (value === '-Infinity')
24263
+ return new Double(-Infinity);
24264
+ if (!Number.isFinite(coercedValue)) {
24265
+ throw new BSONError(`Input: ${value} is not representable as a Double`);
24266
+ }
24267
+ if (value.trim() !== value) {
24268
+ throw new BSONError(`Input: '${value}' contains whitespace`);
24269
+ }
24270
+ if (value === '') {
24271
+ throw new BSONError(`Input is an empty string`);
24272
+ }
24273
+ if (/[^-0-9.+eE]/.test(value)) {
24274
+ throw new BSONError(`Input: '${value}' is not in decimal or exponential notation`);
24275
+ }
24276
+ return new Double(coercedValue);
24277
+ }
24278
+ valueOf() {
24279
+ return this.value;
24280
+ }
24281
+ toJSON() {
24282
+ return this.value;
24283
+ }
24284
+ toString(radix) {
24285
+ return this.value.toString(radix);
24286
+ }
24287
+ toExtendedJSON(options) {
24288
+ if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) {
24289
+ return this.value;
24290
+ }
24291
+ if (Object.is(Math.sign(this.value), -0)) {
24292
+ return { $numberDouble: '-0.0' };
24293
+ }
24294
+ return {
24295
+ $numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString()
24296
+ };
24297
+ }
24298
+ static fromExtendedJSON(doc, options) {
24299
+ const doubleValue = parseFloat(doc.$numberDouble);
24300
+ return options && options.relaxed ? doubleValue : new Double(doubleValue);
24301
+ }
24302
+ inspect(depth, options, inspect) {
24303
+ inspect ??= defaultInspect;
24304
+ return `new Double(${inspect(this.value, options)})`;
24305
+ }
24306
+ }
24307
+
24308
+ class Int32 extends BSONValue {
24309
+ get _bsontype() {
24310
+ return 'Int32';
24311
+ }
24312
+ constructor(value) {
24313
+ super();
24314
+ if (value instanceof Number) {
24315
+ value = value.valueOf();
24316
+ }
24317
+ this.value = +value | 0;
24318
+ }
24319
+ static fromString(value) {
24320
+ const cleanedValue = removeLeadingZerosAndExplicitPlus(value);
24321
+ const coercedValue = Number(value);
24322
+ if (BSON_INT32_MAX < coercedValue) {
24323
+ throw new BSONError(`Input: '${value}' is larger than the maximum value for Int32`);
24324
+ }
24325
+ else if (BSON_INT32_MIN > coercedValue) {
24326
+ throw new BSONError(`Input: '${value}' is smaller than the minimum value for Int32`);
24327
+ }
24328
+ else if (!Number.isSafeInteger(coercedValue)) {
24329
+ throw new BSONError(`Input: '${value}' is not a safe integer`);
24330
+ }
24331
+ else if (coercedValue.toString() !== cleanedValue) {
24332
+ throw new BSONError(`Input: '${value}' is not a valid Int32 string`);
24333
+ }
24334
+ return new Int32(coercedValue);
24335
+ }
24336
+ valueOf() {
24337
+ return this.value;
24338
+ }
24339
+ toString(radix) {
24340
+ return this.value.toString(radix);
24341
+ }
24342
+ toJSON() {
24343
+ return this.value;
24344
+ }
24345
+ toExtendedJSON(options) {
24346
+ if (options && (options.relaxed || options.legacy))
24347
+ return this.value;
24348
+ return { $numberInt: this.value.toString() };
24349
+ }
24350
+ static fromExtendedJSON(doc, options) {
24351
+ return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
24352
+ }
24353
+ inspect(depth, options, inspect) {
24354
+ inspect ??= defaultInspect;
24355
+ return `new Int32(${inspect(this.value, options)})`;
24356
+ }
24357
+ }
24358
+
24359
+ class MaxKey extends BSONValue {
24360
+ get _bsontype() {
24361
+ return 'MaxKey';
24362
+ }
24363
+ toExtendedJSON() {
24364
+ return { $maxKey: 1 };
24365
+ }
24366
+ static fromExtendedJSON() {
24367
+ return new MaxKey();
24368
+ }
24369
+ inspect() {
24370
+ return 'new MaxKey()';
24371
+ }
24372
+ }
24373
+
24374
+ class MinKey extends BSONValue {
24375
+ get _bsontype() {
24376
+ return 'MinKey';
24377
+ }
24378
+ toExtendedJSON() {
24379
+ return { $minKey: 1 };
24380
+ }
24381
+ static fromExtendedJSON() {
24382
+ return new MinKey();
24383
+ }
24384
+ inspect() {
24385
+ return 'new MinKey()';
24386
+ }
24387
+ }
24388
+
24389
+ let PROCESS_UNIQUE = null;
24390
+ const __idCache = new WeakMap();
24391
+ class ObjectId extends BSONValue {
24392
+ get _bsontype() {
24393
+ return 'ObjectId';
24394
+ }
24395
+ constructor(inputId) {
24396
+ super();
24397
+ let workingId;
24398
+ if (typeof inputId === 'object' && inputId && 'id' in inputId) {
24399
+ if (typeof inputId.id !== 'string' && !ArrayBuffer.isView(inputId.id)) {
24400
+ throw new BSONError('Argument passed in must have an id that is of type string or Buffer');
24401
+ }
24402
+ if ('toHexString' in inputId && typeof inputId.toHexString === 'function') {
24403
+ workingId = ByteUtils.fromHex(inputId.toHexString());
24404
+ }
24405
+ else {
24406
+ workingId = inputId.id;
24407
+ }
24408
+ }
24409
+ else {
24410
+ workingId = inputId;
24411
+ }
24412
+ if (workingId == null || typeof workingId === 'number') {
24413
+ this.buffer = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
24414
+ }
24415
+ else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
24416
+ this.buffer = ByteUtils.toLocalBufferType(workingId);
24417
+ }
24418
+ else if (typeof workingId === 'string') {
24419
+ if (ObjectId.validateHexString(workingId)) {
24420
+ this.buffer = ByteUtils.fromHex(workingId);
24421
+ if (ObjectId.cacheHexString) {
24422
+ __idCache.set(this, workingId);
24423
+ }
24424
+ }
24425
+ else {
24426
+ throw new BSONError('input must be a 24 character hex string, 12 byte Uint8Array, or an integer');
24427
+ }
24428
+ }
24429
+ else {
24430
+ throw new BSONError('Argument passed in does not match the accepted types');
24431
+ }
24432
+ }
24433
+ get id() {
24434
+ return this.buffer;
24435
+ }
24436
+ set id(value) {
24437
+ this.buffer = value;
24438
+ if (ObjectId.cacheHexString) {
24439
+ __idCache.set(this, ByteUtils.toHex(value));
24440
+ }
24441
+ }
24442
+ static validateHexString(string) {
24443
+ if (string?.length !== 24)
24444
+ return false;
24445
+ for (let i = 0; i < 24; i++) {
24446
+ const char = string.charCodeAt(i);
24447
+ if ((char >= 48 && char <= 57) ||
24448
+ (char >= 97 && char <= 102) ||
24449
+ (char >= 65 && char <= 70)) {
24450
+ continue;
24451
+ }
24452
+ return false;
24453
+ }
24454
+ return true;
24455
+ }
24456
+ toHexString() {
24457
+ if (ObjectId.cacheHexString) {
24458
+ const __id = __idCache.get(this);
24459
+ if (__id)
24460
+ return __id;
24461
+ }
24462
+ const hexString = ByteUtils.toHex(this.id);
24463
+ if (ObjectId.cacheHexString) {
24464
+ __idCache.set(this, hexString);
24465
+ }
24466
+ return hexString;
24467
+ }
24468
+ static getInc() {
24469
+ return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
24470
+ }
24471
+ static generate(time) {
24472
+ if ('number' !== typeof time) {
24473
+ time = Math.floor(Date.now() / 1000);
24474
+ }
24475
+ const inc = ObjectId.getInc();
24476
+ const buffer = ByteUtils.allocateUnsafe(12);
24477
+ NumberUtils.setInt32BE(buffer, 0, time);
24478
+ if (PROCESS_UNIQUE === null) {
24479
+ PROCESS_UNIQUE = ByteUtils.randomBytes(5);
24480
+ }
24481
+ buffer[4] = PROCESS_UNIQUE[0];
24482
+ buffer[5] = PROCESS_UNIQUE[1];
24483
+ buffer[6] = PROCESS_UNIQUE[2];
24484
+ buffer[7] = PROCESS_UNIQUE[3];
24485
+ buffer[8] = PROCESS_UNIQUE[4];
24486
+ buffer[11] = inc & 0xff;
24487
+ buffer[10] = (inc >> 8) & 0xff;
24488
+ buffer[9] = (inc >> 16) & 0xff;
24489
+ return buffer;
24490
+ }
24491
+ toString(encoding) {
24492
+ if (encoding === 'base64')
24493
+ return ByteUtils.toBase64(this.id);
24494
+ if (encoding === 'hex')
24495
+ return this.toHexString();
24496
+ return this.toHexString();
24497
+ }
24498
+ toJSON() {
24499
+ return this.toHexString();
24500
+ }
24501
+ static is(variable) {
24502
+ return (variable != null &&
24503
+ typeof variable === 'object' &&
24504
+ '_bsontype' in variable &&
24505
+ variable._bsontype === 'ObjectId');
24506
+ }
24507
+ equals(otherId) {
24508
+ if (otherId === undefined || otherId === null) {
24509
+ return false;
24510
+ }
24511
+ if (ObjectId.is(otherId)) {
24512
+ return (this.buffer[11] === otherId.buffer[11] && ByteUtils.equals(this.buffer, otherId.buffer));
24513
+ }
24514
+ if (typeof otherId === 'string') {
24515
+ return otherId.toLowerCase() === this.toHexString();
24516
+ }
24517
+ if (typeof otherId === 'object' && typeof otherId.toHexString === 'function') {
24518
+ const otherIdString = otherId.toHexString();
24519
+ const thisIdString = this.toHexString();
24520
+ return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
24521
+ }
24522
+ return false;
24523
+ }
24524
+ getTimestamp() {
24525
+ const timestamp = new Date();
24526
+ const time = NumberUtils.getUint32BE(this.buffer, 0);
24527
+ timestamp.setTime(Math.floor(time) * 1000);
24528
+ return timestamp;
24529
+ }
24530
+ static createPk() {
24531
+ return new ObjectId();
24532
+ }
24533
+ serializeInto(uint8array, index) {
24534
+ uint8array[index] = this.buffer[0];
24535
+ uint8array[index + 1] = this.buffer[1];
24536
+ uint8array[index + 2] = this.buffer[2];
24537
+ uint8array[index + 3] = this.buffer[3];
24538
+ uint8array[index + 4] = this.buffer[4];
24539
+ uint8array[index + 5] = this.buffer[5];
24540
+ uint8array[index + 6] = this.buffer[6];
24541
+ uint8array[index + 7] = this.buffer[7];
24542
+ uint8array[index + 8] = this.buffer[8];
24543
+ uint8array[index + 9] = this.buffer[9];
24544
+ uint8array[index + 10] = this.buffer[10];
24545
+ uint8array[index + 11] = this.buffer[11];
24546
+ return 12;
24547
+ }
24548
+ static createFromTime(time) {
24549
+ const buffer = ByteUtils.allocate(12);
24550
+ for (let i = 11; i >= 4; i--)
24551
+ buffer[i] = 0;
24552
+ NumberUtils.setInt32BE(buffer, 0, time);
24553
+ return new ObjectId(buffer);
24554
+ }
24555
+ static createFromHexString(hexString) {
24556
+ if (hexString?.length !== 24) {
24557
+ throw new BSONError('hex string must be 24 characters');
24558
+ }
24559
+ return new ObjectId(ByteUtils.fromHex(hexString));
24560
+ }
24561
+ static createFromBase64(base64) {
24562
+ if (base64?.length !== 16) {
24563
+ throw new BSONError('base64 string must be 16 characters');
24564
+ }
24565
+ return new ObjectId(ByteUtils.fromBase64(base64));
24566
+ }
24567
+ static isValid(id) {
24568
+ if (id == null)
24569
+ return false;
24570
+ if (typeof id === 'string')
24571
+ return ObjectId.validateHexString(id);
24572
+ try {
24573
+ new ObjectId(id);
24574
+ return true;
24575
+ }
24576
+ catch {
24577
+ return false;
24578
+ }
24579
+ }
24580
+ toExtendedJSON() {
24581
+ if (this.toHexString)
24582
+ return { $oid: this.toHexString() };
24583
+ return { $oid: this.toString('hex') };
24584
+ }
24585
+ static fromExtendedJSON(doc) {
24586
+ return new ObjectId(doc.$oid);
24587
+ }
24588
+ isCached() {
24589
+ return ObjectId.cacheHexString && __idCache.has(this);
24590
+ }
24591
+ inspect(depth, options, inspect) {
24592
+ inspect ??= defaultInspect;
24593
+ return `new ObjectId(${inspect(this.toHexString(), options)})`;
24594
+ }
24595
+ }
24596
+ ObjectId.index = Math.floor(Math.random() * 0xffffff);
24597
+
24598
+ function alphabetize(str) {
24599
+ return str.split('').sort().join('');
24600
+ }
24601
+ class BSONRegExp extends BSONValue {
24602
+ get _bsontype() {
24603
+ return 'BSONRegExp';
24604
+ }
24605
+ constructor(pattern, options) {
24606
+ super();
24607
+ this.pattern = pattern;
24608
+ this.options = alphabetize(options ?? '');
24609
+ if (this.pattern.indexOf('\x00') !== -1) {
24610
+ throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);
24611
+ }
24612
+ if (this.options.indexOf('\x00') !== -1) {
24613
+ throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);
24614
+ }
24615
+ for (let i = 0; i < this.options.length; i++) {
24616
+ if (!(this.options[i] === 'i' ||
24617
+ this.options[i] === 'm' ||
24618
+ this.options[i] === 'x' ||
24619
+ this.options[i] === 'l' ||
24620
+ this.options[i] === 's' ||
24621
+ this.options[i] === 'u')) {
24622
+ throw new BSONError(`The regular expression option [${this.options[i]}] is not supported`);
24623
+ }
24624
+ }
24625
+ }
24626
+ static parseOptions(options) {
24627
+ return options ? options.split('').sort().join('') : '';
24628
+ }
24629
+ toExtendedJSON(options) {
24630
+ options = options || {};
24631
+ if (options.legacy) {
24632
+ return { $regex: this.pattern, $options: this.options };
24633
+ }
24634
+ return { $regularExpression: { pattern: this.pattern, options: this.options } };
24635
+ }
24636
+ static fromExtendedJSON(doc) {
24637
+ if ('$regex' in doc) {
24638
+ if (typeof doc.$regex !== 'string') {
24639
+ if (doc.$regex._bsontype === 'BSONRegExp') {
24640
+ return doc;
24641
+ }
24642
+ }
24643
+ else {
24644
+ return new BSONRegExp(doc.$regex, BSONRegExp.parseOptions(doc.$options));
24645
+ }
24646
+ }
24647
+ if ('$regularExpression' in doc) {
24648
+ return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
24649
+ }
24650
+ throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
24651
+ }
24652
+ inspect(depth, options, inspect) {
24653
+ const stylize = getStylizeFunction(options) ?? (v => v);
24654
+ inspect ??= defaultInspect;
24655
+ const pattern = stylize(inspect(this.pattern), 'regexp');
24656
+ const flags = stylize(inspect(this.options), 'regexp');
24657
+ return `new BSONRegExp(${pattern}, ${flags})`;
24658
+ }
24659
+ }
24660
+
24661
+ class BSONSymbol extends BSONValue {
24662
+ get _bsontype() {
24663
+ return 'BSONSymbol';
24664
+ }
24665
+ constructor(value) {
24666
+ super();
24667
+ this.value = value;
24668
+ }
24669
+ valueOf() {
24670
+ return this.value;
24671
+ }
24672
+ toString() {
24673
+ return this.value;
24674
+ }
24675
+ toJSON() {
24676
+ return this.value;
24677
+ }
24678
+ toExtendedJSON() {
24679
+ return { $symbol: this.value };
24680
+ }
24681
+ static fromExtendedJSON(doc) {
24682
+ return new BSONSymbol(doc.$symbol);
24683
+ }
24684
+ inspect(depth, options, inspect) {
24685
+ inspect ??= defaultInspect;
24686
+ return `new BSONSymbol(${inspect(this.value, options)})`;
24687
+ }
24688
+ }
24689
+
24690
+ const LongWithoutOverridesClass = Long;
24691
+ class Timestamp extends LongWithoutOverridesClass {
24692
+ get _bsontype() {
24693
+ return 'Timestamp';
24694
+ }
24695
+ get i() {
24696
+ return this.low >>> 0;
24697
+ }
24698
+ get t() {
24699
+ return this.high >>> 0;
24700
+ }
24701
+ constructor(low) {
24702
+ if (low == null) {
24703
+ super(0, 0, true);
24704
+ }
24705
+ else if (typeof low === 'bigint') {
24706
+ super(low, true);
24707
+ }
24708
+ else if (Long.isLong(low)) {
24709
+ super(low.low, low.high, true);
24710
+ }
24711
+ else if (typeof low === 'object' && 't' in low && 'i' in low) {
24712
+ if (typeof low.t !== 'number' && (typeof low.t !== 'object' || low.t._bsontype !== 'Int32')) {
24713
+ throw new BSONError('Timestamp constructed from { t, i } must provide t as a number');
24714
+ }
24715
+ if (typeof low.i !== 'number' && (typeof low.i !== 'object' || low.i._bsontype !== 'Int32')) {
24716
+ throw new BSONError('Timestamp constructed from { t, i } must provide i as a number');
24717
+ }
24718
+ const t = Number(low.t);
24719
+ const i = Number(low.i);
24720
+ if (t < 0 || Number.isNaN(t)) {
24721
+ throw new BSONError('Timestamp constructed from { t, i } must provide a positive t');
24722
+ }
24723
+ if (i < 0 || Number.isNaN(i)) {
24724
+ throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
24725
+ }
24726
+ if (t > 0xffff_ffff) {
24727
+ throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
24728
+ }
24729
+ if (i > 0xffff_ffff) {
24730
+ throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
24731
+ }
24732
+ super(i, t, true);
24733
+ }
24734
+ else {
24735
+ throw new BSONError('A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }');
24736
+ }
24737
+ }
24738
+ toJSON() {
24739
+ return {
24740
+ $timestamp: this.toString()
24741
+ };
24742
+ }
24743
+ static fromInt(value) {
24744
+ return new Timestamp(Long.fromInt(value, true));
24745
+ }
24746
+ static fromNumber(value) {
24747
+ return new Timestamp(Long.fromNumber(value, true));
24748
+ }
24749
+ static fromBits(lowBits, highBits) {
24750
+ return new Timestamp({ i: lowBits, t: highBits });
24751
+ }
24752
+ static fromString(str, optRadix) {
24753
+ return new Timestamp(Long.fromString(str, true, optRadix));
24754
+ }
24755
+ toExtendedJSON() {
24756
+ return { $timestamp: { t: this.t, i: this.i } };
24757
+ }
24758
+ static fromExtendedJSON(doc) {
24759
+ const i = Long.isLong(doc.$timestamp.i)
24760
+ ? doc.$timestamp.i.getLowBitsUnsigned()
24761
+ : doc.$timestamp.i;
24762
+ const t = Long.isLong(doc.$timestamp.t)
24763
+ ? doc.$timestamp.t.getLowBitsUnsigned()
24764
+ : doc.$timestamp.t;
24765
+ return new Timestamp({ t, i });
24766
+ }
24767
+ inspect(depth, options, inspect) {
24768
+ inspect ??= defaultInspect;
24769
+ const t = inspect(this.t, options);
24770
+ const i = inspect(this.i, options);
24771
+ return `new Timestamp({ t: ${t}, i: ${i} })`;
24772
+ }
24773
+ }
24774
+ Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
24775
+
24776
+ Long.fromNumber(JS_INT_MAX);
24777
+ Long.fromNumber(JS_INT_MIN);
24778
+
24779
+ function isBSONType(value) {
24780
+ return (value != null &&
24781
+ typeof value === 'object' &&
24782
+ '_bsontype' in value &&
24783
+ typeof value._bsontype === 'string');
24784
+ }
24785
+ const keysToCodecs = {
24786
+ $oid: ObjectId,
24787
+ $binary: Binary,
24788
+ $uuid: Binary,
24789
+ $symbol: BSONSymbol,
24790
+ $numberInt: Int32,
24791
+ $numberDecimal: Decimal128,
24792
+ $numberDouble: Double,
24793
+ $numberLong: Long,
24794
+ $minKey: MinKey,
24795
+ $maxKey: MaxKey,
24796
+ $regex: BSONRegExp,
24797
+ $regularExpression: BSONRegExp,
24798
+ $timestamp: Timestamp
24799
+ };
24800
+ function deserializeValue(value, options = {}) {
24801
+ if (typeof value === 'number') {
24802
+ const in32BitRange = value <= BSON_INT32_MAX && value >= BSON_INT32_MIN;
24803
+ const in64BitRange = value <= BSON_INT64_MAX && value >= BSON_INT64_MIN;
24804
+ if (options.relaxed || options.legacy) {
24805
+ return value;
24806
+ }
24807
+ if (Number.isInteger(value) && !Object.is(value, -0)) {
24808
+ if (in32BitRange) {
24809
+ return new Int32(value);
24810
+ }
24811
+ if (in64BitRange) {
24812
+ if (options.useBigInt64) {
24813
+ return BigInt(value);
24814
+ }
24815
+ return Long.fromNumber(value);
24816
+ }
24817
+ }
24818
+ return new Double(value);
24819
+ }
24820
+ if (value == null || typeof value !== 'object')
24821
+ return value;
24822
+ if (value.$undefined)
24823
+ return null;
24824
+ const keys = Object.keys(value).filter(k => k.startsWith('$') && value[k] != null);
24825
+ for (let i = 0; i < keys.length; i++) {
24826
+ const c = keysToCodecs[keys[i]];
24827
+ if (c)
24828
+ return c.fromExtendedJSON(value, options);
24829
+ }
24830
+ if (value.$date != null) {
24831
+ const d = value.$date;
24832
+ const date = new Date();
24833
+ if (options.legacy) {
24834
+ if (typeof d === 'number')
24835
+ date.setTime(d);
24836
+ else if (typeof d === 'string')
24837
+ date.setTime(Date.parse(d));
24838
+ else if (typeof d === 'bigint')
24839
+ date.setTime(Number(d));
24840
+ else
24841
+ throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
24842
+ }
24843
+ else {
24844
+ if (typeof d === 'string')
24845
+ date.setTime(Date.parse(d));
24846
+ else if (Long.isLong(d))
24847
+ date.setTime(d.toNumber());
24848
+ else if (typeof d === 'number' && options.relaxed)
24849
+ date.setTime(d);
24850
+ else if (typeof d === 'bigint')
24851
+ date.setTime(Number(d));
24852
+ else
24853
+ throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
24854
+ }
24855
+ return date;
24856
+ }
24857
+ if (value.$code != null) {
24858
+ const copy = Object.assign({}, value);
24859
+ if (value.$scope) {
24860
+ copy.$scope = deserializeValue(value.$scope);
24861
+ }
24862
+ return Code.fromExtendedJSON(value);
24863
+ }
24864
+ if (isDBRefLike(value) || value.$dbPointer) {
24865
+ const v = value.$ref ? value : value.$dbPointer;
24866
+ if (v instanceof DBRef)
24867
+ return v;
24868
+ const dollarKeys = Object.keys(v).filter(k => k.startsWith('$'));
24869
+ let valid = true;
24870
+ dollarKeys.forEach(k => {
24871
+ if (['$ref', '$id', '$db'].indexOf(k) === -1)
24872
+ valid = false;
24873
+ });
24874
+ if (valid)
24875
+ return DBRef.fromExtendedJSON(v);
24876
+ }
24877
+ return value;
24878
+ }
24879
+ function serializeArray(array, options) {
24880
+ return array.map((v, index) => {
24881
+ options.seenObjects.push({ propertyName: `index ${index}`, obj: null });
24882
+ try {
24883
+ return serializeValue(v, options);
24884
+ }
24885
+ finally {
24886
+ options.seenObjects.pop();
24887
+ }
24888
+ });
24889
+ }
24890
+ function getISOString(date) {
24891
+ const isoStr = date.toISOString();
24892
+ return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + 'Z';
24893
+ }
24894
+ function serializeValue(value, options) {
24895
+ if (value instanceof Map || isMap(value)) {
24896
+ const obj = Object.create(null);
24897
+ for (const [k, v] of value) {
24898
+ if (typeof k !== 'string') {
24899
+ throw new BSONError('Can only serialize maps with string keys');
24900
+ }
24901
+ obj[k] = v;
24902
+ }
24903
+ return serializeValue(obj, options);
24904
+ }
24905
+ if ((typeof value === 'object' || typeof value === 'function') && value !== null) {
24906
+ const index = options.seenObjects.findIndex(entry => entry.obj === value);
24907
+ if (index !== -1) {
24908
+ const props = options.seenObjects.map(entry => entry.propertyName);
24909
+ const leadingPart = props
24910
+ .slice(0, index)
24911
+ .map(prop => `${prop} -> `)
24912
+ .join('');
24913
+ const alreadySeen = props[index];
24914
+ const circularPart = ' -> ' +
24915
+ props
24916
+ .slice(index + 1, props.length - 1)
24917
+ .map(prop => `${prop} -> `)
24918
+ .join('');
24919
+ const current = props[props.length - 1];
24920
+ const leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
24921
+ const dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
24922
+ throw new BSONError('Converting circular structure to EJSON:\n' +
24923
+ ` ${leadingPart}${alreadySeen}${circularPart}${current}\n` +
24924
+ ` ${leadingSpace}\\${dashes}/`);
24925
+ }
24926
+ options.seenObjects[options.seenObjects.length - 1].obj = value;
24927
+ }
24928
+ if (Array.isArray(value))
24929
+ return serializeArray(value, options);
24930
+ if (value === undefined)
24931
+ return null;
24932
+ if (value instanceof Date || isDate(value)) {
24933
+ const dateNum = value.getTime(), inRange = dateNum > -1 && dateNum < 253402318800000;
24934
+ if (options.legacy) {
24935
+ return options.relaxed && inRange
24936
+ ? { $date: value.getTime() }
24937
+ : { $date: getISOString(value) };
24938
+ }
24939
+ return options.relaxed && inRange
24940
+ ? { $date: getISOString(value) }
24941
+ : { $date: { $numberLong: value.getTime().toString() } };
24942
+ }
24943
+ if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
24944
+ if (Number.isInteger(value) && !Object.is(value, -0)) {
24945
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
24946
+ return { $numberInt: value.toString() };
24947
+ }
24948
+ if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX) {
24949
+ return { $numberLong: value.toString() };
24950
+ }
24951
+ }
24952
+ return { $numberDouble: Object.is(value, -0) ? '-0.0' : value.toString() };
24953
+ }
24954
+ if (typeof value === 'bigint') {
24955
+ if (!options.relaxed) {
24956
+ return { $numberLong: BigInt.asIntN(64, value).toString() };
24957
+ }
24958
+ return Number(BigInt.asIntN(64, value));
24959
+ }
24960
+ if (value instanceof RegExp || isRegExp(value)) {
24961
+ let flags = value.flags;
24962
+ if (flags === undefined) {
24963
+ const match = value.toString().match(/[gimuy]*$/);
24964
+ if (match) {
24965
+ flags = match[0];
24966
+ }
24967
+ }
24968
+ const rx = new BSONRegExp(value.source, flags);
24969
+ return rx.toExtendedJSON(options);
24970
+ }
24971
+ if (value != null && typeof value === 'object')
24972
+ return serializeDocument(value, options);
24973
+ return value;
24974
+ }
24975
+ const BSON_TYPE_MAPPINGS = {
24976
+ Binary: (o) => new Binary(o.value(), o.sub_type),
24977
+ Code: (o) => new Code(o.code, o.scope),
24978
+ DBRef: (o) => new DBRef(o.collection || o.namespace, o.oid, o.db, o.fields),
24979
+ Decimal128: (o) => new Decimal128(o.bytes),
24980
+ Double: (o) => new Double(o.value),
24981
+ Int32: (o) => new Int32(o.value),
24982
+ Long: (o) => Long.fromBits(o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_),
24983
+ MaxKey: () => new MaxKey(),
24984
+ MinKey: () => new MinKey(),
24985
+ ObjectId: (o) => new ObjectId(o),
24986
+ BSONRegExp: (o) => new BSONRegExp(o.pattern, o.options),
24987
+ BSONSymbol: (o) => new BSONSymbol(o.value),
24988
+ Timestamp: (o) => Timestamp.fromBits(o.low, o.high)
24989
+ };
24990
+ function serializeDocument(doc, options) {
24991
+ if (doc == null || typeof doc !== 'object')
24992
+ throw new BSONError('not an object instance');
24993
+ const bsontype = doc._bsontype;
24994
+ if (typeof bsontype === 'undefined') {
24995
+ const _doc = {};
24996
+ for (const name of Object.keys(doc)) {
24997
+ options.seenObjects.push({ propertyName: name, obj: null });
24998
+ try {
24999
+ const value = serializeValue(doc[name], options);
25000
+ if (name === '__proto__') {
25001
+ Object.defineProperty(_doc, name, {
25002
+ value,
25003
+ writable: true,
25004
+ enumerable: true,
25005
+ configurable: true
25006
+ });
25007
+ }
25008
+ else {
25009
+ _doc[name] = value;
25010
+ }
25011
+ }
25012
+ finally {
25013
+ options.seenObjects.pop();
25014
+ }
25015
+ }
25016
+ return _doc;
25017
+ }
25018
+ else if (doc != null &&
25019
+ typeof doc === 'object' &&
25020
+ typeof doc._bsontype === 'string' &&
25021
+ doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
25022
+ throw new BSONVersionError();
25023
+ }
25024
+ else if (isBSONType(doc)) {
25025
+ let outDoc = doc;
25026
+ if (typeof outDoc.toExtendedJSON !== 'function') {
25027
+ const mapper = BSON_TYPE_MAPPINGS[doc._bsontype];
25028
+ if (!mapper) {
25029
+ throw new BSONError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
25030
+ }
25031
+ outDoc = mapper(outDoc);
25032
+ }
25033
+ if (bsontype === 'Code' && outDoc.scope) {
25034
+ outDoc = new Code(outDoc.code, serializeValue(outDoc.scope, options));
25035
+ }
25036
+ else if (bsontype === 'DBRef' && outDoc.oid) {
25037
+ outDoc = new DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options));
25038
+ }
25039
+ return outDoc.toExtendedJSON(options);
25040
+ }
25041
+ else {
25042
+ throw new BSONError('_bsontype must be a string, but was: ' + typeof bsontype);
25043
+ }
25044
+ }
25045
+ function parse(text, options) {
25046
+ const ejsonOptions = {
25047
+ useBigInt64: options?.useBigInt64 ?? false,
25048
+ relaxed: options?.relaxed ?? true,
25049
+ legacy: options?.legacy ?? false
25050
+ };
25051
+ return JSON.parse(text, (key, value) => {
25052
+ if (key.indexOf('\x00') !== -1) {
25053
+ throw new BSONError(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(key)}`);
25054
+ }
25055
+ return deserializeValue(value, ejsonOptions);
25056
+ });
25057
+ }
25058
+ function stringify(value, replacer, space, options) {
25059
+ if (space != null && typeof space === 'object') {
25060
+ options = space;
25061
+ space = 0;
25062
+ }
25063
+ if (replacer != null && typeof replacer === 'object' && !Array.isArray(replacer)) {
25064
+ options = replacer;
25065
+ replacer = undefined;
25066
+ space = 0;
25067
+ }
25068
+ const serializeOptions = Object.assign({ relaxed: true, legacy: false }, options, {
25069
+ seenObjects: [{ propertyName: '(root)', obj: null }]
25070
+ });
25071
+ const doc = serializeValue(value, serializeOptions);
25072
+ return JSON.stringify(doc, replacer, space);
25073
+ }
25074
+ function EJSONserialize(value, options) {
25075
+ options = options || {};
25076
+ return JSON.parse(stringify(value, options));
25077
+ }
25078
+ function EJSONdeserialize(ejson, options) {
25079
+ options = options || {};
25080
+ return parse(JSON.stringify(ejson), options);
25081
+ }
25082
+ const EJSON = Object.create(null);
25083
+ EJSON.parse = parse;
25084
+ EJSON.stringify = stringify;
25085
+ EJSON.serialize = EJSONserialize;
25086
+ EJSON.deserialize = EJSONdeserialize;
25087
+ Object.freeze(EJSON);
25088
+
25089
+ const BSONElementType = {
25090
+ double: 1,
25091
+ string: 2,
25092
+ object: 3,
25093
+ array: 4,
25094
+ binData: 5,
25095
+ undefined: 6,
25096
+ objectId: 7,
25097
+ bool: 8,
25098
+ date: 9,
25099
+ null: 10,
25100
+ regex: 11,
25101
+ dbPointer: 12,
25102
+ javascript: 13,
25103
+ symbol: 14,
25104
+ javascriptWithScope: 15,
25105
+ int: 16,
25106
+ timestamp: 17,
25107
+ long: 18,
25108
+ decimal: 19,
25109
+ minKey: 255,
25110
+ maxKey: 127
25111
+ };
25112
+ function getSize(source, offset) {
25113
+ try {
25114
+ return NumberUtils.getNonnegativeInt32LE(source, offset);
25115
+ }
25116
+ catch (cause) {
25117
+ throw new BSONOffsetError('BSON size cannot be negative', offset, { cause });
25118
+ }
25119
+ }
25120
+ function findNull(bytes, offset) {
25121
+ let nullTerminatorOffset = offset;
25122
+ for (; bytes[nullTerminatorOffset] !== 0x00; nullTerminatorOffset++)
25123
+ ;
25124
+ if (nullTerminatorOffset === bytes.length - 1) {
25125
+ throw new BSONOffsetError('Null terminator not found', offset);
25126
+ }
25127
+ return nullTerminatorOffset;
25128
+ }
25129
+ function parseToElements(bytes, startOffset = 0) {
25130
+ startOffset ??= 0;
25131
+ if (bytes.length < 5) {
25132
+ throw new BSONOffsetError(`Input must be at least 5 bytes, got ${bytes.length} bytes`, startOffset);
25133
+ }
25134
+ const documentSize = getSize(bytes, startOffset);
25135
+ if (documentSize > bytes.length - startOffset) {
25136
+ throw new BSONOffsetError(`Parsed documentSize (${documentSize} bytes) does not match input length (${bytes.length} bytes)`, startOffset);
25137
+ }
25138
+ if (bytes[startOffset + documentSize - 1] !== 0x00) {
25139
+ throw new BSONOffsetError('BSON documents must end in 0x00', startOffset + documentSize);
25140
+ }
25141
+ const elements = [];
25142
+ let offset = startOffset + 4;
25143
+ while (offset <= documentSize + startOffset) {
25144
+ const type = bytes[offset];
25145
+ offset += 1;
25146
+ if (type === 0) {
25147
+ if (offset - startOffset !== documentSize) {
25148
+ throw new BSONOffsetError(`Invalid 0x00 type byte`, offset);
25149
+ }
25150
+ break;
25151
+ }
25152
+ const nameOffset = offset;
25153
+ const nameLength = findNull(bytes, offset) - nameOffset;
25154
+ offset += nameLength + 1;
25155
+ let length;
25156
+ if (type === BSONElementType.double ||
25157
+ type === BSONElementType.long ||
25158
+ type === BSONElementType.date ||
25159
+ type === BSONElementType.timestamp) {
25160
+ length = 8;
25161
+ }
25162
+ else if (type === BSONElementType.int) {
25163
+ length = 4;
25164
+ }
25165
+ else if (type === BSONElementType.objectId) {
25166
+ length = 12;
25167
+ }
25168
+ else if (type === BSONElementType.decimal) {
25169
+ length = 16;
25170
+ }
25171
+ else if (type === BSONElementType.bool) {
25172
+ length = 1;
25173
+ }
25174
+ else if (type === BSONElementType.null ||
25175
+ type === BSONElementType.undefined ||
25176
+ type === BSONElementType.maxKey ||
25177
+ type === BSONElementType.minKey) {
25178
+ length = 0;
25179
+ }
25180
+ else if (type === BSONElementType.regex) {
25181
+ length = findNull(bytes, findNull(bytes, offset) + 1) + 1 - offset;
25182
+ }
25183
+ else if (type === BSONElementType.object ||
25184
+ type === BSONElementType.array ||
25185
+ type === BSONElementType.javascriptWithScope) {
25186
+ length = getSize(bytes, offset);
25187
+ }
25188
+ else if (type === BSONElementType.string ||
25189
+ type === BSONElementType.binData ||
25190
+ type === BSONElementType.dbPointer ||
25191
+ type === BSONElementType.javascript ||
25192
+ type === BSONElementType.symbol) {
25193
+ length = getSize(bytes, offset) + 4;
25194
+ if (type === BSONElementType.binData) {
25195
+ length += 1;
25196
+ }
25197
+ if (type === BSONElementType.dbPointer) {
25198
+ length += 12;
25199
+ }
25200
+ }
25201
+ else {
25202
+ throw new BSONOffsetError(`Invalid 0x${type.toString(16).padStart(2, '0')} type byte`, offset);
25203
+ }
25204
+ if (length > documentSize) {
25205
+ throw new BSONOffsetError('value reports length larger than document', offset);
25206
+ }
25207
+ elements.push([type, nameOffset, nameLength, offset, length]);
25208
+ offset += length;
25209
+ }
25210
+ return elements;
25211
+ }
25212
+
25213
+ const onDemand = Object.create(null);
25214
+ onDemand.parseToElements = parseToElements;
25215
+ onDemand.ByteUtils = ByteUtils;
25216
+ onDemand.NumberUtils = NumberUtils;
25217
+ Object.freeze(onDemand);
25218
+
25219
+ const MAXSIZE = 1024 * 1024 * 17;
25220
+ ByteUtils.allocate(MAXSIZE);
25221
+
25222
+ try{if("undefined"==typeof fetch&&"undefined"!=typeof process&&process.versions?.node){new Function("m","return import(m)")("cross-fetch/polyfill").catch((()=>{}));}}catch{}function s(e){const t=new URLSearchParams;for(const[s,n]of Object.entries(e))if(void 0!==n)if(Array.isArray(n))for(const e of n)t.append(s,String(e));else t.append(s,String(n));const s=t.toString();return s?`?${s}`:""}try{if("undefined"!=typeof process&&process.versions?.node&&"win32"===process.platform){new Function("m","return import(m)")("win-ca");}}catch{}class o extends Error{constructor(e,t,s){super(s||t?.message||`HTTP ${e}`),this.name="ApiError",this.status=e,this.error_code=t?.error_code,this.request_id=t?.request_id,this.body=t;}}async function r(e){if(e.ok)return;let t;try{t=await e.json();}catch{try{const s=await e.text();t=s?{message:s}:void 0;}catch{t=void 0;}}throw new o(e.status,t)}class a{started=false;constructor(e,t,s="page_token"){this.fetchPage=e,this.baseParams={...t},this.tokenField=s;}hasNext(){return !this.started||!!this.nextToken}reset(){this.started=false,this.nextToken=void 0;}async next(){if(this.started&&!this.nextToken)return [];const e={...this.baseParams};this.started&&this.nextToken&&(e[this.tokenField]=this.nextToken);const t=await this.fetchPage(e);return this.started=true,this.nextToken=t?.next_page??null,t?.items??[]}}function c(e,t,s="page_token"){return new a(e,t,s)}async function l({client:e,limit:t,page_token:n,sort_by:o}){const a="/org/shortlinks"+s({limit:t,page_token:n,sort_by:o}),c=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+a,i=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",_={};i&&(_.Authorization=`Bearer ${i}`);const p={method:"GET",headers:_},O=e?.fetch||fetch,T=await O(c,p);await r(T);return await T.json()}async function N({client:e,limit:t,page_token:n,sort_by:o,role:a}){const c="/org/members"+s({limit:t,page_token:n,sort_by:o,role:a}),i=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+c,_=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",p={};_&&(p.Authorization=`Bearer ${_}`);const O={method:"GET",headers:p},T=e?.fetch||fetch,v=await T(i,O);await r(v);return await v.json()}async function y({client:e,limit:t,page_token:n,sort_by:o}){const a="/orgs"+s({limit:t,page_token:n,sort_by:o}),c=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+a,i=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",_={};i&&(_.Authorization=`Bearer ${i}`);const p={method:"GET",headers:_},O=e?.fetch||fetch,T=await O(c,p);await r(T);return await T.json()}const k={create_org:async function({client:e,body:t}){const n="/org"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_org_member:async function({client:e,body:t}){const n="/org/members"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_org_saml_idp:async function({client:e,body:t}){const n="/org/saml/idp"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},delete_org:async function({client:e}={}){const t="/org"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"DELETE",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},delete_org_member:async function({client:e,user_id:t}){const n=`/org/members/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"DELETE",headers:c},_=e?.fetch||fetch,p=await _(o,i);await r(p);},delete_org_saml_idp:async function({client:e}={}){const t="/org/saml/idp"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"DELETE",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},get_any_org:async function({client:e,id:t}){const n=`/orgs/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"GET",headers:c},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},get_org:async function({client:e}={}){const t="/org"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_org_member:async function({client:e,user_id:t}){const n=`/org/members/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"GET",headers:c},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},get_org_privacy_settings:async function({client:e}={}){const t="/org/privacy"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_org_saml_idp:async function({client:e}={}){const t="/org/saml/idp"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_org_shortlinks:l,get_org_shortlinks_pager:function(e){return c(l,e,"page_token")},get_user_org:async function({client:e}={}){const t="/user/org"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_org_members:N,list_org_members_pager:function(e){return c(N,e,"page_token")},list_orgs:y,list_orgs_pager:function(e){return c(y,e,"page_token")},update_enterprise_pricing_for_org:async function({client:e,id:t,body:n}){const o=`/orgs/${t}/enterprise/pricing`+s({}),a=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+o,c=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",i={};c&&(i.Authorization=`Bearer ${c}`),i["Content-Type"]="application/json";const _={method:"PUT",headers:i,body:JSON.stringify(n)},p=e?.fetch||fetch,O=await p(a,_);return await r(O),await O.json()},update_org:async function({client:e,body:t}){const n="/org"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_org_member:async function({client:e,user_id:t,body:n}){const o=`/org/members/${t}`+s({}),a=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+o,c=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",i={};c&&(i.Authorization=`Bearer ${c}`),i["Content-Type"]="application/json";const _={method:"PUT",headers:i,body:JSON.stringify(n)},p=e?.fetch||fetch,O=await p(a,_);return await r(O),await O.json()},update_org_privacy_settings:async function({client:e,body:t}){const n="/org/privacy"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_org_saml_idp:async function({client:e,body:t}){const n="/org/saml/idp"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()}},$={create_org_subscription:async function({client:e,body:t}){const n="/org/payment/subscriptions"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_payment_information_for_org:async function({client:e,body:t}){const n="/org/payment"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_payment_information_for_user:async function({client:e,body:t}){const n="/user/payment"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_payment_intent_for_org:async function({client:e}={}){const t="/org/payment/intent"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"POST",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},create_payment_intent_for_user:async function({client:e}={}){const t="/user/payment/intent"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"POST",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},create_user_subscription:async function({client:e,body:t}){const n="/user/payment/subscriptions"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},delete_payment_information_for_org:async function({client:e}={}){const t="/org/payment"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"DELETE",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},delete_payment_information_for_user:async function({client:e}={}){const t="/user/payment"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"DELETE",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},delete_payment_method_for_org:async function({client:e,id:t}){const n=`/org/payment/methods/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"DELETE",headers:c},_=e?.fetch||fetch,p=await _(o,i);await r(p);},delete_payment_method_for_user:async function({client:e,id:t}){const n=`/user/payment/methods/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"DELETE",headers:c},_=e?.fetch||fetch,p=await _(o,i);await r(p);},get_org_subscription:async function({client:e}={}){const t="/org/payment/subscriptions"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_payment_balance_for_any_org:async function({client:e,include_total_due:t,id:n}){const o=`/orgs/${n}/payment/balance`+s({include_total_due:t}),a=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+o,c=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",i={};c&&(i.Authorization=`Bearer ${c}`);const _={method:"GET",headers:i},p=e?.fetch||fetch,O=await p(a,_);return await r(O),await O.json()},get_payment_balance_for_any_user:async function({client:e,id:t,include_total_due:n}){const o=`/users/${t}/payment/balance`+s({include_total_due:n}),a=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+o,c=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",i={};c&&(i.Authorization=`Bearer ${c}`);const _={method:"GET",headers:i},p=e?.fetch||fetch,O=await p(a,_);return await r(O),await O.json()},get_payment_balance_for_org:async function({client:e,include_total_due:t}){const n="/org/payment/balance"+s({include_total_due:t}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"GET",headers:c},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},get_payment_balance_for_user:async function({client:e,include_total_due:t}){const n="/user/payment/balance"+s({include_total_due:t}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"GET",headers:c},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},get_payment_information_for_org:async function({client:e}={}){const t="/org/payment"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_payment_information_for_user:async function({client:e}={}){const t="/user/payment"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_user_subscription:async function({client:e}={}){const t="/user/payment/subscriptions"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_invoices_for_org:async function({client:e}={}){const t="/org/payment/invoices"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_invoices_for_user:async function({client:e}={}){const t="/user/payment/invoices"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_payment_methods_for_org:async function({client:e}={}){const t="/org/payment/methods"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_payment_methods_for_user:async function({client:e}={}){const t="/user/payment/methods"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},update_org_subscription:async function({client:e,body:t}){const n="/org/payment/subscriptions"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_payment_balance_for_any_org:async function({client:e,id:t,include_total_due:n,body:o}){const a=`/orgs/${t}/payment/balance`+s({include_total_due:n}),c=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+a,i=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",_={};i&&(_.Authorization=`Bearer ${i}`),_["Content-Type"]="application/json";const p={method:"PUT",headers:_,body:JSON.stringify(o)},O=e?.fetch||fetch,T=await O(c,p);return await r(T),await T.json()},update_payment_balance_for_any_user:async function({client:e,id:t,include_total_due:n,body:o}){const a=`/users/${t}/payment/balance`+s({include_total_due:n}),c=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+a,i=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",_={};i&&(_.Authorization=`Bearer ${i}`),_["Content-Type"]="application/json";const p={method:"PUT",headers:_,body:JSON.stringify(o)},O=e?.fetch||fetch,T=await O(c,p);return await r(T),await T.json()},update_payment_information_for_org:async function({client:e,body:t}){const n="/org/payment"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_payment_information_for_user:async function({client:e,body:t}){const n="/user/payment"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_user_subscription:async function({client:e,body:t}){const n="/user/payment/subscriptions"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},validate_customer_tax_information_for_org:async function({client:e}={}){const t="/org/payment/tax"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},validate_customer_tax_information_for_user:async function({client:e}={}){const t="/user/payment/tax"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);}};
25223
+
25224
+ /**
25225
+ * Adapted from https://github.com/KittyCAD/text-to-cad-ui/blob/309a2e756732b7b9a2b095d6a0f99bc23872d542/src/lib/billing.ts
25226
+ */
25227
+ var EBillingError;
25228
+ (function (EBillingError) {
25229
+ EBillingError[EBillingError["NotOk"] = 0] = "NotOk";
25230
+ EBillingError[EBillingError["UnexpectedStatus"] = 1] = "UnexpectedStatus";
25231
+ EBillingError[EBillingError["CatastrophicRequest"] = 2] = "CatastrophicRequest";
25232
+ EBillingError[EBillingError["JSONParse"] = 3] = "JSONParse";
25233
+ })(EBillingError || (EBillingError = {}));
25234
+ class BillingError {
25235
+ constructor(error) {
25236
+ Object.defineProperty(this, "error", {
25237
+ enumerable: true,
25238
+ configurable: true,
25239
+ writable: true,
25240
+ value: error
25241
+ });
25242
+ }
25243
+ static from(v) {
25244
+ return (typeof v === 'object' &&
25245
+ 'error' in v &&
25246
+ 'type' in v.error &&
25247
+ Object.values(EBillingError).some((x) => x === v.error.type));
25248
+ }
25249
+ }
25250
+ async function fetchBilling(fn, options) {
25251
+ try {
25252
+ const response = await fn(options);
25253
+ if (response === null) {
25254
+ return new BillingError({
25255
+ type: EBillingError.CatastrophicRequest,
25256
+ });
25257
+ }
25258
+ if (typeof response === 'number') {
25259
+ return new BillingError({
25260
+ type: EBillingError.UnexpectedStatus,
25261
+ code: Number(response),
25262
+ });
25263
+ }
25264
+ return response;
25265
+ }
25266
+ catch (e) {
25267
+ if (e && typeof e === 'object' && 'status' in e && 'body' in e) {
25268
+ const fallbackErrorMessage = `Failed to request endpoint: ${e.status}`;
25269
+ const data = e.body;
25270
+ const resolvedMessage = data instanceof Object && 'message' in data
25271
+ ? data.message
25272
+ : fallbackErrorMessage;
25273
+ return new BillingError({
25274
+ type: EBillingError.NotOk,
25275
+ response: e,
25276
+ data: JSON.stringify(data),
25277
+ message: resolvedMessage,
25278
+ });
25279
+ }
25280
+ if (e instanceof SyntaxError) {
25281
+ return new BillingError({
25282
+ type: EBillingError.JSONParse,
25283
+ error: e,
25284
+ });
25285
+ }
25286
+ return new BillingError({
25287
+ type: EBillingError.CatastrophicRequest,
25288
+ });
25289
+ }
25290
+ }
25291
+ async function getBillingInfo(client) {
25292
+ const billing = await fetchBilling($.get_payment_balance_for_user, { client, include_total_due: false });
25293
+ if (BillingError.from(billing)) {
25294
+ return billing;
25295
+ }
25296
+ const subscriptions = await fetchBilling($.get_user_subscription, { client });
25297
+ const org = await fetchBilling(k.get_user_org, { client });
25298
+ if (!BillingError.from(org)) {
25299
+ // Org override here. TODO for api: remove the need for this
25300
+ // If the user is part of an org, they get infinite credits.
25301
+ return {
25302
+ credits: Number.POSITIVE_INFINITY,
25303
+ isOrg: true,
25304
+ hasSubscription: true,
25305
+ };
25306
+ }
25307
+ if (BillingError.from(subscriptions)) {
25308
+ return subscriptions;
25309
+ }
25310
+ const tier = subscriptions.modeling_app.name;
25311
+ const computedAllowance = subscriptions.modeling_app.monthly_pay_as_you_go_api_credits;
25312
+ const computedCredits = Number(billing.monthly_api_credits_remaining) +
25313
+ Number(billing.stable_api_credits_remaining);
25314
+ let allowance;
25315
+ let credits;
25316
+ let hasSubscription;
25317
+ let isOrg;
25318
+ switch (tier) {
25319
+ case 'enterprise':
25320
+ case 'team':
25321
+ credits = Number.POSITIVE_INFINITY;
25322
+ hasSubscription = true;
25323
+ isOrg = true;
25324
+ break;
25325
+ case 'pro':
25326
+ credits = Number.POSITIVE_INFINITY;
25327
+ hasSubscription = true;
25328
+ isOrg = false;
25329
+ break;
25330
+ case 'plus':
25331
+ allowance = computedAllowance;
25332
+ credits = computedCredits;
25333
+ isOrg = false;
25334
+ hasSubscription = true;
25335
+ break;
25336
+ case 'free':
25337
+ allowance = computedAllowance;
25338
+ credits = computedCredits;
25339
+ isOrg = false;
25340
+ hasSubscription = false;
25341
+ break;
25342
+ default: {
25343
+ const _exh = tier;
25344
+ throw new Error(`Unhandled subscription tier: ${_exh}`);
25345
+ }
25346
+ }
25347
+ return {
25348
+ allowance,
25349
+ credits,
25350
+ hasSubscription,
25351
+ isOrg,
25352
+ };
25353
+ }
25354
+
21943
25355
  exports.BillingDialog = BillingDialog;
25356
+ exports.BillingError = BillingError;
21944
25357
  exports.BillingRemaining = BillingRemaining;
21945
25358
  exports.Button = Button;
21946
25359
  exports.CustomIcon = CustomIcon;
@@ -21949,4 +25362,5 @@ exports.LoginTitle = LoginTitle;
21949
25362
  exports.SignInPageContent = SignInPageContent;
21950
25363
  exports.Spinner = Spinner;
21951
25364
  exports.cn = cn;
25365
+ exports.getBillingInfo = getBillingInfo;
21952
25366
  //# sourceMappingURL=index.js.map