polite-crawler 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{cli-daemon-DAq4B_u-.mjs → cli-daemon-C2_Pd4v_.mjs} +2 -2
- package/build/{cli-daemon-DAq4B_u-.mjs.map → cli-daemon-C2_Pd4v_.mjs.map} +1 -1
- package/build/{cli-recipes-BXTuQHc3.mjs → cli-recipes-XlxoNo75.mjs} +2 -2
- package/build/{cli-recipes-BXTuQHc3.mjs.map → cli-recipes-XlxoNo75.mjs.map} +1 -1
- package/build/cli.mjs +7 -7
- package/build/{daemon-CSge_vif.mjs → daemon-B0Cp8xeB.mjs} +3 -3
- package/build/{daemon-CSge_vif.mjs.map → daemon-B0Cp8xeB.mjs.map} +1 -1
- package/build/{diff-DxhmN3bo.mjs → diff-DHpF9lYY.mjs} +2 -2
- package/build/{diff-DxhmN3bo.mjs.map → diff-DHpF9lYY.mjs.map} +1 -1
- package/build/{extract-DmNeGMHX.mjs → extract-BgcEkiQr.mjs} +3 -3
- package/build/{extract-DmNeGMHX.mjs.map → extract-BgcEkiQr.mjs.map} +1 -1
- package/build/{html-DkQUAE_d.mjs → html-DzobO0fy.mjs} +17 -2
- package/build/html-DzobO0fy.mjs.map +1 -0
- package/build/html.mjs +1 -1
- package/build/index.d.mts +1 -1
- package/build/index.mjs +11 -11
- package/build/{open-DWzixXcq.mjs → open-YGJPjbDc.mjs} +7 -7
- package/build/{open-DWzixXcq.mjs.map → open-YGJPjbDc.mjs.map} +1 -1
- package/build/{recipe-BQX7GI1z.mjs → recipe-CPmYb91t.mjs} +4 -4
- package/build/{recipe-BQX7GI1z.mjs.map → recipe-CPmYb91t.mjs.map} +1 -1
- package/build/{recipe-product-DVj9oHdJ.mjs → recipe-product-B6XmkpB3.mjs} +5 -5
- package/build/{recipe-product-DVj9oHdJ.mjs.map → recipe-product-B6XmkpB3.mjs.map} +1 -1
- package/build/robots.mjs +11 -6
- package/build/robots.mjs.map +1 -1
- package/build/{runtime-CmAOsSPn.mjs → runtime-j2NpXEiN.mjs} +10 -4
- package/build/runtime-j2NpXEiN.mjs.map +1 -0
- package/build/{version-BBVugNVm.mjs → version-Dw3pZOVT.mjs} +2 -2
- package/build/{version-BBVugNVm.mjs.map → version-Dw3pZOVT.mjs.map} +1 -1
- package/build/{wacz-t-JDRIMf.mjs → wacz-ixsUXYCs.mjs} +3 -3
- package/build/{wacz-t-JDRIMf.mjs.map → wacz-ixsUXYCs.mjs.map} +1 -1
- package/build/{warc-Ci4ygka2.mjs → warc-B47Bdjzk.mjs} +2 -2
- package/build/{warc-Ci4ygka2.mjs.map → warc-B47Bdjzk.mjs.map} +1 -1
- package/package.json +5 -4
- package/build/html-DkQUAE_d.mjs.map +0 -1
- package/build/runtime-CmAOsSPn.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff-DxhmN3bo.mjs","names":[],"sources":["../src/diff.ts"],"sourcesContent":["import type { CrawlRuntime } from \"./runtime.ts\";\nimport type { VersionText } from \"./docs.ts\";\nimport { HELD_BACK, heldBackMeta, isHeldBack, isoTime, versionAtTime } from \"./runtime.ts\";\nimport { stableStringify } from \"./record.ts\";\n\n/**\n * A diff compares two versions of a stored document. It gives the changes of the text as a line\n * diff, with a word diff inside each changed line. It gives the changes of the title, the URL and\n * the metadata (the JSON-LD too) as changes at a path.\n *\n * The line diff is the algorithm of Myers (1986). Its time is linear in the length of the texts\n * when the change is small. A budget of steps (`DIFF_LIMITS`) bounds the time of a large change.\n * After the budget, the diff gives the rest of the change as one removal and one addition. Then\n * the result says that it is not minimal. A huge text gives its first part, and the result says so.\n *\n * A held-back version gives no text and no title to a diff, and only its structural metadata.\n */\n\n/** These are the limits of a diff. Each limit bounds the time or the size of a result. */\nexport const DIFF_LIMITS = {\n /** The characters of each text that a diff compares. A longer text gives its first part. */\n maxChars: 1_000_000,\n /** The lines of each text that a diff compares. A longer text gives its first lines. */\n maxLines: 50_000,\n /** The steps of the line diff. After them, the rest of the change is one removal and one addition. */\n maxSteps: 1_000_000,\n /** The steps of the word diffs of all the changed lines together. */\n maxWordSteps: 1_000_000,\n /** The words of one line that a word diff compares. A longer line gets no word diff. */\n maxLineWords: 5_000,\n /** The lines of context before and after each change. */\n context: 2,\n /** The lines that the hunks of a result show. The summary counts each line. */\n maxHunkLines: 2_000,\n /** The changes of the metadata that a result shows. The summary counts each change. */\n maxMetaChanges: 200,\n /** The depth of the metadata that a diff compares. A deeper change is a change of the whole value. */\n maxMetaDepth: 16,\n /** The characters of the JSON of each value of a change of the metadata. */\n maxValueChars: 300,\n} as const;\n\n/** These are the limits of a diff, one by one. `DIFF_LIMITS` gives the defaults. */\nexport type DiffLimits = { readonly [K in keyof typeof DIFF_LIMITS]: number };\n\n/** This is a part of a changed line: words that stay, words that the new text adds, or words that it removes. */\nexport interface WordPart {\n readonly op: \"same\" | \"added\" | \"removed\";\n readonly text: string;\n}\n\n/**\n * This is one line of a hunk. A `same` line is context. A `changed` line pairs a removed line with\n * an added line, and `words` gives the word diff, or null when the word budget ended.\n */\nexport type DiffLine =\n | { readonly op: \"same\" | \"added\" | \"removed\"; readonly text: string }\n | {\n readonly op: \"changed\";\n readonly before: string;\n readonly after: string;\n readonly words: readonly WordPart[] | null;\n };\n\n/** This is a part of the diff of the text: the changed lines with some context, as in a unified diff. */\nexport interface DiffHunk {\n /** This value is the number (from 1) of the first line of the hunk in the old text. */\n readonly from_line: number;\n /** This value is the number of lines of the old text in the hunk. */\n readonly from_count: number;\n /** This value is the number (from 1) of the first line of the hunk in the new text. */\n readonly to_line: number;\n /** This value is the number of lines of the new text in the hunk. */\n readonly to_count: number;\n readonly lines: readonly DiffLine[];\n}\n\n/**\n * This is one change of the title, the URL or the metadata. The path names the value, for\n * example `meta.jsonld[0].openingHours`. `before` and `after` are the JSON of the values, cut to\n * `DIFF_LIMITS.maxValueChars`.\n */\nexport interface MetaChange {\n readonly path: string;\n readonly change: \"added\" | \"removed\" | \"changed\";\n /** This text is the JSON of the old value, or null when the new version adds the value. */\n readonly before: string | null;\n /** This text is the JSON of the new value, or null when the new version removes the value. */\n readonly after: string | null;\n}\n\n/** These are the counts of a diff. */\nexport interface DiffSummary {\n /** This value counts the lines that only the new text has. */\n readonly lines_added: number;\n /** This value counts the lines that only the old text has. */\n readonly lines_removed: number;\n /** This value counts the pairs of a removed line and an added line that the result shows as one changed line. */\n readonly lines_changed: number;\n /** This value counts the words that the new text adds, in the added lines and in the changed lines. */\n readonly words_added: number;\n /** This value counts the words that the new text removes, in the removed lines and in the changed lines. */\n readonly words_removed: number;\n /** This value counts the changes of the title, the URL and the metadata. */\n readonly meta_changes: number;\n}\n\n/** This is the input of `diffTexts`: the parts of a version that a diff compares. */\nexport interface DiffInput {\n readonly text: string;\n readonly fields: Readonly<Record<string, unknown>>;\n}\n\n/** This is the result of `diffTexts`. */\nexport interface TextDiff {\n readonly summary: DiffSummary;\n readonly hunks: readonly DiffHunk[];\n readonly meta: readonly MetaChange[];\n /** This value is true when the text and the fields are the same. */\n readonly same: boolean;\n /** This value is true when the line diff is minimal and each changed line has its word diff. */\n readonly exact: boolean;\n /** This value is true when the result leaves out a part. It can leave out the end of a long text, lines of the hunks or changes of the metadata. */\n readonly truncated: boolean;\n /** This value counts the steps of the line diff and of the word diffs. A test reads it: a step count does not change with the computer. */\n readonly steps: number;\n readonly notes: readonly string[];\n}\n\n/** A run of the edit script. `0` keeps lines of the two texts. `1` removes lines of the old text, and `2` adds lines of the new text. */\ninterface Run {\n readonly op: 0 | 1 | 2;\n readonly count: number;\n}\n\n/** A budget of steps. The diffs add to `steps`, and stop when it passes `max`. */\ninterface Budget {\n steps: number;\n max: number;\n}\n\n/**\n * This function gives an edit script from `a` to `b`, with the algorithm of Myers. It first\n * removes the common start and the common end. When the budget ends, it keeps the furthest path\n * that it found, and the rest is one removal and one addition. `exact` is then false.\n */\nexport const editScript = (\n a: ArrayLike<number>,\n b: ArrayLike<number>,\n budget: Budget,\n): { readonly runs: Run[]; readonly exact: boolean } => {\n const n = a.length;\n const m = b.length;\n let head = 0;\n while (head < n && head < m && a[head] === b[head]) head += 1;\n let endA = n;\n let endB = m;\n while (endA > head && endB > head && a[endA - 1] === b[endB - 1]) {\n endA -= 1;\n endB -= 1;\n }\n budget.steps += head + (n - endA) + 1;\n const reversed: Array<[0 | 1 | 2, number]> = [];\n const width = endA - head;\n const height = endB - head;\n let exact = true;\n reversed.push([0, n - endA]);\n if (width === 0 || height === 0) {\n reversed.push([2, height], [1, width]);\n } else {\n const at = (x: number): number => a[head + x]!;\n const bt = (y: number): number => b[head + y]!;\n const max = width + height;\n const offset = max + 1;\n const v = new Int32Array(2 * max + 3);\n // trace[d] is the band of v after the round d: the index k + d holds the furthest x on the diagonal k\n const trace: Int32Array[] = [];\n let end: { readonly x: number; readonly y: number; readonly d: number } | undefined;\n rounds: for (let d = 0; d <= max; d += 1) {\n for (let k = -d; k <= d; k += 2) {\n budget.steps += 1;\n if (budget.steps > budget.max) break rounds;\n let x =\n k === -d || (k !== d && v[offset + k - 1]! < v[offset + k + 1]!)\n ? v[offset + k + 1]!\n : v[offset + k - 1]! + 1;\n let y = x - k;\n while (x < width && y < height && at(x) === bt(y)) {\n x += 1;\n y += 1;\n budget.steps += 1;\n }\n v[offset + k] = x;\n if (x >= width && y >= height) {\n end = { x, y, d };\n break rounds;\n }\n }\n trace.push(v.slice(offset - d, offset + d + 1));\n }\n if (end === undefined) {\n // the budget ended: the furthest point of the last full round, and the rest as one change\n exact = false;\n const d = trace.length - 1;\n let x = 0;\n let y = 0;\n if (d >= 0) {\n const band = trace[d]!;\n for (let k = -d; k <= d; k += 2) {\n const fx = band[k + d]!;\n const fy = fx - k;\n if (fx <= width && fy >= 0 && fy <= height && fx + fy > x + y) {\n x = fx;\n y = fy;\n }\n }\n }\n reversed.push([2, height - y], [1, width - x]);\n end = { x, y, d: Math.max(0, d) };\n }\n let { x, y } = end;\n for (let d = end.d; d > 0; d -= 1) {\n const band = trace[d - 1]!;\n const k = x - y;\n const before = (kk: number): number => band[kk + d - 1]!;\n const down = k === -d || (k !== d && before(k - 1) < before(k + 1));\n const fromK = down ? k + 1 : k - 1;\n const fromX = before(fromK);\n const fromY = fromX - fromK;\n const moved = down ? fromX : fromX + 1;\n reversed.push([0, x - moved], down ? [2, 1] : [1, 1]);\n x = fromX;\n y = fromY;\n }\n reversed.push([0, x]);\n }\n reversed.push([0, head]);\n const runs: Run[] = [];\n for (let at = reversed.length - 1; at >= 0; at -= 1) {\n const [op, count] = reversed[at]!;\n if (count <= 0) continue;\n const last = runs.at(-1);\n if (last !== undefined && last.op === op)\n runs[runs.length - 1] = { op, count: last.count + count };\n else runs.push({ op, count });\n }\n return { runs, exact };\n};\n\n/** This function gives a number for each value, equal numbers for equal values. */\nconst numberer = (): ((value: string) => number) => {\n const ids = new Map<string, number>();\n return (value) => {\n let id = ids.get(value);\n if (id === undefined) {\n id = ids.size;\n ids.set(value, id);\n }\n return id;\n };\n};\n\n/** A token is a word, a run of spaces, or one sign. */\nconst TOKEN = /\\s+|[\\p{L}\\p{N}\\p{M}_]+|[^\\s\\p{L}\\p{N}\\p{M}_]/gu;\n\nconst tokensOf = (line: string): string[] => line.match(TOKEN) ?? [];\n\n/** This function counts the words of a text: each token that is not a space. */\nconst wordsOf = (text: string): number => {\n let count = 0;\n for (const token of tokensOf(text)) if (!/^\\s+$/.test(token)) count += 1;\n return count;\n};\n\n/** This function gives the word diff of a changed line, or null when the line is too long or the budget ended. */\nconst wordDiff = (\n before: string,\n after: string,\n budget: Budget,\n limits: DiffLimits,\n): { readonly parts: WordPart[]; readonly exact: boolean } | null => {\n if (budget.steps >= budget.max) return null;\n const a = tokensOf(before);\n const b = tokensOf(after);\n if (a.length > limits.maxLineWords || b.length > limits.maxLineWords) return null;\n const id = numberer();\n const script = editScript(\n a.map((token) => id(token)),\n b.map((token) => id(token)),\n budget,\n );\n const parts: WordPart[] = [];\n const push = (op: WordPart[\"op\"], text: string): void => {\n const last = parts.at(-1);\n if (last !== undefined && last.op === op)\n parts[parts.length - 1] = { op, text: last.text + text };\n else parts.push({ op, text });\n };\n let i = 0;\n let j = 0;\n for (const run of script.runs) {\n if (run.op === 0) {\n push(\"same\", a.slice(i, i + run.count).join(\"\"));\n i += run.count;\n j += run.count;\n } else if (run.op === 1) {\n push(\"removed\", a.slice(i, i + run.count).join(\"\"));\n i += run.count;\n } else {\n push(\"added\", b.slice(j, j + run.count).join(\"\"));\n j += run.count;\n }\n }\n return { parts, exact: script.exact };\n};\n\n/** One line of the full diff, before the hunks: its kind and its positions in the old and the new text. */\ntype Entry =\n | { readonly op: \"same\"; readonly a: number; readonly b: number }\n | { readonly op: \"removed\"; readonly a: number }\n | { readonly op: \"added\"; readonly b: number }\n | {\n readonly op: \"changed\";\n readonly a: number;\n readonly b: number;\n readonly words: readonly WordPart[] | null;\n };\n\nconst IDENTIFIER = /^[A-Za-z_$][\\w$]*$/;\n\nconst keyPath = (path: string, key: string): string =>\n IDENTIFIER.test(key) ? (path === \"\" ? key : `${path}.${key}`) : `${path}[${JSON.stringify(key)}]`;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/** This function gives the changes at paths between two values, to the limits. */\nconst metaChanges = (\n before: unknown,\n after: unknown,\n limits: DiffLimits,\n): { readonly changes: MetaChange[]; readonly count: number } => {\n const changes: MetaChange[] = [];\n let count = 0;\n const show = (value: unknown): string => {\n const text = stableStringify(value);\n return text.length > limits.maxValueChars ? `${text.slice(0, limits.maxValueChars)}…` : text;\n };\n const note = (path: string, change: MetaChange[\"change\"], a: unknown, b: unknown): void => {\n count += 1;\n if (changes.length < limits.maxMetaChanges) {\n changes.push({\n path,\n change,\n before: change === \"added\" ? null : show(a),\n after: change === \"removed\" ? null : show(b),\n });\n }\n };\n // each array diff has a small budget of its own, so the metadata stays bounded too\n const walk = (a: unknown, b: unknown, path: string, depth: number): void => {\n if (a === b) return;\n if (depth >= limits.maxMetaDepth) {\n if (stableStringify(a) !== stableStringify(b)) note(path, \"changed\", a, b);\n return;\n }\n if (isRecord(a) && isRecord(b)) {\n const keys = [...new Set([...Object.keys(a), ...Object.keys(b)])].sort();\n for (const key of keys) {\n const inA = Object.hasOwn(a, key) && a[key] !== undefined;\n const inB = Object.hasOwn(b, key) && b[key] !== undefined;\n const at = keyPath(path, key);\n if (inA && !inB) note(at, \"removed\", a[key], undefined);\n else if (!inA && inB) note(at, \"added\", undefined, b[key]);\n else if (inA && inB) walk(a[key], b[key], at, depth + 1);\n }\n return;\n }\n if (Array.isArray(a) && Array.isArray(b)) {\n const id = numberer();\n const script = editScript(\n a.map((item) => id(stableStringify(item))),\n b.map((item) => id(stableStringify(item))),\n { steps: 0, max: 100_000 },\n );\n let i = 0;\n let j = 0;\n const removed: number[] = [];\n const added: number[] = [];\n const flush = (): void => {\n const pairs = Math.min(removed.length, added.length);\n for (let at = 0; at < pairs; at += 1) {\n walk(a[removed[at]!], b[added[at]!], `${path}[${String(added[at])}]`, depth + 1);\n }\n for (const at of removed.slice(pairs))\n note(`${path}[${String(at)}]`, \"removed\", a[at], undefined);\n for (const at of added.slice(pairs))\n note(`${path}[${String(at)}]`, \"added\", undefined, b[at]);\n removed.length = 0;\n added.length = 0;\n };\n for (const run of script.runs) {\n if (run.op === 0) {\n flush();\n i += run.count;\n j += run.count;\n } else if (run.op === 1) {\n for (let at = 0; at < run.count; at += 1) removed.push(i + at);\n i += run.count;\n } else {\n for (let at = 0; at < run.count; at += 1) added.push(j + at);\n j += run.count;\n }\n }\n flush();\n return;\n }\n if (stableStringify(a) !== stableStringify(b)) note(path, \"changed\", a, b);\n };\n walk(before, after, \"\", 0);\n return { changes, count };\n};\n\n/** This function gives the limits of a diff, with the defaults of `DIFF_LIMITS` for the limits that it does not get. */\nconst limitsOf = (given: Partial<DiffLimits>): DiffLimits => {\n const limits: Record<string, number> = { ...DIFF_LIMITS };\n for (const [name, value] of Object.entries(given)) {\n if (value === undefined) continue;\n if (!Number.isInteger(value) || value < 0)\n throw new RangeError(`the diff limit ${name} must be an integer of 0 or more`);\n limits[name] = value;\n }\n return limits as DiffLimits;\n};\n\n/**\n * This function compares two versions: the lines of the text, the words of each changed line, and\n * the fields (the title, the URL and the metadata) at their paths. It writes nothing, and its time\n * and its result stay inside the limits.\n */\nexport const diffTexts = (\n before: DiffInput,\n after: DiffInput,\n given: Partial<DiffLimits> = {},\n): TextDiff => {\n const limits = limitsOf(given);\n const notes: string[] = [];\n let truncated = false;\n const cut = (text: string, side: string): string[] => {\n let kept = text;\n if (kept.length > limits.maxChars) {\n kept = kept.slice(0, limits.maxChars);\n truncated = true;\n notes.push(\n `the ${side} text is longer than ${String(limits.maxChars)} characters, so the diff compares its first part`,\n );\n }\n const lines = kept.length === 0 ? [] : kept.split(\"\\n\");\n if (lines.length > limits.maxLines) {\n truncated = true;\n notes.push(\n `the ${side} text has more than ${String(limits.maxLines)} lines, so the diff compares its first lines`,\n );\n return lines.slice(0, limits.maxLines);\n }\n return lines;\n };\n const a = cut(before.text, \"old\");\n const b = cut(after.text, \"new\");\n const id = numberer();\n const lineBudget: Budget = { steps: 0, max: limits.maxSteps };\n const script = editScript(\n a.map((line) => id(line)),\n b.map((line) => id(line)),\n lineBudget,\n );\n let exact = script.exact;\n if (!script.exact) {\n notes.push(\n `the change is too large for a minimal diff in ${String(limits.maxSteps)} steps, so the diff shows its last part as one removal and one addition`,\n );\n }\n const wordBudget: Budget = { steps: 0, max: limits.maxWordSteps };\n const entries: Entry[] = [];\n let linesAdded = 0;\n let linesRemoved = 0;\n let linesChanged = 0;\n let wordsAdded = 0;\n let wordsRemoved = 0;\n let wordsCut = false;\n let i = 0;\n let j = 0;\n const removed: number[] = [];\n const added: number[] = [];\n const flush = (): void => {\n const pairs = Math.min(removed.length, added.length);\n for (let at = 0; at < pairs; at += 1) {\n const from = removed[at]!;\n const to = added[at]!;\n const words = wordDiff(a[from]!, b[to]!, wordBudget, limits);\n if (words === null) {\n wordsCut = true;\n wordsRemoved += wordsOf(a[from]!);\n wordsAdded += wordsOf(b[to]!);\n } else {\n if (!words.exact) exact = false;\n for (const part of words.parts) {\n if (part.op === \"added\") wordsAdded += wordsOf(part.text);\n else if (part.op === \"removed\") wordsRemoved += wordsOf(part.text);\n }\n }\n entries.push({ op: \"changed\", a: from, b: to, words: words?.parts ?? null });\n }\n for (const from of removed.slice(pairs)) {\n wordsRemoved += wordsOf(a[from]!);\n entries.push({ op: \"removed\", a: from });\n }\n for (const to of added.slice(pairs)) {\n wordsAdded += wordsOf(b[to]!);\n entries.push({ op: \"added\", b: to });\n }\n linesChanged += pairs;\n removed.length = 0;\n added.length = 0;\n };\n for (const run of script.runs) {\n if (run.op === 0) {\n flush();\n for (let at = 0; at < run.count; at += 1) entries.push({ op: \"same\", a: i + at, b: j + at });\n i += run.count;\n j += run.count;\n } else if (run.op === 1) {\n for (let at = 0; at < run.count; at += 1) removed.push(i + at);\n linesRemoved += run.count;\n i += run.count;\n } else {\n for (let at = 0; at < run.count; at += 1) added.push(j + at);\n linesAdded += run.count;\n j += run.count;\n }\n }\n flush();\n if (wordsCut) {\n exact = false;\n notes.push(\"some changed lines have no word diff: they are too long, or the word budget ended\");\n }\n\n // the hunks: each change with its context, and the hunks that touch become one\n const hunks: DiffHunk[] = [];\n let shown = 0;\n let current:\n { lines: DiffLine[]; from: number; to: number; a: number; b: number; end: number } | undefined;\n const lineOf = (entry: Entry): DiffLine => {\n switch (entry.op) {\n case \"same\":\n return { op: \"same\", text: a[entry.a]! };\n case \"removed\":\n return { op: \"removed\", text: a[entry.a]! };\n case \"added\":\n return { op: \"added\", text: b[entry.b]! };\n default:\n return { op: \"changed\", before: a[entry.a]!, after: b[entry.b]!, words: entry.words };\n }\n };\n const close = (): void => {\n if (current === undefined) return;\n hunks.push({\n from_line: current.from + 1,\n from_count: current.a,\n to_line: current.to + 1,\n to_count: current.b,\n lines: current.lines,\n });\n current = undefined;\n };\n // the position in the old and the new text of each entry\n let posA = 0;\n let posB = 0;\n const positions: Array<readonly [number, number]> = [];\n for (const entry of entries) {\n positions.push([posA, posB]);\n if (entry.op !== \"added\") posA += 1;\n if (entry.op !== \"removed\") posB += 1;\n }\n const changeAt: number[] = [];\n for (const [at, entry] of entries.entries()) if (entry.op !== \"same\") changeAt.push(at);\n let hunkCut = false;\n for (const at of changeAt) {\n if (shown >= limits.maxHunkLines) {\n hunkCut = true;\n break;\n }\n const start = Math.max(0, at - limits.context);\n const stop = Math.min(entries.length - 1, at + limits.context);\n if (current !== undefined && start > current.end + 1) close();\n if (current === undefined) {\n const [fromA, fromB] = positions[start]!;\n current = { lines: [], from: fromA, to: fromB, a: 0, b: 0, end: start - 1 };\n }\n for (let line = current.end + 1; line <= stop; line += 1) {\n if (shown >= limits.maxHunkLines) {\n hunkCut = true;\n break;\n }\n const entry = entries[line]!;\n current.lines.push(lineOf(entry));\n if (entry.op !== \"added\") current.a += 1;\n if (entry.op !== \"removed\") current.b += 1;\n current.end = line;\n shown += 1;\n }\n }\n close();\n if (hunkCut) {\n truncated = true;\n notes.push(\n `the hunks show ${String(limits.maxHunkLines)} lines, and the summary counts each line`,\n );\n }\n\n const fields = metaChanges(before.fields, after.fields, limits);\n if (fields.count > fields.changes.length) {\n truncated = true;\n notes.push(\n `the result shows ${String(fields.changes.length)} of ${String(fields.count)} changes of the metadata`,\n );\n }\n return {\n summary: {\n lines_added: linesAdded,\n lines_removed: linesRemoved,\n lines_changed: linesChanged,\n words_added: wordsAdded,\n words_removed: wordsRemoved,\n meta_changes: fields.count,\n },\n hunks,\n meta: fields.changes,\n same:\n linesAdded === 0 && linesRemoved === 0 && fields.count === 0 && before.text === after.text,\n exact,\n truncated,\n steps: lineBudget.steps + wordBudget.steps,\n notes,\n };\n};\n\n// ── the diff of a stored document ───────────────────────────────────────────\n\n/** A version of a document for a diff: a capture id, or the version that was current at a time. */\nexport type VersionChoice = string | { readonly at: string | Date };\n\n/** These options choose the two versions of a diff. */\nexport interface DiffOptions {\n /**\n * This version is the old side: a capture id, or `{ at }`. The default is the version before\n * `to` with the same recipe and the same kind of capture (plain or rendered).\n */\n readonly from?: VersionChoice | undefined;\n /** This version is the new side: a capture id, or `{ at }`. The default is the newest version. */\n readonly to?: VersionChoice | undefined;\n /** These values change the limits of the diff (`DIFF_LIMITS`). */\n readonly limits?: Partial<DiffLimits> | undefined;\n}\n\n/** This is one side of a diff: the version that it compares. */\nexport interface DiffSide {\n /** This id is the capture of the version. A citation names it. */\n readonly capture: string;\n /** This time (ISO 8601) is the fetch time of the version. */\n readonly fetched_at: string;\n /** This value is the length of the text of the version. */\n readonly chars: number;\n readonly rendered: boolean;\n /** This value is true when the version is held back, so the diff does not show its text. */\n readonly held_back: boolean;\n /** This time (ISO 8601) is the `at` that chose the version, or null for a capture id or a default. */\n readonly at: string | null;\n}\n\n/** The result of a diff of two versions of a stored document. */\nexport interface DiffResult {\n readonly doc: string;\n readonly url: string | null;\n readonly from: DiffSide;\n readonly to: DiffSide;\n /**\n * This value is true when the two versions have the same text, title, URL and metadata. It is\n * null when a side is held back, because then the diff does not compare the texts.\n */\n readonly same: boolean | null;\n readonly summary: DiffSummary;\n readonly hunks: readonly DiffHunk[];\n readonly meta: readonly MetaChange[];\n /** This value is true when a side is held back. Then the result has no text and no title, and only the structural metadata. */\n readonly held_back: boolean;\n /** This value is true when the line diff is minimal and each changed line has its word diff. */\n readonly exact: boolean;\n /** This value is true when the result leaves out a part. The note tells which part. */\n readonly truncated: boolean;\n /** This value counts the steps of the diff. */\n readonly steps: number;\n readonly note: string | null;\n}\n\n/** This function gives the version of a choice, or throws an error that names the problem. */\nconst chosen = (\n runtime: CrawlRuntime,\n id: string,\n choice: VersionChoice,\n): { readonly version: VersionText; readonly at: string | null } => {\n if (typeof choice === \"string\") {\n const version = runtime.index.versionText(id, choice);\n if (version === undefined)\n throw new Error(`the document ${id} has no version from the capture ${choice}`);\n return { version, at: null };\n }\n if (!isRecord(choice) || choice.at === undefined)\n throw new RangeError(\"a version is a capture id, or an object with the time at\");\n const at = isoTime(\"at\", choice.at);\n const found = versionAtTime(runtime, id, at);\n if (found.version === undefined) {\n throw new Error(\n `the document ${id} has no version at ${at} or before${found.first === undefined ? \"\" : `: its first capture is from ${found.first}`}`,\n );\n }\n return { version: found.version, at };\n};\n\nconst sideOf = (version: VersionText, at: string | null, held: boolean): DiffSide => ({\n capture: version.capture,\n fetched_at: version.fetched_at,\n chars: version.chars,\n rendered: version.rendered,\n held_back: held,\n at,\n});\n\n/**\n * This function compares two versions of a stored document, and writes nothing. It applies the\n * rule for a held-back document. When the document or a version is held back, the diff compares\n * only the structural metadata, and it shows no text and no title.\n *\n * @beta\n */\nexport const diffDocument = async (\n runtime: CrawlRuntime,\n id: string,\n options: DiffOptions = {},\n): Promise<DiffResult> => {\n await Promise.resolve();\n const doc = runtime.index.get(id);\n if (doc === undefined)\n throw new Error(`no stored document ${id}: find one with find(), or fetch its page`);\n let to: { readonly version: VersionText; readonly at: string | null };\n if (options.to === undefined) {\n const newest = runtime.index.versions(id, { limit: 1 })[0];\n const version =\n newest === undefined ? undefined : runtime.index.versionText(id, newest.capture);\n if (version === undefined) throw new Error(`the document ${id} has no version`);\n to = { version, at: null };\n } else to = chosen(runtime, id, options.to);\n let from: { readonly version: VersionText; readonly at: string | null } | undefined;\n if (options.from === undefined) {\n // the version before, of the same recipe and kind: a render and a plain body are not a change\n const earlier = runtime.index\n .versions(id, { limit: 1000 })\n .find(\n (version) =>\n version.capture !== to.version.capture &&\n version.recipe === to.version.recipe &&\n version.rendered === to.version.rendered &&\n version.fetched_at <= to.version.fetched_at,\n );\n const version =\n earlier === undefined ? undefined : runtime.index.versionText(id, earlier.capture);\n if (version !== undefined) from = { version, at: null };\n } else from = chosen(runtime, id, options.from);\n const notes: string[] = [];\n if (from === undefined) {\n from = to;\n notes.push(`the document ${id} has no earlier version of the same kind to compare`);\n }\n const docHeld = isHeldBack(doc);\n const fromHeld = docHeld || isHeldBack(from.version);\n const toHeld = docHeld || isHeldBack(to.version);\n const held = fromHeld || toHeld;\n const fields = (version: VersionText): Record<string, unknown> =>\n held\n ? { kind: version.kind, url: version.url, meta: heldBackMeta(version.meta) }\n : { title: version.title, kind: version.kind, url: version.url, meta: version.meta };\n const diff = diffTexts(\n { text: held ? \"\" : from.version.text, fields: fields(from.version) },\n { text: held ? \"\" : to.version.text, fields: fields(to.version) },\n options.limits ?? {},\n );\n if (held) notes.unshift(HELD_BACK);\n notes.push(...diff.notes);\n return {\n doc: doc.doc,\n url: to.version.url ?? doc.url,\n from: sideOf(from.version, from.at, fromHeld),\n to: sideOf(to.version, to.at, toHeld),\n same: held ? null : diff.same,\n summary: diff.summary,\n hunks: diff.hunks,\n meta: diff.meta,\n held_back: held,\n exact: diff.exact,\n truncated: diff.truncated,\n steps: diff.steps,\n note: notes.length > 0 ? notes.join(\"; \") : null,\n };\n};\n\n/** This function gives the text of the word diff of a changed line: `[-removed-]` and `{+added+}` mark the words. */\nconst wordsText = (line: Extract<DiffLine, { op: \"changed\" }>): string =>\n line.words === null\n ? `[-${line.before}-]{+${line.after}+}`\n : line.words\n .map((part) =>\n part.op === \"same\"\n ? part.text\n : part.op === \"added\"\n ? `{+${part.text}+}`\n : `[-${part.text}-]`,\n )\n .join(\"\");\n\n/**\n * This function gives the text of a diff for a person or an assistant. The text has the counts, the\n * hunks as a unified diff, and the changes of the metadata. A changed line marks its words with `[-removed-]`\n * and `{+added+}`. The text holds the text of the pages, so the MCP server puts it in an envelope.\n *\n * @beta\n */\nexport const formatDiff = (diff: Pick<DiffResult, \"summary\" | \"hunks\" | \"meta\">): string => {\n const { summary } = diff;\n const lines: string[] = [\n `the text: ${String(summary.lines_added)} lines added, ${String(summary.lines_removed)} removed (${String(summary.lines_changed)} changed), ${String(summary.words_added)} words added, ${String(summary.words_removed)} removed`,\n ];\n for (const hunk of diff.hunks) {\n lines.push(\n `@@ -${String(hunk.from_line)},${String(hunk.from_count)} +${String(hunk.to_line)},${String(hunk.to_count)} @@`,\n );\n for (const line of hunk.lines) {\n if (line.op === \"changed\") lines.push(`~ ${wordsText(line)}`);\n else lines.push(`${line.op === \"same\" ? \" \" : line.op === \"added\" ? \"+\" : \"-\"} ${line.text}`);\n }\n }\n lines.push(`the metadata: ${String(summary.meta_changes)} changes`);\n for (const change of diff.meta) {\n if (change.change === \"added\") lines.push(`+ ${change.path}: ${change.after ?? \"\"}`);\n else if (change.change === \"removed\") lines.push(`- ${change.path}: ${change.before ?? \"\"}`);\n else lines.push(`~ ${change.path}: ${change.before ?? \"\"} -> ${change.after ?? \"\"}`);\n }\n return lines.join(\"\\n\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,cAAc;;CAEzB,UAAU;;CAEV,UAAU;;CAEV,UAAU;;CAEV,cAAc;;CAEd,cAAc;;CAEd,SAAS;;CAET,cAAc;;CAEd,gBAAgB;;CAEhB,cAAc;;CAEd,eAAe;AACjB;;;;;;AA0GA,MAAa,cACX,GACA,GACA,WACsD;CACtD,MAAM,IAAI,EAAE;CACZ,MAAM,IAAI,EAAE;CACZ,IAAI,OAAO;CACX,OAAO,OAAO,KAAK,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,QAAQ;CAC5D,IAAI,OAAO;CACX,IAAI,OAAO;CACX,OAAO,OAAO,QAAQ,OAAO,QAAQ,EAAE,OAAO,OAAO,EAAE,OAAO,IAAI;EAChE,QAAQ;EACR,QAAQ;CACV;CACA,OAAO,SAAS,QAAQ,IAAI,QAAQ;CACpC,MAAM,WAAuC,CAAC;CAC9C,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,OAAO;CACtB,IAAI,QAAQ;CACZ,SAAS,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;CAC3B,IAAI,UAAU,KAAK,WAAW,GAC5B,SAAS,KAAK,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;MAChC;EACL,MAAM,MAAM,MAAsB,EAAE,OAAO;EAC3C,MAAM,MAAM,MAAsB,EAAE,OAAO;EAC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G,KAAK,MAAM;CAEhG;CACA,MAAM,KAAK,iBAAiB,OAAO,QAAQ,YAAY,EAAE,SAAS;CAClE,KAAK,MAAM,UAAU,KAAK,MACxB,IAAI,OAAO,WAAW,SAAS,MAAM,KAAK,KAAK,OAAO,KAAK,IAAI,OAAO,SAAS,IAAI;MAC9E,IAAI,OAAO,WAAW,WAAW,MAAM,KAAK,KAAK,OAAO,KAAK,IAAI,OAAO,UAAU,IAAI;MACtF,MAAM,KAAK,KAAK,OAAO,KAAK,IAAI,OAAO,UAAU,GAAG,MAAM,OAAO,SAAS,IAAI;CAErF,OAAO,MAAM,KAAK,IAAI;AACxB"}
|
|
1
|
+
{"version":3,"file":"diff-DHpF9lYY.mjs","names":[],"sources":["../src/diff.ts"],"sourcesContent":["import type { CrawlRuntime } from \"./runtime.ts\";\nimport type { VersionText } from \"./docs.ts\";\nimport { HELD_BACK, heldBackMeta, isHeldBack, isoTime, versionAtTime } from \"./runtime.ts\";\nimport { stableStringify } from \"./record.ts\";\n\n/**\n * A diff compares two versions of a stored document. It gives the changes of the text as a line\n * diff, with a word diff inside each changed line. It gives the changes of the title, the URL and\n * the metadata (the JSON-LD too) as changes at a path.\n *\n * The line diff is the algorithm of Myers (1986). Its time is linear in the length of the texts\n * when the change is small. A budget of steps (`DIFF_LIMITS`) bounds the time of a large change.\n * After the budget, the diff gives the rest of the change as one removal and one addition. Then\n * the result says that it is not minimal. A huge text gives its first part, and the result says so.\n *\n * A held-back version gives no text and no title to a diff, and only its structural metadata.\n */\n\n/** These are the limits of a diff. Each limit bounds the time or the size of a result. */\nexport const DIFF_LIMITS = {\n /** The characters of each text that a diff compares. A longer text gives its first part. */\n maxChars: 1_000_000,\n /** The lines of each text that a diff compares. A longer text gives its first lines. */\n maxLines: 50_000,\n /** The steps of the line diff. After them, the rest of the change is one removal and one addition. */\n maxSteps: 1_000_000,\n /** The steps of the word diffs of all the changed lines together. */\n maxWordSteps: 1_000_000,\n /** The words of one line that a word diff compares. A longer line gets no word diff. */\n maxLineWords: 5_000,\n /** The lines of context before and after each change. */\n context: 2,\n /** The lines that the hunks of a result show. The summary counts each line. */\n maxHunkLines: 2_000,\n /** The changes of the metadata that a result shows. The summary counts each change. */\n maxMetaChanges: 200,\n /** The depth of the metadata that a diff compares. A deeper change is a change of the whole value. */\n maxMetaDepth: 16,\n /** The characters of the JSON of each value of a change of the metadata. */\n maxValueChars: 300,\n} as const;\n\n/** These are the limits of a diff, one by one. `DIFF_LIMITS` gives the defaults. */\nexport type DiffLimits = { readonly [K in keyof typeof DIFF_LIMITS]: number };\n\n/** This is a part of a changed line: words that stay, words that the new text adds, or words that it removes. */\nexport interface WordPart {\n readonly op: \"same\" | \"added\" | \"removed\";\n readonly text: string;\n}\n\n/**\n * This is one line of a hunk. A `same` line is context. A `changed` line pairs a removed line with\n * an added line, and `words` gives the word diff, or null when the word budget ended.\n */\nexport type DiffLine =\n | { readonly op: \"same\" | \"added\" | \"removed\"; readonly text: string }\n | {\n readonly op: \"changed\";\n readonly before: string;\n readonly after: string;\n readonly words: readonly WordPart[] | null;\n };\n\n/** This is a part of the diff of the text: the changed lines with some context, as in a unified diff. */\nexport interface DiffHunk {\n /** This value is the number (from 1) of the first line of the hunk in the old text. */\n readonly from_line: number;\n /** This value is the number of lines of the old text in the hunk. */\n readonly from_count: number;\n /** This value is the number (from 1) of the first line of the hunk in the new text. */\n readonly to_line: number;\n /** This value is the number of lines of the new text in the hunk. */\n readonly to_count: number;\n readonly lines: readonly DiffLine[];\n}\n\n/**\n * This is one change of the title, the URL or the metadata. The path names the value, for\n * example `meta.jsonld[0].openingHours`. `before` and `after` are the JSON of the values, cut to\n * `DIFF_LIMITS.maxValueChars`.\n */\nexport interface MetaChange {\n readonly path: string;\n readonly change: \"added\" | \"removed\" | \"changed\";\n /** This text is the JSON of the old value, or null when the new version adds the value. */\n readonly before: string | null;\n /** This text is the JSON of the new value, or null when the new version removes the value. */\n readonly after: string | null;\n}\n\n/** These are the counts of a diff. */\nexport interface DiffSummary {\n /** This value counts the lines that only the new text has. */\n readonly lines_added: number;\n /** This value counts the lines that only the old text has. */\n readonly lines_removed: number;\n /** This value counts the pairs of a removed line and an added line that the result shows as one changed line. */\n readonly lines_changed: number;\n /** This value counts the words that the new text adds, in the added lines and in the changed lines. */\n readonly words_added: number;\n /** This value counts the words that the new text removes, in the removed lines and in the changed lines. */\n readonly words_removed: number;\n /** This value counts the changes of the title, the URL and the metadata. */\n readonly meta_changes: number;\n}\n\n/** This is the input of `diffTexts`: the parts of a version that a diff compares. */\nexport interface DiffInput {\n readonly text: string;\n readonly fields: Readonly<Record<string, unknown>>;\n}\n\n/** This is the result of `diffTexts`. */\nexport interface TextDiff {\n readonly summary: DiffSummary;\n readonly hunks: readonly DiffHunk[];\n readonly meta: readonly MetaChange[];\n /** This value is true when the text and the fields are the same. */\n readonly same: boolean;\n /** This value is true when the line diff is minimal and each changed line has its word diff. */\n readonly exact: boolean;\n /** This value is true when the result leaves out a part. It can leave out the end of a long text, lines of the hunks or changes of the metadata. */\n readonly truncated: boolean;\n /** This value counts the steps of the line diff and of the word diffs. A test reads it: a step count does not change with the computer. */\n readonly steps: number;\n readonly notes: readonly string[];\n}\n\n/** A run of the edit script. `0` keeps lines of the two texts. `1` removes lines of the old text, and `2` adds lines of the new text. */\ninterface Run {\n readonly op: 0 | 1 | 2;\n readonly count: number;\n}\n\n/** A budget of steps. The diffs add to `steps`, and stop when it passes `max`. */\ninterface Budget {\n steps: number;\n max: number;\n}\n\n/**\n * This function gives an edit script from `a` to `b`, with the algorithm of Myers. It first\n * removes the common start and the common end. When the budget ends, it keeps the furthest path\n * that it found, and the rest is one removal and one addition. `exact` is then false.\n */\nexport const editScript = (\n a: ArrayLike<number>,\n b: ArrayLike<number>,\n budget: Budget,\n): { readonly runs: Run[]; readonly exact: boolean } => {\n const n = a.length;\n const m = b.length;\n let head = 0;\n while (head < n && head < m && a[head] === b[head]) head += 1;\n let endA = n;\n let endB = m;\n while (endA > head && endB > head && a[endA - 1] === b[endB - 1]) {\n endA -= 1;\n endB -= 1;\n }\n budget.steps += head + (n - endA) + 1;\n const reversed: Array<[0 | 1 | 2, number]> = [];\n const width = endA - head;\n const height = endB - head;\n let exact = true;\n reversed.push([0, n - endA]);\n if (width === 0 || height === 0) {\n reversed.push([2, height], [1, width]);\n } else {\n const at = (x: number): number => a[head + x]!;\n const bt = (y: number): number => b[head + y]!;\n const max = width + height;\n const offset = max + 1;\n const v = new Int32Array(2 * max + 3);\n // trace[d] is the band of v after the round d: the index k + d holds the furthest x on the diagonal k\n const trace: Int32Array[] = [];\n let end: { readonly x: number; readonly y: number; readonly d: number } | undefined;\n rounds: for (let d = 0; d <= max; d += 1) {\n for (let k = -d; k <= d; k += 2) {\n budget.steps += 1;\n if (budget.steps > budget.max) break rounds;\n let x =\n k === -d || (k !== d && v[offset + k - 1]! < v[offset + k + 1]!)\n ? v[offset + k + 1]!\n : v[offset + k - 1]! + 1;\n let y = x - k;\n while (x < width && y < height && at(x) === bt(y)) {\n x += 1;\n y += 1;\n budget.steps += 1;\n }\n v[offset + k] = x;\n if (x >= width && y >= height) {\n end = { x, y, d };\n break rounds;\n }\n }\n trace.push(v.slice(offset - d, offset + d + 1));\n }\n if (end === undefined) {\n // the budget ended: the furthest point of the last full round, and the rest as one change\n exact = false;\n const d = trace.length - 1;\n let x = 0;\n let y = 0;\n if (d >= 0) {\n const band = trace[d]!;\n for (let k = -d; k <= d; k += 2) {\n const fx = band[k + d]!;\n const fy = fx - k;\n if (fx <= width && fy >= 0 && fy <= height && fx + fy > x + y) {\n x = fx;\n y = fy;\n }\n }\n }\n reversed.push([2, height - y], [1, width - x]);\n end = { x, y, d: Math.max(0, d) };\n }\n let { x, y } = end;\n for (let d = end.d; d > 0; d -= 1) {\n const band = trace[d - 1]!;\n const k = x - y;\n const before = (kk: number): number => band[kk + d - 1]!;\n const down = k === -d || (k !== d && before(k - 1) < before(k + 1));\n const fromK = down ? k + 1 : k - 1;\n const fromX = before(fromK);\n const fromY = fromX - fromK;\n const moved = down ? fromX : fromX + 1;\n reversed.push([0, x - moved], down ? [2, 1] : [1, 1]);\n x = fromX;\n y = fromY;\n }\n reversed.push([0, x]);\n }\n reversed.push([0, head]);\n const runs: Run[] = [];\n for (let at = reversed.length - 1; at >= 0; at -= 1) {\n const [op, count] = reversed[at]!;\n if (count <= 0) continue;\n const last = runs.at(-1);\n if (last !== undefined && last.op === op)\n runs[runs.length - 1] = { op, count: last.count + count };\n else runs.push({ op, count });\n }\n return { runs, exact };\n};\n\n/** This function gives a number for each value, equal numbers for equal values. */\nconst numberer = (): ((value: string) => number) => {\n const ids = new Map<string, number>();\n return (value) => {\n let id = ids.get(value);\n if (id === undefined) {\n id = ids.size;\n ids.set(value, id);\n }\n return id;\n };\n};\n\n/** A token is a word, a run of spaces, or one sign. */\nconst TOKEN = /\\s+|[\\p{L}\\p{N}\\p{M}_]+|[^\\s\\p{L}\\p{N}\\p{M}_]/gu;\n\nconst tokensOf = (line: string): string[] => line.match(TOKEN) ?? [];\n\n/** This function counts the words of a text: each token that is not a space. */\nconst wordsOf = (text: string): number => {\n let count = 0;\n for (const token of tokensOf(text)) if (!/^\\s+$/.test(token)) count += 1;\n return count;\n};\n\n/** This function gives the word diff of a changed line, or null when the line is too long or the budget ended. */\nconst wordDiff = (\n before: string,\n after: string,\n budget: Budget,\n limits: DiffLimits,\n): { readonly parts: WordPart[]; readonly exact: boolean } | null => {\n if (budget.steps >= budget.max) return null;\n const a = tokensOf(before);\n const b = tokensOf(after);\n if (a.length > limits.maxLineWords || b.length > limits.maxLineWords) return null;\n const id = numberer();\n const script = editScript(\n a.map((token) => id(token)),\n b.map((token) => id(token)),\n budget,\n );\n const parts: WordPart[] = [];\n const push = (op: WordPart[\"op\"], text: string): void => {\n const last = parts.at(-1);\n if (last !== undefined && last.op === op)\n parts[parts.length - 1] = { op, text: last.text + text };\n else parts.push({ op, text });\n };\n let i = 0;\n let j = 0;\n for (const run of script.runs) {\n if (run.op === 0) {\n push(\"same\", a.slice(i, i + run.count).join(\"\"));\n i += run.count;\n j += run.count;\n } else if (run.op === 1) {\n push(\"removed\", a.slice(i, i + run.count).join(\"\"));\n i += run.count;\n } else {\n push(\"added\", b.slice(j, j + run.count).join(\"\"));\n j += run.count;\n }\n }\n return { parts, exact: script.exact };\n};\n\n/** One line of the full diff, before the hunks: its kind and its positions in the old and the new text. */\ntype Entry =\n | { readonly op: \"same\"; readonly a: number; readonly b: number }\n | { readonly op: \"removed\"; readonly a: number }\n | { readonly op: \"added\"; readonly b: number }\n | {\n readonly op: \"changed\";\n readonly a: number;\n readonly b: number;\n readonly words: readonly WordPart[] | null;\n };\n\nconst IDENTIFIER = /^[A-Za-z_$][\\w$]*$/;\n\nconst keyPath = (path: string, key: string): string =>\n IDENTIFIER.test(key) ? (path === \"\" ? key : `${path}.${key}`) : `${path}[${JSON.stringify(key)}]`;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/** This function gives the changes at paths between two values, to the limits. */\nconst metaChanges = (\n before: unknown,\n after: unknown,\n limits: DiffLimits,\n): { readonly changes: MetaChange[]; readonly count: number } => {\n const changes: MetaChange[] = [];\n let count = 0;\n const show = (value: unknown): string => {\n const text = stableStringify(value);\n return text.length > limits.maxValueChars ? `${text.slice(0, limits.maxValueChars)}…` : text;\n };\n const note = (path: string, change: MetaChange[\"change\"], a: unknown, b: unknown): void => {\n count += 1;\n if (changes.length < limits.maxMetaChanges) {\n changes.push({\n path,\n change,\n before: change === \"added\" ? null : show(a),\n after: change === \"removed\" ? null : show(b),\n });\n }\n };\n // each array diff has a small budget of its own, so the metadata stays bounded too\n const walk = (a: unknown, b: unknown, path: string, depth: number): void => {\n if (a === b) return;\n if (depth >= limits.maxMetaDepth) {\n if (stableStringify(a) !== stableStringify(b)) note(path, \"changed\", a, b);\n return;\n }\n if (isRecord(a) && isRecord(b)) {\n const keys = [...new Set([...Object.keys(a), ...Object.keys(b)])].sort();\n for (const key of keys) {\n const inA = Object.hasOwn(a, key) && a[key] !== undefined;\n const inB = Object.hasOwn(b, key) && b[key] !== undefined;\n const at = keyPath(path, key);\n if (inA && !inB) note(at, \"removed\", a[key], undefined);\n else if (!inA && inB) note(at, \"added\", undefined, b[key]);\n else if (inA && inB) walk(a[key], b[key], at, depth + 1);\n }\n return;\n }\n if (Array.isArray(a) && Array.isArray(b)) {\n const id = numberer();\n const script = editScript(\n a.map((item) => id(stableStringify(item))),\n b.map((item) => id(stableStringify(item))),\n { steps: 0, max: 100_000 },\n );\n let i = 0;\n let j = 0;\n const removed: number[] = [];\n const added: number[] = [];\n const flush = (): void => {\n const pairs = Math.min(removed.length, added.length);\n for (let at = 0; at < pairs; at += 1) {\n walk(a[removed[at]!], b[added[at]!], `${path}[${String(added[at])}]`, depth + 1);\n }\n for (const at of removed.slice(pairs))\n note(`${path}[${String(at)}]`, \"removed\", a[at], undefined);\n for (const at of added.slice(pairs))\n note(`${path}[${String(at)}]`, \"added\", undefined, b[at]);\n removed.length = 0;\n added.length = 0;\n };\n for (const run of script.runs) {\n if (run.op === 0) {\n flush();\n i += run.count;\n j += run.count;\n } else if (run.op === 1) {\n for (let at = 0; at < run.count; at += 1) removed.push(i + at);\n i += run.count;\n } else {\n for (let at = 0; at < run.count; at += 1) added.push(j + at);\n j += run.count;\n }\n }\n flush();\n return;\n }\n if (stableStringify(a) !== stableStringify(b)) note(path, \"changed\", a, b);\n };\n walk(before, after, \"\", 0);\n return { changes, count };\n};\n\n/** This function gives the limits of a diff, with the defaults of `DIFF_LIMITS` for the limits that it does not get. */\nconst limitsOf = (given: Partial<DiffLimits>): DiffLimits => {\n const limits: Record<string, number> = { ...DIFF_LIMITS };\n for (const [name, value] of Object.entries(given)) {\n if (value === undefined) continue;\n if (!Number.isInteger(value) || value < 0)\n throw new RangeError(`the diff limit ${name} must be an integer of 0 or more`);\n limits[name] = value;\n }\n return limits as DiffLimits;\n};\n\n/**\n * This function compares two versions: the lines of the text, the words of each changed line, and\n * the fields (the title, the URL and the metadata) at their paths. It writes nothing, and its time\n * and its result stay inside the limits.\n */\nexport const diffTexts = (\n before: DiffInput,\n after: DiffInput,\n given: Partial<DiffLimits> = {},\n): TextDiff => {\n const limits = limitsOf(given);\n const notes: string[] = [];\n let truncated = false;\n const cut = (text: string, side: string): string[] => {\n let kept = text;\n if (kept.length > limits.maxChars) {\n kept = kept.slice(0, limits.maxChars);\n truncated = true;\n notes.push(\n `the ${side} text is longer than ${String(limits.maxChars)} characters, so the diff compares its first part`,\n );\n }\n const lines = kept.length === 0 ? [] : kept.split(\"\\n\");\n if (lines.length > limits.maxLines) {\n truncated = true;\n notes.push(\n `the ${side} text has more than ${String(limits.maxLines)} lines, so the diff compares its first lines`,\n );\n return lines.slice(0, limits.maxLines);\n }\n return lines;\n };\n const a = cut(before.text, \"old\");\n const b = cut(after.text, \"new\");\n const id = numberer();\n const lineBudget: Budget = { steps: 0, max: limits.maxSteps };\n const script = editScript(\n a.map((line) => id(line)),\n b.map((line) => id(line)),\n lineBudget,\n );\n let exact = script.exact;\n if (!script.exact) {\n notes.push(\n `the change is too large for a minimal diff in ${String(limits.maxSteps)} steps, so the diff shows its last part as one removal and one addition`,\n );\n }\n const wordBudget: Budget = { steps: 0, max: limits.maxWordSteps };\n const entries: Entry[] = [];\n let linesAdded = 0;\n let linesRemoved = 0;\n let linesChanged = 0;\n let wordsAdded = 0;\n let wordsRemoved = 0;\n let wordsCut = false;\n let i = 0;\n let j = 0;\n const removed: number[] = [];\n const added: number[] = [];\n const flush = (): void => {\n const pairs = Math.min(removed.length, added.length);\n for (let at = 0; at < pairs; at += 1) {\n const from = removed[at]!;\n const to = added[at]!;\n const words = wordDiff(a[from]!, b[to]!, wordBudget, limits);\n if (words === null) {\n wordsCut = true;\n wordsRemoved += wordsOf(a[from]!);\n wordsAdded += wordsOf(b[to]!);\n } else {\n if (!words.exact) exact = false;\n for (const part of words.parts) {\n if (part.op === \"added\") wordsAdded += wordsOf(part.text);\n else if (part.op === \"removed\") wordsRemoved += wordsOf(part.text);\n }\n }\n entries.push({ op: \"changed\", a: from, b: to, words: words?.parts ?? null });\n }\n for (const from of removed.slice(pairs)) {\n wordsRemoved += wordsOf(a[from]!);\n entries.push({ op: \"removed\", a: from });\n }\n for (const to of added.slice(pairs)) {\n wordsAdded += wordsOf(b[to]!);\n entries.push({ op: \"added\", b: to });\n }\n linesChanged += pairs;\n removed.length = 0;\n added.length = 0;\n };\n for (const run of script.runs) {\n if (run.op === 0) {\n flush();\n for (let at = 0; at < run.count; at += 1) entries.push({ op: \"same\", a: i + at, b: j + at });\n i += run.count;\n j += run.count;\n } else if (run.op === 1) {\n for (let at = 0; at < run.count; at += 1) removed.push(i + at);\n linesRemoved += run.count;\n i += run.count;\n } else {\n for (let at = 0; at < run.count; at += 1) added.push(j + at);\n linesAdded += run.count;\n j += run.count;\n }\n }\n flush();\n if (wordsCut) {\n exact = false;\n notes.push(\"some changed lines have no word diff: they are too long, or the word budget ended\");\n }\n\n // the hunks: each change with its context, and the hunks that touch become one\n const hunks: DiffHunk[] = [];\n let shown = 0;\n let current:\n { lines: DiffLine[]; from: number; to: number; a: number; b: number; end: number } | undefined;\n const lineOf = (entry: Entry): DiffLine => {\n switch (entry.op) {\n case \"same\":\n return { op: \"same\", text: a[entry.a]! };\n case \"removed\":\n return { op: \"removed\", text: a[entry.a]! };\n case \"added\":\n return { op: \"added\", text: b[entry.b]! };\n default:\n return { op: \"changed\", before: a[entry.a]!, after: b[entry.b]!, words: entry.words };\n }\n };\n const close = (): void => {\n if (current === undefined) return;\n hunks.push({\n from_line: current.from + 1,\n from_count: current.a,\n to_line: current.to + 1,\n to_count: current.b,\n lines: current.lines,\n });\n current = undefined;\n };\n // the position in the old and the new text of each entry\n let posA = 0;\n let posB = 0;\n const positions: Array<readonly [number, number]> = [];\n for (const entry of entries) {\n positions.push([posA, posB]);\n if (entry.op !== \"added\") posA += 1;\n if (entry.op !== \"removed\") posB += 1;\n }\n const changeAt: number[] = [];\n for (const [at, entry] of entries.entries()) if (entry.op !== \"same\") changeAt.push(at);\n let hunkCut = false;\n for (const at of changeAt) {\n if (shown >= limits.maxHunkLines) {\n hunkCut = true;\n break;\n }\n const start = Math.max(0, at - limits.context);\n const stop = Math.min(entries.length - 1, at + limits.context);\n if (current !== undefined && start > current.end + 1) close();\n if (current === undefined) {\n const [fromA, fromB] = positions[start]!;\n current = { lines: [], from: fromA, to: fromB, a: 0, b: 0, end: start - 1 };\n }\n for (let line = current.end + 1; line <= stop; line += 1) {\n if (shown >= limits.maxHunkLines) {\n hunkCut = true;\n break;\n }\n const entry = entries[line]!;\n current.lines.push(lineOf(entry));\n if (entry.op !== \"added\") current.a += 1;\n if (entry.op !== \"removed\") current.b += 1;\n current.end = line;\n shown += 1;\n }\n }\n close();\n if (hunkCut) {\n truncated = true;\n notes.push(\n `the hunks show ${String(limits.maxHunkLines)} lines, and the summary counts each line`,\n );\n }\n\n const fields = metaChanges(before.fields, after.fields, limits);\n if (fields.count > fields.changes.length) {\n truncated = true;\n notes.push(\n `the result shows ${String(fields.changes.length)} of ${String(fields.count)} changes of the metadata`,\n );\n }\n return {\n summary: {\n lines_added: linesAdded,\n lines_removed: linesRemoved,\n lines_changed: linesChanged,\n words_added: wordsAdded,\n words_removed: wordsRemoved,\n meta_changes: fields.count,\n },\n hunks,\n meta: fields.changes,\n same:\n linesAdded === 0 && linesRemoved === 0 && fields.count === 0 && before.text === after.text,\n exact,\n truncated,\n steps: lineBudget.steps + wordBudget.steps,\n notes,\n };\n};\n\n// ── the diff of a stored document ───────────────────────────────────────────\n\n/** A version of a document for a diff: a capture id, or the version that was current at a time. */\nexport type VersionChoice = string | { readonly at: string | Date };\n\n/** These options choose the two versions of a diff. */\nexport interface DiffOptions {\n /**\n * This version is the old side: a capture id, or `{ at }`. The default is the version before\n * `to` with the same recipe and the same kind of capture (plain or rendered).\n */\n readonly from?: VersionChoice | undefined;\n /** This version is the new side: a capture id, or `{ at }`. The default is the newest version. */\n readonly to?: VersionChoice | undefined;\n /** These values change the limits of the diff (`DIFF_LIMITS`). */\n readonly limits?: Partial<DiffLimits> | undefined;\n}\n\n/** This is one side of a diff: the version that it compares. */\nexport interface DiffSide {\n /** This id is the capture of the version. A citation names it. */\n readonly capture: string;\n /** This time (ISO 8601) is the fetch time of the version. */\n readonly fetched_at: string;\n /** This value is the length of the text of the version. */\n readonly chars: number;\n readonly rendered: boolean;\n /** This value is true when the version is held back, so the diff does not show its text. */\n readonly held_back: boolean;\n /** This time (ISO 8601) is the `at` that chose the version, or null for a capture id or a default. */\n readonly at: string | null;\n}\n\n/** The result of a diff of two versions of a stored document. */\nexport interface DiffResult {\n readonly doc: string;\n readonly url: string | null;\n readonly from: DiffSide;\n readonly to: DiffSide;\n /**\n * This value is true when the two versions have the same text, title, URL and metadata. It is\n * null when a side is held back, because then the diff does not compare the texts.\n */\n readonly same: boolean | null;\n readonly summary: DiffSummary;\n readonly hunks: readonly DiffHunk[];\n readonly meta: readonly MetaChange[];\n /** This value is true when a side is held back. Then the result has no text and no title, and only the structural metadata. */\n readonly held_back: boolean;\n /** This value is true when the line diff is minimal and each changed line has its word diff. */\n readonly exact: boolean;\n /** This value is true when the result leaves out a part. The note tells which part. */\n readonly truncated: boolean;\n /** This value counts the steps of the diff. */\n readonly steps: number;\n readonly note: string | null;\n}\n\n/** This function gives the version of a choice, or throws an error that names the problem. */\nconst chosen = (\n runtime: CrawlRuntime,\n id: string,\n choice: VersionChoice,\n): { readonly version: VersionText; readonly at: string | null } => {\n if (typeof choice === \"string\") {\n const version = runtime.index.versionText(id, choice);\n if (version === undefined)\n throw new Error(`the document ${id} has no version from the capture ${choice}`);\n return { version, at: null };\n }\n if (!isRecord(choice) || choice.at === undefined)\n throw new RangeError(\"a version is a capture id, or an object with the time at\");\n const at = isoTime(\"at\", choice.at);\n const found = versionAtTime(runtime, id, at);\n if (found.version === undefined) {\n throw new Error(\n `the document ${id} has no version at ${at} or before${found.first === undefined ? \"\" : `: its first capture is from ${found.first}`}`,\n );\n }\n return { version: found.version, at };\n};\n\nconst sideOf = (version: VersionText, at: string | null, held: boolean): DiffSide => ({\n capture: version.capture,\n fetched_at: version.fetched_at,\n chars: version.chars,\n rendered: version.rendered,\n held_back: held,\n at,\n});\n\n/**\n * This function compares two versions of a stored document, and writes nothing. It applies the\n * rule for a held-back document. When the document or a version is held back, the diff compares\n * only the structural metadata, and it shows no text and no title.\n *\n * @beta\n */\nexport const diffDocument = async (\n runtime: CrawlRuntime,\n id: string,\n options: DiffOptions = {},\n): Promise<DiffResult> => {\n await Promise.resolve();\n const doc = runtime.index.get(id);\n if (doc === undefined)\n throw new Error(`no stored document ${id}: find one with find(), or fetch its page`);\n let to: { readonly version: VersionText; readonly at: string | null };\n if (options.to === undefined) {\n const newest = runtime.index.versions(id, { limit: 1 })[0];\n const version =\n newest === undefined ? undefined : runtime.index.versionText(id, newest.capture);\n if (version === undefined) throw new Error(`the document ${id} has no version`);\n to = { version, at: null };\n } else to = chosen(runtime, id, options.to);\n let from: { readonly version: VersionText; readonly at: string | null } | undefined;\n if (options.from === undefined) {\n // the version before, of the same recipe and kind: a render and a plain body are not a change\n const earlier = runtime.index\n .versions(id, { limit: 1000 })\n .find(\n (version) =>\n version.capture !== to.version.capture &&\n version.recipe === to.version.recipe &&\n version.rendered === to.version.rendered &&\n version.fetched_at <= to.version.fetched_at,\n );\n const version =\n earlier === undefined ? undefined : runtime.index.versionText(id, earlier.capture);\n if (version !== undefined) from = { version, at: null };\n } else from = chosen(runtime, id, options.from);\n const notes: string[] = [];\n if (from === undefined) {\n from = to;\n notes.push(`the document ${id} has no earlier version of the same kind to compare`);\n }\n const docHeld = isHeldBack(doc);\n const fromHeld = docHeld || isHeldBack(from.version);\n const toHeld = docHeld || isHeldBack(to.version);\n const held = fromHeld || toHeld;\n const fields = (version: VersionText): Record<string, unknown> =>\n held\n ? { kind: version.kind, url: version.url, meta: heldBackMeta(version.meta) }\n : { title: version.title, kind: version.kind, url: version.url, meta: version.meta };\n const diff = diffTexts(\n { text: held ? \"\" : from.version.text, fields: fields(from.version) },\n { text: held ? \"\" : to.version.text, fields: fields(to.version) },\n options.limits ?? {},\n );\n if (held) notes.unshift(HELD_BACK);\n notes.push(...diff.notes);\n return {\n doc: doc.doc,\n url: to.version.url ?? doc.url,\n from: sideOf(from.version, from.at, fromHeld),\n to: sideOf(to.version, to.at, toHeld),\n same: held ? null : diff.same,\n summary: diff.summary,\n hunks: diff.hunks,\n meta: diff.meta,\n held_back: held,\n exact: diff.exact,\n truncated: diff.truncated,\n steps: diff.steps,\n note: notes.length > 0 ? notes.join(\"; \") : null,\n };\n};\n\n/** This function gives the text of the word diff of a changed line: `[-removed-]` and `{+added+}` mark the words. */\nconst wordsText = (line: Extract<DiffLine, { op: \"changed\" }>): string =>\n line.words === null\n ? `[-${line.before}-]{+${line.after}+}`\n : line.words\n .map((part) =>\n part.op === \"same\"\n ? part.text\n : part.op === \"added\"\n ? `{+${part.text}+}`\n : `[-${part.text}-]`,\n )\n .join(\"\");\n\n/**\n * This function gives the text of a diff for a person or an assistant. The text has the counts, the\n * hunks as a unified diff, and the changes of the metadata. A changed line marks its words with `[-removed-]`\n * and `{+added+}`. The text holds the text of the pages, so the MCP server puts it in an envelope.\n *\n * @beta\n */\nexport const formatDiff = (diff: Pick<DiffResult, \"summary\" | \"hunks\" | \"meta\">): string => {\n const { summary } = diff;\n const lines: string[] = [\n `the text: ${String(summary.lines_added)} lines added, ${String(summary.lines_removed)} removed (${String(summary.lines_changed)} changed), ${String(summary.words_added)} words added, ${String(summary.words_removed)} removed`,\n ];\n for (const hunk of diff.hunks) {\n lines.push(\n `@@ -${String(hunk.from_line)},${String(hunk.from_count)} +${String(hunk.to_line)},${String(hunk.to_count)} @@`,\n );\n for (const line of hunk.lines) {\n if (line.op === \"changed\") lines.push(`~ ${wordsText(line)}`);\n else lines.push(`${line.op === \"same\" ? \" \" : line.op === \"added\" ? \"+\" : \"-\"} ${line.text}`);\n }\n }\n lines.push(`the metadata: ${String(summary.meta_changes)} changes`);\n for (const change of diff.meta) {\n if (change.change === \"added\") lines.push(`+ ${change.path}: ${change.after ?? \"\"}`);\n else if (change.change === \"removed\") lines.push(`- ${change.path}: ${change.before ?? \"\"}`);\n else lines.push(`~ ${change.path}: ${change.before ?? \"\"} -> ${change.after ?? \"\"}`);\n }\n return lines.join(\"\\n\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,cAAc;;CAEzB,UAAU;;CAEV,UAAU;;CAEV,UAAU;;CAEV,cAAc;;CAEd,cAAc;;CAEd,SAAS;;CAET,cAAc;;CAEd,gBAAgB;;CAEhB,cAAc;;CAEd,eAAe;AACjB;;;;;;AA0GA,MAAa,cACX,GACA,GACA,WACsD;CACtD,MAAM,IAAI,EAAE;CACZ,MAAM,IAAI,EAAE;CACZ,IAAI,OAAO;CACX,OAAO,OAAO,KAAK,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,QAAQ;CAC5D,IAAI,OAAO;CACX,IAAI,OAAO;CACX,OAAO,OAAO,QAAQ,OAAO,QAAQ,EAAE,OAAO,OAAO,EAAE,OAAO,IAAI;EAChE,QAAQ;EACR,QAAQ;CACV;CACA,OAAO,SAAS,QAAQ,IAAI,QAAQ;CACpC,MAAM,WAAuC,CAAC;CAC9C,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,OAAO;CACtB,IAAI,QAAQ;CACZ,SAAS,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;CAC3B,IAAI,UAAU,KAAK,WAAW,GAC5B,SAAS,KAAK,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;MAChC;EACL,MAAM,MAAM,MAAsB,EAAE,OAAO;EAC3C,MAAM,MAAM,MAAsB,EAAE,OAAO;EAC3C,MAAM,MAAM,QAAQ;EACpB,MAAM,SAAS,MAAM;EACrB,MAAM,IAAI,IAAI,WAAW,IAAI,MAAM,CAAC;EAEpC,MAAM,QAAsB,CAAC;EAC7B,IAAI;EACJ,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AM,KAAK,KAAK,OAAO,KAAK,IAAI,OAAO,SAAS,IAAI;MAC9E,IAAI,OAAO,WAAW,WAAW,MAAM,KAAK,KAAK,OAAO,KAAK,IAAI,OAAO,UAAU,IAAI;MACtF,MAAM,KAAK,KAAK,OAAO,KAAK,IAAI,OAAO,UAAU,GAAG,MAAM,OAAO,SAAS,IAAI;CAErF,OAAO,MAAM,KAAK,IAAI;AACxB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
2
|
-
import { C as fold, c as isHeldBack, d as recordOverride, l as isoTime, m as versionAtTime, n as HELD_BACK, v as archivedNote, w as foldText, y as archivedOf } from "./runtime-
|
|
2
|
+
import { C as fold, c as isHeldBack, d as recordOverride, l as isoTime, m as versionAtTime, n as HELD_BACK, v as archivedNote, w as foldText, y as archivedOf } from "./runtime-j2NpXEiN.mjs";
|
|
3
3
|
import { n as canonicalUrl } from "./urls-BHFeSyEK.mjs";
|
|
4
|
-
import { r as typesOf } from "./html-
|
|
4
|
+
import { r as typesOf } from "./html-DzobO0fy.mjs";
|
|
5
5
|
//#region src/extract.ts
|
|
6
6
|
var extract_exports = /* @__PURE__ */ __exportAll({
|
|
7
7
|
FIELD_KINDS: () => FIELD_KINDS,
|
|
@@ -1798,4 +1798,4 @@ const extractDocument = async (runtime, id, fields, options = {}) => {
|
|
|
1798
1798
|
//#endregion
|
|
1799
1799
|
export { extract_exports as i, checkFields as n, extractDocument as r, FIELD_KINDS as t };
|
|
1800
1800
|
|
|
1801
|
-
//# sourceMappingURL=extract-
|
|
1801
|
+
//# sourceMappingURL=extract-BgcEkiQr.mjs.map
|