doc-model.js 1.5.2 → 1.6.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/README.md CHANGED
@@ -10,7 +10,7 @@ Both `ooxml.js` and `documents.js` independently arrived at the same content voc
10
10
 
11
11
  It contains only [Zod](https://zod.dev) schemas, their inferred types, and a handful of trivial schema-attached helpers (hex-colour conversion, a recursive structural type guard for the mutually-recursive table/block/embedded-object types). There is no XML, ZIP, PDF, or other binary handling here, and no `zod` dependency other than `zod` itself.
12
12
 
13
- The GitHub repository is [`ExaDev/document-schema.js`](https://github.com/ExaDev/document-schema.js), matching the published npm package name; `document-content-model` (the repository's original name, kept resolving), `doc-model.js`, `doc-schema.js`, `document-schema`, and `document-model.js` republish the identical build as aliases on npmjs.org, alongside a scoped `@exadev/document-content-model` alias on GitHub Packages. A CI matrix job (`publish-aliases` in `.github/workflows/ci.yml`) rewrites `package.json`'s `name` and registry via `npm pkg set` after each release and publishes under each alias in turn -- install whichever name you already depend on.
13
+ The GitHub repository is [`ExaDev/document-schema.js`](https://github.com/ExaDev/document-schema.js), matching the published npm package name.
14
14
 
15
15
  ## Usage
16
16
 
@@ -22,6 +22,26 @@ const layout = LayoutDocumentSchema.parse(somePageLayoutValue);
22
22
  const pkg = DocumentPackageSchema.parse({ formatVersion: 1, content, layout });
23
23
  ```
24
24
 
25
+ ## JSON Schema
26
+
27
+ Alongside the Zod schemas/types above, the package publishes three plain [JSON Schema](https://json-schema.org) files -- generated from the same Zod definitions via [`z.toJSONSchema()`](https://zod.dev/json-schema) at build time (`scripts/generate-json-schemas.mjs`) -- for non-TypeScript consumers that want to validate against or generate types from these shapes without depending on Zod at all:
28
+
29
+ ```ts
30
+ const documentPackageSchema = require('document-schema.js/schemas/document-package.schema.json');
31
+ // or, from a bundler/toolchain that supports JSON module imports:
32
+ import documentPackageSchema from 'document-schema.js/schemas/document-package.schema.json' with { type: 'json' };
33
+ ```
34
+
35
+ or from any language/tool that can read a file out of `node_modules`:
36
+
37
+ ```
38
+ node_modules/document-schema.js/schemas/document-package.schema.json
39
+ node_modules/document-schema.js/schemas/content-document.schema.json
40
+ node_modules/document-schema.js/schemas/layout-document.schema.json
41
+ ```
42
+
43
+ Each file's `$id` is a commit-SHA-pinned `https://raw.githubusercontent.com/ExaDev/document-schema.js/<sha>/schemas/<file>` URL -- immutable, and cross-referenced between the three files via real `$ref`s (e.g. `document-package.schema.json`'s `content`/`layout` properties `$ref` the other two files directly), so a JSON Schema validator that resolves `$ref`s over HTTP (or against local copies of all three files) can validate a whole `DocumentPackage` value. `content-document.schema.json` additionally carries a `$defs` block for the recursive paragraph/table/embedded-object block model, which Zod's own converter can't express directly (see that script's own top-of-file comment for why).
44
+
25
45
  ## Used by
26
46
 
27
47
  - [ooxml.js](https://github.com/ExaDev/ooxml.js) — its `readDocx`/`readPptx`/`readXlsxContent` return `ContentSection[]`/`ContentSlide[]`/spreadsheet `ContentSheet[]` typed against this package's own schemas, not a locally-defined lookalike.
@@ -29,7 +49,7 @@ const pkg = DocumentPackageSchema.parse({ formatVersion: 1, content, layout });
29
49
  - [documents.js](https://github.com/ExaDev/documents.js) — the primary consumer of both `ContentDocument` and `LayoutDocument`, which it converts between via its layout engines and its `pdf-codec` dependency, and of `DocumentPackage` as the `onDocument` side-channel value its conversion functions hand back.
30
50
  - [pdf-codec](https://github.com/ExaDev/pdf-codec) — the hand-written PDF codec extracted from `documents.js`: `readPdf`/`writePdf` and its own `pdfCodec` z.codec() pair operate entirely in terms of this package's `LayoutDocument` (plus the item kinds it's built from -- `LayoutItem`/`LayoutText`/`LayoutImage`/`LayoutRect`/`LayoutEllipse`/`LayoutLink`/`LayoutPath`/`LayoutSubpath`/`LayoutPathSegment`/`LayoutPage`/`LayoutImageAsset`/`LayoutMetadata`), `Color`/`LayoutFont` (aliased `LayoutColor`/`LayoutFont` at its own call sites), and `LAYOUT_FORMAT_VERSION`/`COLOR_BLACK`/`LayoutDocumentSchema` -- it never redeclares any of these itself, unlike its own `MathBox`/`PositionedFormula` mirror of `documents.js`'s MathML types (a deliberate, narrower exception -- see pdf-codec's own README).
31
51
 
32
- None of these four packages depend on each other for this vocabulary — each depends on `document-schema.js` (or one of its aliases above) directly, which is the whole point: one schema, not four independently-maintained, drift-prone copies.
52
+ None of these four packages depend on each other for this vocabulary — each depends on `document-schema.js` directly, which is the whole point: one schema, not four independently-maintained, drift-prone copies.
33
53
 
34
54
  ## License
35
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-model.js",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "The canonical, format-agnostic content and layout schemas shared by ooxml.js, odf.js, and documents.js -- pure Zod schemas, no behaviour.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -19,13 +19,17 @@
19
19
  },
20
20
  "import": "./dist/index.js",
21
21
  "require": "./dist/index.cjs"
22
- }
22
+ },
23
+ "./schemas/document-package.schema.json": "./schemas/document-package.schema.json",
24
+ "./schemas/content-document.schema.json": "./schemas/content-document.schema.json",
25
+ "./schemas/layout-document.schema.json": "./schemas/layout-document.schema.json"
23
26
  },
24
27
  "main": "./dist/index.cjs",
25
28
  "module": "./dist/index.js",
26
29
  "types": "./dist/index.d.ts",
27
30
  "files": [
28
- "dist"
31
+ "dist",
32
+ "schemas"
29
33
  ],
30
34
  "publishConfig": {
31
35
  "access": "public",
@@ -73,13 +77,13 @@
73
77
  "vitest": "^4.1.10"
74
78
  },
75
79
  "scripts": {
76
- "build": "tsdown",
80
+ "build": "tsdown && node scripts/generate-json-schemas.mjs",
77
81
  "lint": "eslint . --max-warnings 0",
78
82
  "typecheck": "tsc --noEmit",
79
83
  "test": "vitest run --project unit",
80
84
  "test:watch": "vitest --project unit",
81
85
  "test:coverage": "vitest run --project unit --coverage",
82
- "test:smoke": "tsdown && vitest run --project smoke",
86
+ "test:smoke": "pnpm run build && vitest run --project smoke",
83
87
  "release": "semantic-release"
84
88
  }
85
89
  }