@sprig-and-prose/sprig-universe 0.1.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/PHILOSOPHY.md +201 -0
- package/README.md +168 -0
- package/REFERENCE.md +355 -0
- package/biome.json +24 -0
- package/package.json +30 -0
- package/repositories/sprig-repository-github/index.js +29 -0
- package/src/ast.js +257 -0
- package/src/cli.js +1510 -0
- package/src/graph.js +950 -0
- package/src/index.js +46 -0
- package/src/ir.js +121 -0
- package/src/parser.js +1656 -0
- package/src/scanner.js +255 -0
- package/src/scene-manifest.js +856 -0
- package/src/util/span.js +46 -0
- package/src/util/text.js +126 -0
- package/src/validator.js +862 -0
- package/src/validators/mysql/connection.js +154 -0
- package/src/validators/mysql/schema.js +209 -0
- package/src/validators/mysql/type-compat.js +219 -0
- package/src/validators/mysql/validator.js +332 -0
- package/test/fixtures/amaranthine-mini.prose +53 -0
- package/test/fixtures/conflicting-universes-a.prose +8 -0
- package/test/fixtures/conflicting-universes-b.prose +8 -0
- package/test/fixtures/duplicate-names.prose +20 -0
- package/test/fixtures/first-line-aware.prose +32 -0
- package/test/fixtures/indented-describe.prose +18 -0
- package/test/fixtures/multi-file-universe-a.prose +15 -0
- package/test/fixtures/multi-file-universe-b.prose +15 -0
- package/test/fixtures/multi-file-universe-conflict-desc.prose +12 -0
- package/test/fixtures/multi-file-universe-conflict-title.prose +4 -0
- package/test/fixtures/multi-file-universe-with-title.prose +10 -0
- package/test/fixtures/named-document.prose +17 -0
- package/test/fixtures/named-duplicate.prose +22 -0
- package/test/fixtures/named-reference.prose +17 -0
- package/test/fixtures/relates-errors.prose +38 -0
- package/test/fixtures/relates-tier1.prose +14 -0
- package/test/fixtures/relates-tier2.prose +16 -0
- package/test/fixtures/relates-tier3.prose +21 -0
- package/test/fixtures/sprig-meta-mini.prose +62 -0
- package/test/fixtures/unresolved-relates.prose +15 -0
- package/test/fixtures/using-in-references.prose +35 -0
- package/test/fixtures/using-unknown.prose +8 -0
- package/test/universe-basic.test.js +804 -0
- package/tsconfig.json +15 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Public API for Sprig universe parser
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { scan } from './scanner.js';
|
|
6
|
+
import { parse } from './parser.js';
|
|
7
|
+
import { buildGraph } from './graph.js';
|
|
8
|
+
import { convertToSceneManifest, convertFilesToSceneManifest } from './scene-manifest.js';
|
|
9
|
+
import { validateScenes } from './validator.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {import('./ir.js').UniverseGraph} UniverseGraph
|
|
13
|
+
* @typedef {import('./ast.js').FileAST} FileAST
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Parses a single text string into an AST
|
|
18
|
+
* @param {string} text - Source text
|
|
19
|
+
* @param {string} file - File path (for source spans)
|
|
20
|
+
* @returns {FileAST}
|
|
21
|
+
*/
|
|
22
|
+
export function parseText(text, file) {
|
|
23
|
+
const tokens = scan(text, file);
|
|
24
|
+
return parse(tokens, file, text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parses multiple files and builds a single UniverseGraph
|
|
29
|
+
* @param {Array<{ text: string, file: string }>} files - Array of file contents
|
|
30
|
+
* @returns {UniverseGraph}
|
|
31
|
+
*/
|
|
32
|
+
export function parseFiles(files) {
|
|
33
|
+
const fileASTs = files.map((f) => parseText(f.text, f.file));
|
|
34
|
+
return buildGraph(fileASTs);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Export scene-related functions
|
|
38
|
+
export { convertToSceneManifest, convertFilesToSceneManifest, validateScenes };
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Builds a UniverseGraph from parsed file ASTs
|
|
42
|
+
* @param {FileAST[]} fileASTs - Array of parsed file ASTs
|
|
43
|
+
* @returns {UniverseGraph}
|
|
44
|
+
*/
|
|
45
|
+
export { buildGraph };
|
|
46
|
+
|
package/src/ir.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview UniverseGraph IR type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} SourceSpan
|
|
7
|
+
* @property {string} file - File path
|
|
8
|
+
* @property {{ line: number, col: number, offset: number }} start - Start position
|
|
9
|
+
* @property {{ line: number, col: number, offset: number }} end - End position
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {Object} TextBlock
|
|
14
|
+
* @property {string} raw - Raw text content (exactly as-authored)
|
|
15
|
+
* @property {string} [normalized] - Dedented/normalized text (optional, computed)
|
|
16
|
+
* @property {SourceSpan} source - Source span
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} UnknownBlock
|
|
21
|
+
* @property {string} keyword - Block keyword (e.g., 'references', 'documentation')
|
|
22
|
+
* @property {string} raw - Raw inner content (without outer braces, exactly as-authored)
|
|
23
|
+
* @property {string} [normalized] - Dedented/normalized text (optional, computed)
|
|
24
|
+
* @property {SourceSpan} source - Source span
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Object} NodeRef
|
|
29
|
+
* @property {string} text - Text as written
|
|
30
|
+
* @property {string} [target] - Resolved node ID if found
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {Object} Diagnostic
|
|
35
|
+
* @property {'error' | 'warning'} severity - Diagnostic severity
|
|
36
|
+
* @property {string} message - Diagnostic message
|
|
37
|
+
* @property {SourceSpan} [source] - Optional source span
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {string} NodeId - Node identifier: `${universeName}:${kind}:${name}`
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {string} EdgeId - Edge identifier: `${universeName}:relates:${aText}--${bText}:${index}`
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {Object} FromView
|
|
50
|
+
* @property {SourceSpan} source - Source span of the from block
|
|
51
|
+
* @property {{ values: string[], source: SourceSpan }} [relationships] - Relationships block if present
|
|
52
|
+
* @property {TextBlock} [describe] - Describe block if present
|
|
53
|
+
* @property {UnknownBlock[]} [unknownBlocks] - Unknown blocks if any
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @typedef {Object} NodeModel
|
|
58
|
+
* @property {NodeId} id - Node identifier
|
|
59
|
+
* @property {'universe' | 'anthology' | 'series' | 'book' | 'chapter' | 'concept' | 'relates'} kind - Node kind (declaration kind, not contract kind)
|
|
60
|
+
* @property {string} name - Node name
|
|
61
|
+
* @property {NodeId} [parent] - Tree parent node ID
|
|
62
|
+
* @property {NodeId[]} children - Child node IDs
|
|
63
|
+
* @property {NodeId} [container] - Container node ID (for book/chapter "in" relationship; always set for book/chapter nodes when resolved)
|
|
64
|
+
* @property {TextBlock} [describe] - Describe block if present
|
|
65
|
+
* @property {UnknownBlock[]} [unknownBlocks] - Unknown blocks if any
|
|
66
|
+
* @property {Array<{repository: string, paths: string[], kind?: string, describe?: TextBlock, source: SourceSpan}>} [references] - References if any
|
|
67
|
+
* @property {Array<{title?: string, kind: string, path: string, describe?: TextBlock, source: SourceSpan}>} [documentation] - Documentation if any
|
|
68
|
+
* @property {SourceSpan} source - Source span
|
|
69
|
+
* @property {NodeId[]} [endpoints] - Endpoint node IDs (for relates nodes)
|
|
70
|
+
* @property {string[]} [unresolvedEndpoints] - Unresolved endpoint names (for relates nodes)
|
|
71
|
+
* @property {Record<string, FromView>} [from] - From blocks keyed by endpoint node ID (for relates nodes)
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {Object} EdgeModel
|
|
76
|
+
* @property {EdgeId} id - Edge identifier
|
|
77
|
+
* @property {'relates'} kind - Edge kind
|
|
78
|
+
* @property {NodeRef} a - First endpoint
|
|
79
|
+
* @property {NodeRef} b - Second endpoint
|
|
80
|
+
* @property {TextBlock} [describe] - Describe block if present
|
|
81
|
+
* @property {SourceSpan} source - Source span
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @typedef {Object} UniverseModel
|
|
86
|
+
* @property {string} name - Universe name
|
|
87
|
+
* @property {NodeId} root - Root node ID (the universe node itself)
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @typedef {Object} NamedReferenceModel
|
|
92
|
+
* @property {string} name - Reference name
|
|
93
|
+
* @property {string} repository - Repository name
|
|
94
|
+
* @property {string[]} paths - Array of path strings
|
|
95
|
+
* @property {string} [kind] - Optional reference kind
|
|
96
|
+
* @property {TextBlock} [describe] - Optional describe block
|
|
97
|
+
* @property {SourceSpan} source - Source span
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @typedef {Object} NamedDocumentModel
|
|
102
|
+
* @property {string} name - Document name
|
|
103
|
+
* @property {string} kind - Document kind
|
|
104
|
+
* @property {string} path - Document path
|
|
105
|
+
* @property {TextBlock} [describe] - Optional describe block
|
|
106
|
+
* @property {SourceSpan} source - Source span
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @typedef {Object} UniverseGraph
|
|
111
|
+
* @property {number} version - Graph version (1)
|
|
112
|
+
* @property {Record<string, UniverseModel>} universes - Universes keyed by name
|
|
113
|
+
* @property {Record<NodeId, NodeModel>} nodes - Nodes keyed by ID
|
|
114
|
+
* @property {Record<EdgeId, EdgeModel>} edges - Edges keyed by ID
|
|
115
|
+
* @property {Diagnostic[]} diagnostics - Diagnostics
|
|
116
|
+
* @property {Record<string, any>} [repositories] - Repository configurations (from config)
|
|
117
|
+
* @property {string} [generatedAt] - ISO timestamp when manifest was generated
|
|
118
|
+
* @property {Record<string, Record<string, NamedReferenceModel>>} [referencesByName] - Named references by universe name, then by reference name
|
|
119
|
+
* @property {Record<string, Record<string, NamedDocumentModel>>} [documentsByName] - Named documents by universe name, then by document name
|
|
120
|
+
*/
|
|
121
|
+
|