@ariestools/toolchain 8.7.3 → 8.7.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"exposureWalk.d.ts","sourceRoot":"","sources":["../../../../src/actions/api-exposure/analyzer/exposureWalk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAWhD,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,gFAAgF;IAChF,SAAS,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAA;IAC5C,OAAO,EAAE,EAAE,CAAC,OAAO,CAAA;CACpB;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAavE;AA0FD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,UAAU,EAAE,SAAS,EAAE,OAAO,GAC/B,EAAE,kBAAkB,GAAG,aAAa,EAAE,CAqMtC"}
1
+ {"version":3,"file":"exposureWalk.d.ts","sourceRoot":"","sources":["../../../../src/actions/api-exposure/analyzer/exposureWalk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAiBhD,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,gFAAgF;IAChF,SAAS,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAA;IAC5C,OAAO,EAAE,EAAE,CAAC,OAAO,CAAA;CACpB;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAavE;AA8FD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,UAAU,EAAE,SAAS,EAAE,OAAO,GAC/B,EAAE,kBAAkB,GAAG,aAAa,EAAE,CAyMtC"}
@@ -0,0 +1,9 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * True when a public type is represented by TypeScript's structural type
4
+ * system rather than a class, enum, constructor, or unique-symbol identity.
5
+ * Type arguments and interface base types must also be structural so wrappers
6
+ * such as `Promise<ExternalClass>` do not hide nominal exposure.
7
+ */
8
+ export declare function isStructuralPublicType(type: ts.Type, checker: ts.TypeChecker, seen?: Set<ts.Type>): boolean;
9
+ //# sourceMappingURL=structuralType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structuralType.d.ts","sourceRoot":"","sources":["../../../../src/actions/api-exposure/analyzer/structuralType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAS3B;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,eAAqB,GAAG,OAAO,CAwBjH"}
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/actions/api-exposure/rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,iBAAiB,EAqKxC,CAAA;AAID,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,MAAM,CAA+B,CAAA;AAE5E,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAEpE"}
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/actions/api-exposure/rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,iBAAiB,EA2KxC,CAAA;AAID,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,MAAM,CAA+B,CAAA;AAE5E,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAEpE"}
package/dist/bin/xy.mjs CHANGED
@@ -23472,6 +23472,12 @@ const AEI_RULES = [
23472
23472
  id: "aei.exposure.generic-parameter",
23473
23473
  kind: "exposure"
23474
23474
  },
23475
+ {
23476
+ defaultWeight: 0,
23477
+ description: "Producer-owned function return represented by a structurally compatible interface or type alias",
23478
+ id: "aei.exposure.structural-return",
23479
+ kind: "exposure"
23480
+ },
23475
23481
  {
23476
23482
  defaultEnabled: false,
23477
23483
  defaultWeight: 0,
@@ -24215,6 +24221,32 @@ function resolveEntryPoints(workspaceDir) {
24215
24221
  return [...entryPoints];
24216
24222
  }
24217
24223
  //#endregion
24224
+ //#region src/actions/api-exposure/analyzer/structuralType.ts
24225
+ const NOMINAL_SYMBOL_FLAGS = ts.SymbolFlags.Class | ts.SymbolFlags.Enum | ts.SymbolFlags.EnumMember;
24226
+ function hasNominalSymbol(type) {
24227
+ return [type.aliasSymbol, type.getSymbol()].some((symbol) => symbol !== void 0 && (symbol.flags & NOMINAL_SYMBOL_FLAGS) !== 0);
24228
+ }
24229
+ /**
24230
+ * True when a public type is represented by TypeScript's structural type
24231
+ * system rather than a class, enum, constructor, or unique-symbol identity.
24232
+ * Type arguments and interface base types must also be structural so wrappers
24233
+ * such as `Promise<ExternalClass>` do not hide nominal exposure.
24234
+ */
24235
+ function isStructuralPublicType(type, checker, seen = /* @__PURE__ */ new Set()) {
24236
+ if (seen.has(type)) return true;
24237
+ seen.add(type);
24238
+ if ((type.flags & (ts.TypeFlags.UniqueESSymbol | ts.TypeFlags.EnumLike)) !== 0 || hasNominalSymbol(type)) return false;
24239
+ if (type.isUnionOrIntersection()) return type.types.every((member) => isStructuralPublicType(member, checker, seen));
24240
+ if (((type.objectFlags ?? 0) & ts.ObjectFlags.Class) !== 0 || type.getConstructSignatures().length > 0) return false;
24241
+ const reference = type;
24242
+ if (reference.target !== void 0 && reference.target !== type && !isStructuralPublicType(reference.target, checker, seen)) return false;
24243
+ if ((reference.typeArguments ?? type.aliasTypeArguments ?? []).some((argument) => !isStructuralPublicType(argument, checker, seen))) return false;
24244
+ if (type.isClassOrInterface()) {
24245
+ if (checker.getBaseTypes(type).some((baseType) => !isStructuralPublicType(baseType, checker, seen))) return false;
24246
+ }
24247
+ return true;
24248
+ }
24249
+ //#endregion
24218
24250
  //#region src/actions/api-exposure/analyzer/exposureWalk.ts
24219
24251
  /** How deep the type walker follows type arguments and object members. */
24220
24252
  const MAX_TYPE_DEPTH = 4;
@@ -24241,29 +24273,33 @@ function symbolDependencies(symbol) {
24241
24273
  }
24242
24274
  return dependencies;
24243
24275
  }
24244
- function recordUsage(context, dependency, usage) {
24245
- if (context.usage.get(dependency) !== "direct") context.usage.set(dependency, usage);
24276
+ function recordUsage(context, dependency, kind, structural) {
24277
+ const existing = context.usage.get(dependency);
24278
+ context.usage.set(dependency, {
24279
+ kind: existing?.kind === "direct" ? "direct" : kind,
24280
+ structural: (existing?.structural ?? true) && structural
24281
+ });
24246
24282
  }
24247
24283
  function resolveAlias(checker, symbol) {
24248
24284
  if (symbol === void 0) return void 0;
24249
24285
  return (symbol.flags & ts.SymbolFlags.Alias) === 0 ? symbol : checker.getAliasedSymbol(symbol);
24250
24286
  }
24251
24287
  /** Walks members and signatures of anonymous object types. */
24252
- function collectAnonymousMemberDependencies(type, usage, depth, context) {
24288
+ function collectAnonymousMemberDependencies(type, kind, depth, context) {
24253
24289
  const symbolType = (property) => {
24254
24290
  const declaration = property.valueDeclaration ?? property.declarations?.[0];
24255
24291
  return declaration === void 0 ? void 0 : context.checker.getTypeOfSymbolAtLocation(property, declaration);
24256
24292
  };
24257
24293
  for (const property of type.getProperties()) {
24258
24294
  const propertyType = symbolType(property);
24259
- if (propertyType !== void 0) collectTypeDependencies(propertyType, usage, depth + 1, context);
24295
+ if (propertyType !== void 0) collectTypeDependencies(propertyType, kind, depth + 1, context);
24260
24296
  }
24261
24297
  for (const signature of [...type.getCallSignatures(), ...type.getConstructSignatures()]) {
24262
24298
  for (const parameter of signature.getParameters()) {
24263
24299
  const parameterType = symbolType(parameter);
24264
- if (parameterType !== void 0) collectTypeDependencies(parameterType, usage, depth + 1, context);
24300
+ if (parameterType !== void 0) collectTypeDependencies(parameterType, kind, depth + 1, context);
24265
24301
  }
24266
- collectTypeDependencies(signature.getReturnType(), usage, depth + 1, context);
24302
+ collectTypeDependencies(signature.getReturnType(), kind, depth + 1, context);
24267
24303
  }
24268
24304
  }
24269
24305
  /**
@@ -24271,17 +24307,18 @@ function collectAnonymousMemberDependencies(type, usage, depth, context) {
24271
24307
  * declared in. Type arguments are recorded as `generic` usage; unions,
24272
24308
  * intersections, and anonymous object members keep their parent's usage.
24273
24309
  */
24274
- function collectTypeDependencies(type, usage, depth, context) {
24310
+ function collectTypeDependencies(type, kind, depth, context) {
24275
24311
  if (depth > MAX_TYPE_DEPTH || context.visited.has(type)) return;
24276
24312
  context.visited.add(type);
24277
- for (const symbol of [type.aliasSymbol, type.getSymbol()]) for (const dependency of symbolDependencies(symbol)) recordUsage(context, dependency, usage);
24313
+ const structural = isStructuralPublicType(type, context.checker);
24314
+ for (const symbol of [type.aliasSymbol, type.getSymbol()]) for (const dependency of symbolDependencies(symbol)) recordUsage(context, dependency, kind, structural);
24278
24315
  if (type.isUnionOrIntersection()) {
24279
- for (const constituent of type.types) collectTypeDependencies(constituent, usage, depth + 1, context);
24316
+ for (const constituent of type.types) collectTypeDependencies(constituent, kind, depth + 1, context);
24280
24317
  return;
24281
24318
  }
24282
24319
  const typeArguments = type.typeArguments ?? type.aliasTypeArguments ?? [];
24283
24320
  for (const argument of typeArguments) collectTypeDependencies(argument, "generic", depth + 1, context);
24284
- if (((type.objectFlags ?? 0) & ts.ObjectFlags.Anonymous) !== 0 && symbolDependencies(type.getSymbol()).size === 0) collectAnonymousMemberDependencies(type, usage, depth, context);
24321
+ if (((type.objectFlags ?? 0) & ts.ObjectFlags.Anonymous) !== 0 && symbolDependencies(type.getSymbol()).size === 0) collectAnonymousMemberDependencies(type, kind, depth, context);
24285
24322
  }
24286
24323
  function typeDependencies(type, checker) {
24287
24324
  const context = {
@@ -24319,8 +24356,9 @@ function getExposureFindings({ entryFiles, fileLabel, program }) {
24319
24356
  ruleId
24320
24357
  });
24321
24358
  }
24322
- function reportUsage(usage, directRuleId, node, directEvidence, genericEvidence) {
24323
- for (const [dependency, kind] of usage) if (kind === "direct") report(directRuleId, dependency, node, directEvidence(dependency));
24359
+ function reportUsage(usage, directRuleId, node, directEvidence, genericEvidence, structuralRuleId) {
24360
+ for (const [dependency, typeUsage] of usage) if (typeUsage.structural && structuralRuleId !== void 0) report(structuralRuleId, dependency, node, `exported API returns a structural type from ${dependency}`);
24361
+ else if (typeUsage.kind === "direct") report(directRuleId, dependency, node, directEvidence(dependency));
24324
24362
  else report("aei.exposure.generic-parameter", dependency, node, genericEvidence(dependency));
24325
24363
  }
24326
24364
  function visitFunctionExport(name, symbol, declaration) {
@@ -24330,7 +24368,7 @@ function getExposureFindings({ entryFiles, fileLabel, program }) {
24330
24368
  const parameterDeclaration = parameter.valueDeclaration ?? parameter.declarations?.[0] ?? declaration;
24331
24369
  reportUsage(typeDependencies(checker.getTypeOfSymbolAtLocation(parameter, parameterDeclaration), checker), "aei.exposure.function-parameter", parameterDeclaration, (dep) => `exported function \`${name}\` parameter \`${parameter.name}\` is typed by ${dep}`, (dep) => `exported function \`${name}\` parameter \`${parameter.name}\` uses ${dep} as a generic argument`);
24332
24370
  }
24333
- reportUsage(typeDependencies(signature.getReturnType(), checker), "aei.exposure.function-return", declaration, (dep) => `exported function \`${name}\` return type originates in ${dep}`, (dep) => `exported function \`${name}\` return type uses ${dep} as a generic argument`);
24371
+ reportUsage(typeDependencies(signature.getReturnType(), checker), "aei.exposure.function-return", declaration, (dep) => `exported function \`${name}\` return type originates in ${dep}`, (dep) => `exported function \`${name}\` return type uses ${dep} as a generic argument`, "aei.exposure.structural-return");
24334
24372
  const typeParameters = signature.typeParameters ?? [];
24335
24373
  for (const typeParameter of typeParameters) {
24336
24374
  const constraint = typeParameter.getConstraint();
@@ -24368,9 +24406,9 @@ function getExposureFindings({ entryFiles, fileLabel, program }) {
24368
24406
  for (const dependency of symbolDependencies(resolved)) report("aei.exposure.exported-owned-value", dependency, declaration, `exported value \`${name}\` is owned by ${dependency}`);
24369
24407
  }
24370
24408
  const usage = typeDependencies(checker.getTypeOfSymbolAtLocation(symbol, declaration), checker);
24371
- const directDependencies = [...usage].filter(([, kind]) => kind === "direct").map(([dependency]) => dependency);
24409
+ const directDependencies = [...usage].filter(([, typeUsage]) => typeUsage.kind === "direct").map(([dependency]) => dependency);
24372
24410
  for (const dependency of directDependencies) report("aei.exposure.exported-value", dependency, declaration, `exported runtime value \`${name}\` has a type originating in ${dependency}`);
24373
- for (const [dependency, kind] of usage) if (kind === "generic") report("aei.exposure.generic-parameter", dependency, declaration, `exported value \`${name}\` uses ${dependency} as a generic argument`);
24411
+ for (const [dependency, typeUsage] of usage) if (typeUsage.kind === "generic") report("aei.exposure.generic-parameter", dependency, declaration, `exported value \`${name}\` uses ${dependency} as a generic argument`);
24374
24412
  if (directDependencies.length === 0 && initializer !== void 0 && ts.isCallExpression(initializer)) {
24375
24413
  const resolved = resolveAlias(checker, checker.getSymbolAtLocation(initializer.expression));
24376
24414
  for (const dependency of symbolDependencies(resolved)) report("aei.exposure.exported-constant", dependency, declaration, `exported constant \`${name}\` is produced by a ${dependency} factory`);