1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[75173],{75173:(e,t,r)=>{r.r(t),r.d(t,{default:()=>e_});var s=r(45993),n=r(75837),a=r(17832),i=r(77771),l=r(30845),o=r(35323),d=r(41945),u=r(73950),c=r(14552);let m=["null","boolean","int","long","float","double","bytes","string"],h=new Set(m),f=/^[A-Za-z_][A-Za-z0-9_]*$/,p=new Set(["record","error","enum","fixed"]),y=["record","error","enum","array","map","fixed"],g={union:'A union has no type name in Avro. It is written as an array of its branches, for example ["null", "string"].',record:'A record is written out in full: { "type": "record", "name": "...", "fields": [...] }.',error:'An error is a record: { "type": "error", "name": "...", "fields": [...] }.',enum:'An enum is written out in full: { "type": "enum", "name": "...", "symbols": ["A", "B"] }.',fixed:'A fixed is written out in full: { "type": "fixed", "name": "...", "size": 16 }.',array:'An array is written out in full: { "type": "array", "items": "string" }.',map:'A map is written out in full: { "type": "map", "values": "long" }.'};function x(e){return"string"==typeof e&&h.has(e)}function b(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function v(e){return""!==e&&e.split(".").every(e=>f.test(e))}function w(e,t){return e.includes(".")?e:t?`${t}.${e}`:e}function $(e){let t=e.lastIndexOf(".");return t<0?"":e.slice(0,t)}function N(e,t){let r="string"==typeof e.name?e.name:"";return r.includes(".")?$(r):"string"==typeof e.namespace?e.namespace:t}function j(e){return""===e?"the schema root":e}let A=(e,t)=>e?`${e}.${t}`:t;function k(e){let t=new Map,r=new Set;return!function e(s,n){if(Array.isArray(s)){for(let t of s)e(t,n);return}if(!b(s)||r.has(s))return;r.add(s);let a=s.type;if("string"!=typeof a)return void e(a,n);if(p.has(a)&&"string"==typeof s.name){let r=N(s,n),a=w(s.name,r);if(t.has(a)||t.set(a,{node:s,ns:r}),Array.isArray(s.fields))for(let t of s.fields)b(t)&&e(t.type,r);return}"array"===a?e(s.items,n):"map"===a&&e(s.values,n)}(e,""),t}function S(e,t,r){if("string"==typeof e)return x(e)?null:r.get(w(e,t))??null;if(b(e)&&"string"==typeof e.type&&!x(e.type)){if(p.has(e.type))return{node:e,ns:N(e,t)};if("array"!==e.type&&"map"!==e.type)return r.get(w(e.type,t))??null}return null}function T(e,t,r){if(Array.isArray(e))return"union";if("string"==typeof e){if(x(e))return e;let s=r.get(w(e,t));if(!s)return"unknown";let n=s.node.type;return"string"==typeof n?"error"===n?"record":n:"unknown"}if(b(e)){let s=e.type;return Array.isArray(s)?"union":"string"!=typeof s?"unknown":x(s)?s:"error"===s?"record":p.has(s)||"array"===s||"map"===s?s:T(s,t,r)}return"unknown"}function O(e){if("string"==typeof e)return`"${e}"`;if(Array.isArray(e))return`a union of ${e.map(e=>O(e)).join(", ")}`;if(b(e)){let t=e.type;return"string"==typeof t?p.has(t)&&"string"==typeof e.name?`${t} "${e.name}"`:"string"==typeof e.logicalType?`"${t}" as ${e.logicalType}`:`"${t}"`:"a nested type"}return String(e)}function C(e){try{return JSON.stringify(e)}catch{return String(e)}}let z={decimal:["bytes","fixed"],uuid:["string","fixed"],date:["int"],"time-millis":["int"],"time-micros":["long"],"timestamp-millis":["long"],"timestamp-micros":["long"],"local-timestamp-millis":["long"],"local-timestamp-micros":["long"],duration:["fixed"]};function J(e,t,r,s){let n=e.logicalType;if(void 0===n)return;if("string"!=typeof n)return void s.issues.push({path:A(r,"logicalType"),sev:"error",message:"A logicalType has to be a string naming the logical type."});let a=z[n];if(!a)return void s.issues.push({path:A(r,"logicalType"),sev:"warning",message:`"${n}" is not one of the logical types in the Avro specification, so readers will ignore it and treat this as a plain "${t}".`,fix:"Custom logical types are allowed, so this is only a problem if you expected a reader to act on it."});if(!a.includes(t))return void s.issues.push({path:A(r,"logicalType"),sev:"warning",message:`"${n}" only applies to ${a.map(e=>`"${e}"`).join(" or ")}, and this is a "${t}". Avro does not reject a mismatched logical type, it drops it, so this field will be read as a plain "${t}" with the logical type silently gone.`,fix:`Change the underlying type to ${a.map(e=>`"${e}"`).join(" or ")}, or remove the logicalType.`});if("decimal"===n){let n=e.precision,a=void 0===e.scale?0:e.scale;if("number"!=typeof n||!Number.isInteger(n)||n<1)s.issues.push({path:A(r,"precision"),sev:"error",message:'A decimal needs a "precision", a whole number of 1 or more, giving the maximum number of digits it can hold.',fix:'Add something like "precision": 10, "scale": 2.'});else if("number"!=typeof a||!Number.isInteger(a)||a<0||a>n)s.issues.push({path:A(r,"scale"),sev:"error",message:`A decimal "scale" has to be a whole number between 0 and the precision (${n}). Found ${JSON.stringify(a)}.`});else if("fixed"===t&&"number"==typeof e.size){let t=Math.floor((8*e.size-1)*Math.LOG10E*Math.LN2);n>t&&s.issues.push({path:A(r,"precision"),sev:"error",message:`A fixed of ${e.size} byte${1===e.size?"":"s"} can only hold ${t} digits of precision, and this asks for ${n}.`,fix:`Raise "size", or lower "precision" to ${t} or less.`})}}"duration"===n&&12!==e.size&&s.issues.push({path:A(r,"size"),sev:"error",message:`A duration is always a fixed of size 12, three 4-byte counts for months, days and milliseconds. This one is ${JSON.stringify(e.size)}.`,fix:'Set "size": 12.'}),"uuid"===n&&"fixed"===t&&16!==e.size&&s.issues.push({path:A(r,"size"),sev:"error",message:`A uuid on a fixed needs "size": 16. This one is ${JSON.stringify(e.size)}.`})}function L(e,t,r,s){if("string"==typeof e)return x(e)?void 0:v(e)?void s.refs.push({name:w(e,r),typed:e,path:t,order:s.order++}):void s.issues.push({path:t,sev:"error",message:`"${e}" is not a usable type name. Names start with a letter or an underscore, then allow letters, digits and underscores, with dots separating the namespace.`});if(Array.isArray(e))return void R(e,t,r,s);if(!b(e))return void s.issues.push({path:t,sev:"error",message:`Expected a type here, but found ${null===e?"null":typeof e}
1. A type is a name like "string", an object like { "type": "record", ... }, or an array of types for a union.`});if(s.seen.has(e))return;s.seen.add(e);let n=e.type;if(void 0===n)return void s.issues.push({path:t,sev:"error",message:'This object has no "type", so there is no way to tell what it describes.',fix:'Add a "type", for example "type": "record" or "type": "string".'});if(Array.isArray(n))return void R(n,A(t,"type"),r,s);if(b(n))return void L(n,A(t,"type"),r,s);if("string"!=typeof n)return void s.issues.push({path:A(t,"type"),sev:"error",message:`"type" has to name a type. Found ${typeof n}.`});if(x(n))return void J(e,n,t,s);switch(n){case"record":case"error":!function(e,t,r,s){E(e,"record",t,r,s);let n=N(e,r),a=e.fields;if(!Array.isArray(a))return s.issues.push({path:A(t,"fields"),sev:"error",message:'A record needs a "fields" array, even if it is empty.'});let i=new Map;a.forEach((e,r)=>{let a,l=(a="fields",t?`${t}.${a}[${r}]`:`${a}[${r}]`);if(!b(e))return void s.issues.push({path:l,sev:"error",message:'Each field is an object with at least a "name" and a "type".'});let o=e.name;if("string"!=typeof o||""===o)s.issues.push({path:l,sev:"error",message:'This field has no "name".'});else{f.test(o)||s.issues.push({path:`${l} "${o}"`,sev:"error",message:`"${o}" is not a valid field name. Field names start with a letter or an underscore and then hold only letters, digits and underscores, with no dots.`,fix:/^[0-9]/.test(o)?`A leading digit is the usual cause. "_${o}" is legal, or rename it in words.`:`Replace the punctuation with underscores, so "${o.replace(/[^A-Za-z0-9_]/g,"_")}".`});let e=i.get(o);void 0!==e?s.issues.push({path:`${l} "${o}"`,sev:"error",message:`This record already has a field called "${o}" at position ${e}. Field names have to be unique inside one record.`}):i.set(o,r)}let d="string"==typeof o&&o?`${l} "${o}"`:l;void 0===e.type?s.issues.push({path:d,sev:"error",message:'This field has no "type".'}):(L(e.type,A(d,"type"),n,s),"default"in e&&function(e,t,r,s,n){let a=A(r,"default");if(Array.isArray(e)){if(0===e.length)return;let r=e[0],i=D(r,t,s,n);if(!i)return;let l=e.findIndex((e,r)=>r>0&&null===D(e,t,s,n));if(l>0){let s=[e[l],...e.filter((e,t)=>t!==l)];n.issues.push({path:a,sev:"error",message:`The default ${JSON.stringify(t)} matches branch ${l} of this union, but Avro checks a union default against the FIRST branch only, and that is ${O(r)}. A registry will reject this.`,fix:`Put the matching branch first: ${C(s)}.`})}else n.issues.push({path:a,sev:"error",message:`The default ${JSON.stringify(t)} does not fit any branch of this union, and Avro checks it against the first branch, ${O(r)}. ${i}`});return}let i=D(e,t,s,n);i&&n.issues.push({path:a,sev:"error",message:`The default ${JSON.stringify(t)} does not match ${O(e)}. ${i}`})}(e.type,e.default,d,n,s)),void 0===e.order||["ascending","descending","ignore"].includes(String(e.order))||s.issues.push({path:A(d,"order"),sev:"error",message:`"order" has to be ascending, descending or ignore. Found ${JSON.stringify(e.order)}.`}),F(e,d,s)})}(e,t,r,s);return;case"enum":!function(e,t,r,s){E(e,"enum",t,r,s);let n=e.symbols;if(!Array.isArray(n))return s.issues.push({path:A(t,"symbols"),sev:"error",message:'An enum needs a "symbols" array listing its allowed values.'});0===n.length&&s.issues.push({path:A(t,"symbols"),sev:"error",message:"This enum has no symbols, so no value can ever be valid for it."});let a=new Map;if(n.forEach((e,r)=>{let n=`${A(t,"symbols")}[${r}]`;if("string"!=typeof e||!f.test(e))return void s.issues.push({path:n,sev:"error",message:`${JSON.stringify(e)} is not a valid enum symbol. Symbols follow the same rules as names, so no spaces, dots or leading digits.`,fix:"string"==typeof e?`Try "${e.replace(/[^A-Za-z0-9_]/g,"_").replace(/^([0-9])/,"_$1")}".`:void 0});let i=a.get(e);void 0!==i?s.issues.push({path:n,sev:"error",message:`"${e}" already appears at position ${i}. Enum symbols have to be unique.`}):a.set(e,r)}),void 0!==e.default){let r=e.default;"string"==typeof r&&n.includes(r)||s.issues.push({path:A(t,"default"),sev:"error",message:`The enum default ${JSON.stringify(r)} is not one of its own symbols (${n.filter(e=>"string"==typeof e).join(", ")}). A reader falls back to this value when it meets a symbol it does not know, so it has to be a symbol it does know.`,fix:n.length?`Use one of the listed symbols, for example ${JSON.stringify(n[0])}.`:void 0})}}(e,t,r,s);return;case"fixed":var a=e,i=t,l=r,o=s;E(a,"fixed",i,l,o);let d=a.size;("number"!=typeof d||!Number.isInteger(d)||d<1)&&o.issues.push({path:A(i,"size"),sev:"error",message:`A fixed needs a "size" in whole bytes, 1 or more. Found ${JSON.stringify(d)}.`}
1),J(a,"fixed",i,o);return;case"array":void 0===e.items?s.issues.push({path:t,sev:"error",message:'An array needs an "items" type saying what it holds.',fix:'Add something like "items": "string".'}):L(e.items,A(t,"items"),r,s);return;case"map":void 0===e.values?s.issues.push({path:t,sev:"error",message:'A map needs a "values" type. Map keys are always strings in Avro, so only the value type is declared.',fix:'Add something like "values": "long".'}):L(e.values,A(t,"values"),r,s);return;default:if(!v(n))return void s.issues.push({path:A(t,"type"),sev:"error",message:`"${n}" is not an Avro type. The primitives are ${m.join(", ")}. The complex types written as { "type": ... } are ${y.join(", ")}. A union has no type name. It is written as an array of its branches, like ["null", "string"].`});s.refs.push({name:w(n,r),typed:n,path:A(t,"type"),order:s.order++})}}function R(e,t,r,s){if(0===e.length)return void s.issues.push({path:t,sev:"error",message:"This union has no branches. A union has to list at least one type."});let n=new Map;e.forEach((e,a)=>{let i=`${t}[${a}]`;if(Array.isArray(e))s.issues.push({path:i,sev:"error",message:"A union cannot contain another union directly. Avro has no nested unions.",fix:"Flatten the inner branches into this union."});else{let t=function(e,t){if("string"==typeof e)return x(e)?e:w(e,t);if(b(e)){let r=e.type;return"string"!=typeof r?null:x(r)||"array"===r||"map"===r?r:p.has(r)&&"string"==typeof e.name?w(e.name,N(e,t)):w(r,t)}return null}(e,r);if(null!==t){let e=n.get(t);void 0!==e?s.issues.push({path:i,sev:"error",message:`This union already has a ${t} branch at position ${e}. A union can hold each unnamed type only once, and two named types in it cannot share a full name.`,fix:h.has(t)?"Drop the duplicate branch, or give one of them a different type.":"Give the two definitions different names or namespaces."}):n.set(t,a)}}L(e,i,r,s)})}function F(e,t,r){let s=e.aliases;if(void 0!==s){if(!Array.isArray(s))return void r.issues.push({path:A(t,"aliases"),sev:"error",message:'"aliases" has to be an array of names.'});s.forEach((e,s)=>{"string"==typeof e&&v(e)||r.issues.push({path:`${A(t,"aliases")}[${s}]`,sev:"error",message:`${JSON.stringify(e)} is not a valid alias. An alias follows the same name rules as a name.`})})}}function E(e,t,r,s,n){let a=e.name;if("string"!=typeof a||""===a)return n.issues.push({path:r,sev:"error",message:`A ${t} needs a "name". Records, enums and fixed types are named so other parts of the schema can refer back to them.`}),"";v(a)||n.issues.push({path:A(r,"name"),sev:"error",message:`"${a}" is not a valid Avro name. A name starts with a letter or an underscore, then allows letters, digits and underscores. Dots are only there to separate a namespace.`,fix:/^[0-9]/.test(a)?`Names cannot start with a digit. Rename it, for example "_${a}".`:"Remove the characters outside letters, digits and underscores."});let i=N(e,s);"string"!=typeof e.namespace||v(e.namespace)||n.issues.push({path:A(r,"namespace"),sev:"error",message:`"${e.namespace}" is not a valid namespace. It is a dot-separated list of names, like com.acme.events.`});let l=w(a,i),o=n.defined.get(l);return o?n.issues.push({path:A(r,"name"),sev:"error",message:`"${l}" is already defined at ${j(o.path)}. Every named type in a schema needs its own full name.`,fix:"Rename one of them, or put them in different namespaces, or define it once and refer to it by name the second time."}):n.defined.set(l,{order:n.order++,path:r}),F(e,r,n),l}function D(e,t,r,s){if(Array.isArray(e)){let n=e[0];return void 0===n?null:D(n,t,r,s)}switch(T(e,r,s.names)){case"null":return null===t?null:"A null field takes null and nothing else.";case"boolean":return"boolean"==typeof t?null:"Expected true or false.";case"int":case"long":return"number"==typeof t&&Number.isInteger(t)?null:"Expected a whole number.";case"float":case"double":return"number"==typeof t?null:"Expected a number.";case"bytes":case"fixed":return"string"==typeof t?null:"Defaults for bytes and fixed are written as JSON strings, one character per byte.";case"string":return"string"==typeof t?null:"Expected a string.";case"enum":{if("string"!=typeof t)return"An enum default is the symbol name as a string.";let n=S(e,r,s.names),a=n&&Array.isArray(n.node.symbols)?n.node.symbols:null;if(a&&!a.includes(t))return`"${t}" is not one of its symbols (${a.join(", ")}).`;return null}case"array":return Array.isArray(t)?null:"Expected an array.";
1case"map":return b(t)?null:"Expected an object of key to value.";case"record":return b(t)?null:"Expected an object with the record fields in it.";default:return null}}let I=["type","name","namespace","doc","aliases","fields","symbols","items","values","size","logicalType","precision","scale","default"],M=["name","type","doc","default","order","aliases","logicalType"],U={2:" ",4:" ",tab:" ",min:""};function _(e,t,r){let s=r?function e(t,r){if(Array.isArray(t))return t.map(t=>e(t,!1));if(!b(t))return t;let s={...t};Array.isArray(s.fields)&&(s.fields=s.fields.map(t=>e(t,!0))),"items"in s&&(s.items=e(s.items,!1)),"values"in s&&(s.values=e(s.values,!1)),"type"in s&&(Array.isArray(s.type)||b(s.type))&&(s.type=e(s.type,!1));let n={};for(let e of r?M:I)Object.prototype.hasOwnProperty.call(s,e)&&(n[e]=s[e]);for(let e of Object.keys(s))Object.prototype.hasOwnProperty.call(n,e)||(n[e]=s[e]);return n}(e,!1):e;return"min"===t?JSON.stringify(s):JSON.stringify(s,null,U[t])}let P=null;async function B(e){let t=globalThis.crypto?.subtle;return t?[...new Uint8Array(await t.digest("SHA-256",new TextEncoder().encode(e)))].map(e=>e.toString(16).padStart(2,"0")).join(""):""}let W=e=>JSON.stringify(e),Z=e=>Array.isArray(e)?[...e]:[e];function V(e){let t=new Set,r=[];for(let s of e){let e=W(s);t.has(e)||(t.add(e),r.push(s))}return 1===r.length?r[0]:[...r.filter(e=>"null"===e),...r.filter(e=>"null"!==e)]}function K(e){let t=Z(e.type);return{...e,type:t.includes("null")?e.type:V(["null",...t]),default:null}}let q=(e,t)=>{let r=e.replace(/[^A-Za-z0-9_]/g,"_").replace(/^([0-9])/,"_$1");return""===r?t:r},G={null:["null"],boolean:["boolean"],int:["int","long","float","double"],long:["long","float","double"],float:["float","double"],double:["double"],bytes:["bytes","string"],string:["string","bytes"]},H=new Set(Object.keys(G));function Y(e){return b(e)&&(Array.isArray(e.type)||b(e.type))?Y(e.type):e}function Q(e,t,r){let s=S(e,t,r);return s&&"string"==typeof s.node.name?w(s.node.name,s.ns):"string"==typeof e?w(e,t):""}function X(e,t,r){let s=S(e,t,r);return s?s.ns:b(e)?N(e,t):t}function ee(e,t,r){let s=S(e,t,r);return s?s.node:b(e)?e:null}function et(e,t,r){let s={readerNames:k(e),writerNames:k(t),roles:r};return function e(t,r,s,n,a,i,l){let o=Y(t),d=Y(s),u=Array.isArray(o);if(Array.isArray(d)){let t=[];for(let s of d)(u?o.some(t=>0===e(t,r,s,n,a,i,l).length):0===e(o,r,s,n,a,i,l).length)||t.push({path:a,kind:"missing-union-branch",message:`${i.roles.writer} can write ${O(s)} here and ${i.roles.reader} has no branch that accepts it.`,fix:`Add ${C(s)} to the union in ${i.roles.reader}.`});return t}if(u)return o.some(t=>0===e(t,r,d,n,a,i,l).length)?[]:[{path:a,kind:"type-mismatch",message:`${i.roles.writer} writes ${O(d)} here, and no branch of the union in ${i.roles.reader} can read that.`}];let c=T(o,r,i.readerNames),m=T(d,n,i.writerNames);if("unknown"===c||"unknown"===m)return[];if(H.has(c)&&H.has(m))return(G[m]??[]).includes(c)?[]:[{path:a,kind:"type-mismatch",message:`${i.roles.writer} writes "${m}" here and ${i.roles.reader} expects "${c}". Avro only promotes upward, int to long, float or double, long to float or double, float to double, and string to bytes or back.`,fix:G[c]?.includes(m)===!0?`This narrows the type, which loses data. Keep "${m}" in ${i.roles.reader}.`:void 0}];if(c!==m)return[{path:a,kind:"type-mismatch",message:`${i.roles.writer} writes a ${m} here and ${i.roles.reader} expects a ${c}. There is no conversion between them.`}];if("array"===c){let t=ee(o,r,i.readerNames),s=ee(d,n,i.writerNames);return t&&s?e(t.items,r,s.items,n,`${a}[]`,i,l):[]}if("map"===c){let t=ee(o,r,i.readerNames),s=ee(d,n,i.writerNames);return t&&s?e(t.values,r,s.values,n,`${a}{}`,i,l):[]}let h=Q(o,r,i.readerNames),f=Q(d,n,i.writerNames),p=[];if(h!==f&&!(function(e,t,r){let s=S(e,t,r);return s&&Array.isArray(s.node.aliases)?s.node.aliases.filter(e=>"string"==typeof e).map(e=>w(e,s.ns)):[]})(o,r,i.readerNames).includes(f))return p.push({path:a,kind:"name-mismatch",message:`The ${c} is called "${f}" in ${i.roles.writer} and "${h}" in ${i.roles.reader}. Avro matches named types by full name, so a rename or a new namespace counts as a different type.`,fix:`Add "aliases": ["${f}"] to the ${c} in ${i.roles.reader}, which is how Avro is told the two are the same type.`}),p;let y=`${h}|${f}`;if(l.has(y))return p;let g=new Set(l);g.add(y);let x=ee(o,r,i.readerNames),v=ee(d,n,i.writerNames);if(!x||!v)return p;if("fixed"===c){let e=x.size,t=v.size;return e!==t&&p.push({path:a,kind:"fixed-size-mismatch",message:`The fixed "${h}" is ${String(t)} bytes in ${i.roles.writer} and ${String(e)} bytes in ${i.roles.reader}. A fixed carries no length on the wire, so the reader would take the wrong number of bytes.`,fix:"A fixed size c
1an never change. Define a new named type instead."}),p}if("enum"===c){let e=Array.isArray(x.symbols)?x.symbols.map(String):[],t=(Array.isArray(v.symbols)?v.symbols.map(String):[]).filter(t=>!e.includes(t));return t.length&&void 0===x.default&&p.push({path:a,kind:"missing-enum-symbols",message:`The enum "${h}" can hold ${t.map(e=>`"${e}"`).join(", ")} in ${i.roles.writer}, and ${i.roles.reader} does not list ${1===t.length?"it":"them"}. A reader that meets a symbol it does not know has nowhere to put it.`,fix:`Add ${t.map(e=>`"${e}"`).join(", ")} to the enum in ${i.roles.reader}, or give that enum a "default" symbol. An enum with no default can never change its symbol list without breaking a consumer that has not been updated yet, so the default has to ship before the symbol does.`}),p}let $=Array.isArray(x.fields)?x.fields:[],N=Array.isArray(v.fields)?v.fields:[],j=new Map;for(let e of N)b(e)&&"string"==typeof e.name&&j.set(e.name,e);let A=X(o,r,i.readerNames),k=X(d,n,i.writerNames);return $.forEach((t,r)=>{if(!b(t)||"string"!=typeof t.name)return;let s=a?`${a}.${t.name}`:`fields[${r}] "${t.name}"`,n=j.get(t.name);if(!n&&Array.isArray(t.aliases)){for(let e of t.aliases)if("string"==typeof e&&j.has(e)){n=j.get(e);break}}if(n)return void p.push(...e(t.type,A,n.type,k,s,i,g));"default"in t||p.push({path:s,kind:"missing-default",message:`"${t.name}" is in ${i.roles.reader} but not in ${i.roles.writer}, and it has no default. Every record written by ${i.roles.writer} arrives with nothing for that field and the reader has no value to fall back on.`,fix:function(e){if(Array.isArray(e)){if("null"===e[0])return'Add "default": null to the field.';if(e.includes("null")){let t=["null",...e.filter(e=>"null"!==e)];return`Put null first, so ${C(t)}, then add "default": null.`}return`Make it nullable with ${C(["null",...e])} and add "default": null.`}return void 0===e?"Give the field a default.":`Change the type to ${C(["null",e])} and add "default": null, or give it a plain default of the right type.`}(t.type)})}),p}(e,"",t,"","",s,new Set)}let er="the new schema",es="the old schema";var en=r(89448);
1class ea extends Error{}let ei=[79,98,106,1];class el{constructor(e){this.bytes=e,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}get remaining(){return this.bytes.length-this.pos}need(e){if(this.pos+e>this.bytes.length)throw new ea("The file ends in the middle of a value, so it is cut short.")}byte(){return this.need(1),this.bytes[this.pos++]}varLong(){let e=0n,t=0n;for(let r=0;r<10;r++){let r=this.byte();if(t|=BigInt(127&r)<<e,(128&r)==0)return t>>1n^-(1n&t);e+=7n}throw new ea("A number in this file runs past 10 bytes, which no valid Avro long does.")}varInt(){return Number(this.varLong())}take(e){if(e<0)throw new ea("A length in this file is negative, so the data is corrupt.");this.need(e);let t=this.bytes.subarray(this.pos,this.pos+e);return this.pos+=e,t}float(){this.need(4);let e=this.view.getFloat32(this.pos,!0);return this.pos+=4,e}double(){this.need(8);let e=this.view.getFloat64(this.pos,!0);return this.pos+=8,e}text(){let e=Number(this.varLong());return new TextDecoder().decode(this.take(e))}}async function eo(e){let t=globalThis.DecompressionStream;if(!t)throw new ea("This browser cannot unpack a deflate-compressed Avro file. Chrome, Edge, Firefox 113 and Safari 16.4 and newer all can.");try{let r=new Blob([e]).stream().pipeThrough(new t("deflate-raw")),s=await new Response(r).arrayBuffer();return new Uint8Array(s)}catch{throw new ea("A compressed block would not unpack. The file says it uses deflate, so either it is damaged or it was written with a different codec than its header claims.")}}let ed=null;function eu(e,t){let r=Number(e);if(!Number.isFinite(r)||Math.abs(r)>864e13)return`${e.toString()} ms`;let s=new Date(r).toISOString();return t?s:s.slice(0,-1)}function ec(e,t){let r=e/1000n,s=e%1000n;s<0n&&(r-=1n,s+=1000n);let n=eu(r,!0);if(!n.endsWith("Z"))return`${e.toString()} us`;let a=`${n.slice(0,-1)}${s.toString().padStart(3,"0")}Z`;return t?a:a.slice(0,-1)}function em(e,t,r){if(!Number.isFinite(e))return r.toString();let s=Math.floor(e/1e3),n=Math.floor(s/3600)%24,a=Math.floor(s/60)%60,i=s%60,l=String(Math.abs(e)%1e3).padStart(3,"0"),o=e=>String(e).padStart(2,"0");return t>0?`${o(n)}:${o(a)}:${o(i)}.${l}`:`${o(n)}:${o(a)}:${o(i)}`}function eh(e,t){let r=e.logicalType;if("string"!=typeof r)return t;try{switch(r){case"date":return"number"==typeof t?new Date(864e5*t).toISOString().slice(0,10):t;case"time-millis":return"number"==typeof t?em(t,3,BigInt(t)):t;case"time-micros":return"bigint"==typeof t?em(Number(t/1000n),3,t):t;case"timestamp-millis":return"bigint"==typeof t?eu(t,!0):t;case"timestamp-micros":return"bigint"==typeof t?ec(t,!0):t;case"local-timestamp-millis":return"bigint"==typeof t?eu(t,!1):t;case"local-timestamp-micros":return"bigint"==typeof t?ec(t,!1):t;case"decimal":{if(!(t instanceof Uint8Array))return t;let r="number"==typeof e.scale?e.scale:0;return function(e,t){if(t<=0)return e.toString();let r=e<0n,s=(r?-e:e).toString().padStart(t+1,"0"),n=s.length-t;return`${r?"-":""}${s.slice(0,n)}.${s.slice(n)}`}(function(e){if(0===e.length)return 0n;let t=0n;for(let r of e)t=t<<8n|BigInt(r);return(128&e[0])!=0&&(t-=1n<<BigInt(8*e.length)),t}(t),r)}default:return t}}catch{return t}}function ef(e){return[...e].map(e=>e.toString(16).padStart(2,"0")).join("")}function ep(e){if(e.length>=4&&ei.every((t,r)=>e[r]===t))return"ocf";if(e.length>=5&&0===e[0])return"confluent";if(e.length>=10&&195===e[0]&&1===e[1])return"single-object";let t=e[0];return 123===t||91===t||32===t||10===t?"text":"unknown"}async function ey(e,t){let r,s=new Uint8Array(e);if("ocf"!==ep(s))throw new ea("This file does not start with the Avro marker, so it is not a .avro data file.");let n=new el(s);n.pos=4;let a=function(e){let t={};for(;;){let r=Number(e.varLong());if(0===r)break;if(r<0&&(r=-r,e.varLong()),r>1e4)throw new ea("The file header claims an absurd number of entries.");for(let s=0;s<r;s++)t[e.text()]=e.take(Number(e.varLong()))}return t}(n),i=new TextDecoder,l={};for(let[e,t]of Object.entries(a))l[e]="avro.schema"===e?"":i.decode(t);let o=a["avro.schema"];if(!o)throw new ea("The header has no avro.schema entry, so nothing describes the records.");let d=i.decode(o);try{r=JSON.parse(d)}
1catch{throw new ea("The schema stored in this file is not valid JSON, so the file is damaged.")}let u=a["avro.codec"],c=u?i.decode(u):"null",m=n.take(16).slice(),h={names:k(r)},f=[],p=[],y=0,g=0,x=0,v=!1,w=!0;for("null"!==c&&"deflate"!==c&&"snappy"!==c&&(w=!1,f.push(`The blocks are compressed with ${c}, which this reader does not unpack. The schema and the record count above are still exact.`));n.remaining>0&&!(n.remaining<2);){let e=Number(n.varLong()),a=Number(n.varLong());if(!Number.isFinite(e)||!Number.isFinite(a)||a<0){f.push("A block header is unreadable, so reading stopped there.");break}if(n.pos+a+16>s.length){f.push("The last block runs past the end of the file. It was written but never finished, which usually means the producer died mid-write."),v=!0;break}g++;let i=n.pos;if(w&&p.length<t.maxRecords&&x<t.maxBytes){let n=s.subarray(i,i+a);try{if("deflate"===c)n=await eo(n);else if("snappy"===c){if(n.length<4)throw new ea("A snappy block is too short to hold its checksum.");let e=n.subarray(0,n.length-4),t=n.subarray(n.length-4),r=((t[0]??0)<<24|(t[1]??0)<<16|(t[2]??0)<<8|(t[3]??0))>>>0;n=function(e){let t=0,r=0,s=0;for(;;){if(t>=e.length)throw new ea("A snappy block ended before its length did.");let n=e[t++];if(r|=(127&n)<<s,(128&n)==0)break;if((s+=7)>28)throw new ea("A snappy block declares an impossible length.")}let n=new Uint8Array(r),a=0;for(;t<e.length;){let r=e[t++];if((3&r)==0){let s=r>>2;if(s>=60){let r=s-59;s=0;for(let n=0;n<r;n++)s|=(e[t+n]??0)<<8*n;t+=r}if(a+(s+=1)>n.length)throw new ea("A snappy block writes past its own length.");n.set(e.subarray(t,t+s),a),t+=s,a+=s}else{let s,i;if((3&r)==1?(s=4+(r>>2&7),i=r>>5<<8|(e[t++]??0)):(3&r)==2?(s=(r>>2)+1,i=(e[t]??0)|(e[t+1]??0)<<8,t+=2):(s=(r>>2)+1,i=((e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24)>>>0,t+=4),0===i||i>a||a+s>n.length)throw new ea("A snappy block points outside itself, so it is damaged.");for(let e=0;e<s;e++)n[a]=n[a-i],a++}}return n}(e),function(e){if(!ed){ed=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t=1&t?0x82f63b78^t>>>1:t>>>1;ed[e]=t>>>0}}let t=0xffffffff;for(let r of e)t=t>>>8^(ed[(t^r)&255]??0);return(0xffffffff^t)>>>0}(n)===r||f.some(e=>e.startsWith("A checksum"))||f.push("A checksum on one of the blocks does not match its data. The records still decoded, but treat the file as suspect.")}x+=n.length;let s=new el(n);for(let n=0;n<e&&p.length<t.maxRecords;n++)p.push(function e(t,r,s,n,a){if(a>64)throw new ea("This schema nests deeper than 64 levels.");if(Array.isArray(r)){let i=t.varInt(),l=r[i];if(void 0===l)throw new ea(`A union in the data picked branch ${i}, and the schema only has ${r.length}. The file and its schema do not agree.`);return e(t,l,s,n,a+1)}let i=T(r,s,n.names),l=b(r)?r:null;switch(i){case"null":return null;case"boolean":return 0!==t.byte();case"int":{let e=t.varInt();return l?eh(l,e):e}case"long":{let e=t.varLong();return l?eh(l,e):e}case"float":return t.float();case"double":return t.double();case"bytes":{let e=t.take(Number(t.varLong()));if(l&&"string"==typeof l.logicalType){let t=eh(l,e);if(!(t instanceof Uint8Array))return t}return ef(e)}case"string":return t.text();case"fixed":{let e=S(r,s,n.names),a=e&&"number"==typeof e.node.size?e.node.size:0,i=t.take(a),o=e?e.node:l;if(o&&"string"==typeof o.logicalType){let e=eh(o,i);if(!(e instanceof Uint8Array))return e}return ef(i)}case"enum":{let e=S(r,s,n.names),a=e&&Array.isArray(e.node.symbols)?e.node.symbols:[],i=t.varInt();return void 0===a[i]?`<symbol ${i}>`:String(a[i])}case"array":{let i=S(r,s,n.names),o=i?i.node:l,d=o?o.items:"null",u=[];for(;;){let r=Number(t.varLong());if(0===r)break;r<0&&(r=-r,t.varLong());for(let i=0;i<r;i++)u.push(e(t,d,s,n,a+1))}return u}case"map":{let i=S(r,s,n.names),o=i?i.node:l,d=o?o.values:"null",u={};for(;;){let r=Number(t.varLong());if(0===r)break;r<0&&(r=-r,t.varLong());for(let i=0;i<r;i++)u[t.text()]=e(t,d,s,n,a+1)}return u}case"record":{let i=S(r,s,n.names);if(!i)throw new ea("The schema refers to a record it never defines.");let l=Array.isArray(i.node.fields)?i.node.fields:[],o={};for(let r of l)b(r)&&"string"==typeof r.name&&(o[r.name]=e(t,r.type,i.ns,n,a+1));return o}default:throw new ea("The schema in this file uses a type name it never defines, so the records cannot be decoded.")}}(s,r,"",h,0));p.length>=t.maxRecords&&(v=!0)}catch(e){if(e instanceof ea)f.push(e.message),w=!1;else throw e}}else w&&(v=!0);if(n.pos=i+a,!function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}(n.take(16),m)){f.push("A block does not end with the marker the header set. Everything up to this point is good, the rest of the file is not trustworthy."),v=!0;break}y+=e}return{schema:r,schemaText:d,codec:c,metadata:l,records:p,recordCount:y,blocks:g,truncated:v,notes:f}}function eg(e){if("bigint"==typeof e)return e.toString();if(Array.isArray(e))return e.map(eg);if(e instanceof Uint8Array)return ef(e);if(b(e)){let t={};for(let[r,s]of Object.entries(e))t[r]=eg(s);return t}return e}function ex(e){if(null==e)return"";if("bigint"==typeof e)return e.toString();if("object"==typeof e)try{return JSON.stringify(eg(e))}catch{}return String(e)}var eb=r(35339),ev=r(15662);let ew="toolbreezy.avro-formatter.recent",e$="toolbreezy.avro-formatter.prefs",eN=[{id:"schema",label:"Format & validate"},{id:"compat",label:"Compatibility check"},{id:"data",label:"Read a .avro file"},{id:"infer",label:"JSON to schema"}],ej=`{ 2 "type": "record", 3 "name": "OrderPlaced", 4 "namespace": "com.acme.orders", 5 "doc": "Emitted once checkout completes.", 6 "fields": [ 7 { "name": "order_id", "type": "string" }, 8 { "name": "customer_id", "type": "string" }, 9 { "name": "placed_at", "type": { "type": "long", "logicalType": "timestamp-millis" } }, 10 { "name": "total", "type": { "type": "bytes", "logicalType": "decimal", "precision": 12, "scale": 2 } }, 11 { "name": "currency", "type": { "type": "enum", "name": "Currency", "symbols": ["USD", "EUR", "GBP"], "default": "USD" } }, 12 { "name": "items", "type": { "type": "array", "items": { "type": "record", "name": "LineItem", "fields": [ 13 { "name": "sku", "type": "string" }, 14 { "name": "quantity", "type": "int" }, 15 { "name": "unit_price", "type": "double" } 16 ] } } }, 17 { "name": "coupon", "type": ["null", "string"], "default": null } 18 ] 19}`,eA=`{ 20 "type": "record", 21 "name": "OrderPlaced", 22 "namespace": "com.acme.orders", 23 "fields": [ 24 { "name": "order_id", "type": "string" }, 25 { "name": "2fa_verified", "type": "boolean" }, 26 { "name": "coupon", "type": ["string", "null"], "default": null }, 27 { "name": "currency", "type": { "type": "enum", "name": "Currency", "symbols": ["USD", "EUR"], "default": "CAD" } },
28 { "name": "total", "type": { "type": "bytes", "logicalType": "decimal" } }, 29 { "name": "shipped_at", "type": { "type": "int", "logicalType": "timestamp-millis" } }, 30 { "name": "address", "type": "com.acme.orders.Address" }, 31 { "name": "tags", "type": ["string", "string"] } 32 ] 33}`,ek=`{type: 'record', name: 'PageView', namespace: 'com.acme.web', 34 fields: [ 35 {name: 'url', type: 'string'}, // where they landed 36 {name: 'viewed_at', type: 'long'}, 37 ], 38}`,eS=`{ 39 "type": "record", 40 "name": "User", 41 "namespace": "com.acme", 42 "fields": [ 43 { "name": "id", "type": "long" }, 44 { "name": "name", "type": "string" }, 45 { "name": "plan", "type": { "type": "enum", "name": "Plan", "symbols": ["free", "pro"] } } 46 ] 47}`,eT=`{ 48 "type": "record", 49 "name": "User", 50 "namespace": "com.acme", 51 "fields": [ 52 { "name": "id", "type": "long" }, 53 { "name": "name", "type": "string" }, 54 { "name": "email", "type": "string" }, 55 { "name": "plan", "type": { "type": "enum", "name": "Plan", "symbols": ["free", "pro", "team"] } } 56 ] 57}`,eO=`{ 58 "id": 90210, 59 "email": "[email protected]", 60 "signed_up": "2021-04-08T09:15:00Z", 61 "verified": true, 62 "score": 4.75, 63 "referrer": null, 64 "address": { "line1": "12 Mill Road", "city": "Bristol", "postcode": "BS1 4TR" }, 65 "tags": ["beta", "invoiced"] 66}`;function eC(e,t,r){(0,eb.WN)(new Blob([e],{type:r}),t)}function ez(e,t){let r=t instanceof Error?t.message:String(t),s=/position (\d+)/.exec(r),n=s&&s[1]?Number(s[1]):-1;if(n<0){let e=/line (\d+) column (\d+)/i.exec(r);return e&&e[1]&&e[2]?{line:Number(e[1]),col:Number(e[2]),message:r}:{line:1,col:1,message:r}}n=Math.min(n,e.length);let a=1,i=0;for(let t=0;t<n;t++)"\n"===e[t]&&(a++,i=t+1);return{line:a,col:n-i+1,message:r}}function eJ(e,t){if(!e.trim())return{kind:"empty"};try{return{kind:"ok",value:JSON.parse(e)}}catch(r){if(t)try{let r=t(e);return{kind:"repaired",value:JSON.parse(r),repairedText:r,repairs:function(e,t){let r=[],s=r=>r.test(e)&&!r.test(t),n=(e,t)=>e.split(t).length-1;return s(/,\s*[}\]]/)&&r.push("a trailing comma"),s(/'/)&&r.push("single quotes around strings"),s(/\/\/|\/\*/)&&r.push("comments"),s(/[{,]\s*[A-Za-z_$][\w$]*\s*:/)&&r.push("unquoted keys"),(n(t,"}")>n(e,"}")||n(t,"]")>n(e,"]"))&&r.push("a missing closing bracket"),r}(e,r)}}catch{}return{kind:"bad",...ez(e,r)}}}function eL({id:e,label:t,value:r,onChange:a,placeholder:l,rows:u="min-h-[240px]",extra:m,below:h}){let[f,p]=(0,n.useState)(!1),y=(0,n.useRef)(null);function g(e){let t=new FileReader;t.onload=()=>a("string"==typeof t.result?t.result:""),t.readAsText(e)}return(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,s.jsx)(o.J,{htmlFor:e,children:t}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-1",children:[m,(0,s.jsx)(i.$,{type:"button",variant:"outline",size:"sm",onClick:()=>y.current?.click(),children:"Open file"}),(0,s.jsx)(i.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>a(""),disabled:0===r.length,children:"Clear"})]})]}),(0,s.jsx)("input",{ref:y,type:"file",accept:".avsc,.json,.txt,application/json",className:"hidden",onChange:e=>{let t=e.target.files?.[0];t&&g(t),e.target.value=""}}),(0,s.jsx)("div",{onDragOver:e=>{e.dataTransfer.types.includes("Files")&&(e.preventDefault(),p(!0))},onDragLeave:()=>p(!1),onDrop:e=>{let t=e.dataTransfer.files?.[0];t&&(e.preventDefault(),p(!1),g(t))},className:(0,c.cn)("rounded-md",f&&"ring-2 ring-primary ring-offset-2 ring-offset-background"),children:(0,s.jsx)(d.T,{id:e,"aria-label":t,value:r,onChange:e=>a(e.target.value),onPaste:e=>{let t=e.clipboardData?.files?.[0];t&&(e.preventDefault(),g(t))},className:(0,c.cn)("font-mono text-xs",u),spellCheck:!1,placeholder:l})}),h]})}function eR({issue:e}){let t="error"===e.sev;return(0,s.jsxs)("li",{className:(0,c.cn)("rounded-md border p-3",t?"border-destructive/30 bg-destructive/5":"border-amber-500/30 bg-amber-500/5"),children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("span",{className:(0,c.cn)("inline-flex items-center rounded px-1.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide",t?"bg-destructive/15 text-destructive":"bg-amber-500/20 text-amber-800 dark:text-amber-300"),children:t?"Error":"Warning"}),(0,s.jsx)("span",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-xs",children:j(e.path)})]}
66),(0,s.jsx)("p",{className:"mt-1.5 text-sm text-foreground/90",children:e.message}),e.fix&&(0,s.jsxs)("p",{className:"mt-1 text-sm text-foreground/90",children:[(0,s.jsx)("span",{className:"font-medium",children:"Fix. "}),e.fix]})]})}function eF({nodes:e,collapsed:t,toggle:r,searching:n}){return(0,s.jsx)(s.Fragment,{children:e.map(e=>{let a=!n&&t.has(e.id);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-baseline gap-2 border-b border-border/40 py-1",style:{paddingLeft:`${14*e.depth}px`},children:[e.children.length>0?(0,s.jsx)("button",{type:"button",onClick:()=>r(e.id),className:"w-4 shrink-0 text-xs text-muted-foreground hover:text-foreground","aria-label":a?`Expand ${e.label}`:`Collapse ${e.label}`,children:a?"+":"-"}):(0,s.jsx)("span",{className:"w-4 shrink-0"}),(0,s.jsx)("span",{className:"font-mono text-xs font-semibold",children:e.label}),(0,s.jsx)("span",{className:"font-mono text-xs text-muted-foreground",children:e.type}),e.hasDefault&&(0,s.jsx)("span",{className:"rounded bg-emerald-500/15 px-1 text-[10px] uppercase text-emerald-700 dark:text-emerald-400",children:"default"}),e.detail&&(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:e.detail})]}),!a&&e.children.length>0&&(0,s.jsx)(eF,{nodes:e.children,collapsed:t,toggle:r,searching:n})]},e.id)})})}function eE({schema:e}){let[t,r]=(0,n.useState)(""),[a,i]=(0,n.useState)(new Set),o=(0,n.useMemo)(()=>(function(e){let t=k(e),r=b(e)&&"string"==typeof e.name?e.name:"schema";return[function e(r,s,n,a,i,l,o){let d={id:i,depth:n,label:s,type:function e(t){if("string"==typeof t)return t;if(Array.isArray(t))return t.map(e).join(" | ");if(b(t)){let r="string"==typeof t.type?t.type:e(t.type);return"string"==typeof t.logicalType?`${r} (${t.logicalType})`:"array"===r?`array<${e(t.items)}>`:"map"===r?`map<${e(t.values)}>`:"string"==typeof t.name?`${r} ${t.name}`:r}return"unknown"}(r),detail:"",hasDefault:o,children:[]};if(n>12)return d;let u=r;Array.isArray(r)&&(u=r.find(e=>"null"!==T(e,a,t))??r[0]);let c=T(u,a,t);if("array"===c&&b(u))return d.children.push(e(u.items,"[item]",n+1,a,`${i}.[]`,l,!1)),d;if("map"===c&&b(u))return d.children.push(e(u.values,"[value]",n+1,a,`${i}.{}`,l,!1)),d;if("record"===c){let r=S(u,a,t);if(!r)return d;let s="string"==typeof r.node.name?w(r.node.name,r.ns):i;if(l.has(s))return d.detail=`recursive, points back at ${s}`,d;let o=new Set(l);o.add(s);let c=Array.isArray(r.node.fields)?r.node.fields:[];d.detail=`${c.length} field${1===c.length?"":"s"}`,c.forEach((t,s)=>{if(!b(t))return;let a="string"==typeof t.name?t.name:`field ${s}`;d.children.push(e(t.type,a,n+1,r.ns,`${i}.${a}`,o,"default"in t))})}if("enum"===c){let e=S(u,a,t);e&&Array.isArray(e.node.symbols)&&(d.detail=e.node.symbols.join(", "))}return d}(e,r,0,"","root",new Set,!1)]})(e),[e]),d=t.trim().toLowerCase(),u=(0,n.useMemo)(()=>d?o.map(e=>(function e(t,r){if(t.label.toLowerCase().includes(r)||t.type.toLowerCase().includes(r))return t;let s=t.children.map(t=>e(t,r)).filter(e=>null!==e);return s.length?{...t,children:s}:null})(e,d)).filter(e=>null!==e):o,[o,d]),c=(0,n.useCallback)(e=>{i(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]);return(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(l.p,{value:t,onChange:e=>r(e.target.value),placeholder:"Filter fields by name or type","aria-label":"Filter fields",className:"max-w-xs"}),(0,s.jsx)("div",{className:"max-h-80 overflow-auto rounded-md border p-2",children:u.length?(0,s.jsx)(eF,{nodes:u,collapsed:a,toggle:c,searching:d.length>0}):(0,s.jsx)("p",{className:"p-2 text-sm text-muted-foreground",children:"Nothing matches that."})})]})}function eD({text:e,setText:t,repair:r,indent:a,setIndent:l,avroOrder:u,setAvroOrder:c,recents:m,onSaveRecent:h}){let[f,p]=(0,n.useState)(""),y=(0,n.useRef)(0),v=(0,n.useMemo)(()=>eJ(e,r),[e,r]),A="ok"===v.kind||"repaired"===v.kind?v.value:void 0,O="ok"===v.kind||"repaired"===v.kind,C=(0,n.useMemo)(()=>O?function(e){let t={issues:[],names:k(e),defined:new Map,refs:[],order:0,seen:new Set};if(Array.isArray(e))L(e,"","",t);else{if(!("string"==typeof e||b(e)))return t.issues.push({path:"",sev:"error",message:`An Avro schema is a type name, a type object, or a union array. This is ${null===e?"null":typeof e}.`}),t.issues;L(e,"","",t)}for(let e of t.refs){let r=t.defined.get(e.name),s=e.typed===e.name?"":` A bare name is read against the namespace it sits in, so this is a reference to "${e.name}".`;if(r)r.order>e.order&&t.issues.push({path:e.path,sev:"warning",message:`"${e.typed}" is used here but defined further down, at ${j(r.path)}. The reference Java parser reads a schema top to bottom and rejects a name it has not seen yet.`,fix:"Move the full definition to its first use and refer to it by name afterwards."});else{let r=e.typed.toLowerCase(),n=[...t.defined.keys()].find(t=>t.toLowerCase()===e.name.toLowerCase()||t.toLowerCase()===r||t.toLowerCase().endsWith(`.${r}`));t.issues.push({path:e.path,sev:"error",message:`"${e.typed}" is used as a type but nothing in this schema defines it.${s} Any type name that is not one of the eight primitives has to be a record, enum or fixed defined somewhere in the same document.`,fix:n?`Did you mean "${n}"? Names are matched in full, so a namespace on the definition has to appear in the reference too.`:g[e.typed]??"Define it inline the first time you use it, then refer to it by name after that."})}}return t.issues.sort((e,t)=>
66e.sev===t.sev?0:"error"===e.sev?-1:1)}(A):[],[O,A]),z=C.filter(e=>"error"===e.sev),J=C.filter(e=>"warning"===e.sev),R=(0,n.useMemo)(()=>O?function(e){let t={fields:0,depth:0,records:0,enums:0,fixed:0,unions:0,nullable:0,withDefault:0},r=new Set;return!function e(s,n){if(t.depth=Math.max(t.depth,n),n>40)return;if(Array.isArray(s)){for(let r of(t.unions++,s))e(r,n+1);return}if(!b(s)||r.has(s))return;r.add(s);let a=s.type;if("string"!=typeof a)return void e(a,n);if("record"===a||"error"===a){for(let r of(t.records++,Array.isArray(s.fields)?s.fields:[]))b(r)&&(t.fields++,"default"in r&&t.withDefault++,Array.isArray(r.type)&&r.type.some(e=>"null"===e)&&t.nullable++,e(r.type,n+1));return}"enum"===a?t.enums++:"fixed"===a?t.fixed++:"array"===a?e(s.items,n+1):"map"===a&&e(s.values,n+1)}(e,0),t}(A):null,[O,A]),F=(0,n.useMemo)(()=>O?_(A,a,u):"",[O,A,a,u]),E=(0,n.useMemo)(()=>O?function(e){let t=k(e);return function e(t,r,s,n){if("string"==typeof t)return x(t)?JSON.stringify(t):JSON.stringify(w(t,r));if(Array.isArray(t))return`[${t.map(t=>e(t,r,s,n)).join(",")}]`;if(!b(t))return"null";let a=t.type;if(Array.isArray(a)||b(a))return e(a,r,s,n);if("string"!=typeof a)return"null";if(x(a))return JSON.stringify(a);if("array"===a)return`{"type":"array","items":${e(t.items,r,s,n)}}`;if("map"===a)return`{"type":"map","values":${e(t.values,r,s,n)}}`;if("record"===a||"error"===a||"enum"===a||"fixed"===a){let i=N(t,r),l=w("string"==typeof t.name?t.name:"",i);if(n.has(l))return JSON.stringify(l);let o=new Set(n);o.add(l);let d=$(l);if("enum"===a){let e=Array.isArray(t.symbols)?t.symbols:[];return`{"name":${JSON.stringify(l)},"type":"enum","symbols":[${e.map(e=>JSON.stringify(String(e))).join(",")}]}`}if("fixed"===a){let e="number"==typeof t.size?t.size:0;return`{"name":${JSON.stringify(l)},"type":"fixed","size":${e}}`}let u=(Array.isArray(t.fields)?t.fields:[]).map(t=>{if(!b(t))return"";let r="string"==typeof t.name?t.name:"";return`{"name":${JSON.stringify(r)},"type":${e(t.type,d,s,o)}}`}).filter(Boolean).join(",");return`{"name":${JSON.stringify(l)},"type":"record","fields":[${u}]}`}return JSON.stringify(w(a,r))}(e,"",t,new Set)}(A):"",[O,A]),D=(0,n.useMemo)(()=>E?function(e){P||(P=function(){let e=[];for(let t=0;t<256;t++){let r=BigInt(t);for(let e=0;e<8;e++)r=(r>>1n^0xc15d213aa4d7a795n&-(1n&r))&0xffffffffffffffffn;e.push(r)}return e}());let t=new TextEncoder().encode(e),r=0xc15d213aa4d7a795n;for(let e of t){let t=Number((r^BigInt(e))&255n);r=(r>>8n^(P[t]??0n))&0xffffffffffffffffn}return r}(E):null,[E]),I=(0,n.useMemo)(()=>{if(!O)return"";try{return JSON.stringify(function(e){let t=k(e);function r(e,t,r){if(b(e))return e;if("string"==typeof e){let s=r.get(w(e,t));return s?s.node:null}return null}return function e(s,n,a,i){if(a>12)return null;if(Array.isArray(s)){var l,o;let t=s[0];if("null"===t)return null;let r=(l=t,o=n,"null"===l?null:"string"==typeof l?x(l)?l:w(l,o):b(l)&&"string"==typeof l.type?"string"==typeof l.name?w(l.name,N(l,o)):l.type:null),d=e(t,n,a+1,i);return null===r?d:{[r]:d}}switch(T(s,n,t)){case"null":default:return null;case"boolean":return!0;case"int":return 42;case"long":return 0x11f71fb04cb;case"float":case"double":return 3.14;case"bytes":return"\\u00ff";case"string":if(b(s)&&"uuid"===s.logicalType)return"3f2504e0-4f89-11d3-9a0c-0305e82c3301";return"example";case"fixed":return"\\u0000\\u0001";case"enum":{let e=S(s,n,t),r=e&&Array.isArray(e.node.symbols)?e.node.symbols:[];return r.length?String(r[0]):"SYMBOL"}case"array":{let l=r(s,n,t);return l?[e(l.items,n,a+1,i)]:[]}case"map":{let l=r(s,n,t);return l?{key:e(l.values,n,a+1,i)}:{}}case"record":{let r=S(s,n,t);if(!r)return{};let l="string"==typeof r.node.name?w(r.node.name,r.ns):"record";if(i.has(l))return null;let o=new Set(i);o.add(l);let d={};for(let t of Array.isArray(r.node.fields)?r.node.fields:[])b(t)&&"string"==typeof t.name&&(d[t.name]="default"in t?t.default:e(t.type,r.ns,a+1,o));return d}}}(e,"",0,new Set)}(A),null,2)}catch{return""}},[O,A]);return(0,n.useEffect)(()=>{if(!E)return void p("");let e=++y.current;B(E).then(t=>{e===y.current&&p(t)}).catch(()=>{e===y.current&&p("")})},[E]),(0,n.useEffect)(()=>
66{if(!O||e.trim().length<40)return;let t=setTimeout(()=>h(e),2500);return()=>clearTimeout(t)},[O,e,h]),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,s.jsx)(eL,{id:"avro-schema-input",label:"Avro schema (.avsc)",value:e,onChange:t,rows:"min-h-[340px]",placeholder:'Paste your .avsc here, or drop the file in.\n\n{\n "type": "record",\n "name": "User",\n "fields": []\n}'}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,s.jsx)(o.J,{htmlFor:"avro-schema-output",children:"Formatted"}),(0,s.jsxs)("div",{className:"flex gap-1",children:[(0,s.jsx)(ev.i,{value:F,label:"Copy",variant:"outline",size:"sm",disabled:!F}),(0,s.jsx)(i.$,{type:"button",variant:"outline",size:"sm",disabled:!F,onClick:()=>eC(F,"schema.avsc","application/json"),children:"Download .avsc"})]})]}),(0,s.jsx)(d.T,{id:"avro-schema-output",readOnly:!0,value:F,className:"min-h-[340px] font-mono text-xs",spellCheck:!1,placeholder:"The tidied schema lands here as you type."})]})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-3 rounded-md border bg-muted/40 px-3 py-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium",children:"Indent"}),(0,s.jsx)("div",{className:"flex gap-1",children:[["2","2 spaces"],["4","4 spaces"],["tab","Tab"],["min","One line"]].map(([e,t])=>(0,s.jsx)(i.$,{type:"button",size:"sm",variant:a===e?"default":"outline",onClick:()=>l(e),children:t},e))}),(0,s.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 text-sm",children:[(0,s.jsx)("input",{type:"checkbox",checked:u,onChange:e=>c(e.target.checked),className:"h-4 w-4"}),"Avro key order (type, name, namespace, doc, then fields)"]}),(0,s.jsxs)("div",{className:"ml-auto flex flex-wrap items-center gap-1",children:[(0,s.jsx)("span",{className:"text-sm text-muted-foreground",children:"Examples:"}),(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",onClick:()=>t(ej),children:"Clean"}),(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",onClick:()=>t(eA),children:"Seven real errors"}),(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",onClick:()=>t(ek),children:"Messy paste"})]})]}),m.length>0&&(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-1",children:[(0,s.jsx)("span",{className:"text-sm text-muted-foreground",children:"Recent, kept in this browser only:"}),m.map((e,r)=>{let n=`Schema ${r+1}`;try{let t=JSON.parse(e);"string"==typeof t.name&&(n=t.name)}catch{}return(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"ghost",onClick:()=>t(e),children:n},`${n}-${r}`)})]}),"bad"===v.kind&&(0,s.jsxs)("div",{role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm",children:[(0,s.jsx)("span",{className:"font-semibold text-destructive",children:"This is not valid JSON yet."})," The parser gave up on line ",v.line,", column ",v.col,". An Avro schema is written in JSON, so it has to parse before any Avro rule can be checked."]}),"repaired"===v.kind&&(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-sm text-amber-900 dark:text-amber-200",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("span",{className:"font-semibold",children:"Recovered."})," The paste was not strict JSON, so it was repaired to read it",v.repairs&&v.repairs.length>0?`: ${v.repairs.join(", ")}.`:"."," Everything below describes the repaired version."]}),(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>v.repairedText&&t(v.repairedText),children:"Keep the repair"})]}),O&&0===z.length&&(0,s.jsxs)("div",{role:"status",className:"rounded-md border border-emerald-500/40 bg-emerald-500/10 px-3 py-2 text-sm font-medium text-emerald-800 dark:text-emerald-300",children:["Valid Avro schema."," ",J.length>0?`A real parser will accept it, with ${J.length} thing${1===J.length?"":"s"} worth a look below.`:"Names, unions, defaults, enums and logical types all check out."]}),O&&z.length>0&&(0,s.jsxs)("div",{role:"status",className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm font-semibold text-destructive",children:[z.length," error",1===z.length?"":"s"," an Avro parser will reject",J.length>0?`, plus ${J.length} warning${1===J.length?"":"s"}`:"","."]}),C.length>0&&(0,s.jsx)("ul",{className:"space-y-2",children:C.map((e,t)=>(0,s.jsx)(eR,{issue:e},`${e.path}-${t}`))}),R&&(0,s.jsx)("div",{className:"grid gap-2 sm:grid-cols-3 lg:grid-cols-6",children:[["Fields",R.fields],["Depth",R.depth],["Records",R.records],["Enums",R.enums],["Nullable",R.nullable],["With defaults",R.withDefault]].map(([e,t])=>(0,s.jsxs)("div",{className:"rounded-md border bg-muted/30 px-3 py-2",children:[(0,s.jsx)("div",{className:"text-lg font-semibold",children:String(t)}),(0,s.jsx)("div",{className:"text-xs text-muted-foreground",children:String(e)})]},String(e)))}),O&&(0,s.jsxs)("details",{className:"rounded-md border p-3",children:[(0,s.jsx)("summary",{className:"cursor-pointer text-sm font-medium",children:"Field outline"}),(0,s.jsx)("div",{className:"mt-3",children:(0,s.jsx)(eE,{schema:A})})]}),O&&E&&(0,s.jsxs)("details",{className:"rounded-md border p-3",children:[(0,s.jsx)("summary",{className:"cursor-pointer text-sm font-medium",children:"Canonical form and fingerprint"}),(0,s.jsxs)("div",{className:"mt-3 space-y-3",children:[(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Parsing Canonical Form is the schema with everything that does not change how data is read stripped out, names resolved
66in full, whitespace gone. Two schemas with the same canonical form are the same schema to a reader, which is what makes the fingerprint below a reliable identity check."}),(0,s.jsx)(d.T,{readOnly:!0,value:E,"aria-label":"Parsing canonical form",className:"min-h-[100px] font-mono text-xs"}),(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:(0,s.jsx)(ev.i,{value:E,label:"Copy canonical form",size:"sm",variant:"outline"})}),(0,s.jsxs)("dl",{className:"space-y-1 text-sm",children:[null!==D&&(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsx)("dt",{className:"font-medium",children:"CRC-64-AVRO"}),(0,s.jsxs)("dd",{className:"font-mono text-xs",children:["0x",D.toString(16).padStart(16,"0")," (",(D>=1n<<63n?D-(1n<<64n):D).toString(),")"]})]}),f&&(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsx)("dt",{className:"font-medium",children:"SHA-256"}),(0,s.jsx)("dd",{className:"break-all font-mono text-xs",children:f})]})]})]})]}),O&&I&&(0,s.jsxs)("details",{className:"rounded-md border p-3",children:[(0,s.jsx)("summary",{className:"cursor-pointer text-sm font-medium",children:"A record that fits this schema"}),(0,s.jsxs)("div",{className:"mt-3 space-y-2",children:[(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Built from the schema itself, with union branches labeled the way the Avro JSON encoding writes them. Handy for a test fixture, or for checking that a field really is optional."}),(0,s.jsx)(d.T,{readOnly:!0,value:I,"aria-label":"Sample record",className:"min-h-[140px] font-mono text-xs"}),(0,s.jsx)(ev.i,{value:I,label:"Copy sample record",size:"sm",variant:"outline"})]})]})]})}function eI({next:e,setNext:t,previous:r,setPrevious:a,level:l,setLevel:o,repair:d}){let u=(0,n.useMemo)(()=>eJ(e,d),[e,d]),m=(0,n.useMemo)(()=>r.map(e=>eJ(e,d)),[r,d]),h=(0,n.useMemo)(()=>{let e=[];return m.forEach((t,r)=>{("ok"===t.kind||"repaired"===t.kind)&&e.push({label:m.length>1?`version ${r+1}`:"the registered version",schema:t.value})}),e},[m]),f=m.some(e=>"bad"===e.kind)||"bad"===u.kind,p=("ok"===u.kind||"repaired"===u.kind)&&h.length>0&&!f,y=(0,n.useMemo)(()=>p?function(e,t,r){let s=t.length>1,n=s?t:t.slice(-1),a=[];for(let t of n){let s=n.length>1?`${es} (${t.label})`:es;("BACKWARD"===r||"FULL"===r)&&a.push({direction:"backward",label:t.label,issues:et(e,t.schema,{reader:er,writer:s})}),("FORWARD"===r||"FULL"===r)&&a.push({direction:"forward",label:t.label,issues:et(t.schema,e,{reader:s,writer:er})})}return{level:r,transitive:s,checks:a,ok:a.every(e=>0===e.issues.length)}}(u.value,h,l):null,[p,u,h,l]),g=y?.checks.filter(e=>"backward"===e.direction)??[],x=y?.checks.filter(e=>"forward"===e.direction)??[];return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-3 rounded-md border bg-muted/40 px-3 py-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium",children:"Level"}),(0,s.jsx)("div",{className:"flex gap-1",children:["BACKWARD","FORWARD","FULL"].map(e=>(0,s.jsx)(i.$,{type:"button",size:"sm",variant:l===e?"default":"outline",onClick:()=>o(e),children:e},e))}),h.length>1&&(0,s.jsxs)("span",{className:"rounded bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary",children:["transitive, checking all ",h.length," versions"]}),(0,s.jsx)("div",{className:"ml-auto flex gap-1",children:(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",onClick:()=>{t(eT),a([eS])},children:"Load an example pair"})})]}),(0,s.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,s.jsxs)("div",{className:"space-y-3",children:[r.map((e,t)=>(0,s.jsx)(eL,{id:`avro-prev-${t}`,label:r.length>1?`Previous version ${t+1}${t===r.length-1?" (the one in the registry)":""}`:"The schema already in the registry",value:e,onChange:e=>a(r.map((r,s)=>s===t?e:r)),rows:"min-h-[220px]",placeholder:"Paste the schema your consumers are running today.",below:m[t]?.kind==="bad"?(0,s.jsxs)("p",{role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:["This is not valid JSON yet. The parser gave up on line ",m[t].line,",
66column ",m[t].col,". This version is left out of the check until it parses."]}):null,extra:r.length>1?(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"ghost",onClick:()=>a(r.filter((e,r)=>r!==t)),children:"Remove"}):null},`prev-${t}`)),(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",onClick:()=>a([...r,""]),disabled:r.length>=6,children:"Add an older version"})]}),(0,s.jsx)(eL,{id:"avro-next",label:"The schema you are about to push",value:e,onChange:t,rows:"min-h-[220px]",placeholder:"Paste the new version here.",below:"bad"===u.kind?(0,s.jsxs)("p",{role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:["This is not valid JSON yet. The parser gave up on line ",u.line,", column"," ",u.col,". Nothing can be checked against it until it parses."]}):null})]}),!p&&(0,s.jsx)("p",{className:"rounded-md border bg-muted px-4 py-3 text-sm text-muted-foreground",children:"Put the registered schema on the left and the one you are about to push on the right. You get the same verdict a Schema Registry gives you, before it gives you one, with the field that causes each failure named and a fix written out. Nothing is uploaded, which matters when the schema carries your internal event names."}),y&&(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{role:"status",className:(0,c.cn)("flex flex-wrap items-center gap-3 rounded-md border px-3 py-2 text-sm font-semibold",y.ok?"border-emerald-500/40 bg-emerald-500/10 text-emerald-800 dark:text-emerald-300":"border-destructive/40 bg-destructive/10 text-destructive"),children:[(0,s.jsxs)("span",{children:[y.level,y.transitive?"_TRANSITIVE":"",": ",y.ok?"compatible":"not compatible"]}),(0,s.jsx)(ev.i,{value:function(){if(!y)return"";let e=[`${y.level}${y.transitive?"_TRANSITIVE":""}: ${y.ok?"PASS":"FAIL"}`];for(let t of y.checks)for(let r of(e.push("",`${t.direction.toUpperCase()} against ${t.label}: ${0===t.issues.length?"pass":"fail"}`),t.issues))e.push(` ${j(r.path)}`,` ${r.message}`),r.fix&&e.push(` Fix: ${r.fix}`);return e.join("\n")}(),label:"Copy report",copiedLabel:"Report copied",size:"sm",variant:"ghost",className:"ml-auto"})]}),[...g,...x].map((e,t)=>{var r,n;return(0,s.jsxs)("div",{className:"rounded-md border p-3",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsxs)("span",{className:(0,c.cn)("rounded px-1.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide",0===e.issues.length?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-400":"bg-destructive/15 text-destructive"),children:[e.direction," ",0===e.issues.length?"pass":"fail"]}),(0,s.jsxs)("span",{className:"text-xs text-muted-foreground",children:["against ",e.label]})]}),(0,s.jsx)("p",{className:"mt-1.5 text-sm text-foreground/90",children:(r=e.direction,n=0===e.issues.length,"backward"===r?n?"A consumer upgraded to the new schema can still read every record written with the old one.":"A consumer upgraded to the new schema cannot read records written with the old one.":n?"A consumer still running the old schema can read records written with the new one.":"A consumer still running the old schema cannot read records written with the new one.")}),e.issues.length>0&&(0,s.jsx)("ul",{className:"mt-2 space-y-2",children:e.issues.map((e,t)=>(0,s.jsxs)("li",{className:"rounded-md border border-destructive/30 bg-destructive/5 p-3",children:[(0,s.jsx)("span",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-xs",children:j(e.path)}),(0,s.jsx)("p",{className:"mt-1.5 text-sm",children:e.message}),e.fix&&(0,s.jsxs)("p",{className:"mt-1 text-sm",children:[(0,s.jsx)("span",{className:"font-medium",children:"Fix. "}),e.fix]})]},`${e.path}-${t}`))})]},`${e.direction}-${e.label}-${t}`)}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"This applies the Avro schema-resolution rules, which is the same logic a registry runs. Your registry still has the last word, since its configured level and any per-subject override live there and not here."})]})]})}function eM({onUseSchema:e}
66){let[t,r]=(0,n.useState)(!1),[a,l]=(0,n.useState)(!1),[o,u]=(0,n.useState)(""),[m,h]=(0,n.useState)(""),[f,p]=(0,n.useState)(null),y=(0,n.useRef)(null),g=(0,n.useRef)(0),x=(0,n.useCallback)(async e=>{let t=++g.current;l(!0),u(""),p(null),h(e.name);try{let s=await e.arrayBuffer(),n=ep(new Uint8Array(s));if("confluent"===n){var r;let e=(r=new Uint8Array(s)).length<5||0!==r[0]?null:((r[1]??0)<<24|(r[2]??0)<<16|(r[3]??0)<<8|(r[4]??0))>>>0;throw new ea(`This looks like a single Kafka message in Confluent wire format, not a data file. It starts with a zero byte and then schema id ${e??"?"}, and that id only means something inside your own registry, so the schema is not in the bytes to read.`)}if("single-object"===n)throw new ea("This is Avro single-object encoding. It carries a schema fingerprint rather than the schema itself, so the bytes cannot be decoded without the matching schema on hand.");if("text"===n)throw new ea("This file is text, not a binary Avro data file. If it is a .avsc schema, the Format and validate tab is the one you want.");let a=await ey(s,{maxRecords:500,maxBytes:5242880});t===g.current&&p(a)}catch(e){t===g.current&&u(e instanceof ea?e.message:"That file could not be read as an Avro data file. It may be damaged, or it may be another format entirely.")}finally{t===g.current&&l(!1)}},[]);(0,n.useEffect)(()=>{let e=e=>{let t=e.clipboardData?.files?.[0];t&&x(t)};return document.addEventListener("paste",e),()=>document.removeEventListener("paste",e)},[x]);let v=(0,n.useMemo)(()=>f?function(e){let t=k(e),r=S(e,"",t);if(!r||!Array.isArray(r.node.fields))return null;let s=[];for(let e of r.node.fields)b(e)&&"string"==typeof e.name&&s.push(e.name);return s.length?s:null}(f.schema):null,[f]),w=(0,n.useMemo)(()=>f?_(f.schema,"2",!0):"",[f]);return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("input",{ref:y,type:"file",accept:".avro,application/octet-stream",className:"hidden",onChange:e=>{let t=e.target.files?.[0];t&&x(t),e.target.value=""}}),(0,s.jsxs)("div",{onDragOver:e=>{e.dataTransfer.types.includes("Files")&&(e.preventDefault(),r(!0))},onDragLeave:()=>r(!1),onDrop:e=>{let t=e.dataTransfer.files?.[0];t&&(e.preventDefault(),r(!1),x(t))},className:(0,c.cn)("flex flex-col items-center justify-center gap-2 rounded-md border-2 border-dashed p-8 text-center",t?"border-primary bg-primary/5":"border-muted-foreground/30"),children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:"Click to choose a .avro file, drag one into this box, or paste it"}),(0,s.jsx)("p",{className:"max-w-lg text-sm text-muted-foreground",children:"The header schema, the codec, the block count and the records themselves, read here on your own machine. Nothing is uploaded, so a production extract off S3 is fine to open."}),(0,s.jsx)(i.$,{type:"button",variant:"outline",size:"sm",onClick:()=>y.current?.click(),children:"Choose a file"})]}),a&&(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Reading ",m,"..."]}),o&&(0,s.jsxs)("div",{role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm",children:[(0,s.jsxs)("span",{className:"font-semibold text-destructive",children:["Could not read ",m,". "]}),o]}),f&&(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:[["Records",f.recordCount.toLocaleString()],["Blocks",String(f.blocks)],["Codec",f.codec],["Shown",`${f.records.length.toLocaleString()}${f.truncated?" of them":""}`]].map(([e,t])=>(0,s.jsxs)("div",{className:"rounded-md border bg-muted/30 px-3 py-2",children:[(0,s.jsx)("div",{className:"truncate text-lg font-semibold",children:t}),(0,s.jsx)("div",{className:"text-xs text-muted-foreground",children:e})]},e))}),f.notes.map((e,t)=>(0,s.jsx)("div",{className:"rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-sm text-amber-900 dark:text-amber-200",children:e},`note-${t}`)),(0,s.jsxs)("details",{className:"rounded-md border p-3",open:!0,children:[(0,s.jsx)("summary",{className:"cursor-pointer text-sm font-medium",children:"The writer schema stored in the file"}),(0,s.jsxs)("div",{className:"mt-3 space-y-2",children:[(0,s.jsx)(d.T,{readOnly:!0,value:w,"aria-label":"Writer schema",className:"min-h-[180px] font-mono text-xs"}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",onClick:()=>e(w),children:"Open it in Format and validate"}),(0,s.jsx)(ev.i,{value:w,label:"Copy schema",size:"sm",variant:"outline"})]}),Object.entries(f.metadata).filter(([e,t])=>t&&"avro.schema"!==e).length>0&&(0,s.jsx)("dl",{className:"text-xs text-muted-foreground",children:Object.entries(f.metadata).filter(([e,t])=>t&&"avro.schema"!==e).map(([e,t])=>(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("dt",{className:"font-mono",children:e}),(0,s.jsx)("dd",{className:"font-mono",children:t})]},e))})]})]}),f.records.length>0&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsxs)("span",{className:"text-sm font-medium",children:["First ",f.records.length.toLocaleStr
66ing()," record",1===f.records.length?"":"s"]}),(0,s.jsxs)("div",{className:"ml-auto flex gap-1",children:[v&&(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",onClick:()=>eC(function(e,t){let r=[t.map(e=>(0,en.r)(e)).join(",")];for(let s of e){let e=b(s)?s:{};r.push(t.map(t=>(0,en.r)(ex(e[t]))).join(","))}return r.join("\r\n")}(f.records,v),"records.csv","text/csv"),children:"Download CSV"}),(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",onClick:()=>eC(JSON.stringify(eg(f.records),null,2),"records.json","application/json"),children:"Download JSON"})]})]}),(0,s.jsx)("div",{className:"max-h-[460px] overflow-auto rounded-md border",children:(0,s.jsxs)("table",{className:"w-full border-collapse text-xs",children:[(0,s.jsx)("thead",{className:"sticky top-0 bg-muted",children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{className:"border-b px-2 py-1.5 text-left font-medium",children:"#"}),(v??["value"]).map(e=>(0,s.jsx)("th",{className:"border-b px-2 py-1.5 text-left font-medium",children:e},e))]})}),(0,s.jsx)("tbody",{children:f.records.map((e,t)=>(0,s.jsxs)("tr",{className:"odd:bg-muted/20",children:[(0,s.jsx)("td",{className:"border-b px-2 py-1 text-muted-foreground",children:t+1}),v?v.map(t=>(0,s.jsx)("td",{className:"max-w-xs truncate border-b px-2 py-1 font-mono",children:ex(e?.[t])},t)):(0,s.jsx)("td",{className:"border-b px-2 py-1 font-mono",children:ex(e)})]},`row-${t}`))})]})}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Whole numbers wider than a JavaScript number stays exact for are shown as plain digits, so a Kafka offset or a microsecond timestamp keeps every one of them. Timestamps, dates and decimals are shown in readable form rather than as the raw counter."})]})]})]})}function eU({onUseSchema:e}
66){let[t,r]=(0,n.useState)(""),[a,u]=(0,n.useState)("Root"),[c,m]=(0,n.useState)("com.example"),[h,f]=(0,n.useState)(!1),p=(0,n.useMemo)(()=>{if(!t.trim())return null;try{return{ok:!0,value:JSON.parse(t)}}catch(e){return{ok:!1,...ez(t,e)}}},[t]),y=(0,n.useMemo)(()=>{if(!p?.ok)return"";try{return _(function(e,t){let r=new Set,s=function e(s,n){if(null===s)return{type:"null",optional:!0};if("boolean"==typeof s)return{type:"boolean",optional:!1};if("number"==typeof s)return{type:Number.isInteger(s)?"long":"double",optional:!1};if("string"==typeof s)return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(s)?{type:{type:"long",logicalType:"timestamp-millis"},optional:!1}:/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s)?{type:{type:"string",logicalType:"uuid"},optional:!1}:{type:"string",optional:!1};if(Array.isArray(s)){if(0===s.length)return{type:{type:"array",items:"string"},optional:!1};let t=e(s[0],`${n}Item`).type;for(let r=1;r<s.length;r++)t=function e(t,r){if(W(t)===W(r))return t;if(b(t)&&b(r)){if("record"===t.type&&"record"===r.type)return function(t,r){let s=Array.isArray(t.fields)?t.fields:[],n=Array.isArray(r.fields)?r.fields:[],a=new Map;for(let e of n)a.set(String(e.name),e);let i=new Set(s.map(e=>String(e.name))),l=s.map(t=>{let r=a.get(String(t.name));return r?function(t,r){let s=e(t.type,r.type),n={...t,type:s};return Z(s).includes("null")&&(n.default=null),n}(t,r):K(t)});for(let e of n)i.has(String(e.name))||l.push(K(e));return{...t,fields:l}}(t,r);if("array"===t.type&&"array"===r.type)return{...t,items:e(t.items,r.items)};if("map"===t.type&&"map"===r.type)return{...t,values:e(t.values,r.values)}}return V([...Z(t),...Z(r)])}(t,e(s[r],`${n}Item`).type);return{type:{type:"array",items:t},optional:!1}}if(b(s)){let a=Object.keys(s);return a.length>0&&a.every(e=>!/^[A-Za-z_][A-Za-z0-9_]*$/.test(e))?{type:{type:"map",values:e(s[a[0]],`${n}Value`).type},optional:!1}:{type:{type:"record",name:function(e){let t=q(e.length?e[0].toUpperCase()+e.slice(1):e,"Record"),s=t,n=2;for(;r.has(s);)s=`${t}${n++}`;return r.add(s),s}(n),fields:a.map(r=>
66{let n=e(s[r],r),a=q(r,"field"),i={name:a,type:n.type};return a!==r&&(i.aliases=[r]),"null"===n.type?(i.type=["null","string"],i.default=null):(t.nullable||n.optional)&&(i.type=["null",n.type],i.default=null),i})},optional:!1}}return{type:"string",optional:!1}}(e,t.recordName||"Root");return b(s.type)&&"record"===s.type.type&&t.namespace?{type:"record",name:s.type.name,namespace:t.namespace,fields:s.type.fields}:s.type}(p.value,{recordName:a,namespace:c,nullable:h}),"2",!0)}catch{return""}},[p,a,c,h]);return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-end gap-3 rounded-md border bg-muted/40 px-3 py-2",children:[(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)(o.J,{htmlFor:"avro-record-name",children:"Record name"}),(0,s.jsx)(l.p,{id:"avro-record-name",value:a,onChange:e=>u(e.target.value),className:"w-40"})]}),(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)(o.J,{htmlFor:"avro-namespace",children:"Namespace"}),(0,s.jsx)(l.p,{id:"avro-namespace",value:c,onChange:e=>m(e.target.value),className:"w-52"})]}),(0,s.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 pb-2 text-sm",children:[(0,s.jsx)("input",{type:"checkbox",checked:h,onChange:e=>f(e.target.checked),className:"h-4 w-4"}),"Make every field nullable with a null default"]}),(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>r(eO),children:"Load a sample record"})]}),(0,s.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,s.jsx)(eL,{id:"avro-json-input",label:"A sample JSON record",value:t,onChange:r,rows:"min-h-[300px]",placeholder:'Paste one record of your data.\n\n{ "id": 1, "name": "Ada" }'}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,s.jsx)(o.J,{htmlFor:"avro-inferred",children:"Inferred schema"}),(0,s.jsxs)("div",{className:"flex gap-1",children:[(0,s.jsx)(ev.i,{value:y,label:"Copy",size:"sm",variant:"outline",disabled:!y}),(0,s.jsx)(i.$,{type:"button",size:"sm",variant:"outline",disabled:!y,onClick:()=>e(y),children:"Validate it"})]})]}),(0,s.jsx)(d.T,{id:"avro-inferred",readOnly:!0,value:y,"aria-label":"Inferred schema",className:"min-h-[300px] font-mono text-xs",placeholder:"The schema shows up here."})]})]}),p&&!p.ok&&(0,s.jsxs)("div",{role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm",children:[(0,s.jsx)("span",{className:"font-semibold text-destructive",children:"That is not valid JSON."}
66)," Line ",p.line,", column ",p.col,"."]}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Whole numbers come out as long rather than int on purpose. An id or a timestamp in milliseconds overflows a 32-bit int, and the sample record almost never shows you that before production does. A null in the sample becomes a nullable union with a null default, since a field that is sometimes absent needs one to stay compatible later. Paste an array and every element is read, not just the first, so a field that only shows up halfway down still lands in the schema as a nullable one. An empty array is the one thing it has to guess at, and it guesses an array of string."})]})}function e_(){let[e,t]=(0,n.useState)("schema"),[l,o]=(0,n.useState)(""),[d,c]=(0,n.useState)("2"),[m,h]=(0,n.useState)(!0),[f,p]=(0,n.useState)(""),[y,g]=(0,n.useState)([""]),[x,b]=(0,n.useState)("BACKWARD"),[v,w]=(0,n.useState)(null),[$,N]=(0,n.useState)([]);(0,n.useEffect)(()=>{let e=!0;return Promise.all([r.e(28628),r.e(59356)]).then(r.bind(r,59356)).then(t=>{e&&w(()=>t.jsonrepair)}).catch(()=>{}),()=>{e=!1}},[]),(0,n.useEffect)(()=>{try{let e=new URLSearchParams(window.location.search),r=e.get("s"),s=e.get("tab"),n=e.get("o");r&&("compat"===s?p(r):o(r)),n&&g([n]),("compat"===s||"data"===s||"infer"===s)&&t(s)}catch{}try{let e=window.localStorage.getItem(e$);if(e){let t=JSON.parse(e);("2"===t.indent||"4"===t.indent||"tab"===t.indent||"min"===t.indent)&&c(t.indent),"boolean"==typeof t.avroOrder&&h(t.avroOrder),("BACKWARD"===t.level||"FORWARD"===t.level||"FULL"===t.level)&&b(t.level)}let t=window.localStorage.getItem(ew);if(t){let e=JSON.parse(t);Array.isArray(e)&&N(e.filter(e=>"string"==typeof e))}}catch{}},[]),(0,a.Vd)(e$,()=>JSON.stringify({indent:d,avroOrder:m,level:x}),[d,m,x]);let j=(0,n.useCallback)(e=>{N(t=>{if(t[0]===e)return t;let r=[e,...t.filter(t=>t!==e)].slice(0,5);try{window.localStorage.setItem(ew,JSON.stringify(r))}catch{}return r})},[]),A=(0,n.useCallback)(e=>{o(e),t("schema")},[]),k=(0,n.useCallback)(()=>{let t=new URLSearchParams;if("schema"!==e&&t.set("tab",e),"compat"===e){f&&f.length<=1400&&t.set("s",f);let e=y[y.length-1];e&&e.length<=1400&&t.set("o",e)}else l&&l.length<=1400&&t.set("s",l);return t},[e,l,f,y]),S=(0,n.useMemo)(()=>{let t=[];if("compat"===e){f&&f.length>1400&&t.push("the new schema");let e=y[y.length-1];e&&e.length>1400&&t.push("the registry schema")}else l&&l.length>1400&&t.push("this schema");return t},[e,l,f,y]),T=(0,n.useMemo)(()=>"compat"===e?y.slice(0,-1).filter(e=>e.trim()).length:0,[e,y]);return(0,s.jsxs)("div",{className:"space-y-5",children:[(0,s.jsx)("div",{className:"flex flex-wrap gap-1 rounded-md border bg-muted/40 p-1",children:eN.map(r=>(0,s.jsx)(i.$,{type:"button",size:"sm",variant:e===r.id?"default":"ghost",onClick:()=>t(r.id),children:r.label},r.id))}),"schema"===e&&(0,s.jsx)(eD,{text:l,setText:o,repair:v,indent:d,setIndent:c,avroOrder:m,setAvroOrder:h,recents:$,onSaveRecent:j}),"compat"===e&&(0,s.jsx)(eI,{next:f,setNext:p,previous:y,setPrevious:g,level:x,setLevel:b,repair:v}),"data"===e&&(0,s.jsx)(eM,{onUseSchema:A}),"infer"===e&&(0,s.jsx)(eU,{onUseSchema:A}),S.length>0&&(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[S.join(" and ")," ",S.length>1?"are":"is"," over ",1400," ","characters, so the share link below leaves ",S.length>1?"them":"it"," out and opens empty. Send the schema text itself instead."]}),T>0&&(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:["The share link carries the new schema and the most recent previous one."," ",T," older ",1===T?"version is":"versions are"," part of this transitive check but will not travel in the link, so send ",1===T?"it":"them"," separately."]}),(0,s.jsx)(u.ToolActions,{getParams:k,title:"Avro Formatter"})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.