@openpkg-ts/sdk 0.54.5 → 0.54.7
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/index.js +96 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2464,6 +2464,9 @@ function createProgram(options) {
|
|
|
2464
2464
|
const configFile = ts3.readConfigFile(configPath, ts3.sys.readFile);
|
|
2465
2465
|
const parsedConfig = ts3.parseJsonConfigFileContent(configFile.config, ts3.sys, path5.dirname(configPath));
|
|
2466
2466
|
compilerOptions = { ...compilerOptions, ...parsedConfig.options };
|
|
2467
|
+
if (parsedConfig.options.module !== undefined && parsedConfig.options.moduleResolution === undefined) {
|
|
2468
|
+
delete compilerOptions.moduleResolution;
|
|
2469
|
+
}
|
|
2467
2470
|
additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
|
|
2468
2471
|
let sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
|
|
2469
2472
|
if (/\.d\.[cm]?ts$/.test(entryFile)) {
|
|
@@ -3210,6 +3213,88 @@ function isFluentThisType(type) {
|
|
|
3210
3213
|
return false;
|
|
3211
3214
|
return declarations.some((decl) => ts5.isClassDeclaration(decl) || ts5.isClassExpression(decl) || ts5.isInterfaceDeclaration(decl));
|
|
3212
3215
|
}
|
|
3216
|
+
function containsUnresolvedTypeParameter(type, seen = new Set) {
|
|
3217
|
+
if (seen.has(type))
|
|
3218
|
+
return false;
|
|
3219
|
+
seen.add(type);
|
|
3220
|
+
if (type.flags & ts5.TypeFlags.TypeParameter) {
|
|
3221
|
+
return !isFluentThisType(type);
|
|
3222
|
+
}
|
|
3223
|
+
if (type.isUnionOrIntersection()) {
|
|
3224
|
+
return type.types.some((t) => containsUnresolvedTypeParameter(t, seen));
|
|
3225
|
+
}
|
|
3226
|
+
if (type.aliasTypeArguments) {
|
|
3227
|
+
for (const arg of type.aliasTypeArguments) {
|
|
3228
|
+
if (containsUnresolvedTypeParameter(arg, seen))
|
|
3229
|
+
return true;
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
const targs = type.typeArguments;
|
|
3233
|
+
if (targs) {
|
|
3234
|
+
for (const arg of targs) {
|
|
3235
|
+
if (containsUnresolvedTypeParameter(arg, seen))
|
|
3236
|
+
return true;
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
if (type.flags & ts5.TypeFlags.IndexedAccess) {
|
|
3240
|
+
const ia = type;
|
|
3241
|
+
return containsUnresolvedTypeParameter(ia.objectType, seen) || containsUnresolvedTypeParameter(ia.indexType, seen);
|
|
3242
|
+
}
|
|
3243
|
+
return false;
|
|
3244
|
+
}
|
|
3245
|
+
function isUtilityOverTypeParameter(type) {
|
|
3246
|
+
const name = type.aliasSymbol?.getName();
|
|
3247
|
+
if (!name || !RESOLVED_UTILITY_TYPES.has(name))
|
|
3248
|
+
return false;
|
|
3249
|
+
const args = type.aliasTypeArguments;
|
|
3250
|
+
if (!args || args.length === 0)
|
|
3251
|
+
return false;
|
|
3252
|
+
return args.some((t) => containsUnresolvedTypeParameter(t));
|
|
3253
|
+
}
|
|
3254
|
+
function writtenUtilityText(type, checker, typeNode) {
|
|
3255
|
+
let node = typeNode;
|
|
3256
|
+
while (node && ts5.isParenthesizedTypeNode(node))
|
|
3257
|
+
node = node.type;
|
|
3258
|
+
const fromNode = writtenTypeText(node);
|
|
3259
|
+
if (fromNode)
|
|
3260
|
+
return fromNode;
|
|
3261
|
+
if (node) {
|
|
3262
|
+
try {
|
|
3263
|
+
const text = scrubImportQualifiers(node.getText().replace(/\s+/g, " ").trim());
|
|
3264
|
+
if (text)
|
|
3265
|
+
return text;
|
|
3266
|
+
} catch {}
|
|
3267
|
+
}
|
|
3268
|
+
const name = type.aliasSymbol?.getName();
|
|
3269
|
+
const args = type.aliasTypeArguments;
|
|
3270
|
+
if (name && args && args.length > 0) {
|
|
3271
|
+
const inner = args.map((t) => scrubImportQualifiers(checker.typeToString(t))).join(", ");
|
|
3272
|
+
return `${name}<${inner}>`;
|
|
3273
|
+
}
|
|
3274
|
+
return renderTypeText(type, checker);
|
|
3275
|
+
}
|
|
3276
|
+
function isReadonlyArrayType(type, typeNode) {
|
|
3277
|
+
let node = typeNode;
|
|
3278
|
+
while (node && ts5.isParenthesizedTypeNode(node))
|
|
3279
|
+
node = node.type;
|
|
3280
|
+
if (node && ts5.isTypeOperatorNode(node) && node.operator === ts5.SyntaxKind.ReadonlyKeyword) {
|
|
3281
|
+
return true;
|
|
3282
|
+
}
|
|
3283
|
+
if (node && ts5.isTypeReferenceNode(node) && typeRefName(node) === "ReadonlyArray") {
|
|
3284
|
+
return true;
|
|
3285
|
+
}
|
|
3286
|
+
const ref = type;
|
|
3287
|
+
const name = ref.target?.getSymbol()?.getName() ?? type.getSymbol()?.getName();
|
|
3288
|
+
return name === "ReadonlyArray";
|
|
3289
|
+
}
|
|
3290
|
+
function withReadonlyArrayHint(schema, type, typeNode) {
|
|
3291
|
+
if (!isReadonlyArrayType(type, typeNode))
|
|
3292
|
+
return schema;
|
|
3293
|
+
if (typeof schema !== "object" || schema === null || Array.isArray(schema))
|
|
3294
|
+
return schema;
|
|
3295
|
+
setSchemaExtension(schema, "x-ts-readonly", true);
|
|
3296
|
+
return schema;
|
|
3297
|
+
}
|
|
3213
3298
|
function withDepth(ctx, fn) {
|
|
3214
3299
|
ctx.currentDepth++;
|
|
3215
3300
|
try {
|
|
@@ -3366,6 +3451,9 @@ function buildSchemaInternal(type, checker, ctx, typeNode) {
|
|
|
3366
3451
|
if (type.flags & ts5.TypeFlags.TypeParameter) {
|
|
3367
3452
|
return { "x-ts-type": checker.typeToString(type) };
|
|
3368
3453
|
}
|
|
3454
|
+
if (isUtilityOverTypeParameter(type)) {
|
|
3455
|
+
return { "x-ts-type": writtenUtilityText(type, checker, typeNode) };
|
|
3456
|
+
}
|
|
3369
3457
|
if (type.flags & ts5.TypeFlags.StringLiteral) {
|
|
3370
3458
|
const literal = type.value;
|
|
3371
3459
|
return { type: "string", enum: [literal] };
|
|
@@ -3465,15 +3553,10 @@ function buildSchemaInternal(type, checker, ctx, typeNode) {
|
|
|
3465
3553
|
const arrayTypeArgs = checker.getTypeArguments(arrayTypeRef);
|
|
3466
3554
|
const elementType = arrayTypeArgs?.[0];
|
|
3467
3555
|
if (elementType) {
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
type: "array",
|
|
3471
|
-
items: buildSchema(elementType, checker, ctx)
|
|
3472
|
-
}));
|
|
3473
|
-
}
|
|
3474
|
-
return { type: "array", items: buildSchema(elementType, checker, ctx) };
|
|
3556
|
+
const build = () => withReadonlyArrayHint({ type: "array", items: buildSchema(elementType, checker, ctx) }, type, typeNode);
|
|
3557
|
+
return ctx ? withDepth(ctx, build) : build();
|
|
3475
3558
|
}
|
|
3476
|
-
return { type: "array" };
|
|
3559
|
+
return withReadonlyArrayHint({ type: "array" }, type, typeNode);
|
|
3477
3560
|
}
|
|
3478
3561
|
if (checker.isTupleType(type)) {
|
|
3479
3562
|
const tupleTypeRef = type;
|
|
@@ -3995,8 +4078,11 @@ function applyDefault(param, initializer) {
|
|
|
3995
4078
|
if (param.schema && typeof param.schema === "object" && !Array.isArray(param.schema)) {
|
|
3996
4079
|
param.schema.default = extracted.value;
|
|
3997
4080
|
}
|
|
3998
|
-
} else
|
|
3999
|
-
param.
|
|
4081
|
+
} else {
|
|
4082
|
+
param.default = extracted.text;
|
|
4083
|
+
if (param.schema && typeof param.schema === "object" && !Array.isArray(param.schema)) {
|
|
4084
|
+
param.schema["x-ts-default"] = extracted.text;
|
|
4085
|
+
}
|
|
4000
4086
|
}
|
|
4001
4087
|
}
|
|
4002
4088
|
function registerReferencedTypes(type, ctx, depth = 0) {
|