@formspec/build 0.1.0-alpha.26 → 0.1.0-alpha.27

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/build.d.ts CHANGED
@@ -27,9 +27,7 @@ import { AnyField } from '@formspec/core';
27
27
  import { ArrayField } from '@formspec/core';
28
28
  import { BooleanField } from '@formspec/core';
29
29
  import { BuiltinConstraintBroadeningRegistration } from '@formspec/core';
30
- import { BuiltinConstraintName } from '@formspec/core';
31
30
  import { Conditional } from '@formspec/core';
32
- import { ConstraintSemanticRole } from '@formspec/core';
33
31
  import { ConstraintTagRegistration } from '@formspec/core';
34
32
  import { CustomAnnotationRegistration } from '@formspec/core';
35
33
  import { CustomConstraintRegistration } from '@formspec/core';
@@ -38,10 +36,7 @@ import { DynamicEnumField } from '@formspec/core';
38
36
  import { DynamicSchemaField } from '@formspec/core';
39
37
  import { EnumOption } from '@formspec/core';
40
38
  import { EnumOptionValue } from '@formspec/core';
41
- import { ExtensionApplicableType } from '@formspec/core';
42
39
  import { ExtensionDefinition } from '@formspec/core';
43
- import { ExtensionPayloadValue } from '@formspec/core';
44
- import { ExtensionTypeKind } from '@formspec/core';
45
40
  import { FormElement } from '@formspec/core';
46
41
  import { FormSpec } from '@formspec/core';
47
42
  import { Group } from '@formspec/core';
@@ -49,7 +44,8 @@ import { NumberField } from '@formspec/core';
49
44
  import { ObjectField } from '@formspec/core';
50
45
  import { StaticEnumField } from '@formspec/core';
51
46
  import { TextField } from '@formspec/core';
52
- import { VocabularyKeywordRegistration } from '@formspec/core';
47
+ import * as ts from 'typescript';
48
+ import { z } from 'zod';
53
49
 
54
50
  export { AnyField }
55
51
 
@@ -142,8 +138,6 @@ export declare interface BuildResult {
142
138
 
143
139
  export { BuiltinConstraintBroadeningRegistration }
144
140
 
145
- export { BuiltinConstraintName }
146
-
147
141
  /**
148
142
  * A Categorization element (tab-based layout).
149
143
  *
@@ -186,8 +180,6 @@ export declare interface Category {
186
180
 
187
181
  export { Conditional }
188
182
 
189
- export { ConstraintSemanticRole }
190
-
191
183
  export { ConstraintTagRegistration }
192
184
 
193
185
  /**
@@ -239,13 +231,15 @@ export { EnumOption }
239
231
 
240
232
  export { EnumOptionValue }
241
233
 
242
- /* Excluded from this release type: ExtendedJSONSchema7 */
243
- export { ExtensionApplicableType }
234
+ /**
235
+ * JSON Schema with FormSpec extension properties for arbitrary `x-formspec-*` keys.
236
+ *
237
+ * @public
238
+ */
239
+ export declare type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;
244
240
 
245
241
  export { ExtensionDefinition }
246
242
 
247
- export { ExtensionPayloadValue }
248
-
249
243
  /**
250
244
  * A registry of extensions that provides lookup by fully-qualified ID.
251
245
  *
@@ -305,13 +299,16 @@ export declare interface ExtensionRegistry {
305
299
  findAnnotation(annotationId: string): CustomAnnotationRegistration | undefined;
306
300
  }
307
301
 
308
- export { ExtensionTypeKind }
309
-
310
302
  export { FormElement }
311
303
 
312
304
  export { FormSpec }
313
305
 
314
- /* Excluded from this release type: FormSpecSchemaExtensions */
306
+ /**
307
+ * Extension properties for custom FormSpec constraint tags.
308
+ *
309
+ * @public
310
+ */
311
+ export declare type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;
315
312
 
316
313
  /**
317
314
  * Options for generating schemas from a decorated class.
@@ -428,6 +425,34 @@ export declare function generateSchemas(options: GenerateSchemasOptions): Genera
428
425
  */
429
426
  export declare function generateSchemasFromClass(options: GenerateFromClassOptions): GenerateFromClassResult;
430
427
 
428
+ /**
429
+ * Generates JSON Schema and UI Schema from a named type within an existing
430
+ * TypeScript program supplied by the caller.
431
+ *
432
+ * This low-level entry point lets downstream tooling reuse a host-owned
433
+ * `Program` for both FormSpec extraction and other TypeScript analysis.
434
+ *
435
+ * @param options - Host program, file path, type name, and optional schema generation options
436
+ * @returns Generated JSON Schema and UI Schema
437
+ *
438
+ * @public
439
+ */
440
+ export declare function generateSchemasFromProgram(options: GenerateSchemasFromProgramOptions): GenerateFromClassResult;
441
+
442
+ /**
443
+ * Options for generating schemas from a named type inside an existing TypeScript program.
444
+ *
445
+ * @public
446
+ */
447
+ export declare interface GenerateSchemasFromProgramOptions extends StaticSchemaGenerationOptions {
448
+ /** Existing TypeScript program supplied by the caller. */
449
+ readonly program: ts.Program;
450
+ /** Path to the TypeScript source file */
451
+ readonly filePath: string;
452
+ /** Name of the exported class, interface, or type alias to analyze */
453
+ readonly typeName: string;
454
+ }
455
+
431
456
  /**
432
457
  * Options for generating schemas from a named type (class, interface, or type alias).
433
458
  *
@@ -599,9 +624,109 @@ export declare interface JsonSchema2020 {
599
624
  [key: `x-${string}`]: unknown;
600
625
  }
601
626
 
602
- /* Excluded from this release type: JSONSchema7 */
627
+ /**
628
+ * A JSON Schema definition (legacy subset used by Zod validator and types.ts).
629
+ *
630
+ * @public
631
+ */
632
+ export declare interface JSONSchema7 {
633
+ /** Declared JSON Schema dialect URI for the document root. */
634
+ $schema?: string;
635
+ /** Stable identifier for the schema document or sub-schema. */
636
+ $id?: string;
637
+ /** Reference to another schema location. */
638
+ $ref?: string;
639
+ /** Human-readable title for the schema node. */
640
+ title?: string;
641
+ /** Human-readable description for the schema node. */
642
+ description?: string;
643
+ /** Whether the schema node is deprecated. */
644
+ deprecated?: boolean;
645
+ /** JSON Schema type keyword for the current node. */
646
+ type?: JSONSchemaType | JSONSchemaType[];
647
+ /** Inclusive minimum string length. */
648
+ minLength?: number;
649
+ /** Inclusive maximum string length. */
650
+ maxLength?: number;
651
+ /** Regular expression pattern applied to string values. */
652
+ pattern?: string;
653
+ /** Inclusive numeric lower bound. */
654
+ minimum?: number;
655
+ /** Inclusive numeric upper bound. */
656
+ maximum?: number;
657
+ /** Exclusive numeric lower bound. */
658
+ exclusiveMinimum?: number;
659
+ /** Exclusive numeric upper bound. */
660
+ exclusiveMaximum?: number;
661
+ /** Closed set of allowed scalar values. */
662
+ enum?: readonly (string | number | boolean | null)[];
663
+ /** Literal value the instance must equal. */
664
+ const?: string | number | boolean | null;
665
+ /** Object properties keyed by property name. */
666
+ properties?: Record<string, JSONSchema7>;
667
+ /** Property names that must be present on object values. */
668
+ required?: string[];
669
+ /** Whether, or how, additional object properties are allowed. */
670
+ additionalProperties?: boolean | JSONSchema7;
671
+ /** Item schema or tuple schemas applied to array elements. */
672
+ items?: JSONSchema7 | JSONSchema7[];
673
+ /** Inclusive minimum array length. */
674
+ minItems?: number;
675
+ /** Inclusive maximum array length. */
676
+ maxItems?: number;
677
+ /** Schemas that must all validate successfully. */
678
+ allOf?: JSONSchema7[];
679
+ /** Schemas of which at least one may validate successfully. */
680
+ anyOf?: JSONSchema7[];
681
+ /** Schemas of which exactly one should validate successfully. */
682
+ oneOf?: JSONSchema7[];
683
+ /** Schema that must not validate successfully. */
684
+ not?: JSONSchema7;
685
+ /** Conditional branch predicate schema. */
686
+ if?: JSONSchema7;
687
+ /** Schema applied when the `if` branch matches. */
688
+ then?: JSONSchema7;
689
+ /** Schema applied when the `if` branch does not match. */
690
+ else?: JSONSchema7;
691
+ /** Format hint for downstream validators and tooling. */
692
+ format?: string;
693
+ /** Default value suggested for the schema node. */
694
+ default?: unknown;
695
+ /**
696
+ * Data source key for dynamic enum fields.
697
+ * Indicates that options should be fetched from a registered resolver.
698
+ */
699
+ "x-formspec-source"?: string;
700
+ /**
701
+ * Field names whose values are needed to fetch dynamic enum options.
702
+ * Used for dependent/cascading dropdowns.
703
+ */
704
+ "x-formspec-params"?: readonly string[];
705
+ /**
706
+ * Schema source identifier for dynamic schema fields.
707
+ * Indicates that the schema should be loaded dynamically at runtime.
708
+ */
709
+ "x-formspec-schemaSource"?: string;
710
+ }
603
711
 
604
- /* Excluded from this release type: JSONSchemaType */
712
+ /**
713
+ * Zod schema for the legacy JSON Schema 7 subset used by `@formspec/build`.
714
+ *
715
+ * @public
716
+ */
717
+ export declare const jsonSchema7Schema: z.ZodType<JSONSchema7>;
718
+
719
+ /**
720
+ * JSON Schema type definitions.
721
+ *
722
+ * These types are a subset of JSON Schema sufficient for form generation.
723
+ */
724
+ /**
725
+ * JSON Schema primitive types.
726
+ *
727
+ * @public
728
+ */
729
+ export declare type JSONSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
605
730
 
606
731
  /**
607
732
  * A Label element for displaying static text.
@@ -769,6 +894,13 @@ export declare interface UISchemaElementBase {
769
894
  */
770
895
  export declare type UISchemaElementType = "Control" | "VerticalLayout" | "HorizontalLayout" | "Group" | "Categorization" | "Category" | "Label";
771
896
 
897
+ /**
898
+ * Zod schema for the root UI Schema (layout types only).
899
+ *
900
+ * @public
901
+ */
902
+ export declare const uiSchemaSchema: z.ZodType<UISchema>;
903
+
772
904
  /**
773
905
  * A vertical layout element.
774
906
  *
@@ -787,8 +919,6 @@ export declare interface VerticalLayout {
787
919
  readonly [k: string]: unknown;
788
920
  }
789
921
 
790
- export { VocabularyKeywordRegistration }
791
-
792
922
  /**
793
923
  * Builds and writes both JSON Schema and UI Schema files to disk.
794
924
  *
package/dist/cli.cjs CHANGED
@@ -1235,6 +1235,74 @@ var init_extensions = __esm({
1235
1235
  }
1236
1236
  });
1237
1237
 
1238
+ // src/json-schema/schema.ts
1239
+ var import_zod3, jsonSchemaTypeSchema, jsonSchema7Schema;
1240
+ var init_schema2 = __esm({
1241
+ "src/json-schema/schema.ts"() {
1242
+ "use strict";
1243
+ import_zod3 = require("zod");
1244
+ jsonSchemaTypeSchema = import_zod3.z.enum([
1245
+ "string",
1246
+ "number",
1247
+ "integer",
1248
+ "boolean",
1249
+ "object",
1250
+ "array",
1251
+ "null"
1252
+ ]);
1253
+ jsonSchema7Schema = import_zod3.z.lazy(
1254
+ () => import_zod3.z.object({
1255
+ $schema: import_zod3.z.string().optional(),
1256
+ $id: import_zod3.z.string().optional(),
1257
+ $ref: import_zod3.z.string().optional(),
1258
+ // Metadata
1259
+ title: import_zod3.z.string().optional(),
1260
+ description: import_zod3.z.string().optional(),
1261
+ deprecated: import_zod3.z.boolean().optional(),
1262
+ // Type
1263
+ type: import_zod3.z.union([jsonSchemaTypeSchema, import_zod3.z.array(jsonSchemaTypeSchema)]).optional(),
1264
+ // String validation
1265
+ minLength: import_zod3.z.number().optional(),
1266
+ maxLength: import_zod3.z.number().optional(),
1267
+ pattern: import_zod3.z.string().optional(),
1268
+ // Number validation
1269
+ minimum: import_zod3.z.number().optional(),
1270
+ maximum: import_zod3.z.number().optional(),
1271
+ exclusiveMinimum: import_zod3.z.number().optional(),
1272
+ exclusiveMaximum: import_zod3.z.number().optional(),
1273
+ // Enum
1274
+ enum: import_zod3.z.array(import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean(), import_zod3.z.null()])).readonly().optional(),
1275
+ const: import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean(), import_zod3.z.null()]).optional(),
1276
+ // Object
1277
+ properties: import_zod3.z.record(import_zod3.z.string(), jsonSchema7Schema).optional(),
1278
+ required: import_zod3.z.array(import_zod3.z.string()).optional(),
1279
+ additionalProperties: import_zod3.z.union([import_zod3.z.boolean(), jsonSchema7Schema]).optional(),
1280
+ // Array
1281
+ items: import_zod3.z.union([jsonSchema7Schema, import_zod3.z.array(jsonSchema7Schema)]).optional(),
1282
+ minItems: import_zod3.z.number().optional(),
1283
+ maxItems: import_zod3.z.number().optional(),
1284
+ // Composition
1285
+ allOf: import_zod3.z.array(jsonSchema7Schema).optional(),
1286
+ anyOf: import_zod3.z.array(jsonSchema7Schema).optional(),
1287
+ oneOf: import_zod3.z.array(jsonSchema7Schema).optional(),
1288
+ not: jsonSchema7Schema.optional(),
1289
+ // Conditional
1290
+ if: jsonSchema7Schema.optional(),
1291
+ then: jsonSchema7Schema.optional(),
1292
+ else: jsonSchema7Schema.optional(),
1293
+ // Format
1294
+ format: import_zod3.z.string().optional(),
1295
+ // Default
1296
+ default: import_zod3.z.unknown().optional(),
1297
+ // FormSpec extensions
1298
+ "x-formspec-source": import_zod3.z.string().optional(),
1299
+ "x-formspec-params": import_zod3.z.array(import_zod3.z.string()).readonly().optional(),
1300
+ "x-formspec-schemaSource": import_zod3.z.string().optional()
1301
+ }).passthrough()
1302
+ );
1303
+ }
1304
+ });
1305
+
1238
1306
  // src/analyzer/tsdoc-parser.ts
1239
1307
  function createFormSpecTSDocConfig(extensionTagNames = []) {
1240
1308
  const config = new import_tsdoc.TSDocConfiguration();
@@ -3204,6 +3272,18 @@ var init_class_analyzer = __esm({
3204
3272
  });
3205
3273
 
3206
3274
  // src/analyzer/program.ts
3275
+ function createProgramContextFromProgram(program, filePath) {
3276
+ const absolutePath = path.resolve(filePath);
3277
+ const sourceFile = program.getSourceFile(absolutePath) ?? program.getSourceFile(filePath);
3278
+ if (!sourceFile) {
3279
+ throw new Error(`Could not find source file in provided program: ${absolutePath}`);
3280
+ }
3281
+ return {
3282
+ program,
3283
+ checker: program.getTypeChecker(),
3284
+ sourceFile
3285
+ };
3286
+ }
3207
3287
  function createProgramContext(filePath) {
3208
3288
  const absolutePath = path.resolve(filePath);
3209
3289
  const fileDir = path.dirname(absolutePath);
@@ -3274,24 +3354,33 @@ function findTypeAliasByName(sourceFile, aliasName) {
3274
3354
  }
3275
3355
  function analyzeNamedTypeToIR(filePath, typeName, extensionRegistry) {
3276
3356
  const ctx = createProgramContext(filePath);
3357
+ return analyzeNamedTypeToIRFromProgramContext(ctx, filePath, typeName, extensionRegistry);
3358
+ }
3359
+ function analyzeNamedTypeToIRFromProgramContext(ctx, filePath, typeName, extensionRegistry) {
3360
+ const analysisFilePath = path.resolve(filePath);
3277
3361
  const classDecl = findClassByName(ctx.sourceFile, typeName);
3278
3362
  if (classDecl !== null) {
3279
- return analyzeClassToIR(classDecl, ctx.checker, filePath, extensionRegistry);
3363
+ return analyzeClassToIR(classDecl, ctx.checker, analysisFilePath, extensionRegistry);
3280
3364
  }
3281
3365
  const interfaceDecl = findInterfaceByName(ctx.sourceFile, typeName);
3282
3366
  if (interfaceDecl !== null) {
3283
- return analyzeInterfaceToIR(interfaceDecl, ctx.checker, filePath, extensionRegistry);
3367
+ return analyzeInterfaceToIR(interfaceDecl, ctx.checker, analysisFilePath, extensionRegistry);
3284
3368
  }
3285
3369
  const typeAlias = findTypeAliasByName(ctx.sourceFile, typeName);
3286
3370
  if (typeAlias !== null) {
3287
- const result = analyzeTypeAliasToIR(typeAlias, ctx.checker, filePath, extensionRegistry);
3371
+ const result = analyzeTypeAliasToIR(
3372
+ typeAlias,
3373
+ ctx.checker,
3374
+ analysisFilePath,
3375
+ extensionRegistry
3376
+ );
3288
3377
  if (result.ok) {
3289
3378
  return result.analysis;
3290
3379
  }
3291
3380
  throw new Error(result.error);
3292
3381
  }
3293
3382
  throw new Error(
3294
- `Type "${typeName}" not found as a class, interface, or type alias in ${filePath}`
3383
+ `Type "${typeName}" not found as a class, interface, or type alias in ${analysisFilePath}`
3295
3384
  );
3296
3385
  }
3297
3386
  var ts4, path;
@@ -3448,16 +3537,34 @@ function generateSchemasFromClass(options) {
3448
3537
  );
3449
3538
  }
3450
3539
  function generateSchemas(options) {
3451
- const analysis = analyzeNamedTypeToIR(
3540
+ const ctx = createProgramContext(options.filePath);
3541
+ return generateSchemasFromProgram({
3542
+ ...options,
3543
+ program: ctx.program
3544
+ });
3545
+ }
3546
+ function generateSchemasFromProgram(options) {
3547
+ const ctx = createProgramContextFromProgram(options.program, options.filePath);
3548
+ const analysis = analyzeNamedTypeToIRFromProgramContext(
3549
+ ctx,
3452
3550
  options.filePath,
3453
3551
  options.typeName,
3454
3552
  options.extensionRegistry
3455
3553
  );
3456
- return generateClassSchemas(analysis, { file: options.filePath }, options);
3554
+ return generateClassSchemas(
3555
+ analysis,
3556
+ { file: options.filePath },
3557
+ {
3558
+ extensionRegistry: options.extensionRegistry,
3559
+ vendorPrefix: options.vendorPrefix
3560
+ }
3561
+ );
3457
3562
  }
3563
+ var ts5;
3458
3564
  var init_class_schema = __esm({
3459
3565
  "src/generators/class-schema.ts"() {
3460
3566
  "use strict";
3567
+ ts5 = require("typescript");
3461
3568
  init_program();
3462
3569
  init_class_analyzer();
3463
3570
  init_canonicalize();
@@ -3661,7 +3768,10 @@ __export(index_exports, {
3661
3768
  generateJsonSchema: () => generateJsonSchema,
3662
3769
  generateSchemas: () => generateSchemas,
3663
3770
  generateSchemasFromClass: () => generateSchemasFromClass,
3771
+ generateSchemasFromProgram: () => generateSchemasFromProgram,
3664
3772
  generateUiSchema: () => generateUiSchema,
3773
+ jsonSchema7Schema: () => jsonSchema7Schema,
3774
+ uiSchemaSchema: () => uiSchema,
3665
3775
  writeSchemas: () => writeSchemas
3666
3776
  });
3667
3777
  function buildFormSchemas(form, options) {
@@ -3693,6 +3803,8 @@ var init_index = __esm({
3693
3803
  fs = __toESM(require("fs"), 1);
3694
3804
  path2 = __toESM(require("path"), 1);
3695
3805
  init_extensions();
3806
+ init_schema2();
3807
+ init_schema();
3696
3808
  init_generator();
3697
3809
  init_generator2();
3698
3810
  init_class_schema();