@formspec/build 0.1.0-alpha.37 → 0.1.0-alpha.38

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/README.md CHANGED
@@ -180,6 +180,41 @@ const result = generateSchemas({
180
180
 
181
181
  Generation validates canonical IR before emitting schemas. Invalid inputs now fail generation with structured diagnostic codes surfaced in the thrown error.
182
182
 
183
+ ### Handling Generation Failures
184
+
185
+ Static generation APIs such as `generateSchemas()` still throw on invalid input, but the thrown error message now includes stable diagnostic codes that consumers can inspect or surface directly.
186
+
187
+ ```ts
188
+ import { generateSchemas } from "@formspec/build";
189
+
190
+ try {
191
+ const { jsonSchema, uiSchema } = generateSchemas({
192
+ filePath: "./src/forms.ts",
193
+ typeName: "Invoice",
194
+ });
195
+ } catch (error) {
196
+ const message = error instanceof Error ? error.message : String(error);
197
+
198
+ if (message.includes("UNSUPPORTED_CUSTOM_TYPE_OVERRIDE")) {
199
+ // An extension tried to override a TS global built-in such as Date or Array
200
+ } else if (message.includes("SYNTHETIC_SETUP_FAILURE")) {
201
+ // Extension setup failed before tag type-checking could run
202
+ } else if (message.includes("TYPE_MISMATCH")) {
203
+ // A tag was applied to an incompatible field or target type
204
+ }
205
+
206
+ throw error;
207
+ }
208
+ ```
209
+
210
+ The most relevant codes for extension-backed static analysis failures are:
211
+
212
+ - `UNSUPPORTED_CUSTOM_TYPE_OVERRIDE` for extension custom types that conflict with unsupported TypeScript global built-ins.
213
+ - `SYNTHETIC_SETUP_FAILURE` for invalid or conflicting extension custom type registrations and other synthetic compiler setup failures.
214
+ - `TYPE_MISMATCH` for normal tag-on-type incompatibilities in author source.
215
+
216
+ As a rule of thumb, `UNSUPPORTED_CUSTOM_TYPE_OVERRIDE` and `SYNTHETIC_SETUP_FAILURE` indicate extension configuration problems, while `TYPE_MISMATCH` usually indicates an authoring error in the analyzed source.
217
+
183
218
  ## Internal Entry Point
184
219
 
185
220
  Low-level canonical IR generators, analyzer primitives, and validation helpers are intentionally no longer exported from the package root. If you need those unstable internals inside the monorepo, import them from `@formspec/build/internals`.
@@ -1 +1 @@
1
- {"version":3,"file":"tsdoc-parser.d.ts","sourceRoot":"","sources":["../../src/analyzer/tsdoc-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAcL,KAAK,4BAA4B,EAGlC,MAAM,6BAA6B,CAAC;AAkBrC,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EAEnB,KAAK,UAAU,EACf,KAAK,QAAQ,EACd,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA4lBhE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD,qEAAqE;IACrE,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD,2EAA2E;IAC3E,QAAQ,CAAC,WAAW,EAAE,SAAS,4BAA4B,EAAE,CAAC;CAC/D;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAC/C;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC;IAC9B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC;IAClC,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;IAC/B,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAA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) {
2223
2223
  return true;
2224
2224
  }).map((statement) => statement.getText(sourceFile));
2225
2225
  }
2226
+ function pushUniqueCompilerDiagnostics(target, additions) {
2227
+ for (const diagnostic of additions) {
2228
+ if ((diagnostic.code === "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" || diagnostic.code === "SYNTHETIC_SETUP_FAILURE") && target.some(
2229
+ (existing) => existing.code === diagnostic.code && existing.message === diagnostic.message
2230
+ )) {
2231
+ continue;
2232
+ }
2233
+ target.push(diagnostic);
2234
+ }
2235
+ }
2226
2236
  function renderSyntheticArgumentExpression(valueKind, argumentText) {
2227
2237
  const trimmed = argumentText.trim();
2228
2238
  if (trimmed === "") {
@@ -2489,6 +2499,16 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
2489
2499
  if (result.diagnostics.length === 0) {
2490
2500
  return [];
2491
2501
  }
2502
+ const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
2503
+ if (setupDiagnostic !== void 0) {
2504
+ return [
2505
+ makeDiagnostic(
2506
+ setupDiagnostic.kind === "unsupported-custom-type-override" ? "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" : "SYNTHETIC_SETUP_FAILURE",
2507
+ setupDiagnostic.message,
2508
+ provenance
2509
+ )
2510
+ ];
2511
+ }
2492
2512
  const expectedLabel = definition.valueKind === null ? "compatible argument" : capabilityLabel(definition.valueKind);
2493
2513
  return [
2494
2514
  makeDiagnostic(
@@ -2652,7 +2672,7 @@ function parseTSDocTags(node, file = "", options) {
2652
2672
  options
2653
2673
  );
2654
2674
  if (compilerDiagnostics.length > 0) {
2655
- diagnostics.push(...compilerDiagnostics);
2675
+ pushUniqueCompilerDiagnostics(diagnostics, compilerDiagnostics);
2656
2676
  continue;
2657
2677
  }
2658
2678
  const constraintNode = (0, import_internal2.parseConstraintTagValue)(
@@ -2739,7 +2759,7 @@ function parseTSDocTags(node, file = "", options) {
2739
2759
  options
2740
2760
  );
2741
2761
  if (compilerDiagnostics.length > 0) {
2742
- diagnostics.push(...compilerDiagnostics);
2762
+ pushUniqueCompilerDiagnostics(diagnostics, compilerDiagnostics);
2743
2763
  continue;
2744
2764
  }
2745
2765
  const constraintNode = (0, import_internal2.parseConstraintTagValue)(
@@ -2773,7 +2793,7 @@ function parseTSDocTags(node, file = "", options) {
2773
2793
  options
2774
2794
  );
2775
2795
  if (compilerDiagnostics.length > 0) {
2776
- diagnostics.push(...compilerDiagnostics);
2796
+ pushUniqueCompilerDiagnostics(diagnostics, compilerDiagnostics);
2777
2797
  continue;
2778
2798
  }
2779
2799
  const constraintNode = (0, import_internal2.parseConstraintTagValue)(