@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/build-alpha.d.ts
CHANGED
|
@@ -905,11 +905,12 @@ export declare interface FormSpecConfig {
|
|
|
905
905
|
readonly vendorPrefix?: string;
|
|
906
906
|
/**
|
|
907
907
|
* JSON Schema representation for static enums.
|
|
908
|
-
* - "enum":
|
|
909
|
-
* - "oneOf":
|
|
908
|
+
* - "enum": compact `enum` output, plus a display-name extension when labels exist
|
|
909
|
+
* - "oneOf": per-member `const` output, with `title` only for distinct labels
|
|
910
|
+
* - "smart-size": uses `enum` unless a distinct display label would be lost
|
|
910
911
|
* @defaultValue "enum"
|
|
911
912
|
*/
|
|
912
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
913
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
913
914
|
/**
|
|
914
915
|
* Per-package configuration overrides for monorepos.
|
|
915
916
|
* Keys are glob patterns matched against file paths relative to
|
|
@@ -928,7 +929,7 @@ declare interface FormSpecPackageOverride {
|
|
|
928
929
|
/** Override constraint surface for this package. */
|
|
929
930
|
readonly constraints?: ConstraintConfig;
|
|
930
931
|
/** Override enum serialization for this package. */
|
|
931
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
932
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
932
933
|
/** Override metadata policy for this package. */
|
|
933
934
|
readonly metadata?: MetadataPolicyInput_2;
|
|
934
935
|
}
|
|
@@ -1011,7 +1012,7 @@ export declare interface GenerateJsonSchemaOptions {
|
|
|
1011
1012
|
* JSON Schema representation to use for static enums.
|
|
1012
1013
|
* @defaultValue "enum"
|
|
1013
1014
|
*/
|
|
1014
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
1015
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
1015
1016
|
/** Metadata resolution policy for chain DSL generation. */
|
|
1016
1017
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1017
1018
|
/**
|
|
@@ -2173,7 +2174,7 @@ export declare interface StaticSchemaGenerationOptions {
|
|
|
2173
2174
|
* @defaultValue "enum"
|
|
2174
2175
|
* @deprecated Provide a `FormSpecConfig` via the `config` option instead.
|
|
2175
2176
|
*/
|
|
2176
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
2177
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
2177
2178
|
/**
|
|
2178
2179
|
* Metadata resolution policy for static schema generation.
|
|
2179
2180
|
* @deprecated Provide a `FormSpecConfig` via the `config` option instead.
|
package/dist/build-beta.d.ts
CHANGED
|
@@ -905,11 +905,12 @@ export declare interface FormSpecConfig {
|
|
|
905
905
|
readonly vendorPrefix?: string;
|
|
906
906
|
/**
|
|
907
907
|
* JSON Schema representation for static enums.
|
|
908
|
-
* - "enum":
|
|
909
|
-
* - "oneOf":
|
|
908
|
+
* - "enum": compact `enum` output, plus a display-name extension when labels exist
|
|
909
|
+
* - "oneOf": per-member `const` output, with `title` only for distinct labels
|
|
910
|
+
* - "smart-size": uses `enum` unless a distinct display label would be lost
|
|
910
911
|
* @defaultValue "enum"
|
|
911
912
|
*/
|
|
912
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
913
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
913
914
|
/**
|
|
914
915
|
* Per-package configuration overrides for monorepos.
|
|
915
916
|
* Keys are glob patterns matched against file paths relative to
|
|
@@ -928,7 +929,7 @@ declare interface FormSpecPackageOverride {
|
|
|
928
929
|
/** Override constraint surface for this package. */
|
|
929
930
|
readonly constraints?: ConstraintConfig;
|
|
930
931
|
/** Override enum serialization for this package. */
|
|
931
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
932
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
932
933
|
/** Override metadata policy for this package. */
|
|
933
934
|
readonly metadata?: MetadataPolicyInput_2;
|
|
934
935
|
}
|
|
@@ -1011,7 +1012,7 @@ export declare interface GenerateJsonSchemaOptions {
|
|
|
1011
1012
|
* JSON Schema representation to use for static enums.
|
|
1012
1013
|
* @defaultValue "enum"
|
|
1013
1014
|
*/
|
|
1014
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
1015
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
1015
1016
|
/** Metadata resolution policy for chain DSL generation. */
|
|
1016
1017
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1017
1018
|
/**
|
|
@@ -2173,7 +2174,7 @@ export declare interface StaticSchemaGenerationOptions {
|
|
|
2173
2174
|
* @defaultValue "enum"
|
|
2174
2175
|
* @deprecated Provide a `FormSpecConfig` via the `config` option instead.
|
|
2175
2176
|
*/
|
|
2176
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
2177
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
2177
2178
|
/**
|
|
2178
2179
|
* Metadata resolution policy for static schema generation.
|
|
2179
2180
|
* @deprecated Provide a `FormSpecConfig` via the `config` option instead.
|
package/dist/build-internal.d.ts
CHANGED
|
@@ -905,11 +905,12 @@ export declare interface FormSpecConfig {
|
|
|
905
905
|
readonly vendorPrefix?: string;
|
|
906
906
|
/**
|
|
907
907
|
* JSON Schema representation for static enums.
|
|
908
|
-
* - "enum":
|
|
909
|
-
* - "oneOf":
|
|
908
|
+
* - "enum": compact `enum` output, plus a display-name extension when labels exist
|
|
909
|
+
* - "oneOf": per-member `const` output, with `title` only for distinct labels
|
|
910
|
+
* - "smart-size": uses `enum` unless a distinct display label would be lost
|
|
910
911
|
* @defaultValue "enum"
|
|
911
912
|
*/
|
|
912
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
913
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
913
914
|
/**
|
|
914
915
|
* Per-package configuration overrides for monorepos.
|
|
915
916
|
* Keys are glob patterns matched against file paths relative to
|
|
@@ -928,7 +929,7 @@ declare interface FormSpecPackageOverride {
|
|
|
928
929
|
/** Override constraint surface for this package. */
|
|
929
930
|
readonly constraints?: ConstraintConfig;
|
|
930
931
|
/** Override enum serialization for this package. */
|
|
931
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
932
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
932
933
|
/** Override metadata policy for this package. */
|
|
933
934
|
readonly metadata?: MetadataPolicyInput_2;
|
|
934
935
|
}
|
|
@@ -1011,7 +1012,7 @@ export declare interface GenerateJsonSchemaOptions {
|
|
|
1011
1012
|
* JSON Schema representation to use for static enums.
|
|
1012
1013
|
* @defaultValue "enum"
|
|
1013
1014
|
*/
|
|
1014
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
1015
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
1015
1016
|
/** Metadata resolution policy for chain DSL generation. */
|
|
1016
1017
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1017
1018
|
/**
|
|
@@ -2173,7 +2174,7 @@ export declare interface StaticSchemaGenerationOptions {
|
|
|
2173
2174
|
* @defaultValue "enum"
|
|
2174
2175
|
* @deprecated Provide a `FormSpecConfig` via the `config` option instead.
|
|
2175
2176
|
*/
|
|
2176
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
2177
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
2177
2178
|
/**
|
|
2178
2179
|
* Metadata resolution policy for static schema generation.
|
|
2179
2180
|
* @deprecated Provide a `FormSpecConfig` via the `config` option instead.
|
package/dist/build.d.ts
CHANGED
|
@@ -905,11 +905,12 @@ export declare interface FormSpecConfig {
|
|
|
905
905
|
readonly vendorPrefix?: string;
|
|
906
906
|
/**
|
|
907
907
|
* JSON Schema representation for static enums.
|
|
908
|
-
* - "enum":
|
|
909
|
-
* - "oneOf":
|
|
908
|
+
* - "enum": compact `enum` output, plus a display-name extension when labels exist
|
|
909
|
+
* - "oneOf": per-member `const` output, with `title` only for distinct labels
|
|
910
|
+
* - "smart-size": uses `enum` unless a distinct display label would be lost
|
|
910
911
|
* @defaultValue "enum"
|
|
911
912
|
*/
|
|
912
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
913
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
913
914
|
/**
|
|
914
915
|
* Per-package configuration overrides for monorepos.
|
|
915
916
|
* Keys are glob patterns matched against file paths relative to
|
|
@@ -928,7 +929,7 @@ declare interface FormSpecPackageOverride {
|
|
|
928
929
|
/** Override constraint surface for this package. */
|
|
929
930
|
readonly constraints?: ConstraintConfig;
|
|
930
931
|
/** Override enum serialization for this package. */
|
|
931
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
932
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
932
933
|
/** Override metadata policy for this package. */
|
|
933
934
|
readonly metadata?: MetadataPolicyInput_2;
|
|
934
935
|
}
|
|
@@ -1011,7 +1012,7 @@ export declare interface GenerateJsonSchemaOptions {
|
|
|
1011
1012
|
* JSON Schema representation to use for static enums.
|
|
1012
1013
|
* @defaultValue "enum"
|
|
1013
1014
|
*/
|
|
1014
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
1015
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
1015
1016
|
/** Metadata resolution policy for chain DSL generation. */
|
|
1016
1017
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1017
1018
|
/**
|
|
@@ -2173,7 +2174,7 @@ export declare interface StaticSchemaGenerationOptions {
|
|
|
2173
2174
|
* @defaultValue "enum"
|
|
2174
2175
|
* @deprecated Provide a `FormSpecConfig` via the `config` option instead.
|
|
2175
2176
|
*/
|
|
2176
|
-
readonly enumSerialization?: "enum" | "oneOf";
|
|
2177
|
+
readonly enumSerialization?: "enum" | "oneOf" | "smart-size";
|
|
2177
2178
|
/**
|
|
2178
2179
|
* Metadata resolution policy for static schema generation.
|
|
2179
2180
|
* @deprecated Provide a `FormSpecConfig` via the `config` option instead.
|
package/dist/cli.cjs
CHANGED
|
@@ -1018,20 +1018,29 @@ var init_collision_guards = __esm({
|
|
|
1018
1018
|
});
|
|
1019
1019
|
|
|
1020
1020
|
// src/json-schema/ir-generator.ts
|
|
1021
|
+
function parseEnumSerialization(value) {
|
|
1022
|
+
switch (value) {
|
|
1023
|
+
case void 0:
|
|
1024
|
+
case "enum":
|
|
1025
|
+
return "enum";
|
|
1026
|
+
case "oneOf":
|
|
1027
|
+
return "oneOf";
|
|
1028
|
+
case "smart-size":
|
|
1029
|
+
return "smart-size";
|
|
1030
|
+
default:
|
|
1031
|
+
throw new Error(
|
|
1032
|
+
`Invalid enumSerialization "${String(value)}". Expected "enum", "oneOf", or "smart-size".`
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1021
1036
|
function makeContext(options) {
|
|
1022
1037
|
const vendorPrefix = options?.vendorPrefix ?? "x-formspec";
|
|
1023
|
-
const
|
|
1038
|
+
const enumSerialization = parseEnumSerialization(options?.enumSerialization);
|
|
1024
1039
|
if (!vendorPrefix.startsWith("x-")) {
|
|
1025
1040
|
throw new Error(
|
|
1026
1041
|
`Invalid vendorPrefix "${vendorPrefix}". Extension JSON Schema keywords must start with "x-".`
|
|
1027
1042
|
);
|
|
1028
1043
|
}
|
|
1029
|
-
if (rawEnumSerialization !== void 0 && rawEnumSerialization !== "enum" && rawEnumSerialization !== "oneOf") {
|
|
1030
|
-
throw new Error(
|
|
1031
|
-
`Invalid enumSerialization "${rawEnumSerialization}". Expected "enum" or "oneOf".`
|
|
1032
|
-
);
|
|
1033
|
-
}
|
|
1034
|
-
const enumSerialization = rawEnumSerialization ?? "enum";
|
|
1035
1044
|
return {
|
|
1036
1045
|
defs: {},
|
|
1037
1046
|
typeNameMap: {},
|
|
@@ -1239,7 +1248,7 @@ function generatePrimitiveType(type) {
|
|
|
1239
1248
|
};
|
|
1240
1249
|
}
|
|
1241
1250
|
function generateEnumType(type, ctx) {
|
|
1242
|
-
if (ctx.enumSerialization === "oneOf") {
|
|
1251
|
+
if (ctx.enumSerialization === "oneOf" || ctx.enumSerialization === "smart-size" && shouldSerializeEnumAsOneOf(type)) {
|
|
1243
1252
|
return {
|
|
1244
1253
|
oneOf: type.members.map((m) => {
|
|
1245
1254
|
const stringValue = String(m.value);
|
|
@@ -1249,12 +1258,21 @@ function generateEnumType(type, ctx) {
|
|
|
1249
1258
|
};
|
|
1250
1259
|
}
|
|
1251
1260
|
const schema = { enum: type.members.map((m) => m.value) };
|
|
1261
|
+
if (ctx.enumSerialization === "smart-size") {
|
|
1262
|
+
return schema;
|
|
1263
|
+
}
|
|
1252
1264
|
const displayNames = buildEnumDisplayNameExtension(type);
|
|
1253
1265
|
if (displayNames !== void 0) {
|
|
1254
1266
|
schema[`${ctx.vendorPrefix}-display-names`] = displayNames;
|
|
1255
1267
|
}
|
|
1256
1268
|
return schema;
|
|
1257
1269
|
}
|
|
1270
|
+
function shouldSerializeEnumAsOneOf(type) {
|
|
1271
|
+
return type.members.some((member) => {
|
|
1272
|
+
const title = member.displayName ?? String(member.value);
|
|
1273
|
+
return title !== String(member.value);
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1258
1276
|
function buildEnumDisplayNameExtension(type) {
|
|
1259
1277
|
if (!type.members.some((member) => member.displayName !== void 0)) {
|
|
1260
1278
|
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;
|