@formspec/build 0.1.0-alpha.55 → 0.1.0-alpha.57
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/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 +31 -11
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +31 -11
- 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 +26 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +26 -8
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +26 -8
- 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.js
CHANGED
|
@@ -4413,20 +4413,29 @@ function assertNoSerializedNameCollisions(ir) {
|
|
|
4413
4413
|
}
|
|
4414
4414
|
|
|
4415
4415
|
// src/json-schema/ir-generator.ts
|
|
4416
|
+
function parseEnumSerialization(value) {
|
|
4417
|
+
switch (value) {
|
|
4418
|
+
case void 0:
|
|
4419
|
+
case "enum":
|
|
4420
|
+
return "enum";
|
|
4421
|
+
case "oneOf":
|
|
4422
|
+
return "oneOf";
|
|
4423
|
+
case "smart-size":
|
|
4424
|
+
return "smart-size";
|
|
4425
|
+
default:
|
|
4426
|
+
throw new Error(
|
|
4427
|
+
`Invalid enumSerialization "${String(value)}". Expected "enum", "oneOf", or "smart-size".`
|
|
4428
|
+
);
|
|
4429
|
+
}
|
|
4430
|
+
}
|
|
4416
4431
|
function makeContext(options) {
|
|
4417
4432
|
const vendorPrefix = options?.vendorPrefix ?? "x-formspec";
|
|
4418
|
-
const
|
|
4433
|
+
const enumSerialization = parseEnumSerialization(options?.enumSerialization);
|
|
4419
4434
|
if (!vendorPrefix.startsWith("x-")) {
|
|
4420
4435
|
throw new Error(
|
|
4421
4436
|
`Invalid vendorPrefix "${vendorPrefix}". Extension JSON Schema keywords must start with "x-".`
|
|
4422
4437
|
);
|
|
4423
4438
|
}
|
|
4424
|
-
if (rawEnumSerialization !== void 0 && rawEnumSerialization !== "enum" && rawEnumSerialization !== "oneOf") {
|
|
4425
|
-
throw new Error(
|
|
4426
|
-
`Invalid enumSerialization "${rawEnumSerialization}". Expected "enum" or "oneOf".`
|
|
4427
|
-
);
|
|
4428
|
-
}
|
|
4429
|
-
const enumSerialization = rawEnumSerialization ?? "enum";
|
|
4430
4439
|
return {
|
|
4431
4440
|
defs: {},
|
|
4432
4441
|
typeNameMap: {},
|
|
@@ -4634,7 +4643,7 @@ function generatePrimitiveType(type) {
|
|
|
4634
4643
|
};
|
|
4635
4644
|
}
|
|
4636
4645
|
function generateEnumType(type, ctx) {
|
|
4637
|
-
if (ctx.enumSerialization === "oneOf") {
|
|
4646
|
+
if (ctx.enumSerialization === "oneOf" || ctx.enumSerialization === "smart-size" && shouldSerializeEnumAsOneOf(type)) {
|
|
4638
4647
|
return {
|
|
4639
4648
|
oneOf: type.members.map((m) => {
|
|
4640
4649
|
const stringValue = String(m.value);
|
|
@@ -4644,12 +4653,21 @@ function generateEnumType(type, ctx) {
|
|
|
4644
4653
|
};
|
|
4645
4654
|
}
|
|
4646
4655
|
const schema = { enum: type.members.map((m) => m.value) };
|
|
4656
|
+
if (ctx.enumSerialization === "smart-size") {
|
|
4657
|
+
return schema;
|
|
4658
|
+
}
|
|
4647
4659
|
const displayNames = buildEnumDisplayNameExtension(type);
|
|
4648
4660
|
if (displayNames !== void 0) {
|
|
4649
4661
|
schema[`${ctx.vendorPrefix}-display-names`] = displayNames;
|
|
4650
4662
|
}
|
|
4651
4663
|
return schema;
|
|
4652
4664
|
}
|
|
4665
|
+
function shouldSerializeEnumAsOneOf(type) {
|
|
4666
|
+
return type.members.some((member) => {
|
|
4667
|
+
const title = member.displayName ?? String(member.value);
|
|
4668
|
+
return title !== String(member.value);
|
|
4669
|
+
});
|
|
4670
|
+
}
|
|
4653
4671
|
function buildEnumDisplayNameExtension(type) {
|
|
4654
4672
|
if (!type.members.some((member) => member.displayName !== void 0)) {
|
|
4655
4673
|
return void 0;
|