@cyphra/schema 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11,13 +11,16 @@ var SchemaValidationError = class extends Error {
11
11
 
12
12
  // src/printSchema.ts
13
13
  function formatScalarType(t) {
14
+ if (t.list) {
15
+ return `${t.name}[]`;
16
+ }
14
17
  return t.optional ? `${t.name}?` : t.name;
15
18
  }
16
19
  function formatDecoratorValue(v) {
17
20
  if (v.kind === "string") {
18
21
  return JSON.stringify(v.value);
19
22
  }
20
- return v.value;
23
+ return String(v.value);
21
24
  }
22
25
  function formatDecorator(d) {
23
26
  if (d.name === "default") {
@@ -25,6 +28,10 @@ function formatDecorator(d) {
25
28
  if (fnArg && fnArg.value.kind === "identifier") {
26
29
  return `@default(${fnArg.value.value}())`;
27
30
  }
31
+ const valueArg = d.args.find((a) => a.key === "value");
32
+ if (valueArg) {
33
+ return `@default(${formatDecoratorValue(valueArg.value)})`;
34
+ }
28
35
  }
29
36
  if (d.args.length === 0) {
30
37
  return `@${d.name}`;
@@ -220,21 +227,27 @@ function peg$parse(input, options) {
220
227
  var peg$c11 = "Float";
221
228
  var peg$c12 = "Boolean";
222
229
  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]/;
230
+ var peg$c14 = "Date";
231
+ var peg$c15 = "@";
232
+ var peg$c16 = "default";
233
+ var peg$c17 = "(";
234
+ var peg$c18 = ")";
235
+ var peg$c19 = ",";
236
+ var peg$c20 = ":";
237
+ var peg$c21 = "true";
238
+ var peg$c22 = "false";
239
+ var peg$c23 = "-";
240
+ var peg$c24 = ".";
241
+ var peg$c25 = '"';
242
+ var peg$c26 = "\\";
243
+ var peg$c27 = "n";
244
+ var peg$c28 = "//";
245
+ var peg$r0 = /^[a-zA-Z0-9_]/;
246
+ var peg$r1 = /^[0-9]/;
247
+ var peg$r2 = /^[^"\\]/;
248
+ var peg$r3 = /^[a-zA-Z_]/;
249
+ var peg$r4 = /^[ \t\n\r]/;
250
+ var peg$r5 = /^[\n\r]/;
238
251
  var peg$e0 = peg$literalExpectation("node", false);
239
252
  var peg$e1 = peg$literalExpectation("{", false);
240
253
  var peg$e2 = peg$literalExpectation("}", false);
@@ -249,23 +262,29 @@ function peg$parse(input, options) {
249
262
  var peg$e11 = peg$literalExpectation("Float", false);
250
263
  var peg$e12 = peg$literalExpectation("Boolean", false);
251
264
  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();
265
+ var peg$e14 = peg$literalExpectation("Date", false);
266
+ var peg$e15 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_"], false, false);
267
+ var peg$e16 = peg$literalExpectation("@", false);
268
+ var peg$e17 = peg$literalExpectation("default", false);
269
+ var peg$e18 = peg$literalExpectation("(", false);
270
+ var peg$e19 = peg$literalExpectation(")", false);
271
+ var peg$e20 = peg$literalExpectation(",", false);
272
+ var peg$e21 = peg$literalExpectation(":", false);
273
+ var peg$e22 = peg$literalExpectation("true", false);
274
+ var peg$e23 = peg$literalExpectation("false", false);
275
+ var peg$e24 = peg$literalExpectation("-", false);
276
+ var peg$e25 = peg$classExpectation([["0", "9"]], false, false);
277
+ var peg$e26 = peg$literalExpectation(".", false);
278
+ var peg$e27 = peg$literalExpectation('"', false);
279
+ var peg$e28 = peg$classExpectation(['"', "\\"], true, false);
280
+ var peg$e29 = peg$literalExpectation("\\", false);
281
+ var peg$e30 = peg$literalExpectation("n", false);
282
+ var peg$e31 = peg$otherExpectation("identifier");
283
+ var peg$e32 = peg$classExpectation([["a", "z"], ["A", "Z"], "_"], false, false);
284
+ var peg$e33 = peg$classExpectation([" ", " ", "\n", "\r"], false, false);
285
+ var peg$e34 = peg$literalExpectation("//", false);
286
+ var peg$e35 = peg$classExpectation(["\n", "\r"], false, false);
287
+ var peg$e36 = peg$anyExpectation();
269
288
  var peg$f0 = function(decls) {
270
289
  return { kind: "Document", declarations: decls };
271
290
  };
@@ -316,47 +335,47 @@ function peg$parse(input, options) {
316
335
  var peg$f11 = function(name, type, decs) {
317
336
  return { kind: "Scalar", name, type, decorators: decs };
318
337
  };
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";
338
+ var peg$f12 = function(n) {
339
+ return { name: n, optional: false, list: true };
330
340
  };
331
- var peg$f16 = function() {
332
- return "Boolean";
341
+ var peg$f13 = function(n, opt) {
342
+ return { name: n, optional: opt === "?" };
333
343
  };
334
- var peg$f17 = function() {
335
- return "DateTime";
344
+ var peg$f14 = function(n) {
345
+ return n;
336
346
  };
337
- var peg$f18 = function(id) {
347
+ var peg$f15 = function(id) {
338
348
  return { name: "default", args: [{ key: "fn", value: { kind: "identifier", value: id } }] };
339
349
  };
340
- var peg$f19 = function(name, args) {
350
+ var peg$f16 = function(v) {
351
+ return { name: "default", args: [{ key: "value", value: v }] };
352
+ };
353
+ var peg$f17 = function(name, args) {
341
354
  return { name, args };
342
355
  };
343
- var peg$f20 = function(name) {
356
+ var peg$f18 = function(name) {
344
357
  return { name, args: [] };
345
358
  };
346
- var peg$f21 = function(head, tail) {
359
+ var peg$f19 = function(head, tail) {
347
360
  return [head, ...tail];
348
361
  };
349
- var peg$f22 = function() {
362
+ var peg$f20 = function() {
350
363
  return [];
351
364
  };
352
- var peg$f23 = function(key, val) {
365
+ var peg$f21 = function(key, val) {
353
366
  return { key, value: val };
354
367
  };
355
- var peg$f24 = function(s) {
368
+ var peg$f22 = function(id) {
369
+ return { kind: "identifier", value: id };
370
+ };
371
+ var peg$f23 = function(s) {
356
372
  return { kind: "string", value: s };
357
373
  };
358
- var peg$f25 = function(id) {
359
- return { kind: "identifier", value: id };
374
+ var peg$f24 = function(b) {
375
+ return { kind: "boolean", value: b === "true" };
376
+ };
377
+ var peg$f25 = function(n) {
378
+ return { kind: "number", value: Number(n) };
360
379
  };
361
380
  var peg$f26 = function(chars) {
362
381
  return chars.join("");
@@ -1031,28 +1050,53 @@ function peg$parse(input, options) {
1031
1050
  s0 = peg$currPos;
1032
1051
  s1 = peg$parsescalarTypeName();
1033
1052
  if (s1 !== peg$FAILED) {
1034
- if (input.charCodeAt(peg$currPos) === 63) {
1035
- s2 = peg$c8;
1036
- peg$currPos++;
1053
+ if (input.substr(peg$currPos, 2) === peg$c7) {
1054
+ s2 = peg$c7;
1055
+ peg$currPos += 2;
1037
1056
  } else {
1038
1057
  s2 = peg$FAILED;
1039
1058
  if (peg$silentFails === 0) {
1040
- peg$fail(peg$e8);
1059
+ peg$fail(peg$e7);
1041
1060
  }
1042
1061
  }
1043
- if (s2 === peg$FAILED) {
1044
- s2 = null;
1062
+ if (s2 !== peg$FAILED) {
1063
+ peg$savedPos = s0;
1064
+ s0 = peg$f12(s1);
1065
+ } else {
1066
+ peg$currPos = s0;
1067
+ s0 = peg$FAILED;
1045
1068
  }
1046
- peg$savedPos = s0;
1047
- s0 = peg$f12(s1, s2);
1048
1069
  } else {
1049
1070
  peg$currPos = s0;
1050
1071
  s0 = peg$FAILED;
1051
1072
  }
1073
+ if (s0 === peg$FAILED) {
1074
+ s0 = peg$currPos;
1075
+ s1 = peg$parsescalarTypeName();
1076
+ if (s1 !== peg$FAILED) {
1077
+ if (input.charCodeAt(peg$currPos) === 63) {
1078
+ s2 = peg$c8;
1079
+ peg$currPos++;
1080
+ } else {
1081
+ s2 = peg$FAILED;
1082
+ if (peg$silentFails === 0) {
1083
+ peg$fail(peg$e8);
1084
+ }
1085
+ }
1086
+ if (s2 === peg$FAILED) {
1087
+ s2 = null;
1088
+ }
1089
+ peg$savedPos = s0;
1090
+ s0 = peg$f13(s1, s2);
1091
+ } else {
1092
+ peg$currPos = s0;
1093
+ s0 = peg$FAILED;
1094
+ }
1095
+ }
1052
1096
  return s0;
1053
1097
  }
1054
1098
  function peg$parsescalarTypeName() {
1055
- var s0, s1;
1099
+ var s0, s1, s2, s3;
1056
1100
  s0 = peg$currPos;
1057
1101
  if (input.substr(peg$currPos, 6) === peg$c9) {
1058
1102
  s1 = peg$c9;
@@ -1063,13 +1107,7 @@ function peg$parse(input, options) {
1063
1107
  peg$fail(peg$e9);
1064
1108
  }
1065
1109
  }
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;
1110
+ if (s1 === peg$FAILED) {
1073
1111
  if (input.substr(peg$currPos, 3) === peg$c10) {
1074
1112
  s1 = peg$c10;
1075
1113
  peg$currPos += 3;
@@ -1079,13 +1117,7 @@ function peg$parse(input, options) {
1079
1117
  peg$fail(peg$e10);
1080
1118
  }
1081
1119
  }
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;
1120
+ if (s1 === peg$FAILED) {
1089
1121
  if (input.substr(peg$currPos, 5) === peg$c11) {
1090
1122
  s1 = peg$c11;
1091
1123
  peg$currPos += 5;
@@ -1095,13 +1127,7 @@ function peg$parse(input, options) {
1095
1127
  peg$fail(peg$e11);
1096
1128
  }
1097
1129
  }
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;
1130
+ if (s1 === peg$FAILED) {
1105
1131
  if (input.substr(peg$currPos, 7) === peg$c12) {
1106
1132
  s1 = peg$c12;
1107
1133
  peg$currPos += 7;
@@ -1111,13 +1137,7 @@ function peg$parse(input, options) {
1111
1137
  peg$fail(peg$e12);
1112
1138
  }
1113
1139
  }
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;
1140
+ if (s1 === peg$FAILED) {
1121
1141
  if (input.substr(peg$currPos, 8) === peg$c13) {
1122
1142
  s1 = peg$c13;
1123
1143
  peg$currPos += 8;
@@ -1127,47 +1147,83 @@ function peg$parse(input, options) {
1127
1147
  peg$fail(peg$e13);
1128
1148
  }
1129
1149
  }
1130
- if (s1 !== peg$FAILED) {
1131
- peg$savedPos = s0;
1132
- s1 = peg$f17();
1150
+ if (s1 === peg$FAILED) {
1151
+ if (input.substr(peg$currPos, 4) === peg$c14) {
1152
+ s1 = peg$c14;
1153
+ peg$currPos += 4;
1154
+ } else {
1155
+ s1 = peg$FAILED;
1156
+ if (peg$silentFails === 0) {
1157
+ peg$fail(peg$e14);
1158
+ }
1159
+ }
1133
1160
  }
1134
- s0 = s1;
1135
1161
  }
1136
1162
  }
1137
1163
  }
1138
1164
  }
1165
+ if (s1 !== peg$FAILED) {
1166
+ s2 = peg$currPos;
1167
+ peg$silentFails++;
1168
+ s3 = input.charAt(peg$currPos);
1169
+ if (peg$r0.test(s3)) {
1170
+ peg$currPos++;
1171
+ } else {
1172
+ s3 = peg$FAILED;
1173
+ if (peg$silentFails === 0) {
1174
+ peg$fail(peg$e15);
1175
+ }
1176
+ }
1177
+ peg$silentFails--;
1178
+ if (s3 === peg$FAILED) {
1179
+ s2 = void 0;
1180
+ } else {
1181
+ peg$currPos = s2;
1182
+ s2 = peg$FAILED;
1183
+ }
1184
+ if (s2 !== peg$FAILED) {
1185
+ peg$savedPos = s0;
1186
+ s0 = peg$f14(s1);
1187
+ } else {
1188
+ peg$currPos = s0;
1189
+ s0 = peg$FAILED;
1190
+ }
1191
+ } else {
1192
+ peg$currPos = s0;
1193
+ s0 = peg$FAILED;
1194
+ }
1139
1195
  return s0;
1140
1196
  }
1141
1197
  function peg$parsedecorator() {
1142
1198
  var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
1143
1199
  s0 = peg$currPos;
1144
1200
  if (input.charCodeAt(peg$currPos) === 64) {
1145
- s1 = peg$c14;
1201
+ s1 = peg$c15;
1146
1202
  peg$currPos++;
1147
1203
  } else {
1148
1204
  s1 = peg$FAILED;
1149
1205
  if (peg$silentFails === 0) {
1150
- peg$fail(peg$e14);
1206
+ peg$fail(peg$e16);
1151
1207
  }
1152
1208
  }
1153
1209
  if (s1 !== peg$FAILED) {
1154
- if (input.substr(peg$currPos, 7) === peg$c15) {
1155
- s2 = peg$c15;
1210
+ if (input.substr(peg$currPos, 7) === peg$c16) {
1211
+ s2 = peg$c16;
1156
1212
  peg$currPos += 7;
1157
1213
  } else {
1158
1214
  s2 = peg$FAILED;
1159
1215
  if (peg$silentFails === 0) {
1160
- peg$fail(peg$e15);
1216
+ peg$fail(peg$e17);
1161
1217
  }
1162
1218
  }
1163
1219
  if (s2 !== peg$FAILED) {
1164
1220
  if (input.charCodeAt(peg$currPos) === 40) {
1165
- s3 = peg$c16;
1221
+ s3 = peg$c17;
1166
1222
  peg$currPos++;
1167
1223
  } else {
1168
1224
  s3 = peg$FAILED;
1169
1225
  if (peg$silentFails === 0) {
1170
- peg$fail(peg$e16);
1226
+ peg$fail(peg$e18);
1171
1227
  }
1172
1228
  }
1173
1229
  if (s3 !== peg$FAILED) {
@@ -1175,39 +1231,39 @@ function peg$parse(input, options) {
1175
1231
  s5 = peg$parseidentifier();
1176
1232
  if (s5 !== peg$FAILED) {
1177
1233
  if (input.charCodeAt(peg$currPos) === 40) {
1178
- s6 = peg$c16;
1234
+ s6 = peg$c17;
1179
1235
  peg$currPos++;
1180
1236
  } else {
1181
1237
  s6 = peg$FAILED;
1182
1238
  if (peg$silentFails === 0) {
1183
- peg$fail(peg$e16);
1239
+ peg$fail(peg$e18);
1184
1240
  }
1185
1241
  }
1186
1242
  if (s6 !== peg$FAILED) {
1187
1243
  s7 = peg$parse_();
1188
1244
  if (input.charCodeAt(peg$currPos) === 41) {
1189
- s8 = peg$c17;
1245
+ s8 = peg$c18;
1190
1246
  peg$currPos++;
1191
1247
  } else {
1192
1248
  s8 = peg$FAILED;
1193
1249
  if (peg$silentFails === 0) {
1194
- peg$fail(peg$e17);
1250
+ peg$fail(peg$e19);
1195
1251
  }
1196
1252
  }
1197
1253
  if (s8 !== peg$FAILED) {
1198
1254
  s9 = peg$parse_();
1199
1255
  if (input.charCodeAt(peg$currPos) === 41) {
1200
- s10 = peg$c17;
1256
+ s10 = peg$c18;
1201
1257
  peg$currPos++;
1202
1258
  } else {
1203
1259
  s10 = peg$FAILED;
1204
1260
  if (peg$silentFails === 0) {
1205
- peg$fail(peg$e17);
1261
+ peg$fail(peg$e19);
1206
1262
  }
1207
1263
  }
1208
1264
  if (s10 !== peg$FAILED) {
1209
1265
  peg$savedPos = s0;
1210
- s0 = peg$f18(s5);
1266
+ s0 = peg$f15(s5);
1211
1267
  } else {
1212
1268
  peg$currPos = s0;
1213
1269
  s0 = peg$FAILED;
@@ -1239,43 +1295,51 @@ function peg$parse(input, options) {
1239
1295
  if (s0 === peg$FAILED) {
1240
1296
  s0 = peg$currPos;
1241
1297
  if (input.charCodeAt(peg$currPos) === 64) {
1242
- s1 = peg$c14;
1298
+ s1 = peg$c15;
1243
1299
  peg$currPos++;
1244
1300
  } else {
1245
1301
  s1 = peg$FAILED;
1246
1302
  if (peg$silentFails === 0) {
1247
- peg$fail(peg$e14);
1303
+ peg$fail(peg$e16);
1248
1304
  }
1249
1305
  }
1250
1306
  if (s1 !== peg$FAILED) {
1251
- s2 = peg$parseidentifier();
1307
+ if (input.substr(peg$currPos, 7) === peg$c16) {
1308
+ s2 = peg$c16;
1309
+ peg$currPos += 7;
1310
+ } else {
1311
+ s2 = peg$FAILED;
1312
+ if (peg$silentFails === 0) {
1313
+ peg$fail(peg$e17);
1314
+ }
1315
+ }
1252
1316
  if (s2 !== peg$FAILED) {
1253
1317
  if (input.charCodeAt(peg$currPos) === 40) {
1254
- s3 = peg$c16;
1318
+ s3 = peg$c17;
1255
1319
  peg$currPos++;
1256
1320
  } else {
1257
1321
  s3 = peg$FAILED;
1258
1322
  if (peg$silentFails === 0) {
1259
- peg$fail(peg$e16);
1323
+ peg$fail(peg$e18);
1260
1324
  }
1261
1325
  }
1262
1326
  if (s3 !== peg$FAILED) {
1263
1327
  s4 = peg$parse_();
1264
- s5 = peg$parsedecoratorArgs();
1328
+ s5 = peg$parseliteralValue();
1265
1329
  if (s5 !== peg$FAILED) {
1266
1330
  s6 = peg$parse_();
1267
1331
  if (input.charCodeAt(peg$currPos) === 41) {
1268
- s7 = peg$c17;
1332
+ s7 = peg$c18;
1269
1333
  peg$currPos++;
1270
1334
  } else {
1271
1335
  s7 = peg$FAILED;
1272
1336
  if (peg$silentFails === 0) {
1273
- peg$fail(peg$e17);
1337
+ peg$fail(peg$e19);
1274
1338
  }
1275
1339
  }
1276
1340
  if (s7 !== peg$FAILED) {
1277
1341
  peg$savedPos = s0;
1278
- s0 = peg$f19(s2, s5);
1342
+ s0 = peg$f16(s5);
1279
1343
  } else {
1280
1344
  peg$currPos = s0;
1281
1345
  s0 = peg$FAILED;
@@ -1299,19 +1363,55 @@ function peg$parse(input, options) {
1299
1363
  if (s0 === peg$FAILED) {
1300
1364
  s0 = peg$currPos;
1301
1365
  if (input.charCodeAt(peg$currPos) === 64) {
1302
- s1 = peg$c14;
1366
+ s1 = peg$c15;
1303
1367
  peg$currPos++;
1304
1368
  } else {
1305
1369
  s1 = peg$FAILED;
1306
1370
  if (peg$silentFails === 0) {
1307
- peg$fail(peg$e14);
1371
+ peg$fail(peg$e16);
1308
1372
  }
1309
1373
  }
1310
1374
  if (s1 !== peg$FAILED) {
1311
1375
  s2 = peg$parseidentifier();
1312
1376
  if (s2 !== peg$FAILED) {
1313
- peg$savedPos = s0;
1314
- s0 = peg$f20(s2);
1377
+ if (input.charCodeAt(peg$currPos) === 40) {
1378
+ s3 = peg$c17;
1379
+ peg$currPos++;
1380
+ } else {
1381
+ s3 = peg$FAILED;
1382
+ if (peg$silentFails === 0) {
1383
+ peg$fail(peg$e18);
1384
+ }
1385
+ }
1386
+ if (s3 !== peg$FAILED) {
1387
+ s4 = peg$parse_();
1388
+ s5 = peg$parsedecoratorArgs();
1389
+ if (s5 !== peg$FAILED) {
1390
+ s6 = peg$parse_();
1391
+ if (input.charCodeAt(peg$currPos) === 41) {
1392
+ s7 = peg$c18;
1393
+ peg$currPos++;
1394
+ } else {
1395
+ s7 = peg$FAILED;
1396
+ if (peg$silentFails === 0) {
1397
+ peg$fail(peg$e19);
1398
+ }
1399
+ }
1400
+ if (s7 !== peg$FAILED) {
1401
+ peg$savedPos = s0;
1402
+ s0 = peg$f17(s2, s5);
1403
+ } else {
1404
+ peg$currPos = s0;
1405
+ s0 = peg$FAILED;
1406
+ }
1407
+ } else {
1408
+ peg$currPos = s0;
1409
+ s0 = peg$FAILED;
1410
+ }
1411
+ } else {
1412
+ peg$currPos = s0;
1413
+ s0 = peg$FAILED;
1414
+ }
1315
1415
  } else {
1316
1416
  peg$currPos = s0;
1317
1417
  s0 = peg$FAILED;
@@ -1320,6 +1420,31 @@ function peg$parse(input, options) {
1320
1420
  peg$currPos = s0;
1321
1421
  s0 = peg$FAILED;
1322
1422
  }
1423
+ if (s0 === peg$FAILED) {
1424
+ s0 = peg$currPos;
1425
+ if (input.charCodeAt(peg$currPos) === 64) {
1426
+ s1 = peg$c15;
1427
+ peg$currPos++;
1428
+ } else {
1429
+ s1 = peg$FAILED;
1430
+ if (peg$silentFails === 0) {
1431
+ peg$fail(peg$e16);
1432
+ }
1433
+ }
1434
+ if (s1 !== peg$FAILED) {
1435
+ s2 = peg$parseidentifier();
1436
+ if (s2 !== peg$FAILED) {
1437
+ peg$savedPos = s0;
1438
+ s0 = peg$f18(s2);
1439
+ } else {
1440
+ peg$currPos = s0;
1441
+ s0 = peg$FAILED;
1442
+ }
1443
+ } else {
1444
+ peg$currPos = s0;
1445
+ s0 = peg$FAILED;
1446
+ }
1447
+ }
1323
1448
  }
1324
1449
  }
1325
1450
  return s0;
@@ -1333,12 +1458,12 @@ function peg$parse(input, options) {
1333
1458
  s3 = peg$currPos;
1334
1459
  s4 = peg$parse_();
1335
1460
  if (input.charCodeAt(peg$currPos) === 44) {
1336
- s5 = peg$c18;
1461
+ s5 = peg$c19;
1337
1462
  peg$currPos++;
1338
1463
  } else {
1339
1464
  s5 = peg$FAILED;
1340
1465
  if (peg$silentFails === 0) {
1341
- peg$fail(peg$e18);
1466
+ peg$fail(peg$e20);
1342
1467
  }
1343
1468
  }
1344
1469
  if (s5 !== peg$FAILED) {
@@ -1359,12 +1484,12 @@ function peg$parse(input, options) {
1359
1484
  s3 = peg$currPos;
1360
1485
  s4 = peg$parse_();
1361
1486
  if (input.charCodeAt(peg$currPos) === 44) {
1362
- s5 = peg$c18;
1487
+ s5 = peg$c19;
1363
1488
  peg$currPos++;
1364
1489
  } else {
1365
1490
  s5 = peg$FAILED;
1366
1491
  if (peg$silentFails === 0) {
1367
- peg$fail(peg$e18);
1492
+ peg$fail(peg$e20);
1368
1493
  }
1369
1494
  }
1370
1495
  if (s5 !== peg$FAILED) {
@@ -1382,7 +1507,7 @@ function peg$parse(input, options) {
1382
1507
  }
1383
1508
  }
1384
1509
  peg$savedPos = s0;
1385
- s0 = peg$f21(s1, s2);
1510
+ s0 = peg$f19(s1, s2);
1386
1511
  } else {
1387
1512
  peg$currPos = s0;
1388
1513
  s0 = peg$FAILED;
@@ -1391,7 +1516,7 @@ function peg$parse(input, options) {
1391
1516
  s0 = peg$currPos;
1392
1517
  s1 = "";
1393
1518
  peg$savedPos = s0;
1394
- s1 = peg$f22();
1519
+ s1 = peg$f20();
1395
1520
  s0 = s1;
1396
1521
  }
1397
1522
  return s0;
@@ -1403,12 +1528,12 @@ function peg$parse(input, options) {
1403
1528
  if (s1 !== peg$FAILED) {
1404
1529
  s2 = peg$parse_();
1405
1530
  if (input.charCodeAt(peg$currPos) === 58) {
1406
- s3 = peg$c19;
1531
+ s3 = peg$c20;
1407
1532
  peg$currPos++;
1408
1533
  } else {
1409
1534
  s3 = peg$FAILED;
1410
1535
  if (peg$silentFails === 0) {
1411
- peg$fail(peg$e19);
1536
+ peg$fail(peg$e21);
1412
1537
  }
1413
1538
  }
1414
1539
  if (s3 !== peg$FAILED) {
@@ -1416,7 +1541,7 @@ function peg$parse(input, options) {
1416
1541
  s5 = peg$parsedecoratorValue();
1417
1542
  if (s5 !== peg$FAILED) {
1418
1543
  peg$savedPos = s0;
1419
- s0 = peg$f23(s1, s5);
1544
+ s0 = peg$f21(s1, s5);
1420
1545
  } else {
1421
1546
  peg$currPos = s0;
1422
1547
  s0 = peg$FAILED;
@@ -1433,21 +1558,190 @@ function peg$parse(input, options) {
1433
1558
  }
1434
1559
  function peg$parsedecoratorValue() {
1435
1560
  var s0, s1;
1561
+ s0 = peg$parseliteralValue();
1562
+ if (s0 === peg$FAILED) {
1563
+ s0 = peg$currPos;
1564
+ s1 = peg$parseidentifier();
1565
+ if (s1 !== peg$FAILED) {
1566
+ peg$savedPos = s0;
1567
+ s1 = peg$f22(s1);
1568
+ }
1569
+ s0 = s1;
1570
+ }
1571
+ return s0;
1572
+ }
1573
+ function peg$parseliteralValue() {
1574
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8;
1436
1575
  s0 = peg$currPos;
1437
1576
  s1 = peg$parsestringLiteral();
1438
1577
  if (s1 !== peg$FAILED) {
1439
1578
  peg$savedPos = s0;
1440
- s1 = peg$f24(s1);
1579
+ s1 = peg$f23(s1);
1441
1580
  }
1442
1581
  s0 = s1;
1443
1582
  if (s0 === peg$FAILED) {
1444
1583
  s0 = peg$currPos;
1445
- s1 = peg$parseidentifier();
1584
+ if (input.substr(peg$currPos, 4) === peg$c21) {
1585
+ s1 = peg$c21;
1586
+ peg$currPos += 4;
1587
+ } else {
1588
+ s1 = peg$FAILED;
1589
+ if (peg$silentFails === 0) {
1590
+ peg$fail(peg$e22);
1591
+ }
1592
+ }
1593
+ if (s1 === peg$FAILED) {
1594
+ if (input.substr(peg$currPos, 5) === peg$c22) {
1595
+ s1 = peg$c22;
1596
+ peg$currPos += 5;
1597
+ } else {
1598
+ s1 = peg$FAILED;
1599
+ if (peg$silentFails === 0) {
1600
+ peg$fail(peg$e23);
1601
+ }
1602
+ }
1603
+ }
1446
1604
  if (s1 !== peg$FAILED) {
1447
- peg$savedPos = s0;
1448
- s1 = peg$f25(s1);
1605
+ s2 = peg$currPos;
1606
+ peg$silentFails++;
1607
+ s3 = input.charAt(peg$currPos);
1608
+ if (peg$r0.test(s3)) {
1609
+ peg$currPos++;
1610
+ } else {
1611
+ s3 = peg$FAILED;
1612
+ if (peg$silentFails === 0) {
1613
+ peg$fail(peg$e15);
1614
+ }
1615
+ }
1616
+ peg$silentFails--;
1617
+ if (s3 === peg$FAILED) {
1618
+ s2 = void 0;
1619
+ } else {
1620
+ peg$currPos = s2;
1621
+ s2 = peg$FAILED;
1622
+ }
1623
+ if (s2 !== peg$FAILED) {
1624
+ peg$savedPos = s0;
1625
+ s0 = peg$f24(s1);
1626
+ } else {
1627
+ peg$currPos = s0;
1628
+ s0 = peg$FAILED;
1629
+ }
1630
+ } else {
1631
+ peg$currPos = s0;
1632
+ s0 = peg$FAILED;
1633
+ }
1634
+ if (s0 === peg$FAILED) {
1635
+ s0 = peg$currPos;
1636
+ s1 = peg$currPos;
1637
+ s2 = peg$currPos;
1638
+ if (input.charCodeAt(peg$currPos) === 45) {
1639
+ s3 = peg$c23;
1640
+ peg$currPos++;
1641
+ } else {
1642
+ s3 = peg$FAILED;
1643
+ if (peg$silentFails === 0) {
1644
+ peg$fail(peg$e24);
1645
+ }
1646
+ }
1647
+ if (s3 === peg$FAILED) {
1648
+ s3 = null;
1649
+ }
1650
+ s4 = [];
1651
+ s5 = input.charAt(peg$currPos);
1652
+ if (peg$r1.test(s5)) {
1653
+ peg$currPos++;
1654
+ } else {
1655
+ s5 = peg$FAILED;
1656
+ if (peg$silentFails === 0) {
1657
+ peg$fail(peg$e25);
1658
+ }
1659
+ }
1660
+ if (s5 !== peg$FAILED) {
1661
+ while (s5 !== peg$FAILED) {
1662
+ s4.push(s5);
1663
+ s5 = input.charAt(peg$currPos);
1664
+ if (peg$r1.test(s5)) {
1665
+ peg$currPos++;
1666
+ } else {
1667
+ s5 = peg$FAILED;
1668
+ if (peg$silentFails === 0) {
1669
+ peg$fail(peg$e25);
1670
+ }
1671
+ }
1672
+ }
1673
+ } else {
1674
+ s4 = peg$FAILED;
1675
+ }
1676
+ if (s4 !== peg$FAILED) {
1677
+ s5 = peg$currPos;
1678
+ if (input.charCodeAt(peg$currPos) === 46) {
1679
+ s6 = peg$c24;
1680
+ peg$currPos++;
1681
+ } else {
1682
+ s6 = peg$FAILED;
1683
+ if (peg$silentFails === 0) {
1684
+ peg$fail(peg$e26);
1685
+ }
1686
+ }
1687
+ if (s6 !== peg$FAILED) {
1688
+ s7 = [];
1689
+ s8 = input.charAt(peg$currPos);
1690
+ if (peg$r1.test(s8)) {
1691
+ peg$currPos++;
1692
+ } else {
1693
+ s8 = peg$FAILED;
1694
+ if (peg$silentFails === 0) {
1695
+ peg$fail(peg$e25);
1696
+ }
1697
+ }
1698
+ if (s8 !== peg$FAILED) {
1699
+ while (s8 !== peg$FAILED) {
1700
+ s7.push(s8);
1701
+ s8 = input.charAt(peg$currPos);
1702
+ if (peg$r1.test(s8)) {
1703
+ peg$currPos++;
1704
+ } else {
1705
+ s8 = peg$FAILED;
1706
+ if (peg$silentFails === 0) {
1707
+ peg$fail(peg$e25);
1708
+ }
1709
+ }
1710
+ }
1711
+ } else {
1712
+ s7 = peg$FAILED;
1713
+ }
1714
+ if (s7 !== peg$FAILED) {
1715
+ s6 = [s6, s7];
1716
+ s5 = s6;
1717
+ } else {
1718
+ peg$currPos = s5;
1719
+ s5 = peg$FAILED;
1720
+ }
1721
+ } else {
1722
+ peg$currPos = s5;
1723
+ s5 = peg$FAILED;
1724
+ }
1725
+ if (s5 === peg$FAILED) {
1726
+ s5 = null;
1727
+ }
1728
+ s3 = [s3, s4, s5];
1729
+ s2 = s3;
1730
+ } else {
1731
+ peg$currPos = s2;
1732
+ s2 = peg$FAILED;
1733
+ }
1734
+ if (s2 !== peg$FAILED) {
1735
+ s1 = input.substring(s1, peg$currPos);
1736
+ } else {
1737
+ s1 = s2;
1738
+ }
1739
+ if (s1 !== peg$FAILED) {
1740
+ peg$savedPos = s0;
1741
+ s1 = peg$f25(s1);
1742
+ }
1743
+ s0 = s1;
1449
1744
  }
1450
- s0 = s1;
1451
1745
  }
1452
1746
  return s0;
1453
1747
  }
@@ -1455,12 +1749,12 @@ function peg$parse(input, options) {
1455
1749
  var s0, s1, s2, s3;
1456
1750
  s0 = peg$currPos;
1457
1751
  if (input.charCodeAt(peg$currPos) === 34) {
1458
- s1 = peg$c20;
1752
+ s1 = peg$c25;
1459
1753
  peg$currPos++;
1460
1754
  } else {
1461
1755
  s1 = peg$FAILED;
1462
1756
  if (peg$silentFails === 0) {
1463
- peg$fail(peg$e20);
1757
+ peg$fail(peg$e27);
1464
1758
  }
1465
1759
  }
1466
1760
  if (s1 !== peg$FAILED) {
@@ -1471,12 +1765,12 @@ function peg$parse(input, options) {
1471
1765
  s3 = peg$parsechar();
1472
1766
  }
1473
1767
  if (input.charCodeAt(peg$currPos) === 34) {
1474
- s3 = peg$c20;
1768
+ s3 = peg$c25;
1475
1769
  peg$currPos++;
1476
1770
  } else {
1477
1771
  s3 = peg$FAILED;
1478
1772
  if (peg$silentFails === 0) {
1479
- peg$fail(peg$e20);
1773
+ peg$fail(peg$e27);
1480
1774
  }
1481
1775
  }
1482
1776
  if (s3 !== peg$FAILED) {
@@ -1495,33 +1789,33 @@ function peg$parse(input, options) {
1495
1789
  function peg$parsechar() {
1496
1790
  var s0, s1, s2;
1497
1791
  s0 = input.charAt(peg$currPos);
1498
- if (peg$r0.test(s0)) {
1792
+ if (peg$r2.test(s0)) {
1499
1793
  peg$currPos++;
1500
1794
  } else {
1501
1795
  s0 = peg$FAILED;
1502
1796
  if (peg$silentFails === 0) {
1503
- peg$fail(peg$e21);
1797
+ peg$fail(peg$e28);
1504
1798
  }
1505
1799
  }
1506
1800
  if (s0 === peg$FAILED) {
1507
1801
  s0 = peg$currPos;
1508
1802
  if (input.charCodeAt(peg$currPos) === 92) {
1509
- s1 = peg$c21;
1803
+ s1 = peg$c26;
1510
1804
  peg$currPos++;
1511
1805
  } else {
1512
1806
  s1 = peg$FAILED;
1513
1807
  if (peg$silentFails === 0) {
1514
- peg$fail(peg$e22);
1808
+ peg$fail(peg$e29);
1515
1809
  }
1516
1810
  }
1517
1811
  if (s1 !== peg$FAILED) {
1518
1812
  if (input.charCodeAt(peg$currPos) === 34) {
1519
- s2 = peg$c20;
1813
+ s2 = peg$c25;
1520
1814
  peg$currPos++;
1521
1815
  } else {
1522
1816
  s2 = peg$FAILED;
1523
1817
  if (peg$silentFails === 0) {
1524
- peg$fail(peg$e20);
1818
+ peg$fail(peg$e27);
1525
1819
  }
1526
1820
  }
1527
1821
  if (s2 !== peg$FAILED) {
@@ -1538,22 +1832,22 @@ function peg$parse(input, options) {
1538
1832
  if (s0 === peg$FAILED) {
1539
1833
  s0 = peg$currPos;
1540
1834
  if (input.charCodeAt(peg$currPos) === 92) {
1541
- s1 = peg$c21;
1835
+ s1 = peg$c26;
1542
1836
  peg$currPos++;
1543
1837
  } else {
1544
1838
  s1 = peg$FAILED;
1545
1839
  if (peg$silentFails === 0) {
1546
- peg$fail(peg$e22);
1840
+ peg$fail(peg$e29);
1547
1841
  }
1548
1842
  }
1549
1843
  if (s1 !== peg$FAILED) {
1550
1844
  if (input.charCodeAt(peg$currPos) === 92) {
1551
- s2 = peg$c21;
1845
+ s2 = peg$c26;
1552
1846
  peg$currPos++;
1553
1847
  } else {
1554
1848
  s2 = peg$FAILED;
1555
1849
  if (peg$silentFails === 0) {
1556
- peg$fail(peg$e22);
1850
+ peg$fail(peg$e29);
1557
1851
  }
1558
1852
  }
1559
1853
  if (s2 !== peg$FAILED) {
@@ -1570,22 +1864,22 @@ function peg$parse(input, options) {
1570
1864
  if (s0 === peg$FAILED) {
1571
1865
  s0 = peg$currPos;
1572
1866
  if (input.charCodeAt(peg$currPos) === 92) {
1573
- s1 = peg$c21;
1867
+ s1 = peg$c26;
1574
1868
  peg$currPos++;
1575
1869
  } else {
1576
1870
  s1 = peg$FAILED;
1577
1871
  if (peg$silentFails === 0) {
1578
- peg$fail(peg$e22);
1872
+ peg$fail(peg$e29);
1579
1873
  }
1580
1874
  }
1581
1875
  if (s1 !== peg$FAILED) {
1582
1876
  if (input.charCodeAt(peg$currPos) === 110) {
1583
- s2 = peg$c22;
1877
+ s2 = peg$c27;
1584
1878
  peg$currPos++;
1585
1879
  } else {
1586
1880
  s2 = peg$FAILED;
1587
1881
  if (peg$silentFails === 0) {
1588
- peg$fail(peg$e23);
1882
+ peg$fail(peg$e30);
1589
1883
  }
1590
1884
  }
1591
1885
  if (s2 !== peg$FAILED) {
@@ -1609,34 +1903,34 @@ function peg$parse(input, options) {
1609
1903
  peg$silentFails++;
1610
1904
  s0 = peg$currPos;
1611
1905
  s1 = input.charAt(peg$currPos);
1612
- if (peg$r1.test(s1)) {
1906
+ if (peg$r3.test(s1)) {
1613
1907
  peg$currPos++;
1614
1908
  } else {
1615
1909
  s1 = peg$FAILED;
1616
1910
  if (peg$silentFails === 0) {
1617
- peg$fail(peg$e25);
1911
+ peg$fail(peg$e32);
1618
1912
  }
1619
1913
  }
1620
1914
  if (s1 !== peg$FAILED) {
1621
1915
  s2 = [];
1622
1916
  s3 = input.charAt(peg$currPos);
1623
- if (peg$r2.test(s3)) {
1917
+ if (peg$r0.test(s3)) {
1624
1918
  peg$currPos++;
1625
1919
  } else {
1626
1920
  s3 = peg$FAILED;
1627
1921
  if (peg$silentFails === 0) {
1628
- peg$fail(peg$e26);
1922
+ peg$fail(peg$e15);
1629
1923
  }
1630
1924
  }
1631
1925
  while (s3 !== peg$FAILED) {
1632
1926
  s2.push(s3);
1633
1927
  s3 = input.charAt(peg$currPos);
1634
- if (peg$r2.test(s3)) {
1928
+ if (peg$r0.test(s3)) {
1635
1929
  peg$currPos++;
1636
1930
  } else {
1637
1931
  s3 = peg$FAILED;
1638
1932
  if (peg$silentFails === 0) {
1639
- peg$fail(peg$e26);
1933
+ peg$fail(peg$e15);
1640
1934
  }
1641
1935
  }
1642
1936
  }
@@ -1650,7 +1944,7 @@ function peg$parse(input, options) {
1650
1944
  if (s0 === peg$FAILED) {
1651
1945
  s1 = peg$FAILED;
1652
1946
  if (peg$silentFails === 0) {
1653
- peg$fail(peg$e24);
1947
+ peg$fail(peg$e31);
1654
1948
  }
1655
1949
  }
1656
1950
  return s0;
@@ -1695,24 +1989,24 @@ function peg$parse(input, options) {
1695
1989
  var s0, s1;
1696
1990
  s0 = [];
1697
1991
  s1 = input.charAt(peg$currPos);
1698
- if (peg$r3.test(s1)) {
1992
+ if (peg$r4.test(s1)) {
1699
1993
  peg$currPos++;
1700
1994
  } else {
1701
1995
  s1 = peg$FAILED;
1702
1996
  if (peg$silentFails === 0) {
1703
- peg$fail(peg$e27);
1997
+ peg$fail(peg$e33);
1704
1998
  }
1705
1999
  }
1706
2000
  if (s1 !== peg$FAILED) {
1707
2001
  while (s1 !== peg$FAILED) {
1708
2002
  s0.push(s1);
1709
2003
  s1 = input.charAt(peg$currPos);
1710
- if (peg$r3.test(s1)) {
2004
+ if (peg$r4.test(s1)) {
1711
2005
  peg$currPos++;
1712
2006
  } else {
1713
2007
  s1 = peg$FAILED;
1714
2008
  if (peg$silentFails === 0) {
1715
- peg$fail(peg$e27);
2009
+ peg$fail(peg$e33);
1716
2010
  }
1717
2011
  }
1718
2012
  }
@@ -1724,13 +2018,13 @@ function peg$parse(input, options) {
1724
2018
  function peg$parselineComment() {
1725
2019
  var s0, s1, s2, s3, s4, s5;
1726
2020
  s0 = peg$currPos;
1727
- if (input.substr(peg$currPos, 2) === peg$c23) {
1728
- s1 = peg$c23;
2021
+ if (input.substr(peg$currPos, 2) === peg$c28) {
2022
+ s1 = peg$c28;
1729
2023
  peg$currPos += 2;
1730
2024
  } else {
1731
2025
  s1 = peg$FAILED;
1732
2026
  if (peg$silentFails === 0) {
1733
- peg$fail(peg$e28);
2027
+ peg$fail(peg$e34);
1734
2028
  }
1735
2029
  }
1736
2030
  if (s1 !== peg$FAILED) {
@@ -1739,12 +2033,12 @@ function peg$parse(input, options) {
1739
2033
  s4 = peg$currPos;
1740
2034
  peg$silentFails++;
1741
2035
  s5 = input.charAt(peg$currPos);
1742
- if (peg$r4.test(s5)) {
2036
+ if (peg$r5.test(s5)) {
1743
2037
  peg$currPos++;
1744
2038
  } else {
1745
2039
  s5 = peg$FAILED;
1746
2040
  if (peg$silentFails === 0) {
1747
- peg$fail(peg$e29);
2041
+ peg$fail(peg$e35);
1748
2042
  }
1749
2043
  }
1750
2044
  peg$silentFails--;
@@ -1761,7 +2055,7 @@ function peg$parse(input, options) {
1761
2055
  } else {
1762
2056
  s5 = peg$FAILED;
1763
2057
  if (peg$silentFails === 0) {
1764
- peg$fail(peg$e30);
2058
+ peg$fail(peg$e36);
1765
2059
  }
1766
2060
  }
1767
2061
  if (s5 !== peg$FAILED) {
@@ -1781,12 +2075,12 @@ function peg$parse(input, options) {
1781
2075
  s4 = peg$currPos;
1782
2076
  peg$silentFails++;
1783
2077
  s5 = input.charAt(peg$currPos);
1784
- if (peg$r4.test(s5)) {
2078
+ if (peg$r5.test(s5)) {
1785
2079
  peg$currPos++;
1786
2080
  } else {
1787
2081
  s5 = peg$FAILED;
1788
2082
  if (peg$silentFails === 0) {
1789
- peg$fail(peg$e29);
2083
+ peg$fail(peg$e35);
1790
2084
  }
1791
2085
  }
1792
2086
  peg$silentFails--;
@@ -1803,7 +2097,7 @@ function peg$parse(input, options) {
1803
2097
  } else {
1804
2098
  s5 = peg$FAILED;
1805
2099
  if (peg$silentFails === 0) {
1806
- peg$fail(peg$e30);
2100
+ peg$fail(peg$e36);
1807
2101
  }
1808
2102
  }
1809
2103
  if (s5 !== peg$FAILED) {
@@ -1952,7 +2246,279 @@ async function parseSchemaFile(path) {
1952
2246
  return parseSchema(source);
1953
2247
  }
1954
2248
 
2249
+ // src/model.ts
2250
+ var SCHEMA_MODEL_VERSION = 1;
2251
+ var DEFAULT_FUNCTIONS = {
2252
+ cuid: ["String"],
2253
+ uuid: ["String"],
2254
+ now: ["DateTime", "Date"]
2255
+ };
2256
+ function findDecorator(decs, name) {
2257
+ return decs.find((d) => d.name === name);
2258
+ }
2259
+ function argValue(dec, key) {
2260
+ return dec.args.find((a) => a.key === key)?.value;
2261
+ }
2262
+ function resolveDefault(owner, f) {
2263
+ const dec = findDecorator(f.decorators, "default");
2264
+ if (!dec) {
2265
+ return void 0;
2266
+ }
2267
+ const where = `${owner} field "${f.name}"`;
2268
+ const fn = argValue(dec, "fn");
2269
+ if (fn && fn.kind === "identifier") {
2270
+ const allowed = DEFAULT_FUNCTIONS[fn.value];
2271
+ if (!allowed) {
2272
+ throw new SchemaValidationError(
2273
+ `${where}: unknown default function "${fn.value}()" (expected ${Object.keys(
2274
+ DEFAULT_FUNCTIONS
2275
+ ).map((k) => `${k}()`).join(", ")}).`
2276
+ );
2277
+ }
2278
+ if (!allowed.includes(f.type.name) || f.type.list) {
2279
+ throw new SchemaValidationError(
2280
+ `${where}: @default(${fn.value}()) is not valid for type ${f.type.name}${f.type.list ? "[]" : ""}.`
2281
+ );
2282
+ }
2283
+ return { kind: "fn", fn: fn.value };
2284
+ }
2285
+ const lit = argValue(dec, "value");
2286
+ if (!lit || lit.kind === "identifier") {
2287
+ throw new SchemaValidationError(`${where}: unsupported @default(...) argument.`);
2288
+ }
2289
+ const t = f.type.name;
2290
+ const ok = !f.type.list && (lit.kind === "string" && t === "String" || lit.kind === "boolean" && t === "Boolean" || lit.kind === "number" && (t === "Float" || t === "Int" && Number.isInteger(lit.value)));
2291
+ if (!ok) {
2292
+ throw new SchemaValidationError(
2293
+ `${where}: default ${JSON.stringify(lit.value)} does not match type ${t}${f.type.list ? "[]" : ""}.`
2294
+ );
2295
+ }
2296
+ return { kind: "literal", value: lit.value };
2297
+ }
2298
+ function resolveScalar(owner, f, allowId) {
2299
+ const id = Boolean(findDecorator(f.decorators, "id"));
2300
+ const list = Boolean(f.type.list);
2301
+ if (id && !allowId) {
2302
+ throw new SchemaValidationError(
2303
+ `${owner} field "${f.name}": @id is only valid on node fields.`
2304
+ );
2305
+ }
2306
+ if (id && (f.type.optional || list)) {
2307
+ throw new SchemaValidationError(
2308
+ `${owner} field "${f.name}": an @id field cannot be optional or a list.`
2309
+ );
2310
+ }
2311
+ for (const d of f.decorators) {
2312
+ if (!["id", "unique", "index", "default"].includes(d.name)) {
2313
+ throw new SchemaValidationError(`${owner} field "${f.name}": unknown decorator @${d.name}.`);
2314
+ }
2315
+ }
2316
+ const field = {
2317
+ kind: "scalar",
2318
+ name: f.name,
2319
+ type: f.type.name,
2320
+ optional: list ? false : f.type.optional,
2321
+ list,
2322
+ id,
2323
+ unique: Boolean(findDecorator(f.decorators, "unique")),
2324
+ index: Boolean(findDecorator(f.decorators, "index"))
2325
+ };
2326
+ const def = resolveDefault(owner, f);
2327
+ return def ? { ...field, default: def } : field;
2328
+ }
2329
+ function assertUniqueNames(owner, names) {
2330
+ const seen = /* @__PURE__ */ new Set();
2331
+ for (const n of names) {
2332
+ if (seen.has(n)) {
2333
+ throw new SchemaValidationError(`${owner}: duplicate field "${n}".`);
2334
+ }
2335
+ seen.add(n);
2336
+ }
2337
+ }
2338
+ function resolveSchema(doc) {
2339
+ const nodeNames = /* @__PURE__ */ new Set();
2340
+ const relNames = /* @__PURE__ */ new Set();
2341
+ for (const d of doc.declarations) {
2342
+ const set = d.kind === "Node" ? nodeNames : relNames;
2343
+ if (nodeNames.has(d.name) || relNames.has(d.name)) {
2344
+ throw new SchemaValidationError(`Duplicate declaration "${d.name}".`);
2345
+ }
2346
+ set.add(d.name);
2347
+ }
2348
+ const relationships = [];
2349
+ for (const d of doc.declarations) {
2350
+ if (d.kind !== "Relationship") {
2351
+ continue;
2352
+ }
2353
+ const owner = `Relationship "${d.name}"`;
2354
+ for (const end of [d.from, d.to]) {
2355
+ if (!nodeNames.has(end)) {
2356
+ throw new SchemaValidationError(`${owner}: unknown node "${end}".`);
2357
+ }
2358
+ }
2359
+ assertUniqueNames(
2360
+ owner,
2361
+ d.fields.map((f) => f.name)
2362
+ );
2363
+ relationships.push({
2364
+ name: d.name,
2365
+ relType: d.relType,
2366
+ from: d.from,
2367
+ to: d.to,
2368
+ properties: d.fields.map((f) => resolveScalar(owner, f, false))
2369
+ });
2370
+ }
2371
+ const nodes = [];
2372
+ for (const d of doc.declarations) {
2373
+ if (d.kind !== "Node") {
2374
+ continue;
2375
+ }
2376
+ const owner = `Node "${d.name}"`;
2377
+ assertUniqueNames(
2378
+ owner,
2379
+ d.fields.map((f) => f.name)
2380
+ );
2381
+ const fields = [];
2382
+ for (const f of d.fields) {
2383
+ if (f.kind === "Scalar") {
2384
+ fields.push(resolveScalar(owner, f, true));
2385
+ continue;
2386
+ }
2387
+ const where = `${owner} field "${f.name}"`;
2388
+ if (!nodeNames.has(f.target)) {
2389
+ throw new SchemaValidationError(`${where}: unknown node "${f.target}".`);
2390
+ }
2391
+ const rel = findDecorator(f.decorators, "relationship");
2392
+ const typeArg = rel ? argValue(rel, "type") : void 0;
2393
+ if (!rel || !typeArg || typeArg.kind !== "string" || typeArg.value === "") {
2394
+ throw new SchemaValidationError(
2395
+ `${where}: relation fields need @relationship(type: "TYPE", direction: OUT|IN).`
2396
+ );
2397
+ }
2398
+ const dirArg = argValue(rel, "direction");
2399
+ let direction = "OUT";
2400
+ if (dirArg) {
2401
+ if (dirArg.kind !== "identifier" || dirArg.value !== "OUT" && dirArg.value !== "IN") {
2402
+ throw new SchemaValidationError(`${where}: direction must be OUT or IN.`);
2403
+ }
2404
+ direction = dirArg.value;
2405
+ }
2406
+ const [start, end] = direction === "OUT" ? [d.name, f.target] : [f.target, d.name];
2407
+ const edges = relationships.filter(
2408
+ (r) => r.relType === typeArg.value && r.from === start && r.to === end
2409
+ );
2410
+ if (edges.length > 1) {
2411
+ throw new SchemaValidationError(
2412
+ `${where}: several relationship models match (${edges.map((e) => e.name).join(", ")}).`
2413
+ );
2414
+ }
2415
+ const field = {
2416
+ kind: "relation",
2417
+ name: f.name,
2418
+ target: f.target,
2419
+ relType: typeArg.value,
2420
+ direction,
2421
+ many: f.cardinality === "many",
2422
+ optional: f.cardinality === "many" ? false : f.optional
2423
+ };
2424
+ fields.push(edges[0] ? { ...field, edge: edges[0].name } : field);
2425
+ }
2426
+ const scalars = fields.filter((f) => f.kind === "scalar");
2427
+ const idField = scalars.find((f) => f.id)?.name;
2428
+ nodes.push({
2429
+ name: d.name,
2430
+ label: d.name,
2431
+ ...idField ? { idField } : {},
2432
+ uniqueFields: scalars.filter((f) => f.id || f.unique).map((f) => f.name),
2433
+ fields
2434
+ });
2435
+ }
2436
+ return { version: SCHEMA_MODEL_VERSION, nodes, relationships };
2437
+ }
2438
+ function getNodeModel(model, name) {
2439
+ const n = model.nodes.find((x) => x.name === name);
2440
+ if (!n) {
2441
+ throw new Error(`Unknown node model "${name}".`);
2442
+ }
2443
+ return n;
2444
+ }
2445
+
1955
2446
  // src/renderCyphraGen.ts
2447
+ var TS_SCALAR = {
2448
+ String: "string",
2449
+ Int: "number",
2450
+ Float: "number",
2451
+ Boolean: "boolean",
2452
+ DateTime: "Date",
2453
+ Date: "Date"
2454
+ };
2455
+ function tsFieldType(f) {
2456
+ const base = TS_SCALAR[f.type];
2457
+ if (f.list) return `${base}[]`;
2458
+ return f.optional ? `${base} | null` : base;
2459
+ }
2460
+ function union(names) {
2461
+ return names.length ? names.map((n) => JSON.stringify(n)).join(" | ") : "never";
2462
+ }
2463
+ function renderObjectType(name, fields, doc) {
2464
+ const lines = [`/** ${doc} */`, `export type ${name} = {`];
2465
+ for (const f of fields) lines.push(` ${f.name}: ${tsFieldType(f)};`);
2466
+ lines.push("};", "");
2467
+ return lines;
2468
+ }
2469
+ function renderClientSection(model) {
2470
+ const lines = [];
2471
+ for (const n of model.nodes) {
2472
+ const scalars = n.fields.filter((f) => f.kind === "scalar");
2473
+ lines.push(...renderObjectType(n.name, scalars, `\`${n.name}\` node properties.`));
2474
+ }
2475
+ for (const r of model.relationships) {
2476
+ lines.push(
2477
+ ...renderObjectType(
2478
+ r.name,
2479
+ r.properties,
2480
+ `\`${r.name}\` (\`:${r.relType}\`) edge properties.`
2481
+ )
2482
+ );
2483
+ }
2484
+ lines.push("/** Type-level description of the schema, consumed by the ORM client. */");
2485
+ lines.push("export type CyphraTypeMap = {");
2486
+ for (const n of model.nodes) {
2487
+ const scalars = n.fields.filter((f) => f.kind === "scalar");
2488
+ const required = scalars.filter((f) => !f.optional && !f.list && !f.default).map((f) => f.name);
2489
+ lines.push(` ${n.name}: {`);
2490
+ lines.push(` scalars: ${n.name};`);
2491
+ lines.push(` createRequired: ${union(required)};`);
2492
+ lines.push(` unique: ${union(n.uniqueFields)};`);
2493
+ lines.push(" relations: {");
2494
+ for (const f of n.fields) {
2495
+ if (f.kind !== "relation") continue;
2496
+ lines.push(
2497
+ ` ${f.name}: { target: ${JSON.stringify(f.target)}; many: ${f.many}; optional: ${f.optional}; edge: ${f.edge ?? "null"} };`
2498
+ );
2499
+ }
2500
+ lines.push(" };");
2501
+ lines.push(" };");
2502
+ }
2503
+ lines.push("};", "");
2504
+ lines.push("/** Resolved schema model embedded for the runtime. */");
2505
+ lines.push(`export const schemaModel: SchemaModel = ${JSON.stringify(model, null, 2)};`, "");
2506
+ lines.push("/** Typed Cyphra client for this schema. */");
2507
+ lines.push("export type Db = OrmClient<CyphraTypeMap>;", "");
2508
+ lines.push("/**");
2509
+ lines.push(
2510
+ " * Create a typed client: `db.user.findMany(...)`, `db.post.create(...)`, `db.$transaction(...)`."
2511
+ );
2512
+ lines.push(" *");
2513
+ lines.push(
2514
+ " * @param options - Connection options (`uri`, `user`, `password`, \u2026) or `{ client }`."
2515
+ );
2516
+ lines.push(" */");
2517
+ lines.push("export function createClient(options: OrmOptions): Db {");
2518
+ lines.push(" return createOrm<CyphraTypeMap>(schemaModel, options);");
2519
+ lines.push("}", "");
2520
+ return lines;
2521
+ }
1956
2522
  function decoratorStringArg(decorators, decoratorName, argKey) {
1957
2523
  const dec = decorators.find((d) => d.name === decoratorName);
1958
2524
  if (!dec) {
@@ -2008,13 +2574,19 @@ function relTypeToExportKey(type, used) {
2008
2574
  used.add(key);
2009
2575
  return key;
2010
2576
  }
2011
- function renderCyphraGenSource(doc) {
2577
+ function renderCyphraGenSource(doc, options = {}) {
2578
+ const resolved = resolveSchema(doc);
2579
+ const runtimeImport = options.runtimeImport ?? "cyphra";
2012
2580
  const model = collectCodegenModel(doc);
2013
2581
  const lines = [];
2014
2582
  lines.push("/**");
2015
2583
  lines.push(" * Generated by `cyphra generate` \u2014 do not edit by hand.");
2016
2584
  lines.push(" */");
2017
2585
  lines.push("");
2586
+ lines.push(
2587
+ `import { createOrm, type OrmClient, type OrmOptions, type SchemaModel } from ${JSON.stringify(runtimeImport)};`
2588
+ );
2589
+ lines.push("");
2018
2590
  lines.push("/** Neo4j node labels from `node` declarations. */");
2019
2591
  lines.push("export const NodeLabel = {");
2020
2592
  for (const L of model.nodeLabels) {
@@ -2048,18 +2620,23 @@ function renderCyphraGenSource(doc) {
2048
2620
  lines.push("");
2049
2621
  lines.push("export type RelTypeKey = keyof typeof RelType;");
2050
2622
  lines.push("");
2623
+ lines.push(...renderClientSection(resolved));
2051
2624
  return lines.join("\n");
2052
2625
  }
2053
2626
  export {
2054
2627
  MAX_SCHEMA_BYTES,
2628
+ SCHEMA_MODEL_VERSION,
2055
2629
  SchemaValidationError,
2056
2630
  collectCodegenModel,
2057
2631
  formatDecorator,
2632
+ getNodeModel,
2058
2633
  parseSchema,
2059
2634
  parseSchemaFile,
2060
2635
  printSchemaDocument,
2061
2636
  relTypeToExportKey,
2637
+ renderClientSection,
2062
2638
  renderCyphraGenSource,
2639
+ resolveSchema,
2063
2640
  validateSchema
2064
2641
  };
2065
2642
  //# sourceMappingURL=index.js.map