@writedocs/generator 0.13.2 → 0.13.4

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.
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { findNodeAtLocation, parseTree } from "jsonc-parser";
2
+ import { findNodeAtLocation, parseTree, visit } from "jsonc-parser";
3
3
  import { BASE_PATH_FIELD_PATTERN } from "./base-path.js";
4
4
  const navPageSchema = z.string();
5
5
  const navGroupPagesSchema = z.lazy(
@@ -730,6 +730,7 @@ const docsConfigSchema = z.object({
730
730
  // See integrationsSchema above.
731
731
  integrations: integrationsSchema
732
732
  });
733
+ const VALIDATION_ISSUE_LIMIT = 100;
733
734
  function positionFromJsonError(message, rawText) {
734
735
  const comLinha = message.match(/line (\d+) column (\d+)/);
735
736
  if (comLinha) return { line: Number(comLinha[1]), column: Number(comLinha[2]) };
@@ -742,10 +743,19 @@ function positionFromJsonError(message, rawText) {
742
743
  }
743
744
  return null;
744
745
  }
745
- function formatValidationIssues(issues) {
746
- return issues.map((i) => ` - ${i.path}: ${i.message}`).join("\n");
746
+ function formatValidationIssues(issues, { total, truncated } = {}) {
747
+ const linhas = issues.map((i) => ` - ${i.path}: ${i.message}`);
748
+ const resto = moreIssuesLine(issues.length, total, truncated);
749
+ if (resto) linhas.push(` ${resto}`);
750
+ return linhas.join("\n");
747
751
  }
748
- function formatValidationIssuesDetailed(issues, { fileName = "writedocs.json" } = {}) {
752
+ function moreIssuesLine(listados, total, truncated = false) {
753
+ if (truncated) return '...and more - run "writedocs validate --all" for the full list.';
754
+ if (total === void 0 || total <= listados) return null;
755
+ return `...and ${total - listados} more - only the first ${listados} are listed.`;
756
+ }
757
+ function formatValidationIssuesDetailed(issues, { fileName = "writedocs.json", total, truncated } = {}) {
758
+ const resto = moreIssuesLine(issues.length, total, truncated);
749
759
  return issues.map((i) => {
750
760
  const temCampo = i.path !== "(root)";
751
761
  const local = i.line ? `${fileName}:${i.line}` : i.path;
@@ -754,7 +764,7 @@ function formatValidationIssuesDetailed(issues, { fileName = "writedocs.json" }
754
764
  if (i.suggestion) linhas.push(` ${i.suggestion}`);
755
765
  if (i.humanMessage && i.message !== i.humanMessage) linhas.push(` (${i.message})`);
756
766
  return linhas.join("\n");
757
- }).join("\n\n");
767
+ }).concat(resto ? [` ${resto}`] : []).join("\n\n");
758
768
  }
759
769
  const ROOT_ALLOWED_EXTRA_KEYS = Object.freeze(["$schema"]);
760
770
  function issuesDoRamo(ramo) {
@@ -762,46 +772,71 @@ function issuesDoRamo(ramo) {
762
772
  const comIssues = ramo;
763
773
  return comIssues?.issues ?? [];
764
774
  }
765
- function maiorProfundidade(lista) {
766
- let maior = 0;
767
- for (const issue of lista) {
768
- const p = issue.caminho.length + (issue.code === "unrecognized_keys" ? 1 : 0);
769
- if (p > maior) maior = p;
770
- }
771
- return maior;
775
+ function ramosDaUniao(issue) {
776
+ const ramos = issue.code === "invalid_union" ? issue.errors ?? issue.unionErrors : null;
777
+ return Array.isArray(ramos) && ramos.length > 0 ? ramos : null;
772
778
  }
773
- const planoPorRamo = /* @__PURE__ */ new WeakMap();
774
- function planoDoRamo(ramo) {
775
- const lista = issuesDoRamo(ramo);
776
- if (typeof ramo !== "object" || ramo === null) return desembrulharUnioes(lista);
777
- const memoizado = planoPorRamo.get(ramo);
778
- if (memoizado) return memoizado;
779
- const plano = desembrulharUnioes(lista);
780
- planoPorRamo.set(ramo, plano);
781
- return plano;
779
+ function resumoDoRamo(ramo, resumos) {
780
+ const memoizavel = typeof ramo === "object" && ramo !== null;
781
+ if (memoizavel) {
782
+ const memoizado = resumos.get(ramo);
783
+ if (memoizado) return memoizado;
784
+ }
785
+ let n = 0;
786
+ let maior = -Infinity;
787
+ let temUniao = false;
788
+ for (const issue of issuesDoRamo(ramo)) {
789
+ const passos = issue.path?.length ?? 0;
790
+ const lista = issue.wdLista;
791
+ if (lista) {
792
+ temUniao = true;
793
+ n += lista.n;
794
+ if (lista.n > 0 && passos + lista.maior > maior) maior = passos + lista.maior;
795
+ continue;
796
+ }
797
+ const ramos = ramosDaUniao(issue);
798
+ if (ramos) {
799
+ temUniao = true;
800
+ const escolhido = resumoDoRamo(melhorRamo(ramos, resumos), resumos);
801
+ n += escolhido.n;
802
+ if (escolhido.n > 0 && passos + escolhido.maior > maior) maior = passos + escolhido.maior;
803
+ } else {
804
+ n += 1;
805
+ const p = passos + (issue.code === "unrecognized_keys" ? 1 : 0);
806
+ if (p > maior) maior = p;
807
+ }
808
+ }
809
+ const resumo = { n, maior };
810
+ if (memoizavel && temUniao) resumos.set(ramo, resumo);
811
+ return resumo;
782
812
  }
783
- function melhorRamo(ramos) {
784
- return ramos.map((ramo) => {
785
- const plano = planoDoRamo(ramo);
786
- return {
787
- lista: issuesDoRamo(ramo),
788
- n: plano.length,
789
- profundidade: maiorProfundidade(plano)
790
- };
791
- }).sort((a, b) => b.profundidade - a.profundidade || a.n - b.n)[0].lista;
813
+ function melhorRamo(ramos, resumos) {
814
+ let melhor = ramos[0];
815
+ const primeiro = resumoDoRamo(melhor, resumos);
816
+ let profundidade = Math.max(0, primeiro.maior);
817
+ let n = primeiro.n;
818
+ for (let i = 1; i < ramos.length; i++) {
819
+ const resumo = resumoDoRamo(ramos[i], resumos);
820
+ const p = Math.max(0, resumo.maior);
821
+ if (p > profundidade || p === profundidade && resumo.n < n) {
822
+ melhor = ramos[i];
823
+ profundidade = p;
824
+ n = resumo.n;
825
+ }
826
+ }
827
+ return melhor;
792
828
  }
793
- function desembrulharUnioes(issues, prefixo = []) {
794
- const saida = [];
829
+ function* desembrulharUnioes(issues, resumos, prefixo = []) {
795
830
  for (const issue of issues) {
796
831
  const caminho = [...prefixo, ...issue.path ?? []];
797
- const ramos = issue.code === "invalid_union" ? issue.errors ?? issue.unionErrors : null;
798
- if (Array.isArray(ramos) && ramos.length > 0) {
799
- saida.push(...desembrulharUnioes(melhorRamo(ramos), caminho));
800
- } else {
801
- saida.push({ ...issue, caminho });
832
+ if (issue.wdLista) {
833
+ yield* itensDaLista(issue.wdLista, resumos, caminho);
834
+ continue;
802
835
  }
836
+ const ramos = ramosDaUniao(issue);
837
+ if (ramos) yield* desembrulharUnioes(issuesDoRamo(melhorRamo(ramos, resumos)), resumos, caminho);
838
+ else yield [issue, caminho];
803
839
  }
804
- return saida;
805
840
  }
806
841
  const LISTAS_DE_CONTAINER = ["tabs", "versions", "languages", "dropdowns", "products"];
807
842
  const ITENS_DE_CONTAINER = {
@@ -811,21 +846,19 @@ const ITENS_DE_CONTAINER = {
811
846
  dropdown: { lista: "dropdowns", nome: "A dropdown" },
812
847
  product: { lista: "products", nome: "A product" }
813
848
  };
814
- function containersEmPaginas(issues, raiz) {
849
+ function* containersEmPaginas(issues, raiz) {
815
850
  const vistos = /* @__PURE__ */ new Set();
816
- const saida = [];
817
- for (const issue of issues) {
818
- const achado = containerEmPaginas(issue.caminho, raiz);
851
+ for (const [issue, caminho] of issues) {
852
+ const achado = containerEmPaginas(caminho, raiz);
819
853
  if (!achado) {
820
- saida.push(issue);
854
+ yield { ...issue, caminho };
821
855
  continue;
822
856
  }
823
857
  const chave = achado.caminho.join(".");
824
858
  if (vistos.has(chave)) continue;
825
859
  vistos.add(chave);
826
- saida.push({ ...issue, code: "custom", caminho: achado.caminho, message: achado.mensagem, keys: void 0 });
860
+ yield { ...issue, code: "custom", caminho: achado.caminho, message: achado.mensagem, keys: void 0 };
827
861
  }
828
- return saida;
829
862
  }
830
863
  function containerEmPaginas(caminho, raiz) {
831
864
  for (let k = 1; k < caminho.length; k++) {
@@ -859,25 +892,282 @@ function containerEmPaginas(caminho, raiz) {
859
892
  }
860
893
  return null;
861
894
  }
895
+ let corte = null;
896
+ const CHAVES_DE_RAMO = ["pages", "tabs", "versions", "languages", "dropdowns", "products", "href", "openapi", "global"];
897
+ function disputado(objeto) {
898
+ let achadas = 0;
899
+ for (const chave of CHAVES_DE_RAMO) if (chave in objeto && ++achadas >= 2) return true;
900
+ return false;
901
+ }
902
+ function recolhido(objeto) {
903
+ return !("group" in objeto) && (LISTAS_DE_CONTAINER.some((l) => l in objeto) || Object.keys(ITENS_DE_CONTAINER).some((t) => t in objeto));
904
+ }
905
+ function ehObjeto(v) {
906
+ return v !== null && typeof v === "object" && !Array.isArray(v);
907
+ }
908
+ function embrulhar(schema, comCorte) {
909
+ const zod = schema._zod;
910
+ let original = zod.parse;
911
+ const runEhParse = zod.run === original;
912
+ const embrulhado = (payload, ctx) => corte ? comCorte(original, schema, payload, ctx) : original(payload, ctx);
913
+ Object.defineProperty(zod, "parse", { configurable: true, enumerable: true, get: () => embrulhado, set: (v) => {
914
+ original = v;
915
+ } });
916
+ if (runEhParse) Object.defineProperty(zod, "run", { configurable: true, enumerable: true, get: () => embrulhado, set: () => {
917
+ } });
918
+ }
919
+ function instalarCorte(raiz, membros) {
920
+ const todos = [];
921
+ const opcoes = /* @__PURE__ */ new Set();
922
+ const vistos = /* @__PURE__ */ new Set();
923
+ const pendentes = [raiz];
924
+ const resolver = (schema) => schema?._zod?.def?.type === "lazy" ? schema._zod.innerType : schema;
925
+ while (pendentes.length) {
926
+ const schema = pendentes.pop();
927
+ if (!schema || typeof schema !== "object" || !schema._zod || vistos.has(schema)) continue;
928
+ vistos.add(schema);
929
+ todos.push(schema);
930
+ const def = schema._zod.def;
931
+ if (def.type === "array") pendentes.push(def.element);
932
+ else if (def.type === "record") pendentes.push(def.keyType, def.valueType);
933
+ else if (def.type === "object") {
934
+ pendentes.push(...Object.values(def.shape));
935
+ if (def.catchall) pendentes.push(def.catchall);
936
+ } else if (def.type === "union") {
937
+ for (const opcao of def.options) opcoes.add(resolver(opcao));
938
+ pendentes.push(...def.options);
939
+ } else if (def.type === "lazy") pendentes.push(schema._zod.innerType);
940
+ else if (def.type === "pipe") pendentes.push(def.in, def.out);
941
+ else if (def.innerType) pendentes.push(def.innerType);
942
+ }
943
+ for (const schema of todos) {
944
+ const tipo = schema._zod.def.type;
945
+ if (tipo === "array") embrulhar(schema, listaComCorte);
946
+ else if (tipo === "record") embrulhar(schema, registroComCorte);
947
+ else if (tipo === "object" && opcoes.has(schema)) embrulhar(schema, objetoComCorte(membros.has(schema)));
948
+ }
949
+ }
950
+ function objetoComCorte(membro) {
951
+ return (original, _schema, payload, ctx) => {
952
+ const estado = corte;
953
+ const valor = payload.value;
954
+ if (estado.regioes.length > 0 || !ehObjeto(valor)) return original(payload, ctx);
955
+ const regiao = disputado(valor) ? "contar" : membro && recolhido(valor) ? "pular" : null;
956
+ if (!regiao) return original(payload, ctx);
957
+ estado.regioes.push(regiao);
958
+ try {
959
+ return original(payload, ctx);
960
+ } finally {
961
+ estado.regioes.pop();
962
+ }
963
+ };
964
+ }
965
+ function rodar(schema, valor, ctx) {
966
+ const resultado = schema._zod.run({ value: valor, issues: [] }, ctx);
967
+ if (resultado instanceof Promise) throw new Error("[writedocs] async validation is not supported");
968
+ return resultado;
969
+ }
970
+ function abortou(resultado) {
971
+ return resultado.aborted === true || resultado.issues.some((issue) => issue.continue !== true);
972
+ }
973
+ const listaComCorte = (original, schema, payload, ctx) => {
974
+ const entrada = payload.value;
975
+ if (!Array.isArray(entrada)) return original(payload, ctx);
976
+ const estado = corte;
977
+ const elemento = schema._zod.def.element;
978
+ const valor = new Array(entrada.length);
979
+ payload.value = valor;
980
+ const regiao = estado.regioes[estado.regioes.length - 1];
981
+ if (regiao === "pular") {
982
+ for (let i = 0; i < entrada.length; i++) valor[i] = entrada[i];
983
+ return payload;
984
+ }
985
+ if (regiao === "contar") {
986
+ let n = 0;
987
+ let maior = -Infinity;
988
+ let algumErrado = false;
989
+ let algumAborta = false;
990
+ for (let i = 0; i < entrada.length; i++) {
991
+ const resultado = rodar(elemento, entrada[i], ctx);
992
+ valor[i] = resultado.value;
993
+ if (resultado.issues.length === 0) continue;
994
+ algumErrado = true;
995
+ if (abortou(resultado)) algumAborta = true;
996
+ const resumo = resumoDoRamo(resultado.issues, /* @__PURE__ */ new Map());
997
+ n += resumo.n;
998
+ if (resumo.n > 0 && 1 + resumo.maior > maior) maior = 1 + resumo.maior;
999
+ }
1000
+ if (algumErrado) {
1001
+ payload.issues.push({
1002
+ code: "custom",
1003
+ message: "writedocs: list summary",
1004
+ path: [],
1005
+ continue: !algumAborta,
1006
+ wdLista: { n, maior, entrada, elemento }
1007
+ });
1008
+ }
1009
+ return payload;
1010
+ }
1011
+ for (let i = 0; i < entrada.length; i++) {
1012
+ if (estado.esgotado) {
1013
+ valor[i] = entrada[i];
1014
+ continue;
1015
+ }
1016
+ const antes = estado.contados;
1017
+ const resultado = rodar(elemento, entrada[i], ctx);
1018
+ valor[i] = resultado.value;
1019
+ if (resultado.issues.length === 0) continue;
1020
+ for (const issue of resultado.issues) {
1021
+ (issue.path ??= []).unshift(i);
1022
+ payload.issues.push(issue);
1023
+ }
1024
+ if (estado.contados === antes && ++estado.contados > VALIDATION_ISSUE_LIMIT) estado.esgotado = true;
1025
+ }
1026
+ return payload;
1027
+ };
1028
+ const registroComCorte = (original, schema, payload, ctx) => {
1029
+ const entrada = payload.value;
1030
+ const estado = corte;
1031
+ const def = schema._zod.def;
1032
+ const chaveTexto = def.keyType?._zod?.def?.type === "string" && !(def.keyType._zod.def.checks?.length > 0);
1033
+ if (estado.regioes.length > 0 || !ehObjeto(entrada) || !chaveTexto || Object.getPrototypeOf(entrada) !== Object.prototype) {
1034
+ return original(payload, ctx);
1035
+ }
1036
+ const valor = {};
1037
+ payload.value = valor;
1038
+ for (const chave of Object.keys(entrada)) {
1039
+ if (chave === "__proto__") continue;
1040
+ if (estado.esgotado) {
1041
+ valor[chave] = entrada[chave];
1042
+ continue;
1043
+ }
1044
+ const antes = estado.contados;
1045
+ const resultado = rodar(def.valueType, entrada[chave], ctx);
1046
+ valor[chave] = resultado.value;
1047
+ if (resultado.issues.length === 0) continue;
1048
+ for (const issue of resultado.issues) {
1049
+ (issue.path ??= []).unshift(chave);
1050
+ payload.issues.push(issue);
1051
+ }
1052
+ if (estado.contados === antes && ++estado.contados > VALIDATION_ISSUE_LIMIT) estado.esgotado = true;
1053
+ }
1054
+ return payload;
1055
+ };
1056
+ function* itensDaLista(lista, resumos, caminho) {
1057
+ for (let i = 0; i < lista.entrada.length; i++) {
1058
+ corte?.regioes.push("contar");
1059
+ let resultado;
1060
+ try {
1061
+ resultado = lista.elemento.safeParse(lista.entrada[i]);
1062
+ } finally {
1063
+ corte?.regioes.pop();
1064
+ }
1065
+ if (resultado.success) continue;
1066
+ yield* desembrulharUnioes(resultado.error.issues, resumos, [...caminho, i]);
1067
+ }
1068
+ }
1069
+ instalarCorte(
1070
+ docsConfigSchema,
1071
+ /* @__PURE__ */ new Set([navGroupPagesSchema._zod.innerType, navGroupOpenApiSchema, navLinkSchema])
1072
+ );
1073
+ function localizarCaminhos(rawText, caminhos) {
1074
+ rawText = semBom(rawText);
1075
+ const raiz = { filhos: /* @__PURE__ */ new Map(), alvo: false };
1076
+ for (const caminho of caminhos) {
1077
+ if (caminho.length === 0) continue;
1078
+ let no = raiz;
1079
+ for (const passo of caminho) {
1080
+ let filho = no.filhos.get(passo);
1081
+ if (!filho) no.filhos.set(passo, filho = { filhos: /* @__PURE__ */ new Map(), alvo: false });
1082
+ no = filho;
1083
+ }
1084
+ no.alvo = true;
1085
+ }
1086
+ const pilha = [];
1087
+ const comecoDeValor = (offset) => {
1088
+ const topo = pilha[pilha.length - 1];
1089
+ if (!topo) return raiz;
1090
+ if (!topo.no) return null;
1091
+ let filho;
1092
+ if (topo.lista) filho = topo.no.filhos.get(topo.indice++) ?? null;
1093
+ else {
1094
+ filho = topo.no.filhos.get(topo.chave) ?? null;
1095
+ if (filho) {
1096
+ if (topo.vistas.has(topo.chave)) filho = null;
1097
+ else topo.vistas.add(topo.chave);
1098
+ }
1099
+ }
1100
+ if (filho?.alvo && filho.offset === void 0) filho.offset = offset;
1101
+ return filho;
1102
+ };
1103
+ const abrir = (lista) => (offset) => {
1104
+ const no = comecoDeValor(offset);
1105
+ pilha.push({ no, lista, indice: 0, chave: "", vistas: /* @__PURE__ */ new Set() });
1106
+ return no !== null && no.filhos.size > 0 ? void 0 : false;
1107
+ };
1108
+ if (raiz.filhos.size > 0) {
1109
+ visit(rawText, {
1110
+ onObjectBegin: abrir(false),
1111
+ onArrayBegin: abrir(true),
1112
+ onObjectEnd: () => void pilha.pop(),
1113
+ onArrayEnd: () => void pilha.pop(),
1114
+ onObjectProperty: (chave) => {
1115
+ pilha[pilha.length - 1].chave = chave;
1116
+ },
1117
+ onLiteralValue: (_valor, offset) => void comecoDeValor(offset)
1118
+ });
1119
+ }
1120
+ let inicios;
1121
+ return (caminho) => {
1122
+ if (caminho.length === 0) return null;
1123
+ let no = raiz;
1124
+ for (const passo of caminho) {
1125
+ no = no.filhos.get(passo);
1126
+ if (!no) return null;
1127
+ }
1128
+ if (no.offset === void 0) return null;
1129
+ inicios ??= iniciosDeLinha(rawText);
1130
+ return linhaEColuna(inicios, no.offset);
1131
+ };
1132
+ }
862
1133
  function createJsonLocator(rawText) {
863
1134
  return criarLocalizador(rawText);
864
1135
  }
865
1136
  function criarLocalizador(rawText) {
866
1137
  rawText = semBom(rawText);
867
- let arvore;
868
- try {
869
- arvore = parseTree(rawText);
870
- } catch {
871
- arvore = void 0;
872
- }
1138
+ let arvore = null;
1139
+ let inicios;
873
1140
  return (caminho) => {
874
- if (!arvore || caminho.length === 0) return null;
1141
+ if (caminho.length === 0) return null;
1142
+ if (arvore === null) {
1143
+ try {
1144
+ arvore = parseTree(rawText);
1145
+ } catch {
1146
+ arvore = void 0;
1147
+ }
1148
+ }
1149
+ if (!arvore) return null;
875
1150
  const no = findNodeAtLocation(arvore, caminho);
876
1151
  if (!no) return null;
877
- const antes = rawText.slice(0, no.offset);
878
- return { line: antes.split("\n").length, column: no.offset - antes.lastIndexOf("\n") };
1152
+ inicios ??= iniciosDeLinha(rawText);
1153
+ return linhaEColuna(inicios, no.offset);
879
1154
  };
880
1155
  }
1156
+ function iniciosDeLinha(texto) {
1157
+ const inicios = [0];
1158
+ for (let i = texto.indexOf("\n"); i !== -1; i = texto.indexOf("\n", i + 1)) inicios.push(i + 1);
1159
+ return inicios;
1160
+ }
1161
+ function linhaEColuna(inicios, offset) {
1162
+ let baixo = 0;
1163
+ let alto = inicios.length - 1;
1164
+ while (baixo < alto) {
1165
+ const meio = baixo + alto + 1 >> 1;
1166
+ if (inicios[meio] <= offset) baixo = meio;
1167
+ else alto = meio - 1;
1168
+ }
1169
+ return { line: baixo + 1, column: offset - inicios[baixo] + 1 };
1170
+ }
881
1171
  function docKeyDoCaminho(caminho) {
882
1172
  const primeiro = caminho[0];
883
1173
  return typeof primeiro === "string" && primeiro ? `config.${primeiro}` : "config";
@@ -982,17 +1272,22 @@ function humanizar(issue, raiz) {
982
1272
  }
983
1273
  }
984
1274
  function unknownRootKeyIssues(rawText) {
1275
+ return unknownRootKeyWarnings(rawText).issues;
1276
+ }
1277
+ function unknownRootKeyWarnings(rawText, { all = false } = {}) {
985
1278
  rawText = semBom(rawText);
986
1279
  let raiz;
987
1280
  try {
988
1281
  raiz = JSON.parse(rawText);
989
1282
  } catch {
990
- return [];
1283
+ return { issues: [], issuesTotal: 0 };
991
1284
  }
992
- if (raiz === null || typeof raiz !== "object" || Array.isArray(raiz)) return [];
1285
+ if (raiz === null || typeof raiz !== "object" || Array.isArray(raiz)) return { issues: [], issuesTotal: 0 };
993
1286
  const conhecidas = /* @__PURE__ */ new Set([...Object.keys(docsConfigSchema.shape), ...ROOT_ALLOWED_EXTRA_KEYS]);
994
- const localizar = criarLocalizador(rawText);
995
- return Object.keys(raiz).filter((chave) => !conhecidas.has(chave)).map((chave) => {
1287
+ const desconhecidas = Object.keys(raiz).filter((chave) => !conhecidas.has(chave));
1288
+ const listadas = all ? desconhecidas : desconhecidas.slice(0, VALIDATION_ISSUE_LIMIT);
1289
+ const localizar = localizarCaminhos(rawText, listadas.map((chave) => [chave]));
1290
+ const issues = listadas.map((chave) => {
996
1291
  const frase = fraseChaveDesconhecida([chave], []);
997
1292
  return {
998
1293
  path: chave,
@@ -1010,11 +1305,12 @@ function unknownRootKeyIssues(rawText) {
1010
1305
  docKey: "config"
1011
1306
  };
1012
1307
  });
1308
+ return { issues, issuesTotal: desconhecidas.length };
1013
1309
  }
1014
1310
  function semBom(texto) {
1015
1311
  return texto.charCodeAt(0) === 65279 ? texto.slice(1) : texto;
1016
1312
  }
1017
- function validateDocsConfig(rawText) {
1313
+ function validateDocsConfig(rawText, { all = false } = {}) {
1018
1314
  rawText = semBom(rawText);
1019
1315
  let raw;
1020
1316
  try {
@@ -1037,30 +1333,69 @@ function validateDocsConfig(rawText) {
1037
1333
  suggestion: posicao ? `Look at line ${posicao.line} - a missing comma, an extra trailing comma, or an unclosed bracket is the usual cause.` : "A missing comma, an extra trailing comma, or an unclosed bracket is the usual cause.",
1038
1334
  docKey: "config"
1039
1335
  }
1040
- ]
1336
+ ],
1337
+ issuesTotal: 1,
1338
+ issuesTruncated: false
1041
1339
  };
1042
1340
  }
1043
- const result = docsConfigSchema.safeParse(raw);
1044
- if (!result.success) {
1045
- const localizar = criarLocalizador(rawText);
1341
+ if (all) return validarTudo(rawText, raw);
1342
+ corte = { contados: 0, esgotado: false, regioes: [] };
1343
+ try {
1344
+ const result = docsConfigSchema.safeParse(raw);
1345
+ if (result.success) return { ok: true, data: result.data, issues: [], issuesTotal: 0, issuesTruncated: false };
1346
+ const primeiros = [];
1347
+ let truncado = false;
1348
+ const resumos = /* @__PURE__ */ new Map();
1349
+ for (const issue of containersEmPaginas(desembrulharUnioes(result.error.issues, resumos), raw)) {
1350
+ if (primeiros.length === VALIDATION_ISSUE_LIMIT) {
1351
+ truncado = true;
1352
+ break;
1353
+ }
1354
+ primeiros.push(issue);
1355
+ }
1356
+ if (corte.esgotado && !truncado) {
1357
+ corte = null;
1358
+ recaidas++;
1359
+ return limitar(validarTudo(rawText, raw));
1360
+ }
1046
1361
  return {
1047
1362
  ok: false,
1048
1363
  data: null,
1049
1364
  kind: "schema",
1050
- issues: containersEmPaginas(desembrulharUnioes(result.error.issues), raw).map((i) => {
1051
- const alvoDaLinha = i.code === "unrecognized_keys" && i.keys?.length ? [...i.caminho, i.keys[0]] : i.caminho;
1052
- return {
1053
- path: i.caminho.join(".") || "(root)",
1054
- message: i.message,
1055
- code: i.code,
1056
- ...localizar(alvoDaLinha) ?? localizar(i.caminho) ?? {},
1057
- ...humanizar(i, raw),
1058
- docKey: docKeyDoCaminho(i.caminho)
1059
- };
1060
- })
1365
+ issues: localizarEHumanizar(primeiros, rawText, raw, localizarCaminhos),
1366
+ issuesTotal: truncado ? VALIDATION_ISSUE_LIMIT + 1 : primeiros.length,
1367
+ issuesTruncated: truncado
1061
1368
  };
1369
+ } finally {
1370
+ corte = null;
1062
1371
  }
1063
- return { ok: true, data: result.data, issues: [] };
1372
+ }
1373
+ let recaidas = 0;
1374
+ function stopFallbacks() {
1375
+ return recaidas;
1376
+ }
1377
+ function validarTudo(rawText, raw) {
1378
+ const result = docsConfigSchema.safeParse(raw);
1379
+ if (result.success) return { ok: true, data: result.data, issues: [], issuesTotal: 0, issuesTruncated: false };
1380
+ const todos = [...containersEmPaginas(desembrulharUnioes(result.error.issues, /* @__PURE__ */ new Map()), raw)];
1381
+ const issues = localizarEHumanizar(todos, rawText, raw, (texto) => criarLocalizador(texto));
1382
+ return { ok: false, data: null, kind: "schema", issues, issuesTotal: issues.length, issuesTruncated: false };
1383
+ }
1384
+ function limitar(resultado) {
1385
+ if (resultado.issues.length <= VALIDATION_ISSUE_LIMIT) return resultado;
1386
+ return { ...resultado, issues: resultado.issues.slice(0, VALIDATION_ISSUE_LIMIT), issuesTotal: VALIDATION_ISSUE_LIMIT + 1, issuesTruncated: true };
1387
+ }
1388
+ function localizarEHumanizar(lista, rawText, raw, criar) {
1389
+ const alvos = lista.map((i) => i.code === "unrecognized_keys" && i.keys?.length ? [...i.caminho, i.keys[0]] : i.caminho);
1390
+ const localizar = criar(rawText, [...alvos, ...lista.map((i) => i.caminho)]);
1391
+ return lista.map((i, k) => ({
1392
+ path: i.caminho.join(".") || "(root)",
1393
+ message: i.message,
1394
+ code: i.code,
1395
+ ...localizar(alvos[k]) ?? localizar(i.caminho) ?? {},
1396
+ ...humanizar(i, raw),
1397
+ docKey: docKeyDoCaminho(i.caminho)
1398
+ }));
1064
1399
  }
1065
1400
  export {
1066
1401
  CONTEXT_MENU_OPTIONS,
@@ -1068,16 +1403,20 @@ export {
1068
1403
  MAX_TAB_MENU_LEVELS,
1069
1404
  MCP_MENU_OPTIONS,
1070
1405
  ROOT_ALLOWED_EXTRA_KEYS,
1406
+ VALIDATION_ISSUE_LIMIT,
1071
1407
  contextMenuOptions,
1072
1408
  createJsonLocator,
1073
1409
  docsConfigSchema,
1074
1410
  formatValidationIssues,
1075
1411
  formatValidationIssuesDetailed,
1076
1412
  mergeSeo,
1413
+ moreIssuesLine,
1077
1414
  pageFrontmatterSchema,
1078
1415
  pageSeoFieldsSchema,
1079
1416
  seoFieldsSchema,
1080
1417
  siteSeoFieldsSchema,
1418
+ stopFallbacks,
1081
1419
  unknownRootKeyIssues,
1420
+ unknownRootKeyWarnings,
1082
1421
  validateDocsConfig
1083
1422
  };