doc-model.js 1.5.3 → 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
@@ -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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-model.js",
3
- "version": "1.5.3",
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
  }