gofish-ir 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.
@@ -0,0 +1,506 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://gofish.graphics/schema/frontend/v0.json",
4
+ "title": "GoFish Frontend IR",
5
+ "description": "Source-level chart specification produced by the v3 fluent API.",
6
+ "type": "object",
7
+ "required": [
8
+ "irVersion",
9
+ "ir",
10
+ "root"
11
+ ],
12
+ "additionalProperties": false,
13
+ "properties": {
14
+ "irVersion": {
15
+ "const": 0
16
+ },
17
+ "ir": {
18
+ "const": "gofish-frontend"
19
+ },
20
+ "$schema": {
21
+ "type": "string"
22
+ },
23
+ "root": {
24
+ "$ref": "#/$defs/Root"
25
+ }
26
+ },
27
+ "$defs": {
28
+ "Root": {
29
+ "oneOf": [
30
+ {
31
+ "$ref": "#/$defs/ChartIR"
32
+ },
33
+ {
34
+ "$ref": "#/$defs/LayerIR"
35
+ },
36
+ {
37
+ "$ref": "#/$defs/RawMarkIR"
38
+ }
39
+ ]
40
+ },
41
+ "Origin": {
42
+ "type": "object",
43
+ "properties": {
44
+ "name": {
45
+ "type": "string"
46
+ },
47
+ "stack": {
48
+ "type": "string"
49
+ }
50
+ }
51
+ },
52
+ "Meta": {
53
+ "type": "object",
54
+ "description": "Optional inline annotations populated by later passes. v0 emitters leave it absent."
55
+ },
56
+ "DataIR": {
57
+ "oneOf": [
58
+ {
59
+ "type": "object",
60
+ "required": [
61
+ "type",
62
+ "rows"
63
+ ],
64
+ "properties": {
65
+ "type": {
66
+ "const": "inline"
67
+ },
68
+ "rows": {
69
+ "type": "array",
70
+ "items": {
71
+ "type": "object"
72
+ }
73
+ }
74
+ }
75
+ },
76
+ {
77
+ "type": "object",
78
+ "required": [
79
+ "type",
80
+ "layer"
81
+ ],
82
+ "properties": {
83
+ "type": {
84
+ "const": "select"
85
+ },
86
+ "layer": {
87
+ "type": "string"
88
+ }
89
+ }
90
+ },
91
+ {
92
+ "type": "object",
93
+ "required": [
94
+ "type"
95
+ ],
96
+ "properties": {
97
+ "type": {
98
+ "const": "external"
99
+ },
100
+ "id": {
101
+ "type": "string"
102
+ }
103
+ }
104
+ }
105
+ ]
106
+ },
107
+ "ChartIR": {
108
+ "type": "object",
109
+ "required": [
110
+ "type",
111
+ "mark"
112
+ ],
113
+ "properties": {
114
+ "type": {
115
+ "const": "chart"
116
+ },
117
+ "data": {
118
+ "oneOf": [
119
+ {
120
+ "$ref": "#/$defs/DataIR"
121
+ },
122
+ {
123
+ "type": "null"
124
+ }
125
+ ]
126
+ },
127
+ "operators": {
128
+ "type": "array",
129
+ "items": {
130
+ "$ref": "#/$defs/OperatorIR"
131
+ }
132
+ },
133
+ "mark": {
134
+ "$ref": "#/$defs/MarkIR"
135
+ },
136
+ "options": {
137
+ "type": "object"
138
+ },
139
+ "zOrder": {
140
+ "type": "number"
141
+ },
142
+ "origin": {
143
+ "$ref": "#/$defs/Origin"
144
+ },
145
+ "meta": {
146
+ "$ref": "#/$defs/Meta"
147
+ }
148
+ }
149
+ },
150
+ "LayerIR": {
151
+ "type": "object",
152
+ "required": [
153
+ "type",
154
+ "charts"
155
+ ],
156
+ "properties": {
157
+ "type": {
158
+ "const": "layer"
159
+ },
160
+ "charts": {
161
+ "type": "array",
162
+ "items": {
163
+ "$ref": "#/$defs/ChartIR"
164
+ }
165
+ },
166
+ "options": {
167
+ "type": "object"
168
+ },
169
+ "origin": {
170
+ "$ref": "#/$defs/Origin"
171
+ },
172
+ "meta": {
173
+ "$ref": "#/$defs/Meta"
174
+ }
175
+ }
176
+ },
177
+ "RawMarkIR": {
178
+ "type": "object",
179
+ "required": [
180
+ "type",
181
+ "mark"
182
+ ],
183
+ "properties": {
184
+ "type": {
185
+ "const": "raw-mark"
186
+ },
187
+ "mark": {
188
+ "$ref": "#/$defs/MarkIR"
189
+ },
190
+ "options": {
191
+ "type": "object"
192
+ },
193
+ "origin": {
194
+ "$ref": "#/$defs/Origin"
195
+ },
196
+ "meta": {
197
+ "$ref": "#/$defs/Meta"
198
+ }
199
+ }
200
+ },
201
+ "OperatorIR": {
202
+ "type": "object",
203
+ "required": [
204
+ "type"
205
+ ],
206
+ "properties": {
207
+ "type": {
208
+ "enum": [
209
+ "derive",
210
+ "spread",
211
+ "stack",
212
+ "group",
213
+ "scatter",
214
+ "table",
215
+ "log"
216
+ ]
217
+ }
218
+ }
219
+ },
220
+ "MarkIR": {
221
+ "oneOf": [
222
+ {
223
+ "$ref": "#/$defs/LeafMarkIR"
224
+ },
225
+ {
226
+ "$ref": "#/$defs/CombinatorMarkIR"
227
+ },
228
+ {
229
+ "$ref": "#/$defs/RefMarkIR"
230
+ }
231
+ ]
232
+ },
233
+ "LeafMarkIR": {
234
+ "type": "object",
235
+ "required": [
236
+ "type"
237
+ ],
238
+ "properties": {
239
+ "type": {
240
+ "enum": [
241
+ "rect",
242
+ "circle",
243
+ "line",
244
+ "area",
245
+ "blank",
246
+ "ellipse",
247
+ "petal",
248
+ "text",
249
+ "image",
250
+ "polygon",
251
+ "mark-fn"
252
+ ]
253
+ },
254
+ "name": {
255
+ "type": "string"
256
+ },
257
+ "label": {
258
+ "$ref": "#/$defs/LabelIR"
259
+ },
260
+ "constraints": {
261
+ "type": "array",
262
+ "items": {
263
+ "$ref": "#/$defs/ConstraintIR"
264
+ }
265
+ },
266
+ "zOrder": {
267
+ "type": "number"
268
+ }
269
+ }
270
+ },
271
+ "CombinatorMarkIR": {
272
+ "type": "object",
273
+ "required": [
274
+ "type",
275
+ "__combinator",
276
+ "children"
277
+ ],
278
+ "properties": {
279
+ "type": {
280
+ "enum": [
281
+ "spread",
282
+ "stack",
283
+ "scatter",
284
+ "group",
285
+ "table",
286
+ "layer",
287
+ "arrow",
288
+ "connect",
289
+ "treemap",
290
+ "over",
291
+ "inside",
292
+ "xor",
293
+ "out",
294
+ "atop",
295
+ "mask"
296
+ ]
297
+ },
298
+ "__combinator": {
299
+ "const": true
300
+ },
301
+ "options": {
302
+ "type": "object"
303
+ },
304
+ "children": {
305
+ "type": "array",
306
+ "items": {
307
+ "$ref": "#/$defs/MarkIR"
308
+ }
309
+ },
310
+ "name": {
311
+ "type": "string"
312
+ },
313
+ "label": {
314
+ "$ref": "#/$defs/LabelIR"
315
+ },
316
+ "constraints": {
317
+ "type": "array",
318
+ "items": {
319
+ "$ref": "#/$defs/ConstraintIR"
320
+ }
321
+ },
322
+ "zOrder": {
323
+ "type": "number"
324
+ }
325
+ }
326
+ },
327
+ "RefMarkIR": {
328
+ "type": "object",
329
+ "required": [
330
+ "type",
331
+ "selection"
332
+ ],
333
+ "properties": {
334
+ "type": {
335
+ "const": "ref"
336
+ },
337
+ "selection": {
338
+ "oneOf": [
339
+ {
340
+ "type": "string"
341
+ },
342
+ {
343
+ "type": "array",
344
+ "items": {
345
+ "oneOf": [
346
+ {
347
+ "type": "string"
348
+ },
349
+ {
350
+ "type": "number"
351
+ }
352
+ ]
353
+ }
354
+ }
355
+ ]
356
+ },
357
+ "name": {
358
+ "type": "string"
359
+ },
360
+ "label": {
361
+ "$ref": "#/$defs/LabelIR"
362
+ },
363
+ "zOrder": {
364
+ "type": "number"
365
+ }
366
+ }
367
+ },
368
+ "LabelIR": {
369
+ "oneOf": [
370
+ {
371
+ "type": "boolean"
372
+ },
373
+ {
374
+ "type": "string"
375
+ },
376
+ {
377
+ "type": "object",
378
+ "required": [
379
+ "accessor"
380
+ ],
381
+ "properties": {
382
+ "accessor": {
383
+ "type": "string"
384
+ },
385
+ "position": {
386
+ "type": "string"
387
+ },
388
+ "fontSize": {
389
+ "type": "number"
390
+ },
391
+ "color": {
392
+ "type": "string"
393
+ },
394
+ "offset": {
395
+ "type": "number"
396
+ },
397
+ "minSpace": {
398
+ "type": "number"
399
+ },
400
+ "rotate": {
401
+ "type": "number"
402
+ }
403
+ }
404
+ }
405
+ ]
406
+ },
407
+ "ConstraintIR": {
408
+ "type": "object",
409
+ "required": [
410
+ "type",
411
+ "refs"
412
+ ],
413
+ "properties": {
414
+ "type": {
415
+ "enum": [
416
+ "align",
417
+ "distribute",
418
+ "zAbove",
419
+ "zBelow"
420
+ ]
421
+ },
422
+ "options": {
423
+ "type": "object"
424
+ },
425
+ "refs": {
426
+ "type": "array",
427
+ "items": {
428
+ "type": "string"
429
+ }
430
+ }
431
+ }
432
+ },
433
+ "ChannelValue": {
434
+ "description": "Right-hand side of a channel slot. Bare primitives for the shorthand path; tagged objects for the explicit field/datum/literal constructors and Python-bridge sentinels.",
435
+ "oneOf": [
436
+ {
437
+ "type": "string"
438
+ },
439
+ {
440
+ "type": "number"
441
+ },
442
+ {
443
+ "type": "boolean"
444
+ },
445
+ {
446
+ "type": "null"
447
+ },
448
+ {
449
+ "type": "object",
450
+ "required": [
451
+ "type",
452
+ "name"
453
+ ],
454
+ "properties": {
455
+ "type": {
456
+ "const": "field"
457
+ },
458
+ "name": {
459
+ "type": "string"
460
+ }
461
+ }
462
+ },
463
+ {
464
+ "type": "object",
465
+ "required": [
466
+ "type",
467
+ "value"
468
+ ],
469
+ "properties": {
470
+ "type": {
471
+ "const": "literal"
472
+ },
473
+ "value": {}
474
+ }
475
+ },
476
+ {
477
+ "type": "object",
478
+ "required": [
479
+ "type",
480
+ "datum"
481
+ ],
482
+ "properties": {
483
+ "type": {
484
+ "const": "datum"
485
+ },
486
+ "datum": {},
487
+ "measure": {
488
+ "type": "string"
489
+ }
490
+ }
491
+ },
492
+ {
493
+ "type": "object",
494
+ "required": [
495
+ "__gofish_lambda"
496
+ ],
497
+ "properties": {
498
+ "__gofish_lambda": {
499
+ "type": "string"
500
+ }
501
+ }
502
+ }
503
+ ]
504
+ }
505
+ }
506
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Runtime validator for the GoFish frontend IR.
3
+ *
4
+ * Hand-rolled, dependency-free. Strict mode rejects unknown fields (used in
5
+ * CI and tests); the default permissive mode ignores them, suitable for
6
+ * forward-compatible reading.
7
+ */
8
+ import { type ChannelValue, type CombinatorMarkIR, type ConstraintIR, type DataIR, type FrontendIRDocument, type LabelIR, type LeafMarkIR, type MarkIR, type Meta, type Origin, type RefMarkIR } from "./schema.js";
9
+ export interface ValidationError {
10
+ /** Dotted path into the document. */
11
+ path: string;
12
+ message: string;
13
+ }
14
+ export type ValidationResult = {
15
+ valid: true;
16
+ } | {
17
+ valid: false;
18
+ errors: ValidationError[];
19
+ };
20
+ export interface ValidateOptions {
21
+ /** Reject unknown fields. Default: false (permissive). */
22
+ strict?: boolean;
23
+ }
24
+ /** Validate a document against the frontend-IR schema. */
25
+ export declare function validate(doc: unknown, options?: ValidateOptions): ValidationResult;
26
+ export type { ChannelValue, CombinatorMarkIR, ConstraintIR, DataIR, FrontendIRDocument, LabelIR, LeafMarkIR, MarkIR, Meta, Origin, RefMarkIR, };
27
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/frontend/validate.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,IAAI,EACT,KAAK,MAAM,EACX,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GACf;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC;AAEhD,MAAM,WAAW,eAAe;IAC9B,0DAA0D;IAC1D,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,0DAA0D;AAC1D,wBAAgB,QAAQ,CACtB,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,eAAoB,GAC5B,gBAAgB,CASlB;AAyrBD,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,kBAAkB,EAClB,OAAO,EACP,UAAU,EACV,MAAM,EACN,IAAI,EACJ,MAAM,EACN,SAAS,GACV,CAAC"}