@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.js
CHANGED
|
@@ -1719,11 +1719,16 @@ var init_ir_generator = __esm({
|
|
|
1719
1719
|
});
|
|
1720
1720
|
|
|
1721
1721
|
// src/json-schema/generator.ts
|
|
1722
|
+
import { noopLogger as noopLogger2 } from "@formspec/core";
|
|
1722
1723
|
function generateJsonSchema(form, options) {
|
|
1724
|
+
const logger = (options?.logger ?? noopLogger2).child({ stage: "ir" });
|
|
1723
1725
|
const metadata = options?.metadata;
|
|
1724
1726
|
const vendorPrefix = options?.vendorPrefix;
|
|
1725
1727
|
const enumSerialization = options?.enumSerialization;
|
|
1728
|
+
logger.debug("canonicalizing chain DSL to IR");
|
|
1726
1729
|
const ir = canonicalizeChainDSL(form, metadata !== void 0 ? { metadata } : void 0);
|
|
1730
|
+
const schemaLogger = (options?.logger ?? noopLogger2).child({ stage: "schema" });
|
|
1731
|
+
schemaLogger.debug("generating JSON Schema from IR");
|
|
1727
1732
|
const internalOptions = vendorPrefix === void 0 && enumSerialization === void 0 ? void 0 : {
|
|
1728
1733
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
1729
1734
|
...enumSerialization !== void 0 && { enumSerialization }
|
|
@@ -2010,11 +2015,16 @@ var init_ir_generator2 = __esm({
|
|
|
2010
2015
|
});
|
|
2011
2016
|
|
|
2012
2017
|
// src/ui-schema/generator.ts
|
|
2018
|
+
import { noopLogger as noopLogger3 } from "@formspec/core";
|
|
2013
2019
|
function generateUiSchema(form, options) {
|
|
2020
|
+
const logger = (options?.logger ?? noopLogger3).child({ stage: "ir" });
|
|
2021
|
+
logger.debug("canonicalizing chain DSL to IR for UI Schema generation");
|
|
2014
2022
|
const ir = canonicalizeChainDSL(
|
|
2015
2023
|
form,
|
|
2016
2024
|
options?.metadata !== void 0 ? { metadata: options.metadata } : void 0
|
|
2017
2025
|
);
|
|
2026
|
+
const schemaLogger = (options?.logger ?? noopLogger3).child({ stage: "schema" });
|
|
2027
|
+
schemaLogger.debug("generating UI Schema from IR");
|
|
2018
2028
|
return generateUiSchemaFromIR(ir);
|
|
2019
2029
|
}
|
|
2020
2030
|
var init_generator2 = __esm({
|
|
@@ -2401,8 +2411,22 @@ var init_resolve_custom_type = __esm({
|
|
|
2401
2411
|
}
|
|
2402
2412
|
});
|
|
2403
2413
|
|
|
2404
|
-
// src/analyzer/
|
|
2414
|
+
// src/analyzer/builtin-brands.ts
|
|
2405
2415
|
import * as ts3 from "typescript";
|
|
2416
|
+
function isIntegerBrandedType(type) {
|
|
2417
|
+
if (!type.isIntersection()) return false;
|
|
2418
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2419
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2420
|
+
}
|
|
2421
|
+
var init_builtin_brands = __esm({
|
|
2422
|
+
"src/analyzer/builtin-brands.ts"() {
|
|
2423
|
+
"use strict";
|
|
2424
|
+
init_ts_type_utils();
|
|
2425
|
+
}
|
|
2426
|
+
});
|
|
2427
|
+
|
|
2428
|
+
// src/analyzer/tsdoc-parser.ts
|
|
2429
|
+
import * as ts4 from "typescript";
|
|
2406
2430
|
import {
|
|
2407
2431
|
checkSyntheticTagApplication,
|
|
2408
2432
|
choosePreferredPayloadText,
|
|
@@ -2410,6 +2434,7 @@ import {
|
|
|
2410
2434
|
getTagDefinition as getTagDefinition2,
|
|
2411
2435
|
hasTypeSemanticCapability,
|
|
2412
2436
|
normalizeFormSpecTagName as normalizeFormSpecTagName2,
|
|
2437
|
+
stripNullishUnion as stripNullishUnion2,
|
|
2413
2438
|
parseConstraintTagValue,
|
|
2414
2439
|
parseDefaultValueTagValue,
|
|
2415
2440
|
parseTagSyntax,
|
|
@@ -2443,23 +2468,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2443
2468
|
function collectImportedNames(sourceFile) {
|
|
2444
2469
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2445
2470
|
for (const statement of sourceFile.statements) {
|
|
2446
|
-
if (
|
|
2471
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2447
2472
|
const clause = statement.importClause;
|
|
2448
2473
|
if (clause.name !== void 0) {
|
|
2449
2474
|
importedNames.add(clause.name.text);
|
|
2450
2475
|
}
|
|
2451
2476
|
if (clause.namedBindings !== void 0) {
|
|
2452
|
-
if (
|
|
2477
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2453
2478
|
for (const specifier of clause.namedBindings.elements) {
|
|
2454
2479
|
importedNames.add(specifier.name.text);
|
|
2455
2480
|
}
|
|
2456
|
-
} else if (
|
|
2481
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2457
2482
|
importedNames.add(clause.namedBindings.name.text);
|
|
2458
2483
|
}
|
|
2459
2484
|
}
|
|
2460
2485
|
continue;
|
|
2461
2486
|
}
|
|
2462
|
-
if (
|
|
2487
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2463
2488
|
importedNames.add(statement.name.text);
|
|
2464
2489
|
}
|
|
2465
2490
|
}
|
|
@@ -2467,50 +2492,96 @@ function collectImportedNames(sourceFile) {
|
|
|
2467
2492
|
}
|
|
2468
2493
|
function isNonReferenceIdentifier(node) {
|
|
2469
2494
|
const parent = node.parent;
|
|
2470
|
-
if ((
|
|
2495
|
+
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) {
|
|
2471
2496
|
return true;
|
|
2472
2497
|
}
|
|
2473
|
-
if ((
|
|
2498
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2474
2499
|
return true;
|
|
2475
2500
|
}
|
|
2476
|
-
if (
|
|
2501
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2477
2502
|
return true;
|
|
2478
2503
|
}
|
|
2479
2504
|
return false;
|
|
2480
2505
|
}
|
|
2481
|
-
function
|
|
2506
|
+
function astReferencesImportedName(root, importedNames) {
|
|
2482
2507
|
if (importedNames.size === 0) {
|
|
2483
2508
|
return false;
|
|
2484
2509
|
}
|
|
2485
|
-
let
|
|
2510
|
+
let found = false;
|
|
2486
2511
|
const visit = (node) => {
|
|
2487
|
-
if (
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2491
|
-
referencesImportedName = true;
|
|
2512
|
+
if (found) return;
|
|
2513
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2514
|
+
found = true;
|
|
2492
2515
|
return;
|
|
2493
2516
|
}
|
|
2494
|
-
|
|
2517
|
+
ts4.forEachChild(node, visit);
|
|
2495
2518
|
};
|
|
2496
|
-
visit(
|
|
2497
|
-
return
|
|
2519
|
+
visit(root);
|
|
2520
|
+
return found;
|
|
2521
|
+
}
|
|
2522
|
+
function getObjectMembers(statement) {
|
|
2523
|
+
if (ts4.isInterfaceDeclaration(statement)) {
|
|
2524
|
+
return statement.members;
|
|
2525
|
+
}
|
|
2526
|
+
if (ts4.isTypeLiteralNode(statement.type)) {
|
|
2527
|
+
return statement.type.members;
|
|
2528
|
+
}
|
|
2529
|
+
return void 0;
|
|
2530
|
+
}
|
|
2531
|
+
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
2532
|
+
const members = getObjectMembers(statement);
|
|
2533
|
+
if (members === void 0) {
|
|
2534
|
+
return null;
|
|
2535
|
+
}
|
|
2536
|
+
const replacements = [];
|
|
2537
|
+
for (const member of members) {
|
|
2538
|
+
if (!ts4.isPropertySignature(member)) {
|
|
2539
|
+
if (astReferencesImportedName(member, importedNames)) {
|
|
2540
|
+
return null;
|
|
2541
|
+
}
|
|
2542
|
+
continue;
|
|
2543
|
+
}
|
|
2544
|
+
const typeAnnotation = member.type;
|
|
2545
|
+
if (typeAnnotation === void 0) continue;
|
|
2546
|
+
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
2547
|
+
replacements.push({
|
|
2548
|
+
start: typeAnnotation.getStart(sourceFile),
|
|
2549
|
+
end: typeAnnotation.getEnd()
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
if (replacements.length === 0) {
|
|
2554
|
+
return statement.getText(sourceFile);
|
|
2555
|
+
}
|
|
2556
|
+
const stmtStart = statement.getStart(sourceFile);
|
|
2557
|
+
let result = statement.getText(sourceFile);
|
|
2558
|
+
for (const { start, end } of [...replacements].reverse()) {
|
|
2559
|
+
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
2560
|
+
}
|
|
2561
|
+
return result;
|
|
2498
2562
|
}
|
|
2499
2563
|
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2500
2564
|
const importedNames = collectImportedNames(sourceFile);
|
|
2501
2565
|
const importedNamesToSkip = new Set(
|
|
2502
2566
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2503
2567
|
);
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
if (
|
|
2507
|
-
if (
|
|
2508
|
-
|
|
2509
|
-
if (
|
|
2510
|
-
|
|
2568
|
+
const result = [];
|
|
2569
|
+
for (const statement of sourceFile.statements) {
|
|
2570
|
+
if (ts4.isImportDeclaration(statement)) continue;
|
|
2571
|
+
if (ts4.isImportEqualsDeclaration(statement)) continue;
|
|
2572
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2573
|
+
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2574
|
+
result.push(statement.getText(sourceFile));
|
|
2575
|
+
continue;
|
|
2511
2576
|
}
|
|
2512
|
-
|
|
2513
|
-
|
|
2577
|
+
if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
|
|
2578
|
+
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2579
|
+
if (rewritten !== null) {
|
|
2580
|
+
result.push(rewritten);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
return result;
|
|
2514
2585
|
}
|
|
2515
2586
|
function pushUniqueCompilerDiagnostics(target, additions) {
|
|
2516
2587
|
for (const diagnostic of additions) {
|
|
@@ -2600,7 +2671,7 @@ function stripHintNullishUnion(type) {
|
|
|
2600
2671
|
return type;
|
|
2601
2672
|
}
|
|
2602
2673
|
const nonNullish = type.types.filter(
|
|
2603
|
-
(member) => (member.flags & (
|
|
2674
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
2604
2675
|
);
|
|
2605
2676
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2606
2677
|
return nonNullish[0];
|
|
@@ -2616,10 +2687,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2616
2687
|
}
|
|
2617
2688
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2618
2689
|
const name = declaration.name;
|
|
2619
|
-
if (
|
|
2690
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
2620
2691
|
return false;
|
|
2621
2692
|
}
|
|
2622
|
-
if (!
|
|
2693
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
2623
2694
|
return false;
|
|
2624
2695
|
}
|
|
2625
2696
|
}
|
|
@@ -2837,6 +2908,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2837
2908
|
}
|
|
2838
2909
|
const hasBroadening = (() => {
|
|
2839
2910
|
if (target === null) {
|
|
2911
|
+
if (isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2912
|
+
return true;
|
|
2913
|
+
}
|
|
2840
2914
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2841
2915
|
}
|
|
2842
2916
|
const registry = options?.extensionRegistry;
|
|
@@ -2988,12 +3062,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2988
3062
|
const sourceText = sourceFile.getFullText();
|
|
2989
3063
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2990
3064
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2991
|
-
const commentRanges =
|
|
3065
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2992
3066
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2993
3067
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2994
3068
|
if (commentRanges) {
|
|
2995
3069
|
for (const range of commentRanges) {
|
|
2996
|
-
if (range.kind !==
|
|
3070
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
2997
3071
|
continue;
|
|
2998
3072
|
}
|
|
2999
3073
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3150,10 +3224,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3150
3224
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3151
3225
|
const sourceFile = node.getSourceFile();
|
|
3152
3226
|
const sourceText = sourceFile.getFullText();
|
|
3153
|
-
const commentRanges =
|
|
3227
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3154
3228
|
if (commentRanges) {
|
|
3155
3229
|
for (const range of commentRanges) {
|
|
3156
|
-
if (range.kind !==
|
|
3230
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3157
3231
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3158
3232
|
if (!commentText.startsWith("/**")) continue;
|
|
3159
3233
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -3178,7 +3252,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3178
3252
|
}
|
|
3179
3253
|
function collectRawTextFallbacks(node, file) {
|
|
3180
3254
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3181
|
-
for (const tag of
|
|
3255
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
3182
3256
|
const tagName = normalizeConstraintTagName2(tag.tagName.text);
|
|
3183
3257
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3184
3258
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3233,14 +3307,15 @@ function getTagCommentText(tag) {
|
|
|
3233
3307
|
if (typeof tag.comment === "string") {
|
|
3234
3308
|
return tag.comment;
|
|
3235
3309
|
}
|
|
3236
|
-
return
|
|
3310
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
3237
3311
|
}
|
|
3238
3312
|
var SYNTHETIC_TYPE_FORMAT_FLAGS, MAX_HINT_CANDIDATES, MAX_HINT_DEPTH, parseResultCache;
|
|
3239
3313
|
var init_tsdoc_parser = __esm({
|
|
3240
3314
|
"src/analyzer/tsdoc-parser.ts"() {
|
|
3241
3315
|
"use strict";
|
|
3242
3316
|
init_resolve_custom_type();
|
|
3243
|
-
|
|
3317
|
+
init_builtin_brands();
|
|
3318
|
+
SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
3244
3319
|
MAX_HINT_CANDIDATES = 5;
|
|
3245
3320
|
MAX_HINT_DEPTH = 3;
|
|
3246
3321
|
parseResultCache = /* @__PURE__ */ new Map();
|
|
@@ -3248,7 +3323,7 @@ var init_tsdoc_parser = __esm({
|
|
|
3248
3323
|
});
|
|
3249
3324
|
|
|
3250
3325
|
// src/analyzer/jsdoc-constraints.ts
|
|
3251
|
-
import * as
|
|
3326
|
+
import * as ts5 from "typescript";
|
|
3252
3327
|
function extractJSDocParseResult(node, file = "", options) {
|
|
3253
3328
|
return parseTSDocTags(node, file, options);
|
|
3254
3329
|
}
|
|
@@ -3263,18 +3338,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3263
3338
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3264
3339
|
if (!initializer) return null;
|
|
3265
3340
|
let value;
|
|
3266
|
-
if (
|
|
3341
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
3267
3342
|
value = initializer.text;
|
|
3268
|
-
} else if (
|
|
3343
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
3269
3344
|
value = Number(initializer.text);
|
|
3270
|
-
} else if (initializer.kind ===
|
|
3345
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
3271
3346
|
value = true;
|
|
3272
|
-
} else if (initializer.kind ===
|
|
3347
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
3273
3348
|
value = false;
|
|
3274
|
-
} else if (initializer.kind ===
|
|
3349
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
3275
3350
|
value = null;
|
|
3276
|
-
} else if (
|
|
3277
|
-
if (initializer.operator ===
|
|
3351
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
3352
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
3278
3353
|
value = -Number(initializer.operand.text);
|
|
3279
3354
|
}
|
|
3280
3355
|
}
|
|
@@ -3301,44 +3376,34 @@ var init_jsdoc_constraints = __esm({
|
|
|
3301
3376
|
});
|
|
3302
3377
|
|
|
3303
3378
|
// src/analyzer/class-analyzer.ts
|
|
3304
|
-
import * as
|
|
3379
|
+
import * as ts6 from "typescript";
|
|
3305
3380
|
import {
|
|
3306
3381
|
analyzeMetadataForNodeWithChecker,
|
|
3307
3382
|
parseCommentBlock
|
|
3308
3383
|
} from "@formspec/analysis/internal";
|
|
3309
3384
|
function isObjectType(type) {
|
|
3310
|
-
return !!(type.flags &
|
|
3385
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
3311
3386
|
}
|
|
3312
3387
|
function isIntersectionType(type) {
|
|
3313
|
-
return !!(type.flags &
|
|
3314
|
-
}
|
|
3315
|
-
function isIntegerBrandedType(type) {
|
|
3316
|
-
if (!type.isIntersection()) {
|
|
3317
|
-
return false;
|
|
3318
|
-
}
|
|
3319
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3320
|
-
if (!hasNumberBase) {
|
|
3321
|
-
return false;
|
|
3322
|
-
}
|
|
3323
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3388
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
3324
3389
|
}
|
|
3325
3390
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3326
|
-
if (
|
|
3391
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3327
3392
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3328
3393
|
}
|
|
3329
|
-
if (
|
|
3394
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
3330
3395
|
return true;
|
|
3331
3396
|
}
|
|
3332
|
-
return
|
|
3397
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3333
3398
|
}
|
|
3334
3399
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3335
3400
|
if (isIntersectionType(type)) {
|
|
3336
3401
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3337
3402
|
}
|
|
3338
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3403
|
+
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);
|
|
3339
3404
|
}
|
|
3340
3405
|
function isTypeReference(type) {
|
|
3341
|
-
return !!(type.flags &
|
|
3406
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
3342
3407
|
}
|
|
3343
3408
|
function makeParseOptions(extensionRegistry, fieldType, checker, subjectType, hostType) {
|
|
3344
3409
|
if (extensionRegistry === void 0 && fieldType === void 0 && checker === void 0 && subjectType === void 0 && hostType === void 0) {
|
|
@@ -3398,7 +3463,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3398
3463
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3399
3464
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3400
3465
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3401
|
-
const logicalName =
|
|
3466
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3402
3467
|
const docResult = extractJSDocParseResult(
|
|
3403
3468
|
declaration,
|
|
3404
3469
|
file,
|
|
@@ -3446,7 +3511,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3446
3511
|
const instanceMethods = [];
|
|
3447
3512
|
const staticMethods = [];
|
|
3448
3513
|
for (const member of classDecl.members) {
|
|
3449
|
-
if (
|
|
3514
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
3450
3515
|
const fieldNode = analyzeFieldToIR(
|
|
3451
3516
|
member,
|
|
3452
3517
|
checker,
|
|
@@ -3462,10 +3527,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3462
3527
|
fields.push(fieldNode);
|
|
3463
3528
|
fieldLayouts.push({});
|
|
3464
3529
|
}
|
|
3465
|
-
} else if (
|
|
3530
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
3466
3531
|
const methodInfo = analyzeMethod(member, checker);
|
|
3467
3532
|
if (methodInfo) {
|
|
3468
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3533
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
3469
3534
|
if (isStatic) {
|
|
3470
3535
|
staticMethods.push(methodInfo);
|
|
3471
3536
|
} else {
|
|
@@ -3528,7 +3593,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3528
3593
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3529
3594
|
const visiting = /* @__PURE__ */ new Set();
|
|
3530
3595
|
for (const member of interfaceDecl.members) {
|
|
3531
|
-
if (
|
|
3596
|
+
if (ts6.isPropertySignature(member)) {
|
|
3532
3597
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3533
3598
|
member,
|
|
3534
3599
|
checker,
|
|
@@ -3586,7 +3651,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3586
3651
|
if (members === null) {
|
|
3587
3652
|
const sourceFile = typeAlias.getSourceFile();
|
|
3588
3653
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3589
|
-
const kindDesc =
|
|
3654
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3590
3655
|
return {
|
|
3591
3656
|
ok: false,
|
|
3592
3657
|
kind: "not-object-like",
|
|
@@ -3621,7 +3686,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3621
3686
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3622
3687
|
const visiting = /* @__PURE__ */ new Set();
|
|
3623
3688
|
for (const member of members) {
|
|
3624
|
-
if (
|
|
3689
|
+
if (ts6.isPropertySignature(member)) {
|
|
3625
3690
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3626
3691
|
member,
|
|
3627
3692
|
checker,
|
|
@@ -3688,13 +3753,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3688
3753
|
function getLeadingParsedTags(node) {
|
|
3689
3754
|
const sourceFile = node.getSourceFile();
|
|
3690
3755
|
const sourceText = sourceFile.getFullText();
|
|
3691
|
-
const commentRanges =
|
|
3756
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3692
3757
|
if (commentRanges === void 0) {
|
|
3693
3758
|
return [];
|
|
3694
3759
|
}
|
|
3695
3760
|
const parsedTags = [];
|
|
3696
3761
|
for (const range of commentRanges) {
|
|
3697
|
-
if (range.kind !==
|
|
3762
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
3698
3763
|
continue;
|
|
3699
3764
|
}
|
|
3700
3765
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3712,19 +3777,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3712
3777
|
return null;
|
|
3713
3778
|
}
|
|
3714
3779
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3715
|
-
(candidate) =>
|
|
3780
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
3716
3781
|
) ?? propertySymbol.declarations?.[0];
|
|
3717
3782
|
return {
|
|
3718
3783
|
declaration,
|
|
3719
3784
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3720
|
-
optional: !!(propertySymbol.flags &
|
|
3785
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3721
3786
|
};
|
|
3722
3787
|
}
|
|
3723
3788
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3724
3789
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3725
3790
|
}
|
|
3726
3791
|
function isNullishSemanticType(type) {
|
|
3727
|
-
if (type.flags & (
|
|
3792
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
3728
3793
|
return true;
|
|
3729
3794
|
}
|
|
3730
3795
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3734,7 +3799,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3734
3799
|
return false;
|
|
3735
3800
|
}
|
|
3736
3801
|
seen.add(type);
|
|
3737
|
-
if (type.flags &
|
|
3802
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
3738
3803
|
return true;
|
|
3739
3804
|
}
|
|
3740
3805
|
if (type.isUnion()) {
|
|
@@ -3747,13 +3812,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3747
3812
|
return false;
|
|
3748
3813
|
}
|
|
3749
3814
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3750
|
-
if (
|
|
3815
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3751
3816
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3752
3817
|
}
|
|
3753
|
-
if (
|
|
3818
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
3754
3819
|
return [...typeNode.members];
|
|
3755
3820
|
}
|
|
3756
|
-
if (
|
|
3821
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
3757
3822
|
const members = [];
|
|
3758
3823
|
for (const intersectionMember of typeNode.types) {
|
|
3759
3824
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3916,7 +3981,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3916
3981
|
}
|
|
3917
3982
|
if (propertyType.isUnion()) {
|
|
3918
3983
|
const nonNullMembers = propertyType.types.filter(
|
|
3919
|
-
(member) => !(member.flags & (
|
|
3984
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3920
3985
|
);
|
|
3921
3986
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3922
3987
|
diagnostics.push(
|
|
@@ -3965,13 +4030,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3965
4030
|
seen.add(type);
|
|
3966
4031
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3967
4032
|
if (symbol !== void 0) {
|
|
3968
|
-
const aliased = symbol.flags &
|
|
4033
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3969
4034
|
const targetSymbol = aliased ?? symbol;
|
|
3970
4035
|
const declaration = targetSymbol.declarations?.find(
|
|
3971
|
-
(candidate) =>
|
|
4036
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
3972
4037
|
);
|
|
3973
4038
|
if (declaration !== void 0) {
|
|
3974
|
-
if (
|
|
4039
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3975
4040
|
return resolveNamedDiscriminatorDeclaration(
|
|
3976
4041
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3977
4042
|
checker,
|
|
@@ -3999,7 +4064,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3999
4064
|
}
|
|
4000
4065
|
if (boundType.isUnion()) {
|
|
4001
4066
|
const nonNullMembers = boundType.types.filter(
|
|
4002
|
-
(member) => !(member.flags & (
|
|
4067
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4003
4068
|
);
|
|
4004
4069
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4005
4070
|
diagnostics.push(
|
|
@@ -4044,7 +4109,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4044
4109
|
return null;
|
|
4045
4110
|
}
|
|
4046
4111
|
function getDeclarationName(node) {
|
|
4047
|
-
if (
|
|
4112
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
4048
4113
|
return node.name?.text ?? "anonymous";
|
|
4049
4114
|
}
|
|
4050
4115
|
return "anonymous";
|
|
@@ -4099,11 +4164,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4099
4164
|
if (sourceTypeNode === void 0) {
|
|
4100
4165
|
return [];
|
|
4101
4166
|
}
|
|
4102
|
-
const unwrapParentheses = (typeNode) =>
|
|
4167
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4103
4168
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4104
|
-
const referenceTypeNode =
|
|
4169
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4105
4170
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4106
|
-
return
|
|
4171
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4107
4172
|
})();
|
|
4108
4173
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4109
4174
|
return [];
|
|
@@ -4158,7 +4223,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4158
4223
|
);
|
|
4159
4224
|
}
|
|
4160
4225
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4161
|
-
if (!
|
|
4226
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
4162
4227
|
return null;
|
|
4163
4228
|
}
|
|
4164
4229
|
const name = prop.name.text;
|
|
@@ -4285,7 +4350,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4285
4350
|
const seen = /* @__PURE__ */ new Set();
|
|
4286
4351
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4287
4352
|
for (const member of members) {
|
|
4288
|
-
if (!
|
|
4353
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4289
4354
|
continue;
|
|
4290
4355
|
}
|
|
4291
4356
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4301,7 +4366,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4301
4366
|
return [...duplicates].sort();
|
|
4302
4367
|
}
|
|
4303
4368
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4304
|
-
if (
|
|
4369
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
4305
4370
|
return name.text;
|
|
4306
4371
|
}
|
|
4307
4372
|
return null;
|
|
@@ -4399,25 +4464,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4399
4464
|
if (isIntegerBrandedType(type)) {
|
|
4400
4465
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4401
4466
|
}
|
|
4402
|
-
if (type.flags &
|
|
4467
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4403
4468
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4404
4469
|
}
|
|
4405
|
-
if (type.flags &
|
|
4470
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4406
4471
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4407
4472
|
}
|
|
4408
|
-
if (type.flags & (
|
|
4473
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4409
4474
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4410
4475
|
}
|
|
4411
|
-
if (type.flags &
|
|
4476
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4412
4477
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4413
4478
|
}
|
|
4414
|
-
if (type.flags &
|
|
4479
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4415
4480
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4416
4481
|
}
|
|
4417
|
-
if (type.flags &
|
|
4482
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
4418
4483
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4419
4484
|
}
|
|
4420
|
-
if (type.flags &
|
|
4485
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
4421
4486
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4422
4487
|
}
|
|
4423
4488
|
if (type.isStringLiteral()) {
|
|
@@ -4504,10 +4569,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4504
4569
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4505
4570
|
}
|
|
4506
4571
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4507
|
-
if (!(type.flags & (
|
|
4572
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4508
4573
|
return null;
|
|
4509
4574
|
}
|
|
4510
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4575
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4511
4576
|
if (!aliasDecl) {
|
|
4512
4577
|
return null;
|
|
4513
4578
|
}
|
|
@@ -4557,14 +4622,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4557
4622
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4558
4623
|
}
|
|
4559
4624
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4560
|
-
const typeNode = sourceNode && (
|
|
4561
|
-
if (!typeNode || !
|
|
4625
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4626
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
4562
4627
|
return void 0;
|
|
4563
4628
|
}
|
|
4564
4629
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4565
4630
|
}
|
|
4566
4631
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4567
|
-
if (!
|
|
4632
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
4568
4633
|
return false;
|
|
4569
4634
|
}
|
|
4570
4635
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4572,10 +4637,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4572
4637
|
return false;
|
|
4573
4638
|
}
|
|
4574
4639
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4575
|
-
return !!(resolved.flags & (
|
|
4640
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
4576
4641
|
}
|
|
4577
4642
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4578
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4643
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
4579
4644
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4580
4645
|
visitedAliases.add(nestedAliasDecl);
|
|
4581
4646
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4593,19 +4658,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4593
4658
|
if (isIntegerBrandedType(type)) {
|
|
4594
4659
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4595
4660
|
}
|
|
4596
|
-
if (type.flags &
|
|
4661
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4597
4662
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4598
4663
|
}
|
|
4599
|
-
if (type.flags &
|
|
4664
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4600
4665
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4601
4666
|
}
|
|
4602
|
-
if (type.flags & (
|
|
4667
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4603
4668
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4604
4669
|
}
|
|
4605
|
-
if (type.flags &
|
|
4670
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4606
4671
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4607
4672
|
}
|
|
4608
|
-
if (type.flags &
|
|
4673
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4609
4674
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4610
4675
|
}
|
|
4611
4676
|
return resolveTypeNode(
|
|
@@ -4632,13 +4697,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4632
4697
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4633
4698
|
);
|
|
4634
4699
|
const nonNullTypes = allTypes.filter(
|
|
4635
|
-
(memberType) => !(memberType.flags & (
|
|
4700
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4636
4701
|
);
|
|
4637
4702
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4638
4703
|
memberType,
|
|
4639
4704
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4640
4705
|
}));
|
|
4641
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4706
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
4642
4707
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4643
4708
|
if (namedDecl) {
|
|
4644
4709
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4681,7 +4746,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4681
4746
|
const displayName = memberDisplayNames.get(String(value));
|
|
4682
4747
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4683
4748
|
});
|
|
4684
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4749
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
4685
4750
|
if (isBooleanUnion2) {
|
|
4686
4751
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4687
4752
|
const result = hasNull ? {
|
|
@@ -4773,7 +4838,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4773
4838
|
if (type.getProperties().length > 0) {
|
|
4774
4839
|
return null;
|
|
4775
4840
|
}
|
|
4776
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4841
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
4777
4842
|
if (!indexInfo) {
|
|
4778
4843
|
return null;
|
|
4779
4844
|
}
|
|
@@ -4821,10 +4886,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4821
4886
|
}
|
|
4822
4887
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4823
4888
|
const name = declaration.name;
|
|
4824
|
-
if (
|
|
4889
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
4825
4890
|
return false;
|
|
4826
4891
|
}
|
|
4827
|
-
if (!
|
|
4892
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
4828
4893
|
return false;
|
|
4829
4894
|
}
|
|
4830
4895
|
}
|
|
@@ -4950,7 +5015,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4950
5015
|
if (!declaration) continue;
|
|
4951
5016
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4952
5017
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4953
|
-
const optional = !!(prop.flags &
|
|
5018
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
4954
5019
|
const propTypeNode = resolveTypeNode(
|
|
4955
5020
|
propType,
|
|
4956
5021
|
checker,
|
|
@@ -4963,7 +5028,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4963
5028
|
collectedDiagnostics
|
|
4964
5029
|
);
|
|
4965
5030
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4966
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
5031
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4967
5032
|
declaration,
|
|
4968
5033
|
checker,
|
|
4969
5034
|
file,
|
|
@@ -4973,7 +5038,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4973
5038
|
type,
|
|
4974
5039
|
metadataPolicy,
|
|
4975
5040
|
extensionRegistry
|
|
4976
|
-
) :
|
|
5041
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4977
5042
|
declaration,
|
|
4978
5043
|
checker,
|
|
4979
5044
|
file,
|
|
@@ -5001,7 +5066,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5001
5066
|
visiting.delete(type);
|
|
5002
5067
|
const objectNode = {
|
|
5003
5068
|
kind: "object",
|
|
5004
|
-
properties: namedDecl !== void 0 && (
|
|
5069
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
5005
5070
|
properties,
|
|
5006
5071
|
namedDecl,
|
|
5007
5072
|
type,
|
|
@@ -5049,12 +5114,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5049
5114
|
for (const symbol of symbols) {
|
|
5050
5115
|
const declarations = symbol.declarations;
|
|
5051
5116
|
if (!declarations) continue;
|
|
5052
|
-
const classDecl = declarations.find(
|
|
5117
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
5053
5118
|
if (classDecl) {
|
|
5054
5119
|
const map = /* @__PURE__ */ new Map();
|
|
5055
5120
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5056
5121
|
for (const member of classDecl.members) {
|
|
5057
|
-
if (
|
|
5122
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
5058
5123
|
const fieldNode = analyzeFieldToIR(
|
|
5059
5124
|
member,
|
|
5060
5125
|
checker,
|
|
@@ -5078,7 +5143,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5078
5143
|
}
|
|
5079
5144
|
return map;
|
|
5080
5145
|
}
|
|
5081
|
-
const interfaceDecl = declarations.find(
|
|
5146
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
5082
5147
|
if (interfaceDecl) {
|
|
5083
5148
|
return buildFieldNodeInfoMap(
|
|
5084
5149
|
interfaceDecl.members,
|
|
@@ -5092,7 +5157,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5092
5157
|
extensionRegistry
|
|
5093
5158
|
);
|
|
5094
5159
|
}
|
|
5095
|
-
const typeAliasDecl = declarations.find(
|
|
5160
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
5096
5161
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5097
5162
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5098
5163
|
return buildFieldNodeInfoMap(
|
|
@@ -5116,10 +5181,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5116
5181
|
return void 0;
|
|
5117
5182
|
}
|
|
5118
5183
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5119
|
-
if (
|
|
5184
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
5120
5185
|
return resolvedTypeNode.elementType;
|
|
5121
5186
|
}
|
|
5122
|
-
if (
|
|
5187
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5123
5188
|
return resolvedTypeNode.typeArguments[0];
|
|
5124
5189
|
}
|
|
5125
5190
|
return void 0;
|
|
@@ -5130,13 +5195,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5130
5195
|
return [];
|
|
5131
5196
|
}
|
|
5132
5197
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5133
|
-
return
|
|
5198
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5134
5199
|
}
|
|
5135
5200
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5136
|
-
if (
|
|
5201
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5137
5202
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5138
5203
|
}
|
|
5139
|
-
if (!
|
|
5204
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
5140
5205
|
return typeNode;
|
|
5141
5206
|
}
|
|
5142
5207
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5147,15 +5212,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5147
5212
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5148
5213
|
}
|
|
5149
5214
|
function isNullishTypeNode(typeNode) {
|
|
5150
|
-
if (typeNode.kind ===
|
|
5215
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
5151
5216
|
return true;
|
|
5152
5217
|
}
|
|
5153
|
-
return
|
|
5218
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
5154
5219
|
}
|
|
5155
5220
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5156
5221
|
const map = /* @__PURE__ */ new Map();
|
|
5157
5222
|
for (const member of members) {
|
|
5158
|
-
if (
|
|
5223
|
+
if (ts6.isPropertySignature(member)) {
|
|
5159
5224
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5160
5225
|
member,
|
|
5161
5226
|
checker,
|
|
@@ -5180,7 +5245,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5180
5245
|
return map;
|
|
5181
5246
|
}
|
|
5182
5247
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5183
|
-
if (!
|
|
5248
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
5184
5249
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5185
5250
|
const aliasName = typeNode.typeName.getText();
|
|
5186
5251
|
throw new Error(
|
|
@@ -5189,7 +5254,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5189
5254
|
}
|
|
5190
5255
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5191
5256
|
if (!aliasDecl) return [];
|
|
5192
|
-
if (
|
|
5257
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5193
5258
|
const aliasFieldType = resolveTypeNode(
|
|
5194
5259
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5195
5260
|
checker,
|
|
@@ -5233,14 +5298,14 @@ function getNamedTypeName(type) {
|
|
|
5233
5298
|
const symbol = type.getSymbol();
|
|
5234
5299
|
if (symbol?.declarations) {
|
|
5235
5300
|
const decl = symbol.declarations[0];
|
|
5236
|
-
if (decl && (
|
|
5237
|
-
const name =
|
|
5301
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5302
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5238
5303
|
if (name) return name;
|
|
5239
5304
|
}
|
|
5240
5305
|
}
|
|
5241
5306
|
const aliasSymbol = type.aliasSymbol;
|
|
5242
5307
|
if (aliasSymbol?.declarations) {
|
|
5243
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5308
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5244
5309
|
if (aliasDecl) {
|
|
5245
5310
|
return aliasDecl.name.text;
|
|
5246
5311
|
}
|
|
@@ -5251,24 +5316,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5251
5316
|
const symbol = type.getSymbol();
|
|
5252
5317
|
if (symbol?.declarations) {
|
|
5253
5318
|
const decl = symbol.declarations[0];
|
|
5254
|
-
if (decl && (
|
|
5319
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5255
5320
|
return decl;
|
|
5256
5321
|
}
|
|
5257
5322
|
}
|
|
5258
5323
|
const aliasSymbol = type.aliasSymbol;
|
|
5259
5324
|
if (aliasSymbol?.declarations) {
|
|
5260
|
-
return aliasSymbol.declarations.find(
|
|
5325
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5261
5326
|
}
|
|
5262
5327
|
return void 0;
|
|
5263
5328
|
}
|
|
5264
5329
|
function analyzeMethod(method, checker) {
|
|
5265
|
-
if (!
|
|
5330
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
5266
5331
|
return null;
|
|
5267
5332
|
}
|
|
5268
5333
|
const name = method.name.text;
|
|
5269
5334
|
const parameters = [];
|
|
5270
5335
|
for (const param of method.parameters) {
|
|
5271
|
-
if (
|
|
5336
|
+
if (ts6.isIdentifier(param.name)) {
|
|
5272
5337
|
const paramInfo = analyzeParameter(param, checker);
|
|
5273
5338
|
parameters.push(paramInfo);
|
|
5274
5339
|
}
|
|
@@ -5279,7 +5344,7 @@ function analyzeMethod(method, checker) {
|
|
|
5279
5344
|
return { name, parameters, returnTypeNode, returnType };
|
|
5280
5345
|
}
|
|
5281
5346
|
function analyzeParameter(param, checker) {
|
|
5282
|
-
const name =
|
|
5347
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
5283
5348
|
const typeNode = param.type;
|
|
5284
5349
|
const type = checker.getTypeAtLocation(param);
|
|
5285
5350
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5288,15 +5353,15 @@ function analyzeParameter(param, checker) {
|
|
|
5288
5353
|
}
|
|
5289
5354
|
function detectFormSpecReference(typeNode) {
|
|
5290
5355
|
if (!typeNode) return null;
|
|
5291
|
-
if (!
|
|
5292
|
-
const typeName =
|
|
5356
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
5357
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5293
5358
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5294
5359
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5295
|
-
if (!typeArg || !
|
|
5296
|
-
if (
|
|
5360
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
5361
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
5297
5362
|
return typeArg.exprName.text;
|
|
5298
5363
|
}
|
|
5299
|
-
if (
|
|
5364
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
5300
5365
|
return typeArg.exprName.right.text;
|
|
5301
5366
|
}
|
|
5302
5367
|
return null;
|
|
@@ -5309,6 +5374,7 @@ var init_class_analyzer = __esm({
|
|
|
5309
5374
|
init_tsdoc_parser();
|
|
5310
5375
|
init_resolve_custom_type();
|
|
5311
5376
|
init_ts_type_utils();
|
|
5377
|
+
init_builtin_brands();
|
|
5312
5378
|
init_metadata();
|
|
5313
5379
|
RESOLVING_TYPE_PLACEHOLDER = {
|
|
5314
5380
|
kind: "object",
|
|
@@ -5320,7 +5386,7 @@ var init_class_analyzer = __esm({
|
|
|
5320
5386
|
});
|
|
5321
5387
|
|
|
5322
5388
|
// src/analyzer/program.ts
|
|
5323
|
-
import * as
|
|
5389
|
+
import * as ts7 from "typescript";
|
|
5324
5390
|
import * as path from "path";
|
|
5325
5391
|
function createProgramContextFromProgram(program, filePath) {
|
|
5326
5392
|
const absolutePath = path.resolve(filePath);
|
|
@@ -5337,23 +5403,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5337
5403
|
function createProgramContext(filePath, additionalFiles) {
|
|
5338
5404
|
const absolutePath = path.resolve(filePath);
|
|
5339
5405
|
const fileDir = path.dirname(absolutePath);
|
|
5340
|
-
const configPath =
|
|
5406
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
5341
5407
|
let compilerOptions;
|
|
5342
5408
|
let fileNames;
|
|
5343
5409
|
if (configPath) {
|
|
5344
|
-
const configFile =
|
|
5410
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
5345
5411
|
if (configFile.error) {
|
|
5346
5412
|
throw new Error(
|
|
5347
|
-
`Error reading tsconfig.json: ${
|
|
5413
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5348
5414
|
);
|
|
5349
5415
|
}
|
|
5350
|
-
const parsed =
|
|
5416
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
5351
5417
|
configFile.config,
|
|
5352
|
-
|
|
5418
|
+
ts7.sys,
|
|
5353
5419
|
path.dirname(configPath)
|
|
5354
5420
|
);
|
|
5355
5421
|
if (parsed.errors.length > 0) {
|
|
5356
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5422
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5357
5423
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5358
5424
|
}
|
|
5359
5425
|
compilerOptions = parsed.options;
|
|
@@ -5361,9 +5427,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5361
5427
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5362
5428
|
} else {
|
|
5363
5429
|
compilerOptions = {
|
|
5364
|
-
target:
|
|
5365
|
-
module:
|
|
5366
|
-
moduleResolution:
|
|
5430
|
+
target: ts7.ScriptTarget.ES2022,
|
|
5431
|
+
module: ts7.ModuleKind.NodeNext,
|
|
5432
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
5367
5433
|
strict: true,
|
|
5368
5434
|
skipLibCheck: true,
|
|
5369
5435
|
declaration: true
|
|
@@ -5371,7 +5437,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5371
5437
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5372
5438
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5373
5439
|
}
|
|
5374
|
-
const program =
|
|
5440
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
5375
5441
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5376
5442
|
if (!sourceFile) {
|
|
5377
5443
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5390,19 +5456,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5390
5456
|
result = node;
|
|
5391
5457
|
return;
|
|
5392
5458
|
}
|
|
5393
|
-
|
|
5459
|
+
ts7.forEachChild(node, visit);
|
|
5394
5460
|
}
|
|
5395
5461
|
visit(sourceFile);
|
|
5396
5462
|
return result;
|
|
5397
5463
|
}
|
|
5398
5464
|
function findClassByName(sourceFile, className) {
|
|
5399
|
-
return findNodeByName(sourceFile, className,
|
|
5465
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
5400
5466
|
}
|
|
5401
5467
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5402
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5468
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
5403
5469
|
}
|
|
5404
5470
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5405
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5471
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5406
5472
|
}
|
|
5407
5473
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5408
5474
|
if (rootType.kind === "object") {
|
|
@@ -5442,22 +5508,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5442
5508
|
};
|
|
5443
5509
|
}
|
|
5444
5510
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5445
|
-
if (
|
|
5511
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5446
5512
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5447
5513
|
}
|
|
5448
|
-
if (
|
|
5514
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5449
5515
|
return true;
|
|
5450
5516
|
}
|
|
5451
|
-
return
|
|
5517
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5452
5518
|
}
|
|
5453
5519
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5454
|
-
if (
|
|
5520
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5455
5521
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5456
5522
|
}
|
|
5457
|
-
if (
|
|
5523
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
5458
5524
|
const propertyNames = [];
|
|
5459
5525
|
for (const member of typeNode.members) {
|
|
5460
|
-
if (!
|
|
5526
|
+
if (!ts7.isPropertySignature(member)) {
|
|
5461
5527
|
continue;
|
|
5462
5528
|
}
|
|
5463
5529
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5467,13 +5533,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5467
5533
|
}
|
|
5468
5534
|
return propertyNames;
|
|
5469
5535
|
}
|
|
5470
|
-
if (
|
|
5536
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5471
5537
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5472
5538
|
}
|
|
5473
5539
|
return null;
|
|
5474
5540
|
}
|
|
5475
5541
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5476
|
-
if (!
|
|
5542
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
5477
5543
|
return [];
|
|
5478
5544
|
}
|
|
5479
5545
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5680,7 +5746,7 @@ var init_program = __esm({
|
|
|
5680
5746
|
});
|
|
5681
5747
|
|
|
5682
5748
|
// src/extensions/symbol-registry.ts
|
|
5683
|
-
import * as
|
|
5749
|
+
import * as ts8 from "typescript";
|
|
5684
5750
|
import * as path2 from "path";
|
|
5685
5751
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5686
5752
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5690,10 +5756,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5690
5756
|
return symbolMap;
|
|
5691
5757
|
}
|
|
5692
5758
|
function visit(node) {
|
|
5693
|
-
if (
|
|
5759
|
+
if (ts8.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5694
5760
|
processDefineCustomTypeCall(node);
|
|
5695
5761
|
}
|
|
5696
|
-
|
|
5762
|
+
ts8.forEachChild(node, visit);
|
|
5697
5763
|
}
|
|
5698
5764
|
function processDefineCustomTypeCall(call) {
|
|
5699
5765
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5730,7 +5796,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5730
5796
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5731
5797
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5732
5798
|
if (callSymbol !== void 0) {
|
|
5733
|
-
const resolved = callSymbol.flags &
|
|
5799
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5734
5800
|
const decl = resolved.declarations?.[0];
|
|
5735
5801
|
if (decl !== void 0) {
|
|
5736
5802
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5738,24 +5804,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5738
5804
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5739
5805
|
}
|
|
5740
5806
|
}
|
|
5741
|
-
return
|
|
5807
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5742
5808
|
}
|
|
5743
5809
|
function extractTypeNameFromCallArg(call) {
|
|
5744
5810
|
const arg = call.arguments[0];
|
|
5745
|
-
if (arg === void 0 || !
|
|
5811
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5746
5812
|
return null;
|
|
5747
5813
|
}
|
|
5748
5814
|
const typeNameProp = arg.properties.find(
|
|
5749
|
-
(p) =>
|
|
5815
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5750
5816
|
);
|
|
5751
|
-
if (typeNameProp === void 0 || !
|
|
5817
|
+
if (typeNameProp === void 0 || !ts8.isStringLiteral(typeNameProp.initializer)) {
|
|
5752
5818
|
return null;
|
|
5753
5819
|
}
|
|
5754
5820
|
return typeNameProp.initializer.text;
|
|
5755
5821
|
}
|
|
5756
5822
|
function extractEnclosingExtensionId(call, checker) {
|
|
5757
|
-
for (let node = call.parent; !
|
|
5758
|
-
if (
|
|
5823
|
+
for (let node = call.parent; !ts8.isSourceFile(node); node = node.parent) {
|
|
5824
|
+
if (ts8.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5759
5825
|
return extractExtensionIdFromCallArg(node);
|
|
5760
5826
|
}
|
|
5761
5827
|
}
|
|
@@ -5764,24 +5830,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5764
5830
|
function isDefineExtensionCall(node, checker) {
|
|
5765
5831
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5766
5832
|
if (callSymbol !== void 0) {
|
|
5767
|
-
const resolved = callSymbol.flags &
|
|
5833
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5768
5834
|
const decl = resolved.declarations?.[0];
|
|
5769
5835
|
if (decl !== void 0) {
|
|
5770
5836
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5771
5837
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5772
5838
|
}
|
|
5773
5839
|
}
|
|
5774
|
-
return
|
|
5840
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5775
5841
|
}
|
|
5776
5842
|
function extractExtensionIdFromCallArg(call) {
|
|
5777
5843
|
const arg = call.arguments[0];
|
|
5778
|
-
if (arg === void 0 || !
|
|
5844
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5779
5845
|
return null;
|
|
5780
5846
|
}
|
|
5781
5847
|
const prop = arg.properties.find(
|
|
5782
|
-
(p) =>
|
|
5848
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5783
5849
|
);
|
|
5784
|
-
if (prop === void 0 || !
|
|
5850
|
+
if (prop === void 0 || !ts8.isStringLiteral(prop.initializer)) {
|
|
5785
5851
|
return null;
|
|
5786
5852
|
}
|
|
5787
5853
|
return prop.initializer.text;
|
|
@@ -5893,7 +5959,7 @@ var init_validate = __esm({
|
|
|
5893
5959
|
});
|
|
5894
5960
|
|
|
5895
5961
|
// src/generators/class-schema.ts
|
|
5896
|
-
import * as
|
|
5962
|
+
import * as ts9 from "typescript";
|
|
5897
5963
|
function generateClassSchemas(analysis, source, options) {
|
|
5898
5964
|
const result = generateClassSchemasDetailed(analysis, source, options);
|
|
5899
5965
|
if (!result.ok || result.jsonSchema === void 0 || result.uiSchema === void 0) {
|
|
@@ -6063,7 +6129,7 @@ function generateSchemasBatch(options) {
|
|
|
6063
6129
|
return options.targets.map((target) => {
|
|
6064
6130
|
let ctx;
|
|
6065
6131
|
try {
|
|
6066
|
-
const cacheKey =
|
|
6132
|
+
const cacheKey = ts9.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6067
6133
|
const cachedContext = contextCache.get(cacheKey);
|
|
6068
6134
|
if (cachedContext === void 0) {
|
|
6069
6135
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6232,7 +6298,7 @@ var init_class_schema = __esm({
|
|
|
6232
6298
|
});
|
|
6233
6299
|
|
|
6234
6300
|
// src/static-build.ts
|
|
6235
|
-
import * as
|
|
6301
|
+
import * as ts10 from "typescript";
|
|
6236
6302
|
function toStaticBuildContext(context) {
|
|
6237
6303
|
return context;
|
|
6238
6304
|
}
|
|
@@ -6247,7 +6313,7 @@ function getModuleSymbol(context) {
|
|
|
6247
6313
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6248
6314
|
}
|
|
6249
6315
|
function isSchemaSourceDeclaration(declaration) {
|
|
6250
|
-
return
|
|
6316
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6251
6317
|
}
|
|
6252
6318
|
function resolveModuleExport(context, exportName = "default") {
|
|
6253
6319
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6258,7 +6324,7 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6258
6324
|
if (exportSymbol === null) {
|
|
6259
6325
|
return null;
|
|
6260
6326
|
}
|
|
6261
|
-
return exportSymbol.flags &
|
|
6327
|
+
return exportSymbol.flags & ts10.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6262
6328
|
}
|
|
6263
6329
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6264
6330
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
@@ -6271,7 +6337,7 @@ var init_static_build = __esm({
|
|
|
6271
6337
|
});
|
|
6272
6338
|
|
|
6273
6339
|
// src/generators/discovered-schema.ts
|
|
6274
|
-
import * as
|
|
6340
|
+
import * as ts11 from "typescript";
|
|
6275
6341
|
import { analyzeMetadataForNodeWithChecker as analyzeMetadataForNodeWithChecker2 } from "@formspec/analysis/internal";
|
|
6276
6342
|
import { IR_VERSION as IR_VERSION3 } from "@formspec/core/internals";
|
|
6277
6343
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6281,17 +6347,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6281
6347
|
};
|
|
6282
6348
|
}
|
|
6283
6349
|
function isNamedTypeDeclaration(declaration) {
|
|
6284
|
-
return
|
|
6350
|
+
return ts11.isClassDeclaration(declaration) || ts11.isInterfaceDeclaration(declaration) || ts11.isTypeAliasDeclaration(declaration);
|
|
6285
6351
|
}
|
|
6286
6352
|
function hasConcreteTypeArguments(type, checker) {
|
|
6287
6353
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6288
6354
|
return true;
|
|
6289
6355
|
}
|
|
6290
|
-
if ((type.flags &
|
|
6356
|
+
if ((type.flags & ts11.TypeFlags.Object) === 0) {
|
|
6291
6357
|
return false;
|
|
6292
6358
|
}
|
|
6293
6359
|
const objectType = type;
|
|
6294
|
-
if ((objectType.objectFlags &
|
|
6360
|
+
if ((objectType.objectFlags & ts11.ObjectFlags.Reference) === 0) {
|
|
6295
6361
|
return false;
|
|
6296
6362
|
}
|
|
6297
6363
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6304,13 +6370,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6304
6370
|
return declaration;
|
|
6305
6371
|
}
|
|
6306
6372
|
}
|
|
6307
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6373
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts11.isTypeAliasDeclaration);
|
|
6308
6374
|
return aliasDeclaration;
|
|
6309
6375
|
}
|
|
6310
6376
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6311
6377
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6312
6378
|
const namedNode = sourceNode;
|
|
6313
|
-
if (namedNode.name !== void 0 &&
|
|
6379
|
+
if (namedNode.name !== void 0 && ts11.isIdentifier(namedNode.name)) {
|
|
6314
6380
|
return namedNode.name.text;
|
|
6315
6381
|
}
|
|
6316
6382
|
}
|
|
@@ -6532,7 +6598,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6532
6598
|
function generateSchemasFromDeclaration(options) {
|
|
6533
6599
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6534
6600
|
const resolved = resolveStaticOptions(options);
|
|
6535
|
-
if (
|
|
6601
|
+
if (ts11.isClassDeclaration(options.declaration)) {
|
|
6536
6602
|
return generateSchemasFromAnalysis(
|
|
6537
6603
|
analyzeClassToIR(
|
|
6538
6604
|
options.declaration,
|
|
@@ -6546,7 +6612,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6546
6612
|
resolved
|
|
6547
6613
|
);
|
|
6548
6614
|
}
|
|
6549
|
-
if (
|
|
6615
|
+
if (ts11.isInterfaceDeclaration(options.declaration)) {
|
|
6550
6616
|
return generateSchemasFromAnalysis(
|
|
6551
6617
|
analyzeInterfaceToIR(
|
|
6552
6618
|
options.declaration,
|
|
@@ -6560,7 +6626,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6560
6626
|
resolved
|
|
6561
6627
|
);
|
|
6562
6628
|
}
|
|
6563
|
-
if (
|
|
6629
|
+
if (ts11.isTypeAliasDeclaration(options.declaration)) {
|
|
6564
6630
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6565
6631
|
options.declaration,
|
|
6566
6632
|
options.context.checker,
|
|
@@ -6619,7 +6685,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6619
6685
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6620
6686
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6621
6687
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6622
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6688
|
+
const fallbackName = options.declaration.name !== void 0 && ts11.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6623
6689
|
return generateSchemasFromResolvedType({
|
|
6624
6690
|
...options,
|
|
6625
6691
|
type,
|
|
@@ -6666,14 +6732,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6666
6732
|
if (typeNode === void 0) {
|
|
6667
6733
|
return void 0;
|
|
6668
6734
|
}
|
|
6669
|
-
if (
|
|
6735
|
+
if (ts11.isParenthesizedTypeNode(typeNode)) {
|
|
6670
6736
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6671
6737
|
return unwrapped ?? typeNode;
|
|
6672
6738
|
}
|
|
6673
6739
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6674
6740
|
}
|
|
6675
6741
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6676
|
-
return
|
|
6742
|
+
return ts11.isTypeReferenceNode(typeNode) && ts11.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6677
6743
|
}
|
|
6678
6744
|
var init_discovered_schema = __esm({
|
|
6679
6745
|
"src/generators/discovered-schema.ts"() {
|
|
@@ -6917,9 +6983,12 @@ __export(index_exports, {
|
|
|
6917
6983
|
uiSchemaSchema: () => uiSchema,
|
|
6918
6984
|
writeSchemas: () => writeSchemas
|
|
6919
6985
|
});
|
|
6986
|
+
import { noopLogger as noopLogger4 } from "@formspec/core";
|
|
6920
6987
|
import * as fs from "fs";
|
|
6921
6988
|
import * as path3 from "path";
|
|
6922
6989
|
function buildFormSchemas(form, options) {
|
|
6990
|
+
const logger = options?.logger ?? noopLogger4;
|
|
6991
|
+
logger.debug("buildFormSchemas: starting schema generation");
|
|
6923
6992
|
return {
|
|
6924
6993
|
jsonSchema: generateJsonSchema(form, options),
|
|
6925
6994
|
uiSchema: generateUiSchema(form, options)
|
|
@@ -6932,12 +7001,15 @@ function writeSchemas(form, options) {
|
|
|
6932
7001
|
indent = 2,
|
|
6933
7002
|
vendorPrefix,
|
|
6934
7003
|
enumSerialization,
|
|
6935
|
-
metadata
|
|
7004
|
+
metadata,
|
|
7005
|
+
logger: rawLogger
|
|
6936
7006
|
} = options;
|
|
6937
|
-
const
|
|
7007
|
+
const logger = (rawLogger ?? noopLogger4).child({ stage: "write" });
|
|
7008
|
+
const buildOptions = vendorPrefix === void 0 && enumSerialization === void 0 && metadata === void 0 ? { logger: rawLogger } : {
|
|
6938
7009
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
6939
7010
|
...enumSerialization !== void 0 && { enumSerialization },
|
|
6940
|
-
...metadata !== void 0 && { metadata }
|
|
7011
|
+
...metadata !== void 0 && { metadata },
|
|
7012
|
+
logger: rawLogger
|
|
6941
7013
|
};
|
|
6942
7014
|
const { jsonSchema, uiSchema: uiSchema2 } = buildFormSchemas(form, buildOptions);
|
|
6943
7015
|
if (!fs.existsSync(outDir)) {
|
|
@@ -6945,7 +7017,9 @@ function writeSchemas(form, options) {
|
|
|
6945
7017
|
}
|
|
6946
7018
|
const jsonSchemaPath = path3.join(outDir, `${name}-schema.json`);
|
|
6947
7019
|
const uiSchemaPath = path3.join(outDir, `${name}-uischema.json`);
|
|
7020
|
+
logger.debug("writing JSON Schema", { path: jsonSchemaPath });
|
|
6948
7021
|
fs.writeFileSync(jsonSchemaPath, JSON.stringify(jsonSchema, null, indent));
|
|
7022
|
+
logger.debug("writing UI Schema", { path: uiSchemaPath });
|
|
6949
7023
|
fs.writeFileSync(uiSchemaPath, JSON.stringify(uiSchema2, null, indent));
|
|
6950
7024
|
return { jsonSchemaPath, uiSchemaPath };
|
|
6951
7025
|
}
|
|
@@ -6973,6 +7047,33 @@ var init_index = __esm({
|
|
|
6973
7047
|
// src/cli.ts
|
|
6974
7048
|
import * as path4 from "path";
|
|
6975
7049
|
import { pathToFileURL } from "url";
|
|
7050
|
+
|
|
7051
|
+
// src/cli/logger.ts
|
|
7052
|
+
import { createRequire } from "module";
|
|
7053
|
+
import { isNamespaceEnabled, noopLogger } from "@formspec/core";
|
|
7054
|
+
var require2 = createRequire(import.meta.url);
|
|
7055
|
+
function createLogger(namespace) {
|
|
7056
|
+
const debugEnv = process.env["DEBUG"] ?? "";
|
|
7057
|
+
if (!isNamespaceEnabled(debugEnv, namespace)) {
|
|
7058
|
+
return noopLogger;
|
|
7059
|
+
}
|
|
7060
|
+
const pinoModule = require2("pino");
|
|
7061
|
+
const pino = typeof pinoModule === "function" ? pinoModule : pinoModule.default;
|
|
7062
|
+
const isTTY = process.stderr.isTTY;
|
|
7063
|
+
if (isTTY) {
|
|
7064
|
+
const pinoPretty = require2("pino-pretty");
|
|
7065
|
+
const prettyTransport = pinoPretty.default ?? pinoPretty;
|
|
7066
|
+
const stream = prettyTransport({ destination: 2, colorize: true, sync: true });
|
|
7067
|
+
return pino({ name: namespace, level: "debug" }, stream);
|
|
7068
|
+
}
|
|
7069
|
+
return pino(
|
|
7070
|
+
{ name: namespace, level: "debug" },
|
|
7071
|
+
pino.destination({ dest: 2, sync: true })
|
|
7072
|
+
);
|
|
7073
|
+
}
|
|
7074
|
+
|
|
7075
|
+
// src/cli.ts
|
|
7076
|
+
var log = createLogger("formspec:build");
|
|
6976
7077
|
function printHelp() {
|
|
6977
7078
|
console.log(`
|
|
6978
7079
|
FormSpec Build CLI - Generate JSON Schema and UI Schema
|
|
@@ -7062,6 +7163,7 @@ function parseArgs(args) {
|
|
|
7062
7163
|
if (!name) {
|
|
7063
7164
|
name = path4.basename(inputFile, path4.extname(inputFile));
|
|
7064
7165
|
}
|
|
7166
|
+
log.debug("Arguments parsed", { inputFile, outDir, name, enumSerialization });
|
|
7065
7167
|
return { inputFile, outDir, name, enumSerialization };
|
|
7066
7168
|
}
|
|
7067
7169
|
async function main() {
|
|
@@ -7072,11 +7174,14 @@ async function main() {
|
|
|
7072
7174
|
}
|
|
7073
7175
|
const { inputFile, outDir, name, enumSerialization } = options;
|
|
7074
7176
|
const absoluteInput = path4.resolve(process.cwd(), inputFile);
|
|
7177
|
+
log.debug("Resolved input file", { absoluteInput });
|
|
7075
7178
|
try {
|
|
7076
7179
|
const fileUrl = pathToFileURL(absoluteInput).href;
|
|
7180
|
+
log.debug("Loading form module", { fileUrl });
|
|
7077
7181
|
const module = await import(fileUrl);
|
|
7078
7182
|
const form = module["default"] ?? module["form"];
|
|
7079
7183
|
if (!form || typeof form !== "object" || !("elements" in form)) {
|
|
7184
|
+
log.error("Input file does not export a valid FormSpec", { fileUrl });
|
|
7080
7185
|
console.error("Error: Input file must export a FormSpec as default export or as 'form'");
|
|
7081
7186
|
console.error("Example:");
|
|
7082
7187
|
console.error(' export default formspec(field.text("name"));');
|
|
@@ -7084,18 +7189,22 @@ async function main() {
|
|
|
7084
7189
|
console.error(' export const form = formspec(field.text("name"));');
|
|
7085
7190
|
process.exit(1);
|
|
7086
7191
|
}
|
|
7192
|
+
log.debug("Form module loaded, generating schemas");
|
|
7087
7193
|
const { writeSchemas: writeSchemas2 } = await Promise.resolve().then(() => (init_index(), index_exports));
|
|
7088
7194
|
const { jsonSchemaPath, uiSchemaPath } = writeSchemas2(
|
|
7089
7195
|
form,
|
|
7090
7196
|
{ outDir, name, enumSerialization }
|
|
7091
7197
|
);
|
|
7198
|
+
log.debug("Schemas written", { jsonSchemaPath, uiSchemaPath });
|
|
7092
7199
|
console.log("Generated:");
|
|
7093
7200
|
console.log(` ${jsonSchemaPath}`);
|
|
7094
7201
|
console.log(` ${uiSchemaPath}`);
|
|
7095
7202
|
} catch (error) {
|
|
7096
7203
|
if (error instanceof Error) {
|
|
7204
|
+
log.child({ err: error.message }).error("Schema generation failed");
|
|
7097
7205
|
console.error(`Error: ${error.message}`);
|
|
7098
7206
|
} else {
|
|
7207
|
+
log.error("Schema generation failed with unknown error");
|
|
7099
7208
|
console.error("Error:", error);
|
|
7100
7209
|
}
|
|
7101
7210
|
process.exit(1);
|