@jxsuite/parser 2.0.1 → 3.0.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/src/types.ts CHANGED
@@ -1,4 +1,12 @@
1
- import type { JxElement, TocEntry } from "@jxsuite/schema/types";
1
+ import type { Root } from "mdast";
2
+ import type {
3
+ ContentFieldValue,
4
+ ContentTypeSchema,
5
+ JsonObject,
6
+ JsonValue,
7
+ JxElement,
8
+ TocEntry,
9
+ } from "@jxsuite/schema/types";
2
10
 
3
11
  // The content wire types are core (extensions implement them, hosts thread them); re-exported here
4
12
  // So parser-internal modules and downstream consumers keep their historical import path.
@@ -7,16 +15,21 @@ export type { ContentLoaderEntry, TocEntry } from "@jxsuite/schema/types";
7
15
  export interface MarkdownFileResult {
8
16
  slug: string;
9
17
  path: string;
10
- frontmatter: Record<string, unknown>;
18
+ /** The parsed front matter: the same field space a loaded content entry's `data` carries. */
19
+ frontmatter: Record<string, ContentFieldValue | undefined>;
11
20
  $children: (JxElement | string)[];
12
21
  $excerpt?: string;
13
22
  $toc?: TocEntry[];
14
23
  $readingTime?: number;
15
24
  $wordCount?: number;
16
- [key: string]: unknown;
17
25
  }
18
26
 
19
- export type ContentEntry = MarkdownFileResult & Record<string, unknown>;
27
+ /**
28
+ * A processed markdown file that may carry fields beyond the ones {@link MarkdownFileResult}
29
+ * declares: any value one of those members holds, or a front-matter field value.
30
+ */
31
+ export type ContentEntry = MarkdownFileResult &
32
+ Record<string, MarkdownFileResult[keyof MarkdownFileResult] | ContentFieldValue>;
20
33
 
21
34
  /**
22
35
  * A content-type definition in the project.json `content` section — the parser extension owns this
@@ -25,12 +38,12 @@ export type ContentEntry = MarkdownFileResult & Record<string, unknown>;
25
38
  export interface ContentTypeDef {
26
39
  source?: string;
27
40
  format?: string;
28
- schema?: Record<string, unknown>;
41
+ schema?: ContentTypeSchema;
29
42
  $elements?: (string | { $ref: string })[];
30
43
  /** Globs, relative to a directory `source`, for files that are never read. */
31
44
  exclude?: string[];
32
45
  /** Declarative frontmatter filter: only entries that satisfy it are kept. */
33
- where?: Record<string, unknown>;
46
+ where?: JsonObject;
34
47
  /** Frontmatter field whose value is the entry id (the path-derived id when absent). */
35
48
  idField?: string;
36
49
  /** Route template giving each entry its URL. */
@@ -44,7 +57,8 @@ export interface ContentTypeDef {
44
57
  * blockquote. `false` for the whole option turns callouts off, `true` is the default.
45
58
  */
46
59
  alerts?: Record<string, string | boolean | null> | boolean;
47
- [key: string]: unknown;
60
+ /** Format-specific options, read from `project.json` like every key above. */
61
+ [key: string]: JsonValue | ContentTypeSchema | undefined;
48
62
  }
49
63
 
50
64
  export interface MdastNode {
@@ -68,6 +82,13 @@ export interface MdastNode {
68
82
  align?: (string | null)[] | null;
69
83
  }
70
84
 
85
+ /**
86
+ * A unified attacher: called by unified with `this` bound to the processor and the settings passed
87
+ * after it to `use`. Its result (a parser, compiler or transformer) is consumed by unified, never
88
+ * by the pipeline, and every plugin this package installs takes only JSON settings.
89
+ */
90
+ export type UnifiedPlugin = (...settings: never[]) => void;
91
+
71
92
  /**
72
93
  * Minimal structural type for the unified() processor chain.
73
94
  *
@@ -77,16 +98,27 @@ export interface MdastNode {
77
98
  * boundary, so the rest of the pipeline is properly typed instead of `any`.
78
99
  */
79
100
  export interface UnifiedProcessor {
80
- use: (plugin: unknown, ...options: unknown[]) => UnifiedProcessor;
101
+ use: (plugin: UnifiedPlugin, ...settings: JsonValue[]) => UnifiedProcessor;
81
102
  parse: (source: string) => MdastNode;
82
- runSync: (tree: MdastNode, file?: unknown) => MdastNode;
83
- stringify: (tree: unknown) => string;
103
+ runSync: (tree: MdastNode, file?: UnifiedFile) => MdastNode;
104
+ stringify: (tree: MdastNode | Root) => string;
105
+ }
106
+
107
+ /**
108
+ * The part of a VFile the pipeline hands to `runSync` and reads back. unified wraps the object in a
109
+ * VFile that shares this `data` record, and `remark-parse-frontmatter` stores the YAML block's
110
+ * parse there. `yaml.parse` uses the YAML 1.2 core schema (no timestamps), so the result is plain
111
+ * JSON; a document with no front matter, or an empty block, leaves it absent or `null`.
112
+ */
113
+ export interface UnifiedFile {
114
+ data: { frontmatter?: JsonValue };
84
115
  }
85
116
 
86
117
  export interface HastNode {
87
118
  type: string;
88
119
  tagName?: string;
89
- properties?: Record<string, unknown>;
120
+ /** Hast's property values (`hast` Properties). */
121
+ properties?: Record<string, string | number | boolean | (string | number)[] | null | undefined>;
90
122
  children?: HastNode[];
91
123
  value?: string;
92
124
  }