@formspec/build 0.1.0-alpha.55 → 0.1.0-alpha.58
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/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +26 -8
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +26 -8
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +7 -6
- package/dist/build-beta.d.ts +7 -6
- package/dist/build-internal.d.ts +7 -6
- package/dist/build.d.ts +7 -6
- package/dist/cli.cjs +86 -19
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +88 -19
- package/dist/cli.js.map +1 -1
- package/dist/generators/class-schema.d.ts +2 -2
- package/dist/generators/class-schema.d.ts.map +1 -1
- package/dist/index.cjs +81 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +83 -16
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +81 -16
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +83 -16
- package/dist/internals.js.map +1 -1
- package/dist/json-schema/generator.d.ts +1 -1
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/json-schema/ir-generator.d.ts +1 -1
- package/dist/json-schema/ir-generator.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/internals.cjs
CHANGED
|
@@ -1142,6 +1142,7 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
1142
1142
|
sourceFile,
|
|
1143
1143
|
tagName,
|
|
1144
1144
|
parsedTag,
|
|
1145
|
+
text,
|
|
1145
1146
|
provenance,
|
|
1146
1147
|
supportingDeclarations,
|
|
1147
1148
|
options
|
|
@@ -1169,6 +1170,9 @@ function renderSyntheticArgumentExpression(valueKind, argumentText) {
|
|
|
1169
1170
|
case "number":
|
|
1170
1171
|
case "integer":
|
|
1171
1172
|
case "signedInteger":
|
|
1173
|
+
if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
|
|
1174
|
+
return trimmed;
|
|
1175
|
+
}
|
|
1172
1176
|
return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
|
|
1173
1177
|
case "string":
|
|
1174
1178
|
return JSON.stringify(argumentText);
|
|
@@ -1380,7 +1384,7 @@ function hasBuiltinConstraintBroadening(tagName, options) {
|
|
|
1380
1384
|
const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
|
|
1381
1385
|
return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
|
|
1382
1386
|
}
|
|
1383
|
-
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, provenance, supportingDeclarations, options) {
|
|
1387
|
+
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, supportingDeclarations, options) {
|
|
1384
1388
|
if (!(0, import_internals3.isBuiltinConstraintName)(tagName)) {
|
|
1385
1389
|
return [];
|
|
1386
1390
|
}
|
|
@@ -1401,8 +1405,10 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1401
1405
|
const log = (0, import_internal3.getBuildLogger)();
|
|
1402
1406
|
const broadeningLog = (0, import_internal3.getBroadeningLogger)();
|
|
1403
1407
|
const syntheticLog = (0, import_internal3.getSyntheticLogger)();
|
|
1408
|
+
const typedParserLog = (0, import_internal3.getTypedParserLogger)();
|
|
1404
1409
|
const logsEnabled = log !== import_core.noopLogger || broadeningLog !== import_core.noopLogger;
|
|
1405
1410
|
const syntheticTraceEnabled = syntheticLog !== import_core.noopLogger;
|
|
1411
|
+
const typedParserTraceEnabled = typedParserLog !== import_core.noopLogger;
|
|
1406
1412
|
const logStart = logsEnabled ? (0, import_internal3.nowMicros)() : 0;
|
|
1407
1413
|
const subjectTypeKind = logsEnabled ? (0, import_internal3.describeTypeKind)(subjectType, checker) : "";
|
|
1408
1414
|
function emit(outcome, result2) {
|
|
@@ -1510,16 +1516,57 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1510
1516
|
]);
|
|
1511
1517
|
}
|
|
1512
1518
|
}
|
|
1513
|
-
const
|
|
1514
|
-
definition.valueKind,
|
|
1515
|
-
parsedTag?.argumentText ?? ""
|
|
1516
|
-
);
|
|
1517
|
-
if (definition.requiresArgument && argumentExpression === null) {
|
|
1518
|
-
return emit("A-pass", []);
|
|
1519
|
-
}
|
|
1519
|
+
const effectiveArgumentText = parsedTag !== null ? (0, import_internal2.parseTagSyntax)(tagName, rawText).argumentText : rawText;
|
|
1520
1520
|
if (hasBroadening) {
|
|
1521
1521
|
return emit("bypass", []);
|
|
1522
1522
|
}
|
|
1523
|
+
const typedParseResult = (0, import_internal3.parseTagArgument)(tagName, effectiveArgumentText, "build");
|
|
1524
|
+
if (!typedParseResult.ok) {
|
|
1525
|
+
if (typedParserTraceEnabled) {
|
|
1526
|
+
typedParserLog.trace("typed-parser C-reject", {
|
|
1527
|
+
consumer: "build",
|
|
1528
|
+
tag: tagName,
|
|
1529
|
+
placement: nonNullPlacement,
|
|
1530
|
+
subjectTypeKind: subjectTypeKind !== "" ? subjectTypeKind : "-",
|
|
1531
|
+
roleOutcome: "C-reject",
|
|
1532
|
+
diagnosticCode: typedParseResult.diagnostic.code
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
let mappedCode;
|
|
1536
|
+
switch (typedParseResult.diagnostic.code) {
|
|
1537
|
+
case "MISSING_TAG_ARGUMENT":
|
|
1538
|
+
mappedCode = "MISSING_TAG_ARGUMENT";
|
|
1539
|
+
break;
|
|
1540
|
+
case "INVALID_TAG_ARGUMENT":
|
|
1541
|
+
mappedCode = "INVALID_TAG_ARGUMENT";
|
|
1542
|
+
break;
|
|
1543
|
+
case "UNKNOWN_TAG":
|
|
1544
|
+
throw new Error(
|
|
1545
|
+
`Unexpected UNKNOWN_TAG from parseTagArgument("${tagName}") \u2014 tag was resolved via getTagDefinition.`
|
|
1546
|
+
);
|
|
1547
|
+
default: {
|
|
1548
|
+
const _exhaustive = typedParseResult.diagnostic.code;
|
|
1549
|
+
throw new Error(`Unknown diagnostic code: ${String(_exhaustive)}`);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
return emit("C-reject", [
|
|
1553
|
+
makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
|
|
1554
|
+
]);
|
|
1555
|
+
}
|
|
1556
|
+
if (typedParserTraceEnabled) {
|
|
1557
|
+
typedParserLog.trace("typed-parser C-pass", {
|
|
1558
|
+
consumer: "build",
|
|
1559
|
+
tag: tagName,
|
|
1560
|
+
placement: nonNullPlacement,
|
|
1561
|
+
subjectTypeKind: subjectTypeKind !== "" ? subjectTypeKind : "-",
|
|
1562
|
+
roleOutcome: "C-pass",
|
|
1563
|
+
valueKind: typedParseResult.value.kind
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
const argumentExpression = renderSyntheticArgumentExpression(
|
|
1567
|
+
definition.valueKind,
|
|
1568
|
+
effectiveArgumentText
|
|
1569
|
+
);
|
|
1523
1570
|
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
1524
1571
|
const hostType = options?.hostType ?? subjectType;
|
|
1525
1572
|
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
@@ -4439,20 +4486,29 @@ function assertNoSerializedNameCollisions(ir) {
|
|
|
4439
4486
|
}
|
|
4440
4487
|
|
|
4441
4488
|
// src/json-schema/ir-generator.ts
|
|
4489
|
+
function parseEnumSerialization(value) {
|
|
4490
|
+
switch (value) {
|
|
4491
|
+
case void 0:
|
|
4492
|
+
case "enum":
|
|
4493
|
+
return "enum";
|
|
4494
|
+
case "oneOf":
|
|
4495
|
+
return "oneOf";
|
|
4496
|
+
case "smart-size":
|
|
4497
|
+
return "smart-size";
|
|
4498
|
+
default:
|
|
4499
|
+
throw new Error(
|
|
4500
|
+
`Invalid enumSerialization "${String(value)}". Expected "enum", "oneOf", or "smart-size".`
|
|
4501
|
+
);
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4442
4504
|
function makeContext(options) {
|
|
4443
4505
|
const vendorPrefix = options?.vendorPrefix ?? "x-formspec";
|
|
4444
|
-
const
|
|
4506
|
+
const enumSerialization = parseEnumSerialization(options?.enumSerialization);
|
|
4445
4507
|
if (!vendorPrefix.startsWith("x-")) {
|
|
4446
4508
|
throw new Error(
|
|
4447
4509
|
`Invalid vendorPrefix "${vendorPrefix}". Extension JSON Schema keywords must start with "x-".`
|
|
4448
4510
|
);
|
|
4449
4511
|
}
|
|
4450
|
-
if (rawEnumSerialization !== void 0 && rawEnumSerialization !== "enum" && rawEnumSerialization !== "oneOf") {
|
|
4451
|
-
throw new Error(
|
|
4452
|
-
`Invalid enumSerialization "${rawEnumSerialization}". Expected "enum" or "oneOf".`
|
|
4453
|
-
);
|
|
4454
|
-
}
|
|
4455
|
-
const enumSerialization = rawEnumSerialization ?? "enum";
|
|
4456
4512
|
return {
|
|
4457
4513
|
defs: {},
|
|
4458
4514
|
typeNameMap: {},
|
|
@@ -4660,7 +4716,7 @@ function generatePrimitiveType(type) {
|
|
|
4660
4716
|
};
|
|
4661
4717
|
}
|
|
4662
4718
|
function generateEnumType(type, ctx) {
|
|
4663
|
-
if (ctx.enumSerialization === "oneOf") {
|
|
4719
|
+
if (ctx.enumSerialization === "oneOf" || ctx.enumSerialization === "smart-size" && shouldSerializeEnumAsOneOf(type)) {
|
|
4664
4720
|
return {
|
|
4665
4721
|
oneOf: type.members.map((m) => {
|
|
4666
4722
|
const stringValue = String(m.value);
|
|
@@ -4670,12 +4726,21 @@ function generateEnumType(type, ctx) {
|
|
|
4670
4726
|
};
|
|
4671
4727
|
}
|
|
4672
4728
|
const schema = { enum: type.members.map((m) => m.value) };
|
|
4729
|
+
if (ctx.enumSerialization === "smart-size") {
|
|
4730
|
+
return schema;
|
|
4731
|
+
}
|
|
4673
4732
|
const displayNames = buildEnumDisplayNameExtension(type);
|
|
4674
4733
|
if (displayNames !== void 0) {
|
|
4675
4734
|
schema[`${ctx.vendorPrefix}-display-names`] = displayNames;
|
|
4676
4735
|
}
|
|
4677
4736
|
return schema;
|
|
4678
4737
|
}
|
|
4738
|
+
function shouldSerializeEnumAsOneOf(type) {
|
|
4739
|
+
return type.members.some((member) => {
|
|
4740
|
+
const title = member.displayName ?? String(member.value);
|
|
4741
|
+
return title !== String(member.value);
|
|
4742
|
+
});
|
|
4743
|
+
}
|
|
4679
4744
|
function buildEnumDisplayNameExtension(type) {
|
|
4680
4745
|
if (!type.members.some((member) => member.displayName !== void 0)) {
|
|
4681
4746
|
return void 0;
|