@formspec/build 0.1.0-alpha.2 → 0.1.0-alpha.20
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 +120 -0
- package/dist/__tests__/alias-chain-propagation.test.d.ts +9 -0
- package/dist/__tests__/alias-chain-propagation.test.d.ts.map +1 -0
- package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts +2 -0
- package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts.map +1 -0
- package/dist/__tests__/class-schema.test.d.ts +2 -0
- package/dist/__tests__/class-schema.test.d.ts.map +1 -0
- package/dist/__tests__/constraint-validator.test.d.ts +2 -0
- package/dist/__tests__/constraint-validator.test.d.ts.map +1 -0
- package/dist/__tests__/date-extension.integration.test.d.ts +2 -0
- package/dist/__tests__/date-extension.integration.test.d.ts.map +1 -0
- package/dist/__tests__/extension-api.test.d.ts +2 -0
- package/dist/__tests__/extension-api.test.d.ts.map +1 -0
- package/dist/__tests__/extension-runtime.integration.test.d.ts +2 -0
- package/dist/__tests__/extension-runtime.integration.test.d.ts.map +1 -0
- package/dist/__tests__/fixtures/alias-chains.d.ts +37 -0
- package/dist/__tests__/fixtures/alias-chains.d.ts.map +1 -0
- package/dist/__tests__/fixtures/class-schema-regressions.d.ts +87 -0
- package/dist/__tests__/fixtures/class-schema-regressions.d.ts.map +1 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts +132 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts +30 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-date-extension.d.ts +12 -0
- package/dist/__tests__/fixtures/example-date-extension.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-interface-types.d.ts +102 -0
- package/dist/__tests__/fixtures/example-interface-types.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-numeric-extension.d.ts +20 -0
- package/dist/__tests__/fixtures/example-numeric-extension.d.ts.map +1 -0
- package/dist/__tests__/fixtures/extension-forms.d.ts +7 -0
- package/dist/__tests__/fixtures/extension-forms.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts +31 -0
- package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts.map +1 -0
- package/dist/__tests__/fixtures/named-primitive-aliases.d.ts +15 -0
- package/dist/__tests__/fixtures/named-primitive-aliases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts +14 -0
- package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts.map +1 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts +65 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts.map +1 -0
- package/dist/__tests__/generate-schemas.test.d.ts +2 -0
- package/dist/__tests__/generate-schemas.test.d.ts.map +1 -0
- package/dist/__tests__/guards.test.d.ts +2 -0
- package/dist/__tests__/guards.test.d.ts.map +1 -0
- package/dist/__tests__/ir-analyzer.test.d.ts +11 -0
- package/dist/__tests__/ir-analyzer.test.d.ts.map +1 -0
- package/dist/__tests__/ir-jsdoc-constraints.test.d.ts +12 -0
- package/dist/__tests__/ir-jsdoc-constraints.test.d.ts.map +1 -0
- package/dist/__tests__/ir-json-schema-generator.test.d.ts +11 -0
- package/dist/__tests__/ir-json-schema-generator.test.d.ts.map +1 -0
- package/dist/__tests__/ir-ui-schema-generator.test.d.ts +2 -0
- package/dist/__tests__/ir-ui-schema-generator.test.d.ts.map +1 -0
- package/dist/__tests__/mixed-authoring.test.d.ts +2 -0
- package/dist/__tests__/mixed-authoring.test.d.ts.map +1 -0
- package/dist/__tests__/numeric-extension.integration.test.d.ts +2 -0
- package/dist/__tests__/numeric-extension.integration.test.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts +6 -0
- package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts +17 -0
- package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts +13 -0
- package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts +28 -0
- package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts +6 -0
- package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts +12 -0
- package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/parity.test.d.ts +18 -0
- package/dist/__tests__/parity/parity.test.d.ts.map +1 -0
- package/dist/__tests__/parity/utils.d.ts +151 -0
- package/dist/__tests__/parity/utils.d.ts.map +1 -0
- package/dist/__tests__/path-target-parser.test.d.ts +9 -0
- package/dist/__tests__/path-target-parser.test.d.ts.map +1 -0
- package/dist/analyzer/class-analyzer.d.ts +100 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -0
- package/dist/analyzer/jsdoc-constraints.d.ts +53 -0
- package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
- package/dist/analyzer/program.d.ts +68 -0
- package/dist/analyzer/program.d.ts.map +1 -0
- package/dist/analyzer/tsdoc-parser.d.ts +122 -0
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
- package/dist/browser.cjs +1291 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.ts +73 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1242 -0
- package/dist/browser.js.map +1 -0
- package/dist/build.d.ts +996 -0
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +18 -0
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -0
- package/dist/canonicalize/index.d.ts +8 -0
- package/dist/canonicalize/index.d.ts.map +1 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts +34 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
- package/dist/cli.cjs +3862 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +3826 -103
- package/dist/cli.js.map +1 -1
- package/dist/extensions/index.d.ts +8 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/registry.d.ts +79 -0
- package/dist/extensions/registry.d.ts.map +1 -0
- package/dist/generators/class-schema.d.ts +99 -0
- package/dist/generators/class-schema.d.ts.map +1 -0
- package/dist/generators/method-schema.d.ts +65 -0
- package/dist/generators/method-schema.d.ts.map +1 -0
- package/dist/generators/mixed-authoring.d.ts +45 -0
- package/dist/generators/mixed-authoring.d.ts.map +1 -0
- package/dist/index.cjs +3627 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +33 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3587 -106
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +3371 -0
- package/dist/internals.cjs.map +1 -0
- package/dist/internals.d.ts +30 -0
- package/dist/internals.d.ts.map +1 -0
- package/dist/internals.js +3345 -0
- package/dist/internals.js.map +1 -0
- package/dist/json-schema/generator.d.ts +16 -5
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/json-schema/ir-generator.d.ts +108 -0
- package/dist/json-schema/ir-generator.d.ts.map +1 -0
- package/dist/json-schema/schema.d.ts +16 -0
- package/dist/json-schema/schema.d.ts.map +1 -0
- package/dist/json-schema/types.d.ts +29 -2
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/ui-schema/generator.d.ts +5 -0
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/ir-generator.d.ts +53 -0
- package/dist/ui-schema/ir-generator.d.ts.map +1 -0
- package/dist/ui-schema/schema.d.ts +357 -0
- package/dist/ui-schema/schema.d.ts.map +1 -0
- package/dist/ui-schema/types.d.ts +8 -73
- package/dist/ui-schema/types.d.ts.map +1 -1
- package/dist/validate/constraint-validator.d.ts +23 -0
- package/dist/validate/constraint-validator.d.ts.map +1 -0
- package/dist/validate/index.d.ts +9 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/package.json +27 -7
- package/dist/__tests__/cli.test.js +0 -178
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/__tests__/edge-cases.test.js +0 -217
- package/dist/__tests__/edge-cases.test.js.map +0 -1
- package/dist/__tests__/generator.test.js +0 -225
- package/dist/__tests__/generator.test.js.map +0 -1
- package/dist/__tests__/integration.test.js +0 -163
- package/dist/__tests__/integration.test.js.map +0 -1
- package/dist/__tests__/write-schemas.test.js +0 -196
- package/dist/__tests__/write-schemas.test.js.map +0 -1
- package/dist/json-schema/generator.js +0 -161
- package/dist/json-schema/generator.js.map +0 -1
- package/dist/json-schema/types.js +0 -7
- package/dist/json-schema/types.js.map +0 -1
- package/dist/ui-schema/generator.js +0 -150
- package/dist/ui-schema/generator.js.map +0 -1
- package/dist/ui-schema/types.js +0 -8
- package/dist/ui-schema/types.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension registry for resolving custom types, constraints, and annotations
|
|
3
|
+
* during JSON Schema generation and IR validation.
|
|
4
|
+
*
|
|
5
|
+
* The registry is created from a list of {@link ExtensionDefinition} objects
|
|
6
|
+
* and provides O(1) lookup by fully-qualified ID (extensionId + "/" + name).
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import type { ExtensionDefinition, CustomTypeRegistration, CustomConstraintRegistration, CustomAnnotationRegistration, ConstraintTagRegistration, BuiltinConstraintBroadeningRegistration } from "@formspec/core";
|
|
11
|
+
/**
|
|
12
|
+
* A registry of extensions that provides lookup by fully-qualified ID.
|
|
13
|
+
*
|
|
14
|
+
* Type IDs follow the format: `<extensionId>/<typeName>`
|
|
15
|
+
* Constraint IDs follow the format: `<extensionId>/<constraintName>`
|
|
16
|
+
* Annotation IDs follow the format: `<extensionId>/<annotationName>`
|
|
17
|
+
*/
|
|
18
|
+
export interface ExtensionRegistry {
|
|
19
|
+
/** The extensions registered in this registry (in registration order). */
|
|
20
|
+
readonly extensions: readonly ExtensionDefinition[];
|
|
21
|
+
/**
|
|
22
|
+
* Look up a custom type registration by its fully-qualified type ID.
|
|
23
|
+
*
|
|
24
|
+
* @param typeId - The fully-qualified type ID (e.g., "x-stripe/monetary/Decimal").
|
|
25
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
26
|
+
*/
|
|
27
|
+
findType(typeId: string): CustomTypeRegistration | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Look up a custom type registration by a TypeScript-facing type name.
|
|
30
|
+
*
|
|
31
|
+
* This is used during TSDoc/class analysis to resolve extension-defined
|
|
32
|
+
* custom types from source-level declarations.
|
|
33
|
+
*/
|
|
34
|
+
findTypeByName(typeName: string): {
|
|
35
|
+
readonly extensionId: string;
|
|
36
|
+
readonly registration: CustomTypeRegistration;
|
|
37
|
+
} | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Look up a custom constraint registration by its fully-qualified constraint ID.
|
|
40
|
+
*
|
|
41
|
+
* @param constraintId - The fully-qualified constraint ID.
|
|
42
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
43
|
+
*/
|
|
44
|
+
findConstraint(constraintId: string): CustomConstraintRegistration | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Look up a TSDoc custom constraint-tag registration by tag name.
|
|
47
|
+
*/
|
|
48
|
+
findConstraintTag(tagName: string): {
|
|
49
|
+
readonly extensionId: string;
|
|
50
|
+
readonly registration: ConstraintTagRegistration;
|
|
51
|
+
} | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Look up built-in tag broadening for a given custom type ID.
|
|
54
|
+
*/
|
|
55
|
+
findBuiltinConstraintBroadening(typeId: string, tagName: string): {
|
|
56
|
+
readonly extensionId: string;
|
|
57
|
+
readonly registration: BuiltinConstraintBroadeningRegistration;
|
|
58
|
+
} | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Look up a custom annotation registration by its fully-qualified annotation ID.
|
|
61
|
+
*
|
|
62
|
+
* @param annotationId - The fully-qualified annotation ID.
|
|
63
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
64
|
+
*/
|
|
65
|
+
findAnnotation(annotationId: string): CustomAnnotationRegistration | undefined;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates an extension registry from a list of extension definitions.
|
|
69
|
+
*
|
|
70
|
+
* The registry indexes all types, constraints, and annotations by their
|
|
71
|
+
* fully-qualified IDs (`<extensionId>/<name>`) for O(1) lookup during
|
|
72
|
+
* generation and validation.
|
|
73
|
+
*
|
|
74
|
+
* @param extensions - The extension definitions to register.
|
|
75
|
+
* @returns An {@link ExtensionRegistry} instance.
|
|
76
|
+
* @throws If duplicate type/constraint/annotation IDs are detected across extensions.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createExtensionRegistry(extensions: readonly ExtensionDefinition[]): ExtensionRegistry;
|
|
79
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/extensions/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,yBAAyB,EACzB,uCAAuC,EACxC,MAAM,gBAAgB,CAAC;AAMxB;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E,QAAQ,CAAC,UAAU,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAEpD;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS,CAAC;IAC7D;;;;;OAKG;IACH,cAAc,CACZ,QAAQ,EAAE,MAAM,GACf;QAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,YAAY,EAAE,sBAAsB,CAAA;KAAE,GAAG,SAAS,CAAC;IAE/F;;;;;OAKG;IACH,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,4BAA4B,GAAG,SAAS,CAAC;IAC/E;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAC7B;QACE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,YAAY,EAAE,yBAAyB,CAAC;KAClD,GACD,SAAS,CAAC;IACd;;OAEG;IACH,+BAA+B,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAEb;QACE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,YAAY,EAAE,uCAAuC,CAAC;KAChE,GACD,SAAS,CAAC;IAEd;;;;;OAKG;IACH,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,4BAA4B,GAAG,SAAS,CAAC;CAChF;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,SAAS,mBAAmB,EAAE,GACzC,iBAAiB,CA8FnB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class schema generator.
|
|
3
|
+
*
|
|
4
|
+
* Generates JSON Schema 2020-12 and JSON Forms UI Schema from statically
|
|
5
|
+
* analyzed class/interface/type alias declarations, routing through the
|
|
6
|
+
* canonical FormIR pipeline.
|
|
7
|
+
*/
|
|
8
|
+
import type { UISchema } from "../ui-schema/types.js";
|
|
9
|
+
import { type IRClassAnalysis } from "../analyzer/class-analyzer.js";
|
|
10
|
+
import { type TSDocSource } from "../canonicalize/index.js";
|
|
11
|
+
import { type GenerateJsonSchemaFromIROptions, type JsonSchema2020 } from "../json-schema/ir-generator.js";
|
|
12
|
+
/**
|
|
13
|
+
* Generated schemas for a class.
|
|
14
|
+
*/
|
|
15
|
+
export interface ClassSchemas {
|
|
16
|
+
/** JSON Schema 2020-12 for validation */
|
|
17
|
+
jsonSchema: JsonSchema2020;
|
|
18
|
+
/** JSON Forms UI Schema for rendering */
|
|
19
|
+
uiSchema: UISchema;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generates JSON Schema 2020-12 and UI Schema from an IR class analysis.
|
|
23
|
+
*
|
|
24
|
+
* Routes through the canonical IR pipeline:
|
|
25
|
+
* IRClassAnalysis → canonicalizeTSDoc → FormIR → JSON Schema / UI Schema
|
|
26
|
+
*
|
|
27
|
+
* @param analysis - The IR analysis result (from analyzeClassToIR, analyzeInterfaceToIR, or analyzeTypeAliasToIR)
|
|
28
|
+
* @param source - Optional source file metadata for provenance
|
|
29
|
+
* @returns Generated JSON Schema and UI Schema
|
|
30
|
+
*/
|
|
31
|
+
export declare function generateClassSchemas(analysis: IRClassAnalysis, source?: TSDocSource, options?: GenerateJsonSchemaFromIROptions): ClassSchemas;
|
|
32
|
+
/**
|
|
33
|
+
* Options for generating schemas from a decorated class.
|
|
34
|
+
*/
|
|
35
|
+
export interface GenerateFromClassOptions extends GenerateJsonSchemaFromIROptions {
|
|
36
|
+
/** Path to the TypeScript source file */
|
|
37
|
+
filePath: string;
|
|
38
|
+
/** Class name to analyze */
|
|
39
|
+
className: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Result of generating schemas from a decorated class.
|
|
43
|
+
*/
|
|
44
|
+
export interface GenerateFromClassResult {
|
|
45
|
+
/** JSON Schema 2020-12 for validation */
|
|
46
|
+
jsonSchema: JsonSchema2020;
|
|
47
|
+
/** JSON Forms UI Schema for rendering */
|
|
48
|
+
uiSchema: UISchema;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Generates JSON Schema and UI Schema from a decorated TypeScript class.
|
|
52
|
+
*
|
|
53
|
+
* This is a high-level entry point that handles the entire pipeline:
|
|
54
|
+
* creating a TypeScript program, finding the class, analyzing it to IR,
|
|
55
|
+
* and generating schemas — all in one call.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const result = generateSchemasFromClass({
|
|
60
|
+
* filePath: "./src/forms.ts",
|
|
61
|
+
* className: "UserForm",
|
|
62
|
+
* });
|
|
63
|
+
* console.log(result.jsonSchema);
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @param options - File path, class name, and optional compiler options
|
|
67
|
+
* @returns Generated JSON Schema and UI Schema
|
|
68
|
+
*/
|
|
69
|
+
export declare function generateSchemasFromClass(options: GenerateFromClassOptions): GenerateFromClassResult;
|
|
70
|
+
/**
|
|
71
|
+
* Options for generating schemas from a named type (class, interface, or type alias).
|
|
72
|
+
*/
|
|
73
|
+
export interface GenerateSchemasOptions extends GenerateJsonSchemaFromIROptions {
|
|
74
|
+
/** Path to the TypeScript source file */
|
|
75
|
+
filePath: string;
|
|
76
|
+
/** Name of the exported class, interface, or type alias to analyze */
|
|
77
|
+
typeName: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Generates JSON Schema and UI Schema from a named TypeScript
|
|
81
|
+
* type — a decorated class, an interface with TSDoc tags, or a type alias.
|
|
82
|
+
*
|
|
83
|
+
* This is the recommended entry point. It automatically detects whether
|
|
84
|
+
* the name resolves to a class, interface, or type alias and uses the
|
|
85
|
+
* appropriate IR analysis pipeline.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const result = generateSchemas({
|
|
90
|
+
* filePath: "./src/config.ts",
|
|
91
|
+
* typeName: "DiscountConfig",
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @param options - File path and type name
|
|
96
|
+
* @returns Generated JSON Schema and UI Schema
|
|
97
|
+
*/
|
|
98
|
+
export declare function generateSchemas(options: GenerateSchemasOptions): GenerateFromClassResult;
|
|
99
|
+
//# sourceMappingURL=class-schema.d.ts.map
|
|
@@ -0,0 +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;AAMtD,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;AAIxC;;GAEG;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;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,+BAA+B;IAC/E,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,yCAAyC;IACzC,UAAU,EAAE,cAAc,CAAC;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,wBAAwB,GAChC,uBAAuB,CAsBzB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,+BAA+B;IAC7E,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,uBAAuB,CAOxF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method schema generator.
|
|
3
|
+
*
|
|
4
|
+
* Generates schemas for method parameters and return types, routing through
|
|
5
|
+
* the canonical IR pipeline (TypeScript type → TypeNode → JSON Schema 2020-12).
|
|
6
|
+
*/
|
|
7
|
+
import type * as ts from "typescript";
|
|
8
|
+
import type { MethodInfo } from "../analyzer/class-analyzer.js";
|
|
9
|
+
import { type JsonSchema2020 } from "../json-schema/ir-generator.js";
|
|
10
|
+
/**
|
|
11
|
+
* Runtime-loaded FormSpec schemas, compatible with the CLI's FormSpecSchemas type.
|
|
12
|
+
*/
|
|
13
|
+
export interface LoadedFormSpecSchemas {
|
|
14
|
+
/** The FormSpec export name */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Generated JSON Schema */
|
|
17
|
+
jsonSchema: unknown;
|
|
18
|
+
/** Generated UI Schema (FormSpec/JSON Forms) */
|
|
19
|
+
uiSchema: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generated schemas for a method.
|
|
23
|
+
*/
|
|
24
|
+
export interface MethodSchemas {
|
|
25
|
+
/** Method name */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Parameter schemas (from FormSpec or static analysis) */
|
|
28
|
+
params: MethodParamsSchemas | null;
|
|
29
|
+
/** Return type schema */
|
|
30
|
+
returnType: JsonSchema2020;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parameter schemas for a method.
|
|
34
|
+
*/
|
|
35
|
+
export interface MethodParamsSchemas {
|
|
36
|
+
/** JSON Schema for parameters */
|
|
37
|
+
jsonSchema: JsonSchema2020;
|
|
38
|
+
/** UI Schema / FormSpec for parameters (if available) */
|
|
39
|
+
uiSchema: object | null;
|
|
40
|
+
/** Name of the FormSpec export used (if any) */
|
|
41
|
+
formSpecExport: string | null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Generates schemas for a method's parameters and return type.
|
|
45
|
+
*
|
|
46
|
+
* If a parameter references a FormSpec via `InferSchema<typeof X>`,
|
|
47
|
+
* the schemas are taken from the loaded FormSpec at runtime.
|
|
48
|
+
* Otherwise, schemas are generated from static type analysis via the IR.
|
|
49
|
+
*
|
|
50
|
+
* @param method - The method information from static analysis
|
|
51
|
+
* @param checker - TypeScript type checker
|
|
52
|
+
* @param loadedFormSpecs - Map of FormSpec export names to their schemas
|
|
53
|
+
* @returns Generated method schemas
|
|
54
|
+
*/
|
|
55
|
+
export declare function generateMethodSchemas(method: MethodInfo, checker: ts.TypeChecker, loadedFormSpecs: Map<string, LoadedFormSpecSchemas>): MethodSchemas;
|
|
56
|
+
/**
|
|
57
|
+
* Collects all FormSpec export names referenced by methods.
|
|
58
|
+
*
|
|
59
|
+
* Use this to determine which exports to load at runtime.
|
|
60
|
+
*
|
|
61
|
+
* @param methods - Array of method infos
|
|
62
|
+
* @returns Set of FormSpec export names
|
|
63
|
+
*/
|
|
64
|
+
export declare function collectFormSpecReferences(methods: MethodInfo[]): Set<string>;
|
|
65
|
+
//# sourceMappingURL=method-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method-schema.d.ts","sourceRoot":"","sources":["../../src/generators/method-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,+BAA+B,CAAC;AAG/E,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAG/F;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,UAAU,EAAE,OAAO,CAAC;IACpB,gDAAgD;IAChD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACnC,yBAAyB;IACzB,UAAU,EAAE,cAAc,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iCAAiC;IACjC,UAAU,EAAE,cAAc,CAAC;IAC3B,yDAAyD;IACzD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gDAAgD;IAChD,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AA6CD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAClD,aAAa,CAYf;AAmED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAY5E"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mixed-authoring schema generator.
|
|
3
|
+
*
|
|
4
|
+
* Composes a statically analyzed TSDoc/class/interface/type-alias model with
|
|
5
|
+
* ChainDSL-authored field overlays. The static model remains authoritative for
|
|
6
|
+
* structure and constraints; overlays may add runtime field behavior such as
|
|
7
|
+
* dynamic enum or dynamic schema metadata.
|
|
8
|
+
*/
|
|
9
|
+
import type { FormElement, FormSpec } from "@formspec/core";
|
|
10
|
+
import type { GenerateJsonSchemaFromIROptions, JsonSchema2020 } from "../json-schema/ir-generator.js";
|
|
11
|
+
import type { UISchema } from "../ui-schema/types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Result of generating schemas from a mixed-authoring composition.
|
|
14
|
+
*/
|
|
15
|
+
export interface MixedAuthoringSchemas {
|
|
16
|
+
/** JSON Schema 2020-12 for validation. */
|
|
17
|
+
readonly jsonSchema: JsonSchema2020;
|
|
18
|
+
/** JSON Forms UI Schema for rendering. */
|
|
19
|
+
readonly uiSchema: UISchema;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for generating mixed-authoring schemas.
|
|
23
|
+
*
|
|
24
|
+
* The `typeName` can resolve to a class, interface, or object type alias, just
|
|
25
|
+
* like `generateSchemas()`.
|
|
26
|
+
*/
|
|
27
|
+
export interface BuildMixedAuthoringSchemasOptions extends GenerateJsonSchemaFromIROptions {
|
|
28
|
+
/** Path to the TypeScript source file. */
|
|
29
|
+
readonly filePath: string;
|
|
30
|
+
/** Name of the class, interface, or type alias to analyze. */
|
|
31
|
+
readonly typeName: string;
|
|
32
|
+
/** ChainDSL overlays to apply to the static model. Groups and conditionals are flattened by field name. */
|
|
33
|
+
readonly overlays: FormSpec<readonly FormElement[]>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds JSON Schema and UI Schema from a TSDoc-derived model with ChainDSL
|
|
37
|
+
* field overlays.
|
|
38
|
+
*
|
|
39
|
+
* Overlays are matched by field name. The static model wins for structure,
|
|
40
|
+
* ordering, and constraints; ChainDSL overlays may contribute dynamic runtime
|
|
41
|
+
* field metadata such as dynamic enum or dynamic schema keywords, and may fill
|
|
42
|
+
* in missing annotations.
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildMixedAuthoringSchemas(options: BuildMixedAuthoringSchemasOptions): MixedAuthoringSchemas;
|
|
45
|
+
//# sourceMappingURL=mixed-authoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixed-authoring.d.ts","sourceRoot":"","sources":["../../src/generators/mixed-authoring.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAGV,WAAW,EAEX,QAAQ,EAET,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,+BAA+B,EAC/B,cAAc,EACf,MAAM,gCAAgC,CAAC;AAGxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAKtD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;;;;GAKG;AACH,MAAM,WAAW,iCAAkC,SAAQ,+BAA+B;IACxF,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;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,iCAAiC,GACzC,qBAAqB,CAUvB"}
|