@formspec/build 0.1.0-alpha.51 → 0.1.0-alpha.53
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/builtin-brands.d.ts +13 -0
- package/dist/analyzer/builtin-brands.d.ts.map +1 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +17 -0
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +8 -2
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +19 -0
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +21 -0
- package/dist/build-beta.d.ts +21 -0
- package/dist/build-internal.d.ts +21 -0
- package/dist/build.d.ts +21 -0
- package/dist/cli/logger.d.ts +22 -0
- package/dist/cli/logger.d.ts.map +1 -0
- package/dist/cli.cjs +326 -214
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +314 -205
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +274 -205
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +277 -205
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +219 -172
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +220 -172
- package/dist/internals.js.map +1 -1
- package/dist/json-schema/generator.d.ts +6 -1
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/generator.d.ts +6 -1
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/package.json +11 -5
package/dist/cli.cjs
CHANGED
|
@@ -1742,19 +1742,25 @@ var init_ir_generator = __esm({
|
|
|
1742
1742
|
|
|
1743
1743
|
// src/json-schema/generator.ts
|
|
1744
1744
|
function generateJsonSchema(form, options) {
|
|
1745
|
+
const logger = (options?.logger ?? import_core2.noopLogger).child({ stage: "ir" });
|
|
1745
1746
|
const metadata = options?.metadata;
|
|
1746
1747
|
const vendorPrefix = options?.vendorPrefix;
|
|
1747
1748
|
const enumSerialization = options?.enumSerialization;
|
|
1749
|
+
logger.debug("canonicalizing chain DSL to IR");
|
|
1748
1750
|
const ir = canonicalizeChainDSL(form, metadata !== void 0 ? { metadata } : void 0);
|
|
1751
|
+
const schemaLogger = (options?.logger ?? import_core2.noopLogger).child({ stage: "schema" });
|
|
1752
|
+
schemaLogger.debug("generating JSON Schema from IR");
|
|
1749
1753
|
const internalOptions = vendorPrefix === void 0 && enumSerialization === void 0 ? void 0 : {
|
|
1750
1754
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
1751
1755
|
...enumSerialization !== void 0 && { enumSerialization }
|
|
1752
1756
|
};
|
|
1753
1757
|
return generateJsonSchemaFromIR(ir, internalOptions);
|
|
1754
1758
|
}
|
|
1759
|
+
var import_core2;
|
|
1755
1760
|
var init_generator = __esm({
|
|
1756
1761
|
"src/json-schema/generator.ts"() {
|
|
1757
1762
|
"use strict";
|
|
1763
|
+
import_core2 = require("@formspec/core");
|
|
1758
1764
|
init_canonicalize();
|
|
1759
1765
|
init_ir_generator();
|
|
1760
1766
|
}
|
|
@@ -2034,15 +2040,21 @@ var init_ir_generator2 = __esm({
|
|
|
2034
2040
|
|
|
2035
2041
|
// src/ui-schema/generator.ts
|
|
2036
2042
|
function generateUiSchema(form, options) {
|
|
2043
|
+
const logger = (options?.logger ?? import_core3.noopLogger).child({ stage: "ir" });
|
|
2044
|
+
logger.debug("canonicalizing chain DSL to IR for UI Schema generation");
|
|
2037
2045
|
const ir = canonicalizeChainDSL(
|
|
2038
2046
|
form,
|
|
2039
2047
|
options?.metadata !== void 0 ? { metadata: options.metadata } : void 0
|
|
2040
2048
|
);
|
|
2049
|
+
const schemaLogger = (options?.logger ?? import_core3.noopLogger).child({ stage: "schema" });
|
|
2050
|
+
schemaLogger.debug("generating UI Schema from IR");
|
|
2041
2051
|
return generateUiSchemaFromIR(ir);
|
|
2042
2052
|
}
|
|
2053
|
+
var import_core3;
|
|
2043
2054
|
var init_generator2 = __esm({
|
|
2044
2055
|
"src/ui-schema/generator.ts"() {
|
|
2045
2056
|
"use strict";
|
|
2057
|
+
import_core3 = require("@formspec/core");
|
|
2046
2058
|
init_canonicalize();
|
|
2047
2059
|
init_ir_generator2();
|
|
2048
2060
|
}
|
|
@@ -2420,6 +2432,21 @@ var init_resolve_custom_type = __esm({
|
|
|
2420
2432
|
}
|
|
2421
2433
|
});
|
|
2422
2434
|
|
|
2435
|
+
// src/analyzer/builtin-brands.ts
|
|
2436
|
+
function isIntegerBrandedType(type) {
|
|
2437
|
+
if (!type.isIntersection()) return false;
|
|
2438
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2439
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2440
|
+
}
|
|
2441
|
+
var ts3;
|
|
2442
|
+
var init_builtin_brands = __esm({
|
|
2443
|
+
"src/analyzer/builtin-brands.ts"() {
|
|
2444
|
+
"use strict";
|
|
2445
|
+
ts3 = __toESM(require("typescript"), 1);
|
|
2446
|
+
init_ts_type_utils();
|
|
2447
|
+
}
|
|
2448
|
+
});
|
|
2449
|
+
|
|
2423
2450
|
// src/analyzer/tsdoc-parser.ts
|
|
2424
2451
|
function sharedTagValueOptions(options) {
|
|
2425
2452
|
return {
|
|
@@ -2440,23 +2467,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2440
2467
|
function collectImportedNames(sourceFile) {
|
|
2441
2468
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2442
2469
|
for (const statement of sourceFile.statements) {
|
|
2443
|
-
if (
|
|
2470
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2444
2471
|
const clause = statement.importClause;
|
|
2445
2472
|
if (clause.name !== void 0) {
|
|
2446
2473
|
importedNames.add(clause.name.text);
|
|
2447
2474
|
}
|
|
2448
2475
|
if (clause.namedBindings !== void 0) {
|
|
2449
|
-
if (
|
|
2476
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2450
2477
|
for (const specifier of clause.namedBindings.elements) {
|
|
2451
2478
|
importedNames.add(specifier.name.text);
|
|
2452
2479
|
}
|
|
2453
|
-
} else if (
|
|
2480
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2454
2481
|
importedNames.add(clause.namedBindings.name.text);
|
|
2455
2482
|
}
|
|
2456
2483
|
}
|
|
2457
2484
|
continue;
|
|
2458
2485
|
}
|
|
2459
|
-
if (
|
|
2486
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2460
2487
|
importedNames.add(statement.name.text);
|
|
2461
2488
|
}
|
|
2462
2489
|
}
|
|
@@ -2464,50 +2491,96 @@ function collectImportedNames(sourceFile) {
|
|
|
2464
2491
|
}
|
|
2465
2492
|
function isNonReferenceIdentifier(node) {
|
|
2466
2493
|
const parent = node.parent;
|
|
2467
|
-
if ((
|
|
2494
|
+
if ((ts4.isBindingElement(parent) || ts4.isClassDeclaration(parent) || ts4.isEnumDeclaration(parent) || ts4.isEnumMember(parent) || ts4.isFunctionDeclaration(parent) || ts4.isFunctionExpression(parent) || ts4.isImportClause(parent) || ts4.isImportEqualsDeclaration(parent) || ts4.isImportSpecifier(parent) || ts4.isInterfaceDeclaration(parent) || ts4.isMethodDeclaration(parent) || ts4.isMethodSignature(parent) || ts4.isModuleDeclaration(parent) || ts4.isNamespaceExport(parent) || ts4.isNamespaceImport(parent) || ts4.isParameter(parent) || ts4.isPropertyDeclaration(parent) || ts4.isPropertySignature(parent) || ts4.isSetAccessorDeclaration(parent) || ts4.isGetAccessorDeclaration(parent) || ts4.isTypeAliasDeclaration(parent) || ts4.isTypeParameterDeclaration(parent) || ts4.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2468
2495
|
return true;
|
|
2469
2496
|
}
|
|
2470
|
-
if ((
|
|
2497
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2471
2498
|
return true;
|
|
2472
2499
|
}
|
|
2473
|
-
if (
|
|
2500
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2474
2501
|
return true;
|
|
2475
2502
|
}
|
|
2476
2503
|
return false;
|
|
2477
2504
|
}
|
|
2478
|
-
function
|
|
2505
|
+
function astReferencesImportedName(root, importedNames) {
|
|
2479
2506
|
if (importedNames.size === 0) {
|
|
2480
2507
|
return false;
|
|
2481
2508
|
}
|
|
2482
|
-
let
|
|
2509
|
+
let found = false;
|
|
2483
2510
|
const visit = (node) => {
|
|
2484
|
-
if (
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2488
|
-
referencesImportedName = true;
|
|
2511
|
+
if (found) return;
|
|
2512
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2513
|
+
found = true;
|
|
2489
2514
|
return;
|
|
2490
2515
|
}
|
|
2491
|
-
|
|
2516
|
+
ts4.forEachChild(node, visit);
|
|
2492
2517
|
};
|
|
2493
|
-
visit(
|
|
2494
|
-
return
|
|
2518
|
+
visit(root);
|
|
2519
|
+
return found;
|
|
2520
|
+
}
|
|
2521
|
+
function getObjectMembers(statement) {
|
|
2522
|
+
if (ts4.isInterfaceDeclaration(statement)) {
|
|
2523
|
+
return statement.members;
|
|
2524
|
+
}
|
|
2525
|
+
if (ts4.isTypeLiteralNode(statement.type)) {
|
|
2526
|
+
return statement.type.members;
|
|
2527
|
+
}
|
|
2528
|
+
return void 0;
|
|
2529
|
+
}
|
|
2530
|
+
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
2531
|
+
const members = getObjectMembers(statement);
|
|
2532
|
+
if (members === void 0) {
|
|
2533
|
+
return null;
|
|
2534
|
+
}
|
|
2535
|
+
const replacements = [];
|
|
2536
|
+
for (const member of members) {
|
|
2537
|
+
if (!ts4.isPropertySignature(member)) {
|
|
2538
|
+
if (astReferencesImportedName(member, importedNames)) {
|
|
2539
|
+
return null;
|
|
2540
|
+
}
|
|
2541
|
+
continue;
|
|
2542
|
+
}
|
|
2543
|
+
const typeAnnotation = member.type;
|
|
2544
|
+
if (typeAnnotation === void 0) continue;
|
|
2545
|
+
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
2546
|
+
replacements.push({
|
|
2547
|
+
start: typeAnnotation.getStart(sourceFile),
|
|
2548
|
+
end: typeAnnotation.getEnd()
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
if (replacements.length === 0) {
|
|
2553
|
+
return statement.getText(sourceFile);
|
|
2554
|
+
}
|
|
2555
|
+
const stmtStart = statement.getStart(sourceFile);
|
|
2556
|
+
let result = statement.getText(sourceFile);
|
|
2557
|
+
for (const { start, end } of [...replacements].reverse()) {
|
|
2558
|
+
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
2559
|
+
}
|
|
2560
|
+
return result;
|
|
2495
2561
|
}
|
|
2496
2562
|
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2497
2563
|
const importedNames = collectImportedNames(sourceFile);
|
|
2498
2564
|
const importedNamesToSkip = new Set(
|
|
2499
2565
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2500
2566
|
);
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
if (
|
|
2504
|
-
if (
|
|
2505
|
-
|
|
2506
|
-
if (
|
|
2507
|
-
|
|
2567
|
+
const result = [];
|
|
2568
|
+
for (const statement of sourceFile.statements) {
|
|
2569
|
+
if (ts4.isImportDeclaration(statement)) continue;
|
|
2570
|
+
if (ts4.isImportEqualsDeclaration(statement)) continue;
|
|
2571
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2572
|
+
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2573
|
+
result.push(statement.getText(sourceFile));
|
|
2574
|
+
continue;
|
|
2508
2575
|
}
|
|
2509
|
-
|
|
2510
|
-
|
|
2576
|
+
if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
|
|
2577
|
+
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2578
|
+
if (rewritten !== null) {
|
|
2579
|
+
result.push(rewritten);
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
return result;
|
|
2511
2584
|
}
|
|
2512
2585
|
function pushUniqueCompilerDiagnostics(target, additions) {
|
|
2513
2586
|
for (const diagnostic of additions) {
|
|
@@ -2597,7 +2670,7 @@ function stripHintNullishUnion(type) {
|
|
|
2597
2670
|
return type;
|
|
2598
2671
|
}
|
|
2599
2672
|
const nonNullish = type.types.filter(
|
|
2600
|
-
(member) => (member.flags & (
|
|
2673
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
2601
2674
|
);
|
|
2602
2675
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2603
2676
|
return nonNullish[0];
|
|
@@ -2613,10 +2686,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2613
2686
|
}
|
|
2614
2687
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2615
2688
|
const name = declaration.name;
|
|
2616
|
-
if (
|
|
2689
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
2617
2690
|
return false;
|
|
2618
2691
|
}
|
|
2619
|
-
if (!
|
|
2692
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
2620
2693
|
return false;
|
|
2621
2694
|
}
|
|
2622
2695
|
}
|
|
@@ -2834,6 +2907,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2834
2907
|
}
|
|
2835
2908
|
const hasBroadening = (() => {
|
|
2836
2909
|
if (target === null) {
|
|
2910
|
+
if (isIntegerBrandedType((0, import_internal3.stripNullishUnion)(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2911
|
+
return true;
|
|
2912
|
+
}
|
|
2837
2913
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2838
2914
|
}
|
|
2839
2915
|
const registry = options?.extensionRegistry;
|
|
@@ -2985,12 +3061,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2985
3061
|
const sourceText = sourceFile.getFullText();
|
|
2986
3062
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2987
3063
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2988
|
-
const commentRanges =
|
|
3064
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2989
3065
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2990
3066
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2991
3067
|
if (commentRanges) {
|
|
2992
3068
|
for (const range of commentRanges) {
|
|
2993
|
-
if (range.kind !==
|
|
3069
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
2994
3070
|
continue;
|
|
2995
3071
|
}
|
|
2996
3072
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3147,10 +3223,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3147
3223
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3148
3224
|
const sourceFile = node.getSourceFile();
|
|
3149
3225
|
const sourceText = sourceFile.getFullText();
|
|
3150
|
-
const commentRanges =
|
|
3226
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3151
3227
|
if (commentRanges) {
|
|
3152
3228
|
for (const range of commentRanges) {
|
|
3153
|
-
if (range.kind !==
|
|
3229
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3154
3230
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3155
3231
|
if (!commentText.startsWith("/**")) continue;
|
|
3156
3232
|
const unified = (0, import_internal3.parseUnifiedComment)(commentText);
|
|
@@ -3175,7 +3251,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3175
3251
|
}
|
|
3176
3252
|
function collectRawTextFallbacks(node, file) {
|
|
3177
3253
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3178
|
-
for (const tag of
|
|
3254
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
3179
3255
|
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
3180
3256
|
if (!import_internal3.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3181
3257
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3230,18 +3306,19 @@ function getTagCommentText(tag) {
|
|
|
3230
3306
|
if (typeof tag.comment === "string") {
|
|
3231
3307
|
return tag.comment;
|
|
3232
3308
|
}
|
|
3233
|
-
return
|
|
3309
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
3234
3310
|
}
|
|
3235
|
-
var
|
|
3311
|
+
var ts4, import_internal3, import_internals4, import_internals5, SYNTHETIC_TYPE_FORMAT_FLAGS, MAX_HINT_CANDIDATES, MAX_HINT_DEPTH, parseResultCache;
|
|
3236
3312
|
var init_tsdoc_parser = __esm({
|
|
3237
3313
|
"src/analyzer/tsdoc-parser.ts"() {
|
|
3238
3314
|
"use strict";
|
|
3239
|
-
|
|
3315
|
+
ts4 = __toESM(require("typescript"), 1);
|
|
3240
3316
|
import_internal3 = require("@formspec/analysis/internal");
|
|
3241
3317
|
import_internals4 = require("@formspec/core/internals");
|
|
3242
3318
|
import_internals5 = require("@formspec/core/internals");
|
|
3243
3319
|
init_resolve_custom_type();
|
|
3244
|
-
|
|
3320
|
+
init_builtin_brands();
|
|
3321
|
+
SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
3245
3322
|
MAX_HINT_CANDIDATES = 5;
|
|
3246
3323
|
MAX_HINT_DEPTH = 3;
|
|
3247
3324
|
parseResultCache = /* @__PURE__ */ new Map();
|
|
@@ -3263,18 +3340,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3263
3340
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3264
3341
|
if (!initializer) return null;
|
|
3265
3342
|
let value;
|
|
3266
|
-
if (
|
|
3343
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
3267
3344
|
value = initializer.text;
|
|
3268
|
-
} else if (
|
|
3345
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
3269
3346
|
value = Number(initializer.text);
|
|
3270
|
-
} else if (initializer.kind ===
|
|
3347
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
3271
3348
|
value = true;
|
|
3272
|
-
} else if (initializer.kind ===
|
|
3349
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
3273
3350
|
value = false;
|
|
3274
|
-
} else if (initializer.kind ===
|
|
3351
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
3275
3352
|
value = null;
|
|
3276
|
-
} else if (
|
|
3277
|
-
if (initializer.operator ===
|
|
3353
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
3354
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
3278
3355
|
value = -Number(initializer.operand.text);
|
|
3279
3356
|
}
|
|
3280
3357
|
}
|
|
@@ -3293,49 +3370,39 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3293
3370
|
}
|
|
3294
3371
|
};
|
|
3295
3372
|
}
|
|
3296
|
-
var
|
|
3373
|
+
var ts5;
|
|
3297
3374
|
var init_jsdoc_constraints = __esm({
|
|
3298
3375
|
"src/analyzer/jsdoc-constraints.ts"() {
|
|
3299
3376
|
"use strict";
|
|
3300
|
-
|
|
3377
|
+
ts5 = __toESM(require("typescript"), 1);
|
|
3301
3378
|
init_tsdoc_parser();
|
|
3302
3379
|
}
|
|
3303
3380
|
});
|
|
3304
3381
|
|
|
3305
3382
|
// src/analyzer/class-analyzer.ts
|
|
3306
3383
|
function isObjectType(type) {
|
|
3307
|
-
return !!(type.flags &
|
|
3384
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
3308
3385
|
}
|
|
3309
3386
|
function isIntersectionType(type) {
|
|
3310
|
-
return !!(type.flags &
|
|
3311
|
-
}
|
|
3312
|
-
function isIntegerBrandedType(type) {
|
|
3313
|
-
if (!type.isIntersection()) {
|
|
3314
|
-
return false;
|
|
3315
|
-
}
|
|
3316
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3317
|
-
if (!hasNumberBase) {
|
|
3318
|
-
return false;
|
|
3319
|
-
}
|
|
3320
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3387
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
3321
3388
|
}
|
|
3322
3389
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3323
|
-
if (
|
|
3390
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3324
3391
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3325
3392
|
}
|
|
3326
|
-
if (
|
|
3393
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
3327
3394
|
return true;
|
|
3328
3395
|
}
|
|
3329
|
-
return
|
|
3396
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3330
3397
|
}
|
|
3331
3398
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3332
3399
|
if (isIntersectionType(type)) {
|
|
3333
3400
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3334
3401
|
}
|
|
3335
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3402
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts6.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts6.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
3336
3403
|
}
|
|
3337
3404
|
function isTypeReference(type) {
|
|
3338
|
-
return !!(type.flags &
|
|
3405
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
3339
3406
|
}
|
|
3340
3407
|
function makeParseOptions(extensionRegistry, fieldType, checker, subjectType, hostType) {
|
|
3341
3408
|
if (extensionRegistry === void 0 && fieldType === void 0 && checker === void 0 && subjectType === void 0 && hostType === void 0) {
|
|
@@ -3395,7 +3462,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3395
3462
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3396
3463
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3397
3464
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3398
|
-
const logicalName =
|
|
3465
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3399
3466
|
const docResult = extractJSDocParseResult(
|
|
3400
3467
|
declaration,
|
|
3401
3468
|
file,
|
|
@@ -3443,7 +3510,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3443
3510
|
const instanceMethods = [];
|
|
3444
3511
|
const staticMethods = [];
|
|
3445
3512
|
for (const member of classDecl.members) {
|
|
3446
|
-
if (
|
|
3513
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
3447
3514
|
const fieldNode = analyzeFieldToIR(
|
|
3448
3515
|
member,
|
|
3449
3516
|
checker,
|
|
@@ -3459,10 +3526,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3459
3526
|
fields.push(fieldNode);
|
|
3460
3527
|
fieldLayouts.push({});
|
|
3461
3528
|
}
|
|
3462
|
-
} else if (
|
|
3529
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
3463
3530
|
const methodInfo = analyzeMethod(member, checker);
|
|
3464
3531
|
if (methodInfo) {
|
|
3465
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3532
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
3466
3533
|
if (isStatic) {
|
|
3467
3534
|
staticMethods.push(methodInfo);
|
|
3468
3535
|
} else {
|
|
@@ -3525,7 +3592,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3525
3592
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3526
3593
|
const visiting = /* @__PURE__ */ new Set();
|
|
3527
3594
|
for (const member of interfaceDecl.members) {
|
|
3528
|
-
if (
|
|
3595
|
+
if (ts6.isPropertySignature(member)) {
|
|
3529
3596
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3530
3597
|
member,
|
|
3531
3598
|
checker,
|
|
@@ -3583,7 +3650,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3583
3650
|
if (members === null) {
|
|
3584
3651
|
const sourceFile = typeAlias.getSourceFile();
|
|
3585
3652
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3586
|
-
const kindDesc =
|
|
3653
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3587
3654
|
return {
|
|
3588
3655
|
ok: false,
|
|
3589
3656
|
kind: "not-object-like",
|
|
@@ -3618,7 +3685,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3618
3685
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3619
3686
|
const visiting = /* @__PURE__ */ new Set();
|
|
3620
3687
|
for (const member of members) {
|
|
3621
|
-
if (
|
|
3688
|
+
if (ts6.isPropertySignature(member)) {
|
|
3622
3689
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3623
3690
|
member,
|
|
3624
3691
|
checker,
|
|
@@ -3685,13 +3752,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3685
3752
|
function getLeadingParsedTags(node) {
|
|
3686
3753
|
const sourceFile = node.getSourceFile();
|
|
3687
3754
|
const sourceText = sourceFile.getFullText();
|
|
3688
|
-
const commentRanges =
|
|
3755
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3689
3756
|
if (commentRanges === void 0) {
|
|
3690
3757
|
return [];
|
|
3691
3758
|
}
|
|
3692
3759
|
const parsedTags = [];
|
|
3693
3760
|
for (const range of commentRanges) {
|
|
3694
|
-
if (range.kind !==
|
|
3761
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
3695
3762
|
continue;
|
|
3696
3763
|
}
|
|
3697
3764
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3709,19 +3776,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3709
3776
|
return null;
|
|
3710
3777
|
}
|
|
3711
3778
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3712
|
-
(candidate) =>
|
|
3779
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
3713
3780
|
) ?? propertySymbol.declarations?.[0];
|
|
3714
3781
|
return {
|
|
3715
3782
|
declaration,
|
|
3716
3783
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3717
|
-
optional: !!(propertySymbol.flags &
|
|
3784
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3718
3785
|
};
|
|
3719
3786
|
}
|
|
3720
3787
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3721
3788
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3722
3789
|
}
|
|
3723
3790
|
function isNullishSemanticType(type) {
|
|
3724
|
-
if (type.flags & (
|
|
3791
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
3725
3792
|
return true;
|
|
3726
3793
|
}
|
|
3727
3794
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3731,7 +3798,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3731
3798
|
return false;
|
|
3732
3799
|
}
|
|
3733
3800
|
seen.add(type);
|
|
3734
|
-
if (type.flags &
|
|
3801
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
3735
3802
|
return true;
|
|
3736
3803
|
}
|
|
3737
3804
|
if (type.isUnion()) {
|
|
@@ -3744,13 +3811,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3744
3811
|
return false;
|
|
3745
3812
|
}
|
|
3746
3813
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3747
|
-
if (
|
|
3814
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3748
3815
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3749
3816
|
}
|
|
3750
|
-
if (
|
|
3817
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
3751
3818
|
return [...typeNode.members];
|
|
3752
3819
|
}
|
|
3753
|
-
if (
|
|
3820
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
3754
3821
|
const members = [];
|
|
3755
3822
|
for (const intersectionMember of typeNode.types) {
|
|
3756
3823
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3913,7 +3980,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3913
3980
|
}
|
|
3914
3981
|
if (propertyType.isUnion()) {
|
|
3915
3982
|
const nonNullMembers = propertyType.types.filter(
|
|
3916
|
-
(member) => !(member.flags & (
|
|
3983
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3917
3984
|
);
|
|
3918
3985
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3919
3986
|
diagnostics.push(
|
|
@@ -3962,13 +4029,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3962
4029
|
seen.add(type);
|
|
3963
4030
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3964
4031
|
if (symbol !== void 0) {
|
|
3965
|
-
const aliased = symbol.flags &
|
|
4032
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3966
4033
|
const targetSymbol = aliased ?? symbol;
|
|
3967
4034
|
const declaration = targetSymbol.declarations?.find(
|
|
3968
|
-
(candidate) =>
|
|
4035
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
3969
4036
|
);
|
|
3970
4037
|
if (declaration !== void 0) {
|
|
3971
|
-
if (
|
|
4038
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3972
4039
|
return resolveNamedDiscriminatorDeclaration(
|
|
3973
4040
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3974
4041
|
checker,
|
|
@@ -3996,7 +4063,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3996
4063
|
}
|
|
3997
4064
|
if (boundType.isUnion()) {
|
|
3998
4065
|
const nonNullMembers = boundType.types.filter(
|
|
3999
|
-
(member) => !(member.flags & (
|
|
4066
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4000
4067
|
);
|
|
4001
4068
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4002
4069
|
diagnostics.push(
|
|
@@ -4041,7 +4108,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4041
4108
|
return null;
|
|
4042
4109
|
}
|
|
4043
4110
|
function getDeclarationName(node) {
|
|
4044
|
-
if (
|
|
4111
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
4045
4112
|
return node.name?.text ?? "anonymous";
|
|
4046
4113
|
}
|
|
4047
4114
|
return "anonymous";
|
|
@@ -4096,11 +4163,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4096
4163
|
if (sourceTypeNode === void 0) {
|
|
4097
4164
|
return [];
|
|
4098
4165
|
}
|
|
4099
|
-
const unwrapParentheses = (typeNode) =>
|
|
4166
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4100
4167
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4101
|
-
const referenceTypeNode =
|
|
4168
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4102
4169
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4103
|
-
return
|
|
4170
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4104
4171
|
})();
|
|
4105
4172
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4106
4173
|
return [];
|
|
@@ -4155,7 +4222,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4155
4222
|
);
|
|
4156
4223
|
}
|
|
4157
4224
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4158
|
-
if (!
|
|
4225
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
4159
4226
|
return null;
|
|
4160
4227
|
}
|
|
4161
4228
|
const name = prop.name.text;
|
|
@@ -4282,7 +4349,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4282
4349
|
const seen = /* @__PURE__ */ new Set();
|
|
4283
4350
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4284
4351
|
for (const member of members) {
|
|
4285
|
-
if (!
|
|
4352
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4286
4353
|
continue;
|
|
4287
4354
|
}
|
|
4288
4355
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4298,7 +4365,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4298
4365
|
return [...duplicates].sort();
|
|
4299
4366
|
}
|
|
4300
4367
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4301
|
-
if (
|
|
4368
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
4302
4369
|
return name.text;
|
|
4303
4370
|
}
|
|
4304
4371
|
return null;
|
|
@@ -4396,25 +4463,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4396
4463
|
if (isIntegerBrandedType(type)) {
|
|
4397
4464
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4398
4465
|
}
|
|
4399
|
-
if (type.flags &
|
|
4466
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4400
4467
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4401
4468
|
}
|
|
4402
|
-
if (type.flags &
|
|
4469
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4403
4470
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4404
4471
|
}
|
|
4405
|
-
if (type.flags & (
|
|
4472
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4406
4473
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4407
4474
|
}
|
|
4408
|
-
if (type.flags &
|
|
4475
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4409
4476
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4410
4477
|
}
|
|
4411
|
-
if (type.flags &
|
|
4478
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4412
4479
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4413
4480
|
}
|
|
4414
|
-
if (type.flags &
|
|
4481
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
4415
4482
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4416
4483
|
}
|
|
4417
|
-
if (type.flags &
|
|
4484
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
4418
4485
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4419
4486
|
}
|
|
4420
4487
|
if (type.isStringLiteral()) {
|
|
@@ -4501,10 +4568,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4501
4568
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4502
4569
|
}
|
|
4503
4570
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4504
|
-
if (!(type.flags & (
|
|
4571
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4505
4572
|
return null;
|
|
4506
4573
|
}
|
|
4507
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4574
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4508
4575
|
if (!aliasDecl) {
|
|
4509
4576
|
return null;
|
|
4510
4577
|
}
|
|
@@ -4554,14 +4621,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4554
4621
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4555
4622
|
}
|
|
4556
4623
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4557
|
-
const typeNode = sourceNode && (
|
|
4558
|
-
if (!typeNode || !
|
|
4624
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4625
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
4559
4626
|
return void 0;
|
|
4560
4627
|
}
|
|
4561
4628
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4562
4629
|
}
|
|
4563
4630
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4564
|
-
if (!
|
|
4631
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
4565
4632
|
return false;
|
|
4566
4633
|
}
|
|
4567
4634
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4569,10 +4636,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4569
4636
|
return false;
|
|
4570
4637
|
}
|
|
4571
4638
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4572
|
-
return !!(resolved.flags & (
|
|
4639
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
4573
4640
|
}
|
|
4574
4641
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4575
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4642
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
4576
4643
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4577
4644
|
visitedAliases.add(nestedAliasDecl);
|
|
4578
4645
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4590,19 +4657,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4590
4657
|
if (isIntegerBrandedType(type)) {
|
|
4591
4658
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4592
4659
|
}
|
|
4593
|
-
if (type.flags &
|
|
4660
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4594
4661
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4595
4662
|
}
|
|
4596
|
-
if (type.flags &
|
|
4663
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4597
4664
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4598
4665
|
}
|
|
4599
|
-
if (type.flags & (
|
|
4666
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4600
4667
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4601
4668
|
}
|
|
4602
|
-
if (type.flags &
|
|
4669
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4603
4670
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4604
4671
|
}
|
|
4605
|
-
if (type.flags &
|
|
4672
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4606
4673
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4607
4674
|
}
|
|
4608
4675
|
return resolveTypeNode(
|
|
@@ -4629,13 +4696,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4629
4696
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4630
4697
|
);
|
|
4631
4698
|
const nonNullTypes = allTypes.filter(
|
|
4632
|
-
(memberType) => !(memberType.flags & (
|
|
4699
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4633
4700
|
);
|
|
4634
4701
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4635
4702
|
memberType,
|
|
4636
4703
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4637
4704
|
}));
|
|
4638
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4705
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
4639
4706
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4640
4707
|
if (namedDecl) {
|
|
4641
4708
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4678,7 +4745,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4678
4745
|
const displayName = memberDisplayNames.get(String(value));
|
|
4679
4746
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4680
4747
|
});
|
|
4681
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4748
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
4682
4749
|
if (isBooleanUnion2) {
|
|
4683
4750
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4684
4751
|
const result = hasNull ? {
|
|
@@ -4770,7 +4837,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4770
4837
|
if (type.getProperties().length > 0) {
|
|
4771
4838
|
return null;
|
|
4772
4839
|
}
|
|
4773
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4840
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
4774
4841
|
if (!indexInfo) {
|
|
4775
4842
|
return null;
|
|
4776
4843
|
}
|
|
@@ -4818,10 +4885,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4818
4885
|
}
|
|
4819
4886
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4820
4887
|
const name = declaration.name;
|
|
4821
|
-
if (
|
|
4888
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
4822
4889
|
return false;
|
|
4823
4890
|
}
|
|
4824
|
-
if (!
|
|
4891
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
4825
4892
|
return false;
|
|
4826
4893
|
}
|
|
4827
4894
|
}
|
|
@@ -4947,7 +5014,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4947
5014
|
if (!declaration) continue;
|
|
4948
5015
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4949
5016
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4950
|
-
const optional = !!(prop.flags &
|
|
5017
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
4951
5018
|
const propTypeNode = resolveTypeNode(
|
|
4952
5019
|
propType,
|
|
4953
5020
|
checker,
|
|
@@ -4960,7 +5027,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4960
5027
|
collectedDiagnostics
|
|
4961
5028
|
);
|
|
4962
5029
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4963
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
5030
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4964
5031
|
declaration,
|
|
4965
5032
|
checker,
|
|
4966
5033
|
file,
|
|
@@ -4970,7 +5037,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4970
5037
|
type,
|
|
4971
5038
|
metadataPolicy,
|
|
4972
5039
|
extensionRegistry
|
|
4973
|
-
) :
|
|
5040
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4974
5041
|
declaration,
|
|
4975
5042
|
checker,
|
|
4976
5043
|
file,
|
|
@@ -4998,7 +5065,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4998
5065
|
visiting.delete(type);
|
|
4999
5066
|
const objectNode = {
|
|
5000
5067
|
kind: "object",
|
|
5001
|
-
properties: namedDecl !== void 0 && (
|
|
5068
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
5002
5069
|
properties,
|
|
5003
5070
|
namedDecl,
|
|
5004
5071
|
type,
|
|
@@ -5046,12 +5113,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5046
5113
|
for (const symbol of symbols) {
|
|
5047
5114
|
const declarations = symbol.declarations;
|
|
5048
5115
|
if (!declarations) continue;
|
|
5049
|
-
const classDecl = declarations.find(
|
|
5116
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
5050
5117
|
if (classDecl) {
|
|
5051
5118
|
const map = /* @__PURE__ */ new Map();
|
|
5052
5119
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5053
5120
|
for (const member of classDecl.members) {
|
|
5054
|
-
if (
|
|
5121
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
5055
5122
|
const fieldNode = analyzeFieldToIR(
|
|
5056
5123
|
member,
|
|
5057
5124
|
checker,
|
|
@@ -5075,7 +5142,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5075
5142
|
}
|
|
5076
5143
|
return map;
|
|
5077
5144
|
}
|
|
5078
|
-
const interfaceDecl = declarations.find(
|
|
5145
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
5079
5146
|
if (interfaceDecl) {
|
|
5080
5147
|
return buildFieldNodeInfoMap(
|
|
5081
5148
|
interfaceDecl.members,
|
|
@@ -5089,7 +5156,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5089
5156
|
extensionRegistry
|
|
5090
5157
|
);
|
|
5091
5158
|
}
|
|
5092
|
-
const typeAliasDecl = declarations.find(
|
|
5159
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
5093
5160
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5094
5161
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5095
5162
|
return buildFieldNodeInfoMap(
|
|
@@ -5113,10 +5180,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5113
5180
|
return void 0;
|
|
5114
5181
|
}
|
|
5115
5182
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5116
|
-
if (
|
|
5183
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
5117
5184
|
return resolvedTypeNode.elementType;
|
|
5118
5185
|
}
|
|
5119
|
-
if (
|
|
5186
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5120
5187
|
return resolvedTypeNode.typeArguments[0];
|
|
5121
5188
|
}
|
|
5122
5189
|
return void 0;
|
|
@@ -5127,13 +5194,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5127
5194
|
return [];
|
|
5128
5195
|
}
|
|
5129
5196
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5130
|
-
return
|
|
5197
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5131
5198
|
}
|
|
5132
5199
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5133
|
-
if (
|
|
5200
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5134
5201
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5135
5202
|
}
|
|
5136
|
-
if (!
|
|
5203
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
5137
5204
|
return typeNode;
|
|
5138
5205
|
}
|
|
5139
5206
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5144,15 +5211,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5144
5211
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5145
5212
|
}
|
|
5146
5213
|
function isNullishTypeNode(typeNode) {
|
|
5147
|
-
if (typeNode.kind ===
|
|
5214
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
5148
5215
|
return true;
|
|
5149
5216
|
}
|
|
5150
|
-
return
|
|
5217
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
5151
5218
|
}
|
|
5152
5219
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5153
5220
|
const map = /* @__PURE__ */ new Map();
|
|
5154
5221
|
for (const member of members) {
|
|
5155
|
-
if (
|
|
5222
|
+
if (ts6.isPropertySignature(member)) {
|
|
5156
5223
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5157
5224
|
member,
|
|
5158
5225
|
checker,
|
|
@@ -5177,7 +5244,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5177
5244
|
return map;
|
|
5178
5245
|
}
|
|
5179
5246
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5180
|
-
if (!
|
|
5247
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
5181
5248
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5182
5249
|
const aliasName = typeNode.typeName.getText();
|
|
5183
5250
|
throw new Error(
|
|
@@ -5186,7 +5253,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5186
5253
|
}
|
|
5187
5254
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5188
5255
|
if (!aliasDecl) return [];
|
|
5189
|
-
if (
|
|
5256
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5190
5257
|
const aliasFieldType = resolveTypeNode(
|
|
5191
5258
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5192
5259
|
checker,
|
|
@@ -5230,14 +5297,14 @@ function getNamedTypeName(type) {
|
|
|
5230
5297
|
const symbol = type.getSymbol();
|
|
5231
5298
|
if (symbol?.declarations) {
|
|
5232
5299
|
const decl = symbol.declarations[0];
|
|
5233
|
-
if (decl && (
|
|
5234
|
-
const name =
|
|
5300
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5301
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5235
5302
|
if (name) return name;
|
|
5236
5303
|
}
|
|
5237
5304
|
}
|
|
5238
5305
|
const aliasSymbol = type.aliasSymbol;
|
|
5239
5306
|
if (aliasSymbol?.declarations) {
|
|
5240
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5307
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5241
5308
|
if (aliasDecl) {
|
|
5242
5309
|
return aliasDecl.name.text;
|
|
5243
5310
|
}
|
|
@@ -5248,24 +5315,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5248
5315
|
const symbol = type.getSymbol();
|
|
5249
5316
|
if (symbol?.declarations) {
|
|
5250
5317
|
const decl = symbol.declarations[0];
|
|
5251
|
-
if (decl && (
|
|
5318
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5252
5319
|
return decl;
|
|
5253
5320
|
}
|
|
5254
5321
|
}
|
|
5255
5322
|
const aliasSymbol = type.aliasSymbol;
|
|
5256
5323
|
if (aliasSymbol?.declarations) {
|
|
5257
|
-
return aliasSymbol.declarations.find(
|
|
5324
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5258
5325
|
}
|
|
5259
5326
|
return void 0;
|
|
5260
5327
|
}
|
|
5261
5328
|
function analyzeMethod(method, checker) {
|
|
5262
|
-
if (!
|
|
5329
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
5263
5330
|
return null;
|
|
5264
5331
|
}
|
|
5265
5332
|
const name = method.name.text;
|
|
5266
5333
|
const parameters = [];
|
|
5267
5334
|
for (const param of method.parameters) {
|
|
5268
|
-
if (
|
|
5335
|
+
if (ts6.isIdentifier(param.name)) {
|
|
5269
5336
|
const paramInfo = analyzeParameter(param, checker);
|
|
5270
5337
|
parameters.push(paramInfo);
|
|
5271
5338
|
}
|
|
@@ -5276,7 +5343,7 @@ function analyzeMethod(method, checker) {
|
|
|
5276
5343
|
return { name, parameters, returnTypeNode, returnType };
|
|
5277
5344
|
}
|
|
5278
5345
|
function analyzeParameter(param, checker) {
|
|
5279
|
-
const name =
|
|
5346
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
5280
5347
|
const typeNode = param.type;
|
|
5281
5348
|
const type = checker.getTypeAtLocation(param);
|
|
5282
5349
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5285,29 +5352,30 @@ function analyzeParameter(param, checker) {
|
|
|
5285
5352
|
}
|
|
5286
5353
|
function detectFormSpecReference(typeNode) {
|
|
5287
5354
|
if (!typeNode) return null;
|
|
5288
|
-
if (!
|
|
5289
|
-
const typeName =
|
|
5355
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
5356
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5290
5357
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5291
5358
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5292
|
-
if (!typeArg || !
|
|
5293
|
-
if (
|
|
5359
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
5360
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
5294
5361
|
return typeArg.exprName.text;
|
|
5295
5362
|
}
|
|
5296
|
-
if (
|
|
5363
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
5297
5364
|
return typeArg.exprName.right.text;
|
|
5298
5365
|
}
|
|
5299
5366
|
return null;
|
|
5300
5367
|
}
|
|
5301
|
-
var
|
|
5368
|
+
var ts6, import_internal4, RESOLVING_TYPE_PLACEHOLDER, MAX_ALIAS_CHAIN_DEPTH;
|
|
5302
5369
|
var init_class_analyzer = __esm({
|
|
5303
5370
|
"src/analyzer/class-analyzer.ts"() {
|
|
5304
5371
|
"use strict";
|
|
5305
|
-
|
|
5372
|
+
ts6 = __toESM(require("typescript"), 1);
|
|
5306
5373
|
import_internal4 = require("@formspec/analysis/internal");
|
|
5307
5374
|
init_jsdoc_constraints();
|
|
5308
5375
|
init_tsdoc_parser();
|
|
5309
5376
|
init_resolve_custom_type();
|
|
5310
5377
|
init_ts_type_utils();
|
|
5378
|
+
init_builtin_brands();
|
|
5311
5379
|
init_metadata();
|
|
5312
5380
|
RESOLVING_TYPE_PLACEHOLDER = {
|
|
5313
5381
|
kind: "object",
|
|
@@ -5334,23 +5402,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5334
5402
|
function createProgramContext(filePath, additionalFiles) {
|
|
5335
5403
|
const absolutePath = path.resolve(filePath);
|
|
5336
5404
|
const fileDir = path.dirname(absolutePath);
|
|
5337
|
-
const configPath =
|
|
5405
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
5338
5406
|
let compilerOptions;
|
|
5339
5407
|
let fileNames;
|
|
5340
5408
|
if (configPath) {
|
|
5341
|
-
const configFile =
|
|
5409
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
5342
5410
|
if (configFile.error) {
|
|
5343
5411
|
throw new Error(
|
|
5344
|
-
`Error reading tsconfig.json: ${
|
|
5412
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5345
5413
|
);
|
|
5346
5414
|
}
|
|
5347
|
-
const parsed =
|
|
5415
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
5348
5416
|
configFile.config,
|
|
5349
|
-
|
|
5417
|
+
ts7.sys,
|
|
5350
5418
|
path.dirname(configPath)
|
|
5351
5419
|
);
|
|
5352
5420
|
if (parsed.errors.length > 0) {
|
|
5353
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5421
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5354
5422
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5355
5423
|
}
|
|
5356
5424
|
compilerOptions = parsed.options;
|
|
@@ -5358,9 +5426,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5358
5426
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5359
5427
|
} else {
|
|
5360
5428
|
compilerOptions = {
|
|
5361
|
-
target:
|
|
5362
|
-
module:
|
|
5363
|
-
moduleResolution:
|
|
5429
|
+
target: ts7.ScriptTarget.ES2022,
|
|
5430
|
+
module: ts7.ModuleKind.NodeNext,
|
|
5431
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
5364
5432
|
strict: true,
|
|
5365
5433
|
skipLibCheck: true,
|
|
5366
5434
|
declaration: true
|
|
@@ -5368,7 +5436,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5368
5436
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5369
5437
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5370
5438
|
}
|
|
5371
|
-
const program =
|
|
5439
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
5372
5440
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5373
5441
|
if (!sourceFile) {
|
|
5374
5442
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5387,19 +5455,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5387
5455
|
result = node;
|
|
5388
5456
|
return;
|
|
5389
5457
|
}
|
|
5390
|
-
|
|
5458
|
+
ts7.forEachChild(node, visit);
|
|
5391
5459
|
}
|
|
5392
5460
|
visit(sourceFile);
|
|
5393
5461
|
return result;
|
|
5394
5462
|
}
|
|
5395
5463
|
function findClassByName(sourceFile, className) {
|
|
5396
|
-
return findNodeByName(sourceFile, className,
|
|
5464
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
5397
5465
|
}
|
|
5398
5466
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5399
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5467
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
5400
5468
|
}
|
|
5401
5469
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5402
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5470
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5403
5471
|
}
|
|
5404
5472
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5405
5473
|
if (rootType.kind === "object") {
|
|
@@ -5439,22 +5507,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5439
5507
|
};
|
|
5440
5508
|
}
|
|
5441
5509
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5442
|
-
if (
|
|
5510
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5443
5511
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5444
5512
|
}
|
|
5445
|
-
if (
|
|
5513
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5446
5514
|
return true;
|
|
5447
5515
|
}
|
|
5448
|
-
return
|
|
5516
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5449
5517
|
}
|
|
5450
5518
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5451
|
-
if (
|
|
5519
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5452
5520
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5453
5521
|
}
|
|
5454
|
-
if (
|
|
5522
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
5455
5523
|
const propertyNames = [];
|
|
5456
5524
|
for (const member of typeNode.members) {
|
|
5457
|
-
if (!
|
|
5525
|
+
if (!ts7.isPropertySignature(member)) {
|
|
5458
5526
|
continue;
|
|
5459
5527
|
}
|
|
5460
5528
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5464,13 +5532,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5464
5532
|
}
|
|
5465
5533
|
return propertyNames;
|
|
5466
5534
|
}
|
|
5467
|
-
if (
|
|
5535
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5468
5536
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5469
5537
|
}
|
|
5470
5538
|
return null;
|
|
5471
5539
|
}
|
|
5472
5540
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5473
|
-
if (!
|
|
5541
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
5474
5542
|
return [];
|
|
5475
5543
|
}
|
|
5476
5544
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5669,11 +5737,11 @@ function makeFileProvenance(filePath) {
|
|
|
5669
5737
|
column: 0
|
|
5670
5738
|
};
|
|
5671
5739
|
}
|
|
5672
|
-
var
|
|
5740
|
+
var ts7, path;
|
|
5673
5741
|
var init_program = __esm({
|
|
5674
5742
|
"src/analyzer/program.ts"() {
|
|
5675
5743
|
"use strict";
|
|
5676
|
-
|
|
5744
|
+
ts7 = __toESM(require("typescript"), 1);
|
|
5677
5745
|
path = __toESM(require("path"), 1);
|
|
5678
5746
|
init_class_analyzer();
|
|
5679
5747
|
}
|
|
@@ -5688,10 +5756,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5688
5756
|
return symbolMap;
|
|
5689
5757
|
}
|
|
5690
5758
|
function visit(node) {
|
|
5691
|
-
if (
|
|
5759
|
+
if (ts8.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5692
5760
|
processDefineCustomTypeCall(node);
|
|
5693
5761
|
}
|
|
5694
|
-
|
|
5762
|
+
ts8.forEachChild(node, visit);
|
|
5695
5763
|
}
|
|
5696
5764
|
function processDefineCustomTypeCall(call) {
|
|
5697
5765
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5728,7 +5796,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5728
5796
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5729
5797
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5730
5798
|
if (callSymbol !== void 0) {
|
|
5731
|
-
const resolved = callSymbol.flags &
|
|
5799
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5732
5800
|
const decl = resolved.declarations?.[0];
|
|
5733
5801
|
if (decl !== void 0) {
|
|
5734
5802
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5736,24 +5804,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5736
5804
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5737
5805
|
}
|
|
5738
5806
|
}
|
|
5739
|
-
return
|
|
5807
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5740
5808
|
}
|
|
5741
5809
|
function extractTypeNameFromCallArg(call) {
|
|
5742
5810
|
const arg = call.arguments[0];
|
|
5743
|
-
if (arg === void 0 || !
|
|
5811
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5744
5812
|
return null;
|
|
5745
5813
|
}
|
|
5746
5814
|
const typeNameProp = arg.properties.find(
|
|
5747
|
-
(p) =>
|
|
5815
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5748
5816
|
);
|
|
5749
|
-
if (typeNameProp === void 0 || !
|
|
5817
|
+
if (typeNameProp === void 0 || !ts8.isStringLiteral(typeNameProp.initializer)) {
|
|
5750
5818
|
return null;
|
|
5751
5819
|
}
|
|
5752
5820
|
return typeNameProp.initializer.text;
|
|
5753
5821
|
}
|
|
5754
5822
|
function extractEnclosingExtensionId(call, checker) {
|
|
5755
|
-
for (let node = call.parent; !
|
|
5756
|
-
if (
|
|
5823
|
+
for (let node = call.parent; !ts8.isSourceFile(node); node = node.parent) {
|
|
5824
|
+
if (ts8.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5757
5825
|
return extractExtensionIdFromCallArg(node);
|
|
5758
5826
|
}
|
|
5759
5827
|
}
|
|
@@ -5762,24 +5830,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5762
5830
|
function isDefineExtensionCall(node, checker) {
|
|
5763
5831
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5764
5832
|
if (callSymbol !== void 0) {
|
|
5765
|
-
const resolved = callSymbol.flags &
|
|
5833
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5766
5834
|
const decl = resolved.declarations?.[0];
|
|
5767
5835
|
if (decl !== void 0) {
|
|
5768
5836
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5769
5837
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5770
5838
|
}
|
|
5771
5839
|
}
|
|
5772
|
-
return
|
|
5840
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5773
5841
|
}
|
|
5774
5842
|
function extractExtensionIdFromCallArg(call) {
|
|
5775
5843
|
const arg = call.arguments[0];
|
|
5776
|
-
if (arg === void 0 || !
|
|
5844
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5777
5845
|
return null;
|
|
5778
5846
|
}
|
|
5779
5847
|
const prop = arg.properties.find(
|
|
5780
|
-
(p) =>
|
|
5848
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5781
5849
|
);
|
|
5782
|
-
if (prop === void 0 || !
|
|
5850
|
+
if (prop === void 0 || !ts8.isStringLiteral(prop.initializer)) {
|
|
5783
5851
|
return null;
|
|
5784
5852
|
}
|
|
5785
5853
|
return prop.initializer.text;
|
|
@@ -5797,11 +5865,11 @@ function findRegistrationByTypeName(registry, typeName) {
|
|
|
5797
5865
|
}
|
|
5798
5866
|
return void 0;
|
|
5799
5867
|
}
|
|
5800
|
-
var
|
|
5868
|
+
var ts8, path2;
|
|
5801
5869
|
var init_symbol_registry = __esm({
|
|
5802
5870
|
"src/extensions/symbol-registry.ts"() {
|
|
5803
5871
|
"use strict";
|
|
5804
|
-
|
|
5872
|
+
ts8 = __toESM(require("typescript"), 1);
|
|
5805
5873
|
path2 = __toESM(require("path"), 1);
|
|
5806
5874
|
init_ts_type_utils();
|
|
5807
5875
|
}
|
|
@@ -6064,7 +6132,7 @@ function generateSchemasBatch(options) {
|
|
|
6064
6132
|
return options.targets.map((target) => {
|
|
6065
6133
|
let ctx;
|
|
6066
6134
|
try {
|
|
6067
|
-
const cacheKey =
|
|
6135
|
+
const cacheKey = ts9.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6068
6136
|
const cachedContext = contextCache.get(cacheKey);
|
|
6069
6137
|
if (cachedContext === void 0) {
|
|
6070
6138
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6218,11 +6286,11 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6218
6286
|
relatedLocations: []
|
|
6219
6287
|
};
|
|
6220
6288
|
}
|
|
6221
|
-
var
|
|
6289
|
+
var ts9;
|
|
6222
6290
|
var init_class_schema = __esm({
|
|
6223
6291
|
"src/generators/class-schema.ts"() {
|
|
6224
6292
|
"use strict";
|
|
6225
|
-
|
|
6293
|
+
ts9 = __toESM(require("typescript"), 1);
|
|
6226
6294
|
init_program();
|
|
6227
6295
|
init_class_analyzer();
|
|
6228
6296
|
init_canonicalize();
|
|
@@ -6249,7 +6317,7 @@ function getModuleSymbol(context) {
|
|
|
6249
6317
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6250
6318
|
}
|
|
6251
6319
|
function isSchemaSourceDeclaration(declaration) {
|
|
6252
|
-
return
|
|
6320
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6253
6321
|
}
|
|
6254
6322
|
function resolveModuleExport(context, exportName = "default") {
|
|
6255
6323
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6260,16 +6328,16 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6260
6328
|
if (exportSymbol === null) {
|
|
6261
6329
|
return null;
|
|
6262
6330
|
}
|
|
6263
|
-
return exportSymbol.flags &
|
|
6331
|
+
return exportSymbol.flags & ts10.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6264
6332
|
}
|
|
6265
6333
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6266
6334
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6267
6335
|
}
|
|
6268
|
-
var
|
|
6336
|
+
var ts10;
|
|
6269
6337
|
var init_static_build = __esm({
|
|
6270
6338
|
"src/static-build.ts"() {
|
|
6271
6339
|
"use strict";
|
|
6272
|
-
|
|
6340
|
+
ts10 = __toESM(require("typescript"), 1);
|
|
6273
6341
|
init_program();
|
|
6274
6342
|
}
|
|
6275
6343
|
});
|
|
@@ -6282,17 +6350,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6282
6350
|
};
|
|
6283
6351
|
}
|
|
6284
6352
|
function isNamedTypeDeclaration(declaration) {
|
|
6285
|
-
return
|
|
6353
|
+
return ts11.isClassDeclaration(declaration) || ts11.isInterfaceDeclaration(declaration) || ts11.isTypeAliasDeclaration(declaration);
|
|
6286
6354
|
}
|
|
6287
6355
|
function hasConcreteTypeArguments(type, checker) {
|
|
6288
6356
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6289
6357
|
return true;
|
|
6290
6358
|
}
|
|
6291
|
-
if ((type.flags &
|
|
6359
|
+
if ((type.flags & ts11.TypeFlags.Object) === 0) {
|
|
6292
6360
|
return false;
|
|
6293
6361
|
}
|
|
6294
6362
|
const objectType = type;
|
|
6295
|
-
if ((objectType.objectFlags &
|
|
6363
|
+
if ((objectType.objectFlags & ts11.ObjectFlags.Reference) === 0) {
|
|
6296
6364
|
return false;
|
|
6297
6365
|
}
|
|
6298
6366
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6305,13 +6373,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6305
6373
|
return declaration;
|
|
6306
6374
|
}
|
|
6307
6375
|
}
|
|
6308
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6376
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts11.isTypeAliasDeclaration);
|
|
6309
6377
|
return aliasDeclaration;
|
|
6310
6378
|
}
|
|
6311
6379
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6312
6380
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6313
6381
|
const namedNode = sourceNode;
|
|
6314
|
-
if (namedNode.name !== void 0 &&
|
|
6382
|
+
if (namedNode.name !== void 0 && ts11.isIdentifier(namedNode.name)) {
|
|
6315
6383
|
return namedNode.name.text;
|
|
6316
6384
|
}
|
|
6317
6385
|
}
|
|
@@ -6533,7 +6601,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6533
6601
|
function generateSchemasFromDeclaration(options) {
|
|
6534
6602
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6535
6603
|
const resolved = resolveStaticOptions(options);
|
|
6536
|
-
if (
|
|
6604
|
+
if (ts11.isClassDeclaration(options.declaration)) {
|
|
6537
6605
|
return generateSchemasFromAnalysis(
|
|
6538
6606
|
analyzeClassToIR(
|
|
6539
6607
|
options.declaration,
|
|
@@ -6547,7 +6615,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6547
6615
|
resolved
|
|
6548
6616
|
);
|
|
6549
6617
|
}
|
|
6550
|
-
if (
|
|
6618
|
+
if (ts11.isInterfaceDeclaration(options.declaration)) {
|
|
6551
6619
|
return generateSchemasFromAnalysis(
|
|
6552
6620
|
analyzeInterfaceToIR(
|
|
6553
6621
|
options.declaration,
|
|
@@ -6561,7 +6629,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6561
6629
|
resolved
|
|
6562
6630
|
);
|
|
6563
6631
|
}
|
|
6564
|
-
if (
|
|
6632
|
+
if (ts11.isTypeAliasDeclaration(options.declaration)) {
|
|
6565
6633
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6566
6634
|
options.declaration,
|
|
6567
6635
|
options.context.checker,
|
|
@@ -6620,7 +6688,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6620
6688
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6621
6689
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6622
6690
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6623
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6691
|
+
const fallbackName = options.declaration.name !== void 0 && ts11.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6624
6692
|
return generateSchemasFromResolvedType({
|
|
6625
6693
|
...options,
|
|
6626
6694
|
type,
|
|
@@ -6667,20 +6735,20 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6667
6735
|
if (typeNode === void 0) {
|
|
6668
6736
|
return void 0;
|
|
6669
6737
|
}
|
|
6670
|
-
if (
|
|
6738
|
+
if (ts11.isParenthesizedTypeNode(typeNode)) {
|
|
6671
6739
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6672
6740
|
return unwrapped ?? typeNode;
|
|
6673
6741
|
}
|
|
6674
6742
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6675
6743
|
}
|
|
6676
6744
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6677
|
-
return
|
|
6745
|
+
return ts11.isTypeReferenceNode(typeNode) && ts11.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6678
6746
|
}
|
|
6679
|
-
var
|
|
6747
|
+
var ts11, import_internal6, import_internals6;
|
|
6680
6748
|
var init_discovered_schema = __esm({
|
|
6681
6749
|
"src/generators/discovered-schema.ts"() {
|
|
6682
6750
|
"use strict";
|
|
6683
|
-
|
|
6751
|
+
ts11 = __toESM(require("typescript"), 1);
|
|
6684
6752
|
import_internal6 = require("@formspec/analysis/internal");
|
|
6685
6753
|
init_class_analyzer();
|
|
6686
6754
|
init_class_schema();
|
|
@@ -6923,6 +6991,8 @@ __export(index_exports, {
|
|
|
6923
6991
|
writeSchemas: () => writeSchemas
|
|
6924
6992
|
});
|
|
6925
6993
|
function buildFormSchemas(form, options) {
|
|
6994
|
+
const logger = options?.logger ?? import_core4.noopLogger;
|
|
6995
|
+
logger.debug("buildFormSchemas: starting schema generation");
|
|
6926
6996
|
return {
|
|
6927
6997
|
jsonSchema: generateJsonSchema(form, options),
|
|
6928
6998
|
uiSchema: generateUiSchema(form, options)
|
|
@@ -6935,12 +7005,15 @@ function writeSchemas(form, options) {
|
|
|
6935
7005
|
indent = 2,
|
|
6936
7006
|
vendorPrefix,
|
|
6937
7007
|
enumSerialization,
|
|
6938
|
-
metadata
|
|
7008
|
+
metadata,
|
|
7009
|
+
logger: rawLogger
|
|
6939
7010
|
} = options;
|
|
6940
|
-
const
|
|
7011
|
+
const logger = (rawLogger ?? import_core4.noopLogger).child({ stage: "write" });
|
|
7012
|
+
const buildOptions = vendorPrefix === void 0 && enumSerialization === void 0 && metadata === void 0 ? { logger: rawLogger } : {
|
|
6941
7013
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
6942
7014
|
...enumSerialization !== void 0 && { enumSerialization },
|
|
6943
|
-
...metadata !== void 0 && { metadata }
|
|
7015
|
+
...metadata !== void 0 && { metadata },
|
|
7016
|
+
logger: rawLogger
|
|
6944
7017
|
};
|
|
6945
7018
|
const { jsonSchema, uiSchema: uiSchema2 } = buildFormSchemas(form, buildOptions);
|
|
6946
7019
|
if (!fs.existsSync(outDir)) {
|
|
@@ -6948,14 +7021,17 @@ function writeSchemas(form, options) {
|
|
|
6948
7021
|
}
|
|
6949
7022
|
const jsonSchemaPath = path3.join(outDir, `${name}-schema.json`);
|
|
6950
7023
|
const uiSchemaPath = path3.join(outDir, `${name}-uischema.json`);
|
|
7024
|
+
logger.debug("writing JSON Schema", { path: jsonSchemaPath });
|
|
6951
7025
|
fs.writeFileSync(jsonSchemaPath, JSON.stringify(jsonSchema, null, indent));
|
|
7026
|
+
logger.debug("writing UI Schema", { path: uiSchemaPath });
|
|
6952
7027
|
fs.writeFileSync(uiSchemaPath, JSON.stringify(uiSchema2, null, indent));
|
|
6953
7028
|
return { jsonSchemaPath, uiSchemaPath };
|
|
6954
7029
|
}
|
|
6955
|
-
var fs, path3;
|
|
7030
|
+
var import_core4, fs, path3;
|
|
6956
7031
|
var init_index = __esm({
|
|
6957
7032
|
"src/index.ts"() {
|
|
6958
7033
|
"use strict";
|
|
7034
|
+
import_core4 = require("@formspec/core");
|
|
6959
7035
|
init_generator();
|
|
6960
7036
|
init_generator2();
|
|
6961
7037
|
init_ir_generator();
|
|
@@ -6979,6 +7055,34 @@ var init_index = __esm({
|
|
|
6979
7055
|
// src/cli.ts
|
|
6980
7056
|
var path4 = __toESM(require("path"), 1);
|
|
6981
7057
|
var import_node_url = require("url");
|
|
7058
|
+
|
|
7059
|
+
// src/cli/logger.ts
|
|
7060
|
+
var import_node_module = require("module");
|
|
7061
|
+
var import_core = require("@formspec/core");
|
|
7062
|
+
var import_meta = {};
|
|
7063
|
+
var require2 = (0, import_node_module.createRequire)(import_meta.url);
|
|
7064
|
+
function createLogger(namespace) {
|
|
7065
|
+
const debugEnv = process.env["DEBUG"] ?? "";
|
|
7066
|
+
if (!(0, import_core.isNamespaceEnabled)(debugEnv, namespace)) {
|
|
7067
|
+
return import_core.noopLogger;
|
|
7068
|
+
}
|
|
7069
|
+
const pinoModule = require2("pino");
|
|
7070
|
+
const pino = typeof pinoModule === "function" ? pinoModule : pinoModule.default;
|
|
7071
|
+
const isTTY = process.stderr.isTTY;
|
|
7072
|
+
if (isTTY) {
|
|
7073
|
+
const pinoPretty = require2("pino-pretty");
|
|
7074
|
+
const prettyTransport = pinoPretty.default ?? pinoPretty;
|
|
7075
|
+
const stream = prettyTransport({ destination: 2, colorize: true, sync: true });
|
|
7076
|
+
return pino({ name: namespace, level: "debug" }, stream);
|
|
7077
|
+
}
|
|
7078
|
+
return pino(
|
|
7079
|
+
{ name: namespace, level: "debug" },
|
|
7080
|
+
pino.destination({ dest: 2, sync: true })
|
|
7081
|
+
);
|
|
7082
|
+
}
|
|
7083
|
+
|
|
7084
|
+
// src/cli.ts
|
|
7085
|
+
var log = createLogger("formspec:build");
|
|
6982
7086
|
function printHelp() {
|
|
6983
7087
|
console.log(`
|
|
6984
7088
|
FormSpec Build CLI - Generate JSON Schema and UI Schema
|
|
@@ -7068,6 +7172,7 @@ function parseArgs(args) {
|
|
|
7068
7172
|
if (!name) {
|
|
7069
7173
|
name = path4.basename(inputFile, path4.extname(inputFile));
|
|
7070
7174
|
}
|
|
7175
|
+
log.debug("Arguments parsed", { inputFile, outDir, name, enumSerialization });
|
|
7071
7176
|
return { inputFile, outDir, name, enumSerialization };
|
|
7072
7177
|
}
|
|
7073
7178
|
async function main() {
|
|
@@ -7078,11 +7183,14 @@ async function main() {
|
|
|
7078
7183
|
}
|
|
7079
7184
|
const { inputFile, outDir, name, enumSerialization } = options;
|
|
7080
7185
|
const absoluteInput = path4.resolve(process.cwd(), inputFile);
|
|
7186
|
+
log.debug("Resolved input file", { absoluteInput });
|
|
7081
7187
|
try {
|
|
7082
7188
|
const fileUrl = (0, import_node_url.pathToFileURL)(absoluteInput).href;
|
|
7189
|
+
log.debug("Loading form module", { fileUrl });
|
|
7083
7190
|
const module2 = await import(fileUrl);
|
|
7084
7191
|
const form = module2["default"] ?? module2["form"];
|
|
7085
7192
|
if (!form || typeof form !== "object" || !("elements" in form)) {
|
|
7193
|
+
log.error("Input file does not export a valid FormSpec", { fileUrl });
|
|
7086
7194
|
console.error("Error: Input file must export a FormSpec as default export or as 'form'");
|
|
7087
7195
|
console.error("Example:");
|
|
7088
7196
|
console.error(' export default formspec(field.text("name"));');
|
|
@@ -7090,18 +7198,22 @@ async function main() {
|
|
|
7090
7198
|
console.error(' export const form = formspec(field.text("name"));');
|
|
7091
7199
|
process.exit(1);
|
|
7092
7200
|
}
|
|
7201
|
+
log.debug("Form module loaded, generating schemas");
|
|
7093
7202
|
const { writeSchemas: writeSchemas2 } = await Promise.resolve().then(() => (init_index(), index_exports));
|
|
7094
7203
|
const { jsonSchemaPath, uiSchemaPath } = writeSchemas2(
|
|
7095
7204
|
form,
|
|
7096
7205
|
{ outDir, name, enumSerialization }
|
|
7097
7206
|
);
|
|
7207
|
+
log.debug("Schemas written", { jsonSchemaPath, uiSchemaPath });
|
|
7098
7208
|
console.log("Generated:");
|
|
7099
7209
|
console.log(` ${jsonSchemaPath}`);
|
|
7100
7210
|
console.log(` ${uiSchemaPath}`);
|
|
7101
7211
|
} catch (error) {
|
|
7102
7212
|
if (error instanceof Error) {
|
|
7213
|
+
log.child({ err: error.message }).error("Schema generation failed");
|
|
7103
7214
|
console.error(`Error: ${error.message}`);
|
|
7104
7215
|
} else {
|
|
7216
|
+
log.error("Schema generation failed with unknown error");
|
|
7105
7217
|
console.error("Error:", error);
|
|
7106
7218
|
}
|
|
7107
7219
|
process.exit(1);
|