@formspec/build 0.1.0-alpha.13 → 0.1.0-alpha.15

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 (71) hide show
  1. package/README.md +20 -20
  2. package/dist/__tests__/alias-chain-propagation.test.d.ts +9 -0
  3. package/dist/__tests__/alias-chain-propagation.test.d.ts.map +1 -0
  4. package/dist/__tests__/extension-runtime.integration.test.d.ts +2 -0
  5. package/dist/__tests__/extension-runtime.integration.test.d.ts.map +1 -0
  6. package/dist/__tests__/fixtures/alias-chains.d.ts +37 -0
  7. package/dist/__tests__/fixtures/alias-chains.d.ts.map +1 -0
  8. package/dist/__tests__/fixtures/edge-cases.d.ts +11 -0
  9. package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -1
  10. package/dist/__tests__/fixtures/example-a-builtins.d.ts +13 -13
  11. package/dist/__tests__/fixtures/example-interface-types.d.ts +33 -33
  12. package/dist/__tests__/fixtures/example-interface-types.d.ts.map +1 -1
  13. package/dist/__tests__/jsdoc-constraints.test.d.ts +4 -5
  14. package/dist/__tests__/jsdoc-constraints.test.d.ts.map +1 -1
  15. package/dist/__tests__/json-utils.test.d.ts +5 -0
  16. package/dist/__tests__/json-utils.test.d.ts.map +1 -0
  17. package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts +19 -0
  18. package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts.map +1 -0
  19. package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts +6 -0
  20. package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts.map +1 -0
  21. package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts +17 -0
  22. package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts.map +1 -0
  23. package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts +9 -0
  24. package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts.map +1 -0
  25. package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts +6 -0
  26. package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts.map +1 -0
  27. package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts +19 -0
  28. package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts.map +1 -0
  29. package/dist/__tests__/parity/utils.d.ts +6 -1
  30. package/dist/__tests__/parity/utils.d.ts.map +1 -1
  31. package/dist/__tests__/path-target-parser.test.d.ts +9 -0
  32. package/dist/__tests__/path-target-parser.test.d.ts.map +1 -0
  33. package/dist/analyzer/class-analyzer.d.ts +1 -1
  34. package/dist/analyzer/class-analyzer.d.ts.map +1 -1
  35. package/dist/analyzer/jsdoc-constraints.d.ts +8 -52
  36. package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -1
  37. package/dist/analyzer/json-utils.d.ts +22 -0
  38. package/dist/analyzer/json-utils.d.ts.map +1 -0
  39. package/dist/analyzer/tsdoc-parser.d.ts +24 -12
  40. package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
  41. package/dist/browser.cjs +452 -94
  42. package/dist/browser.cjs.map +1 -1
  43. package/dist/browser.d.ts +15 -2
  44. package/dist/browser.d.ts.map +1 -1
  45. package/dist/browser.js +450 -94
  46. package/dist/browser.js.map +1 -1
  47. package/dist/build.d.ts +132 -5
  48. package/dist/canonicalize/tsdoc-canonicalizer.d.ts +3 -3
  49. package/dist/cli.cjs +406 -104
  50. package/dist/cli.cjs.map +1 -1
  51. package/dist/cli.js +407 -104
  52. package/dist/cli.js.map +1 -1
  53. package/dist/index.cjs +386 -102
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.ts +20 -3
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +386 -104
  58. package/dist/index.js.map +1 -1
  59. package/dist/internals.cjs +597 -172
  60. package/dist/internals.cjs.map +1 -1
  61. package/dist/internals.js +597 -172
  62. package/dist/internals.js.map +1 -1
  63. package/dist/json-schema/generator.d.ts +8 -2
  64. package/dist/json-schema/generator.d.ts.map +1 -1
  65. package/dist/json-schema/ir-generator.d.ts +25 -2
  66. package/dist/json-schema/ir-generator.d.ts.map +1 -1
  67. package/dist/json-schema/types.d.ts +1 -1
  68. package/dist/json-schema/types.d.ts.map +1 -1
  69. package/dist/validate/constraint-validator.d.ts +3 -7
  70. package/dist/validate/constraint-validator.d.ts.map +1 -1
  71. package/package.json +3 -3
@@ -3,37 +3,17 @@
3
3
  *
4
4
  * Extracts constraints and annotation tags from JSDoc comments on
5
5
  * class/interface fields and returns canonical IR nodes directly:
6
- * - {@link ConstraintNode} for set-influencing tags (@Minimum, @Pattern, etc.)
7
- * - {@link AnnotationNode} for value-influencing tags (@Field_displayName, etc.)
6
+ * - {@link ConstraintNode} for set-influencing tags (@minimum, @pattern, etc.)
7
+ * - {@link AnnotationNode} for value-influencing tags (@displayName, etc.)
8
8
  *
9
9
  * The IR extraction path uses the official `@microsoft/tsdoc` parser for
10
- * constraints (all TSDoc-compliant alphanumeric names) and the TypeScript
11
- * compiler JSDoc API for annotation tags (which contain underscores, e.g.
12
- * `@Field_displayName`).
10
+ * all canonical tags.
13
11
  *
14
- * Supported constraints correspond to keys in {@link BUILTIN_CONSTRAINT_DEFINITIONS}
15
- * from `@formspec/core` (e.g., `@Minimum`, `@Maximum`, `@Pattern`).
12
+ * Supported constraints correspond to the built-in FormSpec constraint tags
13
+ * (e.g., `@minimum`, `@maximum`, `@pattern`).
16
14
  */
17
15
  import * as ts from "typescript";
18
- import { type ConstraintNode, type AnnotationNode } from "@formspec/core";
19
- /**
20
- * A constraint argument value.
21
- */
22
- export type ConstraintArg = string | number | boolean | null | ConstraintArg[] | {
23
- [key: string]: ConstraintArg;
24
- };
25
- /**
26
- * Extracted constraint information from a JSDoc tag.
27
- * @deprecated Use {@link ConstraintNode} from the IR path instead.
28
- */
29
- export interface ConstraintInfo {
30
- /** Constraint name (e.g., "Minimum", "Pattern", "Field") */
31
- name: string;
32
- /** Constraint arguments as literal values */
33
- args: ConstraintArg[];
34
- /** Raw AST node (undefined for synthetic JSDoc constraint entries) */
35
- node: ts.Decorator | undefined;
36
- }
16
+ import type { ConstraintNode, AnnotationNode } from "@formspec/core";
37
17
  /**
38
18
  * Extracts constraints from JSDoc comments on a TypeScript AST node and returns
39
19
  * canonical {@link ConstraintNode} objects.
@@ -47,14 +27,8 @@ export interface ConstraintInfo {
47
27
  */
48
28
  export declare function extractJSDocConstraintNodes(node: ts.Node, file?: string): ConstraintNode[];
49
29
  /**
50
- * Extracts `@Field_displayName`, `@Field_description`, and `@deprecated`
51
- * TSDoc tags from a node and returns canonical {@link AnnotationNode} objects.
52
- *
53
- * Uses a hybrid approach:
54
- * - `@deprecated` is extracted via the TSDoc parser (standard tag).
55
- * - `@Field_displayName` and `@Field_description` are extracted via the
56
- * TypeScript compiler JSDoc API because they contain underscores which
57
- * are invalid in TSDoc tag names.
30
+ * Extracts canonical annotation tags from a node and returns
31
+ * {@link AnnotationNode} objects.
58
32
  *
59
33
  * @param node - The AST node to inspect for annotation tags
60
34
  * @param file - Absolute path to the source file for provenance
@@ -74,22 +48,4 @@ export declare function hasDeprecatedTag(node: ts.Node): boolean;
74
48
  * Only extracts literal values (strings, numbers, booleans, null).
75
49
  */
76
50
  export declare function extractDefaultValueAnnotation(initializer: ts.Expression | undefined, file?: string): AnnotationNode | null;
77
- /**
78
- * Extracts JSDoc constraint tags and returns synthetic {@link ConstraintInfo}
79
- * objects for backward compatibility with the decorator-based pipeline.
80
- *
81
- * Uses the TypeScript compiler JSDoc API (not TSDoc parser) to maintain
82
- * identical behavior with the legacy pipeline.
83
- *
84
- * @deprecated Use {@link extractJSDocConstraintNodes} for IR output.
85
- */
86
- export declare function extractJSDocConstraints(node: ts.Node): ConstraintInfo[];
87
- /**
88
- * Extracts `@Field_displayName` and `@Field_description` TSDoc tags
89
- * and returns a synthetic `Field` {@link ConstraintInfo} for backward
90
- * compatibility with the decorator-based pipeline.
91
- *
92
- * @deprecated Use {@link extractJSDocAnnotationNodes} for IR output.
93
- */
94
- export declare function extractJSDocFieldMetadata(node: ts.Node): ConstraintInfo | null;
95
51
  //# sourceMappingURL=jsdoc-constraints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsdoc-constraints.d.ts","sourceRoot":"","sources":["../../src/analyzer/jsdoc-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,cAAc,EAEpB,MAAM,gBAAgB,CAAC;AAOxB;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,aAAa,EAAE,GACf;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,CAAC;AAErC;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,sEAAsE;IACtE,IAAI,EAAE,EAAE,CAAC,SAAS,GAAG,SAAS,CAAC;CAChC;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,SAAK,GAAG,cAAc,EAAE,CAGtF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,SAAK,GAAG,cAAc,EAAE,CAGtF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,EAAE,CAAC,UAAU,GAAG,SAAS,EACtC,IAAI,SAAK,GACR,cAAc,GAAG,IAAI,CAwCvB;AAMD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,cAAc,EAAE,CA8CvE;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,cAAc,GAAG,IAAI,CAgC9E"}
1
+ {"version":3,"file":"jsdoc-constraints.d.ts","sourceRoot":"","sources":["../../src/analyzer/jsdoc-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAa,MAAM,gBAAgB,CAAC;AAOhF;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,SAAK,GAAG,cAAc,EAAE,CAGtF;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,SAAK,GAAG,cAAc,EAAE,CAGtF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,EAAE,CAAC,UAAU,GAAG,SAAS,EACtC,IAAI,SAAK,GACR,cAAc,GAAG,IAAI,CAwCvB"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Shared JSON parsing utilities for the analyzer pipeline.
3
+ */
4
+ /**
5
+ * Attempts to parse `text` as JSON.
6
+ *
7
+ * Returns the parsed value on success, or `null` if the input is not valid
8
+ * JSON. This is the canonical "try-parse" wrapper used by the constraint tag
9
+ * parsers so that every `JSON.parse` call in this package is consistent and
10
+ * centrally tested.
11
+ *
12
+ * Note: when the input is the literal string `"null"`, the return value is
13
+ * also `null` (valid JSON). This helper therefore cannot distinguish parse
14
+ * failure from a successfully-parsed JSON `null`. Callers that need to
15
+ * distinguish these cases should use a different API (for example, a wrapper
16
+ * that returns a discriminated result such as `{ ok: boolean, value?: unknown }`).
17
+ *
18
+ * @param text - Raw string to parse
19
+ * @returns The parsed value, or `null` on parse failure
20
+ */
21
+ export declare function tryParseJson(text: string): unknown;
22
+ //# sourceMappingURL=json-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-utils.d.ts","sourceRoot":"","sources":["../../src/analyzer/json-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMlD"}
@@ -8,14 +8,15 @@
8
8
  * The parser recognises two categories of tags:
9
9
  *
10
10
  * 1. **Constraint tags** (all alphanumeric, TSDoc-compliant):
11
- * `@Minimum`, `@Maximum`, `@ExclusiveMinimum`, `@ExclusiveMaximum`,
12
- * `@MinLength`, `@MaxLength`, `@Pattern`, `@EnumOptions`
11
+ * `@minimum`, `@maximum`, `@exclusiveMinimum`, `@exclusiveMaximum`,
12
+ * `@multipleOf`, `@minLength`, `@maxLength`, `@minItems`, `@maxItems`,
13
+ * `@pattern`, `@enumOptions`
13
14
  * — Parsed via TSDocParser as custom block tags.
15
+ * Both camelCase and PascalCase forms are accepted (e.g., `@Minimum`).
14
16
  *
15
- * 2. **Annotation tags** (`@Field_displayName`, `@Field_description`):
16
- * These contain underscores which are not valid in TSDoc tag names.
17
- * They are extracted via the TypeScript compiler's `ts.getJSDocTags()`
18
- * until a future migration to underscore-free tag names.
17
+ * 2. **Annotation tags** (`@displayName`, `@description`):
18
+ * These are parsed as structured custom block tags and mapped directly
19
+ * onto annotation IR nodes.
19
20
  *
20
21
  * The `@deprecated` tag is a standard TSDoc block tag, parsed structurally.
21
22
  *
@@ -27,14 +28,14 @@
27
28
  * verbatim.
28
29
  */
29
30
  import * as ts from "typescript";
30
- import { type ConstraintNode, type AnnotationNode } from "@formspec/core";
31
+ import { type ConstraintNode, type AnnotationNode, type PathTarget } from "@formspec/core";
31
32
  /**
32
33
  * Result of parsing a single JSDoc comment attached to a TS AST node.
33
34
  */
34
35
  export interface TSDocParseResult {
35
36
  /** Constraint IR nodes extracted from custom block tags. */
36
37
  readonly constraints: readonly ConstraintNode[];
37
- /** Annotation IR nodes extracted from modifier/block tags and TS JSDoc API. */
38
+ /** Annotation IR nodes extracted from canonical TSDoc block tags. */
38
39
  readonly annotations: readonly AnnotationNode[];
39
40
  }
40
41
  /**
@@ -42,10 +43,9 @@ export interface TSDocParseResult {
42
43
  * official TSDoc parser and returns canonical IR constraint and annotation
43
44
  * nodes.
44
45
  *
45
- * For constraint tags (`@Minimum`, `@Pattern`, `@EnumOptions`, etc.),
46
- * the structured TSDoc parser is used. For annotation tags that contain
47
- * underscores (`@Field_displayName`, `@Field_description`), the TypeScript
48
- * compiler JSDoc API is used as a fallback.
46
+ * For constraint tags (`@minimum`, `@pattern`, `@enumOptions`, etc.),
47
+ * the structured TSDoc parser is used. Canonical annotation tags
48
+ * (`@displayName`, `@description`) are also parsed structurally.
49
49
  *
50
50
  * @param node - The TS AST node to inspect (PropertyDeclaration, PropertySignature, etc.)
51
51
  * @param file - Absolute source file path for provenance
@@ -58,4 +58,16 @@ export declare function parseTSDocTags(node: ts.Node, file?: string): TSDocParse
58
58
  * Falls back to the TS compiler API for nodes without doc comments.
59
59
  */
60
60
  export declare function hasDeprecatedTagTSDoc(node: ts.Node): boolean;
61
+ /**
62
+ * Extracts a path-target prefix (`:fieldName`) from constraint tag text.
63
+ * Returns the parsed PathTarget and remaining text, or null if no path target.
64
+ *
65
+ * @example
66
+ * extractPathTarget(":value 0") // → { path: { segments: ["value"] }, remainingText: "0" }
67
+ * extractPathTarget("42") // → null
68
+ */
69
+ export declare function extractPathTarget(text: string): {
70
+ path: PathTarget;
71
+ remainingText: string;
72
+ } | null;
61
73
  //# sourceMappingURL=tsdoc-parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tsdoc-parser.d.ts","sourceRoot":"","sources":["../../src/analyzer/tsdoc-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAYjC,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,cAAc,EAIpB,MAAM,gBAAgB,CAAC;AA8ExB;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;CACjD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,SAAK,GAAG,gBAAgB,CAuHzE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAsB5D"}
1
+ {"version":3,"file":"tsdoc-parser.d.ts","sourceRoot":"","sources":["../../src/analyzer/tsdoc-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAYjC,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,cAAc,EAInB,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AAwFxB;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD,qEAAqE;IACrE,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;CACjD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,SAAK,GAAG,gBAAgB,CAkGzE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAsB5D;AAMD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQpD"}