@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.
- package/dist/analyzer/program.d.ts +12 -0
- package/dist/analyzer/program.d.ts.map +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +1 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +167 -22
- package/dist/build-beta.d.ts +167 -22
- package/dist/build-internal.d.ts +167 -22
- package/dist/build.d.ts +239 -21
- package/dist/cli.cjs +118 -6
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +117 -6
- package/dist/cli.js.map +1 -1
- package/dist/generators/class-schema.d.ts +27 -0
- package/dist/generators/class-schema.d.ts.map +1 -1
- package/dist/generators/mixed-authoring.d.ts.map +1 -1
- package/dist/index.cjs +114 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +111 -6
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +46 -0
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.d.ts +1 -1
- package/dist/internals.d.ts.map +1 -1
- package/dist/internals.js +44 -0
- package/dist/internals.js.map +1 -1
- package/dist/json-schema/ir-generator.d.ts +30 -0
- package/dist/json-schema/ir-generator.d.ts.map +1 -1
- package/dist/json-schema/schema.d.ts +2 -2
- package/dist/json-schema/types.d.ts +35 -4
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/ui-schema/schema.d.ts +2 -7
- package/dist/ui-schema/schema.d.ts.map +1 -1
- package/dist/ui-schema/types.d.ts +58 -0
- package/dist/ui-schema/types.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* analyzed class/interface/type alias declarations, routing through the
|
|
6
6
|
* canonical FormIR pipeline.
|
|
7
7
|
*/
|
|
8
|
+
import * as ts from "typescript";
|
|
8
9
|
import type { UISchema } from "../ui-schema/types.js";
|
|
9
10
|
import { type IRClassAnalysis } from "../analyzer/class-analyzer.js";
|
|
10
11
|
import { type TSDocSource } from "../canonicalize/index.js";
|
|
@@ -70,6 +71,19 @@ export interface GenerateFromClassResult {
|
|
|
70
71
|
/** JSON Forms UI Schema for rendering */
|
|
71
72
|
uiSchema: UISchema;
|
|
72
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Options for generating schemas from a named type inside an existing TypeScript program.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export interface GenerateSchemasFromProgramOptions extends StaticSchemaGenerationOptions {
|
|
80
|
+
/** Existing TypeScript program supplied by the caller. */
|
|
81
|
+
readonly program: ts.Program;
|
|
82
|
+
/** Path to the TypeScript source file */
|
|
83
|
+
readonly filePath: string;
|
|
84
|
+
/** Name of the exported class, interface, or type alias to analyze */
|
|
85
|
+
readonly typeName: string;
|
|
86
|
+
}
|
|
73
87
|
/**
|
|
74
88
|
* Generates JSON Schema and UI Schema from a decorated TypeScript class.
|
|
75
89
|
*
|
|
@@ -125,4 +139,17 @@ export interface GenerateSchemasOptions extends StaticSchemaGenerationOptions {
|
|
|
125
139
|
* @public
|
|
126
140
|
*/
|
|
127
141
|
export declare function generateSchemas(options: GenerateSchemasOptions): GenerateFromClassResult;
|
|
142
|
+
/**
|
|
143
|
+
* Generates JSON Schema and UI Schema from a named type within an existing
|
|
144
|
+
* TypeScript program supplied by the caller.
|
|
145
|
+
*
|
|
146
|
+
* This low-level entry point lets downstream tooling reuse a host-owned
|
|
147
|
+
* `Program` for both FormSpec extraction and other TypeScript analysis.
|
|
148
|
+
*
|
|
149
|
+
* @param options - Host program, file path, type name, and optional schema generation options
|
|
150
|
+
* @returns Generated JSON Schema and UI Schema
|
|
151
|
+
*
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
export declare function generateSchemasFromProgram(options: GenerateSchemasFromProgramOptions): GenerateFromClassResult;
|
|
128
155
|
//# sourceMappingURL=class-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-schema.d.ts","sourceRoot":"","sources":["../../src/generators/class-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"class-schema.d.ts","sourceRoot":"","sources":["../../src/generators/class-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAOtD,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAEL,KAAK,+BAA+B,EACpC,KAAK,cAAc,EACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAIhE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,UAAU,EAAE,cAAc,CAAC;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,eAAe,EACzB,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,+BAA+B,GACxC,YAAY,CAuBd;AAmBD;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;OAEG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC3D;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAyB,SAAQ,6BAA6B;IAC7E,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,yCAAyC;IACzC,UAAU,EAAE,cAAc,CAAC;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,iCAAkC,SAAQ,6BAA6B;IACtF,0DAA0D;IAC1D,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IAC7B,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,wBAAwB,GAChC,uBAAuB,CAsBzB;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAuB,SAAQ,6BAA6B;IAC3E,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,uBAAuB,CAMxF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,iCAAiC,GACzC,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixed-authoring.d.ts","sourceRoot":"","sources":["../../src/generators/mixed-authoring.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"mixed-authoring.d.ts","sourceRoot":"","sources":["../../src/generators/mixed-authoring.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAItD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iCAAkC,SAAQ,6BAA6B;IACtF,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2GAA2G;IAC3G,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,WAAW,EAAE,CAAC,CAAC;CACrD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,iCAAiC,GACzC,qBAAqB,CAUvB"}
|
package/dist/index.cjs
CHANGED
|
@@ -36,7 +36,10 @@ __export(index_exports, {
|
|
|
36
36
|
generateJsonSchema: () => generateJsonSchema,
|
|
37
37
|
generateSchemas: () => generateSchemas,
|
|
38
38
|
generateSchemasFromClass: () => generateSchemasFromClass,
|
|
39
|
+
generateSchemasFromProgram: () => generateSchemasFromProgram,
|
|
39
40
|
generateUiSchema: () => generateUiSchema,
|
|
41
|
+
jsonSchema7Schema: () => jsonSchema7Schema,
|
|
42
|
+
uiSchemaSchema: () => uiSchema,
|
|
40
43
|
writeSchemas: () => writeSchemas
|
|
41
44
|
});
|
|
42
45
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1184,6 +1187,71 @@ function createExtensionRegistry(extensions) {
|
|
|
1184
1187
|
};
|
|
1185
1188
|
}
|
|
1186
1189
|
|
|
1190
|
+
// src/json-schema/schema.ts
|
|
1191
|
+
var import_zod3 = require("zod");
|
|
1192
|
+
var jsonSchemaTypeSchema = import_zod3.z.enum([
|
|
1193
|
+
"string",
|
|
1194
|
+
"number",
|
|
1195
|
+
"integer",
|
|
1196
|
+
"boolean",
|
|
1197
|
+
"object",
|
|
1198
|
+
"array",
|
|
1199
|
+
"null"
|
|
1200
|
+
]);
|
|
1201
|
+
var jsonSchema7Schema = import_zod3.z.lazy(
|
|
1202
|
+
() => import_zod3.z.object({
|
|
1203
|
+
$schema: import_zod3.z.string().optional(),
|
|
1204
|
+
$id: import_zod3.z.string().optional(),
|
|
1205
|
+
$ref: import_zod3.z.string().optional(),
|
|
1206
|
+
// Metadata
|
|
1207
|
+
title: import_zod3.z.string().optional(),
|
|
1208
|
+
description: import_zod3.z.string().optional(),
|
|
1209
|
+
deprecated: import_zod3.z.boolean().optional(),
|
|
1210
|
+
// Type
|
|
1211
|
+
type: import_zod3.z.union([jsonSchemaTypeSchema, import_zod3.z.array(jsonSchemaTypeSchema)]).optional(),
|
|
1212
|
+
// String validation
|
|
1213
|
+
minLength: import_zod3.z.number().optional(),
|
|
1214
|
+
maxLength: import_zod3.z.number().optional(),
|
|
1215
|
+
pattern: import_zod3.z.string().optional(),
|
|
1216
|
+
// Number validation
|
|
1217
|
+
minimum: import_zod3.z.number().optional(),
|
|
1218
|
+
maximum: import_zod3.z.number().optional(),
|
|
1219
|
+
exclusiveMinimum: import_zod3.z.number().optional(),
|
|
1220
|
+
exclusiveMaximum: import_zod3.z.number().optional(),
|
|
1221
|
+
// Enum
|
|
1222
|
+
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(),
|
|
1223
|
+
const: import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean(), import_zod3.z.null()]).optional(),
|
|
1224
|
+
// Object
|
|
1225
|
+
properties: import_zod3.z.record(import_zod3.z.string(), jsonSchema7Schema).optional(),
|
|
1226
|
+
required: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
1227
|
+
additionalProperties: import_zod3.z.union([import_zod3.z.boolean(), jsonSchema7Schema]).optional(),
|
|
1228
|
+
// Array
|
|
1229
|
+
items: import_zod3.z.union([jsonSchema7Schema, import_zod3.z.array(jsonSchema7Schema)]).optional(),
|
|
1230
|
+
minItems: import_zod3.z.number().optional(),
|
|
1231
|
+
maxItems: import_zod3.z.number().optional(),
|
|
1232
|
+
// Composition
|
|
1233
|
+
allOf: import_zod3.z.array(jsonSchema7Schema).optional(),
|
|
1234
|
+
anyOf: import_zod3.z.array(jsonSchema7Schema).optional(),
|
|
1235
|
+
oneOf: import_zod3.z.array(jsonSchema7Schema).optional(),
|
|
1236
|
+
not: jsonSchema7Schema.optional(),
|
|
1237
|
+
// Conditional
|
|
1238
|
+
if: jsonSchema7Schema.optional(),
|
|
1239
|
+
then: jsonSchema7Schema.optional(),
|
|
1240
|
+
else: jsonSchema7Schema.optional(),
|
|
1241
|
+
// Format
|
|
1242
|
+
format: import_zod3.z.string().optional(),
|
|
1243
|
+
// Default
|
|
1244
|
+
default: import_zod3.z.unknown().optional(),
|
|
1245
|
+
// FormSpec extensions
|
|
1246
|
+
"x-formspec-source": import_zod3.z.string().optional(),
|
|
1247
|
+
"x-formspec-params": import_zod3.z.array(import_zod3.z.string()).readonly().optional(),
|
|
1248
|
+
"x-formspec-schemaSource": import_zod3.z.string().optional()
|
|
1249
|
+
}).passthrough()
|
|
1250
|
+
);
|
|
1251
|
+
|
|
1252
|
+
// src/generators/class-schema.ts
|
|
1253
|
+
var ts5 = require("typescript");
|
|
1254
|
+
|
|
1187
1255
|
// src/analyzer/program.ts
|
|
1188
1256
|
var ts4 = __toESM(require("typescript"), 1);
|
|
1189
1257
|
var path = __toESM(require("path"), 1);
|
|
@@ -3140,6 +3208,18 @@ function detectFormSpecReference(typeNode) {
|
|
|
3140
3208
|
}
|
|
3141
3209
|
|
|
3142
3210
|
// src/analyzer/program.ts
|
|
3211
|
+
function createProgramContextFromProgram(program, filePath) {
|
|
3212
|
+
const absolutePath = path.resolve(filePath);
|
|
3213
|
+
const sourceFile = program.getSourceFile(absolutePath) ?? program.getSourceFile(filePath);
|
|
3214
|
+
if (!sourceFile) {
|
|
3215
|
+
throw new Error(`Could not find source file in provided program: ${absolutePath}`);
|
|
3216
|
+
}
|
|
3217
|
+
return {
|
|
3218
|
+
program,
|
|
3219
|
+
checker: program.getTypeChecker(),
|
|
3220
|
+
sourceFile
|
|
3221
|
+
};
|
|
3222
|
+
}
|
|
3143
3223
|
function createProgramContext(filePath) {
|
|
3144
3224
|
const absolutePath = path.resolve(filePath);
|
|
3145
3225
|
const fileDir = path.dirname(absolutePath);
|
|
@@ -3210,24 +3290,33 @@ function findTypeAliasByName(sourceFile, aliasName) {
|
|
|
3210
3290
|
}
|
|
3211
3291
|
function analyzeNamedTypeToIR(filePath, typeName, extensionRegistry) {
|
|
3212
3292
|
const ctx = createProgramContext(filePath);
|
|
3293
|
+
return analyzeNamedTypeToIRFromProgramContext(ctx, filePath, typeName, extensionRegistry);
|
|
3294
|
+
}
|
|
3295
|
+
function analyzeNamedTypeToIRFromProgramContext(ctx, filePath, typeName, extensionRegistry) {
|
|
3296
|
+
const analysisFilePath = path.resolve(filePath);
|
|
3213
3297
|
const classDecl = findClassByName(ctx.sourceFile, typeName);
|
|
3214
3298
|
if (classDecl !== null) {
|
|
3215
|
-
return analyzeClassToIR(classDecl, ctx.checker,
|
|
3299
|
+
return analyzeClassToIR(classDecl, ctx.checker, analysisFilePath, extensionRegistry);
|
|
3216
3300
|
}
|
|
3217
3301
|
const interfaceDecl = findInterfaceByName(ctx.sourceFile, typeName);
|
|
3218
3302
|
if (interfaceDecl !== null) {
|
|
3219
|
-
return analyzeInterfaceToIR(interfaceDecl, ctx.checker,
|
|
3303
|
+
return analyzeInterfaceToIR(interfaceDecl, ctx.checker, analysisFilePath, extensionRegistry);
|
|
3220
3304
|
}
|
|
3221
3305
|
const typeAlias = findTypeAliasByName(ctx.sourceFile, typeName);
|
|
3222
3306
|
if (typeAlias !== null) {
|
|
3223
|
-
const result = analyzeTypeAliasToIR(
|
|
3307
|
+
const result = analyzeTypeAliasToIR(
|
|
3308
|
+
typeAlias,
|
|
3309
|
+
ctx.checker,
|
|
3310
|
+
analysisFilePath,
|
|
3311
|
+
extensionRegistry
|
|
3312
|
+
);
|
|
3224
3313
|
if (result.ok) {
|
|
3225
3314
|
return result.analysis;
|
|
3226
3315
|
}
|
|
3227
3316
|
throw new Error(result.error);
|
|
3228
3317
|
}
|
|
3229
3318
|
throw new Error(
|
|
3230
|
-
`Type "${typeName}" not found as a class, interface, or type alias in ${
|
|
3319
|
+
`Type "${typeName}" not found as a class, interface, or type alias in ${analysisFilePath}`
|
|
3231
3320
|
);
|
|
3232
3321
|
}
|
|
3233
3322
|
|
|
@@ -3361,12 +3450,28 @@ function generateSchemasFromClass(options) {
|
|
|
3361
3450
|
);
|
|
3362
3451
|
}
|
|
3363
3452
|
function generateSchemas(options) {
|
|
3364
|
-
const
|
|
3453
|
+
const ctx = createProgramContext(options.filePath);
|
|
3454
|
+
return generateSchemasFromProgram({
|
|
3455
|
+
...options,
|
|
3456
|
+
program: ctx.program
|
|
3457
|
+
});
|
|
3458
|
+
}
|
|
3459
|
+
function generateSchemasFromProgram(options) {
|
|
3460
|
+
const ctx = createProgramContextFromProgram(options.program, options.filePath);
|
|
3461
|
+
const analysis = analyzeNamedTypeToIRFromProgramContext(
|
|
3462
|
+
ctx,
|
|
3365
3463
|
options.filePath,
|
|
3366
3464
|
options.typeName,
|
|
3367
3465
|
options.extensionRegistry
|
|
3368
3466
|
);
|
|
3369
|
-
return generateClassSchemas(
|
|
3467
|
+
return generateClassSchemas(
|
|
3468
|
+
analysis,
|
|
3469
|
+
{ file: options.filePath },
|
|
3470
|
+
{
|
|
3471
|
+
extensionRegistry: options.extensionRegistry,
|
|
3472
|
+
vendorPrefix: options.vendorPrefix
|
|
3473
|
+
}
|
|
3474
|
+
);
|
|
3370
3475
|
}
|
|
3371
3476
|
|
|
3372
3477
|
// src/generators/mixed-authoring.ts
|
|
@@ -3573,7 +3678,10 @@ function writeSchemas(form, options) {
|
|
|
3573
3678
|
generateJsonSchema,
|
|
3574
3679
|
generateSchemas,
|
|
3575
3680
|
generateSchemasFromClass,
|
|
3681
|
+
generateSchemasFromProgram,
|
|
3576
3682
|
generateUiSchema,
|
|
3683
|
+
jsonSchema7Schema,
|
|
3684
|
+
uiSchemaSchema,
|
|
3577
3685
|
writeSchemas
|
|
3578
3686
|
});
|
|
3579
3687
|
//# sourceMappingURL=index.cjs.map
|