document-rest 1.4.6 → 1.4.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/bin.js CHANGED
@@ -5,25 +5,27 @@ import { OdbReportNotSpecifiedError, OdmUnresolvedSectionError } from "documents
5
5
  import { z } from "zod";
6
6
  //#region src/server.ts
7
7
  const OPERATIONS_BY_NAME = new Map(DOCUMENT_OPERATIONS.map((operation) => [operation.name, operation]));
8
- const ERROR_MAPPERS = /* @__PURE__ */ new Map([["odb_render_report", (error) => {
9
- if (!(error instanceof OdbReportNotSpecifiedError)) return void 0;
10
- return {
11
- status: 400,
12
- body: {
13
- error: error.message,
14
- availableReports: error.availableReports
15
- }
16
- };
17
- }], ["odm_to_pdf", (error) => {
18
- if (!(error instanceof OdmUnresolvedSectionError)) return void 0;
19
- return {
20
- status: 400,
21
- body: {
22
- error: `${error.message} Pass chaptersDir containing these files, or an explicit chapters override, for each href.`,
23
- hrefs: error.hrefs
24
- }
25
- };
26
- }]]);
8
+ function buildErrorMappers() {
9
+ return /* @__PURE__ */ new Map([["odb_render_report", (error) => {
10
+ if (!(error instanceof OdbReportNotSpecifiedError)) return void 0;
11
+ return {
12
+ status: 400,
13
+ body: {
14
+ error: error.message,
15
+ availableReports: error.availableReports
16
+ }
17
+ };
18
+ }], ["odm_to_pdf", (error) => {
19
+ if (!(error instanceof OdmUnresolvedSectionError)) return void 0;
20
+ return {
21
+ status: 400,
22
+ body: {
23
+ error: `${error.message} Pass chaptersDir containing these files, or an explicit chapters override, for each href.`,
24
+ hrefs: error.hrefs
25
+ }
26
+ };
27
+ }]]);
28
+ }
27
29
  async function readJsonBody(req) {
28
30
  const chunks = [];
29
31
  for await (const chunk of req) chunks.push(chunk);
@@ -36,9 +38,9 @@ function sendJson(res, status, body) {
36
38
  res.writeHead(status, { "content-type": "application/json" });
37
39
  res.end(text);
38
40
  }
39
- function abortSignalFor(req) {
41
+ function abortSignalFor(res) {
40
42
  const controller = new AbortController();
41
- req.once("close", () => {
43
+ res.once("close", () => {
42
44
  controller.abort();
43
45
  });
44
46
  return controller.signal;
@@ -60,9 +62,9 @@ async function handleOperationRequest(req, res, operation) {
60
62
  return;
61
63
  }
62
64
  try {
63
- sendJson(res, 200, { result: await operation.run(parsed.data, { signal: abortSignalFor(req) }) });
65
+ sendJson(res, 200, { result: await operation.run(parsed.data, { signal: abortSignalFor(res) }) });
64
66
  } catch (error) {
65
- const mapped = ERROR_MAPPERS.get(operation.name)?.(error);
67
+ const mapped = buildErrorMappers().get(operation.name)?.(error);
66
68
  if (mapped !== void 0) {
67
69
  sendJson(res, mapped.status, mapped.body);
68
70
  return;
@@ -92,7 +94,7 @@ function createRestServer() {
92
94
  sendJson(res, 200, listOperations());
93
95
  return;
94
96
  }
95
- const name = url.pathname.replace(/^\//, "");
97
+ const name = url.pathname.slice(1);
96
98
  const operation = OPERATIONS_BY_NAME.get(name);
97
99
  if (operation === void 0) {
98
100
  sendJson(res, 404, { error: `No operation named "${name}". GET / lists every available operation.` });
package/dist/index.cjs CHANGED
@@ -5,25 +5,27 @@ let documents_js = require("documents.js");
5
5
  let zod = require("zod");
6
6
  //#region src/server.ts
7
7
  const OPERATIONS_BY_NAME = new Map(document_operations.DOCUMENT_OPERATIONS.map((operation) => [operation.name, operation]));
8
- const ERROR_MAPPERS = /* @__PURE__ */ new Map([["odb_render_report", (error) => {
9
- if (!(error instanceof documents_js.OdbReportNotSpecifiedError)) return void 0;
10
- return {
11
- status: 400,
12
- body: {
13
- error: error.message,
14
- availableReports: error.availableReports
15
- }
16
- };
17
- }], ["odm_to_pdf", (error) => {
18
- if (!(error instanceof documents_js.OdmUnresolvedSectionError)) return void 0;
19
- return {
20
- status: 400,
21
- body: {
22
- error: `${error.message} Pass chaptersDir containing these files, or an explicit chapters override, for each href.`,
23
- hrefs: error.hrefs
24
- }
25
- };
26
- }]]);
8
+ function buildErrorMappers() {
9
+ return /* @__PURE__ */ new Map([["odb_render_report", (error) => {
10
+ if (!(error instanceof documents_js.OdbReportNotSpecifiedError)) return void 0;
11
+ return {
12
+ status: 400,
13
+ body: {
14
+ error: error.message,
15
+ availableReports: error.availableReports
16
+ }
17
+ };
18
+ }], ["odm_to_pdf", (error) => {
19
+ if (!(error instanceof documents_js.OdmUnresolvedSectionError)) return void 0;
20
+ return {
21
+ status: 400,
22
+ body: {
23
+ error: `${error.message} Pass chaptersDir containing these files, or an explicit chapters override, for each href.`,
24
+ hrefs: error.hrefs
25
+ }
26
+ };
27
+ }]]);
28
+ }
27
29
  async function readJsonBody(req) {
28
30
  const chunks = [];
29
31
  for await (const chunk of req) chunks.push(chunk);
@@ -36,9 +38,9 @@ function sendJson(res, status, body) {
36
38
  res.writeHead(status, { "content-type": "application/json" });
37
39
  res.end(text);
38
40
  }
39
- function abortSignalFor(req) {
41
+ function abortSignalFor(res) {
40
42
  const controller = new AbortController();
41
- req.once("close", () => {
43
+ res.once("close", () => {
42
44
  controller.abort();
43
45
  });
44
46
  return controller.signal;
@@ -60,9 +62,9 @@ async function handleOperationRequest(req, res, operation) {
60
62
  return;
61
63
  }
62
64
  try {
63
- sendJson(res, 200, { result: await operation.run(parsed.data, { signal: abortSignalFor(req) }) });
65
+ sendJson(res, 200, { result: await operation.run(parsed.data, { signal: abortSignalFor(res) }) });
64
66
  } catch (error) {
65
- const mapped = ERROR_MAPPERS.get(operation.name)?.(error);
67
+ const mapped = buildErrorMappers().get(operation.name)?.(error);
66
68
  if (mapped !== void 0) {
67
69
  sendJson(res, mapped.status, mapped.body);
68
70
  return;
@@ -92,7 +94,7 @@ function createRestServer() {
92
94
  sendJson(res, 200, listOperations());
93
95
  return;
94
96
  }
95
- const name = url.pathname.replace(/^\//, "");
97
+ const name = url.pathname.slice(1);
96
98
  const operation = OPERATIONS_BY_NAME.get(name);
97
99
  if (operation === void 0) {
98
100
  sendJson(res, 404, { error: `No operation named "${name}". GET / lists every available operation.` });
package/dist/index.js CHANGED
@@ -4,25 +4,27 @@ import { OdbReportNotSpecifiedError, OdmUnresolvedSectionError } from "documents
4
4
  import { z } from "zod";
5
5
  //#region src/server.ts
6
6
  const OPERATIONS_BY_NAME = new Map(DOCUMENT_OPERATIONS.map((operation) => [operation.name, operation]));
7
- const ERROR_MAPPERS = /* @__PURE__ */ new Map([["odb_render_report", (error) => {
8
- if (!(error instanceof OdbReportNotSpecifiedError)) return void 0;
9
- return {
10
- status: 400,
11
- body: {
12
- error: error.message,
13
- availableReports: error.availableReports
14
- }
15
- };
16
- }], ["odm_to_pdf", (error) => {
17
- if (!(error instanceof OdmUnresolvedSectionError)) return void 0;
18
- return {
19
- status: 400,
20
- body: {
21
- error: `${error.message} Pass chaptersDir containing these files, or an explicit chapters override, for each href.`,
22
- hrefs: error.hrefs
23
- }
24
- };
25
- }]]);
7
+ function buildErrorMappers() {
8
+ return /* @__PURE__ */ new Map([["odb_render_report", (error) => {
9
+ if (!(error instanceof OdbReportNotSpecifiedError)) return void 0;
10
+ return {
11
+ status: 400,
12
+ body: {
13
+ error: error.message,
14
+ availableReports: error.availableReports
15
+ }
16
+ };
17
+ }], ["odm_to_pdf", (error) => {
18
+ if (!(error instanceof OdmUnresolvedSectionError)) return void 0;
19
+ return {
20
+ status: 400,
21
+ body: {
22
+ error: `${error.message} Pass chaptersDir containing these files, or an explicit chapters override, for each href.`,
23
+ hrefs: error.hrefs
24
+ }
25
+ };
26
+ }]]);
27
+ }
26
28
  async function readJsonBody(req) {
27
29
  const chunks = [];
28
30
  for await (const chunk of req) chunks.push(chunk);
@@ -35,9 +37,9 @@ function sendJson(res, status, body) {
35
37
  res.writeHead(status, { "content-type": "application/json" });
36
38
  res.end(text);
37
39
  }
38
- function abortSignalFor(req) {
40
+ function abortSignalFor(res) {
39
41
  const controller = new AbortController();
40
- req.once("close", () => {
42
+ res.once("close", () => {
41
43
  controller.abort();
42
44
  });
43
45
  return controller.signal;
@@ -59,9 +61,9 @@ async function handleOperationRequest(req, res, operation) {
59
61
  return;
60
62
  }
61
63
  try {
62
- sendJson(res, 200, { result: await operation.run(parsed.data, { signal: abortSignalFor(req) }) });
64
+ sendJson(res, 200, { result: await operation.run(parsed.data, { signal: abortSignalFor(res) }) });
63
65
  } catch (error) {
64
- const mapped = ERROR_MAPPERS.get(operation.name)?.(error);
66
+ const mapped = buildErrorMappers().get(operation.name)?.(error);
65
67
  if (mapped !== void 0) {
66
68
  sendJson(res, mapped.status, mapped.body);
67
69
  return;
@@ -91,7 +93,7 @@ function createRestServer() {
91
93
  sendJson(res, 200, listOperations());
92
94
  return;
93
95
  }
94
- const name = url.pathname.replace(/^\//, "");
96
+ const name = url.pathname.slice(1);
95
97
  const operation = OPERATIONS_BY_NAME.get(name);
96
98
  if (operation === void 0) {
97
99
  sendJson(res, 404, { error: `No operation named "${name}". GET / lists every available operation.` });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-rest",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "A plain REST API server exposing document-operations' conversion, editing, inspection, and .odb operations as JSON-over-HTTP endpoints -- one POST route per operation, for a caller with no MCP client and no Node runtime of their own.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -87,8 +87,8 @@
87
87
  "license": "MIT",
88
88
  "packageManager": "pnpm@11.6.0",
89
89
  "dependencies": {
90
- "document-operations": "1.1.6",
91
- "documents.js": "7.20.6",
90
+ "document-operations": "1.1.7",
91
+ "documents.js": "7.20.7",
92
92
  "zod": "4.4.3"
93
93
  },
94
94
  "devDependencies": {
@@ -97,7 +97,7 @@
97
97
  "@vitest/coverage-v8": "4.1.11",
98
98
  "eslint": "10.8.1",
99
99
  "husky": "9.1.7",
100
- "odf.js": "7.25.2",
100
+ "odf.js": "7.25.3",
101
101
  "publint": "0.3.22",
102
102
  "semantic-release": "25.0.9",
103
103
  "tsdown": "0.22.14",