document-operations 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -178,6 +178,7 @@ const convertDocumentOperation = defineOperation({
178
178
  async run({ source, targetFormat, output, fonts, onSubstitutionDiagnostics, images }, context) {
179
179
  const signal = context?.signal;
180
180
  const { bytes, format } = await resolveDocumentInput(source, { signal });
181
+ const wantsFontSubstitutionDiagnostics = onSubstitutionDiagnostics === true;
181
182
  const fontSubstitutions = [];
182
183
  const conversionSignal = signal ?? new AbortController().signal;
183
184
  const result = await converter.convert({
@@ -194,7 +195,7 @@ const convertDocumentOperation = defineOperation({
194
195
  italic: font.italic,
195
196
  bytes: (0, documents_js.base64ToBytes)(font.bytesBase64)
196
197
  })),
197
- onFontSubstitution: onSubstitutionDiagnostics === true ? (substitution) => fontSubstitutions.push(substitution) : void 0,
198
+ onFontSubstitution: wantsFontSubstitutionDiagnostics ? (substitution) => fontSubstitutions.push(substitution) : void 0,
198
199
  images: images === void 0 ? void 0 : (destination) => {
199
200
  const base64 = images[destination];
200
201
  return base64 === void 0 ? void 0 : { bytes: (0, documents_js.base64ToBytes)(base64) };
@@ -205,7 +206,7 @@ const convertDocumentOperation = defineOperation({
205
206
  targetFormat: result.document.format,
206
207
  output: resolvedOutput,
207
208
  diagnostics: [...result.diagnostics],
208
- ...onSubstitutionDiagnostics === true ? { fontSubstitutions: [...fontSubstitutions] } : {}
209
+ ...wantsFontSubstitutionDiagnostics ? { fontSubstitutions: [...fontSubstitutions] } : {}
209
210
  };
210
211
  }
211
212
  });
@@ -563,7 +564,7 @@ const fromPackageOperation = defineOperation({
563
564
  result = (0, documents_js.documentFromJson)(parsed);
564
565
  } catch (error) {
565
566
  if (error instanceof documents_js.UnrecognizedDocumentSchemaError) throw new Error("'source' has no recognised $schema -- only a file carrying a real DocumentTree (e.g. written by a caller's own --dump-package-equivalent step) can be read back by this operation", { cause: error });
566
- if (error instanceof zod.z.ZodError) throw new Error(`'source' failed ${(0, documents_js.documentSchemaKindOf)(parsed) ?? "document schema"} validation: ${error.message}`, { cause: error });
567
+ if (error instanceof zod.z.ZodError) throw new Error(`'source' failed ${(0, documents_js.documentSchemaKindOf)(parsed)} validation: ${error.message}`, { cause: error });
567
568
  throw error;
568
569
  }
569
570
  if (result.kind !== "DocumentTree") throw new Error(`'source' is a ${result.kind}, not a DocumentTree -- only a file carrying a real DocumentTree (e.g. written by a caller's own --dump-package-equivalent step) can be read back by this operation`);
@@ -781,20 +782,10 @@ const odbRenderReportOperation = defineOperation({
781
782
  const pkg = (0, documents_js.decodeOdbPackage)(inputBytes);
782
783
  const content = (0, documents_js.readOdbReportContent)(pkg, { report });
783
784
  const mathDiagnostics = [];
784
- const recordMathDiagnostic = (diagnostic, diagnosticContext) => {
785
- mathDiagnostics.push({
786
- kind: diagnostic.kind,
787
- detail: diagnostic.detail,
788
- sourcePath: diagnosticContext.sourcePath
789
- });
790
- };
791
785
  const fontSubstitutions = [];
792
786
  const charSubstitutions = [];
793
787
  let bytes;
794
- if (targetFormat === "docx") bytes = (0, documents_js.odbReportToDocx)(content, {
795
- signal,
796
- onMathDiagnostic: recordMathDiagnostic
797
- });
788
+ if (targetFormat === "docx") bytes = (0, documents_js.odbReportToDocx)(content, { signal });
798
789
  else if (targetFormat === "odt") bytes = (0, documents_js.odbReportToOdt)(content, { signal });
799
790
  else bytes = (0, documents_js.odbReportToPdf)(content, {
800
791
  signal,
@@ -804,15 +795,13 @@ const odbRenderReportOperation = defineOperation({
804
795
  italic: font.italic,
805
796
  bytes: (0, documents_js.base64ToBytes)(font.bytesBase64)
806
797
  })),
807
- onFontSubstitution: (substitution) => fontSubstitutions.push(substitution),
808
798
  onSubstitution: (substitution, substitutionContext) => {
809
799
  charSubstitutions.push({
810
800
  from: substitution.from,
811
801
  to: substitution.to,
812
802
  pageIndex: substitutionContext.pageIndex
813
803
  });
814
- },
815
- onMathDiagnostic: recordMathDiagnostic
804
+ }
816
805
  });
817
806
  return {
818
807
  ...await resolveDocumentOutput(bytes, output ?? {}),
package/dist/index.d.cts CHANGED
@@ -418,8 +418,8 @@ declare const ConvertDocumentOutputSchema: z.ZodObject<{
418
418
  }, z.core.$strip>]>;
419
419
  diagnostics: z.ZodArray<z.ZodObject<{
420
420
  severity: z.ZodEnum<{
421
- warning: "warning";
422
421
  info: "info";
422
+ warning: "warning";
423
423
  }>;
424
424
  code: z.ZodString;
425
425
  message: z.ZodString;
@@ -573,8 +573,8 @@ declare const convertDocumentOperation: {
573
573
  }, z.core.$strip>]>;
574
574
  diagnostics: z.ZodArray<z.ZodObject<{
575
575
  severity: z.ZodEnum<{
576
- warning: "warning";
577
576
  info: "info";
577
+ warning: "warning";
578
578
  }>;
579
579
  code: z.ZodString;
580
580
  message: z.ZodString;
@@ -621,7 +621,7 @@ declare const convertDocumentOperation: {
621
621
  large?: true | undefined;
622
622
  };
623
623
  diagnostics: {
624
- severity: "warning" | "info";
624
+ severity: "info" | "warning";
625
625
  code: string;
626
626
  message: string;
627
627
  pageIndex?: number | undefined;
package/dist/index.d.ts CHANGED
@@ -418,8 +418,8 @@ declare const ConvertDocumentOutputSchema: z.ZodObject<{
418
418
  }, z.core.$strip>]>;
419
419
  diagnostics: z.ZodArray<z.ZodObject<{
420
420
  severity: z.ZodEnum<{
421
- warning: "warning";
422
421
  info: "info";
422
+ warning: "warning";
423
423
  }>;
424
424
  code: z.ZodString;
425
425
  message: z.ZodString;
@@ -573,8 +573,8 @@ declare const convertDocumentOperation: {
573
573
  }, z.core.$strip>]>;
574
574
  diagnostics: z.ZodArray<z.ZodObject<{
575
575
  severity: z.ZodEnum<{
576
- warning: "warning";
577
576
  info: "info";
577
+ warning: "warning";
578
578
  }>;
579
579
  code: z.ZodString;
580
580
  message: z.ZodString;
@@ -621,7 +621,7 @@ declare const convertDocumentOperation: {
621
621
  large?: true | undefined;
622
622
  };
623
623
  diagnostics: {
624
- severity: "warning" | "info";
624
+ severity: "info" | "warning";
625
625
  code: string;
626
626
  message: string;
627
627
  pageIndex?: number | undefined;
package/dist/index.js CHANGED
@@ -177,6 +177,7 @@ const convertDocumentOperation = defineOperation({
177
177
  async run({ source, targetFormat, output, fonts, onSubstitutionDiagnostics, images }, context) {
178
178
  const signal = context?.signal;
179
179
  const { bytes, format } = await resolveDocumentInput(source, { signal });
180
+ const wantsFontSubstitutionDiagnostics = onSubstitutionDiagnostics === true;
180
181
  const fontSubstitutions = [];
181
182
  const conversionSignal = signal ?? new AbortController().signal;
182
183
  const result = await converter.convert({
@@ -193,7 +194,7 @@ const convertDocumentOperation = defineOperation({
193
194
  italic: font.italic,
194
195
  bytes: base64ToBytes(font.bytesBase64)
195
196
  })),
196
- onFontSubstitution: onSubstitutionDiagnostics === true ? (substitution) => fontSubstitutions.push(substitution) : void 0,
197
+ onFontSubstitution: wantsFontSubstitutionDiagnostics ? (substitution) => fontSubstitutions.push(substitution) : void 0,
197
198
  images: images === void 0 ? void 0 : (destination) => {
198
199
  const base64 = images[destination];
199
200
  return base64 === void 0 ? void 0 : { bytes: base64ToBytes(base64) };
@@ -204,7 +205,7 @@ const convertDocumentOperation = defineOperation({
204
205
  targetFormat: result.document.format,
205
206
  output: resolvedOutput,
206
207
  diagnostics: [...result.diagnostics],
207
- ...onSubstitutionDiagnostics === true ? { fontSubstitutions: [...fontSubstitutions] } : {}
208
+ ...wantsFontSubstitutionDiagnostics ? { fontSubstitutions: [...fontSubstitutions] } : {}
208
209
  };
209
210
  }
210
211
  });
@@ -562,7 +563,7 @@ const fromPackageOperation = defineOperation({
562
563
  result = documentFromJson(parsed);
563
564
  } catch (error) {
564
565
  if (error instanceof UnrecognizedDocumentSchemaError) throw new Error("'source' has no recognised $schema -- only a file carrying a real DocumentTree (e.g. written by a caller's own --dump-package-equivalent step) can be read back by this operation", { cause: error });
565
- if (error instanceof z.ZodError) throw new Error(`'source' failed ${documentSchemaKindOf(parsed) ?? "document schema"} validation: ${error.message}`, { cause: error });
566
+ if (error instanceof z.ZodError) throw new Error(`'source' failed ${documentSchemaKindOf(parsed)} validation: ${error.message}`, { cause: error });
566
567
  throw error;
567
568
  }
568
569
  if (result.kind !== "DocumentTree") throw new Error(`'source' is a ${result.kind}, not a DocumentTree -- only a file carrying a real DocumentTree (e.g. written by a caller's own --dump-package-equivalent step) can be read back by this operation`);
@@ -780,20 +781,10 @@ const odbRenderReportOperation = defineOperation({
780
781
  const pkg = decodeOdbPackage(inputBytes);
781
782
  const content = readOdbReportContent(pkg, { report });
782
783
  const mathDiagnostics = [];
783
- const recordMathDiagnostic = (diagnostic, diagnosticContext) => {
784
- mathDiagnostics.push({
785
- kind: diagnostic.kind,
786
- detail: diagnostic.detail,
787
- sourcePath: diagnosticContext.sourcePath
788
- });
789
- };
790
784
  const fontSubstitutions = [];
791
785
  const charSubstitutions = [];
792
786
  let bytes;
793
- if (targetFormat === "docx") bytes = odbReportToDocx(content, {
794
- signal,
795
- onMathDiagnostic: recordMathDiagnostic
796
- });
787
+ if (targetFormat === "docx") bytes = odbReportToDocx(content, { signal });
797
788
  else if (targetFormat === "odt") bytes = odbReportToOdt(content, { signal });
798
789
  else bytes = odbReportToPdf(content, {
799
790
  signal,
@@ -803,15 +794,13 @@ const odbRenderReportOperation = defineOperation({
803
794
  italic: font.italic,
804
795
  bytes: base64ToBytes(font.bytesBase64)
805
796
  })),
806
- onFontSubstitution: (substitution) => fontSubstitutions.push(substitution),
807
797
  onSubstitution: (substitution, substitutionContext) => {
808
798
  charSubstitutions.push({
809
799
  from: substitution.from,
810
800
  to: substitution.to,
811
801
  pageIndex: substitutionContext.pageIndex
812
802
  });
813
- },
814
- onMathDiagnostic: recordMathDiagnostic
803
+ }
815
804
  });
816
805
  return {
817
806
  ...await resolveDocumentOutput(bytes, output ?? {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-operations",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "The canonical set of document-conversion, editing, inspection, and .odb operations documents.js exposes -- one Zod input/output schema and one transport-agnostic run() function per operation, shared by document-mcp, document-cli, and a REST API server rather than each defining its own copy.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -82,10 +82,10 @@
82
82
  "license": "MIT",
83
83
  "packageManager": "pnpm@11.6.0",
84
84
  "dependencies": {
85
- "document-compute.js": "1.5.9",
86
- "document-outline.js": "3.7.3",
87
- "document-schema.js": "7.11.1",
88
- "documents.js": "7.20.6",
85
+ "document-compute.js": "1.5.10",
86
+ "document-outline.js": "3.8.0",
87
+ "document-schema.js": "7.11.2",
88
+ "documents.js": "7.20.7",
89
89
  "zod": "4.4.3"
90
90
  },
91
91
  "devDependencies": {
@@ -98,7 +98,7 @@
98
98
  "@vitest/coverage-v8": "4.1.11",
99
99
  "eslint": "10.8.1",
100
100
  "husky": "9.1.7",
101
- "odf.js": "7.25.2",
101
+ "odf.js": "7.25.3",
102
102
  "publint": "0.3.22",
103
103
  "semantic-release": "25.0.9",
104
104
  "tsdown": "0.22.14",