@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.
Files changed (45) hide show
  1. package/PHILOSOPHY.md +201 -0
  2. package/README.md +168 -0
  3. package/REFERENCE.md +355 -0
  4. package/biome.json +24 -0
  5. package/package.json +30 -0
  6. package/repositories/sprig-repository-github/index.js +29 -0
  7. package/src/ast.js +257 -0
  8. package/src/cli.js +1510 -0
  9. package/src/graph.js +950 -0
  10. package/src/index.js +46 -0
  11. package/src/ir.js +121 -0
  12. package/src/parser.js +1656 -0
  13. package/src/scanner.js +255 -0
  14. package/src/scene-manifest.js +856 -0
  15. package/src/util/span.js +46 -0
  16. package/src/util/text.js +126 -0
  17. package/src/validator.js +862 -0
  18. package/src/validators/mysql/connection.js +154 -0
  19. package/src/validators/mysql/schema.js +209 -0
  20. package/src/validators/mysql/type-compat.js +219 -0
  21. package/src/validators/mysql/validator.js +332 -0
  22. package/test/fixtures/amaranthine-mini.prose +53 -0
  23. package/test/fixtures/conflicting-universes-a.prose +8 -0
  24. package/test/fixtures/conflicting-universes-b.prose +8 -0
  25. package/test/fixtures/duplicate-names.prose +20 -0
  26. package/test/fixtures/first-line-aware.prose +32 -0
  27. package/test/fixtures/indented-describe.prose +18 -0
  28. package/test/fixtures/multi-file-universe-a.prose +15 -0
  29. package/test/fixtures/multi-file-universe-b.prose +15 -0
  30. package/test/fixtures/multi-file-universe-conflict-desc.prose +12 -0
  31. package/test/fixtures/multi-file-universe-conflict-title.prose +4 -0
  32. package/test/fixtures/multi-file-universe-with-title.prose +10 -0
  33. package/test/fixtures/named-document.prose +17 -0
  34. package/test/fixtures/named-duplicate.prose +22 -0
  35. package/test/fixtures/named-reference.prose +17 -0
  36. package/test/fixtures/relates-errors.prose +38 -0
  37. package/test/fixtures/relates-tier1.prose +14 -0
  38. package/test/fixtures/relates-tier2.prose +16 -0
  39. package/test/fixtures/relates-tier3.prose +21 -0
  40. package/test/fixtures/sprig-meta-mini.prose +62 -0
  41. package/test/fixtures/unresolved-relates.prose +15 -0
  42. package/test/fixtures/using-in-references.prose +35 -0
  43. package/test/fixtures/using-unknown.prose +8 -0
  44. package/test/universe-basic.test.js +804 -0
  45. package/tsconfig.json +15 -0
package/biome.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3
+ "organizeImports": {
4
+ "enabled": true
5
+ },
6
+ "linter": {
7
+ "enabled": true,
8
+ "rules": {
9
+ "recommended": true
10
+ }
11
+ },
12
+ "formatter": {
13
+ "enabled": true,
14
+ "indentStyle": "space",
15
+ "indentWidth": 2
16
+ },
17
+ "javascript": {
18
+ "formatter": {
19
+ "quoteStyle": "single",
20
+ "semicolons": "always"
21
+ }
22
+ }
23
+ }
24
+
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@sprig-and-prose/sprig-universe",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Minimal universe parser for sprig",
6
+ "main": "src/index.js",
7
+ "bin": {
8
+ "sprig-universe": "./src/cli.js"
9
+ },
10
+ "scripts": {
11
+ "format": "biome format . --write",
12
+ "lint": "biome lint .",
13
+ "typecheck": "tsc -p tsconfig.json",
14
+ "test": "node --test"
15
+ },
16
+ "keywords": [],
17
+ "author": "",
18
+ "license": "ISC",
19
+ "dependencies": {
20
+ "chokidar": "^3.6.0",
21
+ "glob": "^13.0.0",
22
+ "mysql2": "^3.11.5",
23
+ "yaml": "^2.8.2"
24
+ },
25
+ "devDependencies": {
26
+ "@biomejs/biome": "^1.9.4",
27
+ "typescript": "^5.7.2"
28
+ }
29
+ }
30
+
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @fileoverview GitHub repository handler for Sprig
3
+ *
4
+ * This repository handler provides functionality for working with GitHub repositories.
5
+ * It can be extended to support cloning, fetching, and other GitHub-specific operations.
6
+ */
7
+
8
+ /**
9
+ * Repository handler interface
10
+ * @typedef {Object} RepositoryHandler
11
+ * @property {string} kind - Repository kind identifier
12
+ * @property {Function} [clone] - Clone repository function (optional)
13
+ * @property {Function} [fetch] - Fetch repository function (optional)
14
+ */
15
+
16
+ /**
17
+ * GitHub repository handler
18
+ * @param {Record<string, string | number>} options - Repository options
19
+ * @returns {RepositoryHandler}
20
+ */
21
+ export function createGitHubRepository(options) {
22
+ return {
23
+ kind: 'sprig-repository-github',
24
+ // Future: Add clone, fetch, and other GitHub-specific operations here
25
+ };
26
+ }
27
+
28
+ export default createGitHubRepository;
29
+
package/src/ast.js ADDED
@@ -0,0 +1,257 @@
1
+ /**
2
+ * @fileoverview AST node 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
15
+ * @property {SourceSpan} source - Source span
16
+ */
17
+
18
+ /**
19
+ * @typedef {Object} UnknownBlock
20
+ * @property {string} keyword - Block keyword
21
+ * @property {string} raw - Raw inner content (without outer braces)
22
+ * @property {SourceSpan} source - Source span
23
+ */
24
+
25
+ /**
26
+ * @typedef {Object} ReferenceBlock
27
+ * @property {string} kind - Always 'reference'
28
+ * @property {string} repository - Repository name (string literal)
29
+ * @property {string[]} paths - Array of path strings (string literals)
30
+ * @property {string} [referenceKind] - Optional reference kind (e.g., 'api', 'data')
31
+ * @property {DescribeBlock} [describe] - Optional describe block
32
+ * @property {SourceSpan} source - Source span
33
+ */
34
+
35
+ /**
36
+ * @typedef {Object} NamedReferenceBlock
37
+ * @property {string} kind - Always 'named-reference'
38
+ * @property {string} name - Reference name (identifier)
39
+ * @property {string} repository - Repository name (string literal)
40
+ * @property {string[]} paths - Array of path strings (string literals)
41
+ * @property {string} [referenceKind] - Optional reference kind (e.g., 'api', 'data')
42
+ * @property {DescribeBlock} [describe] - Optional describe block
43
+ * @property {SourceSpan} source - Source span
44
+ */
45
+
46
+ /**
47
+ * @typedef {Object} UsingInReferencesBlock
48
+ * @property {string} kind - Always 'using-in-references'
49
+ * @property {string[]} names - Array of identifier names to reference
50
+ * @property {SourceSpan} source - Source span
51
+ */
52
+
53
+ /**
54
+ * @typedef {Object} ReferencesBlock
55
+ * @property {string} kind - Always 'references'
56
+ * @property {Array<ReferenceBlock | UsingInReferencesBlock>} references - Array of reference blocks and using blocks
57
+ * @property {SourceSpan} source - Source span
58
+ */
59
+
60
+ /**
61
+ * @typedef {Object} DocumentBlock
62
+ * @property {string} kind - Always 'document'
63
+ * @property {string} [title] - Optional title identifier
64
+ * @property {string} documentKind - Document kind (e.g., 'internal')
65
+ * @property {string} path - Document path (e.g., '/docs/items/containers.md')
66
+ * @property {DescribeBlock} [describe] - Optional describe block
67
+ * @property {SourceSpan} source - Source span
68
+ */
69
+
70
+ /**
71
+ * @typedef {Object} NamedDocumentBlock
72
+ * @property {string} kind - Always 'named-document'
73
+ * @property {string} name - Document name (identifier)
74
+ * @property {string} documentKind - Document kind (e.g., 'internal')
75
+ * @property {string} path - Document path (e.g., '/docs/items/containers.md')
76
+ * @property {DescribeBlock} [describe] - Optional describe block
77
+ * @property {SourceSpan} source - Source span
78
+ */
79
+
80
+ /**
81
+ * @typedef {Object} DocumentationBlock
82
+ * @property {string} kind - Always 'documentation'
83
+ * @property {DocumentBlock[]} documents - Array of document blocks
84
+ * @property {SourceSpan} source - Source span
85
+ */
86
+
87
+ /**
88
+ * @typedef {Object} DescribeBlock
89
+ * @property {string} kind - Always 'describe'
90
+ * @property {string} raw - Raw text content (without outer braces)
91
+ * @property {SourceSpan} source - Source span
92
+ */
93
+
94
+ /**
95
+ * @typedef {Object} TitleBlock
96
+ * @property {string} kind - Always 'title'
97
+ * @property {string} raw - Raw text content (without outer braces)
98
+ * @property {SourceSpan} source - Source span
99
+ */
100
+
101
+ /**
102
+ * @typedef {Object} RepositoryDecl
103
+ * @property {string} kind - Always 'repository'
104
+ * @property {string} name - Repository name (identifier)
105
+ * @property {string | number} repositoryKind - Repository kind (string, identifier, or number)
106
+ * @property {Record<string, string | number>} options - Repository options
107
+ * @property {SourceSpan} source - Source span
108
+ */
109
+
110
+ /**
111
+ * @typedef {Object} UniverseDecl
112
+ * @property {string} kind - Always 'universe'
113
+ * @property {string} name - Universe name
114
+ * @property {Array<AnthologyDecl | SeriesDecl | BookDecl | ChapterDecl | ConceptDecl | RelatesDecl | DescribeBlock | TitleBlock | NamedReferenceBlock | NamedDocumentBlock | RepositoryDecl | UnknownBlock>} body - Body declarations
115
+ * @property {SourceSpan} source - Source span
116
+ */
117
+
118
+ /**
119
+ * @typedef {Object} AnthologyDecl
120
+ * @property {string} kind - Always 'anthology'
121
+ * @property {string} name - Anthology name
122
+ * @property {Array<DescribeBlock | TitleBlock | ReferencesBlock | DocumentationBlock | UnknownBlock>} body - Body declarations
123
+ * @property {SourceSpan} source - Source span
124
+ */
125
+
126
+ /**
127
+ * @typedef {Object} SeriesDecl
128
+ * @property {string} kind - Always 'series'
129
+ * @property {string} name - Series name
130
+ * @property {string} [parentName] - Optional parent anthology name (from "in AnthologyName")
131
+ * @property {Array<BookDecl | ChapterDecl | DescribeBlock | TitleBlock | ReferencesBlock | DocumentationBlock | UnknownBlock>} body - Body declarations
132
+ * @property {SourceSpan} source - Source span
133
+ */
134
+
135
+ /**
136
+ * @typedef {Object} BookDecl
137
+ * @property {string} kind - Always 'book'
138
+ * @property {string} name - Book name
139
+ * @property {string} parentName - Parent name (from "in ParentName")
140
+ * @property {Array<ChapterDecl | DescribeBlock | TitleBlock | ReferencesBlock | DocumentationBlock | UnknownBlock>} body - Body declarations
141
+ * @property {SourceSpan} source - Source span
142
+ */
143
+
144
+ /**
145
+ * @typedef {Object} ChapterDecl
146
+ * @property {string} kind - Always 'chapter'
147
+ * @property {string} name - Chapter name
148
+ * @property {string} parentName - Parent name (from "in ParentName")
149
+ * @property {Array<DescribeBlock | ReferencesBlock | DocumentationBlock | UnknownBlock>} body - Body declarations
150
+ * @property {SourceSpan} source - Source span
151
+ */
152
+
153
+ /**
154
+ * @typedef {Object} ConceptDecl
155
+ * @property {string} kind - Always 'concept'
156
+ * @property {string} name - Concept name
157
+ * @property {string} [parentName] - Optional parent name (from "in ParentName")
158
+ * @property {Array<DescribeBlock | ReferencesBlock | DocumentationBlock | UnknownBlock>} body - Body declarations
159
+ * @property {SourceSpan} source - Source span
160
+ */
161
+
162
+ /**
163
+ * @typedef {Object} RelationshipsBlock
164
+ * @property {string} kind - Always 'relationships'
165
+ * @property {string[]} values - Array of string literal values
166
+ * @property {SourceSpan} source - Source span
167
+ */
168
+
169
+ /**
170
+ * @typedef {Object} FromBlock
171
+ * @property {string} kind - Always 'from'
172
+ * @property {string} endpoint - Endpoint identifier
173
+ * @property {Array<RelationshipsBlock | DescribeBlock | TitleBlock | UnknownBlock>} body - Body declarations
174
+ * @property {SourceSpan} source - Source span
175
+ */
176
+
177
+ /**
178
+ * @typedef {Object} RelatesDecl
179
+ * @property {string} kind - Always 'relates'
180
+ * @property {string} a - First endpoint text
181
+ * @property {string} b - Second endpoint text
182
+ * @property {Array<DescribeBlock | TitleBlock | FromBlock | UnknownBlock>} body - Body declarations
183
+ * @property {SourceSpan} source - Source span
184
+ */
185
+
186
+ /**
187
+ * @typedef {Object} UsingBlock
188
+ * @property {string} kind - Always 'using'
189
+ * @property {string[]} identifiers - List of identifiers
190
+ * @property {SourceSpan} source - Source span
191
+ */
192
+
193
+ /**
194
+ * @typedef {Object} TypeBlock
195
+ * @property {string} kind - Always 'type'
196
+ * @property {string} raw - Raw inner content (for future parsing)
197
+ * @property {SourceSpan} source - Source span
198
+ */
199
+
200
+ /**
201
+ * @typedef {Object} IdentityBlock
202
+ * @property {string} kind - Always 'identity'
203
+ * @property {string} raw - Raw inner content (for future parsing)
204
+ * @property {SourceSpan} source - Source span
205
+ */
206
+
207
+ /**
208
+ * @typedef {Object} SourceBlock
209
+ * @property {string} kind - Always 'source'
210
+ * @property {string} sourceType - 'file', 'sqlite', or 'mysql'
211
+ * @property {string} raw - Raw inner content
212
+ * @property {SourceSpan} source - Source span
213
+ */
214
+
215
+ /**
216
+ * @typedef {Object} TransformBlock
217
+ * @property {string} kind - Always 'transform'
218
+ * @property {string} raw - Raw inner content
219
+ * @property {SourceSpan} source - Source span
220
+ */
221
+
222
+ /**
223
+ * @typedef {Object} TransformsBlock
224
+ * @property {string} kind - Always 'transforms'
225
+ * @property {TransformBlock[]} transforms - Array of transform blocks
226
+ * @property {SourceSpan} source - Source span
227
+ */
228
+
229
+ /**
230
+ * @typedef {Object} ActorDecl
231
+ * @property {string} kind - Always 'actor'
232
+ * @property {string} name - Actor name
233
+ * @property {Array<DescribeBlock | TypeBlock | IdentityBlock | SourceBlock | TransformsBlock | UnknownBlock>} body - Body declarations
234
+ * @property {SourceSpan} source - Source span
235
+ */
236
+
237
+ /**
238
+ * @typedef {Object} SceneDecl
239
+ * @property {string} kind - Always 'scene'
240
+ * @property {string} name - Scene name
241
+ * @property {string} target - Target namespace path (from "for Namespace.Path")
242
+ * @property {Array<UsingBlock | ActorDecl | DescribeBlock | UnknownBlock>} body - Body declarations
243
+ * @property {SourceSpan} source - Source span
244
+ */
245
+
246
+ /**
247
+ * @typedef {UniverseDecl | AnthologyDecl | SeriesDecl | BookDecl | ChapterDecl | ConceptDecl | RelatesDecl | DescribeBlock | TitleBlock | FromBlock | RelationshipsBlock | ReferencesBlock | ReferenceBlock | NamedReferenceBlock | DocumentationBlock | DocumentBlock | NamedDocumentBlock | RepositoryDecl | UnknownBlock | SceneDecl | UsingBlock | ActorDecl | TypeBlock | IdentityBlock | SourceBlock | TransformsBlock | TransformBlock} ASTNode
248
+ */
249
+
250
+ /**
251
+ * @typedef {Object} FileAST
252
+ * @property {string} file - File path
253
+ * @property {UniverseDecl[]} universes - Top-level universe declarations
254
+ * @property {SceneDecl[]} scenes - Top-level scene declarations
255
+ * @property {SourceSpan} [source] - File-level source span
256
+ */
257
+