@formspec/build 0.1.0-alpha.24 → 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.
Files changed (39) hide show
  1. package/dist/analyzer/program.d.ts +12 -0
  2. package/dist/analyzer/program.d.ts.map +1 -1
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.ts +1 -0
  5. package/dist/browser.d.ts.map +1 -1
  6. package/dist/browser.js.map +1 -1
  7. package/dist/build-alpha.d.ts +167 -22
  8. package/dist/build-beta.d.ts +167 -22
  9. package/dist/build-internal.d.ts +167 -22
  10. package/dist/build.d.ts +239 -21
  11. package/dist/cli.cjs +118 -6
  12. package/dist/cli.cjs.map +1 -1
  13. package/dist/cli.js +117 -6
  14. package/dist/cli.js.map +1 -1
  15. package/dist/generators/class-schema.d.ts +27 -0
  16. package/dist/generators/class-schema.d.ts.map +1 -1
  17. package/dist/generators/mixed-authoring.d.ts.map +1 -1
  18. package/dist/index.cjs +114 -6
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +5 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +111 -6
  23. package/dist/index.js.map +1 -1
  24. package/dist/internals.cjs +46 -0
  25. package/dist/internals.cjs.map +1 -1
  26. package/dist/internals.d.ts +1 -1
  27. package/dist/internals.d.ts.map +1 -1
  28. package/dist/internals.js +44 -0
  29. package/dist/internals.js.map +1 -1
  30. package/dist/json-schema/ir-generator.d.ts +30 -0
  31. package/dist/json-schema/ir-generator.d.ts.map +1 -1
  32. package/dist/json-schema/schema.d.ts +2 -2
  33. package/dist/json-schema/types.d.ts +35 -4
  34. package/dist/json-schema/types.d.ts.map +1 -1
  35. package/dist/ui-schema/schema.d.ts +2 -7
  36. package/dist/ui-schema/schema.d.ts.map +1 -1
  37. package/dist/ui-schema/types.d.ts +58 -0
  38. package/dist/ui-schema/types.d.ts.map +1 -1
  39. package/package.json +4 -4
package/dist/cli.js CHANGED
@@ -1212,6 +1212,74 @@ var init_extensions = __esm({
1212
1212
  }
1213
1213
  });
1214
1214
 
1215
+ // src/json-schema/schema.ts
1216
+ import { z as z3 } from "zod";
1217
+ var jsonSchemaTypeSchema, jsonSchema7Schema;
1218
+ var init_schema2 = __esm({
1219
+ "src/json-schema/schema.ts"() {
1220
+ "use strict";
1221
+ jsonSchemaTypeSchema = z3.enum([
1222
+ "string",
1223
+ "number",
1224
+ "integer",
1225
+ "boolean",
1226
+ "object",
1227
+ "array",
1228
+ "null"
1229
+ ]);
1230
+ jsonSchema7Schema = z3.lazy(
1231
+ () => z3.object({
1232
+ $schema: z3.string().optional(),
1233
+ $id: z3.string().optional(),
1234
+ $ref: z3.string().optional(),
1235
+ // Metadata
1236
+ title: z3.string().optional(),
1237
+ description: z3.string().optional(),
1238
+ deprecated: z3.boolean().optional(),
1239
+ // Type
1240
+ type: z3.union([jsonSchemaTypeSchema, z3.array(jsonSchemaTypeSchema)]).optional(),
1241
+ // String validation
1242
+ minLength: z3.number().optional(),
1243
+ maxLength: z3.number().optional(),
1244
+ pattern: z3.string().optional(),
1245
+ // Number validation
1246
+ minimum: z3.number().optional(),
1247
+ maximum: z3.number().optional(),
1248
+ exclusiveMinimum: z3.number().optional(),
1249
+ exclusiveMaximum: z3.number().optional(),
1250
+ // Enum
1251
+ enum: z3.array(z3.union([z3.string(), z3.number(), z3.boolean(), z3.null()])).readonly().optional(),
1252
+ const: z3.union([z3.string(), z3.number(), z3.boolean(), z3.null()]).optional(),
1253
+ // Object
1254
+ properties: z3.record(z3.string(), jsonSchema7Schema).optional(),
1255
+ required: z3.array(z3.string()).optional(),
1256
+ additionalProperties: z3.union([z3.boolean(), jsonSchema7Schema]).optional(),
1257
+ // Array
1258
+ items: z3.union([jsonSchema7Schema, z3.array(jsonSchema7Schema)]).optional(),
1259
+ minItems: z3.number().optional(),
1260
+ maxItems: z3.number().optional(),
1261
+ // Composition
1262
+ allOf: z3.array(jsonSchema7Schema).optional(),
1263
+ anyOf: z3.array(jsonSchema7Schema).optional(),
1264
+ oneOf: z3.array(jsonSchema7Schema).optional(),
1265
+ not: jsonSchema7Schema.optional(),
1266
+ // Conditional
1267
+ if: jsonSchema7Schema.optional(),
1268
+ then: jsonSchema7Schema.optional(),
1269
+ else: jsonSchema7Schema.optional(),
1270
+ // Format
1271
+ format: z3.string().optional(),
1272
+ // Default
1273
+ default: z3.unknown().optional(),
1274
+ // FormSpec extensions
1275
+ "x-formspec-source": z3.string().optional(),
1276
+ "x-formspec-params": z3.array(z3.string()).readonly().optional(),
1277
+ "x-formspec-schemaSource": z3.string().optional()
1278
+ }).passthrough()
1279
+ );
1280
+ }
1281
+ });
1282
+
1215
1283
  // src/analyzer/tsdoc-parser.ts
1216
1284
  import * as ts from "typescript";
1217
1285
  import {
@@ -3207,6 +3275,18 @@ var init_class_analyzer = __esm({
3207
3275
  // src/analyzer/program.ts
3208
3276
  import * as ts4 from "typescript";
3209
3277
  import * as path from "path";
3278
+ function createProgramContextFromProgram(program, filePath) {
3279
+ const absolutePath = path.resolve(filePath);
3280
+ const sourceFile = program.getSourceFile(absolutePath) ?? program.getSourceFile(filePath);
3281
+ if (!sourceFile) {
3282
+ throw new Error(`Could not find source file in provided program: ${absolutePath}`);
3283
+ }
3284
+ return {
3285
+ program,
3286
+ checker: program.getTypeChecker(),
3287
+ sourceFile
3288
+ };
3289
+ }
3210
3290
  function createProgramContext(filePath) {
3211
3291
  const absolutePath = path.resolve(filePath);
3212
3292
  const fileDir = path.dirname(absolutePath);
@@ -3277,24 +3357,33 @@ function findTypeAliasByName(sourceFile, aliasName) {
3277
3357
  }
3278
3358
  function analyzeNamedTypeToIR(filePath, typeName, extensionRegistry) {
3279
3359
  const ctx = createProgramContext(filePath);
3360
+ return analyzeNamedTypeToIRFromProgramContext(ctx, filePath, typeName, extensionRegistry);
3361
+ }
3362
+ function analyzeNamedTypeToIRFromProgramContext(ctx, filePath, typeName, extensionRegistry) {
3363
+ const analysisFilePath = path.resolve(filePath);
3280
3364
  const classDecl = findClassByName(ctx.sourceFile, typeName);
3281
3365
  if (classDecl !== null) {
3282
- return analyzeClassToIR(classDecl, ctx.checker, filePath, extensionRegistry);
3366
+ return analyzeClassToIR(classDecl, ctx.checker, analysisFilePath, extensionRegistry);
3283
3367
  }
3284
3368
  const interfaceDecl = findInterfaceByName(ctx.sourceFile, typeName);
3285
3369
  if (interfaceDecl !== null) {
3286
- return analyzeInterfaceToIR(interfaceDecl, ctx.checker, filePath, extensionRegistry);
3370
+ return analyzeInterfaceToIR(interfaceDecl, ctx.checker, analysisFilePath, extensionRegistry);
3287
3371
  }
3288
3372
  const typeAlias = findTypeAliasByName(ctx.sourceFile, typeName);
3289
3373
  if (typeAlias !== null) {
3290
- const result = analyzeTypeAliasToIR(typeAlias, ctx.checker, filePath, extensionRegistry);
3374
+ const result = analyzeTypeAliasToIR(
3375
+ typeAlias,
3376
+ ctx.checker,
3377
+ analysisFilePath,
3378
+ extensionRegistry
3379
+ );
3291
3380
  if (result.ok) {
3292
3381
  return result.analysis;
3293
3382
  }
3294
3383
  throw new Error(result.error);
3295
3384
  }
3296
3385
  throw new Error(
3297
- `Type "${typeName}" not found as a class, interface, or type alias in ${filePath}`
3386
+ `Type "${typeName}" not found as a class, interface, or type alias in ${analysisFilePath}`
3298
3387
  );
3299
3388
  }
3300
3389
  var init_program = __esm({
@@ -3393,6 +3482,7 @@ var init_validate = __esm({
3393
3482
  });
3394
3483
 
3395
3484
  // src/generators/class-schema.ts
3485
+ import "typescript";
3396
3486
  function generateClassSchemas(analysis, source, options) {
3397
3487
  const errorDiagnostics = analysis.diagnostics?.filter(
3398
3488
  (diagnostic) => diagnostic.severity === "error"
@@ -3449,12 +3539,28 @@ function generateSchemasFromClass(options) {
3449
3539
  );
3450
3540
  }
3451
3541
  function generateSchemas(options) {
3452
- const analysis = analyzeNamedTypeToIR(
3542
+ const ctx = createProgramContext(options.filePath);
3543
+ return generateSchemasFromProgram({
3544
+ ...options,
3545
+ program: ctx.program
3546
+ });
3547
+ }
3548
+ function generateSchemasFromProgram(options) {
3549
+ const ctx = createProgramContextFromProgram(options.program, options.filePath);
3550
+ const analysis = analyzeNamedTypeToIRFromProgramContext(
3551
+ ctx,
3453
3552
  options.filePath,
3454
3553
  options.typeName,
3455
3554
  options.extensionRegistry
3456
3555
  );
3457
- return generateClassSchemas(analysis, { file: options.filePath }, options);
3556
+ return generateClassSchemas(
3557
+ analysis,
3558
+ { file: options.filePath },
3559
+ {
3560
+ extensionRegistry: options.extensionRegistry,
3561
+ vendorPrefix: options.vendorPrefix
3562
+ }
3563
+ );
3458
3564
  }
3459
3565
  var init_class_schema = __esm({
3460
3566
  "src/generators/class-schema.ts"() {
@@ -3662,7 +3768,10 @@ __export(index_exports, {
3662
3768
  generateJsonSchema: () => generateJsonSchema,
3663
3769
  generateSchemas: () => generateSchemas,
3664
3770
  generateSchemasFromClass: () => generateSchemasFromClass,
3771
+ generateSchemasFromProgram: () => generateSchemasFromProgram,
3665
3772
  generateUiSchema: () => generateUiSchema,
3773
+ jsonSchema7Schema: () => jsonSchema7Schema,
3774
+ uiSchemaSchema: () => uiSchema,
3666
3775
  writeSchemas: () => writeSchemas
3667
3776
  });
3668
3777
  import * as fs from "fs";
@@ -3693,6 +3802,8 @@ var init_index = __esm({
3693
3802
  init_generator2();
3694
3803
  init_ir_generator();
3695
3804
  init_extensions();
3805
+ init_schema2();
3806
+ init_schema();
3696
3807
  init_generator();
3697
3808
  init_generator2();
3698
3809
  init_class_schema();