@formspec/build 0.1.0-alpha.54 → 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/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +44 -12
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +46 -13
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +7 -46
- package/dist/build-beta.d.ts +7 -46
- package/dist/build-internal.d.ts +7 -46
- package/dist/build.d.ts +7 -46
- package/dist/cli.cjs +175 -66
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +172 -54
- package/dist/cli.js.map +1 -1
- package/dist/extensions/registry.d.ts.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 +165 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +167 -51
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +166 -59
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +164 -48
- 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 +5 -5
package/dist/browser.js
CHANGED
|
@@ -832,20 +832,29 @@ function assertNoSerializedNameCollisions(ir) {
|
|
|
832
832
|
}
|
|
833
833
|
|
|
834
834
|
// src/json-schema/ir-generator.ts
|
|
835
|
+
function parseEnumSerialization(value) {
|
|
836
|
+
switch (value) {
|
|
837
|
+
case void 0:
|
|
838
|
+
case "enum":
|
|
839
|
+
return "enum";
|
|
840
|
+
case "oneOf":
|
|
841
|
+
return "oneOf";
|
|
842
|
+
case "smart-size":
|
|
843
|
+
return "smart-size";
|
|
844
|
+
default:
|
|
845
|
+
throw new Error(
|
|
846
|
+
`Invalid enumSerialization "${String(value)}". Expected "enum", "oneOf", or "smart-size".`
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
835
850
|
function makeContext(options) {
|
|
836
851
|
const vendorPrefix = options?.vendorPrefix ?? "x-formspec";
|
|
837
|
-
const
|
|
852
|
+
const enumSerialization = parseEnumSerialization(options?.enumSerialization);
|
|
838
853
|
if (!vendorPrefix.startsWith("x-")) {
|
|
839
854
|
throw new Error(
|
|
840
855
|
`Invalid vendorPrefix "${vendorPrefix}". Extension JSON Schema keywords must start with "x-".`
|
|
841
856
|
);
|
|
842
857
|
}
|
|
843
|
-
if (rawEnumSerialization !== void 0 && rawEnumSerialization !== "enum" && rawEnumSerialization !== "oneOf") {
|
|
844
|
-
throw new Error(
|
|
845
|
-
`Invalid enumSerialization "${rawEnumSerialization}". Expected "enum" or "oneOf".`
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
const enumSerialization = rawEnumSerialization ?? "enum";
|
|
849
858
|
return {
|
|
850
859
|
defs: {},
|
|
851
860
|
typeNameMap: {},
|
|
@@ -1053,21 +1062,31 @@ function generatePrimitiveType(type) {
|
|
|
1053
1062
|
};
|
|
1054
1063
|
}
|
|
1055
1064
|
function generateEnumType(type, ctx) {
|
|
1056
|
-
if (ctx.enumSerialization === "oneOf") {
|
|
1065
|
+
if (ctx.enumSerialization === "oneOf" || ctx.enumSerialization === "smart-size" && shouldSerializeEnumAsOneOf(type)) {
|
|
1057
1066
|
return {
|
|
1058
|
-
oneOf: type.members.map((m) =>
|
|
1059
|
-
const
|
|
1060
|
-
title
|
|
1061
|
-
|
|
1067
|
+
oneOf: type.members.map((m) => {
|
|
1068
|
+
const stringValue = String(m.value);
|
|
1069
|
+
const title = m.displayName !== void 0 && m.displayName !== stringValue ? m.displayName : void 0;
|
|
1070
|
+
return title !== void 0 ? { const: m.value, title } : { const: m.value };
|
|
1071
|
+
})
|
|
1062
1072
|
};
|
|
1063
1073
|
}
|
|
1064
1074
|
const schema = { enum: type.members.map((m) => m.value) };
|
|
1075
|
+
if (ctx.enumSerialization === "smart-size") {
|
|
1076
|
+
return schema;
|
|
1077
|
+
}
|
|
1065
1078
|
const displayNames = buildEnumDisplayNameExtension(type);
|
|
1066
1079
|
if (displayNames !== void 0) {
|
|
1067
1080
|
schema[`${ctx.vendorPrefix}-display-names`] = displayNames;
|
|
1068
1081
|
}
|
|
1069
1082
|
return schema;
|
|
1070
1083
|
}
|
|
1084
|
+
function shouldSerializeEnumAsOneOf(type) {
|
|
1085
|
+
return type.members.some((member) => {
|
|
1086
|
+
const title = member.displayName ?? String(member.value);
|
|
1087
|
+
return title !== String(member.value);
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1071
1090
|
function buildEnumDisplayNameExtension(type) {
|
|
1072
1091
|
if (!type.members.some((member) => member.displayName !== void 0)) {
|
|
1073
1092
|
return void 0;
|
|
@@ -1851,7 +1870,8 @@ import {
|
|
|
1851
1870
|
} from "@formspec/core/internals";
|
|
1852
1871
|
import {
|
|
1853
1872
|
getTagDefinition,
|
|
1854
|
-
normalizeFormSpecTagName
|
|
1873
|
+
normalizeFormSpecTagName,
|
|
1874
|
+
getSyntheticLogger
|
|
1855
1875
|
} from "@formspec/analysis/internal";
|
|
1856
1876
|
var BUILTIN_METADATA_TAGS = /* @__PURE__ */ new Set(["apiName", "displayName"]);
|
|
1857
1877
|
function buildConstraintTagSources(extensions) {
|
|
@@ -1865,6 +1885,11 @@ function buildConstraintTagSources(extensions) {
|
|
|
1865
1885
|
}));
|
|
1866
1886
|
}
|
|
1867
1887
|
function createExtensionRegistry(extensions) {
|
|
1888
|
+
const registryLog = getSyntheticLogger();
|
|
1889
|
+
registryLog.debug("createExtensionRegistry: constructing", {
|
|
1890
|
+
extensionCount: extensions.length,
|
|
1891
|
+
extensionIds: extensions.map((e) => e.extensionId)
|
|
1892
|
+
});
|
|
1868
1893
|
const reservedTagSources = buildConstraintTagSources(extensions);
|
|
1869
1894
|
let symbolMap = /* @__PURE__ */ new Map();
|
|
1870
1895
|
const typeMap = /* @__PURE__ */ new Map();
|
|
@@ -1996,6 +2021,14 @@ function createExtensionRegistry(extensions) {
|
|
|
1996
2021
|
}
|
|
1997
2022
|
}
|
|
1998
2023
|
}
|
|
2024
|
+
registryLog.debug("createExtensionRegistry: complete", {
|
|
2025
|
+
typeCount: typeMap.size,
|
|
2026
|
+
constraintCount: constraintMap.size,
|
|
2027
|
+
constraintTagCount: constraintTagMap.size,
|
|
2028
|
+
broadeningCount: builtinBroadeningMap.size,
|
|
2029
|
+
annotationCount: annotationMap.size,
|
|
2030
|
+
metadataSlotCount: metadataSlotMap.size
|
|
2031
|
+
});
|
|
1999
2032
|
return {
|
|
2000
2033
|
extensions,
|
|
2001
2034
|
findType: (typeId) => typeMap.get(typeId),
|