@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/cli.js
CHANGED
|
@@ -996,20 +996,29 @@ var init_collision_guards = __esm({
|
|
|
996
996
|
});
|
|
997
997
|
|
|
998
998
|
// src/json-schema/ir-generator.ts
|
|
999
|
+
function parseEnumSerialization(value) {
|
|
1000
|
+
switch (value) {
|
|
1001
|
+
case void 0:
|
|
1002
|
+
case "enum":
|
|
1003
|
+
return "enum";
|
|
1004
|
+
case "oneOf":
|
|
1005
|
+
return "oneOf";
|
|
1006
|
+
case "smart-size":
|
|
1007
|
+
return "smart-size";
|
|
1008
|
+
default:
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
`Invalid enumSerialization "${String(value)}". Expected "enum", "oneOf", or "smart-size".`
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
999
1014
|
function makeContext(options) {
|
|
1000
1015
|
const vendorPrefix = options?.vendorPrefix ?? "x-formspec";
|
|
1001
|
-
const
|
|
1016
|
+
const enumSerialization = parseEnumSerialization(options?.enumSerialization);
|
|
1002
1017
|
if (!vendorPrefix.startsWith("x-")) {
|
|
1003
1018
|
throw new Error(
|
|
1004
1019
|
`Invalid vendorPrefix "${vendorPrefix}". Extension JSON Schema keywords must start with "x-".`
|
|
1005
1020
|
);
|
|
1006
1021
|
}
|
|
1007
|
-
if (rawEnumSerialization !== void 0 && rawEnumSerialization !== "enum" && rawEnumSerialization !== "oneOf") {
|
|
1008
|
-
throw new Error(
|
|
1009
|
-
`Invalid enumSerialization "${rawEnumSerialization}". Expected "enum" or "oneOf".`
|
|
1010
|
-
);
|
|
1011
|
-
}
|
|
1012
|
-
const enumSerialization = rawEnumSerialization ?? "enum";
|
|
1013
1022
|
return {
|
|
1014
1023
|
defs: {},
|
|
1015
1024
|
typeNameMap: {},
|
|
@@ -1217,7 +1226,7 @@ function generatePrimitiveType(type) {
|
|
|
1217
1226
|
};
|
|
1218
1227
|
}
|
|
1219
1228
|
function generateEnumType(type, ctx) {
|
|
1220
|
-
if (ctx.enumSerialization === "oneOf") {
|
|
1229
|
+
if (ctx.enumSerialization === "oneOf" || ctx.enumSerialization === "smart-size" && shouldSerializeEnumAsOneOf(type)) {
|
|
1221
1230
|
return {
|
|
1222
1231
|
oneOf: type.members.map((m) => {
|
|
1223
1232
|
const stringValue = String(m.value);
|
|
@@ -1227,12 +1236,21 @@ function generateEnumType(type, ctx) {
|
|
|
1227
1236
|
};
|
|
1228
1237
|
}
|
|
1229
1238
|
const schema = { enum: type.members.map((m) => m.value) };
|
|
1239
|
+
if (ctx.enumSerialization === "smart-size") {
|
|
1240
|
+
return schema;
|
|
1241
|
+
}
|
|
1230
1242
|
const displayNames = buildEnumDisplayNameExtension(type);
|
|
1231
1243
|
if (displayNames !== void 0) {
|
|
1232
1244
|
schema[`${ctx.vendorPrefix}-display-names`] = displayNames;
|
|
1233
1245
|
}
|
|
1234
1246
|
return schema;
|
|
1235
1247
|
}
|
|
1248
|
+
function shouldSerializeEnumAsOneOf(type) {
|
|
1249
|
+
return type.members.some((member) => {
|
|
1250
|
+
const title = member.displayName ?? String(member.value);
|
|
1251
|
+
return title !== String(member.value);
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1236
1254
|
function buildEnumDisplayNameExtension(type) {
|
|
1237
1255
|
if (!type.members.some((member) => member.displayName !== void 0)) {
|
|
1238
1256
|
return void 0;
|
|
@@ -7194,7 +7212,7 @@ Usage:
|
|
|
7194
7212
|
Options:
|
|
7195
7213
|
-o, --out-dir <dir> Output directory (default: ./generated)
|
|
7196
7214
|
-n, --name <name> Base name for output files (default: derived from input)
|
|
7197
|
-
--enum-serialization <enum|oneOf>
|
|
7215
|
+
--enum-serialization <enum|oneOf|smart-size>
|
|
7198
7216
|
Enum JSON Schema representation (default: enum)
|
|
7199
7217
|
-h, --help Show this help message
|
|
7200
7218
|
|
|
@@ -7246,8 +7264,10 @@ function parseArgs(args) {
|
|
|
7246
7264
|
console.error("Error: --enum-serialization requires a value");
|
|
7247
7265
|
return null;
|
|
7248
7266
|
}
|
|
7249
|
-
if (nextArg !== "enum" && nextArg !== "oneOf") {
|
|
7250
|
-
console.error(
|
|
7267
|
+
if (nextArg !== "enum" && nextArg !== "oneOf" && nextArg !== "smart-size") {
|
|
7268
|
+
console.error(
|
|
7269
|
+
'Error: --enum-serialization must be "enum", "oneOf", or "smart-size"'
|
|
7270
|
+
);
|
|
7251
7271
|
return null;
|
|
7252
7272
|
}
|
|
7253
7273
|
enumSerialization = nextArg;
|