@formspec/build 0.1.0-alpha.14 → 0.1.0-alpha.16

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.
Files changed (68) hide show
  1. package/dist/__tests__/extension-runtime.integration.test.d.ts +2 -0
  2. package/dist/__tests__/extension-runtime.integration.test.d.ts.map +1 -0
  3. package/dist/__tests__/fixtures/edge-cases.d.ts +22 -0
  4. package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -1
  5. package/dist/__tests__/fixtures/example-a-builtins.d.ts +6 -6
  6. package/dist/__tests__/fixtures/example-interface-types.d.ts +26 -26
  7. package/dist/__tests__/fixtures/example-interface-types.d.ts.map +1 -1
  8. package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts +30 -0
  9. package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts.map +1 -0
  10. package/dist/__tests__/mixed-authoring.test.d.ts +2 -0
  11. package/dist/__tests__/mixed-authoring.test.d.ts.map +1 -0
  12. package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts +19 -0
  13. package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts.map +1 -0
  14. package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts +6 -0
  15. package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts.map +1 -0
  16. package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts +17 -0
  17. package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts.map +1 -0
  18. package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts +9 -0
  19. package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts.map +1 -0
  20. package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts +6 -0
  21. package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts.map +1 -0
  22. package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts +19 -0
  23. package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts.map +1 -0
  24. package/dist/__tests__/parity/utils.d.ts +11 -4
  25. package/dist/__tests__/parity/utils.d.ts.map +1 -1
  26. package/dist/analyzer/class-analyzer.d.ts +5 -3
  27. package/dist/analyzer/class-analyzer.d.ts.map +1 -1
  28. package/dist/analyzer/jsdoc-constraints.d.ts +7 -51
  29. package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -1
  30. package/dist/analyzer/tsdoc-parser.d.ts +25 -9
  31. package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
  32. package/dist/browser.cjs +546 -102
  33. package/dist/browser.cjs.map +1 -1
  34. package/dist/browser.d.ts +15 -2
  35. package/dist/browser.d.ts.map +1 -1
  36. package/dist/browser.js +544 -102
  37. package/dist/browser.js.map +1 -1
  38. package/dist/build.d.ts +170 -6
  39. package/dist/canonicalize/tsdoc-canonicalizer.d.ts +3 -3
  40. package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -1
  41. package/dist/cli.cjs +877 -128
  42. package/dist/cli.cjs.map +1 -1
  43. package/dist/cli.js +876 -131
  44. package/dist/cli.js.map +1 -1
  45. package/dist/generators/mixed-authoring.d.ts +45 -0
  46. package/dist/generators/mixed-authoring.d.ts.map +1 -0
  47. package/dist/index.cjs +850 -125
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.ts +22 -3
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +847 -129
  52. package/dist/index.js.map +1 -1
  53. package/dist/internals.cjs +946 -187
  54. package/dist/internals.cjs.map +1 -1
  55. package/dist/internals.js +944 -189
  56. package/dist/internals.js.map +1 -1
  57. package/dist/json-schema/generator.d.ts +8 -2
  58. package/dist/json-schema/generator.d.ts.map +1 -1
  59. package/dist/json-schema/ir-generator.d.ts +27 -4
  60. package/dist/json-schema/ir-generator.d.ts.map +1 -1
  61. package/dist/json-schema/types.d.ts +1 -1
  62. package/dist/json-schema/types.d.ts.map +1 -1
  63. package/dist/ui-schema/ir-generator.d.ts.map +1 -1
  64. package/dist/validate/constraint-validator.d.ts +3 -7
  65. package/dist/validate/constraint-validator.d.ts.map +1 -1
  66. package/package.json +3 -3
  67. package/dist/__tests__/jsdoc-constraints.test.d.ts +0 -10
  68. package/dist/__tests__/jsdoc-constraints.test.d.ts.map +0 -1
package/dist/build.d.ts CHANGED
@@ -23,8 +23,14 @@
23
23
  * @packageDocumentation
24
24
  */
25
25
 
26
+ import type { CustomAnnotationRegistration } from '@formspec/core';
27
+ import type { CustomConstraintRegistration } from '@formspec/core';
28
+ import type { CustomTypeRegistration } from '@formspec/core';
29
+ import type { ExtensionDefinition } from '@formspec/core';
26
30
  import type { FormElement } from '@formspec/core';
31
+ import type { FormIR } from '@formspec/core';
27
32
  import type { FormSpec } from '@formspec/core';
33
+ import type { JsonValue } from '@formspec/core';
28
34
  import { z } from 'zod';
29
35
 
30
36
  /**
@@ -54,7 +60,41 @@ import { z } from 'zod';
54
60
  * @param form - The FormSpec to build schemas from
55
61
  * @returns Object containing both jsonSchema and uiSchema
56
62
  */
57
- export declare function buildFormSchemas<E extends readonly FormElement[]>(form: FormSpec<E>): BuildResult;
63
+ export declare function buildFormSchemas<E extends readonly FormElement[]>(form: FormSpec<E>, options?: BuildFormSchemasOptions): BuildResult;
64
+
65
+ /**
66
+ * Options for building schemas from a FormSpec.
67
+ *
68
+ * Currently identical to `GenerateJsonSchemaOptions`. Defined separately so the
69
+ * Chain DSL surface can grow independently in the future if needed.
70
+ */
71
+ export declare type BuildFormSchemasOptions = GenerateJsonSchemaOptions;
72
+
73
+ /**
74
+ * Builds JSON Schema and UI Schema from a TSDoc-derived model with ChainDSL
75
+ * field overlays.
76
+ *
77
+ * Overlays are matched by field name. The static model wins for structure,
78
+ * ordering, and constraints; ChainDSL overlays may contribute dynamic runtime
79
+ * field metadata such as dynamic enum or dynamic schema keywords, and may fill
80
+ * in missing annotations.
81
+ */
82
+ export declare function buildMixedAuthoringSchemas(options: BuildMixedAuthoringSchemasOptions): MixedAuthoringSchemas;
83
+
84
+ /**
85
+ * Options for generating mixed-authoring schemas.
86
+ *
87
+ * The `typeName` can resolve to a class, interface, or object type alias, just
88
+ * like `generateSchemas()`.
89
+ */
90
+ export declare interface BuildMixedAuthoringSchemasOptions extends GenerateJsonSchemaFromIROptions {
91
+ /** Path to the TypeScript source file. */
92
+ readonly filePath: string;
93
+ /** Name of the class, interface, or type alias to analyze. */
94
+ readonly typeName: string;
95
+ /** ChainDSL overlays to apply to the static model. Groups and conditionals are flattened by field name. */
96
+ readonly overlays: FormSpec<readonly FormElement[]>;
97
+ }
58
98
 
59
99
  /**
60
100
  * Result of building form schemas.
@@ -204,10 +244,56 @@ export declare const controlSchema: z.ZodObject<{
204
244
  options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
205
245
  }, z.ZodTypeAny, "passthrough">>;
206
246
 
247
+ /**
248
+ * Creates an extension registry from a list of extension definitions.
249
+ *
250
+ * The registry indexes all types, constraints, and annotations by their
251
+ * fully-qualified IDs (`<extensionId>/<name>`) for O(1) lookup during
252
+ * generation and validation.
253
+ *
254
+ * @param extensions - The extension definitions to register.
255
+ * @returns An {@link ExtensionRegistry} instance.
256
+ * @throws If duplicate type/constraint/annotation IDs are detected across extensions.
257
+ */
258
+ export declare function createExtensionRegistry(extensions: readonly ExtensionDefinition[]): ExtensionRegistry;
259
+
207
260
  /** JSON Schema with FormSpec extension properties for arbitrary x-formspec-* keys. */
208
261
  export declare type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;
209
262
 
210
- /** Extension properties for custom FormSpec decorators. */
263
+ /**
264
+ * A registry of extensions that provides lookup by fully-qualified ID.
265
+ *
266
+ * Type IDs follow the format: `<extensionId>/<typeName>`
267
+ * Constraint IDs follow the format: `<extensionId>/<constraintName>`
268
+ * Annotation IDs follow the format: `<extensionId>/<annotationName>`
269
+ */
270
+ export declare interface ExtensionRegistry {
271
+ /** The extensions registered in this registry (in registration order). */
272
+ readonly extensions: readonly ExtensionDefinition[];
273
+ /**
274
+ * Look up a custom type registration by its fully-qualified type ID.
275
+ *
276
+ * @param typeId - The fully-qualified type ID (e.g., "x-stripe/monetary/Decimal").
277
+ * @returns The registration if found, otherwise `undefined`.
278
+ */
279
+ findType(typeId: string): CustomTypeRegistration | undefined;
280
+ /**
281
+ * Look up a custom constraint registration by its fully-qualified constraint ID.
282
+ *
283
+ * @param constraintId - The fully-qualified constraint ID.
284
+ * @returns The registration if found, otherwise `undefined`.
285
+ */
286
+ findConstraint(constraintId: string): CustomConstraintRegistration | undefined;
287
+ /**
288
+ * Look up a custom annotation registration by its fully-qualified annotation ID.
289
+ *
290
+ * @param annotationId - The fully-qualified annotation ID.
291
+ * @returns The registration if found, otherwise `undefined`.
292
+ */
293
+ findAnnotation(annotationId: string): CustomAnnotationRegistration | undefined;
294
+ }
295
+
296
+ /** Extension properties for custom FormSpec constraint tags. */
211
297
  export declare type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;
212
298
 
213
299
  /**
@@ -258,7 +344,74 @@ export declare interface GenerateFromClassResult {
258
344
  * @param form - The FormSpec to convert
259
345
  * @returns A JSON Schema 2020-12 object
260
346
  */
261
- export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E>): JsonSchema2020;
347
+ export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E>, options?: GenerateJsonSchemaOptions): JsonSchema2020;
348
+
349
+ /**
350
+ * Generates a JSON Schema 2020-12 object from a canonical FormIR.
351
+ *
352
+ * Groups and conditionals are flattened — they influence UI layout but do not
353
+ * affect the data schema. All fields appear at the level they would occupy in
354
+ * the output data.
355
+ *
356
+ * Named types in the `typeRegistry` are emitted as `$defs` entries and
357
+ * referenced via `$ref` (per PP7 — high-fidelity output).
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * import { canonicalizeDSL } from "./canonicalize/index.js";
362
+ * import { generateJsonSchemaFromIR } from "./json-schema/ir-generator.js";
363
+ * import { formspec, field } from "@formspec/dsl";
364
+ *
365
+ * const form = formspec(
366
+ * field.text("name", { label: "Name", required: true }),
367
+ * field.number("age", { min: 0 }),
368
+ * );
369
+ * const ir = canonicalizeDSL(form);
370
+ * const schema = generateJsonSchemaFromIR(ir);
371
+ * // {
372
+ * // $schema: "https://json-schema.org/draft/2020-12/schema",
373
+ * // type: "object",
374
+ * // properties: {
375
+ * // name: { type: "string", title: "Name" },
376
+ * // age: { type: "number", minimum: 0 }
377
+ * // },
378
+ * // required: ["name"]
379
+ * // }
380
+ * ```
381
+ *
382
+ * Advanced API — most consumers should use `generateJsonSchema()` or
383
+ * `buildFormSchemas()`, which canonicalize form definitions automatically.
384
+ * Callers of this function are responsible for providing pre-canonicalized IR.
385
+ *
386
+ * @param ir - The canonical FormIR produced by a canonicalizer
387
+ * @returns A plain JSON-serializable JSON Schema 2020-12 object
388
+ */
389
+ export declare function generateJsonSchemaFromIR(ir: FormIR, options?: GenerateJsonSchemaFromIROptions): JsonSchema2020;
390
+
391
+ /**
392
+ * Options for generating JSON Schema from a canonical FormIR.
393
+ */
394
+ export declare interface GenerateJsonSchemaFromIROptions {
395
+ /**
396
+ * Registry used to resolve custom types, constraints, and annotations.
397
+ *
398
+ * JSON Schema generation throws when custom IR nodes are present without a
399
+ * matching registration in this registry.
400
+ */
401
+ readonly extensionRegistry?: ExtensionRegistry | undefined;
402
+ /**
403
+ * Vendor prefix passed to extension `toJsonSchema` hooks.
404
+ * @defaultValue "x-formspec"
405
+ */
406
+ readonly vendorPrefix?: string | undefined;
407
+ }
408
+
409
+ /**
410
+ * Options for generating JSON Schema from a Chain DSL form.
411
+ *
412
+ * These options are forwarded to the IR-based JSON Schema generator.
413
+ */
414
+ export declare type GenerateJsonSchemaOptions = GenerateJsonSchemaFromIROptions;
262
415
 
263
416
  /**
264
417
  * Generates JSON Schema and UI Schema from a named TypeScript
@@ -410,9 +563,9 @@ export declare interface JsonSchema2020 {
410
563
  properties?: Record<string, JsonSchema2020>;
411
564
  required?: string[];
412
565
  items?: JsonSchema2020;
413
- additionalProperties?: boolean;
566
+ additionalProperties?: boolean | JsonSchema2020;
414
567
  enum?: readonly (string | number)[];
415
- const?: string | number | boolean | null;
568
+ const?: JsonValue;
416
569
  allOf?: readonly JsonSchema2020[];
417
570
  oneOf?: readonly JsonSchema2020[];
418
571
  anyOf?: readonly JsonSchema2020[];
@@ -427,6 +580,7 @@ export declare interface JsonSchema2020 {
427
580
  maxItems?: number;
428
581
  pattern?: string;
429
582
  uniqueItems?: boolean;
583
+ format?: string;
430
584
  title?: string;
431
585
  description?: string;
432
586
  default?: unknown;
@@ -600,6 +754,16 @@ export declare const labelElementSchema: z.ZodObject<{
600
754
  options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
601
755
  }, z.ZodTypeAny, "passthrough">>;
602
756
 
757
+ /**
758
+ * Result of generating schemas from a mixed-authoring composition.
759
+ */
760
+ export declare interface MixedAuthoringSchemas {
761
+ /** JSON Schema 2020-12 for validation. */
762
+ readonly jsonSchema: JsonSchema2020;
763
+ /** JSON Forms UI Schema for rendering. */
764
+ readonly uiSchema: UISchema;
765
+ }
766
+
603
767
  /**
604
768
  * Rule for conditional element visibility/enablement.
605
769
  */
@@ -784,7 +948,7 @@ export declare function writeSchemas<E extends readonly FormElement[]>(form: For
784
948
  /**
785
949
  * Options for writing schemas to disk.
786
950
  */
787
- export declare interface WriteSchemasOptions {
951
+ export declare interface WriteSchemasOptions extends GenerateJsonSchemaFromIROptions {
788
952
  /** Output directory for the schema files */
789
953
  readonly outDir: string;
790
954
  /** Base name for the output files (without extension). Defaults to "schema" */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * TSDoc canonicalizer — assembles an {@link IRClassAnalysis} into a canonical
3
3
  * {@link FormIR}, applying layout metadata from `@Group` and `@ShowWhen`
4
- * decorators.
4
+ * TSDoc tags.
5
5
  *
6
6
  * The analysis functions in `class-analyzer.ts` produce `FieldNode[]`,
7
7
  * `fieldLayouts`, and `typeRegistry` directly. This canonicalizer uses
@@ -22,8 +22,8 @@ export interface TSDocSource {
22
22
  * `analyzeInterfaceToIR`, or `analyzeTypeAliasToIR`) into a canonical
23
23
  * {@link FormIR}.
24
24
  *
25
- * Fields with `@Group` decorators are grouped into `GroupLayoutNode` elements.
26
- * Fields with `@ShowWhen` decorators are wrapped in `ConditionalLayoutNode` elements.
25
+ * Fields with `@Group` TSDoc tags are grouped into `GroupLayoutNode` elements.
26
+ * Fields with `@ShowWhen` TSDoc tags are wrapped in `ConditionalLayoutNode` elements.
27
27
  * When both are present, the conditional wraps the field inside the group.
28
28
  *
29
29
  * @param analysis - IR analysis result (fields are already FieldNode[])
@@ -1 +1 @@
1
- {"version":3,"file":"tsdoc-canonicalizer.d.ts","sourceRoot":"","sources":["../../src/canonicalize/tsdoc-canonicalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,MAAM,EAMP,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,eAAe,EAAuB,MAAM,+BAA+B,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAmBzF"}
1
+ {"version":3,"file":"tsdoc-canonicalizer.d.ts","sourceRoot":"","sources":["../../src/canonicalize/tsdoc-canonicalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,MAAM,EAMP,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,eAAe,EAAuB,MAAM,+BAA+B,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAqBzF"}