schemair 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.
Files changed (69) hide show
  1. package/README.md +420 -11
  2. package/dist/authoring/index.cjs +13 -350
  3. package/dist/authoring/index.d.cts +2 -90
  4. package/dist/authoring/index.d.ts +2 -90
  5. package/dist/authoring/index.js +2 -304
  6. package/dist/authoring-D3V0iyTe.js +362 -0
  7. package/dist/authoring-Dnrg5TXm.cjs +389 -0
  8. package/dist/chunk-BgLxgFZR.js +18 -0
  9. package/dist/definition/index.cjs +10 -2
  10. package/dist/definition/index.d.cts +3 -21
  11. package/dist/definition/index.d.ts +3 -21
  12. package/dist/definition/index.js +2 -2
  13. package/dist/definition-BLLBpLKv.cjs +1187 -0
  14. package/dist/definition-DmYnDmQO.js +1115 -0
  15. package/dist/index-4aMF0cTE.d.ts +368 -0
  16. package/dist/index-BqfGAU1K.d.ts +56 -0
  17. package/dist/{index-eK2Xgrwp.d.ts → index-CBbd4hXJ.d.ts} +13 -2
  18. package/dist/index-CIim1dG7.d.cts +92 -0
  19. package/dist/{index-TACcK_mi.d.cts → index-CNjYUKvu.d.cts} +13 -2
  20. package/dist/index-CQynt7ft.d.cts +420 -0
  21. package/dist/index-D3mfwaSO.d.cts +56 -0
  22. package/dist/index-DDMwVy2I.d.cts +368 -0
  23. package/dist/index-DM5DSLLL.d.ts +99 -0
  24. package/dist/index-DXWoNYFB.d.ts +92 -0
  25. package/dist/index-DhmHCGpT.d.cts +99 -0
  26. package/dist/index-bQy-C-1l.d.ts +418 -0
  27. package/dist/index.cjs +64 -52
  28. package/dist/index.d.cts +7 -7
  29. package/dist/index.d.ts +7 -7
  30. package/dist/index.js +7 -5
  31. package/dist/integrations/json-schema/index.cjs +328 -0
  32. package/dist/integrations/json-schema/index.d.cts +53 -0
  33. package/dist/integrations/json-schema/index.d.ts +53 -0
  34. package/dist/integrations/json-schema/index.js +324 -0
  35. package/dist/integrations/standard-schema/index.cjs +32 -0
  36. package/dist/integrations/standard-schema/index.d.cts +22 -0
  37. package/dist/integrations/standard-schema/index.d.ts +22 -0
  38. package/dist/integrations/standard-schema/index.js +32 -0
  39. package/dist/payload/index.cjs +1 -1
  40. package/dist/payload/index.d.cts +1 -55
  41. package/dist/payload/index.d.ts +1 -55
  42. package/dist/payload/index.js +1 -1
  43. package/dist/relations/index.cjs +3 -1
  44. package/dist/relations/index.d.cts +2 -2
  45. package/dist/relations/index.d.ts +2 -2
  46. package/dist/relations/index.js +2 -2
  47. package/dist/{relations-CMz_0nf4.cjs → relations-Cymx4iTc.cjs} +158 -5
  48. package/dist/{relations-By0bK3UK.js → relations-ysXDmi-Z.js} +147 -6
  49. package/dist/spec/index.cjs +9 -0
  50. package/dist/spec/index.d.cts +2 -2
  51. package/dist/spec/index.d.ts +2 -2
  52. package/dist/spec/index.js +3 -1
  53. package/dist/standard/index.cjs +810 -0
  54. package/dist/standard/index.d.cts +3 -0
  55. package/dist/standard/index.d.ts +3 -0
  56. package/dist/standard/index.js +777 -0
  57. package/dist/standard-DhKsxu9U.js +471 -0
  58. package/dist/standard-etPFZDJI.cjs +513 -0
  59. package/dist/type-interpreter/index.cjs +3 -3
  60. package/dist/type-interpreter/index.d.cts +2 -99
  61. package/dist/type-interpreter/index.d.ts +2 -99
  62. package/dist/type-interpreter/index.js +2 -2
  63. package/dist/{type-interpreter-Ck0VDhzn.js → type-interpreter-DnrId8aM.js} +5 -284
  64. package/dist/{type-interpreter-DAIBUqKf.cjs → type-interpreter-OLt2W2yd.cjs} +15 -294
  65. package/package.json +38 -3
  66. package/dist/definition-BXj3T94L.js +0 -467
  67. package/dist/definition-DSZZTz4e.cjs +0 -473
  68. package/dist/index-CEzHfht2.d.ts +0 -269
  69. package/dist/index-rzkFjgrt.d.cts +0 -269
@@ -1,5 +1,5 @@
1
- const require_definition = require('./definition-DSZZTz4e.cjs');
2
- const require_relations = require('./relations-CMz_0nf4.cjs');
1
+ const require_definition = require('./definition-BLLBpLKv.cjs');
2
+ const require_relations = require('./relations-Cymx4iTc.cjs');
3
3
 
4
4
  //#region src/type-interpreter/materializer.ts
5
5
  function isRecord(value) {
@@ -1087,201 +1087,6 @@ async function checkTypeTermRelationAsync(source, target, context = {}) {
1087
1087
 
1088
1088
  //#endregion
1089
1089
  //#region src/type-interpreter/interpreter.ts
1090
- const expressionKinds = new Set([
1091
- "typeVar",
1092
- "opaqueHostType",
1093
- "absent",
1094
- "never",
1095
- "unknown",
1096
- "maybeAbsent",
1097
- "arrayOf",
1098
- "tupleOf",
1099
- "recordOf",
1100
- "elementOf",
1101
- "valueOf",
1102
- "elementAt",
1103
- "fieldOf",
1104
- "keyOf",
1105
- "fieldsOf",
1106
- "pickFields",
1107
- "omitFields",
1108
- "partialFields",
1109
- "requiredFields",
1110
- "mergeRecords",
1111
- "nullableOf",
1112
- "taggedUnionOf",
1113
- "intersect",
1114
- "refine",
1115
- "excludeVariants",
1116
- "extractVariants"
1117
- ]);
1118
- const expressionFields = {
1119
- typeVar: {
1120
- required: ["name"],
1121
- allowed: [
1122
- "kind",
1123
- "name",
1124
- "extends"
1125
- ]
1126
- },
1127
- opaqueHostType: {
1128
- required: ["hostPath"],
1129
- allowed: ["kind", "hostPath"]
1130
- },
1131
- absent: {
1132
- required: [],
1133
- allowed: ["kind"]
1134
- },
1135
- never: {
1136
- required: [],
1137
- allowed: ["kind"]
1138
- },
1139
- unknown: {
1140
- required: [],
1141
- allowed: ["kind"]
1142
- },
1143
- maybeAbsent: {
1144
- required: ["value"],
1145
- allowed: ["kind", "value"]
1146
- },
1147
- arrayOf: {
1148
- required: ["element"],
1149
- allowed: [
1150
- "kind",
1151
- "element",
1152
- "constraints"
1153
- ]
1154
- },
1155
- tupleOf: {
1156
- required: ["elements"],
1157
- allowed: ["kind", "elements"]
1158
- },
1159
- recordOf: {
1160
- required: ["fields"],
1161
- allowed: [
1162
- "kind",
1163
- "fields",
1164
- "additionalFields",
1165
- "constraints"
1166
- ]
1167
- },
1168
- nullableOf: {
1169
- required: ["value"],
1170
- allowed: ["kind", "value"]
1171
- },
1172
- taggedUnionOf: {
1173
- required: ["discriminator", "variants"],
1174
- allowed: [
1175
- "kind",
1176
- "discriminator",
1177
- "variants"
1178
- ]
1179
- },
1180
- elementOf: {
1181
- required: ["source"],
1182
- allowed: ["kind", "source"]
1183
- },
1184
- valueOf: {
1185
- required: ["source"],
1186
- allowed: ["kind", "source"]
1187
- },
1188
- elementAt: {
1189
- required: ["source", "index"],
1190
- allowed: [
1191
- "kind",
1192
- "source",
1193
- "index"
1194
- ]
1195
- },
1196
- fieldOf: {
1197
- required: ["source", "key"],
1198
- allowed: [
1199
- "kind",
1200
- "source",
1201
- "key"
1202
- ]
1203
- },
1204
- keyOf: {
1205
- required: ["source"],
1206
- allowed: ["kind", "source"]
1207
- },
1208
- fieldsOf: {
1209
- required: ["source", "fields"],
1210
- allowed: [
1211
- "kind",
1212
- "source",
1213
- "fields"
1214
- ]
1215
- },
1216
- pickFields: {
1217
- required: ["source", "fields"],
1218
- allowed: [
1219
- "kind",
1220
- "source",
1221
- "fields"
1222
- ]
1223
- },
1224
- omitFields: {
1225
- required: ["source", "fields"],
1226
- allowed: [
1227
- "kind",
1228
- "source",
1229
- "fields"
1230
- ]
1231
- },
1232
- partialFields: {
1233
- required: ["source", "fields"],
1234
- allowed: [
1235
- "kind",
1236
- "source",
1237
- "fields"
1238
- ]
1239
- },
1240
- requiredFields: {
1241
- required: ["source", "fields"],
1242
- allowed: [
1243
- "kind",
1244
- "source",
1245
- "fields"
1246
- ]
1247
- },
1248
- mergeRecords: {
1249
- required: ["sources", "conflict"],
1250
- allowed: [
1251
- "kind",
1252
- "sources",
1253
- "conflict"
1254
- ]
1255
- },
1256
- intersect: {
1257
- required: ["sources"],
1258
- allowed: ["kind", "sources"]
1259
- },
1260
- refine: {
1261
- required: ["source", "fields"],
1262
- allowed: [
1263
- "kind",
1264
- "source",
1265
- "fields"
1266
- ]
1267
- },
1268
- excludeVariants: {
1269
- required: ["source", "variants"],
1270
- allowed: [
1271
- "kind",
1272
- "source",
1273
- "variants"
1274
- ]
1275
- },
1276
- extractVariants: {
1277
- required: ["source", "variants"],
1278
- allowed: [
1279
- "kind",
1280
- "source",
1281
- "variants"
1282
- ]
1283
- }
1284
- };
1285
1090
  function isObject(value) {
1286
1091
  return typeof value === "object" && value !== null && !Array.isArray(value);
1287
1092
  }
@@ -1292,7 +1097,7 @@ function result(term, issues = []) {
1292
1097
  const unresolved = /* @__PURE__ */ new Set();
1293
1098
  const seen = /* @__PURE__ */ new Set();
1294
1099
  const visit = (value) => {
1295
- if (!isObject(value) || seen.has(value) || typeof value.kind !== "string" || !expressionKinds.has(value.kind)) return;
1100
+ if (!isObject(value) || seen.has(value) || typeof value.kind !== "string" || !require_definition.expressionKinds.has(value.kind)) return;
1296
1101
  seen.add(value);
1297
1102
  if (value.kind === "typeVar" && typeof value.name === "string") unresolved.add(value.name);
1298
1103
  for (const [, child] of childTerms(value)) visit(child);
@@ -1341,90 +1146,6 @@ function childTerms(expression) {
1341
1146
  });
1342
1147
  return children;
1343
1148
  }
1344
- function hasOnlyKeys(value, keys) {
1345
- return Object.keys(value).every((key) => keys.includes(key));
1346
- }
1347
- function isSelector(value) {
1348
- if (!isObject(value)) return false;
1349
- if (value.kind === "all") return hasOnlyKeys(value, ["kind"]);
1350
- return value.kind === "keys" && hasOnlyKeys(value, [
1351
- "kind",
1352
- "keys",
1353
- "onMissing"
1354
- ]) && Array.isArray(value.keys) && value.keys.every((key) => typeof key === "string") && new Set(value.keys).size === value.keys.length && (value.onMissing === "error" || value.onMissing === "ignore");
1355
- }
1356
- function expressionShapeIssue(expression) {
1357
- const kind = expression.kind;
1358
- if (kind === "typeVar" && (typeof expression.name !== "string" || !expression.name.trim())) return "typeVar name must be non-blank";
1359
- if (kind === "opaqueHostType" && (!Array.isArray(expression.hostPath) || expression.hostPath.length === 0 || expression.hostPath.some((part) => typeof part !== "string" || !part.trim()))) return "hostPath must be a non-empty path";
1360
- if (kind === "tupleOf" && (!Array.isArray(expression.elements) || !isDense(expression.elements))) return "elements must be a dense array";
1361
- if (kind === "recordOf") {
1362
- if (!Array.isArray(expression.fields) || !isDense(expression.fields)) return "fields must be a dense array";
1363
- const keys = /* @__PURE__ */ new Set();
1364
- for (const field of expression.fields) {
1365
- if (!isObject(field) || !hasOnlyKeys(field, [
1366
- "key",
1367
- "value",
1368
- "required",
1369
- "description"
1370
- ]) || typeof field.key !== "string" || keys.has(field.key)) return "record fields must have unique keys and a valid shape";
1371
- if (field.required !== void 0 && typeof field.required !== "boolean") return "record field required must be a boolean";
1372
- if (field.description !== void 0 && typeof field.description !== "string") return "record field description must be a string";
1373
- keys.add(field.key);
1374
- }
1375
- if (expression.additionalFields !== void 0 && expression.additionalFields !== true && !isObject(expression.additionalFields)) return "additionalFields must be a type term or true";
1376
- if (expression.constraints !== void 0 && (!Array.isArray(expression.constraints) || !isDense(expression.constraints))) return "constraints must be a dense array";
1377
- }
1378
- if (kind === "arrayOf" && expression.constraints !== void 0 && (!Array.isArray(expression.constraints) || !isDense(expression.constraints))) return "constraints must be a dense array";
1379
- if (kind === "taggedUnionOf") {
1380
- if (typeof expression.discriminator !== "string" || !expression.discriminator.trim() || !Array.isArray(expression.variants) || !isDense(expression.variants) || expression.variants.length < 2) return "taggedUnionOf requires a discriminator and at least two dense variants";
1381
- const keys = /* @__PURE__ */ new Set();
1382
- for (const variant of expression.variants) {
1383
- if (!isObject(variant) || !hasOnlyKeys(variant, [
1384
- "key",
1385
- "value",
1386
- "description"
1387
- ]) || typeof variant.key !== "string" || !variant.key.trim() || keys.has(variant.key)) return "taggedUnionOf variants must have unique non-blank keys and a valid shape";
1388
- if (variant.description !== void 0 && typeof variant.description !== "string") return "variant description must be a string";
1389
- keys.add(variant.key);
1390
- }
1391
- }
1392
- if ([
1393
- "fieldsOf",
1394
- "pickFields",
1395
- "omitFields",
1396
- "partialFields",
1397
- "requiredFields"
1398
- ].includes(String(kind)) && !isSelector(expression.fields)) return "fields must be a valid field selector";
1399
- if ((kind === "excludeVariants" || kind === "extractVariants") && !isSelector(expression.variants)) return "variants must be a valid variant selector";
1400
- if (kind === "elementAt" && (!Number.isSafeInteger(expression.index) || expression.index < 0)) return "index must be a non-negative safe integer";
1401
- if (kind === "fieldOf" && typeof expression.key !== "string") return "key must be a string";
1402
- if (kind === "mergeRecords" && (!Array.isArray(expression.sources) || !isDense(expression.sources) || expression.sources.length < 2 || ![
1403
- "leftWins",
1404
- "rightWins",
1405
- "error"
1406
- ].includes(String(expression.conflict)))) return "mergeRecords requires at least two dense sources and a valid conflict policy";
1407
- if (kind === "intersect" && (!Array.isArray(expression.sources) || !isDense(expression.sources) || expression.sources.length < 2)) return "intersect requires at least two dense sources";
1408
- if (kind === "refine") {
1409
- if (!Array.isArray(expression.fields) || !isDense(expression.fields) || expression.fields.length === 0) return "refine requires non-empty dense field actions";
1410
- const keys = /* @__PURE__ */ new Set();
1411
- for (const action of expression.fields) {
1412
- if (!isObject(action) || !hasOnlyKeys(action, [
1413
- "key",
1414
- "require",
1415
- "intersectWith",
1416
- "addConstraints"
1417
- ]) || typeof action.key !== "string" || keys.has(action.key)) return "refine actions must have unique keys and a valid shape";
1418
- if (action.require !== void 0 && action.require !== true) return "refine require must be true when specified";
1419
- if (action.addConstraints !== void 0 && (!Array.isArray(action.addConstraints) || !isDense(action.addConstraints))) return "addConstraints must be a dense array";
1420
- keys.add(action.key);
1421
- }
1422
- }
1423
- }
1424
- function isDense(value) {
1425
- for (let index = 0; index < value.length; index += 1) if (!Object.prototype.hasOwnProperty.call(value, index)) return false;
1426
- return true;
1427
- }
1428
1149
  function replaceChild(expression, path, value) {
1429
1150
  const [key, indexText, subkey] = path.split(".");
1430
1151
  if (indexText === void 0) {
@@ -1571,13 +1292,13 @@ function normalize(term, state, depth = 0) {
1571
1292
  }
1572
1293
  }
1573
1294
  const kind = term.kind;
1574
- if (typeof kind !== "string" || !expressionKinds.has(kind)) return failure("rejected", "expression.kind", "term is neither a valid SchemaNode nor a supported expression");
1575
- const shape = expressionFields[kind];
1295
+ if (typeof kind !== "string" || !require_definition.expressionKinds.has(kind)) return failure("rejected", "expression.kind", "term is neither a valid SchemaNode nor a supported expression");
1296
+ const shape = require_definition.expressionFields[kind];
1576
1297
  const unexpected = Object.keys(term).find((key) => !shape.allowed.includes(key));
1577
1298
  if (unexpected) return failure("rejected", "expression.shape", `unknown field '${unexpected}' for expression '${kind}'`);
1578
1299
  const missing = shape.required.find((key) => !(key in term));
1579
1300
  if (missing) return failure("rejected", "expression.shape", `expression '${kind}' requires field '${missing}'`);
1580
- const shapeIssue = expressionShapeIssue(term);
1301
+ const shapeIssue = require_definition.expressionShapeIssue(term);
1581
1302
  if (shapeIssue) return failure("rejected", "expression.shape", shapeIssue);
1582
1303
  if (state.active.has(term)) return failure("incomplete", "cycle.expression", "expression cycle could not be determined");
1583
1304
  if (kind === "unknown") return result({ kind: "unknown" });
@@ -1738,10 +1459,10 @@ async function evaluateExpressionAsync(term, context = {}) {
1738
1459
  }
1739
1460
  }
1740
1461
  const kind = value.kind;
1741
- if (typeof kind !== "string" || !expressionKinds.has(kind)) return { value };
1742
- const shape = expressionFields[kind];
1462
+ if (typeof kind !== "string" || !require_definition.expressionKinds.has(kind)) return { value };
1463
+ const shape = require_definition.expressionFields[kind];
1743
1464
  if (Object.keys(value).some((key) => !shape.allowed.includes(key)) || shape.required.some((key) => !(key in value))) return { value };
1744
- if (expressionShapeIssue(value)) return { value };
1465
+ if (require_definition.expressionShapeIssue(value)) return { value };
1745
1466
  const copy = { ...value };
1746
1467
  for (const [path, child] of childTerms(value)) {
1747
1468
  const resolved$1 = await resolveTree(child, depth + 1);
@@ -1760,8 +1481,8 @@ async function evaluateExpressionAsync(term, context = {}) {
1760
1481
  maxSteps: Number.MAX_SAFE_INTEGER
1761
1482
  });
1762
1483
  }
1763
- const evaluateSchemaValueTypeTerm = evaluateExpression;
1764
- const evaluateSchemaValueTypeTermAsync = evaluateExpressionAsync;
1484
+ const evaluateSchemaTypeTerm = evaluateExpression;
1485
+ const evaluateSchemaTypeTermAsync = evaluateExpressionAsync;
1765
1486
 
1766
1487
  //#endregion
1767
1488
  //#region src/type-interpreter/type-variable-solver.ts
@@ -1956,16 +1677,16 @@ Object.defineProperty(exports, 'evaluateExpressionAsync', {
1956
1677
  return evaluateExpressionAsync;
1957
1678
  }
1958
1679
  });
1959
- Object.defineProperty(exports, 'evaluateSchemaValueTypeTerm', {
1680
+ Object.defineProperty(exports, 'evaluateSchemaTypeTerm', {
1960
1681
  enumerable: true,
1961
1682
  get: function () {
1962
- return evaluateSchemaValueTypeTerm;
1683
+ return evaluateSchemaTypeTerm;
1963
1684
  }
1964
1685
  });
1965
- Object.defineProperty(exports, 'evaluateSchemaValueTypeTermAsync', {
1686
+ Object.defineProperty(exports, 'evaluateSchemaTypeTermAsync', {
1966
1687
  enumerable: true,
1967
1688
  get: function () {
1968
- return evaluateSchemaValueTypeTermAsync;
1689
+ return evaluateSchemaTypeTermAsync;
1969
1690
  }
1970
1691
  });
1971
1692
  Object.defineProperty(exports, 'solveTypeVariables', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schemair",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "TypeScript wire bindings and authoring tools for SchemaIR",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/schemair/schemair#readme",
@@ -16,7 +16,9 @@
16
16
  "main": "./dist/index.cjs",
17
17
  "module": "./dist/index.js",
18
18
  "types": "./dist/index.d.ts",
19
- "files": ["dist"],
19
+ "files": [
20
+ "dist"
21
+ ],
20
22
  "exports": {
21
23
  ".": {
22
24
  "import": {
@@ -87,12 +89,42 @@
87
89
  "types": "./dist/authoring/index.d.cts",
88
90
  "default": "./dist/authoring/index.cjs"
89
91
  }
92
+ },
93
+ "./standard": {
94
+ "import": {
95
+ "types": "./dist/standard/index.d.ts",
96
+ "default": "./dist/standard/index.js"
97
+ },
98
+ "require": {
99
+ "types": "./dist/standard/index.d.cts",
100
+ "default": "./dist/standard/index.cjs"
101
+ }
102
+ },
103
+ "./standard-schema": {
104
+ "import": {
105
+ "types": "./dist/integrations/standard-schema/index.d.ts",
106
+ "default": "./dist/integrations/standard-schema/index.js"
107
+ },
108
+ "require": {
109
+ "types": "./dist/integrations/standard-schema/index.d.cts",
110
+ "default": "./dist/integrations/standard-schema/index.cjs"
111
+ }
112
+ },
113
+ "./json-schema": {
114
+ "import": {
115
+ "types": "./dist/integrations/json-schema/index.d.ts",
116
+ "default": "./dist/integrations/json-schema/index.js"
117
+ },
118
+ "require": {
119
+ "types": "./dist/integrations/json-schema/index.d.cts",
120
+ "default": "./dist/integrations/json-schema/index.cjs"
121
+ }
90
122
  }
91
123
  },
92
124
  "scripts": {
93
125
  "typecheck": "tsc --noEmit",
94
126
  "build": "tsdown",
95
- "test": "node --import tsx --test tests/conformance.test.ts",
127
+ "test": "node --import tsx --test tests/*.test.ts",
96
128
  "test:package": "pnpm build && node --test tests/package-exports.test.mjs",
97
129
  "prepack": "pnpm build"
98
130
  },
@@ -101,5 +133,8 @@
101
133
  "tsdown": "^0.18.2",
102
134
  "tsx": "^4.20.0",
103
135
  "typescript": "^5.7.2"
136
+ },
137
+ "dependencies": {
138
+ "@standard-schema/spec": "^1.1.0"
104
139
  }
105
140
  }