document-schema.js 1.5.3 → 1.6.1

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 `https://cdn.jsdelivr.net/npm/document-schema.js@<version>/schemas/<file>` URL, pinned to the exact npm version that generated it -- immutable (jsdelivr serves each version's own published tarball contents forever, with an immutable cache header) and genuinely live the moment that version is published, unlike a commit-SHA-pinned raw GitHub URL would be: a gitignored, generated file can never actually be committed at the commit whose SHA it would need to embed, since committing it changes the tree and thus the hash. The three files are cross-referenced via real `$ref`s (e.g. `document-package.schema.json`'s `content`/`layout` properties `$ref` the other two files directly, at that same version), 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/dist/index.d.cts CHANGED
@@ -46,12 +46,12 @@ type Alignment = z.infer<typeof AlignmentSchema>;
46
46
  declare const LayoutFontSchema: z.ZodObject<{
47
47
  family: z.ZodString;
48
48
  weight: z.ZodEnum<{
49
- normal: "normal";
50
49
  bold: "bold";
50
+ normal: "normal";
51
51
  }>;
52
52
  style: z.ZodEnum<{
53
- normal: "normal";
54
53
  italic: "italic";
54
+ normal: "normal";
55
55
  }>;
56
56
  }, z.core.$strip>;
57
57
  type LayoutFont = z.infer<typeof LayoutFontSchema>;
@@ -1264,12 +1264,12 @@ declare const LayoutTextSchema: z.ZodObject<{
1264
1264
  font: z.ZodObject<{
1265
1265
  family: z.ZodString;
1266
1266
  weight: z.ZodEnum<{
1267
- normal: "normal";
1268
1267
  bold: "bold";
1268
+ normal: "normal";
1269
1269
  }>;
1270
1270
  style: z.ZodEnum<{
1271
- normal: "normal";
1272
1271
  italic: "italic";
1272
+ normal: "normal";
1273
1273
  }>;
1274
1274
  }, z.core.$strip>;
1275
1275
  sizePt: z.ZodNumber;
@@ -1445,12 +1445,12 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1445
1445
  font: z.ZodObject<{
1446
1446
  family: z.ZodString;
1447
1447
  weight: z.ZodEnum<{
1448
- normal: "normal";
1449
1448
  bold: "bold";
1449
+ normal: "normal";
1450
1450
  }>;
1451
1451
  style: z.ZodEnum<{
1452
- normal: "normal";
1453
1452
  italic: "italic";
1453
+ normal: "normal";
1454
1454
  }>;
1455
1455
  }, z.core.$strip>;
1456
1456
  sizePt: z.ZodNumber;
@@ -1584,12 +1584,12 @@ declare const LayoutPageSchema: z.ZodObject<{
1584
1584
  font: z.ZodObject<{
1585
1585
  family: z.ZodString;
1586
1586
  weight: z.ZodEnum<{
1587
- normal: "normal";
1588
1587
  bold: "bold";
1588
+ normal: "normal";
1589
1589
  }>;
1590
1590
  style: z.ZodEnum<{
1591
- normal: "normal";
1592
1591
  italic: "italic";
1592
+ normal: "normal";
1593
1593
  }>;
1594
1594
  }, z.core.$strip>;
1595
1595
  sizePt: z.ZodNumber;
@@ -1747,12 +1747,12 @@ declare const LayoutDocumentSchema: z.ZodObject<{
1747
1747
  font: z.ZodObject<{
1748
1748
  family: z.ZodString;
1749
1749
  weight: z.ZodEnum<{
1750
- normal: "normal";
1751
1750
  bold: "bold";
1751
+ normal: "normal";
1752
1752
  }>;
1753
1753
  style: z.ZodEnum<{
1754
- normal: "normal";
1755
1754
  italic: "italic";
1755
+ normal: "normal";
1756
1756
  }>;
1757
1757
  }, z.core.$strip>;
1758
1758
  sizePt: z.ZodNumber;
@@ -2271,12 +2271,12 @@ declare const DocumentPackageSchema: z.ZodObject<{
2271
2271
  font: z.ZodObject<{
2272
2272
  family: z.ZodString;
2273
2273
  weight: z.ZodEnum<{
2274
- normal: "normal";
2275
2274
  bold: "bold";
2275
+ normal: "normal";
2276
2276
  }>;
2277
2277
  style: z.ZodEnum<{
2278
- normal: "normal";
2279
2278
  italic: "italic";
2279
+ normal: "normal";
2280
2280
  }>;
2281
2281
  }, z.core.$strip>;
2282
2282
  sizePt: z.ZodNumber;
package/dist/index.d.ts CHANGED
@@ -46,12 +46,12 @@ type Alignment = z.infer<typeof AlignmentSchema>;
46
46
  declare const LayoutFontSchema: z.ZodObject<{
47
47
  family: z.ZodString;
48
48
  weight: z.ZodEnum<{
49
- normal: "normal";
50
49
  bold: "bold";
50
+ normal: "normal";
51
51
  }>;
52
52
  style: z.ZodEnum<{
53
- normal: "normal";
54
53
  italic: "italic";
54
+ normal: "normal";
55
55
  }>;
56
56
  }, z.core.$strip>;
57
57
  type LayoutFont = z.infer<typeof LayoutFontSchema>;
@@ -1264,12 +1264,12 @@ declare const LayoutTextSchema: z.ZodObject<{
1264
1264
  font: z.ZodObject<{
1265
1265
  family: z.ZodString;
1266
1266
  weight: z.ZodEnum<{
1267
- normal: "normal";
1268
1267
  bold: "bold";
1268
+ normal: "normal";
1269
1269
  }>;
1270
1270
  style: z.ZodEnum<{
1271
- normal: "normal";
1272
1271
  italic: "italic";
1272
+ normal: "normal";
1273
1273
  }>;
1274
1274
  }, z.core.$strip>;
1275
1275
  sizePt: z.ZodNumber;
@@ -1445,12 +1445,12 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1445
1445
  font: z.ZodObject<{
1446
1446
  family: z.ZodString;
1447
1447
  weight: z.ZodEnum<{
1448
- normal: "normal";
1449
1448
  bold: "bold";
1449
+ normal: "normal";
1450
1450
  }>;
1451
1451
  style: z.ZodEnum<{
1452
- normal: "normal";
1453
1452
  italic: "italic";
1453
+ normal: "normal";
1454
1454
  }>;
1455
1455
  }, z.core.$strip>;
1456
1456
  sizePt: z.ZodNumber;
@@ -1584,12 +1584,12 @@ declare const LayoutPageSchema: z.ZodObject<{
1584
1584
  font: z.ZodObject<{
1585
1585
  family: z.ZodString;
1586
1586
  weight: z.ZodEnum<{
1587
- normal: "normal";
1588
1587
  bold: "bold";
1588
+ normal: "normal";
1589
1589
  }>;
1590
1590
  style: z.ZodEnum<{
1591
- normal: "normal";
1592
1591
  italic: "italic";
1592
+ normal: "normal";
1593
1593
  }>;
1594
1594
  }, z.core.$strip>;
1595
1595
  sizePt: z.ZodNumber;
@@ -1747,12 +1747,12 @@ declare const LayoutDocumentSchema: z.ZodObject<{
1747
1747
  font: z.ZodObject<{
1748
1748
  family: z.ZodString;
1749
1749
  weight: z.ZodEnum<{
1750
- normal: "normal";
1751
1750
  bold: "bold";
1751
+ normal: "normal";
1752
1752
  }>;
1753
1753
  style: z.ZodEnum<{
1754
- normal: "normal";
1755
1754
  italic: "italic";
1755
+ normal: "normal";
1756
1756
  }>;
1757
1757
  }, z.core.$strip>;
1758
1758
  sizePt: z.ZodNumber;
@@ -2271,12 +2271,12 @@ declare const DocumentPackageSchema: z.ZodObject<{
2271
2271
  font: z.ZodObject<{
2272
2272
  family: z.ZodString;
2273
2273
  weight: z.ZodEnum<{
2274
- normal: "normal";
2275
2274
  bold: "bold";
2275
+ normal: "normal";
2276
2276
  }>;
2277
2277
  style: z.ZodEnum<{
2278
- normal: "normal";
2279
2278
  italic: "italic";
2279
+ normal: "normal";
2280
2280
  }>;
2281
2281
  }, z.core.$strip>;
2282
2282
  sizePt: z.ZodNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-schema.js",
3
- "version": "1.5.3",
3
+ "version": "1.6.1",
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",
@@ -37,14 +41,14 @@
37
41
  "node": ">=20"
38
42
  },
39
43
  "scripts": {
40
- "build": "tsdown",
41
- "prepublishOnly": "pnpm run lint && pnpm run typecheck && tsdown && publint && attw --pack",
44
+ "build": "tsdown && node scripts/generate-json-schemas.mjs",
45
+ "prepublishOnly": "pnpm run lint && pnpm run typecheck && pnpm run build && publint && attw --pack",
42
46
  "lint": "eslint . --max-warnings 0",
43
47
  "typecheck": "tsc --noEmit",
44
48
  "test": "vitest run --project unit",
45
49
  "test:watch": "vitest --project unit",
46
50
  "test:coverage": "vitest run --project unit --coverage",
47
- "test:smoke": "tsdown && vitest run --project smoke",
51
+ "test:smoke": "pnpm run build && vitest run --project smoke",
48
52
  "prepare": "husky",
49
53
  "release": "semantic-release"
50
54
  },