@cyphra/schema 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/dist/index.js ADDED
@@ -0,0 +1,2065 @@
1
+ // src/errors.ts
2
+ var SchemaValidationError = class extends Error {
3
+ name = "SchemaValidationError";
4
+ /**
5
+ * @param message - Human-readable explanation for library consumers.
6
+ */
7
+ constructor(message) {
8
+ super(message);
9
+ }
10
+ };
11
+
12
+ // src/printSchema.ts
13
+ function formatScalarType(t) {
14
+ return t.optional ? `${t.name}?` : t.name;
15
+ }
16
+ function formatDecoratorValue(v) {
17
+ if (v.kind === "string") {
18
+ return JSON.stringify(v.value);
19
+ }
20
+ return v.value;
21
+ }
22
+ function formatDecorator(d) {
23
+ if (d.name === "default") {
24
+ const fnArg = d.args.find((a) => a.key === "fn");
25
+ if (fnArg && fnArg.value.kind === "identifier") {
26
+ return `@default(${fnArg.value.value}())`;
27
+ }
28
+ }
29
+ if (d.args.length === 0) {
30
+ return `@${d.name}`;
31
+ }
32
+ const inner = d.args.map((a) => `${a.key}: ${formatDecoratorValue(a.value)}`).join(", ");
33
+ return `@${d.name}(${inner})`;
34
+ }
35
+ function formatScalarField(f) {
36
+ const decs = f.decorators.map(formatDecorator).join(" ");
37
+ const base = `${f.name} ${formatScalarType(f.type)}`;
38
+ return decs ? `${base} ${decs}` : base;
39
+ }
40
+ function formatRelationalField(f) {
41
+ let typeSuffix = f.target;
42
+ if (f.cardinality === "many") {
43
+ typeSuffix += "[]";
44
+ } else if (f.optional) {
45
+ typeSuffix += "?";
46
+ }
47
+ const decs = f.decorators.map(formatDecorator).join(" ");
48
+ return `${f.name} ${typeSuffix} ${decs}`;
49
+ }
50
+ function formatNodeField(f) {
51
+ return f.kind === "Scalar" ? formatScalarField(f) : formatRelationalField(f);
52
+ }
53
+ function printSchemaDocument(doc) {
54
+ const blocks = [];
55
+ for (const d of doc.declarations) {
56
+ if (d.kind === "Node") {
57
+ const lines = [`node ${d.name} {`, ...d.fields.map((f) => ` ${formatNodeField(f)}`), "}"];
58
+ blocks.push(lines.join("\n"));
59
+ } else {
60
+ const fieldLines = d.fields.map((f) => ` ${formatScalarField(f)}`);
61
+ const lines = [
62
+ `relationship ${d.name} {`,
63
+ ` type ${JSON.stringify(d.relType)}`,
64
+ ` from ${d.from}`,
65
+ ` to ${d.to}`,
66
+ ...fieldLines,
67
+ "}"
68
+ ];
69
+ blocks.push(lines.join("\n"));
70
+ }
71
+ }
72
+ return `${blocks.join("\n\n")}
73
+ `;
74
+ }
75
+
76
+ // src/parseSchema.ts
77
+ import { Buffer } from "buffer";
78
+
79
+ // src/generated/parser.js
80
+ function peg$subclass(child, parent) {
81
+ function C() {
82
+ this.constructor = child;
83
+ }
84
+ C.prototype = parent.prototype;
85
+ child.prototype = new C();
86
+ }
87
+ function peg$SyntaxError(message, expected, found, location) {
88
+ var self = Error.call(this, message);
89
+ if (Object.setPrototypeOf) {
90
+ Object.setPrototypeOf(self, peg$SyntaxError.prototype);
91
+ }
92
+ self.expected = expected;
93
+ self.found = found;
94
+ self.location = location;
95
+ self.name = "SyntaxError";
96
+ return self;
97
+ }
98
+ peg$subclass(peg$SyntaxError, Error);
99
+ function peg$padEnd(str, targetLength, padString) {
100
+ padString = padString || " ";
101
+ if (str.length > targetLength) {
102
+ return str;
103
+ }
104
+ targetLength -= str.length;
105
+ padString += padString.repeat(targetLength);
106
+ return str + padString.slice(0, targetLength);
107
+ }
108
+ peg$SyntaxError.prototype.format = function(sources) {
109
+ var str = "Error: " + this.message;
110
+ if (this.location) {
111
+ var src = null;
112
+ var k;
113
+ for (k = 0; k < sources.length; k++) {
114
+ if (sources[k].source === this.location.source) {
115
+ src = sources[k].text.split(/\r\n|\n|\r/g);
116
+ break;
117
+ }
118
+ }
119
+ var s = this.location.start;
120
+ var offset_s = this.location.source && typeof this.location.source.offset === "function" ? this.location.source.offset(s) : s;
121
+ var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
122
+ if (src) {
123
+ var e = this.location.end;
124
+ var filler = peg$padEnd("", offset_s.line.toString().length, " ");
125
+ var line = src[s.line - 1];
126
+ var last = s.line === e.line ? e.column : line.length + 1;
127
+ var hatLen = last - s.column || 1;
128
+ str += "\n --> " + loc + "\n" + filler + " |\n" + offset_s.line + " | " + line + "\n" + filler + " | " + peg$padEnd("", s.column - 1, " ") + peg$padEnd("", hatLen, "^");
129
+ } else {
130
+ str += "\n at " + loc;
131
+ }
132
+ }
133
+ return str;
134
+ };
135
+ peg$SyntaxError.buildMessage = function(expected, found) {
136
+ var DESCRIBE_EXPECTATION_FNS = {
137
+ literal: function(expectation) {
138
+ return '"' + literalEscape(expectation.text) + '"';
139
+ },
140
+ class: function(expectation) {
141
+ var escapedParts = expectation.parts.map(function(part) {
142
+ return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part);
143
+ });
144
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
145
+ },
146
+ any: function() {
147
+ return "any character";
148
+ },
149
+ end: function() {
150
+ return "end of input";
151
+ },
152
+ other: function(expectation) {
153
+ return expectation.description;
154
+ }
155
+ };
156
+ function hex(ch) {
157
+ return ch.charCodeAt(0).toString(16).toUpperCase();
158
+ }
159
+ function literalEscape(s) {
160
+ return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, function(ch) {
161
+ return "\\x0" + hex(ch);
162
+ }).replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) {
163
+ return "\\x" + hex(ch);
164
+ });
165
+ }
166
+ function classEscape(s) {
167
+ return s.replace(/\\/g, "\\\\").replace(/\]/g, "\\]").replace(/\^/g, "\\^").replace(/-/g, "\\-").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, function(ch) {
168
+ return "\\x0" + hex(ch);
169
+ }).replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) {
170
+ return "\\x" + hex(ch);
171
+ });
172
+ }
173
+ function describeExpectation(expectation) {
174
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
175
+ }
176
+ function describeExpected(expected2) {
177
+ var descriptions = expected2.map(describeExpectation);
178
+ var i, j;
179
+ descriptions.sort();
180
+ if (descriptions.length > 0) {
181
+ for (i = 1, j = 1; i < descriptions.length; i++) {
182
+ if (descriptions[i - 1] !== descriptions[i]) {
183
+ descriptions[j] = descriptions[i];
184
+ j++;
185
+ }
186
+ }
187
+ descriptions.length = j;
188
+ }
189
+ switch (descriptions.length) {
190
+ case 1:
191
+ return descriptions[0];
192
+ case 2:
193
+ return descriptions[0] + " or " + descriptions[1];
194
+ default:
195
+ return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
196
+ }
197
+ }
198
+ function describeFound(found2) {
199
+ return found2 ? '"' + literalEscape(found2) + '"' : "end of input";
200
+ }
201
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
202
+ };
203
+ function peg$parse(input, options) {
204
+ options = options !== void 0 ? options : {};
205
+ var peg$FAILED = {};
206
+ var peg$source = options.grammarSource;
207
+ var peg$startRuleFunctions = { start: peg$parsestart };
208
+ var peg$startRuleFunction = peg$parsestart;
209
+ var peg$c0 = "node";
210
+ var peg$c1 = "{";
211
+ var peg$c2 = "}";
212
+ var peg$c3 = "relationship";
213
+ var peg$c4 = "type";
214
+ var peg$c5 = "from";
215
+ var peg$c6 = "to";
216
+ var peg$c7 = "[]";
217
+ var peg$c8 = "?";
218
+ var peg$c9 = "String";
219
+ var peg$c10 = "Int";
220
+ var peg$c11 = "Float";
221
+ var peg$c12 = "Boolean";
222
+ var peg$c13 = "DateTime";
223
+ var peg$c14 = "@";
224
+ var peg$c15 = "default";
225
+ var peg$c16 = "(";
226
+ var peg$c17 = ")";
227
+ var peg$c18 = ",";
228
+ var peg$c19 = ":";
229
+ var peg$c20 = '"';
230
+ var peg$c21 = "\\";
231
+ var peg$c22 = "n";
232
+ var peg$c23 = "//";
233
+ var peg$r0 = /^[^"\\]/;
234
+ var peg$r1 = /^[a-zA-Z_]/;
235
+ var peg$r2 = /^[a-zA-Z0-9_]/;
236
+ var peg$r3 = /^[ \t\n\r]/;
237
+ var peg$r4 = /^[\n\r]/;
238
+ var peg$e0 = peg$literalExpectation("node", false);
239
+ var peg$e1 = peg$literalExpectation("{", false);
240
+ var peg$e2 = peg$literalExpectation("}", false);
241
+ var peg$e3 = peg$literalExpectation("relationship", false);
242
+ var peg$e4 = peg$literalExpectation("type", false);
243
+ var peg$e5 = peg$literalExpectation("from", false);
244
+ var peg$e6 = peg$literalExpectation("to", false);
245
+ var peg$e7 = peg$literalExpectation("[]", false);
246
+ var peg$e8 = peg$literalExpectation("?", false);
247
+ var peg$e9 = peg$literalExpectation("String", false);
248
+ var peg$e10 = peg$literalExpectation("Int", false);
249
+ var peg$e11 = peg$literalExpectation("Float", false);
250
+ var peg$e12 = peg$literalExpectation("Boolean", false);
251
+ var peg$e13 = peg$literalExpectation("DateTime", false);
252
+ var peg$e14 = peg$literalExpectation("@", false);
253
+ var peg$e15 = peg$literalExpectation("default", false);
254
+ var peg$e16 = peg$literalExpectation("(", false);
255
+ var peg$e17 = peg$literalExpectation(")", false);
256
+ var peg$e18 = peg$literalExpectation(",", false);
257
+ var peg$e19 = peg$literalExpectation(":", false);
258
+ var peg$e20 = peg$literalExpectation('"', false);
259
+ var peg$e21 = peg$classExpectation(['"', "\\"], true, false);
260
+ var peg$e22 = peg$literalExpectation("\\", false);
261
+ var peg$e23 = peg$literalExpectation("n", false);
262
+ var peg$e24 = peg$otherExpectation("identifier");
263
+ var peg$e25 = peg$classExpectation([["a", "z"], ["A", "Z"], "_"], false, false);
264
+ var peg$e26 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_"], false, false);
265
+ var peg$e27 = peg$classExpectation([" ", " ", "\n", "\r"], false, false);
266
+ var peg$e28 = peg$literalExpectation("//", false);
267
+ var peg$e29 = peg$classExpectation(["\n", "\r"], false, false);
268
+ var peg$e30 = peg$anyExpectation();
269
+ var peg$f0 = function(decls) {
270
+ return { kind: "Document", declarations: decls };
271
+ };
272
+ var peg$f1 = function(name, fields) {
273
+ return { kind: "Node", name, fields };
274
+ };
275
+ var peg$f2 = function(name, body) {
276
+ return {
277
+ kind: "Relationship",
278
+ name,
279
+ relType: body.relType,
280
+ from: body.from,
281
+ to: body.to,
282
+ fields: body.fields
283
+ };
284
+ };
285
+ var peg$f3 = function(rt, fromLine, toLine, fields) {
286
+ return { relType: rt, from: fromLine, to: toLine, fields };
287
+ };
288
+ var peg$f4 = function(id) {
289
+ return id;
290
+ };
291
+ var peg$f5 = function(id) {
292
+ return id;
293
+ };
294
+ var peg$f6 = function(name, type, decs) {
295
+ return { kind: "Scalar", name, type, decorators: decs };
296
+ };
297
+ var peg$f7 = function(name, target, decs) {
298
+ return {
299
+ kind: "Relational",
300
+ name,
301
+ target: target.target,
302
+ cardinality: target.cardinality,
303
+ optional: target.optional,
304
+ decorators: decs
305
+ };
306
+ };
307
+ var peg$f8 = function(t) {
308
+ return { target: t, cardinality: "many", optional: false };
309
+ };
310
+ var peg$f9 = function(t) {
311
+ return { target: t, cardinality: "one", optional: true };
312
+ };
313
+ var peg$f10 = function(t) {
314
+ return { target: t, cardinality: "one", optional: false };
315
+ };
316
+ var peg$f11 = function(name, type, decs) {
317
+ return { kind: "Scalar", name, type, decorators: decs };
318
+ };
319
+ var peg$f12 = function(n, opt) {
320
+ return { name: n, optional: opt === "?" };
321
+ };
322
+ var peg$f13 = function() {
323
+ return "String";
324
+ };
325
+ var peg$f14 = function() {
326
+ return "Int";
327
+ };
328
+ var peg$f15 = function() {
329
+ return "Float";
330
+ };
331
+ var peg$f16 = function() {
332
+ return "Boolean";
333
+ };
334
+ var peg$f17 = function() {
335
+ return "DateTime";
336
+ };
337
+ var peg$f18 = function(id) {
338
+ return { name: "default", args: [{ key: "fn", value: { kind: "identifier", value: id } }] };
339
+ };
340
+ var peg$f19 = function(name, args) {
341
+ return { name, args };
342
+ };
343
+ var peg$f20 = function(name) {
344
+ return { name, args: [] };
345
+ };
346
+ var peg$f21 = function(head, tail) {
347
+ return [head, ...tail];
348
+ };
349
+ var peg$f22 = function() {
350
+ return [];
351
+ };
352
+ var peg$f23 = function(key, val) {
353
+ return { key, value: val };
354
+ };
355
+ var peg$f24 = function(s) {
356
+ return { kind: "string", value: s };
357
+ };
358
+ var peg$f25 = function(id) {
359
+ return { kind: "identifier", value: id };
360
+ };
361
+ var peg$f26 = function(chars) {
362
+ return chars.join("");
363
+ };
364
+ var peg$f27 = function() {
365
+ return '"';
366
+ };
367
+ var peg$f28 = function() {
368
+ return "\\";
369
+ };
370
+ var peg$f29 = function() {
371
+ return "\n";
372
+ };
373
+ var peg$f30 = function(first, rest) {
374
+ return first + rest.join("");
375
+ };
376
+ var peg$currPos = options.peg$currPos | 0;
377
+ var peg$savedPos = peg$currPos;
378
+ var peg$posDetailsCache = [{ line: 1, column: 1 }];
379
+ var peg$maxFailPos = peg$currPos;
380
+ var peg$maxFailExpected = options.peg$maxFailExpected || [];
381
+ var peg$silentFails = options.peg$silentFails | 0;
382
+ var peg$result;
383
+ if (options.startRule) {
384
+ if (!(options.startRule in peg$startRuleFunctions)) {
385
+ throw new Error(`Can't start parsing from rule "` + options.startRule + '".');
386
+ }
387
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
388
+ }
389
+ function text() {
390
+ return input.substring(peg$savedPos, peg$currPos);
391
+ }
392
+ function offset() {
393
+ return peg$savedPos;
394
+ }
395
+ function range() {
396
+ return {
397
+ source: peg$source,
398
+ start: peg$savedPos,
399
+ end: peg$currPos
400
+ };
401
+ }
402
+ function location() {
403
+ return peg$computeLocation(peg$savedPos, peg$currPos);
404
+ }
405
+ function expected(description, location2) {
406
+ location2 = location2 !== void 0 ? location2 : peg$computeLocation(peg$savedPos, peg$currPos);
407
+ throw peg$buildStructuredError(
408
+ [peg$otherExpectation(description)],
409
+ input.substring(peg$savedPos, peg$currPos),
410
+ location2
411
+ );
412
+ }
413
+ function error(message, location2) {
414
+ location2 = location2 !== void 0 ? location2 : peg$computeLocation(peg$savedPos, peg$currPos);
415
+ throw peg$buildSimpleError(message, location2);
416
+ }
417
+ function peg$literalExpectation(text2, ignoreCase) {
418
+ return { type: "literal", text: text2, ignoreCase };
419
+ }
420
+ function peg$classExpectation(parts, inverted, ignoreCase) {
421
+ return { type: "class", parts, inverted, ignoreCase };
422
+ }
423
+ function peg$anyExpectation() {
424
+ return { type: "any" };
425
+ }
426
+ function peg$endExpectation() {
427
+ return { type: "end" };
428
+ }
429
+ function peg$otherExpectation(description) {
430
+ return { type: "other", description };
431
+ }
432
+ function peg$computePosDetails(pos) {
433
+ var details = peg$posDetailsCache[pos];
434
+ var p;
435
+ if (details) {
436
+ return details;
437
+ } else {
438
+ if (pos >= peg$posDetailsCache.length) {
439
+ p = peg$posDetailsCache.length - 1;
440
+ } else {
441
+ p = pos;
442
+ while (!peg$posDetailsCache[--p]) {
443
+ }
444
+ }
445
+ details = peg$posDetailsCache[p];
446
+ details = {
447
+ line: details.line,
448
+ column: details.column
449
+ };
450
+ while (p < pos) {
451
+ if (input.charCodeAt(p) === 10) {
452
+ details.line++;
453
+ details.column = 1;
454
+ } else {
455
+ details.column++;
456
+ }
457
+ p++;
458
+ }
459
+ peg$posDetailsCache[pos] = details;
460
+ return details;
461
+ }
462
+ }
463
+ function peg$computeLocation(startPos, endPos, offset2) {
464
+ var startPosDetails = peg$computePosDetails(startPos);
465
+ var endPosDetails = peg$computePosDetails(endPos);
466
+ var res = {
467
+ source: peg$source,
468
+ start: {
469
+ offset: startPos,
470
+ line: startPosDetails.line,
471
+ column: startPosDetails.column
472
+ },
473
+ end: {
474
+ offset: endPos,
475
+ line: endPosDetails.line,
476
+ column: endPosDetails.column
477
+ }
478
+ };
479
+ if (offset2 && peg$source && typeof peg$source.offset === "function") {
480
+ res.start = peg$source.offset(res.start);
481
+ res.end = peg$source.offset(res.end);
482
+ }
483
+ return res;
484
+ }
485
+ function peg$fail(expected2) {
486
+ if (peg$currPos < peg$maxFailPos) {
487
+ return;
488
+ }
489
+ if (peg$currPos > peg$maxFailPos) {
490
+ peg$maxFailPos = peg$currPos;
491
+ peg$maxFailExpected = [];
492
+ }
493
+ peg$maxFailExpected.push(expected2);
494
+ }
495
+ function peg$buildSimpleError(message, location2) {
496
+ return new peg$SyntaxError(message, null, null, location2);
497
+ }
498
+ function peg$buildStructuredError(expected2, found, location2) {
499
+ return new peg$SyntaxError(
500
+ peg$SyntaxError.buildMessage(expected2, found),
501
+ expected2,
502
+ found,
503
+ location2
504
+ );
505
+ }
506
+ function peg$parsestart() {
507
+ var s0, s1, s2, s3, s4, s5;
508
+ s0 = peg$currPos;
509
+ s1 = peg$parse_();
510
+ s2 = [];
511
+ s3 = peg$currPos;
512
+ s4 = peg$parse_();
513
+ s5 = peg$parsedeclaration();
514
+ if (s5 !== peg$FAILED) {
515
+ s3 = s5;
516
+ } else {
517
+ peg$currPos = s3;
518
+ s3 = peg$FAILED;
519
+ }
520
+ while (s3 !== peg$FAILED) {
521
+ s2.push(s3);
522
+ s3 = peg$currPos;
523
+ s4 = peg$parse_();
524
+ s5 = peg$parsedeclaration();
525
+ if (s5 !== peg$FAILED) {
526
+ s3 = s5;
527
+ } else {
528
+ peg$currPos = s3;
529
+ s3 = peg$FAILED;
530
+ }
531
+ }
532
+ s3 = peg$parse_();
533
+ peg$savedPos = s0;
534
+ s0 = peg$f0(s2);
535
+ return s0;
536
+ }
537
+ function peg$parsedeclaration() {
538
+ var s0;
539
+ s0 = peg$parsenodeDeclaration();
540
+ if (s0 === peg$FAILED) {
541
+ s0 = peg$parserelationshipDeclaration();
542
+ }
543
+ return s0;
544
+ }
545
+ function peg$parsenodeDeclaration() {
546
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
547
+ s0 = peg$currPos;
548
+ if (input.substr(peg$currPos, 4) === peg$c0) {
549
+ s1 = peg$c0;
550
+ peg$currPos += 4;
551
+ } else {
552
+ s1 = peg$FAILED;
553
+ if (peg$silentFails === 0) {
554
+ peg$fail(peg$e0);
555
+ }
556
+ }
557
+ if (s1 !== peg$FAILED) {
558
+ s2 = peg$parse__();
559
+ if (s2 !== peg$FAILED) {
560
+ s3 = peg$parseidentifier();
561
+ if (s3 !== peg$FAILED) {
562
+ s4 = peg$parse_();
563
+ if (input.charCodeAt(peg$currPos) === 123) {
564
+ s5 = peg$c1;
565
+ peg$currPos++;
566
+ } else {
567
+ s5 = peg$FAILED;
568
+ if (peg$silentFails === 0) {
569
+ peg$fail(peg$e1);
570
+ }
571
+ }
572
+ if (s5 !== peg$FAILED) {
573
+ s6 = peg$parse_();
574
+ s7 = [];
575
+ s8 = peg$parsenodeField();
576
+ while (s8 !== peg$FAILED) {
577
+ s7.push(s8);
578
+ s8 = peg$parsenodeField();
579
+ }
580
+ s8 = peg$parse_();
581
+ if (input.charCodeAt(peg$currPos) === 125) {
582
+ s9 = peg$c2;
583
+ peg$currPos++;
584
+ } else {
585
+ s9 = peg$FAILED;
586
+ if (peg$silentFails === 0) {
587
+ peg$fail(peg$e2);
588
+ }
589
+ }
590
+ if (s9 !== peg$FAILED) {
591
+ peg$savedPos = s0;
592
+ s0 = peg$f1(s3, s7);
593
+ } else {
594
+ peg$currPos = s0;
595
+ s0 = peg$FAILED;
596
+ }
597
+ } else {
598
+ peg$currPos = s0;
599
+ s0 = peg$FAILED;
600
+ }
601
+ } else {
602
+ peg$currPos = s0;
603
+ s0 = peg$FAILED;
604
+ }
605
+ } else {
606
+ peg$currPos = s0;
607
+ s0 = peg$FAILED;
608
+ }
609
+ } else {
610
+ peg$currPos = s0;
611
+ s0 = peg$FAILED;
612
+ }
613
+ return s0;
614
+ }
615
+ function peg$parserelationshipDeclaration() {
616
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
617
+ s0 = peg$currPos;
618
+ if (input.substr(peg$currPos, 12) === peg$c3) {
619
+ s1 = peg$c3;
620
+ peg$currPos += 12;
621
+ } else {
622
+ s1 = peg$FAILED;
623
+ if (peg$silentFails === 0) {
624
+ peg$fail(peg$e3);
625
+ }
626
+ }
627
+ if (s1 !== peg$FAILED) {
628
+ s2 = peg$parse__();
629
+ if (s2 !== peg$FAILED) {
630
+ s3 = peg$parseidentifier();
631
+ if (s3 !== peg$FAILED) {
632
+ s4 = peg$parse_();
633
+ if (input.charCodeAt(peg$currPos) === 123) {
634
+ s5 = peg$c1;
635
+ peg$currPos++;
636
+ } else {
637
+ s5 = peg$FAILED;
638
+ if (peg$silentFails === 0) {
639
+ peg$fail(peg$e1);
640
+ }
641
+ }
642
+ if (s5 !== peg$FAILED) {
643
+ s6 = peg$parse_();
644
+ s7 = peg$parserelationshipBody();
645
+ if (s7 !== peg$FAILED) {
646
+ s8 = peg$parse_();
647
+ if (input.charCodeAt(peg$currPos) === 125) {
648
+ s9 = peg$c2;
649
+ peg$currPos++;
650
+ } else {
651
+ s9 = peg$FAILED;
652
+ if (peg$silentFails === 0) {
653
+ peg$fail(peg$e2);
654
+ }
655
+ }
656
+ if (s9 !== peg$FAILED) {
657
+ peg$savedPos = s0;
658
+ s0 = peg$f2(s3, s7);
659
+ } else {
660
+ peg$currPos = s0;
661
+ s0 = peg$FAILED;
662
+ }
663
+ } else {
664
+ peg$currPos = s0;
665
+ s0 = peg$FAILED;
666
+ }
667
+ } else {
668
+ peg$currPos = s0;
669
+ s0 = peg$FAILED;
670
+ }
671
+ } else {
672
+ peg$currPos = s0;
673
+ s0 = peg$FAILED;
674
+ }
675
+ } else {
676
+ peg$currPos = s0;
677
+ s0 = peg$FAILED;
678
+ }
679
+ } else {
680
+ peg$currPos = s0;
681
+ s0 = peg$FAILED;
682
+ }
683
+ return s0;
684
+ }
685
+ function peg$parserelationshipBody() {
686
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
687
+ s0 = peg$currPos;
688
+ if (input.substr(peg$currPos, 4) === peg$c4) {
689
+ s1 = peg$c4;
690
+ peg$currPos += 4;
691
+ } else {
692
+ s1 = peg$FAILED;
693
+ if (peg$silentFails === 0) {
694
+ peg$fail(peg$e4);
695
+ }
696
+ }
697
+ if (s1 !== peg$FAILED) {
698
+ s2 = peg$parse__();
699
+ if (s2 !== peg$FAILED) {
700
+ s3 = peg$parsestringLiteral();
701
+ if (s3 !== peg$FAILED) {
702
+ s4 = peg$parse_();
703
+ s5 = peg$parsefromLine();
704
+ if (s5 !== peg$FAILED) {
705
+ s6 = peg$parse_();
706
+ s7 = peg$parsetoLine();
707
+ if (s7 !== peg$FAILED) {
708
+ s8 = peg$parse_();
709
+ s9 = [];
710
+ s10 = peg$parsescalarFieldInRel();
711
+ while (s10 !== peg$FAILED) {
712
+ s9.push(s10);
713
+ s10 = peg$parsescalarFieldInRel();
714
+ }
715
+ peg$savedPos = s0;
716
+ s0 = peg$f3(s3, s5, s7, s9);
717
+ } else {
718
+ peg$currPos = s0;
719
+ s0 = peg$FAILED;
720
+ }
721
+ } else {
722
+ peg$currPos = s0;
723
+ s0 = peg$FAILED;
724
+ }
725
+ } else {
726
+ peg$currPos = s0;
727
+ s0 = peg$FAILED;
728
+ }
729
+ } else {
730
+ peg$currPos = s0;
731
+ s0 = peg$FAILED;
732
+ }
733
+ } else {
734
+ peg$currPos = s0;
735
+ s0 = peg$FAILED;
736
+ }
737
+ return s0;
738
+ }
739
+ function peg$parsefromLine() {
740
+ var s0, s1, s2, s3, s4;
741
+ s0 = peg$currPos;
742
+ if (input.substr(peg$currPos, 4) === peg$c5) {
743
+ s1 = peg$c5;
744
+ peg$currPos += 4;
745
+ } else {
746
+ s1 = peg$FAILED;
747
+ if (peg$silentFails === 0) {
748
+ peg$fail(peg$e5);
749
+ }
750
+ }
751
+ if (s1 !== peg$FAILED) {
752
+ s2 = peg$parse__();
753
+ if (s2 !== peg$FAILED) {
754
+ s3 = peg$parseidentifier();
755
+ if (s3 !== peg$FAILED) {
756
+ s4 = peg$parse_();
757
+ peg$savedPos = s0;
758
+ s0 = peg$f4(s3);
759
+ } else {
760
+ peg$currPos = s0;
761
+ s0 = peg$FAILED;
762
+ }
763
+ } else {
764
+ peg$currPos = s0;
765
+ s0 = peg$FAILED;
766
+ }
767
+ } else {
768
+ peg$currPos = s0;
769
+ s0 = peg$FAILED;
770
+ }
771
+ return s0;
772
+ }
773
+ function peg$parsetoLine() {
774
+ var s0, s1, s2, s3, s4;
775
+ s0 = peg$currPos;
776
+ if (input.substr(peg$currPos, 2) === peg$c6) {
777
+ s1 = peg$c6;
778
+ peg$currPos += 2;
779
+ } else {
780
+ s1 = peg$FAILED;
781
+ if (peg$silentFails === 0) {
782
+ peg$fail(peg$e6);
783
+ }
784
+ }
785
+ if (s1 !== peg$FAILED) {
786
+ s2 = peg$parse__();
787
+ if (s2 !== peg$FAILED) {
788
+ s3 = peg$parseidentifier();
789
+ if (s3 !== peg$FAILED) {
790
+ s4 = peg$parse_();
791
+ peg$savedPos = s0;
792
+ s0 = peg$f5(s3);
793
+ } else {
794
+ peg$currPos = s0;
795
+ s0 = peg$FAILED;
796
+ }
797
+ } else {
798
+ peg$currPos = s0;
799
+ s0 = peg$FAILED;
800
+ }
801
+ } else {
802
+ peg$currPos = s0;
803
+ s0 = peg$FAILED;
804
+ }
805
+ return s0;
806
+ }
807
+ function peg$parsescalarFieldInRel() {
808
+ var s0, s1, s2, s3, s4, s5, s6, s7;
809
+ s0 = peg$currPos;
810
+ s1 = peg$parseidentifier();
811
+ if (s1 !== peg$FAILED) {
812
+ s2 = peg$parse__();
813
+ if (s2 !== peg$FAILED) {
814
+ s3 = peg$parsefieldType();
815
+ if (s3 !== peg$FAILED) {
816
+ s4 = [];
817
+ s5 = peg$currPos;
818
+ s6 = peg$parse_();
819
+ s7 = peg$parsedecorator();
820
+ if (s7 !== peg$FAILED) {
821
+ s5 = s7;
822
+ } else {
823
+ peg$currPos = s5;
824
+ s5 = peg$FAILED;
825
+ }
826
+ while (s5 !== peg$FAILED) {
827
+ s4.push(s5);
828
+ s5 = peg$currPos;
829
+ s6 = peg$parse_();
830
+ s7 = peg$parsedecorator();
831
+ if (s7 !== peg$FAILED) {
832
+ s5 = s7;
833
+ } else {
834
+ peg$currPos = s5;
835
+ s5 = peg$FAILED;
836
+ }
837
+ }
838
+ s5 = peg$parse_();
839
+ peg$savedPos = s0;
840
+ s0 = peg$f6(s1, s3, s4);
841
+ } else {
842
+ peg$currPos = s0;
843
+ s0 = peg$FAILED;
844
+ }
845
+ } else {
846
+ peg$currPos = s0;
847
+ s0 = peg$FAILED;
848
+ }
849
+ } else {
850
+ peg$currPos = s0;
851
+ s0 = peg$FAILED;
852
+ }
853
+ return s0;
854
+ }
855
+ function peg$parsenodeField() {
856
+ var s0;
857
+ s0 = peg$parsescalarNodeField();
858
+ if (s0 === peg$FAILED) {
859
+ s0 = peg$parserelationalNodeField();
860
+ }
861
+ return s0;
862
+ }
863
+ function peg$parserelationalNodeField() {
864
+ var s0, s1, s2, s3, s4, s5, s6, s7;
865
+ s0 = peg$currPos;
866
+ s1 = peg$parseidentifier();
867
+ if (s1 !== peg$FAILED) {
868
+ s2 = peg$parse__();
869
+ if (s2 !== peg$FAILED) {
870
+ s3 = peg$parserelationalTarget();
871
+ if (s3 !== peg$FAILED) {
872
+ s4 = [];
873
+ s5 = peg$currPos;
874
+ s6 = peg$parse_();
875
+ s7 = peg$parsedecorator();
876
+ if (s7 !== peg$FAILED) {
877
+ s5 = s7;
878
+ } else {
879
+ peg$currPos = s5;
880
+ s5 = peg$FAILED;
881
+ }
882
+ if (s5 !== peg$FAILED) {
883
+ while (s5 !== peg$FAILED) {
884
+ s4.push(s5);
885
+ s5 = peg$currPos;
886
+ s6 = peg$parse_();
887
+ s7 = peg$parsedecorator();
888
+ if (s7 !== peg$FAILED) {
889
+ s5 = s7;
890
+ } else {
891
+ peg$currPos = s5;
892
+ s5 = peg$FAILED;
893
+ }
894
+ }
895
+ } else {
896
+ s4 = peg$FAILED;
897
+ }
898
+ if (s4 !== peg$FAILED) {
899
+ s5 = peg$parse_();
900
+ peg$savedPos = s0;
901
+ s0 = peg$f7(s1, s3, s4);
902
+ } else {
903
+ peg$currPos = s0;
904
+ s0 = peg$FAILED;
905
+ }
906
+ } else {
907
+ peg$currPos = s0;
908
+ s0 = peg$FAILED;
909
+ }
910
+ } else {
911
+ peg$currPos = s0;
912
+ s0 = peg$FAILED;
913
+ }
914
+ } else {
915
+ peg$currPos = s0;
916
+ s0 = peg$FAILED;
917
+ }
918
+ return s0;
919
+ }
920
+ function peg$parserelationalTarget() {
921
+ var s0, s1, s2;
922
+ s0 = peg$currPos;
923
+ s1 = peg$parseidentifier();
924
+ if (s1 !== peg$FAILED) {
925
+ if (input.substr(peg$currPos, 2) === peg$c7) {
926
+ s2 = peg$c7;
927
+ peg$currPos += 2;
928
+ } else {
929
+ s2 = peg$FAILED;
930
+ if (peg$silentFails === 0) {
931
+ peg$fail(peg$e7);
932
+ }
933
+ }
934
+ if (s2 !== peg$FAILED) {
935
+ peg$savedPos = s0;
936
+ s0 = peg$f8(s1);
937
+ } else {
938
+ peg$currPos = s0;
939
+ s0 = peg$FAILED;
940
+ }
941
+ } else {
942
+ peg$currPos = s0;
943
+ s0 = peg$FAILED;
944
+ }
945
+ if (s0 === peg$FAILED) {
946
+ s0 = peg$currPos;
947
+ s1 = peg$parseidentifier();
948
+ if (s1 !== peg$FAILED) {
949
+ if (input.charCodeAt(peg$currPos) === 63) {
950
+ s2 = peg$c8;
951
+ peg$currPos++;
952
+ } else {
953
+ s2 = peg$FAILED;
954
+ if (peg$silentFails === 0) {
955
+ peg$fail(peg$e8);
956
+ }
957
+ }
958
+ if (s2 !== peg$FAILED) {
959
+ peg$savedPos = s0;
960
+ s0 = peg$f9(s1);
961
+ } else {
962
+ peg$currPos = s0;
963
+ s0 = peg$FAILED;
964
+ }
965
+ } else {
966
+ peg$currPos = s0;
967
+ s0 = peg$FAILED;
968
+ }
969
+ if (s0 === peg$FAILED) {
970
+ s0 = peg$currPos;
971
+ s1 = peg$parseidentifier();
972
+ if (s1 !== peg$FAILED) {
973
+ peg$savedPos = s0;
974
+ s1 = peg$f10(s1);
975
+ }
976
+ s0 = s1;
977
+ }
978
+ }
979
+ return s0;
980
+ }
981
+ function peg$parsescalarNodeField() {
982
+ var s0, s1, s2, s3, s4, s5, s6, s7;
983
+ s0 = peg$currPos;
984
+ s1 = peg$parseidentifier();
985
+ if (s1 !== peg$FAILED) {
986
+ s2 = peg$parse__();
987
+ if (s2 !== peg$FAILED) {
988
+ s3 = peg$parsefieldType();
989
+ if (s3 !== peg$FAILED) {
990
+ s4 = [];
991
+ s5 = peg$currPos;
992
+ s6 = peg$parse_();
993
+ s7 = peg$parsedecorator();
994
+ if (s7 !== peg$FAILED) {
995
+ s5 = s7;
996
+ } else {
997
+ peg$currPos = s5;
998
+ s5 = peg$FAILED;
999
+ }
1000
+ while (s5 !== peg$FAILED) {
1001
+ s4.push(s5);
1002
+ s5 = peg$currPos;
1003
+ s6 = peg$parse_();
1004
+ s7 = peg$parsedecorator();
1005
+ if (s7 !== peg$FAILED) {
1006
+ s5 = s7;
1007
+ } else {
1008
+ peg$currPos = s5;
1009
+ s5 = peg$FAILED;
1010
+ }
1011
+ }
1012
+ s5 = peg$parse_();
1013
+ peg$savedPos = s0;
1014
+ s0 = peg$f11(s1, s3, s4);
1015
+ } else {
1016
+ peg$currPos = s0;
1017
+ s0 = peg$FAILED;
1018
+ }
1019
+ } else {
1020
+ peg$currPos = s0;
1021
+ s0 = peg$FAILED;
1022
+ }
1023
+ } else {
1024
+ peg$currPos = s0;
1025
+ s0 = peg$FAILED;
1026
+ }
1027
+ return s0;
1028
+ }
1029
+ function peg$parsefieldType() {
1030
+ var s0, s1, s2;
1031
+ s0 = peg$currPos;
1032
+ s1 = peg$parsescalarTypeName();
1033
+ if (s1 !== peg$FAILED) {
1034
+ if (input.charCodeAt(peg$currPos) === 63) {
1035
+ s2 = peg$c8;
1036
+ peg$currPos++;
1037
+ } else {
1038
+ s2 = peg$FAILED;
1039
+ if (peg$silentFails === 0) {
1040
+ peg$fail(peg$e8);
1041
+ }
1042
+ }
1043
+ if (s2 === peg$FAILED) {
1044
+ s2 = null;
1045
+ }
1046
+ peg$savedPos = s0;
1047
+ s0 = peg$f12(s1, s2);
1048
+ } else {
1049
+ peg$currPos = s0;
1050
+ s0 = peg$FAILED;
1051
+ }
1052
+ return s0;
1053
+ }
1054
+ function peg$parsescalarTypeName() {
1055
+ var s0, s1;
1056
+ s0 = peg$currPos;
1057
+ if (input.substr(peg$currPos, 6) === peg$c9) {
1058
+ s1 = peg$c9;
1059
+ peg$currPos += 6;
1060
+ } else {
1061
+ s1 = peg$FAILED;
1062
+ if (peg$silentFails === 0) {
1063
+ peg$fail(peg$e9);
1064
+ }
1065
+ }
1066
+ if (s1 !== peg$FAILED) {
1067
+ peg$savedPos = s0;
1068
+ s1 = peg$f13();
1069
+ }
1070
+ s0 = s1;
1071
+ if (s0 === peg$FAILED) {
1072
+ s0 = peg$currPos;
1073
+ if (input.substr(peg$currPos, 3) === peg$c10) {
1074
+ s1 = peg$c10;
1075
+ peg$currPos += 3;
1076
+ } else {
1077
+ s1 = peg$FAILED;
1078
+ if (peg$silentFails === 0) {
1079
+ peg$fail(peg$e10);
1080
+ }
1081
+ }
1082
+ if (s1 !== peg$FAILED) {
1083
+ peg$savedPos = s0;
1084
+ s1 = peg$f14();
1085
+ }
1086
+ s0 = s1;
1087
+ if (s0 === peg$FAILED) {
1088
+ s0 = peg$currPos;
1089
+ if (input.substr(peg$currPos, 5) === peg$c11) {
1090
+ s1 = peg$c11;
1091
+ peg$currPos += 5;
1092
+ } else {
1093
+ s1 = peg$FAILED;
1094
+ if (peg$silentFails === 0) {
1095
+ peg$fail(peg$e11);
1096
+ }
1097
+ }
1098
+ if (s1 !== peg$FAILED) {
1099
+ peg$savedPos = s0;
1100
+ s1 = peg$f15();
1101
+ }
1102
+ s0 = s1;
1103
+ if (s0 === peg$FAILED) {
1104
+ s0 = peg$currPos;
1105
+ if (input.substr(peg$currPos, 7) === peg$c12) {
1106
+ s1 = peg$c12;
1107
+ peg$currPos += 7;
1108
+ } else {
1109
+ s1 = peg$FAILED;
1110
+ if (peg$silentFails === 0) {
1111
+ peg$fail(peg$e12);
1112
+ }
1113
+ }
1114
+ if (s1 !== peg$FAILED) {
1115
+ peg$savedPos = s0;
1116
+ s1 = peg$f16();
1117
+ }
1118
+ s0 = s1;
1119
+ if (s0 === peg$FAILED) {
1120
+ s0 = peg$currPos;
1121
+ if (input.substr(peg$currPos, 8) === peg$c13) {
1122
+ s1 = peg$c13;
1123
+ peg$currPos += 8;
1124
+ } else {
1125
+ s1 = peg$FAILED;
1126
+ if (peg$silentFails === 0) {
1127
+ peg$fail(peg$e13);
1128
+ }
1129
+ }
1130
+ if (s1 !== peg$FAILED) {
1131
+ peg$savedPos = s0;
1132
+ s1 = peg$f17();
1133
+ }
1134
+ s0 = s1;
1135
+ }
1136
+ }
1137
+ }
1138
+ }
1139
+ return s0;
1140
+ }
1141
+ function peg$parsedecorator() {
1142
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
1143
+ s0 = peg$currPos;
1144
+ if (input.charCodeAt(peg$currPos) === 64) {
1145
+ s1 = peg$c14;
1146
+ peg$currPos++;
1147
+ } else {
1148
+ s1 = peg$FAILED;
1149
+ if (peg$silentFails === 0) {
1150
+ peg$fail(peg$e14);
1151
+ }
1152
+ }
1153
+ if (s1 !== peg$FAILED) {
1154
+ if (input.substr(peg$currPos, 7) === peg$c15) {
1155
+ s2 = peg$c15;
1156
+ peg$currPos += 7;
1157
+ } else {
1158
+ s2 = peg$FAILED;
1159
+ if (peg$silentFails === 0) {
1160
+ peg$fail(peg$e15);
1161
+ }
1162
+ }
1163
+ if (s2 !== peg$FAILED) {
1164
+ if (input.charCodeAt(peg$currPos) === 40) {
1165
+ s3 = peg$c16;
1166
+ peg$currPos++;
1167
+ } else {
1168
+ s3 = peg$FAILED;
1169
+ if (peg$silentFails === 0) {
1170
+ peg$fail(peg$e16);
1171
+ }
1172
+ }
1173
+ if (s3 !== peg$FAILED) {
1174
+ s4 = peg$parse_();
1175
+ s5 = peg$parseidentifier();
1176
+ if (s5 !== peg$FAILED) {
1177
+ if (input.charCodeAt(peg$currPos) === 40) {
1178
+ s6 = peg$c16;
1179
+ peg$currPos++;
1180
+ } else {
1181
+ s6 = peg$FAILED;
1182
+ if (peg$silentFails === 0) {
1183
+ peg$fail(peg$e16);
1184
+ }
1185
+ }
1186
+ if (s6 !== peg$FAILED) {
1187
+ s7 = peg$parse_();
1188
+ if (input.charCodeAt(peg$currPos) === 41) {
1189
+ s8 = peg$c17;
1190
+ peg$currPos++;
1191
+ } else {
1192
+ s8 = peg$FAILED;
1193
+ if (peg$silentFails === 0) {
1194
+ peg$fail(peg$e17);
1195
+ }
1196
+ }
1197
+ if (s8 !== peg$FAILED) {
1198
+ s9 = peg$parse_();
1199
+ if (input.charCodeAt(peg$currPos) === 41) {
1200
+ s10 = peg$c17;
1201
+ peg$currPos++;
1202
+ } else {
1203
+ s10 = peg$FAILED;
1204
+ if (peg$silentFails === 0) {
1205
+ peg$fail(peg$e17);
1206
+ }
1207
+ }
1208
+ if (s10 !== peg$FAILED) {
1209
+ peg$savedPos = s0;
1210
+ s0 = peg$f18(s5);
1211
+ } else {
1212
+ peg$currPos = s0;
1213
+ s0 = peg$FAILED;
1214
+ }
1215
+ } else {
1216
+ peg$currPos = s0;
1217
+ s0 = peg$FAILED;
1218
+ }
1219
+ } else {
1220
+ peg$currPos = s0;
1221
+ s0 = peg$FAILED;
1222
+ }
1223
+ } else {
1224
+ peg$currPos = s0;
1225
+ s0 = peg$FAILED;
1226
+ }
1227
+ } else {
1228
+ peg$currPos = s0;
1229
+ s0 = peg$FAILED;
1230
+ }
1231
+ } else {
1232
+ peg$currPos = s0;
1233
+ s0 = peg$FAILED;
1234
+ }
1235
+ } else {
1236
+ peg$currPos = s0;
1237
+ s0 = peg$FAILED;
1238
+ }
1239
+ if (s0 === peg$FAILED) {
1240
+ s0 = peg$currPos;
1241
+ if (input.charCodeAt(peg$currPos) === 64) {
1242
+ s1 = peg$c14;
1243
+ peg$currPos++;
1244
+ } else {
1245
+ s1 = peg$FAILED;
1246
+ if (peg$silentFails === 0) {
1247
+ peg$fail(peg$e14);
1248
+ }
1249
+ }
1250
+ if (s1 !== peg$FAILED) {
1251
+ s2 = peg$parseidentifier();
1252
+ if (s2 !== peg$FAILED) {
1253
+ if (input.charCodeAt(peg$currPos) === 40) {
1254
+ s3 = peg$c16;
1255
+ peg$currPos++;
1256
+ } else {
1257
+ s3 = peg$FAILED;
1258
+ if (peg$silentFails === 0) {
1259
+ peg$fail(peg$e16);
1260
+ }
1261
+ }
1262
+ if (s3 !== peg$FAILED) {
1263
+ s4 = peg$parse_();
1264
+ s5 = peg$parsedecoratorArgs();
1265
+ if (s5 !== peg$FAILED) {
1266
+ s6 = peg$parse_();
1267
+ if (input.charCodeAt(peg$currPos) === 41) {
1268
+ s7 = peg$c17;
1269
+ peg$currPos++;
1270
+ } else {
1271
+ s7 = peg$FAILED;
1272
+ if (peg$silentFails === 0) {
1273
+ peg$fail(peg$e17);
1274
+ }
1275
+ }
1276
+ if (s7 !== peg$FAILED) {
1277
+ peg$savedPos = s0;
1278
+ s0 = peg$f19(s2, s5);
1279
+ } else {
1280
+ peg$currPos = s0;
1281
+ s0 = peg$FAILED;
1282
+ }
1283
+ } else {
1284
+ peg$currPos = s0;
1285
+ s0 = peg$FAILED;
1286
+ }
1287
+ } else {
1288
+ peg$currPos = s0;
1289
+ s0 = peg$FAILED;
1290
+ }
1291
+ } else {
1292
+ peg$currPos = s0;
1293
+ s0 = peg$FAILED;
1294
+ }
1295
+ } else {
1296
+ peg$currPos = s0;
1297
+ s0 = peg$FAILED;
1298
+ }
1299
+ if (s0 === peg$FAILED) {
1300
+ s0 = peg$currPos;
1301
+ if (input.charCodeAt(peg$currPos) === 64) {
1302
+ s1 = peg$c14;
1303
+ peg$currPos++;
1304
+ } else {
1305
+ s1 = peg$FAILED;
1306
+ if (peg$silentFails === 0) {
1307
+ peg$fail(peg$e14);
1308
+ }
1309
+ }
1310
+ if (s1 !== peg$FAILED) {
1311
+ s2 = peg$parseidentifier();
1312
+ if (s2 !== peg$FAILED) {
1313
+ peg$savedPos = s0;
1314
+ s0 = peg$f20(s2);
1315
+ } else {
1316
+ peg$currPos = s0;
1317
+ s0 = peg$FAILED;
1318
+ }
1319
+ } else {
1320
+ peg$currPos = s0;
1321
+ s0 = peg$FAILED;
1322
+ }
1323
+ }
1324
+ }
1325
+ return s0;
1326
+ }
1327
+ function peg$parsedecoratorArgs() {
1328
+ var s0, s1, s2, s3, s4, s5, s6, s7;
1329
+ s0 = peg$currPos;
1330
+ s1 = peg$parsedecoratorArg();
1331
+ if (s1 !== peg$FAILED) {
1332
+ s2 = [];
1333
+ s3 = peg$currPos;
1334
+ s4 = peg$parse_();
1335
+ if (input.charCodeAt(peg$currPos) === 44) {
1336
+ s5 = peg$c18;
1337
+ peg$currPos++;
1338
+ } else {
1339
+ s5 = peg$FAILED;
1340
+ if (peg$silentFails === 0) {
1341
+ peg$fail(peg$e18);
1342
+ }
1343
+ }
1344
+ if (s5 !== peg$FAILED) {
1345
+ s6 = peg$parse_();
1346
+ s7 = peg$parsedecoratorArg();
1347
+ if (s7 !== peg$FAILED) {
1348
+ s3 = s7;
1349
+ } else {
1350
+ peg$currPos = s3;
1351
+ s3 = peg$FAILED;
1352
+ }
1353
+ } else {
1354
+ peg$currPos = s3;
1355
+ s3 = peg$FAILED;
1356
+ }
1357
+ while (s3 !== peg$FAILED) {
1358
+ s2.push(s3);
1359
+ s3 = peg$currPos;
1360
+ s4 = peg$parse_();
1361
+ if (input.charCodeAt(peg$currPos) === 44) {
1362
+ s5 = peg$c18;
1363
+ peg$currPos++;
1364
+ } else {
1365
+ s5 = peg$FAILED;
1366
+ if (peg$silentFails === 0) {
1367
+ peg$fail(peg$e18);
1368
+ }
1369
+ }
1370
+ if (s5 !== peg$FAILED) {
1371
+ s6 = peg$parse_();
1372
+ s7 = peg$parsedecoratorArg();
1373
+ if (s7 !== peg$FAILED) {
1374
+ s3 = s7;
1375
+ } else {
1376
+ peg$currPos = s3;
1377
+ s3 = peg$FAILED;
1378
+ }
1379
+ } else {
1380
+ peg$currPos = s3;
1381
+ s3 = peg$FAILED;
1382
+ }
1383
+ }
1384
+ peg$savedPos = s0;
1385
+ s0 = peg$f21(s1, s2);
1386
+ } else {
1387
+ peg$currPos = s0;
1388
+ s0 = peg$FAILED;
1389
+ }
1390
+ if (s0 === peg$FAILED) {
1391
+ s0 = peg$currPos;
1392
+ s1 = "";
1393
+ peg$savedPos = s0;
1394
+ s1 = peg$f22();
1395
+ s0 = s1;
1396
+ }
1397
+ return s0;
1398
+ }
1399
+ function peg$parsedecoratorArg() {
1400
+ var s0, s1, s2, s3, s4, s5;
1401
+ s0 = peg$currPos;
1402
+ s1 = peg$parseidentifier();
1403
+ if (s1 !== peg$FAILED) {
1404
+ s2 = peg$parse_();
1405
+ if (input.charCodeAt(peg$currPos) === 58) {
1406
+ s3 = peg$c19;
1407
+ peg$currPos++;
1408
+ } else {
1409
+ s3 = peg$FAILED;
1410
+ if (peg$silentFails === 0) {
1411
+ peg$fail(peg$e19);
1412
+ }
1413
+ }
1414
+ if (s3 !== peg$FAILED) {
1415
+ s4 = peg$parse_();
1416
+ s5 = peg$parsedecoratorValue();
1417
+ if (s5 !== peg$FAILED) {
1418
+ peg$savedPos = s0;
1419
+ s0 = peg$f23(s1, s5);
1420
+ } else {
1421
+ peg$currPos = s0;
1422
+ s0 = peg$FAILED;
1423
+ }
1424
+ } else {
1425
+ peg$currPos = s0;
1426
+ s0 = peg$FAILED;
1427
+ }
1428
+ } else {
1429
+ peg$currPos = s0;
1430
+ s0 = peg$FAILED;
1431
+ }
1432
+ return s0;
1433
+ }
1434
+ function peg$parsedecoratorValue() {
1435
+ var s0, s1;
1436
+ s0 = peg$currPos;
1437
+ s1 = peg$parsestringLiteral();
1438
+ if (s1 !== peg$FAILED) {
1439
+ peg$savedPos = s0;
1440
+ s1 = peg$f24(s1);
1441
+ }
1442
+ s0 = s1;
1443
+ if (s0 === peg$FAILED) {
1444
+ s0 = peg$currPos;
1445
+ s1 = peg$parseidentifier();
1446
+ if (s1 !== peg$FAILED) {
1447
+ peg$savedPos = s0;
1448
+ s1 = peg$f25(s1);
1449
+ }
1450
+ s0 = s1;
1451
+ }
1452
+ return s0;
1453
+ }
1454
+ function peg$parsestringLiteral() {
1455
+ var s0, s1, s2, s3;
1456
+ s0 = peg$currPos;
1457
+ if (input.charCodeAt(peg$currPos) === 34) {
1458
+ s1 = peg$c20;
1459
+ peg$currPos++;
1460
+ } else {
1461
+ s1 = peg$FAILED;
1462
+ if (peg$silentFails === 0) {
1463
+ peg$fail(peg$e20);
1464
+ }
1465
+ }
1466
+ if (s1 !== peg$FAILED) {
1467
+ s2 = [];
1468
+ s3 = peg$parsechar();
1469
+ while (s3 !== peg$FAILED) {
1470
+ s2.push(s3);
1471
+ s3 = peg$parsechar();
1472
+ }
1473
+ if (input.charCodeAt(peg$currPos) === 34) {
1474
+ s3 = peg$c20;
1475
+ peg$currPos++;
1476
+ } else {
1477
+ s3 = peg$FAILED;
1478
+ if (peg$silentFails === 0) {
1479
+ peg$fail(peg$e20);
1480
+ }
1481
+ }
1482
+ if (s3 !== peg$FAILED) {
1483
+ peg$savedPos = s0;
1484
+ s0 = peg$f26(s2);
1485
+ } else {
1486
+ peg$currPos = s0;
1487
+ s0 = peg$FAILED;
1488
+ }
1489
+ } else {
1490
+ peg$currPos = s0;
1491
+ s0 = peg$FAILED;
1492
+ }
1493
+ return s0;
1494
+ }
1495
+ function peg$parsechar() {
1496
+ var s0, s1, s2;
1497
+ s0 = input.charAt(peg$currPos);
1498
+ if (peg$r0.test(s0)) {
1499
+ peg$currPos++;
1500
+ } else {
1501
+ s0 = peg$FAILED;
1502
+ if (peg$silentFails === 0) {
1503
+ peg$fail(peg$e21);
1504
+ }
1505
+ }
1506
+ if (s0 === peg$FAILED) {
1507
+ s0 = peg$currPos;
1508
+ if (input.charCodeAt(peg$currPos) === 92) {
1509
+ s1 = peg$c21;
1510
+ peg$currPos++;
1511
+ } else {
1512
+ s1 = peg$FAILED;
1513
+ if (peg$silentFails === 0) {
1514
+ peg$fail(peg$e22);
1515
+ }
1516
+ }
1517
+ if (s1 !== peg$FAILED) {
1518
+ if (input.charCodeAt(peg$currPos) === 34) {
1519
+ s2 = peg$c20;
1520
+ peg$currPos++;
1521
+ } else {
1522
+ s2 = peg$FAILED;
1523
+ if (peg$silentFails === 0) {
1524
+ peg$fail(peg$e20);
1525
+ }
1526
+ }
1527
+ if (s2 !== peg$FAILED) {
1528
+ peg$savedPos = s0;
1529
+ s0 = peg$f27();
1530
+ } else {
1531
+ peg$currPos = s0;
1532
+ s0 = peg$FAILED;
1533
+ }
1534
+ } else {
1535
+ peg$currPos = s0;
1536
+ s0 = peg$FAILED;
1537
+ }
1538
+ if (s0 === peg$FAILED) {
1539
+ s0 = peg$currPos;
1540
+ if (input.charCodeAt(peg$currPos) === 92) {
1541
+ s1 = peg$c21;
1542
+ peg$currPos++;
1543
+ } else {
1544
+ s1 = peg$FAILED;
1545
+ if (peg$silentFails === 0) {
1546
+ peg$fail(peg$e22);
1547
+ }
1548
+ }
1549
+ if (s1 !== peg$FAILED) {
1550
+ if (input.charCodeAt(peg$currPos) === 92) {
1551
+ s2 = peg$c21;
1552
+ peg$currPos++;
1553
+ } else {
1554
+ s2 = peg$FAILED;
1555
+ if (peg$silentFails === 0) {
1556
+ peg$fail(peg$e22);
1557
+ }
1558
+ }
1559
+ if (s2 !== peg$FAILED) {
1560
+ peg$savedPos = s0;
1561
+ s0 = peg$f28();
1562
+ } else {
1563
+ peg$currPos = s0;
1564
+ s0 = peg$FAILED;
1565
+ }
1566
+ } else {
1567
+ peg$currPos = s0;
1568
+ s0 = peg$FAILED;
1569
+ }
1570
+ if (s0 === peg$FAILED) {
1571
+ s0 = peg$currPos;
1572
+ if (input.charCodeAt(peg$currPos) === 92) {
1573
+ s1 = peg$c21;
1574
+ peg$currPos++;
1575
+ } else {
1576
+ s1 = peg$FAILED;
1577
+ if (peg$silentFails === 0) {
1578
+ peg$fail(peg$e22);
1579
+ }
1580
+ }
1581
+ if (s1 !== peg$FAILED) {
1582
+ if (input.charCodeAt(peg$currPos) === 110) {
1583
+ s2 = peg$c22;
1584
+ peg$currPos++;
1585
+ } else {
1586
+ s2 = peg$FAILED;
1587
+ if (peg$silentFails === 0) {
1588
+ peg$fail(peg$e23);
1589
+ }
1590
+ }
1591
+ if (s2 !== peg$FAILED) {
1592
+ peg$savedPos = s0;
1593
+ s0 = peg$f29();
1594
+ } else {
1595
+ peg$currPos = s0;
1596
+ s0 = peg$FAILED;
1597
+ }
1598
+ } else {
1599
+ peg$currPos = s0;
1600
+ s0 = peg$FAILED;
1601
+ }
1602
+ }
1603
+ }
1604
+ }
1605
+ return s0;
1606
+ }
1607
+ function peg$parseidentifier() {
1608
+ var s0, s1, s2, s3;
1609
+ peg$silentFails++;
1610
+ s0 = peg$currPos;
1611
+ s1 = input.charAt(peg$currPos);
1612
+ if (peg$r1.test(s1)) {
1613
+ peg$currPos++;
1614
+ } else {
1615
+ s1 = peg$FAILED;
1616
+ if (peg$silentFails === 0) {
1617
+ peg$fail(peg$e25);
1618
+ }
1619
+ }
1620
+ if (s1 !== peg$FAILED) {
1621
+ s2 = [];
1622
+ s3 = input.charAt(peg$currPos);
1623
+ if (peg$r2.test(s3)) {
1624
+ peg$currPos++;
1625
+ } else {
1626
+ s3 = peg$FAILED;
1627
+ if (peg$silentFails === 0) {
1628
+ peg$fail(peg$e26);
1629
+ }
1630
+ }
1631
+ while (s3 !== peg$FAILED) {
1632
+ s2.push(s3);
1633
+ s3 = input.charAt(peg$currPos);
1634
+ if (peg$r2.test(s3)) {
1635
+ peg$currPos++;
1636
+ } else {
1637
+ s3 = peg$FAILED;
1638
+ if (peg$silentFails === 0) {
1639
+ peg$fail(peg$e26);
1640
+ }
1641
+ }
1642
+ }
1643
+ peg$savedPos = s0;
1644
+ s0 = peg$f30(s1, s2);
1645
+ } else {
1646
+ peg$currPos = s0;
1647
+ s0 = peg$FAILED;
1648
+ }
1649
+ peg$silentFails--;
1650
+ if (s0 === peg$FAILED) {
1651
+ s1 = peg$FAILED;
1652
+ if (peg$silentFails === 0) {
1653
+ peg$fail(peg$e24);
1654
+ }
1655
+ }
1656
+ return s0;
1657
+ }
1658
+ function peg$parse_() {
1659
+ var s0, s1;
1660
+ s0 = [];
1661
+ s1 = peg$parsewhitespace();
1662
+ if (s1 === peg$FAILED) {
1663
+ s1 = peg$parselineComment();
1664
+ }
1665
+ while (s1 !== peg$FAILED) {
1666
+ s0.push(s1);
1667
+ s1 = peg$parsewhitespace();
1668
+ if (s1 === peg$FAILED) {
1669
+ s1 = peg$parselineComment();
1670
+ }
1671
+ }
1672
+ return s0;
1673
+ }
1674
+ function peg$parse__() {
1675
+ var s0, s1;
1676
+ s0 = [];
1677
+ s1 = peg$parsewhitespace();
1678
+ if (s1 === peg$FAILED) {
1679
+ s1 = peg$parselineComment();
1680
+ }
1681
+ if (s1 !== peg$FAILED) {
1682
+ while (s1 !== peg$FAILED) {
1683
+ s0.push(s1);
1684
+ s1 = peg$parsewhitespace();
1685
+ if (s1 === peg$FAILED) {
1686
+ s1 = peg$parselineComment();
1687
+ }
1688
+ }
1689
+ } else {
1690
+ s0 = peg$FAILED;
1691
+ }
1692
+ return s0;
1693
+ }
1694
+ function peg$parsewhitespace() {
1695
+ var s0, s1;
1696
+ s0 = [];
1697
+ s1 = input.charAt(peg$currPos);
1698
+ if (peg$r3.test(s1)) {
1699
+ peg$currPos++;
1700
+ } else {
1701
+ s1 = peg$FAILED;
1702
+ if (peg$silentFails === 0) {
1703
+ peg$fail(peg$e27);
1704
+ }
1705
+ }
1706
+ if (s1 !== peg$FAILED) {
1707
+ while (s1 !== peg$FAILED) {
1708
+ s0.push(s1);
1709
+ s1 = input.charAt(peg$currPos);
1710
+ if (peg$r3.test(s1)) {
1711
+ peg$currPos++;
1712
+ } else {
1713
+ s1 = peg$FAILED;
1714
+ if (peg$silentFails === 0) {
1715
+ peg$fail(peg$e27);
1716
+ }
1717
+ }
1718
+ }
1719
+ } else {
1720
+ s0 = peg$FAILED;
1721
+ }
1722
+ return s0;
1723
+ }
1724
+ function peg$parselineComment() {
1725
+ var s0, s1, s2, s3, s4, s5;
1726
+ s0 = peg$currPos;
1727
+ if (input.substr(peg$currPos, 2) === peg$c23) {
1728
+ s1 = peg$c23;
1729
+ peg$currPos += 2;
1730
+ } else {
1731
+ s1 = peg$FAILED;
1732
+ if (peg$silentFails === 0) {
1733
+ peg$fail(peg$e28);
1734
+ }
1735
+ }
1736
+ if (s1 !== peg$FAILED) {
1737
+ s2 = [];
1738
+ s3 = peg$currPos;
1739
+ s4 = peg$currPos;
1740
+ peg$silentFails++;
1741
+ s5 = input.charAt(peg$currPos);
1742
+ if (peg$r4.test(s5)) {
1743
+ peg$currPos++;
1744
+ } else {
1745
+ s5 = peg$FAILED;
1746
+ if (peg$silentFails === 0) {
1747
+ peg$fail(peg$e29);
1748
+ }
1749
+ }
1750
+ peg$silentFails--;
1751
+ if (s5 === peg$FAILED) {
1752
+ s4 = void 0;
1753
+ } else {
1754
+ peg$currPos = s4;
1755
+ s4 = peg$FAILED;
1756
+ }
1757
+ if (s4 !== peg$FAILED) {
1758
+ if (input.length > peg$currPos) {
1759
+ s5 = input.charAt(peg$currPos);
1760
+ peg$currPos++;
1761
+ } else {
1762
+ s5 = peg$FAILED;
1763
+ if (peg$silentFails === 0) {
1764
+ peg$fail(peg$e30);
1765
+ }
1766
+ }
1767
+ if (s5 !== peg$FAILED) {
1768
+ s4 = [s4, s5];
1769
+ s3 = s4;
1770
+ } else {
1771
+ peg$currPos = s3;
1772
+ s3 = peg$FAILED;
1773
+ }
1774
+ } else {
1775
+ peg$currPos = s3;
1776
+ s3 = peg$FAILED;
1777
+ }
1778
+ while (s3 !== peg$FAILED) {
1779
+ s2.push(s3);
1780
+ s3 = peg$currPos;
1781
+ s4 = peg$currPos;
1782
+ peg$silentFails++;
1783
+ s5 = input.charAt(peg$currPos);
1784
+ if (peg$r4.test(s5)) {
1785
+ peg$currPos++;
1786
+ } else {
1787
+ s5 = peg$FAILED;
1788
+ if (peg$silentFails === 0) {
1789
+ peg$fail(peg$e29);
1790
+ }
1791
+ }
1792
+ peg$silentFails--;
1793
+ if (s5 === peg$FAILED) {
1794
+ s4 = void 0;
1795
+ } else {
1796
+ peg$currPos = s4;
1797
+ s4 = peg$FAILED;
1798
+ }
1799
+ if (s4 !== peg$FAILED) {
1800
+ if (input.length > peg$currPos) {
1801
+ s5 = input.charAt(peg$currPos);
1802
+ peg$currPos++;
1803
+ } else {
1804
+ s5 = peg$FAILED;
1805
+ if (peg$silentFails === 0) {
1806
+ peg$fail(peg$e30);
1807
+ }
1808
+ }
1809
+ if (s5 !== peg$FAILED) {
1810
+ s4 = [s4, s5];
1811
+ s3 = s4;
1812
+ } else {
1813
+ peg$currPos = s3;
1814
+ s3 = peg$FAILED;
1815
+ }
1816
+ } else {
1817
+ peg$currPos = s3;
1818
+ s3 = peg$FAILED;
1819
+ }
1820
+ }
1821
+ s1 = [s1, s2];
1822
+ s0 = s1;
1823
+ } else {
1824
+ peg$currPos = s0;
1825
+ s0 = peg$FAILED;
1826
+ }
1827
+ return s0;
1828
+ }
1829
+ peg$result = peg$startRuleFunction();
1830
+ if (options.peg$library) {
1831
+ return (
1832
+ /** @type {any} */
1833
+ {
1834
+ peg$result,
1835
+ peg$currPos,
1836
+ peg$FAILED,
1837
+ peg$maxFailExpected,
1838
+ peg$maxFailPos
1839
+ }
1840
+ );
1841
+ }
1842
+ if (peg$result !== peg$FAILED && peg$currPos === input.length) {
1843
+ return peg$result;
1844
+ } else {
1845
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1846
+ peg$fail(peg$endExpectation());
1847
+ }
1848
+ throw peg$buildStructuredError(
1849
+ peg$maxFailExpected,
1850
+ peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
1851
+ peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
1852
+ );
1853
+ }
1854
+ }
1855
+
1856
+ // src/validate.ts
1857
+ function hasDecoratorNamed(decorators, name) {
1858
+ return decorators.some((d) => d.name === name);
1859
+ }
1860
+ function countIdFields(node) {
1861
+ let n = 0;
1862
+ for (const f of node.fields) {
1863
+ if (f.kind === "Scalar" && hasDecoratorNamed(f.decorators, "id")) {
1864
+ n += 1;
1865
+ }
1866
+ }
1867
+ return n;
1868
+ }
1869
+ function decoratorCount(decorators, name) {
1870
+ return decorators.filter((d) => d.name === name).length;
1871
+ }
1872
+ function validateSchema(doc) {
1873
+ for (const decl of doc.declarations) {
1874
+ if (decl.kind === "Node") {
1875
+ const idCount = countIdFields(decl);
1876
+ if (idCount > 1) {
1877
+ throw new SchemaValidationError(
1878
+ `Node "${decl.name}" must have at most one @id field (found ${idCount}).`
1879
+ );
1880
+ }
1881
+ for (const f of decl.fields) {
1882
+ if (f.kind !== "Scalar") {
1883
+ continue;
1884
+ }
1885
+ const idx = decoratorCount(f.decorators, "index");
1886
+ if (idx > 1) {
1887
+ throw new SchemaValidationError(
1888
+ `Node "${decl.name}" field "${f.name}": at most one @index allowed (found ${idx}).`
1889
+ );
1890
+ }
1891
+ if (idx === 0) {
1892
+ continue;
1893
+ }
1894
+ if (hasDecoratorNamed(f.decorators, "unique")) {
1895
+ throw new SchemaValidationError(
1896
+ `Node "${decl.name}" field "${f.name}": @index is redundant with @unique (unique constraints are indexed).`
1897
+ );
1898
+ }
1899
+ if (hasDecoratorNamed(f.decorators, "id")) {
1900
+ throw new SchemaValidationError(
1901
+ `Node "${decl.name}" field "${f.name}": @index is redundant with @id (id uniqueness is indexed).`
1902
+ );
1903
+ }
1904
+ }
1905
+ continue;
1906
+ }
1907
+ for (const f of decl.fields) {
1908
+ const idx = decoratorCount(f.decorators, "index");
1909
+ const uniq = decoratorCount(f.decorators, "unique");
1910
+ if (idx > 1) {
1911
+ throw new SchemaValidationError(
1912
+ `Relationship "${decl.name}" field "${f.name}": at most one @index allowed (found ${idx}).`
1913
+ );
1914
+ }
1915
+ if (uniq > 1) {
1916
+ throw new SchemaValidationError(
1917
+ `Relationship "${decl.name}" field "${f.name}": at most one @unique allowed (found ${uniq}).`
1918
+ );
1919
+ }
1920
+ if (idx > 0 && uniq > 0) {
1921
+ throw new SchemaValidationError(
1922
+ `Relationship "${decl.name}" field "${f.name}": @index is redundant with @unique (unique constraints are indexed).`
1923
+ );
1924
+ }
1925
+ if (hasDecoratorNamed(f.decorators, "id")) {
1926
+ throw new SchemaValidationError(
1927
+ `Relationship "${decl.name}" field "${f.name}": @id is only valid on node scalar fields.`
1928
+ );
1929
+ }
1930
+ }
1931
+ }
1932
+ }
1933
+
1934
+ // src/parseSchema.ts
1935
+ var MAX_SCHEMA_BYTES = 512 * 1024;
1936
+ function parseSchema(source) {
1937
+ const bytes = Buffer.byteLength(source, "utf8");
1938
+ if (bytes > MAX_SCHEMA_BYTES) {
1939
+ throw new SchemaValidationError(
1940
+ `Schema exceeds maximum size of ${MAX_SCHEMA_BYTES} bytes (got ${bytes}).`
1941
+ );
1942
+ }
1943
+ const doc = peg$parse(source);
1944
+ validateSchema(doc);
1945
+ return doc;
1946
+ }
1947
+
1948
+ // src/readSchemaFile.ts
1949
+ import { readFile } from "fs/promises";
1950
+ async function parseSchemaFile(path) {
1951
+ const source = await readFile(path, "utf8");
1952
+ return parseSchema(source);
1953
+ }
1954
+
1955
+ // src/renderCyphraGen.ts
1956
+ function decoratorStringArg(decorators, decoratorName, argKey) {
1957
+ const dec = decorators.find((d) => d.name === decoratorName);
1958
+ if (!dec) {
1959
+ return void 0;
1960
+ }
1961
+ const arg = dec.args.find((a) => a.key === argKey);
1962
+ if (!arg || arg.value.kind !== "string") {
1963
+ return void 0;
1964
+ }
1965
+ return arg.value.value;
1966
+ }
1967
+ function collectCodegenModel(doc) {
1968
+ const nodeLabels = [];
1969
+ const relationshipModels = [];
1970
+ const relTypes = /* @__PURE__ */ new Set();
1971
+ for (const decl of doc.declarations) {
1972
+ if (decl.kind === "Node") {
1973
+ nodeLabels.push(decl.name);
1974
+ for (const f of decl.fields) {
1975
+ if (f.kind === "Relational") {
1976
+ const t = decoratorStringArg(f.decorators, "relationship", "type");
1977
+ if (t) {
1978
+ relTypes.add(t);
1979
+ }
1980
+ }
1981
+ }
1982
+ } else {
1983
+ relationshipModels.push({
1984
+ name: decl.name,
1985
+ neo4jType: decl.relType,
1986
+ fromLabel: decl.from,
1987
+ toLabel: decl.to
1988
+ });
1989
+ relTypes.add(decl.relType);
1990
+ }
1991
+ }
1992
+ return {
1993
+ nodeLabels,
1994
+ relationshipModels,
1995
+ relNeo4jTypes: [...relTypes].sort()
1996
+ };
1997
+ }
1998
+ function relTypeToExportKey(type, used) {
1999
+ let base = type.replace(/[^A-Za-z0-9_]/g, "_");
2000
+ if (!base || /^[0-9]/.test(base)) {
2001
+ base = `T_${base || "rel"}`;
2002
+ }
2003
+ let key = base;
2004
+ let n = 2;
2005
+ while (used.has(key)) {
2006
+ key = `${base}_${n++}`;
2007
+ }
2008
+ used.add(key);
2009
+ return key;
2010
+ }
2011
+ function renderCyphraGenSource(doc) {
2012
+ const model = collectCodegenModel(doc);
2013
+ const lines = [];
2014
+ lines.push("/**");
2015
+ lines.push(" * Generated by `cyphra generate` \u2014 do not edit by hand.");
2016
+ lines.push(" */");
2017
+ lines.push("");
2018
+ lines.push("/** Neo4j node labels from `node` declarations. */");
2019
+ lines.push("export const NodeLabel = {");
2020
+ for (const L of model.nodeLabels) {
2021
+ lines.push(` ${L}: ${JSON.stringify(L)},`);
2022
+ }
2023
+ lines.push("} as const;");
2024
+ lines.push("");
2025
+ lines.push("export type NodeLabelName = keyof typeof NodeLabel;");
2026
+ lines.push("");
2027
+ lines.push("/** Rich `relationship { \u2026 }` blocks: Neo4j type + endpoint labels. */");
2028
+ lines.push("export const RelationshipSpec = {");
2029
+ for (const r of model.relationshipModels) {
2030
+ lines.push(` ${r.name}: {`);
2031
+ lines.push(` neo4jType: ${JSON.stringify(r.neo4jType)},`);
2032
+ lines.push(` fromLabel: ${JSON.stringify(r.fromLabel)},`);
2033
+ lines.push(` toLabel: ${JSON.stringify(r.toLabel)},`);
2034
+ lines.push(` },`);
2035
+ }
2036
+ lines.push("} as const;");
2037
+ lines.push("");
2038
+ lines.push("export type RelationshipModelName = keyof typeof RelationshipSpec;");
2039
+ lines.push("");
2040
+ lines.push("/** Distinct Neo4j relationship types used on fields or declarations. */");
2041
+ lines.push("export const RelType = {");
2042
+ const usedKeys = /* @__PURE__ */ new Set();
2043
+ for (const t of model.relNeo4jTypes) {
2044
+ const key = relTypeToExportKey(t, usedKeys);
2045
+ lines.push(` ${key}: ${JSON.stringify(t)},`);
2046
+ }
2047
+ lines.push("} as const;");
2048
+ lines.push("");
2049
+ lines.push("export type RelTypeKey = keyof typeof RelType;");
2050
+ lines.push("");
2051
+ return lines.join("\n");
2052
+ }
2053
+ export {
2054
+ MAX_SCHEMA_BYTES,
2055
+ SchemaValidationError,
2056
+ collectCodegenModel,
2057
+ formatDecorator,
2058
+ parseSchema,
2059
+ parseSchemaFile,
2060
+ printSchemaDocument,
2061
+ relTypeToExportKey,
2062
+ renderCyphraGenSource,
2063
+ validateSchema
2064
+ };
2065
+ //# sourceMappingURL=index.js.map