dexin-content 0.1.2 → 0.2.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/core/types.ts DELETED
@@ -1,162 +0,0 @@
1
- // ─────────────────────────────────────────────────────────────
2
- // dexin-content/core/types.ts — Generic shared types.
3
- // ─────────────────────────────────────────────────────────────
4
- // This file defines the shared type system used across domains.
5
- // It MUST remain business-agnostic. All names, literals, and
6
- // comment text are written in generic, domain-neutral vocabulary.
7
-
8
- // ── Inline content (shared across the neutral AST and all domains) ──
9
-
10
- export type Inline =
11
- | TextInline
12
- | BoldInline
13
- | ItalicInline
14
- | CodeInline
15
- | LinkInline
16
- | FormulaInline
17
-
18
- export interface TextInline { type: 'text'; value: string }
19
- export interface BoldInline { type: 'bold'; children: Inline[] }
20
- export interface ItalicInline { type: 'italic'; children: Inline[] }
21
- export interface CodeInline { type: 'code'; value: string }
22
- export interface LinkInline { type: 'link'; url: string; children: Inline[] }
23
- /** Inline LaTeX-format formula span (single-paragraph). */
24
- export interface FormulaInline { type: 'math'; latex: string }
25
-
26
- // ── Document-level blocks (neutral AST — no domain mapping) ──
27
-
28
- /**
29
- * HeadingBlock in the neutral AST: level is clamped to 1–4
30
- * (h1→1, h2→2, h3→3, h4→4). `mdDepth` is the ORIGINAL markdown heading
31
- * depth (1..6 inclusive) captured at parse time. It is OPTIONAL and exists
32
- * ONLY so active domain parsers can run their own fail-fast checks for
33
- * out-of-range depths. `mdDepth` MUST NOT leak into the serialised
34
- * canonical Artifact (the `content` output): domain parsers' clone/render
35
- * paths must drop it.
36
- */
37
- export interface HeadingBlock {
38
- type: 'heading'
39
- level: 1 | 2 | 3 | 4
40
- children: Inline[]
41
- /** Original markdown heading depth (1..6). Transient, non-canonical. */
42
- mdDepth?: number
43
- }
44
- export interface ParagraphBlock { type: 'paragraph'; children: Inline[] }
45
- export interface QuoteBlock { type: 'quote'; children: DocumentBlock[] }
46
- export interface DividerBlock { type: 'divider' }
47
- export interface ListBlock { type: 'list'; ordered: boolean; items: Inline[][] }
48
- export type TableCell = Inline[]
49
- export interface TableBlock { type: 'table'; headers: TableCell[]; rows: TableCell[][] }
50
- export interface ImageBlock { type: 'image'; src: string; alt: string; caption?: string }
51
- export interface CodeBlock { type: 'code'; language: string; code: string }
52
- /** Block-level LaTeX-format formula node; display=true for centered fences. */
53
- export interface FormulaBlock { type: 'formula'; latex: string; display: boolean }
54
-
55
- /**
56
- * Neutral ContainerBlock:
57
- * Produced for every directive container encountered in the markdown body.
58
- * The active domain decides whether an unknown name is acceptable;
59
- * the generic layer always preserves the structure as-is.
60
- */
61
- export interface ContainerBlock {
62
- type: 'container'
63
- name: string
64
- attrs: Record<string, string>
65
- children: DocumentBlock[]
66
- }
67
-
68
- export type DocumentBlock =
69
- | ParagraphBlock
70
- | HeadingBlock
71
- | QuoteBlock
72
- | DividerBlock
73
- | ListBlock
74
- | TableBlock
75
- | ImageBlock
76
- | CodeBlock
77
- | FormulaBlock
78
- | ContainerBlock
79
-
80
- export interface DocumentContent {
81
- version: 1
82
- blocks: DocumentBlock[]
83
- }
84
-
85
- // ── Artifact shapes (shared five-field header) ──
86
-
87
- /**
88
- * Generic domain tag. Literal string values are chosen by the host runner
89
- * and flow through to the Artifact output untouched. Core itself does not
90
- * interpret them beyond registry lookup keys.
91
- */
92
- export type DomainName = string & { readonly __brand?: unique symbol }
93
-
94
- /**
95
- * Plain-document identity:
96
- * id — relative to content root; strip `.md` and trailing `/index`
97
- * path — URL semantics: `'/' + id`
98
- * file — physical path relative to content root, INCLUDING `.md` extension
99
- *
100
- * Domain-specific routing fields may be attached by hosts via the index
101
- * signature; core never interprets them.
102
- */
103
- export interface DocumentIdentity {
104
- id: string
105
- path: string // URL semantic: '/' + id
106
- file: string // physical path relative to content root WITH ext
107
- collection: string
108
- [k: string]: unknown // auxiliary fields (e.g. index_file:true)
109
- }
110
-
111
- /** Frontmatter scalar-only projection (SCHEMA-FREE RULE) */
112
- export type Meta = Record<string, string | number | boolean>
113
-
114
- export interface ArtifactHeader {
115
- id: string // Stable document id (unique within a store)
116
- domain: DomainName | string
117
- identity: DocumentIdentity
118
- meta: Meta
119
- }
120
-
121
- export interface PositiveArtifact extends ArtifactHeader {
122
- content: { version: 1; blocks: unknown[] }
123
- }
124
-
125
- /** Compile-failure output — captures first fail-fast error. */
126
- export interface ErrorArtifact extends ArtifactHeader {
127
- kind: 'COMPILE_ERROR'
128
- error: { code: string; message: string }
129
- }
130
-
131
- export type Artifact = PositiveArtifact | ErrorArtifact
132
-
133
- // ── Unified error object ──
134
-
135
- export interface ParseError extends Error {
136
- code: string
137
- message: string
138
- file: string
139
- loc?: { container?: string; headingDepth?: number; invalidEnumValue?: string; allowed?: string }
140
- }
141
-
142
- // ── Parser contract — domains implement; core dispatches ──
143
-
144
- export interface ParseContext {
145
- /** Relative path to the source file, used in error messages. */
146
- file: string
147
- /** Collection-level schema (required fields + scalar type checks). */
148
- schema?: Schema
149
- /** Frontmatter already projected as scalar-only meta. */
150
- meta: Meta
151
- }
152
-
153
- export interface Schema {
154
- required?: string[]
155
- types?: Record<string, 'string' | 'number' | 'boolean'>
156
- }
157
-
158
- export interface DomainParser {
159
- domain: DomainName | string
160
- /** Convert neutral AST → domain-specific Artifact content.blocks shape. May throw ParseError. */
161
- parse(content: DocumentContent, ctx: ParseContext): { version: 1; blocks: unknown[] }
162
- }